1 /* 2 * Copyright (c) 2021-2022 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 #ifndef STARTUP_SYSPARAM_PARAMETER_API_H 17 #define STARTUP_SYSPARAM_PARAMETER_API_H 18 #include <stdint.h> 19 #ifdef __cplusplus 20 #if __cplusplus 21 extern "C" { 22 #endif 23 #endif /* __cplusplus */ 24 25 #define PARAM_CONST_VALUE_LEN_MAX 4096 26 #define PARAM_VALUE_LEN_MAX 96 27 #define PARAM_NAME_LEN_MAX 96 28 #define OS_FULL_NAME_LEN 128 29 #define VERSION_ID_MAX_LEN 256 30 #define PARAM_BUFFER_MAX (0x01 << 16) 31 #define PERFORMANCE_CLASS_HIGH_LEVEL 0 32 #define PERFORMANCE_CLASS_LOW_LEVEL 2 33 34 static const char EMPTY_STR[] = { "" }; 35 36 /** 37 * @brief Obtains a system parameter matching the specified <b>key</b>. 38 * 39 * If no system parameter is found, the <b>def</b> parameter will be returned.\n 40 * 41 * @param key Indicates the key for the system parameter to query. 42 * The value can contain lowercase letters, digits, underscores (_), and dots (.). 43 * Its length cannot exceed 32 bytes (including the end-of-text character in the string). 44 * @param def Indicates the default value to return when no query result is found. 45 * This parameter is specified by the caller. 46 * @param value Indicates the data buffer that stores the query result. 47 * This parameter is applied for and released by the caller and can be used as an output parameter. 48 * @param len Indicates the length of the data in the buffer. 49 * @return Returns the number of bytes of the system parameter if the operation is successful; 50 * returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios. 51 * @since 1 52 * @version 1 53 */ 54 int GetParameter(const char *key, const char *def, char *value, uint32_t len); 55 56 /** 57 * @brief Sets or updates a system parameter. 58 * 59 * You can use this function to set a system parameter that matches <b>key</b> as <b>value</b>.\n 60 * 61 * @param key Indicates the key for the parameter to set or update. 62 * The value can contain lowercase letters, digits, underscores (_), and dots (.). 63 * Its length cannot exceed 32 bytes (including the end-of-text character in the string). 64 * @param value Indicates the system parameter value. 65 * Its length cannot exceed 128 bytes (including the end-of-text character in the string). 66 * @return Returns <b>0</b> if the operation is successful; 67 * returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios. 68 * @since 1 69 * @version 1 70 */ 71 int SetParameter(const char *key, const char *value); 72 73 /** 74 * @brief Wait for a system parameter with specified value. 75 * 76 * You can use this function to wait a system parameter that matches <b>key</b> as <b>value</b>.\n 77 * 78 * @param key Indicates the key for the parameter to wait. 79 * The value can contain lowercase letters, digits, underscores (_), and dots (.). 80 * Its length cannot exceed 96 bytes (including the end-of-text character in the string). 81 * @param value Indicates the system parameter value. 82 * Its length cannot exceed 96 bytes (including the end-of-text character in the string). 83 * value can use "*" to do arbitrary match. 84 * @param timeout Indicates the timeout value, in seconds. 85 * <=0 means wait for ever. 86 * >0 means wait for specified seconds 87 * @return Returns <b>0</b> if the operation is successful; 88 * returns <b>-10</b> if timeout; returns <b>-1</b> in other scenarios. 89 * @since 1.1 90 * @version 1.1 91 */ 92 int WaitParameter(const char *key, const char *value, int timeout); 93 94 /** 95 * @brief Watch for system parameter values. 96 * 97 * You can use this function to watch system parameter values.\n 98 * 99 * @param keyPrefix Indicates the key prefix for the parameter to be watched. 100 * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.". 101 * @param callback Indicates value change callback. 102 * If callback is NULL, it means to cancel the watch. 103 * @return Returns <b>0</b> if the operation is successful; 104 * returns <b>-1</b> in other scenarios. 105 * @since 1.1 106 * @version 1.1 107 */ 108 typedef void (*ParameterChgPtr)(const char *key, const char *value, void *context); 109 int WatchParameter(const char *keyPrefix, ParameterChgPtr callback, void *context); 110 111 /** 112 * @brief Remove parameter watcher. 113 * 114 * You can use this function to remove system parameter watcher.\n 115 * 116 * @param keyPrefix Indicates the key prefix for the parameter to be watched. 117 * If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.". 118 * @param callback Indicates value change callback. 119 * If callback is NULL, it means to cancel the watch. 120 * @return Returns <b>0</b> if the operation is successful; 121 * returns <b>-1</b> in other scenarios. 122 * @since 1.1 123 * @version 1.1 124 */ 125 int RemoveParameterWatcher(const char *keyPrefix, ParameterChgPtr callback, void *context); 126 127 /** 128 * @brief Synchronize saving persistent parameters. 129 * 130 * You can use this function to save system parameter in shared memory immediately.\n 131 * 132 * @return Returns <b>0</b> if the operation is successful; 133 * returns <b>-1</b> in other scenarios. 134 * @since 4.1 135 * @version 4.1 136 */ 137 int SaveParameters(void); 138 const char *GetSecurityPatchTag(void); 139 const char *GetOSFullName(void); 140 const char *GetVersionId(void); 141 const char *GetBuildRootHash(void); 142 const char *GetOsReleaseType(void); 143 int GetSdkApiVersion(void); 144 int GetSdkMinorApiVersion(void); 145 int GetSdkPatchApiVersion(void); 146 147 const char *GetDeviceType(void); 148 const char *GetProductModel(void); 149 const char *GetProductModelAlias(void); 150 const char *GetManufacture(void); 151 const char *GetBrand(void); 152 const char *GetMarketName(void); 153 const char *GetProductSeries(void); 154 const char *GetSoftwareModel(void); 155 const char *GetHardwareModel(void); 156 const char *GetHardwareProfile(void); 157 const char *GetSerial(void); 158 const char *GetAbiList(void); 159 const char *GetDisplayVersion(void); 160 const char *GetIncrementalVersion(void); 161 const char *GetBootloaderVersion(void); 162 const char *GetBuildType(void); 163 const char *GetBuildUser(void); 164 const char *GetBuildHost(void); 165 const char *GetBuildTime(void); 166 int GetFirstApiVersion(void); 167 int GetDevUdid(char *udid, int size); 168 169 const char *AclGetSerial(void); 170 int AclGetDevUdid(char *udid, int size); 171 int AclGetDiskSN(char *diskSN, int size); 172 173 int GetPerformanceClass(void); 174 175 /** 176 * @brief Obtains a system parameter matching the specified <b>key</b>. 177 * 178 * If no system parameter is found, return -1.\n 179 * 180 * @param key Indicates the key for the system parameter to find. 181 * @return Returns the index for parameter; 182 * returns <b>handle</b> if a parameter is correct; returns <b>-1</b> in other scenarios. 183 * @since 1 184 * @version 1 185 */ 186 uint32_t FindParameter(const char *key); 187 uint32_t GetParameterCommitId(uint32_t handle); 188 int GetParameterName(uint32_t handle, char *key, uint32_t len); 189 int GetParameterValue(uint32_t handle, char *value, uint32_t len); 190 long long GetSystemCommitId(void); 191 192 int32_t GetIntParameter(const char *key, int32_t def); 193 uint32_t GetUintParameter(const char *key, uint32_t def); 194 195 const char *GetDistributionOSName(void); 196 const char *GetDistributionOSVersion(void); 197 int GetDistributionOSApiVersion(void); 198 const char *GetDistributionOSApiName(void); 199 const char *GetDistributionOSReleaseType(void); 200 201 #ifdef __cplusplus 202 #if __cplusplus 203 } 204 #endif 205 #endif /* __cplusplus */ 206 207 #endif // STARTUP_SYSPARAM_PARAMETER_API_H 208