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 util from '@ohos.util'; 17import userAuth from '@ohos.userIAM.userAuth'; 18import { DialogType } from '../module/DialogType'; 19import LogUtils from './LogUtils'; 20import window from '@ohos.window'; 21import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 22 23const TAG = 'FuncUtils'; 24 25export class FuncUtils { 26 getUint8PW(value: string): Uint8Array { 27 let textEncoder = new util.TextEncoder(); 28 return textEncoder.encode(value); 29 } 30 31 getStringFromCharCode(input: Uint8Array): string { 32 return String.fromCharCode(...input); 33 } 34 35 getDialogType(type: Array<userAuth.UserAuthType>): DialogType { 36 if (type) { 37 if (type.includes(userAuth.UserAuthType.PIN)) { 38 if (type.includes(userAuth.UserAuthType.FACE)) { 39 if (type.includes(userAuth.UserAuthType.FINGERPRINT)) { 40 return DialogType.ALL; 41 } 42 return DialogType.PIN_FACE; 43 } 44 if (type.includes(userAuth.UserAuthType.FINGERPRINT)) { 45 return DialogType.PIN_FINGER; 46 } 47 return DialogType.PIN; 48 } 49 if (type.includes(userAuth.UserAuthType.FACE) && type.includes(userAuth.UserAuthType.FINGERPRINT)) { 50 return DialogType.FACE_FINGER_NAVIGATION; 51 } 52 if (type.includes(userAuth.UserAuthType.FINGERPRINT)) { 53 return DialogType.FINGER; 54 } 55 if (type.includes(userAuth.UserAuthType.FACE)) { 56 return DialogType.FACE; 57 } 58 } 59 return DialogType.PIN; 60 } 61 62 getWindowHeight(): void { 63 LogUtils.info(TAG, 'getWindowHeight'); 64 try { 65 window.on('systemBarTintChange', (data) => { 66 LogUtils.debug(TAG, 'Succeeded in enabling the listener for window stage event changes. Data: ' + 67 JSON.stringify(data)); 68 for (let i = 0; i < data.regionTint.length; i++) { 69 let regionData = data.regionTint[i]; 70 if (regionData.region === undefined) { 71 continue; 72 } else if (regionData.type === window.WindowType.TYPE_STATUS_BAR) { 73 AppStorage.SetOrCreate('SYSTEM_STATUS_BAR_HEIGHT', px2vp(regionData.region.height)); 74 continue; 75 } else if (regionData.type === window.WindowType.TYPE_NAVIGATION_BAR) { 76 AppStorage.SetOrCreate('SYSTEM_NAVIGATION_BAR_HEIGHT', px2vp(regionData.region.height)); 77 continue; 78 } 79 } 80 }); 81 } catch (error) { 82 LogUtils.error(TAG, 'Failed to enable the listener for window stage event changes. error: ' + error?.code); 83 } 84 } 85 86 judgmentOverflow(value: number): void { 87 if (value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) { 88 LogUtils.error(TAG, 'judgmentOverflow spill code value: ' + value); 89 (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf(); 90 } 91 } 92} 93 94let funcUtils = new FuncUtils(); 95 96export default funcUtils as FuncUtils; 97