diff --git a/OAT.xml b/OAT.xml index 9705a1cbe38d1ac277d21d688189b738b49a37d6..411f097818d0ebb7b065cc912378d075d71f5611 100644 --- a/OAT.xml +++ b/OAT.xml @@ -1346,6 +1346,12 @@ Note:If the text contains special characters, please escape them according to th + + + + + + diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/.gitignore b/code/DocsSample/Account/ManageSystemAccountCredentials/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/app.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..2f4344584bfc9e3f28eab29c24dbf4fc67174260 --- /dev/null +++ b/code/DocsSample/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.sample.managesystemaccountcredentials", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..ed0031b2726f87930b679a0c78da46f749d2e031 --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ManageSystemAccountCredentials" + } + ] +} diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/README.md b/code/DocsSample/Account/ManageSystemAccountCredentials/README.md new file mode 100755 index 0000000000000000000000000000000000000000..983910e0ff1a7cb95b10dff3b20a745d6358f7f5 --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/README.md @@ -0,0 +1,75 @@ +# 管理系统账号凭据 + +### 介绍 + +凭据可用于认证用户的身份,本文档将介绍如何录入、认证、更新、查询和删除指定系统账号的凭据。 + +该工程中展示的代码详细描述可查如下链接: + +- [ 管理系统账号凭据](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/basic-services/account/manage-os-account-credential.md) + +### 效果预览 + +| 首页 | 执行录入PIN码 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| 执行认证PIN码 | 执行更新凭据 | +| | | +| 执行查询凭据信息 | 执行删除凭据 | +| | | + +### 使用说明 + +1. 在主界面,点击'录入PIN码',执行录入PIN码。 +2. 点击'认证PIN码',执行认证PIN码。 +3. 点击'更新凭据',执行更新凭据。 +4. 点击'查询凭据信息',执行查询凭据信息。 +5. 点击'删除凭据',执行删除凭据。 +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 +- ohos.permission.ACCESS_PIN_AUTH + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/ManageSystemAccountCredentials > .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/ManageSystemAccountCredentials/build-profile.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..a33a4782e91c9280a45ec05115ebd546882ce072 --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/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/ManageSystemAccountCredentials/code-linter.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/.gitignore b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/build-profile.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b4d65d490ef6cbe22d933b9231555210f1555786 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/hvigorfile.ts b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/obfuscation-rules.txt b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/oh-package.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..1504a74f09dfdcfae408be979f99369a2c5affab --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..4956e131f621dd985baf4a9d22099ec5ce191ced --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,397 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 } from '@kit.BasicServicesKit'; +import account_osAccount from '@ohos.account.osAccount' + +@Entry +@Component +struct SystemAccount { + @State message: string = 'Nothing'; + @State cid: number = 100; + + private async addCred(): Promise { + try { + this.cid = await account_osAccount.getAccountManager().getForegroundOsAccountLocalId(); + let userIdentityManager = new account_osAccount.UserIdentityManager(); + let password: Uint8Array = new Uint8Array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36]); + let pinAuth = new account_osAccount.PINAuth(); + let credentialInfo :account_osAccount.CredentialInfo = { + accountId: this.cid, + credType:account_osAccount.AuthType.PIN, + credSubType:account_osAccount.AuthSubType.PIN_SIX, + token:new Uint8Array([]) + } + pinAuth.unregisterInputer(); + pinAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, password); + } + }) + userIdentityManager.closeSession(this.cid); + userIdentityManager.openSession(this.cid).then((data)=>{ + console.log('openSession info: ' + JSON.stringify(data)); + userIdentityManager.addCredential(credentialInfo,{ + onResult: (err, extraInfo)=>{ + console.log('addCredential result: ' + JSON.stringify(err)); + console.log('addCredential info: ' + JSON.stringify(extraInfo)); + if(err == 0) { + this.message = '录入PIN码成功'; + } + pinAuth.unregisterInputer(); + userIdentityManager.closeSession(this.cid); + }}) + }).catch((err: Error)=>{ + console.log('test failed, error: ' + JSON.stringify(err)); + }) + } catch (e) { + console.log('test cur failed, error: ' + JSON.stringify(e)); + } + } + + private async auth(): Promise { + try { + let userIdentityManager = 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); + } + }) + userIdentityManager.closeSession(this.cid); + userIdentityManager.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)); + let authToken = extraInfo.token; + if(result == 0) { + this.message = '认证PIN码成功'; + } + } + }); + }).catch((err: Error)=>{ + console.log('openSession failed, error: ' + JSON.stringify(err)); + }) + } catch (err) { + console.log('getEnrolledId cur failed, error: ' + JSON.stringify(err)); + } + } + + private async addBiologyCred(): Promise { + let faceCredInfo: osAccount.CredentialInfo = { + credType: osAccount.AuthType.FACE, + credSubType: osAccount.AuthSubType.FACE_2D, + token: new Uint8Array([1, 2, 3, 4, 5]) + } + let fingerprintCredInfo: osAccount.CredentialInfo = { + credType: osAccount.AuthType.FINGERPRINT, + credSubType: osAccount.AuthSubType.FINGERPRINT_CAPACITIVE, + token: new Uint8Array([1, 2, 3, 4, 5]) + } + try { + let userIdentityManager = 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); + } + }) + userIdentityManager.closeSession(this.cid); + userIdentityManager.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; + userIdentityManager.addCredential(faceCredInfo, { + onResult: (code: number, result: osAccount.RequestResult) => { + console.log('add face credential, resultCode: ' + code); + console.log('add face credential, request result: ' + result); + if(code == 0) { + this.message = '录入人脸凭据成功'; + } else { + this.message = '录入人脸凭据失败: ' + code; + } + } + }); + userIdentityManager.addCredential(fingerprintCredInfo, { + onResult: (code: number, result: osAccount.RequestResult) => { + console.log('add fingerprint credential, resultCode: ' + code); + console.log('add fingerprint credential, request result: ' + result); + if(code == 0) { + this.message += '并且录入指纹凭据成功'; + } else { + this.message = '并且录入指纹凭据失败: ' + code; + } + } + }); + } + }); + }).catch((err: Error)=>{ + console.log('openSession failed, error: ' + JSON.stringify(err)); + }) + } catch (err) { + console.log('getEnrolledId cur failed, error: ' + JSON.stringify(err)); + } + } + + private async biologyAuth(): Promise { + try { + let userIdentityManager = 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); + } + }) + userIdentityManager.closeSession(this.cid); + userIdentityManager.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; + 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)); + if(result == 0) { + this.message = '认证生物识别凭据成功'; + } else { + this.message = '认证生物识别凭据失败:' + result; + } + } + }); + }).catch((err: Error)=>{ + console.log('openSession failed, error: ' + JSON.stringify(err)); + }) + } catch (err) { + console.log('getEnrolledId cur failed, error: ' + JSON.stringify(err)); + } + } + + private async updateCred(): Promise { + let userIdentityManager = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let pinAuth = new account_osAccount.PINAuth(); + let credentialInfo :account_osAccount.CredentialInfo = { + accountId:this.cid, + credType:account_osAccount.AuthType.PIN, + credSubType:account_osAccount.AuthSubType.PIN_SIX, + token:new Uint8Array([]) + } + pinAuth.unregisterInputer(); + pinAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, new Uint8Array([0x31, 0x32, 0x33, 0x34, 0x35, 0x36])); + } + }) + userIdentityManager.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, + new Uint8Array([0x31, 0x31, 0x31, 0x31, 0x31, 0x31])) + } + }) + userIdentityManager.updateCredential(credentialInfo, { + onResult:(result: number, extraInfo: osAccount.RequestResult)=>{ + console.log('updateCredential result: ' + JSON.stringify(result)); + console.log('updateCredential extraInfo: ' + JSON.stringify(extraInfo)); + if(result == 0) { + this.message = '更新pin码凭证成功'; + } + PINAuth.unregisterInputer(); + userIdentityManager.closeSession(this.cid); + } + }) + } + }) + }).catch((err: Error)=>{ + console.log('openSession failed, error: ' + JSON.stringify(err)); + }) + } + + private async getCred(): Promise { + let userIdentityManager = new account_osAccount.UserIdentityManager(); + try { + userIdentityManager.getAuthInfo((err, data)=>{ + console.log('getAuthInfo err: ' + JSON.stringify(err)); + console.log('getAuthInfo data: ' + JSON.stringify(data)); + this.message = '查询信息的长度:' + data.length; + }) + let enrolledFingerCredInfoList: osAccount.EnrolledCredInfo[] = + await userIdentityManager.getAuthInfo(osAccount.AuthType.PIN); + } catch (err) { + console.log('getAuthInfo failed: ' + JSON.stringify(err)); + } + } + + private async deleteBiologyCred(): Promise { + let userIdentityManager = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let pinAuth = new account_osAccount.PINAuth(); + 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 userIdentityManager.getAuthInfo(osAccount.AuthType.FINGERPRINT); + if (credInfoList.length != 0) { + credentialId = credInfoList[0].credentialId; + } + pinAuth.unregisterInputer(); + pinAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, + new Uint8Array([0x31, 0x31, 0x31, 0x31, 0x31, 0x31])); + } + }) + userIdentityManager.closeSession(this.cid) + userIdentityManager.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 { + userIdentityManager.delCred(credentialId, authResult.token, { + onResult: (result: number, extraInfo: osAccount.RequestResult) => { + console.log('delCred result = ' + result); + console.log('delCred extraInfo = ' + JSON.stringify(extraInfo)); + if(result == 0) { + this.message = '删除凭据成功'; + } else { + this.message = '删除凭据失败:' + result; + } + } + }); + } catch (e) { + console.log('delUser exception = ' + JSON.stringify(e)); + } + pinAuth.unregisterInputer(); + userIdentityManager.closeSession(this.cid); + } + }) + }).catch((err: Error)=>{ + console.log('openSession failed, error: ' + JSON.stringify(err)); + }) + } + + private async deleteCred(): Promise { + let userIdentityManager = new account_osAccount.UserIdentityManager(); + let userAuth = new account_osAccount.UserAuth(); + let pinAuth = new account_osAccount.PINAuth(); + pinAuth.unregisterInputer(); + pinAuth.registerInputer({ + onGetData:(authSubType, callback)=>{ + callback.onSetData(account_osAccount.AuthSubType.PIN_SIX, + new Uint8Array([0x31, 0x31, 0x31, 0x31, 0x31, 0x31])); + } + }) + userIdentityManager.closeSession(this.cid) + userIdentityManager.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 { + userIdentityManager.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 = '删除pin码凭证成功'; + } + } + }); + } catch (e) { + console.log('delUser exception = ' + JSON.stringify(e)); + } + pinAuth.unregisterInputer(); + userIdentityManager.closeSession(this.cid); + } + }) + }).catch((err: Error)=>{ + console.log('openSession failed, error: ' + JSON.stringify(err)); + }) + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button('录入PIN码') + .margin(10) + .id('button1') + .onClick(() => this.addCred()) + Button('认证PIN码') + .margin(10) + .id('button2') + .onClick(() => this.auth()) + Button('录入生物识别凭据') + .margin(10) + .id('button3') + .onClick(() => this.addBiologyCred()) + Button('认证生物识别凭据') + .margin(10) + .id('button4') + .onClick(() => this.biologyAuth()) + Button('更新凭据') + .margin(10) + .id('button5') + .onClick(() => this.updateCred()) + Button('查询凭据信息') + .margin(10) + .id('button6') + .onClick(() => this.getCred()) + Button('删除生物凭据') + .margin(10) + .id('button8') + .onClick(() => this.deleteBiologyCred()) + Button('删除凭据') + .margin(10) + .id('button7') + .onClick(() => this.deleteCred()) + + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..023a6f1bd88156e6afb3b3813ed973cdfd8381e2 --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "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_USER_IDM", + }, + { + "name": "ohos.permission.ACCESS_PIN_AUTH", + }], + "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/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/string.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/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/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json new file mode 100755 index 0000000000000000000000000000000000000000..d742c2f96e7dd0f406f499941f3147345e998f95 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..438d5bc43bb23c59c210d586b96635a72da5b64a --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/mock/mock-config.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/mock/mock-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1896604b9a4f33c2f30c69ce966b411c3737a37a --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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码成功'); + + 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码成功'); + + const button3 = await driver.findComponent(ON.id('button5')); + await button3.click(); + await driver.delayMs(5000); + let content3: string = await text.getText(); + expect(content3).assertEqual('更新pin码凭证成功'); + + const button4 = await driver.findComponent(ON.id('button6')); + await button4.click(); + await driver.delayMs(1000); + let content4: string = await text.getText(); + expect(content4).assertEqual('查询信息的长度:1'); + + const button5 = await driver.findComponent(ON.id('button7')); + await button5.click(); + await driver.delayMs(3000); + await button5.click(); + await driver.delayMs(3000); + let content5: string = await text.getText(); + expect(content5).assertEqual('删除pin码凭证成功'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..c8bd24faff0ff0064a57435f74662f1db5865f88 --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/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/ManageSystemAccountCredentials/entry/src/test/List.test.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/test/LocalUnit.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..cef74543b1f97c82275e4bf3434b162395bff2eb --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/hvigorfile.ts b/code/DocsSample/Account/ManageSystemAccountCredentials/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/oh-package.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..eaef52736f22c14e04fca386ba01611ab32a7e4a --- /dev/null +++ b/code/DocsSample/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/code/DocsSample/Account/ManageSystemAccountCredentials/ohosTest.md b/code/DocsSample/Account/ManageSystemAccountCredentials/ohosTest.md new file mode 100755 index 0000000000000000000000000000000000000000..8a6c5c566e946df696169f08eb5d5fc0948a1e80 --- /dev/null +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/ohosTest.md @@ -0,0 +1,12 @@ +# ManageSystemAccountCredentials 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------------ | --------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 录入PIN码 | 位于首页 | 点击'录入PIN码' | 页面显示“录入PIN码成功” | 是 | Pass | +| 认证PIN码 | 位于首页 | 点击'认证PIN码' | 页面显示“认证PIN码成功” | 是 | Pass | +| 更新凭据 | 位于首页 | 点击'更新凭据' | 页面显示“更新pin码凭证成功” | 是 | Pass | +| 查询凭据信息 | 位于首页 | 点击'查询凭据信息' | 页面显示“查询信息的长度:1” | 是 | Pass | +| 删除凭据 | 位于首页 | 点击'删除凭据' | 页面显示“删除pin码凭证成功” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_0.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_0.png new file mode 100755 index 0000000000000000000000000000000000000000..dd5afe6739f78639bcb9b2a514b3aa4803fbe842 Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_0.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png new file mode 100755 index 0000000000000000000000000000000000000000..bad10745657b39e630cf6afc236413f0f5acfb7b Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png new file mode 100755 index 0000000000000000000000000000000000000000..dabbdf0b9392f79153ed903b45126521596d1246 Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png new file mode 100755 index 0000000000000000000000000000000000000000..3bcc51eba12d93982f21f3d755bfc48856b58080 Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png new file mode 100755 index 0000000000000000000000000000000000000000..2d20f9f8c12e2787120cfd716c5bea0528c25b6b Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png differ diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png new file mode 100755 index 0000000000000000000000000000000000000000..dbae8a326cdad16303d72be304329945d1f42a12 Binary files /dev/null and b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png differ