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 16 #include <stdlib.h> 17 #include <stdio.h> 18 #include <info/device_api_version.h> 19 20 #ifdef OHOS_ENABLE_PARAMETER 21 #include "sys_param.h" 22 #endif 23 24 #define API_VERSION_DEFAULT 0 25 #define API_VERSION_NAME_LEN 256 26 27 static int device_api_level = API_VERSION_DEFAULT; 28 InitDeviceApiVersion(void)29void InitDeviceApiVersion(void) 30 { 31 #ifdef OHOS_ENABLE_PARAMETER 32 const char para_name[API_VERSION_NAME_LEN] = "const.ohos.apiversion"; 33 CachedHandle para_handler = CachedParameterCreate(para_name, "0"); 34 if (para_handler == NULL) { 35 device_api_level = API_VERSION_DEFAULT; 36 return; 37 } 38 const char *para_value = CachedParameterGet(para_handler); 39 if (para_value == NULL) { 40 device_api_level = API_VERSION_DEFAULT; 41 return; 42 } 43 int api_level = atoi(para_value); 44 CachedParameterDestroy(para_handler); 45 device_api_level = (api_level > 0 ) ? api_level : API_VERSION_DEFAULT; 46 #endif // OHOS_ENABLE_PARAMETER 47 } 48 get_device_api_version(void)49int get_device_api_version(void) 50 { 51 // depend subsystem of syspara support the interface of get system property 52 return API_VERSION_DEFAULT; 53 } 54 get_device_api_version_inner(void)55int get_device_api_version_inner(void) 56 { 57 #ifdef OHOS_ENABLE_PARAMETER 58 if (device_api_level == API_VERSION_DEFAULT) { 59 // Api version may not init by InitDeviceApiVersion in dls3, try again. 60 InitDeviceApiVersion(); 61 } 62 #endif // OHOS_ENABLE_PARAMETER 63 return device_api_level; 64 } 65