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 display from '@ohos.display'; 17import userAuth from '@ohos.userIAM.userAuth'; 18import Constants, { CmdData, CmdType, FingerPosition, NumKeyBoardItem, WantParams } from '../../common/vm/Constants'; 19import AuthUtils from '../utils/AuthUtils'; 20import FuncUtils from '../utils/FuncUtils'; 21import LogUtils from '../utils/LogUtils'; 22import TimeUtils from '../utils/TimeUtils'; 23import NumKeyBoard from './NumkeyBoard'; 24import common from '@ohos.app.ability.common'; 25import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 26 27const TAG = 'FullScreen'; 28const INTERVAL = 1000; 29const THOUSANDTH = 1000; 30const DEL_PWD = -2; 31const CALL_PHONE = -1; 32const GO_BACK = -3; 33const FINGER_TEXT_POSITION = 120; 34const FINGER_HIGH = 80; 35const FINGER_Y_POSITION = 60; 36const MAX_LENGTH = 32; 37const SIX_MAX_LENGTH = 6; 38const AUTH_TYPE_FACE = 2; 39const AUTH_TYPE_FINGER = 4; 40const PASSWORD_LENGTH = 4; 41const PASSWORD_ARRAY_LENGTH = 6; 42const NOTICE_DELAY = 50; 43const FINGER_SENSOR_POSITION_LINE = 0.75; 44const RADIUS = 2; 45const PADDING_8 = 8; 46const CANCEL_HIGH = 40; 47const BOTTOM = 72; 48const MARGIN = 4; 49const NUM_KEY_BOTTOM = 0.63; 50const NUM_KEY_POSITION = 0.54; 51const TIPS_POSITION = 0.245; 52const LOCK_POSITION = 0.2675; 53 54interface ControlType { 55 isSixPassword?: boolean, 56 isLandscape: boolean, 57 jumpFinger: boolean, 58 isShowFace: boolean, 59 isShowFinger: boolean, 60} 61 62@Component 63export default struct FullScreen { 64 @Link pinSubType: string; 65 @Link textValue: string; 66 @Link authType: Array<userAuth.UserAuthType>; 67 @Link @Watch('onCmdDataChange') cmdData: Array<CmdType>; 68 @Link cancelImage: boolean; 69 @State pinLock: number = 0; 70 @State fingerPositionY: number = 0; 71 @State fingerTextPositionY: number = 0; 72 @State fingerTipsPositionY: number = 0; 73 @State fingerButtonPositionY: number = 0; 74 @State fingerPositionLine: number = 0; 75 @StorageLink('passwordArray') passwordArray: string[] = []; 76 @StorageLink('passwordArrayNumber') passwordArrayNumber: string[] = []; 77 @State passwordObj: string = ''; 78 numKeyboard: NumKeyBoardItem[] = Constants.numKeyBoard; 79 @State prompt: string = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 80 .getStringSync($r('app.string.unified_authwidget_use_pwd').id); 81 @State fingerText: string = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 82 .getStringSync($r('app.string.unified_authwidget_hint_inscreen_fp').id); 83 @StorageLink('screenLockDirection') screenLockDirection: number = 1; 84 @StorageLink('SYSTEM_STATUS_BAR_HEIGHT') SYSTEM_STATUS_BAR_HEIGHT: number = 0; 85 @StorageLink('SYSTEM_NAVIGATION_BAR_HEIGHT') SYSTEM_NAVIGATION_BAR_HEIGHT: number = 0; 86 @State controlType: ControlType = { 87 jumpFinger: false, 88 isLandscape: false, 89 isSixPassword: true, 90 isShowFace: this.authType.includes(AUTH_TYPE_FACE), 91 isShowFinger: this.authType.includes(AUTH_TYPE_FINGER) 92 } 93 @State fingerPosition: FingerPosition = { 94 sensorType: '' 95 } 96 @State screen: number[] = []; 97 @State faceFingerLockArr: boolean[] = [false, false]; 98 @StorageLink('IS_LANDSCAPE') IS_LANDSCAPE: boolean = false; 99 @Consume underFingerPrint: boolean; 100 101 onCmdDataChange(num?: string): void { 102 this.cmdData.length > 0 && this.cmdData.map((item) => { 103 const payload: CmdData = item.payload; 104 if (payload.type === Constants.noticeTypePin) { 105 this.clearPassword(); 106 if (payload.remainAttempts) { 107 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 108 .getStringSync($r('app.string.unified_authwidget_hint_pwd_error').id); 109 if (num === 'first' && this.prompt !== (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 110 .getStringSync($r('app.string.unified_authwidget_hint_recognition').id)) { 111 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 112 .getStringSync($r('app.string.unified_authwidget_use_pwd').id); 113 } 114 // 3: pin Residual number 115 if (payload.remainAttempts < 3 && num !== 'first') { 116 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 117 .getStringSync($r('app.string.unified_authwidget_pwd_error_can_try').id) + 118 payload.remainAttempts + (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 119 .getStringSync($r('app.string.unified_authwidget_frequency').id); 120 } 121 } 122 if (payload.remainAttempts === 0 && payload.lockoutDuration) { 123 // 1: pin lock 124 this.pinLock = 1; 125 this.countdown(payload.lockoutDuration); 126 } 127 128 if (!payload.remainAttempts && !payload.lockoutDuration) { 129 // 1: pin lock 130 this.pinLock = 1; 131 } 132 if (payload.result === 0) { 133 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 134 } 135 } else if (payload.type === Constants.noticeTypeFace) { 136 if (payload.remainAttempts < 5 && payload.remainAttempts > 0) { 137 if (this.pinLock !== 1) { 138 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 139 .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id); 140 this.faceFingerLockArr[0] = false; 141 } 142 } 143 if (num === 'first') { 144 if (payload.remainAttempts === 0) { 145 this.controlType.isShowFace = false; 146 } else { 147 if (this.pinLock !== 1) { 148 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 149 .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); 150 } 151 } 152 } 153 if (payload.remainAttempts === 0) { 154 if (num !== 'first') { 155 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 156 .getStringSync($r('app.string.unified_authwidget_title_number_failed_face_forbidden').id); 157 } 158 this.faceFingerLockArr[0] = true; 159 } 160 if (payload.result === 0) { 161 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 162 } 163 } else if (payload.type === Constants.noticeTypeFinger) { 164 let sensor: FingerPosition = { sensorType: '' }; 165 if (payload.sensorInfo && JSON.stringify(payload.sensorInfo) !== '{}') { 166 sensor = JSON.parse(payload.sensorInfo); 167 this.fingerPosition = sensor || { sensorType: '' }; 168 } 169 if (payload.remainAttempts && payload.result !== 0) { 170 if (this.controlType.jumpFinger) { 171 this.fingerText = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 172 .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); 173 } 174 if (sensor && this.fingerPosition.udSensorCenterYInThousandth !== undefined && 175 this.fingerPosition.udSensorRadiusInPx !== undefined) { 176 if (sensor.sensorType === 'UNDER_SCREEN_SENSOR' || 177 sensor.sensorType === 'BOTH_SENSOR' || 178 sensor.sensorType === 'SensorType1') { 179 if (num !== 'first' && payload.remainAttempts > 0 && payload.result != 0) { 180 setTimeout(() => { 181 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); 182 }, NOTICE_DELAY); 183 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 184 .getStringSync($r('app.string.unified_authwidget_hint_fp_retry_s2').id); 185 } 186 187 this.fingerButtonPositionY = 188 px2vp(this.fingerPosition.udSensorCenterYInThousandth / THOUSANDTH * this.screen[1]); 189 FuncUtils.judgmentOverflow(this.fingerButtonPositionY); 190 this.fingerPositionY = this.fingerButtonPositionY - this.SYSTEM_STATUS_BAR_HEIGHT - 191 this.SYSTEM_STATUS_BAR_HEIGHT - px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - PADDING_8; 192 this.fingerPositionLine = this.fingerPositionY / px2vp(this.screen[1]); 193 FuncUtils.judgmentOverflow(this.fingerPositionLine); 194 if (num === 'first' && this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && payload.result != 0) { 195 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); 196 } 197 } 198 } 199 } 200 if (payload.remainAttempts === 0) { 201 if (num === 'first') { 202 this.controlType.isShowFinger = false; 203 } else { 204 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 205 .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); 206 this.fingerText = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 207 .getStringSync($r('app.string.unified_authwidget_title_number_failed_fp_forbidden').id); 208 } 209 this.faceFingerLockArr[1] = true; 210 this.controlType.jumpFinger = false; 211 this.cancelImage = false; 212 } 213 if (payload.result === 0) { 214 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 215 } 216 } else { 217 LogUtils.error(TAG, 'type: ' + payload.type); 218 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 219 } 220 }) 221 } 222 223 aboutToAppear(): void { 224 LogUtils.debug(TAG, 'aboutToAppear'); 225 try { 226 const displayClass = display.getDefaultDisplaySync(); 227 this.screen = [displayClass.width, displayClass.height]; 228 AppStorage.SetOrCreate('passwordArray', [] as string[]); 229 if (this.cmdData && this.cmdData.length > 0) { 230 this.onCmdDataChange('first'); 231 } 232 233 if (this.controlType.isShowFinger && this.fingerPosition.udSensorCenterYInThousandth !== undefined && 234 this.fingerPosition.udSensorRadiusInPx !== undefined) { 235 let tempPosition = px2vp(this.fingerPosition.udSensorCenterYInThousandth * this.screen[1]); 236 FuncUtils.judgmentOverflow(tempPosition); 237 this.fingerButtonPositionY = tempPosition / THOUSANDTH; 238 FuncUtils.judgmentOverflow(this.fingerButtonPositionY); 239 this.fingerPositionY = this.fingerButtonPositionY - this.SYSTEM_STATUS_BAR_HEIGHT - 240 this.SYSTEM_STATUS_BAR_HEIGHT - px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - PADDING_8; 241 FuncUtils.judgmentOverflow(this.fingerPositionY); 242 243 this.fingerTipsPositionY = this.fingerButtonPositionY - px2vp(FINGER_Y_POSITION) - FINGER_HIGH - 244 this.SYSTEM_STATUS_BAR_HEIGHT - px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - PADDING_8; 245 FuncUtils.judgmentOverflow(this.fingerTipsPositionY); 246 247 this.fingerTextPositionY = this.fingerButtonPositionY - px2vp(FINGER_Y_POSITION) - FINGER_TEXT_POSITION - 248 this.SYSTEM_STATUS_BAR_HEIGHT - px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - PADDING_8; 249 FuncUtils.judgmentOverflow(this.fingerTextPositionY); 250 } 251 252 if (this.controlType.isShowFace && this.pinLock !== 1) { 253 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); 254 return; 255 } 256 } catch (error) { 257 LogUtils.error(TAG, 'aboutToAppear catch error: ' + error?.code); 258 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 259 } 260 } 261 262 clearPassword(): void { 263 this.passwordArray = []; 264 this.passwordArrayNumber = []; 265 this.passwordArray = ['', '', '', '', '', '']; 266 this.passwordObj = ''; 267 this.numKeyboard[11].value = GO_BACK; 268 this.numKeyboard[11].row1 = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 269 .getStringSync($r('app.string.unified_authwidget_back').id); 270 this.updateStorage(() => { 271 }) 272 } 273 274 aboutToDisappear(): void { 275 this.clearPassword(); 276 } 277 278 countdown(freezingTime: number): void { 279 const TRY_AGAIN = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager.getStringSync($r('app.string.unified_authwidget_postretry').id); 280 const PLEASE_TRY = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager.getStringSync($r('app.string.unified_authwidget_pleaseretry').id); 281 let promptText: string = ''; 282 let freezingMillisecond = freezingTime; 283 if (freezingMillisecond > 0) { 284 promptText = TimeUtils.getFreezingTimeNm(freezingMillisecond, (AppStorage.get('context') as common.ExtensionContext)); 285 promptText = PLEASE_TRY + promptText + TRY_AGAIN; 286 setTimeout((t: number):void => this.countdown(t), INTERVAL, freezingTime - INTERVAL); 287 } else { 288 promptText = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager.getStringSync($r('app.string.unified_authwidget_use_pwd').id); 289 this.clearPassword(); 290 // 0: pin unlock 291 this.pinLock = 0; 292 } 293 this.prompt = promptText; 294 } 295 296 updateStorage(callback: Function): void { 297 AppStorage.SetOrCreate('passwordArray', this.passwordArray); 298 AppStorage.SetOrCreate('numKeyboard', this.numKeyboard); 299 callback(); 300 } 301 302 build() { 303 if (!this.controlType.jumpFinger) { 304 Column() { 305 306 // 1: pin lock 307 if (this.pinLock === 1) { 308 Column() { 309 Text($r('app.string.unified_authwidget_locked')) 310 .draggable(false) 311 .margin({ bottom: $r('app.float.content_padding') }) 312 .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) 313 .fontSize($r('sys.float.ohos_id_text_size_headline6')) 314 .fontWeight(FontWeight.Medium) 315 Text(this.prompt) 316 .draggable(false) 317 .id('cancelIconCustomPassword') 318 .fontSize($r('sys.float.ohos_id_text_size_body2')) 319 .fontWeight(FontWeight.Medium) 320 .fontColor($r('sys.color.ohos_id_color_text_secondary_contrary')) 321 .margin({ bottom: $r('app.float.margin_16') }) 322 .textAlign(TextAlign.Center) 323 .textOverflow({ overflow: TextOverflow.None }) 324 .height($r('app.float.size_24')) 325 Button(($r('app.string.unified_authwidget_forgotpwd')), { 326 stateEffect: false 327 }) 328 .id('forgotBtnCustomPwd') 329 .height($r('app.float.text_high')) 330 .backgroundColor(Color.Transparent) 331 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 332 .fontSize($r('sys.float.ohos_id_text_size_button1')) 333 .fontWeight(FontWeight.Medium) 334 .onClick(() => { 335 let str = this.passwordArrayNumber.toString() 336 this.textValue = str.replace(new RegExp(',', 'g'), ''); 337 }) 338 .visibility(Visibility.Hidden) 339 } 340 .position({ y: px2vp(this.screen[1] * LOCK_POSITION) - CANCEL_HIGH - this.SYSTEM_STATUS_BAR_HEIGHT}) 341 .width(Constants.fullContainerWidth) 342 } else { 343 Column() { 344 if (this.controlType.isShowFace) { 345 Image($r('app.media.white_faceID')) 346 .draggable(false) 347 .id('faceImgCustomPwd') 348 .width($r('app.float.image_small')) 349 .height($r('app.float.image_small')) 350 .margin({ bottom: $r('app.float.content_padding') }) 351 .onClick(() => { 352 if (!this.faceFingerLockArr[0]) { 353 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 354 .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); 355 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); 356 } else { 357 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 358 .getStringSync($r('app.string.unified_authwidget_title_face_forbidden').id); 359 } 360 }) 361 } 362 if (!this.controlType.isShowFace) { 363 Text() 364 .draggable(false) 365 .width($r('app.float.image_small')) 366 .height($r('app.float.image_small')) 367 .margin({ bottom: $r('app.float.content_padding') }) 368 } 369 Text(this.prompt) 370 .draggable(false) 371 .id('cancelIconCustomPassword') 372 .fontSize($r('sys.float.ohos_id_text_size_body1')) 373 .fontWeight(FontWeight.Medium) 374 .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) 375 .margin({ bottom: $r('app.float.margin_16') }) 376 .textAlign(TextAlign.Center) 377 .textOverflow({ overflow: TextOverflow.None }) 378 .height($r('app.float.size_24')) 379 .onClick(() => { 380 if (this.prompt === (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 381 .getStringSync($r('app.string.unified_authwidget_hint_face_verify_fail_click_retry_s1').id)) { 382 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 383 .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); 384 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); 385 } 386 }) 387 388 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 389 // 0: pin unlock 390 if (this.pinLock === 0) { 391 if (this.pinSubType === Constants.pinSix) { 392 Stack() { 393 List() { 394 ForEach(this.passwordArray, (item: string) => { 395 if ((!item || item === '') && item !== '0') { 396 ListItem() { 397 Button() 398 .border({ 399 color: Color.White, 400 style: BorderStyle.Solid, 401 width: 1 402 }) 403 .borderRadius($r('app.float.input_btn_size')) 404 .width($r('app.float.input_btn_size')) 405 .height($r('app.float.input_btn_size')) 406 .type(ButtonType.Circle) 407 .backgroundColor(Color.Transparent) 408 } 409 .margin({ 410 left: $r('app.float.margin_12'), 411 right: $r('app.float.margin_12'), 412 top: $r('app.float.margin_14') 413 }) 414 } else { 415 ListItem() { 416 Button() 417 .borderRadius($r('app.float.input_btn_size')) 418 .width($r('app.float.input_btn_size')) 419 .height($r('app.float.input_btn_size')) 420 .type(ButtonType.Circle) 421 .backgroundColor($r('sys.color.ohos_id_color_text_primary_contrary')) 422 } 423 .margin({ 424 left: $r('app.float.margin_12'), 425 right: $r('app.float.margin_12'), 426 top: $r('app.float.margin_14') 427 }) 428 } 429 }) 430 } 431 .listDirection(Axis.Horizontal) 432 .height($r('app.float.input_height')) 433 434 if (this.IS_LANDSCAPE) { 435 TextInput({ placeholder: '', text: this.passwordArray?.join('') }) 436 .draggable(false) 437 .onChange(async (value: string) => { 438 const arr = value.replace(new RegExp('[^\\d]', 'g'), '').split(''); 439 arr?.map((item, index) => { 440 this.passwordArray[index] = item; 441 }); 442 if (arr?.length === SIX_MAX_LENGTH) { 443 this.textValue = arr?.join(''); 444 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 445 } 446 }) 447 .maxLength(SIX_MAX_LENGTH) 448 .visibility(Visibility.Visible) 449 .opacity(0) 450 .caretColor('transparent') 451 } 452 } 453 454 } else if (this.pinSubType === Constants.pinNumber) { 455 Stack() { 456 TextInput({ placeholder: '', text: this.passwordArrayNumber.join('') }) 457 .draggable(false) 458 .onChange(async (value: string) => { 459 // Removes non-numeric characters from a string 460 this.passwordArrayNumber = value.replace(new RegExp('[^\\d]', 'g'), '').split(''); 461 }) 462 .id('pinInputNumber') 463 .onSubmit(async (enterKey: EnterKeyType) => { 464 let str = this.passwordArrayNumber.toString(); 465 this.textValue = str.replace(new RegExp(',', 'g'), ''); 466 if (this.passwordArrayNumber.length < PASSWORD_LENGTH) { 467 return; 468 } 469 const strData = this.passwordArrayNumber.toString(); 470 this.textValue = strData.replace(new RegExp(',', 'g'), ''); 471 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 472 }) 473 .fontColor(Color.White) 474 .height($r('app.float.btn_height')) 475 .width($r('app.float.fullScreen_input_width')) 476 .type(InputType.Password) 477 .copyOption(CopyOptions.None) 478 .fontSize($r('sys.float.ohos_id_text_size_body1')) 479 .fontWeight(FontWeight.Regular) 480 .maxLength(MAX_LENGTH) 481 .backgroundColor('rgba(255,255,255,0.2)') 482 .textAlign(TextAlign.Start) 483 .margin({ 484 left: $r('app.float.custom_password_input_margin'), 485 right: $r('app.float.custom_password_input_margin') 486 }) 487 } 488 } else if (this.pinSubType === Constants.pinMixed) { 489 TextInput({ text: this.passwordObj }) 490 .draggable(false) 491 .fontColor(Color.White) 492 .height($r('app.float.btn_height')) 493 .width($r('app.float.fullScreen_input_width')) 494 .type(InputType.Password) 495 .copyOption(CopyOptions.None) 496 .fontSize($r('sys.float.ohos_id_text_size_body1')) 497 .fontWeight(FontWeight.Regular) 498 .maxLength(MAX_LENGTH) 499 .backgroundColor('rgba(255,255,255,0.2)') 500 .textAlign(TextAlign.Start) 501 .margin({ 502 left: $r('app.float.custom_password_input_margin'), 503 right: $r('app.float.custom_password_input_margin') 504 }) 505 .onSubmit(async (enterKey: EnterKeyType) => { 506 // check callback 507 if (this.passwordObj.length < PASSWORD_LENGTH) { 508 return; 509 } 510 this.textValue = this.passwordObj; 511 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 512 }) 513 .onChange((value: string) => { 514 this.passwordObj = value; 515 }) 516 .id('pinInput') 517 } 518 } 519 } 520 .height($r('app.float.text_high')) 521 Button(($r('app.string.unified_authwidget_forgotpwd')), { 522 stateEffect: false 523 }) 524 .id('forgotBtnCustomPwd') 525 .height($r('app.float.text_high')) 526 .backgroundColor(Color.Transparent) 527 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 528 .fontSize($r('sys.float.ohos_id_text_size_button1')) 529 .fontWeight(FontWeight.Medium) 530 .onClick(() => { 531 let str = this.passwordArrayNumber.toString() 532 this.textValue = str.replace(new RegExp(',', 'g'), ''); 533 }) 534 .visibility(Visibility.Hidden) 535 } 536 .width(Constants.fullContainerWidth) 537 .position({ y: px2vp(this.screen[1] * TIPS_POSITION) - CANCEL_HIGH - this.SYSTEM_STATUS_BAR_HEIGHT }) 538 } 539 540 // 0: pin unlock 541 if (!this.IS_LANDSCAPE && this.pinLock === 0 && this.pinSubType === Constants.pinSix) { 542 if (this.controlType.isShowFinger && this.fingerPosition.sensorType !== 'OUT_OF_SCREEN_SENSOR' && 543 this.fingerPosition.sensorType !== 'NON_SENSOR') { 544 if (this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && 545 this.fingerPosition.udSensorRadiusInPx !== undefined && 546 this.fingerPosition.udSensorCenterYInThousandth !== undefined) { 547 Column() { 548 NumKeyBoard({ 549 onKeyPress: (index, callback) => { 550 let keyValue = this.numKeyboard[index].value; 551 if (keyValue != undefined && keyValue >= 0) { 552 const index = this.passwordArray.map(item => item).indexOf('') 553 if (index > -1) { 554 this.passwordArray[index] = keyValue + ''; 555 this.numKeyboard[11].row1 = $r('app.string.unified_authwidget_delete'); 556 this.numKeyboard[11].value = DEL_PWD; 557 if (index === 5) { 558 this.passwordArray[index] = keyValue + ''; 559 if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { 560 return; 561 } 562 let str = this.passwordArray.toString(); 563 this.textValue = str.replace(new RegExp(',', 'g'), ''); 564 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 565 } 566 this.updateStorage(callback); 567 } 568 } else if (keyValue === DEL_PWD) { 569 const index = this.passwordArray.map(item => item).indexOf(''); 570 if (index === -1) { 571 this.passwordArray[5] = ''; 572 } else if (index === 1) { 573 this.passwordArray[index - 1] = ''; 574 this.numKeyboard[11].value = GO_BACK; 575 this.numKeyboard[11].row1 = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 576 .getStringSync($r('app.string.unified_authwidget_back').id); 577 } else { 578 this.passwordArray[index - 1] = ''; 579 } 580 this.updateStorage(callback); 581 } else if (keyValue === GO_BACK) { 582 // 0: pin unlock 583 this.pinLock = 0; 584 this.clearPassword(); 585 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 586 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || 587 (AppStorage.get('wantParams') as WantParams)?.type as string[]); 588 } else if (keyValue === CALL_PHONE) { 589 if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { 590 return; 591 } 592 593 let str = this.passwordArray.toString(); 594 this.textValue = str.replace(new RegExp(',', 'g'), ''); 595 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 596 } 597 } 598 }) 599 } 600 .width(Constants.fullContainerWidth) 601 .height('37%') 602 .position({ y: px2vp(this.screen[1] * NUM_KEY_BOTTOM) - 603 CANCEL_HIGH - MARGIN - px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - 604 px2vp((THOUSANDTH - this.fingerPosition.udSensorCenterYInThousandth) / THOUSANDTH * this.screen[1]) - 605 this.SYSTEM_STATUS_BAR_HEIGHT }) 606 } else { 607 Column() { 608 NumKeyBoard({ 609 onKeyPress: (index, callback) => { 610 let keyValue = this.numKeyboard[index].value; 611 if (keyValue !== undefined && keyValue >= 0) { 612 const index = this.passwordArray.map(item => item).indexOf('') 613 if (index > -1) { 614 this.passwordArray[index] = keyValue + ''; 615 this.numKeyboard[11].row1 = $r('app.string.unified_authwidget_delete'); 616 this.numKeyboard[11].value = DEL_PWD; 617 if (index === 5) { 618 this.passwordArray[index] = keyValue + ''; 619 if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { 620 return; 621 } 622 let str = this.passwordArray.toString(); 623 this.textValue = str.replace(new RegExp(',', 'g'), ''); 624 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 625 } 626 this.updateStorage(callback); 627 } 628 } else if (keyValue === DEL_PWD) { 629 const index = this.passwordArray.map(item => item).indexOf(''); 630 if (index === -1) { 631 this.passwordArray[5] = ''; 632 } else if (index === 1) { 633 this.passwordArray[index - 1] = ''; 634 this.numKeyboard[11].value = GO_BACK; 635 this.numKeyboard[11].row1 = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 636 .getStringSync($r('app.string.unified_authwidget_back').id); 637 } else { 638 this.passwordArray[index - 1] = ''; 639 } 640 this.updateStorage(callback); 641 } else if (keyValue === GO_BACK) { 642 // 0: pin unlock 643 this.pinLock = 0; 644 this.clearPassword(); 645 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 646 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || 647 (AppStorage.get('wantParams') as WantParams)?.type as string[]); 648 } else if (keyValue === CALL_PHONE) { 649 if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { 650 return; 651 } 652 let str = this.passwordArray.toString(); 653 this.textValue = str.replace(new RegExp(',', 'g'), ''); 654 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 655 } 656 } 657 }) 658 } 659 .width(Constants.fullContainerWidth) 660 .height('37%') 661 .position({ y: px2vp(this.screen[1] * NUM_KEY_BOTTOM) - CANCEL_HIGH - BOTTOM - 662 this.SYSTEM_STATUS_BAR_HEIGHT - this.SYSTEM_NAVIGATION_BAR_HEIGHT }) 663 } 664 } else { 665 Column() { 666 NumKeyBoard({ 667 onKeyPress: (index, callback) => { 668 let keyValue = this.numKeyboard[index].value; 669 if (keyValue !== undefined && keyValue >= 0) { 670 const index = this.passwordArray.map(item => item).indexOf('') 671 if (index > -1) { 672 this.passwordArray[index] = keyValue + ''; 673 this.numKeyboard[11].row1 = $r('app.string.unified_authwidget_delete'); 674 this.numKeyboard[11].value = DEL_PWD; 675 if (index === 5) { 676 this.passwordArray[index] = keyValue + ''; 677 if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { 678 return; 679 } 680 let str = this.passwordArray.toString(); 681 this.textValue = str.replace(new RegExp(',', 'g'), ''); 682 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 683 } 684 this.updateStorage(callback); 685 } 686 } else if (keyValue === DEL_PWD) { 687 const index = this.passwordArray.map(item => item).indexOf(''); 688 if (index === -1) { 689 this.passwordArray[5] = ''; 690 } else if (index === 1) { 691 this.passwordArray[index - 1] = ''; 692 this.numKeyboard[11].value = GO_BACK; 693 this.numKeyboard[11].row1 = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 694 .getStringSync($r('app.string.unified_authwidget_back').id); 695 } else { 696 this.passwordArray[index - 1] = ''; 697 } 698 this.updateStorage(callback); 699 } else if (keyValue === GO_BACK) { 700 // 0: pin unlock 701 this.pinLock = 0; 702 this.clearPassword(); 703 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 704 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || 705 (AppStorage.get('wantParams') as WantParams)?.type as string[]); 706 } else if (keyValue === CALL_PHONE) { 707 if (this.passwordArray.join('').length < PASSWORD_ARRAY_LENGTH) { 708 return; 709 } 710 711 let str = this.passwordArray.toString(); 712 this.textValue = str.replace(new RegExp(',', 'g'), ''); 713 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypePin]); 714 } 715 } 716 }) 717 } 718 .width(Constants.fullContainerWidth) 719 .height('37%') 720 .position({ y: px2vp(this.screen[1] * NUM_KEY_POSITION) - CANCEL_HIGH - 721 this.SYSTEM_STATUS_BAR_HEIGHT }) 722 } 723 } 724 725 // 1: pin lock 726 if (this.controlType.isShowFinger && this.pinLock !== 1 && !this.faceFingerLockArr[1]) { 727 if (this.fingerPosition.sensorType !== 'OUT_OF_SCREEN_SENSOR' && 728 this.fingerPosition.sensorType !== 'NON_SENSOR') { 729 if (this.fingerPosition.sensorType === 'UNDER_SCREEN_SENSOR' || 730 this.fingerPosition.sensorType === 'BOTH_SENSOR' || 731 this.fingerPosition.sensorType === 'SensorType1') { 732 if (this.fingerPositionLine > FINGER_SENSOR_POSITION_LINE && !this.IS_LANDSCAPE && 733 this.fingerPosition.udSensorRadiusInPx !== undefined && 734 this.fingerPosition.udSensorCenterYInThousandth !== undefined) { 735 Column() { 736 Image($r('app.media.ic_unlock_fingerprint')) 737 .draggable(false) 738 .id('fingerprintImgCustomPassword') 739 .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 740 .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 741 .onClick(() => { 742 if (!this.faceFingerLockArr[1]) { 743 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); 744 } 745 }) 746 } 747 .position({ y: px2vp(this.fingerPosition.udSensorCenterYInThousandth / THOUSANDTH * this.screen[1]) - 748 px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS) - 749 CANCEL_HIGH - this.SYSTEM_STATUS_BAR_HEIGHT }) 750 .width(Constants.fullContainerWidth) 751 .height(this.controlType.isShowFinger ? $r('app.float.finger_high') : '9%') 752 .justifyContent(FlexAlign.Start) 753 .alignItems(HorizontalAlign.Center) 754 } else { 755 Column() { 756 Image($r('app.media.finger_white')) 757 .draggable(false) 758 .id('fingerWhiteImgCustomPassword') 759 .width($r('app.float.image_back_size')) 760 .height($r('app.float.image_back_size')) 761 .margin({ top: $r('app.float.input_btn_size') }) 762 .onClick(() => { 763 if (this.IS_LANDSCAPE) { 764 this.underFingerPrint = true; 765 } else { 766 this.controlType.jumpFinger = true; 767 AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger]); 768 this.cancelImage = true; 769 } 770 }) 771 } 772 .width(Constants.fullContainerWidth) 773 .height(this.controlType.isShowFinger ? $r('app.float.finger_high') : '9%') 774 .justifyContent(FlexAlign.Start) 775 .alignItems(HorizontalAlign.Center) 776 .position({ y: px2vp(this.screen[1]) - CANCEL_HIGH - BOTTOM - 777 this.SYSTEM_STATUS_BAR_HEIGHT - this.SYSTEM_NAVIGATION_BAR_HEIGHT }) 778 } 779 } 780 } 781 } 782 } 783 .alignItems(HorizontalAlign.Center) 784 .height(Constants.fullContainerHeight) 785 .width(Constants.fullContainerWidth) 786 } else if (!this.controlType.isLandscape && this.fingerPosition.udSensorRadiusInPx !== undefined) { 787 Column() { 788 if (AppStorage.Get('titleLength') as number < (AppStorage.get('wantParams') as WantParams)?.title.length) { 789 Scroll() { 790 Column() { 791 Text((AppStorage.get('wantParams') as WantParams)?.title) 792 .draggable(false) 793 .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) 794 .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) 795 .fontWeight(FontWeight.Medium) 796 Text(this.fingerText) 797 .draggable(false) 798 .height($r('app.float.text_high')) 799 .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) 800 .fontSize($r('sys.float.ohos_id_text_size_body2')) 801 .fontWeight(FontWeight.Regular) 802 .textAlign(TextAlign.Center) 803 .margin({ top: $r('app.float.padding_8') }) 804 }.margin({left: $r('app.float.margin_36'), right: $r('app.float.size_24')}) 805 } 806 .width('96%') 807 .id('titleFullScreen') 808 .position({ 809 y: this.fingerTextPositionY, 810 }) 811 .height($r('app.float.scroll_height_72')) 812 .scrollable(ScrollDirection.Vertical) 813 .scrollBarColor('sys.color.ohos_id_color_foreground') 814 } else { 815 Text((AppStorage.get('wantParams') as WantParams)?.title) 816 .draggable(false) 817 .height($r('app.float.text_high')) 818 .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) 819 .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) 820 .fontWeight(FontWeight.Medium) 821 .id('titleFullScreen') 822 .position({ 823 y: this.fingerTextPositionY 824 }) 825 .width('100%') 826 .textAlign(TextAlign.Center) 827 Text(this.fingerText) 828 .draggable(false) 829 .height($r('app.float.text_high')) 830 .fontColor($r('sys.color.ohos_id_color_text_secondary_contrary')) 831 .fontSize($r('sys.float.ohos_id_text_size_body2')) 832 .fontWeight(FontWeight.Regular) 833 .position({ 834 y: this.fingerTipsPositionY 835 }) 836 .width('100%') 837 .textAlign(TextAlign.Center) 838 .margin({ top: $r('app.float.padding_8') }) 839 } 840 841 Column() { 842 Image($r('app.media.ic_unlock_fingerprint')) 843 .draggable(false) 844 .id('unlockFingerprintImgCustomPwd') 845 // radius 846 .width(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 847 .height(px2vp(this.fingerPosition.udSensorRadiusInPx * RADIUS)) 848 }.width('100%') 849 .position({ y: this.fingerPositionY }) 850 .justifyContent(FlexAlign.Center) 851 .alignItems(HorizontalAlign.Center) 852 853 Button($r('app.string.unified_authwidget_cancel'), { 854 type: ButtonType.Normal, 855 stateEffect: true 856 }) 857 .width('100%') 858 .position({ 859 y: this.fingerButtonPositionY 860 }) 861 .backgroundColor(Color.Transparent) 862 .fontColor($r('sys.color.ohos_id_color_text_primary_contrary')) 863 .onClick(() => { 864 this.controlType.jumpFinger = false; 865 this.cancelImage = false; 866 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFinger]); 867 this.prompt = (AppStorage.get('context') as common.ExtensionContext)?.resourceManager 868 .getStringSync($r('app.string.unified_authwidget_use_pwd').id); 869 }) 870 } 871 .justifyContent(FlexAlign.End) 872 .alignItems(HorizontalAlign.Center) 873 .height('100%') 874 .width('100%') 875 } 876 } 877}