diff --git a/AbilityKit/AppLinking/.gitignore b/AbilityKit/AppLinking/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/AppLinking/.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/AppLinking/AppScope/app.json5 b/AbilityKit/AppLinking/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9594896730261656ec30be17563aab812cf5d733 --- /dev/null +++ b/AbilityKit/AppLinking/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.example.applinking", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/AppLinking/AppScope/resources/base/element/string.json b/AbilityKit/AppLinking/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0864daa0eed66e0272cd3b18180e23aa9321ad32 --- /dev/null +++ b/AbilityKit/AppLinking/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AppLinking" + } + ] +} diff --git a/AbilityKit/AppLinking/AppScope/resources/base/media/background.png b/AbilityKit/AppLinking/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/AppLinking/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/AppLinking/AppScope/resources/base/media/foreground.png b/AbilityKit/AppLinking/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/AppLinking/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/AppLinking/AppScope/resources/base/media/layered_image.json b/AbilityKit/AppLinking/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/README_zh.md b/AbilityKit/AppLinking/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..0050c5de9a82661841331454797d12ef666b9bc4 --- /dev/null +++ b/AbilityKit/AppLinking/README_zh.md @@ -0,0 +1,85 @@ +# App Linking应用间跳转 + +### 介绍 + +应用间跳转主要有App Linking和Deep Linking两种方式。以下主要讲解使用AppLinking方式: +使用App Linking进行跳转时,系统会根据接口传入的uri信息(HTTPS链接)将用户引导至目标应用中的特定内容,无论应用是否已安装,用户都可以访问到链接对应的内容,跳转体验相比Deep Linking方式更加顺畅。二者相比如下: + +1. App Linking在Deep Linking基础上增加了域名校验环节,通过域名校验,可帮助用户消除歧义,识别合法归属于域名的应用,使链接更加安全可靠。 +2. App Linking要求对于同一HTTPS网址,有应用和网页两种内容的呈现方式。当应用安装时则优先打开应用去呈现内容;当应用未安装时,则打开浏览器呈现Web版的内容。 + +### 效果预览 + +不涉及。 + +### 使用说明 + +1. 前期准备: + 需在开发者平台(如 OpenHarmony 应用市场)配置 App Linking 域名,完成域名与应用的关联验证(确保 HTTPS 链接能被正确解析到目标应用)。 + 准备两个应用(调用方和目标应用),或在同一工程中通过多 Ability 模拟跨应用场景。 +2. 操作步骤: + 调用方应用:在页面中触发跳转逻辑(如点击按钮),通过openLink接口传入 App Linking 的 HTTPS 链接。 + 目标应用:配置module.json5以支持该链接,并在 Ability 中处理链接解析与页面导航。 + 测试场景:分别在 “目标应用已安装” 和 “未安装” 两种状态下验证跳转效果。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── common + │ │ ├── GlobalContext.ets // AppLink 获取应用上下文的接口 + │ │ ├── entryability + │ │ ├── AppLinkEntryAbility.ets // AppLink 拉起应用的元能力 + │ │ ├── EntryAbility.ets + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // AppLink 拉起应用界面 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 具体实现 + +* 目标应用配,配置参考:[module.json5](./entry/src/main/module.json5) + * 在目标应用的module.json5中声明支持的 App Linking 规则,确保系统能将 HTTPS 链接匹配到该应用。 + * AppLinking/entry/src/ohosTest/module.json5 +* 全局上下文工具,源码参考:[GlobalContext.ets](./entry/src/main/ets/common/GlobalContext.ets) + * 提供全局上下文访问能力,方便页面获取UIAbilityContext以调用openLink接口。 +* 调用方跳转逻辑,源码参考:[Index.ets](./entry/src/main/ets/pages/Index.ets) + * 在页面中触发 App Linking 跳转,通过openLink接口传入 HTTPS 链接。 +* 目标应用处理跳转,源码参考:[AppLinkEntryAbility.ets](./entry/src/main/ets/entryability/AppLinkEntryAbility.ets) + * 在目标应用的 Ability 中解析 App Linking 链接,提取参数并导航至对应页面。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/AppLinking > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/AppLinking/build-profile.json5 b/AbilityKit/AppLinking/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/code-linter.json5 b/AbilityKit/AppLinking/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/.gitignore b/AbilityKit/AppLinking/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/AppLinking/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/AppLinking/entry/build-profile.json5 b/AbilityKit/AppLinking/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/hvigorfile.ts b/AbilityKit/AppLinking/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/obfuscation-rules.txt b/AbilityKit/AppLinking/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/oh-package.json5 b/AbilityKit/AppLinking/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/main/ets/common/GlobalContext.ets b/AbilityKit/AppLinking/entry/src/main/ets/common/GlobalContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..8687b1c925dfd3cade6b757003cb7e9ed46dc8fe --- /dev/null +++ b/AbilityKit/AppLinking/entry/src/main/ets/common/GlobalContext.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 quick_start0] +import { common } from '@kit.AbilityKit'; + +export class GlobalContext { + private static context: common.UIAbilityContext; + + public static initContext(context: common.UIAbilityContext): void { + GlobalContext.context = context; + } + + public static getContext(): common.UIAbilityContext { + return GlobalContext.context; + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/AppLinking/entry/src/main/ets/entryability/AppLinkEntryAbility.ets b/AbilityKit/AppLinking/entry/src/main/ets/entryability/AppLinkEntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..51b79619b01bc749533701cd79d6a1a373be565d --- /dev/null +++ b/AbilityKit/AppLinking/entry/src/main/ets/entryability/AppLinkEntryAbility.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { url } from '@kit.ArkTS'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 从want中获取传入的链接信息。 + // 如传入的url为:https://www.example.com/programs?action=showall + let uri = want?.uri; + if (uri) { + // 从链接中解析query参数,拿到参数后,开发者可根据自己的业务需求进行后续的处理。 + let urlObject = url.URL.parseURL(want?.uri); + let action = urlObject.params.get('action'); + // 例如,当action为showall时,展示所有的节目。 + if (action === 'showall') { + // ... + } + } + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/AppLinking/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/AppLinking/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/AppLinking/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/main/ets/pages/Index.ets b/AbilityKit/AppLinking/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..45c76faa1fcd13ac36ce09d387759b942d43ea75 --- /dev/null +++ b/AbilityKit/AppLinking/entry/src/main/ets/pages/Index.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 quick_start0] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { GlobalContext } from '../common/GlobalContext'; + +@Entry +@Component +struct Index { + build() { + Button('start link', { type: ButtonType.Capsule, stateEffect: true }) + .width('87%') + .height('5%') + .margin({ bottom: '12vp' }) + .onClick(() => { + let context = GlobalContext.getContext(); + let link: string = 'https://www.example.com/programs?action=showall'; + // 仅以App Linking的方式打开应用 + context.openLink(link, { appLinkingOnly: true }) + .then(() => { + hilog.info(0x0000, 'testTag', `Succeeded in opening link.`); + }) + .catch((error: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to open link, code: ${error.code}, message: ${error.message}`); + }) + }) + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/AppLinking/entry/src/main/module.json5 b/AbilityKit/AppLinking/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..00f4eca7f52bb0c2445d88708ecd7244c4252009 --- /dev/null +++ b/AbilityKit/AppLinking/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. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + // [Start quick_start0] + { + // [StartExclude quick_start0] + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "icon": "$media:startIcon", + "label": "$string:EntryAbility_label", + // 请将exported配置为true;如果exported为false,仅具有权限的系统应用能够拉起该应用,否则无法拉起应用 + "exported": true, + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + // [EndExclude quick_start0] + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + }, + { + "entities": [ + // entities须包含"entity.system.browsable" + "entity.system.browsable" + ], + "actions": [ + // actions须包含"ohos.want.action.viewData" + "ohos.want.action.viewData" + ], + "uris": [ + { + // scheme须配置为https + "scheme": "https", + // host须配置关联的域名 + "host": "www.example.com", + // path可选,为了避免匹配到多个应用,建议配置该字段 + "path": "path1" + } + ], + // domainVerify须设置为true + "domainVerify": true + } // 新增一个skill对象,用于跳转场景。如果存在多个跳转场景,需配置多个skill对象。 + ] + }, + // [End quick_start0] + { + "name": "AppLinkEntryAbility", + "srcEntry": "./ets/entryability/AppLinkEntryAbility.ets", + "description": "$string:EntryAbility_desc", + "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/AppLinking/entry/src/main/resources/base/element/color.json b/AbilityKit/AppLinking/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/main/resources/base/element/float.json b/AbilityKit/AppLinking/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/AppLinking/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/AppLinking/entry/src/main/resources/base/element/string.json b/AbilityKit/AppLinking/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/main/resources/base/media/background.png b/AbilityKit/AppLinking/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/AppLinking/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/AppLinking/entry/src/main/resources/base/media/foreground.png b/AbilityKit/AppLinking/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/AppLinking/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/AppLinking/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/AppLinking/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/AppLinking/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/AppLinking/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/AppLinking/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/AppLinking/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/AppLinking/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/AbilityKit/AppLinking/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/AbilityKit/AppLinking/entry/src/main/resources/dark/element/color.json b/AbilityKit/AppLinking/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/mock/mock-config.json5 b/AbilityKit/AppLinking/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/AppLinking/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..489c4ef8df0780b555c7e2b6d2f4caed9e29bf8e --- /dev/null +++ b/AbilityKit/AppLinking/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_AppLinking]'; + +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + /** + * @tc.number SUB_AppLink1 + * @tc.name SUB_AppLink1 + * @tc.desc test AppLink1 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_AppLink1', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.applinking', + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_AppLink2 + * @tc.name SUB_AppLink12 + * @tc.desc test AppLink2 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_AppLink2', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.applinking', + abilityName: 'AppLinkEntryAbility' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + }) +} \ No newline at end of file diff --git a/AbilityKit/AppLinking/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/AppLinking/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/ohosTest/module.json5 b/AbilityKit/AppLinking/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1cafc28b86d7d9f2b34f24d26a75c0dbd7299715 --- /dev/null +++ b/AbilityKit/AppLinking/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": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/AppLinking/entry/src/test/List.test.ets b/AbilityKit/AppLinking/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/entry/src/test/LocalUnit.test.ets b/AbilityKit/AppLinking/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/hvigor/hvigor-config.json5 b/AbilityKit/AppLinking/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/hvigorfile.ts b/AbilityKit/AppLinking/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/oh-package.json5 b/AbilityKit/AppLinking/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/AppLinking/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/AppLinking/ohosTest.md b/AbilityKit/AppLinking/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..bb1902b0aaece0bfc9478754844f966231ae8f13 --- /dev/null +++ b/AbilityKit/AppLinking/ohosTest.md @@ -0,0 +1,8 @@ +# 使用App Linking实现应用间跳转 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------| ------------ | ---- |----------------------------| -------- | -------- | +| 使用App Linking实现应用间跳转 | 设备正常运行 | | 使用App Linking实现应用间跳转,不出现异常 | 是 | Pass | + diff --git a/AbilityKit/EnvConfig/.gitignore b/AbilityKit/EnvConfig/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/EnvConfig/.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/EnvConfig/AppScope/app.json5 b/AbilityKit/EnvConfig/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..95ab14230c86e3f3c8685acb1824df85e95a3b78 --- /dev/null +++ b/AbilityKit/EnvConfig/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.example.envconfig", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/EnvConfig/AppScope/resources/base/element/string.json b/AbilityKit/EnvConfig/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..54911d382eff0d4811394e285e0c71ce1b722288 --- /dev/null +++ b/AbilityKit/EnvConfig/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "envConfig" + } + ] +} diff --git a/AbilityKit/EnvConfig/AppScope/resources/base/media/background.png b/AbilityKit/EnvConfig/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/EnvConfig/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/EnvConfig/AppScope/resources/base/media/foreground.png b/AbilityKit/EnvConfig/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/EnvConfig/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/EnvConfig/AppScope/resources/base/media/layered_image.json b/AbilityKit/EnvConfig/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/README_zh.md b/AbilityKit/EnvConfig/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..45c77d6ecd2b340acc27a18896419721ae7a970c --- /dev/null +++ b/AbilityKit/EnvConfig/README_zh.md @@ -0,0 +1,98 @@ +# 获取/设置环境变量 + +### 介绍 + +环境变量涵盖了所有可能影响应用运行时的环境配置信息,包括应用可指定的内部环境变量(字体大小、外观、语言等)和应用可感知的外部环境变量(屏幕方向等)。环境变量的操作主要包含获取环境变量和设置环境变量两种方式。具体如下: +1. 获取环境变量 + 开发者通过使用getConfigurationSync主动获取当前环境变量,包括深浅色模式、屏幕方向、语言地区、屏幕密度、设备类型等,对应用程序作出相应处理,提供更好的用户体验。 +2. 设置环境变量 + 设置环境变量主要包含 设置字体大小、设置深浅色模式、设置应用语言。通过setFontSizeScale设置应用字体大小、使用setColorMode设置应用和UIAbility的深浅模式、使用setLanguage设置应用语言。 + +### 效果预览 + +不涉及。 + +### 使用说明 + +1. 功能入口:启动应用后,通过首页(Index.ets)可进入环境变量管理、应用异常退出原因查询、应用间跳转等功能模块。 +2. 环境变量获取操作: + 在首页触发 “获取环境变量” 功能,系统通过 Want 拉起EnvAbility0.ets元能力。 + 元能力执行getConfigurationSync接口获取配置,可通过日志输出或页面展示结果。 +3. 环境变量设置操作: + 进入 “设置环境变量” 模块,系统拉起EnvAbility6.ets或EnvAbility7.ets元能力,并加载对应页面(EnvAbility6Page.ets/EnvAbility7Page.ets)。 + 在设置页面通过开关、滑块等控件修改字体大小、深浅色模式等,操作后配置即时生效。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── EnvAbility // 获取/设置环境变量 + │ │ ├── EnvAbility0.ets + │ │ ├── EnvAbility1.ets + │ │ ├── EnvAbility2.ets + │ │ ├── EnvAbility3.ets + │ │ ├── EnvAbility4.ets + │ │ ├── EnvAbility5.ets + │ │ ├── EnvAbility6.ets + │ │ ├── EnvAbility7.ets + │ │ ├── EnvAbility8.ets + │ │ ├── EnvAbility9.ets + │ │ ├── EnvAbility10.ets + │ │ ├── MyAbility // 获取应用异常退出原因 + │ │ ├── MyAbility1.ets + │ │ ├── MyAbility2.ets + │ │ ├── OpenApp // 应用间跳转 + │ │ ├── OpenAppAbility1.ets + │ │ ├── pages + │ │ ├── EnvAbilityPage6.ets // 设置环境变量页面对应其元能力EnvAbility6 + │ │ ├── EnvAbilityPage7.ets // 设置环境变量页面对应其元能力EnvAbility7 + │ │ ├── Index.ets // 首页 + │ │ ├── OpenAppPage.ets // 应用间跳转页面 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` +### 具体实现 + +* 核心实现逻辑框架 + * 环境变量管理采用 “Want 拉起元能力→元能力加载对应页面” 的流程,核心分为获取与设置两大模块,各模块对应明确的元能力与页面文件。 +* 环境变量获取实现: + * 通过getConfigurationSync接口获取系统与应用的环境配置。源码参考:[EnvAbility0.ets](./entry/src/main/ets/EnvAbility/EnvAbility0.ets) +* 环境变量设置实现: + * 设置字体大小:通过函数setFontSizeScale设置字体大小。源码参考:[EnvAbility1.ets](./entry/src/main/ets/EnvAbility/EnvAbility1.ets) + * 设置深浅色模式:通过函数setColorMode设置深浅色模式。源码参考:[EnvAbility2.ets](./entry/src/main/ets/EnvAbility/EnvAbility2.ets) + * 设置应用语言:通过函数setLanguage设置应用语言。源码参考:[EnvAbility5.ets](./entry/src/main/ets/EnvAbility/EnvAbility5.ets) +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/EnvConfig > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/EnvConfig/build-profile.json5 b/AbilityKit/EnvConfig/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/code-linter.json5 b/AbilityKit/EnvConfig/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/.gitignore b/AbilityKit/EnvConfig/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/build-profile.json5 b/AbilityKit/EnvConfig/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/hvigorfile.ts b/AbilityKit/EnvConfig/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/obfuscation-rules.txt b/AbilityKit/EnvConfig/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/oh-package.json5 b/AbilityKit/EnvConfig/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility0.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility0.ets new file mode 100644 index 0000000000000000000000000000000000000000..fefdc3bf8581a4a6c893bfe7ea0769893e43a298 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility0.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +// [StartExclude quick_start0] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_EnvConfig]'; +// [EndExclude quick_start0] +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + let value = this.context.resourceManager.getConfigurationSync(); + // 屏幕方向 + let direction = value.direction; + // 语言文字国家地区 + let locale = value.locale; + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'getConfigurationSync error is ' + error); + } + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility1.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility1.ets new file mode 100644 index 0000000000000000000000000000000000000000..6870fecf1530775784e326e8e919513f59225e0b --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility1.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. + */ +// [Start quick_start0] +import { UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; + +export default class MyAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + let applicationContext = this.context.getApplicationContext(); + applicationContext.setFontSizeScale(2); + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility10.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility10.ets new file mode 100644 index 0000000000000000000000000000000000000000..1150149c7bddf21249edd67b34b0f745a0c04e76 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility10.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 quick_start0] +import { FormExtensionAbility } from '@kit.FormKit'; +import { Configuration } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[EntryAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryFormAbility extends FormExtensionAbility { + onConfigurationUpdate(newConfig: Configuration) { + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onConfigurationUpdate: ' + JSON.stringify(newConfig)); + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility2.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility2.ets new file mode 100644 index 0000000000000000000000000000000000000000..ccf02ae5bfa4426ede3901d91fb1f7f0483451a0 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility2.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { UIAbility, ConfigurationConstant } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class MyAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content.'); + return; + } + let applicationContext = this.context.getApplicationContext(); + applicationContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + }); + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility3.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility3.ets new file mode 100644 index 0000000000000000000000000000000000000000..9dbf6eb3e6dd84040f5f34275ac276f407ec1669 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility3.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { UIAbility, ConfigurationConstant } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class MyAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content.'); + return; + } + let uiAbilityContext = this.context; + uiAbilityContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + }); + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility4.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility4.ets new file mode 100644 index 0000000000000000000000000000000000000000..b8262c2313b328425bc7abc76d9fe0c22ee6f4bc --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility4.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 quick_start0] +// UIExtensionAbility不支持三方应用直接继承,故以派生类ShareExtensionAbility举例说明。 +import { ShareExtensionAbility, ConfigurationConstant } from '@kit.AbilityKit'; + +export default class MyAbility extends ShareExtensionAbility { + onForeground() { + let uiExtensionContext = this.context; + uiExtensionContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility5.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility5.ets new file mode 100644 index 0000000000000000000000000000000000000000..85d5f36638a701338549be6c3f1c1e08a18a332c --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility5.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { UIAbility } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class MyAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content.'); + return; + } + let applicationContext = this.context.getApplicationContext(); + applicationContext.setLanguage('zh-cn'); + }); + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility6.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility6.ets new file mode 100644 index 0000000000000000000000000000000000000000..cbe357f981b5afdcceddd0e1c142b132f1ad2708 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility6.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/EnvAbilityPage6', (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/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility7.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility7.ets new file mode 100644 index 0000000000000000000000000000000000000000..53b1d0626a043f4bc06bc38ec1e1bac9257f0aef --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility7.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/EnvAbilityPage7', (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/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility8.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility8.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f65a1c5a68d08282ea1eaacda8d95856625016f --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility8.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { AbilityStage, Configuration } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[MyAbilityStage]'; +const DOMAIN_NUMBER: number = 0xFF00; + +let systemLanguage: string | undefined; // 系统当前语言 + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + systemLanguage = this.context.config.language; // Module首次加载时,获取系统当前语言 + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage is ${systemLanguage}`); + } + + onConfigurationUpdate(newConfig: Configuration): void { + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdate, language: ${newConfig.language}`); + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); + + if (systemLanguage !== newConfig.language) { + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); + systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 + } + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility9.ets b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility9.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4e5fd5a70511fbefcff26f57320ed72571835b5 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/EnvAbility/EnvAbility9.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { AbilityConstant, Configuration, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[EntryAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +let systemLanguage: string | undefined; // 系统当前语言 + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + systemLanguage = this.context.config.language; // UIAbility实例首次加载时,获取系统当前语言 + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage is ${systemLanguage}`); + } + + onConfigurationUpdate(newConfig: Configuration): void { + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); + + if (systemLanguage !== newConfig.language) { + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); + systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 + } + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/EnvConfig/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/EnvConfig/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/ets/pages/EnvAbilityPage6.ets b/AbilityKit/EnvConfig/entry/src/main/ets/pages/EnvAbilityPage6.ets new file mode 100644 index 0000000000000000000000000000000000000000..374d3617ceb907853ce1ef409898e7d438c1a79d --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/pages/EnvAbilityPage6.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. + */ +// [Start quick_start0] +import { common, EnvironmentCallback, Configuration } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[MyAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + private callbackId: number = 0; // 注册订阅系统环境变化的ID + + subscribeConfigurationUpdate(): void { + let systemLanguage: string | undefined = this.context.config.language; // 获取系统当前语言 + + // 1.获取ApplicationContext + let applicationContext = this.context.getApplicationContext(); + + // 2.通过applicationContext订阅环境变量变化 + let environmentCallback: EnvironmentCallback = { + onConfigurationUpdated(newConfig: Configuration) { + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); + if (systemLanguage !== newConfig.language) { + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); + systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 + } + }, + onMemoryLevel(level) { + hilog.info(DOMAIN_NUMBER, TAG, `onMemoryLevel level: ${level}`); + } + } + try { + this.callbackId = applicationContext.on('environment', environmentCallback); + } 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}`); + } + } + + // 页面展示 + build() { + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/pages/EnvAbilityPage7.ets b/AbilityKit/EnvConfig/entry/src/main/ets/pages/EnvAbilityPage7.ets new file mode 100644 index 0000000000000000000000000000000000000000..40e07641606384335aa5f8084139deb240214d2b --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/ets/pages/EnvAbilityPage7.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 quick_start0] +import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[MyAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + private callbackId: number = 0; // 注册订阅系统环境变化的ID + + unsubscribeConfigurationUpdate() { + let applicationContext = this.context.getApplicationContext(); + try { + applicationContext.off('environment', this.callbackId); + } 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}`); + } + } + + // 页面展示 + build() { + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/ets/pages/Index.ets b/AbilityKit/EnvConfig/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..64ca99781cb5c3e261ecdd74d316c6fa7cec67e4 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/module.json5 b/AbilityKit/EnvConfig/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..766f9914fbd7f633666c89a3815d48f20a18103c --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/module.json5 @@ -0,0 +1,295 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "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": "EnvAbility0", + "srcEntry": "./ets/EnvAbility/EnvAbility0.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility1", + "srcEntry": "./ets/EnvAbility/EnvAbility1.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility2", + "srcEntry": "./ets/EnvAbility/EnvAbility2.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility3", + "srcEntry": "./ets/EnvAbility/EnvAbility3.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility4", + "srcEntry": "./ets/EnvAbility/EnvAbility4.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility5", + "srcEntry": "./ets/EnvAbility/EnvAbility5.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility6", + "srcEntry": "./ets/EnvAbility/EnvAbility6.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility7", + "srcEntry": "./ets/EnvAbility/EnvAbility7.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility8", + "srcEntry": "./ets/EnvAbility/EnvAbility8.ets", + "description": "$string:EntryAbility_desc", + "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": "EnvAbility9", + "srcEntry": "./ets/EnvAbility/EnvAbility9.ets", + "description": "$string:EntryAbility_desc", + "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" + ] + }, + { + // actions不能为空,actions为空会造成目标方匹配失败 + "actions": ["ohos.want.action.home"], + "uris": [ + { + "scheme": "app1Scheme", + "host": "test.example.com", + "pathStartWith": "home" + } + ] + } + ] + }, + { + "name": "EnvAbility10", + "srcEntry": "./ets/EnvAbility/EnvAbility10.ets", + "description": "$string:EntryAbility_desc", + "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/EnvConfig/entry/src/main/resources/base/element/color.json b/AbilityKit/EnvConfig/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/resources/base/element/float.json b/AbilityKit/EnvConfig/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/EnvConfig/entry/src/main/resources/base/element/string.json b/AbilityKit/EnvConfig/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/resources/base/media/background.png b/AbilityKit/EnvConfig/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/EnvConfig/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/EnvConfig/entry/src/main/resources/base/media/foreground.png b/AbilityKit/EnvConfig/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/EnvConfig/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/EnvConfig/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/EnvConfig/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/EnvConfig/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/EnvConfig/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/EnvConfig/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/EnvConfig/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/EnvConfig/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..8553e0da3ac9e90fd8a466c126247a4ef2de6486 --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/EnvAbilityPage6", + "pages/EnvAbilityPage7" + ] +} \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/main/resources/dark/element/color.json b/AbilityKit/EnvConfig/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/mock/mock-config.json5 b/AbilityKit/EnvConfig/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/EnvConfig/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..adba668cbc7c222d75a647f8756e73b648dd79cf --- /dev/null +++ b/AbilityKit/EnvConfig/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,383 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 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 { UIAbility, Want } from '@kit.AbilityKit'; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_EnvConfig]'; +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + + + /** + * @tc.number SUB_EnvAbility0 + * @tc.name SUB_EnvEntryAbility + * @tc.desc test EnvAbility0 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility0', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility0' + }; + await delegator.startAbility(want); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + /** + * @tc.number SUB_EnvAbility1 + * @tc.name SUB_EnvAbility1 + * @tc.desc test Ability1 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility1', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility1' + }; + await delegator.startAbility(want); + //const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_EnvAbility2 + * @tc.name SUB_EnvAbility2 + * @tc.desc test MyAbility2 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility2', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility2' + }; + await delegator.startAbility(want); + //const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_EnvAbility3 + * @tc.name SUB_EnvAbility3 + * @tc.desc test MyAbility3 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility3', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility3' + }; + await delegator.startAbility(want); + //const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_EnvAbility4 + * @tc.name SUB_EnvAbility4 + * @tc.desc test MyAbility4 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility4', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility4' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_EnvAbility5 + * @tc.name SUB_EnvAbility5 + * @tc.desc test MyAbility5 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility5', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility5' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + /** + * @tc.number SUB_EnvAbility6 + * @tc.name SUB_EnvAbility6 + * @tc.desc test MyAbility6 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility6', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility6' + }; + // router.pushUrl({url: 'pages/EnvAbility6'}) + //router.pushUrl({url: 'pages/Index'}) + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + /** + * @tc.number SUB_EnvAbility7 + * @tc.name SUB_EnvAbility7 + * @tc.desc test MyAbility7 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility7', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility7' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(6000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + /** + * @tc.number SUB_EnvAbility8 + * @tc.name SUB_EnvAbility8 + * @tc.desc test MyAbility8 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility8', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility8' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + /** + * @tc.number SUB_EnvAbility9 + * @tc.name SUB_EnvAbility9 + * @tc.desc test MyAbility9 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility9', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility9' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + // await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + /** + * @tc.number SUB_EnvAbility10 + * @tc.name SUB_EnvAbility10 + * @tc.desc test MyAbility10 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_EnvAbility10', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER, TAG, 'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.envconfig', + abilityName: 'EnvAbility10' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + // await sleep(2000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + }) +} \ No newline at end of file diff --git a/AbilityKit/EnvConfig/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/EnvConfig/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/ohosTest/module.json5 b/AbilityKit/EnvConfig/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1cafc28b86d7d9f2b34f24d26a75c0dbd7299715 --- /dev/null +++ b/AbilityKit/EnvConfig/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": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/EnvConfig/entry/src/test/List.test.ets b/AbilityKit/EnvConfig/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/entry/src/test/LocalUnit.test.ets b/AbilityKit/EnvConfig/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/hvigor/hvigor-config.json5 b/AbilityKit/EnvConfig/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/hvigorfile.ts b/AbilityKit/EnvConfig/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/oh-package.json5 b/AbilityKit/EnvConfig/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/EnvConfig/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/EnvConfig/ohosTest.md b/AbilityKit/EnvConfig/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..9fde2e38c7b84f81207ebae6c2978153bb1a9930 --- /dev/null +++ b/AbilityKit/EnvConfig/ohosTest.md @@ -0,0 +1,10 @@ +# 获取/设置环境变量 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|----------| ------------ | ---- |------------| -------- | -------- | +| 获取环境变量 | 设备正常运行 | | 环境变量获取成功 | 是 | Pass | +| -------- | ------------ | ---- | ---------- | -------- | -------- | +| 设置环境变量 | 设备正常运行 | | 环境变量设置成功 | 是 | Pass | + diff --git a/AbilityKit/PullLinking/.gitignore b/AbilityKit/PullLinking/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/PullLinking/.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/PullLinking/AppScope/app.json5 b/AbilityKit/PullLinking/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c7975bcb59150af02fe38a10c101651a139927e1 --- /dev/null +++ b/AbilityKit/PullLinking/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.example.pulllinking", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/PullLinking/AppScope/resources/base/element/string.json b/AbilityKit/PullLinking/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b053bc1c88dfdefbb9dc51cb31cf1475f67c6826 --- /dev/null +++ b/AbilityKit/PullLinking/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Linking" + } + ] +} diff --git a/AbilityKit/PullLinking/AppScope/resources/base/media/background.png b/AbilityKit/PullLinking/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/PullLinking/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/PullLinking/AppScope/resources/base/media/foreground.png b/AbilityKit/PullLinking/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/PullLinking/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/PullLinking/AppScope/resources/base/media/layered_image.json b/AbilityKit/PullLinking/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/README_zh.md b/AbilityKit/PullLinking/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..1181bfadefb813b392bea466dba2433954572c57 --- /dev/null +++ b/AbilityKit/PullLinking/README_zh.md @@ -0,0 +1,83 @@ +# 应用间跳转 + +### 介绍 + +应用间跳转是 OpenHarmony 系统中实现跨应用协作的核心能力,支持从当前应用(调用方)拉起目标应用(被调用方),并可伴随数据传递、指定页面唤起、特定功能触发等场景。本工程聚焦应用间跳转的核心实现方案,覆盖兼容性判断、主流跳转方式、版本适配规范及配置说明,为开发者提供标准化的跨应用交互开发参考。​ +本工程主要包含四大核心内容: +1. 应用可访问性预检(canOpenLink): + 调用方应用在发起跳转前,通过canOpenLink接口预先检测目标应用是否已安装、且其配置的链接协议可被系统识别,避免因目标应用缺失导致的跳转失败,提升交互稳定性。​ +2. Deep Linking 跳转实现: + 基于统一资源标识符(URI)的跳转方案,调用方通过openLink接口传入目标应用的 URI,系统自动扫描本地已安装应用,匹配与 URI 协议匹配的应用并拉起;若存在多个匹配应用,将弹出应用选择弹窗供用户决策。 +3. 显式 Want 跳转版本适配: + 针对系统版本迭代的适配指导:自 API 12 开始,系统不再推荐第三方应用基于 “指定 Ability 名称” 的显式 Want 方式拉起目标应用,强制要求采用 “基于 URI 协议的应用链接” 方式实现跳转,以提升应用间交互的规范性和兼容性。 +4. 应用链接(URI)配置说明: + 被调用方应用需在配置文件module.json5的skills字段中声明uris信息,明确自身可被唤起的协议规则,核心配置字段包括schem(协议名)、host(主机名)、port(端口)、path(路径)、linkFeature(链接功能标识)等。 + +### 效果预览 + +不涉及。 + +### 使用说明 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── OpenApp // 应用间跳转 + │ │ ├── OpenAppAbility1.ets + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── OpenAppPage1.ets // 应用间跳转页面 + │ │ ├── OpenAppPage2.ets // 应用间跳转页面 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 具体实现 + +* 应用间跳转: + * 首先使用canOpenLink判断应用是否可访问,然后通过App Linking 和 Deep Linking以及显式Want三种方式实现应用跳转。 + * 其中App Linking 和 Deep Linking主要是通过openLink函数来实现。 +* 核心配置(被调用方):module.json5 中 uris 声明,被调用方需在module.json5的skills字段中配置可被唤起的链接协议。 + * 被调方配置参考:[module.json5](./entry/src/main/module.json5) +* 应用间跳转完整流程(调用方): + * 步骤 1:应用可访问性预检(canOpenLink)在触发跳转前,通过canOpenLink接口检测目标应用是否可访问。 + * 步骤 2:执行跳转(三种方式实现) + 方式 1:Deep Linking 跳转(推荐,API 12 + 适配),通过openLink接口传入 URI,实现跨应用跳转。 + 方式 2:App Linking 跳转(与 Deep Linking 共用 openLink,适用于云链接场景),App Linking 支持通过云端链接拉起应用,若应用未安装可引导至应用市场。 + 方式 3:显式 Want 跳转(API 12 前兼容,不推荐使用),通过指定目标 Ability 名称拉起应用,API 12 及以上版本可能失效。 + * 步骤 3:被调用方接收跳转参数(OpenAppAbility1.ets) 被唤起时,可在 Ability 的onCreate或onNewWant生命周期中接收调用方传递的参数。调用方接收源码参考:[OpenAppAbility1.ets](./entry/src/main/ets/OpenApp/OpenAppAbility1.ets) + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/PullLinking > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/PullLinking/build-profile.json5 b/AbilityKit/PullLinking/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/code-linter.json5 b/AbilityKit/PullLinking/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/.gitignore b/AbilityKit/PullLinking/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/PullLinking/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/build-profile.json5 b/AbilityKit/PullLinking/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/hvigorfile.ts b/AbilityKit/PullLinking/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/obfuscation-rules.txt b/AbilityKit/PullLinking/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/oh-package.json5 b/AbilityKit/PullLinking/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/main/ets/DeepAbility/DeepAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..604ed57f91395b11df83cea45c7837d5da426161 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepAbility.ets @@ -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. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +// [Start quick_start0] +// 以EntryAbility.ets为例 +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { url } from '@kit.ArkTS'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 从want中获取传入的链接信息。 + // 如传入的url为:link://www.example.com/programs?action=showall + let uri = want?.uri; + if (uri) { + // 从链接中解析query参数,拿到参数后,开发者可根据自己的业务需求进行后续的处理。 + let urlObject = url.URL.parseURL(want?.uri); + let action = urlObject.params.get('action'); + // 例如,当action为showall时,展示所有的节目。 + if (action === 'showall') { + } + } + } +// [End quick_start0] + 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/PullLinking/entry/src/main/ets/DeepAbility/DeepOpenLinkAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepOpenLinkAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..63477c4f61187742b8d4dc1bb2cdce5bd921ca31 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepOpenLinkAbility.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/DeepOpenLinkIndex', (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/PullLinking/entry/src/main/ets/DeepAbility/DeepStartAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepStartAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5efad645c677af0de2fdede418f600f90d35ea9 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepStartAbility.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/DeepStartIndex', (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/PullLinking/entry/src/main/ets/DeepAbility/DeepWebAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepWebAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a4a099da79e242319e83bf172151a4d138dfd33 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/DeepAbility/DeepWebAbility.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/DeepWebIndex', (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/PullLinking/entry/src/main/ets/OpenApp/OpenAppAbility1.ets b/AbilityKit/PullLinking/entry/src/main/ets/OpenApp/OpenAppAbility1.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce78c6c475b40d534a4bb0b3f82d0cffa41d4e4 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/OpenApp/OpenAppAbility1.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/OpenAppPage1', (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/PullLinking/entry/src/main/ets/OpenApp/OpenAppAbility2.ets b/AbilityKit/PullLinking/entry/src/main/ets/OpenApp/OpenAppAbility2.ets new file mode 100644 index 0000000000000000000000000000000000000000..538c6076a907e2749a226127bdcdd92ca285d549 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/OpenApp/OpenAppAbility2.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/OpenAppPage2', (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/PullLinking/entry/src/main/ets/clearability/ClearAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/clearability/ClearAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..28b7b686aa9206cd2f2ae8d1537153c3eef0d273 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/clearability/ClearAbility.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/WebIndex', (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/PullLinking/entry/src/main/ets/clearability/LoginAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/clearability/LoginAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..28b7b686aa9206cd2f2ae8d1537153c3eef0d273 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/clearability/LoginAbility.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/WebIndex', (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/PullLinking/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a4a099da79e242319e83bf172151a4d138dfd33 --- /dev/null +++ b/AbilityKit/PullLinking/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/DeepWebIndex', (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/PullLinking/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/PullLinking/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/main/ets/pages/DeepOpenLinkIndex.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepOpenLinkIndex.ets new file mode 100644 index 0000000000000000000000000000000000000000..946d67c7c5d13e21e2533c43bac2f472b42918b8 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepOpenLinkIndex.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 quick_start0] +import { common, OpenLinkOptions } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[UIAbilityComponentsOpenLink]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + build() { + Button('start link', { type: ButtonType.Capsule, stateEffect: true }) + .width('87%') + .height('5%') + .margin({ bottom: '12vp' }) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let link: string = 'link://www.example.com'; + let openLinkOptions: OpenLinkOptions = { + appLinkingOnly: false + }; + + try { + context.openLink(link, openLinkOptions) + .then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'openLink success.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `openLink failed. Code is ${err.code}, message is ${err.message}`); + }); + } catch (paramError) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); + } + }) + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepStartIndex.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepStartIndex.ets new file mode 100644 index 0000000000000000000000000000000000000000..bcdd31073aa09667d0d5907a432a1542b269a0f5 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepStartIndex.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[UIAbilityComponentsOpenLink]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + build() { + Button('start ability', { type: ButtonType.Capsule, stateEffect: true }) + .width('87%') + .height('5%') + .margin({ bottom: '12vp' }) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let want: Want = { + uri: 'link://www.example.com' + }; + + try { + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`); + }); + } catch (paramError) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${paramError.code}, message is ${paramError.message}`); + } + }) + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepWebIndex.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepWebIndex.ets new file mode 100644 index 0000000000000000000000000000000000000000..64b26fd728107bbda6c7b0df500c319f0400f807 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/DeepWebIndex.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { common } from '@kit.AbilityKit'; +// [StartExclude quick_start0] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_PullLinking]'; +// [EndExclude quick_start0] +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onLoadIntercept((event) => { + const url: string = event.data.getRequestUrl(); + if (url === 'link://www.example.com') { + (this.getUIContext().getHostContext() as common.UIAbilityContext).openLink(url) + .then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'openLink success.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG,`openLink failed, err: ${JSON.stringify(err)}.`); + }); + return true; + } + // 返回true表示阻止此次加载,否则允许此次加载 + return false; + }) + } + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/Index.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b437aa852bf7df97817413c64ae55145bbc8b6a6 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { common, OpenLinkOptions } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[UIAbilityComponentsOpenLink]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + build() { + Button('start link', { type: ButtonType.Capsule, stateEffect: true }) + .width('87%') + .height('5%') + .margin({ bottom: '12vp' }) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let link: string = 'link://www.example.com'; + let openLinkOptions: OpenLinkOptions = { + appLinkingOnly: false + }; + + try { + context.openLink(link, openLinkOptions) + .then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'openLink success.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `openLink failed. Code is ${err.code}, message is ${err.message}`); + }); + } catch (paramError) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); + } + }) + } +} \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/LinkFeature.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/LinkFeature.ets new file mode 100644 index 0000000000000000000000000000000000000000..b437aa852bf7df97817413c64ae55145bbc8b6a6 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/LinkFeature.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { common, OpenLinkOptions } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[UIAbilityComponentsOpenLink]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + build() { + Button('start link', { type: ButtonType.Capsule, stateEffect: true }) + .width('87%') + .height('5%') + .margin({ bottom: '12vp' }) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let link: string = 'link://www.example.com'; + let openLinkOptions: OpenLinkOptions = { + appLinkingOnly: false + }; + + try { + context.openLink(link, openLinkOptions) + .then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'openLink success.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `openLink failed. Code is ${err.code}, message is ${err.message}`); + }); + } catch (paramError) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); + } + }) + } +} \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/OpenAppPage1.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/OpenAppPage1.ets new file mode 100644 index 0000000000000000000000000000000000000000..80754d7d7b557ac66d2442d3afd244278f2c0ee9 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/OpenAppPage1.ets @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { common, Want, wantConstant } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[Page_UIAbilityComponentsInteractive]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_UIAbilityComponentsInteractive { + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + + build() { + Column() { + List({ initialIndex: 0 }) { + ListItem() { + Row() { + } + .onClick(() => { + // context为UIAbility对象的成员 + let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + action: 'xxxx', // 隐式启动 + flags: wantConstant.Flags.FLAG_START_WITHOUT_TIPS, + }; + // context为调用方UIAbility的UIAbilityContext + this.context.startAbility(wantInfo).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.'); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'startAbility failed.'); + }); + }) + } + } + } + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/OpenAppPage2.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/OpenAppPage2.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eb8e5faef0a59e767f690aa296754bf1c5e2000 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/OpenAppPage2.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { bundleManager } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +// [StartExclude quick_start0] +import { common, Want, wantConstant } from '@kit.AbilityKit'; + +const TAG: string = '[Page_UIAbilityComponentsInteractive]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_UIAbilityComponentsInteractive { + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + public canOpen: boolean = false; + aboutToAppear() { +// [EndExclude quick_start0] + try { + let link = 'app1Scheme://test.example.com/home'; + let canOpen = bundleManager.canOpenLink(link); + // [StartExclude quick_start0] + this.canOpen = canOpen; + // [EndExclude quick_start0] + hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(canOpen)); + } catch (err) { + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message); + } + // [End quick_start0] + } + build() { + Column() { + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Button('MyAbility') + .onClick(() => { + }) + } + } + } + } + } +} diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/WantAbilityPage1.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/WantAbilityPage1.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e935842128c2cfe1910b7e6b9ee92927be0bf0a --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/WantAbilityPage1.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { common, OpenLinkOptions } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[UIAbilityComponentsOpenLink]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + build() { + Button('start link', { type: ButtonType.Capsule, stateEffect: true }) + .width('87%') + .height('5%') + .margin({ bottom: '12vp' }) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + // 通过startAbility接口显式启动其他UIAbility,推荐使用openLink接口。 + // let want: Want = { + // bundleName: "com.test.example", + // moduleName: "entry", + // abilityName: "EntryAbility" + // }; + // try { + // context.startAbility(want) + // .then(() => { + // hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.'); + // }).catch((err: BusinessError) => { + // hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`); + // }) + // } catch (paramError) { + // hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code},\ + // message is ${paramError.message}`); + // } + let link: string = 'https://www.example.com'; + let openLinkOptions: OpenLinkOptions = { + // 匹配的abilities选项是否需要通过App Linking域名校验,匹配到唯一配置过的应用ability + appLinkingOnly: true, + // 同want中的parameter,用于传递的参数 + parameters: {demo_key: 'demo_value'} + }; + + try { + context.openLink(link, openLinkOptions) + .then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'open link success.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`); + }) + } catch (paramError) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); + } + }) + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/pages/WantAbilityPage2.ets b/AbilityKit/PullLinking/entry/src/main/ets/pages/WantAbilityPage2.ets new file mode 100644 index 0000000000000000000000000000000000000000..cdabee2116ada20e6298a38f7a0fd829889eeb8e --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/pages/WantAbilityPage2.ets @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start quick_start0] +import { common, OpenLinkOptions } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[UIAbilityComponentsOpenLink]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + build() { + Button('start link', { type: ButtonType.Capsule, stateEffect: true }) + .width('87%') + .height('5%') + .margin({ bottom: '12vp' }) + .onClick(() => { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + // 通过startAbility接口显式启动其他UIAbility,推荐使用openLink接口。 + // let want: Want = { + // bundleName: "com.test.example", + // moduleName: "entry", + // abilityName: "EntryAbility" + // }; + // try { + // context.startAbilityForResult(want) + // .then((data) => { + // hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success. data: ' + JSON.stringify(data)); + // }).catch((err: BusinessError) => { + // hilog.error(DOMAIN_NUMBER, TAG, `startAbility failed. Code is ${err.code}, message is ${err.message}`); + // }) + // } catch (paramError) { + // hilog.error(DOMAIN_NUMBER, TAG, `Failed to startAbility. Code is ${paramError.code}, \ + // message is ${paramError.message}`); + // } + let link: string = 'https://www.example.com'; + let openLinkOptions: OpenLinkOptions = { + // 匹配的abilities选项是否需要通过App Linking域名校验,匹配到唯一配置过的应用ability + appLinkingOnly: true, + // 同want中的parameter,用于传递的参数 + parameters: {demo_key: 'demo_value'} + }; + + try { + context.openLink(link, openLinkOptions, (err, data) => { + // AbilityResult回调函数,仅在被启动的UIAbility终止时触发 + hilog.info(DOMAIN_NUMBER, TAG, 'open link success. Callback result: ' + JSON.stringify(data)); + }).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'open link success.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `open link failed. Code is ${err.code}, message is ${err.message}`); + }) + } catch (paramError) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); + } + }) + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/ets/want/WantAbility1.ets b/AbilityKit/PullLinking/entry/src/main/ets/want/WantAbility1.ets new file mode 100644 index 0000000000000000000000000000000000000000..0061c702606d5cbf84e9b046ab3194ab91a7ff6b --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/want/WantAbility1.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/WantAbilityPage1', (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/PullLinking/entry/src/main/ets/want/WantAbility2.ets b/AbilityKit/PullLinking/entry/src/main/ets/want/WantAbility2.ets new file mode 100644 index 0000000000000000000000000000000000000000..441589823ac3b81d588376a93b5045c50ed155e4 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/ets/want/WantAbility2.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/WantAbilityPage2', (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/PullLinking/entry/src/main/module.json5 b/AbilityKit/PullLinking/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c6123717fff0237629ad652235a5f6f4bc76ef38 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/module.json5 @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the 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" + ], + "deliveryWithInstall": true, + "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": "OpenAppAbility1", + "srcEntry": "./ets/OpenApp/OpenAppAbility1.ets", + "description": "$string:EntryAbility_desc", + "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": "OpenAppAbility2", + "srcEntry": "./ets/OpenApp/OpenAppAbility2.ets", + "description": "$string:EntryAbility_desc", + "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": "DeepOpenLinkAbility", + "srcEntry": "./ets/DeepAbility/DeepOpenLinkAbility.ets", + "description": "$string:EntryAbility_desc", + "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": "DeepStartAbility", + "srcEntry": "./ets/DeepAbility/DeepStartAbility.ets", + "description": "$string:EntryAbility_desc", + "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": "DeepWebAbility", + "srcEntry": "./ets/DeepAbility/DeepWebAbility.ets", + "description": "$string:EntryAbility_desc", + "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" + ] + } + ] + }, + // [Start quick_start0] + { + // [StartExclude quick_start0] + "name": "DeepEntryAbility", + "srcEntry": "./ets/DeepAbility/DeepAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + // [EndExclude quick_start0] + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + }, + { + "actions": [ + // actions不能为空,actions为空会造成目标方匹配失败。 + "ohos.want.action.viewData" + ], + "uris": [ + { + // scheme必选,可以自定义,以link为例,需要替换为实际的scheme + "scheme": "link", + // host必选,配置待匹配的域名 + "host": "www.example.com" + } + ] + } // 新增一个skill对象,用于跳转场景。如果存在多个跳转场景,需配置多个skill对象。 + ] + }, + // [End quick_start0] + // [Start quick_start1] + { + // [StartExclude quick_start1] + "name": "WantAbility1", + "srcEntry": "./ets/want/WantAbility1.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + // [EndExclude quick_start1] + "skills": [ + { + "entities": [ + "entity.system.browsable" + ], + "actions": [ + "ohos.want.action.viewData" + ], + "uris": [ + { + "scheme": "https", + "host": "www.example.com" + } + ], + "domainVerify": true + } + ] + }, + // [End quick_start1] + // [Start quick_start2] + { + // [StartExclude quick_start2] + "name": "WantAbility2", + "srcEntry": "./ets/want/WantAbility2.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + // [EndExclude quick_start2] + "skills": [ + { + "entities": [ + "entity.system.browsable" + ], + "actions": [ + "ohos.want.action.viewData" + ], + "uris": [ + { + "scheme": "https", + "host": "www.example.com" + } + ], + "domainVerify": true + } + ] + }, + // [End quick_start2] + // [Start quick_start3] + { + // [StartExclude quick_start3] + "name": "loginAbility", + "srcEntry": "./ets/clearability/LoginAbility.ets", + "description": "$string:ClearAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ClearAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + // [EndExclude quick_start3] + "skills": [ + { + "uris": [ + { + "scheme": "https", + "host": "developer.huawei.com", + "path": "consumer", + "linkFeature": "Login" + } + ] + } + ] + }, + // [End quick_start3] + // [Start quick_start4] + { + // [StartExclude quick_start4] + "name": "clearAbility", + "srcEntry": "./ets/clearability/ClearAbility.ets", + "description": "$string:ClearAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ClearAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + // [EndExclude quick_start4] + "skills": [ + { + "uris": [ + { + "scheme": "storage", + "host": "developer.huawei.com", + "path": "clearcache", + "linkFeature": "AppStorageMgmt" + } + ] + } + ] + } + // [End quick_start4] + ], + "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.LOCATION", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [ "EntryAbility" ], + "when": "always" + } + }, + { + "name": "ohos.permission.INTERNET", + "reason": "$string:location_reason", + "usedScene": { + "abilities": [ "EntryAbility" ], + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/resources/base/element/color.json b/AbilityKit/PullLinking/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/main/resources/base/element/float.json b/AbilityKit/PullLinking/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/PullLinking/entry/src/main/resources/base/element/string.json b/AbilityKit/PullLinking/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cc0c35c11c3264ad76765ad947856366c1f7b7aa --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/resources/base/element/string.json @@ -0,0 +1,29 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "ClearAbility_desc", + "value": "description" + }, + { + "name": "ClearAbility_label", + "value": "label" + }, + { + "name": "location_reason", + "value": "Links" + } + + ] +} \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/resources/base/media/background.png b/AbilityKit/PullLinking/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/PullLinking/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/PullLinking/entry/src/main/resources/base/media/foreground.png b/AbilityKit/PullLinking/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/PullLinking/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/PullLinking/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/PullLinking/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/PullLinking/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/PullLinking/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/PullLinking/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/PullLinking/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/PullLinking/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..eebfd1701987501683141f02e5a125ee0a8b67f1 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,13 @@ +{ + "src": [ + "pages/Index", + "pages/OpenAppPage1", + "pages/OpenAppPage2", + "pages/DeepOpenLinkIndex", + "pages/DeepStartIndex", + "pages/DeepWebIndex", + "pages/LinkFeature", + "pages/WantAbilityPage1", + "pages/WantAbilityPage2" + ] +} \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/main/resources/dark/element/color.json b/AbilityKit/PullLinking/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/main/resources/rawfile/index.html b/AbilityKit/PullLinking/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000000000000000000000000000000000000..14752f8ebd2821e16805332321336d35a6631430 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,21 @@ +// [Start quick_start0] +// index.html + + + + + + +

Hello World

+ + + +跳转其他应用二 + + + +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/mock/mock-config.json5 b/AbilityKit/PullLinking/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/PullLinking/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..df1a79c2b7041795bca3f404e6a7a62636f136f8 --- /dev/null +++ b/AbilityKit/PullLinking/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 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 { UIAbility, Want } from '@kit.AbilityKit'; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_PullLinking]'; + +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + /** + * @tc.number SUB_OpenAppPage1 + * @tc.name SUB_OpenAppPage1 + * @tc.desc test OpenAppPage1 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_OpenAppPage1', 0, async (done: Function) => { + console.info('uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'OpenAppAbility1' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_OpenAppAbility2 + * @tc.name SUB_OpenAppAbility2 + * @tc.desc test OpenAppAbility2 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_OpenAppAbility2', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'OpenAppAbility2' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_DeepOpenLinkAbility + * @tc.name SUB_DeepOpenLinkAbility + * @tc.desc test DeepOpenLinkAbility + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_DeepOpenLinkAbility', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'DeepOpenLinkAbility' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_DeepStartAbility + * @tc.name SUB_DeepStartAbility + * @tc.desc test DeepStartAbility + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_DeepStartAbility', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'DeepStartAbility' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_DeepWebAbility + * @tc.name SUB_DeepWebAbility + * @tc.desc test DeepWebAbility + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_DeepWebAbility', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'DeepWebAbility' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_WantAppAbility1 + * @tc.name SUB_WantAppAbility1 + * @tc.desc test WantAppAbility1 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_WantAppAbility1', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'WantAbility1' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_WantAppAbility2 + * @tc.name SUB_WantAppAbility2 + * @tc.desc test WantAppAbility1 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_WantAppAbility2', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'WantAbility2' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_LoginAbility + * @tc.name SUB_LoginAbility + * @tc.desc test LoginAbility + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_LoginAbility', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'loginAbility' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + + /** + * @tc.number SUB_ClearAbility + * @tc.name SUB_ClearAbility + * @tc.desc test ClearAbility + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_ClearAbility', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.pulllinking', + abilityName: 'clearAbility' + }; + await delegator.startAbility(want); + // const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(10000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + console.error('Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + }) +} \ No newline at end of file diff --git a/AbilityKit/PullLinking/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/PullLinking/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/ohosTest/module.json5 b/AbilityKit/PullLinking/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1cafc28b86d7d9f2b34f24d26a75c0dbd7299715 --- /dev/null +++ b/AbilityKit/PullLinking/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": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/PullLinking/entry/src/test/List.test.ets b/AbilityKit/PullLinking/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/entry/src/test/LocalUnit.test.ets b/AbilityKit/PullLinking/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/hvigor/hvigor-config.json5 b/AbilityKit/PullLinking/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/hvigorfile.ts b/AbilityKit/PullLinking/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/oh-package.json5 b/AbilityKit/PullLinking/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/PullLinking/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/PullLinking/ohosTest.md b/AbilityKit/PullLinking/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..7b8a3f2c2bf227b2f80d2fa8f1f506701415b1d6 --- /dev/null +++ b/AbilityKit/PullLinking/ohosTest.md @@ -0,0 +1,8 @@ +# 拉起指定应用 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ---- |--------------| -------- | -------- | +| 拉起应用 | 设备正常运行 | | 被拉起的目标应用正常运行 | 是 | Pass | + diff --git a/AbilityKit/UnexpExit/.gitignore b/AbilityKit/UnexpExit/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/AbilityKit/UnexpExit/.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/UnexpExit/AppScope/app.json5 b/AbilityKit/UnexpExit/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ef7f9352e19cddbc6f68941c946595a57adf4b55 --- /dev/null +++ b/AbilityKit/UnexpExit/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.example.unexpexit", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AbilityKit/UnexpExit/AppScope/resources/base/element/string.json b/AbilityKit/UnexpExit/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a6adcd057eb719e31fe08b1dcc174937481a93e8 --- /dev/null +++ b/AbilityKit/UnexpExit/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "unexpExit" + } + ] +} diff --git a/AbilityKit/UnexpExit/AppScope/resources/base/media/background.png b/AbilityKit/UnexpExit/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/UnexpExit/AppScope/resources/base/media/background.png differ diff --git a/AbilityKit/UnexpExit/AppScope/resources/base/media/foreground.png b/AbilityKit/UnexpExit/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/AbilityKit/UnexpExit/AppScope/resources/base/media/foreground.png differ diff --git a/AbilityKit/UnexpExit/AppScope/resources/base/media/layered_image.json b/AbilityKit/UnexpExit/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/README_zh.md b/AbilityKit/UnexpExit/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..e21fa601f0364accfe721f8730da3ee7751c3b57 --- /dev/null +++ b/AbilityKit/UnexpExit/README_zh.md @@ -0,0 +1,75 @@ +# 获取应用异常退出原因 + +### 介绍 + +当应用异常退出后再次启动时,开发者往往需要获取上次异常退出的具体原因和当时的应用状态信息,比如应用内存占用的rss、pss值、上次应用退出的时间等等。通过UIAbility和UIExtensionAbility的OnCreate生命周期函数中的launchParam参数,开发者可以获取到相关信息,并将其应用于应用体验的分析改进,从而调整业务逻辑、提高应用的存活率。 + +### 效果预览 + +不涉及。 + +### 使用说明 + +具体说明主要有异常获取和异常处理两个: +1. 异常获取 + 获取UIAbility上次退出的原因:在UIAbility类的OnCreate成员函数的launchParam参数中读取Ability上次退出的信息。 +2. 异常处理 + 根据上次退出的信息做相应的业务处理,包含以下处理: + 1. 对于不同的退出原因,开发者可以增加不同的处理逻辑。 + 2. 对于不同的退出原因,开发者可以增加不同的处理逻辑。 + 3. 根据异常退出时刻的时间戳,明确异常发生的时刻,便于问题定位。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── exitability // 获取应用异常退出原因 + │ │ ├── exitAbility1.ets + │ │ ├── exitAbility2.ets + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` +### 具体实现 + +* 获取应用异常退出原因 + * 获取应用异常通过AbilityConstant.LaunchParam参数lastExitReason字段获取,具体源码参考:[ExitAbility1](./entry/src/main/ets/exitability/ExitAbility1.ets) +* 获取应用异常退出原因类型: + * 通过lastExitReason获取不同的退出原因类型(取APP_FREEZE和SIGNAL等)退出原因。源码参考:[ExitAbility2](./entry/src/main/ets/exitability/ExitAbility2.ets) + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/UnexpExit > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/AbilityKit/UnexpExit/build-profile.json5 b/AbilityKit/UnexpExit/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/code-linter.json5 b/AbilityKit/UnexpExit/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/.gitignore b/AbilityKit/UnexpExit/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/AbilityKit/UnexpExit/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/AbilityKit/UnexpExit/entry/build-profile.json5 b/AbilityKit/UnexpExit/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/hvigorfile.ts b/AbilityKit/UnexpExit/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/obfuscation-rules.txt b/AbilityKit/UnexpExit/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/oh-package.json5 b/AbilityKit/UnexpExit/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/ets/entryability/EntryAbility.ets b/AbilityKit/UnexpExit/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/AbilityKit/UnexpExit/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/ets/exitability/ExitAbility1.ets b/AbilityKit/UnexpExit/entry/src/main/ets/exitability/ExitAbility1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d6194b381486bc5ec8ba3e9366853e876ddcc8fc --- /dev/null +++ b/AbilityKit/UnexpExit/entry/src/main/ets/exitability/ExitAbility1.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start quick_start0] +import { UIAbility, Want, AbilityConstant } from '@kit.AbilityKit'; +// [StartExclude quick_start0] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_UnexpExit]'; +// [EndExclude quick_start0] +const MAX_RSS_THRESHOLD: number = 100000; +const MAX_PSS_THRESHOLD: number = 100000; + + +function doSomething() { + hilog.info(DOMAIN_NUMBER, TAG, 'do Something'); +} + +function doAnotherThing() { + hilog.info(DOMAIN_NUMBER, TAG, 'do Another Thing'); +} + +export default class MyAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + // 获取退出原因 + let reason: number = launchParam.lastExitReason; + let subReason: number = -1; + if (launchParam.lastExitDetailInfo) { + subReason = launchParam.lastExitDetailInfo.exitSubReason; + } + let exitMsg: string = launchParam.lastExitMessage; + + if (launchParam.lastExitDetailInfo) { + // 获取Ability上次退出时所在进程的信息 + let pid = launchParam.lastExitDetailInfo.pid; + let processName: string = launchParam.lastExitDetailInfo.processName; + let rss: number = launchParam.lastExitDetailInfo.rss; + let pss: number = launchParam.lastExitDetailInfo.pss; + // 其他信息 + let uid: number = launchParam.lastExitDetailInfo.uid; + let timestamp: number = launchParam.lastExitDetailInfo.timestamp; + } + } +} +// [End quick_start0] \ No newline at end of file diff --git a/AbilityKit/UnexpExit/entry/src/main/ets/exitability/ExitAbility2.ets b/AbilityKit/UnexpExit/entry/src/main/ets/exitability/ExitAbility2.ets new file mode 100644 index 0000000000000000000000000000000000000000..04f7f0b0e267c24956c8c2a14ec845113ef0bdb4 --- /dev/null +++ b/AbilityKit/UnexpExit/entry/src/main/ets/exitability/ExitAbility2.ets @@ -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. + */ +import { UIAbility, Want, AbilityConstant } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +const MAX_RSS_THRESHOLD: number = 100000; +const MAX_PSS_THRESHOLD: number = 100000; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_UnexpExit]'; + +function doSomething() { + hilog.info(DOMAIN_NUMBER,TAG,'do Something'); +} + +function doAnotherThing() { + hilog.info(DOMAIN_NUMBER,TAG,'do Another Thing'); +} + +export default class MyAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + // 获取退出原因 + let reason: number = launchParam.lastExitReason; + let subReason: number = -1; + if (launchParam.lastExitDetailInfo) { + subReason = launchParam.lastExitDetailInfo.exitSubReason; + } + let exitMsg: string = launchParam.lastExitMessage; + // [Start quick_start0] + if (reason === AbilityConstant.LastExitReason.APP_FREEZE) { + // Ability上次因无响应而退出,此处可增加处理逻辑。 + doSomething(); + } else if (reason === AbilityConstant.LastExitReason.SIGNAL && subReason === 9) { + // Ability上次所在进程因kill -9信号而退出,此处可增加处理逻辑。 + doAnotherThing(); + } else if (reason === AbilityConstant.LastExitReason.RESOURCE_CONTROL) { + // Ability上次因rss管控而退出,此处可实现处理逻辑,最简单的就是打印出来。 + hilog.info(DOMAIN_NUMBER,TAG,`The ability has exit last because the rss control,the lastExitReason is ${reason}, subReason is ${subReason}, lastExitMessage is ${exitMsg}.`); + } + // [End quick_start0] + if (launchParam.lastExitDetailInfo) { + // 获取Ability上次退出时所在进程的信息 + let pid = launchParam.lastExitDetailInfo.pid; + let processName: string = launchParam.lastExitDetailInfo.processName; + let rss: number = launchParam.lastExitDetailInfo.rss; + let pss: number = launchParam.lastExitDetailInfo.pss; + // [Start quick_start1] + if (rss > MAX_RSS_THRESHOLD || pss > MAX_PSS_THRESHOLD) { + // RSS或PSS值过大,说明内存使用率接近或达到上限,打印告警,或者增加处理逻辑。 + hilog.warn(DOMAIN_NUMBER,TAG,`Process ${processName}(${pid}) memory usage approaches or reaches the upper limit.`); + } + // [End quick_start1] + let uid: number = launchParam.lastExitDetailInfo.uid; + let timestamp: number = launchParam.lastExitDetailInfo.timestamp; + // [Start quick_start2] + hilog.info(DOMAIN_NUMBER,TAG,`App ${uid} terminated at ${timestamp}.`); + // [End quick_start2] + } + } +} diff --git a/AbilityKit/UnexpExit/entry/src/main/ets/pages/Index.ets b/AbilityKit/UnexpExit/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..64ca99781cb5c3e261ecdd74d316c6fa7cec67e4 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/module.json5 b/AbilityKit/UnexpExit/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..83f8e90d925aa88f7c524b10059899e6c9a8db1f --- /dev/null +++ b/AbilityKit/UnexpExit/entry/src/main/module.json5 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "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": "ExitAbility1", + "srcEntry": "./ets/exitability/ExitAbility1.ets", + "description": "$string:EntryAbility_desc", + "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": "ExitAbility2", + "srcEntry": "./ets/exitability/ExitAbility2.ets", + "description": "$string:EntryAbility_desc", + "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/UnexpExit/entry/src/main/resources/base/element/color.json b/AbilityKit/UnexpExit/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/resources/base/element/float.json b/AbilityKit/UnexpExit/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/AbilityKit/UnexpExit/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/AbilityKit/UnexpExit/entry/src/main/resources/base/element/string.json b/AbilityKit/UnexpExit/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/resources/base/media/background.png b/AbilityKit/UnexpExit/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/AbilityKit/UnexpExit/entry/src/main/resources/base/media/background.png differ diff --git a/AbilityKit/UnexpExit/entry/src/main/resources/base/media/foreground.png b/AbilityKit/UnexpExit/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/AbilityKit/UnexpExit/entry/src/main/resources/base/media/foreground.png differ diff --git a/AbilityKit/UnexpExit/entry/src/main/resources/base/media/layered_image.json b/AbilityKit/UnexpExit/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/resources/base/media/startIcon.png b/AbilityKit/UnexpExit/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/AbilityKit/UnexpExit/entry/src/main/resources/base/media/startIcon.png differ diff --git a/AbilityKit/UnexpExit/entry/src/main/resources/base/profile/backup_config.json b/AbilityKit/UnexpExit/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/UnexpExit/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/AbilityKit/UnexpExit/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/AbilityKit/UnexpExit/entry/src/main/resources/dark/element/color.json b/AbilityKit/UnexpExit/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/mock/mock-config.json5 b/AbilityKit/UnexpExit/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/ohosTest/ets/test/Ability.test.ets b/AbilityKit/UnexpExit/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d879d8f60849e09ef742ef598164905230311a58 --- /dev/null +++ b/AbilityKit/UnexpExit/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER = 0xF811; +const TAG = '[Sample_UnexpExit]'; + +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + + + /** + * @tc.number SUB_ExitAbility1 + * @tc.name SUB_ExitAbility1 + * @tc.desc test ExitAbility1 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_ExitAbility1', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.unexpexit', + abilityName: 'ExitAbility1' + }; + await delegator.startAbility(want); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER, TAG, 'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + done(); + } + }); + + /** + * @tc.number SUB_ExitAbility2 + * @tc.name SUB_ExitAbility2 + * @tc.desc test ExitAbility2 + * @tc.level Level1 + * @tc.size MediumTest + * @tc.type Function + */ + it('SUB_ExitAbility2', 0, async (done: Function) => { + hilog.info(DOMAIN_NUMBER,TAG,'uitest: TestUiExample begin'); + try { + const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + const want: Want = { + deviceId: '', + bundleName: 'com.example.unexpexit', + abilityName: 'ExitAbility2' + }; + await delegator.startAbility(want); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + await sleep(5000); + hilog.info(DOMAIN_NUMBER,TAG,'get top ability'); + expect(1).assertEqual(1); + done(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, 'Start Fail: ', error); + expect(0).assertEqual(1); + } + }); + }) +} \ No newline at end of file diff --git a/AbilityKit/UnexpExit/entry/src/ohosTest/ets/test/List.test.ets b/AbilityKit/UnexpExit/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/ohosTest/module.json5 b/AbilityKit/UnexpExit/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1cafc28b86d7d9f2b34f24d26a75c0dbd7299715 --- /dev/null +++ b/AbilityKit/UnexpExit/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": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/AbilityKit/UnexpExit/entry/src/test/List.test.ets b/AbilityKit/UnexpExit/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/entry/src/test/LocalUnit.test.ets b/AbilityKit/UnexpExit/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/hvigor/hvigor-config.json5 b/AbilityKit/UnexpExit/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/hvigorfile.ts b/AbilityKit/UnexpExit/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/oh-package.json5 b/AbilityKit/UnexpExit/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..837c0ff9f35a6bb9eea849fead7955c19bcdec8d --- /dev/null +++ b/AbilityKit/UnexpExit/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/UnexpExit/ohosTest.md b/AbilityKit/UnexpExit/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..d98e141320e2aa07d6267d07cf668f633cae75ea --- /dev/null +++ b/AbilityKit/UnexpExit/ohosTest.md @@ -0,0 +1,8 @@ +# 获取应用异常退出原因 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------| ------------ | ---- |--------------| -------- | -------- | +| 获取应用异常退出原因 | 设备正常运行 | | 获取应用异常退出原因成功 | 是 | Pass | +