17859cbb8Sopenharmony_ci# Telephony Core Service<a name="EN-US_TOPIC_0000001152064913"></a> 27859cbb8Sopenharmony_ci 37859cbb8Sopenharmony_ci- [Introduction](#section117mcpsimp) 47859cbb8Sopenharmony_ci- [Directory Structure](#section129mcpsimp) 57859cbb8Sopenharmony_ci- [Constraints](#section133mcpsimp) 67859cbb8Sopenharmony_ci- [Available APIs](#section139mcpsimp) 77859cbb8Sopenharmony_ci - [SimManager APIs](#section142mcpsimp) 87859cbb8Sopenharmony_ci - [NetworkSearchManager APIs](#section198mcpsimp) 97859cbb8Sopenharmony_ci 107859cbb8Sopenharmony_ci- [Usage Guidelines](#section370mcpsimp) 117859cbb8Sopenharmony_ci - [Network Search](#section393mcpsimp) 127859cbb8Sopenharmony_ci - [SIM Card Management](#section402mcpsimp) 137859cbb8Sopenharmony_ci 147859cbb8Sopenharmony_ci- [Repositories Involved](#section409mcpsimp) 157859cbb8Sopenharmony_ci 167859cbb8Sopenharmony_ci## Introduction<a name="section117mcpsimp"></a> 177859cbb8Sopenharmony_ci 187859cbb8Sopenharmony_ciThe telephony core service initializes the SimManager, NetworkSearchManager, and TelRilManager modules, and provides access to the RIL Adapter service. 197859cbb8Sopenharmony_ci 207859cbb8Sopenharmony_ciYou can implement communication with the RIL Adapter by registering the callback service and implement communication between modules by subscribing to callbacks. 217859cbb8Sopenharmony_ci 227859cbb8Sopenharmony_ci**Figure 1** Architecture of the telephony core service<a name="fig5700192716219"></a> 237859cbb8Sopenharmony_ci 247859cbb8Sopenharmony_ci 257859cbb8Sopenharmony_ci  267859cbb8Sopenharmony_ci 277859cbb8Sopenharmony_ciAs shown in the preceding figure, the telephony core service consists of the following: 287859cbb8Sopenharmony_ci 297859cbb8Sopenharmony_ci- 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. 307859cbb8Sopenharmony_ci- 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. 317859cbb8Sopenharmony_ci- TelRilManager: provides the proactive callback service and query result callback service. 327859cbb8Sopenharmony_ci 337859cbb8Sopenharmony_ci## Directory Structure<a name="section129mcpsimp"></a> 347859cbb8Sopenharmony_ci 357859cbb8Sopenharmony_ci```sh 367859cbb8Sopenharmony_ci/base/telphony/core_service 377859cbb8Sopenharmony_ci├── figures # Figures of readme files 387859cbb8Sopenharmony_ci├── frameworks # Framework layer 397859cbb8Sopenharmony_ci│ ├── js 407859cbb8Sopenharmony_ci│ └── native 417859cbb8Sopenharmony_ci├── interfaces # APIs 427859cbb8Sopenharmony_ci│ ├── innerkits # Internal APIs 437859cbb8Sopenharmony_ci| | ├── ims # IMS network status reporting APIs 447859cbb8Sopenharmony_ci│ └── kits # External APIs \(such as JS APIs\) 457859cbb8Sopenharmony_ci├── sa_profile # SA profile 467859cbb8Sopenharmony_ci├── services # Implementation of the telephony core service 477859cbb8Sopenharmony_ci│ ├── etc # Telephony core service driver scripts 487859cbb8Sopenharmony_ci| ├── ims_service_interaction # IMS service interaction (for status reporting) 497859cbb8Sopenharmony_ci│ ├── include 507859cbb8Sopenharmony_ci│ ├── network_search # Network search service 517859cbb8Sopenharmony_ci│ ├── sim # SIM card service 527859cbb8Sopenharmony_ci│ ├── src 537859cbb8Sopenharmony_ci│ └── tel_ril # Telephony core service and RIL Adapter communication 547859cbb8Sopenharmony_ci├─ test # Test code 557859cbb8Sopenharmony_ci│ └── unittest 567859cbb8Sopenharmony_ci└── utils 577859cbb8Sopenharmony_ci ├── common # Telephony core service log 587859cbb8Sopenharmony_ci ├── log 597859cbb8Sopenharmony_ci └── preferences 607859cbb8Sopenharmony_ci``` 617859cbb8Sopenharmony_ci 627859cbb8Sopenharmony_ci## Constraints<a name="section133mcpsimp"></a> 637859cbb8Sopenharmony_ci 647859cbb8Sopenharmony_ci- Programming language: C++ and JavaScript. 657859cbb8Sopenharmony_ci- 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\). 667859cbb8Sopenharmony_ci- Hardware constraints: The accommodating device must be equipped with a modem and a SIM card capable of independent cellular communication. 677859cbb8Sopenharmony_ci 687859cbb8Sopenharmony_ci## Available APIs<a name="section139mcpsimp"></a> 697859cbb8Sopenharmony_ci 707859cbb8Sopenharmony_ciThe telephony core service module needs to provide APIs for related modules, including the SIM card and radio modules. 717859cbb8Sopenharmony_ci 727859cbb8Sopenharmony_ci### SimManager APIs<a name="section142mcpsimp"></a> 737859cbb8Sopenharmony_ci 747859cbb8Sopenharmony_ci| Name | Description | Required Permission | 757859cbb8Sopenharmony_ci| ------------------------------------------------------------ | ----------------------------------------------------------- | ----------------------------------- | 767859cbb8Sopenharmony_ci| function getSimState(slotId: number, callback: AsyncCallback\<SimState>): void; | Obtains the state of the SIM card in a specified slot. | – | 777859cbb8Sopenharmony_ci| 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 | 787859cbb8Sopenharmony_ci| 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 | 797859cbb8Sopenharmony_ci| function getISOCountryCodeForSim(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the ISO country code of the SIM card in the specified slot. | – | 807859cbb8Sopenharmony_ci| function getSimOperatorNumeric(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the public land mobile network \(PLMN\) ID of the SIM card in the specified slot. | – | 817859cbb8Sopenharmony_ci| function getSimSpn(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the service provider name \(SPN\) of the SIM card in the specified slot. | – | 827859cbb8Sopenharmony_ci| function getDefaultVoiceSlotId(callback: AsyncCallback\<number>): void; | Obtains the slot of the default SIM card that provides the voice service. | – | 837859cbb8Sopenharmony_ci| function getDefaultVoiceSimId(callback: AsyncCallback\<number>): void; | Obtains the sim id of the default SIM card that provides the voice service. | – | 847859cbb8Sopenharmony_ci| function isSimActive(slotId: number, callback: AsyncCallback\<boolean>): void | Checks whether the SIM card in the specified slot is activated. | – | 857859cbb8Sopenharmony_ci| function hasSimCard(slotId: number, callback: AsyncCallback\<boolean>): void | Checks whether the specified slot is populated with a SIM card. | – | 867859cbb8Sopenharmony_ci| 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 | 877859cbb8Sopenharmony_ci| 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 | 887859cbb8Sopenharmony_ci| 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 | 897859cbb8Sopenharmony_ci| function getCardType(slotId: number, callback: AsyncCallback\<CardType>): void | Obtains the type of the SIM card in the specified slot. | –| 907859cbb8Sopenharmony_ci| function hasOperatorPrivileges(slotId: number, callback: AsyncCallback\<boolean>): void | Checks whether the application (caller) has been granted the operator permission.| –| 917859cbb8Sopenharmony_ci| function getMaxSimCount(): number | Obtains the maximum number of SIM cards, that is, the maximum number of SIM card slots, available on the device.| –| 927859cbb8Sopenharmony_ci 937859cbb8Sopenharmony_ciFor 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). 947859cbb8Sopenharmony_ci 957859cbb8Sopenharmony_ci### NetworkSearchManager APIs<a name="section198mcpsimp"></a> 967859cbb8Sopenharmony_ci 977859cbb8Sopenharmony_ci| Name | Description | Required Permission | 987859cbb8Sopenharmony_ci| ------------------------------------------------------------ | ----------------------------- | ----------------------------------- | 997859cbb8Sopenharmony_ci| 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 | 1007859cbb8Sopenharmony_ci| function getSignalInformation(slotId: number, callback: AsyncCallback\<Array\<SignalInformation>>): void; | Obtains the signal information of the SIM card in the specified slot. | – | 1017859cbb8Sopenharmony_ci| 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 | 1027859cbb8Sopenharmony_ci| function getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the ISO country code of the SIM card in the specified slot. | – | 1037859cbb8Sopenharmony_ci| 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 | 1047859cbb8Sopenharmony_ci| function getNetworkSelectionMode(slotId: number, callback: AsyncCallback\<NetworkSelectionMode>): void; | Obtains the network selection mode of the SIM card in the specified slot. | – | 1057859cbb8Sopenharmony_ci| 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 | 1067859cbb8Sopenharmony_ci| function isRadioOn(callback: AsyncCallback\<boolean>): void; | Checks whether the radio service is enabled on the primary SIM card. | ohos.permission.GET_NETWORK_INFO | 1077859cbb8Sopenharmony_ci| 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 | 1087859cbb8Sopenharmony_ci| function turnOnRadio(callback: AsyncCallback\<void>): void; | Enables the radio service on the primary SIM card. | ohos.permission.SET_TELEPHONY_STATE | 1097859cbb8Sopenharmony_ci| 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 | 1107859cbb8Sopenharmony_ci| function turnOffRadio(callback: AsyncCallback\<void>): void; | Disables the radio service on the primary SIM card. | ohos.permission.SET_TELEPHONY_STATE | 1117859cbb8Sopenharmony_ci| 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 | 1127859cbb8Sopenharmony_ci| function getOperatorName(slotId: number, callback: AsyncCallback\<string>): void; | Obtains the carrier name of the SIM card in the specified slot. | – | 1137859cbb8Sopenharmony_ci| 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 | 1147859cbb8Sopenharmony_ci| 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 | 1157859cbb8Sopenharmony_ci| function getCellInformation(slotId: number, callback: AsyncCallback<Array\<CellInformation>>) | Obtains the cell information list. | ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION | 1167859cbb8Sopenharmony_ci| function sendUpdateCellLocationRequest(slotId: number, callback: AsyncCallback\<void>) | Requests for a cell location update. | ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION | 1177859cbb8Sopenharmony_ci| function getIMEI(slotId: number, callback: AsyncCallback\<string>) | Obtains the international mobile equipment identity (IMEI). | ohos.permission.GET_TELEPHONY_STATE | 1187859cbb8Sopenharmony_ci| function getMEID(slotId: number, callback: AsyncCallback\<string>)| Obtains the mobile equipment identifier (MEID). | ohos.permission.GET_TELEPHONY_STATE | 1197859cbb8Sopenharmony_ci| function getUniqueDeviceId(slotId: number, callback: AsyncCallback\<string>)| Obtains the unique ID of a device. | ohos.permission.GET_TELEPHONY_STATE | 1207859cbb8Sopenharmony_ci| function getNrOptionMode(slotId: number, callback: AsyncCallback\<NrOptionMode>)| Obtains the 5G mode. | – | 1217859cbb8Sopenharmony_ci| function isNrSupported: boolean; | Checks whether 5G is supported. | – | 1227859cbb8Sopenharmony_ci| function getImsRegInfo(slotId: number, imsType: ImsServiceType, callback: AsyncCallback\<ImsRegInfo>): void; | Gets IMS register status info | ohos.permission.GET_TELEPHONY_STATE | 1237859cbb8Sopenharmony_ci| function on(type: 'imsRegStateChange', slotId: number, imsType: ImsServiceType, callback: Callback\<ImsRegInfo>): void; | Registers IMS network status callback | ohos.permission.GET_TELEPHONY_STATE | 1247859cbb8Sopenharmony_ci| function off(type: 'imsRegStateChange', slotId: number, imsType: ImsServiceType, callback?: Callback\<ImsRegInfo>): void; | Unregisters IMS network status callback | ohos.permission.GET_TELEPHONY_STATE | 1257859cbb8Sopenharmony_ci 1267859cbb8Sopenharmony_ci 1277859cbb8Sopenharmony_ciFor 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). 1287859cbb8Sopenharmony_ci 1297859cbb8Sopenharmony_ci**NOTE** 1307859cbb8Sopenharmony_ci 1317859cbb8Sopenharmony_ci>The RIL Manager does not provide external APIs. It can only be called by modules of the Telephony subsystem. 1327859cbb8Sopenharmony_ci 1337859cbb8Sopenharmony_ci## Usage Guidelines<a name="section370mcpsimp"></a> 1347859cbb8Sopenharmony_ci 1357859cbb8Sopenharmony_ci### Network Search<a name="section393mcpsimp"></a> 1367859cbb8Sopenharmony_ci 1377859cbb8Sopenharmony_ciThe function of obtaining the network status is used as an example. The process is as follows: 1387859cbb8Sopenharmony_ci 1397859cbb8Sopenharmony_ci1. Query the SIM card in the slot specified by **slotId**. If **slotId** is not set, information about the primary card is queried by default. 1407859cbb8Sopenharmony_ci2. Call the **getNetworkState** method in callback or promise mode to obtain the network status. 1417859cbb8Sopenharmony_ci3. Obtain the SIM card status information. The **getNetworkState** method works in asynchronous mode. The execution result is returned through the callback. 1427859cbb8Sopenharmony_ci 1437859cbb8Sopenharmony_ci ```js 1447859cbb8Sopenharmony_ci import radio from "@ohos.telephony.radio"; 1457859cbb8Sopenharmony_ci 1467859cbb8Sopenharmony_ci // Set the value of slotId. 1477859cbb8Sopenharmony_ci let slotId = 0; 1487859cbb8Sopenharmony_ci 1497859cbb8Sopenharmony_ci // Call the API in callback mode. 1507859cbb8Sopenharmony_ci radio.getNetworkState(slotId, (err, value) => { 1517859cbb8Sopenharmony_ci if (err) { 1527859cbb8Sopenharmony_ci // If the API call fails, err is not empty. 1537859cbb8Sopenharmony_ci console.error(`failed to getNetworkState because ${err.message}`); 1547859cbb8Sopenharmony_ci return; 1557859cbb8Sopenharmony_ci } 1567859cbb8Sopenharmony_ci // If the API call is successful, err is empty. 1577859cbb8Sopenharmony_ci console.log(`success to getNetworkState: ${value}`); 1587859cbb8Sopenharmony_ci }); 1597859cbb8Sopenharmony_ci 1607859cbb8Sopenharmony_ci // Call the API in promise mode. 1617859cbb8Sopenharmony_ci let promise = radio.getNetworkState(slotId); 1627859cbb8Sopenharmony_ci promise.then((value) => { 1637859cbb8Sopenharmony_ci // The API call is successful. 1647859cbb8Sopenharmony_ci console.log(`success to getNetworkState: ${value}`); 1657859cbb8Sopenharmony_ci }).catch((err) => { 1667859cbb8Sopenharmony_ci // The API call fails. 1677859cbb8Sopenharmony_ci console.error(`failed to getNetworkState because ${err.message}`); 1687859cbb8Sopenharmony_ci }); 1697859cbb8Sopenharmony_ci ``` 1707859cbb8Sopenharmony_ci 1717859cbb8Sopenharmony_ci 1727859cbb8Sopenharmony_ci### SIM Card Management<a name="section402mcpsimp"></a> 1737859cbb8Sopenharmony_ci 1747859cbb8Sopenharmony_ciThe function of querying the status of a specified SIM card is used as an example. The process is as follows: 1757859cbb8Sopenharmony_ci 1767859cbb8Sopenharmony_ci1. Set the value of **slotId**. 1777859cbb8Sopenharmony_ci2. Call the **getSimState** method in callback or promise mode to obtain the SIM card status. 1787859cbb8Sopenharmony_ci3. Obtain the SIM card status information. The **getSimState** method works in asynchronous mode. The execution result is returned through the callback. 1797859cbb8Sopenharmony_ci 1807859cbb8Sopenharmony_ci ```js 1817859cbb8Sopenharmony_ci import sim from "@ohos.telephony.sim"; 1827859cbb8Sopenharmony_ci 1837859cbb8Sopenharmony_ci // Set the value of slotId. 1847859cbb8Sopenharmony_ci let slotId = 0; 1857859cbb8Sopenharmony_ci 1867859cbb8Sopenharmony_ci // Call the API in callback mode. 1877859cbb8Sopenharmony_ci sim.getSimState(slotId, (err, value) => { 1887859cbb8Sopenharmony_ci if (err) { 1897859cbb8Sopenharmony_ci // If the API call fails, err is not empty. 1907859cbb8Sopenharmony_ci console.error(`failed to getSimState because ${err.message}`); 1917859cbb8Sopenharmony_ci return; 1927859cbb8Sopenharmony_ci } 1937859cbb8Sopenharmony_ci // If the API call is successful, err is empty. 1947859cbb8Sopenharmony_ci console.log(`success to getSimState: ${value}`); 1957859cbb8Sopenharmony_ci }); 1967859cbb8Sopenharmony_ci 1977859cbb8Sopenharmony_ci // Call the API in promise mode. 1987859cbb8Sopenharmony_ci let promise = sim.getSimState(slotId); 1997859cbb8Sopenharmony_ci promise.then((value) => { 2007859cbb8Sopenharmony_ci // The API call is successful. 2017859cbb8Sopenharmony_ci console.log(`success to getSimState: ${value}`); 2027859cbb8Sopenharmony_ci }).catch((err) => { 2037859cbb8Sopenharmony_ci // The API call fails. 2047859cbb8Sopenharmony_ci console.error(`failed to getSimState because ${err.message}`); 2057859cbb8Sopenharmony_ci }); 2067859cbb8Sopenharmony_ci ``` 2077859cbb8Sopenharmony_ci 2087859cbb8Sopenharmony_ci 2097859cbb8Sopenharmony_ci## Repositories Involved<a name="section409mcpsimp"></a> 2107859cbb8Sopenharmony_ci 2117859cbb8Sopenharmony_ci[Telephony Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/telephony.md) 2127859cbb8Sopenharmony_ci 2137859cbb8Sopenharmony_ci**telephony\_core\_service** 2147859cbb8Sopenharmony_ci 2157859cbb8Sopenharmony_ci[telephony\_sms\_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md) 2167859cbb8Sopenharmony_ci 2177859cbb8Sopenharmony_ci[drivers_interface](https://gitee.com/openharmony/drivers_interface) 2187859cbb8Sopenharmony_ci 2197859cbb8Sopenharmony_ci[drivers_peripheral](https://gitee.com/openharmony/drivers_peripheral) 2207859cbb8Sopenharmony_ci 2217859cbb8Sopenharmony_ci[telephony\_ril\_adapter](https://gitee.com/openharmony/telephony_ril_adapter/blob/master/README.md) 222