telephony.md 6.0 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Telephony <a name="EN-US_TOPIC_0000001162422291"></a>

-   [Introduction](#section104mcpsimp)
-   [Directory Structure](#section119mcpsimp)
-   [Constraints](#section123mcpsimp)
-   [Usage Guidelines](#section128mcpsimp)
    -   [Obtaining Current Cellular Network Signal Information](#section1458213210369)
    -   [Observing Cellular Network Status Changes](#section750135512369)

-   [Repositories Involved](#section152mcpsimp)

## 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:

C
clevercong 已提交
18
-   Telephony core service: initializes the RIL Manager, SIM card module, and network search module.
M
mamingshuai 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
-   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.
-   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. 

**Figure 1**  Telephony subsystem architecture

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

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

```
base/telephony/
├── core_service            # Core service
├── call_manager            # Call Manager module
├── cellular_call           # Cellular call module
├── sms_mms                 # SMS & MMS module
└── state_registry          # State registry module
```

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

C
clevercong 已提交
41
1.  The open-source version currently supports only the CS call and SMS services. Cellular data and dual-SIM card are not supported.
M
mamingshuai 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

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

### Obtaining Current Cellular Network Signal Information<a name="section1458213210369"></a>

1.  Import the  **radio**  namespace from  **@ohos.telephony.radio.d.ts**.
2.  Call the  **getSignalInformation\(slotId: number\)**  method in callback or Promise mode. This method 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\).

    ```
    // Import the radio package.
    import radio from "@ohos.telephony.radio";
    
    // Set the value of slotId.
    let slotId = 1;
    
    // Call the API in callback mode.
    radio.getSignalInformation(slotId, (err, value) => {
      if (err) {
        // If the API call failed, err is not empty.
        console.error(`failed to getSignalInformation because ${err.message}`);
        return;
      }
      // If the API call succeeded, err is empty.
      for (let i = 0; i < value.length; i++) {
        console.log(`success to getSignalInformation: type is ${value[i].signalType}, level is ${value[i].signalLevel}`);
      }
    });
    
    // Call the API in Promise mode.
    let promise = radio.getSignalInformation(slotId);
    promise.then((value) => {
      // The API call succeeded.
      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) => {
      // The API call failed.
      console.error(`failed to getSignalInformation because ${err.message}`);
    });
    ```


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

**Adding an Observer**

1.  Import the  **observer**  namespace from  **@ohos.telephony.observer.d.ts**.
2.  Call the  **on\(type: 'networkStateChange'\)**  method with  **slotId**  \(slot ID, optional\) and  **callback**  \(callback processing function\) passed in.
3.  Register an  **observer**  instance for callback events of network status changes.

    ```
    // Import the observer package.
    import observer from '@ohos.telephony.observer';
    
    // Registers an observer.
    observer.on('networkStateChange', {slotId: 1}, (err, value) => {
      if (err) {
        // If the API call failed, err is not empty.
        console.error(`failed, because ${err.message}`);
        return;
      }
      // If the API call succeeded, err is empty.
      console.log(`success on. network state is ` + value);
    });
    ```


**Removing the Observer**

1.  Import the  **observer**  namespace from  **@ohos.telephony.observer.d.ts**.
2.  Call the  **off\(type: 'networkStateChange'\)**  method with the  **callback**  object passed to the  **observer**.

    ```
    // Import the observer package.
    import observer from '@ohos.telephony.observer';
    
    // Deregister the observer.
    observer.off('networkStateChange', (err, value) => {
      if (err) {
        // If the API call failed, err is not empty.
        console.error(`failed, because ${err.message}`);
        return;
      }
      // If the API call succeeded, err is empty.
      console.log(`success off`);
    });
    ```


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

**Telephony subsystem**

C
clevercong 已提交
137
[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README.md)
M
mamingshuai 已提交
138

C
clevercong 已提交
139
[telephony_call_manager](https://gitee.com/openharmony/telephony_call_manager/blob/master/README.md)
M
mamingshuai 已提交
140

C
clevercong 已提交
141
[telephony_cellular_call](https://gitee.com/openharmony/telephony_cellular_call/blob/master/README.md)
M
mamingshuai 已提交
142

C
clevercong 已提交
143
[telephony_sms_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md)
M
mamingshuai 已提交
144

C
clevercong 已提交
145
[telephony_state_registry](https://gitee.com/openharmony/telephony_state_registry/blob/master/README.md)
M
mamingshuai 已提交
146