• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  getDialogType(type: Array<userAuth.UserAuthType>): DialogType {
32    if (type) {
33      if (type.includes(userAuth.UserAuthType.PIN)) {
34        if (type.includes(userAuth.UserAuthType.FACE)) {
35          if (type.includes(userAuth.UserAuthType.FINGERPRINT)) {
36            return DialogType.ALL;
37          }
38          return DialogType.PIN_FACE;
39        }
40        if (type.includes(userAuth.UserAuthType.FINGERPRINT)) {
41          return DialogType.PIN_FINGER;
42        }
43        return DialogType.PIN;
44      }
45      if (type.includes(userAuth.UserAuthType.FACE) && type.includes(userAuth.UserAuthType.FINGERPRINT)) {
46        return DialogType.FACE_FINGER_NAVIGATION;
47      }
48      if (type.includes(userAuth.UserAuthType.FINGERPRINT)) {
49        return DialogType.FINGER;
50      }
51      if (type.includes(userAuth.UserAuthType.FACE)) {
52        return DialogType.FACE;
53      }
54    }
55    return DialogType.PIN;
56  }
57
58  getWindowHeight(): void {
59    LogUtils.info(TAG, 'getWindowHeight');
60    try {
61      window.on('systemBarTintChange', (data) => {
62        LogUtils.debug(TAG, 'Succeeded in enabling the listener for window stage event changes. Data: ' +
63        JSON.stringify(data));
64        for (let i = 0; i < data.regionTint.length; i++) {
65          let regionData = data.regionTint[i];
66          if (regionData.region === undefined) {
67            continue;
68          } else if (regionData.type === window.WindowType.TYPE_STATUS_BAR) {
69            AppStorage.SetOrCreate('SYSTEM_STATUS_BAR_HEIGHT', px2vp(regionData.region.height));
70            continue;
71          } else if (regionData.type === window.WindowType.TYPE_NAVIGATION_BAR) {
72            AppStorage.SetOrCreate('SYSTEM_NAVIGATION_BAR_HEIGHT', px2vp(regionData.region.height));
73            continue;
74          }
75        }
76      });
77    } catch (error) {
78      LogUtils.error(TAG, 'Failed to enable the listener for window stage event changes. error: ' + error?.code);
79    }
80  }
81
82  judgmentOverflow(value: number): void {
83    if (value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) {
84      LogUtils.error(TAG, 'judgmentOverflow spill code value: ' + value);
85      (AppStorage.get('session') as UIExtensionContentSession)?.terminateSelf();
86    }
87  }
88}
89
90let funcUtils = new FuncUtils();
91
92export default funcUtils as FuncUtils;
93