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 userAuth from '@ohos.userIAM.userAuth'; 18import FullScreen from '../../common/components/FullScreen'; 19import FuncUtils from '../../common/utils/FuncUtils'; 20import LogUtils from '../../common/utils/LogUtils'; 21import Constants, { CmdType, WantParams } from '../../common/vm/Constants'; 22import AuthUtils from '../../common/utils/AuthUtils'; 23import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 24 25const TAG = 'CustomPassword'; 26const BLUR_OPACITY = 0.5; 27const SATURATE = 1.3; 28const BLUR_RADIUS = 242; 29const BACK_BLUR = 80; 30const PADDING_SIXTEEN = 16; 31let pinAuthManager: account_osAccount.PINAuth; 32let pinData = ''; 33 34@Component 35export default struct CustomPassword { 36 @Link pinSubType: string; 37 @Link authType: Array<userAuth.UserAuthType>; 38 @Link cmdData: Array<CmdType>; 39 @State isBackTouched: boolean = false; 40 @State cancelImageShow: boolean = false; 41 @State @Watch('onTextValueChange') textValue: string = ''; 42 @StorageLink('IS_LANDSCAPE') IS_LANDSCAPE: boolean = false; 43 @StorageLink('SYSTEM_STATUS_BAR_HEIGHT') SYSTEM_STATUS_BAR_HEIGHT: number = 0; 44 @StorageLink('SYSTEM_NAVIGATION_BAR_HEIGHT') SYSTEM_NAVIGATION_BAR_HEIGHT: number = 0; 45 46 onTextValueChange(): void { 47 pinData = this.textValue; 48 } 49 50 aboutToAppear(): void { 51 try { 52 LogUtils.info(TAG, 'aboutToAppear PINAuth'); 53 pinAuthManager = new account_osAccount.PINAuth(); 54 // register input 55 pinAuthManager.registerInputer({ 56 onGetData: (authSubType: account_osAccount.AuthSubType, callback: account_osAccount.IInputData) => { 57 LogUtils.info(TAG, 'aboutToAppear registerInputer onGetData'); 58 const uint8PW = FuncUtils.getUint8PW(pinData); 59 callback.onSetData(authSubType, uint8PW); 60 } 61 }); 62 } catch (error) { 63 LogUtils.error(TAG, 'aboutToAppear PINAuth catch error: ' + error?.code); 64 (AppStorage.get("session") as UIExtensionContentSession)?.terminateSelf(); 65 } 66 } 67 68 aboutToDisappear(): void { 69 LogUtils.info(TAG, 'aboutToDisappear PINAuth unregisterInputer'); 70 pinAuthManager?.unregisterInputer?.(); 71 } 72 73 build() { 74 Column() { 75 Column() { 76 } 77 .width(Constants.fullContainerWidth) 78 .height(Constants.fullContainerWidth) 79 .position({ x: 0, y: 0 }) 80 .opacity(BLUR_OPACITY) 81 .backgroundColor($r('app.color.full_screen_background')) 82 .blur(BLUR_RADIUS) 83 .saturate(SATURATE) 84 85 Column() { 86 Flex({ direction: FlexDirection.Row }) { 87 Image($r('app.media.ic_white_cancel')) 88 .draggable(false) 89 .id('cancelImgCustomPwd') 90 .width($r('app.float.image_back_size')) 91 .height($r('app.float.image_back_size')) 92 .margin({ left: $r('sys.float.ohos_id_max_padding_start'), top: this.SYSTEM_STATUS_BAR_HEIGHT + PADDING_SIXTEEN }) 93 .backgroundColor(this.isBackTouched 94 ? $r('sys.color.ohos_id_color_hover'): Color.Transparent) 95 .onClick(() => { 96 (AppStorage.get("session") as UIExtensionContentSession)?.terminateSelf(); 97 AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [] || 98 (AppStorage.get("wantParams") as WantParams)?.type as string[]); 99 }) 100 .onTouch((event?: TouchEvent) => { 101 if (event == undefined) { 102 return; 103 } else if (event.type === TouchType.Down) { 104 this.isBackTouched = true; 105 } else if (event.type === TouchType.Up) { 106 this.isBackTouched = false; 107 } 108 }); 109 }.visibility(this.cancelImageShow ? Visibility.Hidden : Visibility.Visible) 110 111 GridRow({ 112 columns: { xs: 4, sm: 4, md: 8, lg: 12 }, 113 gutter: { x: 24, y: 24 }, 114 breakpoints: { value: Constants.deviceDpi, 115 reference: BreakpointsReference.WindowSize }, 116 direction: GridRowDirection.Row 117 }) { 118 GridCol({ 119 span: { xs: 4, sm: 4, md: 4, lg: 6 }, 120 offset: { md: 2, lg: 3 }, 121 }) { 122 FullScreen({ 123 textValue: $textValue, 124 authType: $authType, 125 pinSubType: $pinSubType, 126 cmdData: $cmdData, 127 cancelImage: $cancelImageShow, 128 }) 129 } 130 } 131 } 132 .justifyContent(FlexAlign.SpaceBetween) 133 .width(Constants.fullContainerWidth) 134 .height(Constants.fullContainerWidth) 135 } 136 .width(Constants.fullContainerWidth) 137 .height(Constants.fullContainerWidth) 138 .backdropBlur(BACK_BLUR) 139 } 140}