• 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 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 isSimActive(slotId: number, callback: AsyncCallback\<boolean>): void | Checks whether the SIM card in the specified slot is activated.                          | –                                 |
84| function hasSimCard(slotId: number, callback: AsyncCallback\<boolean>): void  | Checks whether the specified slot is populated with a SIM card.                            | –                                 |
85| 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_TELEPHONY_STATE |
86| 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 |
87| 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 |
88| function getCardType(slotId: number, callback: AsyncCallback\<CardType>): void | Obtains the type of the SIM card in the specified slot. | –|
89| function hasOperatorPrivileges(slotId: number, callback: AsyncCallback\<boolean>): void | Checks whether the application (caller) has been granted the operator permission.| –|
90| function getMaxSimCount(): number | Obtains the maximum number of SIM cards, that is, the maximum number of SIM card slots, available on the device.| –|
91
92For 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/js-reference/apis/js-apis-sim.md).
93
94### NetworkSearchManager APIs<a name="section198mcpsimp"></a>
95
96| Name                                                    | Description                     | Required Permission                           |
97| ------------------------------------------------------------ | ----------------------------- | ----------------------------------- |
98| 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    |
99| function getSignalInformation(slotId: number, callback: AsyncCallback\<Array\<SignalInformation>>): void; | Obtains the signal information of the SIM card in the specified slot.       | –                                 |
100| 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    |
101| function getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the ISO country code of the SIM card in the specified slot.     | –                                 |
102| 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 |
103| function getNetworkSelectionMode(slotId: number, callback: AsyncCallback\<NetworkSelectionMode>): void; | Obtains the network selection mode of the SIM card in the specified slot.       | –                                 |
104| 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 |
105| function isRadioOn(callback: AsyncCallback\<boolean>): void; | Checks whether the radio service is enabled on the primary SIM card.         | ohos.permission.GET_NETWORK_INFO    |
106| 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    |
107| function turnOnRadio(callback: AsyncCallback\<void>): void;  | Enables the radio service on the primary SIM card.                 | ohos.permission.SET_TELEPHONY_STATE |
108| 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 |
109| function turnOffRadio(callback: AsyncCallback\<void>): void; | Disables the radio service on the primary SIM card.                 | ohos.permission.SET_TELEPHONY_STATE |
110| 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 |
111| function getOperatorName(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the carrier name of the SIM card in the specified slot.      | –                                 |
112| 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                                 |
113| 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                                 |
114| function getCellInformation(slotId: number, callback: AsyncCallback<Array\<CellInformation>>) | Obtains the cell information list.             | ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION         |
115| function sendUpdateCellLocationRequest(slotId: number, callback: AsyncCallback\<void>) | Requests for a cell location update.                 | ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION            |
116| function getIMEI(slotId: number, callback: AsyncCallback\<string>) | Obtains the international mobile equipment identity (IMEI).                     | ohos.permission.GET_TELEPHONY_STATE |
117| function getMEID(slotId: number, callback: AsyncCallback\<string>)| Obtains the mobile equipment identifier (MEID).                     | ohos.permission.GET_TELEPHONY_STATE |
118| function getUniqueDeviceId(slotId: number, callback: AsyncCallback\<string>)| Obtains the unique ID of a device.           | ohos.permission.GET_TELEPHONY_STATE |
119| function getNrOptionMode(slotId: number, callback: AsyncCallback\<NrOptionMode>)| Obtains the 5G mode.                   | – |
120| function isNrSupported: boolean;                             | Checks whether 5G is supported.               | –                                 |
121| function getImsRegInfo(slotId: number, imsType: ImsServiceType, callback: AsyncCallback\<ImsRegInfo>): void; | Gets IMS register status info  | ohos.permission.GET_TELEPHONY_STATE                     |
122| function on(type: 'imsRegStateChange', slotId: number, imsType: ImsServiceType, callback: Callback\<ImsRegInfo>): void; | Registers IMS network status callback  | ohos.permission.GET_TELEPHONY_STATE     |
123| function off(type: 'imsRegStateChange', slotId: number, imsType: ImsServiceType, callback?: Callback\<ImsRegInfo>): void; | Unregisters IMS network status callback  | ohos.permission.GET_TELEPHONY_STATE  |
124
125
126For details about the complete description of JavaScript APIs and sample code, see [Radio](https://gitee.com/openharmony/docs/blob/master/en/application-dev/js-reference/apis/js-apis-radio.md).
127
128**NOTE**
129
130>The RIL Manager does not provide external APIs. It can only be called by modules of the Telephony subsystem.
131
132## Usage Guidelines<a name="section370mcpsimp"></a>
133
134### Network Search<a name="section393mcpsimp"></a>
135
136The function of obtaining the network status is used as an example. The process is as follows:
137
1381.  Query the SIM card in the slot specified by **slotId**. If **slotId** is not set, information about the primary card is queried by default.
1392.  Call the **getNetworkState** method in callback or promise mode to obtain the network status.
1403.  Obtain the SIM card status information. The **getNetworkState** method works in asynchronous mode. The execution result is returned through the callback.
141
142    ```js
143    import radio from "@ohos.telephony.radio";
144
145    // Set the value of slotId.
146    let slotId = 0;
147
148    // Call the API in callback mode.
149    radio.getNetworkState(slotId, (err, value) => {
150      if (err) {
151        // If the API call fails, err is not empty.
152        console.error(`failed to getNetworkState because ${err.message}`);
153        return;
154      }
155      // If the API call is successful, err is empty.
156      console.log(`success to getNetworkState: ${value}`);
157    });
158
159    // Call the API in promise mode.
160    let promise = radio.getNetworkState(slotId);
161    promise.then((value) => {
162      // The API call is successful.
163      console.log(`success to getNetworkState: ${value}`);
164    }).catch((err) => {
165      // The API call fails.
166      console.error(`failed to getNetworkState because ${err.message}`);
167    });
168    ```
169
170
171### SIM Card Management<a name="section402mcpsimp"></a>
172
173The function of querying the status of a specified SIM card is used as an example. The process is as follows:
174
1751.  Set the value of **slotId**.
1762.  Call the **getSimState** method in callback or promise mode to obtain the SIM card status.
1773.  Obtain the SIM card status information. The **getSimState** method works in asynchronous mode. The execution result is returned through the callback.
178
179    ```js
180    import sim from "@ohos.telephony.sim";
181
182    // Set the value of slotId.
183    let slotId = 0;
184
185    // Call the API in callback mode.
186    sim.getSimState(slotId, (err, value) => {
187      if (err) {
188        // If the API call fails, err is not empty.
189        console.error(`failed to getSimState because ${err.message}`);
190        return;
191      }
192      // If the API call is successful, err is empty.
193      console.log(`success to getSimState: ${value}`);
194    });
195
196    // Call the API in promise mode.
197    let promise = sim.getSimState(slotId);
198    promise.then((value) => {
199      // The API call is successful.
200      console.log(`success to getSimState: ${value}`);
201    }).catch((err) => {
202      // The API call fails.
203      console.error(`failed to getSimState because ${err.message}`);
204    });
205    ```
206
207
208## Repositories Involved<a name="section409mcpsimp"></a>
209
210[Telephony Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/%E7%94%B5%E8%AF%9D%E6%9C%8D%E5%8A%A1%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
211
212**telephony\_core\_service**
213
214[telephony\_sms\_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md)
215
216[telephony\_ril\_adapter](https://gitee.com/openharmony/telephony_ril_adapter/blob/master/README.md)
217