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