diff --git a/entry/src/main/ets/common/components/FullScreen.ets b/entry/src/main/ets/common/components/FullScreen.ets index 53e5e1c786e38d9052dde1a741a8df5ddcd1399d..4b7f911ac259d527417a43e8dfa398277e96d0cb 100644 --- a/entry/src/main/ets/common/components/FullScreen.ets +++ b/entry/src/main/ets/common/components/FullScreen.ets @@ -16,6 +16,7 @@ import display from '@ohos.display'; import userAuth from '@ohos.userIAM.userAuth'; import Constants, { CmdType, FingerPosition } from '../../common/vm/Constants'; +import { globalContext, globalSession, globalWantParams } from '../../extensionability/UserAuthAbility'; import AuthUtils from '../utils/AuthUtils'; import FuncUtils from '../utils/FuncUtils'; import LogUtils from '../utils/LogUtils'; @@ -83,9 +84,9 @@ export default struct FullScreen { @StorageLink('passwordArrayNumber') passwordArrayNumber: string[] = []; @State passwordObj: string = ''; numKeyboard: KeyboardType[] = Constants.numKeyBoard; - @State prompt: string = globalThis.context.resourceManager + @State prompt: string = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_use_pwd')); - @State fingerText: string = globalThis.context.resourceManager + @State fingerText: string = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp')); @StorageLink('screenLockDirection') screenLockDirection: number = 1; @StorageLink('SYSTEM_STATUS_BAR_HEIGHT') SYSTEM_STATUS_BAR_HEIGHT: number = 0; @@ -112,18 +113,18 @@ export default struct FullScreen { case Constants.noticeTypePin: this.clearPassword(); if (remainAttempts) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_pwd_error')); - if (num === 'first' && this.prompt !== globalThis.context.resourceManager + if (num === 'first' && this.prompt !== globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition'))) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_use_pwd')); } // 3: pin Residual number if (remainAttempts < 3 && num !== 'first') { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) - + remainAttempts + globalThis.context.resourceManager + + remainAttempts + globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_frequency')); } } @@ -138,13 +139,13 @@ export default struct FullScreen { this.pinLock = 1; } if (result === 0) { - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } break; case Constants.noticeTypeFace: if (remainAttempts < 5 && remainAttempts > 0) { if (this.pinLock !== 1) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1')); this.faceFingerLockArr[0] = false; } @@ -154,20 +155,20 @@ export default struct FullScreen { this.controlType.isShowFace = false; } else { if (this.pinLock !== 1) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition')); } } } if (remainAttempts === 0) { if (num !== 'first') { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden')); } this.faceFingerLockArr[0] = true; } if (result === 0) { - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } break; case Constants.noticeTypeFinger: @@ -178,10 +179,11 @@ export default struct FullScreen { } if (remainAttempts && result !== 0) { if (this.controlType.jumpFinger) { - this.fingerText = globalThis.context.resourceManager + this.fingerText = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); } - if (sensor) { + if (sensor && this.fingerPosition.udSensorCenterYInThousandth !== undefined && + this.fingerPosition.udSensorRadiusInPx !== undefined) { if (sensor.sensorType === 'UNDER_SCREEN_SENSOR' || sensor.sensorType === 'BOTH_SENSOR' || sensor.sensorType === 'SensorType1') { @@ -189,7 +191,7 @@ export default struct FullScreen { setTimeout(() => { AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); }, NOTICE_DELAY); - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); } @@ -209,9 +211,9 @@ export default struct FullScreen { if (num === 'first') { this.controlType.isShowFinger = false; } else { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); - this.fingerText = globalThis.context.resourceManager + this.fingerText = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); } this.faceFingerLockArr[1] = true; @@ -219,12 +221,12 @@ export default struct FullScreen { this.cancelImage = false; } if (result === 0) { - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } break; default: LogUtils.error(TAG, 'type: ' + type); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); break; } }) @@ -240,7 +242,8 @@ export default struct FullScreen { this.onCmdDataChange('first'); } - if (this.controlType.isShowFinger) { + if (this.controlType.isShowFinger && this.fingerPosition.udSensorCenterYInThousandth !== undefined && + this.fingerPosition.udSensorRadiusInPx !== undefined) { let tempPosition = px2vp(this.fingerPosition.udSensorCenterYInThousandth * this.screen[1]); FuncUtils.judgmentOverflow(tempPosition); this.fingerButtonPositionY = tempPosition / THOUSANDTH; @@ -264,7 +267,7 @@ export default struct FullScreen { } } catch (error) { LogUtils.error(TAG, 'aboutToAppear catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } @@ -274,7 +277,7 @@ export default struct FullScreen { this.passwordArray = ['', '', '', '', '', '']; this.passwordObj = ''; this.numKeyboard[11].value = GO_BACK; - this.numKeyboard[11].row1 = globalThis.context.resourceManager + this.numKeyboard[11].row1 = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_back')); this.updateStorage(() => { }) @@ -285,16 +288,16 @@ export default struct FullScreen { } countdown(freezingTime): void { - const TRY_AGAIN = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); - const PLEASE_TRY = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_pleaseretry')); + const TRY_AGAIN = globalContext.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); + const PLEASE_TRY = globalContext.resourceManager.getStringSync($r('app.string.unified_authwidget_pleaseretry')); let promptText: string = ''; let freezingMillisecond = freezingTime; if (freezingMillisecond > 0) { - promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalThis.context); + promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalContext); promptText =PLEASE_TRY + promptText + TRY_AGAIN; setTimeout(this.countdown.bind(this), INTERVAL, freezingTime - INTERVAL); } else { - promptText = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_use_pwd')); + promptText = globalContext.resourceManager.getStringSync($r('app.string.unified_authwidget_use_pwd')); this.clearPassword(); // 0: pin unlock this.pinLock = 0; @@ -359,11 +362,11 @@ export default struct FullScreen { .margin({ bottom: $r('app.float.content_padding') }) .onClick(() => { if (!this.faceFingerLockArr[0]) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition')); AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); } else { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_title_face_forbidden')); } }) @@ -386,9 +389,9 @@ export default struct FullScreen { .textOverflow({ overflow: TextOverflow.None }) .height($r('app.float.size_24')) .onClick(() => { - if (this.prompt === globalThis.context.resourceManager + if (this.prompt === globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1'))) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition')); AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); } @@ -550,12 +553,13 @@ export default struct FullScreen { if (!this.IS_LANDSCAPE && this.pinLock === 0 && this.pinSubType === Constants.pinSix) { if (this.controlType.isShowFinger && this.fingerPosition.sensorType !== 'OUT_OF_SCREEN_SENSOR' && this.fingerPosition.sensorType !== 'NON_SENSOR') { - if (this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE) { + if (this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && this.fingerPosition.udSensorRadiusInPx !== undefined + && this.fingerPosition.udSensorCenterYInThousandth !== undefined) { Column() { NumKeyBoard({ onKeyPress: (index, callback) => { let keyValue = this.numKeyboard[index].value; - if (keyValue > 0 || keyValue === 0) { + if (keyValue!= undefined && keyValue >= 0) { const index = this.passwordArray.map(item => item).indexOf('') if (index > -1) { this.passwordArray[index] = keyValue + ''; @@ -579,7 +583,7 @@ export default struct FullScreen { } else if (index === 1) { this.passwordArray[index - 1] = ''; this.numKeyboard[11].value = GO_BACK; - this.numKeyboard[11].row1 = globalThis.context.resourceManager + this.numKeyboard[11].row1 = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_back')); } else { this.passwordArray[index - 1] = ''; @@ -589,8 +593,9 @@ export default struct FullScreen { // 0: pin unlock this.pinLock = 0; this.clearPassword(); - globalThis.session?.terminateSelf?.(); - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, globalThis?.wantParams?.type || []); + globalSession?.terminateSelf?.(); + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || + globalWantParams?.type as string[]); } else if (keyValue === CALL_PHONE) { if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { return; @@ -614,7 +619,7 @@ export default struct FullScreen { NumKeyBoard({ onKeyPress: (index, callback) => { let keyValue = this.numKeyboard[index].value; - if (keyValue > 0 || keyValue === 0) { + if (keyValue !== undefined && keyValue >= 0) { const index = this.passwordArray.map(item => item).indexOf('') if (index > -1) { this.passwordArray[index] = keyValue + ''; @@ -638,7 +643,7 @@ export default struct FullScreen { } else if (index === 1) { this.passwordArray[index - 1] = ''; this.numKeyboard[11].value = GO_BACK; - this.numKeyboard[11].row1 = globalThis.context.resourceManager + this.numKeyboard[11].row1 = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_back')); } else { this.passwordArray[index - 1] = ''; @@ -648,8 +653,9 @@ export default struct FullScreen { // 0: pin unlock this.pinLock = 0; this.clearPassword(); - globalThis.session?.terminateSelf?.(); - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, globalThis?.wantParams?.type || []); + globalSession?.terminateSelf?.(); + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || + globalWantParams?.type as string[]); } else if (keyValue === CALL_PHONE) { if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { return; @@ -671,7 +677,7 @@ export default struct FullScreen { NumKeyBoard({ onKeyPress: (index, callback) => { let keyValue = this.numKeyboard[index].value; - if (keyValue > 0 || keyValue === 0) { + if (keyValue !== undefined && keyValue >= 0) { const index = this.passwordArray.map(item => item).indexOf('') if (index > -1) { this.passwordArray[index] = keyValue + ''; @@ -695,7 +701,7 @@ export default struct FullScreen { } else if (index === 1) { this.passwordArray[index - 1] = ''; this.numKeyboard[11].value = GO_BACK; - this.numKeyboard[11].row1 = globalThis.context.resourceManager + this.numKeyboard[11].row1 = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_back')); } else { this.passwordArray[index - 1] = ''; @@ -705,8 +711,9 @@ export default struct FullScreen { // 0: pin unlock this.pinLock = 0; this.clearPassword(); - globalThis.session?.terminateSelf?.(); - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, globalThis?.wantParams?.type || []); + globalSession?.terminateSelf?.(); + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || + globalWantParams?.type as string[]); } else if (keyValue === CALL_PHONE) { if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { return; @@ -733,7 +740,8 @@ export default struct FullScreen { if (this.fingerPosition.sensorType === 'UNDER_SCREEN_SENSOR' || this.fingerPosition.sensorType === 'BOTH_SENSOR' || this.fingerPosition.sensorType === 'SensorType1') { - if (this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && !this.IS_LANDSCAPE) { + if (this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && !this.IS_LANDSCAPE && this.fingerPosition.udSensorRadiusInPx !== undefined + && this.fingerPosition.udSensorCenterYInThousandth !== undefined) { Column() { Image($r('app.media.ic_unlock_fingerprint')) .draggable(false) @@ -785,12 +793,12 @@ export default struct FullScreen { .alignItems(HorizontalAlign.Center) .height(Constants.fullContainerHeight) .width(Constants.fullContainerWidth) - } else if (!this.controlType.isLandscape) { + } else if (!this.controlType.isLandscape && this.fingerPosition.udSensorRadiusInPx !== undefined) { Column() { - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) @@ -814,7 +822,7 @@ export default struct FullScreen { .scrollable(ScrollDirection.Vertical) .scrollBarColor('sys.color.ohos_id_color_foreground') } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .height($r('app.float.text_high')) .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) @@ -866,7 +874,7 @@ export default struct FullScreen { this.controlType.jumpFinger = false; this.cancelImage = false; AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFinger]); - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_use_pwd')); }) } diff --git a/entry/src/main/ets/common/components/NumkeyBoard.ets b/entry/src/main/ets/common/components/NumkeyBoard.ets index 718ab58594cbd455864d6a5799467ac36560876d..331e1c9da6274868b60ecbf97631e15b203dadea 100644 --- a/entry/src/main/ets/common/components/NumkeyBoard.ets +++ b/entry/src/main/ets/common/components/NumkeyBoard.ets @@ -25,7 +25,7 @@ const GO_BACK = -3; @Component export default struct NumKeyBoard { - private onKeyPress: (params, callback) => void; + private onKeyPress?: (params, callback) => void; @StorageLink('numKeyboard') numKeyboard: any[] = Constants.numKeyBoard; build() { @@ -108,8 +108,10 @@ export default struct NumKeyBoard { } } .onClick(() => { - setTimeout(this.onKeyPress.bind(this), 0, item.index, () => { - }); + if (this.onKeyPress !== undefined){ + setTimeout(this.onKeyPress.bind(this), 0, item.index, () => { + }); + } }) .id('numKeyBordCustomPwd' + item.index) } diff --git a/entry/src/main/ets/common/components/PassWord.ets b/entry/src/main/ets/common/components/PassWord.ets index f73b69cd0483d5d8e86b568852b2df04cdfa5f60..e8ba3ce595e2b858fc6e7413382b141c2c3d61d6 100644 --- a/entry/src/main/ets/common/components/PassWord.ets +++ b/entry/src/main/ets/common/components/PassWord.ets @@ -14,6 +14,7 @@ */ import Constants from '../../common/vm/Constants'; +import { globalWantParams } from '../../extensionability/UserAuthAbility'; const MAX_LENGTH = 32; @@ -24,9 +25,9 @@ export default struct PassWord { @Link inputValue: string; @Link isEdit: boolean; @StorageLink('passwordArrayNumber') passwordArrNumber: string[] = []; - controller: CustomDialogController; - cancel: () => void; - confirm: () => void; + controller?: CustomDialogController; + cancel?: () => void; + confirm?: () => void; onTextValueChange(): void { this.passwordArrNumber = this.textValue.replace(/[^\d]/g, '').split(''); @@ -44,10 +45,10 @@ export default struct PassWord { build() { Column() { - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -95,7 +96,7 @@ export default struct PassWord { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .margin({ top: $r('app.float.title_padding_top') }) .fontSize($r('sys.float.ohos_id_text_size_body1')) diff --git a/entry/src/main/ets/common/components/SixPassword.ets b/entry/src/main/ets/common/components/SixPassword.ets index 183ce4cf447fdc4208c7f656e05780ce3d8e77b8..29f88a489d0e956dbaead7e2ec4701c91259dfaa 100644 --- a/entry/src/main/ets/common/components/SixPassword.ets +++ b/entry/src/main/ets/common/components/SixPassword.ets @@ -14,6 +14,7 @@ */ import Constants from '../../common/vm/Constants'; +import { globalWantParams } from '../../extensionability/UserAuthAbility'; import AuthUtils from '../utils/AuthUtils'; const MAX_LENGTH = 6; @@ -41,10 +42,10 @@ export default struct SixPassword { build() { Column() { - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -54,25 +55,27 @@ export default struct SixPassword { Stack() { 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) + if (index !== undefined) { + 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) } @@ -113,7 +116,7 @@ export default struct SixPassword { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .margin({ top: $r('app.float.title_padding_top') }) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -124,25 +127,27 @@ export default struct SixPassword { Stack() { 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) + if (index !== undefined) { + 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) } diff --git a/entry/src/main/ets/common/utils/AuthUtils.ts b/entry/src/main/ets/common/utils/AuthUtils.ts index 8287346665feccb4d0d4dc9bbcf88438b443e67c..cfdaf6f5e1327cd50dd8949962c2c60b4bf8a84f 100644 --- a/entry/src/main/ets/common/utils/AuthUtils.ts +++ b/entry/src/main/ets/common/utils/AuthUtils.ts @@ -14,6 +14,7 @@ */ import userAuth from '@ohos.userIAM.userAuth'; +import { globalSession } from '../../extensionability/UserAuthAbility'; import Constants from '../vm/Constants'; import LogUtils from './LogUtils'; @@ -45,7 +46,7 @@ export default class AuthUtils { LogUtils.info(TAG, 'sendNotice success'); } catch (error) { LogUtils.error(TAG, 'sendNotice catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.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 fa5e43ba61949978fc9bf7243eb8560dd74d29e8..777ab0986828ecf4eedde15e42fc98f9d41ffadd 100644 --- a/entry/src/main/ets/common/utils/FuncUtils.ts +++ b/entry/src/main/ets/common/utils/FuncUtils.ts @@ -18,6 +18,7 @@ import userAuth from '@ohos.userIAM.userAuth'; import { DialogType } from '../module/DialogType'; import LogUtils from './LogUtils'; import window from '@ohos.window'; +import { globalSession } from '../../extensionability/UserAuthAbility'; const TAG = 'FuncUtils'; @@ -59,11 +60,12 @@ export class FuncUtils { JSON.stringify(data)); for (let i = 0; i < data.regionTint.length; i++) { let regionData = data.regionTint[i]; - if (regionData.type === window.WindowType.TYPE_STATUS_BAR) { + if (regionData.region == undefined) { + continue; + } else if (regionData.type === window.WindowType.TYPE_STATUS_BAR) { AppStorage.SetOrCreate('SYSTEM_STATUS_BAR_HEIGHT', px2vp(regionData.region.height)); continue; - } - if (regionData.type === window.WindowType.TYPE_NAVIGATION_BAR) { + } else if (regionData.type === window.WindowType.TYPE_NAVIGATION_BAR) { AppStorage.SetOrCreate('SYSTEM_NAVIGATION_BAR_HEIGHT', px2vp(regionData.region.height)); continue; } @@ -77,7 +79,7 @@ export class FuncUtils { judgmentOverflow(value: number): void { if (value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) { LogUtils.error(TAG, 'judgmentOverflow spill code value: ' + value); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } } diff --git a/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts b/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts index e6421a4791799699332a64feb6b6ec093bb24792..1ae7c846a52b81d56decb6e9df5b4e3c09486efc 100644 --- a/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts +++ b/entry/src/main/ets/common/utils/WindowPrivacyUtils.ts @@ -13,6 +13,7 @@ * limitations under the License. */ import type UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import { globalSession } from '../../extensionability/UserAuthAbility'; import LogUtils from './LogUtils'; const TAG = 'WindowPrivacyUtils'; @@ -30,7 +31,7 @@ export class WindowPrivacyUtils { }); } catch (error) { LogUtils.error(TAG, 'setWindowPrivacyMode catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } } diff --git a/entry/src/main/ets/extensionability/UserAuthAbility.ts b/entry/src/main/ets/extensionability/UserAuthAbility.ts index 233e8d3003cc79f08bfdebe7ac02c144c04b792a..d87a1164da43ac7204ee90ff7f74c4a2de713528 100644 --- a/entry/src/main/ets/extensionability/UserAuthAbility.ts +++ b/entry/src/main/ets/extensionability/UserAuthAbility.ts @@ -16,6 +16,13 @@ import LogUtils from '../common/utils/LogUtils'; import UserAuthExtensionAbility from '@ohos.app.ability.UserAuthExtensionAbility'; import WindowPrivacyUtils from '../common/utils/WindowPrivacyUtils'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import { CmdType } from '../common/vm/Constants'; +import common from '@ohos.app.ability.common'; + +export let globalSession : UIExtensionContentSession; +export let globalWantParams : {[key: string]: (string | CmdType[] | string[])}; +export let globalContext : common.UIExtensionContext; const TAG = 'UserAuthAbility'; // The current interface only support string type @@ -25,7 +32,7 @@ const MASK_THIN_COLOR = '#33182431'; export default class UserAuthAbility extends UserAuthExtensionAbility { onCreate() { LogUtils.info(TAG, 'UserAuthExtensionAbility onCreate'); - globalThis.context = this.context; + globalContext = this.context; } onForeground(): void { @@ -34,7 +41,7 @@ export default class UserAuthAbility extends UserAuthExtensionAbility { onBackground(): void { LogUtils.info(TAG, 'UserAuthExtensionAbility onBackground'); - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); } onDestroy(): void | Promise { @@ -43,18 +50,18 @@ export default class UserAuthAbility extends UserAuthExtensionAbility { onSessionCreate(want, session): void { LogUtils.info(TAG, 'UserAuthExtensionAbility onSessionCreate'); - globalThis.wantParams = want?.parameters?.useriamCmdData; - globalThis.session = session; - session?.loadContent('pages/Index'); + globalWantParams = want?.parameters?.useriamCmdData; + globalSession = session; + (session as UIExtensionContentSession)?.loadContent('pages/Index'); try { - if (globalThis.wantParams?.windowModeType === 'DIALOG_BOX') { - session?.setWindowBackgroundColor(MASK_THIN_COLOR); + if (globalWantParams?.windowModeType as string === 'DIALOG_BOX') { + (session as UIExtensionContentSession)?.setWindowBackgroundColor(MASK_THIN_COLOR); } else { - session?.setWindowBackgroundColor(TRANSPARENT_COLOR); + (session as UIExtensionContentSession)?.setWindowBackgroundColor(TRANSPARENT_COLOR); } } catch (error) { LogUtils.error(TAG, 'UserAuthExtensionAbility onSessionCreate error: ' + error?.code); - session?.terminateSelf(); + (session as UIExtensionContentSession)?.terminateSelf(); } WindowPrivacyUtils.setWindowPrivacyMode(session, true); } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 2f7e1766829a052130f85c84feccd9e71e354ab5..9c027cae14be55c1fca4c4bed10a3c0ef4bd583f 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -19,6 +19,7 @@ import { DialogType } from '../common/module/DialogType'; import FuncUtils from '../common/utils/FuncUtils'; import LogUtils from '../common/utils/LogUtils'; import Constants, { CmdType } from '../common/vm/Constants'; +import { globalContext, globalSession, globalWantParams } from '../extensionability/UserAuthAbility'; import CustomPassword from './components/CustomPassword'; import FaceAuth from './components/FaceAuth'; import FingerprintAuth from './components/FingerprintAuth'; @@ -50,7 +51,7 @@ struct Index { screen.getAllScreens((err, data) => { if (err.code) { LogUtils.error(TAG, 'Failed to get all screens. err: ' + err.code); - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); return; } LogUtils.debug(TAG, ' get all screens. result:-- ' + JSON.stringify(data)); @@ -58,20 +59,20 @@ struct Index { || data[0]?.supportedModeInfo[0]?.width > data[0]?.supportedModeInfo[0]?.height; AppStorage.SetOrCreate('titleLength', (data[0]?.supportedModeInfo[0]?.width * 0.8 / fp2px(16))) LogUtils.debug(TAG, 'titleLength: ' + (data[0]?.supportedModeInfo[0]?.width * 0.8 / fp2px(16))); - LogUtils.debug(TAG, 'title: ' + globalThis.wantParams?.title.length); + LogUtils.debug(TAG, 'title: ' + (globalWantParams?.title as string).length); AppStorage.SetOrCreate('IS_LANDSCAPE', this.isLandscape); - LogUtils.debug(TAG, 'globalThis.wantParams: ' + JSON.stringify(globalThis.wantParams)); - if (globalThis.wantParams) { - this.getParams(globalThis.wantParams); + LogUtils.debug(TAG, 'WantParams: ' + JSON.stringify(globalWantParams)); + if (globalWantParams) { + this.getParams(globalWantParams); this.handleAuthStart(); - this.cmdData = globalThis.wantParams?.cmd; + this.cmdData = globalWantParams?.cmd as CmdType[]; } else { LogUtils.error(TAG, 'aboutToAppear wantParams null'); - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); } if (this.isLandscape && this.underFingerPrint) { setTimeout(() => { - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); }, FIVE_SECOND) } else { this.loadFlag = true; @@ -79,7 +80,7 @@ struct Index { }); } catch (error) { LogUtils.error(TAG, 'getAllScreens catch error: ' + error?.code); - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); } } @@ -100,7 +101,7 @@ struct Index { }); } catch (error) { LogUtils.error(TAG, 'getUserAuthWidgetMgr catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } @@ -154,6 +155,8 @@ struct Index { return userAuth.UserAuthType.FINGERPRINT; case Constants.noticeTypeFace: return userAuth.UserAuthType.FACE; + default: + return userAuth.UserAuthType.PIN; } }) globalThis.widgetContextId = widgetContextId; @@ -170,7 +173,7 @@ struct Index { if (this.isLandscape && this.underFingerPrint) { Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.End }) { Column() { - Text(globalThis.context.resourceManager + Text(globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_tip_verify_in_portrait_mode'))) .draggable(false) .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) diff --git a/entry/src/main/ets/pages/components/CustomPassword.ets b/entry/src/main/ets/pages/components/CustomPassword.ets index 77b07640a92e94f877dbca1b1b40b708486b3f10..3db3cb875b585789575f9ca80c1a361525e8a761 100644 --- a/entry/src/main/ets/pages/components/CustomPassword.ets +++ b/entry/src/main/ets/pages/components/CustomPassword.ets @@ -20,6 +20,7 @@ import FuncUtils from '../../common/utils/FuncUtils'; import LogUtils from '../../common/utils/LogUtils'; import Constants from '../../common/vm/Constants'; import AuthUtils from '../../common/utils/AuthUtils'; +import { globalSession, globalWantParams } from '../../extensionability/UserAuthAbility'; const TAG = 'CustomPassword'; const BLUR_OPACITY = 0.5; @@ -60,7 +61,7 @@ export default struct CustomPassword { }); } catch (error) { LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } @@ -92,14 +93,16 @@ export default struct CustomPassword { .backgroundColor(this.isBackTouched ? $r('sys.color.ohos_id_color_hover') : Color.Transparent) .onClick(() => { - globalThis.session?.terminateSelf?.(); - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, globalThis?.wantParams?.type || []); + globalSession?.terminateSelf?.(); + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || + globalWantParams?.type as string[]); }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { + .onTouch((event?: TouchEvent) => { + if (event == undefined) { + return; + } else if (event.type === TouchType.Down) { this.isBackTouched = true; - } - if (event.type === TouchType.Up) { + } else if (event.type === TouchType.Up) { this.isBackTouched = false; } }); diff --git a/entry/src/main/ets/pages/components/FaceAuth.ets b/entry/src/main/ets/pages/components/FaceAuth.ets index af17db14d7d43e3b3e9217b3e289106c277d0d27..1a5c2e379c9fcf053312ee588dd4c81297203add 100644 --- a/entry/src/main/ets/pages/components/FaceAuth.ets +++ b/entry/src/main/ets/pages/components/FaceAuth.ets @@ -23,10 +23,11 @@ import FuncUtils from '../../common/utils/FuncUtils'; import LogUtils from '../../common/utils/LogUtils'; import TimeUtils from '../../common/utils/TimeUtils'; import Constants, { CmdType, FingerPosition } from '../../common/vm/Constants'; +import { globalContext, globalSession, globalWantParams } from '../../extensionability/UserAuthAbility'; const TAG = 'FaceAuth'; -let pinAuthManager; +let pinAuthManager : account_osAccount.PINAuth; const INTERVAL = 1000; const THOUSANDTH = 1000; const PADDING_24 = 24; @@ -46,7 +47,7 @@ let pinData = ''; @Component export default struct FaceAuth { - @State prompt: string = globalThis.context.resourceManager + @State prompt: string = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition')); @State @Watch('onTextValueChange') textValue: string = ''; @Link @Watch('onCmdDataChange') cmdData: Array; @@ -72,12 +73,12 @@ export default struct FaceAuth { @StorageLink('SYSTEM_NAVIGATION_BAR_HEIGHT') SYSTEM_NAVIGATION_BAR_HEIGHT: number = 0; countTime(freezingTime): void { - const TRY_AGAIN = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); + const TRY_AGAIN = globalContext.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); let promptText: string = ''; let freezingMillisecond = freezingTime; if (freezingMillisecond > 0) { - promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalThis.context); - promptText = globalThis.context.resourceManager + promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalContext); + promptText = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_many_failures')) + promptText + TRY_AGAIN; setTimeout(this.countTime.bind(this), INTERVAL, freezingTime - INTERVAL); } else { @@ -94,7 +95,8 @@ export default struct FaceAuth { this.onCmdDataChange('first'); } - if (this.isPinFaceFinger) { + if (this.isPinFaceFinger && this.fingerPosition.udSensorCenterYInThousandth !== undefined && + this.fingerPosition.udSensorRadiusInPx !== undefined) { let tempPosition = this.fingerPosition.udSensorCenterYInThousandth / this.screen[1]; FuncUtils.judgmentOverflow(tempPosition); let tempFingerPositionY = px2vp(this.screen[1]) * this.fingerPosition.udSensorCenterYInThousandth; @@ -110,7 +112,7 @@ export default struct FaceAuth { } LogUtils.info(TAG, 'aboutToAppear this.fingerPositionY: ' + this.fingerPositionY); if (this.dialogType === DialogType.PIN_FACE || this.dialogType === DialogType.FACE) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition')); AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); } else if (this.dialogType === DialogType.ALL) { @@ -118,7 +120,7 @@ export default struct FaceAuth { .sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger, Constants.noticeTypeFace]); } else { LogUtils.error(TAG, 'aboutToAppear not support type'); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } pinAuthManager = new account_osAccount.PINAuth(); pinAuthManager.registerInputer({ @@ -130,7 +132,7 @@ export default struct FaceAuth { }); } catch (error) { LogUtils.error(TAG, 'aboutToAppear catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } @@ -158,7 +160,7 @@ export default struct FaceAuth { sendFaceEvent(): void { if (!this.faceLock) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition')); AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); } @@ -192,6 +194,8 @@ export default struct FaceAuth { case context?.resourceManager ?.getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp')): return $r('sys.color.ohos_id_color_text_secondary'); + default: + return $r('sys.color.ohos_id_color_text_secondary'); } } @@ -201,19 +205,19 @@ export default struct FaceAuth { switch (type) { case Constants.noticeTypePin: if (result === 0) { - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); } else { if (remainAttempts) { - this.inputValue = globalThis.context.resourceManager + this.inputValue = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_pwd_error')); this.textValue = ''; if (num === 'first') { this.inputValue = ''; } if (remainAttempts < HINT_TIMES_BY_FAIL_LESS) { - this.inputValue = globalThis.context.resourceManager + this.inputValue = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) - + remainAttempts + globalThis.context.resourceManager + + remainAttempts + globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_frequency')); } } @@ -230,16 +234,16 @@ export default struct FaceAuth { return; } if (remainAttempts && result !== 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1')); this.faceLock = false; } if (num === 'first') { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition')); } if (remainAttempts === 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden')); this.faceLock = true; if (this.dialogType === DialogType.ALL) { @@ -251,10 +255,10 @@ export default struct FaceAuth { } } if (result === 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognize_success')) setTimeout(() => { - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); }, SECOND); } break; @@ -289,7 +293,7 @@ export default struct FaceAuth { } } if (remainAttempts && result !== 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); this.fingerLock = false; if (num !== 'first' && remainAttempts > 0 && result !== 0) { @@ -299,11 +303,11 @@ export default struct FaceAuth { } } if (num === 'first') { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_normal_fp_only')); } if (remainAttempts === 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); this.fingerLock = true; if (this.dialogType === DialogType.ALL) { @@ -315,16 +319,16 @@ export default struct FaceAuth { } } if (result === 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) setTimeout(() => { - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); }, SECOND); } break; default: LogUtils.error(TAG, 'onCmdDataChange default'); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); break; } }) @@ -334,9 +338,10 @@ export default struct FaceAuth { if (this.dialogTypeFlag === SIX_PIN || this.dialogTypeFlag === MULTI_PIN) { AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypePin]); } else { - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, globalThis?.wantParams?.type || []); + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || + globalWantParams?.type as string[]); } - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } build() { @@ -442,7 +447,8 @@ export default struct FaceAuth { right: ($r('sys.float.ohos_id_dialog_margin_end')), bottom: this.IS_LANDSCAPE ? '0' : ($r('sys.float.ohos_id_dialog_margin_bottom')) }) - } else if (this.dialogTypeFlag === PIN_FACE_FINGER && this.screenType === SCREEN_PORTRAIT) { + } else if (this.dialogTypeFlag === PIN_FACE_FINGER && this.screenType === SCREEN_PORTRAIT && + this.fingerPosition.udSensorRadiusInPx !== undefined) { Column() { // The first form of facial fingerprint password Flex({ justifyContent: FlexAlign.SpaceBetween }) { @@ -477,7 +483,7 @@ export default struct FaceAuth { }) } - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { Image($r('app.media.error_faceID')) @@ -490,7 +496,7 @@ export default struct FaceAuth { .onClick(() => { this.sendFaceEvent(); }) - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -501,7 +507,7 @@ export default struct FaceAuth { .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)) + .fontColor(this.onFontColor(this.prompt, globalContext)) }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) } .width('100%') @@ -520,7 +526,7 @@ export default struct FaceAuth { .onClick(() => { this.sendFaceEvent(); }) - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -532,7 +538,7 @@ export default struct FaceAuth { .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)) + .fontColor(this.onFontColor(this.prompt, globalContext)) } Image($r('app.media.ic_blue_fingerprint')) .draggable(false) @@ -557,9 +563,10 @@ export default struct FaceAuth { right: ($r('sys.float.ohos_id_dialog_margin_end')), bottom: ($r('sys.float.ohos_id_dialog_margin_bottom')) }) - } else if (this.dialogTypeFlag === PIN_FACE_FINGER && this.screenType === SCREEN_LAND) { + } else if (this.dialogTypeFlag === PIN_FACE_FINGER && this.screenType === SCREEN_LAND + && this.fingerPosition.udSensorRadiusInPx !== undefined) { Column() { - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { // Facial fingerprint password, second form @@ -573,7 +580,7 @@ export default struct FaceAuth { .onClick(() => { this.sendFaceEvent(); }) - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -597,7 +604,7 @@ export default struct FaceAuth { .onClick(() => { this.sendFaceEvent(); }) - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -620,9 +627,9 @@ export default struct FaceAuth { .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)) + .fontColor(this.onFontColor(this.prompt, globalContext)) .onClick(() => { - if (this.prompt === globalThis?.context?.resourceManager + if (this.prompt === globalContext?.resourceManager ?.getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1'))) { this.sendFaceEvent(); } @@ -684,15 +691,15 @@ export default struct FaceAuth { Column() { if (this.dialogTypeFlag === PIN_FACE) { // Pin FACE - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) .fontWeight(FontWeight.Medium) - Image(this.prompt !== globalThis.context.resourceManager + Image(this.prompt !== globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognize_success')) ? $r('app.media.error_faceID') : $r('app.media.right_faceID')) .draggable(false) @@ -708,7 +715,7 @@ export default struct FaceAuth { }) Text(this.prompt).fontSize($r('sys.float.ohos_id_text_size_body2')) .draggable(false) - .fontColor(this.onFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFontColor(this.prompt, globalContext)) .height($r('app.float.size_24')) .onClick(() => { this.sendFaceEvent(); @@ -721,14 +728,14 @@ export default struct FaceAuth { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .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')) .height($r('app.float.size_24')) .fontWeight(FontWeight.Medium) - Image(this.prompt !== globalThis.context.resourceManager + Image(this.prompt !== globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognize_success')) ? $r('app.media.error_faceID') : $r('app.media.right_faceID')) .draggable(false) @@ -744,7 +751,7 @@ export default struct FaceAuth { }) Text(this.prompt).fontSize($r('sys.float.ohos_id_text_size_body2')) .draggable(false) - .fontColor(this.onFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFontColor(this.prompt, globalContext)) .height($r('app.float.size_24')) .onClick(() => { this.sendFaceEvent(); @@ -867,16 +874,16 @@ export default struct FaceAuth { } if (this.dialogTypeFlag === SINGLE_FACE) { // Single FACE - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) .fontWeight(FontWeight.Medium) .id('titleFaceAuth') - Image(this.prompt !== globalThis.context.resourceManager + Image(this.prompt !== globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognize_success')) ? $r('app.media.error_faceID') : $r('app.media.right_faceID')) .draggable(false) @@ -896,7 +903,7 @@ export default struct FaceAuth { .fontSize($r('sys.float.ohos_id_text_size_body2')) .id('textFaceAuth') .height($r('app.float.size_24')) - .fontColor(this.onFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFontColor(this.prompt, globalContext)) .onClick(() => { this.sendFaceEvent(); }) @@ -908,7 +915,7 @@ export default struct FaceAuth { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .margin({ top: $r('app.float.title_padding_top') }) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -916,7 +923,7 @@ export default struct FaceAuth { .height($r('app.float.size_24')) .fontWeight(FontWeight.Medium) .id('titleFaceAuth') - Image(this.prompt !== globalThis.context.resourceManager + Image(this.prompt !== globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognize_success')) ? $r('app.media.error_faceID') : $r('app.media.right_faceID')) .draggable(false) @@ -936,12 +943,12 @@ export default struct FaceAuth { .fontSize($r('sys.float.ohos_id_text_size_body2')) .id('textFaceAuth') .height($r('app.float.size_24')) - .fontColor(this.onFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFontColor(this.prompt, globalContext)) .onClick(() => { this.sendFaceEvent(); }) } - if (!globalThis.wantParams?.navigationButtonText) { + if (!(globalWantParams?.navigationButtonText as string)) { Row() { Column() { Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) @@ -982,10 +989,10 @@ export default struct FaceAuth { .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { - Button(globalThis.wantParams?.navigationButtonText) + Button(globalWantParams?.navigationButtonText as string) .onClick(() => { AuthUtils.getInstance().sendNotice('EVENT_AUTH_USER_NAVIGATION', [Constants.noticeTypeFace]); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); }) .margin({ right: $r('app.float.content_padding') }) .width(Constants.ninetyPercentWidth) diff --git a/entry/src/main/ets/pages/components/FingerprintAuth.ets b/entry/src/main/ets/pages/components/FingerprintAuth.ets index 9af192c49bcccdeea6d6eccb713ae1e9cfa5cee9..bdb71116b77e192621cb427f15836ee3c8abc40d 100644 --- a/entry/src/main/ets/pages/components/FingerprintAuth.ets +++ b/entry/src/main/ets/pages/components/FingerprintAuth.ets @@ -23,6 +23,7 @@ import FuncUtils from '../../common/utils/FuncUtils'; import LogUtils from '../../common/utils/LogUtils'; import TimeUtils from '../../common/utils/TimeUtils'; import Constants, { CmdType, FingerPosition } from '../../common/vm/Constants'; +import { globalContext, globalSession, globalWantParams } from '../../extensionability/UserAuthAbility'; const TAG = 'FingerprintAuth'; const INTERVAL = 1000; @@ -44,7 +45,6 @@ const NOTICE_DELAY = 50; const ON_SCREEN = 1; const UNDER_SCREEN = 2; const FINGER_SENSOR_POSITION_LINE = 0.75; -const MAX_FAIL_TIMES = 5; const SECOND = 1000; @Component @@ -52,7 +52,7 @@ export default struct FingerprintAuth { @Link type: string; @Link pinSubType: string; @Link dialogType: DialogType; - @State prompt: string = globalThis.context.resourceManager + @State prompt: string = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp')); @State @Watch('onTextValueChange') textValue: string = ''; @Link @Watch('onCmdDataChange') cmdData: Array; @@ -78,7 +78,7 @@ export default struct FingerprintAuth { if (this.cmdData && this.cmdData.length > 0) { this.onCmdDataChange('first'); } - if (this.screenType === ON_SCREEN || this.screenType === UNDER_SCREEN) { + if (this.fingerPosition.udSensorCenterYInThousandth !== undefined && (this.screenType === ON_SCREEN || this.screenType === UNDER_SCREEN)) { let tempPositionY = px2vp(this.fingerPosition.udSensorCenterYInThousandth * this.screen[1]); FuncUtils.judgmentOverflow(tempPositionY); if (this.screenType === ON_SCREEN) { @@ -100,7 +100,7 @@ export default struct FingerprintAuth { }); } catch (error) { LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } @@ -119,19 +119,19 @@ export default struct FingerprintAuth { switch (type) { case Constants.noticeTypePin: if (result === 0) { - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); } else { if (remainAttempts) { - this.inputValue = globalThis.context.resourceManager + this.inputValue = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_pwd_error')); this.textValue = ''; if (num === 'first') { this.inputValue = ''; } if (remainAttempts < PIN_FAIL_TIP) { - this.inputValue = globalThis.context.resourceManager + this.inputValue = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) + - remainAttempts + globalThis.context.resourceManager + remainAttempts + globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_frequency')); } } @@ -168,7 +168,7 @@ export default struct FingerprintAuth { } } if (remainAttempts && result !== 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2')); this.fingerLock = false; if (remainAttempts > AUTH_LOCK && num !== 'first' && result != 0) { @@ -178,13 +178,13 @@ export default struct FingerprintAuth { } } if (num === 'first') { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync(this.isOffFinger ? $r('app.string.unified_authwidget_hint_normal_fp_only') : $r('app.string.unified_authwidget_hint_inscreen_fp')); } if (remainAttempts === AUTH_LOCK) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden')); this.fingerLock = true; if (this.dialogType === DialogType.PIN_FINGER) { @@ -197,16 +197,16 @@ export default struct FingerprintAuth { } } if (result === 0) { - this.prompt = globalThis.context.resourceManager + this.prompt = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) setTimeout(() => { - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); }, SECOND); } break; default: LogUtils.error(TAG, 'onCmdDataChange default'); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); break; } }) @@ -219,14 +219,14 @@ export default struct FingerprintAuth { } countTime(freezingTime): void { - const TRY_AGAIN = globalThis.context.resourceManager + const TRY_AGAIN = globalContext.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 + promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalContext); + promptText = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_many_failures')) + promptText + TRY_AGAIN; setTimeout(this.countTime.bind(this), INTERVAL, freezingTime - INTERVAL); } else { @@ -251,6 +251,8 @@ export default struct FingerprintAuth { ?.getStringSync($r('app.string.unified_authwidget_hint_normal_fp_only')): { return $r('sys.color.ohos_id_color_text_secondary'); } + default: + return $r('sys.color.ohos_id_color_text_secondary'); } } @@ -262,6 +264,8 @@ export default struct FingerprintAuth { return $r('app.media.icon_applock_3'); case 'SIDE': return $r('app.media.icon_applock_4'); + default: + return $r('app.media.icon_applock_3'); } } @@ -269,9 +273,10 @@ export default struct FingerprintAuth { if (this.state === SIX_PIN || this.state === MULTI_PIN) { AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypePin]); } else { - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, globalThis?.wantParams?.type || []); + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || + globalWantParams?.type as string[]); } - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } toPin(): void { @@ -299,16 +304,16 @@ export default struct FingerprintAuth { }) { if (this.isOffFinger) { Column() { - if ([PIN_FINGER, SINGLE_FINGER].includes(this.state)) { - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if ([PIN_FINGER, SINGLE_FINGER].includes(this.state) && this.fingerPosition !== undefined) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) .fontWeight(FontWeight.Medium) - Image(this.getFingerPosition(this.fingerPosition?.outOfScreenSensorType)) + Image(this.getFingerPosition(this.fingerPosition.outOfScreenSensorType as string)) .draggable(false) .width($r('app.float.image_big')) .height($r('app.float.image_big')) @@ -316,7 +321,7 @@ export default struct FingerprintAuth { .id('outFingerImage') Text(this.prompt) .draggable(false) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) .fontSize($r('sys.float.ohos_id_text_size_body2')) }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) } @@ -326,14 +331,14 @@ export default struct FingerprintAuth { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .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')) .height($r('app.float.size_24')) .fontWeight(FontWeight.Medium) - Image(this.getFingerPosition(this.fingerPosition?.outOfScreenSensorType)) + Image(this.getFingerPosition(this.fingerPosition.outOfScreenSensorType as string)) .draggable(false) .width($r('app.float.image_big')) .height($r('app.float.image_big')) @@ -341,7 +346,7 @@ export default struct FingerprintAuth { .id('outFingerImage') Text(this.prompt) .draggable(false) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) .fontSize($r('sys.float.ohos_id_text_size_body2')) } } @@ -388,7 +393,7 @@ 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 === SINGLE_FINGER) { - if (!globalThis.wantParams?.navigationButtonText) { + if (!(globalWantParams?.navigationButtonText as string)) { Row() { Column() { Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) @@ -430,11 +435,11 @@ export default struct FingerprintAuth { .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { - Button(globalThis.wantParams?.navigationButtonText) + Button(globalWantParams?.navigationButtonText as string) .onClick(() => { AuthUtils.getInstance() .sendNotice('EVENT_AUTH_USER_NAVIGATION', [Constants.noticeTypeFinger]); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); }) .margin({ right: $r('app.float.content_padding') }) .width(Constants.ninetyPercentWidth) @@ -617,12 +622,12 @@ export default struct FingerprintAuth { right: ($r('sys.float.ohos_id_dialog_margin_end')), bottom: this.IS_LANDSCAPE ? '0' : ($r('sys.float.ohos_id_dialog_margin_bottom')) }) - } else if (this.state === PIN_FINGER) { + } else if (this.state === PIN_FINGER && this.fingerPosition.udSensorRadiusInPx !== undefined ) { Column() { if (this.screenType === ON_SCREEN) { - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -635,7 +640,7 @@ export default struct FingerprintAuth { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .margin({ top: $r('app.float.title_padding_top') }) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -643,7 +648,7 @@ export default struct FingerprintAuth { .height($r('app.float.size_24')) .fontWeight(FontWeight.Medium) } - Image(this.prompt === globalThis.context.resourceManager + Image(this.prompt === globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) .draggable(false) @@ -660,7 +665,7 @@ export default struct FingerprintAuth { }) Text(this.prompt) .draggable(false) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) .fontSize($r('sys.float.ohos_id_text_size_body2')) Row() { Column() { @@ -734,10 +739,10 @@ export default struct FingerprintAuth { }) } - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -747,7 +752,7 @@ export default struct FingerprintAuth { .margin({ top: $r('app.float.element_margin') }) .height($r('app.float.size_24')) .fontSize($r('sys.float.ohos_id_text_size_body2')) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) } .width('100%') @@ -755,7 +760,7 @@ export default struct FingerprintAuth { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -766,9 +771,9 @@ export default struct FingerprintAuth { .margin({ top: $r('app.float.element_margin') }) .height($r('app.float.size_24')) .fontSize($r('sys.float.ohos_id_text_size_body2')) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) } - Image(this.prompt === globalThis.context.resourceManager + Image(this.prompt === globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) .draggable(false) @@ -794,10 +799,10 @@ export default struct FingerprintAuth { }) } else if (this.state === SINGLE_FINGER) { Column() { - if (this.screenType === ON_SCREEN) { - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (this.screenType === ON_SCREEN && this.fingerPosition.udSensorRadiusInPx !== undefined) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -810,7 +815,7 @@ export default struct FingerprintAuth { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .margin({ top: $r('app.float.title_padding_top') }) .fontSize($r('sys.float.ohos_id_text_size_body1')) @@ -818,7 +823,7 @@ export default struct FingerprintAuth { .height($r('app.float.size_24')) .fontWeight(FontWeight.Medium) } - Image(this.prompt === globalThis.context.resourceManager + Image(this.prompt === globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) .draggable(false) @@ -835,9 +840,9 @@ export default struct FingerprintAuth { }) Text(this.prompt) .draggable(false) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) .fontSize($r('sys.float.ohos_id_text_size_body2')) - if (!globalThis.wantParams?.navigationButtonText) { + if (!(globalWantParams?.navigationButtonText as string)) { Row() { Column() { Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) @@ -879,11 +884,11 @@ export default struct FingerprintAuth { .color($r('sys.color.ohos_id_color_list_separator')) .width($r('app.float.divider_width')) Column() { - Button(globalThis.wantParams?.navigationButtonText) + Button((globalWantParams?.navigationButtonText as string)) .onClick(() => { AuthUtils.getInstance() .sendNotice('EVENT_AUTH_USER_NAVIGATION', [Constants.noticeTypeFinger]); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); }) .id('navigationButtonTextFingerprintAuth') .margin({ right: $r('app.float.content_padding') }) @@ -898,7 +903,7 @@ 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.screenType === UNDER_SCREEN) { + } else if (this.screenType === UNDER_SCREEN && this.fingerPosition.udSensorRadiusInPx !== undefined) { Flex({ justifyContent: FlexAlign.SpaceBetween }) { Image($r('app.media.ic_public_cancel')) .draggable(false) @@ -913,8 +918,8 @@ export default struct FingerprintAuth { this.handleCancel(); this.textValue = ''; }) - if (globalThis.wantParams?.navigationButtonText) { - Button(globalThis.wantParams?.navigationButtonText) + if (globalWantParams?.navigationButtonText as string) { + Button(globalWantParams?.navigationButtonText as string) .id('fingerUnderButton') .backgroundColor(Color.White) .height($r('app.float.digital_password_mask_height')) @@ -929,15 +934,15 @@ export default struct FingerprintAuth { .onClick(() => { AuthUtils.getInstance() .sendNotice('EVENT_AUTH_USER_NAVIGATION', [Constants.noticeTypeFinger]); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); }) } } - if (AppStorage.Get('titleLength') < globalThis.wantParams?.title.length) { + if (AppStorage.Get('titleLength') as number < (globalWantParams?.title as string).length) { Scroll() { Column() { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -947,7 +952,7 @@ export default struct FingerprintAuth { .margin({ top: $r('app.float.element_margin') }) .height($r('app.float.size_24')) .fontSize($r('sys.float.ohos_id_text_size_body2')) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) } .width('100%') @@ -955,7 +960,7 @@ export default struct FingerprintAuth { .scrollable(ScrollDirection.Vertical) .scrollBarColor(Color.Gray) } else { - Text(globalThis.wantParams?.title) + Text(globalWantParams?.title as string) .draggable(false) .fontSize($r('sys.float.ohos_id_text_size_body1')) .fontColor($r('sys.color.ohos_id_color_text_primary')) @@ -966,9 +971,9 @@ export default struct FingerprintAuth { .margin({ top: $r('app.float.element_margin') }) .height($r('app.float.size_24')) .fontSize($r('sys.float.ohos_id_text_size_body2')) - .fontColor(this.onFingerPrintFontColor(this.prompt, globalThis.context)) + .fontColor(this.onFingerPrintFontColor(this.prompt, globalContext)) } - Image(this.prompt === globalThis.context.resourceManager + Image(this.prompt === globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success')) ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) .draggable(false) diff --git a/entry/src/main/ets/pages/components/PasswordAuth.ets b/entry/src/main/ets/pages/components/PasswordAuth.ets index 90144e15cdc1e2b874d882b731cc0ee6cacccf06..69fa2839c5d6b51b65e87088b126f4b76b721e8a 100644 --- a/entry/src/main/ets/pages/components/PasswordAuth.ets +++ b/entry/src/main/ets/pages/components/PasswordAuth.ets @@ -21,6 +21,7 @@ import FuncUtils from '../../common/utils/FuncUtils'; import LogUtils from '../../common/utils/LogUtils'; import TimeUtils from '../../common/utils/TimeUtils'; import Constants, { CmdType } from '../../common/vm/Constants'; +import { globalContext, globalSession, globalWantParams } from '../../extensionability/UserAuthAbility'; const TAG = 'PasswordAuth'; const INTERVAL = 1000; @@ -29,7 +30,7 @@ const TEXT_LENGTH = 4; const MAX_FAIL_TIMES = 5; const HINT_TIMES_BY_FAIL_LESS = 3; -let pinAuthManager; +let pinAuthManager : account_osAccount.PINAuth; let pinData = ''; @Component @@ -52,15 +53,15 @@ export default struct PasswordAuth { const { type, remainAttempts, lockoutDuration, result } = item.payload; if (type === Constants.noticeTypePin) { if (remainAttempts && remainAttempts < MAX_FAIL_TIMES) { - this.inputValue = globalThis.context.resourceManager + this.inputValue = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_pwd_error')); this.textValue = ''; // pin auth Remaining number if (remainAttempts < HINT_TIMES_BY_FAIL_LESS) { - this.inputValue = globalThis.context.resourceManager + this.inputValue = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try')) - + remainAttempts + globalThis.context.resourceManager + + remainAttempts + globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_frequency')); } if (num === 'first') { @@ -76,7 +77,7 @@ export default struct PasswordAuth { return; } if (result === 0) { - globalThis.session?.terminateSelf(); + globalSession?.terminateSelf(); } this.inputValue = ' '; this.textValue = ''; @@ -101,7 +102,7 @@ export default struct PasswordAuth { }); } catch (error) { LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); - globalThis.session?.terminateSelf?.(); + globalSession?.terminateSelf?.(); } } @@ -111,12 +112,12 @@ export default struct PasswordAuth { } countTime(freezingTime): void { - const TRY_AGAIN = globalThis.context.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); + const TRY_AGAIN = globalContext.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry')); let promptText: string = ''; let freezingMillisecond = freezingTime; if (freezingMillisecond > 0) { - promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalThis.context); - promptText = globalThis.context.resourceManager + promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, globalContext); + promptText = globalContext.resourceManager .getStringSync($r('app.string.unified_authwidget_many_failures')) + promptText + TRY_AGAIN; setTimeout(this.countTime.bind(this), INTERVAL, freezingTime - INTERVAL); } else { @@ -127,8 +128,9 @@ export default struct PasswordAuth { } handleCancel(): void { - AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, globalThis?.wantParams?.type || []); - globalThis.session?.terminateSelf?.(); + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || + globalWantParams?.type as string[]); + globalSession?.terminateSelf?.(); } build() {