From 38894e7ada10fea01653272706e3d4981287b36e Mon Sep 17 00:00:00 2001 From: dengjiewen Date: Mon, 17 Jul 2023 14:38:30 +0800 Subject: [PATCH 1/2] update code Signed-off-by: dengjiewen --- .../main/ets/common/components/FullScreen.ets | 586 ++++++++++++++++++ .../ets/common/components/NumkeyBoard.ets | 60 +- .../main/ets/common/components/PassWord.ets | 86 +++ .../ets/common/components/SixPassword.ets | 88 +++ entry/src/main/ets/common/utils/AuthUtils.ts | 7 +- entry/src/main/ets/common/utils/FuncUtils.ts | 9 +- entry/src/main/ets/common/utils/LogUtils.ts | 16 +- .../ets/common/utils/WindowPrivacyUtils.ts | 9 +- entry/src/main/ets/common/vm/Constants.ts | 9 +- .../ets/extensionability/UserAuthAbility.ts | 25 +- entry/src/main/ets/pages/Index.ets | 152 ++--- .../ets/pages/components/CustomPassword.ets | 79 +-- .../main/ets/pages/components/FaceAuth.ets | 207 ++++--- .../ets/pages/components/FingerprintAuth.ets | 326 +++++----- .../ets/pages/components/PasswordAuth.ets | 34 +- entry/src/main/module.json5 | 22 - .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/float.json | 140 +++-- .../ets/extensionability/UserAuthAbility.ts | 31 +- entry/src/ohosTest/ets/test/List.test.ets | 80 +-- .../ets/test/jsunit/Constants.test.ets | 34 + .../ets/test/jsunit/FuncUtils.test.ets | 111 ++++ .../ohosTest/ets/test/jsunit/PageCom.test.ets | 46 ++ .../ets/test/uitest/CustomMixFail.test.ets | 68 ++ .../test/uitest/CustomMixFailTimes.test.ets | 68 ++ .../uitest/CustomPasswordFingerTimes.test.ets | 68 ++ .../test/uitest/CustomPasswordNumber.test.ets | 257 +++++++- .../ets/test/uitest/CustomPin.test.ets | 72 +++ .../ohosTest/ets/test/uitest/Face.test.ets | 103 +++ .../ets/test/uitest/FaceFailTimes.test.ets | 73 +++ .../ets/test/uitest/FaceFingerFail.test.ets | 71 +++ .../ets/test/uitest/FaceMixAuth.test.ets | 71 +++ .../ets/test/uitest/FaceMixFailAuth.test.ets | 71 +++ .../test/uitest/FaceMixSuccessAuth3.test.ets | 75 +++ .../test/uitest/FindWindowExample.test.ets | 18 +- .../ohosTest/ets/test/uitest/Finger.test.ets | 67 ++ .../test/uitest/FingerFailTimesAuth.test.ets | 71 +++ .../src/ohosTest/ets/test/uitest/Pin.test.ets | 72 +++ .../ohosTest/ets/test/uitest/PinFace.test.ets | 50 +- .../ets/test/uitest/PinFaceFail.test.ets | 68 ++ .../ets/test/uitest/PinFaceFinger.test.ets | 71 +++ .../ets/test/uitest/PinFinger.test.ets | 71 +++ .../ets/test/uitest/PinFingerFail.test.ets | 71 +++ .../ets/test/uitest/PinNumber.test.ets | 90 +++ .../ets/testability/CustomMixFailAbility.ets | 35 ++ .../testability/CustomMixFailTimesAbility.ets | 32 + .../ets/testability/CustomPwdAbility.ets | 32 + .../testability/CustomPwdNumberAbility.ets | 32 + .../ohosTest/ets/testability/FaceAbility.ets | 32 + .../ets/testability/FaceFailTimesAbility.ets | 32 + .../ets/testability/FaceMixAbility.ets | 32 + .../testability/FaceMixSuccess3Ability.ets | 32 + .../ets/testability/FaceMixSuccessAbility.ets | 32 + .../ets/testability/FaceMixTimesAbility.ets | 32 + .../ets/testability/FaceSingleAbility.ets | 32 + .../ets/testability/FingerFailAbility.ets | 32 + .../testability/FingerFailTimesAbility.ets | 32 + .../ets/testability/FingerprintAbility.ets | 32 + .../ets/testability/PasswordAbility.ets | 32 + .../ets/testability/PasswordSixAbility.ets | 32 + .../ohosTest/ets/testability/TestAbility.ets | 25 - .../ohosTest/ets/testability/pages/Index.ets | 44 +- entry/src/ohosTest/module.json5 | 162 ++++- .../resources/base/element/color.json | 8 + .../resources/base/element/float.json | 140 +++-- .../resources/base/element/string.json | 12 - 66 files changed, 4009 insertions(+), 708 deletions(-) create mode 100644 entry/src/main/ets/common/components/FullScreen.ets create mode 100644 entry/src/main/ets/common/components/PassWord.ets create mode 100644 entry/src/main/ets/common/components/SixPassword.ets create mode 100644 entry/src/ohosTest/ets/test/jsunit/Constants.test.ets create mode 100644 entry/src/ohosTest/ets/test/jsunit/FuncUtils.test.ets create mode 100644 entry/src/ohosTest/ets/test/jsunit/PageCom.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/CustomMixFail.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/CustomMixFailTimes.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/CustomPasswordFingerTimes.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/CustomPin.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/Face.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/FaceFailTimes.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/FaceFingerFail.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/FaceMixAuth.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/FaceMixFailAuth.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/FaceMixSuccessAuth3.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/Finger.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/FingerFailTimesAuth.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/Pin.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/PinFaceFail.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/PinFaceFinger.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/PinFinger.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/PinFingerFail.test.ets create mode 100644 entry/src/ohosTest/ets/test/uitest/PinNumber.test.ets create mode 100644 entry/src/ohosTest/ets/testability/CustomMixFailAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/CustomMixFailTimesAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/CustomPwdAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/CustomPwdNumberAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FaceAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FaceFailTimesAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FaceMixAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FaceMixSuccess3Ability.ets create mode 100644 entry/src/ohosTest/ets/testability/FaceMixSuccessAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FaceMixTimesAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FaceSingleAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FingerFailAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FingerFailTimesAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/FingerprintAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/PasswordAbility.ets create mode 100644 entry/src/ohosTest/ets/testability/PasswordSixAbility.ets diff --git a/entry/src/main/ets/common/components/FullScreen.ets b/entry/src/main/ets/common/components/FullScreen.ets new file mode 100644 index 0000000..06fc153 --- /dev/null +++ b/entry/src/main/ets/common/components/FullScreen.ets @@ -0,0 +1,586 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 display from '@ohos.display'; +import screen from '@ohos.screen'; +import userAuth from '@ohos.userIAM.userAuth'; +import Constants, { CmdType, FingerPosition } from '../../common/vm/Constants'; +import AuthUtils from '../utils/AuthUtils'; +import LogUtils from '../utils/LogUtils'; +import TimeUtils from '../utils/TimeUtils'; +import NumKeyBoard from './NumkeyBoard'; + +const TAG = 'FullScreen'; +const INTERVAL = 1000; +const DIGITAL_PASSWORD_IC_DIAMETER = 12; +const THOUSANDTH = 1000; +const TITLE_POSITION = 200; +const DEL_PWD = -2; +const CALL_PHONE = -1; +const GO_BACK = -3; +const DEFAULT_SIZE = 72; +const FINGER_TEXT_POSITION = 120; +const FINGER_HIGH = 72; +const FINGER_X_POSITION = 86; +const FINGER_Y_POSITION = 40; +const MAX_LENGTH = 32; +const AUTH_TYPE_FACE = 2; +const AUTH_TYPE_FINGER = 4; +const PASSWORD_LENGTH = 4; +const PASSWORD_ARRAY_LENGTH = 6; + +interface ControlType { + isSixPassword?: boolean, + isLandscape: boolean, + jumpFinger: boolean, + isShowFace: boolean, + isShowFinger: boolean, +} + +interface KeyboardType { + index: number, + row1: string | Resource, + row2?: string, + value?: number, + bkg?: boolean, +} + +@Component +export default struct FullScreen { + @Link pinSubType: string; + @Link textValue: string; + @Link authType: Array; + @Link @Watch('onCmdDataChange') cmdData: Array; + @State pinLock: number = 0; + @State screenClass: object = {}; + @StorageLink('cueWord') cueWord: string = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_use_pwd')); + @StorageLink('passwordArray') passwordArray: string[] = []; + @StorageLink('passwordArrayNumber') passwordArrayNumber: string[] = []; + @State passwordObj: string = ''; + numKeyboard: KeyboardType[] = Constants.numKeyBoard; + @State prompt: string = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_use_pwd')); + @State fingerText: string = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp')); + @StorageLink('screenLockDirection') screenLockDirection: number = 1; + @State controlType: ControlType = { + jumpFinger: false, + isLandscape: false, + isSixPassword: true, + isShowFace: this.authType.includes(AUTH_TYPE_FACE), + isShowFinger: this.authType.includes(AUTH_TYPE_FINGER) + } + @State fingerPosition: FingerPosition = { + sensorType: '' + } + @State screen: number[] = []; + @State faceFingerLockArr: boolean[] = [false, false]; + @Consume isLandscape: boolean; + @Consume underFingerPrint: boolean; + + queryScreenInfo(): void { + try { + screen.getAllScreens((err, data) => { + if (err.code) { + LogUtils.error(TAG, 'Failed to get all screens. err: ' + err.code); + return; + } + this.screenClass = data[0]; + }); + } catch (error) { + LogUtils.error(TAG, 'getAllScreens catch error: ' + error?.code); + } + } + + onCmdDataChange(num?: string): void { + this.cmdData.length > 0 && this.cmdData.map((item) => { + const { type,remainAttempts, lockoutDuration,sensorInfo} = item.payload; + switch (type) { + case Constants.noticeTypePin: + this.clearPassword(); + if (remainAttempts) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_pwd_error')); + if (num === 'first') { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_use_pwd')); + } + // 3: pin Residual number + if (remainAttempts < 3) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) + + remainAttempts + globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_frequency')); + } + } + if (remainAttempts === 0 && lockoutDuration) { + // 1: pin lock + this.pinLock = 1; + this.countdown(lockoutDuration); + } + + if (!remainAttempts && !lockoutDuration) { + // 1: pin lock + this.pinLock = 1; + } + break; + case Constants.noticeTypeFace: + if (remainAttempts) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1')); + this.faceFingerLockArr[0] = false; + } + if (num === 'first') { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognition')); + } + if (remainAttempts === 0) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden')); + this.faceFingerLockArr[0] = true; + } + break; + case Constants.noticeTypeFinger: + let sensor; + if (sensorInfo && JSON.stringify(sensorInfo) !== '{}') { + sensor = JSON.parse(sensorInfo); + this.fingerPosition = sensor || { sensorType: '' }; + const displayClass = display.getDefaultDisplaySync(); + this.screen = [displayClass.width, displayClass.height]; + } + if (num === 'first') { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_use_pwd')); + } + if (remainAttempts) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); + this.fingerText = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); + if (sensor) { + if (sensor.sensorType === 'UNDER_SCREEN_SENSOR' || + sensor.sensorType === 'BOTH_SENSOR' || + sensor.sensorType === 'SensorType1') { + // 5: Residual number + if (num !== 'first' && remainAttempts > 0) { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); + } + } + } + } + if (remainAttempts === 0) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); + this.fingerText = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); + this.faceFingerLockArr[1] = true; + } + break; + default: + LogUtils.error(TAG, 'type: ' + type); + break; + } + }) + } + + aboutToAppear(): void { + LogUtils.debug(TAG, 'aboutToAppear'); + try { + AppStorage.SetOrCreate('passwordArray', []); + this.queryScreenInfo(); + if (this.cmdData && this.cmdData.length > 0) { + this.onCmdDataChange('first'); + } + if (this.controlType.isShowFace && this.controlType.isShowFinger) { + AuthUtils.getInstance() + .sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace, Constants.noticeTypeFinger]); + return; + } + if (this.controlType.isShowFace) { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); + return; + } + } catch (error) { + LogUtils.error(TAG, 'aboutToAppear catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); + } + } + + clearPassword(): void { + this.passwordArray = []; + this.passwordArrayNumber = []; + this.passwordArray = ['', '', '', '', '', '']; + this.numKeyboard[11].value = GO_BACK; + this.numKeyboard[11].row1 = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_back')); + this.updateStorage(() => { + }) + } + + aboutToDisappear(): void { + this.clearPassword(); + } + + countdown(freezingTime): void { + const TRY_AGAIN = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); + let promptText: string = ''; + let freezingMillisecond = freezingTime; + if (freezingMillisecond > 0) { + promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalThis.context); + promptText += TRY_AGAIN; + setTimeout(this.countdown.bind(this), INTERVAL, freezingTime - INTERVAL); + } else { + promptText = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_use_pwd')); + this.clearPassword(); + // 0: pin unlock + this.pinLock = 0; + } + this.prompt = promptText; + } + + updateStorage(callback): void { + AppStorage.SetOrCreate('passwordArray', this.passwordArray); + AppStorage.SetOrCreate('numKeyboard', this.numKeyboard); + callback(); + } + + build() { + if (!this.controlType.jumpFinger) { + Column() { + Column() { + // 1: pin lock + if (this.pinLock === 1) { + Text($r('app.string.unified_authwidget_locked')) + .margin({ bottom: $r('app.float.content_padding') }) + .fontColor($r('sys.color.ohos_id_color_primary_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_headline6')) + .fontWeight(FontWeight.Medium) + } else if (this.controlType.isShowFace) { + Image($r('app.media.white_faceID')) + .id('faceImgCustomPwd') + .width($r('app.float.image_small')) + .height($r('app.float.image_small')) + .margin({ bottom: $r('app.float.content_padding') }) + .onClick(() => { + if (!this.faceFingerLockArr[0]) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognition')); + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); + } else { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_face_forbidden')); + } + }) + } else { + Text() + .margin({ bottom: $r('app.float.content_padding') }) + .fontColor($r('sys.color.ohos_id_color_primary_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_headline6')) + .fontWeight(FontWeight.Medium) + } + Text(this.prompt) + .id('cancelIconCustomPassword') + .fontSize(this.prompt === globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_use_pwd')) + ? $r('sys.float.ohos_id_text_size_body1') + : $r('sys.float.ohos_id_text_size_body2')) + .fontWeight(FontWeight.Medium) + .fontColor($r('sys.color.ohos_id_color_text_secondary_contrary')) + .margin({ bottom: $r('app.float.margin_16') }) + .textAlign(TextAlign.Center) + .textOverflow({ overflow: TextOverflow.None }) + .height($r('app.float.size_24')) + .onClick(() => { + if (this.prompt === globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1'))) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognition')); + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); + } + }) + + Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + // 0: pin unlock + if (this.pinLock === 0) { + if (this.pinSubType === Constants.pinSix) { + List({ space: DIGITAL_PASSWORD_IC_DIAMETER }) { + ForEach(this.passwordArray, (item) => { + if ((!item || item === '') && item !== 0) { + ListItem() { + Button() + .border({ + color: Color.White, + style: BorderStyle.Solid, + width: 1 + }) + .borderRadius($r('app.float.input_btn_size')) + .width($r('app.float.input_btn_size')) + .height($r('app.float.input_btn_size')) + .type(ButtonType.Circle) + .backgroundColor(Color.Transparent) + } + .margin({ + left: $r('app.float.margin_12'), + right: $r('app.float.margin_12'), + top: $r('app.float.margin_14') + }) + } else { + ListItem() { + Button() + .borderRadius($r('app.float.input_btn_size')) + .width($r('app.float.input_btn_size')) + .height($r('app.float.input_btn_size')) + .type(ButtonType.Circle) + .backgroundColor($r('sys.color.ohos_id_color_text_primary_contrary')) + } + .margin({ + left: $r('app.float.margin_12'), + right: $r('app.float.margin_12'), + top: $r('app.float.margin_14') + }) + } + }) + } + .listDirection(Axis.Horizontal) + .height($r('app.float.input_height')) + + } else if (this.pinSubType === Constants.pinNumber) { + Stack() { + TextInput({ placeholder: '', text: this.passwordArrayNumber.join('') }) + .width('100%') + .onChange(async (value: string) => { + // Removes non-numeric characters from a string + this.passwordArrayNumber = value.replace(/[^\d]/g, '').split(''); + }) + .id('pinInputNumber') + .onSubmit(async (enterKey: EnterKeyType) => { + let str = this.passwordArrayNumber.toString(); + this.textValue = str.replace(/,/g, ''); + if (this.passwordArrayNumber.length < PASSWORD_LENGTH) { + return; + } + + const strData = this.passwordArrayNumber.toString(); + this.textValue = strData.replace(/,/g, ''); + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); + }) + .type(InputType.Password) + .backgroundImageSize(ImageSize.Auto) + .visibility(Visibility.Visible) + .copyOption(CopyOptions.None) + .maxLength(MAX_LENGTH) + } + } else if (this.pinSubType === Constants.pinMixed) { + TextInput({ text: this.passwordObj }) + .height($r('app.float.btn_height')) + .type(InputType.Password) + .textAlign(TextAlign.Center) + .copyOption(CopyOptions.None) + .maxLength(MAX_LENGTH) + .onSubmit(async (enterKey: EnterKeyType) => { + // check callback + if (this.passwordObj.length < PASSWORD_LENGTH) { + return; + } + this.textValue = this.passwordObj; + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); + }) + .onChange((value: string) => { + this.passwordObj = value; + }) + .id('pinInput') + } + } + } + .height($r('app.float.text_high')) + + Button(($r('app.string.unified_authwidget_forgotpwd')), { + stateEffect: false + }) + .id('forgotBtnCustomPwd') + .height($r('app.float.text_high')) + .backgroundColor(Color.Transparent) + .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .fontWeight(FontWeight.Medium) + .onClick(() => { + let str = this.passwordArrayNumber.toString() + this.textValue = str.replace(/,/g, ''); + }) + .visibility(Visibility.Hidden) + } + + // 0: pin unlock + Column() { + if (!this.isLandscape && this.pinLock === 0 && this.pinSubType === Constants.pinSix) { + NumKeyBoard({ + onKeyPress: (index, callback) => { + let keyValue = this.numKeyboard[index].value; + if (keyValue > 0 || keyValue === 0) { + const index = this.passwordArray.map(item => item).indexOf('') + if (index > -1) { + this.passwordArray[index] = keyValue + ''; + this.numKeyboard[11].row1 = $r('app.string.unified_authwidget_delete'); + this.numKeyboard[11].value = DEL_PWD; + if (index === 5) { + this.passwordArray[index] = keyValue + ''; + if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { + return; + } + let str = this.passwordArray.toString(); + this.textValue = str.replace(/,/g, ''); + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); + } + this.updateStorage(callback); + } + } else if (keyValue === DEL_PWD) { + const index = this.passwordArray.map(item => item).indexOf(''); + if (index === -1) { + this.passwordArray[5] = ''; + } else if (index === 1) { + this.passwordArray[index - 1] = ''; + this.numKeyboard[11].value = GO_BACK; + this.numKeyboard[11].row1 = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_back')); + } else { + this.passwordArray[index - 1] = ''; + } + this.updateStorage(callback); + } else if (keyValue === GO_BACK) { + // 0: pin unlock + this.pinLock = 0; + this.clearPassword(); + globalThis.session?.terminateSelf?.(); + } else if (keyValue === CALL_PHONE) { + if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { + return; + } + + let str = this.passwordArray.toString(); + this.textValue = str.replace(/,/g, ''); + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); + } + } + }) + } else { + Text().height(Constants.fullContainerHeight) + } + } + .width(Constants.fullContainerWidth) + .height('40%') + + // 1: pin lock + Column() { + if (this.controlType.isShowFinger && this.pinLock !== 1) { + if (this.fingerPosition.sensorType !== 'OUT_OF_SCREEN_SENSOR' + && this.fingerPosition.sensorType !== 'NON_SENSOR') { + if (this.fingerPosition.sensorType === 'UNDER_SCREEN_SENSOR' || + this.fingerPosition.sensorType === 'BOTH_SENSOR' || + this.fingerPosition.sensorType === 'SensorType1') { + if (this.fingerPosition.udSensorCenterYInThousandth / + this.screen[1] > Constants.fingerSensorPositionLine && + !this.isLandscape) { + Image($r('app.media.ic_unlock_fingerprint')) + .id('fingerprintImgCustomPassword') + .width(px2vp(this.fingerPosition.udSensorRadiusInPx)) + .height(px2vp(this.fingerPosition.udSensorRadiusInPx)) + .position({ + x: px2vp(this.fingerPosition.udSensorCenterXInThousandth), + y: px2vp(this.fingerPosition.udSensorCenterYInThousandth) + }) + .onClick(() => { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); + }) + } else { + Image($r('app.media.finger_white')) + .id('fingerWhiteImgCustomPassword') + .width($r('app.float.image_back_size')) + .height($r('app.float.image_back_size')) + .margin({ top: $r('app.float.input_btn_size') }) + .onClick(() => { + if (this.isLandscape) { + this.underFingerPrint = true; + } else { + this.controlType.jumpFinger = true; + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); + } + }) + } + } + } + } + }.width($r('app.float.digital_password_mask_height')) + .height(this.controlType.isShowFinger ? $r('app.float.finger_high') : '9%') + .justifyContent(FlexAlign.Start) + } + .justifyContent(FlexAlign.End) + .width(Constants.fullContainerWidth) + } else if (!this.controlType.isLandscape) { + Column() { + Text(globalThis.wantParams?.title) + .id('titleFullScreen') + .height($r('app.float.text_high')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) + .fontWeight(FontWeight.Medium) + .position({ y: TITLE_POSITION }) + .width('100%') + .textAlign(TextAlign.Center) + Text(this.fingerText) + .height($r('app.float.text_high')) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .position({ + y: (px2vp(this.fingerPosition.udSensorCenterYInThousandth * this.screen[1] / THOUSANDTH) - + FINGER_TEXT_POSITION - px2vp(FINGER_HIGH + this.fingerPosition.udSensorRadiusInPx)) + }) + .width('100%') + .textAlign(TextAlign.Center) + .margin({ top: $r('app.float.padding_8') }) + Image($r('app.media.ic_unlock_fingerprint')) + .id('unlockFingerprintImgCustomPwd') + // radius + .width(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) + .height(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) + .position({ + x: (px2vp(this.fingerPosition.udSensorCenterXInThousandth * this.screen[0] / THOUSANDTH) + - px2vp(FINGER_X_POSITION + this.fingerPosition.udSensorRadiusInPx)), + y: (px2vp(this.fingerPosition.udSensorCenterYInThousandth * this.screen[1] / THOUSANDTH) + - FINGER_Y_POSITION - px2vp(DEFAULT_SIZE + this.fingerPosition.udSensorRadiusInPx)) + }) + .onClick(() => { + if (this.prompt !== globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden'))) { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); + } + }) + Button($r('app.string.unified_authwidget_cancel'), { + type: ButtonType.Normal, + stateEffect: true + }) + .margin({ bottom: $r('app.float.three_hundred_size'), left: 'auto', right: 'auto' }) + .backgroundColor(Color.Transparent) + .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) + .onClick(() => { + this.controlType.jumpFinger = false; + }) + } + .justifyContent(FlexAlign.End) + .height('100%') + .width('100%') + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/common/components/NumkeyBoard.ets b/entry/src/main/ets/common/components/NumkeyBoard.ets index 36d8b63..144ef60 100644 --- a/entry/src/main/ets/common/components/NumkeyBoard.ets +++ b/entry/src/main/ets/common/components/NumkeyBoard.ets @@ -16,16 +16,15 @@ import deviceInfo from '@ohos.deviceInfo'; import Constants from '../vm/Constants'; -const DIGITALPSD_BUTTON_DIAMETER = 60; -const DIGITALPSD_BUTTON_RECT_WH = 100; -const DIGITALPSD_BUTTON_RECT_HH = 50; -const DEL_PWD = -2; +const DIGITAL_BUTTON_DIAMETER = 60; +const DIGITAL_BUTTON_RECT_WH = 100; +const DIGITAL_BUTTON_RECT_HH = 50; +const DEL_PASSWORD = -2; const CALL_PHONE = -1; const GO_BACK = -3; @Component export default struct NumKeyBoard { - @Link themeType: number; private onKeyPress: (params, callback) => void; @StorageLink('numKeyboard') numKeyboard: any[] = Constants.numKeyBoard; @@ -34,7 +33,6 @@ export default struct NumKeyBoard { Grid() { ForEach(this.numKeyboard, (item: any) => { GridItem() { - Stack({ alignContent: Alignment.Center }) { Column({ space: 0 }) { Flex({ @@ -42,59 +40,57 @@ export default struct NumKeyBoard { alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - if (item.value === CALL_PHONE || - item.value === GO_BACK || - item.value === DEL_PWD) { + if (item.value === CALL_PHONE || item.value === GO_BACK || item.value === DEL_PASSWORD) { Text(item.row1) - .fontSize($r('app.float.digitalpsd_prompt_fontsize')) + .id('textNumKeyBordCustomPwd' + item.index) + .fontSize($r('app.float.digital_password_prompt_font_size')) .fontWeight(FontWeight.Medium) - .fontColor(this.themeType === 1 ? Color.Black : Color.White) + .fontColor(Color.White) .textAlign(TextAlign.Center) .width(Constants.fullContainerWidth) - .padding(0) - .margin(0) + .padding($r('app.float.numkeyBoard_rowsGap')) + .margin($r('app.float.numkeyBoard_rowsGap')) } else { Text(item.row1) - .fontSize($r('app.float.digitalpsd_row1_fontsize')) + .id('textNumKeyBordCustomPwd' + item.index) + .fontSize($r('app.float.digital_password_row1_font_size')) .fontWeight(FontWeight.Medium) - .fontColor(this.themeType === 1 ? Color.Black : Color.White) + .fontColor(Color.White) .textAlign(TextAlign.Center) .width(Constants.fullContainerWidth) - .padding(0) - .margin(0) + .padding($r('app.float.numkeyBoard_rowsGap')) + .margin($r('app.float.numkeyBoard_rowsGap')) } if (!!item.row2) { Text(item.row2) - .fontSize($r('app.float.digitalpsd_row2_fontsize')) + .fontSize($r('app.float.digital_password_row2_font_size')) .fontWeight(FontWeight.Regular) - .fontColor(this.themeType === 1 ? Color.Black : Color.White) + .fontColor(Color.White) .opacity($r('app.float.numkeyBoard_text_opacity')) .textAlign(TextAlign.Center) .width(Constants.fullContainerWidth) - .padding(0) - .margin(0) + .padding($r('app.float.numkeyBoard_rowsGap')) + .margin($r('app.float.numkeyBoard_rowsGap')) } } .width(Constants.fullContainerWidth) - .height('120px') + .height($r('app.float.keyboard_key_high')) } if (deviceInfo.deviceType === 'tablet') { - if (item.value === CALL_PHONE || - item.value === GO_BACK || - item.value === DEL_PWD) { + if (item.value === CALL_PHONE || item.value === GO_BACK || item.value === DEL_PASSWORD) { Column() { Button({ type: ButtonType.Normal, stateEffect: true }) - .backgroundColor('#00FFFFFF') - .width(DIGITALPSD_BUTTON_RECT_WH) - .height(DIGITALPSD_BUTTON_RECT_HH) + .backgroundColor($r('app.color.button_color')) + .width(DIGITAL_BUTTON_RECT_WH) + .height(DIGITAL_BUTTON_RECT_HH) } } else { Column() { Button({ type: ButtonType.Circle }) - .backgroundColor('#00FFFFFF') - .width(DIGITALPSD_BUTTON_DIAMETER) - .height(DIGITALPSD_BUTTON_DIAMETER) + .backgroundColor($r('app.color.button_color')) + .width(DIGITAL_BUTTON_DIAMETER) + .height(DIGITAL_BUTTON_DIAMETER) } } } @@ -103,7 +99,7 @@ export default struct NumKeyBoard { setTimeout(this.onKeyPress.bind(this), 0, item.index, () => { }); }) - .id('numKeyBordCustomPwd') + .id('numKeyBordCustomPwd' + item.index) } }) } diff --git a/entry/src/main/ets/common/components/PassWord.ets b/entry/src/main/ets/common/components/PassWord.ets new file mode 100644 index 0000000..254557c --- /dev/null +++ b/entry/src/main/ets/common/components/PassWord.ets @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 Constants from '../../common/vm/Constants'; + +const MAX_LENGTH = 32; + +@Component +export default struct PassWord { + @Link pinSubType: string; + @Link @Watch('onTextValueChange') textValue: string; + @Link inputValue: string; + @Link isEdit: boolean; + @StorageLink('passwordArrayNumber') passwordArrNumber: string[] = []; + controller: CustomDialogController; + cancel: () => void; + confirm: () => void; + + onTextValueChange(): void { + this.passwordArrNumber = this.textValue.replace(/[^\d]/g, '').split(''); + } + + clearPassword(): void { + this.passwordArrNumber = []; + this.textValue = ''; + this.inputValue = ' '; + } + + aboutToDisappear(): void { + this.clearPassword(); + } + + build() { + Column() { + Text(globalThis.wantParams?.title) + .margin({ top: $r('app.float.content_padding_top') }) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .fontWeight(FontWeight.Medium) + .height($r('app.float.size_24')) + .id('titlePwdAuth') + TextInput({ + placeholder: '', + text: this.pinSubType === Constants.pinNumber ? this.passwordArrNumber.join('') : this.textValue + }) + .maxLength(MAX_LENGTH) + .enabled(this.isEdit) + .height($r('app.float.input_height')) + .type(InputType.Password) + .margin({ + top: $r('app.float.content_padding'), + left: $r('app.float.digital_password_mask_height'), + right: $r('app.float.digital_password_mask_height') + }) + .textAlign(TextAlign.Center) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .border({ + width: this.inputValue === ' ' ? '' : $r('app.float.input_border'), + color: this.inputValue === ' ' ? '' : ($r('sys.color.ohos_id_color_warning')) + }) + .onChange((value: string) => { + if (this.pinSubType === Constants.pinNumber) { + this.passwordArrNumber = value.replace(/[^\d]/g, '').split(''); + } + this.textValue = value; + }) + .id('pinInputMix') + Text(this.inputValue) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .margin({ top: $r('app.float.element_margin') }) + .fontColor($r('sys.color.ohos_id_color_warning')) + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/common/components/SixPassword.ets b/entry/src/main/ets/common/components/SixPassword.ets new file mode 100644 index 0000000..e7c17d3 --- /dev/null +++ b/entry/src/main/ets/common/components/SixPassword.ets @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 Constants from '../../common/vm/Constants'; +import AuthUtils from '../utils/AuthUtils'; + +const MAX_LENGTH = 6; + +@Component +export default struct SixPassword { + @Link textValue: string; + @Link inputValue: string; + @Link isEdit: boolean; + + build() { + Column() { + Text(globalThis.wantParams?.title) + .margin({ top: $r('app.float.content_padding_top') }) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .height($r('app.float.size_24')) + .fontWeight(FontWeight.Medium) + Column() { + Stack() { + TextInput({ placeholder: '', text: this.textValue }) + .onChange(async (value: string) => { + this.textValue = value + if (value.length === MAX_LENGTH) { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); + } + }) + .backgroundImageSize(ImageSize.Auto) + .enabled(this.isEdit) + .maxLength(MAX_LENGTH) + .visibility(Visibility.Visible) + .opacity(0) + .caretColor('transparent') + .id('pinSix') + List({ space: 4 }) { + ForEach(['', '', '', '', '', ''], (item, index) => { + ListItem() { + Button() + .border({ + color: $r('sys.color.ohos_id_color_primary'), + style: BorderStyle.Solid, + width: this.textValue.length !== 0 && index < this.textValue.length + ? $r('app.float.button_border_width') : 1 + }) + .type(ButtonType.Circle) + .backgroundColor(Color.White) + .width($r('app.float.input_btn_size')) + .height($r('app.float.input_btn_size')) + .borderRadius($r('app.float.input_btn_size')) + .margin(index > 0 ? + { + left: $r('app.float.input_btn_padding_around'), + top: $r('app.float.margin_12') + } : { top: $r('app.float.margin_12') }) + .focusable(true) + } + }, item => item) + } + .listDirection(Axis.Horizontal) + .height($r('app.float.input_height')) + + } + } + .margin({ top: $r('app.float.content_padding') }) + + Text(this.inputValue) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .margin({ top: $r('app.float.element_margin') }) + .fontColor($r('sys.color.ohos_id_color_warning')) + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/AuthUtils.ts b/entry/src/main/ets/common/utils/AuthUtils.ts index 496b85e..8287346 100644 --- a/entry/src/main/ets/common/utils/AuthUtils.ts +++ b/entry/src/main/ets/common/utils/AuthUtils.ts @@ -40,11 +40,12 @@ export default class AuthUtils { } }; const jsonEventData = JSON.stringify(eventData); - LogUtils.i(TAG, 'sendNotice start eventData: ' + jsonEventData); + LogUtils.info(TAG, 'sendNotice start eventData: ' + jsonEventData); userAuth.sendNotice(userAuth.NoticeType.WIDGET_NOTICE, jsonEventData); - LogUtils.i(TAG, 'sendNotice success'); + LogUtils.info(TAG, 'sendNotice success'); } catch (error) { - LogUtils.e(TAG, 'sendNotice catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'sendNotice catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); } } } \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/FuncUtils.ts b/entry/src/main/ets/common/utils/FuncUtils.ts index 07e475b..f466bd3 100644 --- a/entry/src/main/ets/common/utils/FuncUtils.ts +++ b/entry/src/main/ets/common/utils/FuncUtils.ts @@ -52,10 +52,10 @@ export class FuncUtils { } getWindowHeight(): void { - LogUtils.i(TAG, 'getWindowHeight'); + LogUtils.info(TAG, 'getWindowHeight'); try { window.on('systemBarTintChange', (data) => { - LogUtils.d(TAG, 'Succeeded in enabling the listener for window stage event changes. Data: ' + + LogUtils.debug(TAG, 'Succeeded in enabling the listener for window stage event changes. Data: ' + JSON.stringify(data)); for (let i = 0; i < data.regionTint.length; i++) { let regionData = data.regionTint[i]; @@ -69,9 +69,8 @@ export class FuncUtils { } } }); - } catch (exception) { - LogUtils.e(TAG, 'Failed to enable the listener for window stage event changes. Cause:' + - JSON.stringify(exception)); + } catch (error) { + LogUtils.error(TAG, 'Failed to enable the listener for window stage event changes. error: ' + error?.code); } } } diff --git a/entry/src/main/ets/common/utils/LogUtils.ts b/entry/src/main/ets/common/utils/LogUtils.ts index 0a73c1f..95faea0 100644 --- a/entry/src/main/ets/common/utils/LogUtils.ts +++ b/entry/src/main/ets/common/utils/LogUtils.ts @@ -40,9 +40,8 @@ export class LogUtils { * * @param tag Identifies the log tag. * @param format Indicates the log format string. - * @since 7 */ - d(tag: string, format: string): void { + debug(tag: string, format: string): void { if (LogUtils.isLogGable(hiLog.LogLevel.DEBUG)) { hiLog.debug(DOMAIN, TAG, tag + SYMBOL + format); } @@ -53,9 +52,8 @@ export class LogUtils { * * @param tag Identifies the log tag. * @param format Indicates the log format string. - * @since 7 */ - i(tag: string, format: string): void { + info(tag: string, format: string): void { if (LogUtils.isLogGable(hiLog.LogLevel.INFO)) { hiLog.info(DOMAIN, TAG, tag + SYMBOL + format); } @@ -66,9 +64,8 @@ export class LogUtils { * * @param tag Identifies the log tag. * @param format Indicates the log format string. - * @since 7 */ - w(tag: string, format: string): void { + warn(tag: string, format: string): void { if (LogUtils.isLogGable(hiLog.LogLevel.WARN)) { hiLog.warn(DOMAIN, TAG, tag + SYMBOL + format); } @@ -79,9 +76,8 @@ export class LogUtils { * * @param tag Identifies the log tag. * @param format Indicates the log format string. - * @since 7 */ - e(tag: string, format: string): void { + error(tag: string, format: string): void { if (LogUtils.isLogGable(hiLog.LogLevel.ERROR)) { hiLog.error(DOMAIN, TAG, tag + SYMBOL + format); } @@ -92,9 +88,8 @@ export class LogUtils { * * @param tag Identifies the log tag. * @param format Indicates the log format string. - * @since 7 */ - f(tag: string, format: string): void { + fatal(tag: string, format: string): void { if (LogUtils.isLogGable(hiLog.LogLevel.FATAL)) { hiLog.fatal(DOMAIN, TAG, tag + SYMBOL + format); } @@ -105,7 +100,6 @@ export class LogUtils { * * @param tag Identifies the log tag. * @param level log level - * @since 7 */ private static isLogGable(level: hiLog.LogLevel): boolean { return hiLog.isLoggable(DOMAIN, TAG, level); diff --git a/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts b/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts index fefdbe8..e6421a4 100644 --- a/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts +++ b/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts @@ -19,17 +19,18 @@ const TAG = 'WindowPrivacyUtils'; export class WindowPrivacyUtils { setWindowPrivacyMode(session: UIExtensionContentSession, isPrivacyMode: boolean): void { - LogUtils.d(TAG, 'setWindowPrivacyMode'); + LogUtils.debug(TAG, 'setWindowPrivacyMode'); try { session?.setWindowPrivacyMode(isPrivacyMode, (error) => { if (error) { - LogUtils.e(TAG, 'setWindowPrivacyMode error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'setWindowPrivacyMode error'); return; } - LogUtils.d(TAG, 'setWindowPrivacyMode success'); + LogUtils.debug(TAG, 'setWindowPrivacyMode success'); }); } catch (error) { - LogUtils.e(TAG, 'setWindowPrivacyMode catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'setWindowPrivacyMode catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); } } } diff --git a/entry/src/main/ets/common/vm/Constants.ts b/entry/src/main/ets/common/vm/Constants.ts index 6381480..8665d3b 100644 --- a/entry/src/main/ets/common/vm/Constants.ts +++ b/entry/src/main/ets/common/vm/Constants.ts @@ -29,17 +29,20 @@ export default class Constants { // getUserAuthWidgetMgr params static userAuthWidgetMgrVersion = 1; - //command result success + // command result success static userAuthWidgetMgrSuccess = 0; - // sendNotice param - // version + // sendNotice param: version static noticeVersion = '1'; // type static noticeTypePin = 'pin'; static noticeTypeFace = 'face'; static noticeTypeFinger = 'fingerprint'; + static fingerSensorPositionLine = 0.75; + + static hintTimesByFailLess = 3; + static maxFailTimes = 5; static numKeyBoard = [ { diff --git a/entry/src/main/ets/extensionability/UserAuthAbility.ts b/entry/src/main/ets/extensionability/UserAuthAbility.ts index 5551858..233e8d3 100644 --- a/entry/src/main/ets/extensionability/UserAuthAbility.ts +++ b/entry/src/main/ets/extensionability/UserAuthAbility.ts @@ -18,40 +18,49 @@ import UserAuthExtensionAbility from '@ohos.app.ability.UserAuthExtensionAbility import WindowPrivacyUtils from '../common/utils/WindowPrivacyUtils'; const TAG = 'UserAuthAbility'; +// The current interface only support string type +const TRANSPARENT_COLOR = '#00000000'; +const MASK_THIN_COLOR = '#33182431'; export default class UserAuthAbility extends UserAuthExtensionAbility { onCreate() { - LogUtils.i(TAG, 'UserAuthExtensionAbility onCreate context: ' + JSON.stringify(this.context)); + LogUtils.info(TAG, 'UserAuthExtensionAbility onCreate'); globalThis.context = this.context; } onForeground(): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onForeground'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onForeground'); } onBackground(): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onBackground'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onBackground'); + globalThis.session?.terminateSelf(); } onDestroy(): void | Promise { - LogUtils.i(TAG, 'UserAuthExtensionAbility onDestroy'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onDestroy'); } onSessionCreate(want, session): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onSessionCreate want: ' + JSON.stringify(want)); + LogUtils.info(TAG, 'UserAuthExtensionAbility onSessionCreate'); globalThis.wantParams = want?.parameters?.useriamCmdData; globalThis.session = session; session?.loadContent('pages/Index'); try { - session.setWindowBackgroundColor('#00000000'); + if (globalThis.wantParams?.windowModeType === 'DIALOG_BOX') { + session?.setWindowBackgroundColor(MASK_THIN_COLOR); + } else { + session?.setWindowBackgroundColor(TRANSPARENT_COLOR); + } } catch (error) { - LogUtils.e(TAG, 'UserAuthExtensionAbility onSessionCreate error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'UserAuthExtensionAbility onSessionCreate error: ' + error?.code); + session?.terminateSelf(); } WindowPrivacyUtils.setWindowPrivacyMode(session, true); } onSessionDestroy(session): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onSessionDestroy'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onSessionDestroy'); WindowPrivacyUtils.setWindowPrivacyMode(session, false); } } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 9d5fa17..a2f1256 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -28,7 +28,6 @@ const DEFAULT_SIZE = 72; const FIVE_SECOND = 5000; const LAND_SCAPE = 2; const TAG = 'Index'; -const THEME_BLUR = 2; let userAuthWidgetMgr; @Entry @@ -41,8 +40,6 @@ struct Index { @State pinSubType: string = Constants.pinNumber; @State dialogType: DialogType = DialogType.ALL; @State windowModeType: string = 'DIALOG_BOX'; - // background 1:white 2:Gaussian Blur - @State themeType: number = THEME_BLUR; @State cmdData: Array = []; @Provide isLandscape: boolean = false; @Provide underFingerPrint: boolean = false; @@ -52,18 +49,20 @@ struct Index { try { screen.getAllScreens((err, data) => { if (err.code) { - LogUtils.e(TAG, 'Failed to get all screens. Cause: ' + JSON.stringify(err)); + LogUtils.error(TAG, 'Failed to get all screens. err: ' + err.code); + globalThis.session?.terminateSelf(); return; } - LogUtils.d(TAG, ' get all screens. result:-- ' + JSON.stringify(data)); + LogUtils.debug(TAG, ' get all screens. result:-- ' + JSON.stringify(data)); this.isLandscape = data[0].orientation === LAND_SCAPE; + LogUtils.debug(TAG, 'globalThis.wantParams: ' + JSON.stringify(globalThis.wantParams)); if (globalThis.wantParams) { this.getParams(globalThis.wantParams); this.handleAuthStart(); this.cmdData = globalThis.wantParams?.cmd; - LogUtils.d(TAG, 'globalThis.wantParams: ' + JSON.stringify(globalThis.wantParams)); } else { - LogUtils.e(TAG, 'aboutToAppear wantParams null'); + LogUtils.error(TAG, 'aboutToAppear wantParams null'); + globalThis.session?.terminateSelf(); } if (this.isLandscape && this.underFingerPrint) { setTimeout(() => { @@ -73,19 +72,21 @@ struct Index { this.loadFlag = true; } }); - } catch (exception) { - LogUtils.e(TAG, 'getAllScreens catch exception: ' + exception); + } catch (error) { + LogUtils.error(TAG, 'getAllScreens catch error: ' + error?.code); + globalThis.session?.terminateSelf(); } } handleAuthStart(): void { + LogUtils.info(TAG, 'handleAuthStart'); try { userAuthWidgetMgr = userAuth.getUserAuthWidgetMgr(Constants.userAuthWidgetMgrVersion); - LogUtils.i(TAG, 'getUserAuthWidgetMgr success'); + LogUtils.info(TAG, 'getUserAuthWidgetMgr success'); let that = this; userAuthWidgetMgr.on('command', { callback: function (result) { - LogUtils.i(TAG, 'userAuthWidgetMgr onCommand result: ' + JSON.stringify(result)); + LogUtils.info(TAG, 'userAuthWidgetMgr onCommand result: ' + JSON.stringify(result)); const cmdDataObj = JSON.parse(result?.cmdData || '{}'); if (cmdDataObj?.cmd?.[0]?.payload?.result === Constants.userAuthWidgetMgrSuccess) { globalThis.session?.terminateSelf(); @@ -97,48 +98,51 @@ struct Index { } }); } catch (error) { - LogUtils.e(TAG, 'getUserAuthWidgetMgr catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'getUserAuthWidgetMgr catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); } } handleIsUnder(cmd: Array): void { - cmd?.length > 0 && cmd.map((item) => { - const { type, sensorInfo } = item.payload; - if (type === Constants.noticeTypeFinger) { - if (sensorInfo && JSON.stringify(sensorInfo) !== '{}') { - const fingerPosition = JSON.parse(sensorInfo); - if (fingerPosition.sensorType === 'UNDER_SCREEN_SENSOR' || - fingerPosition.sensorType === 'BOTH_SENSOR' || - fingerPosition.sensorType === 'SensorType1') { - this.underFingerPrint = true; + try { + LogUtils.info(TAG, 'handleIsUnder'); + cmd?.length > 0 && cmd.map((item) => { + const { type, sensorInfo } = item?.payload; + if (type === Constants.noticeTypeFinger) { + if (sensorInfo && JSON.stringify(sensorInfo) !== '{}') { + const fingerPosition = JSON.parse(sensorInfo); + if (fingerPosition?.sensorType === 'UNDER_SCREEN_SENSOR' || + fingerPosition?.sensorType === 'BOTH_SENSOR' || + fingerPosition?.sensorType === 'SensorType1') { + this.underFingerPrint = true; + } } } - } - }); + }); + } catch (error) { + LogUtils.error(TAG, 'handleIsUnder catch error: ' + error?.code); + } } aboutToAppear(): void { + LogUtils.debug(TAG, 'aboutToAppear'); this.onScreenChange(); - LogUtils.d(TAG, 'aboutToAppear'); } aboutToDisappear(): void { - LogUtils.i(TAG, 'aboutToDisappear'); + LogUtils.info(TAG, 'aboutToDisappear'); if (userAuthWidgetMgr) { userAuthWidgetMgr.off('command', { callback: function (result) { - LogUtils.i(TAG, 'aboutToDisappear userAuthWidgetMgr offCommand result: ' + JSON.stringify(result)); + LogUtils.info(TAG, 'aboutToDisappear userAuthWidgetMgr offCommand result: ' + JSON.stringify(result)); } }); } } - onPageShow(): void { - LogUtils.i(TAG, 'onPageShow'); - } - getParams(result): void { - LogUtils.i(TAG, 'getParams'); + LogUtils.info(TAG, 'getParams'); + LogUtils.info(TAG, 'dengjiewen msg test'); const { pinSubType, windowModeType, cmd, type, widgetContextId } = result; this.pinSubType = pinSubType; const newType = type && type.map(item => { @@ -161,54 +165,62 @@ struct Index { } build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) { + Column() { if (this.isLandscape && this.underFingerPrint) { - Column() { - Text(globalThis.context.resourceManager - .getStringSync($r('app.string.unified_authwidget_tip_verify_in_portrait_mode'))) - .height('40vp') - .fontColor(Color.Black) - .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) - .fontWeight(FontWeight.Medium) - }.justifyContent(FlexAlign.End) - .backgroundColor(Color.White) + Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.End }) { + Column() { + Text(globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_tip_verify_in_portrait_mode'))) + .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .fontWeight(FontWeight.Regular) + } + .backgroundColor($r('sys.color.ohos_id_color_instant_tip_bg')) + .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) + .padding({ + left: $r('app.float.padding_16'), + top: $r('app.float.padding_8'), + right: $r('app.float.padding_16'), + bottom: $r('app.float.padding_8') + }) + .margin({ bottom: $r('app.float.margin_64') }) + } .width(Constants.fullContainerWidth) - .height(Constants.fullContainerWidth) + .height(Constants.fullContainerHeight) } else if (this.loadFlag) { - if ('DIALOG_BOX' === this.windowModeType) { - if (this.authType.includes(userAuth.UserAuthType.FACE)) { - FaceAuth({ - type: $windowModeType, - pinSubType: $pinSubType, - dialogType: $dialogType, - cmdData: $cmdData, - }) - } else if (this.authType.includes(userAuth.UserAuthType.FINGERPRINT)) { - FingerprintAuth({ - type: $windowModeType, - pinSubType: $pinSubType, - dialogType: $dialogType, - cmdData: $cmdData, - }) + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) { + if ('DIALOG_BOX' === this.windowModeType) { + if (this.authType.includes(userAuth.UserAuthType.FACE)) { + FaceAuth({ + type: $windowModeType, + pinSubType: $pinSubType, + dialogType: $dialogType, + cmdData: $cmdData, + }) + } else if (this.authType.includes(userAuth.UserAuthType.FINGERPRINT)) { + FingerprintAuth({ + type: $windowModeType, + pinSubType: $pinSubType, + dialogType: $dialogType, + cmdData: $cmdData, + }) + } else { + PasswordAuth({ + pinSubType: $pinSubType, + cmdData: $cmdData + }) + } } else { - PasswordAuth({ + // full screen PIN + CustomPassword({ + authType: $authType, pinSubType: $pinSubType, - cmdData: $cmdData + cmdData: $cmdData, }) } - - } else { - // full screen PIN - CustomPassword({ - themeType: $themeType, - authType: $authType, - pinSubType: $pinSubType, - cmdData: $cmdData, - }) } } - } - .onAreaChange(() => { + }.onAreaChange(() => { FuncUtils.getWindowHeight(); }) } diff --git a/entry/src/main/ets/pages/components/CustomPassword.ets b/entry/src/main/ets/pages/components/CustomPassword.ets index aabaa00..de65bd9 100644 --- a/entry/src/main/ets/pages/components/CustomPassword.ets +++ b/entry/src/main/ets/pages/components/CustomPassword.ets @@ -15,24 +15,23 @@ import account_osAccount from '@ohos.account.osAccount'; import userAuth from '@ohos.userIAM.userAuth'; -import CustomPSD from '../../common/components/CustomPSD'; +import FullScreen from '../../common/components/FullScreen'; import FuncUtils from '../../common/utils/FuncUtils'; import LogUtils from '../../common/utils/LogUtils'; import Constants from '../../common/vm/Constants'; const TAG = 'CustomPassword'; const BLUR_OPACITY = 0.5; -const BTN_BORDER_RADIUS = 25; -const THEME_WHITE = 1; const SATURATE = 1.3; const BLUR_RADIUS = 242; +const BACK_BLUR = 80; +const PADDING_ZERO = 0; let pinAuthManager; let pinData = ''; @Component export default struct CustomPassword { @Link pinSubType: string; - @Link themeType: number; @Link authType: Array; @Link cmdData: []; @State isBackTouched: boolean = false @@ -46,25 +45,25 @@ export default struct CustomPassword { } aboutToAppear(): void { - // register input try { - LogUtils.i(TAG, 'aboutToAppear PINAuth start'); + LogUtils.info(TAG, 'aboutToAppear PINAuth'); pinAuthManager = new account_osAccount.PINAuth(); - LogUtils.i(TAG, 'aboutToAppear PINAuth pinAuthManager: ' + JSON.stringify(pinAuthManager)); + // register input pinAuthManager.registerInputer({ onGetData: (authSubType, callback) => { + LogUtils.info(TAG, 'aboutToAppear registerInputer onGetData'); const uint8PW = FuncUtils.getUint8PW(pinData); - LogUtils.i(TAG, 'PINAuth onGetData pinData'); callback.onSetData(authSubType, uint8PW); } }); } catch (error) { - LogUtils.e(TAG, 'aboutToAppear PINAuth catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); } } aboutToDisappear(): void { - LogUtils.i(TAG, 'aboutToDisappear PINAuth unregisterInputer'); + LogUtils.info(TAG, 'aboutToDisappear PINAuth unregisterInputer'); pinAuthManager?.unregisterInputer?.(); } @@ -76,34 +75,19 @@ export default struct CustomPassword { .height(Constants.fullContainerWidth) .position({ x: 0, y: 0 }) .opacity(BLUR_OPACITY) - .backgroundColor('#0d0d0d') + .backgroundColor($r('app.color.full_screen_background')) .blur(BLUR_RADIUS) .saturate(SATURATE) Column() { Flex({ direction: FlexDirection.Row }) { - if (this.themeType === THEME_WHITE) { - Flex() { - Text('←') - .borderRadius(8) - .fontSize($r('app.float.title_size')) - .backgroundColor(Color.Transparent) - .fontColor(Color.Black) - Text($r('app.string.unified_authwidget_back')) - .fontSize($r('app.float.title_size')) - .fontWeight(FontWeight.Medium) - .fontColor(Color.Black) - .textAlign(TextAlign.Center) - .textOverflow({ overflow: TextOverflow.None }) - .margin({ left: 12 }) - } - .id('cancelIconCustomPwd') - .margin({ left: $r('sys.float.ohos_id_max_padding_start'), right: $r('app.float.element_margin'), top: - '2vp' }) - .padding($r('app.float.back_padding')) - .width($r('app.float.back_width')) - .backgroundColor(this.isBackTouched ? $r('sys.color.ohos_id_color_hover') : Color.Transparent) - .borderRadius(BTN_BORDER_RADIUS) + Image($r('app.media.ic_white_cancel')) + .id('cancelImgCustomPwd') + .width($r('app.float.image_back_size')) + .height($r('app.float.image_back_size')) + .margin({ left: $r('sys.float.ohos_id_max_padding_start'), top: $r('app.float.content_padding') }) + .backgroundColor(this.isBackTouched + ? $r('sys.color.ohos_id_color_hover') : Color.Transparent) .onClick(() => { globalThis.session?.terminateSelf?.(); }) @@ -115,26 +99,6 @@ export default struct CustomPassword { this.isBackTouched = false; } }); - } else { - Image($r('app.media.ic_white_cancel')) - .id('cancelImgCustomPwd') - .width($r('app.float.image_back_size')) - .height($r('app.float.image_back_size')) - .margin({ left: $r('sys.float.ohos_id_max_padding_start'), top: $r('app.float.content_padding') }) - .backgroundColor(this.isBackTouched ? $r('sys.color.ohos_id_color_hover') : Color.Transparent) - .onClick(() => { - globalThis.session?.terminateSelf?.(); - }) - - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isBackTouched = true; - } - if (event.type === TouchType.Up) { - this.isBackTouched = false; - } - }); - } } GridRow({ @@ -149,8 +113,7 @@ export default struct CustomPassword { GridCol({ span: { xs: 8, sm: 6, md: 6, lg: 6 }, }) { - CustomPSD({ - themeType: $themeType, + FullScreen({ textValue: $textValue, authType: $authType, pinSubType: $pinSubType, @@ -159,13 +122,15 @@ export default struct CustomPassword { } } } - .padding(this.isLandscape ? 0 : { top: this.SYSTEM_STATUS_BAR_HEIGHT, bottom: this.SYSTEM_NAVIGATION_BAR_HEIGHT }) + .padding(this.isLandscape + ? PADDING_ZERO + : { top: this.SYSTEM_STATUS_BAR_HEIGHT, bottom: this.SYSTEM_NAVIGATION_BAR_HEIGHT }) .justifyContent(FlexAlign.SpaceBetween) .width(Constants.fullContainerWidth) .height(Constants.fullContainerWidth) } .width(Constants.fullContainerWidth) .height(Constants.fullContainerWidth) - .backdropBlur(80) + .backdropBlur(BACK_BLUR) } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/components/FaceAuth.ets b/entry/src/main/ets/pages/components/FaceAuth.ets index e675c7e..deaa9bf 100644 --- a/entry/src/main/ets/pages/components/FaceAuth.ets +++ b/entry/src/main/ets/pages/components/FaceAuth.ets @@ -16,20 +16,28 @@ import screen from '@ohos.screen'; import account_osAccount from '@ohos.account.osAccount'; import display from '@ohos.display'; import util from '@ohos.util'; -import Pwd from '../../common/components/Pwd'; -import SixPwd from '../../common/components/SixPwd'; +import PassWord from '../../common/components/PassWord'; +import SixPassword from '../../common/components/SixPassword'; import { DialogType } from '../../common/module/DialogType'; import AuthUtils from '../../common/utils/AuthUtils'; import LogUtils from '../../common/utils/LogUtils'; import TimeUtils from '../../common/utils/TimeUtils'; import Constants, { CmdType, FingerPosition } from '../../common/vm/Constants'; -let pinAuthManager; const TAG = 'FaceAuth'; + +let pinAuthManager; const INTERVAL = 1000; const THOUSANDTH = 1000; const NORMAL_POSITION = -260; - +const MARGIN_TOP = 100; +const PIN_FACE = 1; +const PIN_FACE_FINGER = 2; +const MULTI_PIN = 4; +const SIX_PIN = 5; +const SINGLE_FACE = 6; +const SCREEN_LAND = 1; +const SCREEN_PORTRAIT = 2; let pinData = ''; @Component @@ -44,8 +52,10 @@ export default struct FaceAuth { @Link pinSubType: string; @Link dialogType: DialogType; @State inputValue: string = ''; - @State flag: boolean = true; - @State flagN: number = this.dialogType === DialogType.PIN_FACE ? 1 : (this.dialogType === DialogType.ALL ? 2 : 6); + @State dialogTypeFlag: number = this.dialogType === DialogType.PIN_FACE ? + PIN_FACE : (this.dialogType === DialogType.ALL ? PIN_FACE_FINGER : SINGLE_FACE); + // 1:Portrait screen 2:Landscape mode + @State screenType: number = 0; @State screenClass: object = {}; @State fingerPosition: FingerPosition = { sensorType: '' @@ -72,32 +82,32 @@ export default struct FaceAuth { } aboutToAppear(): void { - if (this.cmdData && this.cmdData.length > 0) { - this.onCmdDataChange('first'); - } - if (this.dialogType === DialogType.PIN_FACE || - this.dialogType === DialogType.FACE) { - this.prompt = globalThis.context.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_recognition')); - AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); - } - if (this.dialogType === DialogType.ALL) { - AuthUtils.getInstance() - .sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger, Constants.noticeTypeFace]); - } + LogUtils.debug(TAG, 'aboutToAppear'); try { - LogUtils.d(TAG, 'PINAuth start'); + if (this.cmdData && this.cmdData.length > 0) { + this.onCmdDataChange('first'); + } + if (this.dialogType === DialogType.PIN_FACE || this.dialogType === DialogType.FACE) { + this.prompt = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognition')); + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); + } + if (this.dialogType === DialogType.ALL) { + AuthUtils.getInstance() + .sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger, Constants.noticeTypeFace]); + } pinAuthManager = new account_osAccount.PINAuth(); - LogUtils.d(TAG, 'PINAuth new success: ' + pinData); pinAuthManager.registerInputer({ onGetData: (authSubType, callback) => { + LogUtils.info(TAG, 'aboutToAppear registerInputer onGetData'); let textEncoder = new util.TextEncoder(); let uint8PW = textEncoder.encode(pinData); callback.onSetData(authSubType, uint8PW); } }); } catch (error) { - LogUtils.e(TAG, 'PINAuth catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'PINAuth catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); } } @@ -105,15 +115,17 @@ export default struct FaceAuth { pinAuthManager?.unregisterInputer?.(); } - toPin() { - if (this.pinSubType !== Constants.pinSix) { - this.flagN = 4; - } else { - this.flagN = 5; + toPin(): void { + if ([DialogType.PIN_FACE, DialogType.ALL].includes(this.dialogType)) { + if (this.pinSubType !== Constants.pinSix) { + this.dialogTypeFlag = MULTI_PIN; + } else { + this.dialogTypeFlag = SIX_PIN; + } } - }; + } - send() { + send(): void { if (this.prompt === globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1'))) { this.prompt = globalThis.context.resourceManager @@ -146,10 +158,7 @@ export default struct FaceAuth { } onCmdDataChange(num?: string): void { - LogUtils.i(TAG, 'onCmdDataChanger ' + JSON.stringify(this.cmdData)) - let isToPin = false; this.cmdData.length > 0 && this.cmdData.map(async (item) => { - LogUtils.i(TAG, 'itemData ' + JSON.stringify(item)) const { type, remainAttempts, lockoutDuration,sensorInfo} = item.payload; switch (type) { case Constants.noticeTypePin: @@ -160,7 +169,7 @@ export default struct FaceAuth { if (num === 'first') { this.inputValue = ''; } - if (remainAttempts < 3) { + if (remainAttempts < Constants.hintTimesByFailLess) { this.inputValue = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) + remainAttempts + globalThis.context.resourceManager @@ -173,6 +182,9 @@ export default struct FaceAuth { } break; case Constants.noticeTypeFace: + if ([SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { + return; + } if (remainAttempts) { this.prompt = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1')); @@ -185,13 +197,15 @@ export default struct FaceAuth { if (remainAttempts === 0) { this.prompt = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden')); - this.faceLock = true - if (this.dialogType === DialogType.PIN_FACE || this.dialogType === DialogType.ALL) { - isToPin = true; - } + + this.faceLock = true; + this.toPin(); } break; case Constants.noticeTypeFinger: + if ([SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { + return; + } if (sensorInfo && JSON.stringify(sensorInfo) !== '{}') { this.fingerPosition = JSON.parse(sensorInfo); const displayClass = display.getDefaultDisplaySync(); @@ -199,23 +213,26 @@ export default struct FaceAuth { switch (JSON.parse(sensorInfo)?.sensorType) { case 'NON_SENSOR': case 'OUT_OF_SCREEN_SENSOR': { - this.flagN = 1; + this.dialogTypeFlag = PIN_FACE; break; } default: - if ((JSON.parse(sensorInfo).udSensorCenterYInThousandth / displayClass.height < 0.75)) { + if ((JSON.parse(sensorInfo) + .udSensorCenterYInThousandth / displayClass.height < Constants.fingerSensorPositionLine)) { try { await screen.getAllScreens((err, data) => { if (err.code) { - LogUtils.e(TAG, 'Failed to get all screens. Cause: ' + JSON.stringify(err)); + LogUtils.error(TAG, 'Failed to get all screens. err: ' + err.code); return; } - if (data[0].orientation !== 2 && !isToPin) { - this.flagN = 3; + if (data[0].orientation !== SCREEN_PORTRAIT && ![SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { + this.screenType = SCREEN_LAND; + } else { + this.screenType = SCREEN_PORTRAIT; } }); - } catch (exception) { - LogUtils.e(TAG, 'getAllScreens catch exception: ' + exception); + } catch (error) { + LogUtils.error(TAG, 'getAllScreens catch error: ' + error?.code); } } break; @@ -224,7 +241,7 @@ export default struct FaceAuth { if (remainAttempts) { this.prompt = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); - if (remainAttempts < 5) { + if (num !== 'first' && remainAttempts > 0) { AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); } } @@ -235,18 +252,14 @@ export default struct FaceAuth { if (remainAttempts === 0) { this.prompt = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); - if (this.dialogType === DialogType.PIN_FACE || this.dialogType === DialogType.ALL) { - isToPin = true; - } + this.toPin(); } + break; default: + LogUtils.error(TAG, 'onCmdDataChange default'); break; } }) - - if (isToPin) { - this.toPin(); - } } build() { @@ -264,9 +277,10 @@ export default struct FaceAuth { span: { xs: 8, sm: 8, md: 4, lg: 4 }, }) { Column() { - if (this.flagN === 1) { - // Single FACE + if (this.dialogTypeFlag === PIN_FACE) { + // Pin FACE Text(globalThis.wantParams.title) + .id('titlePinFace') .fontSize($r('sys.float.ohos_id_text_size_body1')) .margin({ top: $r('app.float.content_padding_top') }) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -275,8 +289,8 @@ export default struct FaceAuth { .getStringSync($r('app.string.unified_authwidget_hint_recognize_success')) ? $r('app.media.error_faceID') : $r('app.media.right_faceID')) .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - bottom: $r('app.float.digitalpsd_passwdmask_height') + top: $r('app.float.digital_password_mask_height'), + bottom: $r('app.float.digital_password_mask_height') }) .width($r('app.float.image_size')) .height($r('app.float.image_size')) @@ -286,6 +300,7 @@ export default struct FaceAuth { }) Text(this.prompt).fontSize($r('sys.float.ohos_id_text_size_body2')) .fontColor(this.onFontColor(this.prompt, globalThis.context)) + .height($r('app.float.size_24')) .onClick(() => { this.send(); }) @@ -307,7 +322,7 @@ export default struct FaceAuth { Divider() .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { @@ -330,30 +345,30 @@ export default struct FaceAuth { .height($r('app.float.btn_height')) .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) } - if (this.flagN === 2) { + if (this.dialogTypeFlag === PIN_FACE_FINGER && this.screenType === SCREEN_PORTRAIT) { if (!this.isLandscape) { // The first form of facial fingerprint password Flex({ justifyContent: FlexAlign.SpaceBetween }) { Image($r('app.media.ic_public_cancel')) .id('cancelImgAllFaceAuth') - .width($r('app.float.digitalpsd_passwdmask_height')) - .height($r('app.float.digitalpsd_passwdmask_height')) + .width($r('app.float.digital_password_mask_height')) + .height($r('app.float.digital_password_mask_height')) .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - left: $r('app.float.digitalpsd_passwdmask_height') + top: $r('app.float.digital_password_mask_height'), + left: $r('app.float.digital_password_mask_height') }) .onClick(() => { - globalThis.session?.terminateSelf?.(); this.textValue = ''; + globalThis.session?.terminateSelf?.(); }) Button($r('app.string.unified_authwidget_usepwd')) .id('usePwdBtnAllFaceAuth') .backgroundColor(Color.White) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .padding(0) .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - right: $r('app.float.digitalpsd_passwdmask_height') + top: $r('app.float.digital_password_mask_height'), + right: $r('app.float.digital_password_mask_height') }) .fontColor($r('sys.color.ohos_id_color_activated')) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -365,6 +380,7 @@ export default struct FaceAuth { } Image($r('app.media.error_faceID')) + .id('imgAllFaceAuth') .width($r('app.float.image_small')) .height($r('app.float.image_small')) .margin({ top: $r('app.float.content_padding'), bottom: $r('app.float.content_padding') }) @@ -381,6 +397,7 @@ export default struct FaceAuth { Text(this.prompt) .id('resetPromptTextAllFaceAuth') .margin({ top: $r('app.float.element_margin') }) + .height($r('app.float.size_24')) .fontSize($r('sys.float.ohos_id_text_size_body2')) .fontColor(this.onFontColor(this.prompt, globalThis.context)) .onClick(() => { @@ -390,11 +407,12 @@ export default struct FaceAuth { }) Image($r('app.media.ic_blue_fingerprint')) .id('blueFingerprintImgAllFaceAuth') - .width($r('app.float.image_medium')) - .height($r('app.float.image_medium')) + // radius + .width(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) + .height(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - bottom: $r('app.float.digitalpsd_passwdmask_height') + top: $r('app.float.digital_password_mask_height'), + bottom: $r('app.float.digital_password_mask_height') }) .onClick(() => { if (this.prompt !== globalThis.context.resourceManager @@ -404,7 +422,7 @@ export default struct FaceAuth { }) } } - if (this.flagN === 3) { + if (this.dialogTypeFlag === PIN_FACE_FINGER && this.screenType === SCREEN_LAND) { // Facial fingerprint password, second form Image($r('app.media.error_faceID')) .id('errFaceImgFaceAuth') @@ -417,8 +435,9 @@ export default struct FaceAuth { Image($r('app.media.ic_blue_fingerprint')) .id('blueFingerprintImgFaceAuth') - .width($r('app.float.image_medium')) - .height($r('app.float.image_medium')) + // radius + .width(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) + .height(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) .margin({ top: $r('app.float.content_padding') }) .onClick(() => { AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); @@ -426,6 +445,7 @@ export default struct FaceAuth { Text(this.prompt) .margin({ top: $r('app.float.content_padding') }) .fontSize($r('sys.float.ohos_id_text_size_body2')) + .height($r('app.float.size_24')) .fontColor(this.onFontColor(this.prompt, globalThis.context)) Row() { Column() { @@ -446,7 +466,7 @@ export default struct FaceAuth { Divider() .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { @@ -469,10 +489,10 @@ export default struct FaceAuth { .height($r('app.float.btn_height')) .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) } - if (this.flagN === 4) { + if (this.dialogTypeFlag === MULTI_PIN) { // Password 32-bit Column() { - Pwd({ + PassWord({ textValue: $textValue, inputValue: $inputValue, isEdit: $isEdit, @@ -490,14 +510,14 @@ export default struct FaceAuth { .fontWeight(FontWeight.Medium) .backgroundColor(Color.Transparent) .onClick(() => { - globalThis.session?.terminateSelf?.(); this.textValue = ''; + globalThis.session?.terminateSelf?.(); }) }.width(Constants.halfContainerWidth) Divider() .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { @@ -520,10 +540,10 @@ export default struct FaceAuth { } } - if (this.flagN === 5) { + if (this.dialogTypeFlag === SIX_PIN) { // Password 6-bit Column() { - SixPwd({ + SixPassword({ textValue: $textValue, inputValue: $inputValue, isEdit: $isEdit @@ -543,9 +563,10 @@ export default struct FaceAuth { .fontWeight(FontWeight.Medium) } } - if (this.flagN === 6) { + if (this.dialogTypeFlag === SINGLE_FACE) { // Single FACE Text(globalThis.wantParams.title) + .id('titleFaceAuth') .fontSize($r('sys.float.ohos_id_text_size_body1')) .margin({ top: $r('app.float.content_padding_top') }) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -553,9 +574,10 @@ export default struct FaceAuth { Image(this.prompt !== globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognize_success')) ? $r('app.media.error_faceID') : $r('app.media.right_faceID')) + .id('imageFaceAuth') .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - bottom: $r('app.float.digitalpsd_passwdmask_height') + top: $r('app.float.digital_password_mask_height'), + bottom: $r('app.float.digital_password_mask_height') }) .width($r('app.float.image_size')) .height($r('app.float.image_size')) @@ -563,7 +585,10 @@ export default struct FaceAuth { .onClick(() => { this.send(); }) - Text(this.prompt).fontSize($r('sys.float.ohos_id_text_size_body2')) + Text(this.prompt) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .id('textFaceAuth') + .height($r('app.float.size_24')) .fontColor(this.onFontColor(this.prompt, globalThis.context)) .onClick(() => { this.send(); @@ -605,7 +630,7 @@ export default struct FaceAuth { Divider() .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { @@ -627,10 +652,14 @@ export default struct FaceAuth { } } } - .position({ y: this.fingerPosition.udSensorCenterYInThousandth / this.screen[1] < 0.75 && !this.isLandscape - ? (px2vp(this.screen[1]) * this.fingerPosition.udSensorCenterYInThousandth / THOUSANDTH) - - px2vp(this.screen[1]) - 100 - px2vp(this.fingerPosition.udSensorRadiusInPx) - : NORMAL_POSITION }) + .position({ + y: this.fingerPosition.udSensorCenterYInThousandth / this.screen[1] < Constants.fingerSensorPositionLine && + !this.isLandscape + ? (px2vp(this.screen[1]) * this.fingerPosition.udSensorCenterYInThousandth / THOUSANDTH) + - px2vp(this.screen[1]) + + this.SYSTEM_NAVIGATION_BAR_HEIGHT - MARGIN_TOP - px2vp(this.fingerPosition.udSensorRadiusInPx) + : NORMAL_POSITION + }) .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) .margin({ diff --git a/entry/src/main/ets/pages/components/FingerprintAuth.ets b/entry/src/main/ets/pages/components/FingerprintAuth.ets index 5b8029d..959036a 100644 --- a/entry/src/main/ets/pages/components/FingerprintAuth.ets +++ b/entry/src/main/ets/pages/components/FingerprintAuth.ets @@ -15,9 +15,8 @@ import account_osAccount from '@ohos.account.osAccount'; import display from '@ohos.display'; -import screen from '@ohos.screen'; -import Pwd from '../../common/components/Pwd'; -import SixPwd from '../../common/components/SixPwd'; +import PassWord from '../../common/components/PassWord'; +import SixPassword from '../../common/components/SixPassword'; import { DialogType } from '../../common/module/DialogType'; import AuthUtils from '../../common/utils/AuthUtils'; import FuncUtils from '../../common/utils/FuncUtils'; @@ -31,6 +30,16 @@ let pinAuthManager; let pinData = ''; const THOUSANDTH = 1000; const NORMAL_POSITION = -260; +const OUT_SENSOR = -292 +const MARGIN_TOP = 66 +const OFF_SCREEN_FINGER = 3; +const SINGLE_FINGER = 1; +const PIN_FINGER = 2; +const SIX_PIN = 6; +const MULTI_PIN = 5; +const RADIUS = 2; +const PIN_FAIL_TIP = 3; +const AUTH_LOCK = 0; @Component export default struct FingerprintAuth { @@ -43,51 +52,39 @@ export default struct FingerprintAuth { @Link @Watch('onCmdDataChange') cmdData: Array; @State isEdit: boolean = true; @State inputValue: string = ''; - @State flag: boolean = true; @State state: number = 0; @State screenClass: object = {}; @State fingerPosition: FingerPosition = { - sensorType: '' + sensorType: '', + udSensorRadiusInPx: 60 } + @StorageLink('SYSTEM_NAVIGATION_BAR_HEIGHT') SYSTEM_NAVIGATION_BAR_HEIGHT: number = 0; @State screen: number[] = []; @Consume isLandscape: boolean; - queryScreenInfo(): void { - try { - screen.getAllScreens((err, data) => { - if (err.code) { - LogUtils.e(TAG, 'Failed to get all screens. Cause: ' + JSON.stringify(err)); - return; - } - this.screenClass = data[0]; - }); - } catch (exception) { - LogUtils.e(TAG, 'getAllScreens catch exception: ' + exception); - } - } - aboutToAppear(): void { AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); - if (this.cmdData && this.cmdData.length > 0) { - this.onCmdDataChange('first'); - } try { - LogUtils.i(TAG, 'aboutToAppear PINAuth start'); + if (this.cmdData && this.cmdData.length > 0) { + this.onCmdDataChange('first'); + } + LogUtils.info(TAG, 'aboutToAppear PINAuth'); pinAuthManager = new account_osAccount.PINAuth(); - LogUtils.i(TAG, 'aboutToAppear PINAuth new success: ' + pinData); pinAuthManager.registerInputer({ onGetData: (authSubType, callback) => { + LogUtils.info(TAG, 'aboutToAppear registerInputer onGetData'); let uint8PW = FuncUtils.getUint8PW(pinData); callback.onSetData(authSubType, uint8PW); } }); } catch (error) { - LogUtils.e(TAG, 'aboutToAppear PINAuth catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); } } aboutToDisappear(): void { - LogUtils.i(TAG, 'PINAuth unregisterInputer'); + LogUtils.info(TAG, 'PINAuth unregisterInputer'); pinAuthManager?.unregisterInputer?.(); } @@ -97,7 +94,7 @@ export default struct FingerprintAuth { onCmdDataChange(num?: string): void { this.cmdData.length > 0 && this.cmdData.map((item) => { - let stateNew = this.dialogType === DialogType.PIN_FINGER ? 2 : 1; + let stateNew = this.dialogType === DialogType.PIN_FINGER ? PIN_FINGER : SINGLE_FINGER; const { type,remainAttempts, lockoutDuration,sensorInfo } = item.payload; switch (type) { case Constants.noticeTypePin: @@ -108,34 +105,27 @@ export default struct FingerprintAuth { if (num === 'first') { this.inputValue = ''; } - if (remainAttempts < 3) { + if (remainAttempts < PIN_FAIL_TIP) { this.inputValue = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) + remainAttempts + globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_frequency')); } } - if (remainAttempts === 0 && lockoutDuration) { + if (remainAttempts === AUTH_LOCK && lockoutDuration) { this.countTime(lockoutDuration); this.isEdit = false; } break; - case Constants.noticeTypeFace: - if (remainAttempts) { - this.prompt = globalThis.context.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1')); - } - if (remainAttempts === 0) { - this.prompt = globalThis.context.resourceManager - .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden')); - } - break; case Constants.noticeTypeFinger: + if ([MULTI_PIN, SIX_PIN].includes(this.state)) { + return; + } if (sensorInfo && JSON.stringify(sensorInfo) !== '{}') { this.fingerPosition = JSON.parse(sensorInfo); switch (this.fingerPosition.sensorType) { case 'OUT_OF_SCREEN_SENSOR': { - stateNew = 3; + stateNew = OFF_SCREEN_FINGER; break; } } @@ -145,7 +135,7 @@ export default struct FingerprintAuth { if (remainAttempts) { this.prompt = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); - if (remainAttempts < 5) { + if (num !== 'first' && remainAttempts > AUTH_LOCK) { AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); } } @@ -153,18 +143,20 @@ export default struct FingerprintAuth { this.prompt = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp')); } - if (remainAttempts === 0) { + if (remainAttempts === AUTH_LOCK) { this.prompt = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); if (this.dialogType === DialogType.PIN_FINGER) { if (this.pinSubType !== Constants.pinSix) { - stateNew = 5; + stateNew = MULTI_PIN; } else { - stateNew = 6; + stateNew = SIX_PIN; } } } + break; default: + LogUtils.error(TAG, 'onCmdDataChange default'); break; } this.state = stateNew; @@ -172,9 +164,11 @@ export default struct FingerprintAuth { } countTime(freezingTime): void { - const TRY_AGAIN = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); + const TRY_AGAIN = globalThis.context.resourceManager + .getStringSync($r('app.string.unified_authwidget_postretry')); let promptText: string = ''; let freezingMillisecond = freezingTime; + // O: freezing FINISH if (freezingMillisecond > 0) { promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalThis.context); promptText = globalThis.context.resourceManager @@ -228,7 +222,7 @@ export default struct FingerprintAuth { span: { xs: 8, sm: 8, md: 4, lg: 4 }, }) { Column() { - if (this.state === 3) { + if (this.state === OFF_SCREEN_FINGER) { Text(globalThis.wantParams?.title) .margin({ top: $r('app.float.title_padding_top') }) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -240,51 +234,114 @@ export default struct FingerprintAuth { .margin({ top: $r('app.float.content_padding'), bottom: $r('app.float.content_padding') }) Text($r('app.string.unified_authwidget_hint_normal_fp_only')) - .fontColor($r('sys.color.ohos_id_color_primary')) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) .fontSize($r('sys.float.ohos_id_text_size_body2')) - Row() { - Column() { - Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) - .id('cancelBthState3FingerprintAuth') - .margin({ left: $r('app.float.content_padding') }) - .width(Constants.ninetyPercentWidth) - .height($r('app.float.btn_height')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) - .fontWeight(FontWeight.Medium) - .backgroundColor(Color.Transparent) - .onClick(() => { - globalThis.session?.terminateSelf?.(); - this.textValue = ''; - }) - }.width(Constants.halfContainerWidth) + if (this.dialogType === DialogType.PIN_FINGER) { + Row() { + Column() { + Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) + .id('cancelBthState3FingerprintAuth') + .margin({ left: $r('app.float.content_padding') }) + .width(Constants.ninetyPercentWidth) + .height($r('app.float.btn_height')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) + .fontWeight(FontWeight.Medium) + .backgroundColor(Color.Transparent) + .onClick(() => { + globalThis.session?.terminateSelf?.(); + this.textValue = ''; + }) + }.width(Constants.halfContainerWidth) - Divider() - .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) - .color($r('sys.color.ohos_id_color_list_separator')) - .width($r('app.float.divider_width')) - Column() { - Button($r('app.string.unified_authwidget_usepwd')) - .id('usePwdBtnState3FingerprintAuth') - .margin({ right: $r('app.float.content_padding') }) - .width(Constants.ninetyPercentWidth) - .height($r('app.float.btn_height')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) - .fontWeight(FontWeight.Medium) - .backgroundColor(Color.Transparent) - .onClick(() => { - this.inputValue = ' '; - this.state = 5; - }) - }.width(Constants.halfContainerWidth) + Divider() + .vertical(true) + .height($r('app.float.digital_password_mask_height')) + .color($r('sys.color.ohos_id_color_list_separator')) + .width($r('app.float.divider_width')) + Column() { + Button($r('app.string.unified_authwidget_usepwd')) + .id('usePwdBtnState3FingerprintAuth') + .margin({ right: $r('app.float.content_padding') }) + .width(Constants.ninetyPercentWidth) + .height($r('app.float.btn_height')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) + .fontWeight(FontWeight.Medium) + .backgroundColor(Color.Transparent) + .onClick(() => { + this.inputValue = ' '; + if (this.pinSubType !== Constants.pinSix) { + this.state = MULTI_PIN; + } else { + this.state = SIX_PIN; + } + }) + }.width(Constants.halfContainerWidth) + } + .height($r('app.float.btn_height')) + .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) + } else { + if (!globalThis.wantParams?.navigationButtonText) { + Row() { + Column() { + Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) + .id('cancelDefBtnState3FingerprintAuth') + .onClick(() => { + globalThis.session?.terminateSelf?.(); + }) + .backgroundColor(Color.Transparent) + .height($r('app.float.btn_height')) + .width(Constants.fullContainerHeight) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) + .fontWeight(FontWeight.Medium) + } + } + .height($r('app.float.btn_height')) + .padding({ left: $r('app.float.content_padding'), right: $r('app.float.content_padding') }) + .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) + } else { + Row() { + Column() { + Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) + .id('cancelBtnState3FingerprintAuth') + .margin({ left: $r('app.float.content_padding') }) + .width(Constants.ninetyPercentWidth) + .height($r('app.float.btn_height')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) + .fontWeight(FontWeight.Medium) + .backgroundColor(Color.Transparent) + .onClick(() => { + globalThis.session?.terminateSelf?.(); + }) + }.width(Constants.halfContainerWidth) + Divider() + .vertical(true) + .height($r('app.float.digital_password_mask_height')) + .color($r('sys.color.ohos_id_color_list_separator')) + .width($r('app.float.divider_width')) + Column() { + Button(globalThis.wantParams?.navigationButtonText) + .onClick(() => { + globalThis.session?.terminateSelf?.(); + }) + .margin({ right: $r('app.float.content_padding') }) + .width(Constants.ninetyPercentWidth) + .height($r('app.float.btn_height')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) + .fontWeight(FontWeight.Medium) + .backgroundColor(Color.Transparent) + }.width(Constants.halfContainerWidth) + } + .height($r('app.float.btn_height')) + .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) + } } - .height($r('app.float.btn_height')) - .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) - } - else if (this.state === 2) { + } else if (this.state === PIN_FINGER) { if (!this.isLandscape) { Text(globalThis.wantParams?.title) .margin({ top: $r('app.float.title_padding_top') }) @@ -295,12 +352,12 @@ export default struct FingerprintAuth { .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - bottom: $r('app.float.digitalpsd_passwdmask_height') + top: $r('app.float.digital_password_mask_height'), + bottom: $r('app.float.digital_password_mask_height') }) .id('blueFingerprintImgState2FingerprintAuth') - .width($r('app.float.image_size')) - .height($r('app.float.image_size')) + .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) + .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) .onClick(() => { if (this.prompt !== globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden'))) { @@ -329,7 +386,7 @@ export default struct FingerprintAuth { Divider() .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { @@ -345,9 +402,9 @@ export default struct FingerprintAuth { .onClick(() => { this.inputValue = ' '; if (this.pinSubType !== Constants.pinSix) { - this.state = 5; + this.state = MULTI_PIN; } else { - this.state = 6; + this.state = SIX_PIN; } }) }.width(Constants.halfContainerWidth) @@ -355,13 +412,10 @@ export default struct FingerprintAuth { .height($r('app.float.btn_height')) .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) } - } - - else if (this.state === 1) { + } else if (this.state === SINGLE_FINGER) { if (!this.isLandscape) { Text(globalThis.wantParams?.title) .margin({ top: $r('app.float.title_padding_top') }) - .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) .fontWeight(FontWeight.Medium) @@ -369,12 +423,12 @@ export default struct FingerprintAuth { .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - bottom: $r('app.float.digitalpsd_passwdmask_height') + top: $r('app.float.digital_password_mask_height'), + bottom: $r('app.float.digital_password_mask_height') }) .id('blueFingerprintState1FingerprintAuth') - .width(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) - .height(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) + .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) + .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) .onClick(() => { if (this.prompt !== globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden'))) { @@ -388,7 +442,7 @@ export default struct FingerprintAuth { Row() { Column() { Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) - .id('usePwdBtnState1FingerprintAuth') + .id('cancelDefBtnState1FingerprintAuth') .onClick(() => { globalThis.session?.terminateSelf?.(); }) @@ -422,7 +476,7 @@ export default struct FingerprintAuth { Divider() .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { @@ -443,57 +497,10 @@ export default struct FingerprintAuth { .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) } } - } - else if (this.state === 4) { - Flex({ justifyContent: FlexAlign.SpaceBetween }) { - Image($r('app.media.ic_public_cancel')) - .id('cancelState4FingerprintAuth') - .width($r('app.float.digitalpsd_passwdmask_height')) - .height($r('app.float.digitalpsd_passwdmask_height')) - .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - left: $r('app.float.digitalpsd_passwdmask_height') - }) - .onClick(() => { - globalThis.session?.terminateSelf?.(); - }) - Button($r('app.string.unified_authwidget_usepwd')) - .id('usePwdBtnState4FingerprintAuth') - .backgroundColor(Color.White) - .height($r('app.float.digitalpsd_passwdmask_height')) - .padding(0) - .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - right: $r('app.float.digitalpsd_passwdmask_height') - }) - .fontColor($r('sys.color.ohos_id_color_activated')) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontWeight(FontWeight.Medium) - .onClick(() => { - this.state = 5; - }) - } - - Text(globalThis.wantParams?.title) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .margin({ top: $r('app.float.digitalpsd_passwdmask_height') }) - Text($r('app.string.unified_authwidget_hint_inscreen_fp')) - .margin({ top: $r('app.float.element_margin') }) - .fontColor($r('sys.color.ohos_id_color_text_secondary')) - .fontSize($r('sys.float.ohos_id_text_size_body2')) - Image($r('app.media.ic_blue_fingerprint')) - .width($r('app.float.image_medium')) - .height($r('app.float.image_medium')) - .margin({ - top: $r('app.float.digitalpsd_passwdmask_height'), - bottom: $r('app.float.digitalpsd_passwdmask_height') - }) - } - else if (this.state === 5) { + } else if (this.state === MULTI_PIN) { // Password 32-bit Column() { - Pwd({ + PassWord({ textValue: $textValue, inputValue: $inputValue, isEdit: $isEdit, @@ -518,7 +525,7 @@ export default struct FingerprintAuth { Divider() .vertical(true) - .height($r('app.float.digitalpsd_passwdmask_height')) + .height($r('app.float.digital_password_mask_height')) .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { @@ -539,11 +546,10 @@ export default struct FingerprintAuth { .height($r('app.float.btn_height')) .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) } - } - else if (this.state === 6) { + } else if (this.state === SIX_PIN) { // Password 6-bit Column() { - SixPwd({ + SixPassword({ textValue: $textValue, inputValue: $inputValue, isEdit: $isEdit @@ -563,15 +569,15 @@ export default struct FingerprintAuth { .fontWeight(FontWeight.Medium) } } - } .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) .position({ y: (this.isLandscape || !this.fingerPosition.udSensorCenterYInThousandth) - ? NORMAL_POSITION + ? (this.state === OFF_SCREEN_FINGER + ? OUT_SENSOR - this.SYSTEM_NAVIGATION_BAR_HEIGHT : NORMAL_POSITION) : (px2vp(this.screen[1]) * this.fingerPosition.udSensorCenterYInThousandth / THOUSANDTH) - - px2vp(this.screen[1]) - 66 - px2vp(this.fingerPosition.udSensorRadiusInPx) + - px2vp(this.screen[1]) - MARGIN_TOP - px2vp(this.fingerPosition.udSensorRadiusInPx) }) .margin({ left: ($r('sys.float.ohos_id_dialog_margin_start')), diff --git a/entry/src/main/ets/pages/components/PasswordAuth.ets b/entry/src/main/ets/pages/components/PasswordAuth.ets index 33547b5..7d935b7 100644 --- a/entry/src/main/ets/pages/components/PasswordAuth.ets +++ b/entry/src/main/ets/pages/components/PasswordAuth.ets @@ -14,8 +14,8 @@ */ import account_osAccount from '@ohos.account.osAccount'; -import Pwd from '../../common/components/Pwd'; -import SixPwd from '../../common/components/SixPwd'; +import PassWord from '../../common/components/PassWord'; +import SixPassword from '../../common/components/SixPassword'; import AuthUtils from '../../common/utils/AuthUtils'; import FuncUtils from '../../common/utils/FuncUtils'; import LogUtils from '../../common/utils/LogUtils'; @@ -24,6 +24,8 @@ import Constants, { CmdType } from '../../common/vm/Constants'; const TAG = 'PasswordAuth'; const INTERVAL = 1000; +const BUTTON_OPACITY = 1; +const TEXT_LENGTH = 4; let pinAuthManager; let pinData = ''; @@ -53,6 +55,7 @@ export default struct PasswordAuth { if (num === 'first') { this.inputValue = ''; } + // pin auth Remaining number if (remainAttempts < 3) { this.inputValue = globalThis.context.resourceManager .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) @@ -61,6 +64,7 @@ export default struct PasswordAuth { } return; } + // pin auth Remaining number if (remainAttempts === 0 && lockoutDuration) { this.countTime(lockoutDuration); this.isEdit = false; @@ -75,26 +79,28 @@ export default struct PasswordAuth { } aboutToAppear(): void { - if (this.cmdData && this.cmdData.length > 0) { - this.onCmdDataChange('first'); - } - // register input try { - LogUtils.i(TAG, 'aboutToAppear PINAuth start'); + if (this.cmdData && this.cmdData.length > 0) { + this.onCmdDataChange('first'); + } + LogUtils.info(TAG, 'aboutToAppear PINAuth start'); pinAuthManager = new account_osAccount.PINAuth(); + // register input pinAuthManager.registerInputer({ onGetData: (authSubType, callback) => { + LogUtils.info(TAG, 'aboutToAppear registerInputer onGetData'); const uint8PW = FuncUtils.getUint8PW(pinData); callback.onSetData(authSubType, uint8PW); } }); } catch (error) { - LogUtils.e(TAG, 'aboutToAppear PINAuth catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); + globalThis.session?.terminateSelf?.(); } } aboutToDisappear(): void { - LogUtils.i(TAG, 'aboutToAppear pinAuthManager unregisterInputer'); + LogUtils.info(TAG, 'aboutToAppear pinAuthManager unregisterInputer'); pinAuthManager?.unregisterInputer?.(); } @@ -132,7 +138,7 @@ export default struct PasswordAuth { if (this.pinSubType !== Constants.pinSix) { // arbitrary input Column() { - Pwd({ + PassWord({ pinSubType: $pinSubType, textValue: $textValue, inputValue: $inputValue, @@ -164,13 +170,15 @@ export default struct PasswordAuth { .onClick(async () => { AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); }) - .enabled(this.textValue.length >= 4) + .enabled(this.textValue.length >= TEXT_LENGTH) .margin({ right: $r('app.float.content_padding') }) .width('90%') .height($r('app.float.btn_height')) .fontSize($r('sys.float.ohos_id_text_size_button1')) .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) - .opacity(this.textValue.length >= 4 ? 1 : $r('sys.float.ohos_fa_alpha_disabled')) + .opacity(this.textValue.length >= TEXT_LENGTH + ? BUTTON_OPACITY + : $r('sys.float.ohos_fa_alpha_disabled')) .fontWeight(FontWeight.Medium) .backgroundColor(Color.Transparent) .id('okBtn') @@ -182,7 +190,7 @@ export default struct PasswordAuth { } else { // six number Column() { - SixPwd({ + SixPassword({ textValue: $textValue, inputValue: $inputValue, isEdit: $isEdit diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 42607ef..39bdc98 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -26,28 +26,6 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntrance": "./ets/mainability/MainAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], "extensionAbilities": [ { "name": "userauthuiextensionability", diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json index 3c71296..060bfc8 100644 --- a/entry/src/main/resources/base/element/color.json +++ b/entry/src/main/resources/base/element/color.json @@ -3,6 +3,14 @@ { "name": "start_window_background", "value": "#FFFFFF" + }, + { + "name": "full_screen_background", + "value": "#0d0d0d" + }, + { + "name": "button_color", + "value": "#00FFFFFF" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json index a2b515d..5980ab5 100644 --- a/entry/src/main/resources/base/element/float.json +++ b/entry/src/main/resources/base/element/float.json @@ -21,7 +21,7 @@ "value": "0" }, { - "name": "lock_prompt_fontsize", + "name": "lock_prompt_font_size", "value": "32px" }, { @@ -29,7 +29,7 @@ "value": "0" }, { - "name": "batterysoc_fontsize", + "name": "batterysoc_font_size", "value": "36px" }, { @@ -45,7 +45,7 @@ "value": "72px" }, { - "name": "accounts_name_fontsize", + "name": "accounts_name_font_size", "value": "24px" }, { @@ -53,167 +53,167 @@ "value": "8px" }, { - "name": "digitalpsd_prompt_fontsize", + "name": "digital_password_prompt_font_size", "value": "32px" }, { - "name": "digitalpsd_prompt_margin_bottom", + "name": "digital_password_prompt_margin_bottom", "value": "48px" }, { - "name": "digitalpsd_prompt_width", + "name": "digital_password_prompt_width", "value": "800px" }, { - "name": "digitalpsd_prompt_height", + "name": "digital_password_prompt_height", "value": "72px" }, { - "name": "digitalpsd_passwdmask_width", + "name": "digital_password_mask_width", "value": "400px" }, { - "name": "digitalpsd_passwdmask_height", + "name": "digital_password_mask_height", "value": "24vp" }, { - "name": "digitalpsd_passwdmask_margin_bottom", + "name": "digital_password_mask_margin_bottom", "value": "128px" }, { - "name": "digitalpsd_input_area_height", + "name": "digital_password_input_area_height", "value": "200px" }, { - "name": "digitalpsd_row1_fontsize", + "name": "digital_password_row1_font_size", "value": "48px" }, { - "name": "digitalpsd_row2_fontsize", + "name": "digital_password_row2_font_size", "value": "24px" }, { - "name": "digitalpsd_row_height", + "name": "digital_password_row_height", "value": "200px" }, { - "name": "digitalpsd_key_area_height", + "name": "digital_password_key_area_height", "value": "800px" }, { - "name": "digitalpsd_key_area_margin_bottom", + "name": "digital_password_key_area_margin_bottom", "value": "64px" }, { - "name": "digitalpsd_key_area_margin_bottom_portrait", + "name": "digital_password_key_area_margin_bottom_portrait", "value": "128px" }, { - "name": "mixedpsd_prompt_fontsize", + "name": "mixed_password_prompt_font_size", "value": "32px" }, { - "name": "mixedpsd_prompt_text_fontsize", + "name": "mixed_password_prompt_text_font_size", "value": "32px" }, { - "name": "mixedpsd_prompt_margin_bottom", + "name": "mixed_password_prompt_margin_bottom", "value": "48px" }, { - "name": "mixedpsd_prompt_margin_top", + "name": "mixed_password_prompt_margin_top", "value": "0" }, { - "name": "mixedpsd_prompt_width", + "name": "mixed_password_prompt_width", "value": "800px" }, { - "name": "mixedpsd_prompt_height", + "name": "mixed_password_prompt_height", "value": "72px" }, { - "name": "mixedpsd_input_maxlen", + "name": "mixed_password_input_maxlen", "value": "30px" }, { - "name": "mixedpsd_input_width", + "name": "mixed_password_input_width", "value": "600px" }, { - "name": "mixedpsd_input_height", + "name": "mixed_password_input_height", "value": "72px" }, { - "name": "mixedpsd_input_margin_bottom", + "name": "mixed_password_input_margin_bottom", "value": "64px" }, { - "name": "custompsd_prompt_fontsize", + "name": "custom_password_prompt_font_size", "value": "32px" }, { - "name": "custompsd_prompt_margin_bottom", + "name": "custom_password_prompt_margin_bottom", "value": "48px" }, { - "name": "custompsd_prompt_width", + "name": "custom_password_prompt_width", "value": "800px" }, { - "name": "custompsd_prompt_height", + "name": "custom_password_prompt_height", "value": "72px" }, { - "name": "custompsd_input_width", + "name": "custom_password_input_width", "value": "600px" }, { - "name": "custompsd_input_width_portrait", + "name": "custom_password_input_width_portrait", "value": "700px" }, { - "name": "custompsd_input_height", + "name": "custom_password_input_height", "value": "72px" }, { - "name": "custompsd_input_radius", + "name": "custom_password_input_radius", "value": "36px" }, { - "name": "custompsd_input_margin_bottom", + "name": "custom_password_input_margin_bottom", "value": "90px" }, { - "name": "custompsd_passwdmask_margin_bottom", + "name": "custom_password_mask_margin_bottom", "value": "128px" }, { - "name": "custompsd_input_area_height", + "name": "custom_password_input_area_height", "value": "400px" }, { - "name": "custompsd_key_area_height", + "name": "custom_password_key_area_height", "value": "800px" }, { - "name": "custompsd_key_area_margin_bottom", + "name": "custom_password_key_area_margin_bottom", "value": "64px" }, { - "name": "custompsd_key_area_margin_bottom_portrait", + "name": "custom_password_key_area_margin_bottom_portrait", "value": "128px" }, { - "name": "custompsd_text_opacity", + "name": "custom_password_text_opacity", "value": "1px" }, { - "name": "custompsd_digitalpsd_ic_diameter", + "name": "custom_password_digital_password_ic_diameter", "value": "12vp" }, { - "name": "custompsd_button_height", + "name": "custom_password_button_height", "value": "36vp" }, { @@ -292,6 +292,10 @@ "name": "element_margin", "value": "8vp" }, + { + "name": "margin_16", + "value": "16vp" + }, { "name": "input_height", "value": "40vp" @@ -336,6 +340,10 @@ "name": "title_size", "value": "20vp" }, + { + "name": "size_24", + "value": "24vp" + }, { "name": "back_width", "value": "97vp" @@ -343,6 +351,50 @@ { "name": "back_padding", "value": "10vp" + }, + { + "name": "keyboard_key_high", + "value": "120vp" + }, + { + "name": "button_border_width", + "value": "6vp" + }, + { + "name": "cancel_margin_top", + "value": "2vp" + }, + { + "name": "margin_12", + "value": "12vp" + }, + { + "name": "margin_14", + "value": "14vp" + }, + { + "name": "text_high", + "value": "40vp" + }, + { + "name": "finger_high", + "value": "72vp" + }, + { + "name": "three_hundred_size", + "value": "300vp" + }, + { + "name": "padding_8", + "value": "8vp" + }, + { + "name": "padding_16", + "value": "16vp" + }, + { + "name": "margin_64", + "value": "64vp" } ] } \ No newline at end of file diff --git a/entry/src/ohosTest/ets/extensionability/UserAuthAbility.ts b/entry/src/ohosTest/ets/extensionability/UserAuthAbility.ts index 432b48d..dbfc99b 100644 --- a/entry/src/ohosTest/ets/extensionability/UserAuthAbility.ts +++ b/entry/src/ohosTest/ets/extensionability/UserAuthAbility.ts @@ -15,35 +15,52 @@ import LogUtils from '../../../main/ets/common/utils/LogUtils'; import UserAuthExtensionAbility from '@ohos.app.ability.UserAuthExtensionAbility'; +import WindowPrivacyUtils from '../../../main/ets/common/utils/WindowPrivacyUtils'; const TAG = 'UserAuthAbility'; +// The current interface only support string type +const TRANSPARENT_COLOR = '#00000000'; +const MASK_THIN_COLOR = '#33182431'; export default class UserAuthAbility extends UserAuthExtensionAbility { onCreate() { - LogUtils.i(TAG, 'UserAuthExtensionAbility onCreate context: ' + JSON.stringify(this.context)); + LogUtils.info(TAG, 'UserAuthExtensionAbility onCreate'); globalThis.context = this.context; } onForeground(): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onForeground'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onForeground'); } onBackground(): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onBackground'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onBackground'); + globalThis.session?.terminateSelf(); } onDestroy(): void | Promise { - LogUtils.i(TAG, 'UserAuthExtensionAbility onDestroy'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onDestroy'); } onSessionCreate(want, session): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onSessionCreate want: ' + JSON.stringify(want)); + LogUtils.info(TAG, 'UserAuthExtensionAbility onSessionCreate'); globalThis.wantParams = want?.parameters?.useriamCmdData; globalThis.session = session; - session.loadContent('pages/Index'); + session?.loadContent('pages/Index'); + try { + if (globalThis.wantParams?.windowModeType === 'DIALOG_BOX') { + session?.setWindowBackgroundColor(MASK_THIN_COLOR); + } else { + session?.setWindowBackgroundColor(TRANSPARENT_COLOR); + } + } catch (error) { + LogUtils.error(TAG, 'UserAuthExtensionAbility onSessionCreate error: ' + error?.code); + session?.terminateSelf(); + } + WindowPrivacyUtils.setWindowPrivacyMode(session, true); } onSessionDestroy(session): void { - LogUtils.i(TAG, 'UserAuthExtensionAbility onSessionDestroy'); + LogUtils.info(TAG, 'UserAuthExtensionAbility onSessionDestroy'); + WindowPrivacyUtils.setWindowPrivacyMode(session, false); } } diff --git a/entry/src/ohosTest/ets/test/List.test.ets b/entry/src/ohosTest/ets/test/List.test.ets index 1ac86e3..b4ec1da 100644 --- a/entry/src/ohosTest/ets/test/List.test.ets +++ b/entry/src/ohosTest/ets/test/List.test.ets @@ -13,48 +13,48 @@ * limitations under the License. */ -import funcUtilsTest from './jsunit/commonUtilsTest/FuncUtils.test'; -import constantsTest from './jsunit/constantsTest/Constants.test'; -import customPasswordTest from './jsunit/widgetTest/CustomPassword.test'; -import CustomPasswordFaceTest from './jsunit/widgetTest/CustomPasswordFace.test'; -import CustomPasswordFingerTest from './jsunit/widgetTest/CustomPasswordFinger.test'; -import faceAuthJsTest from './jsunit/widgetTest/FaceAuth.test'; -import FingerprintAuth from './jsunit/widgetTest/FingerprintAuth.test'; -import pageComTest from './jsunit/widgetTest/PageCom.test'; -import passwordAuthTest from './jsunit/widgetTest/PasswordAuth.test'; -import PasswordAuthTestSix from './jsunit/widgetTest/PasswordAuthSix.test'; -import CustomPasswordTest from './uitest/CustomPassword.test'; -import FaceAuthTest from './uitest/FaceAuth.test'; -import FingerprintAuthTest from './uitest/FingerprintAuth.test'; -import PasswordAuthTest from './uitest/PasswordAuth.test'; -import passwordAuthSixUiTest from './uitest/PasswordAuthSix.test'; -import PinFingerPrintTest from './uitest/PinFingerPrint.test'; +import ConstantsTest from './jsunit/Constants.test'; +import FuncUtilsTest from './jsunit/FuncUtils.test'; +import PageComTest from './jsunit/PageCom.test'; +import FindWindowExampleTest from './uitest/FindWindowExample.test'; +import PinNumberTest from './uitest/PinNumber.test'; +import CustomPinTest from './uitest/CustomPin.test'; +import CustomMixFailTest from './uitest/CustomMixFail.test'; +import CustomMixFailTimesTest from './uitest/CustomMixFailTimes.test'; +import CustomPasswordNumberTest from './uitest/CustomPasswordNumber.test'; +import PinTest from './uitest/Pin.test'; import PinFaceTest from './uitest/PinFace.test'; -import CustomPasswordNumber from './uitest/CustomPasswordNumber.test'; -import CustomPasswordAttrTest from './uitest/CustomPasswordAttr.test'; -import findWindowExampleTest from './uitest/FindWindowExample.test' -import IndexTest from './Index.test'; +import FaceTest from './uitest/Face.test'; +import FaceFailTimesTest from './uitest/FaceFailTimes.test'; +import FaceMixTimesAuthTest from './uitest/FaceMixAuth.test'; +import PinFaceFailTest from './uitest/PinFaceFail.test'; +import FaceMixFailAuthTest from './uitest/FaceMixFailAuth.test'; +import FaceFingerFailTest from './uitest/FaceFingerFail.test'; +import FingerTest from './uitest/finger.test'; +import PinFingerTest from './uitest/PinFinger.test'; +import FingerFailAuthTest from './uitest/FingerFailTimesAuth.test'; +import PinFingerFailTest from './uitest/PinFingerFail.test'; export default function testsuite() { - CustomPasswordTest(); - PasswordAuthTest(); - passwordAuthSixUiTest(); - FaceAuthTest(); - FingerprintAuthTest(); - funcUtilsTest(); - pageComTest(); - constantsTest(); - passwordAuthTest(); - PasswordAuthTestSix(); - faceAuthJsTest(); - FingerprintAuth(); - customPasswordTest(); - CustomPasswordFaceTest(); - CustomPasswordFingerTest(); - PinFingerPrintTest(); + PageComTest(); + FuncUtilsTest(); + ConstantsTest(); + FindWindowExampleTest(); + FingerTest(); + PinFingerTest(); + FingerFailAuthTest(); + PinFingerFailTest(); + PinNumberTest(); + CustomPinTest(); + CustomMixFailTest(); + CustomMixFailTimesTest(); + CustomPasswordNumberTest(); + FaceTest(); + FaceFailTimesTest(); + FaceMixTimesAuthTest(); + PinTest(); PinFaceTest(); - CustomPasswordNumber(); - CustomPasswordAttrTest(); - findWindowExampleTest(); - IndexTest(); + PinFaceFailTest(); + FaceMixFailAuthTest(); + FaceFingerFailTest(); } \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/jsunit/Constants.test.ets b/entry/src/ohosTest/ets/test/jsunit/Constants.test.ets new file mode 100644 index 0000000..ecd455b --- /dev/null +++ b/entry/src/ohosTest/ets/test/jsunit/Constants.test.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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, expect, it } from '@ohos/hypium'; +import Constants from '../../../../main/ets/common/vm/Constants'; + +export default function ConstantsTest() { + describe('ConstantsTest', function () { + it('constants_test', 0, function (done) { + expect(Constants.pinSix).assertEqual('PIN_SIX'); + expect(Constants.pinNumber).assertEqual('PIN_NUMBER'); + expect(Constants.pinMixed).assertEqual('PIN_MIXED'); + expect(Constants.userAuthWidgetMgrVersion).assertEqual(1); + expect(Constants.userAuthWidgetMgrSuccess).assertEqual(0); + expect(Constants.noticeVersion).assertEqual('1'); + expect(Constants.noticeTypePin).assertEqual('pin'); + expect(Constants.noticeTypeFace).assertEqual('face'); + expect(Constants.noticeTypeFinger).assertEqual('fingerprint'); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/jsunit/FuncUtils.test.ets b/entry/src/ohosTest/ets/test/jsunit/FuncUtils.test.ets new file mode 100644 index 0000000..e3c77a6 --- /dev/null +++ b/entry/src/ohosTest/ets/test/jsunit/FuncUtils.test.ets @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 userAuth from '@ohos.userIAM.userAuth'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import AuthUtils from '../../../../main/ets/common/utils/AuthUtils'; +import FuncUtils from '../../../../main/ets/common/utils/FuncUtils'; +import LogUtils from '../../../../main/ets/common/utils/LogUtils'; +import TimeUtils from '../../../../main/ets/common/utils/TimeUtils'; +import WindowPrivacyUtils from '../../../../main/ets/common/utils/WindowPrivacyUtils'; + +const TAG = 'FuncUtilsTest'; + +export default function FuncUtilsTest() { + describe('FuncUtilsTest', function () { + beforeAll(async function () { + let userAuthInstance = null; + const authParam = { + challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), + authType: [1], + authTrustLevel: 10000, + }; + const widgetParam = { + title: '', + windowMode: 1, + navigationButtonText: '', + }; + userAuthInstance = await userAuth.getUserAuthInstance(authParam, widgetParam); + userAuthInstance.on('result', { + callback: function (result) { + LogUtils.info(TAG, 'userAuthInstance callback result = ' + JSON.stringify(result)); + } + }); + userAuthInstance.start(); + }) + + it('getUint8PWFunc_test', 0, function (done) { + const data1 = FuncUtils.getUint8PW('111111'); + const data2 = FuncUtils.getUint8PW('11111111'); + FuncUtils.getWindowHeight(); + expect(data1).assertInstanceOf('Uint8Array'); + expect(data2).assertInstanceOf('Uint8Array'); + done(); + }) + + it('getDialogTypeFunc_test', 0, function (done) { + const data1 = FuncUtils.getDialogType([1]); + const data2 = FuncUtils.getDialogType([1, 2, 4]); + const data3 = FuncUtils.getDialogType([]); + const data4 = FuncUtils.getDialogType(null); + const data5 = FuncUtils.getDialogType(undefined); + const data6 = FuncUtils.getDialogType([1, 2]); + const data7 = FuncUtils.getDialogType([1, 4]); + const data8 = FuncUtils.getDialogType([2]); + const data9 = FuncUtils.getDialogType([4]); + expect(data1).assertEqual(1); + expect(data2).assertEqual(10); + expect(data3).assertEqual(1); + expect(data4).assertEqual(1); + expect(data5).assertEqual(1); + expect(data6).assertEqual(6); + expect(data7).assertEqual(7); + expect(data8).assertEqual(2); + expect(data9).assertEqual(3); + done(); + }) + + it('getWindowHeightFunc_test', 0, function (done) { + FuncUtils.getWindowHeight(); + done(); + }) + + it('sendNoticeFunc_test', 0, async function (done) { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', ['pin']); + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_START', ['pin']); + done(); + }) + + it('logFunc_test', 0, async function (done) { + LogUtils.debug(TAG, 'debug log test'); + LogUtils.info(TAG, 'info log test'); + LogUtils.warn(TAG, 'warning log test'); + LogUtils.error(TAG, 'error log test'); + LogUtils.fatal(TAG, 'fatal log test'); + done(); + }) + + it('getFreezingTimeNmFunc_test', 0, async function (done) { + TimeUtils.getFreezingTimeNm(10000, globalThis.context); + TimeUtils.getFreezingTimeNm(100000, globalThis.context); + done(); + }) + + it('setWindowPrivacyModeFunc_test', 0, async function (done) { + WindowPrivacyUtils.setWindowPrivacyMode(null, false); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/jsunit/PageCom.test.ets b/entry/src/ohosTest/ets/test/jsunit/PageCom.test.ets new file mode 100644 index 0000000..a5e6fc6 --- /dev/null +++ b/entry/src/ohosTest/ets/test/jsunit/PageCom.test.ets @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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, expect, it } from '@ohos/hypium'; +import userAuth from '@ohos.userIAM.userAuth'; +import LogUtils from '../../../../main/ets/common/utils/LogUtils'; + +const TAG = 'PageComTest'; + +export default function PageComTest() { + describe('PageComTest', function () { + it('clickEventOk_Input', 0, async function (done) { + let userAuthInstance = null; + const authParam = { + challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), + authType: [1, 2, 4], + authTrustLevel: 10000, + }; + const widgetParam = { + title: '使用密码验证', + windowMode: 1, + navigationButtonText: '确认', + }; + userAuthInstance = await userAuth.getUserAuthInstance(authParam, widgetParam); + userAuthInstance.on('result', { + callback: function (result) { + LogUtils.info(TAG, 'userAuthInstance onResult: ' + JSON.stringify(result)); + } + }); + expect(userAuthInstance).not().assertNull(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/CustomMixFail.test.ets b/entry/src/ohosTest/ets/test/uitest/CustomMixFail.test.ets new file mode 100644 index 0000000..856210d --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/CustomMixFail.test.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function CustomMixFailTest() { + describe('CustomMixFailTest', function () { + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 23333, "remainAttempts": 0, "type": "pin", "sensorInfo": "" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 10000, "remainAttempts": 0, "type": "face", "sensorInfo": "" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 110, + "remainAttempts": 0, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_MIXED", + "title": "", + "type": ["pin", "face", "fingerprint"], + "widgetContextId": 6711153399710207000, + "windowModeType": "FULLSCREEN" + }; + globalThis.wantParams = data; + + let want = { + bundleName: bundleName, + abilityName: 'CustomMixFailAbility' + } + await delegator.startAbility(want); + }) + + it('pinInput_full_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('pinInput')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/CustomMixFailTimes.test.ets b/entry/src/ohosTest/ets/test/uitest/CustomMixFailTimes.test.ets new file mode 100644 index 0000000..5ee10c5 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/CustomMixFailTimes.test.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function CustomMixFailTimesTest() { + describe('CustomMixFailTimes', function () { + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 2, "type": "pin", "sensorInfo": "" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 1, "type": "face", "sensorInfo": "" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, + "remainAttempts": 2, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_MIXED", + "title": "", + "type": ["pin", "face", "fingerprint"], + "widgetContextId": 6711153399710207000, + "windowModeType": "FULLSCREEN" + }; + globalThis.wantParams = data; + + let want = { + bundleName: bundleName, + abilityName: 'CustomMixFailTimesAbility' + } + await delegator.startAbility(want); + }) + + it('pinInput_full_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('pinInput')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/CustomPasswordFingerTimes.test.ets b/entry/src/ohosTest/ets/test/uitest/CustomPasswordFingerTimes.test.ets new file mode 100644 index 0000000..93d74ca --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/CustomPasswordFingerTimes.test.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function CustomPasswordFingerTimesTest() { + describe('CustomPasswordFingerTimesTest', function () { + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 2, "type": "pin", "sensorInfo": "" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 1, "type": "face", "sensorInfo": "" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, + "remainAttempts": 1, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_MIXED", + "title": "", + "type": ["pin", "face", "fingerprint"], + "widgetContextId": 6711153399710207000, + "windowModeType": "FULLSCREEN" + }; + globalThis.wantParams = data; + + let want = { + bundleName: bundleName, + abilityName: 'FingerprintAbility' + } + await delegator.startAbility(want); + }) + + it('pinInput_full_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('pinInput')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/CustomPasswordNumber.test.ets b/entry/src/ohosTest/ets/test/uitest/CustomPasswordNumber.test.ets index d50572b..a869b6c 100644 --- a/entry/src/ohosTest/ets/test/uitest/CustomPasswordNumber.test.ets +++ b/entry/src/ohosTest/ets/test/uitest/CustomPasswordNumber.test.ets @@ -15,12 +15,31 @@ import { Driver, ON } from '@ohos.UiTest'; import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import userAuth from '@ohos.userIAM.userAuth'; -const delays: number = 1000; +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -export default function CustomPasswordNumber() { - describe('CustomPasswordNumber', function () { +const delayTime: number = 1000; + +export default function CustomPasswordNumberTest() { + describe('CustomPasswordNumberTest', function () { beforeAll(async function () { + let userAuthInstance = null; + const authParam = { + challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), + authType: [1], + authTrustLevel: 10000, + }; + const widgetParam = { + title: '使用密码验证', + windowMode: 2, + navigationButtonText: '确认', + }; + userAuthInstance = await userAuth.getUserAuthInstance(authParam, widgetParam); + userAuthInstance.start(); + const data = { "cmd": [{ "event": "CMD_NOTIFY_AUTH_START", "payload": { @@ -31,14 +50,242 @@ export default function CustomPasswordNumber() { "title": "", "type": ["pin"], "widgetContextId": 7932856209793250000, - "windowModeType": "DIALOG_BOX", + "windowModeType": "FULLSCREEN", }; globalThis.wantParams = data; + + let want = { + bundleName: bundleName, + abilityName: 'CustomPwdNumberAbility' + } + await delegator.startAbility(want); + }) + + it('numKeyBord0_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('numKeyBordCustomPwd0')); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord1_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd1')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord2_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd2')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord3_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd3')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord4_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd4')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord5_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd5')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord6_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd6')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord7_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd7')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord8_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd8')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord10_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd10')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord9_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd9')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('numKeyBord11_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('numKeyBordCustomPwd11')); + await btn.click(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord0_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('textNumKeyBordCustomPwd0')); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord1_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd1')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('teNtnumKeyBord2_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd2')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord3_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd3')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord4_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd4')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord5_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd5')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord6_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd6')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord7_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd7')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord8_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd8')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord10_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd10')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord9_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd9')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textNumKeyBord11_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + const btn = await driver.findComponent(ON.id('textNumKeyBordCustomPwd11')); + await btn.getType(); + expect(true).assertTrue(); + done(); + }) + + it('textPrompt_customPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelIconCustomPwd')); + expect(true).assertTrue(); + done(); }) it('clickEventCancal_Input', 0, async function (done) { let driver = Driver.create(); - await driver.delayMs(delays); + await driver.delayMs(delayTime); await driver.findComponent(ON.id('pinSix')); expect(true).assertTrue(); done(); diff --git a/entry/src/ohosTest/ets/test/uitest/CustomPin.test.ets b/entry/src/ohosTest/ets/test/uitest/CustomPin.test.ets new file mode 100644 index 0000000..b061254 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/CustomPin.test.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function CustomPinTest() { + describe('CustomPinTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 5, "type": "pin", "sensorInfo": "" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "请输入密码", + "type": ["pin"], + "widgetContextId": 6711153399710207000, + "windowModeType": "FULLSCREEN" + }; + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'CustomPwdAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('title_full_screen_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('titleFullScreen')); + expect(true).assertTrue(); + done(); + }) + + it('cancelImgCustomPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelImgCustomPwd')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/Face.test.ets b/entry/src/ohosTest/ets/test/uitest/Face.test.ets new file mode 100644 index 0000000..2c5a6eb --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/Face.test.ets @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import userAuth from '@ohos.userIAM.userAuth'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FaceTest() { + describe('FaceTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + let userAuthInstance = null; + const authParam = { + challenge: new Uint8Array([49, 49, 49, 49, 49, 49]), + authType: [2], + authTrustLevel: 10000, + }; + const widgetParam = { + title: '使用人脸验证', + windowMode: 1, + navigationButtonText: '确认', + }; + userAuthInstance = await userAuth.getUserAuthInstance(authParam, widgetParam); + userAuthInstance.start(); + + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 5, "type": "face" + }, "version": "1" + }], + "pinSubType": "", + "title": "", + "type": ["face"], + "widgetContextId": 13808827370146417000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('title_faceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('titleFaceAuth')); + expect(true).assertTrue(); + done(); + }) + + it('image_faceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('imageFaceAuth')); + expect(true).assertTrue(); + done(); + }) + + it('text_faceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('textFaceAuth')); + expect(true).assertTrue(); + done(); + }) + + it('cancelBtn_allFace_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelBtnAllFace')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/FaceFailTimes.test.ets b/entry/src/ohosTest/ets/test/uitest/FaceFailTimes.test.ets new file mode 100644 index 0000000..b985f13 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/FaceFailTimes.test.ets @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FaceFailTimesTest() { + describe('FaceFailTimesTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 1, "type": "face" + }, "version": "1" + }], + "pinSubType": "", + "title": "", + "type": ["face"], + "widgetContextId": 13808827370146417000, + "windowModeType": "DIALOG_BOX", + "navigationButtonText": "确定!" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceFailTimesAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('navigationBtnFace_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('navigationBtnFace')); + expect(true).assertTrue(); + done(); + }) + + it('imageFaceAuth_fail_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('textFaceAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/FaceFingerFail.test.ets b/entry/src/ohosTest/ets/test/uitest/FaceFingerFail.test.ets new file mode 100644 index 0000000..bbdf9fa --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/FaceFingerFail.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FaceFingerFailTest() { + describe('FaceFingerFailTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 555, "remainAttempts": 0, "type": "face" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 5555, + "remainAttempts": 0, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "", + "title": "", + "type": ["face", "fingerprint"], + "widgetContextId": 7728484037972500000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceMixSuccess3Ability' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelImg_allFaceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelImgAllFaceAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/FaceMixAuth.test.ets b/entry/src/ohosTest/ets/test/uitest/FaceMixAuth.test.ets new file mode 100644 index 0000000..fdadfd8 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/FaceMixAuth.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FaceMixTimesAuthTest() { + describe('FaceMixTimesAuthTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 2, "type": "face" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, + "remainAttempts": 2, + "sensorInfo": "{\"sensorType\":\"NON_SENSOR22\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":100,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["face", "fingerprint"], + "widgetContextId": 7728484037972500000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceMixAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelImg_allFaceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelImgAllFaceAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/FaceMixFailAuth.test.ets b/entry/src/ohosTest/ets/test/uitest/FaceMixFailAuth.test.ets new file mode 100644 index 0000000..441ab72 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/FaceMixFailAuth.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FaceMixFailAuthTest() { + describe('FaceMixFailAuthTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 555, "remainAttempts": 0, "type": "face" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 5555, + "remainAttempts": 0, + "sensorInfo": "{\"sensorType\":\"OUT_OF_SCREEN_SENSOR\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["face", "fingerprint"], + "widgetContextId": 7728484037972500000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceMixSuccess3Ability' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelImg_allFaceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelImgAllFaceAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/FaceMixSuccessAuth3.test.ets b/entry/src/ohosTest/ets/test/uitest/FaceMixSuccessAuth3.test.ets new file mode 100644 index 0000000..c9392e3 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/FaceMixSuccessAuth3.test.ets @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function PinFaceFingerTest() { + describe('PinFaceFingerTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 0, "type": "pin" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 5, "type": "face" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, + "remainAttempts": 5, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["pin", "face", "fingerprint"], + "widgetContextId": 7728484037972500000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceMixSuccess3Ability' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelImg_allFaceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelImgAllFaceAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/FindWindowExample.test.ets b/entry/src/ohosTest/ets/test/uitest/FindWindowExample.test.ets index 6c2e412..815f573 100644 --- a/entry/src/ohosTest/ets/test/uitest/FindWindowExample.test.ets +++ b/entry/src/ohosTest/ets/test/uitest/FindWindowExample.test.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import { describe, expect, it, TestType } from '@ohos/hypium' -import { Driver } from '@ohos.UiTest' +import { describe, expect, it, TestType } from '@ohos/hypium'; +import { Driver } from '@ohos.UiTest'; import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; const delegator = abilityDelegatorRegistry.getAbilityDelegator(); @@ -22,21 +22,21 @@ const bundleName = abilityDelegatorRegistry.getArguments().bundleName; const delays = 1000; -export default function findWindowExampleTest() { - describe('findWindowExampleTest', function () { +export default function FindWindowExampleTest() { + describe('FindWindowExampleTest', function () { it('findWindowExampleTest_bundleName', TestType.FUNCTION, async function (done) { let want = { bundleName: bundleName, - abilityName: "EntryAbility" + abilityName: "TestAbility" } await delegator.startAbility(want); - let driver = Driver.create() - await driver.delayMs(delays) + let driver = Driver.create(); + await driver.delayMs(delays); await driver.findWindow({ bundleName: bundleName - }) + }); expect(true).assertTrue(); - done() + done(); }) }) } \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/Finger.test.ets b/entry/src/ohosTest/ets/test/uitest/Finger.test.ets new file mode 100644 index 0000000..a984032 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/Finger.test.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FingerTest() { + describe('FingerTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, + "remainAttempts": 5, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "", + "title": "", + "type": ["fingerprint"], + "widgetContextId": 10234972519197798000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FingerprintAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelBth_state3_fingerprintAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelBthState3FingerprintAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/FingerFailTimesAuth.test.ets b/entry/src/ohosTest/ets/test/uitest/FingerFailTimesAuth.test.ets new file mode 100644 index 0000000..31586a4 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/FingerFailTimesAuth.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FingerFailAuthTest() { + describe('FingerFailAuthTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 2, "type": "pin" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, + "remainAttempts": 2, + "sensorInfo": "{\"sensorType\":\"OUT_OF_SCREEN_SENSOR\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["pin", "fingerprint"], + "widgetContextId": 10234972519197798000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FingerFailTimesAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelBth_state3_fingerprintAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelBthState3FingerprintAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/Pin.test.ets b/entry/src/ohosTest/ets/test/uitest/Pin.test.ets new file mode 100644 index 0000000..04972a6 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/Pin.test.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function PinTest() { + describe('PinTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 1123, "remainAttempts": 0, "type": "pin" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["pin"], + "widgetContextId": 17202660292065450000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: "PasswordSixAbility" + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('pinSix_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('pinSix')); + expect(true).assertTrue(); + done(); + }) + + it('cancelBtn_dialog_sixPwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelBtnDialogSixPwd')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/PinFace.test.ets b/entry/src/ohosTest/ets/test/uitest/PinFace.test.ets index bc4fcfa..b36b4d9 100644 --- a/entry/src/ohosTest/ets/test/uitest/PinFace.test.ets +++ b/entry/src/ohosTest/ets/test/uitest/PinFace.test.ets @@ -13,42 +13,54 @@ * limitations under the License. */ -import { BY, Driver, ON } from '@ohos.UiTest'; +import { Driver, ON } from '@ohos.UiTest'; import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -const delays: number = 1000 +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; export default function PinFaceTest() { describe('PinFaceTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + beforeAll(async function () { const data = { "cmd": [{ "event": "CMD_NOTIFY_AUTH_START", "payload": { - "lockoutDuration": 0, "remainAttempts": 5, "type": "pin", "sensorInfo": "" + "lockoutDuration": 0, "remainAttempts": 5, "type": "pin" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 5, "type": "face" }, "version": "1" }], - "pinSubType": "PIN_MIXED", - "title": "", - "type": ["pin"], - "widgetContextId": 7932856209793250000, + "pinSubType": "PIN_NUMBER", + "title": "口令人脸", + "type": ["pin", "face"], + "widgetContextId": 13808827370146417000, "windowModeType": "DIALOG_BOX" - }; + } globalThis.wantParams = data; - }) + sleep(1000); - it('clickEventCancal_face', 0, async function (done) { - let driver = Driver.create(); - await driver.delayMs(delays); - await driver.findComponent(ON.clickable(true)); - expect(true).assertTrue(); - done(); + let want = { + bundleName: bundleName, + abilityName: 'FaceSingleAbility' + } + await delegator.startAbility(want); + sleep(1000); }) - - it('clickEventError_face', 0, async function (done) { + it('title_pinFace_test', 0, async function (done) { let driver = Driver.create(); - await driver.delayMs(delays); - await driver.findComponent(ON.id('cancelBtnDialogSixPwd')); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('titlePinFace')); expect(true).assertTrue(); done(); }) diff --git a/entry/src/ohosTest/ets/test/uitest/PinFaceFail.test.ets b/entry/src/ohosTest/ets/test/uitest/PinFaceFail.test.ets new file mode 100644 index 0000000..2074dde --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/PinFaceFail.test.ets @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function PinFaceFailTest() { + describe('PinFaceFailTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 2147483647, "remainAttempts": 0, "type": "pin" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 2147483647, "remainAttempts": 0, "type": "face" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["pin", "face"], + "widgetContextId": 7728484037972500000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceMixSuccessAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelImg_allFaceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelImgAllFaceAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/PinFaceFinger.test.ets b/entry/src/ohosTest/ets/test/uitest/PinFaceFinger.test.ets new file mode 100644 index 0000000..33136d6 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/PinFaceFinger.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function FaceFingerFailTest() { + describe('FaceFingerFailTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 1111111, "remainAttempts": 0, "type": "face" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 111110, + "remainAttempts": 0, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["face", "fingerprint"], + "widgetContextId": 7728484037972500000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FaceMixTimesAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelImg_allFaceAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelImgAllFaceAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/PinFinger.test.ets b/entry/src/ohosTest/ets/test/uitest/PinFinger.test.ets new file mode 100644 index 0000000..494691e --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/PinFinger.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function PinFingerTest() { + describe('PinFingerTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 5, "type": "pin" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, + "remainAttempts": 5, + "sensorInfo": "{\"OUT_OF_SCREEN_SENSOR\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["pin", "fingerprint"], + "widgetContextId": 10234972519197798000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FingerprintAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelBth_state3_fingerprintAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelBthState3FingerprintAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/PinFingerFail.test.ets b/entry/src/ohosTest/ets/test/uitest/PinFingerFail.test.ets new file mode 100644 index 0000000..ea82ca2 --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/PinFingerFail.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function PinFingerFailTest() { + describe('PinFingerFailTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 34343, "remainAttempts": 0, "type": "pin" + }, "version": "1" + }, { + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 2343, + "remainAttempts": 0, + "sensorInfo": "{\"sensorType\":\"SensorType1\",\"udSensorCenterXInThousandth\":500,\"udSensorCenterYInThousandth\":500,\"udSensorRadiusInPx\":30}", + "type": "fingerprint" + }, "version": "1" + }], + "pinSubType": "PIN_SIX", + "title": "", + "type": ["pin", "fingerprint"], + "widgetContextId": 10234972519197798000, + "windowModeType": "DIALOG_BOX" + } + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: 'FingerFailAbility' + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('cancelBth_state3_fingerprintAuth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelBthState3FingerprintAuth')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/uitest/PinNumber.test.ets b/entry/src/ohosTest/ets/test/uitest/PinNumber.test.ets new file mode 100644 index 0000000..72c0e4c --- /dev/null +++ b/entry/src/ohosTest/ets/test/uitest/PinNumber.test.ets @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT 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 { Driver, ON } from '@ohos.UiTest'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +const delayTime: number = 1000; + +export default function PinNumberTest() { + describe('PinNumberTest', function () { + + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(async function () { + const data = { + "cmd": [{ + "event": "CMD_NOTIFY_AUTH_START", "payload": { + "lockoutDuration": 0, "remainAttempts": 5, "type": "pin", "sensorInfo": "" + }, "version": "1" + }], + "pinSubType": "PIN_NUMBER", + "title": "使用密码验证", + "type": ["pin"], + "widgetContextId": 7932856209793250000, + "windowModeType": "DIALOG_BOX" + }; + globalThis.wantParams = data; + sleep(1000); + + let want = { + bundleName: bundleName, + abilityName: "PasswordAbility" + } + await delegator.startAbility(want); + sleep(1000); + }) + + it('title_pwd_auth_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('titlePwdAuth')); + expect(true).assertTrue(); + done(); + }) + + it('input_dialog_pwd_fail_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('pinInputMix')); + expect(true).assertTrue(); + done(); + }) + + it('input_dialog_pwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('pinInputMix')); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('okBtn')); + expect(true).assertTrue(); + done(); + }) + + it('cancelBtn_dialog_pwd_test', 0, async function (done) { + let driver = Driver.create(); + await driver.delayMs(delayTime); + await driver.findComponent(ON.id('cancelBtnDialogPwd')); + expect(true).assertTrue(); + done(); + }) + }) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/testability/CustomMixFailAbility.ets b/entry/src/ohosTest/ets/testability/CustomMixFailAbility.ets new file mode 100644 index 0000000..86f99f9 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/CustomMixFailAbility.ets @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class CustomMixFailAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onDestroy() { + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/CustomMixFailTimesAbility.ets b/entry/src/ohosTest/ets/testability/CustomMixFailTimesAbility.ets new file mode 100644 index 0000000..61d9f5a --- /dev/null +++ b/entry/src/ohosTest/ets/testability/CustomMixFailTimesAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class CustomMixFailTimesAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/CustomPwdAbility.ets b/entry/src/ohosTest/ets/testability/CustomPwdAbility.ets new file mode 100644 index 0000000..904a6e0 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/CustomPwdAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class CustomPwdAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/CustomPwdNumberAbility.ets b/entry/src/ohosTest/ets/testability/CustomPwdNumberAbility.ets new file mode 100644 index 0000000..3dea1fa --- /dev/null +++ b/entry/src/ohosTest/ets/testability/CustomPwdNumberAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class CustomPwdNumberAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FaceAbility.ets b/entry/src/ohosTest/ets/testability/FaceAbility.ets new file mode 100644 index 0000000..b8cec36 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FaceAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FaceAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FaceFailTimesAbility.ets b/entry/src/ohosTest/ets/testability/FaceFailTimesAbility.ets new file mode 100644 index 0000000..3270b3e --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FaceFailTimesAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FaceFailTimesAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FaceMixAbility.ets b/entry/src/ohosTest/ets/testability/FaceMixAbility.ets new file mode 100644 index 0000000..9875a84 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FaceMixAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FaceMixAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FaceMixSuccess3Ability.ets b/entry/src/ohosTest/ets/testability/FaceMixSuccess3Ability.ets new file mode 100644 index 0000000..33e2467 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FaceMixSuccess3Ability.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FaceMixSuccess3Ability extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FaceMixSuccessAbility.ets b/entry/src/ohosTest/ets/testability/FaceMixSuccessAbility.ets new file mode 100644 index 0000000..daa5ff2 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FaceMixSuccessAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FaceMixSuccessAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FaceMixTimesAbility.ets b/entry/src/ohosTest/ets/testability/FaceMixTimesAbility.ets new file mode 100644 index 0000000..087fe94 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FaceMixTimesAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FaceMixTimesAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FaceSingleAbility.ets b/entry/src/ohosTest/ets/testability/FaceSingleAbility.ets new file mode 100644 index 0000000..a09d5ec --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FaceSingleAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FaceSingleAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FingerFailAbility.ets b/entry/src/ohosTest/ets/testability/FingerFailAbility.ets new file mode 100644 index 0000000..f938987 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FingerFailAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FingerFailAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FingerFailTimesAbility.ets b/entry/src/ohosTest/ets/testability/FingerFailTimesAbility.ets new file mode 100644 index 0000000..078c510 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FingerFailTimesAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FingerFailTimesAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/FingerprintAbility.ets b/entry/src/ohosTest/ets/testability/FingerprintAbility.ets new file mode 100644 index 0000000..7017563 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/FingerprintAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class FingerprintAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/PasswordAbility.ets b/entry/src/ohosTest/ets/testability/PasswordAbility.ets new file mode 100644 index 0000000..f1c222c --- /dev/null +++ b/entry/src/ohosTest/ets/testability/PasswordAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class PasswordAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/PasswordSixAbility.ets b/entry/src/ohosTest/ets/testability/PasswordSixAbility.ets new file mode 100644 index 0000000..d28abf9 --- /dev/null +++ b/entry/src/ohosTest/ets/testability/PasswordSixAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License") +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class PasswordSixAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.context = this.context; + globalThis.session = {}; + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } +} diff --git a/entry/src/ohosTest/ets/testability/TestAbility.ets b/entry/src/ohosTest/ets/testability/TestAbility.ets index 1696475..adcbc97 100644 --- a/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -15,51 +15,26 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; import UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; import window from '@ohos.window'; import { Hypium } from '@ohos/hypium'; import testsuite from '../test/List.test'; export default class TestAbility extends UIAbility { onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); - hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); - hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); var abilityDelegator: any; abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); var abilityDelegatorArguments: any; abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); globalThis.context = this.context; globalThis.session = {}; } - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); - } - onWindowStageCreate(windowStage: window.WindowStage) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); windowStage.loadContent('testability/pages/Index', (err, data) => { 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. Data: %{public}s', - JSON.stringify(data) ?? ''); }); } - - onWindowStageDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); - } - - onForeground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); - } - - onBackground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); - } } \ No newline at end of file diff --git a/entry/src/ohosTest/ets/testability/pages/Index.ets b/entry/src/ohosTest/ets/testability/pages/Index.ets index b9de311..15ab0a0 100644 --- a/entry/src/ohosTest/ets/testability/pages/Index.ets +++ b/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -38,34 +38,32 @@ struct Index { @State pinSubType: string = Constants.pinNumber; @State dialogType: DialogType = DialogType.ALL; @State windowModeType: string = 'DIALOG_BOX'; - // background 1:white 2:Gaussian Blur - @State themeType: number = 1; @State cmdData: Array = []; @Provide isLandscape: boolean = false; @Provide underFingerPrint: boolean = false; onCancel(): void { - LogUtils.d(TAG, 'Callback when the first button is clicked'); + LogUtils.debug(TAG, 'Callback when the first button is clicked'); globalThis.session?.terminateSelf(); } onAccept(): void { - LogUtils.d(TAG, 'Callback when the second button is clicked'); + LogUtils.debug(TAG, 'Callback when the second button is clicked'); } existApp(): void { - LogUtils.d(TAG, 'Click the callback in the blank area'); + LogUtils.debug(TAG, 'Click the callback in the blank area'); globalThis.session?.terminateSelf(); } handleAuthStart(): void { try { userAuthWidgetMgr = userAuth.getUserAuthWidgetMgr(Constants.userAuthWidgetMgrVersion); - LogUtils.i(TAG, 'getUserAuthWidgetMgr success'); + LogUtils.info(TAG, 'getUserAuthWidgetMgr success'); let that = this; userAuthWidgetMgr.on('command', { callback: function (result) { - LogUtils.i(TAG, 'userAuthWidgetMgr onCommand result: ' + JSON.stringify(result)); + LogUtils.info(TAG, 'userAuthWidgetMgr onCommand result: ' + JSON.stringify(result)); const cmdDataObj = JSON.parse(result?.cmdData || '{}'); if (cmdDataObj?.cmd?.[0]?.payload?.result === Constants.userAuthWidgetMgrSuccess) { that.onCancel(); @@ -76,48 +74,46 @@ struct Index { } }); } catch (error) { - LogUtils.e(TAG, 'getUserAuthWidgetMgr catch error: ' + JSON.stringify(error)); + LogUtils.error(TAG, 'getUserAuthWidgetMgr catch error: ' + error?.code); } } aboutToAppear(): void { - LogUtils.d(TAG, 'aboutToAppear'); + LogUtils.debug(TAG, 'aboutToAppear test'); if (globalThis.wantParams) { + LogUtils.debug(TAG, 'globalThis.wantParams: ' + JSON.stringify(globalThis.wantParams)); this.getParams(globalThis.wantParams); - this.handleAuthStart(); - this.cmdData = globalThis.wantParams?.cmd; - LogUtils.d(TAG, 'globalThis.wantParams: ' + JSON.stringify(globalThis.wantParams)); } else { - LogUtils.e(TAG, 'aboutToAppear wantParams null'); + LogUtils.error(TAG, 'aboutToAppear wantParams null'); } this.getWindowHeight(); } aboutToDisappear(): void { - LogUtils.i(TAG, 'aboutToDisappear'); + LogUtils.info(TAG, 'aboutToDisappear'); if (userAuthWidgetMgr) { userAuthWidgetMgr.off('command', { callback: function (result) { - LogUtils.i(TAG, 'aboutToDisappear userAuthWidgetMgr offCommand result: ' + JSON.stringify(result)); + LogUtils.info(TAG, 'aboutToDisappear userAuthWidgetMgr offCommand result: ' + JSON.stringify(result)); } }); } } onPageShow(): void { - LogUtils.i(TAG, 'onPageShow'); + LogUtils.info(TAG, 'onPageShow'); } onPageHide(): void { - LogUtils.i(TAG, 'onPageHide'); + LogUtils.info(TAG, 'onPageHide'); } onBackPress(): void { - LogUtils.i(TAG, 'onBackPress'); + LogUtils.info(TAG, 'onBackPress'); } getParams(result): void { - LogUtils.i(TAG, 'getParams'); + LogUtils.info(TAG, 'getParams'); const { pinSubType, windowModeType, cmd, type, widgetContextId } = result; this.pinSubType = pinSubType; const newType = type && type.map(item => { @@ -139,10 +135,10 @@ struct Index { } getWindowHeight(): void { - LogUtils.i(TAG, 'getWindowHeight'); + LogUtils.info(TAG, 'getWindowHeight'); try { window.on('systemBarTintChange', (data) => { - LogUtils.d(TAG, 'Succeeded in enabling the listener for window stage event changes. Data: ' + + LogUtils.debug(TAG, 'Succeeded in enabling the listener for window stage event changes. Data: ' + JSON.stringify(data)); for (let i = 0; i < data.regionTint.length; i++) { let regionData = data.regionTint[i]; @@ -156,9 +152,8 @@ struct Index { } } }); - } catch (exception) { - LogUtils.e(TAG, 'Failed to enable the listener for window stage event changes. Cause:' + - JSON.stringify(exception)); + } catch (error) { + LogUtils.error(TAG, 'Failed to enable the listener for window stage event changes. error: ' + error?.code); } } @@ -189,7 +184,6 @@ struct Index { } else { // full screen PIN CustomPassword({ - themeType: $themeType, authType: $authType, pinSubType: $pinSubType, cmdData: $cmdData diff --git a/entry/src/ohosTest/module.json5 b/entry/src/ohosTest/module.json5 index 4d80a0c..fb14eba 100644 --- a/entry/src/ohosTest/module.json5 +++ b/entry/src/ohosTest/module.json5 @@ -18,7 +18,7 @@ "name": "entry_test", "type": "feature", "description": "$string:module_test_desc", - "mainElement": "userauthuiextensionability", + "mainElement": "TestAbility", "deviceTypes": [ "default", "tablet" @@ -46,6 +46,166 @@ ] } ] + }, + { + "name": "PasswordAbility", + "srcEntrance": "./ets/testability/PasswordAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "PasswordSixAbility", + "srcEntrance": "./ets/testability/PasswordSixAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "CustomPwdAbility", + "srcEntrance": "./ets/testability/CustomPwdAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "CustomPwdNumberAbility", + "srcEntrance": "./ets/testability/CustomPwdNumberAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "CustomMixFailAbility", + "srcEntrance": "./ets/testability/CustomMixFailAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "CustomMixFailTimesAbility", + "srcEntrance": "./ets/testability/CustomMixFailTimesAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FaceAbility", + "srcEntrance": "./ets/testability/FaceAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FaceFailTimesAbility", + "srcEntrance": "./ets/testability/FaceFailTimesAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FaceMixAbility", + "srcEntrance": "./ets/testability/FaceMixAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FaceMixSuccess3Ability", + "srcEntrance": "./ets/testability/FaceMixSuccess3Ability.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FaceMixSuccessAbility", + "srcEntrance": "./ets/testability/FaceMixSuccessAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FaceMixTimesAbility", + "srcEntrance": "./ets/testability/FaceMixTimesAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FaceSingleAbility", + "srcEntrance": "./ets/testability/FaceSingleAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FingerprintAbility", + "srcEntrance": "./ets/testability/FingerprintAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FingerFailAbility", + "srcEntrance": "./ets/testability/FingerFailAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + }, + { + "name": "FingerFailTimesAbility", + "srcEntrance": "./ets/testability/FingerFailTimesAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", } ], "extensionAbilities": [ diff --git a/entry/src/ohosTest/resources/base/element/color.json b/entry/src/ohosTest/resources/base/element/color.json index 3c71296..060bfc8 100644 --- a/entry/src/ohosTest/resources/base/element/color.json +++ b/entry/src/ohosTest/resources/base/element/color.json @@ -3,6 +3,14 @@ { "name": "start_window_background", "value": "#FFFFFF" + }, + { + "name": "full_screen_background", + "value": "#0d0d0d" + }, + { + "name": "button_color", + "value": "#00FFFFFF" } ] } \ No newline at end of file diff --git a/entry/src/ohosTest/resources/base/element/float.json b/entry/src/ohosTest/resources/base/element/float.json index a2b515d..5980ab5 100644 --- a/entry/src/ohosTest/resources/base/element/float.json +++ b/entry/src/ohosTest/resources/base/element/float.json @@ -21,7 +21,7 @@ "value": "0" }, { - "name": "lock_prompt_fontsize", + "name": "lock_prompt_font_size", "value": "32px" }, { @@ -29,7 +29,7 @@ "value": "0" }, { - "name": "batterysoc_fontsize", + "name": "batterysoc_font_size", "value": "36px" }, { @@ -45,7 +45,7 @@ "value": "72px" }, { - "name": "accounts_name_fontsize", + "name": "accounts_name_font_size", "value": "24px" }, { @@ -53,167 +53,167 @@ "value": "8px" }, { - "name": "digitalpsd_prompt_fontsize", + "name": "digital_password_prompt_font_size", "value": "32px" }, { - "name": "digitalpsd_prompt_margin_bottom", + "name": "digital_password_prompt_margin_bottom", "value": "48px" }, { - "name": "digitalpsd_prompt_width", + "name": "digital_password_prompt_width", "value": "800px" }, { - "name": "digitalpsd_prompt_height", + "name": "digital_password_prompt_height", "value": "72px" }, { - "name": "digitalpsd_passwdmask_width", + "name": "digital_password_mask_width", "value": "400px" }, { - "name": "digitalpsd_passwdmask_height", + "name": "digital_password_mask_height", "value": "24vp" }, { - "name": "digitalpsd_passwdmask_margin_bottom", + "name": "digital_password_mask_margin_bottom", "value": "128px" }, { - "name": "digitalpsd_input_area_height", + "name": "digital_password_input_area_height", "value": "200px" }, { - "name": "digitalpsd_row1_fontsize", + "name": "digital_password_row1_font_size", "value": "48px" }, { - "name": "digitalpsd_row2_fontsize", + "name": "digital_password_row2_font_size", "value": "24px" }, { - "name": "digitalpsd_row_height", + "name": "digital_password_row_height", "value": "200px" }, { - "name": "digitalpsd_key_area_height", + "name": "digital_password_key_area_height", "value": "800px" }, { - "name": "digitalpsd_key_area_margin_bottom", + "name": "digital_password_key_area_margin_bottom", "value": "64px" }, { - "name": "digitalpsd_key_area_margin_bottom_portrait", + "name": "digital_password_key_area_margin_bottom_portrait", "value": "128px" }, { - "name": "mixedpsd_prompt_fontsize", + "name": "mixed_password_prompt_font_size", "value": "32px" }, { - "name": "mixedpsd_prompt_text_fontsize", + "name": "mixed_password_prompt_text_font_size", "value": "32px" }, { - "name": "mixedpsd_prompt_margin_bottom", + "name": "mixed_password_prompt_margin_bottom", "value": "48px" }, { - "name": "mixedpsd_prompt_margin_top", + "name": "mixed_password_prompt_margin_top", "value": "0" }, { - "name": "mixedpsd_prompt_width", + "name": "mixed_password_prompt_width", "value": "800px" }, { - "name": "mixedpsd_prompt_height", + "name": "mixed_password_prompt_height", "value": "72px" }, { - "name": "mixedpsd_input_maxlen", + "name": "mixed_password_input_maxlen", "value": "30px" }, { - "name": "mixedpsd_input_width", + "name": "mixed_password_input_width", "value": "600px" }, { - "name": "mixedpsd_input_height", + "name": "mixed_password_input_height", "value": "72px" }, { - "name": "mixedpsd_input_margin_bottom", + "name": "mixed_password_input_margin_bottom", "value": "64px" }, { - "name": "custompsd_prompt_fontsize", + "name": "custom_password_prompt_font_size", "value": "32px" }, { - "name": "custompsd_prompt_margin_bottom", + "name": "custom_password_prompt_margin_bottom", "value": "48px" }, { - "name": "custompsd_prompt_width", + "name": "custom_password_prompt_width", "value": "800px" }, { - "name": "custompsd_prompt_height", + "name": "custom_password_prompt_height", "value": "72px" }, { - "name": "custompsd_input_width", + "name": "custom_password_input_width", "value": "600px" }, { - "name": "custompsd_input_width_portrait", + "name": "custom_password_input_width_portrait", "value": "700px" }, { - "name": "custompsd_input_height", + "name": "custom_password_input_height", "value": "72px" }, { - "name": "custompsd_input_radius", + "name": "custom_password_input_radius", "value": "36px" }, { - "name": "custompsd_input_margin_bottom", + "name": "custom_password_input_margin_bottom", "value": "90px" }, { - "name": "custompsd_passwdmask_margin_bottom", + "name": "custom_password_mask_margin_bottom", "value": "128px" }, { - "name": "custompsd_input_area_height", + "name": "custom_password_input_area_height", "value": "400px" }, { - "name": "custompsd_key_area_height", + "name": "custom_password_key_area_height", "value": "800px" }, { - "name": "custompsd_key_area_margin_bottom", + "name": "custom_password_key_area_margin_bottom", "value": "64px" }, { - "name": "custompsd_key_area_margin_bottom_portrait", + "name": "custom_password_key_area_margin_bottom_portrait", "value": "128px" }, { - "name": "custompsd_text_opacity", + "name": "custom_password_text_opacity", "value": "1px" }, { - "name": "custompsd_digitalpsd_ic_diameter", + "name": "custom_password_digital_password_ic_diameter", "value": "12vp" }, { - "name": "custompsd_button_height", + "name": "custom_password_button_height", "value": "36vp" }, { @@ -292,6 +292,10 @@ "name": "element_margin", "value": "8vp" }, + { + "name": "margin_16", + "value": "16vp" + }, { "name": "input_height", "value": "40vp" @@ -336,6 +340,10 @@ "name": "title_size", "value": "20vp" }, + { + "name": "size_24", + "value": "24vp" + }, { "name": "back_width", "value": "97vp" @@ -343,6 +351,50 @@ { "name": "back_padding", "value": "10vp" + }, + { + "name": "keyboard_key_high", + "value": "120vp" + }, + { + "name": "button_border_width", + "value": "6vp" + }, + { + "name": "cancel_margin_top", + "value": "2vp" + }, + { + "name": "margin_12", + "value": "12vp" + }, + { + "name": "margin_14", + "value": "14vp" + }, + { + "name": "text_high", + "value": "40vp" + }, + { + "name": "finger_high", + "value": "72vp" + }, + { + "name": "three_hundred_size", + "value": "300vp" + }, + { + "name": "padding_8", + "value": "8vp" + }, + { + "name": "padding_16", + "value": "16vp" + }, + { + "name": "margin_64", + "value": "64vp" } ] } \ No newline at end of file diff --git a/entry/src/ohosTest/resources/base/element/string.json b/entry/src/ohosTest/resources/base/element/string.json index 9e9700f..220be93 100644 --- a/entry/src/ohosTest/resources/base/element/string.json +++ b/entry/src/ohosTest/resources/base/element/string.json @@ -1,17 +1,5 @@ { "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - }, { "name": "module_desc", "value": "module description" -- Gitee From d8d976dacc0e4057e950bd053980b36fa9253958 Mon Sep 17 00:00:00 2001 From: dengjiewen Date: Mon, 17 Jul 2023 16:10:36 +0800 Subject: [PATCH 2/2] change bundle.json subsystem Signed-off-by: dengjiewen --- bundle.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index a3e2177..b2423ed 100644 --- a/bundle.json +++ b/bundle.json @@ -11,7 +11,7 @@ "scripts": {}, "component": { "name": "auth_widget", - "subsystem": "useriam", + "subsystem": "applications", "syscap": [ "SystemCapability.UserIAM.UserAuth.Core" ], -- Gitee