telephony.md 6.7 KB
Newer Older
M
mamingshuai 已提交
1 2
# Telephony <a name="EN-US_TOPIC_0000001162422291"></a>

S
shawn_he 已提交
3 4 5 6 7 8 9 10 11
-   [Introduction](#section104mcpsimp)
-   [Directory Structure](#section119mcpsimp)
-   [Constraints](#section123mcpsimp)
-   [Usage](#section128mcpsimp)
    -   [Obtaining the Current Cellular Network Signal Information](#section1458213210369)
    -   [Observing Changes to the Cellular Network Status](#section750135512369)

-   [Repositories Involved](#section152mcpsimp)

M
mamingshuai 已提交
12 13 14 15 16 17
## Introduction<a name="section104mcpsimp"></a>

The Telephony subsystem provides APIs for obtaining information about the wireless cellular network and SIM card. Applications can call these APIs to obtain information such as the name of the currently registered network, network service status, signal strength, and SIM card information.

The Telephony subsystem consists of the following modules:

S
shawn_he 已提交
18
-   Telephony core service: initializes the Radio Interface Layer (RIL) Manager, SIM card module, and radio module.
M
mamingshuai 已提交
19 20
-   Call Manager module: manages three types of calls – circuit switched \(CS\), IP multimedia subsystem \(IMS\), and over the top \(OTT\) calls. It is responsible for applying for the audio and video resources required for a call and resolving conflicts in a multi-channel call.
-   Cellular call module: implements basic calls over carrier networks.
S
shawn_he 已提交
21
-   Cellular data module: implements cellular data services over carrier networks.
M
mamingshuai 已提交
22 23
-   SMS & MMS module: provides the capabilities of sending and receiving short message service \(SMS\) messages and encoding and decoding multimedia messaging service \(MMS\) messages.
-   State registry module: provides APIs to register and deregister an observer that listens for various callback events of the telephony subsystem. 
S
shawn_he 已提交
24 25
-   Data storage module: stores persistent data and provides **DataAbility** access APIs.
-   RIL Adapter module: implements adaptation of the modem communication interfaces.
M
mamingshuai 已提交
26

S
shawn_he 已提交
27
**Figure 1** Telephony subsystem architecture
M
mamingshuai 已提交
28 29 30 31 32 33 34

![](figures/en-us_architecture-of-telephony-subsystem.png)

## Directory Structure<a name="section119mcpsimp"></a>

```
base/telephony/
S
shawn_he 已提交
35
├── core_service            # Telephony core service
M
mamingshuai 已提交
36 37
├── call_manager            # Call Manager module
├── cellular_call           # Cellular call module
S
shawn_he 已提交
38
├── cellular_data           # Cellular data module
M
mamingshuai 已提交
39
├── sms_mms                 # SMS & MMS module
S
shawn_he 已提交
40 41 42
├── state_registry          # State registry module
├── data_storage            # Data storage module
└── ril_adapter             # RIL Adapter module
M
mamingshuai 已提交
43 44 45 46
```

## Constraints<a name="section123mcpsimp"></a>

S
shawn_he 已提交
47 48
1.  The open-source version currently provides the cellular call (CS call only), SMS & MMS, and cellular data services and supports the dual-SIM framework.
2.  The Hardware Device Interface (HDI) support is subject to the chip vendors' adaptation capability. For details, see [Telephony Service Development](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-tel.md).
M
mamingshuai 已提交
49 50 51

## Usage Guidelines<a name="section128mcpsimp"></a>

S
shawn_he 已提交
52 53 54
To learn more about the usage of each subsystem module, refer to the respective README. The following illustrates API usage by exemplifying how to obtain the current cellular network signal information and observe the cellular network status changes.

### Obtaining the Current Cellular Network Signal Information<a name="section1458213210369"></a>
M
mamingshuai 已提交
55

S
shawn_he 已提交
56 57 58 59
1.  Import the **radio** namespace from **@ohos.telephony.radio.d.ts**.
2.  Call the **getSignalInformation\(slotId: number\)** function via callback or promise. This function works in asynchronous mode. 
3.  Obtain the result from the **SignalInformation** array in the callback.
4.  Traverse the **SignalInformation** array to obtain the **signalLevel** (signal strength) for each **signalType** (radio access technology).
M
mamingshuai 已提交
60 61 62 63 64 65

    ```
    // Import the radio package.
    import radio from "@ohos.telephony.radio";
    
    // Set the value of slotId.
S
shawn_he 已提交
66
    let slotId = 0;
M
mamingshuai 已提交
67 68 69 70
    
    // Call the API in callback mode.
    radio.getSignalInformation(slotId, (err, value) => {
      if (err) {
S
shawn_he 已提交
71
        // If the API call fails, err is not empty.
M
mamingshuai 已提交
72 73 74
        console.error(`failed to getSignalInformation because ${err.message}`);
        return;
      }
S
shawn_he 已提交
75
      // If the API call is successful, err is empty.
M
mamingshuai 已提交
76 77 78 79 80
      for (let i = 0; i < value.length; i++) {
        console.log(`success to getSignalInformation: type is ${value[i].signalType}, level is ${value[i].signalLevel}`);
      }
    });
    
S
shawn_he 已提交
81
    // Call the API in promise mode.
M
mamingshuai 已提交
82 83
    let promise = radio.getSignalInformation(slotId);
    promise.then((value) => {
S
shawn_he 已提交
84
      // The API call is successful.
M
mamingshuai 已提交
85 86 87 88
      for (let i = 0; i < value.length; i++) {
        console.log(`success to getSignalInformation: type is ${value[i].signalType}, level is ${value[i].signalLevel}`);
      }
    }).catch((err) => {
S
shawn_he 已提交
89
      // The API call fails.
M
mamingshuai 已提交
90 91 92 93 94 95 96
      console.error(`failed to getSignalInformation because ${err.message}`);
    });
    ```


### Observing Cellular Network Status Changes<a name="section750135512369"></a>

S
shawn_he 已提交
97
Adding an Observer
M
mamingshuai 已提交
98

S
shawn_he 已提交
99 100 101
1.  Import the **observer** namespace from **@ohos.telephony.observer.d.ts**.
2.  Call the **on\(type:'networkStateChange'\)** function with **slotId** (slot ID, optional) and **callback** (callback processing function) passed in.
3.  Register an **observer** instance for callback events of network status changes.
M
mamingshuai 已提交
102 103 104 105 106 107

    ```
    // Import the observer package.
    import observer from '@ohos.telephony.observer';
    
    // Registers an observer.
S
shawn_he 已提交
108 109
    observer.on('networkStateChange', {slotId: 0}, (value) => {
      console.log(`network state is ` + value);
M
mamingshuai 已提交
110 111 112 113
    });
    ```


S
shawn_he 已提交
114
Removing the Observer
M
mamingshuai 已提交
115

S
shawn_he 已提交
116 117
1.  Import the **observer** namespace from **@ohos.telephony.observer.d.ts**.
2.  Call the **off\(type: 'networkStateChange'\)** function with the **callback** object passed to **observer**.
M
mamingshuai 已提交
118 119 120 121 122

    ```
    // Import the observer package.
    import observer from '@ohos.telephony.observer';
    
S
shawn_he 已提交
123 124
    // Unregister the observer.
    observer.off('networkStateChange');
M
mamingshuai 已提交
125 126 127 128 129
    ```


## Repositories Involved<a name="section152mcpsimp"></a>

S
shawn_he 已提交
130 131 132 133 134
**Telephony Subsystem**

[telephony\_core\_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README.md)

[telephony\_call\_manager](https://gitee.com/openharmony/telephony_call_manager/blob/master/README.md)
M
mamingshuai 已提交
135

S
shawn_he 已提交
136
[telephony\_cellular\_call](https://gitee.com/openharmony/telephony_cellular_call/blob/master/README.md)
M
mamingshuai 已提交
137

S
shawn_he 已提交
138
[telephony\_cellular\_data](https://gitee.com/openharmony/telephony_cellular_data/blob/master/README.md)
M
mamingshuai 已提交
139

S
shawn_he 已提交
140
[telephony\_sms\_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md)
M
mamingshuai 已提交
141

S
shawn_he 已提交
142
[telephony\_state\_registry](https://gitee.com/openharmony/telephony_state_registry/blob/master/README.md)
M
mamingshuai 已提交
143

S
shawn_he 已提交
144
telephony\_data\_storage
M
mamingshuai 已提交
145

S
shawn_he 已提交
146
[telephony\_ril\_adapter](https://gitee.com/openharmony/telephony_ril_adapter/blob/master/README.md)