telephony.md 6.1 KB
Newer Older
G
Gloria 已提交
1
# Telephony
M
mamingshuai 已提交
2

G
Gloria 已提交
3
## Introduction
M
mamingshuai 已提交
4 5 6 7 8

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 已提交
9
-   Telephony core service: initializes the Radio Interface Layer (RIL) Manager, SIM card module, and radio module.
M
mamingshuai 已提交
10 11
-   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 已提交
12
-   Cellular data module: implements cellular data services over carrier networks.
M
mamingshuai 已提交
13 14
-   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 已提交
15 16
-   Data storage module: stores persistent data and provides **DataAbility** access APIs.
-   RIL Adapter module: implements adaptation of the modem communication interfaces.
M
mamingshuai 已提交
17

S
shawn_he 已提交
18
**Figure 1** Telephony subsystem architecture
M
mamingshuai 已提交
19 20 21

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

G
Gloria 已提交
22
## Directory Structure
M
mamingshuai 已提交
23 24 25

```
base/telephony/
S
shawn_he 已提交
26
├── core_service            # Telephony core service
M
mamingshuai 已提交
27 28
├── call_manager            # Call Manager module
├── cellular_call           # Cellular call module
S
shawn_he 已提交
29
├── cellular_data           # Cellular data module
M
mamingshuai 已提交
30
├── sms_mms                 # SMS & MMS module
S
shawn_he 已提交
31 32 33
├── state_registry          # State registry module
├── data_storage            # Data storage module
└── ril_adapter             # RIL Adapter module
M
mamingshuai 已提交
34 35
```

G
Gloria 已提交
36
## Constraints
M
mamingshuai 已提交
37

S
shawn_he 已提交
38
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.
L
liyan 已提交
39
2.  The Hardware Device Interface (HDI) support is subject to the chip vendors' adaptation capability. For details, see [Telephony Development](../device-dev/subsystems/subsys-tel-overview.md).
M
mamingshuai 已提交
40

G
Gloria 已提交
41
## Usage Guidelines
M
mamingshuai 已提交
42

S
shawn_he 已提交
43 44
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.

G
Gloria 已提交
45
### Obtaining the Current Cellular Network Signal Information
M
mamingshuai 已提交
46

S
shawn_he 已提交
47 48 49 50
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 已提交
51 52 53 54 55 56

    ```
    // Import the radio package.
    import radio from "@ohos.telephony.radio";
    
    // Set the value of slotId.
S
shawn_he 已提交
57
    let slotId = 0;
M
mamingshuai 已提交
58 59 60 61
    
    // Call the API in callback mode.
    radio.getSignalInformation(slotId, (err, value) => {
      if (err) {
S
shawn_he 已提交
62
        // If the API call fails, err is not empty.
M
mamingshuai 已提交
63 64 65
        console.error(`failed to getSignalInformation because ${err.message}`);
        return;
      }
S
shawn_he 已提交
66
      // If the API call is successful, err is empty.
M
mamingshuai 已提交
67 68 69 70 71
      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 已提交
72
    // Call the API in promise mode.
M
mamingshuai 已提交
73 74
    let promise = radio.getSignalInformation(slotId);
    promise.then((value) => {
S
shawn_he 已提交
75
      // The API call is successful.
M
mamingshuai 已提交
76 77 78 79
      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 已提交
80
      // The API call fails.
M
mamingshuai 已提交
81 82 83 84 85
      console.error(`failed to getSignalInformation because ${err.message}`);
    });
    ```


G
Gloria 已提交
86
### Observing Cellular Network Status Changes
M
mamingshuai 已提交
87

S
shawn_he 已提交
88
Adding an Observer
M
mamingshuai 已提交
89

S
shawn_he 已提交
90 91 92
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 已提交
93 94 95 96 97 98

    ```
    // Import the observer package.
    import observer from '@ohos.telephony.observer';
    
    // Registers an observer.
S
shawn_he 已提交
99 100
    observer.on('networkStateChange', {slotId: 0}, (value) => {
      console.log(`network state is ` + value);
M
mamingshuai 已提交
101 102 103 104
    });
    ```


S
shawn_he 已提交
105
Removing the Observer
M
mamingshuai 已提交
106

S
shawn_he 已提交
107 108
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 已提交
109 110 111 112 113

    ```
    // Import the observer package.
    import observer from '@ohos.telephony.observer';
    
S
shawn_he 已提交
114 115
    // Unregister the observer.
    observer.off('networkStateChange');
M
mamingshuai 已提交
116 117 118
    ```


G
Gloria 已提交
119
## Repositories Involved
M
mamingshuai 已提交
120

S
shawn_he 已提交
121 122 123 124 125
**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 已提交
126

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

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

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

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

Mr-YX's avatar
Mr-YX 已提交
135
[telephony\_data\_storage](https://gitee.com/openharmony/telephony_data_storage)
M
mamingshuai 已提交
136

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