提交 43623a01 编写于 作者: E ester.zhou

Update doc (10080)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 a01cf7b5
# System Parameter
# SystemParameter
> **NOTE**<br>
The **SystemParameter** module provides system services with easy access to key-value pairs. You can use the APIs of 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.
For details about the system parameter design principles and definitions, see
[Service Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md).
> **NOTE**
>
> - The APIs of this module are no longer maintained since API version 9. It is recommended that you use [@ohos.systemParameterV9](js-apis-system-parameterV9.md) instead.
> - 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.
> - This is a system API and cannot be called by third-party applications.
> - The APIs provided by this module are system APIs.
> - Third-party applications cannot use the APIs provided by this module, because system parameters each require specific discretionary access control (DAC) and MAC permissions.
## Modules to Import
```ts
import parameter from '@ohos.systemparameter'
import systemparameter from '@ohos.systemparameter'
```
## parameter.getSync
## systemparameter.getSync<sup>(deprecated)</sup>
getSync(key: string, def?: string): string
Obtains the value of the attribute with the specified key.
Obtains the value of the system parameter with the specified key.
**System capability**: SystemCapability.Startup.SystemInfo
......@@ -23,32 +30,31 @@ Obtains the value of the attribute with the specified key.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system attribute.|
| key | string | Yes| Key of the system parameter.|
| def | string | No| Default value.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | System attribute value. If the specified key does not exist, the default value is returned. If no default value has been set, an empty string will be returned.|
| string | Value of the system parameter. If the specified key does not exist, the default value is returned. If no default value has been set, an empty string will be returned.|
**Example**
```ts
try {
var info = parameter.getSync("test.parameter.key");
var info = systemparameter.getSync("const.ohos.apiversion");
console.log(JSON.stringify(info));
}catch(e){
console.log("getSync unexpected error: " + e);
}
```
## parameter.get
## systemparameter.get<sup>(deprecated)</sup>
get(key: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the value of the attribute with the specified key. This API uses an asynchronous callback to return the result.
Obtains the value of the system parameter with the specified key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
......@@ -56,14 +62,14 @@ Obtains the value of the attribute with the specified key. This API uses an asyn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system attribute.|
| key | string | Yes| Key of the system parameter.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
**Example**
```ts
try {
parameter.get("test.parameter.key", function (err, data) {
systemparameter.get("const.ohos.apiversion", function (err, data) {
if (err == undefined) {
console.log("get test.parameter.key value success:" + data)
} else {
......@@ -74,12 +80,11 @@ try {
}
```
## parameter.get
## systemparameter.get<sup>(deprecated)</sup>
get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the value of the attribute with the specified key. This API uses an asynchronous callback to return the result.
Obtains the value of the system parameter with the specified key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
......@@ -87,7 +92,7 @@ Obtains the value of the attribute with the specified key. This API uses an asyn
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system attribute.|
| key | string | Yes| Key of the system parameter.|
| def | string | Yes| Default value.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
......@@ -95,7 +100,7 @@ Obtains the value of the attribute with the specified key. This API uses an asyn
```ts
try {
parameter.get("test.parameter.key", "default", function (err, data) {
systemparameter.get("const.ohos.apiversion", "default", function (err, data) {
if (err == undefined) {
console.log("get test.parameter.key value success:" + data)
} else {
......@@ -107,12 +112,11 @@ try {
}
```
## parameter.get
## systemparameter.get<sup>(deprecated)</sup>
get(key: string, def?: string): Promise&lt;string&gt;
Obtains the value of the attribute with the specified key. This API uses a promise to return the result.
Obtains the value of the system parameter with the specified key. This API uses a promise to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
......@@ -120,7 +124,7 @@ Obtains the value of the attribute with the specified key. This API uses a promi
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system attribute.|
| key | string | Yes| Key of the system parameter.|
| def | string | No| Default value.|
**Return value**
......@@ -133,7 +137,7 @@ Obtains the value of the attribute with the specified key. This API uses a promi
```ts
try {
var p = parameter.get("test.parameter.key");
var p = systemparameter.get("const.ohos.apiversion");
p.then(function (value) {
console.log("get test.parameter.key success: " + value);
}).catch(function (err) {
......@@ -144,12 +148,11 @@ try {
}
```
## parameter.setSync
## systemparameter.setSync<sup>(deprecated)</sup>
setSync(key: string, value: string): void
Sets a value for the attribute with the specified key.
Sets a value for the system parameter with the specified key.
**System capability**: SystemCapability.Startup.SystemInfo
......@@ -157,25 +160,29 @@ Sets a value for the attribute with the specified key.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system attribute.|
| value | string | Yes| System attribute value to set.|
| key | string | Yes| Key of the system parameter.|
| value | string | Yes| Value of the system parameter to set.|
> **NOTE**
>
> - This API can be used only for setting parameters of system applications.
> - SELinux and DAC rules must be configured for authorized system applications. For details, see [Service Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md).
**Example**
```ts
try {
parameter.setSync("test.parameter.key", "default");
systemparameter.setSync("test.parameter.key", "default");
}catch(e){
console.log("set unexpected error: " + e);
}
```
## parameter.set
## systemparameter.set<sup>(deprecated)</sup>
set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
Sets a value for the attribute with the specified key. This API uses an asynchronous callback to return the result.
Sets a value for the system parameter with the specified key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
......@@ -183,15 +190,20 @@ Sets a value for the attribute with the specified key. This API uses an asynchro
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system attribute.|
| value | string | Yes| System attribute value to set.|
| key | string | Yes| Key of the system parameter.|
| value | string | Yes| Value of the system parameter to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
> **NOTE**
>
> - This API can be used only for setting parameters of system applications.
> - SELinux and discretionary access control (DAC) rules must be configured for authorized system applications. For details, see [Service Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md).
**Example**
```ts
try {
parameter.set("test.parameter.key", "testValue", function (err, data) {
systemparameter.set("test.parameter.key", "testValue", function (err, data) {
if (err == undefined) {
console.log("set test.parameter.key value success :" + data)
} else {
......@@ -202,12 +214,11 @@ try {
}
```
## parameter.set
## systemparameter.set<sup>(deprecated)</sup>
set(key: string, value: string): Promise&lt;void&gt;
Sets a value for the attribute with the specified key. This API uses a promise to return the result.
Sets a value for the system parameter with the specified key. This API uses a promise to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
......@@ -215,8 +226,8 @@ Sets a value for the attribute with the specified key. This API uses a promise t
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system attribute.|
| value| string | Yes| System attribute value to set.|
| key | string | Yes| Key of the system parameter.|
| value| string | Yes| Value of the system parameter to set.|
**Return value**
......@@ -224,11 +235,16 @@ Sets a value for the attribute with the specified key. This API uses a promise t
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the execution result.|
> **NOTE**
>
> - This API can be used only for setting parameters of system applications.
> - SELinux and discretionary access control (DAC) rules must be configured for authorized system applications. For details, see [Service Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md).
**Example**
```ts
try {
var p = para.set("test.parameter.key", "testValue");
var p = systemparameter.set("test.parameter.key", "testValue");
p.then(function (value) {
console.log("set test.parameter.key success: " + value);
}).catch(function (err) {
......
# SystemParameter
The **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.
For details about the system parameter design principles and definitions, see
[Service Management](../../../device-dev/subsystems/subsys-boot-init-sysparam.md).
> **NOTE**
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are system APIs.
> - Third-party applications cannot use the APIs provided by this module, because system parameters each require specific discretionary access control (DAC) and MAC permissions.
## Modules to Import
```ts
import systemparameter from '@ohos.systemParameterV9'
```
## systemparameter.getSync
getSync(key: string, def?: string): string
Obtains the value of the system parameter with the specified key.
**System capability**: SystemCapability.Startup.SystemInfo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system parameter.|
| def | string | No| Default value.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | Value of the system parameter. If the specified key does not exist, the default value is returned. If no default value has been set, an empty string will be returned.|
**Example**
```ts
try {
var info = systemparameter.getSync("const.ohos.apiversion");
console.log(JSON.stringify(info));
}catch(e){
console.log("getSync unexpected error: " + e);
}
```
## systemparameter.get
get(key: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the value of the system parameter with the specified key.
**System capability**: SystemCapability.Startup.SystemInfo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system parameter.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
**Example**
```ts
try {
systemparameter.get("const.ohos.apiversion", function (err, data) {
if (err == undefined) {
console.log("get test.parameter.key value success:" + data)
} else {
console.log(" get test.parameter.key value err:" + err.code)
}});
}catch(e){
console.log("get unexpected error: " + e);
}
```
## systemparameter.get
get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the value of the system parameter with the specified key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system parameter.|
| def | string | Yes| Default value.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
**Example**
```ts
try {
systemparameter.get("const.ohos.apiversion", "default", function (err, data) {
if (err == undefined) {
console.log("get test.parameter.key value success:" + data)
} else {
console.log(" get test.parameter.key value err:" + err.code)
}
});
}catch(e){
console.log("get unexpected error:" + e)
}
```
## systemparameter.get
get(key: string, def?: string): Promise&lt;string&gt;
Obtains the value of the system parameter with the specified key. This API uses a promise to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system parameter.|
| def | string | No| Default value.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the execution result.|
**Example**
```ts
try {
var p = systemparameter.get("const.ohos.apiversion");
p.then(function (value) {
console.log("get test.parameter.key success: " + value);
}).catch(function (err) {
console.log("get test.parameter.key error: " + err.code);
});
}catch(e){
console.log("get unexpected error: " + e);
}
```
## systemparameter.setSync
setSync(key: string, value: string): void
Sets a value for the system parameter with the specified key.
**System capability**: SystemCapability.Startup.SystemInfo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system parameter.|
| value | string | Yes| Value of the system parameter to set.|
**Example**
```ts
try {
systemparameter.setSync("test.parameter.key", "default");
}catch(e){
console.log("set unexpected error: " + e);
}
```
## systemparameter.set
set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
Sets a value for the system parameter with the specified key. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system parameter.|
| value | string | Yes| Value of the system parameter to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
**Example**
```ts
try {
systemparameter.set("test.parameter.key", "testValue", function (err, data) {
if (err == undefined) {
console.log("set test.parameter.key value success :" + data)
} else {
console.log("set test.parameter.key value err:" + err.code)
}});
}catch(e){
console.log("set unexpected error: " + e);
}
```
## systemparameter.set
set(key: string, value: string): Promise&lt;void&gt;
Sets a value for the system parameter with the specified key. This API uses a promise to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the system parameter.|
| value| string | Yes| Value of the system parameter to set.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the execution result.|
**Example**
```ts
try {
var p = systemparameter.set("test.parameter.key", "testValue");
p.then(function (value) {
console.log("set test.parameter.key success: " + value);
}).catch(function (err) {
console.log(" set test.parameter.key error: " + err.code);
});
}catch(e){
console.log("set unexpected error: " + e);
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册