diff --git a/Account/DomainAccount/.gitignore b/Account/DomainAccount/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Account/DomainAccount/.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/Account/DomainAccount/AppScope/app.json5 b/Account/DomainAccount/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4055b54e63ab301b6a6c48c98e0d5ba269d332a9 --- /dev/null +++ b/Account/DomainAccount/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.samples.domainaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/Account/DomainAccount/AppScope/resources/base/element/string.json b/Account/DomainAccount/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..da3774353bb1eda7bd7c9347d91900a3ad64f52b --- /dev/null +++ b/Account/DomainAccount/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DomainAccount" + } + ] +} diff --git a/Account/DomainAccount/AppScope/resources/base/media/app_icon.png b/Account/DomainAccount/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/Account/DomainAccount/AppScope/resources/base/media/app_icon.png differ diff --git a/Account/DomainAccount/README.md b/Account/DomainAccount/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2b1b5f02e5cee3a7bb355e4a3c6e24090b5b8f84 --- /dev/null +++ b/Account/DomainAccount/README.md @@ -0,0 +1,94 @@ +# DomainAccount + +### 介绍 + +用户可以在系统中添加域账号,后续可以使用该账号登录、使用系统。 + +当需要验证域账号身份(比如屏幕解锁、登录会话失效等场景)时,可以使用系统提供的接口对域账号进行身份认证。 + +OEM厂商可以采用插件方式定制化域账号管理能力,系统提供了域账号插件注册和注销能能力。 + +实现对以下指南文件中[管理域账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-domain-account.md) [域账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/auth-domain-account.md) [管理域账号插件](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-domain-plugin.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | 域账号插件管理页面 | 注册插件及结果 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | ------------------------------------------------------------ | +| | | | +| 注销插件及结果 | 域账号管理页面 | 判断指定域账号是否存在及结果 | +| | | | +| 添加域账号及结果 | 删除域账号及结果 | 查询域账号信息和认证结果 | +| | | | +| 域账号认证页面 | 使用密码认证域账号及结果 | 弹窗验证域账号及结果 | +| | | | + +### 使用说明 + +1. 在主界面,点击ManageDomainAccountsPlugin,进入域账号插件管理页面。 +2. 点击注册插件按钮,进行插件注册。 +3. 进入管理域账号管理页面。 +4. 点击判断指定域账号是否存在。 +5. 点击添加域账号。 +6. 点击删除域账号。 +7. 点击查询域账号信息。 +8. 进入认证域账号界面。 +9. 点击使用密码认证域账号。 +10. 点击使用弹窗验证域账号。 +11. 回到域账号插件管理页面。 +12. 点击注销插件按钮,进行注销插件。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + | | ├──DomainAccount + | | | ├──AuthenticationDomainAccount // 域账号管理示例代码 + | | | ├──ManageDomainAccounts // 域处理示例代码 + | | | └──ManageDomainAccountsPlugin // 域账号插件示例代码 + │ │ ├── Index.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagelocalaccounts) + +[ohos.permission.GET_DOMAIN_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissiongetdomainaccounts) + +[ohos.permission.ACCESS_USER_AUTH_INTERNAL](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccessuserauthinternal) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo Account/DomainAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/Account/DomainAccount/build-profile.json5 b/Account/DomainAccount/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/Account/DomainAccount/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "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/Account/DomainAccount/code-linter.json5 b/Account/DomainAccount/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/Account/DomainAccount/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/.gitignore b/Account/DomainAccount/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Account/DomainAccount/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Account/DomainAccount/entry/build-profile.json5 b/Account/DomainAccount/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/Account/DomainAccount/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/hvigorfile.ts b/Account/DomainAccount/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/Account/DomainAccount/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/DomainAccount/entry/obfuscation-rules.txt b/Account/DomainAccount/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Account/DomainAccount/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/Account/DomainAccount/entry/oh-package.json5 b/Account/DomainAccount/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/Account/DomainAccount/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets b/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets b/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets new file mode 100644 index 0000000000000000000000000000000000000000..bd8de78cf0b1f164ae75f4e92da7e621c0271aeb --- /dev/null +++ b/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_the_system_account_module] +import { osAccount } from '@kit.BasicServicesKit'; +// [End import_the_system_account_module] +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct AuthenticationDomainAccount { + @State message: string = 'No Message'; + + private async passwordAuthenticateDomainAccount(): Promise { + // [Start get_user_input] + let domainAccountInfo: osAccount.DomainAccountInfo = { + domain: 'CHINA', + accountName: 'zhangsan' + }; + let credential: Uint8Array = new Uint8Array([0]); + // [End get_user_input] + // [Start define_the_callback_for_the_authentication_result] + let callback: osAccount.IUserAuthCallback = { + onResult: (resultCode: number, authResult: osAccount.AuthResult) => { + console.log('auth resultCode = ' + resultCode); + console.log('auth authResult = ' + JSON.stringify(authResult)); + // [StartExclude define_the_callback_for_the_authentication_result] + if(resultCode == 0) { + this.message = 'Successfully authenticated domain account using password'; + } else { + this.message = 'Failed to authenticate domain account using password: ' + resultCode; + } + // [EndExclude define_the_callback_for_the_authentication_result] + + } + }; + // [End define_the_callback_for_the_authentication_result] + // [Start perform_password_authentication] + try { + osAccount.DomainAccountManager.auth(domainAccountInfo, credential, callback); + } catch (err) { + console.error('auth exception = ' + JSON.stringify(err)); + } + // [End perform_password_authentication] + } + + private async popupAuthenticateDomainAccount(): Promise { + // [Start define_the_callback_object_of_the_authentication_result] + let callback: osAccount.IUserAuthCallback = { + onResult: (resultCode: number, authResult: osAccount.AuthResult) => { + console.log('authWithPopup resultCode = ' + resultCode); + console.log('authWithPopup authResult = ' + JSON.stringify(authResult)); + // [StartExclude define_the_callback_object_of_the_authentication_result] + if(resultCode == 0) { + this.message = 'Successfully authenticated domain account using popup'; + } else if(resultCode == 12300003) { + this.message = 'No domain account is bound'; + } else { + this.message = 'Failed to authenticate domain account using popup: ' + resultCode; + } + // [EndExclude define_the_callback_object_of_the_authentication_result] + } + } + // [End define_the_callback_object_of_the_authentication_result] + // [Start call_operation_to_authenticate_the_current_domain_account] + try { + osAccount.DomainAccountManager.authWithPopup(callback) + } catch (err) { + console.error('authWithPopup exception = ' + JSON.stringify(err)); + // [StartExclude call_operation_to_authenticate_the_current_domain_account] + this.message = 'Exception occurred during popup authentication: ' + JSON.stringify(err); + // [EndExclude call_operation_to_authenticate_the_current_domain_account] + } + // [End call_operation_to_authenticate_the_current_domain_account] + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Domain1')) + .margin(10) + .id('button1') + .onClick(() => this.passwordAuthenticateDomainAccount()) + Button($r('app.string.Domain2')) + .margin(10) + .id('button2') + .onClick(() => this.popupAuthenticateDomainAccount()) + Button('Go to plugin') + .margin(10) + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/ManageDomainAccountsPlugin' + }) + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets b/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc092ac305fd66ebca208d814a0767205e7d54ef --- /dev/null +++ b/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_the_system_account_module] +import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_the_system_account_module] +import { router } from '@kit.ArkUI'; + +// [Start obtain_the_system_account_management_object] +let osAccountMgr = osAccount.getAccountManager(); +// [End obtain_the_system_account_management_object] + +@Entry +@Component +struct ManageDomainAccounts { + @State message: string = 'Hello World'; + + private async domainAccountExists(): Promise { + // [Start define_the_domain_account_information_to_be_determined] + let domainAccountInfo: osAccount.DomainAccountInfo = { + accountName: 'testAccountName', + domain: 'testDomain' + } + // [End define_the_domain_account_information_to_be_determined] + + // [Start call_the_hasaccount_operation] + let isAccountExisted: boolean = await osAccount.DomainAccountManager.hasAccount(domainAccountInfo); + // [End call_the_hasaccount_operation] + console.log('domainAccount isAccountExisted:' + isAccountExisted); + if(isAccountExisted) { + this.message = 'Domain account already exists'; + } else { + this.message = 'Domain account does not exist'; + } + } + + private async createDomainAccount(): Promise { + // [Start define_the_domain_account_information] + let domainInfo: osAccount.DomainAccountInfo = { + domain: 'testDomain', + accountName: 'testAccountName' + }; + // [End define_the_domain_account_information] + + // [Start create_a_domain_account] + try { + osAccountMgr.createOsAccountForDomain(osAccount.OsAccountType.NORMAL, domainInfo, + (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ + console.log('createOsAccountForDomain err:' + JSON.stringify(err)); + console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); + // [StartExclude create_a_domain_account] + this.message = 'Account creation information: ' + JSON.stringify(osAccountInfo.localName); + // [EndExclude create_a_domain_account] + }); + } catch (e) { + console.error('createOsAccountForDomain exception: ' + JSON.stringify(e)); + // [StartExclude create_a_domain_account] + this.message = 'Account creation failed: ' + JSON.stringify(e); + // [EndExclude create_a_domain_account] + } + // [End create_a_domain_account] + } + + private async deleteDomainAccount(): Promise { + // [Start obtain_the_system_account_id_based_on_the_domain_account_information] + let domainInfo: osAccount.DomainAccountInfo = { + domain: 'testDomain', + accountName: 'testAccountName' + }; + let localId: number = 0; + try { + localId = await osAccountMgr.getOsAccountLocalIdForDomain(domainInfo); + } catch (err) { + console.error('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); + // [StartExclude obtain_the_system_account_id_based_on_the_domain_account_information] + this.message = 'Failed to get account deletion information: ' + JSON.stringify(err); + // [EndExclude obtain_the_system_account_id_based_on_the_domain_account_information] + } + // [End obtain_the_system_account_id_based_on_the_domain_account_information] + // [Start delete_the_domain_account] + try { + osAccountMgr.removeOsAccount(localId, (err: BusinessError)=>{ + if (err) { + console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); + // [StartExclude delete_the_domain_account] + this.message = 'Failed to delete account: ' + JSON.stringify(err); + // [EndExclude delete_the_domain_account] + } else { + console.log('removeOsAccount successfully'); + // [StartExclude delete_the_domain_account] + this.message = 'Successfully deleted account'; + // [EndExclude delete_the_domain_account] + } + }); + } catch (err) { + console.error('removeOsAccount exception: ' + JSON.stringify(err)); + } + // [End delete_the_domain_account] + + } + + private async queryDomainAccount(): Promise { + // [Start define_query_options] + let options: osAccount.GetDomainAccountInfoOptions = { + domain: 'testDomain', + accountName: 'testAccountName' + } + // [End define_query_options] + // [Start query_the_domain_account_information] + try { + osAccount.DomainAccountManager.getAccountInfo(options, + (err: BusinessError, result: osAccount.DomainAccountInfo) => { + if (err) { + console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); + // [StartExclude query_the_domain_account_information] + this.message = 'Query failed: ' + JSON.stringify(err); + // [EndExclude query_the_domain_account_information] + } else { + console.log('getAccountInfo result: ' + result); + // [StartExclude query_the_domain_account_information] + this.message = 'Queried account information: ' + JSON.stringify(result.accountName); + // [EndExclude query_the_domain_account_information] + } + }); + } catch (err) { + console.error('getAccountInfo exception = ' + JSON.stringify(err)); + // [StartExclude query_the_domain_account_information] + this.message = 'Failed to query account information: ' + JSON.stringify(err); + // [EndExclude query_the_domain_account_information] + } + // [End query_the_domain_account_information] + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Domain5')) + .margin(10) + .id('button1') + .onClick(() => this.domainAccountExists()) + Button($r('app.string.Domain6')) + .margin(10) + .id('button2') + .onClick(() => this.createDomainAccount()) + Button($r('app.string.Domain7')) + .margin(10) + .id('button3') + .onClick(() => this.deleteDomainAccount()) + Button($r('app.string.Domain8')) + .margin(10) + .id('button4') + .onClick(() => this.queryDomainAccount()) + Button('Go to AuthenticationDomainAccount') + .margin(10) + .id('button5') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/AuthenticationDomainAccount' + }) + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets b/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c9ad0bae9e4d5b887d5435fac923c96556fa406 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_the_system_account_module] +import { osAccount, AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; +// [End import_the_system_account_module] +import { router } from '@kit.ArkUI'; + +// [Start define_the_plug_in] +let plugin: osAccount.DomainPlugin = { + auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, + callback: osAccount.IUserAuthCallback) => { + console.info('plugin auth domain' + domainAccountInfo.domain); + console.info('plugin auth accountName' + domainAccountInfo.accountName); + console.info('plugin auth accountId' + domainAccountInfo.accountId); + + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, + callback: osAccount.IUserAuthCallback) => { + console.info('plugin authWithPopup domain' + domainAccountInfo.domain); + console.info('plugin authWithPopup accountName' + domainAccountInfo.accountName); + console.info('plugin authWithPopup accountId' + domainAccountInfo.accountId); + + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, + token: Uint8Array, callback: osAccount.IUserAuthCallback) => { + console.info('plugin authWithToken domain' + domainAccountInfo.domain); + console.info('plugin authWithToken accountName' + domainAccountInfo.accountName); + console.info('plugin authWithToken accountId' + domainAccountInfo.accountId); + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, + callback: AsyncCallback) => { + console.info('plugin getAccountInfo domain'); + let domainAccountId = Date.now().toString(); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let domainStr: string = ''; + if (options.domain != undefined) { + domainStr = options.domain + } + let accountInfo: osAccount.DomainAccountInfo = { + domain: domainStr, + accountName: options.accountName, + accountId: domainAccountId, + isAuthenticated: false + }; + callback(code, accountInfo); + }, + getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, + callback: AsyncCallback) => { + + console.info('plugin getAuthStatusInfo domain' + domainAccountInfo.domain); + console.info('plugin getAuthStatusInfo accountName' + domainAccountInfo.accountName); + console.info('plugin getAuthStatusInfo accountId' + domainAccountInfo.accountId); + + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let statusInfo: osAccount.AuthStatusInfo = { + remainTimes: 5, + freezingTime: 0 + }; + callback(code, statusInfo); + }, + bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, + callback: AsyncCallback) => { + console.info('plugin bindAccount domain' + domainAccountInfo.domain); + console.info('plugin bindAccount accountName' + domainAccountInfo.accountName); + console.info('plugin bindAccount accountId' + domainAccountInfo.accountId); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + callback(code); + }, + unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback) => { + console.info('plugin unbindAccount domain' + domainAccountInfo.domain); + console.info('plugin unbindAccount accountName' + domainAccountInfo.accountName); + console.info('plugin unbindAccount accountId' + domainAccountInfo.accountId); + }, + isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, + callback: AsyncCallback) => { + console.info('plugin isAccountTokenValid domain' + domainAccountInfo.domain); + console.info('plugin isAccountTokenValid accountName' + domainAccountInfo.accountName); + console.info('plugin isAccountTokenValid accountId' + domainAccountInfo.accountId); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + callback(code, true); + }, + getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback) => { + console.info('plugin getAccessToken domain') + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let token: Uint8Array = new Uint8Array([0]); + callback(code, token); + } +} +// [End define_the_plug_in] + + +@Entry +@Component +struct ManageDomainAccountsPlugin { + @State message: string = 'Manage domain account plugin'; + + private async registrationPlugin(): Promise { + // [Start call_the_api_to_register_the_plug_in] + try { + osAccount.DomainAccountManager.registerPlugin(plugin) + console.info('registerPlugin success'); + // [StartExclude call_the_api_to_register_the_plug_in] + this.message = 'Successfully registered plugin'; + // [EndExclude call_the_api_to_register_the_plug_in] + } catch (err) { + console.error('registerPlugin err: ' + JSON.stringify(err)); + // [StartExclude call_the_api_to_register_the_plug_in] + this.message = 'Failed to register plugin: ' + JSON.stringify(err); + // [EndExclude call_the_api_to_register_the_plug_in] + } + // [End call_the_api_to_register_the_plug_in] + } + + private async logoutPlugin(): Promise { + // [Start call_the_api_to_log_out_the_plug_in] + try { + osAccount.DomainAccountManager.unregisterPlugin(); + console.log('unregisterPlugin success.'); + // [StartExclude call_the_api_to_log_out_the_plug_in] + this.message = 'unregisterPlugin success'; + // [EndExclude call_the_api_to_log_out_the_plug_in] + } catch(err) { + console.error('unregisterPlugin err:' + JSON.stringify(err)); + // [StartExclude call_the_api_to_log_out_the_plug_in] + this.message = 'Failed to unregister plugin: ' + JSON.stringify(err); + // [EndExclude call_the_api_to_log_out_the_plug_in] + } + // [End call_the_api_to_log_out_the_plug_in] + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Domain3')) + .margin(10) + .id('button1') + .onClick(() => this.registrationPlugin()) + Button($r('app.string.Domain4')) + .margin(10) + .id('button2') + .onClick(() => this.logoutPlugin()) + Button('Return back') + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/ManageDomainAccounts' + }) + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/ets/pages/Index.ets b/Account/DomainAccount/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a207adae204d5245cf80aabcd5bef33581de5b0 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/ets/pages/Index.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 { CommonButton } from '../util/CommonButton'; + +@Entry +@Component +struct Index { + build() { + Scroll() { + Column() { + Text('DomainAccountHome') + .padding('15vp') + .width('100%') + .fontSize('25fp') + .textAlign(TextAlign.Center) + CommonButton({ + buttonName: 'AuthenticationDomainAccount', + buttonUrl: 'pages/DomainAccount/AuthenticationDomainAccount' + }); + CommonButton({ + buttonName: 'ManageDomainAccounts', + buttonUrl: 'pages/DomainAccount/ManageDomainAccounts' + }); + CommonButton({ + buttonName: 'ManageDomainAccountsPlugin', + buttonUrl: 'pages/DomainAccount/ManageDomainAccountsPlugin' + }); + } + .padding('5vp') + .width('100%') + }.margin({ bottom: 60 }) + .width('100%') + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/ets/util/CommonButton.ets b/Account/DomainAccount/entry/src/main/ets/util/CommonButton.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2d268bf3aec25d2dcec35d282290ebc90d9d7d9 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/ets/util/CommonButton.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router'; + +@Component +export struct CommonButton { + @State buttonName: string = ''; + @State buttonUrl: string = ''; + @State data: string = ''; + + build() { + Text(this.buttonName) + .id(this.buttonName) + .padding(px2vp(5)) + .fontSize(px2fp(24)) + .textAlign(TextAlign.Center) + .backgroundColor(Color.Blue) + .fontColor(Color.White) + .borderRadius(5) + .margin(px2vp(20)) + .padding(px2vp(15)) + .onClick(() => { + router.pushUrl({ + url: this.buttonUrl, + params: { + text: this.data, + buttonName: this.buttonName + } + }) + }) + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/module.json5 b/Account/DomainAccount/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9024413aca7716ffee807c1caf8ba5846877dcd3 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/module.json5 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + }, + { + "name": "ohos.permission.GET_DOMAIN_ACCOUNTS" + }, + { + "name": "ohos.permission.ACCESS_USER_AUTH_INTERNAL" + }], + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/resources/base/element/color.json b/Account/DomainAccount/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Account/DomainAccount/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/Account/DomainAccount/entry/src/main/resources/base/element/string.json b/Account/DomainAccount/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..195e14de37503d0215b75d2f13a2ad44804085c7 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/resources/base/element/string.json @@ -0,0 +1,48 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "DomainAccount" + }, + { + "name": "Domain1", + "value": "Authenticate domain account using password" + }, + { + "name": "Domain2", + "value": "Authenticate domain account using popup" + }, + { + "name": "Domain3", + "value": "Register plugin" + }, + { + "name": "Domain4", + "value": "Unregister plugin" + }, + { + "name": "Domain5", + "value": "Check if the specified domain account exists" + }, + { + "name": "Domain6", + "value": "Add domain account" + }, + { + "name": "Domain7", + "value": "Delete domain account" + }, + { + "name": "Domain8", + "value": "Query domain account information" + } + ] +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/resources/base/media/background.png b/Account/DomainAccount/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/Account/DomainAccount/entry/src/main/resources/base/media/background.png differ diff --git a/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png b/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png differ diff --git a/Account/DomainAccount/entry/src/main/resources/base/media/layered_image.json b/Account/DomainAccount/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Account/DomainAccount/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/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png b/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json b/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/main/resources/base/profile/main_pages.json b/Account/DomainAccount/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..e47a9436e04a20e9f2c2c825ba5c7049a6b0d372 --- /dev/null +++ b/Account/DomainAccount/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/DomainAccount/AuthenticationDomainAccount", + "pages/DomainAccount/ManageDomainAccounts", + "pages/DomainAccount/ManageDomainAccountsPlugin" + ] +} diff --git a/Account/DomainAccount/entry/src/main/resources/dark/element/color.json b/Account/DomainAccount/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Account/DomainAccount/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/Account/DomainAccount/entry/src/mock/mock-config.json5 b/Account/DomainAccount/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/Account/DomainAccount/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/ohosTest/ets/test/Ability.test.ets b/Account/DomainAccount/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..25279cdbcac906d8242ec0a379fe58af536f71f8 --- /dev/null +++ b/Account/DomainAccount/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, it, expect } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} +export default function abilityTest() { + describe('DomainAccountAbilityTest', () => { + /* + * 打开应用,依次点击页面中按钮 + * 使用域账号接口功能 + */ + it('DomainAccountsExample', 0, async (done: Function) => { + console.info("uitest: TestUiExample begin"); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + await sleep(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info("get top ability"); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('ManageDomainAccountsPlugin')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.id('button1')); + await button2.click(); + await driver.delayMs(1000); + const text0 = await driver.findComponent(ON.id('show')); + let content0: string = await text0.getText(); + expect(content0).assertEqual('Successfully registered plugin'); + + const button3 = await driver.findComponent(ON.id('button3')); + await button3.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.id('button1')); + await button5.click(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.id('show')); + let content1: string = await text.getText(); + expect(content1).assertEqual('Domain account already exists'); + + const button6 = await driver.findComponent(ON.id('button2')); + await button6.click(); + await driver.delayMs(10000); + let content2: string = await text.getText(); + expect(content2).assertEqual('Account creation information: "testAccountName"'); + + const button7 = await driver.findComponent(ON.id('button3')); + await button7.click(); + await driver.delayMs(10000); + let content3: string = await text.getText(); + expect(content3).assertEqual('Successfully deleted account'); + + const button8 = await driver.findComponent(ON.id('button4')); + await button8.click(); + await driver.delayMs(1000); + let content4: string = await text.getText(); + expect(content4).assertEqual('Queried account information: "testAccountName"'); + + const button9 = await driver.findComponent(ON.id('button5')); + await button9.click(); + await driver.delayMs(1000); + + const button10 = await driver.findComponent(ON.id('button1')); + await button10.click(); + await driver.delayMs(1000); + const text1 = await driver.findComponent(ON.id('show')); + let content5: string = await text1.getText(); + expect(content5).assertEqual('Successfully authenticated domain account using password'); + + const button11 = await driver.findComponent(ON.id('button2')); + await button11.click(); + await driver.delayMs(10000); + let content6: string = await text1.getText(); + expect(content6).assertEqual('No domain account is bound'); + + const button12 = await driver.findComponent(ON.id('button3')); + await button12.click(); + await driver.delayMs(1000); + + const button13 = await driver.findComponent(ON.id('button2')); + await button13.click(); + await driver.delayMs(1000); + const text2 = await driver.findComponent(ON.id('show')); + let content7: string = await text2.getText(); + expect(content7).assertEqual('unregisterPlugin success'); + done(); + console.info("uitest: TestUiExample end"); + }) + }) +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/ohosTest/ets/test/List.test.ets b/Account/DomainAccount/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/Account/DomainAccount/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/ohosTest/module.json5 b/Account/DomainAccount/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/Account/DomainAccount/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Account/DomainAccount/entry/src/test/List.test.ets b/Account/DomainAccount/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/Account/DomainAccount/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/Account/DomainAccount/entry/src/test/LocalUnit.test.ets b/Account/DomainAccount/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/Account/DomainAccount/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/Account/DomainAccount/hvigor/hvigor-config.json5 b/Account/DomainAccount/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/Account/DomainAccount/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/Account/DomainAccount/hvigorfile.ts b/Account/DomainAccount/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/Account/DomainAccount/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/DomainAccount/oh-package.json5 b/Account/DomainAccount/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/Account/DomainAccount/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/Account/DomainAccount/ohosTest.md b/Account/DomainAccount/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..0631be022a69ff140f92cbb98a30aeb4eb4ef348 --- /dev/null +++ b/Account/DomainAccount/ohosTest.md @@ -0,0 +1,15 @@ +# DomainAccount 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ----------------------------------------------- | ----------------------------- | --------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 注册插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘Register plugin’ | 页面显示“Successfully registered plugin” | 是 | Pass | +| 注销插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘Register plugin’ | 页面显示“unregisterPlugin success“ | 是 | Pass | +| Check if the specified domain account exists | 位于ManageDomainAccounts页面,已注册插件 | 点击‘ Check if the specified domain account exists’ | 页面显示“Domain account already exists“ | 是 | Pass | +| Add domain account | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Add domain account’ | 页面显示“Account creation information: "testAccountName"“ | 是 | Pass | +| Delete domain account | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Delete domain account’ | 页面显示“Successfully deleted account“ | 是 | Pass | +| Query domain account information | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Query domain account information’ | 页面显示“Queried account information: "testAccountName"“ | 是 | Pass | +| Authenticate domain account using password | 位于AuthenticationDomainAccount页面,已注册插件 | 点击‘使用密码进行认证’ | 页面显示“Successfully authenticated domain account using password“ | 是 | Pass | +| Authenticate domain account using popup | 位于AuthenticationDomainAccount页面,已注册插件 | 点击‘Authenticate domain account using popup’ | 页面显示"No domain account is bound" | 是 | Pass | \ No newline at end of file diff --git a/Account/DomainAccount/screenshots/DomainAccount_1.png b/Account/DomainAccount/screenshots/DomainAccount_1.png new file mode 100644 index 0000000000000000000000000000000000000000..cfd2e01bbc1b4122f2bc5479238d691c8673115e Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_1.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_10.png b/Account/DomainAccount/screenshots/DomainAccount_10.png new file mode 100644 index 0000000000000000000000000000000000000000..31c95223b1684e300cd35310cfe1c22cafbb980e Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_10.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_11.png b/Account/DomainAccount/screenshots/DomainAccount_11.png new file mode 100644 index 0000000000000000000000000000000000000000..9974b35442f9b7520afb0a83a494ea3af0773e6f Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_11.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_12.png b/Account/DomainAccount/screenshots/DomainAccount_12.png new file mode 100644 index 0000000000000000000000000000000000000000..8bc5178f742f2bd95f690ca1c31e4edc2b69e113 Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_12.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_2.png b/Account/DomainAccount/screenshots/DomainAccount_2.png new file mode 100644 index 0000000000000000000000000000000000000000..dc15152d5840f7c70fc56ddd75e6b16791e154f9 Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_2.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_3.png b/Account/DomainAccount/screenshots/DomainAccount_3.png new file mode 100644 index 0000000000000000000000000000000000000000..1ed3f8e478479524fca7c47b0efb3be7c04c39ee Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_3.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_4.png b/Account/DomainAccount/screenshots/DomainAccount_4.png new file mode 100644 index 0000000000000000000000000000000000000000..74a8cba911568d6a44eded3ca078fd7863a4ded2 Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_4.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_5.png b/Account/DomainAccount/screenshots/DomainAccount_5.png new file mode 100644 index 0000000000000000000000000000000000000000..2fac836435d2f5dabd4b4610f81f32a017511d61 Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_5.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_6.png b/Account/DomainAccount/screenshots/DomainAccount_6.png new file mode 100644 index 0000000000000000000000000000000000000000..9724d16af1c3dab011b73cdc353682ad9a7e1be2 Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_6.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_7.png b/Account/DomainAccount/screenshots/DomainAccount_7.png new file mode 100644 index 0000000000000000000000000000000000000000..fe58ce1397f4ec097f487a98f369408a3c576ff7 Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_7.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_8.png b/Account/DomainAccount/screenshots/DomainAccount_8.png new file mode 100644 index 0000000000000000000000000000000000000000..bd5431a1fa936b673a520a25067af24bfd084e00 Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_8.png differ diff --git a/Account/DomainAccount/screenshots/DomainAccount_9.png b/Account/DomainAccount/screenshots/DomainAccount_9.png new file mode 100644 index 0000000000000000000000000000000000000000..7897af572765f17884b765aa06f983a5773d99de Binary files /dev/null and b/Account/DomainAccount/screenshots/DomainAccount_9.png differ diff --git a/Account/ManageDistributedAccount/.gitignore b/Account/ManageDistributedAccount/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Account/ManageDistributedAccount/.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/Account/ManageDistributedAccount/AppScope/app.json5 b/Account/ManageDistributedAccount/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c95d19eb6503146663065560369c424e00886939 --- /dev/null +++ b/Account/ManageDistributedAccount/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.samples.managedistributedaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/Account/ManageDistributedAccount/AppScope/resources/base/element/string.json b/Account/ManageDistributedAccount/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9d32d7a58a3f857d71cfb988c01ffb3b1914e134 --- /dev/null +++ b/Account/ManageDistributedAccount/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageDistributedAccount" + } + ] +} diff --git a/Account/ManageDistributedAccount/AppScope/resources/base/media/app_icon.png b/Account/ManageDistributedAccount/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/Account/ManageDistributedAccount/AppScope/resources/base/media/app_icon.png differ diff --git a/Account/ManageDistributedAccount/README.md b/Account/ManageDistributedAccount/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9385100060428dfd9d8ddb08f871982018d61641 --- /dev/null +++ b/Account/ManageDistributedAccount/README.md @@ -0,0 +1,73 @@ +# 管理分布式账号(仅对系统应用开放) + +### 介绍 + +1.OEM厂商可以通过[分布式账号SDK](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-distributed-account.md)将自有账号与本地系统账号建立关联关系。 + +2.实现对以下指南文档中 [管理分布式账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-distributed-account.md) 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | 执行Log in and bind distributed account on the current system account | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| **执行Log out and unbind distributed account on the current system account** | **执行Log in and bind distributed account on the specified system account** | +| | | +| **执行Log out and unbind distributed account on the specified system account** | | +| | | + +### 使用说明 + +1. 在主界面,点击'Log in and bind distributed account on the current system account',执行Log in and bind distributed account on the current system account。 +2. 点击'Log out and unbind distributed account on the current system account',执行Log out and unbind distributed account on the current system account。 +3. 点击'Log in and bind distributed account on the specified system account',执行Log in and bind distributed account on the specified system account。 +4. 点击'Log out and unbind distributed account on the specified system account',执行Log out and unbind distributed account on the specified system account。 +5. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ └── pages + │ │ └── Index.ets // 管理分布式账号示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ └── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagedistributedaccounts) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo Account/ManageDistributedAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/Account/ManageDistributedAccount/build-profile.json5 b/Account/ManageDistributedAccount/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c284a291dc2cd15abf8025431e67aa253f01b81 --- /dev/null +++ b/Account/ManageDistributedAccount/build-profile.json5 @@ -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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/code-linter.json5 b/Account/ManageDistributedAccount/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/Account/ManageDistributedAccount/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/.gitignore b/Account/ManageDistributedAccount/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/build-profile.json5 b/Account/ManageDistributedAccount/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/hvigorfile.ts b/Account/ManageDistributedAccount/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/ManageDistributedAccount/entry/obfuscation-rules.txt b/Account/ManageDistributedAccount/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Account/ManageDistributedAccount/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/Account/ManageDistributedAccount/entry/oh-package.json5 b/Account/ManageDistributedAccount/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/Account/ManageDistributedAccount/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/Account/ManageDistributedAccount/entry/src/main/ets/entryability/EntryAbility.ets b/Account/ManageDistributedAccount/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Account/ManageDistributedAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/main/ets/pages/Index.ets b/Account/ManageDistributedAccount/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..88bd7546fecd23c0a9f1688ead1b04f83c68aa7d --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_the_distributed_account_module] +import { distributedAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_the_distributed_account_module] + +// [Start obtain_the_single-instance_object_of_the_distributed_account] +const distributedAccountAbility = distributedAccount.getDistributedAccountAbility(); +// [End obtain_the_single-instance_object_of_the_distributed_account] + +@Entry +@Component +struct Index { + @State message: string = 'No Name'; + + private async bindCurrentManageDistributedAccounts(): Promise { + // [Start define_the_distributed_account_information_to_be_logged_in] + let distributedInfo: distributedAccount.DistributedInfo = { + name: 'ZhangSan', + id: '12345', + event: 'Ohos.account.event.LOGIN', + }; + // [End define_the_distributed_account_information_to_be_logged_in] + + // [Start bind_the_current_system_account_to_the_specified_distributed_account] + await distributedAccountAbility.setOsAccountDistributedInfo(distributedInfo).then(() => { + console.log('setOsAccountDistributedInfo successfully'); + }).catch((err: BusinessError) => { + console.error('setOsAccountDistributedInfo exception: ' + JSON.stringify(err)); + // [StartExclude bind_the_current_system_account_to_the_specified_distributed_account] + this.message = 'Failed to bind distributed account: ' + JSON.stringify(err); + // [EndExclude bind_the_current_system_account_to_the_specified_distributed_account] + }); + // [End bind_the_current_system_account_to_the_specified_distributed_account] + + // [Start view_the_login_information_of_distributed_account] + distributedAccountAbility.getOsAccountDistributedInfo().then((data: distributedAccount.DistributedInfo) => { + console.log('distributed information: ' + JSON.stringify(data)); + // [StartExclude view_the_login_information_of_distributed_account] + this.message = 'Bind distributed account: ' + data.name; + // [EndExclude view_the_login_information_of_distributed_account] + }).catch((err: BusinessError) => { + console.error('getOsAccountDistributedInfo exception: ' + JSON.stringify(err)); + // [StartExclude view_the_login_information_of_distributed_account] + this.message = 'Failed to get distributed account: ' + JSON.stringify(err); + // [EndExclude view_the_login_information_of_distributed_account] + }); + // [End view_the_login_information_of_distributed_account] + } + + private async unbindCurrentManageDistributedAccounts(): Promise { + // [Start define_the_distributed_account_information_to_be_logged_out] + let distributedInfo: distributedAccount.DistributedInfo = { + name: 'ZhangSan', + id: '12345', + event: 'Ohos.account.event.LOGOUT', + }; + // [End define_the_distributed_account_information_to_be_logged_out] + + // [Start unbind_the_specified_distributed_account_from_the_current_system_account] + distributedAccountAbility.setOsAccountDistributedInfo(distributedInfo).then(() => { + console.log('setOsAccountDistributedInfo successfully'); + // [StartExclude unbind_the_specified_distributed_account_from_the_current_system_account] + this.message = 'Successfully unbound distributed account' + // [EndExclude unbind_the_specified_distributed_account_from_the_current_system_account] + }).catch((err: BusinessError) => { + console.error('setOsAccountDistributedInfo exception: ' + JSON.stringify(err)); + // [StartExclude unbind_the_specified_distributed_account_from_the_current_system_account] + this.message = 'Failed to unbind distributed account' + // [EndExclude unbind_the_specified_distributed_account_from_the_current_system_account] + }); + // [End unbind_the_specified_distributed_account_from_the_current_system_account] + } + + private async bindSpecifyManageDistributedAccounts(): Promise { + // [Start determine_the_target_system_account_and_define_the_distributed_account_information_to_be_logged_in] + let localId: number = 100; + let distributedInfo: distributedAccount.DistributedInfo = { + name: 'ZhangSan', + id: '12345', + event: 'Ohos.account.event.LOGIN', + }; + // [End determine_the_target_system_account_and_define_the_distributed_account_information_to_be_logged_in] + + // [Start bind_the_specified_distributed_account_to_the_current_system_account] + await distributedAccountAbility.setOsAccountDistributedInfoByLocalId(localId, distributedInfo).then(() => { + console.log('setOsAccountDistributedInfoByLocalId successfully'); + }).catch((err: BusinessError) => { + console.error('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); + // [StartExclude bind_the_specified_distributed_account_to_the_current_system_account] + this.message = 'Failed to bind distributed account on the specified system account: ' + JSON.stringify(err); + // [EndExclude bind_the_specified_distributed_account_to_the_current_system_account] + }); + // [End bind_the_specified_distributed_account_to_the_current_system_account] + + // [Start view_the_login_information_of_a_distributed_account] + distributedAccountAbility.getOsAccountDistributedInfoByLocalId(localId) + .then((data: distributedAccount.DistributedInfo) => { + console.log('distributed information: ' + JSON.stringify(data)); + // [StartExclude view_the_login_information_of_a_distributed_account] + this.message = 'Bind distributed account on the specified system account: ' + data.name; + // [EndExclude view_the_login_information_of_a_distributed_account] + }).catch((err: BusinessError) => { + console.error('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); + // [StartExclude view_the_login_information_of_a_distributed_account] + this.message = 'Failed to get distributed account on the specified system account: ' + JSON.stringify(err); + // [EndExclude view_the_login_information_of_a_distributed_account] + }); + // [End view_the_login_information_of_a_distributed_account] + } + + private async unbindSpecifyManageDistributedAccounts(): Promise { + // [Start determine_the_target_system_account_and_define_the_distributed_account_information_to_be_logged_out] + let localId: number = 100; + let distributedInfo: distributedAccount.DistributedInfo = { + name: 'ZhangSan', + id: '12345', + event: 'Ohos.account.event.LOGOUT', + }; + // [End determine_the_target_system_account_and_define_the_distributed_account_information_to_be_logged_out] + + // [Start unbind_the_specified_distributed_account_from_the_target_system_account] + distributedAccountAbility.setOsAccountDistributedInfoByLocalId(localId, distributedInfo).then(() => { + console.log('setOsAccountDistributedInfoByLocalId successfully'); + // [StartExclude unbind_the_specified_distributed_account_from_the_target_system_account] + this.message = 'Successfully logged out and unbound distributed account on the specified system account' + // [EndExclude unbind_the_specified_distributed_account_from_the_target_system_account] + }).catch((err: BusinessError) => { + console.error('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err)); + // [StartExclude unbind_the_specified_distributed_account_from_the_target_system_account] + this.message = 'Failed to log out and unbind distributed account on the specified system account' + // [EndExclude unbind_the_specified_distributed_account_from_the_target_system_account] + }); + // [End unbind_the_specified_distributed_account_from_the_target_system_account] + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.DistributedAccount1')) + .margin(10) + .id('button1') + .onClick(() => this.bindCurrentManageDistributedAccounts()) + Button($r('app.string.DistributedAccount2')) + .margin(10) + .id('button2') + .onClick(() => this.unbindCurrentManageDistributedAccounts()) + Button($r('app.string.DistributedAccount3')) + .margin(10) + .id('button3') + .onClick(() => this.bindSpecifyManageDistributedAccounts()) + Button($r('app.string.DistributedAccount4')) + .margin(10) + .id('button4') + .onClick(() => this.unbindSpecifyManageDistributedAccounts()) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/main/module.json5 b/Account/ManageDistributedAccount/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ab3c58be13aa74b5ce6d1c1eba75f4a854517414 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/main/module.json5 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS" + }], + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/main/resources/base/element/color.json b/Account/ManageDistributedAccount/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Account/ManageDistributedAccount/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/Account/ManageDistributedAccount/entry/src/main/resources/base/element/string.json b/Account/ManageDistributedAccount/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fd8ed54be3d64ad16b0c9fa46bfb2c3294b569a0 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "DistributedAccount1", + "value": "Log in and bind distributed account on the current system account" + }, + { + "name": "DistributedAccount2", + "value": "Log out and unbind distributed account on the current system account" + }, + { + "name": "DistributedAccount3", + "value": "Log in and bind distributed account on the specified system account" + }, + { + "name": "DistributedAccount4", + "value": "Log out and unbind distributed account on the specified system account" + } + ] +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/main/resources/base/media/background.png b/Account/ManageDistributedAccount/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/Account/ManageDistributedAccount/entry/src/main/resources/base/media/background.png differ diff --git a/Account/ManageDistributedAccount/entry/src/main/resources/base/media/foreground.png b/Account/ManageDistributedAccount/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/Account/ManageDistributedAccount/entry/src/main/resources/base/media/foreground.png differ diff --git a/Account/ManageDistributedAccount/entry/src/main/resources/base/media/layered_image.json b/Account/ManageDistributedAccount/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Account/ManageDistributedAccount/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/Account/ManageDistributedAccount/entry/src/main/resources/base/media/startIcon.png b/Account/ManageDistributedAccount/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Account/ManageDistributedAccount/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/backup_config.json b/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/main_pages.json b/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/Account/ManageDistributedAccount/entry/src/main/resources/dark/element/color.json b/Account/ManageDistributedAccount/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Account/ManageDistributedAccount/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/Account/ManageDistributedAccount/entry/src/mock/mock-config.json5 b/Account/ManageDistributedAccount/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/Ability.test.ets b/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..915855c45b514631b0cd26fd559926b27919fd55 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} +export default function abilityTest() { + describe('DistributedAccountsTest', () => { + /* + * 打开应用,依次点击页面中按钮 + * 使用分布式账号接口功能 + */ + it('distributedAccountsExample', 0, async (done: Function) => { + console.info("uitest: TestUiExample begin"); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + await sleep(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info("get top ability"); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.id('button1')); + await button1.click(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.id('show')); + let content1: string = await text.getText(); + expect(content1).assertEqual('Bind distributed account: ZhangSan'); + + const button2 = await driver.findComponent(ON.id('button2')); + await button2.click(); + await driver.delayMs(1000); + let content2: string = await text.getText(); + expect(content2).assertEqual('Successfully unbound distributed account'); + + const button3 = await driver.findComponent(ON.id('button3')); + await button3.click(); + await driver.delayMs(1000); + let content3: string = await text.getText(); + expect(content3).assertEqual('Bind distributed account on the specified system account: ZhangSan'); + + const button4 = await driver.findComponent(ON.id('button4')); + await button4.click(); + await driver.delayMs(1000); + let content4: string = await text.getText(); + expect(content4) + .assertEqual('Successfully logged out and unbound distributed account on the specified system account'); + done(); + console.info("uitest: TestUiExample end"); + }) + }) +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/List.test.ets b/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/ohosTest/module.json5 b/Account/ManageDistributedAccount/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Account/ManageDistributedAccount/entry/src/test/List.test.ets b/Account/ManageDistributedAccount/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/entry/src/test/LocalUnit.test.ets b/Account/ManageDistributedAccount/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/Account/ManageDistributedAccount/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/Account/ManageDistributedAccount/hvigor/hvigor-config.json5 b/Account/ManageDistributedAccount/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/Account/ManageDistributedAccount/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/Account/ManageDistributedAccount/hvigorfile.ts b/Account/ManageDistributedAccount/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/Account/ManageDistributedAccount/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/ManageDistributedAccount/oh-package.json5 b/Account/ManageDistributedAccount/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/Account/ManageDistributedAccount/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/Account/ManageDistributedAccount/ohosTest.md b/Account/ManageDistributedAccount/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..364f669fd15bf085ee67f498bf7b4916c8ec14e0 --- /dev/null +++ b/Account/ManageDistributedAccount/ohosTest.md @@ -0,0 +1,11 @@ +# ManageDistributedAccount 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------ | ------------ | ------------------------------------------ | -------------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Log in and bind distributed account on the current system account | 位于首页 | 点击'Log in and bind distributed account on the current system account' | 页面显示'Bind distributed account: ZhangSan' | 是 | Pass | +| Log out and unbind distributed account on the current system account | 位于首页 | 点击'Log out and unbind distributed account on the current system account' | 页面显示'Successfully unbound distributed account' | 是 | Pass | +| Log in and bind distributed account on the specified system account | 位于首页 | 点击'Log in and bind distributed account on the specified system account' | 页面显示'指定的系统账号上Bind distributed account: ZhangSan' | 是 | Pass | +| Log out and unbind distributed account on the specified system account | 位于首页 | 点击'Log out and unbind distributed account on the specified system account' | 页面显示'指定系统账号上登出Successfully unbound distributed account' | 是 | Pass | \ No newline at end of file diff --git a/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_1.png b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_1.png new file mode 100644 index 0000000000000000000000000000000000000000..468804a9bded5cd7abfc0e5d8f1b686cea9a281c Binary files /dev/null and b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_1.png differ diff --git a/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_2.png b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_2.png new file mode 100644 index 0000000000000000000000000000000000000000..285dc2044b277e98fab204c5e8d23005a6d6615b Binary files /dev/null and b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_2.png differ diff --git a/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_3.png b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_3.png new file mode 100644 index 0000000000000000000000000000000000000000..51f9f245174a540e6136017ec679ac26809509d1 Binary files /dev/null and b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_3.png differ diff --git a/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_4.png b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_4.png new file mode 100644 index 0000000000000000000000000000000000000000..83e36c3fa8715332a9057754727a7c6762ac1844 Binary files /dev/null and b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_4.png differ diff --git a/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_5.png b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_5.png new file mode 100644 index 0000000000000000000000000000000000000000..be827dc3a026b33836334a927c9853240489a4f2 Binary files /dev/null and b/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_5.png differ diff --git a/Account/ManageSystemAccountCredentials/.gitignore b/Account/ManageSystemAccountCredentials/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Account/ManageSystemAccountCredentials/.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/Account/ManageSystemAccountCredentials/AppScope/app.json5 b/Account/ManageSystemAccountCredentials/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..67a573f30005c9281a33397b362463e39aeb9519 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.samples.managesystemaccountcredentials", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json b/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..249189f1407c54943f0b7ba0a94be9e83b9784da --- /dev/null +++ b/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageSystemAccountCredentials" + } + ] +} diff --git a/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png b/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png differ diff --git a/Account/ManageSystemAccountCredentials/README.md b/Account/ManageSystemAccountCredentials/README.md new file mode 100644 index 0000000000000000000000000000000000000000..eea33effc754f08a69fd224d096ba2ff44ec9d30 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/README.md @@ -0,0 +1,82 @@ +# 管理系统账号凭据 + +### 介绍 + +凭据可用于认证用户的身份,本文档将介绍如何录入、认证、更新、查询和删除指定系统账号的凭据。 + +该工程中展示的代码详细描述可查如下链接: + +- [ 管理系统账号凭据](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-os-account-credential.md) + +### 效果预览 + +| 首页 | 执行录入PIN码 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| 执行认证PIN码 | 执行更新凭据 | +| | | +| 执行查询凭据信息 | 执行删除凭据 | +| | | + +### 使用说明 + +1. 在主界面,点击'Enter PIN code',执行录入PIN码。 +2. 点击'Authenticate PIN code',执行认证PIN码。 +3. 点击'Update credentials',执行更新凭据。 +4. 点击'Query credential information',执行查询凭据信息。 +5. 点击'Delete credentials',执行删除凭据。 +6. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 管理系统账号凭据示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_USER_IDM](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanageuseridm) + +[ohos.permission.ACCESS_PIN_AUTH](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccesspinauth) + +[ohos.permission.ACCESS_USER_AUTH_INTERNAL](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccessuserauthinternal) + +[ohos.permission.USE_USER_IDM](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionuseuseridm) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo Account/ManageSystemAccountCredentials > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/build-profile.json5 b/Account/ManageSystemAccountCredentials/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/Account/ManageSystemAccountCredentials/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "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/Account/ManageSystemAccountCredentials/code-linter.json5 b/Account/ManageSystemAccountCredentials/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/.gitignore b/Account/ManageSystemAccountCredentials/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/build-profile.json5 b/Account/ManageSystemAccountCredentials/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/hvigorfile.ts b/Account/ManageSystemAccountCredentials/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/ManageSystemAccountCredentials/entry/obfuscation-rules.txt b/Account/ManageSystemAccountCredentials/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Account/ManageSystemAccountCredentials/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/Account/ManageSystemAccountCredentials/entry/oh-package.json5 b/Account/ManageSystemAccountCredentials/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets b/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets b/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..053b9735e63e31c82f28006ea62871f365bd3d27 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,532 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_system_account_module] +import { osAccount } from '@kit.BasicServicesKit'; +// [End import_system_account_module] +import account_osAccount from "@ohos.account.osAccount"; + +function strToUint8Arr(str: string): Uint8Array { + const buffer: number[] = []; + for (let i = 0; i < str.length; i++) { + const char = str.charAt(i); + const code = char.codePointAt(0)!; + if (code < 0x80) { + buffer.push(code); + } else if (code < 0x800) { + buffer.push(0xc0 + (code >> 6)); + buffer.push(0x80 + (code & 0x3f)); + } else if (code < 0x10000) { + buffer.push(0xe0 + (code >> 12)); + buffer.push(0x80 + ((code >> 6) & 0x3f)); + buffer.push(0x80 + (code & 0x3f)); + } + } + return new Uint8Array(buffer); +} + +@Entry +@Component +struct SystemAccount { + @State message: string = 'Nothing'; + @State cid: number = 100; + @State textPassword: string = '' + @State oldTextPassword: string = '' + + private async addCred(): Promise { + try { + this.cid = await account_osAccount.getAccountManager().getForegroundOsAccountLocalId(); + // [Start create_credential_management_object] + let userIDM = new account_osAccount.UserIdentityManager(); + // [End create_credential_management_object] + let password: Uint8Array = new Uint8Array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36]); + if (this.textPassword != '') { + password = strToUint8Arr(this.textPassword); + } + let PINAuth = new account_osAccount.PINAuth(); + // [Start define_pin_credential_information] + let credentialInfo :account_osAccount.CredentialInfo = { + // [StartExclude define_pin_credential_information] + accountId: this.cid, + // [EndExclude define_pin_credential_information] + credType:account_osAccount.AuthType.PIN, + credSubType:account_osAccount.AuthSubType.PIN_SIX, + token:new Uint8Array([]) + } + // [End define_pin_credential_information] + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, password); + } + }) + userIDM.closeSession(this.cid); + userIDM.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + // [Start call_the_api_to_add_the_specified_credentials] + userIDM.addCredential(credentialInfo,{ + onResult: (err, extraInfo)=>{ + console.log('addCredential result: ' + JSON.stringify(err)); + console.log('edential info: ' + JSON.stringify(extraInfo)); + // [StartExclude call_the_api_to_add_the_specified_credentials] + if (err == 0) { + this.message = 'PIN code entry successful'; + } else { + this.message = 'PIN code entry failed: ' + JSON.stringify(err); + } + PINAuth.unregisterInputer(); + userIDM.closeSession(this.cid); + // [EndExclude call_the_api_to_add_the_specified_credentials] + }}) + // [End call_the_api_to_add_the_specified_credentials] + }).catch((err: Error)=>{ + console.error('openSession failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to open session:' + JSON.stringify(err); + }) + } catch (e) { + console.error('getEnrolledId cur failed, error: ' + JSON.stringify(e)); + } + } + + private async auth(): Promise { + try { + let userIDM = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let PINAuth = new account_osAccount.PINAuth(); + let password: Uint8Array = new Uint8Array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36]); + if (this.textPassword != '') { + password = strToUint8Arr(this.textPassword); + } + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, password); + } + }) + userIDM.closeSession(this.cid); + userIDM.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + let authType: osAccount.AuthType = osAccount.AuthType.PIN; + let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; + // [Start call_the_auth_operation_for_authentication] + userAuth.auth(data, authType, authTrustLevel, { + onResult: (result: number, extraInfo: osAccount.AuthResult) => { + console.log('pin auth result = ' + result); + console.log('pin auth extraInfo = ' + JSON.stringify(extraInfo)); + let authToken = extraInfo.token; + // [StartExclude call_the_auth_operation_for_authentication] + if(result == 0) { + this.message = 'PIN code entry successful'; + } else { + this.message = 'PIN code authentication failed: ' + result; + } + // [EndExclude call_the_auth_operation_for_authentication] + } + }); + // [End call_the_auth_operation_for_authentication] + }).catch((err: Error)=>{ + console.error('openSession failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to open session:' + JSON.stringify(err); + }) + } catch (err) { + console.error('getEnrolledId cur failed, error: ' + JSON.stringify(err)); + } + } + + private async addBiologyCred(): Promise { + // [Start define_facial_credential_information] + let faceCredInfo: osAccount.CredentialInfo = { + credType: osAccount.AuthType.FACE, + credSubType: osAccount.AuthSubType.FACE_2D, + token: new Uint8Array([1, 2, 3, 4, 5]) + } + // [End define_facial_credential_information] + // [Start define_fingerprint_credential_information] + let fingerprintCredInfo: osAccount.CredentialInfo = { + credType: osAccount.AuthType.FINGERPRINT, + credSubType: osAccount.AuthSubType.FINGERPRINT_CAPACITIVE, + token: new Uint8Array([1, 2, 3, 4, 5]) + } + // [End define_fingerprint_credential_information] + try { + let userIDM = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let PINAuth = new account_osAccount.PINAuth(); + let password: Uint8Array = new Uint8Array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36]); + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, password); + } + }) + userIDM.closeSession(this.cid); + userIDM.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + let authType: osAccount.AuthType = osAccount.AuthType.PIN; + let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; + userAuth.auth(data, authType, authTrustLevel, { + onResult: (result: number, extraInfo: osAccount.AuthResult) => { + console.log('pin auth result = ' + result); + console.log('pin auth extraInfo = ' + JSON.stringify(extraInfo)); + faceCredInfo.token = extraInfo.token; + fingerprintCredInfo.token = extraInfo.token; + // [Start input_facial_credential_information] + userIDM.addCredential(faceCredInfo, { + onResult: (code: number, result: osAccount.RequestResult) => { + console.log('add face credential, resultCode: ' + code); + console.log('add face credential, request result: ' + result); + // [StartExclude input_facial_credential_information] + if(code == 0) { + this.message = 'Successfully entered facial credentials'; + } else { + this.message = 'Failed to enter facial credentials: ' + code; + } + // [EndExclude input_facial_credential_information] + } + }); + // [End input_facial_credential_information] + // [Start enter_the_fingerprint_credentials] + userIDM.addCredential(fingerprintCredInfo, { + onResult: (code: number, result: osAccount.RequestResult) => { + console.log('add fingerprint credential, resultCode: ' + code); + console.log('add fingerprint credential, request result: ' + result); + // [StartExclude enter_the_fingerprint_credentials] + if(code == 0) { + this.message += 'Successfully entered fingerprint credentials'; + } else { + this.message = 'Failed to enter fingerprint credentials: ' + code; + } + // [EndExclude enter_the_fingerprint_credentials] + } + }); + // [End enter_the_fingerprint_credentials] + } + }); + }).catch((err: Error)=>{ + console.error('openSession failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to open session:' + JSON.stringify(err); + }) + } catch (err) { + console.error('getEnrolledId cur failed, error: ' + JSON.stringify(err)); + } + } + + private async biologyAuth(): Promise { + try { + let userIDM = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let PINAuth = new account_osAccount.PINAuth(); + let password: Uint8Array = new Uint8Array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36]); + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, password); + } + }) + userIDM.closeSession(this.cid); + userIDM.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + let authType: osAccount.AuthType = osAccount.AuthType.FACE; + let authTrustLevel: osAccount.AuthTrustLevel = osAccount.AuthTrustLevel.ATL1; + // [Start call_the_auth_operation_for_face_authentication] + userAuth.auth(data, authType, authTrustLevel, { + onResult: (result: number, extraInfo: osAccount.AuthResult) => { + console.log('face auth result = ' + result); + console.log('face auth extraInfo = ' + JSON.stringify(extraInfo)); + // [StartExclude call_the_auth_operation_for_face_authentication] + if(result == 0) { + this.message = 'Successfully authenticated biometric credentials'; + } else { + this.message = 'Failed to authenticate biometric credentials: ' + result; + } + // [EndExclude call_the_auth_operation_for_face_authentication] + } + }); + // [End call_the_auth_operation_for_face_authentication] + }).catch((err: Error)=>{ + console.error('openSession failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to open session:' + JSON.stringify(err); + }) + } catch (err) { + console.error('getEnrolledId cur failed, error: ' + JSON.stringify(err)); + } + } + + private async updateCred(): Promise { + let userIDM = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let PINAuth = new account_osAccount.PINAuth(); + let oldPassword: Uint8Array = new Uint8Array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36]); + if (this.oldTextPassword != '') { + oldPassword = strToUint8Arr(this.oldTextPassword); + } + let password: Uint8Array = new Uint8Array([0x31, 0x31, 0x31, 0x31, 0x31, 0x31]); + if (this.textPassword != '') { + password = strToUint8Arr(this.textPassword); + } + // [Start define_the_credential_information_to_be_updated] + let credentialInfo :account_osAccount.CredentialInfo = { + // [StartExclude define_the_credential_information_to_be_updated] + accountId:this.cid, + // [EndExclude define_the_credential_information_to_be_updated] + credType:account_osAccount.AuthType.PIN, + credSubType:account_osAccount.AuthSubType.PIN_SIX, + token:new Uint8Array([]) + } + // [End define_the_credential_information_to_be_updated] + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, oldPassword); + } + }) + userIDM.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + userAuth.authUser(this.cid, data, account_osAccount.AuthType.PIN, + account_osAccount.AuthTrustLevel.ATL1, { + onResult:(err, authResult)=>{ + console.log('authUser err: ' + JSON.stringify(err)); + console.log('authUser info: ' + JSON.stringify(authResult)); + console.log('authUser info.userId: ' + authResult.accountId); + credentialInfo.token = authResult.token; + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(subType, callback) =>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, password) + } + }) + // [Start update_your_credentials] + userIDM.updateCredential(credentialInfo, { + onResult:(result: number, extraInfo: osAccount.RequestResult)=>{ + console.log('updateCredential result: ' + JSON.stringify(result)); + console.log('updateCredential extraInfo: ' + JSON.stringify(extraInfo)); + // [StartExclude update_your_credentials] + if(result == 0) { + this.message = 'Successfully updated PIN code credentials'; + } else { + this.message = 'Failed to update PIN code credentials: ' + JSON.stringify(result); + } + PINAuth.unregisterInputer(); + userIDM.closeSession(this.cid); + // [EndExclude update_your_credentials] + } + }) + // [End update_your_credentials] + } + }) + }).catch((err: Error)=>{ + console.error('openSession failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to open session:' + JSON.stringify(err); + }) + } + + private async getCred(): Promise { + let userIDM = new account_osAccount.UserIdentityManager(); + try { + userIDM.getAuthInfo((err, data)=>{ + console.log('getAuthInfo err: ' + JSON.stringify(err)); + console.log('getAuthInfo data: ' + JSON.stringify(data)); + this.message = 'Query information length: ' + data.length; + }) + // [Start obtain_credential_information_of_the_specified_type] + let enrolledFingerCredInfoList: osAccount.EnrolledCredInfo[] = + await userIDM.getAuthInfo(osAccount.AuthType.PIN); + // [End obtain_credential_information_of_the_specified_type] + } catch (err) { + console.error('getAuthInfo failed: ' + JSON.stringify(err)); + this.message = 'Query information failed: ' + JSON.stringify(err); + } + } + + private async deleteBiologyCred(): Promise { + let userIDM = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let PINAuth = new account_osAccount.PINAuth(); + // [Start obtain_the_credential_information_of_the_fingerprint_type] + let credentialId: Uint8Array = new Uint8Array([1, 2, 3, 4, 5]); + let token: Uint8Array = new Uint8Array([1, 2, 3, 4, 5]) + let credInfoList: osAccount.EnrolledCredInfo[] = + await userIDM.getAuthInfo(osAccount.AuthType.FINGERPRINT); + if (credInfoList.length != 0) { + credentialId = credInfoList[0].credentialId; + } + // [End obtain_the_credential_information_of_the_fingerprint_type] + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, + new Uint8Array([0x31, 0x31, 0x31, 0x31, 0x31, 0x31])); + } + }) + userIDM.closeSession(this.cid) + userIDM.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + userAuth.authUser(this.cid, data, account_osAccount.AuthType.PIN, + account_osAccount.AuthTrustLevel.ATL1, { + onResult:(err, authResult)=>{ + console.log('authUser err: ' + JSON.stringify(err)); + console.log('authUser info: ' + JSON.stringify(authResult)); + console.log('authUser info.userId: ' + authResult.accountId); + try { + // [Start delete_specified_credentials] + userIDM.delCred(credentialId, authResult.token, { + onResult: (result: number, extraInfo: osAccount.RequestResult) => { + console.log('delCred result = ' + result); + console.log('delCred extraInfo = ' + JSON.stringify(extraInfo)); + // [StartExclude delete_specified_credentials] + if(result == 0) { + this.message = 'Successfully deleted credentials'; + } else { + this.message = 'Failed to delete credentials: ' + result; + } + // [EndExclude delete_specified_credentials] + } + }); + // [End delete_specified_credentials] + } catch (e) { + console.error('delUser exception = ' + JSON.stringify(e)); + this.message = 'Failed to delete credentials: ' + JSON.stringify(e); + } + // [Start deactivate_pin_input_device] + PINAuth.unregisterInputer(); + // [End deactivate_pin_input_device] + // [Start close_the_session_and_end_credential_management] + userIDM.closeSession(this.cid); + // [End close_the_session_and_end_credential_management] + } + }) + }).catch((err: Error)=>{ + console.error('openSession failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to open session:' + JSON.stringify(err); + }) + } + + private async deleteCred(): Promise { + let userIDM = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let PINAuth = new account_osAccount.PINAuth(); + let password: Uint8Array = new Uint8Array([0x31, 0x31, 0x31, 0x31, 0x31, 0x31]); + if (this.textPassword != '') { + password = strToUint8Arr(this.textPassword); + } + PINAuth.unregisterInputer(); + PINAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, password); + } + }) + userIDM.closeSession(this.cid) + userIDM.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + userAuth.authUser(this.cid, data, account_osAccount.AuthType.PIN, + account_osAccount.AuthTrustLevel.ATL1, { + onResult:(err, authResult)=>{ + console.log('authUser err: ' + JSON.stringify(err)); + console.log('authUser info: ' + JSON.stringify(authResult)); + console.log('authUser info.userId: ' + authResult.accountId); + console.log('authUser info.token: ' + authResult.token); + try { + userIDM.delUser(authResult.token, { + onResult: (result: number, extraInfo: osAccount.RequestResult) => { + console.log('delUser result = ' + result); + console.log('delUser extraInfo = ' + JSON.stringify(extraInfo)); + if(result == 0) { + this.message = 'Successfully deleted PIN code credentials'; + } else { + this.message = 'Failed to delete PIN code credentials: ' + JSON.stringify(result); + } + + PINAuth.unregisterInputer(); + userIDM.closeSession(this.cid); + } + }); + } catch (e) { + console.error('delUser exception = ' + JSON.stringify(e)); + } + } + }) + }).catch((err: Error)=>{ + console.error('openSession failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to open session:' + JSON.stringify(err); + }) + } + + build() { + Column() { + TextInput({ text: this.textPassword, placeholder: 'input password...'}) + .placeholderColor(Color.Grey) + .placeholderFont({ size: 14, weight: 400 }) + .caretColor(Color.Blue) + .width(200) + .height(40) + .margin(10) + .fontSize(14) + .fontColor(Color.Black) + .onChange((value: string) => { + this.textPassword = value; + }) + TextInput({ text: this.oldTextPassword, placeholder: 'old password...'}) + .placeholderColor(Color.Grey) + .placeholderFont({ size: 14, weight: 400 }) + .caretColor(Color.Blue) + .width(200) + .height(40) + .margin(10) + .fontSize(14) + .fontColor(Color.Black) + .onChange((value: string) => { + this.oldTextPassword = value; + }) + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.ManageSystemAccountCredentials1')) + .margin(10) + .id('button1') + .onClick(() => this.addCred()) + Button($r('app.string.ManageSystemAccountCredentials2')) + .margin(10) + .id('button2') + .onClick(() => this.auth()) + Button($r('app.string.ManageSystemAccountCredentials3')) + .margin(10) + .id('button3') + .onClick(() => this.addBiologyCred()) + Button($r('app.string.ManageSystemAccountCredentials4')) + .margin(10) + .id('button4') + .onClick(() => this.biologyAuth()) + Button($r('app.string.ManageSystemAccountCredentials5')) + .margin(10) + .id('button5') + .onClick(() => this.updateCred()) + Button($r('app.string.ManageSystemAccountCredentials6')) + .margin(10) + .id('button6') + .onClick(() => this.getCred()) + Button($r('app.string.ManageSystemAccountCredentials7')) + .margin(10) + .id('button8') + .onClick(() => this.deleteBiologyCred()) + Button($r('app.string.ManageSystemAccountCredentials8')) + .margin(10) + .id('button7') + .onClick(() => this.deleteCred()) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 b/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fa8002f504bf50c1bf07a558e6665c2e125e4bcd --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_USER_IDM" + }, + { + "name": "ohos.permission.ACCESS_PIN_AUTH" + }, + { + "name": "ohos.permission.ACCESS_USER_AUTH_INTERNAL" + }, + { + "name": "ohos.permission.USE_USER_IDM" + } + ], + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/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/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/string.json b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2fe0787892f6c85c8ac11eaf73caeb7aeab0020f --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/string.json @@ -0,0 +1,48 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ManageSystemAccountCredentials" + }, + { + "name": "ManageSystemAccountCredentials1", + "value": "Enter PIN code" + }, + { + "name": "ManageSystemAccountCredentials2", + "value": "Authenticate PIN code" + }, + { + "name": "ManageSystemAccountCredentials3", + "value": "Enter biometric credentials" + }, + { + "name": "ManageSystemAccountCredentials4", + "value": "Authenticate biometric credentials" + }, + { + "name": "ManageSystemAccountCredentials5", + "value": "Update credentials" + }, + { + "name": "ManageSystemAccountCredentials6", + "value": "Query credential information" + }, + { + "name": "ManageSystemAccountCredentials7", + "value": "Delete biometric credentials" + }, + { + "name": "ManageSystemAccountCredentials8", + "value": "Delete credentials" + } + ] +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png differ diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png differ diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/layered_image.json b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Account/ManageSystemAccountCredentials/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/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json b/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/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/Account/ManageSystemAccountCredentials/entry/src/mock/mock-config.json5 b/Account/ManageSystemAccountCredentials/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/Ability.test.ets b/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e500640d0d1e343422b48aefa1a77a8ebd7f1dc8 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} +export default function abilityTest() { + describe('AccountCredentialsAbilityTest', () => { + /* + * 打开应用,依次点击页面中按钮 + * 使用系统凭证账号接口功能 + */ + it('accountCredentialsExample',0, async (done: Function) => { + console.info("uitest: TestUiExample begin"); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + await sleep(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info("get top ability"); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.id('button1')); + await button1.click(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.id('show')); + let content1: string = await text.getText(); + expect(content1).assertEqual('PIN code entry successful'); + + const button2 = await driver.findComponent(ON.id('button2')); + await button2.click(); + await driver.delayMs(1000); + let content2: string = await text.getText(); + expect(content2).assertEqual('PIN code entry successful'); + + const button3 = await driver.findComponent(ON.id('button5')); + await button3.click(); + await driver.delayMs(5000); + let content3: string = await text.getText(); + expect(content3).assertEqual('Successfully updated PIN code credentials'); + + const button4 = await driver.findComponent(ON.id('button6')); + await button4.click(); + await driver.delayMs(1000); + let content4: string = await text.getText(); + expect(content4).assertEqual('Query information length: 1'); + + const button5 = await driver.findComponent(ON.id('button7')); + await button5.click(); + await driver.delayMs(3000); + let content5: string = await text.getText(); + expect(content5).assertEqual('Successfully deleted PIN code credentials'); + done(); + console.info("uitest: TestUiExample end"); + }) + }) +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/List.test.ets b/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 b/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Account/ManageSystemAccountCredentials/entry/src/test/List.test.ets b/Account/ManageSystemAccountCredentials/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/entry/src/test/LocalUnit.test.ets b/Account/ManageSystemAccountCredentials/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 b/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/Account/ManageSystemAccountCredentials/hvigorfile.ts b/Account/ManageSystemAccountCredentials/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/Account/ManageSystemAccountCredentials/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/ManageSystemAccountCredentials/oh-package.json5 b/Account/ManageSystemAccountCredentials/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/Account/ManageSystemAccountCredentials/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/Account/ManageSystemAccountCredentials/ohosTest.md b/Account/ManageSystemAccountCredentials/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..2268c1c90558dd8a0b4a58c161f5e0747c9c3d4c --- /dev/null +++ b/Account/ManageSystemAccountCredentials/ohosTest.md @@ -0,0 +1,12 @@ +# ManageSystemAccountCredentials 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------------ | --------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Enter PIN code | 位于首页 | 点击'Enter PIN code' | 页面显示“PIN code entry successful” | 是 | Pass | +| Authenticate PIN code | 位于首页 | 点击'Authenticate PIN code' | 页面显示“PIN code entry successful” | 是 | Pass | +| Update credentials | 位于首页 | 点击'Update credentials' | 页面显示“Successfully updated PIN code credentials” | 是 | Pass | +| Query credential information | 位于首页 | 点击'Query credential information' | 页面显示“Query information length:1” | 是 | Pass | +| Delete credentials | 位于首页 | 点击'Delete credentials' | 页面显示“Successfully deleted PIN code credentials” | 是 | Pass | \ No newline at end of file diff --git a/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png new file mode 100644 index 0000000000000000000000000000000000000000..42f43349352fe4d0ee4201410ebad572cf508341 Binary files /dev/null and b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png differ diff --git a/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png new file mode 100644 index 0000000000000000000000000000000000000000..e190b36d6184400dbb043b378340c8e70e0ce503 Binary files /dev/null and b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png differ diff --git a/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png new file mode 100644 index 0000000000000000000000000000000000000000..3a977ab2959b85ba2e6de1368e0ba2e4fa0888ef Binary files /dev/null and b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png differ diff --git a/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png new file mode 100644 index 0000000000000000000000000000000000000000..49c2f301a595c25a342bb610e5538800fe07804d Binary files /dev/null and b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png differ diff --git a/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png new file mode 100644 index 0000000000000000000000000000000000000000..a67b5d00bbd1d0c979f849891fbff0eeaa64a86d Binary files /dev/null and b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png differ diff --git a/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_6.png b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_6.png new file mode 100644 index 0000000000000000000000000000000000000000..5d8283bfd24f2af70725ba7e31ad369bb59a13d2 Binary files /dev/null and b/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_6.png differ diff --git a/Account/ManagerApplicationAccount/.gitignore b/Account/ManagerApplicationAccount/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Account/ManagerApplicationAccount/.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/Account/ManagerApplicationAccount/AppScope/app.json5 b/Account/ManagerApplicationAccount/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aeff47f52adeccb1ff3512d5603808211a189be0 --- /dev/null +++ b/Account/ManagerApplicationAccount/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.samples.managerapplicationaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/Account/ManagerApplicationAccount/AppScope/resources/base/element/string.json b/Account/ManagerApplicationAccount/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f6d7ea24284e3dcce83c0dbe00eb3c0a991889ae --- /dev/null +++ b/Account/ManagerApplicationAccount/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManagerApplicationAccount" + } + ] +} diff --git a/Account/ManagerApplicationAccount/AppScope/resources/base/media/app_icon.png b/Account/ManagerApplicationAccount/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/Account/ManagerApplicationAccount/AppScope/resources/base/media/app_icon.png differ diff --git a/Account/ManagerApplicationAccount/README.md b/Account/ManagerApplicationAccount/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2e84646fa621ad090e8b5f5636ea4dcaff9a8acd --- /dev/null +++ b/Account/ManagerApplicationAccount/README.md @@ -0,0 +1,79 @@ +# 管理应用账号 + +### 介绍 + +1.应用开发者可以使用[应用账号SDK](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-appAccount.md)管理本应用的账号数据。 + +能力限制:应用卸载场景下,被卸载应用的账号数据会被删除;本地账号删除场景下,被删除本地账号下的所有应用的账号数据会被删除。 + +2.实现对以下指南文件中 [管理应用账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-application-account.md#/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-appAccount.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | **执行创建应用账号** | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| **执行查询应用账号** | **执行存取账号的凭据** | +| | | +| **执行存取账号的自定义数据** | **执行存取账号的授权令牌** | +| | | +| **执行删除应用账号** | | +| | | + +### 使用说明 + +1. 在主界面,可以点击’Create application account‘,创建应用账号。 +2. 点击’Query application account‘,查询应用账号。 +3. 点击’Access account credentials‘,存取账号的凭据。 +4. 点击’Access custom data of the account‘,存取账号的自定义数据。 +5. 点击’Access account authorization token‘,存取账号的授权令牌。 +6. 点击’Delete application account‘,删除应用账号。 +7. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ └── pages + │ │ └── Index.ets // 管理应用账号示例代码 + │ ├── module.json5 + │ └── resources + └── ohosTest + └── ets + └── test + └── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo Account/ApplicationAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/build-profile.json5 b/Account/ManagerApplicationAccount/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/Account/ManagerApplicationAccount/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "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/Account/ManagerApplicationAccount/code-linter.json5 b/Account/ManagerApplicationAccount/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/Account/ManagerApplicationAccount/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/.gitignore b/Account/ManagerApplicationAccount/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/build-profile.json5 b/Account/ManagerApplicationAccount/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/hvigorfile.ts b/Account/ManagerApplicationAccount/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/ManagerApplicationAccount/entry/obfuscation-rules.txt b/Account/ManagerApplicationAccount/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Account/ManagerApplicationAccount/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/Account/ManagerApplicationAccount/entry/oh-package.json5 b/Account/ManagerApplicationAccount/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/Account/ManagerApplicationAccount/entry/src/main/ets/entryability/EntryAbility.ets b/Account/ManagerApplicationAccount/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Account/ManagerApplicationAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/main/ets/pages/Index.ets b/Account/ManagerApplicationAccount/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a071985d9a513d513d8512bb3cf6f03d189a32d --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_the_application_account_module] +import { appAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_the_application_account_module] + +// [Start obtain_the_instance_object_of_the_application_account] +const appAccountManager = appAccount.createAppAccountManager(); +// [End obtain_the_instance_object_of_the_application_account] + +@Entry +@Component +struct Index { + @State message: string = 'No Name'; + + private async createAccount(): Promise { + // [Start parameter_preparation] + let name: string = 'ZhangSan'; + let options: appAccount.CreateAccountOptions = { + customData: { + age: '10' + } + }; + // [End parameter_preparation] + // [Start create_an_app_account_based_on_the_name_and_options] + try { + await appAccountManager.createAccount(name, options); + console.log('createAccount successfully'); + // [StartExclude create_an_app_account_based_on_the_name_and_options] + this.message = 'Account creation successful'; + // [EndExclude create_an_app_account_based_on_the_name_and_options] + } catch (err) { + console.error('createAccount failed, error: ' + JSON.stringify(err)); + // [StartExclude create_an_app_account_based_on_the_name_and_options] + this.message = 'Account creation failed: ' + JSON.stringify(err); + // [EndExclude create_an_app_account_based_on_the_name_and_options] + } + // [End create_an_app_account_based_on_the_name_and_options] + } + + private async getAccounts(): Promise { + // [Start query_the_account_list] + appAccountManager.getAllAccounts().then((data: appAccount.AppAccountInfo[]) => { + console.debug('getAllAccounts successfully, data: ' + JSON.stringify(data)); + // [StartExclude query_the_account_list] + this.message = 'Query account result: ' + data[0].name; + // [EndExclude query_the_account_list] + }).catch((err: BusinessError) => { + console.error('getAllAccounts failed, error: ' + JSON.stringify(err)); + // [StartExclude query_the_account_list] + this.message = 'Query account failed: ' + JSON.stringify(err); + // [EndExclude query_the_account_list] + }); + // [End query_the_account_list] + } + + private async setCredential(): Promise { + // [Start prepare_parameters_to_specify_the_account_name_credential_type_and_credential] + let name: string = 'ZhangSan'; + let credentialType: string = 'PIN_SIX'; + let credential: string = 'xxxxxx'; + // [End prepare_parameters_to_specify_the_account_name_credential_type_and_credential] + + // [Start set_the_credentials_for_your_account] + await appAccountManager.setCredential(name, credentialType, credential).then(() => { + console.log('setCredential successfully'); + }).catch((err: BusinessError) => { + console.error('setCredential failed: ' + JSON.stringify(err)); + // [StartExclude set_the_credentials_for_your_account] + this.message = 'Failed to set account credentials: ' + JSON.stringify(err); + // [EndExclude set_the_credentials_for_your_account] + }); + // [End set_the_credentials_for_your_account] + + // [Start obtain_the_credentials_for_your_account] + appAccountManager.getCredential(name, credentialType).then((data: string) => { + console.log('getCredential successfully, data: ' + data); + // [StartExclude obtain_the_credentials_for_your_account] + this.message = 'Successfully set account credentials: ' + data; + // [EndExclude obtain_the_credentials_for_your_account] + }).catch((err: BusinessError) => { + console.error('getCredential failed, error: ' + JSON.stringify(err)); + // [StartExclude obtain_the_credentials_for_your_account] + this.message = 'Failed to query account credentials: ' + JSON.stringify(err); + // [EndExclude obtain_the_credentials_for_your_account] + }); + // [End obtain_the_credentials_for_your_account] + } + + private async setCustomData(): Promise { + // [Start prepare_parameters_specify_the_account_name_and_custom_key_values] + let name: string = 'ZhangSan'; + let key: string = 'age'; + let value: string = '12'; + // [End prepare_parameters_specify_the_account_name_and_custom_key_values] + // [Start set_up_custom_data_for_your_account] + await appAccountManager.setCustomData(name, key, value).then(() => { + console.log('setCustomData successfully'); + }).catch((err: BusinessError) => { + console.error('setCustomData failed: ' + JSON.stringify(err)); + // [StartExclude set_up_custom_data_for_your_account] + this.message = 'Failed to set custom account credentials: ' + JSON.stringify(err); + // [EndExclude set_up_custom_data_for_your_account] + }); + // [End set_up_custom_data_for_your_account] + // [Start obtain_the_custom_data_of_the_account] + appAccountManager.getCustomData(name, key).then((data: string) => { + console.log('getCustomData successfully, data: ' + data); + // [StartExclude obtain_the_custom_data_of_the_account] + this.message = 'Successfully set custom account credentials, ' + key + ' is ' + data; + // [EndExclude obtain_the_custom_data_of_the_account] + }).catch((err: BusinessError) => { + console.error('getCustomData failed, error: ' + JSON.stringify(err)); + // [StartExclude obtain_the_custom_data_of_the_account] + this.message = 'Failed to query custom account credentials: ' + JSON.stringify(err); + // [EndExclude obtain_the_custom_data_of_the_account] + }); + // [End obtain_the_custom_data_of_the_account] + } + + private async setAuthToken(): Promise { + // [Start prepare_parameters_to_specify_the_account_name_account_owner_authorization_type_and_authorization_token] + let name: string = 'ZhangSan'; + let owner: string = 'com.samples.managerapplicationaccount'; + let authType: string = 'getSocialData'; + let token: string = 'xxxxxx'; + // [End prepare_parameters_to_specify_the_account_name_account_owner_authorization_type_and_authorization_token] + // [Start set_the_authorization_token_for_the_specified_authorization_type] + await appAccountManager.setAuthToken(name, authType, token).then(() => { + console.log('setAuthToken successfully'); + }).catch((err: BusinessError) => { + console.error('setAuthToken failed: ' + JSON.stringify(err)); + // [StartExclude set_the_authorization_token_for_the_specified_authorization_type] + this.message = 'Failed to store account authorization token: ' + JSON.stringify(err); + // [EndExclude set_the_authorization_token_for_the_specified_authorization_type] + }); + // [End set_the_authorization_token_for_the_specified_authorization_type] + // [Start obtain_an_authorization_token_for_the_specified_authorization_type] + await appAccountManager.getAuthToken(name, owner, authType).then((data: string) => { + console.log('getAuthToken successfully, data: ' + data); + // [StartExclude obtain_an_authorization_token_for_the_specified_authorization_type] + this.message = 'Successfully stored account authorization token: ' + data; + // [EndExclude obtain_an_authorization_token_for_the_specified_authorization_type] + }).catch((err: BusinessError) => { + console.error('getAuthToken failed, error: ' + JSON.stringify(err)); + // [StartExclude obtain_an_authorization_token_for_the_specified_authorization_type] + this.message = 'Failed to get account authorization token: ' + JSON.stringify(err); + // [EndExclude obtain_an_authorization_token_for_the_specified_authorization_type] + }); + // [End obtain_an_authorization_token_for_the_specified_authorization_type] + } + + private async removeAccount(): Promise { + // [Start delete_account] + let name: string = 'ZhangSan'; + appAccountManager.removeAccount(name).then(() => { + console.log('removeAccount successfully'); + // [StartExclude delete_account] + this.message = 'removeAccount successfully'; + // [EndExclude delete_account] + }).catch((err: BusinessError) => { + console.error('removeAccount failed, error: ' + JSON.stringify(err)); + // [StartExclude delete_account] + this.message = 'Account removal failed: ' + JSON.stringify(err); + // [EndExclude delete_account] + }); + // [End delete_account] + + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Application1')) + .margin(10) + .id('button1') + .onClick(() => this.createAccount()) + Button($r('app.string.Application2')) + .margin(10) + .id('button2') + .onClick(() => this.getAccounts()) + Button($r('app.string.Application3')) + .margin(10) + .id('button3') + .onClick(() => this.setCredential()) + Button($r('app.string.Application4')) + .margin(10) + .id('button4') + .onClick(() => this.setCustomData()) + Button($r('app.string.Application5')) + .margin(10) + .id('button5') + .onClick(() => this.setAuthToken()) + Button($r('app.string.Application6')) + .margin(10) + .id('button6') + .onClick(() => this.removeAccount()) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/main/module.json5 b/Account/ManagerApplicationAccount/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/color.json b/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Account/ManagerApplicationAccount/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/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/string.json b/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..599fe1e3ea8035e3be37b3e3c4e9966f75b88cbd --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "Application1", + "value": "Create application account" + }, + { + "name": "Application2", + "value": "Query application account" + }, + { + "name": "Application3", + "value": "Access account credentials" + }, + { + "name": "Application4", + "value": "Access custom data of the account" + }, + { + "name": "Application5", + "value": "Access account authorization token" + }, + { + "name": "Application6", + "value": "Delete application account" + } + ] +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/background.png b/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/background.png differ diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/foreground.png b/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/foreground.png differ diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/layered_image.json b/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Account/ManagerApplicationAccount/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/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/startIcon.png b/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/backup_config.json b/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/main_pages.json b/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/dark/element/color.json b/Account/ManagerApplicationAccount/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Account/ManagerApplicationAccount/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/Account/ManagerApplicationAccount/entry/src/main/resources/en_US/element/string.json b/Account/ManagerApplicationAccount/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8fddd8fce87fcaf4635a7294392822515acdc9b7 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AsyncConcurrencyOverview" + } + ] +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/main/resources/zh_CN/element/string.json b/Account/ManagerApplicationAccount/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..55f88339349ae1e6872f5a14b04db8fa78445b2b --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AsyncConcurrencyOverview" + } + ] +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/mock/mock-config.json5 b/Account/ManagerApplicationAccount/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/Ability.test.ets b/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..afaa47a2b8605108403c0f0163ccdad3c22f5fbe --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} +export default function abilityTest() { + describe('ApplicationAccountAbilityTest', () => { + /* + * 打开应用,依次点击页面中按钮 + * 使用应用账号接口功能 + */ + it('applicationAccountExample',0, async (done: Function) => { + console.info("uitest: TestUiExample begin"); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + await sleep(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info("get top ability"); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.id('button1')); + await button1.click(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.id('show')); + let content1: string = await text.getText(); + expect(content1).assertEqual('Account creation successful'); + + const button2 = await driver.findComponent(ON.id('button2')); + await button2.click(); + await driver.delayMs(1000); + let content2: string = await text.getText(); + expect(content2).assertEqual('Query account result: ZhangSan'); + + const button3 = await driver.findComponent(ON.id('button3')); + await button3.click(); + await driver.delayMs(1000); + let content3: string = await text.getText(); + expect(content3).assertEqual('Successfully set account credentials: xxxxxx'); + + const button4 = await driver.findComponent(ON.id('button4')); + await button4.click(); + await driver.delayMs(1000); + let content4: string = await text.getText(); + expect(content4).assertEqual('Successfully set custom account credentials, age is 12'); + + const button5 = await driver.findComponent(ON.id('button5')); + await button5.click(); + await driver.delayMs(1000); + let content5: string = await text.getText(); + expect(content5).assertEqual('Successfully stored account authorization token: xxxxxx'); + + const button6 = await driver.findComponent(ON.id('button6')); + await button6.click(); + await driver.delayMs(1000); + let content6: string = await text.getText(); + expect(content6).assertEqual('removeAccount successfully'); + done(); + console.info("uitest: TestUiExample end"); + }) + }) +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/List.test.ets b/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/ohosTest/module.json5 b/Account/ManagerApplicationAccount/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Account/ManagerApplicationAccount/entry/src/test/List.test.ets b/Account/ManagerApplicationAccount/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/entry/src/test/LocalUnit.test.ets b/Account/ManagerApplicationAccount/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/Account/ManagerApplicationAccount/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/hvigor/hvigor-config.json5 b/Account/ManagerApplicationAccount/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/Account/ManagerApplicationAccount/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/Account/ManagerApplicationAccount/hvigorfile.ts b/Account/ManagerApplicationAccount/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/Account/ManagerApplicationAccount/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/ManagerApplicationAccount/oh-package.json5 b/Account/ManagerApplicationAccount/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/Account/ManagerApplicationAccount/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/Account/ManagerApplicationAccount/ohosTest.md b/Account/ManagerApplicationAccount/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..cad8a8315a9af47212c7353e59eb6c21690d0c08 --- /dev/null +++ b/Account/ManagerApplicationAccount/ohosTest.md @@ -0,0 +1,13 @@ +# AsyncConcurrencyOverview 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | -------------------------- | --------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Create application account | 位于首页 | 点击'Create application account' | 页面显示'Account creation successful' | 是 | Pass | +| Query application account | 位于首页 | 点击'Query application account' | 页面显示'Query account result: ZhangSan' | 是 | Pass | +| Access account credentials | 位于首页 | 点击'Access account credentials' | 页面显示'Successfully set account credentials: xxxxxx' | 是 | Pass | +| Access custom data of the account | 位于首页 | 点击'Access custom data of the account’ | 页面显示'Successfully set custom account credentials, age is 12‘ | 是 | Pass | +| Access account authorization token | 位于首页 | 点击'Access account authorization token’ | 页面显示'Successfully stored account authorization token: xxxxxx‘ | 是 | Pass | +| Delete application account | 位于首页 | 点击'Delete application account’ | 页面显示'removeAccount successfully‘ | 是 | Pass | \ No newline at end of file diff --git a/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_1.png b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_1.png new file mode 100644 index 0000000000000000000000000000000000000000..e840eb7e55fc25e9b807f4f18727ca714c0847a7 Binary files /dev/null and b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_1.png differ diff --git a/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_2.png b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8ec82f37622be4a3bc2c905f0ee8efc0a1536082 Binary files /dev/null and b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_2.png differ diff --git a/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_3.png b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_3.png new file mode 100644 index 0000000000000000000000000000000000000000..3e78d78424a5b91b9508ebf040ca239eae6de99f Binary files /dev/null and b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_3.png differ diff --git a/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_4.png b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_4.png new file mode 100644 index 0000000000000000000000000000000000000000..0b6925fc1f9138fbe541b79d53e8dd86b6cc1878 Binary files /dev/null and b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_4.png differ diff --git a/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_5.png b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_5.png new file mode 100644 index 0000000000000000000000000000000000000000..f3da04caeaa894ea9de33a1779e5ed8906d73841 Binary files /dev/null and b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_5.png differ diff --git a/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_6.png b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_6.png new file mode 100644 index 0000000000000000000000000000000000000000..2a0130469bb7d2f9cb6b0a9b8408a22f29236253 Binary files /dev/null and b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_6.png differ diff --git a/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_7.png b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_7.png new file mode 100644 index 0000000000000000000000000000000000000000..abeb59ba0df57be165623d48a6113b14e3e6ff65 Binary files /dev/null and b/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_7.png differ diff --git a/Account/SystemAccount/.gitignore b/Account/SystemAccount/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/Account/SystemAccount/.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/Account/SystemAccount/AppScope/app.json5 b/Account/SystemAccount/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ffb36aacd699e82211fc965fc66e1a4dd6e42120 --- /dev/null +++ b/Account/SystemAccount/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.samples.systemaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/Account/SystemAccount/AppScope/resources/base/element/string.json b/Account/SystemAccount/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4b7f6c149123aef13cf93622c8c390011b23c951 --- /dev/null +++ b/Account/SystemAccount/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SystemAccount" + } + ] +} diff --git a/Account/SystemAccount/AppScope/resources/base/media/app_icon.png b/Account/SystemAccount/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/Account/SystemAccount/AppScope/resources/base/media/app_icon.png differ diff --git a/Account/SystemAccount/README.md b/Account/SystemAccount/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b767ccd963b137e9e40518e8bffc9e4e6d3fa237 --- /dev/null +++ b/Account/SystemAccount/README.md @@ -0,0 +1,97 @@ +# 系统账号 (管理系统账号和使用约束管控系统账号) + +### 介绍 + +1.管理系统账号: + +系统提供了用于管理系统账号的接口。 系统应用开发者在申请对应的权限后,可以创建、激活、修改和删除系统账号,实现对系统账号的生命周期管理;三方应用开发者可以查询系统账号的基本信息,以完成与系统账号相关的业务逻辑开发。 + +2.使用约束管控系统账号: + +账号管理模块提供了基于角色的访问控制机制,用户可以为系统账号设置约束,以限制目标账号的行为。 + +预定义的账号约束条件,可以参考 :[系统账号约束列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-osAccount.md#系统账号约束列表) + +3.实现对以下指南文件中 [管理系统账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-os-account.md) [使用约束管控系统账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/control-os-account-by-constraints.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | 使用约束管控系统账号页面 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| 执行Set the constraint list for the specified system account | 执行Determine if the specified constraint for the target system account is enabled | +| | | +| 管理系统账号首页 | 执行Create system account | +| | | +| 执行Query all system accounts | 执行Query specified system account information | +| | | +| 执行Modify system account avatar | 执行Modify system account nickname | +| | | +| 执行Delete system account | | +| | | + +### 使用说明 + +1. 在主界面,点击’UseConstraintManagementSystemAccount‘,进入约束管控系统账号页面。 +2. 点击’Set the constraint list for the specified system account‘,Set the constraint list for the specified system account。 +3. 点击’Determine if the specified constraint for the target system account is enabled‘,Determine if the specified constraint for the target system account is enabled。 +4. 点击’Go to ManageSystem‘,进入管理系统账号首页。 +5. 点击’Create system account‘,Create system account。 +6. 点击’Query all system accounts‘,Query all system accounts。 +7. 点击’Query specified system account information‘,Query specified system account information。 +8. 点击’Modify system account avatar‘,Modify system account avatar。 +9. 点击’Modify system account nickname‘,Modify system account nickname。 +10. 点击’Delete system account‘,Delete system account。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ └── pages + | | ├──SystemAccount + | | | ├── ManageSystemAccounts // 管理系统账号示例代码 + | | | └── UseConstraintManagementSystemAccount // 使用约束管控系统账号示例代码 + │ │ └── Index.ets // 系统账号首页 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ └── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagelocalaccounts) + +[ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissioninteractacrosslocalaccountsextension) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo Account/SystemAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/Account/SystemAccount/build-profile.json5 b/Account/SystemAccount/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/Account/SystemAccount/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "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/Account/SystemAccount/code-linter.json5 b/Account/SystemAccount/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/Account/SystemAccount/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/.gitignore b/Account/SystemAccount/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/Account/SystemAccount/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/Account/SystemAccount/entry/build-profile.json5 b/Account/SystemAccount/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/Account/SystemAccount/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/hvigorfile.ts b/Account/SystemAccount/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/Account/SystemAccount/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/SystemAccount/entry/obfuscation-rules.txt b/Account/SystemAccount/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/Account/SystemAccount/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/Account/SystemAccount/entry/oh-package.json5 b/Account/SystemAccount/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/Account/SystemAccount/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/Account/SystemAccount/entry/src/main/ets/entryability/EntryAbility.ets b/Account/SystemAccount/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/Account/SystemAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/Account/SystemAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/Account/SystemAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/ets/pages/Index.ets b/Account/SystemAccount/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..03155159c8eadbae023eb7ac642613afb9f1c101 --- /dev/null +++ b/Account/SystemAccount/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { CommonButton } from '../util/CommonButton'; + +@Entry +@Component +struct Index { + build() { + Scroll() { + Column() { + Text('SystemAccountHome') + .padding('15vp') + .width('100%') + .fontSize('25fp') + .textAlign(TextAlign.Center) + CommonButton({ + buttonName: 'ManageSystemAccounts', + buttonUrl: 'pages/SystemAccount/ManageSystemAccounts' + }); + CommonButton({ + buttonName: 'UseConstraintManagementSystemAccount', + buttonUrl: 'pages/SystemAccount/UseConstraintManagementSystemAccount' + }); + } + .padding('5vp') + .width('100%') + }.margin({ bottom: 60 }) + .width('100%') + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets b/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a1080220cb525fedb44d34b0ac15a67fc6712d9 --- /dev/null +++ b/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_system_account_module] +import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +// [End import_system_account_module] + +// [Start obtain_account_management_single_instance_object] +let accountManager = osAccount.getAccountManager(); +// [End obtain_account_management_single_instance_object] + +@Entry +@Component +struct ManageSystemAccounts { + @State message: string = 'No work done'; + @State createLocalId: number = -1; + + private async createOsAccount(): Promise { + // [Start specify_nickname_and_type_information_to_create_system_account] + let name: string = 'Bob'; + let type: osAccount.OsAccountType = osAccount.OsAccountType.NORMAL; + + accountManager.createOsAccount(name, type, (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ + console.log('createOsAccount err:' + JSON.stringify(err)); + console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); + // [StartExclude specify_nickname_and_type_information_to_create_system_account] + if (!err) { + this.message = 'Account creation successful. Account name: ' + JSON.stringify(osAccountInfo.localName); + this.createLocalId = osAccountInfo.localId; + } else { + this.message = 'Failed to create account: ' + JSON.stringify(err); + } + // [EndExclude specify_nickname_and_type_information_to_create_system_account] + }); + // [End specify_nickname_and_type_information_to_create_system_account] + } + + private async findAllOsAccount(): Promise { + // [Start query_the_full_account] + accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: osAccount.OsAccountInfo[])=>{ + console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); + console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); + // [StartExclude query_the_full_account] + if (!err) { + this.message = 'Query account successful. Account name:' + JSON.stringify(accountArr[0].localName); + } else { + this.message = 'Query account failed: ' + JSON.stringify(err); + } + // [EndExclude query_the_full_account] + }); + // [End query_the_full_account] + } + + private async findOsAccount(): Promise { + // [Start query_information_of_the_specified_account] + let localId: number = 100; + accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: osAccount.OsAccountInfo)=>{ + console.log('queryOsAccountById err:' + JSON.stringify(err)); + console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); + // [StartExclude query_information_of_the_specified_account] + if (!err) { + this.message = 'Query account successful. Account name for account 100: ' + JSON.stringify(accountInfo.localName); + } else { + this.message = 'Query account failed: ' + JSON.stringify(err); + } + // [EndExclude query_information_of_the_specified_account] + }); + // [End query_information_of_the_specified_account] + } + + private async changeOsAccountHead(): Promise { + // [Start change_system_account_avatar] + let localId: number = 100; + // [StartExclude change_system_account_avatar] + localId = this.createLocalId; + // [EndExclude change_system_account_avatar] + let newPhoto: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ + 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ + 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ + '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' + + accountManager.setOsAccountProfilePhoto(localId, newPhoto, (err: BusinessError)=>{ + console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); + // [StartExclude change_system_account_avatar] + if(!err) { + this.message = 'Successfully updated system account avatar' + } else { + this.message = 'Failed to update system account avatar: ' + JSON.stringify(err); + } + // [EndExclude change_system_account_avatar] + }); + // [End change_system_account_avatar] + } + + private async changeOsAccountName(): Promise { + // [Start change_system_account_name] + let localId: number = 100; + // [StartExclude change_system_account_name] + localId = this.createLocalId; + // [EndExclude change_system_account_name] + let newName: string = 'Tom'; + accountManager.setOsAccountName(localId, newName, (err: BusinessError) => { + if (err) { + console.error('setOsAccountName failed, error: ' + JSON.stringify(err)); + // [StartExclude change_system_account_name] + this.message = 'Failed to modify system account name: ' + JSON.stringify(err); + // [EndExclude change_system_account_name] + } else { + console.log('setOsAccountName successfully'); + // [StartExclude change_system_account_name] + this.message = 'Successfully modified system account name'; + // [EndExclude change_system_account_name] + } + }); + // [End change_system_account_name] + } + + private async activateOsAccount(): Promise { + // [Start activate_system_account] + let localId: number = 101; + // [StartExclude activate_system_account] + localId = this.createLocalId; + // [EndExclude activate_system_account] + accountManager.activateOsAccount(localId, (err: BusinessError)=>{ + if (err) { + console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); + // [StartExclude activate_system_account] + this.message = 'Failed to activate system account: ' + err.code; + // [EndExclude activate_system_account] + } else { + console.log('activateOsAccount successfully'); + // [StartExclude activate_system_account] + this.message = 'Successfully activated system account' + // [EndExclude activate_system_account] + } + }); + // [End activate_system_account] + } + + private async deleteOsAccount(): Promise { + // [Start delete_the_specified_account] + let localId: number = 101; + localId = this.createLocalId; + accountManager.removeOsAccount(localId, (err: BusinessError)=>{ + if (err) { + console.error('removeOsAccount failed, error: ' + JSON.stringify(err)); + // [StartExclude delete_the_specified_account] + this.message = 'Failed to delete system account: ' + JSON.stringify(err); + // [EndExclude delete_the_specified_account] + } else { + console.log('removeOsAccount successfully'); + // [StartExclude delete_the_specified_account] + this.message = 'Successfully deleted system account' + // [EndExclude delete_the_specified_account] + } + }); + // [End delete_the_specified_account] + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Manager1')) + .margin(10) + .id('button1') + .onClick(() => this.createOsAccount()) + Button($r('app.string.Manager2')) + .margin(10) + .id('button2') + .onClick(() => this.findAllOsAccount()) + Button($r('app.string.Manager3')) + .margin(10) + .id('button3') + .onClick(() => this.findOsAccount()) + Button($r('app.string.Manager4')) + .margin(10) + .id('button4') + .onClick(() => this.changeOsAccountHead()) + Button($r('app.string.Manager5')) + .margin(10) + .id('button5') + .onClick(() => this.changeOsAccountName()) + Button($r('app.string.Manager6')) + .margin(10) + .id('button6') + .onClick(() => this.activateOsAccount()) + Button($r('app.string.Manager7')) + .margin(10) + .id('button7') + .onClick(() => this.deleteOsAccount()) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets b/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets new file mode 100644 index 0000000000000000000000000000000000000000..078ee1310f1bb8f576ef2fa15ea9aa0d2238234e --- /dev/null +++ b/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start import_system_account_module] +import { osAccount } from '@kit.BasicServicesKit'; +// [End import_system_account_module] +import { router } from '@kit.ArkUI'; + +// [Start obtain_account_single_instance_object] +let accountManager = osAccount.getAccountManager(); +// [End obtain_account_single_instance_object] + +@Entry +@Component +struct UseConstraintManagementSystemAccount { + @State message: string = 'No work done'; + + private async setOsAccountConstraints(): Promise { + // [Start constraint_collections] + let localId: number = 100; + let constraint: string[] = [ 'constraint.wifi.set' ]; + // [End constraint_collections] + // [Start system_account_constraint] + try { + accountManager.setOsAccountConstraints(localId, constraint, true); + console.log('setOsAccountConstraints successfully'); + // [StartExclude system_account_constraint] + this.message = 'Successfully set the constraint list for the specified system account'; + // [EndExclude system_account_constraint] + } catch (err) { + console.error('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); + // [StartExclude system_account_constraint] + this.message = 'Failed to set the constraint list for the specified system account'; + // [EndExclude system_account_constraint] + } + // [End system_account_constraint] + } + + private async isOsAccountConstraintEnabled(): Promise { + // [Start specify_the_system_account_id_and_constraint_name] + let localId: number = 100; + let constraint: string = 'constraint.wifi.set'; + // [End specify_the_system_account_id_and_constraint_name] + // [Start check_whether_the_specified_constraint_is_enabled] + let isEnabled: boolean = await accountManager.isOsAccountConstraintEnabled(localId, constraint); + if (isEnabled) { + // your business logic + // [StartExclude check_whether_the_specified_constraint_is_enabled] + this.message = 'Set the constraint list for the specified system account'; + } else { + this.message = 'Can not set the constraint list for the specified system account'; + // [EndExclude check_whether_the_specified_constraint_is_enabled] + } + // [End check_whether_the_specified_constraint_is_enabled] + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Use1')) + .margin(10) + .id('button1') + .onClick(() => this.setOsAccountConstraints()) + Button($r('app.string.Use2')) + .margin(10) + .id('button2') + .onClick(() => this.isOsAccountConstraintEnabled()) + Button($r('app.string.Use3')) + .margin(10) + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/SystemAccount/ManageSystemAccounts' + }) + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/ets/util/CommonButton.ets b/Account/SystemAccount/entry/src/main/ets/util/CommonButton.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2d268bf3aec25d2dcec35d282290ebc90d9d7d9 --- /dev/null +++ b/Account/SystemAccount/entry/src/main/ets/util/CommonButton.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import router from '@ohos.router'; + +@Component +export struct CommonButton { + @State buttonName: string = ''; + @State buttonUrl: string = ''; + @State data: string = ''; + + build() { + Text(this.buttonName) + .id(this.buttonName) + .padding(px2vp(5)) + .fontSize(px2fp(24)) + .textAlign(TextAlign.Center) + .backgroundColor(Color.Blue) + .fontColor(Color.White) + .borderRadius(5) + .margin(px2vp(20)) + .padding(px2vp(15)) + .onClick(() => { + router.pushUrl({ + url: this.buttonUrl, + params: { + text: this.data, + buttonName: this.buttonName + } + }) + }) + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/module.json5 b/Account/SystemAccount/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0c29d1b3db38feff667efb16cbd32da2a96df7e6 --- /dev/null +++ b/Account/SystemAccount/entry/src/main/module.json5 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + }, + { + "name": "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION" + }], + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/resources/base/element/color.json b/Account/SystemAccount/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/Account/SystemAccount/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/Account/SystemAccount/entry/src/main/resources/base/element/string.json b/Account/SystemAccount/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a6934d02eacecd5cbad2c08b2e1223f1727fab26 --- /dev/null +++ b/Account/SystemAccount/entry/src/main/resources/base/element/string.json @@ -0,0 +1,56 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "system account" + }, + { + "name": "Manager1", + "value": "Create system account" + }, + { + "name": "Manager2", + "value": "Query all system accounts" + }, + { + "name": "Manager3", + "value": "Query specified system account information" + }, + { + "name": "Manager4", + "value": "Modify system account avatar" + }, + { + "name": "Manager5", + "value": "Modify system account nickname" + }, + { + "name": "Manager6", + "value": "Activate system account" + }, + { + "name": "Manager7", + "value": "Delete system account" + }, + { + "name": "Use1", + "value": "Set the constraint list for the specified system account" + }, + { + "name": "Use2", + "value": "Determine if the specified constraint for the target system account is enabled" + }, + { + "name": "Use3", + "value": "Go to ManageSystem" + } + ] +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/resources/base/media/background.png b/Account/SystemAccount/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/Account/SystemAccount/entry/src/main/resources/base/media/background.png differ diff --git a/Account/SystemAccount/entry/src/main/resources/base/media/foreground.png b/Account/SystemAccount/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/Account/SystemAccount/entry/src/main/resources/base/media/foreground.png differ diff --git a/Account/SystemAccount/entry/src/main/resources/base/media/layered_image.json b/Account/SystemAccount/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/Account/SystemAccount/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/Account/SystemAccount/entry/src/main/resources/base/media/startIcon.png b/Account/SystemAccount/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/Account/SystemAccount/entry/src/main/resources/base/media/startIcon.png differ diff --git a/Account/SystemAccount/entry/src/main/resources/base/profile/backup_config.json b/Account/SystemAccount/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/Account/SystemAccount/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/main/resources/base/profile/main_pages.json b/Account/SystemAccount/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..01e59d474ed71c8ce240b7b0e4c5bde146e57a3f --- /dev/null +++ b/Account/SystemAccount/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,7 @@ +{ + "src": [ + "pages/Index", + "pages/SystemAccount/ManageSystemAccounts", + "pages/SystemAccount/UseConstraintManagementSystemAccount" + ] +} diff --git a/Account/SystemAccount/entry/src/main/resources/dark/element/color.json b/Account/SystemAccount/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/Account/SystemAccount/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/Account/SystemAccount/entry/src/mock/mock-config.json5 b/Account/SystemAccount/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/Account/SystemAccount/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/ohosTest/ets/test/Ability.test.ets b/Account/SystemAccount/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ca272522bf3b12990942f335f7240a4d2c6ce3e --- /dev/null +++ b/Account/SystemAccount/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /* + * 打开应用,依次点击页面中按钮 + * 使用系统账号接口功能 + */ + it('UseConstraintManagementSystemAccountExample',0, async (done: Function) => { + console.info("uitest: TestUiExample begin"); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + await sleep(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info("get top ability"); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.id('UseConstraintManagementSystemAccount')); + await button1.click(); + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.id('button1')); + await button2.click(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.id('show')); + let content1: string = await text.getText(); + expect(content1).assertEqual('Successfully set the constraint list for the specified system account'); + + const button3 = await driver.findComponent(ON.id('button2')); + await button3.click(); + await driver.delayMs(1000); + let content2: string = await text.getText(); + expect(content2).assertEqual('Set the constraint list for the specified system account'); + + const button4 = await driver.findComponent(ON.id('button3')); + await button4.click(); + await driver.delayMs(1000); + + const button5 = await driver.findComponent(ON.id('button1')); + await button5.click(); + await driver.delayMs(10000); + const text2 = await driver.findComponent(ON.id('show')); + let content3: string = await text2.getText(); + expect(content3).assertEqual('Account creation successful. Account name: "Bob"'); + + const button6 = await driver.findComponent(ON.id('button2')); + await button6.click(); + await driver.delayMs(1000); + let content4: string = await text2.getText(); + expect(content4).assertEqual('Query account successful. Account name:"user"'); + + const button7 = await driver.findComponent(ON.id('button3')); + await button7.click(); + await driver.delayMs(1000); + let content5: string = await text2.getText(); + expect(content5).assertEqual('Query account successful. Account name for account 100: "user"'); + + const button8 = await driver.findComponent(ON.id('button4')); + await button8.click(); + await driver.delayMs(1000); + let content6: string = await text2.getText(); + expect(content6).assertEqual('Successfully updated system account avatar'); + + const button9 = await driver.findComponent(ON.id('button5')); + await button9.click(); + await driver.delayMs(1000); + let content7: string = await text2.getText(); + expect(content7).assertEqual('Successfully modified system account name'); + + const button10 = await driver.findComponent(ON.id('button7')); + await button10.click(); + await driver.delayMs(10000); + let content8: string = await text2.getText(); + expect(content8).assertEqual('Successfully deleted system account'); + done(); + console.info("uitest: TestUiExample end"); + }) + }) +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/ohosTest/ets/test/List.test.ets b/Account/SystemAccount/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/Account/SystemAccount/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/ohosTest/module.json5 b/Account/SystemAccount/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/Account/SystemAccount/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/Account/SystemAccount/entry/src/test/List.test.ets b/Account/SystemAccount/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/Account/SystemAccount/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/Account/SystemAccount/entry/src/test/LocalUnit.test.ets b/Account/SystemAccount/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/Account/SystemAccount/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/Account/SystemAccount/hvigor/hvigor-config.json5 b/Account/SystemAccount/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/Account/SystemAccount/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/Account/SystemAccount/hvigorfile.ts b/Account/SystemAccount/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/Account/SystemAccount/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/Account/SystemAccount/oh-package.json5 b/Account/SystemAccount/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/Account/SystemAccount/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/Account/SystemAccount/ohosTest.md b/Account/SystemAccount/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..95675252d0409de4a70ee9c4a27fbabfca69feca --- /dev/null +++ b/Account/SystemAccount/ohosTest.md @@ -0,0 +1,15 @@ +# SystemAccount 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------- | -------------------------------------------- | ---------------------------------------- | -------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Set the constraint list for the specified system account | 位于UseConstraintManagementSystemAccount页面 | 点击'Set the constraint list for the specified system account' | 页面显示“Successfully set the constraint list for the specified system account” | 是 | Pass | +| Determine if the specified constraint for the target system account is enabled | 位于UseConstraintManagementSystemAccount页面 | 点击'Determine if the specified constraint for the target system account is enabled' | 页面显示“Set the constraint list for the specified system account” | 是 | Pass | +| Create system account | 位于ManageSystemAccounts页面 | 点击'Create system account' | 页面显示“Account creation successful. Account name:: "Bob"” | 是 | Pass | +| Query all system accounts | 位于ManageSystemAccounts页面 | 点击'Query all system accounts' | 页面显示“Query account successful. Account name:"user"” | 是 | Pass | +| Query specified system account information | 位于ManageSystemAccounts页面 | 点击'Query specified system account information' | 页面显示“Query account successful. Account name for account 100: "user"” | 是 | Pass | +| Modify system account avatar | 位于ManageSystemAccounts页面 | 点击'Modify system account avatar' | 页面显示“Successfully updated system account avatar” | 是 | Pass | +| Modify system account nickname | 位于ManageSystemAccounts页面 | 点击'Modify system account nickname' | 页面显示“Successfully modified system account name” | 是 | Pass | +| Delete system account | 位于ManageSystemAccounts页面 | 点击'Delete system account' | 页面显示“Successfully deleted system account” | 是 | Pass | \ No newline at end of file diff --git a/Account/SystemAccount/screenshots/SystemAccount_1.png b/Account/SystemAccount/screenshots/SystemAccount_1.png new file mode 100644 index 0000000000000000000000000000000000000000..1d7ec794c6292a897740cfcde219814339a3994b Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_1.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_10.png b/Account/SystemAccount/screenshots/SystemAccount_10.png new file mode 100644 index 0000000000000000000000000000000000000000..30e8339df87811f81041e178bdeb09337bd22599 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_10.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_11.png b/Account/SystemAccount/screenshots/SystemAccount_11.png new file mode 100644 index 0000000000000000000000000000000000000000..8931d3c2a129fe1644eecb2b55d9b3a9b21b18d0 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_11.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_2.png b/Account/SystemAccount/screenshots/SystemAccount_2.png new file mode 100644 index 0000000000000000000000000000000000000000..26a2bae68313c755c3d8b380d7571cc5c1903783 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_2.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_3.png b/Account/SystemAccount/screenshots/SystemAccount_3.png new file mode 100644 index 0000000000000000000000000000000000000000..b2ebf0788fcecb471818e837027be14b279304f5 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_3.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_4.png b/Account/SystemAccount/screenshots/SystemAccount_4.png new file mode 100644 index 0000000000000000000000000000000000000000..003428c601687fd8d309b94e8d01facb9e671408 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_4.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_5.png b/Account/SystemAccount/screenshots/SystemAccount_5.png new file mode 100644 index 0000000000000000000000000000000000000000..b216e3b0281dd34abe0402d5af6f021100c0b4ca Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_5.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_6.png b/Account/SystemAccount/screenshots/SystemAccount_6.png new file mode 100644 index 0000000000000000000000000000000000000000..9f4c4e852eb50d3182412bfaa0a723bd3d33d316 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_6.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_7.png b/Account/SystemAccount/screenshots/SystemAccount_7.png new file mode 100644 index 0000000000000000000000000000000000000000..5137afedc7b49d54f893817ea4093c8e17de2f3c Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_7.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_8.png b/Account/SystemAccount/screenshots/SystemAccount_8.png new file mode 100644 index 0000000000000000000000000000000000000000..a743e513d97af5263509b3e8d8dc047b91a8c9e7 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_8.png differ diff --git a/Account/SystemAccount/screenshots/SystemAccount_9.png b/Account/SystemAccount/screenshots/SystemAccount_9.png new file mode 100644 index 0000000000000000000000000000000000000000..dfae1df5d9dcb2ae9c132e6112807ada63eec648 Binary files /dev/null and b/Account/SystemAccount/screenshots/SystemAccount_9.png differ