diff --git a/OAT.xml b/OAT.xml index 9705a1cbe38d1ac277d21d688189b738b49a37d6..fb7ba7ed70ddfb3f9e36e79d795f4fe6e7a8b114 100644 --- a/OAT.xml +++ b/OAT.xml @@ -1342,6 +1342,18 @@ Note:If the text contains special characters, please escape them according to th + + + + + + + + + + + + diff --git a/code/DocsSample/Account/DomainAccount/.gitignore b/code/DocsSample/Account/DomainAccount/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/AppScope/app.json5 b/code/DocsSample/Account/DomainAccount/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..24b7bbd9efd9aa0d65abe633451875c0949c556a --- /dev/null +++ b/code/DocsSample/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.sample.domainaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Account/DomainAccount/AppScope/resources/base/element/string.json b/code/DocsSample/Account/DomainAccount/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..1cbfc016cbd9684ea1c1bbc44c328dbed4b7e279 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DomainAccount" + } + ] +} diff --git a/code/DocsSample/Account/DomainAccount/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Account/DomainAccount/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/Account/DomainAccount/README.md b/code/DocsSample/Account/DomainAccount/README.md new file mode 100755 index 0000000000000000000000000000000000000000..6e497a40638fdf91722b52b45fb9a52a6f3072e4 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/README.md @@ -0,0 +1,96 @@ +# DomainAccount + +### 介绍 + +用户可以在系统中添加域账号,后续可以使用该账号登录、使用系统。 + +当需要验证域账号身份(比如屏幕解锁、登录会话失效等场景)时,可以使用系统提供的接口对域账号进行身份认证。 + +OEM厂商可以采用插件方式定制化域账号管理能力,系统提供了域账号插件注册和注销能能力。 + +实现对以下指南文件中[管理域账号](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/basic-services/account/manage-domain-account.md) [域账号](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/basic-services/account/auth-domain-account.md) [管理域账号插件](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/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 + +ohos.permission.GET_DOMAIN_ACCOUNTS + +ohos.permission.ACCESS_USER_AUTH_INTERNAL + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Account/DomainAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/build-profile.json5 b/code/DocsSample/Account/DomainAccount/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..a33a4782e91c9280a45ec05115ebd546882ce072 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 14, + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/code-linter.json5 b/code/DocsSample/Account/DomainAccount/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/.gitignore b/code/DocsSample/Account/DomainAccount/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/build-profile.json5 b/code/DocsSample/Account/DomainAccount/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/hvigorfile.ts b/code/DocsSample/Account/DomainAccount/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/obfuscation-rules.txt b/code/DocsSample/Account/DomainAccount/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/oh-package.json5 b/code/DocsSample/Account/DomainAccount/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..1504a74f09dfdcfae408be979f99369a2c5affab --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets new file mode 100755 index 0000000000000000000000000000000000000000..d0110cec8c2d196355fbc01765b3c62c18a4f3b5 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { BusinessError, osAccount } from '@kit.BasicServicesKit'; +import { router } from '@kit.ArkUI'; + +let osAccountMgr = osAccount.getAccountManager(); + +@Entry +@Component +struct SystemAccount { + @State message: string = 'No Message'; + + private async passwordAuthenticateDomainAccount(): Promise { + let domainAccountInfo: osAccount.DomainAccountInfo = { + domain: 'CHINA', + accountName: 'zhangsan' + }; + let credential: Uint8Array = new Uint8Array([0]); + let callback: osAccount.IUserAuthCallback = { + onResult: (resultCode: number, authResult: osAccount.AuthResult) => { + console.log('auth resultCode = ' + resultCode); + console.log('auth authResult = ' + JSON.stringify(authResult)); + this.message = '用户结果码:' + resultCode; + } + }; + try { + osAccount.DomainAccountManager.auth(domainAccountInfo, credential, callback); + } catch (err) { + console.log('auth exception = ' + JSON.stringify(err)); + } + } + + private async popupAuthenticateDomainAccount(): Promise { + let domainInfo: osAccount.DomainAccountInfo = { + domain: 'testDomain', + accountName: 'testAccountName' + }; + try { + osAccountMgr.createOsAccountForDomain(osAccount.OsAccountType.NORMAL, domainInfo, + (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ + console.log('createOsAccountForDomain err:' + JSON.stringify(err)); + console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); + this.message = '当前域账号名称:' + JSON.stringify(osAccountInfo.localName); + }); + } catch (e) { + console.log('createOsAccountForDomain exception: ' + JSON.stringify(e)); + } + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button('使用密码认证域账号') + .margin(10) + .id('button1') + .onClick(() => this.passwordAuthenticateDomainAccount()) + Button('弹窗认证域账号') + .margin(10) + .id('button2') + .onClick(() => this.popupAuthenticateDomainAccount()) + Button('Go to plugin') + .margin(10) + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/ManageDomainAccountsPlugin' + }) + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets new file mode 100755 index 0000000000000000000000000000000000000000..98144d1489bd8e92de7cce75abed9b68c460ce00 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { osAccount, BusinessError } from '@kit.BasicServicesKit'; +import { router } from '@kit.ArkUI'; + +let osAccountMgr = osAccount.getAccountManager(); + +@Entry +@Component +struct SystemAccount { + @State message: string = 'Hello World'; + + private async domainAccountExists(): Promise { + let domainAccountInfo: osAccount.DomainAccountInfo = { + accountName: 'testAccountName', + domain: 'testDomain' + } + + let isAccountExisted: boolean = await osAccount.DomainAccountManager.hasAccount(domainAccountInfo); + console.log('domainAccount isAccountExisted:' + isAccountExisted); + if(isAccountExisted) { + this.message = '域账号已存在'; + } else { + this.message = '域账号未存在'; + } + } + + private async createDomainAccount(): Promise { + let domainInfo: osAccount.DomainAccountInfo = { + domain: 'testDomain', + accountName: 'testAccountName' + }; + + try { + osAccountMgr.createOsAccountForDomain(osAccount.OsAccountType.NORMAL, domainInfo, + (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ + console.log('createOsAccountForDomain err:' + JSON.stringify(err)); + console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); + this.message = '创建账号的信息:' + JSON.stringify(osAccountInfo.localName); + }); + } catch (e) { + console.log('createOsAccountForDomain exception: ' + JSON.stringify(e)); + this.message = '创建账号失败:' + JSON.stringify(e); + } + } + + private async deleteDomainAccount(): Promise { + let domainInfo: osAccount.DomainAccountInfo = { + domain: 'testDomain', + accountName: 'testAccountName' + }; + let localId: number = 0; + try { + localId = await osAccountMgr.getOsAccountLocalIdForDomain(domainInfo); + } catch (err) { + console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); + this.message = '获取删除账号信息失败:' + JSON.stringify(err); + } + try { + osAccountMgr.removeOsAccount(localId, (err: BusinessError)=>{ + if (err) { + console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); + this.message = '删除账号失败:' + JSON.stringify(err); + } else { + console.log('removeOsAccount successfully'); + this.message = '删除账号成功'; + } + }); + } catch (err) { + console.log('removeOsAccount exception: ' + JSON.stringify(err)); + } + + } + + private async queryDomainAccount(): Promise { + let options: osAccount.GetDomainAccountInfoOptions = { + domain: 'testDomain', + accountName: 'testAccountName' + } + try { + osAccount.DomainAccountManager.getAccountInfo(options, + (err: BusinessError, result: osAccount.DomainAccountInfo) => { + if (err) { + console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); + this.message = '调用查询失败:' + JSON.stringify(err); + } else { + console.log('getAccountInfo result: ' + result); + this.message = '查询到的账号信息:' + JSON.stringify(result.accountName); + } + }); + } catch (err) { + console.log('getAccountInfo exception = ' + JSON.stringify(err)); + this.message = '查询账号信息失败:' + JSON.stringify(err); + } + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button('判断指定域账号是否存在') + .margin(10) + .id('button1') + .onClick(() => this.domainAccountExists()) + Button('添加域账号') + .margin(10) + .id('button2') + .onClick(() => this.createDomainAccount()) + Button('删除域账号') + .margin(10) + .id('button3') + .onClick(() => this.deleteDomainAccount()) + Button('查询域账号信息') + .margin(10) + .id('button4') + .onClick(() => this.queryDomainAccount()) + Button('Go to AuthenticationDomainAccount') + .margin(10) + .id('button5') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/AuthenticationDomainAccount' + }) + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets new file mode 100755 index 0000000000000000000000000000000000000000..44430b983f25c59b157c5959f99d929072b8c158 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { osAccount, AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; +import { router } from '@kit.ArkUI'; + +let accountMgr = osAccount.getAccountManager() + +let plugin: osAccount.DomainPlugin = { + auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, + callback: osAccount.IUserAuthCallback) => { + console.info('plugin auth domain' + domainAccountInfo.domain); + console.info('plugin auth accountName' + domainAccountInfo.accountName); + console.info('plugin auth accountId' + domainAccountInfo.accountId); + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, + callback: osAccount.IUserAuthCallback) => { + console.info('plugin authWithPopup domain' + domainAccountInfo.domain); + console.info('plugin authWithPopup accountName' + domainAccountInfo.accountName); + console.info('plugin authWithPopup accountId' + domainAccountInfo.accountId); + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, + token: Uint8Array, + callback: osAccount.IUserAuthCallback) => { + console.info('plugin authWithToken domain' + domainAccountInfo.domain); + console.info('plugin authWithToken accountName' + domainAccountInfo.accountName); + console.info('plugin authWithToken accountId' + domainAccountInfo.accountId); + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, + callback: AsyncCallback) => { + console.info('plugin getAccountInfo domain'); + let domainAccountId = Date.now().toString(); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let domainStr: string = ''; + if (options.domain != undefined) { + domainStr = options.domain; + } + let accountInfo: osAccount.DomainAccountInfo = { + domain: domainStr, + accountName: options.accountName, + accountId: domainAccountId, + isAuthenticated: false + }; + callback(code, accountInfo); + }, + getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, + callback: AsyncCallback) => { + console.info('plugin getAuthStatusInfo domain' + domainAccountInfo.domain); + console.info('plugin getAuthStatusInfo accountName' + domainAccountInfo.accountName); + console.info('plugin getAuthStatusInfo accountId' + domainAccountInfo.accountId); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let statusInfo: osAccount.AuthStatusInfo = { + remainTimes: 5, + freezingTime: 0 + }; + callback(code, statusInfo); + }, + bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, + callback: AsyncCallback) => { + console.info('plugin bindAccount domain' + domainAccountInfo.domain); + console.info('plugin bindAccount accountName' + domainAccountInfo.accountName); + console.info('plugin bindAccount accountId' + domainAccountInfo.accountId); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + callback(code); + }, + unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback) => { + console.info('plugin unbindAccount domain' + domainAccountInfo.domain); + console.info('plugin unbindAccount accountName' + domainAccountInfo.accountName); + console.info('plugin unbindAccount accountId' + domainAccountInfo.accountId); + }, + isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, + callback: AsyncCallback) => { + console.info('plugin isAccountTokenValid domain' + domainAccountInfo.domain); + console.info('plugin isAccountTokenValid accountName' + domainAccountInfo.accountName); + console.info('plugin isAccountTokenValid accountId' + domainAccountInfo.accountId); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + callback(code, true); + }, + getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback) => { + console.info('plugin getAccessToken domain'); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let token: Uint8Array = new Uint8Array([0]); + callback(code, token); + } +} + +@Entry +@Component +struct SystemAccount { + @State message: string = '域账号插件管理'; + + private async registrationPlugin(): Promise { + try { + osAccount.DomainAccountManager.registerPlugin(plugin); + console.info('registerPlugin success'); + this.message = '注册插件成功'; + } catch (err) { + console.info('registerPlugin err: ' + JSON.stringify(err)); + this.message = '注册插件失败: ' + JSON.stringify(err); + } + } + + private async logoutPlugin(): Promise { + try { + osAccount.DomainAccountManager.unregisterPlugin(); + console.log('unregisterPlugin success.'); + this.message = '注销插件成功'; + } catch(err) { + console.log('unregisterPlugin err:' + JSON.stringify(err)); + this.message = '注销插件失败: ' + JSON.stringify(err); + } + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button('注册插件') + .margin(10) + .id('button1') + .onClick(() => this.registrationPlugin()) + Button('注销插件') + .margin(20) + .id('button2') + .onClick(() => this.logoutPlugin()) + Button('Return back') + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/DomainAccountHome' + }) + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..12f04553986975cd7efdd05c82a2b17674a9a001 --- /dev/null +++ b/code/DocsSample/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() { + Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap }) { + 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/code/DocsSample/Account/DomainAccount/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/util/CommonButton.ets new file mode 100755 index 0000000000000000000000000000000000000000..8f8f7335dc0098536ec7b906947946d9bf43e1ca --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/util/CommonButton.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 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(16)) + .backgroundColor(Color.Blue) + .fontColor(Color.White) + .borderRadius(5) + .margin(px2vp(5)) + .onClick(() => { + router.pushUrl({ + url: this.buttonUrl, + params: { + text: this.data, + buttonName: this.buttonName + } + }) + }) + } +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/module.json5 b/code/DocsSample/Account/DomainAccount/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..269eca939a3da98eab53814e2eef0c9f6f53c5bb --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/module.json5 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS", + }, + { + "name": "ohos.permission.GET_DOMAIN_ACCOUNTS", + }, + { + "name": "ohos.permission.ACCESS_USER_AUTH_INTERNAL", + }], + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/color.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/string.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/background.png b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..e47a9436e04a20e9f2c2c825ba5c7049a6b0d372 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/dark/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/mock/mock-config.json5 b/code/DocsSample/Account/DomainAccount/entry/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..cea0ac84abe4b4c4ef77ca8e29830b206aee14c1 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, 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() { + 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 button = await driver.findComponent(ON.text('DomainAccount')); + await button.click(); + 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('注册插件成功'); + + const button3 = await driver.findComponent(ON.id('button3')); + await button3.click(); + await driver.delayMs(1000); + + const button4 = await driver.findComponent(ON.text('ManageDomainAccounts')); + await button4.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('域账号已存在'); + + const button6 = await driver.findComponent(ON.id('button2')); + await button6.click(); + await driver.delayMs(10000); + let content2: string = await text.getText(); + expect(content2).assertEqual('创建账号的信息:"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('删除账号成功'); + + const button8 = await driver.findComponent(ON.id('button4')); + await button8.click(); + await driver.delayMs(1000); + let content4: string = await text.getText(); + expect(content4).assertEqual('查询到的账号信息:"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('用户结果码:0'); + + const button11 = await driver.findComponent(ON.id('button2')); + await button11.click(); + await driver.delayMs(10000); + let content6: string = await text1.getText(); + expect(content6).assertEqual('当前域账号名称:"testAccountName"'); + + 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('注销插件成功'); + done(); + }) +} \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/module.json5 b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c8bd24faff0ff0064a57435f74662f1db5865f88 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Account/DomainAccount/entry/src/test/List.test.ets b/code/DocsSample/Account/DomainAccount/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Account/DomainAccount/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/hvigor/hvigor-config.json5 b/code/DocsSample/Account/DomainAccount/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..cef74543b1f97c82275e4bf3434b162395bff2eb --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/hvigorfile.ts b/code/DocsSample/Account/DomainAccount/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/oh-package.json5 b/code/DocsSample/Account/DomainAccount/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..eaef52736f22c14e04fca386ba01611ab32a7e4a --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/DomainAccount/ohosTest.md b/code/DocsSample/Account/DomainAccount/ohosTest.md new file mode 100755 index 0000000000000000000000000000000000000000..40bc70c516cfa1c8b1698e932ba2258e7c8088f9 --- /dev/null +++ b/code/DocsSample/Account/DomainAccount/ohosTest.md @@ -0,0 +1,15 @@ +# DomainAccount 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ----------------------------------------------- | ----------------------------- | --------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 注册插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘注册插件’ | 页面显示“注册插件成功” | 是 | Pass | +| 注销插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘注销插件’ | 页面显示“注销插件成功“ | 是 | Pass | +| 判断指定域账号是否存在 | 位于ManageDomainAccounts页面,已注册插件 | 点击‘ 判断指定域账号是否存在’ | 页面显示“域账号已存在“ | 是 | Pass | +| 添加域账号 | 位于ManageDomainAccounts页面,已注册插件 | 点击‘添加域账号’ | 页面显示“创建账号的信息:"testAccountName"“ | 是 | Pass | +| 删除域账号 | 位于ManageDomainAccounts页面,已注册插件 | 点击‘删除域账号’ | 页面显示“删除账号成功“ | 是 | Pass | +| 查询域账号信息 | 位于ManageDomainAccounts页面,已注册插件 | 点击‘查询域账号信息’ | 页面显示“查询到的账号信息:"testAccountName"“ | 是 | Pass | +| 使用密码认证域账号 | 位于AuthenticationDomainAccount页面,已注册插件 | 点击‘使用密码进行认证’ | 页面显示“用户结果码:0“ | 是 | Pass | +| 弹窗认证域账号 | 位于AuthenticationDomainAccount页面,已注册插件 | 点击‘弹窗认证域账号’ | 页面显示"当前域账号名称:"testAccountName"" | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_1.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_1.png new file mode 100755 index 0000000000000000000000000000000000000000..b6f12369ec77c38fc47ae957eecd26ce03d786cf Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_1.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_10.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_10.png new file mode 100755 index 0000000000000000000000000000000000000000..53349228c39101cf3d6d6e3c5ba3ba9dc1d77852 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_10.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_11.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_11.png new file mode 100755 index 0000000000000000000000000000000000000000..8a3ac8b87be7a6c6f760428bccd476ddd8bd1681 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_11.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_12.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_12.png new file mode 100755 index 0000000000000000000000000000000000000000..9a16a1159e8ac3fd43cf7488589c97ecbe6c0fe0 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_12.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_2.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_2.png new file mode 100755 index 0000000000000000000000000000000000000000..3d6501af1d0b9a86db8d71514be3e421e9a8b00c Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_2.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_3.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_3.png new file mode 100755 index 0000000000000000000000000000000000000000..ba4aca27bdc89b6995dacb3b00bc97ab784a75bc Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_3.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_4.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_4.png new file mode 100755 index 0000000000000000000000000000000000000000..40e4f86903885d8014ac08f19fbc7857003721c8 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_4.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_5.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_5.png new file mode 100755 index 0000000000000000000000000000000000000000..68c81b9555db5b9bfec8d7b2ebdb20e91d3ceb44 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_5.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_6.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_6.png new file mode 100755 index 0000000000000000000000000000000000000000..e31500b1c0b95732c2b830eb8ee430ddf523b1a0 Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_6.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_7.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_7.png new file mode 100755 index 0000000000000000000000000000000000000000..54097d5872a27d2e4964169c08cce9a58e03658b Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_7.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_8.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_8.png new file mode 100755 index 0000000000000000000000000000000000000000..7d59e9adfacf4ffa97d1de20bd299c190e5a2d8f Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_8.png differ diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_9.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_9.png new file mode 100755 index 0000000000000000000000000000000000000000..05fd8b4a5063466a8c2081b67bfa96fb6b9473cd Binary files /dev/null and b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_9.png differ