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