diff --git a/entry/src/main/ets/common/components/FullScreen.ets b/entry/src/main/ets/common/components/FullScreen.ets index f78e7ca62827afcfef8b8a395fe9d4b2646f16c6..602f0a79032e644f02054d99e8ee079f9c9663cb 100644 --- a/entry/src/main/ets/common/components/FullScreen.ets +++ b/entry/src/main/ets/common/components/FullScreen.ets @@ -232,6 +232,123 @@ export default struct FullScreen { }) } + 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 === 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); + } + + 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.faceFingerLockArr[1] = true; + this.controlType.jumpFinger = false; + this.cancelImage = false; + } + if (payload.result === 0) { + (AppStorage.get("session") as UIExtensionContentSession)?.terminateSelf(); + } + } + aboutToAppear(): void { LogUtils.debug(TAG, 'aboutToAppear'); try { diff --git a/entry/src/main/ets/pages/components/FaceAuth.ets b/entry/src/main/ets/pages/components/FaceAuth.ets index 4f6da34b1d835169cf2979266ea9e94ddc644918..2645c790f09d246dae468fecf5ff6b36f8417d79 100644 --- a/entry/src/main/ets/pages/components/FaceAuth.ets +++ b/entry/src/main/ets/pages/components/FaceAuth.ets @@ -442,6 +442,145 @@ export default struct FaceAuth { }) } + 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 < 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; + } + } + } + + 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 { + 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); + 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': + 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; + } + } + 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 { + 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 { if (this.dialogTypeFlag === SIX_PIN || this.dialogTypeFlag === MULTI_PIN) { AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypePin]); diff --git a/entry/src/main/ets/pages/components/FingerprintAuth.ets b/entry/src/main/ets/pages/components/FingerprintAuth.ets index cb34aa1cfa44aa3a03429473e40c316ad1e680d7..bf168b28749ebecc2e6a3332fbbd967c85214834 100644 --- a/entry/src/main/ets/pages/components/FingerprintAuth.ets +++ b/entry/src/main/ets/pages/components/FingerprintAuth.ets @@ -222,6 +222,10 @@ export default struct FingerprintAuth { onCmdDataChange(num?: string): void { this.cmdData.length > 0 && this.cmdData.map((item) => { const payload: CmdData = item.payload; + if (payload.type === Constants.noticeTypePin) { + this.processPinCmdData(payload, num); + } else if (payload.type === Constants.noticeTypeFinger) { + this.processFingerCmdData(payload, num); let lockoutDuration: number = 0; let remainAttempts: number = 0; let authResult: number = -1; @@ -308,6 +312,100 @@ export default struct FingerprintAuth { }) } + 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 < 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; + } + } + } + + private processFingerCmdData(payload: CmdData, num?: string): void { + if ([MULTI_PIN, SIX_PIN].includes(this.state)) { + return; + } + 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); + 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; + } + } + 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); + } + } + sendFingerEvent(): void { if (!this.fingerLock) { AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]);