• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Telephony Core Service<a name="EN-US_TOPIC_0000001152064913"></a>
2
3-   [Introduction](#section117mcpsimp)
4-   [Directory Structure](#section129mcpsimp)
5-   [Constraints](#section133mcpsimp)
6-   [Available APIs](#section139mcpsimp)
7    -   [SimManager APIs](#section142mcpsimp)
8    -   [NetworkSearchManager APIs](#section198mcpsimp)
9
10-   [Usage Guidelines](#section370mcpsimp)
11    -   [Network Search](#section393mcpsimp)
12    -   [SIM Card Management](#section402mcpsimp)
13
14-   [Repositories Involved](#section409mcpsimp)
15
16## Introduction<a name="section117mcpsimp"></a>
17
18The telephony core service initializes the SimManager, NetworkSearchManager, and TelRilManager modules, and provides access to the RIL Adapter service.
19
20You can implement communication with the RIL Adapter by registering the callback service and implement communication between modules by subscribing to callbacks.
21
22**Figure  1**  Architecture of the telephony core service<a name="fig5700192716219"></a>
23
24
25 ![](figures/en-us_architecture-of-the-core_service-module.png)
26
27As shown in the preceding figure, the telephony core service consists of the following:
28
29-   SimManager: provides services including SIM card initialization, file read/write, loading status notification, and single-SIM/dual-SIM control. These services implement functions such as SIM card status query, SIM card management, SIM card control, STK, contact storage, and SMS storage.
30-   NetworkSearchManager: provides services including network registration and network status acquisition. These services offer functions such as network registration, network mode query, IMS network status reporting, radio service status query, radio service management, signal strength query, cell management, registration status management, and time and time zone setting.
31-   TelRilManager: provides the proactive callback service and query result callback service.
32
33## Directory Structure<a name="section129mcpsimp"></a>
34
35```sh
36/base/telphony/core_service
37├── figures                       # Figures of readme files
38├── frameworks                    # Framework layer
39│   ├── js
40│   └── native
41├── interfaces                    # APIs
42│   ├── innerkits                 # Internal APIs
43|   |    ├── ims                  # IMS network status reporting APIs
44│   └── kits                      # External APIs \(such as JS APIs\)
45├── sa_profile                    # SA profile
46├── services                      # Implementation of the telephony core service
47│   ├── etc                       # Telephony core service driver scripts
48|   ├── ims_service_interaction   # IMS service interaction (for status reporting)
49│   ├── include
50│   ├── network_search            # Network search service
51│   ├── sim                       # SIM card service
52│   ├── src
53│   └── tel_ril                   # Telephony core service and RIL Adapter communication
54├─ test                            # Test code
55│   └── unittest
56└── utils
57    ├── common                    # Telephony core service log
58    ├── log
59    └── preferences
60```
61
62## Constraints<a name="section133mcpsimp"></a>
63
64-   Programming language: C++ and JavaScript.
65-   Software constraints: This module must work with the HDF (drivers\_interface and drivers\_peripheral), RIL Adapter service \(ril\_adapter\), and state registry service \(state\_registry\).
66-   Hardware constraints: The accommodating device must be equipped with a modem and a SIM card capable of independent cellular communication.
67
68## Available APIs<a name="section139mcpsimp"></a>
69
70The telephony core service module needs to provide APIs for related modules, including the SIM card and radio modules.
71
72###  SimManager APIs<a name="section142mcpsimp"></a>
73
74| Name                                                    | Description                                                   | Required Permission                           |
75| ------------------------------------------------------------ | ----------------------------------------------------------- | ----------------------------------- |
76| function getSimState(slotId: number, callback: AsyncCallback\<SimState>): void; | Obtains the state of the SIM card in a specified slot.                                    | –                                 |
77| function getSimGid1(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the group identifier level 1 \(GID1\) of the SIM card in the specified slot.          | ohos.permission.GET_TELEPHONY_STATE |
78| function getSimIccId(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the integrated circuit card identity \(ICCID\) of the SIM card in the specified slot.| ohos.permission.GET_TELEPHONY_STATE |
79| function getISOCountryCodeForSim(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the ISO country code of the SIM card in the specified slot.                               | –                                 |
80| function getSimOperatorNumeric(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the public land mobile network \(PLMN\) ID of the SIM card in the specified slot. | –                                 |
81| function getSimSpn(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the service provider name \(SPN\) of the SIM card in the specified slot.      | –                                 |
82| function getDefaultVoiceSlotId(callback: AsyncCallback\<number>): void; | Obtains the slot of the default SIM card that provides the voice service.                                   | –                                 |
83| function getDefaultVoiceSimId(callback: AsyncCallback\<number>): void; | Obtains the sim id of the default SIM card that provides the voice service.                                   | –                                 |
84| function isSimActive(slotId: number, callback: AsyncCallback\<boolean>): void | Checks whether the SIM card in the specified slot is activated.                          | –                                 |
85| function hasSimCard(slotId: number, callback: AsyncCallback\<boolean>): void  | Checks whether the specified slot is populated with a SIM card.                            | –                                 |
86| function getSimTelephoneNumber(slotId: number, callback: AsyncCallback\<string>): void | Obtains the mobile station integrated services digital network (MSISDN) of the SIM card in the specified slot.|ohos.permission.GET_PHONE_NUMBERS |
87| function getVoiceMailIdentifier(slotId: number, callback: AsyncCallback\<string>): void | Obtains the voice mailbox identifier of the SIM card in the specified slot.| ohos.permission.GET_TELEPHONY_STATE |
88| function getVoiceMailNumber(slotId: number, callback: AsyncCallback\<string>): void | Obtains the voice mailbox number of the SIM card in the specified slot.| ohos.permission.GET_TELEPHONY_STATE |
89| function getCardType(slotId: number, callback: AsyncCallback\<CardType>): void | Obtains the type of the SIM card in the specified slot. | –|
90| function hasOperatorPrivileges(slotId: number, callback: AsyncCallback\<boolean>): void | Checks whether the application (caller) has been granted the operator permission.| –|
91| function getMaxSimCount(): number | Obtains the maximum number of SIM cards, that is, the maximum number of SIM card slots, available on the device.| –|
92
93For details about the complete description of JavaScript APIs and sample code, see [SIM Card Management](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-sim.md).
94
95### NetworkSearchManager APIs<a name="section198mcpsimp"></a>
96
97| Name                                                    | Description                     | Required Permission                           |
98| ------------------------------------------------------------ | ----------------------------- | ----------------------------------- |
99| function getRadioTech(slotId: number, callback: AsyncCallback\<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void; | Obtains the current radio access technology of the SIM card in the specified slot.   | ohos.permission.GET_NETWORK_INFO    |
100| function getSignalInformation(slotId: number, callback: AsyncCallback\<Array\<SignalInformation>>): void; | Obtains the signal information of the SIM card in the specified slot.       | –                                 |
101| function getNetworkState(slotId: number, callback: AsyncCallback\<NetworkState>): void; | Obtains the network status of the SIM card in the specified slot.       | ohos.permission.GET_NETWORK_INFO    |
102| function getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the ISO country code of the SIM card in the specified slot.     | –                                 |
103| function getNetworkSearchInformation(slotId: number, callback: AsyncCallback\<NetworkSearchResult>): void; | Obtains the manual network search result of the SIM card in the specified slot.   | ohos.permission.GET_TELEPHONY_STATE |
104| function getNetworkSelectionMode(slotId: number, callback: AsyncCallback\<NetworkSelectionMode>): void; | Obtains the network selection mode of the SIM card in the specified slot.       | –                                 |
105| function setNetworkSelectionMode(options: NetworkSelectionModeOptions, callback: AsyncCallback\<void>): void; | Sets the network selection mode of the SIM card in the specified slot.       | ohos.permission.SET_TELEPHONY_STATE |
106| function isRadioOn(callback: AsyncCallback\<boolean>): void; | Checks whether the radio service is enabled on the primary SIM card.         | ohos.permission.GET_NETWORK_INFO    |
107| function isRadioOn(slotId: number, callback: AsyncCallback\<boolean>): void; | Checks whether the radio service is enabled on the SIM card in the specified slot.| ohos.permission.GET_NETWORK_INFO    |
108| function turnOnRadio(callback: AsyncCallback\<void>): void;  | Enables the radio service on the primary SIM card.                 | ohos.permission.SET_TELEPHONY_STATE |
109| function turnOnRadio(slotId: number, callback: AsyncCallback\<void>): void; | Enables the radio service on the SIM card in the specified slot.        | ohos.permission.SET_TELEPHONY_STATE |
110| function turnOffRadio(callback: AsyncCallback\<void>): void; | Disables the radio service on the primary SIM card.                 | ohos.permission.SET_TELEPHONY_STATE |
111| function turnOffRadio(slotId: number, callback: AsyncCallback\<void>): void; | Disables the radio service on the SIM card in the specified slot.        | ohos.permission.SET_TELEPHONY_STATE |
112| function getOperatorName(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the carrier name of the SIM card in the specified slot.      | –                                 |
113| function setPreferredNetwork(slotId: number, networkMode: PreferredNetworkMode, callback: AsyncCallback\<void>): void; | Sets the preferred network of the SIM card in the specified slot.   | ohos.permission.SET_TELEPHONY_STATE                                 |
114| function getPreferredNetwork(slotId: number, callback: AsyncCallback\<PreferredNetworkMode>): void; | Obtains the preferred network of the SIM card in the specified slot.   | ohos.permission.GET_TELEPHONY_STATE                                 |
115| function getCellInformation(slotId: number, callback: AsyncCallback<Array\<CellInformation>>) | Obtains the cell information list.             | ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION         |
116| function sendUpdateCellLocationRequest(slotId: number, callback: AsyncCallback\<void>) | Requests for a cell location update.                 | ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION            |
117| function getIMEI(slotId: number, callback: AsyncCallback\<string>) | Obtains the international mobile equipment identity (IMEI).                     | ohos.permission.GET_TELEPHONY_STATE |
118| function getMEID(slotId: number, callback: AsyncCallback\<string>)| Obtains the mobile equipment identifier (MEID).                     | ohos.permission.GET_TELEPHONY_STATE |
119| function getUniqueDeviceId(slotId: number, callback: AsyncCallback\<string>)| Obtains the unique ID of a device.           | ohos.permission.GET_TELEPHONY_STATE |
120| function getNrOptionMode(slotId: number, callback: AsyncCallback\<NrOptionMode>)| Obtains the 5G mode.                   | – |
121| function isNrSupported: boolean;                             | Checks whether 5G is supported.               | –                                 |
122| function getImsRegInfo(slotId: number, imsType: ImsServiceType, callback: AsyncCallback\<ImsRegInfo>): void; | Gets IMS register status info  | ohos.permission.GET_TELEPHONY_STATE                     |
123| function on(type: 'imsRegStateChange', slotId: number, imsType: ImsServiceType, callback: Callback\<ImsRegInfo>): void; | Registers IMS network status callback  | ohos.permission.GET_TELEPHONY_STATE     |
124| function off(type: 'imsRegStateChange', slotId: number, imsType: ImsServiceType, callback?: Callback\<ImsRegInfo>): void; | Unregisters IMS network status callback  | ohos.permission.GET_TELEPHONY_STATE  |
125
126
127For details about the complete description of JavaScript APIs and sample code, see [Radio](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-radio.md).
128
129**NOTE**
130
131>The RIL Manager does not provide external APIs. It can only be called by modules of the Telephony subsystem.
132
133## Usage Guidelines<a name="section370mcpsimp"></a>
134
135### Network Search<a name="section393mcpsimp"></a>
136
137The function of obtaining the network status is used as an example. The process is as follows:
138
1391.  Query the SIM card in the slot specified by **slotId**. If **slotId** is not set, information about the primary card is queried by default.
1402.  Call the **getNetworkState** method in callback or promise mode to obtain the network status.
1413.  Obtain the SIM card status information. The **getNetworkState** method works in asynchronous mode. The execution result is returned through the callback.
142
143    ```js
144    import radio from "@ohos.telephony.radio";
145
146    // Set the value of slotId.
147    let slotId = 0;
148
149    // Call the API in callback mode.
150    radio.getNetworkState(slotId, (err, value) => {
151      if (err) {
152        // If the API call fails, err is not empty.
153        console.error(`failed to getNetworkState because ${err.message}`);
154        return;
155      }
156      // If the API call is successful, err is empty.
157      console.log(`success to getNetworkState: ${value}`);
158    });
159
160    // Call the API in promise mode.
161    let promise = radio.getNetworkState(slotId);
162    promise.then((value) => {
163      // The API call is successful.
164      console.log(`success to getNetworkState: ${value}`);
165    }).catch((err) => {
166      // The API call fails.
167      console.error(`failed to getNetworkState because ${err.message}`);
168    });
169    ```
170
171
172### SIM Card Management<a name="section402mcpsimp"></a>
173
174The function of querying the status of a specified SIM card is used as an example. The process is as follows:
175
1761.  Set the value of **slotId**.
1772.  Call the **getSimState** method in callback or promise mode to obtain the SIM card status.
1783.  Obtain the SIM card status information. The **getSimState** method works in asynchronous mode. The execution result is returned through the callback.
179
180    ```js
181    import sim from "@ohos.telephony.sim";
182
183    // Set the value of slotId.
184    let slotId = 0;
185
186    // Call the API in callback mode.
187    sim.getSimState(slotId, (err, value) => {
188      if (err) {
189        // If the API call fails, err is not empty.
190        console.error(`failed to getSimState because ${err.message}`);
191        return;
192      }
193      // If the API call is successful, err is empty.
194      console.log(`success to getSimState: ${value}`);
195    });
196
197    // Call the API in promise mode.
198    let promise = sim.getSimState(slotId);
199    promise.then((value) => {
200      // The API call is successful.
201      console.log(`success to getSimState: ${value}`);
202    }).catch((err) => {
203      // The API call fails.
204      console.error(`failed to getSimState because ${err.message}`);
205    });
206    ```
207
208
209## Repositories Involved<a name="section409mcpsimp"></a>
210
211[Telephony Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/telephony.md)
212
213**telephony\_core\_service**
214
215[telephony\_sms\_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md)
216
217[drivers_interface](https://gitee.com/openharmony/drivers_interface)
218
219[drivers_peripheral](https://gitee.com/openharmony/drivers_peripheral)
220
221[telephony\_ril\_adapter](https://gitee.com/openharmony/telephony_ril_adapter/blob/master/README.md)
222