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