未验证 提交 133b1959 编写于 作者: O openharmony_ci 提交者: Gitee

!1707 翻译已完成

Merge pull request !1707 from shawn_he/hichecker-1
# Performance Tracing<a name="EN-US_TOPIC_0000001165886716"></a> # Performance Tracing
>![](../../public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> - The APIs of this module are no longer maintained since API version 8. It is recommended that you use the APIs of [hiTraceMeter](js-apis-hitracemeter.md) instead. > - The APIs of this module are no longer maintained since API version 8. It is recommended that you use the APIs of [hiTraceMeter](js-apis-hitracemeter.md) instead.
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
## Modules to Import
``` ```
import bytrace from '@ohos.bytrace'; import bytrace from '@ohos.bytrace';
``` ```
## Required Permissions<a name="section11257113618419"></a>
## System Capabilities
None
SystemCapability.Developtools.Bytrace
## bytrace.startTrace<a name="section785191510485"></a>
startTrace\(name: string, taskId: number, expectedTime?: number\): void ## bytrace.startTrace
Starts a trace of a task. **expectedTime** is an optional parameter, which specifies the expected duration of the trace. startTrace(name: string, taskId: number, expectedTime?: number): void
- Parameters Starts a trace task. **expectedTime** is an optional parameter, which specifies the expected duration of the trace.
<a name="table69661135912"></a> **Parameters**
<table><thead align="left"><tr id="row149668318915"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p7966738914"><a name="p7966738914"></a><a name="p7966738914"></a>Name</p>
</th> | Name| Type| Mandatory| Description|
<th class="cellrowborder" valign="top" width="13.22%" id="mcps1.1.5.1.2"><p id="p296713699"><a name="p296713699"></a><a name="p296713699"></a>Type</p> | -------- | -------- | -------- | -------- |
</th> | name | string | Yes| Name of the trace task to start.|
<th class="cellrowborder" valign="top" width="10.67%" id="mcps1.1.5.1.3"><p id="p196718315911"><a name="p196718315911"></a><a name="p196718315911"></a>Mandatory</p> | taskId | number | Yes| Task ID.|
</th> | expectedTime | number | No| Expected duration of the trace, in ms.|
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p9967231197"><a name="p9967231197"></a><a name="p9967231197"></a>Description</p>
</th> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
</tr> > If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same taskId can be used. For details, see the bytrace.finishTrace example.
</thead>
<tbody><tr id="row99671533914"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p79671633910"><a name="p79671633910"></a><a name="p79671633910"></a>name</p> **Example**
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p11967433914"><a name="p11967433914"></a><a name="p11967433914"></a>string</p> ```
</td> bytrace.startTrace("myTestFunc", 1);
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p19671336916"><a name="p19671336916"></a><a name="p19671336916"></a>Yes</p> bytrace.startTrace("myTestFunc", 1, 5); // The expected duration of the trace is 5 ms.
</td> ```
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p2084833211463"><a name="p2084833211463"></a><a name="p2084833211463"></a>Name of the trace task to start.</p>
</td>
</tr> ## bytrace.finishTrace
<tr id="row18967831393"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p16813106387"><a name="p16813106387"></a><a name="p16813106387"></a>taskId</p>
</td> finishTrace(name: string, taskId: number): void
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p976115416386"><a name="p976115416386"></a><a name="p976115416386"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p149671932919"><a name="p149671932919"></a><a name="p149671932919"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p19675312911"><a name="p19675312911"></a><a name="p19675312911"></a>Task ID.</p>
</td>
</tr>
<tr id="row1225911163813"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p132250110380"><a name="p132250110380"></a><a name="p132250110380"></a>expectedTime</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p1622551113381"><a name="p1622551113381"></a><a name="p1622551113381"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p5226151110383"><a name="p5226151110383"></a><a name="p5226151110383"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p22262111381"><a name="p22262111381"></a><a name="p22262111381"></a>Expected duration of the trace, in ms.</p>
</td>
</tr>
</tbody>
</table>
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different **taskId**s must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same **taskId** can be used. For details, see the **bytrace.finishTrace** example.
- Example
```
bytrace.startTrace("myTestFunc", 1);
bytrace.startTrace("myTestFunc", 1, 5); // The expected duration of the trace is 5 ms.
```
## bytrace.finishTrace<a name="section7895134841213"></a>
finishTrace\(name: string, taskId: number\): void
Stops a trace task. Stops a trace task.
- Parameters **Parameters**
<a name="table1589613488127"></a> | Name| Type| Mandatory| Description|
<table><thead align="left"><tr id="row208961448131215"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p1089674831216"><a name="p1089674831216"></a><a name="p1089674831216"></a>Name</p> | -------- | -------- | -------- | -------- |
</th> | name | string | Yes| Name of the trace task to start.|
<th class="cellrowborder" valign="top" width="13.22%" id="mcps1.1.5.1.2"><p id="p1689613481128"><a name="p1689613481128"></a><a name="p1689613481128"></a>Type</p> | taskId | number | Yes| Task ID.|
</th>
<th class="cellrowborder" valign="top" width="10.67%" id="mcps1.1.5.1.3"><p id="p989613483125"><a name="p989613483125"></a><a name="p989613483125"></a>Mandatory</p> > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
</th> > To stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in **startTrace**.
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p13896148111215"><a name="p13896148111215"></a><a name="p13896148111215"></a>Description</p>
</th> **Example**
</tr>
</thead> ```
<tbody><tr id="row14896204817125"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p10896174817128"><a name="p10896174817128"></a><a name="p10896174817128"></a>name</p> bytrace.finishTrace("myTestFunc", 1);
</td> ```
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p189618483125"><a name="p189618483125"></a><a name="p189618483125"></a>string</p>
</td> ```
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p118961548101215"><a name="p118961548101215"></a><a name="p118961548101215"></a>Yes</p> // Start track tasks with the same name concurrently.
</td> bytrace.startTrace("myTestFunc", 1);
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p1989674810124"><a name="p1989674810124"></a><a name="p1989674810124"></a>Name of the trace task to stop.</p> // Service flow
</td> bytrace.startTrace("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
</tr> // Service flow
<tr id="row5896548101211"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p10896164811121"><a name="p10896164811121"></a><a name="p10896164811121"></a>taskId</p> bytrace.finishTrace("myTestFunc", 1);
</td> // Service flow
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p1789694821215"><a name="p1789694821215"></a><a name="p1789694821215"></a>number</p> bytrace.finishTrace("myTestFunc", 2);
</td> ```
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p08962488128"><a name="p08962488128"></a><a name="p08962488128"></a>Yes</p>
</td> ```
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p8896194831214"><a name="p8896194831214"></a><a name="p8896194831214"></a>Task ID.</p> // Start track tasks with the same name at different times.
</td> bytrace.startTrace("myTestFunc", 1);
</tr> // Service flow
</tbody> bytrace.finishTrace("myTestFunc", 1); // The first trace task ends.
</table> // Service flow
bytrace.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
>![](../../public_sys-resources/icon-note.gif) **NOTE:** // Service flow
>To stop a trace task, the values of **name** and **taskId** in **finishTrace** must be the same as those in **startTrace**. bytrace.finishTrace("myTestFunc", 1);
```
- Example
``` ## bytrace.traceByValue
bytrace.finishTrace("myTestFunc", 1);
``` traceByValue(name: string, value: number): void
```
// Start track tasks with the same name concurrently.
bytrace.startTrace("myTestFunc", 1);
...... // Service flow
bytrace.startTrace ("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
...... // Service flow
bytrace.finishTrace("myTestFunc", 1);
...... // Service flow
bytrace.finishTrace("myTestFunc", 2);
```
```
// Start track tasks with the same name at different times.
bytrace.startTrace("myTestFunc", 1);
...... // Service flow
bytrace.finishTrace("myTestFunc", 1); // The first trace task ends.
...... // Service flow
bytrace.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
...... // Service flow
bytrace.finishTrace("myTestFunc", 1);
```
## bytrace.traceByValue<a name="section1388414179173"></a>
traceByValue\(name: string, value: number\): void
Traces the value changes of a variable. Traces the value changes of a variable.
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
<a name="table0884617171718"></a> | -------- | -------- | -------- | -------- |
<table><thead align="left"><tr id="row1188481771714"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p488419174178"><a name="p488419174178"></a><a name="p488419174178"></a>Name</p> | name | string | Yes| Name of the variable.|
</th> | value | number | Yes| Value of the variable.|
<th class="cellrowborder" valign="top" width="13.22%" id="mcps1.1.5.1.2"><p id="p12884131721718"><a name="p12884131721718"></a><a name="p12884131721718"></a>Type</p>
</th> **Example**
<th class="cellrowborder" valign="top" width="10.67%" id="mcps1.1.5.1.3"><p id="p188481714178"><a name="p188481714178"></a><a name="p188481714178"></a>Mandatory</p>
</th> ```
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p188411174177"><a name="p188411174177"></a><a name="p188411174177"></a>Description</p> let traceCount = 3;
</th> bytrace.traceByValue("myTestCount", traceCount);
</tr> traceCount = 4;
</thead> bytrace.traceByValue("myTestCount", traceCount);
<tbody><tr id="row38849172174"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p7884121719172"><a name="p7884121719172"></a><a name="p7884121719172"></a>name</p> // Service flow
</td> ```
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p1488415174171"><a name="p1488415174171"></a><a name="p1488415174171"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p7884171711717"><a name="p7884171711717"></a><a name="p7884171711717"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p17884517161715"><a name="p17884517161715"></a><a name="p17884517161715"></a>Name of the variable to trace.</p>
</td>
</tr>
<tr id="row188419179172"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p206756457267"><a name="p206756457267"></a><a name="p206756457267"></a>value</p>
</td>
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.1.5.1.2 "><p id="p9884917111710"><a name="p9884917111710"></a><a name="p9884917111710"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="10.67%" headers="mcps1.1.5.1.3 "><p id="p18841217141719"><a name="p18841217141719"></a><a name="p18841217141719"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p178842174174"><a name="p178842174174"></a><a name="p178842174174"></a>Value of the variable to trace.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
let traceCount = 3;
bytrace.traceByValue("myTestCount", traceCount);
......
traceCount = 5;
bytrace.traceByValue("myTestCount", traceCount);
```
# Call # Call
>**Note:** >**NOTE**
> >
>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. >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.
...@@ -19,20 +19,20 @@ Initiates a call. This function uses an asynchronous callback to return the exec ...@@ -19,20 +19,20 @@ Initiates a call. This function uses an asynchronous callback to return the exec
Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission). Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission).
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | ----------- | ---------------------------- | ---- | ------------------------------------------------- |
| phoneNumber | string | Yes|Phone number.| | phoneNumber | string | Yes| Phone number.|
| callback |AsyncCallback&lt;boolean&gt;|Yes|Callback used to return the result.<br/> - **true**: success <br/> -**false**: failure| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: success <br/> - **false**: failure|
- Example **Example**
``` ```
call.dial("138xxxxxxxx", (err, data) => { call.dial("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.dial<a name=call.dial-callback2></a> ## call.dial<a name=call.dial-callback2></a>
...@@ -43,24 +43,23 @@ Initiates a call. You can set call options as needed. This function uses an asyn ...@@ -43,24 +43,23 @@ Initiates a call. You can set call options as needed. This function uses an asyn
Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission). Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission).
- Parameters **Parameters**
| Parameter| Type| Mandatory| Description|
| ----------- | ---------------------------- | ---- | ------------------------------------------------- |
| phoneNumber | string | Yes| Phone number.|
| options | DialOptions | Yes| Call options. For details, see [DialOptions](#DialOptions).|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: success <br/> -**false**: failure|
| Name| Type| Mandatory| Description|
| ----------- | ---------------------------- | ---- | ------------------------------------------------- |
| phoneNumber | string | Yes| Phone number.|
| options | DialOptions | Yes| Call options. For details, see [DialOptions](#DialOptions).|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: success <br/> - **false**: failure|
- Example **Example**
``` ```
call.dial("138xxxxxxxx", { call.dial("138xxxxxxxx", {
extras: false extras: false
}, (err, data) => { }, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.dial<a name=call.dial-promise></a> ## call.dial<a name=call.dial-promise></a>
...@@ -71,31 +70,31 @@ Initiates a call. You can set call options as needed. This function uses a promi ...@@ -71,31 +70,31 @@ Initiates a call. You can set call options as needed. This function uses a promi
Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission). Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission).
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | ----------- | ---- | ------------------------------------------- | | ----------- | ----------- | ---- | ------------------------------------------- |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| options | DialOptions | Yes| Call options. For details, see [DialOptions](#DialOptions).| | options | DialOptions | Yes| Call options. For details, see [DialOptions](#DialOptions).|
- Return values **Return value**
| Type| Description| | Type| Description|
| ---------------------- | --------------------------------- | | ---------------------- | --------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.| | Promise&lt;boolean&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let promise = call.dial("138xxxxxxxx", { let promise = call.dial("138xxxxxxxx", {
extras: false extras: false
}); });
promise.then(data => { promise.then(data => {
console.log(`dial success, promise: data->${JSON.stringify(data)}`); console.log(`dial success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`dial fail, promise: err->${JSON.stringify(err)}`); console.error(`dial fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## call.hasCall<a name=call.hasCall-callback></a> ## call.hasCall<a name=call.hasCall-callback></a>
...@@ -103,19 +102,19 @@ hasCall\(callback: AsyncCallback<boolean\>\): void ...@@ -103,19 +102,19 @@ hasCall\(callback: AsyncCallback<boolean\>\): void
Checks whether a call is in progress. This function uses an asynchronous callback to return the result. Checks whether a call is in progress. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result: <br/> - **true**: A call is in progress. <br/> - **false**: No call is in progress. | | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result: <br/> - **true**: A call is in progress. <br/> - **false**: No call is in progress. |
- Example **Example**
``` ```
call.hasCall((err, data) => { call.hasCall((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.hasCall<a name=call.hasCall-promise></a> ## call.hasCall<a name=call.hasCall-promise></a>
...@@ -124,22 +123,22 @@ hasCall\(\): Promise<boolean\> ...@@ -124,22 +123,22 @@ hasCall\(\): Promise<boolean\>
Checks whether a call is in progress. This function uses a promise to return the result. Checks whether a call is in progress. This function uses a promise to return the result.
- Return values **Return value**
| Type| Description| | Type| Description|
| ---------------------- | --------------------------------------- | | ---------------------- | --------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.| | Promise&lt;boolean&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let promise = call.hasCall(); let promise = call.hasCall();
promise.then(data => { promise.then(data => {
console.log(`hasCall success, promise: data->${JSON.stringify(data)}`); console.log(`hasCall success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`); console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## call.getCallState<a name=call.getCallState-callback></a> ## call.getCallState<a name=call.getCallState-callback></a>
...@@ -148,19 +147,19 @@ getCallState\(callback: AsyncCallback<CallState\>\): void ...@@ -148,19 +147,19 @@ getCallState\(callback: AsyncCallback<CallState\>\): void
Obtains the call status. This function uses an asynchronous callback to return the result. Obtains the call status. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------------------------------------------- | ---- | ------------------------------------ | | -------- | -------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[CallState](#CallState)&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;[CallState](#CallState)&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```
call.getCallState((err, data) => { call.getCallState((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.getCallState<a name="call.getCallState-promise"></a> ## call.getCallState<a name="call.getCallState-promise"></a>
...@@ -169,118 +168,118 @@ getCallState\(\): Promise<CallState\> ...@@ -169,118 +168,118 @@ getCallState\(\): Promise<CallState\>
Obtains the call status. This function uses a promise to return the result. Obtains the call status. This function uses a promise to return the result.
- Return values **Return value**
| Type| Description| | Type| Description|
| -------------------------------------- | ----------------------------------------- | | -------------------------------------- | ----------------------------------------- |
| Promise&lt;[CallState](#CallState)&gt; | Promise used to return the result.| | Promise&lt;[CallState](#CallState)&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let promise = call.getCallState(); let promise = call.getCallState();
promise.then(data => { promise.then(data => {
console.log(`getCallState success, promise: data->${JSON.stringify(data)}`); console.log(`getCallState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`); console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-callback1></a> ## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-callback1></a>
isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
Checks whether the call number is an emergency number. This function uses an asynchronous callback to return the result. Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ | | ----------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: The called number is an emergency number. <br/> - **false**: The called number is not an emergency number.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: The called number is an emergency number. <br/> - **false**: The called number is not an emergency number.|
- Example **Example**
``` ```
call.isEmergencyPhoneNumber("138xxxxxxxx", (err, data) => { call.isEmergencyPhoneNumber("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-callback2></a> ## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-callback2></a>
isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback<boolean\>\): void isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback<boolean\>\): void
Checks whether the call number is an emergency number. This function uses an asynchronous callback to return the result. Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ | | ----------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| options | EmergencyNumberOptions | Yes| Emergency number options defined in [EmergencyNumberOptions](#EmergencyNumberOptions).| | options | EmergencyNumberOptions | Yes| Emergency number options defined in [EmergencyNumberOptions](#EmergencyNumberOptions).|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: The called number is an emergency number. <br/> - **false**: The called number is not an emergency number.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: The called number is an emergency number. <br/> - **false**: The called number is not an emergency number.|
- Example **Example**
``` ```
call.isEmergencyPhoneNumber("112", {slotId: 1}, (err, value) => { call.isEmergencyPhoneNumber("112", {slotId: 1}, (err, value) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-promise></a> ## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-promise></a>
isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise<boolean\> isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise<boolean\>
Checks whether the call number is an emergency number. This function uses a promise to return the result. Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | ---------------------- | ---- | ------------------------------------------------------------ | | ----------- | ---------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| options | EmergencyNumberOptions | Yes| Emergency number options defined in [EmergencyNumberOptions](#EmergencyNumberOptions).| | options | EmergencyNumberOptions | Yes| Emergency number options defined in [EmergencyNumberOptions](#EmergencyNumberOptions).|
- Return values **Return value**
| Type| Description| | Type| Description|
| ---------------------- | --------------------------------------------------- | | ---------------------- | --------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.| | Promise&lt;boolean&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let promise = call.isEmergencyPhoneNumber("138xxxxxxxx", {slotId: 1}); let promise = call.isEmergencyPhoneNumber("138xxxxxxxx", {slotId: 1});
promise.then(data => { promise.then(data => {
console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`); console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`); console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-callback1></a> ## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-callback1></a>
formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void
Formats a phone number. This function uses an asynchronous callback to return the result. Formats a phone number based on the specified ISO country code. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | --------------------------- | ---- | ------------------------------------ | | ----------- | --------------------------- | ---- | ------------------------------------ |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```
call.formatPhoneNumber("138xxxxxxxx", (err, data) => { call.formatPhoneNumber("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-callback2></a> ## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-callback2></a>
...@@ -289,23 +288,23 @@ formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: ...@@ -289,23 +288,23 @@ formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback:
Formats a phone number based on specified formatting options. This function uses an asynchronous callback to return the result. Formats a phone number based on specified formatting options. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | --------------------------- | ---- | ------------------------------------------------------------ | | ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| options | NumberFormatOptions | Yes| Number formatting options defined in [NumberFormatOptions](#NumberFormatOptions).| | options | NumberFormatOptions | Yes| Number formatting options defined in [NumberFormatOptions](#NumberFormatOptions).|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```
call.formatPhoneNumber("138xxxxxxxx",{ call.formatPhoneNumber("138xxxxxxxx",{
countryCode: "CN" countryCode: "CN"
}, (err, data) => { }, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-promise></a> ## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-promise></a>
...@@ -314,31 +313,31 @@ formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise ...@@ -314,31 +313,31 @@ formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise
Formats a phone number based on specified formatting options. This function uses a promise to return the result. Formats a phone number based on specified formatting options. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | ------------------- | ---- | ------------------------------------------------------------ | | ----------- | ------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| options | NumberFormatOptions | Yes| Number formatting options defined in [NumberFormatOptions](#NumberFormatOptions).| | options | NumberFormatOptions | Yes| Number formatting options defined in [NumberFormatOptions](#NumberFormatOptions).|
- Return values **Return value**
| Type| Description| | Type| Description|
| --------------------- | ------------------------------------------- | | --------------------- | ------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.| | Promise&lt;string&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let promise = call.formatPhoneNumber("138xxxxxxxx", { let promise = call.formatPhoneNumber("138xxxxxxxx", {
countryCode: "CN" countryCode: "CN"
}); });
promise.then(data => { promise.then(data => {
console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`); console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`); console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## call.formatPhoneNumberToE164<sup>7+</sup><a name=call.formatPhoneNumberToE164-callback></a> ## call.formatPhoneNumberToE164<sup>7+</sup><a name=call.formatPhoneNumberToE164-callback></a>
...@@ -350,23 +349,23 @@ The phone number must match the specified country code. For example, for a China ...@@ -350,23 +349,23 @@ The phone number must match the specified country code. For example, for a China
All country codes are supported. All country codes are supported.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | --------------------------- | ---- | ----------------------------------------------------- | | ----------- | --------------------------- | ---- | ----------------------------------------------------- |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| countryCode | string | Yes| Country code, for example, **CN** (China). All country codes are supported.| | countryCode | string | Yes| Country code, for example, **CN** (China). All country codes are supported.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```
call.formatPhoneNumberToE164("138xxxxxxxx",{ call.formatPhoneNumberToE164("138xxxxxxxx",{
countryCode: "CN" countryCode: "CN"
}, (err, data) => { }, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## call.formatPhoneNumberToE164<sup>7+</sup><a name=call.formatPhoneNumberToE164-promise></a> ## call.formatPhoneNumberToE164<sup>7+</sup><a name=call.formatPhoneNumberToE164-promise></a>
...@@ -379,44 +378,44 @@ The phone number must match the specified country code. For example, for a China ...@@ -379,44 +378,44 @@ The phone number must match the specified country code. For example, for a China
All country codes are supported. All country codes are supported.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ----------- | ------ | ---- | ---------------------------------------- | | ----------- | ------ | ---- | ---------------------------------------- |
| phoneNumber | string | Yes| Phone number.| | phoneNumber | string | Yes| Phone number.|
| countryCode | string | Yes| Country code, for example, **CN** (China). All country codes are supported.| | countryCode | string | Yes| Country code, for example, **CN** (China). All country codes are supported.|
- Return values **Return value**
| Type| Description| | Type| Description|
| --------------------- | ------------------------------------------------------------ | | --------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise used to return the result.| | Promise&lt;string&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let promise = call.formatPhoneNumberToE164("138xxxxxxxx", { let promise = call.formatPhoneNumberToE164("138xxxxxxxx", {
countryCode: "CN" countryCode: "CN"
}); });
promise.then(data => { promise.then(data => {
console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`); console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`); console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## DialOptions<a name=DialOptions></a> ## DialOptions<a name=DialOptions></a>
Provides an option for determining whether a call is a video call. Provides an option for determining whether a call is a video call.
| Name| Type| Mandatory| Description| | Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | ------ | ------- | ---- | ------------------------------------------------------------ |
| extras | boolean | No|Indication of a video call. The options are as follows: <br/> - **true**: video call <br/> - **false**: voice call| | extras | boolean | No| Indication of a video call. The options are as follows: <br/> - **true**: video call <br/> - **false**: voice call|
## CallState<a name=CallState></a> ## CallState<a name=CallState></a>
Enumerates call states. Enumerates call states.
| Variable| Value| Description| | Variable| Value| Description|
| -------- | -------- | -------- | | ------------------ | ---- | ------------------------------------------------------------ |
| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown.| | CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown.|
| CALL_STATE_IDLE | 0 | No call is in progress.| | CALL_STATE_IDLE | 0 | No call is in progress.|
| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state.| | CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state.|
...@@ -425,13 +424,13 @@ Enumerates call states. ...@@ -425,13 +424,13 @@ Enumerates call states.
## EmergencyNumberOptions<sup>7+</sup><a name=EmergencyNumberOptions></a> ## EmergencyNumberOptions<sup>7+</sup><a name=EmergencyNumberOptions></a>
Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot. Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot.
| Name| Type| Mandatory| Description| | Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | ------ | ------ | ---- | ------------------------------------------ |
| slotId | number | No|SIM card slot ID.<br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | No| SIM card slot ID.<br/> - **0**: slot 1 <br/> - **1**: slot 2|
## NumberFormatOptions<sup>7+</sup><a name=NumberFormatOptions></a> ## NumberFormatOptions<sup>7+</sup><a name=NumberFormatOptions></a>
Provides an option for number formatting. Provides an option for number formatting.
| Name| Type| Mandatory| Description| | Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | ----------- | ------ | ---- | ---------------------------------------------------------- |
| countryCode | string | No|Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.| | countryCode | string | No| Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.|
# HiAppEvent<a name="EN-US_TOPIC_0000001163817362"></a> # Application dotting
>![](../../public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
## Modules to Import
``` ```
import hiAppEvent from '@ohos.hiAppEvent'; import hiAppEvent from '@ohos.hiAppEvent';
``` ```
## System Capabilities ## System Capabilities
SystemCapability.HiviewDFX.HiAppEvent SystemCapability.HiviewDFX.HiAppEvent
## hiAppEvent.write<a name="section570630172512"></a>
write\(eventName: string, eventType: EventType, keyValues: object, callback: AsyncCallback<void\>\): void ## hiAppEvent.write
write(eventName: string, eventType: EventType, keyValues: object, callback: AsyncCallback&lt;void&gt;): void
Writes event information to the event file of the current day. This function supports JSON parameters and uses an asynchronous callback to return the result. Writes event information to the event file of the current day. This function supports JSON parameters and uses an asynchronous callback to return the result.
- Parameters **Parameters**
<a name="table1054125415456"></a> | Name| Type| Mandatory| Description|
<table><thead align="left"><tr id="row354155454518"><th class="cellrowborder" valign="top" width="15.030000000000001%" id="mcps1.1.5.1.1"><p id="p17541135415455"><a name="p17541135415455"></a><a name="p17541135415455"></a>Name</p> | -------- | -------- | -------- | -------- |
</th> | eventName | string | Yes| App event name.|
<th class="cellrowborder" valign="top" width="24.430000000000003%" id="mcps1.1.5.1.2"><p id="p454195484516"><a name="p454195484516"></a><a name="p454195484516"></a>Type</p> | eventType | [EventType](#eventtype) | Yes| Application event type.|
</th> | keyValues | object | Yes| Array of JSON parameters of the application event. A key must be a string, and a value must be a string, number, boolean, or Array (which can only be a string, number, or boolean).|
<th class="cellrowborder" valign="top" width="7.870000000000002%" id="mcps1.1.5.1.3"><p id="p115414549454"><a name="p115414549454"></a><a name="p115414549454"></a>Mandatory</p> | callback | AsyncCallback&lt;void&gt; | No| Callback used to process the received return value. <br/>-&nbsp;The value **0** indicates that the event parameter verification is successful, and the event will be written to the event file asynchronously.<br/>-&nbsp;A value greater than **0** indicates that invalid parameters are present in the event, and the event will be written to the event file asynchronously after the invalid parameters are ignored.<br/>-&nbsp;A value smaller than **0** indicates that the event parameter verification fails, and the event will not be written to the event file asynchronously.|
</th>
<th class="cellrowborder" valign="top" width="52.67000000000001%" id="mcps1.1.5.1.4"><p id="p155411354104516"><a name="p155411354104516"></a><a name="p155411354104516"></a>Description</p> **Example**
</th>
</tr> ```
</thead> hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"}, (err, value) => {
<tbody><tr id="row6541155413451"><td class="cellrowborder" valign="top" width="15.030000000000001%" headers="mcps1.1.5.1.1 "><p id="p125411454184516"><a name="p125411454184516"></a><a name="p125411454184516"></a>eventName</p>
</td>
<td class="cellrowborder" valign="top" width="24.430000000000003%" headers="mcps1.1.5.1.2 "><p id="p5541195416452"><a name="p5541195416452"></a><a name="p5541195416452"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.870000000000002%" headers="mcps1.1.5.1.3 "><p id="p754115424514"><a name="p754115424514"></a><a name="p754115424514"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="52.67000000000001%" headers="mcps1.1.5.1.4 "><p id="p185421054144516"><a name="p185421054144516"></a><a name="p185421054144516"></a>Indicates the application event name.</p>
</td>
</tr>
<tr id="row2542145416459"><td class="cellrowborder" valign="top" width="15.030000000000001%" headers="mcps1.1.5.1.1 "><p id="p19542185415455"><a name="p19542185415455"></a><a name="p19542185415455"></a>eventType</p>
</td>
<td class="cellrowborder" valign="top" width="24.430000000000003%" headers="mcps1.1.5.1.2 "><p id="p20542205474519"><a name="p20542205474519"></a><a name="p20542205474519"></a><a href="#section099619567453">EventType</a></p>
</td>
<td class="cellrowborder" valign="top" width="7.870000000000002%" headers="mcps1.1.5.1.3 "><p id="p1354295494510"><a name="p1354295494510"></a><a name="p1354295494510"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="52.67000000000001%" headers="mcps1.1.5.1.4 "><p id="p754216544454"><a name="p754216544454"></a><a name="p754216544454"></a>Indicates the application event type.</p>
</td>
</tr>
<tr id="row354265418456"><td class="cellrowborder" valign="top" width="15.030000000000001%" headers="mcps1.1.5.1.1 "><p id="p1354215547452"><a name="p1354215547452"></a><a name="p1354215547452"></a>keyValues</p>
</td>
<td class="cellrowborder" valign="top" width="24.430000000000003%" headers="mcps1.1.5.1.2 "><p id="p754225416456"><a name="p754225416456"></a><a name="p754225416456"></a>object</p>
</td>
<td class="cellrowborder" valign="top" width="7.870000000000002%" headers="mcps1.1.5.1.3 "><p id="p55421654124517"><a name="p55421654124517"></a><a name="p55421654124517"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="52.67000000000001%" headers="mcps1.1.5.1.4 "><p id="p55431154164513"><a name="p55431154164513"></a><a name="p55431154164513"></a>Indicates an array of JSON parameters of the application event. A key must be a string, and a value must be a string, number, boolean, or Array (which can only be a string, number, or boolean).</p>
</td>
</tr>
<tr id="row87751758579"><td class="cellrowborder" valign="top" width="15.030000000000001%" headers="mcps1.1.5.1.1 "><p id="p777595810712"><a name="p777595810712"></a><a name="p777595810712"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="24.430000000000003%" headers="mcps1.1.5.1.2 "><p id="p1577513581719"><a name="p1577513581719"></a><a name="p1577513581719"></a>AsyncCallback&lt;void&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="7.870000000000002%" headers="mcps1.1.5.1.3 "><p id="p157753585718"><a name="p157753585718"></a><a name="p157753585718"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="52.67000000000001%" headers="mcps1.1.5.1.4 "><p id="p1065434111303"><a name="p1065434111303"></a><a name="p1065434111303"></a>Indicates the callback function, which can be used to process the received return value.</p>
<a name="ul182248492307"></a><a name="ul182248492307"></a><ul id="ul182248492307"><li>Value <strong id="b27171235133215"><a name="b27171235133215"></a><a name="b27171235133215"></a>0</strong> indicates that the event verification is successful, and the event will be written to the event file asynchronously. </li><li>A value greater than <strong id="b89271810175013"><a name="b89271810175013"></a><a name="b89271810175013"></a>0</strong> indicates that invalid parameters are present in the event, and the event will be written to the event file asynchronously after the invalid parameters are ignored. </li><li>A value smaller than <strong id="b8363151395017"><a name="b8363151395017"></a><a name="b8363151395017"></a>0</strong> indicates that the event verification fails, and the event will not be written to the event file.</li></ul>
</td>
</tr>
</tbody>
</table>
- Example
```
hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"}, (err, value) => {
if (err) { if (err) {
// Event writing exception: Write the event to the event file after the invalid parameters in the event are ignored, or stop writing the event if the event verification fails. // Event writing exception: Write the event to the event file after the invalid parameters in the event are ignored, or stop writing the event if the event verification fails.
console.error(`failed to write event because ${err.code}`); console.error(`failed to write event because ${err.code}`);
...@@ -84,80 +43,34 @@ Writes event information to the event file of the current day. This function sup ...@@ -84,80 +43,34 @@ Writes event information to the event file of the current day. This function sup
// Event writing succeeded. // Event writing succeeded.
console.log(`success to write event: ${value}`); console.log(`success to write event: ${value}`);
}); });
``` ```
## hiAppEvent.write<a name="section0857164934517"></a> ## hiAppEvent.write
write\(eventName: string, eventType: EventType, keyValues: object\): Promise<void\> write(eventName: string, eventType: EventType, keyValues: object): Promise&lt;void&gt;
Writes event information to the event file of the current day. This function supports JSON parameters and uses a promise to return the result. Writes event information to the event file of the current day. This function supports JSON parameters and uses a promise to return the result.
- Parameters **Parameters**
<a name="table11857249104514"></a> | Name| Type| Mandatory| Description|
<table><thead align="left"><tr id="row198584493457"><th class="cellrowborder" valign="top" width="13.969999999999999%" id="mcps1.1.5.1.1"><p id="p128580494453"><a name="p128580494453"></a><a name="p128580494453"></a>Name</p> | -------- | -------- | -------- | -------- |
</th> | eventName | string | Yes| App event name.|
<th class="cellrowborder" valign="top" width="13.389999999999999%" id="mcps1.1.5.1.2"><p id="p2085813494456"><a name="p2085813494456"></a><a name="p2085813494456"></a>Type</p> | eventType | [EventType](#eventtype) | Yes| Application event type.|
</th> | keyValues | object | Yes| Array of JSON parameters of the application event. A key must be a string, and a value must be a string, number, boolean, or Array (which can only be a string, number, or boolean).|
<th class="cellrowborder" valign="top" width="8.23%" id="mcps1.1.5.1.3"><p id="p1285894934516"><a name="p1285894934516"></a><a name="p1285894934516"></a>Mandatory</p>
</th> **Return value**
<th class="cellrowborder" valign="top" width="64.41%" id="mcps1.1.5.1.4"><p id="p48581849104511"><a name="p48581849104511"></a><a name="p48581849104511"></a>Description</p>
</th> | Type| Description|
</tr> | -------- | -------- |
</thead> | Promise&lt;void&gt; | Promise used to process the callback in the then() and catch() methods when event writing succeeded or failed.|
<tbody><tr id="row98581498450"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="p1185884919459"><a name="p1185884919459"></a><a name="p1185884919459"></a>eventName</p>
</td> **Example**
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="p28586495454"><a name="p28586495454"></a><a name="p28586495454"></a>string</p>
</td> ```
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="p2858144912459"><a name="p2858144912459"></a><a name="p2858144912459"></a>Yes</p> hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"})
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="p8858164984518"><a name="p8858164984518"></a><a name="p8858164984518"></a>Indicates the application event name.</p>
</td>
</tr>
<tr id="row198584495457"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="p128583494450"><a name="p128583494450"></a><a name="p128583494450"></a>eventType</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="p13858449194517"><a name="p13858449194517"></a><a name="p13858449194517"></a><a href="#section099619567453">EventType</a></p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="p1785894934513"><a name="p1785894934513"></a><a name="p1785894934513"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="p198581349194515"><a name="p198581349194515"></a><a name="p198581349194515"></a>Indicates the application event type.</p>
</td>
</tr>
<tr id="row78580497453"><td class="cellrowborder" valign="top" width="13.969999999999999%" headers="mcps1.1.5.1.1 "><p id="p2085819494459"><a name="p2085819494459"></a><a name="p2085819494459"></a>keyValues</p>
</td>
<td class="cellrowborder" valign="top" width="13.389999999999999%" headers="mcps1.1.5.1.2 "><p id="p8859749154519"><a name="p8859749154519"></a><a name="p8859749154519"></a>object</p>
</td>
<td class="cellrowborder" valign="top" width="8.23%" headers="mcps1.1.5.1.3 "><p id="p1385984964515"><a name="p1385984964515"></a><a name="p1385984964515"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="64.41%" headers="mcps1.1.5.1.4 "><p id="p1859114984515"><a name="p1859114984515"></a><a name="p1859114984515"></a>Indicates an array of JSON parameters of the application event. A key must be a string, and a value must be a string, number, boolean, or Array (which can only be a string, number, or boolean).</p>
</td>
</tr>
</tbody>
</table>
- Return values
<a name="table10811610134713"></a>
<table><thead align="left"><tr id="row7811410124716"><th class="cellrowborder" valign="top" width="26.06%" id="mcps1.1.3.1.1"><p id="p118116107479"><a name="p118116107479"></a><a name="p118116107479"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="73.94%" id="mcps1.1.3.1.2"><p id="p8811910124715"><a name="p8811910124715"></a><a name="p8811910124715"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1181161019479"><td class="cellrowborder" valign="top" width="26.06%" headers="mcps1.1.3.1.1 "><p id="p15811181004712"><a name="p15811181004712"></a><a name="p15811181004712"></a>Promise&lt;void&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="73.94%" headers="mcps1.1.3.1.2 "><p id="p14811710164718"><a name="p14811710164718"></a><a name="p14811710164718"></a>Promise used to process the callback in the <strong id="b1588612407278"><a name="b1588612407278"></a><a name="b1588612407278"></a>then()</strong> and <strong id="b116252458275"><a name="b116252458275"></a><a name="b116252458275"></a>catch()</strong> methods when event writing succeeded or failed.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
hiAppEvent.write("test_event", hiAppEvent.EventType.FAULT, {"int_data":100, "str_data":"strValue"})
.then((value) => { .then((value) => {
// Event writing succeeded. // Event writing succeeded.
console.log(`success to write event: ${value}`); console.log(`success to write event: ${value}`);
...@@ -165,254 +78,80 @@ Writes event information to the event file of the current day. This function sup ...@@ -165,254 +78,80 @@ Writes event information to the event file of the current day. This function sup
// Event writing exception: Write the event to the event file after the invalid parameters in the event are ignored, or stop writing the event if the event verification fails. // Event writing exception: Write the event to the event file after the invalid parameters in the event are ignored, or stop writing the event if the event verification fails.
console.error(`failed to write event because ${err.code}`); console.error(`failed to write event because ${err.code}`);
}); });
``` ```
## hiAppEvent.configure<a name="section5378143772018"></a> ## hiAppEvent.configure
configure\(config: ConfigOption\): boolean configure(config: ConfigOption): boolean
Configures the application event logging function, such as setting the event logging switch and maximum size of the directory that stores the event logging files. Configures the application event logging function, such as setting the event logging switch and maximum size of the directory that stores the event logging files.
- Parameters **Parameters**
<a name="table1252915782516"></a> | Name| Type| Mandatory| Description|
<table><thead align="left"><tr id="row35293782515"><th class="cellrowborder" valign="top" width="11.51%" id="mcps1.1.5.1.1"><p id="p35291371251"><a name="p35291371251"></a><a name="p35291371251"></a>Name</p> | -------- | -------- | -------- | -------- |
</th> | config | [ConfigOption](#configoption) | Yes| Configuration items for application event logging.|
<th class="cellrowborder" valign="top" width="16.39%" id="mcps1.1.5.1.2"><p id="p75296712250"><a name="p75296712250"></a><a name="p75296712250"></a>Type</p>
</th> **Return value**
<th class="cellrowborder" valign="top" width="7.9%" id="mcps1.1.5.1.3"><p id="p105291377254"><a name="p105291377254"></a><a name="p105291377254"></a>Mandatory</p>
</th> | Type| Description|
<th class="cellrowborder" valign="top" width="64.2%" id="mcps1.1.5.1.4"><p id="p155291674252"><a name="p155291674252"></a><a name="p155291674252"></a>Description</p> | -------- | -------- |
</th> | boolean | Returns **true** if the configuration is successful; returns **false** otherwise.|
</tr>
</thead> **Example**
<tbody><tr id="row652919711259"><td class="cellrowborder" valign="top" width="11.51%" headers="mcps1.1.5.1.1 "><p id="p18529970251"><a name="p18529970251"></a><a name="p18529970251"></a>config</p> ```
</td> // Set the application event logging switch.
<td class="cellrowborder" valign="top" width="16.39%" headers="mcps1.1.5.1.2 "><p id="p65296742520"><a name="p65296742520"></a><a name="p65296742520"></a><a href="#section1877154515916">ConfigOption</a></p> hiAppEvent.configure({
</td>
<td class="cellrowborder" valign="top" width="7.9%" headers="mcps1.1.5.1.3 "><p id="p155299792512"><a name="p155299792512"></a><a name="p155299792512"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="64.2%" headers="mcps1.1.5.1.4 "><p id="p38353293497"><a name="p38353293497"></a><a name="p38353293497"></a>Configuration items for application event logging.</p>
</td>
</tr>
</tbody>
</table>
- Return values
<a name="table253014717256"></a>
<table><thead align="left"><tr id="row3530471251"><th class="cellrowborder" valign="top" width="26.06%" id="mcps1.1.3.1.1"><p id="p195304762520"><a name="p195304762520"></a><a name="p195304762520"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="73.94%" id="mcps1.1.3.1.2"><p id="p1353017722518"><a name="p1353017722518"></a><a name="p1353017722518"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row2053010792510"><td class="cellrowborder" valign="top" width="26.06%" headers="mcps1.1.3.1.1 "><p id="p155308717259"><a name="p155308717259"></a><a name="p155308717259"></a>boolean</p>
</td>
<td class="cellrowborder" valign="top" width="73.94%" headers="mcps1.1.3.1.2 "><p id="p1953016720258"><a name="p1953016720258"></a><a name="p1953016720258"></a>Returns <strong id="b188031557115015"><a name="b188031557115015"></a><a name="b188031557115015"></a>true</strong> if the configuration is successful; returns <strong id="b1612180105111"><a name="b1612180105111"></a><a name="b1612180105111"></a>false</strong> otherwise.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
// Configure the application event logging switch.
hiAppEvent.configure({
disable: true disable: true
}); });
// Configure the maximum size of the directory that stores the event logging files. // Configure the maximum size of the directory that stores the event logging files.
hiAppEvent.configure({ hiAppEvent.configure({
maxStorage: '100M' maxStorage: '100M'
}); });
``` ```
## ConfigOption<a name="section1877154515916"></a> ## ConfigOption
Provides the configuration items for application event logging. Provides the configuration items for application event logging.
<a name="t1e7d4d4f9078490d8dcdbb56465b8ab3"></a> | Name| Type| Mandatory| Description|
<table><thead align="left"><tr id="r85a1aa805727476a8e768b658530fc49"><th class="cellrowborder" valign="top" width="13.08%" id="mcps1.1.5.1.1"><p id="a58cac6e212134a42a245df58d7b6f3a3"><a name="a58cac6e212134a42a245df58d7b6f3a3"></a><a name="a58cac6e212134a42a245df58d7b6f3a3"></a>Name</p> | -------- | -------- | -------- | -------- |
</th> | disable | boolean | No| Application event logging switch. The value <b>true</b> means to disable the application event logging function, and the value <b>false</b> means the opposite.|
<th class="cellrowborder" valign="top" width="10.5%" id="mcps1.1.5.1.2"><p id="ae520989fe4be4482acdfdf2c26d6517d"><a name="ae520989fe4be4482acdfdf2c26d6517d"></a><a name="ae520989fe4be4482acdfdf2c26d6517d"></a>Type</p> | maxStorage | string | No| Maximum size of the event file storage directory. The default value is **10M**. If the specified size is exceeded, the oldest event logging files in the storage directory will be deleted to free up space.|
</th>
<th class="cellrowborder" valign="top" width="10.63%" id="mcps1.1.5.1.3"><p id="a6b396dd84a564272a6f3d4732b4e12fe"><a name="a6b396dd84a564272a6f3d4732b4e12fe"></a><a name="a6b396dd84a564272a6f3d4732b4e12fe"></a>Mandatory</p>
</th> ## EventType
<th class="cellrowborder" valign="top" width="65.79%" id="mcps1.1.5.1.4"><p id="ae728420f819e42d1b31424ac9747665b"><a name="ae728420f819e42d1b31424ac9747665b"></a><a name="ae728420f819e42d1b31424ac9747665b"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="r3e8e2a236aee4030b7f7878cf5bc7537"><td class="cellrowborder" valign="top" width="13.08%" headers="mcps1.1.5.1.1 "><p id="ada6eeced8a7c481dac17cdb7d5c37dce"><a name="ada6eeced8a7c481dac17cdb7d5c37dce"></a><a name="ada6eeced8a7c481dac17cdb7d5c37dce"></a>disable</p>
</td>
<td class="cellrowborder" valign="top" width="10.5%" headers="mcps1.1.5.1.2 "><p id="a89ee25b3dc1045b5aa724c83751b3c0f"><a name="a89ee25b3dc1045b5aa724c83751b3c0f"></a><a name="a89ee25b3dc1045b5aa724c83751b3c0f"></a>boolean</p>
</td>
<td class="cellrowborder" valign="top" width="10.63%" headers="mcps1.1.5.1.3 "><p id="p936187569"><a name="p936187569"></a><a name="p936187569"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65.79%" headers="mcps1.1.5.1.4 "><p id="a42ab0decfa2a497782c54a4edfc72b8a"><a name="a42ab0decfa2a497782c54a4edfc72b8a"></a><a name="a42ab0decfa2a497782c54a4edfc72b8a"></a>Application event logging switch. The value <strong id="b13365319489"><a name="b13365319489"></a><a name="b13365319489"></a>true</strong> means to disable the application event logging function, and the value <strong id="b4491356184818"><a name="b4491356184818"></a><a name="b4491356184818"></a>false</strong> means the opposite.</p>
</td>
</tr>
<tr id="row860615273611"><td class="cellrowborder" valign="top" width="13.08%" headers="mcps1.1.5.1.1 "><p id="p116072272610"><a name="p116072272610"></a><a name="p116072272610"></a>maxStorage</p>
</td>
<td class="cellrowborder" valign="top" width="10.5%" headers="mcps1.1.5.1.2 "><p id="p9607727863"><a name="p9607727863"></a><a name="p9607727863"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="10.63%" headers="mcps1.1.5.1.3 "><p id="p66070271869"><a name="p66070271869"></a><a name="p66070271869"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="65.79%" headers="mcps1.1.5.1.4 "><p id="p96071927366"><a name="p96071927366"></a><a name="p96071927366"></a>Maximum size of the event file storage directory. The default value is <strong id="b1263295715012"><a name="b1263295715012"></a><a name="b1263295715012"></a>10M</strong>. If the specified size is exceeded, the oldest event logging files in the storage directory will be deleted to free up space.</p>
</td>
</tr>
</tbody>
</table>
## EventType<a name="section099619567453"></a>
Enumerates event types. Enumerates event types.
<a name="table20633101642315"></a> | Name| Default Value| Description|
<table><thead align="left"><tr id="row663331618238"><th class="cellrowborder" valign="top" width="27.900000000000002%" id="mcps1.1.4.1.1"><p id="a3d0fc780cc904c1cbab7991251622f65"><a name="a3d0fc780cc904c1cbab7991251622f65"></a><a name="a3d0fc780cc904c1cbab7991251622f65"></a>Name</p> | -------- | -------- | -------- |
</th> | FAULT | 1 | Fault event|
<th class="cellrowborder" valign="top" width="12.43%" id="mcps1.1.4.1.2"><p id="aace9cae4ba0d4939bfa048460f61c3c7"><a name="aace9cae4ba0d4939bfa048460f61c3c7"></a><a name="aace9cae4ba0d4939bfa048460f61c3c7"></a>Default Value</p> | STATISTIC | 2 | Statistical event|
</th> | SECURITY | 3 | Security event|
<th class="cellrowborder" valign="top" width="59.67%" id="mcps1.1.4.1.3"><p id="afec895de33f94e3c87ee7acc20190a17"><a name="afec895de33f94e3c87ee7acc20190a17"></a><a name="afec895de33f94e3c87ee7acc20190a17"></a>Description</p> | BEHAVIOR | 4 | Behavior event|
</th>
</tr>
</thead> ## Event
<tbody><tr id="row188481425182510"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="p13876443113318"><a name="p13876443113318"></a><a name="p13876443113318"></a>FAULT</p>
</td>
<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="p2282152962115"><a name="p2282152962115"></a><a name="p2282152962115"></a>1</p>
</td>
<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="p28751543103312"><a name="p28751543103312"></a><a name="p28751543103312"></a>Fault event</p>
</td>
</tr>
<tr id="row0461622112513"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="p68697436338"><a name="p68697436338"></a><a name="p68697436338"></a>STATISTIC</p>
</td>
<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="p1310553911218"><a name="p1310553911218"></a><a name="p1310553911218"></a>2</p>
</td>
<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="p14868114312331"><a name="p14868114312331"></a><a name="p14868114312331"></a>Statistical event</p>
</td>
</tr>
<tr id="row91702048195619"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="p123991673342"><a name="p123991673342"></a><a name="p123991673342"></a>SECURITY</p>
</td>
<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="p14170114811561"><a name="p14170114811561"></a><a name="p14170114811561"></a>3</p>
</td>
<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="p1539912793411"><a name="p1539912793411"></a><a name="p1539912793411"></a>Security event</p>
</td>
</tr>
<tr id="row717094895612"><td class="cellrowborder" valign="top" width="27.900000000000002%" headers="mcps1.1.4.1.1 "><p id="p10231410193416"><a name="p10231410193416"></a><a name="p10231410193416"></a>BEHAVIOR</p>
</td>
<td class="cellrowborder" valign="top" width="12.43%" headers="mcps1.1.4.1.2 "><p id="p1817134815569"><a name="p1817134815569"></a><a name="p1817134815569"></a>4</p>
</td>
<td class="cellrowborder" valign="top" width="59.67%" headers="mcps1.1.4.1.3 "><p id="p523171020343"><a name="p523171020343"></a><a name="p523171020343"></a>Behavior event</p>
</td>
</tr>
</tbody>
</table>
## Event<a name="section107763162597"></a>
Provides constants that define the names of all predefined events. Provides constants that define the names of all predefined events.
<a name="table728861911417"></a> | Name| Type| Readable| Writable| Description|
<table><thead align="left"><tr id="row62887198149"><th class="cellrowborder" valign="top" width="33.550000000000004%" id="mcps1.1.6.1.1"><p id="p928811911410"><a name="p928811911410"></a><a name="p928811911410"></a>Name</p> | -------- | -------- | -------- | -------- | -------- |
</th> | USER_LOGIN | string | Yes| No| User login event.|
<th class="cellrowborder" valign="top" width="12.6%" id="mcps1.1.6.1.2"><p id="p8288191916149"><a name="p8288191916149"></a><a name="p8288191916149"></a>Parameter Type</p> | USER_LOGOUT | string | Yes| No| User logout event.|
</th> | DISTRIBUTED_SERVICE_START | string | Yes| No| Distributed service startup event.|
<th class="cellrowborder" valign="top" width="7.6899999999999995%" id="mcps1.1.6.1.3"><p id="p14288131911418"><a name="p14288131911418"></a><a name="p14288131911418"></a>Readable</p>
</th>
<th class="cellrowborder" valign="top" width="8.43%" id="mcps1.1.6.1.4"><p id="p1928861921411"><a name="p1928861921411"></a><a name="p1928861921411"></a>Writable</p>
</th>
<th class="cellrowborder" valign="top" width="37.730000000000004%" id="mcps1.1.6.1.5"><p id="p728815191149"><a name="p728815191149"></a><a name="p728815191149"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row528891919142"><td class="cellrowborder" valign="top" width="33.550000000000004%" headers="mcps1.1.6.1.1 "><p id="p3288191991414"><a name="p3288191991414"></a><a name="p3288191991414"></a>USER_LOGIN</p>
</td>
<td class="cellrowborder" valign="top" width="12.6%" headers="mcps1.1.6.1.2 "><p id="p3288121901418"><a name="p3288121901418"></a><a name="p3288121901418"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.6899999999999995%" headers="mcps1.1.6.1.3 "><p id="p182881319191414"><a name="p182881319191414"></a><a name="p182881319191414"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="8.43%" headers="mcps1.1.6.1.4 "><p id="p1928801914148"><a name="p1928801914148"></a><a name="p1928801914148"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="37.730000000000004%" headers="mcps1.1.6.1.5 "><p id="p1428811192144"><a name="p1428811192144"></a><a name="p1428811192144"></a>User login event.</p>
</td>
</tr>
<tr id="row72571514202916"><td class="cellrowborder" valign="top" width="33.550000000000004%" headers="mcps1.1.6.1.1 "><p id="p18257151413298"><a name="p18257151413298"></a><a name="p18257151413298"></a>USER_LOGOUT</p>
</td>
<td class="cellrowborder" valign="top" width="12.6%" headers="mcps1.1.6.1.2 "><p id="p3976112512293"><a name="p3976112512293"></a><a name="p3976112512293"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.6899999999999995%" headers="mcps1.1.6.1.3 "><p id="p1497682515293"><a name="p1497682515293"></a><a name="p1497682515293"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="8.43%" headers="mcps1.1.6.1.4 "><p id="p1697613259298"><a name="p1697613259298"></a><a name="p1697613259298"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="37.730000000000004%" headers="mcps1.1.6.1.5 "><p id="p162571914162912"><a name="p162571914162912"></a><a name="p162571914162912"></a>User logout event.</p>
</td>
</tr>
<tr id="row37723173299"><td class="cellrowborder" valign="top" width="33.550000000000004%" headers="mcps1.1.6.1.1 "><p id="p07721917182914"><a name="p07721917182914"></a><a name="p07721917182914"></a>DISTRIBUTED_SERVICE_START</p>
</td>
<td class="cellrowborder" valign="top" width="12.6%" headers="mcps1.1.6.1.2 "><p id="p8324132810299"><a name="p8324132810299"></a><a name="p8324132810299"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.6899999999999995%" headers="mcps1.1.6.1.3 "><p id="p20324928192912"><a name="p20324928192912"></a><a name="p20324928192912"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="8.43%" headers="mcps1.1.6.1.4 "><p id="p1432413281294"><a name="p1432413281294"></a><a name="p1432413281294"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="37.730000000000004%" headers="mcps1.1.6.1.5 "><p id="p19772191715296"><a name="p19772191715296"></a><a name="p19772191715296"></a>Distributed service startup event.</p>
</td>
</tr>
</tbody>
</table>
## Param<a name="section382852073116"></a>
Provides constants that define the names of all predefined event parameters.
<table><thead align="left"><tr id="row12828192018319"><th class="cellrowborder" valign="top" width="35.24%" id="mcps1.1.6.1.1"><p id="p1082932073115"><a name="p1082932073115"></a><a name="p1082932073115"></a>Name</p> ## Param
</th>
<th class="cellrowborder" valign="top" width="12.45%" id="mcps1.1.6.1.2"><p id="p14829920163113"><a name="p14829920163113"></a><a name="p14829920163113"></a>Parameter Type</p> Provides constants that define the names of all predefined event parameters.
</th>
<th class="cellrowborder" valign="top" width="7.82%" id="mcps1.1.6.1.3"><p id="p15829620133110"><a name="p15829620133110"></a><a name="p15829620133110"></a>Readable</p>
</th>
<th class="cellrowborder" valign="top" width="8.540000000000001%" id="mcps1.1.6.1.4"><p id="p3829192013312"><a name="p3829192013312"></a><a name="p3829192013312"></a>Writable</p>
</th>
<th class="cellrowborder" valign="top" width="35.949999999999996%" id="mcps1.1.6.1.5"><p id="p6829132018315"><a name="p6829132018315"></a><a name="p6829132018315"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row48291920183117"><td class="cellrowborder" valign="top" width="35.24%" headers="mcps1.1.6.1.1 "><p id="p9829162043119"><a name="p9829162043119"></a><a name="p9829162043119"></a>USER_ID</p>
</td>
<td class="cellrowborder" valign="top" width="12.45%" headers="mcps1.1.6.1.2 "><p id="p1182912013120"><a name="p1182912013120"></a><a name="p1182912013120"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.82%" headers="mcps1.1.6.1.3 "><p id="p188294201316"><a name="p188294201316"></a><a name="p188294201316"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="8.540000000000001%" headers="mcps1.1.6.1.4 "><p id="p88297205315"><a name="p88297205315"></a><a name="p88297205315"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="35.949999999999996%" headers="mcps1.1.6.1.5 "><p id="p4829620183115"><a name="p4829620183115"></a><a name="p4829620183115"></a>Custom user ID.</p>
</td>
</tr>
<tr id="row482992011315"><td class="cellrowborder" valign="top" width="35.24%" headers="mcps1.1.6.1.1 "><p id="p12829120163115"><a name="p12829120163115"></a><a name="p12829120163115"></a>DISTRIBUTED_SERVICE_NAME</p>
</td>
<td class="cellrowborder" valign="top" width="12.45%" headers="mcps1.1.6.1.2 "><p id="p78291420183111"><a name="p78291420183111"></a><a name="p78291420183111"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.82%" headers="mcps1.1.6.1.3 "><p id="p15829720143116"><a name="p15829720143116"></a><a name="p15829720143116"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="8.540000000000001%" headers="mcps1.1.6.1.4 "><p id="p18291920133110"><a name="p18291920133110"></a><a name="p18291920133110"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="35.949999999999996%" headers="mcps1.1.6.1.5 "><p id="p882916205315"><a name="p882916205315"></a><a name="p882916205315"></a>Distributed service name.</p>
</td>
</tr>
<tr id="row9829112019318"><td class="cellrowborder" valign="top" width="35.24%" headers="mcps1.1.6.1.1 "><p id="p8829220163110"><a name="p8829220163110"></a><a name="p8829220163110"></a>DISTRIBUTED_SERVICE_INSTANCE_ID</p>
</td>
<td class="cellrowborder" valign="top" width="12.45%" headers="mcps1.1.6.1.2 "><p id="p98299202316"><a name="p98299202316"></a><a name="p98299202316"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.82%" headers="mcps1.1.6.1.3 "><p id="p2829142017310"><a name="p2829142017310"></a><a name="p2829142017310"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="8.540000000000001%" headers="mcps1.1.6.1.4 "><p id="p2829152073111"><a name="p2829152073111"></a><a name="p2829152073111"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="35.949999999999996%" headers="mcps1.1.6.1.5 "><p id="p15829132023112"><a name="p15829132023112"></a><a name="p15829132023112"></a>Distributed service instance ID.</p>
</td>
</tr>
</tbody>
</table>
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| USER_ID | string | Yes| No| Custom user ID.|
| DISTRIBUTED_SERVICE_NAME | string | Yes| No| Distributed service name.|
| DISTRIBUTED_SERVICE_INSTANCE_ID | string | Yes| No| Distributed service instance ID.|
# HiChecker
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import hichecker from '@ohos.hichecker';
```
## System Capabilities
SystemCapability.HiviewDFX.HiChecker
## Rule Constants
Provides the constants of all rule types.
| Name| Type| Description|
| ---------------------------------- | -------- | ------------------------------------------------------ |
| RULE_CAUTION_PRINT_LOG | BigInt | Alarm rule, which is programmed to print a log when an alarm is generated.|
| RULE_CAUTION_TRIGGER_CRASH | BigInt | Alarm rule. When an alarm is generated, the application exits.|
| RULE_THREAD_CHECK_SLOW_PROCESS | BigInt | Caution rule, which is programmed to detect whether any time-consuming function is invoked.|
| RULE_CHECK_SLOW_EVENT | BigInt | Caution rule, which is programmed to detect whether the event distribution or processing time has exceeded the specified time threshold.|
| RULE_CHECK_ABILITY_CONNECTION_LEAK | BigInt | Caution rule, which is programmed to detect whether ability leakage has occurred.|
## hichecker.addRule
addRule(rule: BigInt): void
Adds one or more rules. HiChecker detects unexpected operations or gives feedback based on the added rules.
**Parameters**
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ---------------- |
| rule | BigInt | Yes| Rule to be added.|
**Example**
```
// Add a rule.
hichecker.addRule(hichecker.RULE_CAUTION_PRINT_LOG);
// Add multiple rules.
hichecker.addRule(
hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH);
```
## hichecker.removeRule
removeRule(rule: BigInt): void
Removes one or more rules. The removed rules will become ineffective.
**Parameters**
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ---------------- |
| rule | BigInt | Yes| Rule to be removed.|
**Example**
```
// Remove a rule.
hichecker.removeRule(hichecker.RULE_CAUTION_PRINT_LOG);
// Remove multiple rules.
hichecker.removeRule(
hichecker.RULE_CAUTION_PRINT_LOG | hichecker.RULE_CAUTION_TRIGGER_CRASH);
```
## hichecker.getRule
getRule(): BigInt
Obtains a collection of thread, process, and alarm rules that have been added.
**Return value**
| Type| Description|
| ------ | ---------------------- |
| BigInt | Collection of added rules.|
**Example**
```
// Add a rule.
hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
// Obtain the collection of added rules.
hichecker.getRule(); // return 1n;
```
## hichecker.contains
contains(rule: BigInt): boolean
Checks whether the specified rule exists in the collection of added rules. If the rule is of the thread level, this operation is performed only on the current thread.
**Parameters**
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ---------------- |
| rule | BigInt | Yes| Rule to be checked.|
**Return value**
| Type| Description|
| ------- | ---------------------------------------------------------- |
| boolean | Returns **true** if the rule exists in the collection of added rules; returns **false** otherwise.|
**Example**
```
// Add a rule.
hichecker.addRule(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS);
// Check whether the added rule exists in the collection of added rules.
hichecker.contains(hichecker.RULE_THREAD_CHECK_SLOW_PROCESS); // return true;
hichecker.contains(hichecker.RULE_CAUTION_PRINT_LOG); // return false;
```
# HiDebug
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
You can run the hidebug command to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data.
## Modules to Import
```
import hidebug from '@ohos.hidebug';
```
## System Capabilities
SystemCapability.HiviewDFX.HiProfiler.HiDebug
## hidebug.getNativeHeapSize
getNativeHeapSize(): bigint
Obtains the total size of the native heap memory.
- **Return value**
| Type| Description|
| -------- | -------- |
| bigint | Total size of the native heap memory.|
- **Example**
```
let nativeHeapSize = hidebug.getNativeHeapSize();
```
## hidebug.getNativeHeapAllocatedSize
getNativeHeapAllocatedSize(): bigint
Obtains the size of the allocated native heap memory.
- **Return value**
| Type| Description|
| -------- | -------- |
| bigint | Size of the allocated native heap memory.|
- **Example**
```
let nativeHeapAllocatedSize = hidebug.getNativeHeapAllocatedSize();
```
## hidebug.getNativeHeapFreeSize
getNativeHeapFreeSize(): bigint
Obtains the size of the free native heap memory.
- **Return value**
| Type| Description|
| -------- | -------- |
| bigint | Size of the free native heap memory.|
- **Example**
```
let nativeHeapFreeSize = hidebug.getNativeHeapFreeSize();
```
## hidebug.getPss
getPss(): bigint
Obtains the PSS of this process.
- **Return value**
| Type| Description|
| -------- | -------- |
| bigint | PSS of the process.|
- **Example**
```
let pss = hidebug.getPss();
```
## hidebug.getSharedDirty
getSharedDirty(): bigint
Obtains the size of the shared dirty memory of this process.
- **Return value**
| Type| Description|
| -------- | -------- |
| bigint | Size of the shared dirty memory of the process.|
- **Example**
```
let sharedDirty = hidebug.getSharedDirty());
```
## hidebug.startProfiling
startProfiling(filename : string) : void
Starts the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the following sequences is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | ------ | ---- | ------------------------------------------------------------ |
| filename | string | Yes| User-defined profile name. The `filename.json` file is generated in the `files` directory of the application based on the specified `filename`.|
**Example**
```js
hidebug.startProfiling("cpuprofiler-20220216");
// Code block
// ...
// Code block
hidebug.stopProfiling();
```
## hidebug.stopProfiling
stopProfiling() : void
Stops the profiling method. `stopProfiling()` and `startProfiling()` are called in pairs. `stopProfiling()` always occurs after `startProfiling()`; that is, calling the functions in the following sequences is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`.
**Example**
```js
hidebug.startProfiling("cpuprofiler-20220216");
// Code block
// ...
// Code block
hidebug.stopProfiling();
```
## hidebug.dumpHeapData
dumpHeapData(filename : string) : void
Exports the heap data.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | ------ | ---- | ------------------------------------------------------------ |
| filename | string | Yes| User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the app based on the specified `filename`.|
**Example**
```js
hidebug.dumpHeapData("heap-20220216");
```
# Distributed Call Chain Tracing # Distributed Call Chain Tracing
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -68,20 +68,24 @@ begin(name: string, flags: number = HiTraceFlag.DEFAULT): HiTraceId ...@@ -68,20 +68,24 @@ begin(name: string, flags: number = HiTraceFlag.DEFAULT): HiTraceId
Starts call chain tracing. This API works in synchronous manner. Starts call chain tracing. This API works in synchronous manner.
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| name | string | Yes| Traced service name.| | -------- | -------- | -------- | -------- |
| flags | number | Yes| [Trace flag combination](#hitraceflag).| | name | string | Yes| Traced service name.|
- Return value | flags | number | Yes| Trace flag combination. For details, see [HiTraceFlag](#hitraceflag).|
| Type| Description|
| -------- | -------- | **Return value**
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
| Type| Description|
- Example | -------- | -------- |
``` | [HiTraceId](#hitraceid) | **HiTraceId** instance.|
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
``` **Example**
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
```
## hiTraceChain.end ## hiTraceChain.end
...@@ -89,17 +93,19 @@ end(id: HiTraceId): void ...@@ -89,17 +93,19 @@ end(id: HiTraceId): void
Stops call chain tracing. This API works in synchronous manner. Stops call chain tracing. This API works in synchronous manner.
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.| | -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
**Example**
- Example ```
``` let asyncTraceId = hiTraceChain.begin("business");
let asyncTraceId = hiTraceChain.begin("business"); // End the call chain tracing after the service logic is executed for several times.
// End the call chain tracing after the service logic is executed for several times. hiTraceChain.end(asyncTraceId);
hiTraceChain.end(asyncTraceId); ```
```
## hiTraceChain.getId ## hiTraceChain.getId
...@@ -107,17 +113,19 @@ getId(): HiTraceId ...@@ -107,17 +113,19 @@ getId(): HiTraceId
Obtains the trace ID. This API works in synchronous manner. Obtains the trace ID. This API works in synchronous manner.
- Return value **Return value**
| Type| Description|
| -------- | -------- | | Type| Description|
| [HiTraceId](#hitraceid) | **HiTraceId** instance.| | -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
- Example **Example**
```
let traceId = hiTraceChain.begin("business"); ```
// Obtain the current trace ID after the service logic is executed for several times. let traceId = hiTraceChain.begin("business");
let curTraceId = hiTraceChain.getId(); // Obtain the current trace ID after the service logic is executed for several times.
``` let curTraceId = hiTraceChain.getId();
```
## hiTraceChain.setId ## hiTraceChain.setId
...@@ -125,17 +133,19 @@ setId(id: HiTraceId): void ...@@ -125,17 +133,19 @@ setId(id: HiTraceId): void
Sets a trace ID. This API works in synchronous manner. Sets a trace ID. This API works in synchronous manner.
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.| | -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
- Example **Example**
```
let traceId = hiTraceChain.begin("business"); ```
// Set the current trace ID after the service logic is executed for several times. let traceId = hiTraceChain.begin("business");
hiTraceChain.setId(asyncTraceId); // Set the current trace ID after the service logic is executed for several times.
``` hiTraceChain.setId(asyncTraceId);
```
## hiTraceChain.clearId ## hiTraceChain.clearId
...@@ -143,12 +153,13 @@ clearId(): void ...@@ -143,12 +153,13 @@ clearId(): void
Clears the trace ID. This API works in synchronous manner. Clears the trace ID. This API works in synchronous manner.
- Example **Example**
```
let traceId = hiTraceChain.begin("business"); ```
// Clear the current trace ID after the service logic is executed for several times. let traceId = hiTraceChain.begin("business");
hiTraceChain.clearId(); // Clear the current trace ID after the service logic is executed for several times.
``` hiTraceChain.clearId();
```
## hiTraceChain.createSpan ## hiTraceChain.createSpan
...@@ -156,17 +167,19 @@ createSpan(): HiTraceId ...@@ -156,17 +167,19 @@ createSpan(): HiTraceId
Creates a trace span. This API works in synchronous manner. Creates a trace span. This API works in synchronous manner.
- Return value **Return value**
| Type| Description|
| -------- | -------- |
| [HiTraceId](#hitraceid) | **HiTraceId** instance.|
- Example | Type| Description|
``` | -------- | -------- |
let traceId = hiTraceChain.begin("business"); | [HiTraceId](#hitraceid) | **HiTraceId** instance.|
// Create a trace span after the service logic is executed for several times.
let spanTraceId = hiTraceChain.createSpan(); **Example**
```
```
let traceId = hiTraceChain.begin("business");
// Create a trace span after the service logic is executed for several times.
let spanTraceId = hiTraceChain.createSpan();
```
## hiTraceChain.tracepoint ## hiTraceChain.tracepoint
...@@ -174,20 +187,22 @@ tracepoint(mode: HiTraceCommunicationMode, type: HiTraceTracepointType, id: HiTr ...@@ -174,20 +187,22 @@ tracepoint(mode: HiTraceCommunicationMode, type: HiTraceTracepointType, id: HiTr
Triggers a trace point. This API works in synchronous manner. Triggers a trace point. This API works in synchronous manner.
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| mode | [HiTraceCommunicationMode](#hitracecommunicationmode) | Yes| Communication mode for the trace point.| | -------- | -------- | -------- | -------- |
| type | [HiTraceTracepointType](#hitracetracepointtype)| Yes| Trace point type.| | mode | [HiTraceCommunicationMode](#hitracecommunicationmode) | Yes| Communication mode for the trace point.|
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance for trace point triggering.| | type | [HiTraceTracepointType](#hitracetracepointtype)| Yes| Trace point type.|
| msg | string | No| Trace description passed for trace point triggering.| | id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance for trace point triggering.|
| msg | string | No| Trace description passed for trace point triggering.|
- Example
``` **Example**
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
// Trigger the trace point after the service logic is executed for several times. ```
hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.THREAD, hiTraceChain.HiTraceTracepointType.SS, asyncTraceId, "Just a example"); let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC | hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
``` // Trigger the trace point after the service logic is executed for several times.
hiTraceChain.tracepoint(hiTraceChain.HiTraceCommunicationMode.THREAD, hiTraceChain.HiTraceTracepointType.SS, asyncTraceId, "Just a example");
```
## hiTraceChain.isValid ## hiTraceChain.isValid
...@@ -195,20 +210,24 @@ isValid(id: HiTraceId): boolean ...@@ -195,20 +210,24 @@ isValid(id: HiTraceId): boolean
Checks whether a **HiTraceId** instance is valid. This API works in synchronous manner. Checks whether a **HiTraceId** instance is valid. This API works in synchronous manner.
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.| | -------- | -------- | -------- | -------- |
- Return value | id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
| Type| Description|
| -------- | -------- | **Return value**
| boolean | Returns **true** if the **HiTraceId** instance is valid; returns **false** otherwise.|
| Type| Description|
- Example | -------- | -------- |
``` | boolean | Returns **true** if the **HiTraceId** instance is valid; returns **false** otherwise.|
let traceId = hiTraceChain.begin("business");
let traceIdIsvalid = hiTraceChain.isValid(traceId); **Example**
```
```
let traceId = hiTraceChain.begin("business");
let traceIdIsvalid = hiTraceChain.isValid(traceId);
```
## hiTraceChain.isFlagEnabled ## hiTraceChain.isFlagEnabled
...@@ -216,21 +235,26 @@ isFlagEnabled(id: HiTraceId, flag: HiTraceFlag): boolean ...@@ -216,21 +235,26 @@ isFlagEnabled(id: HiTraceId, flag: HiTraceFlag): boolean
Checks whether the specified trace flag in the **HiTraceId** instance is enabled. This API works in synchronous manner. Checks whether the specified trace flag in the **HiTraceId** instance is enabled. This API works in synchronous manner.
- Parameters **Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | Name| Type| Mandatory| Description|
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.| | -------- | -------- | -------- | -------- |
| flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.| | id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
- Return value | flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.|
| Type| Description|
| -------- | -------- | **Return value**
| boolean | Returns **true** if the specified trace flag in the **HiTraceId** instance is enabled; returns **false** otherwise.|
- Example | Type| Description|
``` | -------- | -------- |
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC); | boolean | Returns **true** if the specified trace flag in the **HiTraceId** instance is enabled; returns **false** otherwise.|
// The value of enabledDoNotCreateSpanFlag is true.
let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC); **Example**
```
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
// The value of enabledDoNotCreateSpanFlag is true.
let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
```
## hiTraceChain.enableFlag ## hiTraceChain.enableFlag
...@@ -238,16 +262,17 @@ enableFlag(id: HiTraceId, flag: HiTraceFlag): void ...@@ -238,16 +262,17 @@ enableFlag(id: HiTraceId, flag: HiTraceFlag): void
Enables the specified trace flag in the **HiTraceId** instance. This API works in synchronous manner. Enables the specified trace flag in the **HiTraceId** instance. This API works in synchronous manner.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.| | id | [HiTraceId](#hitraceid) | Yes| **HiTraceId** instance.|
| flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.| | flag | [HiTraceFlag](#hitraceflag) | Yes| Specified trace flag.|
- Example **Example**
```
let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC); ```
hiTraceChain.enable(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN); let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.INCLUDE_ASYNC);
// The value of enabledDoNotCreateSpanFlag is true. hiTraceChain.enable(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN); // The value of enabledDoNotCreateSpanFlag is true.
``` let enabledDoNotCreateSpanFlag = hiTraceChain.isFlagEnabled(asyncTraceId, hiTraceChain.HiTraceFlag.DONOT_CREATE_SPAN);
```
# Performance Tracing # Performance Tracing
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -22,22 +22,24 @@ startTrace(name: string, taskId: number, expectedTime?: number): void ...@@ -22,22 +22,24 @@ startTrace(name: string, taskId: number, expectedTime?: number): void
Starts a trace task. **expectedTime** is an optional parameter, which specifies the expected duration of the trace. Starts a trace task. **expectedTime** is an optional parameter, which specifies the expected duration of the trace.
If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**.
- Parameters If the trace tasks with the same name are not performed at the same time, the same taskId can be used. For a specific example, refer to an example in [hiTraceMeter.finishTrace](#hitracemeterfinishtrace).
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the trace task to start.|
| taskId | number | Yes| Task ID.|
| expectedTime | number | No| Expected duration of the trace, in ms.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** **Parameters**
> If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**. If the trace tasks with the same name are not performed at the same time, the same task ID can be used. For details, see the **hiTraceMeter.finishTrace** example.
- Example | Name| Type| Mandatory| Description|
``` | -------- | -------- | -------- | -------- |
hiTraceMeter.startTrace("myTestFunc", 1); | name | string | Yes| Name of the trace task to start.|
hiTraceMeter.startTrace("myTestFunc", 1, 5); // The expected duration of the trace task is 5 ms. | taskId | number | Yes| Task ID.|
``` | expectedTime | number | No| Expected duration of the trace, in ms.|
**Example**
```
hiTraceMeter.startTrace("myTestFunc", 1);
hiTraceMeter.startTrace("myTestFunc", 1, 5); // The expected duration of the trace task is 5 ms.
```
## hiTraceMeter.finishTrace ## hiTraceMeter.finishTrace
...@@ -46,42 +48,42 @@ finishTrace(name: string, taskId: number): void ...@@ -46,42 +48,42 @@ finishTrace(name: string, taskId: number): void
Stops a trace task. Stops a trace task.
To stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in [startTrace](#hitracemeterstarttrace).
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the trace task to start.|
| taskId | number | Yes| Task ID.|
**Example**
```
hiTraceMeter.finishTrace("myTestFunc", 1);
```
```
// Start track tasks with the same name concurrently.
hiTraceMeter.startTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.startTrace("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 2);
```
- Parameters ```
| Name| Type| Mandatory| Description| // Start track tasks with the same name at different times.
| -------- | -------- | -------- | -------- | hiTraceMeter.startTrace("myTestFunc", 1);
| name | string | Yes| Name of the trace task to start.| // Service flow
| taskId | number | Yes| Task ID.| hiTraceMeter.finishTrace("myTestFunc", 1); // The first trace task ends.
// Service flow
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** hiTraceMeter.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
> To stop a trace task, the values of name and task ID in **finishTrace** must be the same as those in **startTrace**. // Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
- Example ```
```
hiTraceMeter.finishTrace("myTestFunc", 1);
```
```
// Start track tasks with the same name concurrently.
hiTraceMeter.startTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.startTrace("myTestFunc", 2); // The second trace task starts while the first task is still running. The first and second tasks have the same name but different task IDs.
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 2);
```
```
// Start track tasks with the same name at different times.
hiTraceMeter.startTrace("myTestFunc", 1);
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1); // The first trace task ends.
// Service flow
hiTraceMeter.startTrace("myTestFunc", 1); // The second trace task starts after the first task ends. The two tasks have the same name and task ID.
// Service flow
hiTraceMeter.finishTrace("myTestFunc", 1);
```
## hiTraceMeter.traceByValue ## hiTraceMeter.traceByValue
...@@ -90,18 +92,18 @@ traceByValue(name: string, value: number): void ...@@ -90,18 +92,18 @@ traceByValue(name: string, value: number): void
Traces the value changes of a variable. Traces the value changes of a variable.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the variable.|
| value | number | Yes| Value of the variable.|
- Parameters **Example**
| Name| Type| Mandatory| Description| ```
| -------- | -------- | -------- | -------- | let traceCount = 3;
| name | string | Yes| Name of the variable.| hiTraceMeter.traceByValue("myTestCount", traceCount);
| value | number | Yes| Value of the variable.| traceCount = 4;
hiTraceMeter.traceByValue("myTestCount", traceCount);
- Example // Service flow
``` ```
let traceCount = 3;
hiTraceMeter.traceByValue("myTestCount", traceCount);
traceCount = 4;
hiTraceMeter.traceByValue("myTestCount", traceCount);
// Service flow
```
# Power Management<a name="EN-US_TOPIC_0000001133775514"></a> # Power Management
>![](../../public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
## Modules to Import
``` ```
import power from '@ohos.power'; import power from '@ohos.power';
...@@ -14,163 +15,94 @@ import power from '@ohos.power'; ...@@ -14,163 +15,94 @@ import power from '@ohos.power';
SystemCapability.PowerManager.PowerManager SystemCapability.PowerManager.PowerManager
## power.shutdownDevice<a name="section192192415554"></a> ## power.shutdownDevice
shutdownDevice\(reason: string\): void shutdownDevice(reason: string): void
Shuts down the system. Shuts down the system.
- Parameters Before using this API, you must declare the **ohos.permission.SHUTDOWN** permission.
<a name="table69661135912"></a> **Parameters**
<table><thead align="left"><tr id="row149668318915"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p7966738914"><a name="p7966738914"></a><a name="p7966738914"></a>Name</p>
</th> | Name| Type| Mandatory| Description|
<th class="cellrowborder" valign="top" width="14.729999999999999%" id="mcps1.1.5.1.2"><p id="p296713699"><a name="p296713699"></a><a name="p296713699"></a>Type</p> | -------- | -------- | -------- | -------- |
</th> | reason | string | Yes| Reason for system shutdown.|
<th class="cellrowborder" valign="top" width="9.16%" id="mcps1.1.5.1.3"><p id="p196718315911"><a name="p196718315911"></a><a name="p196718315911"></a>Mandatory</p>
</th> **Example**
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p9967231197"><a name="p9967231197"></a><a name="p9967231197"></a>Description</p>
</th> ```
</tr> power.shutdownDevice("shutdown_test");
</thead> console.info('power_shutdown_device_test success')
<tbody><tr id="row99671533914"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p5518501625"><a name="p5518501625"></a><a name="p5518501625"></a>reason</p> ```
</td>
<td class="cellrowborder" valign="top" width="14.729999999999999%" headers="mcps1.1.5.1.2 "><p id="p11967433914"><a name="p11967433914"></a><a name="p11967433914"></a>string</p>
</td> ## power.rebootDevice
<td class="cellrowborder" valign="top" width="9.16%" headers="mcps1.1.5.1.3 "><p id="p19671336916"><a name="p19671336916"></a><a name="p19671336916"></a>Yes</p>
</td> rebootDevice(reason: string): void
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p69671631796"><a name="p69671631796"></a><a name="p69671631796"></a>Reason for system shutdown.</p>
</td> Restarts the device.
</tr>
</tbody> Before using this API, you must declare the **ohos.permission.REBOOT** permission (to reboot) or the **ohos.permission.REBOOT_RECOVERY** permission (to reboot and enter the recovery mode)
</table>
**Parameters**
- Example
| Name| Type| Mandatory| Description|
``` | -------- | -------- | -------- | -------- |
power.shutdownDevice("shutdown_test"); | reason | string | Yes| Reason for system reboot.|
console.info('power_shutdown_device_test success')
``` **Example**
```
## power.rebootDevice<a name="section1773218207620"></a> power.rebootDevice("reboot_test");
console.info('power_reboot_device_test success')
rebootDevice\(reason: string\): void ```
Reboots the system.
## power.isScreenOn
- Parameters
isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void
<a name="table8732192015611"></a>
<table><thead align="left"><tr id="row1173216204612"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p973222015615"><a name="p973222015615"></a><a name="p973222015615"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="16.830000000000002%" id="mcps1.1.5.1.2"><p id="p273232015612"><a name="p273232015612"></a><a name="p273232015612"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="11.88%" id="mcps1.1.5.1.3"><p id="p9732202013618"><a name="p9732202013618"></a><a name="p9732202013618"></a>Mandatory</p>
</th>
<th class="cellrowborder" valign="top" width="56.47%" id="mcps1.1.5.1.4"><p id="p167326201566"><a name="p167326201566"></a><a name="p167326201566"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row773292016614"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p57320201162"><a name="p57320201162"></a><a name="p57320201162"></a>reason</p>
</td>
<td class="cellrowborder" valign="top" width="16.830000000000002%" headers="mcps1.1.5.1.2 "><p id="p973216201164"><a name="p973216201164"></a><a name="p973216201164"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="11.88%" headers="mcps1.1.5.1.3 "><p id="p5732132020612"><a name="p5732132020612"></a><a name="p5732132020612"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="56.47%" headers="mcps1.1.5.1.4 "><p id="p4733720662"><a name="p4733720662"></a><a name="p4733720662"></a>Reason for system reboot.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
power.rebootDevice("reboot_test");
console.info('power_reboot_device_test success')
```
## power.isScreenOn<a name="section69511458115312"></a>
isScreenOn\(callback: AsyncCallback<boolean\>\): void
Checks the screen status of the current device. Checks the screen status of the current device.
- Parameters **Parameters**
<a name="table183681450191519"></a> | Type| Type| Mandatory| Description|
<table><thead align="left"><tr id="row20368050151519"><th class="cellrowborder" valign="top" width="15.989999999999998%" id="mcps1.1.5.1.1"><p id="p13681150121519"><a name="p13681150121519"></a><a name="p13681150121519"></a>Type</p> | -------- | -------- | -------- | -------- |
</th> | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to obtain the return value. <br/>The value **true** indicates that the screen is on, and value **false** indicates the opposite.|
<th class="cellrowborder" valign="top" width="28.27%" id="mcps1.1.5.1.2"><p id="p1636895015154"><a name="p1636895015154"></a><a name="p1636895015154"></a>Type</p>
</th> **Example**
<th class="cellrowborder" valign="top" width="9.64%" id="mcps1.1.5.1.3"><p id="p7565410191617"><a name="p7565410191617"></a><a name="p7565410191617"></a>Mandatory</p>
</th> ```
<th class="cellrowborder" valign="top" width="46.1%" id="mcps1.1.5.1.4"><p id="p43681350181515"><a name="p43681350181515"></a><a name="p43681350181515"></a>Description</p> power.isScreenOn((error, screenOn) => {
</th>
</tr>
</thead>
<tbody><tr id="row636865081513"><td class="cellrowborder" valign="top" width="15.989999999999998%" headers="mcps1.1.5.1.1 "><p id="p4368165091513"><a name="p4368165091513"></a><a name="p4368165091513"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="28.27%" headers="mcps1.1.5.1.2 "><p id="p83691450151519"><a name="p83691450151519"></a><a name="p83691450151519"></a>AsyncCallback&lt;boolean&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="9.64%" headers="mcps1.1.5.1.3 "><p id="p17565310191610"><a name="p17565310191610"></a><a name="p17565310191610"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="46.1%" headers="mcps1.1.5.1.4 "><p id="p163691850191515"><a name="p163691850191515"></a><a name="p163691850191515"></a>Callback used to obtain the return value.</p>
<p id="p3566124615812"><a name="p3566124615812"></a><a name="p3566124615812"></a>The value <strong id="b4350172620165"><a name="b4350172620165"></a><a name="b4350172620165"></a>true</strong> indicates that the screen is on, and value <strong id="b035432613168"><a name="b035432613168"></a><a name="b035432613168"></a>false</strong> indicates the opposite.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
power.isScreenOn((error, screenOn) => {
if (typeof error === "undefined") { if (typeof error === "undefined") {
console.info('screenOn status is ' + screenOn); console.info('screenOn status is ' + screenOn);
} else { } else {
console.log('error: ' + error); console.log('error: ' + error);
} }
}) })
``` ```
## power.isScreenOn<a name="section143367619119"></a> ## power.isScreenOn
isScreenOn\(\): Promise<boolean\> isScreenOn(): Promise&lt;boolean&gt;
Checks the screen status of the current device. Checks the screen status of the current device.
- Return values **Return value**
| Type| Description|
<a name="table1730417311314"></a> | -------- | -------- |
<table><thead align="left"><tr id="row1930412311018"><th class="cellrowborder" valign="top" width="23.87%" id="mcps1.1.3.1.1"><p id="p15304113117114"><a name="p15304113117114"></a><a name="p15304113117114"></a>Type</p> | Promise&lt;boolean&gt; | Promise used to asynchronously obtain the return value. <br/>The value **true** indicates that the screen is on, and value **false** indicates the opposite.|
</th>
<th class="cellrowborder" valign="top" width="76.13%" id="mcps1.1.3.1.2"><p id="p830411311017"><a name="p830411311017"></a><a name="p830411311017"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row173045311711"><td class="cellrowborder" valign="top" width="23.87%" headers="mcps1.1.3.1.1 "><p id="p686517815914"><a name="p686517815914"></a><a name="p686517815914"></a>Promise&lt;boolean&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="76.13%" headers="mcps1.1.3.1.2 "><p id="p163041531916"><a name="p163041531916"></a><a name="p163041531916"></a>Promise used to asynchronously obtain the return value. The value <strong id="b1934154320392"><a name="b1934154320392"></a><a name="b1934154320392"></a>true</strong> indicates that the screen is on, and value <strong id="b1693454393914"><a name="b1693454393914"></a><a name="b1693454393914"></a>false</strong> indicates the opposite.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
power.isScreenOn()
.then(screenOn => {
console.info('screenOn status is ' + screenOn);
})
.catch(error => {
console.log('error: ' + error);
})
```
**Example**
```
power.isScreenOn()
.then(screenOn => {
console.info('screenOn status is ' + screenOn);
})
.catch(error => {
console.log('error: ' + error);
})
```
# Radio # Radio
>**Note:** >**NOTE**
> >
>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. >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.
...@@ -19,21 +19,21 @@ Obtains the radio access technologies (RATs) used by the CS and PS domains. This ...@@ -19,21 +19,21 @@ Obtains the radio access technologies (RATs) used by the CS and PS domains. This
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission. Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | | -------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech:[RadioTechnology](#RadioTechnology)}\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech:[RadioTechnology](#RadioTechnology)}\> | Yes| Callback used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
radio.getRadioTech(slotId, (err, data) =>{ radio.getRadioTech(slotId, (err, data) =>{
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## radio.getRadioTech<a name=radio.getRadioTech-promise></a> ## radio.getRadioTech<a name=radio.getRadioTech-promise></a>
...@@ -44,52 +44,52 @@ Obtains the RAT used by the CS and PS domains. This function uses a promise to r ...@@ -44,52 +44,52 @@ Obtains the RAT used by the CS and PS domains. This function uses a promise to r
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission. Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ------------------------------------------------------------ | ----------------------------------------------- | | ------------------------------------------------------------ | ----------------------------------------------- |
| Promise<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech: [RadioTechnology](#RadioTechnology)}> | Promise used to return the result.| | Promise<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech: [RadioTechnology](#RadioTechnology)}> | Promise used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let promise = radio.getRadioTech(slotId); let promise = radio.getRadioTech(slotId);
promise.then(data => { promise.then(data => {
console.log(`getRadioTech success, data->${JSON.stringify(data)}`); console.log(`getRadioTech success, data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getRadioTech fail, err->${JSON.stringify(err)}`); console.log(`getRadioTech fail, err->${JSON.stringify(err)}`);
}); });
``` ```
## radio.getNetworkState<a name=radio.getNetworkState-callback1></a> ## radio.getNetworkState<a name=radio.getNetworkState-callback1></a>
getNetworkState\(callback: AsyncCallback<NetworkState\>\): void getNetworkState\(callback: AsyncCallback<NetworkState\>\): void
Obtains the network status. This function uses an asynchronous callback to return the result. Obtains the network status of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission. Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ---------------------------------------------- | ---- | ---------- | | -------- | ---------------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<[NetworkState](#NetworkState)\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<[NetworkState](#NetworkState)\> | Yes| Callback invoked to traverse the entries in the container.|
- Example **Example**
``` ```
radio.getNetworkState((err, data) =>{ radio.getNetworkState((err, data) =>{
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## radio.getNetworkState<a name=radio.getNetworkState-callback2></a> ## radio.getNetworkState<a name=radio.getNetworkState-callback2></a>
...@@ -100,21 +100,21 @@ Obtains the network status of the SIM card in the specified slot. This function ...@@ -100,21 +100,21 @@ Obtains the network status of the SIM card in the specified slot. This function
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission. Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ---------------------------------------------- | ---- | -------------------------------------- | | -------- | ---------------------------------------------- | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<[NetworkState](#NetworkState)\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<[NetworkState](#NetworkState)\> | Yes| Callback used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
radio.getNetworkState(slotId, (err, data) => { radio.getNetworkState(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## radio.getNetworkState<a name=radio.getNetworkState-promise></a> ## radio.getNetworkState<a name=radio.getNetworkState-promise></a>
...@@ -125,29 +125,29 @@ Obtains the network status of the SIM card in the specified slot. This function ...@@ -125,29 +125,29 @@ Obtains the network status of the SIM card in the specified slot. This function
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission. Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | No| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | No| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ---------------------------------------- | --------------------------- | | ---------------------------------------- | --------------------------- |
| Promise\<[NetworkState](#NetworkState)\> | Promise used to return the result.| | Promise\<[NetworkState](#NetworkState)\> | Promise used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let promise = radio.getNetworkState(slotId); let promise = radio.getNetworkState(slotId);
promise.then(data => { promise.then(data => {
console.log(`getNetworkState success, promise: data->${JSON.stringify(data)}`); console.log(`getNetworkState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getNetworkState fail, promise: err->${JSON.stringify(err)}`); console.log(`getNetworkState fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## radio.getNetworkSelectionMode<a name=radio.getNetworkSelectionMode-callback></a> ## radio.getNetworkSelectionMode<a name=radio.getNetworkSelectionMode-callback></a>
...@@ -156,21 +156,21 @@ getNetworkSelectionMode\(slotId: number, callback: AsyncCallback<NetworkSelectio ...@@ -156,21 +156,21 @@ getNetworkSelectionMode\(slotId: number, callback: AsyncCallback<NetworkSelectio
Obtains the network selection mode of the SIM card in the specified slot. This function uses an asynchronous callback to return the result. Obtains the network selection mode of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- | | -------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<[NetworkSelectionMode](#NetworkSelectionMode)\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<[NetworkSelectionMode](#NetworkSelectionMode)\> | Yes| Callback used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
radio.getNetworkSelectionMode(slotId, (err, data) => { radio.getNetworkSelectionMode(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## radio.getNetworkSelectionMode<a name=radio.getNetworkSelectionMode-promise></a> ## radio.getNetworkSelectionMode<a name=radio.getNetworkSelectionMode-promise></a>
...@@ -179,29 +179,29 @@ getNetworkSelectionMode\(slotId: number\): Promise<NetworkSelectionMode\> ...@@ -179,29 +179,29 @@ getNetworkSelectionMode\(slotId: number\): Promise<NetworkSelectionMode\>
Obtains the network selection mode of the SIM card in the specified slot. This function uses a promise to return the result. Obtains the network selection mode of the SIM card in the specified slot. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| -------------------------------------------------------- | ------------------------------- | | -------------------------------------------------------- | ------------------------------- |
| Promise\<[NetworkSelectionMode](#NetworkSelectionMode)\> | Promise used to return the result.| | Promise\<[NetworkSelectionMode](#NetworkSelectionMode)\> | Promise used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let promise = radio.getNetworkSelectionMode(slotId); let promise = radio.getNetworkSelectionMode(slotId);
promise.then(data => { promise.then(data => {
console.log(`getNetworkSelectionMode success, promise: data->${JSON.stringify(data)}`); console.log(`getNetworkSelectionMode success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getNetworkSelectionMode fail, promise: err->${JSON.stringify(err)}`); console.log(`getNetworkSelectionMode fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## radio.getISOCountryCodeForNetwork<sup>7+</sup><a name=radio.getISOCountryCodeForNetwork-callback></a> ## radio.getISOCountryCodeForNetwork<sup>7+</sup><a name=radio.getISOCountryCodeForNetwork-callback></a>
...@@ -210,21 +210,21 @@ getISOCountryCodeForNetwork\(slotId: number, callback: AsyncCallback<string\>\): ...@@ -210,21 +210,21 @@ getISOCountryCodeForNetwork\(slotId: number, callback: AsyncCallback<string\>\):
Obtains the ISO country code of the network with which the SIM card in the specified slot is registered. This function uses an asynchronous callback to return the result. Obtains the ISO country code of the network with which the SIM card in the specified slot is registered. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ----------------------- | ---- | ---------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<string\> | Yes| Callback used to return the result, which is a country code, for example, **CN** (China).| | callback | AsyncCallback\<string\> | Yes| Callback used to return the result, which is a country code, for example, **CN** (China).|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
radio.getISOCountryCodeForNetwork(slotId, (err, data) => { radio.getISOCountryCodeForNetwork(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## radio.getISOCountryCodeForNetwork<sup>7+</sup><a name=radio.getISOCountryCodeForNetwork-promise></a> ## radio.getISOCountryCodeForNetwork<sup>7+</sup><a name=radio.getISOCountryCodeForNetwork-promise></a>
...@@ -233,29 +233,29 @@ getISOCountryCodeForNetwork\(slotId: number\): Promise<string\> ...@@ -233,29 +233,29 @@ getISOCountryCodeForNetwork\(slotId: number\): Promise<string\>
Obtains the ISO country code of the network with which the SIM card in the specified slot is registered. This function uses a promise to return the result. Obtains the ISO country code of the network with which the SIM card in the specified slot is registered. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ----------------- | ------------------------------------------------------------ | | ----------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the result, which is an ISO country code, for example, **CN** (China).| | Promise\<string\> | Promise used to return the result, which is an ISO country code, for example, **CN** (China).|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let promise = radio.getISOCountryCodeForNetwork(slotId); let promise = radio.getISOCountryCodeForNetwork(slotId);
promise.then(data => { promise.then(data => {
console.log(`getISOCountryCodeForNetwork success, promise: data->${JSON.stringify(data)}`); console.log(`getISOCountryCodeForNetwork success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getISOCountryCodeForNetwork fail, promise: err->${JSON.stringify(err)}`); console.log(`getISOCountryCodeForNetwork fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## radio.getSignalInformation<a name=radio.getSignalInformation-callback></a> ## radio.getSignalInformation<a name=radio.getSignalInformation-callback></a>
...@@ -264,21 +264,21 @@ getSignalInformation\(slotId: number, callback: AsyncCallback<Array<SignalInform ...@@ -264,21 +264,21 @@ getSignalInformation\(slotId: number, callback: AsyncCallback<Array<SignalInform
Obtains a list of signal strengths of the network with which the SIM card in the specified slot is registered. This function uses an asynchronous callback to return the result. Obtains a list of signal strengths of the network with which the SIM card in the specified slot is registered. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback\<Array\<[SignalInformation](#SignalInformation)\>\> | Yes| Callback used to return the result, which is a list of [SignalInformation](#SignalInformation) objects.| | callback | AsyncCallback\<Array\<[SignalInformation](#SignalInformation)\>\> | Yes| Callback used to return the result, which is a list of [SignalInformation](#SignalInformation) objects.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
radio.getSignalInformation(slotId, (err, data) => { radio.getSignalInformation(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## radio.getSignalInformation<a name=radio.getSignalInformation-promise></a> ## radio.getSignalInformation<a name=radio.getSignalInformation-promise></a>
...@@ -287,78 +287,78 @@ getSignalInformation\(slotId: number\): Promise<Array<SignalInformation\>\> ...@@ -287,78 +287,78 @@ getSignalInformation\(slotId: number\): Promise<Array<SignalInformation\>\>
Obtains a list of signal strengths of the network with which the SIM card in the specified slot is registered. This function uses a promise to return the result. Obtains a list of signal strengths of the network with which the SIM card in the specified slot is registered. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Array\<[SignalInformation](#SignalInformation)\>\> | Promise used to return the result, which is a list of [SignalInformation](#SignalInformation) objects.| | Promise\<Array\<[SignalInformation](#SignalInformation)\>\> | Promise used to return the result, which is a list of [SignalInformation](#SignalInformation) objects.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let promise = radio.getSignalInformation(slotId); let promise = radio.getSignalInformation(slotId);
promise.then(data => { promise.then(data => {
console.log(`getSignalInformation success, promise: data->${JSON.stringify(data)}`); console.log(`getSignalInformation success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`getSignalInformation fail, promise: err->${JSON.stringify(err)}`); console.error(`getSignalInformation fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## radio.isRadioOn<sup>7+</sup><a name=radio.isRadioOn-callback></a> ## radio.isRadioOn<sup>7+</sup><a name=radio.isRadioOn-callback></a>
isRadioOn\(callback: AsyncCallback<boolean\>\): void isRadioOn\(callback: AsyncCallback<boolean\>\): void
Checks whether radio is turned on. This function uses an asynchronous callback to return the result. Checks whether the radio service is enabled. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission. Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ------------------------ | ---- | ------------------------------------------------------- | | -------- | ------------------------ | ---- | ------------------------------------------------------- |
| callback | AsyncCallback\<boolean\> | Yes| Callback used to return the result. <br/> - **true**: Radio is turned on.<br/> - **false**: Radio is turned off.| | callback | AsyncCallback\<boolean\> | Yes| Callback used to return the result. <br/> - **true**: The radio service is enabled.<br/> - **false**: The radio service is disabled.|
- Example **Example**
``` ```
radio.isRadioOn((err, data) => { radio.isRadioOn((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## radio.isRadioOn<sup>7+</sup><a name=radio.isRadioOn-promise></a> ## radio.isRadioOn<sup>7+</sup><a name=radio.isRadioOn-promise></a>
isRadioOn\(\): Promise<boolean\> isRadioOn\(\): Promise<boolean\>
Checks whether radio is turned on. This function uses a promise to return the result. Checks whether the radio service is enabled. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission. Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Return values **Return value**
| Type| Description| | Type| Description|
| ------------------ | ------------------------------------------------------------ | | ------------------ | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result. <br/> - **true**: Radio is turned on.<br/> - **false**: Radio is turned off.| | Promise\<boolean\> | Promise used to return the result. <br/> - **true**: The radio service is enabled.<br/> - **false**: The radio service is disabled.|
- Example **Example**
``` ```
let promise = radio.isRadioOn(); let promise = radio.isRadioOn();
promise.then(data => { promise.then(data => {
console.log(`isRadioOn success, promise: data->${JSON.stringify(data)}`); console.log(`isRadioOn success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`isRadioOn fail, promise: err->${JSON.stringify(err)}`); console.error(`isRadioOn fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## RadioTechnology<a name=RadioTechnology></a> ## RadioTechnology<a name=RadioTechnology></a>
...@@ -394,7 +394,7 @@ Defines the signal strength. ...@@ -394,7 +394,7 @@ Defines the signal strength.
## NetworkType<a name=NetworkType></a> ## NetworkType<a name=NetworkType></a>
Enumerates network types. Network type.
| Variable| Value| Description| | Variable| Value| Description|
| -------------------- | ---- | ------------------------------------------------------------ | | -------------------- | ---- | ------------------------------------------------------------ |
...@@ -424,7 +424,7 @@ Defines the network registration status. ...@@ -424,7 +424,7 @@ Defines the network registration status.
## RegState<a name=RegState></a> ## RegState<a name=RegState></a>
Enumerates network registration states. Defines the network registration status.
| Variable| Value| Description| | Variable| Value| Description|
| ----------------------------- | ---- | -------------------------- | | ----------------------------- | ---- | -------------------------- |
......
# Running Lock<a name="EN-US_TOPIC_0000001133776274"></a> # Running Lock
>![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import<a name="s56d19203690d4782bfc74069abb6bd71"></a>
## Modules to Import
``` ```
import runninglock from '@ohos.runningLock'; import runninglock from '@ohos.runningLock';
``` ```
## System Capabilities ## System Capabilities
SystemCapability.PowerManager.PowerManager SystemCapability.PowerManager.PowerManager
## RunningLockType<a name="section7299123218370"></a> ## RunningLockType
Enumerates the types of running locks.
<a name="table1540155452420"></a>
<table><thead align="left"><tr id="row1947713549244"><th class="cellrowborder" valign="top" width="30.78%" id="mcps1.1.4.1.1"><p id="p74771754102410"><a name="p74771754102410"></a><a name="p74771754102410"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="11.52%" id="mcps1.1.4.1.2"><p id="p1047755412411"><a name="p1047755412411"></a><a name="p1047755412411"></a>Default Value</p>
</th>
<th class="cellrowborder" valign="top" width="57.699999999999996%" id="mcps1.1.4.1.3"><p id="p12478954132419"><a name="p12478954132419"></a><a name="p12478954132419"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1247811541240"><td class="cellrowborder" valign="top" width="30.78%" headers="mcps1.1.4.1.1 "><p id="p11478654162419"><a name="p11478654162419"></a><a name="p11478654162419"></a>BACKGROUND</p>
</td>
<td class="cellrowborder" valign="top" width="11.52%" headers="mcps1.1.4.1.2 "><p id="p9478135414243"><a name="p9478135414243"></a><a name="p9478135414243"></a>1</p>
</td>
<td class="cellrowborder" valign="top" width="57.699999999999996%" headers="mcps1.1.4.1.3 "><p id="p12478654172415"><a name="p12478654172415"></a><a name="p12478654172415"></a>A lock that prevents the system from hibernating.</p>
</td>
</tr>
<tr id="row184789546249"><td class="cellrowborder" valign="top" width="30.78%" headers="mcps1.1.4.1.1 "><p id="p1971014525154"><a name="p1971014525154"></a><a name="p1971014525154"></a>PROXIMITY_SCREEN_CONTROL</p>
</td>
<td class="cellrowborder" valign="top" width="11.52%" headers="mcps1.1.4.1.2 "><p id="p570945210150"><a name="p570945210150"></a><a name="p570945210150"></a>2</p>
</td>
<td class="cellrowborder" valign="top" width="57.699999999999996%" headers="mcps1.1.4.1.3 "><p id="p1470645211154"><a name="p1470645211154"></a><a name="p1470645211154"></a>A lock that determines whether to turn on or off the screen based on the distance away from the screen.</p>
</td>
</tr>
</tbody>
</table>
## runninglock.isRunningLockTypeSupported<a name="section192192415554"></a>
isRunningLockTypeSupported\(type: RunningLockType, callback: AsyncCallback<boolean\>\): void
Checks whether a specified type of **RunningLock** is supported. This function uses an asynchronous callback to return the result. Enumerates the types of **RunningLock** objects.
| Name| Default Value| Description|
| -------- | -------- | -------- |
| BACKGROUND | 1 | Defines a **RunningLock** object.|
| PROXIMITY_SCREEN_CONTROL | 2 | A lock that determines whether to turn on or off the screen based on the distance away from the screen.|
## isRunningLockTypeSupported
isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback&lt;boolean&gt;): void
- Parameters Checks whether a specified type of RunningLock is supported. This function uses an asynchronous callback to return the result.
<a name="table69661135912"></a> **Parameters**
<table><thead align="left"><tr id="row149668318915"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p7966738914"><a name="p7966738914"></a><a name="p7966738914"></a>Name</p>
</th> | Name| Type| Mandatory| Description|
<th class="cellrowborder" valign="top" width="27.74%" id="mcps1.1.5.1.2"><p id="p296713699"><a name="p296713699"></a><a name="p296713699"></a>Type</p> | -------- | -------- | -------- | -------- |
</th> | type | RunningLockType | Yes| Type of the **RunningLock** object.|
<th class="cellrowborder" valign="top" width="11.200000000000001%" id="mcps1.1.5.1.3"><p id="p196718315911"><a name="p196718315911"></a><a name="p196718315911"></a>Mandatory</p> | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to obtain the return value. <br/>The value **true** indicates that the specified type of **RunningLock** is supported, and value **false** indicates the opposite.|
</th>
<th class="cellrowborder" valign="top" width="46.239999999999995%" id="mcps1.1.5.1.4"><p id="p9967231197"><a name="p9967231197"></a><a name="p9967231197"></a>Description</p> **Example**
</th>
</tr> ```
</thead> runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) => {
<tbody><tr id="row99671533914"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p134721811816"><a name="p134721811816"></a><a name="p134721811816"></a>type</p>
</td>
<td class="cellrowborder" valign="top" width="27.74%" headers="mcps1.1.5.1.2 "><p id="p11967433914"><a name="p11967433914"></a><a name="p11967433914"></a>RunningLockType</p>
</td>
<td class="cellrowborder" valign="top" width="11.200000000000001%" headers="mcps1.1.5.1.3 "><p id="p19671336916"><a name="p19671336916"></a><a name="p19671336916"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="46.239999999999995%" headers="mcps1.1.5.1.4 "><p id="p69671631796"><a name="p69671631796"></a><a name="p69671631796"></a>Type of the <strong id="b2090215448153"><a name="b2090215448153"></a><a name="b2090215448153"></a>RunningLock</strong> object.</p>
</td>
</tr>
<tr id="row10192174731012"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p61933477103"><a name="p61933477103"></a><a name="p61933477103"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="27.74%" headers="mcps1.1.5.1.2 "><p id="p1193104791012"><a name="p1193104791012"></a><a name="p1193104791012"></a>AsyncCallback&lt;boolean&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="11.200000000000001%" headers="mcps1.1.5.1.3 "><p id="p1919313476105"><a name="p1919313476105"></a><a name="p1919313476105"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="46.239999999999995%" headers="mcps1.1.5.1.4 "><p id="p81931947161019"><a name="p81931947161019"></a><a name="p81931947161019"></a>Callback used to obtain the return value.</p>
<p id="p1189279101115"><a name="p1189279101115"></a><a name="p1189279101115"></a>The value <strong id="b662801125113"><a name="b662801125113"></a><a name="b662801125113"></a>true</strong> indicates that the specified type of <strong id="b155741421610"><a name="b155741421610"></a><a name="b155741421610"></a>RunningLock</strong> is supported, and value <strong id="b1062831135112"><a name="b1062831135112"></a><a name="b1062831135112"></a>false</strong> indicates the opposite.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (error, supported) => {
if (typeof error === "undefined") { if (typeof error === "undefined") {
console.info('BACKGROUND support status is ' + supported); console.info('BACKGROUND support status is ' + supported);
} else { } else {
console.log('error: ' + error); console.log('error: ' + error);
} }
}) })
``` ```
## runninglock.isRunningLockTypeSupported<a name="section517513334611"></a> ## isRunningLockTypeSupported
isRunningLockTypeSupported\(type: RunningLockType\): Promise<boolean\> isRunningLockTypeSupported(type: RunningLockType): Promise&lt;boolean&gt;
Checks whether a specified type of **RunningLock** is supported. This function uses a promise to return the result. Checks whether a specified type of **RunningLock** is supported. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
<a name="table12266112710718"></a> | Name| Type| Mandatory| Description|
<table><thead align="left"><tr id="row626618271679"><th class="cellrowborder" valign="top" width="15.1%" id="mcps1.1.5.1.1"><p id="p626612710712"><a name="p626612710712"></a><a name="p626612710712"></a>Name</p> | -------- | -------- | -------- | -------- |
</th> | type | RunningLockType | Yes| Type of the **RunningLock** object.|
<th class="cellrowborder" valign="top" width="21.55%" id="mcps1.1.5.1.2"><p id="p826613271875"><a name="p826613271875"></a><a name="p826613271875"></a>Type</p>
</th> **Return value**
<th class="cellrowborder" valign="top" width="10.100000000000001%" id="mcps1.1.5.1.3"><p id="p142678273718"><a name="p142678273718"></a><a name="p142678273718"></a>Mandatory</p>
</th> | Type| Description|
<th class="cellrowborder" valign="top" width="53.25%" id="mcps1.1.5.1.4"><p id="p1926718271072"><a name="p1926718271072"></a><a name="p1926718271072"></a>Description</p> | -------- | -------- |
</th> | Promise&lt;boolean&gt; | Promise used to asynchronously obtain the return value. The value **true** indicates that the specified type of **RunningLock** is supported, and value **false** indicates the opposite.|
</tr>
</thead> **Example**
<tbody><tr id="row162676272717"><td class="cellrowborder" valign="top" width="15.1%" headers="mcps1.1.5.1.1 "><p id="p1826716272716"><a name="p1826716272716"></a><a name="p1826716272716"></a>type</p>
</td> ```
<td class="cellrowborder" valign="top" width="21.55%" headers="mcps1.1.5.1.2 "><p id="p42673277712"><a name="p42673277712"></a><a name="p42673277712"></a>RunningLockType</p> runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL)
</td> .then(supported => {
<td class="cellrowborder" valign="top" width="10.100000000000001%" headers="mcps1.1.5.1.3 "><p id="p426792717710"><a name="p426792717710"></a><a name="p426792717710"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="53.25%" headers="mcps1.1.5.1.4 "><p id="p1426717270710"><a name="p1426717270710"></a><a name="p1426717270710"></a>Type of the <strong id="b1156123615151"><a name="b1156123615151"></a><a name="b1156123615151"></a>RunningLock</strong> object.</p>
</td>
</tr>
</tbody>
</table>
- Return values
<a name="table82682027272"></a>
<table><thead align="left"><tr id="row92681627972"><th class="cellrowborder" valign="top" width="25.569999999999997%" id="mcps1.1.3.1.1"><p id="p19268192715713"><a name="p19268192715713"></a><a name="p19268192715713"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="74.42999999999999%" id="mcps1.1.3.1.2"><p id="p22684273719"><a name="p22684273719"></a><a name="p22684273719"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1926882720712"><td class="cellrowborder" valign="top" width="25.569999999999997%" headers="mcps1.1.3.1.1 "><p id="p172682272071"><a name="p172682272071"></a><a name="p172682272071"></a>Promise&lt;boolean&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="74.42999999999999%" headers="mcps1.1.3.1.2 "><p id="p102681127973"><a name="p102681127973"></a><a name="p102681127973"></a>Promise used to asynchronously obtain the return value. The value <strong id="b13367196248"><a name="b13367196248"></a><a name="b13367196248"></a>true</strong> indicates that the specified type of <strong id="b594492361616"><a name="b594492361616"></a><a name="b594492361616"></a>RunningLock</strong> is supported, and value <strong id="b136619112410"><a name="b136619112410"></a><a name="b136619112410"></a>false</strong> indicates the opposite.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.PROXIMITY_SCREEN_CONTROL)
.then(supported => {
console.info('PROXIMITY_SCREEN_CONTROL support status is ' + supported); console.info('PROXIMITY_SCREEN_CONTROL support status is ' + supported);
}) })
.catch(error => { .catch(error => {
console.log('error: ' + error); console.log('error: ' + error);
}); });
``` ```
## runninglock.createRunningLock<a name="section787751152220"></a> ## createRunningLock
createRunningLock\(name: string, type: RunningLockType, callback: AsyncCallback<RunningLock\>\): void createRunningLock(name: string, type: RunningLockType, callback: AsyncCallback&lt;RunningLock&gt;): void
Creates a **RunningLock** object. Creates a **RunningLock** object.
- Parameters Before using this API, you must declare the **ohos.permission.RUNNING_LOCK** permission.
<a name="table9878312223"></a> **Parameters**
<table><thead align="left"><tr id="row6878618227"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p1487811115229"><a name="p1487811115229"></a><a name="p1487811115229"></a>Name</p>
</th> | Name| Type| Mandatory| Description|
<th class="cellrowborder" valign="top" width="36.88%" id="mcps1.1.5.1.2"><p id="p1987813113226"><a name="p1987813113226"></a><a name="p1987813113226"></a>Type</p> | -------- | -------- | -------- | -------- |
</th> | name | string | Yes| Name of the **RunningLock** object.|
<th class="cellrowborder" valign="top" width="7.8100000000000005%" id="mcps1.1.5.1.3"><p id="p10878101102213"><a name="p10878101102213"></a><a name="p10878101102213"></a>Mandatory</p> | type | RunningLockType | Yes| Type of the **RunningLock** object to be created.|
</th> | callback | AsyncCallback&lt;[RunningLock](#runninglock)&gt; | Yes| Callback used to obtain the return value.|
<th class="cellrowborder" valign="top" width="40.489999999999995%" id="mcps1.1.5.1.4"><p id="p68781112224"><a name="p68781112224"></a><a name="p68781112224"></a>Description</p>
</th> **Example**
</tr>
</thead> ```
<tbody><tr id="row205362045162115"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p5536134542111"><a name="p5536134542111"></a><a name="p5536134542111"></a>name</p> runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
</td> .then(runninglock => {
<td class="cellrowborder" valign="top" width="36.88%" headers="mcps1.1.5.1.2 "><p id="p5536114512117"><a name="p5536114512117"></a><a name="p5536114512117"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="7.8100000000000005%" headers="mcps1.1.5.1.3 "><p id="p1253617450215"><a name="p1253617450215"></a><a name="p1253617450215"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="40.489999999999995%" headers="mcps1.1.5.1.4 "><p id="p155361545102116"><a name="p155361545102116"></a><a name="p155361545102116"></a>Name of the <strong id="b29521630171617"><a name="b29521630171617"></a><a name="b29521630171617"></a>RunningLock</strong> object.</p>
</td>
</tr>
<tr id="row19878113221"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p1087811152212"><a name="p1087811152212"></a><a name="p1087811152212"></a>type</p>
</td>
<td class="cellrowborder" valign="top" width="36.88%" headers="mcps1.1.5.1.2 "><p id="p14878615224"><a name="p14878615224"></a><a name="p14878615224"></a>RunningLockType</p>
</td>
<td class="cellrowborder" valign="top" width="7.8100000000000005%" headers="mcps1.1.5.1.3 "><p id="p198788152211"><a name="p198788152211"></a><a name="p198788152211"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="40.489999999999995%" headers="mcps1.1.5.1.4 "><p id="p1287815113222"><a name="p1287815113222"></a><a name="p1287815113222"></a>Type of the <strong id="b8849195023516"><a name="b8849195023516"></a><a name="b8849195023516"></a>RunningLock</strong> object to be created.</p>
</td>
</tr>
<tr id="row84458101013"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p104459119108"><a name="p104459119108"></a><a name="p104459119108"></a>callback</p>
</td>
<td class="cellrowborder" valign="top" width="36.88%" headers="mcps1.1.5.1.2 "><p id="p144619141011"><a name="p144619141011"></a><a name="p144619141011"></a>AsyncCallback&lt;<a href="#section189341937163212">RunningLock</a>&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="7.8100000000000005%" headers="mcps1.1.5.1.3 "><p id="p844617111014"><a name="p844617111014"></a><a name="p844617111014"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="40.489999999999995%" headers="mcps1.1.5.1.4 "><p id="p14467151017"><a name="p14467151017"></a><a name="p14467151017"></a>Callback used to obtain the return value.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runninglock => {
var used = runninglock.isUsed(); var used = runninglock.isUsed();
console.info('runninglock is used: ' + used); console.info('runninglock is used: ' + used);
runninglock.lock(500); runninglock.lock(500);
used = runninglock.isUsed(); used = runninglock.isUsed();
console.info('after lock runninglock is used ' + used); console.info('after lock runninglock is used ' + used);
}) })
.catch(error => { .catch(error => {
console.log('create runningLock test error: ' + error); console.log('create runningLock test error: ' + error);
}) })
``` ```
## runninglock.createRunningLock<a name="section16799155115717"></a> ## createRunningLock
createRunningLock\(name: string, type: RunningLockType\): Promise<RunningLock\> createRunningLock(name: string, type: RunningLockType): Promise&lt;RunningLock&gt;
Creates a **RunningLock** object. Creates a **RunningLock** object.
- Parameters Before using this API, you must declare the **ohos.permission.RUNNING_LOCK** permission.
<a name="table254113503814"></a> **Parameters**
<table><thead align="left"><tr id="row85411350182"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p15415503818"><a name="p15415503818"></a><a name="p15415503818"></a>Name</p>
</th> | Name| Type| Mandatory| Description|
<th class="cellrowborder" valign="top" width="33.57%" id="mcps1.1.5.1.2"><p id="p4541105010811"><a name="p4541105010811"></a><a name="p4541105010811"></a>Type</p> | -------- | -------- | -------- | -------- |
</th> | name | string | Yes| Name of the **RunningLock** object.|
<th class="cellrowborder" valign="top" width="12.1%" id="mcps1.1.5.1.3"><p id="p1554115507812"><a name="p1554115507812"></a><a name="p1554115507812"></a>Mandatory</p> | type | RunningLockType | Yes| Type of the **RunningLock** object to be created.|
</th>
<th class="cellrowborder" valign="top" width="39.51%" id="mcps1.1.5.1.4"><p id="p5541650982"><a name="p5541650982"></a><a name="p5541650982"></a>Description</p> **Return value**
</th>
</tr> | Type| Description|
</thead> | -------- | -------- |
<tbody><tr id="row55417507819"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p1754114500810"><a name="p1754114500810"></a><a name="p1754114500810"></a>name</p> | Promise&lt;[RunningLock](#runninglock)&gt; | Promise used to asynchronously obtain the returned **RunningLock** object.|
</td>
<td class="cellrowborder" valign="top" width="33.57%" headers="mcps1.1.5.1.2 "><p id="p65412501586"><a name="p65412501586"></a><a name="p65412501586"></a>string</p> **Example**
</td>
<td class="cellrowborder" valign="top" width="12.1%" headers="mcps1.1.5.1.3 "><p id="p1354195015810"><a name="p1354195015810"></a><a name="p1354195015810"></a>Yes</p> ```
</td> runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
<td class="cellrowborder" valign="top" width="39.51%" headers="mcps1.1.5.1.4 "><p id="p654111501384"><a name="p654111501384"></a><a name="p654111501384"></a>Name of the <strong id="b1071917389164"><a name="b1071917389164"></a><a name="b1071917389164"></a>RunningLock</strong> object.</p> .then(runninglock => {
</td>
</tr>
<tr id="row454111501682"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p1054275016813"><a name="p1054275016813"></a><a name="p1054275016813"></a>type</p>
</td>
<td class="cellrowborder" valign="top" width="33.57%" headers="mcps1.1.5.1.2 "><p id="p55426505812"><a name="p55426505812"></a><a name="p55426505812"></a>RunningLockType</p>
</td>
<td class="cellrowborder" valign="top" width="12.1%" headers="mcps1.1.5.1.3 "><p id="p1254210501587"><a name="p1254210501587"></a><a name="p1254210501587"></a>Yes</p>
</td>
<td class="cellrowborder" valign="top" width="39.51%" headers="mcps1.1.5.1.4 "><p id="p1254245010819"><a name="p1254245010819"></a><a name="p1254245010819"></a>Type of the <strong id="b1302039324"><a name="b1302039324"></a><a name="b1302039324"></a>RunningLock</strong> object to be created.</p>
</td>
</tr>
</tbody>
</table>
- Return values
<a name="table17542250488"></a>
<table><thead align="left"><tr id="row35421550384"><th class="cellrowborder" valign="top" width="32.57%" id="mcps1.1.3.1.1"><p id="p35421501189"><a name="p35421501189"></a><a name="p35421501189"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="67.43%" id="mcps1.1.3.1.2"><p id="p1254213507819"><a name="p1254213507819"></a><a name="p1254213507819"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row165431250282"><td class="cellrowborder" valign="top" width="32.57%" headers="mcps1.1.3.1.1 "><p id="p115430501589"><a name="p115430501589"></a><a name="p115430501589"></a>Promise&lt;<a href="#section189341937163212">RunningLock</a>&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="67.43%" headers="mcps1.1.3.1.2 "><p id="p165439501082"><a name="p165439501082"></a><a name="p165439501082"></a>Promise used to asynchronously obtain the returned <strong id="b120575312249"><a name="b120575312249"></a><a name="b120575312249"></a>RunningLock</strong> object.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runninglock => {
console.info('create runningLock success'); console.info('create runningLock success');
}) })
.catch(error => { .catch(error => {
console.log('create runningLock test error: ' + error); console.log('create runningLock test error: ' + error);
}) })
``` ```
## RunningLock<a name="section189341937163212"></a> ## RunningLock
Defines a **RunningLock** object. Defines a **RunningLock** object.
### lock<a name="section86521450132716"></a>
lock\(timeout: number\): void ### lock
lock(timeout: number): void
Locks and holds a **RunningLock** object. Locks and holds a **RunningLock** object.
- Parameters **Parameters**
<a name="table206539501273"></a> | Name| Type| Mandatory| Description|
<table><thead align="left"><tr id="row3653205002714"><th class="cellrowborder" valign="top" width="14.82%" id="mcps1.1.5.1.1"><p id="p165311506273"><a name="p165311506273"></a><a name="p165311506273"></a>Name</p> | -------- | -------- | -------- | -------- |
</th> | timeout | number | No| Duration for locking and holding the **RunningLock** object.|
<th class="cellrowborder" valign="top" width="14.729999999999999%" id="mcps1.1.5.1.2"><p id="p1065365082714"><a name="p1065365082714"></a><a name="p1065365082714"></a>Type</p>
</th> **Example**
<th class="cellrowborder" valign="top" width="9.16%" id="mcps1.1.5.1.3"><p id="p4653175062711"><a name="p4653175062711"></a><a name="p4653175062711"></a>Mandatory</p>
</th> ```
<th class="cellrowborder" valign="top" width="61.29%" id="mcps1.1.5.1.4"><p id="p665425019272"><a name="p665425019272"></a><a name="p665425019272"></a>Description</p> runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
</th> .then(runningLock => {
</tr>
</thead>
<tbody><tr id="row7654150172712"><td class="cellrowborder" valign="top" width="14.82%" headers="mcps1.1.5.1.1 "><p id="p0444142272919"><a name="p0444142272919"></a><a name="p0444142272919"></a>timeout</p>
</td>
<td class="cellrowborder" valign="top" width="14.729999999999999%" headers="mcps1.1.5.1.2 "><p id="p26542503275"><a name="p26542503275"></a><a name="p26542503275"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="9.16%" headers="mcps1.1.5.1.3 "><p id="p17654105062720"><a name="p17654105062720"></a><a name="p17654105062720"></a>No</p>
</td>
<td class="cellrowborder" valign="top" width="61.29%" headers="mcps1.1.5.1.4 "><p id="p965405018273"><a name="p965405018273"></a><a name="p965405018273"></a>Duration for locking and holding the <strong id="b11111639133615"><a name="b11111639133615"></a><a name="b11111639133615"></a>RunningLock</strong> object.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runningLock => {
runningLock.lock(100) runningLock.lock(100)
console.info('create runningLock success') console.info('create runningLock success')
}) })
.catch(error => { .catch(error => {
console.log('Lock runningLock test error: ' + error) console.log('Lock runningLock test error: ' + error)
}); });
``` ```
### unlock<a name="section19100160122813"></a> ### unlock
unlock\(\): void unlock(): void
Releases a **Runninglock** object. Releases a **Runninglock** object.
- Example **Example**
``` ```
runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND) runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runningLock => { .then(runningLock => {
runningLock.unlock() runningLock.unlock()
console.info('unLock runningLock success') console.info('unLock runningLock success')
}) })
.catch(error => { .catch(error => {
console.log('unLock runningLock test error: ' + error) console.log('unLock runningLock test error: ' + error)
}); });
``` ```
### isUsed<a name="section1410593619146"></a> ### isUsed
isUsed\(\): boolean isUsed(): boolean
Checks the status of the **Runninglock** object. Checks the status of the **Runninglock** object.
- Return values **Return value**
| Type| Description|
<a name="table115061181517"></a> | -------- | -------- |
<table><thead align="left"><tr id="row1150161121510"><th class="cellrowborder" valign="top" width="17.01%" id="mcps1.1.3.1.1"><p id="p1015015113159"><a name="p1015015113159"></a><a name="p1015015113159"></a>Type</p> | boolean | Returns **true** if the **Runninglock** object is held; returns **false** if the **Runninglock** object is released.|
</th>
<th class="cellrowborder" valign="top" width="82.99%" id="mcps1.1.3.1.2"><p id="p2150211201512"><a name="p2150211201512"></a><a name="p2150211201512"></a>Description</p> **Example**
</th>
</tr> ```
</thead> runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
<tbody><tr id="row17150811131514"><td class="cellrowborder" valign="top" width="17.01%" headers="mcps1.1.3.1.1 "><p id="p1150161110157"><a name="p1150161110157"></a><a name="p1150161110157"></a>boolean</p> .then(runningLock => {
</td>
<td class="cellrowborder" valign="top" width="82.99%" headers="mcps1.1.3.1.2 "><p id="p51501611141518"><a name="p51501611141518"></a><a name="p51501611141518"></a>Returns <strong id="b11722741312"><a name="b11722741312"></a><a name="b11722741312"></a>true</strong> if the <strong id="b174812717112"><a name="b174812717112"></a><a name="b174812717112"></a>Runninglock</strong> object is held; returns <strong id="b266618551918"><a name="b266618551918"></a><a name="b266618551918"></a>false</strong> if the <strong id="b1448872517112"><a name="b1448872517112"></a><a name="b1448872517112"></a>Runninglock</strong> object is released.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
runningLock.createRunningLock("running_lock_test", runningLock.RunningLockType.BACKGROUND)
.then(runningLock => {
var used = runningLock.isUsed() var used = runningLock.isUsed()
console.info('runningLock used status: ' + used) console.info('runningLock used status: ' + used)
}) })
.catch(error => { .catch(error => {
console.log('runningLock isUsed test error: ' + error) console.log('runningLock isUsed test error: ' + error)
}); });
``` ```
# SIM Management # SIM Management
>**Note:** >**NOTE**
> >
>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. >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.
...@@ -18,21 +18,20 @@ Obtains the integrated circuit card identity (ICCID) of the SIM card in the spe ...@@ -18,21 +18,20 @@ Obtains the integrated circuit card identity (ICCID) of the SIM card in the spe
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | -------------------------------------- | | -------- | --------------------------- | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
**Example**
- Example ```
sim.getSimIccId(0, (err, data) => {
```
sim.getSimIccId(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sim.getSimIccId<a name=sim.getSimIccId-promise></a> ## sim.getSimIccId<a name=sim.getSimIccId-promise></a>
...@@ -43,28 +42,28 @@ Obtains the ICCID of the SIM card in the specified slot. This function uses a pr ...@@ -43,28 +42,28 @@ Obtains the ICCID of the SIM card in the specified slot. This function uses a pr
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| --------------------- | ---------------------------------- | | --------------------- | ---------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.| | Promise&lt;string&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let promise = sim.getSimIccId(0); let promise = sim.getSimIccId(0);
promise.then(data => { promise.then(data => {
console.log(`getSimIccId success, promise: data->${JSON.stringify(data)}`); console.log(`getSimIccId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getSimIccId fail, promise: err->${JSON.stringify(err)}`); console.log(`getSimIccId fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sim.getDefaultVoiceSlotId<sup>7+</sup><a name= sim.getDefaultVoiceSlotId-callback></a> ## sim.getDefaultVoiceSlotId<sup>7+</sup><a name= sim.getDefaultVoiceSlotId-callback></a>
...@@ -72,19 +71,19 @@ getDefaultVoiceSlotId\(callback: AsyncCallback<number\>\): void ...@@ -72,19 +71,19 @@ getDefaultVoiceSlotId\(callback: AsyncCallback<number\>\): void
Obtains the default slot ID of the SIM card that provides voice services. This function uses an asynchronous callback to return the result. Obtains the default slot ID of the SIM card that provides voice services. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | ---------- | | -------- | --------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to traverse the entries in the container.|
- Example **Example**
``` ```
sim.getDefaultVoiceSlotId((err, data) => { sim.getDefaultVoiceSlotId((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sim.getDefaultVoiceSlotId<sup>7+</sup><a name=sim.getDefaultVoiceSlotId-promise></a> ## sim.getDefaultVoiceSlotId<sup>7+</sup><a name=sim.getDefaultVoiceSlotId-promise></a>
...@@ -93,22 +92,22 @@ getDefaultVoiceSlotId\(\): Promise<number\> ...@@ -93,22 +92,22 @@ getDefaultVoiceSlotId\(\): Promise<number\>
Obtains the default slot ID of the SIM card that provides voice services. This function uses a promise to return the result. Obtains the default slot ID of the SIM card that provides voice services. This function uses a promise to return the result.
- Return values **Return value**
| Type| Description| | Type| Description|
| ----------------- | --------------------------------------- | | ----------------- | --------------------------------------- |
| Promise\<number\> | Promise used to return the result.| | Promise\<number\> | Promise used to return the result.|
- Example **Example**
``` ```
let promise = sim.getDefaultVoiceSlotId(); let promise = sim.getDefaultVoiceSlotId();
promise.then(data => { promise.then(data => {
console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`); console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getDefaultVoiceSlotId fail, promise: err->${JSON.stringify(err)}`); console.log(`getDefaultVoiceSlotId fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sim.getISOCountryCodeForSim<a name=sim.getISOCountryCodeForSim-callback></a> ## sim.getISOCountryCodeForSim<a name=sim.getISOCountryCodeForSim-callback></a>
...@@ -116,20 +115,20 @@ getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback<string\>\): voi ...@@ -116,20 +115,20 @@ getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback<string\>\): voi
Obtains the ISO country code of the SIM card in the specified slot. This function uses an asynchronous callback to return the result. Obtains the ISO country code of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | ---------------------------------------- | | -------- | ----------------------- | ---- | ---------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<string\> | Yes| Callback used to return the result, which is a country code, for example, **CN** (China).| | callback | AsyncCallback\<string\> | Yes| Callback used to return the result, which is a country code, for example, **CN** (China).|
- Example **Example**
``` ```
sim.getISOCountryCodeForSim(0, (err, data) => { sim.getISOCountryCodeForSim(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sim.getISOCountryCodeForSim<a name=sim.getISOCountryCodeForSim-promise></a> ## sim.getISOCountryCodeForSim<a name=sim.getISOCountryCodeForSim-promise></a>
...@@ -138,28 +137,28 @@ getISOCountryCodeForSim\(slotId: number\): Promise<string\> ...@@ -138,28 +137,28 @@ getISOCountryCodeForSim\(slotId: number\): Promise<string\>
Obtains the ISO country code of the SIM card in the specified slot. This function uses a promise to return the result. Obtains the ISO country code of the SIM card in the specified slot. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ----------------- | ------------------------------------------------------------ | | ----------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the result, which is a country code, for example, **CN** (China).| | Promise\<string\> | Promise used to return the result, which is a country code, for example, **CN** (China).|
- Example **Example**
``` ```
let promise = sim.getISOCountryCodeForSim(0); let promise = sim.getISOCountryCodeForSim(0);
promise.then(data => { promise.then(data => {
console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`); console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getISOCountryCodeForSim fail, promise: err->${JSON.stringify(err)}`); console.log(`getISOCountryCodeForSim fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sim.getSimOperatorNumeric<a name=sim.getSimOperatorNumeric-callback></a> ## sim.getSimOperatorNumeric<a name=sim.getSimOperatorNumeric-callback></a>
...@@ -168,20 +167,20 @@ getSimOperatorNumeric\(slotId: number, callback: AsyncCallback<string\>\): void ...@@ -168,20 +167,20 @@ getSimOperatorNumeric\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the public land mobile network (PLMN) ID of the SIM card in the specified slot. This function uses an asynchronous callback to return the result. Obtains the public land mobile network (PLMN) ID of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<string\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<string\> | Yes| Callback used to return the result.|
- Example **Example**
``` ```
sim.getSimOperatorNumeric(0, (err, data) => { sim.getSimOperatorNumeric(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sim.getSimOperatorNumeric<a name=sim.getSimOperatorNumeric-promise></a> ## sim.getSimOperatorNumeric<a name=sim.getSimOperatorNumeric-promise></a>
...@@ -190,28 +189,28 @@ getSimOperatorNumeric\(slotId: number\): Promise<string\> ...@@ -190,28 +189,28 @@ getSimOperatorNumeric\(slotId: number\): Promise<string\>
Obtains the PLMN ID of the SIM card in the specified slot. This function uses a promise to return the result. Obtains the PLMN ID of the SIM card in the specified slot. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ----------------- | ------------------------------------------------ | | ----------------- | ------------------------------------------------ |
| Promise\<string\> | Promise used to return the result.| | Promise\<string\> | Promise used to return the result.|
- Example **Example**
``` ```
let promise = sim.getSimOperatorNumeric(0); let promise = sim.getSimOperatorNumeric(0);
promise.then(data => { promise.then(data => {
console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`); console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getSimOperatorNumeric fail, promise: err->${JSON.stringify(err)}`); console.log(`getSimOperatorNumeric fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sim.getSimSpn<a name=sim.getSimSpn-callback></a> ## sim.getSimSpn<a name=sim.getSimSpn-callback></a>
...@@ -220,20 +219,20 @@ getSimSpn\(slotId: number, callback: AsyncCallback<string\>\): void ...@@ -220,20 +219,20 @@ getSimSpn\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the service provider name (SPN) of the SIM card in the specified slot. This function uses an asynchronous callback to return the result. Obtains the service provider name (SPN) of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<string\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<string\> | Yes| Callback used to return the result.|
- Example **Example**
``` ```
sim.getSimSpn(0, (err, data) => { sim.getSimSpn(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sim.getSimSpn<a name=sim.getSimSpn-promise></a> ## sim.getSimSpn<a name=sim.getSimSpn-promise></a>
...@@ -242,28 +241,28 @@ getSimSpn\(slotId: number\): Promise<string\> ...@@ -242,28 +241,28 @@ getSimSpn\(slotId: number\): Promise<string\>
Obtains the SPN of the SIM card in the specified slot. This function uses a promise to return the result. Obtains the SPN of the SIM card in the specified slot. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ----------------- | ----------------------------------------- | | ----------------- | ----------------------------------------- |
| Promise\<string\> | Promise used to return the result.| | Promise\<string\> | Promise used to return the result.|
- Example **Example**
``` ```
let promise = sim.getSimSpn(0); let promise = sim.getSimSpn(0);
promise.then(data => { promise.then(data => {
console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`); console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getSimSpn fail, promise: err->${JSON.stringify(err)}`); console.log(`getSimSpn fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sim.getSimState<a name=sim.getSimState-callback></a> ## sim.getSimState<a name=sim.getSimState-callback></a>
...@@ -272,20 +271,20 @@ getSimState\(slotId: number, callback: AsyncCallback<SimState\>\): void ...@@ -272,20 +271,20 @@ getSimState\(slotId: number, callback: AsyncCallback<SimState\>\): void
Obtains the status of the SIM card in the specified slot. This function uses an asynchronous callback to return the result. Obtains the status of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------------------------------------- | ---- | ----------------------------------------- | | -------- | -------------------------------------- | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<[SimState](#SimState)\> | Yes| Callback used to return the result. For details, see [SimState](#SimState).| | callback | AsyncCallback\<[SimState](#SimState)\> | Yes| Callback used to return the result, For details, see [SimState](#SimState).|
- Example **Example**
``` ```
sim.getSimState(0, (err, data) => { sim.getSimState(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sim.getSimState<a name=sim.getSimState-promise></a> ## sim.getSimState<a name=sim.getSimState-promise></a>
...@@ -294,28 +293,28 @@ getSimState\(slotId: number\): Promise<SimState\> ...@@ -294,28 +293,28 @@ getSimState\(slotId: number\): Promise<SimState\>
Obtains the status of the SIM card in the specified slot. This function uses a promise to return the result. Obtains the status of the SIM card in the specified slot. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| -------------------------------- | ------------------------------------------ | | -------------------------------- | ------------------------------------------ |
| Promise\<[SimState](#SimState)\> | Promise used to return the result.| | Promise\<[SimState](#SimState)\> | Promise used to return the result.|
- Example **Example**
``` ```
let promise = sim.getSimState(0); let promise = sim.getSimState(0);
promise.then(data => { promise.then(data => {
console.log(`getSimState success, promise: data->${JSON.stringify(data)}`); console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getSimState fail, promise: err->${JSON.stringify(err)}`); console.log(`getSimState fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sim.getSimGid1<a name=sim.getSimGid1-callback></a> ## sim.getSimGid1<a name=sim.getSimGid1-callback></a>
...@@ -325,20 +324,20 @@ Obtains the group identifier level 1 (GID1) of the SIM card in the specified slo ...@@ -325,20 +324,20 @@ Obtains the group identifier level 1 (GID1) of the SIM card in the specified slo
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | AsyncCallback\<string\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<string\> | Yes| Callback used to return the result.|
- Example **Example**
``` ```
sim.getSimGid1(0, (err, data) => { sim.getSimGid1(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sim.getSimGid1<a name=sim.getSimGid1-promise></a> ## sim.getSimGid1<a name=sim.getSimGid1-promise></a>
...@@ -349,28 +348,28 @@ Obtains the GID1 of the SIM card in the specified slot. This function uses a pro ...@@ -349,28 +348,28 @@ Obtains the GID1 of the SIM card in the specified slot. This function uses a pro
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Card slot ID. The options are as follows: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| ----------------- | ------------------------------------------------------------ | | ----------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the result.| | Promise\<string\> | Promise used to return the result.|
- Example **Example**
``` ```
let promise = sim.getSimGid1(0); let promise = sim.getSimGid1(0);
promise.then(data => { promise.then(data => {
console.log(`getSimGid1 success, promise: data->${JSON.stringify(data)}`); console.log(`getSimGid1 success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.log(`getSimGid1 fail, promise: err->${JSON.stringify(err)}`); console.log(`getSimGid1 fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## SimState<a name=SimState></a> ## SimState<a name=SimState></a>
......
# SMS # SMS
>**Note:** >**NOTE**
> >
>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. >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.
...@@ -16,24 +16,24 @@ createMessage\(pdu: Array<number\>, specification: string, callback: AsyncCallba ...@@ -16,24 +16,24 @@ createMessage\(pdu: Array<number\>, specification: string, callback: AsyncCallba
Creates an SMS message instance based on the protocol data unit (PDU) and the specified SMS protocol. This function uses an asynchronous callback to return the result. Creates an SMS message instance based on the protocol data unit (PDU) and the specified SMS protocol. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ | | ------------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
| pdu | Array&lt;number&gt; | Yes| Protocol data unit, which is obtained from the received SMS message.| | pdu | Array&lt;number&gt; | Yes| PDU, which is obtained from the received SMS message.|
| specification | string | Yes| SMS protocol type. The options are as follows: <br/> - **3gpp**: GSM/UMTS/LTE SMS<br/> - **3gpp2**: CDMA SMS| | specification | string | Yes| SMS protocol type. The options are as follows: <br/> - **3gpp**: GSM/UMTS/LTE SMS<br/> - **3gpp2**: CDMA SMS|
| callback | AsyncCallback&lt;[ShortMessage](#ShortMessage)&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;[ShortMessage](#ShortMessage)&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```
const specification = '3gpp'; const specification = '3gpp';
// Display PDUs using numbers in an array, for example, [0x08, 0x91, ...]. // Display PDUs using numbers in an array, for example, [0x08, 0x91, ...].
const pdu = [0x08, 0x91]; const pdu = [0x08, 0x91];
sms.createMessage(pdu, specification, (err, data) => { sms.createMessage(pdu, specification, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sms.createMessage<a name=sms.createMessage-promise></a> ## sms.createMessage<a name=sms.createMessage-promise></a>
...@@ -42,32 +42,32 @@ createMessage\(pdu: Array<number\>, specification: string\): Promise<ShortMessag ...@@ -42,32 +42,32 @@ createMessage\(pdu: Array<number\>, specification: string\): Promise<ShortMessag
Creates an SMS message instance based on the PDU and the specified SMS protocol. This function uses a promise to return the result. Creates an SMS message instance based on the PDU and the specified SMS protocol. This function uses a promise to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------------- | ------------------- | ---- | ------------------------------------------------------------ | | ------------- | ------------------- | ---- | ------------------------------------------------------------ |
| pdu | Array&lt;number&gt; | Yes| Protocol data unit, which is obtained from the received SMS message.| | pdu | Array&lt;number&gt; | Yes| PDU, which is obtained from the received SMS message.|
| specification | string | Yes| SMS protocol type. The options are as follows: <br/> - **3gpp**: GSM/UMTS/LTE SMS<br/> - **3gpp2**: CDMA SMS| | specification | string | Yes| SMS protocol type. The options are as follows: <br/> - **3gpp**: GSM/UMTS/LTE SMS<br/> - **3gpp2**: CDMA SMS|
- Return values **Return value**
| Type| Description| | Type| Description|
| -------------------------------------------- | --------------------------------- | | -------------------------------------------- | --------------------------------- |
| Promise&lt;[ShortMessage](#ShortMessage)&gt; | Promise used to return the result.| | Promise&lt;[ShortMessage](#ShortMessage)&gt; | Promise used to return the result.|
- Example **Example**
``` ```
const specification = '3gpp'; const specification = '3gpp';
// Display PDUs using numbers in an array, for example, [0x08, 0x91, ...]. // Display PDUs using numbers in an array, for example, [0x08, 0x91, ...].
const pdu = [0x08, 0x91]; const pdu = [0x08, 0x91];
let promise = sms.createMessage(pdu, specification); let promise = sms.createMessage(pdu, specification);
promise.then(data => { promise.then(data => {
console.log(`createMessage success, promise: data->${JSON.stringify(data)}`); console.log(`createMessage success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`createMessage fail, promise: err->${JSON.stringify(err)}`); console.error(`createMessage fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sms.sendMessage ## sms.sendMessage
...@@ -77,29 +77,29 @@ Sends an SMS message. ...@@ -77,29 +77,29 @@ Sends an SMS message.
Before using this API, you must declare the **ohos.permission.SEND_MESSAGES** permission. Before using this API, you must declare the **ohos.permission.SEND_MESSAGES** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [SendMessageOptions](#SendMessageOptions) | Yes| Options (including the callback) for sending an SMS message. For details, see [SendMessageOptions](#SendMessageOptions).| | options | [SendMessageOptions](#SendMessageOptions) | Yes| Options (including the callback) for sending an SMS message. For details, see [SendMessageOptions](#SendMessageOptions).|
- Example **Example**
``` ```
let sendCallback = function (err, data) { let sendCallback = function (err, data) {
console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
} }
let deliveryCallback = function (err, data) { let deliveryCallback = function (err, data) {
console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
} }
let slotId = 0; let slotId = 0;
let content ='SMS message content'; let content ='SMS message content';
let destinationHost = '+861xxxxxxxxxx'; let destinationHost = '+861xxxxxxxxxx';
let serviceCenter = '+861xxxxxxxxxx'; let serviceCenter = '+861xxxxxxxxxx';
let destinationPort = 1000; let destinationPort = 1000;
let options = {slotId, content, destinationHost, serviceCenter, destinationPort, sendCallback, deliveryCallback}; let options = {slotId, content, destinationHost, serviceCenter, destinationPort, sendCallback, deliveryCallback};
sms.sendMessage(options); sms.sendMessage(options);
``` ```
## sms.getDefaultSmsSlotId<sup>7+</sup><a name=sms.getDefaultSmsSlotId-callback></a> ## sms.getDefaultSmsSlotId<sup>7+</sup><a name=sms.getDefaultSmsSlotId-callback></a>
...@@ -108,19 +108,19 @@ getDefaultSmsSlotId\(callback: AsyncCallback<number\>\): void ...@@ -108,19 +108,19 @@ getDefaultSmsSlotId\(callback: AsyncCallback<number\>\): void
Obtains the default slot of the SIM card used to send SMS messages. This function uses an asynchronous callback to return the result. Obtains the default slot of the SIM card used to send SMS messages. This function uses an asynchronous callback to return the result.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | ---------------------------------------- | | -------- | --------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result. <br/> - **0**: slot 1<br/> - **1**: slot 2| | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result, <br/> - **0**: slot 1 <br/> - **1**: slot 2|
- Example **Example**
``` ```
sms.getDefaultSmsSlotId((err, data) => { sms.getDefaultSmsSlotId((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sms.getDefaultSmsSlotId<sup>7+</sup><a name=sms.getDefaultSmsSlotId-promise></a> ## sms.getDefaultSmsSlotId<sup>7+</sup><a name=sms.getDefaultSmsSlotId-promise></a>
...@@ -129,22 +129,22 @@ getDefaultSmsSlotId\(\): Promise<number\> ...@@ -129,22 +129,22 @@ getDefaultSmsSlotId\(\): Promise<number\>
Obtains the default slot of the SIM card used to send SMS messages. This function uses a promise to return the result. Obtains the default slot of the SIM card used to send SMS messages. This function uses a promise to return the result.
- Return values **Return value**
| Type| Description| | Type| Description|
| --------------- | ------------------------------------------------------------ | | --------------- | ------------------------------------------------------------ |
| Promise<number> | Promise used to return the result.<br/> - **0**: slot 1<br/> - **1**: slot 2| | Promise<number> | Promise used to return the result.<br/> - **0**: slot 1<br/> - **1**: slot 2|
- Example **Example**
``` ```
let promise = call.getDefaultSmsSlotId(); let promise = call.getDefaultSmsSlotId();
promise.then(data => { promise.then(data => {
console.log(`getDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`); console.log(`getDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`getDefaultSmsSlotId fail, promise: err->${JSON.stringify(err)}`); console.error(`getDefaultSmsSlotId fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sms.setSmscAddr<sup>7+</sup><a name=sms.setSmscAddr-callback></a> ## sms.setSmscAddr<sup>7+</sup><a name=sms.setSmscAddr-callback></a>
...@@ -155,23 +155,23 @@ Sets the short message service center (SMSC) address. This function uses an asyn ...@@ -155,23 +155,23 @@ Sets the short message service center (SMSC) address. This function uses an asyn
Before using this API, you must declare the **ohos.permission.SET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.SET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ------------------------- | ---- | ----------------------------------------- | | -------- | ------------------------- | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| SIM card slot ID: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| smscAddr | string | Yes| SMSC address. | | smscAddr | string | Yes| SMSC address. |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let smscAddr = '+861xxxxxxxxxx'; let smscAddr = '+861xxxxxxxxxx';
sms.setSmscAddr(slotId, smscAddr, (err,data) => { sms.setSmscAddr(slotId, smscAddr, (err,data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sms.setSmscAddr<sup>7+</sup><a name=sms.setSmscAddr-promise></a> ## sms.setSmscAddr<sup>7+</sup><a name=sms.setSmscAddr-promise></a>
...@@ -182,31 +182,31 @@ Sets the SMSC address. This function uses a promise to return the result. ...@@ -182,31 +182,31 @@ Sets the SMSC address. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.SET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.SET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | ------ | ---- | ----------------------------------------- | | -------- | ------ | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| SIM card slot ID: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| smscAddr | string | Yes| SMSC address.| | smscAddr | string | Yes| SMSC address. |
- Return values **Return value**
| Type| Description| | Type| Description|
| ------------------- | ------------------------------- | | ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let smscAddr = '+861xxxxxxxxxx'; let smscAddr = '+861xxxxxxxxxx';
let promise = sms.setSmscAddr(slotId, smscAddr); let promise = sms.setSmscAddr(slotId, smscAddr);
promise.then(data => { promise.then(data => {
console.log(`setSmscAddr success, promise: data->${JSON.stringify(data)}`); console.log(`setSmscAddr success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`setSmscAddr fail, promise: err->${JSON.stringify(err)}`); console.error(`setSmscAddr fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## sms.getSmscAddr<sup>7+</sup><a name=sms.getSmscAddr-callback></a> ## sms.getSmscAddr<sup>7+</sup><a name=sms.getSmscAddr-callback></a>
...@@ -217,21 +217,21 @@ Obtains the SMSC address. This function uses an asynchronous callback to return ...@@ -217,21 +217,21 @@ Obtains the SMSC address. This function uses an asynchronous callback to return
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | ----------------------------------------- | | -------- | --------------------------- | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| SIM card slot ID: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.| | callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
sms.getSmscAddr(slotId, (err, data) => { sms.getSmscAddr(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}); });
``` ```
## sms.getSmscAddr<sup>7+</sup><a name=sms.getSmscAddr-promise></a> ## sms.getSmscAddr<sup>7+</sup><a name=sms.getSmscAddr-promise></a>
...@@ -242,29 +242,29 @@ Obtains the SMSC address. This function uses a promise to return the result. ...@@ -242,29 +242,29 @@ Obtains the SMSC address. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ----------------------------------------- | | ------ | ------ | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2| | slotId | number | Yes| SIM card slot ID: <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Return values **Return value**
| Type| Description| | Type| Description|
| --------------------- | --------------------------------------------- | | --------------------- | --------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.| | Promise&lt;string&gt; | Promise used to return the result.|
- Example **Example**
``` ```
let slotId = 0; let slotId = 0;
let promise = sms.getSmscAddr(slotId); let promise = sms.getSmscAddr(slotId);
promise.then(data => { promise.then(data => {
console.log(`getSmscAddr success, promise: data->${JSON.stringify(data)}`); console.log(`getSmscAddr success, promise: data->${JSON.stringify(data)}`);
}).catch(err => { }).catch(err => {
console.error(`getSmscAddr fail, promise: err->${JSON.stringify(err)}`); console.error(`getSmscAddr fail, promise: err->${JSON.stringify(err)}`);
}); });
``` ```
## ShortMessage<a name=ShortMessage></a> ## ShortMessage<a name=ShortMessage></a>
...@@ -281,13 +281,13 @@ Defines an SMS message instance. ...@@ -281,13 +281,13 @@ Defines an SMS message instance.
| isSmsStatusReportMessage | boolean | Whether the received SMS message is an SMS delivery status report. The default value is **false**. <br/>SMS delivery status report: a message sent from the SMSC to show the current status of the SMS message you delivered.| | isSmsStatusReportMessage | boolean | Whether the received SMS message is an SMS delivery status report. The default value is **false**. <br/>SMS delivery status report: a message sent from the SMSC to show the current status of the SMS message you delivered.|
| messageClass | [ShortMessageClass](#ShortMessageClass) | SMS message type.| | messageClass | [ShortMessageClass](#ShortMessageClass) | SMS message type.|
| pdu | Array&lt;number&gt; | PDU in the SMS message.| | pdu | Array&lt;number&gt; | PDU in the SMS message.|
|protocolId|number|Protocol identifier used for delivering the SMS message.| | protocolId | number | ID of the protocol used for sending SMS messages.|
|scAddress|string|SMSC address.| | scAddress | string | Address of the short message service center (SMSC).|
|scTimestamp|number|SMSC timestamp.| | scTimestamp | number | SMSC timestamp.|
|status|number|SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.| | status | number | SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.|
|userRawData|Array&lt;number&gt;|User data excluding the data header.| | userRawData | Array&lt;number&gt; | User data except the data header.|
|visibleMessageBody|string|SMS message body.| | visibleMessageBody | string | SMS message body.|
|visibleRawAddress|string|Sender address to be displayed on the UI.| | visibleRawAddress | string | Sender address.|
## ShortMessageClass<a name=ShortMessageClass></a> ## ShortMessageClass<a name=ShortMessageClass></a>
...@@ -315,7 +315,7 @@ For example, you can specify the SMS message type by the optional parameter **co ...@@ -315,7 +315,7 @@ For example, you can specify the SMS message type by the optional parameter **co
| destinationHost | string | Yes| Destination address of the SMS message.| | destinationHost | string | Yes| Destination address of the SMS message.|
| content | string \| Array&lt;number&gt; | Yes| SMS message type. If the content is comprised of character strings, the SMS message is a text message. If the content is comprised of byte arrays, the SMS message is a data message.| | content | string \| Array&lt;number&gt; | Yes| SMS message type. If the content is comprised of character strings, the SMS message is a text message. If the content is comprised of byte arrays, the SMS message is a data message.|
| serviceCenter | string | No| SMSC address. By default, the SMSC address in the SIM card is used.| | serviceCenter | string | No| SMSC address. By default, the SMSC address in the SIM card is used.|
| destinationPort | number | No| Destination port of the SMS message. This parameter is mandatory only for a data message. | | destinationPort | number | No| Destination port of the SMS message. This parameter is mandatory only for a data message. Otherwise, it is optional.|
| sendCallback | AsyncCallback&lt;[ISendShortMessageCallback](#ISendShortMessageCallback)&gt; | No| Callback used to return the SMS message sending result. For details, see [ISendShortMessageCallback](#ISendShortMessageCallback).| | sendCallback | AsyncCallback&lt;[ISendShortMessageCallback](#ISendShortMessageCallback)&gt; | No| Callback used to return the SMS message sending result. For details, see [ISendShortMessageCallback](#ISendShortMessageCallback).|
| deliveryCallback | AsyncCallback&lt;[IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback)&gt; | No| Callback used to return the SMS message delivery report. For details, see [IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback).| | deliveryCallback | AsyncCallback&lt;[IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback)&gt; | No| Callback used to return the SMS message delivery report. For details, see [IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback).|
...@@ -333,7 +333,7 @@ Provides the callback for the SMS message delivery report. It consists of three ...@@ -333,7 +333,7 @@ Provides the callback for the SMS message delivery report. It consists of three
## IDeliveryShortMessageCallback<a name=IDeliveryShortMessageCallback></a> ## IDeliveryShortMessageCallback<a name=IDeliveryShortMessageCallback></a>
Provides the callback for the SMS message delivery report. Provides the callback for the SMS message delivery report. Return the SMS delivery report.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ------ | ------------------- | ---- | -------------- | | ------ | ------------------- | ---- | -------------- |
...@@ -346,7 +346,7 @@ Enumerates SMS message sending results. ...@@ -346,7 +346,7 @@ Enumerates SMS message sending results.
| Name| Value| Description| | Name| Value| Description|
| ------------------------------------ | ---- | ------------------------------------------------------ | | ------------------------------------ | ---- | ------------------------------------------------------ |
| SEND_SMS_SUCCESS | 0 | The SMS message is sent successfully.| | SEND_SMS_SUCCESS | 0 | SMS message sent successfully.|
| SEND_SMS_FAILURE_UNKNOWN | 1 | Failed to send the SMS message due to unknown reasons.| | SEND_SMS_FAILURE_UNKNOWN | 1 | Failed to send the SMS message due to unknown reasons.|
| SEND_SMS_FAILURE_RADIO_OFF | 2 | Failed to send the SMS message because the modem is shut down.| | SEND_SMS_FAILURE_RADIO_OFF | 2 | Failed to send the SMS message because the modem is shut down.|
| SEND_SMS_FAILURE_SERVICE_UNAVAILABLE | 3 | Failed to send the SMS message because the network is unavailable or SMS message sending or receiving is not supported.| | SEND_SMS_FAILURE_SERVICE_UNAVAILABLE | 3 | Failed to send the SMS message because the network is unavailable or SMS message sending or receiving is not supported.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册