diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 22a79fc6abbfc5f9459331399c611fef61e7ba62..0000000000000000000000000000000000000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/.gitignore b/ArkUIKit/RequireDemo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/RequireDemo/.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/ArkUIKit/RequireDemo/AppScope/app.json5 b/ArkUIKit/RequireDemo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0269c02d809434f248ed788a241069e7d0269fda --- /dev/null +++ b/ArkUIKit/RequireDemo/AppScope/app.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. + */ +{ + "app": { + "bundleName": "com.samples.requiredemo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/RequireDemo/AppScope/resources/base/element/string.json b/ArkUIKit/RequireDemo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee186f8ff8195825b07c3aeda51ae04f2b4bed66 --- /dev/null +++ b/ArkUIKit/RequireDemo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "RequireDemo" + } + ] +} diff --git a/ArkUIKit/RequireDemo/AppScope/resources/base/media/background.png b/ArkUIKit/RequireDemo/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/RequireDemo/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/RequireDemo/AppScope/resources/base/media/foreground.png b/ArkUIKit/RequireDemo/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/ArkUIKit/RequireDemo/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/RequireDemo/AppScope/resources/base/media/layered_image.json b/ArkUIKit/RequireDemo/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/RequireDemo/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/README_zh.md b/ArkUIKit/RequireDemo/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..6b494ce2b3021903bb40729206a644d6bdfe3f47 --- /dev/null +++ b/ArkUIKit/RequireDemo/README_zh.md @@ -0,0 +1,72 @@ +# ArkTs Require装饰器简介 + +### 介绍 + +@Require是校验@Prop、@State、@Provide、@BuilderParam、@Param和普通变量(无状态装饰器修饰的变量)是否需要构造传参的一个装饰器。 + +### 效果预览 + +| 首页选项目录 | SceneRequire示例 | ParentPage示例 | PageOne示例 | Explame +|-------------------|------------------------------------|------------------------------------|--------------------------------------|--------------------------------------| +| ![](screenshots/Screenshot_2025-10-24T173700.png) | ![](screenshots/Screenshot_2025-10-24T173714.png) | ![](screenshots/Screenshot_2025-10-24T173738.png) | ![](screenshots/Screenshot_2025-10-24T173811.png) | ![](screenshots/Screenshot_2025-10-24T173835.png) | + + +不涉及。 +### 使用说明 + +1. 应用在启动后显示首页4个按钮。 +2. 分别点击4个按钮进入相应代码片段的页面。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Explame.ets + │ │ ├── Index.ets // 首页 + │ │ ├── PageOne.ets + │ │ ├── ParentPage.ets + │ │ ├── SceneRequire.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` +### 具体实现 + +1. 当Child组件内使用@Require装饰器和@Prop、@State、@Provide、@BuilderParam、@Param和普通变量(无状态装饰器修饰的变量)结合使用时,父组件Index在构造Child时必须传参,否则编译不通过。 +2. 使用@ComponentV2修饰的自定义组件ChildPage通过父组件ParentPage进行初始化,因为有@Require装饰@Param,所以父组件必须进行构造赋值。 +3. 当Child组件内将@Require装饰器与@Prop、@State、@Provide、@BuilderParam、普通变量(无状态装饰器修饰的变量)结合使用时,若父组件Index在构造Child时未传递相应参数,则会导致编译失败。当ChildV2组件内将@Require装饰器与@Param结合使用时,若父组件Index在构造ChildV2时未传递相应参数,则同样会导致编译失败。 +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API20版本SDK,版本号:6.0.0.40,镜像版本号:OpenHarmony_6.0.0.40。 + +3.本示例需要使用DevEco Studio 6.0.0 Release (Build Version: 6.0.0.858, built on September 24, 2025)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/RequireDemo > .git/info/sparse-checkout +git remote add origin https:///gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/ArkUIKit/RequireDemo/build-profile.json5 b/ArkUIKit/RequireDemo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3ca5a93fb814017ac4c398aacbdf17b1d8b0a237 --- /dev/null +++ b/ArkUIKit/RequireDemo/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/code-linter.json5 b/ArkUIKit/RequireDemo/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/ArkUIKit/RequireDemo/code-linter.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. + */ +{ + "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/ArkUIKit/RequireDemo/entry/.gitignore b/ArkUIKit/RequireDemo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/build-profile.json5 b/ArkUIKit/RequireDemo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/build-profile.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. + */ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/hvigorfile.ts b/ArkUIKit/RequireDemo/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/hvigorfile.ts @@ -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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/obfuscation-rules.txt b/ArkUIKit/RequireDemo/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/oh-package.json5 b/ArkUIKit/RequireDemo/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/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": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkUIKit/RequireDemo/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/RequireDemo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/RequireDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +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 { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/ets/pages/Explame.ets b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/Explame.ets new file mode 100644 index 0000000000000000000000000000000000000000..732b65f6707e1e05c32b981d8d17ffacbd15e9a9 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/Explame.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 explame_require_tart] +@Entry +@Component +struct Explame { + @State message: string = 'Hello World!'; + + @Builder + buildTest() { + Row() { + Text('Hello, world!!') + .fontSize(30) + } + } + + build() { + Row() { + // 构造Child、ChildV2组件时传递相应参数,编译通过。 + ChildV1({ + regularValue: 'Hello', + stateValue: 'Hello', + provideValue: 'Hello', + initBuildTest: this.buildTest, + initMessage: 'Hello' + }) + ChildV2({ message: this.message }) + } + } +} + +@Component +struct ChildV1 { + @Builder + buildFunction() { + Column() { + Text('initBuilderParam') + .fontSize(30) + } + } + + // 使用@Require必须构造时传参。 + @Require regularValue: string = 'Hello'; + @Require @State stateValue: string = 'Hello'; + @Require @Provide provideValue: string = 'Hello'; + @Require @BuilderParam initBuildTest: () => void = this.buildFunction; + @Require @Prop initMessage: string = 'Hello'; + + build() { + Column() { + Text(this.initMessage) + .fontSize(30) + this.initBuildTest(); + } + } +} + +@ComponentV2 +struct ChildV2 { + // 使用@Require必须构造时传参。 + @Require @Param message: string; + + build() { + Column() { + Text(this.message) + } + } +} +// [End explame_require_tart] \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/ets/pages/Index.ets b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6c41ddcf80cf4206174f11e0d2a4ddb83758818a --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Column(){ + Button('usage scene') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('SceneRequire') + .onClick(() => { + router.pushUrl({ + url:'pages/SceneRequire' + }) + }) + + Button('usage ComponentV2') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('ParentPage') + .onClick(() => { + router.pushUrl({ + url:'pages/ParentPage' + }) + }) + Button('page one') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('PageOne') + .onClick(() => { + router.pushUrl({ + url:'pages/PageOne' + }) + }) + Button('ask') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('Explame') + .onClick(() => { + router.pushUrl({ + url:'pages/Explame' + }) + }) + } + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/ets/pages/PageOne.ets b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/PageOne.ets new file mode 100644 index 0000000000000000000000000000000000000000..ec48d64f233c25019e1fd522f7d50d6c04d6e15b --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/PageOne.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start page_one_require_tart] +@Entry +@Component +struct Index { + message: string = 'Hello World'; + + build() { + Column() { + Child_V1({ message: this.message }) + } + } +} + +@Component +struct Child_V1 { + @Require @State message: string; + + build() { + Column() { + Text(this.message) // 从API version 18开始,可以编译通过。 + } + } +} +// [End page_one_require_tart] \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/ets/pages/ParentPage.ets b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/ParentPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee443d95a8683fc4c44871a8221b4d12114f47cb --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/ParentPage.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 parent_require_tart] +@ObservedV2 +class Info { + @Trace public name: string = ''; + @Trace public age: number = 0; +} + +@ComponentV2 +struct ChildPage { + @Require @Param childInfo: Info = new Info(); + @Require @Param stateValue: string = 'Hello'; + + build() { + Column() { + Text(`ChildPage childInfo name :${this.childInfo.name}`) + .fontSize(20) + .fontWeight(FontWeight.Bold) + Text(`ChildPage childInfo age :${this.childInfo.age}`) + .fontSize(20) + .fontWeight(FontWeight.Bold) + Text(`ChildPage stateValue age :${this.stateValue}`) + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + } +} + +@Entry +@ComponentV2 +struct ParentPage { + info1: Info = { name: 'Tom', age: 25 }; + label1: string = 'Hello World'; + @Local info2: Info = { name: 'Tom', age: 25 }; + @Local label2: string = 'Hello World'; + + build() { + Column() { + Text(`info1: ${this.info1.name} ${this.info1.age}`) // Text1 + .fontSize(30) + .fontWeight(FontWeight.Bold) + // 父组件ParentPage构造子组件ChildPage时进行了构造赋值。 + // 为ChildPage中被@Require @Param装饰的childInfo和stateValue属性传入了值。 + ChildPage({ childInfo: this.info1, stateValue: this.label1 }) // 创建自定义组件。 + Line() + .width('100%') + .height(5) + .backgroundColor('#000000').margin(10) + Text(`info2: ${this.info2.name} ${this.info2.age}`) // Text2。 + .fontSize(30) + .fontWeight(FontWeight.Bold) + // 同上,在父组件创建子组件的过程中进行构造赋值。 + ChildPage({ childInfo: this.info2, stateValue: this.label2 }) // 创建自定义组件。 + Line() + .width('100%') + .height(5) + .backgroundColor('#000000').margin(10) + Button('change info1&info2') + .onClick(() => { + this.info1 = { name: 'Cat', age: 18 }; // Text1不会刷新,原因是info1没有装饰器装饰,监听不到值的改变。 + this.info2 = { name: 'Cat', age: 18 }; // Text2会刷新,原因是info2有装饰器装饰,能够监听到值的改变。 + this.label1 = 'Luck'; // 不会刷新,原因是label1没有装饰器装饰,监听不到值的改变。 + this.label2 = 'Luck'; // 会刷新,原因是label2有装饰器装饰,可以监听到值的改变。 + }) + } + } +} +// [End parent_require_tart] \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/ets/pages/SceneRequire.ets b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/SceneRequire.ets new file mode 100644 index 0000000000000000000000000000000000000000..3a35ed916eb36169c752224573350d23c80bbdbe --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/ets/pages/SceneRequire.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. + */ + +// [Start scene_require_tart] +@Entry +@Component +struct SceneRequire { + @State message: string = 'Hello World'; + + @Builder + buildTest() { + Row() { + Text('Hello, world') + .fontSize(30) + } + } + + build() { + Row() { + // 构造Child时需传入所有@Require对应参数,否则编译失败。 + Child({ + regularValue: this.message, + stateValue: this.message, + provideValue: this.message, + initMessage: this.message, + message: this.message, + buildTest: this.buildTest, + initBuildTest: this.buildTest + }) + } + } +} + +@Component +struct Child { + @Builder + buildFunction() { + Column() { + Text('initBuilderParam') + .fontSize(30) + } + } + + @Require regularValue: string = 'Hello'; + @Require @State stateValue: string = 'Hello'; + @Require @Provide provideValue: string = 'Hello'; + @Require @BuilderParam buildTest: () => void; + @Require @BuilderParam initBuildTest: () => void = this.buildFunction; + @Require @Prop initMessage: string = 'Hello'; + @Require @Prop message: string; + + build() { + Column() { + Text(this.initMessage) + .fontSize(30) + Text(this.message) + .fontSize(30) + this.initBuildTest(); + this.buildTest(); + } + .width('100%') + .height('100%') + } +} +// [End scene_require_tart] \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/module.json5 b/ArkUIKit/RequireDemo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..48003bfc257d2a69115144f9564906f623ea981d --- /dev/null +++ b/ArkUIKit/RequireDemo/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": [ + "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": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/color.json b/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/RequireDemo/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/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/float.json b/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/string.json b/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/background.png b/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/RequireDemo/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/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/RequireDemo/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/RequireDemo/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/RequireDemo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b61fb8f6e123bf74be70cb8db6170be622c97f07 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,9 @@ +{ + "src": [ + "pages/Index", + "pages/SceneRequire", + "pages/ParentPage", + "pages/Explame", + "pages/PageOne" + ] +} diff --git a/ArkUIKit/RequireDemo/entry/src/main/resources/dark/element/color.json b/ArkUIKit/RequireDemo/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/RequireDemo/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/ArkUIKit/RequireDemo/entry/src/mock/mock-config.json5 b/ArkUIKit/RequireDemo/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/mock/mock-config.json5 @@ -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. + */ +{ +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/RequireDemo/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..efb51f0054fa929c9c52e2ef6526699bb97df1a0 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/ohosTest/ets/test/Ability.test.ets @@ -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. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Want } from '@kit.AbilityKit'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const TAG = '[Sample_RequireDemo]'; +const DOMAIN_NUMBER: number = 0xF811; + +export default function abilityTest() { + let driver = Driver.create(); + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(async (done: Function) => { + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + await driver.delayMs(1000); + // 获取当前top的ability + let entryAbility = await delegator.getCurrentTopAbility(); + expect(entryAbility.context.abilityInfo.name).assertEqual('EntryAbility'); + done(); + }) + 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('RequireDemo_button_001', 0, async (done: Function) => { + // 跳转到UIAbility组件启动模式界面 + hilog.info(DOMAIN_NUMBER, TAG, 'button_001 start'); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.id('SceneRequire')); + let button = await driver.findComponent(ON.id('SceneRequire')); + await button.click(); + await driver.delayMs(1000); + await driver.pressBack() + hilog.info(DOMAIN_NUMBER, TAG, 'button_001 End'); + done(); + }) + + it('RequireDemo_button_002', 0, async (done: Function) => { + // 跳转到UIAbility组件启动模式界面 + hilog.info(DOMAIN_NUMBER, TAG, 'button_002 start'); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.id('ParentPage')); + let button = await driver.findComponent(ON.id('ParentPage')); + await button.click(); + await driver.delayMs(1000); + await driver.pressBack() + hilog.info(DOMAIN_NUMBER, TAG, 'button_002 End'); + done(); + }) + it('RequireDemo_button_003', 0, async (done: Function) => { + // 跳转到UIAbility组件启动模式界面 + hilog.info(DOMAIN_NUMBER, TAG, 'button_003 start'); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.id('PageOne')); + let button = await driver.findComponent(ON.id('PageOne')); + await button.click(); + await driver.delayMs(1000); + await driver.pressBack() + hilog.info(DOMAIN_NUMBER, TAG, 'button_003 End'); + done(); + }) + it('RequireDemo_button_004', 0, async (done: Function) => { + // 跳转到UIAbility组件启动模式界面 + hilog.info(DOMAIN_NUMBER, TAG, 'button_004 start'); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.id('Explame')); + let button = await driver.findComponent(ON.id('Explame')); + await button.click(); + await driver.delayMs(1000); + await driver.pressBack() + hilog.info(DOMAIN_NUMBER, TAG, 'button_004 End'); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/RequireDemo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +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. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/ohosTest/module.json5 b/ArkUIKit/RequireDemo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3069fb7f9163da9f7e6ffe7366140c3368edc34 --- /dev/null +++ b/ArkUIKit/RequireDemo/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": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/RequireDemo/entry/src/test/List.test.ets b/ArkUIKit/RequireDemo/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/test/List.test.ets @@ -0,0 +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. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/entry/src/test/LocalUnit.test.ets b/ArkUIKit/RequireDemo/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/ArkUIKit/RequireDemo/entry/src/test/LocalUnit.test.ets @@ -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. + */ +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/ArkUIKit/RequireDemo/hvigor/hvigor-config.json5 b/ArkUIKit/RequireDemo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/ArkUIKit/RequireDemo/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": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/RequireDemo/hvigorfile.ts b/ArkUIKit/RequireDemo/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/ArkUIKit/RequireDemo/hvigorfile.ts @@ -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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/RequireDemo/oh-package.json5 b/ArkUIKit/RequireDemo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/ArkUIKit/RequireDemo/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. + */ +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/RequireDemo/ohosTest.md b/ArkUIKit/RequireDemo/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..ae0dfca6fc2211c50526aeb6df8cb4f17108aed2 --- /dev/null +++ b/ArkUIKit/RequireDemo/ohosTest.md @@ -0,0 +1,12 @@ +# @Require装饰器示例测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|-------------------| ------------ | ---- |-------------| -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| usage scene | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | +| usage ComponentV2 | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | +| page one | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | +| ask | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | + diff --git a/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173700.png b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173700.png new file mode 100644 index 0000000000000000000000000000000000000000..d6d5747762bb0779f337369297f10dcff585c42b Binary files /dev/null and b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173700.png differ diff --git a/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173714.png b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173714.png new file mode 100644 index 0000000000000000000000000000000000000000..55204b53675561c5402e4e1ec7221580e609b3a2 Binary files /dev/null and b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173714.png differ diff --git a/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173738.png b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173738.png new file mode 100644 index 0000000000000000000000000000000000000000..8d2a191ebd35b8d0ae526895de38c41010bd315e Binary files /dev/null and b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173738.png differ diff --git a/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173752.png b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173752.png new file mode 100644 index 0000000000000000000000000000000000000000..3ebe4af2d570927322a9589acc53a164b1e85d5f Binary files /dev/null and b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173752.png differ diff --git a/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173811.png b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173811.png new file mode 100644 index 0000000000000000000000000000000000000000..1704dbbb5ea21294677218942c38dd290f8e4e1e Binary files /dev/null and b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173811.png differ diff --git a/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173835.png b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173835.png new file mode 100644 index 0000000000000000000000000000000000000000..aea230516530660e282c4069f95e2df1cce26012 Binary files /dev/null and b/ArkUIKit/RequireDemo/screenshots/Screenshot_2025-10-24T173835.png differ diff --git a/ArkUIKit/Restrictions/.gitignore b/ArkUIKit/Restrictions/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/Restrictions/.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/ArkUIKit/Restrictions/AppScope/app.json5 b/ArkUIKit/Restrictions/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ab445a742898dcfbc56f38dc435fdca605a92729 --- /dev/null +++ b/ArkUIKit/Restrictions/AppScope/app.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. + */ +{ + "app": { + "bundleName": "com.samples.restrictions", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/Restrictions/AppScope/resources/base/element/string.json b/ArkUIKit/Restrictions/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6465bfb67b7d003dc673ae40f4a377b3eb8ae67a --- /dev/null +++ b/ArkUIKit/Restrictions/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Restrictions" + } + ] +} diff --git a/ArkUIKit/Restrictions/AppScope/resources/base/media/background.png b/ArkUIKit/Restrictions/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/Restrictions/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/Restrictions/AppScope/resources/base/media/foreground.png b/ArkUIKit/Restrictions/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/ArkUIKit/Restrictions/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/Restrictions/AppScope/resources/base/media/layered_image.json b/ArkUIKit/Restrictions/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/Restrictions/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/README_zh.md b/ArkUIKit/Restrictions/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..a1ead70de9942f3331ede5e61964170aec26f66d --- /dev/null +++ b/ArkUIKit/Restrictions/README_zh.md @@ -0,0 +1,138 @@ +# Restrictions指南文档示例 + +### 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui)中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。该工程中展示的代码详细描述可查如下链接: +1. [自定义组件成员属性访问限定符使用限制](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/state-management/arkts-custom-components-access-restrictions.md)。 + +### 效果预览 + +| 首页 | +|---------------------------------| +| ![](screenshots/device/img.png) | + +### 使用说明 + +1. 在主界面,可以点击对应卡片,选择需要参考的组件示例。 + +2. 在组件目录选择详细的示例参考。 + +3. 进入示例界面,查看参考示例。 + +4. 通过自动测试框架可进行测试及维护。 + +### 工程目录 +``` +entry/src/main/ets/ +|---entryability // 应用入口能力模块:包含EntryAbility,负责应用启动、生命周期管理 +|---pages // 应用页面模块:存放所有功能页面,按业务模块分类 +| |---linkWithPrivate // linkWithPrivate权限限制测试模块:验证组件关联时private修饰符的影响 +| | |---LlinkWithPrivateCorrectCase.ets // 正确案例页面:组件关联无private修饰符,功能正常 +| | |---LlinkWithPrivateErrorCase.ets // 错误案例页面:组件关联加private修饰符,预期输出告警日志 +| |---privateWithLink // privateWithLink权限限制测试模块:验证@Link/@ObjectLink装饰器加private修饰符的影响 +| | |---PrivateWithLinkCorrectCase.ets // 正确案例页面:@Link/@ObjectLink无private修饰符,功能正常 +| | |---PrivateWithLinkEerrorCase.ets // 错误案例页面:@Link/@ObjectLink加private修饰符,预期输出告警日志 +| |---privateWithRequire // privateWithRequire权限限制测试模块:验证@Require@Prop装饰器加private修饰符的影响 +| | |---PrivateWithRequireCorrectCase.ets // 正确案例页面:@Require@Prop无private修饰符,功能正常 +| | |---PrivateWithRequireErrorCase.ets // 错误案例页面:@Require@Prop加private修饰符,预期输出告警日志 +| |---protectedInStruct // protectedInStruct权限限制测试模块:验证组件属性加protected修饰符的影响 +| | |---ProtectedInStructCorrectCase.ets // 正确案例页面:组件属性无protected修饰符,功能正常 +| | |---ProtectedInStructErrorCase.ets // 错误案例页面:组件属性加protected修饰符,预期输出告警日志 +| |---publicWithStorageProp // publicWithStorageProp权限限制测试模块:验证存储相关装饰器加public修饰符的影响 +| | |---PublicWithStoragePropCorrectCase.ets // 正确案例页面:@LocalStorageProp等无public修饰符,功能正常 +| | |---PublicWithStoragePropErrorCase.ets // 错误案例页面:@LocalStorageProp等加public修饰符,预期输出告警日志 +| |---Index.ets // 应用主页面:提供所有测试模块的导航入口,点击对应文本跳转到目标测试页面 +entry/src/ohosTest/ +|---ets +| |---test // 自动化测试模块:存放所有页面的UI自动化测试代码,与pages目录模块一一对应 +| | |---LinkWithPrivate.test.ets // linkWithPrivate模块测试代码:验证LlinkWithPrivateCorrectCase/EerrorCase页面跳转及功能 +| | |---PrivateWithLink.test.ets // privateWithLink模块测试代码:验证PrivateWithLinkCorrectCase/EerrorCase页面跳转及功能(原重复标注已修正) +| | |---PrivateWithRequire.test.ets // privateWithRequire模块测试代码:验证PrivateWithRequireCorrectCase/ErrorCase页面跳转及功能 +| | |---ProtectedInStruct.test.ets // protectedInStruct模块测试代码:验证ProtectedInStructCorrectCase/ErrorCase页面跳转及功能 +| | |---PublicWithStorgeProp.test.ets // publicWithStorageProp模块测试代码(文件名拼写修正:Storge→Storage):验证PublicWithStoragePropCorrectCase/ErrorCase页面跳转及功能 +``` + +### 具体实现 +1.linkWithPrivate 权限限制 +正确案例功能封装在 LlinkWithPrivateCorrectCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateCorrectCase.ets) +* 组件关联配置:父组件通过属性传递方式与子组件建立数据关联,子组件的关联属性未添加 private 修饰符,遵循组件间数据传递规范。 +* 状态管理逻辑:父组件使用 @State 修饰核心状态变量,确保状态变更可驱动 UI 刷新,子组件通过常规参数接收状态,实现父子组件状态同步。 +* 页面布局设计:父组件采用 Column 布局承载子组件,设置合适的宽高占比确保页面适配,子组件聚焦核心内容渲染,布局简洁清晰。 +* 功能验证要点:组件间数据传递无阻塞,页面正常渲染 Hello 文本及 Parentbuilder 相关内容,无任何权限相关告警日志输出。 +错误案例功能封装在 LlinkWithPrivateErrorCase,源码参考:[LlinkWithPrivateErrorCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateErrorCase.ets) +* 组件关联配置:父子组件数据传递逻辑与正确案例一致,但子组件的关联属性添加 private 修饰符,触发权限限制校验。 +* 状态管理逻辑:父组件状态定义与传递方式不变,子组件虽添加 private 修饰符,但仍可正常接收父组件状态,确保基础功能可用。 +* 页面布局设计:保持与正确案例一致的布局结构,Column 布局承载子组件,页面适配效果无差异,核心内容渲染位置统一。 +* 功能验证要点:页面正常渲染 Hello 文本及 Parentbuilder 相关内容,系统输出 private 修饰符使用不当的告警日志,权限限制机制生效。 +2.privateWithLink 权限限制 +正确案例功能封装在 PrivateWithLinkCorrectCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkCorrectCase.ets) +* 装饰器组合配置:子组件使用 @Link 修饰字符串类型状态、@ObjectLink 修饰自定义对象类型状态,未添加 private 修饰符。 +* 自定义类设计:定义 @Observed 装饰的 PWLComponentObj 类,封装 count 状态变量,支持 @ObjectLink 装饰器的双向绑定功能。 +* 页面渲染逻辑:父组件通过 @State 定义 link_value 字符串和 objectLink_value 对象,传递给子组件后,子组件渲染 Hello 文本,状态同步正常。 +* 功能验证要点:@Link 和 @ObjectLink 装饰器正常实现数据双向绑定,修改父 / 子组件状态可同步刷新,无权限相关告警。 +错误案例功能封装在 PrivateWithLinkEerrorCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkEerrorCase.ets) +* 装饰器组合配置:子组件的 @Link 和 @ObjectLink 修饰属性均添加 private 修饰符,与装饰器功能产生冲突,触发系统告警。 +* 自定义类设计:沿用正确案例的 @Observed 装饰 PWLComponentObj 类,对象结构与状态变量定义不变,确保案例对比的一致性。 +* 页面渲染逻辑:父组件状态传递逻辑不变,子组件接收状态后正常渲染 Hello 文本,基础功能不受修饰符影响。 +* 功能验证要点:页面渲染正常,系统输出 @Link/@ObjectLink 与 private 修饰符冲突的告警日志,验证权限限制的准确性。 +3.privateWithRequire 权限限制 +正确案例功能封装在 PrivateWithRequireCorrectCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireCorrectCase.ets) +* 装饰器组合配置:子组件使用 @Require+@Prop 组合装饰器声明属性,@Require 确保属性必传,@Prop 支持状态单向同步,未添加 private 修饰符。 +* 属性传递规范:父组件通过组件参数显式传递 prop_value 字符串,符合 @Require 装饰器的必传要求,无参数缺失问题。 +* 页面布局设计:父子组件均采用 Column 布局,父组件承载子组件并占满屏幕宽度,子组件居中渲染 Hello 文本,视觉效果统一。 +* 功能验证要点:@Require+@Prop 组合装饰器正常工作,属性传递完整、状态同步无误,无权限告警日志输出。 +错误案例功能封装在 PrivateWithRequireErrorCase,源码参考:源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireErrorCase.ets) +* 装饰器组合配置:子组件的 @Require+@Prop 组合装饰器属性添加 private 修饰符,破坏装饰器原有功能逻辑,触发系统告警。 +* 属性传递规范:父组件保持必传参数的传递逻辑,参数类型与格式和正确案例一致,确保测试场景的单一变量性。 +* 页面布局设计:布局结构与正确案例完全一致,父子组件宽高配置、文本样式无差异,避免布局影响功能验证。 +* 功能验证要点:页面正常渲染 Hello 文本,系统输出 @Require+@Prop 与 private 修饰符冲突的告警日志,权限限制机制有效。 +4.protectedInStruct 权限限制 +正确案例功能封装在 ProtectedInStructCorrectCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructCorrectCase.ets) +* 组件属性配置:子组件的 regular_value 属性为默认公有属性,未添加 protected 修饰符,支持父组件直接传递参数。 +* 页面渲染逻辑:父组件通过组件参数向子组件传递 regular_value 字符串,子组件接收后渲染 Hello 文本,参数传递无阻碍。 +* 访问权限设计:默认公有属性允许跨组件访问,符合组件间数据交互的常规场景,无权限访问限制。 +* 功能验证要点:页面正常渲染核心文本,属性传递顺畅,无任何权限相关告警,功能符合预期。 +错误案例功能封装在 ProtectedInStructErrorCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructErrorCase.ets) +* 组件属性配置:子组件的 regular_value 属性添加 protected 修饰符,限制跨组件访问权限,触发系统告警。 +* 页面渲染逻辑:父组件参数传递逻辑不变,子组件虽添加 protected 修饰符,但仍可接收参数并渲染 Hello 文本,基础功能正常。 +* 访问权限设计:protected 修饰符本应限制外部访问,此处用于验证组件属性的权限限制机制,场景设计贴合测试需求。 +* 功能验证要点:页面渲染正常,系统输出组件属性使用 protected 修饰符的告警日志,权限限制校验生效。 +5.publicWithStorageProp 权限限制 +正确案例功能封装在 PublicWithStoragePropCorrectCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropCorrectCase.ets) +* 存储装饰器配置:子组件使用 @LocalStorageProp、@LocalStorageLink、@StorageProp、@StorageLink 四种存储装饰器,未添加 public 修饰符(默认公有)。 +* 状态传递设计:父组件通过 @Provide 装饰器提供 consume_value 状态,子组件通过 @Consume 装饰器接收,实现跨组件状态共享。 +* 存储数据关联:装饰器分别关联本地存储和全局存储的键值对,支持数据持久化与多组件共享,状态变更可同步刷新 UI。 +* 功能验证要点:存储装饰器正常工作,数据持久化与状态同步无误,@Provide/@Consume 跨组件通信正常,无权限告警。 +错误案例功能封装在 PublicWithStoragePropErrorCase,源码参考:[LlinkWithPrivateCorrectCase.ets](https://gitcode.com/openharmony/applications_app_samples/blob/master/code/DocsSample/ArkUISample/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropErrorCase.ets) +* 存储装饰器配置:子组件的四种存储装饰器属性及 @Consume 属性均添加 public 修饰符,与装饰器默认公有特性冲突,触发告警。 +* 状态传递设计:保持与正确案例一致的 @Provide/@Consume 跨组件通信逻辑,确保状态传递机制不受修饰符影响。 +* 存储数据关联:存储键值对关联逻辑不变,装饰器仍可正常访问本地 / 全局存储,数据持久化功能正常。 +* 功能验证要点:页面正常渲染 Hello 文本,存储功能与跨组件通信正常,系统输出装饰器与 public 修饰符冲突的告警日志,权限限制有效。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API20版本SDK,版本号:6.0.0.33,镜像版本号:OpenHarmony_6.0.0.33。 + +3.本示例需要使用DevEco Studio 6.0.0 Canary1 (Build Version: 6.0.0.270, built on May 9, 2025)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/Restrictions > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/Restrictions/build-profile.json5 b/ArkUIKit/Restrictions/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3ca5a93fb814017ac4c398aacbdf17b1d8b0a237 --- /dev/null +++ b/ArkUIKit/Restrictions/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/code-linter.json5 b/ArkUIKit/Restrictions/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/ArkUIKit/Restrictions/code-linter.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. + */ +{ + "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/ArkUIKit/Restrictions/entry/.gitignore b/ArkUIKit/Restrictions/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/build-profile.json5 b/ArkUIKit/Restrictions/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/ArkUIKit/Restrictions/entry/build-profile.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. + */ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/hvigorfile.ts b/ArkUIKit/Restrictions/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/hvigorfile.ts @@ -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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/obfuscation-rules.txt b/ArkUIKit/Restrictions/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/Restrictions/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/oh-package.json5 b/ArkUIKit/Restrictions/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/ArkUIKit/Restrictions/entry/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": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/common/resource.ets b/ArkUIKit/Restrictions/entry/src/main/ets/common/resource.ets new file mode 100644 index 0000000000000000000000000000000000000000..723a394265ee2e6bf6d895e9503c4b2d8e49207a --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/common/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/ArkUIKit/Restrictions/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/Restrictions/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/Restrictions/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +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 { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/Index.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7508e17070bf1ef0eaa52c391a4bccba885ec4c4 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { + + build() { + Column({ space: 20 }) { + + // --------------- 1. linkWithPrivate 目录页面跳转 --------------- + // $r('app.string.linkWithPrivate_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.linkWithPrivate_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/linkWithPrivate/LlinkWithPrivateCorrectCase'}) + }) + + // $r('app.string.linkWithPrivateerr_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.linkWithPrivateerr_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/linkWithPrivate/LlinkWithPrivateErrorCase'}) + }) + + // --------------- 2. privateWithLink 目录页面跳转 --------------- + // $r('app.string.privateWithLink_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.privateWithLink_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/privateWithLink/PrivateWithLinkCorrectCase'}) + }) + + // $r('app.string.privateWithLinkerr_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.privateWithLinkerr_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/privateWithLink/PrivateWithLinkEerrorCase'}) + }) + + // --------------- 3. privateWithRequire 目录页面跳转 --------------- + // $r('app.string.privateWithRequire_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.privateWithRequire_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/privateWithRequire/PrivateWithRequireCorrectCase'}) + }) + + // $r('app.string.privateWithRequireerr_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.privateWithRequireerr_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/privateWithRequire/PrivateWithRequireErrorCase'}) + }) + + // --------------- 4. protectedInStruct 目录页面跳转 --------------- + // $r('app.string.protectedInStruct_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.protectedInStruct_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/protectedInStruct/ProtectedInStructCorrectCase'}) + }) + + // $r('app.string.protectedInStructerr_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.protectedInStructerr_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/protectedInStruct/ProtectedInStructErrorCase'}) + }) + + // --------------- 5. publicWithStorageProp 目录页面跳转 --------------- + // $r('app.string.publicWithStorageProp_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.publicWithStorageProp_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/publicWithStorageProp/PublicWithStoragePropCorrectCase'}) + }) + + // $r('app.string.publicWithStorageProperr_lable')需要替换为开发者所需的资源文件 + Text($r('app.string.publicWithStorageProperr_lable')) + .fontSize(16) + .fontColor('#1890FF') + .onClick(() => { + this.getUIContext().getRouter().pushUrl({ url: 'pages/publicWithStorageProp/PublicWithStoragePropErrorCase'}) + }) + + } + .height('100%') + .width('100%') + .padding(20) + .justifyContent(FlexAlign.Start) + } +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/common/Index.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/common/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..02c5c6b987280c6731d3e40af7c56c416176a3af --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/common/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. + */ + +export interface Route { + name: string; + label: ResourceStr; +} + +export interface RouteGroup extends Route { + children: Route[]; +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateCorrectCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateCorrectCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..37c25bc59f1f175e3ff3431b8d08f5e478aa666f --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateCorrectCase.ets @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start LlinkWithPrivate_CorrectCase] +@Entry +@Component +struct LWPCCAccessRestrictions { + @Builder + buildTest() { + // $r('app.string.Parentbuilder')需要替换为开发者所需的资源文件 + Text($r('app.string.Parentbuilder')); + } + + build() { + Column() { + LWPCCComponentChild({ + stateValue: 'Hello', + propValue: 'Hello', + provideValue: 'Hello', + builderValue: this.buildTest, + regularValue: 'Hello' + }); + } + .width('100%'); + } +} + +@Component +struct LWPCCComponentChild { + @State stateValue: string = 'Hello'; + @Prop propValue: string = 'Hello'; + @Provide provideValue: string = 'Hello'; + @BuilderParam builderValue: () => void = this.buildTest; + regularValue: string = 'Hello'; + + @Builder + buildTest() { + // $r('app.string.Childbuilder')需要替换为开发者所需的资源文件 + Text($r('app.string.Childbuilder')); + } + + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End LlinkWithPrivate_CorrectCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateErrorCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateErrorCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c4bb08b9ab8ed88d32cbc792756221df5179c23 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/linkWithPrivate/LlinkWithPrivateErrorCase.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start LlinkWithPrivate_ErrorCase] +@Entry +@Component +struct LWPErrorAccessRestrictions { + @Builder + buildTest() { + // $r('app.string.Parentbuilder')需要替换为开发者所需的资源文件 + Text($r('app.string.Parentbuilder')); + } + + build() { + Column() { + LWPErrorComponentChild({ + stateValue: 'Hello', + propValue: 'Hello', + provideValue: 'Hello', + builderValue: this.buildTest, + regularValue: 'Hello' + }); + } + .width('100%'); + } +} + +@Component +struct LWPErrorComponentChild { + // 此处使用private修饰符时会出现告警日志 + @State private stateValue: string = 'Hello'; + // 此处使用private修饰符时会出现告警日志 + @Prop private propValue: string = 'Hello'; + // 此处使用private修饰符时会出现告警日志 + @Provide private provideValue: string = 'Hello'; + // 此处使用private修饰符时会出现告警日志 + @BuilderParam private builderValue: () => void = this.buildTest; + // 此处使用private修饰符时会出现告警日志 + private regularValue: string = 'Hello'; + + @Builder + buildTest() { + // $r('app.string.Childbuilder')需要替换为开发者所需的资源文件 + Text($r('app.string.Childbuilder')); + } + + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End LlinkWithPrivate_ErrorCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkCorrectCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkCorrectCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6b7e9c67ff637d189cd65eee9f43096472229b6 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkCorrectCase.ets @@ -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. + */ + +// [Start PrivateWithLink_CorrectCase] +@Entry +@Component +struct PWLCAccessRestrictions { + @State linkValue: string = 'Hello'; + @State objectLinkValue: PWLComponentObj = new PWLComponentObj(); + build() { + Column() { + PWLComponentChild({linkValue: this.linkValue, objectLinkValue: this.objectLinkValue}); + } + .width('100%'); + } +} + +@Observed +class PWLComponentObj { + public count: number = 0; +} +@Component +struct PWLComponentChild { + @Link linkValue: string; + @ObjectLink objectLinkValue: PWLComponentObj; + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End PrivateWithLink_CorrectCase] \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkEerrorCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkEerrorCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..bdeec8767386b904921ccabf1f535d6ffb125666 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithLink/PrivateWithLinkEerrorCase.ets @@ -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. + */ + +// [Start PrivateWithLinkEerrorCase] +@Entry +@Component +struct PWLErrorAccessRestrictions{ + @State linkValue: string = 'Hello'; + @State objectLinkValue: PWLErrorComponentObj = new PWLErrorComponentObj(); + build() { + Column() { + PWLErrorComponentChild({linkValue: this.linkValue, objectLinkValue: this.objectLinkValue}); + } + .width('100%'); + } +} + +@Observed +class PWLErrorComponentObj { + public count: number = 0; +} +@Component +struct PWLErrorComponentChild { + // 此处使用private修饰符时会出现告警日志 + @Link private linkValue: string; + // 此处使用private修饰符时会出现告警日志 + @ObjectLink private objectLinkValue: PWLErrorComponentObj; + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End PrivateWithLinkEerrorCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireCorrectCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireCorrectCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..639b835142122006ae641fac531fbd0a9f0b6bad --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireCorrectCase.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start PrivateWithRequire_CorrectCase] +@Entry +@Component +struct PWRCorrectAccessRestrictions { + build() { + Column() { + PWRCorrectComponentChild({propValue: 'Hello'}); + } + .width('100%'); + } +} +@Component +struct PWRCorrectComponentChild { + @Require @Prop propValue: string = 'Hello'; + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End PrivateWithRequire_CorrectCase] + diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireErrorCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireErrorCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee0ef59519d54af7fac7d7e50b4d9d71761621e6 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/privateWithRequire/PrivateWithRequireErrorCase.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start PrivateWithRequire_ErrorCase] +@Entry +@Component +struct PWRErrorAccessRestrictions { + build() { + Column() { + PWRErrorComponentChild({propValue: 'Hello'}); + } + .width('100%'); + } +} +@Component +struct PWRErrorComponentChild { + // 此处使用private修饰符时会出现告警日志 + @Require @Prop private propValue: string = 'Hello'; + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End PrivateWithRequire_ErrorCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructCorrectCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructCorrectCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..fc2dcaebaa27e74d644e15b0e7b1914edf4651ae --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructCorrectCase.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ProtectedInStruct_CorrectCase] +@Entry +@Component +struct PISCorrectAccessRestrictions { + build() { + Column() { + PISCorrectComponentChild({regularValue: 'Hello'}); + } + .width('100%'); + } +} + +@Component +struct PISCorrectComponentChild { + regularValue: string = 'Hello'; + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End ProtectedInStruct_CorrectCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructErrorCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructErrorCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..d385ae0dc7a63d5fc69d60c07049fc898018356d --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/protectedInStruct/ProtectedInStructErrorCase.ets @@ -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. + */ + +// [Start ProtectedInStruct_ErrorCase] +@Entry +@Component +struct PISErrorAccessRestrictions { + build() { + Column() { + PISErrorComponentChild({regularValue: 'Hello'}); + } + .width('100%'); + } +} + +@Component +struct PISErrorComponentChild { + // 此处使用protected修饰符时会出现告警日志 + protected regularValue: string = 'Hello'; + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End ProtectedInStruct_ErrorCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropCorrectCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropCorrectCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..be95a55f557855d24c68888ea0c07a2c547660e8 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropCorrectCase.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 PublicWithStorageProp_CorrectCase] +@Entry +@Component +struct PWPCorrectAccessRestrictions { + @Provide consumeValue: string = 'Hello'; + build() { + Column() { + PWPCorrectComponentChild(); + } + .width('100%'); + } +} + +@Component +struct PWPCorrectComponentChild { + @LocalStorageProp('sessionLocalProp') localPropValue: string = 'Hello'; + @LocalStorageLink('sessionLocalLink') localLinkValue: string = 'Hello'; + @StorageProp('sessionProp') storagePropValue: string = 'Hello'; + @StorageLink('sessionLink') storageLinkValue: string = 'Hello'; + @Consume consumeValue: string; + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End PublicWithStorageProp_CorrectCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropErrorCase.ets b/ArkUIKit/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropErrorCase.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a4c67e0fe9120d3251a5252846f2cd94a96416f --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/ets/pages/publicWithStorageProp/PublicWithStoragePropErrorCase.ets @@ -0,0 +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. + */ + +// [Start PublicWithStorageProp_ErrorCase] +@Entry +@Component +struct PWPErrorAccessRestrictions { + @Provide consumeValue: string = 'Hello'; + build() { + Column() { + PWPErrorComponentChild(); + } + .width('100%'); + } +} + +@Component +struct PWPErrorComponentChild { + // 此处使用public修饰符时会出现告警日志 + @LocalStorageProp('sessionLocalProp') public localPropValue: string = 'Hello'; + // 此处使用public修饰符时会出现告警日志 + @LocalStorageLink('sessionLocalLink') public localLinkValue: string = 'Hello'; + // 此处使用public修饰符时会出现告警日志 + @StorageProp('sessionProp') public storagePropValue: string = 'Hello'; + // 此处使用public修饰符时会出现告警日志 + @StorageLink('sessionLink') public storageLinkValue: string = 'Hello'; + // 此处使用public修饰符时会出现告警日志 + @Consume public consumeValue: string; + + build() { + Column() { + // $r('app.string.Hello')需要替换为开发者所需的资源文件 + Text($r('app.string.Hello')) + .fontSize(50) + .fontWeight(FontWeight.Bold); + }; + } +} +// [End PublicWithStorageProp_ErrorCase] diff --git a/ArkUIKit/Restrictions/entry/src/main/module.json5 b/ArkUIKit/Restrictions/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..476f4f508edb44dc9edfe115808545c33b284e0b --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/module.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. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/base/element/color.json b/ArkUIKit/Restrictions/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/Restrictions/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/ArkUIKit/Restrictions/entry/src/main/resources/base/element/float.json b/ArkUIKit/Restrictions/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/base/element/string.json b/ArkUIKit/Restrictions/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..55235fa87fea8f4a97c82dba89fbd5208d8b8e0a --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/resources/base/element/string.json @@ -0,0 +1,68 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "Hello", + "value": "Hello" + }, + { + "name": "Parentbuilder", + "value": "Parent builder" + }, + { + "name": "linkWithPrivate_lable", + "value": "跳转到 linkWithPrivate 正确案例" + }, + { + "name": "linkWithPrivateerr_lable", + "value": "跳转到 linkWithPrivate 错误案例" + }, + { + "name": "privateWithLink_lable", + "value": "跳转到 privateWithLink 正确案例" + }, + { + "name": "privateWithLinkerr_lable", + "value": "跳转到 privateWithLink 错误案例" + }, + { + "name": "privateWithRequire_lable", + "value": "跳转到 privateWithRequire 正确案例" + }, + { + "name": "privateWithRequireerr_lable", + "value": "跳转到 privateWithRequire 错误案例" + }, + { + "name": "protectedInStruct_lable", + "value": "跳转到 protectedInStruct 正确案例" + }, + { + "name": "protectedInStructerr_lable", + "value": "跳转到 protectedInStruct 错误案例" + }, + { + "name": "publicWithStorageProp_lable", + "value": "跳转到 publicWithStorageProp 正确案例" + }, + { + "name": "publicWithStorageProperr_lable", + "value": "跳转到 publicWithStorageProp 错误案例" + }, + { + "name": "Childbuilder", + "value": "Child builder" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/base/media/background.png b/ArkUIKit/Restrictions/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/Restrictions/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/Restrictions/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/Restrictions/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/Restrictions/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/Restrictions/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/ArkUIKit/Restrictions/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/Restrictions/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/Restrictions/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/Restrictions/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/Restrictions/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..6c9aa2d1b6ccfc51f30d3907cffbe47ab4a36dee --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,15 @@ +{ + "src": [ + "pages/Index", + "pages/linkWithPrivate/LlinkWithPrivateCorrectCase", + "pages/linkWithPrivate/LlinkWithPrivateErrorCase", + "pages/privateWithLink/PrivateWithLinkCorrectCase", + "pages/privateWithLink/PrivateWithLinkEerrorCase", + "pages/privateWithRequire/PrivateWithRequireCorrectCase", + "pages/privateWithRequire/PrivateWithRequireErrorCase", + "pages/protectedInStruct/ProtectedInStructCorrectCase", + "pages/protectedInStruct/ProtectedInStructErrorCase", + "pages/publicWithStorageProp/PublicWithStoragePropCorrectCase", + "pages/publicWithStorageProp/PublicWithStoragePropErrorCase" + ] +} diff --git a/ArkUIKit/Restrictions/entry/src/main/resources/dark/element/color.json b/ArkUIKit/Restrictions/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/Restrictions/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/ArkUIKit/Restrictions/entry/src/mock/mock-config.json5 b/ArkUIKit/Restrictions/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/mock/mock-config.json5 @@ -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. + */ +{ +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..23094c61a923c2be76f84d7990a3f52165debc43 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/Ability.test.ets @@ -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. + */ + +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. + }); + /* + * @tc.number: Animation_assertContain + * @tc.name: Test ability + * @tc.desc: Test ability + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + 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/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/LinkWithPrivate.test.ets b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/LinkWithPrivate.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa21e360c67368810c0a1d5c4f4294472955a7a4 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/LinkWithPrivate.test.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 { abilityDelegatorRegistry, Component, Driver } from '@kit.TestKit'; +import { afterEach, beforeAll, describe, expect, it } from '@ohos/hypium'; +import { ON } from '@ohos.UiTest'; +import resource from '../../../main/ets/common/resource'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + +const driver = Driver.create(); +const BUNDLE = 'Restrictions_'; +const TAG = '[Sample_Restrictions]'; +const DOMAIN = 0xF811; + +let aimComponent: Component; + +export function LinkWithPrivateTest() { + describe('LinkWithPrivateTest', () => { + + beforeAll(async () => { + // 启动主Ability,进入首页 + await delegator.startAbility({ + bundleName: 'com.samples.restrictions', + abilityName: 'EntryAbility' + }); + await driver.delayMs(3000); // 延长延迟,确保首页完全加载 + }); + + afterEach(async () => { + // 每次测试后返回首页(通过多次按返回键,避免页面层级残留) + let homeEntry: Component | null = null; + do { + await driver.pressBack(); + await driver.delayMs(500); + // 验证是否回到首页:检查linkWithPrivate正确案例入口是否存在 + homeEntry = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.linkWithPrivate_lable'))) + ).catch(() => null); + } while (homeEntry == null); + }); + + /* + * @tc.number: LinkWithPrivateTest_001 + * @tc.name: Test correct case of link with private + * @tc.desc: Test correct case of link with private + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'LinkWithPrivateTest_001', 0, async () => { + hilog.info(DOMAIN, TAG, 'LinkWithPrivateTest_001_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.linkWithPrivate_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Correct case entry (linkWithPrivate_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + const parentBuilderText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Parentbuilder'))) + ); + + hilog.info(DOMAIN, TAG, 'LinkWithPrivateTest_001_end'); + }); + + /* + * @tc.number: LinkWithPrivateTest_002 + * @tc.name: Test error case of link with private + * @tc.desc: Test error case of link with private + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'LinkWithPrivateTest_002', 0, async () => { + hilog.info(DOMAIN, TAG, 'LinkWithPrivateTest_002_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.linkWithPrivateerr_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Error case entry (linkWithPrivaterr_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + const parentBuilderText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Parentbuilder'))) + ); + + hilog.info(DOMAIN, TAG, 'LinkWithPrivateTest_002_end'); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fc351dfba9708d1d3bf5bd8cfda26a7b5692663 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +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 { LinkWithPrivateTest } from './LinkWithPrivate.test'; +import { PrivateWithLinkTest } from './PrivateWithLink.test'; +import { PrivateWithRequireTest } from './PrivateWithRequire.test'; +import { ProtectedInStructTest } from './ProtectedInStruct.test'; +import { PublicWithStoragePropTest } from './PublicWithStorgeProp.test'; + + +export default function testsuite() { + LinkWithPrivateTest(); + PrivateWithLinkTest(); + PrivateWithRequireTest(); + ProtectedInStructTest(); + PublicWithStoragePropTest(); + +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PrivateWithLink.test.ets b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PrivateWithLink.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c1f423ce0070c1bd443e09ecba702a146b068857 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PrivateWithLink.test.ets @@ -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. + */ +import { abilityDelegatorRegistry, Component, Driver } from '@kit.TestKit'; +import { afterEach, beforeAll, describe, expect, it } from '@ohos/hypium'; +import { ON } from '@ohos.UiTest'; +import resource from '../../../main/ets/common/resource'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + +const driver = Driver.create(); +const BUNDLE = 'Restrictions_'; +const TAG = '[Sample_Restrictions]'; +const DOMAIN = 0xF811; + +let aimComponent: Component; + +export function PrivateWithLinkTest() { + describe('PrivateWithLinkTest', () => { + + beforeAll(async () => { + // 启动主Ability,进入首页 + await delegator.startAbility({ + bundleName: 'com.samples.restrictions', + abilityName: 'EntryAbility' + }); + await driver.delayMs(3000); // 延长延迟,确保首页完全加载 + }); + + afterEach(async () => { + // 每次测试后返回首页(通过多次按返回键,避免页面层级残留) + let homeEntry: Component | null = null; + do { + await driver.pressBack(); + await driver.delayMs(500); + // 验证是否回到首页:检查linkWithPrivate正确案例入口是否存在 + homeEntry = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.linkWithPrivate_lable'))) + ).catch(() => null); + } while (homeEntry == null); + }); + + /* + * @tc.number: PrivateWithLinkTest_001 + * @tc.name: Test correct case of private with link + * @tc.desc: Test correct case of private with link + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'PrivateWithLinkTest_001', 0, async () => { + hilog.info(DOMAIN, TAG, 'PrivateWithLinkTest_001_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.privateWithLink_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Correct case entry (privateWithLink_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与页面PWLComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'PrivateWithLinkTest_001_end'); + }); + + /* + * @tc.number: PrivateWithLinkTest_002 + * @tc.name: Test error case of private with link + * @tc.desc: Test error case of private with link + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'PrivateWithLinkTest_002', 0, async () => { + hilog.info(DOMAIN, TAG, 'PrivateWithLinkTest_002_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.privateWithLinkerr_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Error case entry (privateWithLinkerr_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与页面PWLErrorComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'PrivateWithLinkTest_002_end'); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PrivateWithRequire.test.ets b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PrivateWithRequire.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..07883752f3d539dd8c02c7109adbe02d6b5ddd32 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PrivateWithRequire.test.ets @@ -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. + */ +import { abilityDelegatorRegistry, Component, Driver } from '@kit.TestKit'; +import { afterEach, beforeAll, describe, expect, it } from '@ohos/hypium'; +import { ON } from '@ohos.UiTest'; +import resource from '../../../main/ets/common/resource'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + +const driver = Driver.create(); +const BUNDLE = 'Restrictions_'; +const TAG = '[Sample_Restrictions]'; +const DOMAIN = 0xF811; + +let aimComponent: Component; + +export function PrivateWithRequireTest() { + describe('PrivateWithRequireTest', () => { + + beforeAll(async () => { + // 启动主Ability,进入首页 + await delegator.startAbility({ + bundleName: 'com.samples.restrictions', + abilityName: 'EntryAbility' + }); + await driver.delayMs(3000); // 延长延迟,确保首页完全加载 + }); + + afterEach(async () => { + // 每次测试后返回首页(通过多次按返回键,避免页面层级残留) + let homeEntry: Component | null = null; + do { + await driver.pressBack(); + await driver.delayMs(500); + // 验证是否回到首页:检查linkWithPrivate正确案例入口是否存在 + homeEntry = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.linkWithPrivate_lable'))) + ).catch(() => null); + } while (homeEntry == null); + }); + + /* + * @tc.number: PrivateWithRequireTest_001 + * @tc.name: Test correct case of private with require + * @tc.desc: Test correct case of private with require + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'PrivateWithRequireTest_001', 0, async () => { + hilog.info(DOMAIN, TAG, 'PrivateWithRequireTest_001_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.privateWithRequire_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Correct case entry (privateWithRequire_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与PWRCorrectComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'PrivateWithRequireTest_001_end'); + }); + + /* + * @tc.number: PrivateWithRequireTest_002 + * @tc.name: Test error case of private with require + * @tc.desc: Test error case of private with require + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'PrivateWithRequireTest_002', 0, async () => { + hilog.info(DOMAIN, TAG, 'PrivateWithRequireTest_002_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.privateWithRequireerr_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Error case entry (privateWithRequireerr_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与PWRErrorComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'PrivateWithRequireTest_002_end'); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/ProtectedInStruct.test.ets b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/ProtectedInStruct.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..20441d8592d25bf13de92d2cd492912ee1e533ae --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/ProtectedInStruct.test.ets @@ -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. + */ +import { abilityDelegatorRegistry, Component, Driver } from '@kit.TestKit'; +import { afterEach, beforeAll, describe, expect, it } from '@ohos/hypium'; +import { ON } from '@ohos.UiTest'; +import resource from '../../../main/ets/common/resource'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + +const driver = Driver.create(); +const BUNDLE = 'Restrictions_'; +const TAG = '[Sample_Restrictions]'; +const DOMAIN = 0xF811; + +let aimComponent: Component; + +export function ProtectedInStructTest() { + describe('ProtectedInStructTest', () => { + + beforeAll(async () => { + // 启动主Ability,进入首页 + await delegator.startAbility({ + bundleName: 'com.samples.restrictions', + abilityName: 'EntryAbility' + }); + await driver.delayMs(3000); // 延长延迟,确保首页完全加载 + }); + + afterEach(async () => { + // 每次测试后返回首页(通过多次按返回键,避免页面层级残留) + let homeEntry: Component | null = null; + do { + await driver.pressBack(); + await driver.delayMs(500); + // 验证是否回到首页:检查linkWithPrivate正确案例入口是否存在 + homeEntry = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.linkWithPrivate_lable'))) + ).catch(() => null); + } while (homeEntry == null); + }); + + /* + * @tc.number: ProtectedInStructTest_001 + * @tc.name: Test correct case of protected in struct + * @tc.desc: Test correct case of protected in struct + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ProtectedInStructTest_001', 0, async () => { + hilog.info(DOMAIN, TAG, 'ProtectedInStructTest_001_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.protectedInStruct_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Correct case entry (protectedInStruct_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与PISCorrectComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'ProtectedInStructTest_001_end'); + }); + + /* + * @tc.number: ProtectedInStructTest_002 + * @tc.name: Test error case of protected in struct + * @tc.desc: Test error case of protected in struct + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ProtectedInStructTest_002', 0, async () => { + hilog.info(DOMAIN, TAG, 'ProtectedInStructTest_002_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.protectedInStructerr_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Error case entry (protectedInStructerr_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与PISErrorComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'ProtectedInStructTest_002_end'); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PublicWithStorgeProp.test.ets b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PublicWithStorgeProp.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4bb2407c3c00f9829b168cb8d0ff6b6d3a53113c --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/ets/test/PublicWithStorgeProp.test.ets @@ -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. + */ +import { abilityDelegatorRegistry, Component, Driver } from '@kit.TestKit'; +import { afterEach, beforeAll, describe, expect, it } from '@ohos/hypium'; +import { ON } from '@ohos.UiTest'; +import resource from '../../../main/ets/common/resource'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + +const driver = Driver.create(); +const BUNDLE = 'Restrictions_'; +const TAG = '[Sample_Restrictions]'; +const DOMAIN = 0xF811; + +let aimComponent: Component; + +export function PublicWithStoragePropTest() { + describe('PublicWithStoragePropTest', () => { + + beforeAll(async () => { + // 启动主Ability,进入首页 + await delegator.startAbility({ + bundleName: 'com.samples.restrictions', + abilityName: 'EntryAbility' + }); + await driver.delayMs(3000); // 延长延迟,确保首页完全加载 + }); + + afterEach(async () => { + // 每次测试后返回首页(通过多次按返回键,避免页面层级残留) + let homeEntry: Component | null = null; + do { + await driver.pressBack(); + await driver.delayMs(500); + // 验证是否回到首页:检查linkWithPrivate正确案例入口是否存在 + homeEntry = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.linkWithPrivate_lable'))) + ).catch(() => null); + } while (homeEntry == null); + }); + + /* + * @tc.number: PublicWithStoragePropTest_001 + * @tc.name: Test correct case of public with storage prop + * @tc.desc: Test correct case of public with storage prop + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'PublicWithStoragePropTest_001', 0, async () => { + hilog.info(DOMAIN, TAG, 'PublicWithStoragePropTest_001_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.publicWithStorageProp_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Correct case entry (publicWithStorageProp_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与PWPCorrectComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'PublicWithStoragePropTest_001_end'); + }); + + /* + * @tc.number: PublicWithStoragePropTest_002 + * @tc.name: Test error case of public with storage prop + * @tc.desc: Test error case of public with storage prop + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'PublicWithStoragePropTest_002', 0, async () => { + hilog.info(DOMAIN, TAG, 'PublicWithStoragePropTest_002_begin'); + + aimComponent = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.publicWithStorageProperr_lable'))) + ); + if (!aimComponent) { + hilog.error(DOMAIN, TAG, 'Error case entry (publicWithStorageProperr_lable) not found'); + expect(false).assertTrue(); + return; + } + await aimComponent.click(); + await driver.delayMs(2000); // 延长延迟,确保目标页面渲染完成 + + // 验证页面核心元素:Hello文本(与PWPErrorComponentChild中的Text组件匹配) + const helloText = await driver.findComponent( + ON.text(await resource.resourceToString($r('app.string.Hello'))) + ); + + hilog.info(DOMAIN, TAG, 'PublicWithStoragePropTest_002_end'); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/ohosTest/module.json5 b/ArkUIKit/Restrictions/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..59667117c86b64ab9863f7b382c435ae4a3c32fa --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/ohosTest/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": "entry_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/Restrictions/entry/src/test/List.test.ets b/ArkUIKit/Restrictions/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/test/List.test.ets @@ -0,0 +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. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/entry/src/test/LocalUnit.test.ets b/ArkUIKit/Restrictions/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/ArkUIKit/Restrictions/entry/src/test/LocalUnit.test.ets @@ -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. + */ +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/ArkUIKit/Restrictions/hvigor/hvigor-config.json5 b/ArkUIKit/Restrictions/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/ArkUIKit/Restrictions/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": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ArkUIKit/Restrictions/hvigorfile.ts b/ArkUIKit/Restrictions/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/ArkUIKit/Restrictions/hvigorfile.ts @@ -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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/Restrictions/oh-package.json5 b/ArkUIKit/Restrictions/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/ArkUIKit/Restrictions/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. + */ +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/Restrictions/ohosTest.md b/ArkUIKit/Restrictions/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..0a21015e999381ebc02191ee87b307666d572740 --- /dev/null +++ b/ArkUIKit/Restrictions/ohosTest.md @@ -0,0 +1,16 @@ +# Restrictions 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|-------------------------------| -------------- |----------------------| ------------------------------------------------------------ | :------- | -------- | +| linkWithPrivate 正确案例功能验证 | 设备正常运行 | 进入应用首页,点击「linkWithPrivate 正确案例」入口 | 无功能异常 | 是 | Pass | +| linkWithPrivate 错误案例功能验证 | 设备正常运行 | 进入应用首页,点击「linkWithPrivate 错误案例」入口 | 相关告警日志正常输出 | 是 | Pass | +| privateWithLink 正确案例功能验证 | 设备正常运行 | 进入应用首页,点击「privateWithLink 正确案例」入口 | 无功能异常 | 是 | Pass | +| privateWithLink 错误案例功能验证 | 设备正常运行 | 进入应用首页,点击「privateWithLink 错误案例」入口 | 相关告警日志正常输出 | 是 | Pass | +| privateWithRequire 正确案例功能验证 | 设备正常运行 | 进入应用首页,点击「privateWithRequire 正确案例」入口 | 无功能异常 | 是 | Pass | +| privateWithRequire 错误案例功能验证 | 设备正常运行 | 进入应用首页,点击「privateWithRequire 错误案例」入口 | 相关告警日志正常输出 | 是 | Pass | +| protectedInStruct 正确案例功能验证 | 设备正常运行 | 进入应用首页,点击「protectedInStruct 正确案例」入口 | 无功能异常 | 是 | Pass | +| protectedInStruct 错误案例功能验证 | 设备正常运行 | 进入应用首页,点击「protectedInStruct 错误案例」入口 | 相关告警日志正常输出 | 是 | Pass | +| publicWithStorageProp 正确案例功能验证 | 设备正常运行 | 进入应用首页,点击「publicWithStorageProp 正确案例」入口 | 无功能异常 | 是 | Pass | +| publicWithStorageProp 错误案例功能验证 | 设备正常运行 | 进入应用首页,点击「publicWithStorageProp 错误案例」入口 | 相关告警日志正常输出 | 是 | Pass | diff --git a/ArkUIKit/Restrictions/screenshots/device/img.png b/ArkUIKit/Restrictions/screenshots/device/img.png new file mode 100644 index 0000000000000000000000000000000000000000..fb020cc8241b47ae9ce323304f69a4f21196d95c Binary files /dev/null and b/ArkUIKit/Restrictions/screenshots/device/img.png differ