1/** 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import account_osAccount from '@ohos.account.osAccount'; 17import display from '@ohos.display'; 18import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 19import PassWord from '../../common/components/PassWord'; 20import SixPassword from '../../common/components/SixPassword'; 21import { DialogType } from '../../common/module/DialogType'; 22import AuthUtils from '../../common/utils/AuthUtils'; 23import FuncUtils from '../../common/utils/FuncUtils'; 24import LogUtils from '../../common/utils/LogUtils'; 25import TimeUtils from '../../common/utils/TimeUtils'; 26import Constants, { CmdData, CmdType, FingerPosition, WantParams } from '../../common/vm/Constants'; 27import common from '@ohos.app.ability.common'; 28 29const TAG = 'FingerprintAuth'; 30const INTERVAL = 1000; 31let pinAuthManager: account_osAccount.PINAuth; 32let pinData = ''; 33const THOUSANDTH = 1000; 34const BOTTOM_BUTTON = 56; 35const BOTTOM_TEXT = 20; 36const PADDING_8 = 8; 37const PADDING_24 = 24; 38const SINGLE_FINGER = 1; 39const PIN_FINGER = 2; 40const SIX_PIN = 6; 41const MULTI_PIN = 5; 42const RADIUS = 2; 43const PIN_FAIL_TIP = 3; 44const AUTH_LOCK = 0; 45const NOTICE_DELAY = 50; 46const ON_SCREEN = 1; 47const UNDER_SCREEN = 2; 48const FINGER_SENSOR_POSITION_LINE = 0.75; 49const SECOND = 1000; 50 51@Component 52export default struct FingerprintAuth { 53 @Link type: string; 54 @Link pinSubType: string; 55 @Link dialogType: DialogType; 56 @State prompt: string = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 57 .getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp').id); 58 @State @Watch('onTextValueChange') textValue: string = ''; 59 @Link @Watch('onCmdDataChange') cmdData: Array<CmdType>; 60 @State isEdit: boolean = true; 61 @State inputValue: string = ''; 62 @State state: number = this.dialogType === DialogType.PIN_FINGER ? PIN_FINGER : SINGLE_FINGER; 63 @State fingerPositionY: number = 0; 64 @State fingerPosition: FingerPosition = { 65 sensorType: '', 66 udSensorRadiusInPx: 60 67 } 68 @State fingerLock: boolean = false; 69 @StorageLink('SYSTEM_NAVIGATION_BAR_HEIGHT') SYSTEM_NAVIGATION_BAR_HEIGHT: number = 0; 70 @State screen: number[] = []; 71 @StorageLink('IS_LANDSCAPE') IS_LANDSCAPE: boolean = false; 72 @State isOffFinger: boolean = false; 73 @State screenType: number = 0; 74 75 aboutToAppear(): void { 76 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); 77 try { 78 if (this.cmdData && this.cmdData.length > 0) { 79 this.onCmdDataChange('first'); 80 } 81 if (this.fingerPosition.udSensorCenterYInThousandth !== undefined && (this.screenType === ON_SCREEN || 82 this.screenType === UNDER_SCREEN)) { 83 let tempPositionY = px2vp(this.fingerPosition.udSensorCenterYInThousandth * this.screen[1]); 84 FuncUtils.judgmentOverflow(tempPositionY); 85 if (this.screenType === ON_SCREEN) { 86 this.fingerPositionY = px2vp(this.screen[1]) - tempPositionY / THOUSANDTH + BOTTOM_BUTTON + 87 PADDING_8 + BOTTOM_TEXT + PADDING_24; 88 } else if (this.screenType === UNDER_SCREEN) { 89 this.fingerPositionY = px2vp(this.screen[1]) - tempPositionY / THOUSANDTH + PADDING_24; 90 } 91 FuncUtils.judgmentOverflow(this.fingerPositionY); 92 } 93 LogUtils.info(TAG, 'aboutToAppear this.fingerPositionY: ' + this.fingerPositionY); 94 pinAuthManager = new account_osAccount.PINAuth(); 95 pinAuthManager.registerInputer({ 96 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 97 LogUtils.info(TAG, 'aboutToAppear registerInputer onGetData'); 98 let uint8PW = FuncUtils.getUint8PW(pinData); 99 callback.onSetData(authSubType, uint8PW); 100 } 101 }); 102 } catch (error) { 103 LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); 104 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 105 } 106 } 107 108 aboutToDisappear(): void { 109 LogUtils.info(TAG, 'PINAuth unregisterInputer'); 110 pinAuthManager?.unregisterInputer?.(); 111 } 112 113 onTextValueChange(): void { 114 pinData = this.textValue; 115 } 116 117 onCmdDataChange(num?: string): void { 118 this.cmdData.length > 0 && this.cmdData.map((item) => { 119 const payload: CmdData = item.payload; 120 if (payload.type === Constants.noticeTypePin) { 121 if (payload.result === 0) { 122 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 123 } else if (payload.result && payload.result === Constants.authResultPinExpired) { 124 this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 125 .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); 126 this.textValue = ''; 127 return; 128 } else { 129 if (payload.remainAttempts) { 130 this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 131 .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); 132 this.textValue = ''; 133 if (num === 'first') { 134 this.inputValue = ''; 135 } 136 if (payload.remainAttempts < PIN_FAIL_TIP) { 137 this.inputValue = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 138 .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + 139 payload.remainAttempts + (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 140 .getStringSync($r('app.string.unified_authwidget_frequency').id); 141 } 142 } 143 if (payload.remainAttempts === AUTH_LOCK && payload.lockoutDuration) { 144 this.countTime(payload.lockoutDuration); 145 this.textValue = ''; 146 this.toPin(); 147 this.isEdit = false; 148 } 149 } 150 } else if (payload.type === Constants.noticeTypeFinger) { 151 if ([MULTI_PIN, SIX_PIN].includes(this.state)) { 152 return; 153 } 154 const displayClass = display.getDefaultDisplaySync(); 155 this.screen = [displayClass.width, displayClass.height]; 156 if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { 157 this.fingerPosition = JSON.parse(payload.sensorInfo); 158 switch (this.fingerPosition.sensorType) { 159 case 'OUT_OF_SCREEN_SENSOR': { 160 this.isOffFinger = true; 161 break; 162 } 163 default: 164 let tempPositionLine = JSON.parse(payload.sensorInfo).udSensorCenterYInThousandth / displayClass.height; 165 FuncUtils.judgmentOverflow(tempPositionLine); 166 if (tempPositionLine < FINGER_SENSOR_POSITION_LINE) { 167 this.screenType = ON_SCREEN; 168 } else if (tempPositionLine > FINGER_SENSOR_POSITION_LINE) { 169 this.screenType = UNDER_SCREEN; 170 } 171 break; 172 } 173 } 174 if ((payload.remainAttempts && payload.result !== 0) || payload.result === Constants.authResultPinExpired) { 175 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 176 .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); 177 this.fingerLock = false; 178 } 179 if (num === 'first') { 180 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 181 .getStringSync(this.isOffFinger ? 182 $r('app.string.unified_authwidget_hint_normal_fp_only').id : 183 $r('app.string.unified_authwidget_hint_inscreen_fp').id); 184 } 185 if (payload.remainAttempts === AUTH_LOCK) { 186 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 187 .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); 188 this.fingerLock = true; 189 if (this.dialogType === DialogType.PIN_FINGER) { 190 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFinger]); 191 if (this.pinSubType !== Constants.pinSix) { 192 this.state = MULTI_PIN; 193 } else { 194 this.state = SIX_PIN; 195 } 196 } 197 } 198 if (payload.result === 0) { 199 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 200 .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) 201 setTimeout(() => { 202 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 203 }, SECOND); 204 } 205 } else { 206 LogUtils.error(TAG, 'onCmdDataChange default'); 207 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 208 } 209 }) 210 } 211 212 sendFingerEvent(): void { 213 if (!this.fingerLock) { 214 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); 215 } 216 } 217 218 countTime(freezingTime: number): void { 219 const TRY_AGAIN = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 220 .getStringSync($r('app.string.unified_authwidget_postretry').id); 221 let promptText: string = ''; 222 let freezingMillisecond = freezingTime; 223 // O: freezing FINISH 224 if (freezingMillisecond > 0) { 225 promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, (AppStorage.get('context') as common.ExtensionContext)); 226 promptText = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 227 .getStringSync($r('app.string.unified_authwidget_many_failures').id) + promptText + TRY_AGAIN; 228 setTimeout((t: number):void => this.countTime(t), INTERVAL, freezingTime - INTERVAL); 229 } else { 230 promptText = ' '; 231 this.isEdit = true; 232 } 233 this.inputValue = promptText; 234 } 235 236 onFingerPrintFontColor(prompt: string, context: Context): Resource { 237 if (prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id) || 238 prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id)) { 239 return $r('sys.color.ohos_id_color_warning'); 240 } else if (prompt === context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) || 241 context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp').id) || 242 context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hint_normal_fp_only').id)) { 243 return $r('sys.color.ohos_id_color_text_secondary'); 244 } else { 245 return $r('sys.color.ohos_id_color_text_secondary'); 246 } 247 } 248 249 getFingerPosition(type: string): Resource { 250 switch (type) { 251 case 'BACK': 252 return $r('app.media.icon_applock_2'); 253 case 'FRONT': 254 return $r('app.media.icon_applock_3'); 255 case 'SIDE': 256 return $r('app.media.icon_applock_4'); 257 default: 258 return $r('app.media.icon_applock_3'); 259 } 260 } 261 262 handleCancel(): void { 263 if (this.state === SIX_PIN || this.state === MULTI_PIN) { 264 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypePin]); 265 } else { 266 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || 267 (AppStorage.get('wantParams') as WantParams)?.type as string[]); 268 } 269 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 270 } 271 272 toPin(): void { 273 LogUtils.debug(TAG, 'toPin this.pinSubType: ' + this.pinSubType); 274 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFinger]); 275 if (this.pinSubType !== Constants.pinSix) { 276 this.state = MULTI_PIN; 277 } else { 278 this.state = SIX_PIN; 279 } 280 } 281 282 build() { 283 Column() { 284 GridRow({ 285 columns: { xs: 4, sm: 4, md: 8, lg: 12 }, 286 gutter: { x: 24, y: 24 }, 287 breakpoints: { value: Constants.deviceDpi, 288 reference: BreakpointsReference.WindowSize }, 289 direction: GridRowDirection.Row 290 }) { 291 GridCol({ 292 span: { xs: 4, sm: 4, md: 4, lg: 6 }, 293 offset: { md: 2, lg: 3 }, 294 }) { 295 if (this.isOffFinger) { 296 Column() { 297 if ([PIN_FINGER, SINGLE_FINGER].includes(this.state) && this.fingerPosition !== undefined) { 298 if (AppStorage.Get('titleLength') as number < (AppStorage.get('wantParams') as WantParams)?.title.length) { 299 Scroll() { 300 Column() { 301 Text((AppStorage.get('wantParams') as WantParams)?.title) 302 .draggable(false) 303 .fontSize($r('sys.float.ohos_id_text_size_body1')) 304 .fontColor($r('sys.color.ohos_id_color_text_primary')) 305 .fontWeight(FontWeight.Medium) 306 Image(this.getFingerPosition(this.fingerPosition.outOfScreenSensorType as string)) 307 .draggable(false) 308 .width($r('app.float.image_big')) 309 .height($r('app.float.image_big')) 310 .margin({ top: $r('app.float.content_padding'), bottom: $r('app.float.content_padding') }) 311 .id('outFingerImage') 312 Text(this.prompt) 313 .draggable(false) 314 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 315 .fontSize($r('sys.float.ohos_id_text_size_body2')) 316 }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) 317 } 318 .width('100%') 319 .height($r('app.float.scroll_height_220')) 320 .margin({ top: $r('app.float.title_padding_top') }) 321 .scrollable(ScrollDirection.Vertical) 322 .scrollBarColor(Color.Gray) 323 } else { 324 Text((AppStorage.get('wantParams') as WantParams)?.title) 325 .draggable(false) 326 .margin({ top: $r('app.float.title_padding_top') }) 327 .fontSize($r('sys.float.ohos_id_text_size_body1')) 328 .fontColor($r('sys.color.ohos_id_color_text_primary')) 329 .height($r('app.float.size_24')) 330 .fontWeight(FontWeight.Medium) 331 Image(this.getFingerPosition(this.fingerPosition.outOfScreenSensorType as string)) 332 .draggable(false) 333 .width($r('app.float.image_big')) 334 .height($r('app.float.image_big')) 335 .margin({ top: $r('app.float.content_padding'), bottom: $r('app.float.content_padding') }) 336 .id('outFingerImage') 337 Text(this.prompt) 338 .draggable(false) 339 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 340 .fontSize($r('sys.float.ohos_id_text_size_body2')) 341 } 342 } 343 344 if (this.state === PIN_FINGER) { 345 Row() { 346 Column() { 347 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 348 .id('cancelBthState3FingerprintAuth') 349 .margin({ left: $r('app.float.content_padding') }) 350 .width(Constants.ninetyPercentWidth) 351 .height($r('app.float.btn_height')) 352 .fontSize($r('sys.float.ohos_id_text_size_button1')) 353 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 354 .fontWeight(FontWeight.Medium) 355 .backgroundColor(Color.Transparent) 356 .onClick(() => { 357 this.handleCancel(); 358 this.textValue = ''; 359 }) 360 }.width(Constants.halfContainerWidth) 361 362 Divider() 363 .vertical(true) 364 .height($r('app.float.digital_password_mask_height')) 365 .color($r('sys.color.ohos_id_color_list_separator')) 366 .width($r('app.float.divider_width')) 367 Column() { 368 Button($r('app.string.unified_authwidget_usepwd')) 369 .id('usePwdBtnState3FingerprintAuth') 370 .margin({ right: $r('app.float.content_padding') }) 371 .width(Constants.ninetyPercentWidth) 372 .height($r('app.float.btn_height')) 373 .fontSize($r('sys.float.ohos_id_text_size_button1')) 374 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 375 .fontWeight(FontWeight.Medium) 376 .backgroundColor(Color.Transparent) 377 .onClick(() => { 378 this.inputValue = ' '; 379 this.toPin(); 380 }) 381 }.width(Constants.halfContainerWidth) 382 } 383 .height($r('app.float.btn_height')) 384 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 385 } else if (this.state === SINGLE_FINGER) { 386 if (!((AppStorage.get('wantParams') as WantParams)?.navigationButtonText as string)) { 387 Row() { 388 Column() { 389 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 390 .id('cancelDefBtnState3FingerprintAuth') 391 .onClick(() => { 392 this.handleCancel(); 393 }) 394 .backgroundColor(Color.Transparent) 395 .height($r('app.float.btn_height')) 396 .width(Constants.halfContainerWidth) 397 .fontSize($r('sys.float.ohos_id_text_size_button1')) 398 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 399 .fontWeight(FontWeight.Medium) 400 }.width(Constants.fullContainerHeight) 401 } 402 .height($r('app.float.btn_height')) 403 .padding({ left: $r('app.float.content_padding'), right: $r('app.float.content_padding') }) 404 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 405 } else { 406 Row() { 407 Column() { 408 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 409 .id('cancelBtnState3FingerprintAuth') 410 .margin({ left: $r('app.float.content_padding') }) 411 .width(Constants.ninetyPercentWidth) 412 .height($r('app.float.btn_height')) 413 .fontSize($r('sys.float.ohos_id_text_size_button1')) 414 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 415 .fontWeight(FontWeight.Medium) 416 .backgroundColor(Color.Transparent) 417 .onClick(() => { 418 this.handleCancel(); 419 }) 420 }.width(Constants.halfContainerWidth) 421 422 Divider() 423 .vertical(true) 424 .height($r('app.float.digital_password_mask_height')) 425 .color($r('sys.color.ohos_id_color_list_separator')) 426 .width($r('app.float.divider_width')) 427 Column() { 428 Button((AppStorage.get('wantParams') as WantParams)?.navigationButtonText as string) 429 .onClick(() => { 430 AuthUtils.getInstance() 431 .sendNotice('EVENT_AUTH_USER_NAVIGATION', [Constants.noticeTypeFinger]); 432 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 433 }) 434 .margin({ right: $r('app.float.content_padding') }) 435 .width(Constants.ninetyPercentWidth) 436 .height($r('app.float.btn_height')) 437 .fontSize($r('sys.float.ohos_id_text_size_button1')) 438 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 439 .fontWeight(FontWeight.Medium) 440 .backgroundColor(Color.Transparent) 441 }.width(Constants.halfContainerWidth) 442 } 443 .height($r('app.float.btn_height')) 444 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 445 } 446 } else if (this.state === MULTI_PIN) { 447 // Password 32-bit 448 Column() { 449 PassWord({ 450 textValue: $textValue, 451 inputValue: $inputValue, 452 isEdit: $isEdit, 453 pinSubType: $pinSubType 454 }) 455 Row() { 456 Column() { 457 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 458 .id('cancelStateMultiFingerprintAuth') 459 .margin({ left: $r('app.float.content_padding') }) 460 .width(Constants.ninetyPercentWidth) 461 .height($r('app.float.btn_height')) 462 .fontSize($r('sys.float.ohos_id_text_size_button1')) 463 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 464 .fontWeight(FontWeight.Medium) 465 .backgroundColor(Color.Transparent) 466 .onClick(() => { 467 this.handleCancel(); 468 this.textValue = ''; 469 }) 470 }.width(Constants.halfContainerWidth) 471 472 Divider() 473 .vertical(true) 474 .height($r('app.float.digital_password_mask_height')) 475 .color($r('sys.color.ohos_id_color_list_separator')) 476 .width($r('app.float.divider_width')) 477 Column() { 478 Button($r('app.string.unified_authwidget_confirm')) 479 .margin({ right: $r('app.float.content_padding') }) 480 .width(Constants.ninetyPercentWidth) 481 .height($r('app.float.btn_height')) 482 .fontSize($r('sys.float.ohos_id_text_size_button1')) 483 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 484 .fontWeight(FontWeight.Medium) 485 .backgroundColor(Color.Transparent) 486 .onClick(async (e) => { 487 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 488 }) 489 }.width(Constants.halfContainerWidth) 490 } 491 .height($r('app.float.btn_height')) 492 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 493 } 494 } else if (this.state === SIX_PIN) { 495 // Password 6-bit 496 Column() { 497 SixPassword({ 498 textValue: $textValue, 499 inputValue: $inputValue, 500 isEdit: $isEdit 501 }) 502 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 503 .id('cancelState6FingerprintAuth') 504 .onClick(() => { 505 this.handleCancel(); 506 this.textValue = ''; 507 }) 508 .backgroundColor(Color.Transparent) 509 .height($r('app.float.btn_height')) 510 .width(Constants.halfContainerWidth) 511 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 512 .fontSize($r('sys.float.ohos_id_text_size_button1')) 513 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 514 .fontWeight(FontWeight.Medium) 515 } 516 } 517 } 518 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 519 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 520 .margin({ 521 left: ($r('sys.float.ohos_id_dialog_margin_start')), 522 right: ($r('sys.float.ohos_id_dialog_margin_end')), 523 bottom: this.IS_LANDSCAPE ? '0' : ($r('sys.float.ohos_id_dialog_margin_bottom')) 524 }) 525 } else { 526 if (this.state === MULTI_PIN) { 527 Column() { 528 // Password 32-bit 529 Column() { 530 PassWord({ 531 textValue: $textValue, 532 inputValue: $inputValue, 533 isEdit: $isEdit, 534 pinSubType: $pinSubType 535 }) 536 Row() { 537 Column() { 538 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 539 .id('cancelBtnState5FingerprintAuth') 540 .margin({ left: $r('app.float.content_padding') }) 541 .width(Constants.ninetyPercentWidth) 542 .height($r('app.float.btn_height')) 543 .fontSize($r('sys.float.ohos_id_text_size_button1')) 544 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 545 .fontWeight(FontWeight.Medium) 546 .backgroundColor(Color.Transparent) 547 .onClick(() => { 548 this.handleCancel(); 549 this.textValue = ''; 550 }) 551 }.width(Constants.halfContainerWidth) 552 553 Divider() 554 .vertical(true) 555 .height($r('app.float.digital_password_mask_height')) 556 .color($r('sys.color.ohos_id_color_list_separator')) 557 .width($r('app.float.divider_width')) 558 Column() { 559 Button($r('app.string.unified_authwidget_confirm')) 560 .id('okBthState5FingerprintAuth') 561 .margin({ right: $r('app.float.content_padding') }) 562 .width(Constants.ninetyPercentWidth) 563 .height($r('app.float.btn_height')) 564 .fontSize($r('sys.float.ohos_id_text_size_button1')) 565 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 566 .fontWeight(FontWeight.Medium) 567 .backgroundColor(Color.Transparent) 568 .onClick(async (e) => { 569 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 570 }) 571 }.width(Constants.halfContainerWidth) 572 } 573 .height($r('app.float.btn_height')) 574 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 575 } 576 } 577 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 578 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 579 .margin({ 580 left: ($r('sys.float.ohos_id_dialog_margin_start')), 581 right: ($r('sys.float.ohos_id_dialog_margin_end')), 582 bottom: this.IS_LANDSCAPE ? '0' : ($r('sys.float.ohos_id_dialog_margin_bottom')) 583 }) 584 } else if (this.state === SIX_PIN) { 585 Column() { 586 // Password 6-bit 587 Column() { 588 SixPassword({ 589 textValue: $textValue, 590 inputValue: $inputValue, 591 isEdit: $isEdit 592 }) 593 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 594 .id('sixPassCancel') 595 .onClick(() => { 596 this.handleCancel(); 597 this.textValue = ''; 598 }) 599 .backgroundColor(Color.Transparent) 600 .height($r('app.float.btn_height')) 601 .width(Constants.halfContainerWidth) 602 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 603 .fontSize($r('sys.float.ohos_id_text_size_button1')) 604 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 605 .fontWeight(FontWeight.Medium) 606 } 607 } 608 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 609 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 610 .margin({ 611 left: ($r('sys.float.ohos_id_dialog_margin_start')), 612 right: ($r('sys.float.ohos_id_dialog_margin_end')), 613 bottom: this.IS_LANDSCAPE ? '0' : ($r('sys.float.ohos_id_dialog_margin_bottom')) 614 }) 615 } else if (this.state === PIN_FINGER && this.fingerPosition.udSensorRadiusInPx !== undefined ) { 616 Column() { 617 if (this.screenType === ON_SCREEN) { 618 if (AppStorage.Get('titleLength') as number < (AppStorage.get('wantParams') as WantParams)?.title.length) { 619 Scroll() { 620 Text((AppStorage.get('wantParams') as WantParams)?.title) 621 .draggable(false) 622 .fontSize($r('sys.float.ohos_id_text_size_body1')) 623 .fontColor($r('sys.color.ohos_id_color_text_primary')) 624 .fontWeight(FontWeight.Medium) 625 .margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) 626 } 627 .width('100%') 628 .height($r('app.float.textArea_height')) 629 .margin({ top: $r('app.float.title_padding_top') }) 630 .scrollable(ScrollDirection.Vertical) 631 .scrollBarColor(Color.Gray) 632 } else { 633 Text((AppStorage.get('wantParams') as WantParams)?.title) 634 .draggable(false) 635 .margin({ top: $r('app.float.title_padding_top') }) 636 .fontSize($r('sys.float.ohos_id_text_size_body1')) 637 .fontColor($r('sys.color.ohos_id_color_text_primary')) 638 .height($r('app.float.size_24')) 639 .fontWeight(FontWeight.Medium) 640 } 641 Image(this.prompt === (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 642 .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) 643 ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) 644 .draggable(false) 645 .margin({ 646 top: $r('app.float.digital_password_mask_height'), 647 bottom: $r('app.float.digital_password_mask_height') 648 }) 649 .id('blueFingerprintImgState2FingerprintAuth') 650 .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 651 .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 652 .colorBlend($r('sys.color.ohos_id_color_activated')) 653 .onClick(() => { 654 this.sendFingerEvent(); 655 }) 656 Text(this.prompt) 657 .draggable(false) 658 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 659 .fontSize($r('sys.float.ohos_id_text_size_body2')) 660 Row() { 661 Column() { 662 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 663 .id('cancelBtnState2FingerprintAuth') 664 .margin({ left: $r('app.float.content_padding') }) 665 .width(Constants.ninetyPercentWidth) 666 .height($r('app.float.btn_height')) 667 .fontSize($r('sys.float.ohos_id_text_size_button1')) 668 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 669 .fontWeight(FontWeight.Medium) 670 .backgroundColor(Color.Transparent) 671 .onClick(() => { 672 this.handleCancel(); 673 this.textValue = ''; 674 }) 675 }.width(Constants.halfContainerWidth) 676 677 Divider() 678 .vertical(true) 679 .height($r('app.float.digital_password_mask_height')) 680 .color($r('sys.color.ohos_id_color_list_separator')) 681 .width($r('app.float.divider_width')) 682 Column() { 683 Button($r('app.string.unified_authwidget_usepwd')) 684 .id('usePwdBtnState2FingerprintAuth') 685 .margin({ right: $r('app.float.content_padding') }) 686 .width(Constants.ninetyPercentWidth) 687 .height($r('app.float.btn_height')) 688 .fontSize($r('sys.float.ohos_id_text_size_button1')) 689 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 690 .fontWeight(FontWeight.Medium) 691 .backgroundColor(Color.Transparent) 692 .onClick(() => { 693 this.inputValue = ' '; 694 this.toPin(); 695 }) 696 }.width(Constants.halfContainerWidth) 697 } 698 .height($r('app.float.btn_height')) 699 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 700 } else if (this.screenType === UNDER_SCREEN) { 701 Flex({ justifyContent: FlexAlign.SpaceBetween }) { 702 Image($r('app.media.ic_public_cancel')) 703 .draggable(false) 704 .id('cancelBtnState4FingerprintAuth') 705 .width($r('app.float.digital_password_mask_height')) 706 .height($r('app.float.digital_password_mask_height')) 707 .margin({ 708 top: $r('app.float.digital_password_mask_height'), 709 left: $r('app.float.digital_password_mask_height') 710 }) 711 .onClick(() => { 712 this.handleCancel(); 713 this.textValue = ''; 714 }) 715 Button($r('app.string.unified_authwidget_usepwd')) 716 .backgroundColor(Color.White) 717 .height($r('app.float.digital_password_mask_height')) 718 .padding(0) 719 .margin({ 720 top: $r('app.float.digital_password_mask_height'), 721 right: $r('app.float.digital_password_mask_height') 722 }) 723 .fontColor($r('sys.color.ohos_id_color_activated')) 724 .fontSize($r('sys.float.ohos_id_text_size_body1')) 725 .fontWeight(FontWeight.Medium) 726 .onClick(() => { 727 this.inputValue = ' '; 728 this.toPin(); 729 }) 730 } 731 732 if (AppStorage.Get('titleLength') as number < (AppStorage.get('wantParams') as WantParams)?.title.length) { 733 Scroll() { 734 Column() { 735 Text((AppStorage.get('wantParams') as WantParams)?.title) 736 .draggable(false) 737 .fontSize($r('sys.float.ohos_id_text_size_body1')) 738 .fontColor($r('sys.color.ohos_id_color_text_primary')) 739 .fontWeight(FontWeight.Medium) 740 Text(this.prompt) 741 .draggable(false) 742 .margin({ top: $r('app.float.element_margin') }) 743 .height($r('app.float.size_24')) 744 .fontSize($r('sys.float.ohos_id_text_size_body2')) 745 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 746 }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) 747 } 748 .width('100%') 749 .height($r('app.float.scroll_height_76')) 750 .scrollable(ScrollDirection.Vertical) 751 .scrollBarColor(Color.Gray) 752 } else { 753 Text((AppStorage.get('wantParams') as WantParams)?.title) 754 .draggable(false) 755 .fontSize($r('sys.float.ohos_id_text_size_body1')) 756 .fontColor($r('sys.color.ohos_id_color_text_primary')) 757 .height($r('app.float.size_24')) 758 .fontWeight(FontWeight.Medium) 759 Text(this.prompt) 760 .draggable(false) 761 .margin({ top: $r('app.float.element_margin') }) 762 .height($r('app.float.size_24')) 763 .fontSize($r('sys.float.ohos_id_text_size_body2')) 764 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 765 } 766 Image(this.prompt === (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 767 .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) 768 ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) 769 .draggable(false) 770 .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 771 .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 772 .margin({ 773 top: $r('app.float.digital_password_mask_height'), 774 bottom: $r('app.float.digital_password_mask_height') 775 }) 776 .colorBlend($r('sys.color.ohos_id_color_activated')) 777 .onClick(() => { 778 this.sendFingerEvent(); 779 }) 780 } 781 } 782 .position({ y: -Math.ceil(this.fingerPositionY) }) 783 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 784 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 785 .margin({ 786 left: ($r('sys.float.ohos_id_dialog_margin_start')), 787 right: ($r('sys.float.ohos_id_dialog_margin_end')), 788 bottom: ($r('sys.float.ohos_id_dialog_margin_bottom')) 789 }) 790 } else if (this.state === SINGLE_FINGER) { 791 Column() { 792 if (this.screenType === ON_SCREEN && this.fingerPosition.udSensorRadiusInPx !== undefined) { 793 if (AppStorage.Get('titleLength') as number < (AppStorage.get('wantParams') as WantParams)?.title.length) { 794 Scroll() { 795 Text((AppStorage.get('wantParams') as WantParams)?.title) 796 .draggable(false) 797 .fontSize($r('sys.float.ohos_id_text_size_body1')) 798 .fontColor($r('sys.color.ohos_id_color_text_primary')) 799 .fontWeight(FontWeight.Medium) 800 .margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) 801 } 802 .width('100%') 803 .height($r('app.float.textArea_height')) 804 .margin({ top: $r('app.float.title_padding_top') }) 805 .scrollable(ScrollDirection.Vertical) 806 .scrollBarColor(Color.Gray) 807 } else { 808 Text((AppStorage.get('wantParams') as WantParams)?.title) 809 .draggable(false) 810 .margin({ top: $r('app.float.title_padding_top') }) 811 .fontSize($r('sys.float.ohos_id_text_size_body1')) 812 .fontColor($r('sys.color.ohos_id_color_text_primary')) 813 .height($r('app.float.size_24')) 814 .fontWeight(FontWeight.Medium) 815 } 816 Image(this.prompt === (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 817 .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) 818 ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) 819 .draggable(false) 820 .margin({ 821 top: $r('app.float.digital_password_mask_height'), 822 bottom: $r('app.float.digital_password_mask_height') 823 }) 824 .id('blueFingerprintState1FingerprintAuth') 825 .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 826 .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 827 .colorBlend($r('sys.color.ohos_id_color_activated')) 828 .onClick(() => { 829 this.sendFingerEvent(); 830 }) 831 Text(this.prompt) 832 .draggable(false) 833 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 834 .fontSize($r('sys.float.ohos_id_text_size_body2')) 835 if (!((AppStorage.get('wantParams') as WantParams)?.navigationButtonText as string)) { 836 Row() { 837 Column() { 838 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 839 .id('cancelDefBtnState1FingerprintAuth') 840 .onClick(() => { 841 this.handleCancel(); 842 }) 843 .backgroundColor(Color.Transparent) 844 .height($r('app.float.btn_height')) 845 .width(Constants.halfContainerWidth) 846 .fontSize($r('sys.float.ohos_id_text_size_button1')) 847 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 848 .fontWeight(FontWeight.Medium) 849 }.width(Constants.fullContainerHeight) 850 } 851 .height($r('app.float.btn_height')) 852 .padding({ left: $r('app.float.content_padding'), right: $r('app.float.content_padding') }) 853 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 854 } else { 855 Row() { 856 Column() { 857 Button($r('app.string.unified_authwidget_cancel'), { stateEffect: true }) 858 .id('cancelBtnState1FingerprintAuth') 859 .margin({ left: $r('app.float.content_padding') }) 860 .width(Constants.ninetyPercentWidth) 861 .height($r('app.float.btn_height')) 862 .fontSize($r('sys.float.ohos_id_text_size_button1')) 863 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 864 .fontWeight(FontWeight.Medium) 865 .backgroundColor(Color.Transparent) 866 .onClick(() => { 867 this.handleCancel(); 868 }) 869 }.width(Constants.halfContainerWidth) 870 871 Divider() 872 .vertical(true) 873 .height($r('app.float.digital_password_mask_height')) 874 .color($r('sys.color.ohos_id_color_list_separator')) 875 .width($r('app.float.divider_width')) 876 Column() { 877 Button(((AppStorage.get('wantParams') as WantParams)?.navigationButtonText as string)) 878 .onClick(() => { 879 AuthUtils.getInstance() 880 .sendNotice('EVENT_AUTH_USER_NAVIGATION', [Constants.noticeTypeFinger]); 881 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 882 }) 883 .id('navigationButtonTextFingerprintAuth') 884 .margin({ right: $r('app.float.content_padding') }) 885 .width(Constants.ninetyPercentWidth) 886 .height($r('app.float.btn_height')) 887 .fontSize($r('sys.float.ohos_id_text_size_button1')) 888 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 889 .fontWeight(FontWeight.Medium) 890 .backgroundColor(Color.Transparent) 891 }.width(Constants.halfContainerWidth) 892 } 893 .height($r('app.float.btn_height')) 894 .margin({ top: $r('app.float.element_margin'), bottom: $r('app.float.content_padding') }) 895 } 896 } else if (this.screenType === UNDER_SCREEN && this.fingerPosition.udSensorRadiusInPx !== undefined) { 897 Flex({ justifyContent: FlexAlign.SpaceBetween }) { 898 Image($r('app.media.ic_public_cancel')) 899 .draggable(false) 900 .id('fingerUnderImage') 901 .width($r('app.float.digital_password_mask_height')) 902 .height($r('app.float.digital_password_mask_height')) 903 .margin({ 904 top: $r('app.float.digital_password_mask_height'), 905 left: $r('app.float.digital_password_mask_height') 906 }) 907 .onClick(() => { 908 this.handleCancel(); 909 this.textValue = ''; 910 }) 911 if ((AppStorage.get('wantParams') as WantParams)?.navigationButtonText as string) { 912 Button((AppStorage.get('wantParams') as WantParams)?.navigationButtonText as string) 913 .id('fingerUnderButton') 914 .backgroundColor(Color.White) 915 .height($r('app.float.digital_password_mask_height')) 916 .padding(0) 917 .margin({ 918 top: $r('app.float.digital_password_mask_height'), 919 right: $r('app.float.digital_password_mask_height') 920 }) 921 .fontColor($r('sys.color.ohos_id_color_activated')) 922 .fontSize($r('sys.float.ohos_id_text_size_body1')) 923 .fontWeight(FontWeight.Medium) 924 .onClick(() => { 925 AuthUtils.getInstance() 926 .sendNotice('EVENT_AUTH_USER_NAVIGATION', [Constants.noticeTypeFinger]); 927 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 928 }) 929 } 930 } 931 932 if (AppStorage.Get('titleLength') as number < (AppStorage.get('wantParams') as WantParams)?.title.length) { 933 Scroll() { 934 Column() { 935 Text((AppStorage.get('wantParams') as WantParams)?.title) 936 .draggable(false) 937 .fontSize($r('sys.float.ohos_id_text_size_body1')) 938 .fontColor($r('sys.color.ohos_id_color_text_primary')) 939 .fontWeight(FontWeight.Medium) 940 Text(this.prompt) 941 .draggable(false) 942 .margin({ top: $r('app.float.element_margin') }) 943 .height($r('app.float.size_24')) 944 .fontSize($r('sys.float.ohos_id_text_size_body2')) 945 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 946 }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) 947 } 948 .width('100%') 949 .height($r('app.float.scroll_height_76')) 950 .scrollable(ScrollDirection.Vertical) 951 .scrollBarColor(Color.Gray) 952 } else { 953 Text((AppStorage.get('wantParams') as WantParams)?.title) 954 .draggable(false) 955 .fontSize($r('sys.float.ohos_id_text_size_body1')) 956 .fontColor($r('sys.color.ohos_id_color_text_primary')) 957 .height($r('app.float.size_24')) 958 .fontWeight(FontWeight.Medium) 959 Text(this.prompt) 960 .draggable(false) 961 .margin({ top: $r('app.float.element_margin') }) 962 .height($r('app.float.size_24')) 963 .fontSize($r('sys.float.ohos_id_text_size_body2')) 964 .fontColor(this.onFingerPrintFontColor(this.prompt, (AppStorage.get('context') as common.ExtensionContext))) 965 } 966 Image(this.prompt === (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 967 .getStringSync($r('app.string.unified_authwidget_hint_fp_verify_success').id) 968 ? $r('app.media.right_faceID') : $r('app.media.ic_blue_fingerprint')) 969 .draggable(false) 970 .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 971 .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 972 .margin({ 973 top: $r('app.float.digital_password_mask_height'), 974 bottom: $r('app.float.digital_password_mask_height') 975 }) 976 .colorBlend($r('sys.color.ohos_id_color_activated')) 977 .onClick(() => { 978 this.sendFingerEvent(); 979 }) 980 } 981 } 982 .position({ y: -Math.ceil(this.fingerPositionY) }) 983 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 984 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 985 .margin({ 986 left: ($r('sys.float.ohos_id_dialog_margin_start')), 987 right: ($r('sys.float.ohos_id_dialog_margin_end')), 988 bottom: ($r('sys.float.ohos_id_dialog_margin_bottom')) 989 }) 990 } 991 } 992 } 993 } 994 } 995 .margin(this.IS_LANDSCAPE ? '0' : { bottom: this.SYSTEM_NAVIGATION_BAR_HEIGHT }) 996 .height(Constants.fullContainerHeight) 997 .justifyContent(this.IS_LANDSCAPE ? FlexAlign.Center : FlexAlign.End) 998 .backgroundColor(Color.Transparent) 999 .id('fingerprintAuth') 1000 } 1001} 1002 1003