1/* 2 * Copyright (c) 2024 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 */ 16/// <reference path="./arkts_util.d.ts" /> 17class Utils { 18 private static currentAppApiVersion: number = -1; 19 private static arkTsUtil: ArkTsUtil | undefined = undefined; 20 21 public static getApiVersion(): number { 22 if (Utils.currentAppApiVersion <= 0) { 23 Utils.currentAppApiVersion = typeof ViewStackProcessor.getApiVersion === 'function' 24 ? ViewStackProcessor.getApiVersion() : -1; 25 } 26 return Utils.currentAppApiVersion; 27 } 28 29 public static isApiVersionEQAbove(target: number): boolean { 30 let version = Utils.getApiVersion(); 31 if (version <= 0) { 32 stateMgmtConsole.error(`get api version error in isApiVersionEQAbove, version:${version}`); 33 return false; 34 } 35 return version % 1000 >= target; 36 } 37 38 public static getArkTsUtil(): ArkTsUtil { 39 if (!Utils.arkTsUtil) { 40 Utils.arkTsUtil = requireInternal('util'); 41 } 42 return Utils.arkTsUtil; 43 } 44}