diff --git a/AbilityKit/AbilityStage/.gitignore b/AbilityKit/AbilityStage/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/AbilityStage/.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/AbilityKit/AbilityStage/AppScope/app.json5 b/AbilityKit/AbilityStage/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7aa80e9d3f9843def1a59922fc50c983b536ed47 --- /dev/null +++ b/AbilityKit/AbilityStage/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.abilitystage", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/AbilityStage/AppScope/resources/base/element/string.json b/AbilityKit/AbilityStage/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..30a72a7dcd6a6c9be4ba91ab2792dc3d0c52abdb --- /dev/null +++ b/AbilityKit/AbilityStage/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AbilityStage" + } + ] +} diff --git a/AbilityKit/AbilityStage/AppScope/resources/base/media/background.png b/AbilityKit/AbilityStage/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/AbilityStage/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/AbilityStage/AppScope/resources/base/media/foreground.png b/AbilityKit/AbilityStage/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/AbilityStage/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/AbilityStage/AppScope/resources/base/media/layered_image.json b/AbilityKit/AbilityStage/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/README_zh.md b/AbilityKit/AbilityStage/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..e9846dd7ad17f72957744b18dd6213956de1b222 --- /dev/null +++ b/AbilityKit/AbilityStage/README_zh.md @@ -0,0 +1,139 @@ +# AbilityStage组件管理器 简介 + +### 介绍 + +AbilityStage是应用程序中的一个模块,用于管理和控制应用的生命周期组件。 + +该工程中展示的代码详细描述可查如下链接: + +- [AbilityStage简介](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/application-models/abilitystage.md) + +### 效果预览 +不涉及。 + +### 使用说明 + +1. 拉起应用,触发EnvironmentCallback中的onConfigurationUpdated()回调,并打印相关信息。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── exampleabilitystage + │ │ ├── MyAbilityStage.ets // 自定义类继承AbilityStage并加上需要的生命周期回调 + │ │ ├── myabilitystage + │ │ ├── MyAbilityStage.ets // 监听系统环境变量的变化 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` +### 具体实现 + +1.创建AbilityStage文件 + +entry/src/main/ets/exampleabilitystage/MyAbilityStage.ets + +```ts +import { AbilityStage, Want } from '@kit.AbilityKit'; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + // 应用HAP首次加载时触发,可以在此执行该Module的初始化操作(例如资源预加载、线程创建等)。 + } + + onAcceptWant(want: Want): string { + // 仅specified模式下触发 + return 'MyAbilityStage'; + } +} +``` + +2.在module.json5配置文件中,通过配置 srcEntry 参数来指定模块对应的代码路径,以作为HAP加载的入口。 + +entry/src/main/module.json5 + +```json +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntry": "./ets/myabilitystage/MyAbilityStage.ets" + } +} +``` + +3.监听系统环境变量的变化 + +entry/src/main/ets/pages/Index.ets + +```ts +import { EnvironmentCallback, AbilityStage } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + console.info('AbilityStage onCreate'); + let envCallback: EnvironmentCallback = { + onConfigurationUpdated(config) { + console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`); + let language = config.language; //应用程序的当前语言 + let colorMode = config.colorMode; //深浅色模式 + let direction = config.direction; //屏幕方向 + let fontSizeScale = config.fontSizeScale; //字体大小缩放比例 + let fontWeightScale = config.fontWeightScale; //字体粗细缩放比例 + }, + onMemoryLevel(level) { + console.info(`onMemoryLevel level: ${level}`); + } + }; + try { + let applicationContext = this.context.getApplicationContext(); + let callbackId = applicationContext.on('environment', envCallback); + console.info(`callbackId: ${callbackId}`); + } catch (paramError) { + console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`); + } + } + + onDestroy(): void { + // 通过onDestroy()方法,可以监听到Ability的销毁事件。 + console.info('AbilityStage onDestroy'); + } +} +``` +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/Ability/AbilityStage > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/AbilityStage/build-profile.json5 b/AbilityKit/AbilityStage/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/AbilityStage/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/AbilityKit/AbilityStage/code-linter.json5 b/AbilityKit/AbilityStage/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/.gitignore b/AbilityKit/AbilityStage/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/AbilityStage/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/AbilityStage/entry/build-profile.json5 b/AbilityKit/AbilityStage/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/hvigorfile.ts b/AbilityKit/AbilityStage/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/obfuscation-rules.txt b/AbilityKit/AbilityStage/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/oh-package.json5 b/AbilityKit/AbilityStage/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/AbilityStage/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/AbilityStage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/main/ets/exampleabilitystage/MyAbilityStage.ets b/AbilityKit/AbilityStage/entry/src/main/ets/exampleabilitystage/MyAbilityStage.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9e1465c8459634da311aecad7c597fe3dc365ba --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/main/ets/exampleabilitystage/MyAbilityStage.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start my_examole_ability_start] +import { AbilityStage, Want } from '@kit.AbilityKit'; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + // 应用HAP首次加载时触发,可以在此执行该Module的初始化操作(例如资源预加载、线程创建等)。 + } + + onAcceptWant(want: Want): string { + // 仅specified模式下触发 + return 'MyAbilityStage'; + } +} +// [End my_examole_ability_start] \ No newline at end of file diff --git a/AbilityKit/AbilityStage/entry/src/main/ets/myabilitystage/MyAbilityStage.ets b/AbilityKit/AbilityStage/entry/src/main/ets/myabilitystage/MyAbilityStage.ets new file mode 100644 index 0000000000000000000000000000000000000000..2af410f20ec60e1642bff565d4bb6a49d6e1cdcd --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/main/ets/myabilitystage/MyAbilityStage.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start myAbility_start] +import { EnvironmentCallback, AbilityStage } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + console.info('AbilityStage onCreate'); + let envCallback: EnvironmentCallback = { + onConfigurationUpdated(config) { + console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`); + let language = config.language; //应用程序的当前语言 + let colorMode = config.colorMode; //深浅色模式 + let direction = config.direction; //屏幕方向 + let fontSizeScale = config.fontSizeScale; //字体大小缩放比例 + let fontWeightScale = config.fontWeightScale; //字体粗细缩放比例 + }, + onMemoryLevel(level) { + console.info(`onMemoryLevel level: ${level}`); + } + }; + try { + let applicationContext = this.context.getApplicationContext(); + let callbackId = applicationContext.on('environment', envCallback); + console.info(`callbackId: ${callbackId}`); + } catch (paramError) { + console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`); + } + } + + onDestroy(): void { + // 通过onDestroy()方法,可以监听到Ability的销毁事件。 + console.info('AbilityStage onDestroy'); + } +} +// [End myAbility_start] \ No newline at end of file diff --git a/AbilityKit/AbilityStage/entry/src/main/ets/pages/Index.ets b/AbilityKit/AbilityStage/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..64ca99781cb5c3e261ecdd74d316c6fa7cec67e4 --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/main/ets/pages/Index.ets @@ -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. + */ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/AbilityKit/AbilityStage/entry/src/main/module.json5 b/AbilityKit/AbilityStage/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c7bc310e7d6d6687c98c9c1e23419f026efdca7 --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/main/module.json5 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start abilityModule_start] +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntry": "./ets/myabilitystage/MyAbilityStage.ets", + // [StartExclude abilityModule_start] + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "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" + } + ], + } + ], + // [EndExclude abilityModule_start] + } +} +// [End abilityModule_start] \ No newline at end of file diff --git a/AbilityKit/AbilityStage/entry/src/main/resources/base/element/color.json b/AbilityKit/AbilityStage/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/main/resources/base/element/float.json b/AbilityKit/AbilityStage/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/AbilityStage/entry/src/main/resources/base/element/string.json b/AbilityKit/AbilityStage/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/main/resources/base/media/background.png b/AbilityKit/AbilityStage/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/AbilityStage/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/AbilityStage/entry/src/main/resources/base/media/foreground.png b/AbilityKit/AbilityStage/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/AbilityStage/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/AbilityStage/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/AbilityStage/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/AbilityStage/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/AbilityStage/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/AbilityStage/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/AbilityStage/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/AbilityKit/AbilityStage/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/AbilityStage/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/AbilityKit/AbilityStage/entry/src/main/resources/dark/element/color.json b/AbilityKit/AbilityStage/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/mock/mock-config.json5 b/AbilityKit/AbilityStage/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/AbilityStage/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..246bf2e2ed3178ea1932d54a2f34328de403be22 --- /dev/null +++ b/AbilityKit/AbilityStage/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const TAG = '[Sample_AbilityStage]' +const BUNDLE = 'AbilityStage_'; +const DOMAIN = 0xF811 + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('AbilityStage__Startup_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'Startup_001 begin'); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + try { + await abilityDelegator.startAbility({ + bundleName: 'com.samples.abilitystage', + abilityName: 'EntryAbility' + }); + done(); + } + catch (expection) { + hilog.info(DOMAIN, TAG, BUNDLE + `Startup_001 end ${JSON.stringify(expection)}`); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/AbilityKit/AbilityStage/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/AbilityStage/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/ohosTest/module.json5 b/AbilityKit/AbilityStage/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..12ddf9861a24545643847583653f531bf1679c6c --- /dev/null +++ b/AbilityKit/AbilityStage/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", + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/AbilityStage/entry/src/test/List.test.ets b/AbilityKit/AbilityStage/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/entry/src/test/LocalUnit.test.ets b/AbilityKit/AbilityStage/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/hvigor/hvigor-config.json5 b/AbilityKit/AbilityStage/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/hvigorfile.ts b/AbilityKit/AbilityStage/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/oh-package.json5 b/AbilityKit/AbilityStage/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/AbilityStage/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/AbilityKit/AbilityStage/ohosTest.md b/AbilityKit/AbilityStage/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..f2743535f9de49a6a190689d31ea224213e09b29 --- /dev/null +++ b/AbilityKit/AbilityStage/ohosTest.md @@ -0,0 +1,7 @@ +# AbilityStage 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------- | ----------------------------- | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | diff --git a/AbilityKit/AppServiceExtensionAbility/.gitignore b/AbilityKit/AppServiceExtensionAbility/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/.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/AbilityKit/AppServiceExtensionAbility/AppScope/app.json5 b/AbilityKit/AppServiceExtensionAbility/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d6b3cee65c277f45283472071fe0387f01212d35 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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.appserviceextensionability", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/element/string.json b/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f178e392a5eafb0ee194608b028b4192b545763d --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AppServiceExtensionAbility" + } + ] +} diff --git a/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/background.png b/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/foreground.png b/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/layered_image.json b/AbilityKit/AppServiceExtensionAbility/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/README_zh.md b/AbilityKit/AppServiceExtensionAbility/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..9aedeeb0ae717d2b88fecd4dcac3c2e0d0738779 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/README_zh.md @@ -0,0 +1,82 @@ +# AppServiceExtensionAbility简介 + +### 介绍 + +AppServiceExtensionAbility 从 API version 20 开始支持的组件,旨在为应用程序提供后台服务。其它应用可以通过启动或连接该组件获取相应服务,界面的长期运行任务(例如数据监控、文件操作监听等)。 + +### 效果预览 + +不涉及。 +### 使用说明 + +1. 应用在启动后展示首页,首页展示相关按钮,点击进入相应功能界面。 +2. 点击对应按钮触发相关回调,并打印相关信息 +3. 示例将被启动或被连接的AppServiceExtensionAbility组件称为服务端,将启动或连接AppServiceExtensionAbility组件的应用组件(当前仅支持UIAbility)称为客户端。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── myappserviceextability + │ │ ├── MyAppServiceExtAbility.ets + │ │ ├── myappserviceextabilityfour + │ │ ├── MyAppServiceExtAbility.ets + │ │ ├── myappserviceextabilitythree + │ │ ├── MyAppServiceExtAbility.ets + │ │ ├── myappserviceextabilitytwo + │ │ ├── MyAppServiceExtAbility.ets + │ │ ├── pages + │ │ ├── ClientServerExt.ets // 客户端与服务端通信 + │ │ ├── ConnectAppServiceExt.ets // 连接一个后台服务 + │ │ ├── DisConnectAppServiceExt.ets // 使用disconnectAppServiceExtensionAbility()断开与后台服务的连接 + │ │ ├── Index.ets // 首页 + │ │ ├── StartAppServiceExt.ets // 启动一个后台服务 + │ │ ├── StopAppServiceExt.ets // 停止一个已启动的AppServiceExtensionAbility组件 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` +### 具体实现 + +1. 在MyAppServiceExtAbility目录,右键选择“New > ArkTS File”,新建一个文件并命名为MyAppServiceExtAbility.ets。 +2. 在应用中启动一个新的AppServiceExtensionAbility组件。 +3. 在应用中停止一个已启动的AppServiceExtensionAbility组件。 +4. 已启动的AppServiceExtensionAbility组件停止自身。 +5. 使用connectAppServiceExtensionAbility()建立与后台服务的连接。 +6. 使用disconnectAppServiceExtensionAbility()断开与后台服务的连接。 +7. 客户端在onConnect()中获取到rpc.IRemoteObject对象后便可与服务端进行通信。 + +### 相关权限 + +应用集成AppServiceExtensionAbility组件需要申请ACL权限(ohos.permission.SUPPORT_APP_SERVICE_EXTENSION)。该ACL权限当前只对企业普通应用开放申请。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例AppServiceExtensionAbility组件当前仅支持2in1设备。 + +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/Ability/AppServiceExtensionAbility > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/AppServiceExtensionAbility/build-profile.json5 b/AbilityKit/AppServiceExtensionAbility/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/AbilityKit/AppServiceExtensionAbility/code-linter.json5 b/AbilityKit/AppServiceExtensionAbility/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/.gitignore b/AbilityKit/AppServiceExtensionAbility/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/build-profile.json5 b/AbilityKit/AppServiceExtensionAbility/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/hvigorfile.ts b/AbilityKit/AppServiceExtensionAbility/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/obfuscation-rules.txt b/AbilityKit/AppServiceExtensionAbility/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/oh-package.json5 b/AbilityKit/AppServiceExtensionAbility/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextability/MyAppServiceExtAbility.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextability/MyAppServiceExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c36b9fceaa790e3b20eb002899c4c2363d4acbb --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextability/MyAppServiceExtAbility.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 ability_app_service_one] +// [Start ability_app_service_two] +import { AppServiceExtensionAbility, Want } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +// [StartExclude ability_app_service_one] +import { BusinessError } from '@kit.BasicServicesKit'; +// [EndExclude ability_app_service_one] +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[MyAppServiceExtAbility]'; +// [StartExclude ability_app_service_two] +const DOMAIN_NUMBER: number = 0xFF00; +// [EndExclude ability_app_service_two] + +// [StartExclude ability_app_service_two] +class StubTest extends rpc.RemoteObject { + constructor(des: string) { + super(des); + } + + onRemoteMessageRequest(code: number, + data: rpc.MessageSequence, + reply: rpc.MessageSequence, + options: rpc.MessageOption): boolean | Promise { + // 处理客户端发送的消息 + return true; + } +} +// [EndExclude ability_app_service_two] + +export default class MyAppServiceExtAbility extends AppServiceExtensionAbility { + onCreate(want: Want): void { + // [StartExclude ability_app_service_two] + let appServiceExtensionContext = this.context; + hilog.info(DOMAIN_NUMBER, TAG, `onCreate, want: ${want.abilityName}`); + // [EndExclude ability_app_service_two] + // [StartExclude ability_app_service_one] + // 执行业务逻辑 + this.context.terminateSelf().then(() => { + hilog.info(0x0000, TAG, '----------- terminateSelf succeed -----------'); + }).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, `terminateSelf failed, error.code: ${error.code}, error.message: $ {error.message}`); + }); + // [EndExclude ability_app_service_one] + } + + // [StartExclude ability_app_service_two] + onRequest(want: Want, startId: number): void { + hilog.info(DOMAIN_NUMBER, TAG, `onRequest, want: ${want.abilityName}`); + } + + onConnect(want: Want): rpc.RemoteObject { + hilog.info(DOMAIN_NUMBER, TAG, `onConnect, want: ${want.abilityName}`); + return new StubTest('test'); + } + + onDisconnect(want: Want): void { + hilog.info(DOMAIN_NUMBER, TAG, `onDisconnect, want: ${want.abilityName}`); + } + + onDestroy(): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onDestroy'); + } + // [EndExclude ability_app_service_two] +}; +// [End ability_app_service_two] +// [End ability_app_service_one] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilityfour/MyAppServiceExtAbility.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilityfour/MyAppServiceExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..96375bcf251b7b49199a75d996cc899a031e0d9d --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilityfour/MyAppServiceExtAbility.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 ability_app_service_four] +import { AppServiceExtensionAbility, Want } from '@kit.AbilityKit'; +import { abilityAccessCtrl, bundleManager } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[AppServiceExtImpl]'; +const DOMAIN_NUMBER: number = 0xFF00; + +// 开发者需要在这个类里进行实现 + +class Stub extends rpc.RemoteObject { + onRemoteMessageRequest( + code: number, + data: rpc.MessageSequence, + reply: rpc.MessageSequence, + options: rpc.MessageOption): boolean | Promise { + // 开发者自行实现业务逻辑 + hilog.info(DOMAIN_NUMBER, TAG, `onRemoteMessageRequest: ${data}`); + let callerUid = rpc.IPCSkeleton.getCallingUid(); + bundleManager.getBundleNameByUid(callerUid).then((callerBundleName) => { + hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid: ' + callerBundleName); + // 对客户端包名进行识别 + if (callerBundleName !== 'com.samples.stagemodelabilitydevelop') { // 识别不通过 + hilog.info(DOMAIN_NUMBER, TAG, 'The caller bundle is not in trustlist, reject'); + return; + } + // 识别通过,执行正常业务逻辑 + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'getBundleNameByUid failed: ' + err.message); + }); + + let callerTokenId = rpc.IPCSkeleton.getCallingTokenId(); + let accessManager = abilityAccessCtrl.createAtManager(); + // 所校验的具体权限由开发者自行选择,此处ohos.permission.GET_BUNDLE_INFO_PRIVILEGED只作为示例 + let grantStatus = accessManager.verifyAccessTokenSync(callerTokenId, 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'); + if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { + hilog.error(DOMAIN_NUMBER, TAG, 'PERMISSION_DENIED'); + return false; + } + hilog.info(DOMAIN_NUMBER, TAG, 'verify access token success.'); + return true; + } +} + +export default class MyAppServiceExtAbility extends AppServiceExtensionAbility { + onConnect(want: Want): rpc.RemoteObject { + return new Stub('test'); + } + // 其他生命周期 +} +// [End ability_app_service_four] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilitythree/MyAppServiceExtAbility.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilitythree/MyAppServiceExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a313e24d213cc01705e26bfb8010391c811cf62 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilitythree/MyAppServiceExtAbility.ets @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ability_app_service_five] +import { AppServiceExtensionAbility, Want } from '@kit.AbilityKit'; +import { bundleManager } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[MyAppServiceExtAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +class Stub extends rpc.RemoteObject { + private validAppIdentifier: string = 'your_valid_app_identifier_here'; + + onRemoteMessageRequest( + code: number, + data: rpc.MessageSequence, + reply: rpc.MessageSequence, + options: rpc.MessageOption): boolean | Promise { + this.verifyClientIdentity().then((isValid: boolean) => { + if (isValid) { + hilog.info(DOMAIN_NUMBER, TAG, 'Client authentication PASSED'); + } else { + hilog.error(DOMAIN_NUMBER, TAG, 'Client authentication FAILED'); + } + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Authentication error: ${err.code}, ${err.message}`); + }); + return true; + } + + private async verifyClientIdentity(): Promise { + try { + const callerUid: number = rpc.IPCSkeleton.getCallingUid(); + hilog.info(DOMAIN_NUMBER, TAG, `Caller UID: ${callerUid}`); + + const userId: number = await this.getUserIdByUid(callerUid); + hilog.info(DOMAIN_NUMBER, TAG, `User ID: ${userId}`); + + const bundleName: string = await bundleManager.getBundleNameByUid(callerUid); + hilog.info(DOMAIN_NUMBER, TAG, `Bundle Name: ${bundleName}`); + + const bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; + const bundleInfo: bundleManager.BundleInfo = await bundleManager.getBundleInfo(bundleName, bundleFlags, userId); + + if (bundleInfo.signatureInfo && bundleInfo.signatureInfo.appIdentifier) { + const appIdentifier: string = bundleInfo.signatureInfo.appIdentifier; + hilog.info(DOMAIN_NUMBER, TAG, `App Identifier: ${appIdentifier}`); + return appIdentifier === this.validAppIdentifier; + } + return false; + } catch (err) { + if (err instanceof Error) { + hilog.error(DOMAIN_NUMBER, TAG, `Verification failed: ${err.message}`); + } else { + hilog.error(DOMAIN_NUMBER, TAG, `Verification failed: ${String(err)}`); + } + return false; + } + } + + private async getUserIdByUid(uid: number): Promise { + try { + const accountManager = osAccount.getAccountManager(); + const userId: number = await accountManager.getOsAccountLocalIdForUid(uid); + return userId; + } catch (err) { + if (err instanceof Error) { + hilog.error(DOMAIN_NUMBER, TAG, `Get userId failed: ${err.message}`); + throw err; + } else { + const error = new Error(String(err)); + hilog.error(DOMAIN_NUMBER, TAG, `Get userId failed: ${error.message}`); + throw error; + } + } + } +} + +export default class MyAppServiceExtAbility extends AppServiceExtensionAbility { + onConnect(want: Want): rpc.RemoteObject { + return new Stub('test'); + } + // 其他生命周期 +} +// [End ability_app_service_five] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilitytwo/MyAppServiceExtAbility.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilitytwo/MyAppServiceExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..127e0898aea9ec4faab08fe257cf192f9f670bef --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/myappserviceextabilitytwo/MyAppServiceExtAbility.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start ability_app_service_three] +import { AppServiceExtensionAbility, Want } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[MyAppServiceExtAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +// 开发者需要在这个类型里对接口进行实现 +class Stub extends rpc.RemoteObject { + onRemoteMessageRequest(code: number, + data: rpc.MessageSequence, + reply: rpc.MessageSequence, + options: rpc.MessageOption): boolean | Promise { + hilog.info(DOMAIN_NUMBER, TAG, 'onRemoteMessageRequest'); + let sum = data.readInt() + data.readInt(); + reply.writeInt(sum); + return true; + } +} + +// 服务端实现 +export default class MyAppServiceExtAbility extends AppServiceExtensionAbility { + onCreate(want: Want): void { + hilog.info(DOMAIN_NUMBER, TAG, 'MyAppServiceExtAbility onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN_NUMBER, TAG, 'MyAppServiceExtAbility onDestroy'); + } + + onConnect(want: Want): rpc.RemoteObject { + hilog.info(DOMAIN_NUMBER, TAG, 'MyAppServiceExtAbility onConnect'); + return new Stub('test'); + } + + onDisconnect(): void { + hilog.info(DOMAIN_NUMBER, TAG, 'MyAppServiceExtAbility onDisconnect'); + } +} +// [End ability_app_service_three] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/ClientServerExt.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/ClientServerExt.ets new file mode 100644 index 0000000000000000000000000000000000000000..378ca059ed4a3b59c55ce2a117625fdb35c7790d --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/ClientServerExt.ets @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start app_ext_service_five_start] +import { common, Want } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[Page_AppServiceExtensionAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; +const REQUEST_CODE = 1; +let connectionId: number; +let want: Want = { + deviceId: '', + bundleName: 'com.samples.appserviceextensionability', + abilityName: 'MyAppServiceExtAbility' +}; +let options: common.ConnectOptions = { + onConnect(elementName, remote): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onConnect callback'); + if (remote === null) { + hilog.info(DOMAIN_NUMBER, TAG, `onConnect remote is null`); + return; + } + let option = new rpc.MessageOption(); + let data = new rpc.MessageSequence(); + let reply = new rpc.MessageSequence(); + + // 写入请求数据 + data.writeInt(1); + data.writeInt(2); + + remote.sendMessageRequest(REQUEST_CODE, data, reply, option).then((ret: rpc.RequestResult) => { + if (ret.errCode === 0) { + hilog.info(DOMAIN_NUMBER, TAG, `sendRequest got result`); + let sum = ret.reply.readInt(); + hilog.info(DOMAIN_NUMBER, TAG, `sendRequest success, sum:${sum}`); + } else { + hilog.error(DOMAIN_NUMBER, TAG, `sendRequest failed`); + } + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `sendRequest failed, ${JSON.stringify(error)}`); + }); + }, + onDisconnect(elementName): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect callback'); + }, + onFailed(code): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onFailed callback'); + } +}; + +// 调用connectAppServiceExtensionAbility相关代码 + +@Entry +@Component +struct Page_AppServiceExtensionAbility { + build() { + Column() { + // [StartExclude app_ext_service_five_start] + Text('top') + .fontSize(20) + // [EndExclude app_ext_service_five_start] + List({ initialIndex: 0 }) { + ListItem() { + Row() { + // [StartExclude app_ext_service_five_start] + Text('list') + .fontSize(20) + // [EndExclude app_ext_service_five_start] + } + // [StartExclude app_ext_service_four_start] + .id('clientService') + .width('100%') + .height('100%') + // [EndExclude app_ext_service_four_start] + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext + connectionId = context.connectAppServiceExtensionAbility(want, options); + hilog.info(DOMAIN_NUMBER, TAG, `connectionId is : ${connectionId}`); + }) + } + } + // [StartExclude app_ext_service_five_start] + .width('100%') + // [EndExclude app_ext_service_five_start] + } + } +} +// [End app_ext_service_five_start] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/ConnectAppServiceExt.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/ConnectAppServiceExt.ets new file mode 100644 index 0000000000000000000000000000000000000000..390a9b0a51bb44af628c9588bc59f00ecdb9839d --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/ConnectAppServiceExt.ets @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start app_ext_service_three_start] +import { common, Want } from '@kit.AbilityKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[Page_AppServiceExtensionAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +let connectionId: number; +let want: Want = { + deviceId: '', + bundleName: 'com.samples.appserviceextensionability', + abilityName: 'MyAppServiceExtAbility' +}; + +let options: common.ConnectOptions = { + onConnect(elementName, remote: rpc.IRemoteObject): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onConnect callback'); + if (remote === null) { + hilog.info(DOMAIN_NUMBER, TAG, `onConnect remote is null`); + return; + } + // 通过remote进行通信 + }, + onDisconnect(elementName): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect callback'); + }, + onFailed(code: number): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onFailed callback', JSON.stringify(code)); + } +}; + +@Entry +@Component +struct Page_AppServiceExtensionAbility { + build() { + Column() { + // [StartExclude app_ext_service_three_start] + Text('top') + .fontSize(20) + // [EndExclude app_ext_service_three_start] + List({ initialIndex: 0 }) { + ListItem() { + Row() { + // [StartExclude app_ext_service_three_start] + Text('list') + .fontSize(20) + .fontColor(Color.White) + // [EndExclude app_ext_service_three_start] + } + // [StartExclude app_ext_service_three_start] + .id('connect service') + .width('100%') + .height('100%') + // [EndExclude app_ext_service_three_start] + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext + // 建立连接后返回的Id需要保存下来,在解绑服务时需要作为参数传入 + connectionId = context.connectAppServiceExtensionAbility(want, options); + // 成功连接后台服务 + this.getUIContext().getPromptAction().showToast({ + message: 'SuccessfullyConnectBackendService' + }); + hilog.info(DOMAIN_NUMBER, TAG, `connectionId is : ${connectionId}`); + }) + } + + // [StartExclude app_ext_service_three_start] + .backgroundColor(Color.Blue) + .width('100%') + .height('50vp') + // [EndExclude app_ext_service_three_start] + } + + // [StartExclude app_ext_service_three_start] + .width('100%') + // [EndExclude app_ext_service_three_start] + } + + // [StartExclude app_ext_service_three_start] + .width('100%') + // [EndExclude app_ext_service_three_start] + } +} +// [End app_ext_service_three_start] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/DisConnectAppServiceExt.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/DisConnectAppServiceExt.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f7e1a0959fad5fd5b6b6fdb2fb52388d4377cd1 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/DisConnectAppServiceExt.ets @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start app_ext_service_four_start] +import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[Page_AppServiceExtensionAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +let connectionId: number; + +@Entry +@Component +struct Page_AppServiceExtensionAbility { + build() { + Column() { + // [StartExclude app_ext_service_four_start] + Text('top') + .fontSize(20) + // [EndExclude app_ext_service_four_start] + List({ initialIndex: 0 }) { + ListItem() { + Row() { + // [StartExclude app_ext_service_four_start] + Text('list') + .fontSize(20) + .fontColor(Color.White) + // [EndExclude app_ext_service_four_start] + } + // [StartExclude app_ext_service_four_start] + .id('dis connect service') + .width('100%') + .height('100%') + // [EndExclude app_ext_service_four_start] + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext + // connectionId为调用connectServiceExtensionAbility接口时的返回值,需开发者自行维护 + context.disconnectAppServiceExtensionAbility(connectionId).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'disconnectAppServiceExtensionAbility success'); + // 成功断连后台服务 + this.getUIContext().getPromptAction().showToast({ + message: 'SuccessfullyDisconnectBackendService' + }); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'disconnectAppServiceExtensionAbility failed'); + }); + }) + } + + // [StartExclude app_ext_service_four_start] + .backgroundColor(Color.Blue) + .width('100%') + .height('50vp') + // [EndExclude app_ext_service_four_start] + } + + // [StartExclude app_ext_service_four_start] + .width('100%') + // [EndExclude app_ext_service_four_start] + } + + // [StartExclude app_ext_service_four_start] + .width('100%') + // [EndExclude app_ext_service_four_start] + } +} +// [End app_ext_service_four_start] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/Index.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..34949d4895a99f81c200ca05ef2c043907a27817 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Column(){ + Button('start backend service') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .onClick(() => { + router.pushUrl({ + url:'pages/StartAppServiceExt' + }) + }) + Button('stop backend service') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .onClick(() => { + router.pushUrl({ + url:'pages/StopAppServiceExt' + }) + }) + Button('connect backend service') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .onClick(() => { + router.pushUrl({ + url:'pages/ConnectAppServiceExt' + }) + }) + Button('dis connect backend service') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .onClick(() => { + router.pushUrl({ + url:'pages/DisConnectAppServiceExt' + }) + }) + Button('client service') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .onClick(() => { + router.pushUrl({ + url:'pages/ClientServerExt' + }) + }) + + } + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/StartAppServiceExt.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/StartAppServiceExt.ets new file mode 100644 index 0000000000000000000000000000000000000000..128002a35bb044ac680e281a6cc51a9337f06c0c --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/StartAppServiceExt.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 app_ext_service_one_start] +import { common, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[Page_AppServiceExtensionAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_AppServiceExtensionAbility { + build() { + Column() { + // [StartExclude app_ext_service_one_start] + Text('top') + .fontSize(20) + // [EndExclude app_ext_service_one_start] + List({ initialIndex: 0 }) { + ListItem() { + Row() { + // [StartExclude app_ext_service_one_start] + Text('list') + .fontSize(20) + .fontColor(Color.White) + // [EndExclude app_ext_service_one_start] + } + // [StartExclude app_ext_service_one_start] + .id('start service') + .width('100%') + .height('100%') + // [EndExclude app_ext_service_one_start] + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', + bundleName: 'com.samples.appserviceextensionability', + abilityName: 'MyAppServiceExtAbility' + }; + context.startAppServiceExtensionAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting AppServiceExtensionAbility.'); + // 成功启动后台服务 + this.getUIContext().getPromptAction().showToast({ + message: 'SuccessfullyStartBackendService' + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to start AppServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + + // [StartExclude app_ext_service_one_start] + .backgroundColor(Color.Blue) + .width('100%') + .height('50vp') + // [EndExclude app_ext_service_one_start] + } + // [StartExclude app_ext_service_one_start] + .width('100%') + // [EndExclude app_ext_service_one_start] + } + + // [StartExclude app_ext_service_one_start] + .width('100%') + // [EndExclude app_ext_service_one_start] + } +} +// [End app_ext_service_one_start] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/StopAppServiceExt.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/StopAppServiceExt.ets new file mode 100644 index 0000000000000000000000000000000000000000..9af84b38ec21203ad110f50e50882220482e7214 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/ets/pages/StopAppServiceExt.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 app_ext_service_two_start] +import { common, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[Page_AppServiceExtensionAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_AppServiceExtensionAbility { + build() { + Column() { + // [StartExclude app_ext_service_two_start] + Text('top') + .fontSize(20) + // [EndExclude app_ext_service_two_start] + List({ initialIndex: 0 }) { + ListItem() { + Row() { + // [StartExclude app_ext_service_two_start] + Text('list') + .fontSize(20) + .fontColor(Color.White) + // [EndExclude app_ext_service_two_start] + } + // [StartExclude app_ext_service_two_start] + .id('stop service') + .width('100%') + .height('100%') + // [EndExclude app_ext_service_two_start] + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', + bundleName: 'com.samples.appserviceextensionability', + abilityName: 'MyAppServiceExtAbility' + }; + context.stopAppServiceExtensionAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in stopping AppServiceExtensionAbility.'); + this.getUIContext().getPromptAction().showToast({ + message: 'SuccessfullyStoppedAStartedBackendService' + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to stop AppServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + + // [StartExclude app_ext_service_two_start] + .backgroundColor(Color.Blue) + .width('100%') + .height('50vp') + // [EndExclude app_ext_service_two_start] + } + + // [StartExclude app_ext_service_two_start] + .width('100%') + // [EndExclude app_ext_service_two_start] + } + + // [StartExclude app_ext_service_two_start] + .width('100%') + // [EndExclude app_ext_service_two_start] + } +} +// [End app_ext_service_two_start] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/module.json5 b/AbilityKit/AppServiceExtensionAbility/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e8c7352bdf3dbe4ae8df5bee7d2aa5702e52841b --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/module.json5 @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start my_app_service_module_start] +{ + "module": { + // [StartExclude my_app_service_module_start] + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "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" + ] + } + ] + }, + { + "name": "MyAppServiceExtAbility", + "srcEntry": "./ets/myappserviceextability/MyAppServiceExtAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": false, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + // [EndExclude my_app_service_module_start] + "extensionAbilities": [ + // [StartExclude my_app_service_module_start] + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + }, + { + "name": "MyAppServiceExtAbility", + "description": "appService", + "type": "appService", + "exported": true, + "srcEntry": "./ets/myappserviceextabilitytwo/MyAppServiceExtAbility.ets", + "appIdentifierAllowList": [ + // 此处填写允许启动该后台服务的客户端应用的appIdentifier列表 + ], + }, + // [EndExclude my_app_service_module_start] + { + "name": "MyAppServiceExtAbility", + "description": "appService", + "type": "appService", + "exported": true, + "srcEntry": "./ets/myappserviceextability/MyAppServiceExtAbility.ets", + "appIdentifierAllowList": [ + // 此处填写允许启动该后台服务的客户端应用的appIdentifier列表 + ], + } + ] + } +} +// [End my_app_service_module_start] \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/element/color.json b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/element/float.json b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/element/string.json b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/background.png b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/foreground.png b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..0a9c7a1c442c639b5e7934716a8c71b182e7928a --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,10 @@ +{ + "src": [ + "pages/Index", + "pages/StartAppServiceExt", + "pages/StopAppServiceExt", + "pages/ConnectAppServiceExt", + "pages/DisConnectAppServiceExt", + "pages/ClientServerExt" + ] +} diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/dark/element/color.json b/AbilityKit/AppServiceExtensionAbility/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/mock/mock-config.json5 b/AbilityKit/AppServiceExtensionAbility/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c8f9ff5188b526d5e89e9053643233756472efe --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry } from '@kit.TestKit'; +import { Driver, ON, Component, MatchPattern } from '@ohos.UiTest' + +const TAG = '[Sample_AppServiceExtensionAbility]'; +const DOMAIN = 0xF811; +const BUNDLE = 'AppServiceExtensionAbility_'; +const TIME = 1000; + +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 () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 begin'); + let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + try { + await abilityDelegator.startAbility({ + bundleName: 'com.samples.appserviceextensionability', + abilityName: 'EntryAbility' + }); + await driver.delayMs(1000); + // 获取当前top的ability + let entryAbility = await abilityDelegator.getCurrentTopAbility(); + expect(entryAbility.context.abilityInfo.name).assertEqual('EntryAbility'); + } catch (err) { + hilog.info(DOMAIN, TAG, BUNDLE + 'error: ' + err.message); + expect(err.code).assertEqual(0); + } + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 end'); + }) + 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('AppServiceExtensionAbility_start_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'start_001 begin'); + try { + const button = await driver.findComponent(ON.text('start backend service')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'start_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_start_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'start_002 begin'); + try { + const button = await driver.findComponent(ON.id('start service')); + await button.click(); + await driver.delayMs(TIME); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'start_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_stop_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'stop_001 begin'); + try { + const button = await driver.findComponent(ON.text('stop backend service')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'stop_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_stop_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'stop_002 begin'); + try { + const button = await driver.findComponent(ON.id('stop service')); + await button.click(); + await driver.delayMs(TIME); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'stop_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_connect_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_001 begin'); + try { + const button = await driver.findComponent(ON.text('connect backend service')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_connect_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_002 begin'); + try { + const button = await driver.findComponent(ON.id('connect service')); + await button.click(); + await driver.delayMs(TIME); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_disconnect_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'disconnect_001 begin'); + try { + const button = await driver.findComponent(ON.text('dis connect backend service')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'disconnect_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_disconnect_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'disconnect_002 begin'); + try { + const button = await driver.findComponent(ON.id('dis connect service')); + await button.click(); + await driver.delayMs(TIME); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'disconnect_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_client_service_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'client_service_001 begin'); + try { + const button = await driver.findComponent(ON.text('client service')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'client_service_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('AppServiceExtensionAbility_client_service_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'client_service_002 begin'); + try { + const button = await driver.findComponent(ON.id('clientService')); + await button.click(); + await driver.delayMs(TIME); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'client_service_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/ohosTest/module.json5 b/AbilityKit/AppServiceExtensionAbility/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b188ccdd3772c3d946df8843cc4dae17eef4321 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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": [ + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/AppServiceExtensionAbility/entry/src/test/List.test.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/entry/src/test/LocalUnit.test.ets b/AbilityKit/AppServiceExtensionAbility/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/hvigor/hvigor-config.json5 b/AbilityKit/AppServiceExtensionAbility/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/hvigorfile.ts b/AbilityKit/AppServiceExtensionAbility/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/oh-package.json5 b/AbilityKit/AppServiceExtensionAbility/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/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/AbilityKit/AppServiceExtensionAbility/ohosTest.md b/AbilityKit/AppServiceExtensionAbility/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..3837a5b51a5e0b24a7425272ea89e5c7bd9ff6cd --- /dev/null +++ b/AbilityKit/AppServiceExtensionAbility/ohosTest.md @@ -0,0 +1,13 @@ +# AppServiceExtensionAbility示例测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------| ------------ | ---- |-------------------| -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用后,展示首页 | 是 | Pass | +| start backend service | 设备正常运行 | | 正常跳转页面,点击相应按钮正常触发 | 是 | Pass | +| stop backend service | 设备正常运行 | | 正常跳转页面,点击相应按钮正常触发 | 是 | Pass | +| connect backend service | 设备正常运行 | | 正常跳转页面,点击相应按钮正常触发 | 是 | Pass | +| dis connect backend service | 设备正常运行 | | 正常跳转页面,点击相应按钮正常触发 | 是 | Pass | +| client service | 设备正常运行 | | 正常跳转页面,点击相应按钮正常触发 | 是 | Pass | + diff --git a/AbilityKit/ApplicationContextDemo/.gitignore b/AbilityKit/ApplicationContextDemo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/.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/AbilityKit/ApplicationContextDemo/AppScope/app.json5 b/AbilityKit/ApplicationContextDemo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..881b3c012b2252e30cf62681fb8925897f7da806 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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.applicationcontext", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/ApplicationContextDemo/AppScope/resources/base/element/string.json b/AbilityKit/ApplicationContextDemo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4e34477815ae402e3ef0fb436ac90ed442c0305c --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ApplicationContextDemo" + } + ] +} diff --git a/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/background.png b/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/foreground.png b/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/layered_image.json b/AbilityKit/ApplicationContextDemo/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/README_zh.md b/AbilityKit/ApplicationContextDemo/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..68607d20e4b748c7eafa80447f9e1690b15e94ba --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/README_zh.md @@ -0,0 +1,113 @@ +# ApplicationContext简介 + +### 介绍 + +[Context](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-context.md)是应用中对象的上下文,其提供了应用的一些基础信息,例如resourceManager(资源管理)、applicationInfo(当前应用信息)、area(文件分区)等。 + +### 效果预览 + +不涉及。 +### 使用说明 + +1. 应用在启动后显示文本"hello world"。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── abilitystagecontextability + │ │ ├── MyAbilityStage.ets // 模块级别的上下文 + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── entryexampleability + │ │ ├── EntryExampleAbility.ets // 应用的全局上下文 + │ │ ├── entrylifecycleability + │ │ ├── EntryLifecycleAbility.ets // 监听UIAbility生命周期变化 + │ │ ├── entrysceneability + │ │ ├── EntrySceneAbility.ets // 获取基本信息 + │ │ ├── extensionability + │ │ ├── ExtensionAbility.ets // ExtensionAbility组件的上下文 + │ │ ├── lifecycleability + │ │ ├── LifecycleAbility.ets // 监听应用前后台变化 + │ │ ├── pages + │ │ ├── ApplicationContextCache.ets // 获取应用缓存目录 + │ │ ├── ApplicationContextFile.ets // 获取应用文件目录 + │ │ ├── AreaContext.ets // 加密分区使用 + │ │ ├── CreateModuleContext.ets // 获取本应用中其他Module的模块级别的上下文 + │ │ ├── EventHub.ets // 在页面中获取UIAbility实例的上下文信息 + │ │ ├── Index.ets // 首页 + │ │ ├── UIAbilityComponentsBasicUsage.ets // 可以在具体使用UIAbilityContext前进行变量定义 + │ │ ├── UIAbilityComponentsUsage.ets // 当业务完成后,开发者如果想要终止当前UIAbility实例 + │ │ ├── uiAbilitycontextability + │ │ ├── UIAbilityContextAbility.ets // 通过this.context获取UIAbility实例的上下文信息 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` +### 具体实现 + +1.获取ApplicationContext(应用的全局上下文) + +ApplicationContext在基类Context的基础上提供了监听应用内应用组件的生命周期的变化、监听系统内存变化、监听应用内系统环境变化、设置应用语言、设置应用颜色模式、清除应用自身数据的同时撤销应用向用户申请的权限等能力,在UIAbility、ExtensionAbility、AbilityStage中均可以获取。 + +entry/src/main/ets/entryexampleability/EntryExampleAbility.ets + +```ts +import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + let applicationContext = this.context.getApplicationContext(); + //... + } +} +``` + +2.获取ApplicationContext(应用的全局上下文) + +AbilityStageContext和基类Context相比,额外提供HapModuleInfo、Configuration等信息。 + +entry/src/main/ets/abilitystagecontextability/MyAbilityStage.ets + +```ts +import { AbilityStage } from '@kit.AbilityKit'; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + let abilityStageContext = this.context; + //... + } +} +``` +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/Ability/ApplicationContextDemo > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/ApplicationContextDemo/build-profile.json5 b/AbilityKit/ApplicationContextDemo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/AbilityKit/ApplicationContextDemo/code-linter.json5 b/AbilityKit/ApplicationContextDemo/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/.gitignore b/AbilityKit/ApplicationContextDemo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/build-profile.json5 b/AbilityKit/ApplicationContextDemo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/hvigorfile.ts b/AbilityKit/ApplicationContextDemo/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/obfuscation-rules.txt b/AbilityKit/ApplicationContextDemo/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/oh-package.json5 b/AbilityKit/ApplicationContextDemo/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/main/ets/abilitystagecontextability/MyAbilityStage.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/abilitystagecontextability/MyAbilityStage.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c2e76b959c8ff11b102c5c979aaef757c14b71e --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/abilitystagecontextability/MyAbilityStage.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. + */ + +// [Start abilityStageContext_start] +import { AbilityStage } from '@kit.AbilityKit'; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + let abilityStageContext = this.context; + //... + } +} +// [End abilityStageContext_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryareaability/EntryAreaAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryareaability/EntryAreaAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e99d7dd99708c813b7aee7b09e1a2f8437758f0 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryareaability/EntryAreaAbility.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ability_area_start] +import { UIAbility, contextConstant, AbilityConstant, Want } from '@kit.AbilityKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + // 存储普通信息前,切换到EL1设备级加密 + this.context.area = contextConstant.AreaMode.EL1; // 切换area + // 存储普通信息 + + // 存储敏感信息前,切换到EL2用户级加密 + this.context.area = contextConstant.AreaMode.EL2; // 切换area + // 存储敏感信息 + + // 存储敏感信息前,切换到EL3用户级加密 + this.context.area = contextConstant.AreaMode.EL3; // 切换area + // 存储敏感信息 + + // 存储敏感信息前,切换到EL4用户级加密 + this.context.area = contextConstant.AreaMode.EL4; // 切换area + // 存储敏感信息 + + // 存储敏感信息前,切换到EL5应用级加密 + this.context.area = contextConstant.AreaMode.EL5; // 切换area + // 存储敏感信息 + } +} +// [End ability_area_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryexampleability/EntryExampleAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryexampleability/EntryExampleAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c3b67a38b3b4b575fdea0cdaeadcb7871cf18e7 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entryexampleability/EntryExampleAbility.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start application_context_start] +import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + let applicationContext = this.context.getApplicationContext(); + } +} +// [End application_context_start] diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrylifecycleability/EntryLifecycleAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrylifecycleability/EntryLifecycleAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3eb1a84f87b6411481c4bdbd121212710f0e683 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrylifecycleability/EntryLifecycleAbility.ets @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start entry_lifecycle_ability_start] +import { AbilityConstant, AbilityLifecycleCallback, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[LifecycleAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class LifecycleAbility extends UIAbility { + // 定义生命周期ID + private lifecycleId: number = -1; + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 定义生命周期回调对象 + let abilityLifecycleCallback: AbilityLifecycleCallback = { + // 当UIAbility创建时被调用 + onAbilityCreate(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityCreate uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当窗口创建时被调用 + onWindowStageCreate(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageCreate uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageCreate windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当窗口处于活动状态时被调用 + onWindowStageActive(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageActive uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageActive windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当窗口处于非活动状态时被调用 + onWindowStageInactive(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageInactive uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageInactive windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当窗口被销毁时被调用 + onWindowStageDestroy(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageDestroy uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageDestroy windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当UIAbility被销毁时被调用 + onAbilityDestroy(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityDestroy uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当UIAbility从后台转到前台时触发回调 + onAbilityForeground(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityForeground uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当UIAbility从前台转到后台时触发回调 + onAbilityBackground(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityBackground uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当UIAbility迁移时被调用 + onAbilityContinue(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityContinue uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + } + }; + // 获取应用上下文 + let applicationContext = this.context.getApplicationContext(); + try { + // 注册应用内生命周期回调 + this.lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback); + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(DOMAIN_NUMBER, TAG, `Failed to register applicationContext. Code is ${code}, message is ${message}`); + } + + hilog.info(DOMAIN_NUMBER, TAG, `register callback number: ${this.lifecycleId}`); + } + onDestroy(): void { + // 获取应用上下文 + let applicationContext = this.context.getApplicationContext(); + try { + // 取消应用内生命周期回调 + applicationContext.off('abilityLifecycle', this.lifecycleId); + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(DOMAIN_NUMBER, TAG, `Failed to unregister applicationContext. Code is ${code}, message is ${message}`); + } + } +} +// [End entry_lifecycle_ability_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrysceneability/EntrySceneAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrysceneability/EntrySceneAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..a698daff4b00a1defec46d86aa8fdcf69ae2bd5f --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/entrysceneability/EntrySceneAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start scene_entry_ability_start] +import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 获取ResourceManager(资源管理) + let resourceManager = this.context.getApplicationContext().resourceManager; + // 获取applicationInfo(当前应用信息) + let applicationInfo = this.context.getApplicationContext().applicationInfo; + } +} +// [End scene_entry_ability_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/extensionability/ExtensionAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/extensionability/ExtensionAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f9178d43ccfd8000c0f59548ee528f194ffcc60 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/extensionability/ExtensionAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start extension_ability_context_start] +import { FormExtensionAbility, formBindingData } from '@kit.FormKit'; +import { Want } from '@kit.AbilityKit'; + +export default class MyFormExtensionAbility extends FormExtensionAbility { + onAddForm(want: Want) { + let formExtensionContext = this.context; + let dataObj1: Record = { + 'temperature': '11c', + 'time': '11:00' + }; + let obj1: formBindingData.FormBindingData = formBindingData.createFormBindingData(dataObj1); + return obj1; + } +} +// [End extension_ability_context_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/lifecycleability/LifecycleAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/lifecycleability/LifecycleAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..94ac2f1ab5810f87208a2e853b7c4347c4d94833 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/lifecycleability/LifecycleAbility.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start lifecycle_ability_start] +import { UIAbility, ApplicationStateChangeCallback } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +const TAG = '[LifecycleAbility]'; +const DOMAIN = 0xF811; + +export default class LifecycleAbility extends UIAbility { + onCreate() { + let applicationStateChangeCallback: ApplicationStateChangeCallback = { + onApplicationForeground() { + hilog.info(DOMAIN, TAG, 'applicationStateChangeCallback onApplicationForeground'); + }, + onApplicationBackground() { + hilog.info(DOMAIN, TAG, 'applicationStateChangeCallback onApplicationBackground'); + } + } + + // 1.获取applicationContext + let applicationContext = this.context.getApplicationContext(); + try { + // 2.通过applicationContext注册应用前后台状态监听 + applicationContext.on('applicationStateChange', applicationStateChangeCallback); + } catch (paramError) { + hilog.error(DOMAIN, TAG, `error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`); + } + hilog.info(DOMAIN, TAG, 'Register applicationStateChangeCallback'); + } +} +// [End lifecycle_ability_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/ApplicationContextCache.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/ApplicationContextCache.ets new file mode 100644 index 0000000000000000000000000000000000000000..4cd63f4da21351bebfa324970983a9177985de46 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/ApplicationContextCache.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start app_context_cache_start] +import { common } from '@kit.AbilityKit'; + +const TAG: string = '[Page_Context]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + + build() { + Row() { + Column() { + Text(this.message) + // [StartExclude app_context_cache_start] + .width('50vp') + // [EndExclude app_context_cache_start] + Button() { + Text('create file') + // [StartExclude app_context_cache_start] + .width('50vp') + // [EndExclude app_context_cache_start] + .onClick(() => { + let applicationContext = this.context.getApplicationContext(); + // 获取应用缓存路径 + let cacheDir = applicationContext.cacheDir; + }) + } + // [StartExclude app_context_cache_start] + .width('50vp') + // [EndExclude app_context_cache_start] + } + // [StartExclude app_context_cache_start] + .width('50vp') + // [EndExclude app_context_cache_start] + } + // [StartExclude app_context_cache_start] + .width('50vp') + // [EndExclude app_context_cache_start] + } +} +// [End app_context_cache_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/ApplicationContextFile.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/ApplicationContextFile.ets new file mode 100644 index 0000000000000000000000000000000000000000..32cc3899eeb82ecaa1c4f002d68017723393551c --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/ApplicationContextFile.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 app_context_file_start] +import { common } from '@kit.AbilityKit'; +import { buffer } from '@kit.ArkTS'; +import { fileIo, ReadOptions } from '@kit.CoreFileKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[Page_Context]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + + build() { + Row() { + Column() { + Text(this.message) + // [StartExclude app_context_file_start] + .width('50vp') + // [EndExclude app_context_file_start] + Button() { + Text('create file') + // [StartExclude app_context_file_start] + .width('50vp') + // [EndExclude app_context_file_start] + .onClick(() => { + let applicationContext = this.context.getApplicationContext(); + // 获取应用文件路径 + let filesDir = applicationContext.filesDir; + hilog.info(DOMAIN_NUMBER, TAG, `filePath: ${filesDir}`); + // 文件不存在时创建并打开文件,文件存在时打开文件 + let file = fileIo.openSync(filesDir + '/test.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + // 写入一段内容至文件 + let writeLen = fileIo.writeSync(file.fd, 'Try to write str.'); + hilog.info(DOMAIN_NUMBER, TAG, `The length of str is: ${writeLen}`); + // 创建一个大小为1024字节的ArrayBuffer对象,用于存储从文件中读取的数据 + let arrayBuffer = new ArrayBuffer(1024); + // 设置读取的偏移量和长度 + let readOptions: ReadOptions = { + offset: 0, + length: arrayBuffer.byteLength + }; + // 读取文件内容到ArrayBuffer对象中,并返回实际读取的字节数 + let readLen = fileIo.readSync(file.fd, arrayBuffer, readOptions); + // 将ArrayBuffer对象转换为Buffer对象,并转换为字符串输出 + let buf = buffer.from(arrayBuffer, 0, readLen); + hilog.info(DOMAIN_NUMBER, TAG, `the content of file: ${buf.toString()}`); + // 关闭文件 + fileIo.closeSync(file); + }) + } + // [StartExclude app_context_file_start] + .width('50vp') + // [EndExclude app_context_file_start] + } + // [StartExclude app_context_file_start] + .width('50vp') + // [EndExclude app_context_file_start] + } + // [StartExclude app_context_file_start] + .width('50vp') + // [EndExclude app_context_file_start] + } +} +// [End app_context_file_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/AreaContext.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/AreaContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..21750522a58a583e3ddb3d8add53eb1ce5293323 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/AreaContext.ets @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start scene_area_context_start] +// Index.ets +import { contextConstant, common } from '@kit.AbilityKit'; + +@Entry +@Component +struct Page_Context { + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + + build() { + Column() { + // [StartExclude scene_area_context_start] + Text('top') + .width('50vp') + // [EndExclude scene_area_context_start] + List({ initialIndex: 0 }) { + // [StartExclude scene_area_context_start] + ListItem() { + Row() { + Text('list') + .width('60vp') + } + } + // [EndExclude scene_area_context_start] + ListItem() { + Row() { + // [StartExclude scene_area_context_start] + Text('list') + .width('50vp') + // [EndExclude scene_area_context_start] + } + .onClick(() => { + // 存储普通信息前,切换到EL1设备级加密 + if (this.context.area === contextConstant.AreaMode.EL2) { // 获取area + this.context.area = contextConstant.AreaMode.EL1; // 修改area + this.getUIContext().getPromptAction().showToast({ + message: 'SwitchToEL1' + }); + } + // 存储普通信息 + }) + } + // [StartExclude scene_area_context_start] + .width('100%') + // [EndExclude scene_area_context_start] + ListItem() { + Row() { + // [StartExclude scene_area_context_start] + Text('list') + .width('50vp') + // [EndExclude scene_area_context_start] + } + .onClick(() => { + // 存储敏感信息前,切换到EL2用户级加密 + if (this.context.area === contextConstant.AreaMode.EL1) { // 获取area + this.context.area = contextConstant.AreaMode.EL2; // 修改area + this.getUIContext().getPromptAction().showToast({ + message: 'SwitchToEL2' + }); + } + // 存储敏感信息 + }) + } + // [StartExclude scene_area_context_start] + .width('100%') + // [EndExclude scene_area_context_start] + } + // [StartExclude scene_area_context_start] + .width('100%') + // [EndExclude scene_area_context_start] + } + // [StartExclude scene_area_context_start] + .width('100%') + // [EndExclude scene_area_context_start] + } +} +// [End scene_area_context_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/CreateModuleContext.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/CreateModuleContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..12fe165139a67f78ae74e4a2a0e1f50bf509d864 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/CreateModuleContext.ets @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start createModuleContext_start] +import { common, application } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG = '[Page_Context]'; +const DOMAIN = 0xF811; + +let storageEventCall = new LocalStorage(); + +@Entry(storageEventCall) +@Component +struct Page_Context { + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + + build() { + Column() { + // [StartExclude createModuleContext_start] + Text('top') + .width('50vp') + // [EndExclude createModuleContext_start] + List({ initialIndex: 0 }) { + ListItem() { + Row() { + // [StartExclude createModuleContext_start] + Text('list') + .width('50vp') + // [EndExclude createModuleContext_start] + } + .onClick(() => { + let moduleName2: string = 'entry'; + application.createModuleContext(this.context, moduleName2) + .then((data: common.Context) => { + hilog.info(DOMAIN, TAG, `CreateModuleContext success, data: ${JSON.stringify(data)}`); + if (data !== null) { + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.success_message') + }); + } + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, `CreateModuleContext failed, err code:${err.code}, err msg: ${err.message}`); + }); + }) + } + // [StartExclude createModuleContext_start] + .width('50vp') + // [EndExclude createModuleContext_start] + } + // [StartExclude createModuleContext_start] + .width('50vp') + // [EndExclude createModuleContext_start] + } + // [StartExclude createModuleContext_start] + .width('50vp') + // [EndExclude createModuleContext_start] + } +} +// [End createModuleContext_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/EventHub.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/EventHub.ets new file mode 100644 index 0000000000000000000000000000000000000000..60582c6081b14337874984f09885a8581adf07f6 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/EventHub.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ui_ability_eventHub_start] +import { common, Want } from '@kit.AbilityKit'; // 导入依赖资源context模块 + +@Entry +@Component +struct Page_EventHub { + // 定义context变量 + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + + startAbilityTest(): void { + let want: Want = { + // Want参数信息 + }; + this.context.startAbility(want); + } + + // 页面展示 + build() { + // [StartExclude ui_ability_eventHub_start] + Column(){ + Text('eventhub') + .width('50vp') + } + .width('100%') + // [EndExclude ui_ability_eventHub_start] + } +} +// [End ui_ability_eventHub_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/Index.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..64ca99781cb5c3e261ecdd74d316c6fa7cec67e4 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/Index.ets @@ -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. + */ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/UIAbilityComponentsBasicUsage.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/UIAbilityComponentsBasicUsage.ets new file mode 100644 index 0000000000000000000000000000000000000000..1d46b7417ab04ceee5d828a634448b5805a32626 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/UIAbilityComponentsBasicUsage.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 ui_ability_basic_usage_start] +import { common, Want } from '@kit.AbilityKit'; + +@Entry +@Component +struct Page_UIAbilityComponentsBasicUsage { + startAbilityTest(): void { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let want: Want = { + // Want参数信息 + }; + context.startAbility(want); + } + + // 页面展示 + build() { + // [StartExclude ui_ability_basic_usage_start] + Column(){ + Text('basic usage start') + .width('50vp') + } + .width('100%') + // [EndExclude ui_ability_basic_usage_start] + } +} +// [End ui_ability_basic_usage_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/UIAbilityComponentsUsage.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/UIAbilityComponentsUsage.ets new file mode 100644 index 0000000000000000000000000000000000000000..1803fba92ed31928842251607c4c5b0dcfe8cb01 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/pages/UIAbilityComponentsUsage.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ui_ability_usage_start] +import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG = '[Page_UIAbilityComponentsBasicUsage]'; +const DOMAIN = 0xF811; +@Entry +@Component +struct Page_UIAbilityComponentsBasicUsage { + // 页面展示 + build() { + Column() { + // [StartExclude ui_ability_usage_start] + Text('usage start') + .width('50vp') + // [EndExclude ui_ability_usage_start] + Button('FuncAbilityB') + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + try { + context.terminateSelf((err: BusinessError) => { + if (err.code) { + // 处理业务逻辑错误 + hilog.error(DOMAIN, TAG, `terminateSelf failed, code is ${err.code}, message is ${err.message}.`); + return; + } + // 执行正常业务 + hilog.info(DOMAIN, TAG, `terminateSelf succeed.`); + }); + } catch (err) { + // 捕获同步的参数错误 + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(DOMAIN, TAG, `terminateSelf failed, code is ${code}, message is ${message}.`); + } + }) + } + } +} +// [End ui_ability_usage_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/ets/uiAbilitycontextability/UIAbilityContextAbility.ets b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/uiAbilitycontextability/UIAbilityContextAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..19a297b3172f28807e52f793de39377977f03e76 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/ets/uiAbilitycontextability/UIAbilityContextAbility.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. + */ + +// [Start ui_ability_context_start] +import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 获取UIAbility实例的上下文 + let context = this.context; + } +} +// [End ui_ability_context_start] \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/module.json5 b/AbilityKit/ApplicationContextDemo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2545e156fed622ee3d1e8176ff1fbc43f4343bc4 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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", + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "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/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/color.json b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/float.json b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/string.json b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a1bb17f0e45eab6179be0263df073522246d1328 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "success_message", + "value": "成功获取Context" + } + ] +} \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/background.png b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/foreground.png b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/AbilityKit/ApplicationContextDemo/entry/src/main/resources/dark/element/color.json b/AbilityKit/ApplicationContextDemo/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/mock/mock-config.json5 b/AbilityKit/ApplicationContextDemo/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/ApplicationContextDemo/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..47c4e07b438da4ea3a903c577484b8babc70d4f2 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +const TAG = '[Sample_ApplicationContext]'; +const DOMAIN = 0xF811; +const BUNDLE = 'ApplicationContext_'; +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('ApplicationContext_Startup_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'Startup_001 begin'); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + try { + await abilityDelegator.startAbility({ + bundleName: 'com.samples.applicationcontext', + abilityName: 'EntryAbility' + }); + done(); + } + catch (expection) { + hilog.info(DOMAIN, TAG, BUNDLE + `Startup_001 end ${JSON.stringify(expection)}`); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/AbilityKit/ApplicationContextDemo/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/ApplicationContextDemo/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/ohosTest/module.json5 b/AbilityKit/ApplicationContextDemo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..12ddf9861a24545643847583653f531bf1679c6c --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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", + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/ApplicationContextDemo/entry/src/test/List.test.ets b/AbilityKit/ApplicationContextDemo/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/entry/src/test/LocalUnit.test.ets b/AbilityKit/ApplicationContextDemo/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/hvigor/hvigor-config.json5 b/AbilityKit/ApplicationContextDemo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/hvigorfile.ts b/AbilityKit/ApplicationContextDemo/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/oh-package.json5 b/AbilityKit/ApplicationContextDemo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/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/AbilityKit/ApplicationContextDemo/ohosTest.md b/AbilityKit/ApplicationContextDemo/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..85edb4a9b90a77a94f2ef2d6c0257ad4604a5eb5 --- /dev/null +++ b/AbilityKit/ApplicationContextDemo/ohosTest.md @@ -0,0 +1,8 @@ +# ApplicationContextDemo示例测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------| ------------ | ---- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | + diff --git a/AbilityKit/EmbeddedUIExtensionAbility/.gitignore b/AbilityKit/EmbeddedUIExtensionAbility/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/.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/AbilityKit/EmbeddedUIExtensionAbility/AppScope/app.json5 b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2ae960c00ea4f9bb24bfacf71c4a408ba01e5a8e --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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.embeddeduiextensionability", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/element/string.json b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6e273b77f75875a9b361f0bb06adc938d17b4842 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "EmbeddedUIExtensionAbility" + } + ] +} diff --git a/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/background.png b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/foreground.png b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/layered_image.json b/AbilityKit/EmbeddedUIExtensionAbility/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/README_zh.md b/AbilityKit/EmbeddedUIExtensionAbility/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..291ab8503bd948f28e5588c32c7e3b6227a8338f --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/README_zh.md @@ -0,0 +1,201 @@ +# EmbeddedUIExtensionAbility简介 + +### 介绍 + +[EmbeddedUIExtensionAbility](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-embeddedUIExtensionAbility.md)是EMBEDDED_UI类型的[ExtensionAbility](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-extensionAbility.md)组件,提供了跨进程界面嵌入的能力。 + +EmbeddedUIExtensionAbility需要和[EmbeddedComponent](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-container-embedded-component.md)一起配合使用,开发者可以在[UIAbility](https://gitcode.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-uiAbility.md)的页面中通过EmbeddedComponent嵌入本应用的EmbeddedUIExtensionAbility提供的UI。EmbeddedUIExtensionAbility在独立进程中运行,完成其页面的布局和渲染,与UIAbility数据不互通,适用于有进程隔离诉求的模块化开发场景。 + +### 效果预览 +不涉及。 + +### 使用说明 + +1. 拉起应用。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── embeddeduiextability + │ │ ├── ExampleEmbeddedAbility.ets // 自定义类继承EmbeddedUIExtensionAbility + │ │ ├── pages + │ │ ├── BasicClass.ets + │ │ ├── Extension.ets // EmbeddedUIExtensionAbility的onSessionCreate中加载了入口页面文件 + │ │ ├── Index.ets // 首页 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 具体实现 + +1.创建EmbeddedUIExtAbility文件 + +entry/src/main/ets/embeddeduiextability/ExampleEmbeddedAbility.ets + +```ts +import { EmbeddedUIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; + +const TAG: string = '[ExampleEmbeddedAbility]'; + +export default class ExampleEmbeddedAbility extends EmbeddedUIExtensionAbility { + onCreate() { + console.info(TAG, `onCreate`); + } + + onForeground() { + console.info(TAG, `onForeground`); + } + + onBackground() { + console.info(TAG, `onBackground`); + } + + onDestroy() { + console.info(TAG, `onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + console.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`); + let param: Record = { + 'session': session + }; + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/extension', storage); + } + + onSessionDestroy(session: UIExtensionContentSession) { + console.info(TAG, `onSessionDestroy`); + } +} +``` + +2.EmbeddedUIExtensionAbility的onSessionCreate中加载了入口页面文件pages/extension.ets内容如下。 + +entry/src/main/ets/pages/Extension.ets + +```ts +import { UIExtensionContentSession } from '@kit.AbilityKit'; + +@Entry() +@Component +struct Extension { + @State message: string = 'EmbeddedUIExtensionAbility Index'; + localStorage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage(); + private session: UIExtensionContentSession | undefined = this.localStorage?.get('session'); + + build() { + Column() { + Text(this.message) + .fontSize(20) + .fontWeight(FontWeight.Bold) + Button('terminateSelfWithResult').fontSize(20).onClick(() => { + this.session?.terminateSelfWithResult({ + resultCode: 1, + want: { + bundleName: 'com.example.embeddeddemo', + abilityName: 'ExampleEmbeddedAbility' + }}); + }) + }.width('100%').height('100%') + } +} +``` + +3.在工程Module对应的module.json5配置文件中注册EmbeddedUIExtensionAbility,type标签需要设置为“embeddedUI”,srcEntry标签表示当前EmbeddedUIExtensionAbility组件所对应的代码路径 + +entry/src/main/module.json5 + +```json +{ + "module": { + "extensionAbilities": [ + { + "name": "EmbeddedUIExtAbility", + "icon": "$media:icon", + "description": "EmbeddedUIExtAbility", + "type": "embeddedUI", + "srcEntry": "./ets/EmbeddedUIExtAbility/EmbeddedUIExtAbility.ets" + } + ] + } +} +``` + + +4.开发EmbeddedUIExtensionAbility使用方 + +entry/src/main/ets/pages/Index.ets + +```ts +import { Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + @State message: string = 'Message: ' + private want: Want = { + bundleName: 'com.samples.embeddeduiextensionability', + abilityName: 'EmbeddedUIExtAbility', + parameters: { + 'ohos.extension.processMode.hostInstance': 'true' + } + } + + build() { + Row() { + Column() { + Text(this.message).fontSize(30) + EmbeddedComponent(this.want, EmbeddedType.EMBEDDED_UI_EXTENSION) + .width('100%') + .height('90%') + .onTerminated((info: TerminationInfo) => { + this.message = 'Termination: code = ' + info.code + ', want = ' + JSON.stringify(info.want); + }) + .onError((error: BusinessError) => { + this.message = 'Error: code = ' + error.code; + }) + } + .width('100%') + } + .height('100%') + } +} +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.当前EmbeddedUIExtensionAbility和EmbeddedComponent仅支持在拥有多进程配置的设备上使用,目前支持多进程配置的设备有2in1与Tablet。。 + +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/Ability/EmbeddedUIExtensionAbility > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/EmbeddedUIExtensionAbility/build-profile.json5 b/AbilityKit/EmbeddedUIExtensionAbility/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/AbilityKit/EmbeddedUIExtensionAbility/code-linter.json5 b/AbilityKit/EmbeddedUIExtensionAbility/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/.gitignore b/AbilityKit/EmbeddedUIExtensionAbility/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/build-profile.json5 b/AbilityKit/EmbeddedUIExtensionAbility/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/hvigorfile.ts b/AbilityKit/EmbeddedUIExtensionAbility/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/obfuscation-rules.txt b/AbilityKit/EmbeddedUIExtensionAbility/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/oh-package.json5 b/AbilityKit/EmbeddedUIExtensionAbility/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/embeddeduiextability/EmbeddedUIExtAbility.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/embeddeduiextability/EmbeddedUIExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5a48b5ed99e0f6951dd3b117a1a43f01829f81b --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/embeddeduiextability/EmbeddedUIExtAbility.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 embeddedAbility_start] +import { EmbeddedUIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; + +const TAG: string = '[ExampleEmbeddedAbility]'; + +export default class ExampleEmbeddedAbility extends EmbeddedUIExtensionAbility { + onCreate() { + console.info(TAG, `onCreate`); + } + + onForeground() { + console.info(TAG, `onForeground`); + } + + onBackground() { + console.info(TAG, `onBackground`); + } + + onDestroy() { + console.info(TAG, `onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + console.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`); + let param: Record = { + 'session': session + }; + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/extension', storage); + } + + onSessionDestroy(session: UIExtensionContentSession) { + console.info(TAG, `onSessionDestroy`); + } +} +// [End embeddedAbility_start] \ No newline at end of file diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/BasicClass.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/BasicClass.ets new file mode 100644 index 0000000000000000000000000000000000000000..682e69276dc97ae24dd92020f3528c0eadf7f67a --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/BasicClass.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 embedded_start] +import { Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + @State message: string = 'Message: '; + private want: Want = { + bundleName: 'com.samples.embeddeduiextensionability', + abilityName: 'EmbeddedUIExtAbility', + parameters: { + 'ohos.extension.processMode.hostInstance': 'true' + } + }; + + build() { + Row() { + Column() { + Text(this.message).fontSize(30) + EmbeddedComponent(this.want, EmbeddedType.EMBEDDED_UI_EXTENSION) + .width('100%') + .height('90%') + .onTerminated((info: TerminationInfo) => { + this.message = 'Termination: code = ' + info.code + ', want = ' + JSON.stringify(info.want); + }) + .onError((error: BusinessError) => { + this.message = 'Error: code = ' + error.code; + }) + } + .width('100%') + } + .height('100%') + } +} +// [End embedded_start] \ No newline at end of file diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/Extension.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/Extension.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c7a3b62326085ccab307d1fcf9ef0d04d3f83d1 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/Extension.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start extension_start] +import { UIExtensionContentSession } from '@kit.AbilityKit'; + +@Entry() +@Component +struct Extension { + @State message: string = 'EmbeddedUIExtensionAbility Index'; + localStorage: LocalStorage | undefined = this.getUIContext().getSharedLocalStorage(); + private session: UIExtensionContentSession | undefined = this.localStorage?.get('session'); + + build() { + Column() { + Text(this.message) + .fontSize(20) + .fontWeight(FontWeight.Bold) + Button('terminateSelfWithResult').fontSize(20).onClick(() => { + this.session?.terminateSelfWithResult({ + resultCode: 1, + want: { + bundleName: 'com.samples.embeddeduiextensionability', + abilityName: 'ExampleEmbeddedAbility' + }}); + }) + }.width('100%').height('100%') + } +} +// [End extension_start] diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/Index.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..62ee67f35c118ace0751d172b382a5e2b98d6df5 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Column(){ + Button('BasicClass') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('BasicClass') + .onClick(() => { + router.pushUrl({ + url:'pages/BasicClass' + }) + }) + + Button('Extension') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('Extension') + .onClick(() => { + router.pushUrl({ + url:'pages/Extension' + }) + }) + + } + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/module.json5 b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..12f7754f220a8354a9587ee2a93307b742c57deb --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/module.json5 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start embeddedModule_start] +{ + "module": { + // [StartExclude embeddedModule_start] + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + // [EndExclude embeddedModule_start] + "extensionAbilities": [ + // [StartExclude embeddedModule_start] + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + }, + // [EndExclude embeddedModule_start] + { + "name": "EmbeddedUIExtAbility", + "icon": "$media:startIcon", + "description": "EmbeddedUIExtAbility", + "type": "embeddedUI", + "srcEntry": "./ets/embeddeduiextability/EmbeddedUIExtAbility.ets" + } + ] + } +} +// [End embeddedModule_start] \ No newline at end of file diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/color.json b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/float.json b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/string.json b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/background.png b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/foreground.png b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..96af93621fd7b506700bac4a7ea5a54cffa079de --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/BasicClass", + "pages/Extension" + ] +} diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/dark/element/color.json b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/mock/mock-config.json5 b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f0b6930df0e19c1002a8d234b9f1eb830174aa0 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON, Component, MatchPattern } from '@ohos.UiTest' +import { abilityDelegatorRegistry } from '@kit.TestKit'; +const TAG = '[Sample_EmbeddedUIExtensionAbility]'; +const DOMAIN = 0xF811; +const BUNDLE = 'EmbeddedUIExtensionAbility_'; +const TIME = 500; + +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 () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 begin'); + let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + try { + await abilityDelegator.startAbility({ + bundleName: 'com.samples.embeddeduiextensionability', + abilityName: 'EntryAbility' + }); + await driver.delayMs(1000); + // 获取当前top的ability + let entryAbility = await abilityDelegator.getCurrentTopAbility(); + expect(entryAbility.context.abilityInfo.name).assertEqual('EntryAbility'); + } catch (err) { + hilog.info(DOMAIN, TAG, BUNDLE + 'error: ' + err.message); + expect(err.code).assertEqual(0); + } + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 end'); + }) + 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('EmbeddedUIExtensionAbility_button_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'button_001 begin'); + try { + const button = await driver.findComponent(ON.text('BasicClass')); + await button.click(); + await driver.delayMs(TIME); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'button_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('EmbeddedUIExtensionAbility_button_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'button_002 begin'); + try { + const button = await driver.findComponent(ON.text('Extension')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'button_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('EmbeddedUIExtensionAbility_Extension_001', 0, async (done: () => void) => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(DOMAIN, TAG, BUNDLE + 'Extension_001 begin'); + try { + const button = await driver.findComponent(ON.text('terminateSelfWithResult')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'Extension_001 end'); + await driver.pressBack(); + expect(true).assertTrue(); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(false).assertFalse(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/module.json5 b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..180f312b032f7db2fae63313b6cdcd53e03fb12b --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/EmbeddedUIExtensionAbility/entry/src/test/List.test.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/entry/src/test/LocalUnit.test.ets b/AbilityKit/EmbeddedUIExtensionAbility/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/hvigor/hvigor-config.json5 b/AbilityKit/EmbeddedUIExtensionAbility/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/hvigorfile.ts b/AbilityKit/EmbeddedUIExtensionAbility/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/oh-package.json5 b/AbilityKit/EmbeddedUIExtensionAbility/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/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/AbilityKit/EmbeddedUIExtensionAbility/ohosTest.md b/AbilityKit/EmbeddedUIExtensionAbility/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..c8527bfc610a85262fc465e3a5e7cde0e68aaac3 --- /dev/null +++ b/AbilityKit/EmbeddedUIExtensionAbility/ohosTest.md @@ -0,0 +1,11 @@ +# EmbeddedUIExtensionAbility示例测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------| ------------ | ---- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 基类按钮 | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | +| 扩展按钮 | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | +| terminateSelfWithResult | 设备正常运行 | | 效果正常 | 是 | Pass | + diff --git a/AbilityKit/UIServiceExtensionAbility/.gitignore b/AbilityKit/UIServiceExtensionAbility/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/.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/AbilityKit/UIServiceExtensionAbility/AppScope/app.json5 b/AbilityKit/UIServiceExtensionAbility/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eeb634d05c2109367d0723bc3acaf0b8c0bc8766 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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.uiserviceextensionability", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/element/string.json b/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..11e64c835198917c3adbc15082338a84c6033bc3 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UIServiceExtensionAbility" + } + ] +} diff --git a/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/background.png b/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/foreground.png b/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/layered_image.json b/AbilityKit/UIServiceExtensionAbility/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/README_zh.md b/AbilityKit/UIServiceExtensionAbility/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..8812f81db3bcfe20cde6d12d30597a2b1a156f96 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/README_zh.md @@ -0,0 +1,172 @@ +# UIServiceExtensionAbility简介 + +### 介绍 + +UIServiceExtensionAbility扩展能力是OpenHarmony中用于提供用户界面服务的扩展能力。系统应用可以通过该扩展能力实现特定的UI服务功能,并将其开放给其它应用调用。 + +### 效果预览 + 不涉及。 +### 使用说明 + +1. 通过UIExtensionContext调用startUIServiceExtensionAbility()方法启动UIServiceExtensionAbility。 +2. 通过UIAbilityContext、UIExtensionContext调用connectUIServiceExtensionAbility()方法连接UIServiceExtensionAbility。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── Connect.ets //客户端连接服务 + │ │ ├── Start.ets // 启动 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 具体实现 + +1.启动UIServiceExtensionAbility组件 + +应用通过startUIServiceExtensionAbility()方法启动一个UIServiceExtensionAbility组件。UIServiceExtensionAbility组件启动后,其生命周期独立于客户端,即使客户端已经销毁,该后台服务仍可继续运行,窗口创建失败或销毁后该服务会被销毁。 + +entry/src/main/ets/pages/Index.ets + +```ts +import { common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + // 创建启动按钮 + Button('start UIServiceExtensionAbility') + .enabled(true) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let startWant: Want = { + bundleName: 'com.acts.uiserviceextensionability', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件的包名。 + abilityName: 'UiServiceExtAbility', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件名称。 + }; + try { + // 启动UIServiceExtensionAbility组件 + context.startUIServiceExtensionAbility(startWant).then(() => { + console.info('startUIServiceExtensionAbility success.'); + }).catch((error: BusinessError) => { + console.error(`startUIServiceExtensionAbility failed, err code: ${error.code}, err msg: ${error.message}.`); + }); + } catch (err) { + let code = (err as BusinessError).code; + let msg = (err as BusinessError).message; + console.error(`startUIServiceExtensionAbility failed, err code: ${code}, err msg: ${msg}.`); + } + }) + } + } + } +} +``` + +2.客户端连接服务端 + +客户端通过connectUIServiceExtensionAbility()连接服务端,获取并保存UIServiceProxy对象。通过该proxy对象的sendData()方法发送数据给服务端。服务端通过UIServiceExtensionAbility类onData()(系统接口)方法接收客户端数据。 + +entry/src/main/ets/pages/Connect.ets +```ts +import { common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + comProxy: common.UIServiceProxy | null = null; + connectCallback: common.UIServiceExtensionConnectCallback = { + onData: (data: Record) => { + console.info(`data received, data: ${JSON.stringify(data)}.`); + }, + onDisconnect: () => { + console.info(`onDisconnect.`); + } + } + + build() { + Column() { + Row() { + // 创建连接按钮 + Button('connect ability') + .enabled(true) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let startWant: Want = { + bundleName: 'com.acts.uiserviceextensionability', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件的包名。 + abilityName: 'UiServiceExtAbility', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件名称。 + }; + try { + // 连接UIServiceExtensionAbility组件 + context.connectUIServiceExtensionAbility(startWant, this.connectCallback) + .then((proxy: common.UIServiceProxy) => { + this.comProxy = proxy; + let formData: Record = { + 'test': 'test' + }; + try { + this.comProxy.sendData(formData); + } catch (err) { + let code = (err as BusinessError).code; + let msg = (err as BusinessError).message; + console.error(`sendData failed, err code:${code}, err msg:${msg}.`); + } + }) + .catch((err: BusinessError) => { + console.error(`connectUIServiceExtensionAbility failed, err code: ${err.code}, err msg: ${err.message}.`); + }); + } catch (err) { + let code = (err as BusinessError).code; + let msg = (err as BusinessError).message; + console.error(`connectUIServiceExtensionAbility failed, err code:${code}, err msg:${msg}.`); + } + }) + } + } + } +} +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持2in1设备。 + +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/Ability/UIServiceExtensionAbility > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/UIServiceExtensionAbility/build-profile.json5 b/AbilityKit/UIServiceExtensionAbility/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/AbilityKit/UIServiceExtensionAbility/code-linter.json5 b/AbilityKit/UIServiceExtensionAbility/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/.gitignore b/AbilityKit/UIServiceExtensionAbility/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/build-profile.json5 b/AbilityKit/UIServiceExtensionAbility/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/hvigorfile.ts b/AbilityKit/UIServiceExtensionAbility/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/obfuscation-rules.txt b/AbilityKit/UIServiceExtensionAbility/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/oh-package.json5 b/AbilityKit/UIServiceExtensionAbility/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Connect.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Connect.ets new file mode 100644 index 0000000000000000000000000000000000000000..77376935f4341962c2e1de1295c3755f37dd1f8f --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Connect.ets @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start connect_service_ext_start] +import { common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + comProxy: common.UIServiceProxy | null = null; + connectCallback: common.UIServiceExtensionConnectCallback = { + onData: (data: Record) => { + console.info(`data received, data: ${JSON.stringify(data)}.`); + }, + onDisconnect: () => { + console.info(`onDisconnect.`); + } + } + + build() { + Column() { + Row() { + // 创建连接按钮 + Button('connect ability') + .enabled(true) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let startWant: Want = { + bundleName: 'com.acts.uiserviceextensionability', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件的包名。 + abilityName: 'UiServiceExtAbility', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件名称。 + }; + try { + // 连接UIServiceExtensionAbility组件 + context.connectUIServiceExtensionAbility(startWant, this.connectCallback) + .then((proxy: common.UIServiceProxy) => { + this.comProxy = proxy; + let formData: Record = { + 'test': 'test' + }; + try { + this.comProxy.sendData(formData); + } catch (err) { + let code = (err as BusinessError).code; + let msg = (err as BusinessError).message; + console.error(`sendData failed, err code:${code}, err msg:${msg}.`); + } + }) + .catch((err: BusinessError) => { + console.error(`connectUIServiceExtensionAbility failed, err code: ${err.code}, err msg: ${err.message}.`); + }); + } catch (err) { + let code = (err as BusinessError).code; + let msg = (err as BusinessError).message; + console.error(`connectUIServiceExtensionAbility failed, err code:${code}, err msg:${msg}.`); + } + }) + } + } + } +} +// [End connect_service_ext_start] \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Index.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..03d7c1f2a7c7c8111d3d06b6a8375ef1e703f8ab --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Column(){ + Button('start') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('start button') + .onClick(() => { + router.pushUrl({ + url:'pages/Start' + }) + }) + + Button('connect') + .width('50%') + .height('50vp') + .margin({ top: '40vp' }) + .id('connect button') + .onClick(() => { + router.pushUrl({ + url:'pages/Connect' + }) + }) + + } + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Start.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Start.ets new file mode 100644 index 0000000000000000000000000000000000000000..e20e38b52c5257a7d5c10d7b798c3f9a00abc8c2 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/ets/pages/Start.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start service_ext_start] +import { common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + // 创建启动按钮 + Button('start UIServiceExtensionAbility') + .enabled(true) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let startWant: Want = { + bundleName: 'com.samples.uiserviceextensionability', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件的包名。 + abilityName: 'UiServiceExtAbility', // 仅作为示例代码,需要替换为实际的UIServiceExtensionAbility组件名称。 + }; + try { + // 启动UIServiceExtensionAbility组件 + context.startUIServiceExtensionAbility(startWant).then(() => { + console.info('startUIServiceExtensionAbility success.'); + }).catch((error: BusinessError) => { + console.error(`startUIServiceExtensionAbility failed, err code: ${error.code}, err msg: ${error.message}.`); + }); + } catch (err) { + let code = (err as BusinessError).code; + let msg = (err as BusinessError).message; + console.error(`startUIServiceExtensionAbility failed, err code: ${code}, err msg: ${msg}.`); + } + }) + } + } + } +} +// [End service_ext_start] \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/module.json5 b/AbilityKit/UIServiceExtensionAbility/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c20b71914f625d701fe858e24eb44df15613079d --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/module.json5 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "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" + } + ], + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SYSTEM_FLOAT_WINDOW", + "reason": "$string:permission_reason" + } + ] + } +} \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/color.json b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/float.json b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/string.json b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2f9d30fc04f88e9159d0d138788167b99c353c31 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "permission_reason", + "value": "1234566444" + } + ] +} \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/background.png b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/foreground.png b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..6476c3421e7cd11be2175e44cf75bc2f19b467a4 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/Start", + "pages/Connect" + ] +} diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/dark/element/color.json b/AbilityKit/UIServiceExtensionAbility/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/mock/mock-config.json5 b/AbilityKit/UIServiceExtensionAbility/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..06de673ee87c748e6cb841d8e19211e6669b9177 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/entry/src/ohosTest/ets/test/Ability.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 { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry } from '@kit.TestKit'; +import { Driver, ON, Component, MatchPattern } from '@ohos.UiTest' + +const TAG = '[Sample_UIServiceExtensionAbility]'; +const DOMAIN = 0xF811; +const BUNDLE = 'UIServiceExtensionAbility_'; +const TIME = 500; + +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 () => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 begin'); + let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + try { + await abilityDelegator.startAbility({ + bundleName: 'com.samples.uiserviceextensionability', + abilityName: 'EntryAbility' + }); + await driver.delayMs(1000); + // 获取当前top的ability + let entryAbility = await abilityDelegator.getCurrentTopAbility(); + expect(entryAbility.context.abilityInfo.name).assertEqual('EntryAbility'); + } catch (err) { + hilog.info(DOMAIN, TAG, BUNDLE + 'error: ' + err.message); + expect(err.code).assertEqual(0); + } + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 end'); + }) + 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('UIServiceExtensionAbility_start_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'start_001 begin'); + try { + const button = await driver.findComponent(ON.text('start')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'start_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + it('UIServiceExtensionAbility_start_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'start_002 begin'); + try { + const button = await driver.findComponent(ON.text('start UIServiceExtensionAbility')); + await button.click(); + await driver.delayMs(TIME); + await driver.pressBack(); + hilog.info(DOMAIN, TAG, BUNDLE + 'start_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + + it('UIServiceExtensionAbility_connect_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_001 begin'); + try { + const button = await driver.findComponent(ON.text('connect')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_001 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + + it('UIServiceExtensionAbility_connect_002', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_001 begin'); + try { + const button = await driver.findComponent(ON.text('connect ability')); + await button.click(); + await driver.delayMs(TIME); + hilog.info(DOMAIN, TAG, BUNDLE + 'connect_002 end'); + done(); + } catch (err) { + hilog.info(DOMAIN, TAG, `${BUNDLE} ${err}`); + expect(true).assertTrue(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/ohosTest/module.json5 b/AbilityKit/UIServiceExtensionAbility/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b188ccdd3772c3d946df8843cc4dae17eef4321 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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": [ + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/UIServiceExtensionAbility/entry/src/test/List.test.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/entry/src/test/LocalUnit.test.ets b/AbilityKit/UIServiceExtensionAbility/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/hvigor/hvigor-config.json5 b/AbilityKit/UIServiceExtensionAbility/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/hvigorfile.ts b/AbilityKit/UIServiceExtensionAbility/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/oh-package.json5 b/AbilityKit/UIServiceExtensionAbility/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/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/AbilityKit/UIServiceExtensionAbility/ohosTest.md b/AbilityKit/UIServiceExtensionAbility/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..74951ba98b9b2225e2131f1d2eed326f570f98ae --- /dev/null +++ b/AbilityKit/UIServiceExtensionAbility/ohosTest.md @@ -0,0 +1,11 @@ +# UIServiceExtensionAbility示例测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------| ------------ | ---- |-------------| -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 首页 | 设备正常运行 | | 显示效果正常 | 是 | Pass | +| 启动 | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | +| 连接 | 设备正常运行 | | 正常跳转、显示效果正常 | 是 | Pass | + diff --git a/AbilityKit/WantOverview/.gitignore b/AbilityKit/WantOverview/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/WantOverview/.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/AbilityKit/WantOverview/AppScope/app.json5 b/AbilityKit/WantOverview/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bcb86cf7e6798d8e5b3b8835c36e431bc394ea5b --- /dev/null +++ b/AbilityKit/WantOverview/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.wantoverview", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/WantOverview/AppScope/resources/base/element/string.json b/AbilityKit/WantOverview/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6fdea09476ac2091e81f31ca672bc2d18d217b1b --- /dev/null +++ b/AbilityKit/WantOverview/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "WantOverview" + } + ] +} diff --git a/AbilityKit/WantOverview/AppScope/resources/base/media/background.png b/AbilityKit/WantOverview/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/WantOverview/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/WantOverview/AppScope/resources/base/media/foreground.png b/AbilityKit/WantOverview/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/WantOverview/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/WantOverview/AppScope/resources/base/media/layered_image.json b/AbilityKit/WantOverview/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/README_zh.md b/AbilityKit/WantOverview/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..675ef586c268a33a90664452b498d484d6f2cf1d --- /dev/null +++ b/AbilityKit/WantOverview/README_zh.md @@ -0,0 +1,92 @@ +# Want简介 + +### 介绍 + +Want是一种对象,用于在应用组件之间传递信息。 + +### 效果预览 + +不涉及。 +### 使用说明 + +1. 应用在启动后显示文本"hello world"。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── explicitability + │ │ ├── ExplicitAbility.ets // 显式Want一般使用 + │ │ ├── implicitability + │ │ ├── ImplicitAbility.ets // 隐式Want一般使用 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` +### 具体实现 + +1.通常用于应用内组件启动,通过在Want对象内指定本应用Bundle名称信息(bundleName)和abilityName来启动应用内目标组件。当有明确处理请求的对象时,显式Want是一种简单有效的启动目标应用组件的方式。 + +entry/src/main/ets/explicitability/ExplicitAbility.ets +```ts +import { Want } from '@kit.AbilityKit'; + +let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', +} +``` + +2.隐式Want:在启动目标应用组件时,调用方传入的want参数中未指定abilityName,称为隐式Want + +entry/src/main/ets/implicitability/ImplicitAbility.ets +```ts +import { Want } from '@kit.AbilityKit'; + +let wantInfo: Want = { + // uncomment line below if wish to implicitly query only in the specific bundle. + // bundleName: 'com.example.myapplication', + action: 'ohos.want.action.search', + // entities can be omitted + entities: [ 'entity.system.browsable' ], + uri: 'https://www.test.com:8080/query/student', + type: 'text/plain', +}; +``` +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/Ability/WantOverview > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/WantOverview/build-profile.json5 b/AbilityKit/WantOverview/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/WantOverview/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "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/AbilityKit/WantOverview/code-linter.json5 b/AbilityKit/WantOverview/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/.gitignore b/AbilityKit/WantOverview/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/WantOverview/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/WantOverview/entry/build-profile.json5 b/AbilityKit/WantOverview/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/hvigorfile.ts b/AbilityKit/WantOverview/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/obfuscation-rules.txt b/AbilityKit/WantOverview/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/oh-package.json5 b/AbilityKit/WantOverview/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/WantOverview/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/WantOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/main/ets/explicitability/ExplicitAbility.ets b/AbilityKit/WantOverview/entry/src/main/ets/explicitability/ExplicitAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4deefe5f18110df2bf8815f2dfdc953e20feccf --- /dev/null +++ b/AbilityKit/WantOverview/entry/src/main/ets/explicitability/ExplicitAbility.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start explicit_start] +import { Want } from '@kit.AbilityKit'; + +let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.example.myapplication', + abilityName: 'FuncAbility', +}; +// [End explicit_start] \ No newline at end of file diff --git a/AbilityKit/WantOverview/entry/src/main/ets/implicitability/ImplicitAbility.ets b/AbilityKit/WantOverview/entry/src/main/ets/implicitability/ImplicitAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..01f3bc3f06fcf3510f57b86e4874d2bf6de90417 --- /dev/null +++ b/AbilityKit/WantOverview/entry/src/main/ets/implicitability/ImplicitAbility.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start implicit_start] +import { Want } from '@kit.AbilityKit'; + +let wantInfo: Want = { + // uncomment line below if wish to implicitly query only in the specific bundle. + // bundleName: 'com.example.myapplication', + action: 'ohos.want.action.search', + // entities can be omitted + entities: [ 'entity.system.browsable' ], + uri: 'https://www.test.com:8080/query/student', + type: 'text/plain', +}; +// [End implicit_start] \ No newline at end of file diff --git a/AbilityKit/WantOverview/entry/src/main/ets/pages/Index.ets b/AbilityKit/WantOverview/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..64ca99781cb5c3e261ecdd74d316c6fa7cec67e4 --- /dev/null +++ b/AbilityKit/WantOverview/entry/src/main/ets/pages/Index.ets @@ -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. + */ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/AbilityKit/WantOverview/entry/src/main/module.json5 b/AbilityKit/WantOverview/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bd1eba7933749ddb86019480863694d6259cb76e --- /dev/null +++ b/AbilityKit/WantOverview/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", + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon" : "$media:startIcon", + "startWindowBackground" : "$color:start_window_background" + , + "exported": true + , + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "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/AbilityKit/WantOverview/entry/src/main/resources/base/element/color.json b/AbilityKit/WantOverview/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/main/resources/base/element/float.json b/AbilityKit/WantOverview/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/WantOverview/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/WantOverview/entry/src/main/resources/base/element/string.json b/AbilityKit/WantOverview/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/main/resources/base/media/background.png b/AbilityKit/WantOverview/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/WantOverview/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/WantOverview/entry/src/main/resources/base/media/foreground.png b/AbilityKit/WantOverview/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/WantOverview/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/WantOverview/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/WantOverview/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/WantOverview/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/WantOverview/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/WantOverview/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/WantOverview/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/WantOverview/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/AbilityKit/WantOverview/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/WantOverview/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/AbilityKit/WantOverview/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/AbilityKit/WantOverview/entry/src/main/resources/dark/element/color.json b/AbilityKit/WantOverview/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/mock/mock-config.json5 b/AbilityKit/WantOverview/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/WantOverview/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..99591ca8c03c54549f80ec7cb470525cab5b2750 --- /dev/null +++ b/AbilityKit/WantOverview/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +const TAG = '[Sample_WantOverview]'; +const DOMAIN = 0xF811; +const BUNDLE = 'WantOverview_'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('WantOverview_Startup_001', 0, async (done: () => void) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'Startup_001 begin'); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + try { + await abilityDelegator.startAbility({ + bundleName: 'com.samples.wantoverview', + abilityName: 'EntryAbility' + }); + done(); + } + catch (expection) { + hilog.info(DOMAIN, TAG, BUNDLE + `Startup_001 end ${JSON.stringify(expection)}`); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/AbilityKit/WantOverview/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/WantOverview/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/ohosTest/module.json5 b/AbilityKit/WantOverview/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..12ddf9861a24545643847583653f531bf1679c6c --- /dev/null +++ b/AbilityKit/WantOverview/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", + "2in1", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/WantOverview/entry/src/test/List.test.ets b/AbilityKit/WantOverview/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/entry/src/test/LocalUnit.test.ets b/AbilityKit/WantOverview/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/hvigor/hvigor-config.json5 b/AbilityKit/WantOverview/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/hvigorfile.ts b/AbilityKit/WantOverview/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/oh-package.json5 b/AbilityKit/WantOverview/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/WantOverview/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/AbilityKit/WantOverview/ohosTest.md b/AbilityKit/WantOverview/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..21936b96354452690bcb437c04a14f3542ba9e38 --- /dev/null +++ b/AbilityKit/WantOverview/ohosTest.md @@ -0,0 +1,8 @@ +# WantOverview示例测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ---- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +