From 27294206fc13550a7ea9246ce53281696f6da0bd Mon Sep 17 00:00:00 2001 From: abonadon_hk Date: Mon, 7 Jul 2025 21:05:59 +0800 Subject: [PATCH 1/2] fix : fix codecheck Signed-off-by: abonadon_hk --- .../main/ets/common/components/FullScreen.ets | 223 +++++++------- .../main/ets/pages/components/FaceAuth.ets | 272 ++++++++++-------- .../ets/pages/components/FingerprintAuth.ets | 172 +++++------ 3 files changed, 353 insertions(+), 314 deletions(-) diff --git a/entry/src/main/ets/common/components/FullScreen.ets b/entry/src/main/ets/common/components/FullScreen.ets index 0ddb895..2c89e08 100644 --- a/entry/src/main/ets/common/components/FullScreen.ets +++ b/entry/src/main/ets/common/components/FullScreen.ets @@ -102,122 +102,133 @@ export default struct FullScreen { this.cmdData.length > 0 && this.cmdData.map((item) => { const payload: CmdData = item.payload; if (payload.type === Constants.noticeTypePin) { - this.clearPassword(); - if (payload.remainAttempts) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); - if (num === 'first' && this.prompt !== (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_recognition').id)) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_use_pwd').id); - } - // 3: pin Residual number - if (payload.remainAttempts < 3 && num !== 'first') { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + - payload.remainAttempts + (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_frequency').id); - } - } - if (payload.remainAttempts === 0 && payload.lockoutDuration) { - // 1: pin lock - this.pinLock = 1; - this.countdown(payload.lockoutDuration); - } - - if (!payload.remainAttempts && !payload.lockoutDuration) { - // 1: pin lock - this.pinLock = 1; - } - if (payload.result === 0) { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); - } + this.processPinCmdData(payload); } else if (payload.type === Constants.noticeTypeFace) { - if (payload.remainAttempts < 5 && payload.remainAttempts > 0) { - if (this.pinLock !== 1) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id); - this.faceFingerLockArr[0] = false; - } - } - if (num === 'first') { - if (payload.remainAttempts === 0) { - this.controlType.isShowFace = false; - } else { - if (this.pinLock !== 1) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); - } - } - } - if (payload.remainAttempts === 0) { - if (num !== 'first') { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden').id); - } - this.faceFingerLockArr[0] = true; - } - if (payload.result === 0) { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); - } + this.processFaceCmdData(payload); } else if (payload.type === Constants.noticeTypeFinger) { - let sensor: FingerPosition = { sensorType: '' }; - if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { - sensor = JSON.parse(payload.sensorInfo); - this.fingerPosition = sensor || { sensorType: '' }; + this.processFingerprintCmdData(payload); + } else { + LogUtils.error(TAG, 'type: ' + payload.type); + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + } + }) + } + + private processPinCmdData(payload: CmdData): void { + this.clearPassword(); + if (payload.remainAttempts) { + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); + if (num === 'first' && this.prompt !== (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognition').id)) { + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_use_pwd').id); + } + // 3: pin Residual number + if (payload.remainAttempts < 3 && num !== 'first') { + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + + payload.remainAttempts + (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_frequency').id); + } + } + if (payload.remainAttempts === 0 && payload.lockoutDuration) { + // 1: pin lock + this.pinLock = 1; + this.countdown(payload.lockoutDuration); + } + + if (!payload.remainAttempts && !payload.lockoutDuration) { + // 1: pin lock + this.pinLock = 1; + } + if (payload.result === 0) { + (AppStorage.get("session") as UIExtensionContentSession)?.terminateSelf(); + } + } + + private processFaceCmdData(payload: CmdData): void { + if (payload.remainAttempts < 5 && payload.remainAttempts > 0) { + if (this.pinLock !== 1) { + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id); + this.faceFingerLockArr[0] = false; + } + } + if (num === 'first') { + if (payload.remainAttempts === 0) { + this.controlType.isShowFace = false; + } else { + if (this.pinLock !== 1) { + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); } - if (payload.remainAttempts && payload.result !== 0) { - if (this.controlType.jumpFinger) { - this.fingerText = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + } + } + if (payload.remainAttempts === 0) { + if (num !== 'first') { + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden').id); + } + this.faceFingerLockArr[0] = true; + } + if (payload.result === 0) { + (AppStorage.get("session") as UIExtensionContentSession)?.terminateSelf(); + } + } + + private processFingerprintCmdData(payload: CmdData): void { + let sensor: FingerPosition = { sensorType: '' }; + if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { + sensor = JSON.parse(payload.sensorInfo); + this.fingerPosition = sensor || { sensorType: '' }; + } + if (payload.remainAttempts && payload.result !== 0) { + if (this.controlType.jumpFinger) { + this.fingerText = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); + } + if (sensor && this.fingerPosition.udSensorCenterYInThousandth !== undefined && + this.fingerPosition.udSensorRadiusInPx !== undefined) { + if (sensor.sensorType === 'UNDER_SCREEN_SENSOR' || + sensor.sensorType === 'BOTH_SENSOR' || + sensor.sensorType === 'SensorType1') { + if (num !== 'first' && payload.remainAttempts > 0 && payload.result != 0) { + setTimeout(() => { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); + }, NOTICE_DELAY); + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); } - if (sensor && this.fingerPosition.udSensorCenterYInThousandth !== undefined && - this.fingerPosition.udSensorRadiusInPx !== undefined) { - if (sensor.sensorType === 'UNDER_SCREEN_SENSOR' || - sensor.sensorType === 'BOTH_SENSOR' || - sensor.sensorType === 'SensorType1') { - if (num !== 'first' && payload.remainAttempts > 0 && payload.result != 0) { - setTimeout(() => { - AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); - }, NOTICE_DELAY); - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); - } - this.fingerButtonPositionY = - px2vp(this.fingerPosition.udSensorCenterYInThousandth / THOUSANDTH * this.screen[1]); - FuncUtils.judgmentOverflow(this.fingerButtonPositionY); - this.fingerPositionY = this.fingerButtonPositionY - this.SYSTEM_STATUS_BAR_HEIGHT - - this.SYSTEM_STATUS_BAR_HEIGHT - px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - PADDING_8; - this.fingerPositionLine = this.fingerPositionY / px2vp(this.screen[1]); - FuncUtils.judgmentOverflow(this.fingerPositionLine); - if (num === 'first' && this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && payload.result != 0) { - AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); - } - } - } - } - if (payload.remainAttempts === 0) { - if (num === 'first') { - this.controlType.isShowFinger = false; - } else { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); - this.fingerText = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); + this.fingerButtonPositionY = px2vp(this.fingerPosition.udSensorCenterYInThousandth / THOUSANDTH * this.screen[1]); + FuncUtils.judgmentOverflow(this.fingerButtonPositionY); + this.fingerPositionY = this.fingerButtonPositionY - this.SYSTEM_STATUS_BAR_HEIGHT + - this.SYSTEM_STATUS_BAR_HEIGHT - px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - PADDING_8; + this.fingerPositionLine = this.fingerPositionY / px2vp(this.screen[1]); + FuncUtils.judgmentOverflow(this.fingerPositionLine); + if (num === 'first' && this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && payload.result != 0) { + AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); } - this.faceFingerLockArr[1] = true; - this.controlType.jumpFinger = false; - this.cancelImage = false; - } - if (payload.result === 0) { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); } + } + } + if (payload.remainAttempts === 0) { + if (num === 'first') { + this.controlType.isShowFinger = false; } else { - LogUtils.error(TAG, 'type: ' + payload.type); - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); + this.fingerText = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); } - }) + this.faceFingerLockArr[1] = true; + this.controlType.jumpFinger = false; + this.cancelImage = false; + } + if (payload.result === 0) { + (AppStorage.get("session") as UIExtensionContentSession)?.terminateSelf(); + } } aboutToAppear(): void { diff --git a/entry/src/main/ets/pages/components/FaceAuth.ets b/entry/src/main/ets/pages/components/FaceAuth.ets index 743dcc1..a347ebc 100644 --- a/entry/src/main/ets/pages/components/FaceAuth.ets +++ b/entry/src/main/ets/pages/components/FaceAuth.ets @@ -193,15 +193,23 @@ export default struct FaceAuth { pinData = this.textValue; } - onFontColor(prompt: string, context: Context): Resource { - if (prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id) || + private getWarningResource(prompt: string, context: Context): boolean { + return prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id) || prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id) || prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden').id) || - prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id)) { - return $r('sys.color.ohos_id_color_warning'); - } else if (prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_recognition').id) || + prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id) + } + + private getTextSecondaryResource(prompt: string, context: Context): boolean { + return prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_recognition').id) || prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_recognize_success').id) || - prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp').id)) { + prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp').id) + } + + onFontColor(prompt: string, context: Context): Resource { + if (this.getWarningResource(prompt, context)) { + return $r('sys.color.ohos_id_color_warning'); + } else if (this.getTextSecondaryResource(prompt, context)) { return $r('sys.color.ohos_id_color_text_secondary'); } else { return $r('sys.color.ohos_id_color_text_secondary'); @@ -212,138 +220,150 @@ export default struct FaceAuth { this.cmdData.length > 0 && this.cmdData.map(async (item) => { const payload: CmdData = item.payload; if (payload.type === Constants.noticeTypePin) { - if (payload.result === 0) { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); - } else if (payload.result && payload.result === Constants.authResultPinExpired) { - this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); - this.textValue = ''; - return; - } else { - if (payload.remainAttempts) { - this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); - this.textValue = ''; - if (num === 'first') { - this.inputValue = ''; - } - if (payload.remainAttempts < HINT_TIMES_BY_FAIL_LESS) { - this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + - payload.remainAttempts + (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_frequency').id); - } - } - if (payload.remainAttempts === 0 && payload.lockoutDuration) { - this.countTime(payload.lockoutDuration); - this.textValue = ''; - this.toPin(); - this.isEdit = false; - } - } + this.processPinCmdData(payload, num); } else if (payload.type === Constants.noticeTypeFace) { - if ([SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { - return; - } - if (payload.result && payload.result === Constants.authResultPinExpired) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id); - this.faceLock = false; - return; - } - if (payload.remainAttempts && payload.result !== 0) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id); - this.faceLock = false; - } + this.processFaceCmdData(payload, num); + } else if (payload.type === Constants.noticeTypeFinger) { + this.processFingerCmdData(payload, num); + } else { + LogUtils.error(TAG, 'onCmdDataChange default'); + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + } + }) + } + + private processPinCmdData(payload: CmdData, num?: string): void { + if (payload.result === 0) { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + } else if (payload.result && payload.result === Constants.authResultPinExpired) { + this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); + this.textValue = ''; + return; + } else { + if (payload.remainAttempts) { + this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); + this.textValue = ''; if (num === 'first') { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); + this.inputValue = ''; } - if (payload.remainAttempts === 0) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden').id); - this.faceLock = true; - if (this.dialogType === DialogType.ALL) { - if (this.fingerLock) { - this.toPin(); - } - } else { - this.toPin(); - } + if (payload.remainAttempts < HINT_TIMES_BY_FAIL_LESS) { + this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + + payload.remainAttempts + (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_frequency').id); } - if (payload.result === 0) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_recognize_success').id) - setTimeout(() => { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); - }, SECOND); + } + if (payload.remainAttempts === 0 && payload.lockoutDuration) { + this.countTime(payload.lockoutDuration); + this.textValue = ''; + this.toPin(); + this.isEdit = false; + } + } + } + + private processFaceCmdData(payload: CmdData, num?: string): void { + if ([SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { + return; + } + if (payload.result && payload.result === Constants.authResultPinExpired) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id); + this.faceLock = false; + return; + } + if (payload.remainAttempts && payload.result !== 0) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id); + this.faceLock = false; + } + if (num === 'first') { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); + } + if (payload.remainAttempts === 0) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden').id); + this.faceLock = true; + if (this.dialogType === DialogType.ALL) { + if (this.fingerLock) { + this.toPin(); } - } else if (payload.type === Constants.noticeTypeFinger) { - if ([SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { - return; + } else { + this.toPin(); + } + } + if (payload.result === 0) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_recognize_success').id) + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND); + } + } + + private processFingerCmdData(payload: CmdData, num?: string): void { + if ([SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { + return; + } + if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { + this.fingerPosition = JSON.parse(payload.sensorInfo); + const displayClass = display.getDefaultDisplaySync(); + this.screen = [displayClass.width, displayClass.height]; + switch (JSON.parse(payload.sensorInfo)?.sensorType as string) { + case 'NON_SENSOR': + case 'OUT_OF_SCREEN_SENSOR': { + this.dialogTypeFlag = PIN_FACE; + break; } - if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { - this.fingerPosition = JSON.parse(payload.sensorInfo); - const displayClass = display.getDefaultDisplaySync(); - this.screen = [displayClass.width, displayClass.height]; - switch (JSON.parse(payload.sensorInfo)?.sensorType as string) { - case 'NON_SENSOR': - case 'OUT_OF_SCREEN_SENSOR': { - this.dialogTypeFlag = PIN_FACE; - break; - } - default: - if (this.dialogType !== DialogType.FACE_FINGER_NAVIGATION) { - this.isPinFaceFinger = true; - } - let tempPositionLine = JSON.parse(payload.sensorInfo).udSensorCenterYInThousandth / displayClass.height; - FuncUtils.judgmentOverflow(tempPositionLine); - if (tempPositionLine < FINGER_SENSOR_POSITION_LINE) { - if (!this.IS_LANDSCAPE && ![SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { - this.screenType = SCREEN_LAND; - } - } else if (tempPositionLine > FINGER_SENSOR_POSITION_LINE) { - if (!this.IS_LANDSCAPE && ![SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { - this.screenType = SCREEN_PORTRAIT; - } - } - break; + default: + if (this.dialogType !== DialogType.FACE_FINGER_NAVIGATION) { + this.isPinFaceFinger = true; } - } - if ((payload.remainAttempts && payload.result !== 0) || payload.result === Constants.authResultPinExpired) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); - this.fingerLock = false; - } - if (num === 'first') { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_normal_fp_only').id); - } - if (payload.remainAttempts === 0) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); - this.fingerLock = true; - if (this.dialogType === DialogType.ALL) { - if (this.faceLock) { - this.toPin(); + let tempPositionLine = JSON.parse(payload.sensorInfo).udSensorCenterYInThousandth / displayClass.height; + FuncUtils.judgmentOverflow(tempPositionLine); + if (tempPositionLine < FINGER_SENSOR_POSITION_LINE) { + if (!this.IS_LANDSCAPE && ![SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { + this.screenType = SCREEN_LAND; + } + } else if (tempPositionLine > FINGER_SENSOR_POSITION_LINE) { + if (!this.IS_LANDSCAPE && ![SIX_PIN, MULTI_PIN].includes(this.dialogTypeFlag)) { + this.screenType = SCREEN_PORTRAIT; } - } else { - this.toPin(); } - } - if (payload.result === 0) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) - setTimeout(() => { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); - }, SECOND); + break; + } + } + if ((payload.remainAttempts && payload.result !== 0) || payload.result === Constants.authResultPinExpired) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); + this.fingerLock = false; + } + if (num === 'first') { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_normal_fp_only').id); + } + if (payload.remainAttempts === 0) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); + this.fingerLock = true; + if (this.dialogType === DialogType.ALL) { + if (this.faceLock) { + this.toPin(); } } else { - LogUtils.error(TAG, 'onCmdDataChange default'); - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + this.toPin(); } - }) + } + if (payload.result === 0) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND); + } } handleCancel(): void { diff --git a/entry/src/main/ets/pages/components/FingerprintAuth.ets b/entry/src/main/ets/pages/components/FingerprintAuth.ets index 489290d..a2e3f54 100644 --- a/entry/src/main/ets/pages/components/FingerprintAuth.ets +++ b/entry/src/main/ets/pages/components/FingerprintAuth.ets @@ -118,95 +118,103 @@ export default struct FingerprintAuth { this.cmdData.length > 0 && this.cmdData.map((item) => { const payload: CmdData = item.payload; if (payload.type === Constants.noticeTypePin) { - if (payload.result === 0) { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); - } else if (payload.result && payload.result === Constants.authResultPinExpired) { - this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); - this.textValue = ''; - return; - } else { - if (payload.remainAttempts) { - this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); - this.textValue = ''; - if (num === 'first') { - this.inputValue = ''; - } - if (payload.remainAttempts < PIN_FAIL_TIP) { - this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + - payload.remainAttempts + (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_frequency').id); - } - } - if (payload.remainAttempts === AUTH_LOCK && payload.lockoutDuration) { - this.countTime(payload.lockoutDuration); - this.textValue = ''; - this.toPin(); - this.isEdit = false; - } - } + this.processPinCmdData(payload, num); } else if (payload.type === Constants.noticeTypeFinger) { - if ([MULTI_PIN, SIX_PIN].includes(this.state)) { - return; - } - const displayClass = display.getDefaultDisplaySync(); - this.screen = [displayClass.width, displayClass.height]; - if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { - this.fingerPosition = JSON.parse(payload.sensorInfo); - switch (this.fingerPosition.sensorType) { - case 'OUT_OF_SCREEN_SENSOR': { - this.isOffFinger = true; - break; - } - default: - let tempPositionLine = JSON.parse(payload.sensorInfo).udSensorCenterYInThousandth / displayClass.height; - FuncUtils.judgmentOverflow(tempPositionLine); - if (tempPositionLine < FINGER_SENSOR_POSITION_LINE) { - this.screenType = ON_SCREEN; - } else if (tempPositionLine > FINGER_SENSOR_POSITION_LINE) { - this.screenType = UNDER_SCREEN; - } - break; - } + this.processFingerCmdData(payload, num); + } else { + LogUtils.error(TAG, 'onCmdDataChange default'); + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + } + }) + } + + private processPinCmdData(payload: CmdData, num?: string): void { + if (payload.result === 0) { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + } else if (payload.result && payload.result === Constants.authResultPinExpired) { + this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); + this.textValue = ''; + return; + } else { + if (payload.remainAttempts) { + this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); + this.textValue = ''; + if (num === 'first') { + this.inputValue = ''; } - if ((payload.remainAttempts && payload.result !== 0) || payload.result === Constants.authResultPinExpired) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); - this.fingerLock = false; + if (payload.remainAttempts < PIN_FAIL_TIP) { + this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + + payload.remainAttempts + (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_frequency').id); } - if (num === 'first') { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync(this.isOffFinger ? - $r('app.string.unified_authwidget_hint_normal_fp_only').id : - $r('app.string.unified_authwidget_hint_inscreen_fp').id); + } + if (payload.remainAttempts === AUTH_LOCK && payload.lockoutDuration) { + this.countTime(payload.lockoutDuration); + this.textValue = ''; + this.toPin(); + this.isEdit = false; + } + } + } + + private processFingerCmdData(payload: CmdData, num?: string): void { + if ([MULTI_PIN, SIX_PIN].includes(this.state)) { + return; + } + const displayClass = display.getDefaultDisplaySync(); + this.screen = [displayClass.width, displayClass.height]; + if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { + this.fingerPosition = JSON.parse(payload.sensorInfo); + switch (this.fingerPosition.sensorType) { + case 'OUT_OF_SCREEN_SENSOR': { + this.isOffFinger = true; + break; } - if (payload.remainAttempts === AUTH_LOCK) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); - this.fingerLock = true; - if (this.dialogType === DialogType.PIN_FINGER) { - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFinger]); - if (this.pinSubType !== Constants.pinSix) { - this.state = MULTI_PIN; - } else { - this.state = SIX_PIN; - } + default: + let tempPositionLine = JSON.parse(payload.sensorInfo).udSensorCenterYInThousandth / displayClass.height; + FuncUtils.judgmentOverflow(tempPositionLine); + if (tempPositionLine < FINGER_SENSOR_POSITION_LINE) { + this.screenType = ON_SCREEN; + } else if (tempPositionLine > FINGER_SENSOR_POSITION_LINE) { + this.screenType = UNDER_SCREEN; } + break; + } + } + if ((payload.remainAttempts && payload.result !== 0) || payload.result === Constants.authResultPinExpired) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); + this.fingerLock = false; + } + if (num === 'first') { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync(this.isOffFinger ? + $r('app.string.unified_authwidget_hint_normal_fp_only').id : + $r('app.string.unified_authwidget_hint_inscreen_fp').id); + } + if (payload.remainAttempts === AUTH_LOCK) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); + this.fingerLock = true; + if (this.dialogType === DialogType.PIN_FINGER) { + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFinger]); + if (this.pinSubType !== Constants.pinSix) { + this.state = MULTI_PIN; + } else { + this.state = SIX_PIN; } - if (payload.result === 0) { - this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager - .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) - setTimeout(() => { - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); - }, SECOND); - } - } else { - LogUtils.error(TAG, 'onCmdDataChange default'); - (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); } - }) + } + if (payload.result === 0) { + this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager + .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) + setTimeout(() => { + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + }, SECOND); + } } sendFingerEvent(): void { -- Gitee From cb39fdc08f91d8899ecd8c2cb9185eac1aa13c9d Mon Sep 17 00:00:00 2001 From: abonadon-hk Date: Fri, 29 Aug 2025 17:32:07 +0800 Subject: [PATCH 2/2] fix : fix codecheck error Signed-off-by: abonadon-hk --- entry/src/main/ets/pages/components/FaceAuth.ets | 7 ++++++- entry/src/main/ets/pages/components/FingerprintAuth.ets | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/entry/src/main/ets/pages/components/FaceAuth.ets b/entry/src/main/ets/pages/components/FaceAuth.ets index a347ebc..959cf4b 100644 --- a/entry/src/main/ets/pages/components/FaceAuth.ets +++ b/entry/src/main/ets/pages/components/FaceAuth.ets @@ -310,7 +310,12 @@ export default struct FaceAuth { } if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { this.fingerPosition = JSON.parse(payload.sensorInfo); - const displayClass = display.getDefaultDisplaySync(); + try { + const displayClass = display.getDefaultDisplaySync(); + } catch (error) { + LogUtils.error(TAG, `getDefaultDisplaySync catch error: ${error?.code}`); + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + } this.screen = [displayClass.width, displayClass.height]; switch (JSON.parse(payload.sensorInfo)?.sensorType as string) { case 'NON_SENSOR': diff --git a/entry/src/main/ets/pages/components/FingerprintAuth.ets b/entry/src/main/ets/pages/components/FingerprintAuth.ets index a2e3f54..0128c4c 100644 --- a/entry/src/main/ets/pages/components/FingerprintAuth.ets +++ b/entry/src/main/ets/pages/components/FingerprintAuth.ets @@ -164,7 +164,12 @@ export default struct FingerprintAuth { if ([MULTI_PIN, SIX_PIN].includes(this.state)) { return; } - const displayClass = display.getDefaultDisplaySync(); + try { + const displayClass = display.getDefaultDisplaySync(); + } catch (error) { + LogUtils.error(TAG, `getDefaultDisplaySync catch error: ${error?.code}`); + (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); + } this.screen = [displayClass.width, displayClass.height]; if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { this.fingerPosition = JSON.parse(payload.sensorInfo); -- Gitee