1e41f4b71Sopenharmony_ci# @ohos.systemParameter (System Parameter) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **SystemParameter** module provides system services with easy access to key-value pairs. You can use the APIs provided by this module to describe the service status and change the service behavior. The basic operation primitives are get and set. You can obtain the values of system parameters through getters and modify the values through setters. 4e41f4b71Sopenharmony_ciFor details about the system parameter design principles and definitions, see [Parameter Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md). 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci> **NOTE** 7e41f4b71Sopenharmony_ci> - The APIs of this module are no longer maintained since API version 9. It is recommended that you use [@ohos.systemParameterEnhance](js-apis-system-parameterEnhance-sys.md) instead. 8e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 9e41f4b71Sopenharmony_ci> - The APIs provided by this module are system APIs. 10e41f4b71Sopenharmony_ci> - Third-party applications cannot use the APIs provided by this module, because system parameters each require specific discretionary access control (DAC) and MAC permissions. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Modules to Import 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport systemparameter from '@ohos.systemparameter'; 17e41f4b71Sopenharmony_ci``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## systemparameter.getSync<sup>(deprecated)</sup> 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_cigetSync(key: string, def?: string): string 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciObtains the value of the system parameter with the specified key. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Startup.SystemInfo 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**Parameters** 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 30e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 31e41f4b71Sopenharmony_ci| key | string | Yes| Key of the system parameter.| 32e41f4b71Sopenharmony_ci| def | string | No| Default value of the system parameter.<br> It works only when the system parameter does not exist.<br>The value can be **undefined** or any custom value.| 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Return value** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Type| Description| 37e41f4b71Sopenharmony_ci| -------- | -------- | 38e41f4b71Sopenharmony_ci| string | Value of the system parameter.<br> If the specified key exists, the set value is returned.<br> If the specified key does not exist and **def** is set to a valid value, the set value is returned. If the specified key does not exist and **def** is set to an invalid value (such as **undefined**) or is not set, an empty string is returned.| 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Example** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci```ts 43e41f4b71Sopenharmony_citry { 44e41f4b71Sopenharmony_ci let info: string = systemparameter.getSync("const.ohos.apiversion"); 45e41f4b71Sopenharmony_ci console.log(JSON.stringify(info)); 46e41f4b71Sopenharmony_ci} catch(e) { 47e41f4b71Sopenharmony_ci console.log("getSync unexpected error: " + e); 48e41f4b71Sopenharmony_ci} 49e41f4b71Sopenharmony_ci``` 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci## systemparameter.get<sup>(deprecated)</sup> 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ciget(key: string, callback: AsyncCallback<string>): void 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ciObtains the value of the system parameter with the specified key. This API uses an asynchronous callback to return the result. 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Startup.SystemInfo 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**Parameters** 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 62e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 63e41f4b71Sopenharmony_ci| key | string | Yes| Key of the system parameter.| 64e41f4b71Sopenharmony_ci| callback | AsyncCallback<string> | Yes| Callback used to return the result.| 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci**Example** 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci```ts 69e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_citry { 72e41f4b71Sopenharmony_ci systemparameter.get("const.ohos.apiversion", (err: BusinessError, data: string) => { 73e41f4b71Sopenharmony_ci if (err == undefined) { 74e41f4b71Sopenharmony_ci console.log("get test.parameter.key value success:" + data) 75e41f4b71Sopenharmony_ci } else { 76e41f4b71Sopenharmony_ci console.log(" get test.parameter.key value err:" + err.code) 77e41f4b71Sopenharmony_ci }}); 78e41f4b71Sopenharmony_ci} catch(e) { 79e41f4b71Sopenharmony_ci console.log("get unexpected error: " + e); 80e41f4b71Sopenharmony_ci} 81e41f4b71Sopenharmony_ci``` 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci## systemparameter.get<sup>(deprecated)</sup> 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciget(key: string, def: string, callback: AsyncCallback<string>): void 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ciObtains the value of the system parameter with the specified key. This API uses an asynchronous callback to return the result. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Startup.SystemInfo 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**Parameters** 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 94e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 95e41f4b71Sopenharmony_ci| key | string | Yes| Key of the system parameter.| 96e41f4b71Sopenharmony_ci| def | string | Yes| Default value.| 97e41f4b71Sopenharmony_ci| callback | AsyncCallback<string> | Yes| Callback used to return the result.| 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**Example** 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci```ts 102e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_citry { 105e41f4b71Sopenharmony_ci systemparameter.get("const.ohos.apiversion", "default", (err: BusinessError, data: string) => { 106e41f4b71Sopenharmony_ci if (err == undefined) { 107e41f4b71Sopenharmony_ci console.log("get test.parameter.key value success:" + data) 108e41f4b71Sopenharmony_ci } else { 109e41f4b71Sopenharmony_ci console.log(" get test.parameter.key value err:" + err.code) 110e41f4b71Sopenharmony_ci } 111e41f4b71Sopenharmony_ci }); 112e41f4b71Sopenharmony_ci} catch(e) { 113e41f4b71Sopenharmony_ci console.log("get unexpected error:" + e) 114e41f4b71Sopenharmony_ci} 115e41f4b71Sopenharmony_ci``` 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci## systemparameter.get<sup>(deprecated)</sup> 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ciget(key: string, def?: string): Promise<string> 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciObtains the value of the system parameter with the specified key. This API uses a promise to return the result. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Startup.SystemInfo 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**Parameters** 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 128e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 129e41f4b71Sopenharmony_ci| key | string | Yes| Key of the system parameter.| 130e41f4b71Sopenharmony_ci| def | string | No| Default value of the system parameter.<br> It works only when the system parameter does not exist.<br> The value can be **undefined** or any custom value.| 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**Return value** 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| Type| Description| 135e41f4b71Sopenharmony_ci| -------- | -------- | 136e41f4b71Sopenharmony_ci| Promise<string> | Promise used to return the execution result.| 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**Example** 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci```ts 141e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_citry { 144e41f4b71Sopenharmony_ci let p: Promise<string> = systemparameter.get("const.ohos.apiversion"); 145e41f4b71Sopenharmony_ci p.then((value: string) => { 146e41f4b71Sopenharmony_ci console.log("get test.parameter.key success: " + value); 147e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 148e41f4b71Sopenharmony_ci console.log("get test.parameter.key error: " + err.code); 149e41f4b71Sopenharmony_ci }); 150e41f4b71Sopenharmony_ci} catch(e) { 151e41f4b71Sopenharmony_ci console.log("get unexpected error: " + e); 152e41f4b71Sopenharmony_ci} 153e41f4b71Sopenharmony_ci``` 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci## systemparameter.setSync<sup>(deprecated)</sup> 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_cisetSync(key: string, value: string): void 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ciSets a value for the system parameter with the specified key. 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Startup.SystemInfo 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**Parameters** 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 166e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 167e41f4b71Sopenharmony_ci| key | string | Yes| Key of the system parameter.| 168e41f4b71Sopenharmony_ci| value | string | Yes| Value of the system parameter to set.| 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci> **NOTE** 171e41f4b71Sopenharmony_ci> - This API can be used only for setting parameters of system applications. 172e41f4b71Sopenharmony_ci> - SELinux and Discretionary Access Control (DAC) rules must be configured for authorized system applications. For details about how to configure SELinux and DAC rules, see [Parameter Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md). 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**Example** 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci```ts 178e41f4b71Sopenharmony_citry { 179e41f4b71Sopenharmony_ci systemparameter.setSync("test.parameter.key", "default"); 180e41f4b71Sopenharmony_ci} catch(e) { 181e41f4b71Sopenharmony_ci console.log("set unexpected error: " + e); 182e41f4b71Sopenharmony_ci} 183e41f4b71Sopenharmony_ci``` 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci## systemparameter.set<sup>(deprecated)</sup> 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ciset(key: string, value: string, callback: AsyncCallback<void>): void 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ciSets a value for the system parameter with the specified key. This API uses an asynchronous callback to return the result. 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Startup.SystemInfo 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**Parameters** 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 196e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 197e41f4b71Sopenharmony_ci| key | string | Yes| Key of the system parameter.| 198e41f4b71Sopenharmony_ci| value | string | Yes| Value of the system parameter to set.| 199e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci> **NOTE** 202e41f4b71Sopenharmony_ci> - This API can be used only for setting parameters of system applications. 203e41f4b71Sopenharmony_ci> - SELinux and Discretionary Access Control (DAC) rules must be configured for authorized system applications. For details about how to configure SELinux and DAC rules, see [Parameter Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md). 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**Example** 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci```ts 208e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_citry { 211e41f4b71Sopenharmony_ci systemparameter.set("test.parameter.key", "testValue", (err: BusinessError, data: void) =>{ 212e41f4b71Sopenharmony_ci if (err == undefined) { 213e41f4b71Sopenharmony_ci console.log("set test.parameter.key value success :" + data) 214e41f4b71Sopenharmony_ci } else { 215e41f4b71Sopenharmony_ci console.log("set test.parameter.key value err:" + err.code) 216e41f4b71Sopenharmony_ci }}); 217e41f4b71Sopenharmony_ci} catch(e) { 218e41f4b71Sopenharmony_ci console.log("set unexpected error: " + e); 219e41f4b71Sopenharmony_ci} 220e41f4b71Sopenharmony_ci``` 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci## systemparameter.set<sup>(deprecated)</sup> 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ciset(key: string, value: string): Promise<void> 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ciSets a value for the system parameter with the specified key. This API uses a promise to return the result. 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Startup.SystemInfo 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci**Parameters** 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 233e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 234e41f4b71Sopenharmony_ci| key | string | Yes| Key of the system parameter.| 235e41f4b71Sopenharmony_ci| value| string | Yes| Value of the system parameter to set.| 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci**Return value** 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci| Type| Description| 240e41f4b71Sopenharmony_ci| -------- | -------- | 241e41f4b71Sopenharmony_ci| Promise<void> | Promise used to return the execution result.| 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci> **NOTE** 244e41f4b71Sopenharmony_ci> - This API can be used only for setting parameters of system applications. 245e41f4b71Sopenharmony_ci> - SELinux and Discretionary Access Control (DAC) rules must be configured for authorized system applications. For details about how to configure SELinux and DAC rules, see [Parameter Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md). 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci**Example** 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci```ts 250e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_citry { 253e41f4b71Sopenharmony_ci let p: Promise<void> = systemparameter.set("test.parameter.key", "testValue"); 254e41f4b71Sopenharmony_ci p.then((value: void) => { 255e41f4b71Sopenharmony_ci console.log("set test.parameter.key success: " + value); 256e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 257e41f4b71Sopenharmony_ci console.log(" set test.parameter.key error: " + err.code); 258e41f4b71Sopenharmony_ci }); 259e41f4b71Sopenharmony_ci} catch(e) { 260e41f4b71Sopenharmony_ci console.log("set unexpected error: " + e); 261e41f4b71Sopenharmony_ci} 262e41f4b71Sopenharmony_ci``` 263