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 - [APIs for the SIM Card Service](#section142mcpsimp) 8 - [APIs for the Network Search Service](#section198mcpsimp) 9 10- [Usage Guidelines](#section370mcpsimp) 11 - [Network Search](#section393mcpsimp) 12 - [SIM Card](#section402mcpsimp) 13 14- [Repositories Involved](#section409mcpsimp) 15 16## Introduction<a name="section117mcpsimp"></a> 17 18The telephony core service initializes the RIL Manager, SIM card module, and network search module, 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 SIM card service, network search service, and RIL Manager service. 28 29- SIM card service: 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- Network search service: Provides services including network registration and network status acquisition. These services offer functions such as network registration, network mode query, radio status query, network search management, signal strength query, cell management, registration status management, and time and time zone setting. 31- RIL Manager service: Provides the proactive callback service and query result callback service. 32 33## Directory Structure<a name="section129mcpsimp"></a> 34 35```shell 36/base/telphony/core_service 37├── figures # Resource of Readme 38├── frameworks # Framework Level Directory 39│ ├── js 40│ └── native 41├── interfaces # APIs 42│ ├── innerkits # Internal APIs 43│ └── kits # External APIs (such as JS APIs) 44├── sa_profile # Core service startup file directory 45├── services # Implementation of the telephony core service 46│ ├── etc # Driver script directory for core services 47│ ├── include 48│ ├── network_search # Search Network Service Code Directory 49│ ├── sim # SIM card service code directory 50│ ├── src 51│ └── tel_ril # Core service and RIL Adapter communication code directory 52├── test # Unit test related code 53│ └── unittest 54└── utils 55 ├── common # Core service log print directory 56 ├── log 57 └── preferences 58``` 59 60## Constraints<a name="section133mcpsimp"></a> 61 62- Programming language: C++、JavaScript 63- In terms of software, this module needs to work with the RIL adapter service \(ril\_adapter\) and status registration service \(state\_registry\). 64- In terms of hardware, the accommodating device must be equipped with a modem and a SIM card capable of independent cellular communication. 65 66## Available APIs<a name="section139mcpsimp"></a> 67 68The telephony core service module needs to provide APIs for related modules, including the SIM card, network search modules. 69 70### APIs for the SIM Card Service<a name="section142mcpsimp"></a> 71 72| Interface name | Interface description | Required permissions | 73| ------------------------------------------------------------ | ----------------------------------------------------------- | ----------------------------------- | 74| function getSimState(slotId: number, callback: AsyncCallback\<SimState>): void; | Get the SIM card status of the specified slot | None | 75| function getSimGid1(slotId: number, callback: AsyncCallback\<string>): void; | Get the GID1 of the SIM card in the specified slot (Group Identifier Level 1) | ohos.permission.GET_TELEPHONY_STATE | 76| function getSimIccId(slotId: number, callback: AsyncCallback\<string>): void; | Get the ICCID (Integrate Circuit Card Identity) of the SIM card in the specified slot | ohos.permission.GET_TELEPHONY_STATE | 77| function getISOCountryCodeForSim(slotId: number, callback: AsyncCallback\<string>): void; | Get the ISO country code of the SIM card in the specified slot | None | 78| function getSimOperatorNumeric(slotId: number, callback: AsyncCallback\<string>): void; | Get the PLMN (Public Land Mobile Network) number of the SIM card in the specified slot | None | 79| function getSimSpn(slotId: number, callback: AsyncCallback\<string>): void; | Get the SPN (Service Provider Name) of the SIM card of the specified slot | None | 80| function getDefaultVoiceSlotId(callback: AsyncCallback\<number>): void; | Get the default card slot of the voice service | None | 81| function isSimActive(slotId: number, callback: AsyncCallback\<boolean>): void | Check whether the SIM card in the specified slot is activated | None | 82| function hasSimCard(slotId: number, callback: AsyncCallback\<boolean>): void | Check whether the SIM card is inserted into the specified card slot | None | 83| function getSimTelephoneNumber(slotId: number, callback: AsyncCallback\<string>): void | Get the MSISDN (Mobile Station Integrated Services Digital Network) of the SIM card in the specified slot|ohos.permission.GET_TELEPHONY_STATE | 84| function getVoiceMailIdentifier(slotId: number, callback: AsyncCallback\<string>): void | Get the voicemail identification of the SIM card in the specified slot | ohos.permission.GET_TELEPHONY_STATE | ohos.permission.GET_TELEPHONY_STATE | 85| function getVoiceMailNumber(slotId: number, callback: AsyncCallback\<string>): void | Get the voice mailbox number of the SIM card in the specified slot | ohos.permission.GET_TELEPHONY_STATE | 86| function getCardType(slotId: number, callback: AsyncCallback\<CardType>): void | Check whether the application (caller) has been granted operator privileges | None | 87| function hasOperatorPrivileges(slotId: number, callback: AsyncCallback\<boolean>): void | Get the type of SIM card in the specified slot | None | 88| function getMaxSimCount(): number | Get the maximum number of SIM cards that can be used simultaneously on the device, that is, the maximum number of SIM card slots. | None | 89| function getPrimarySlotId(callback: AsyncCallback\<number>): void | Get the default primary slot ID | None | 90 91 92### APIs for the Network Search Service<a name="section198mcpsimp"></a> 93 94| Interface name | Interface description | Required permissions | 95| ------------------------------------------------------------ | ----------------------------------------------------------- | ----------------------------------- | 96| function getRadioTech(slotId: number, callback: AsyncCallback\<{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology}>): void; | Get the current access technology of the specified card slot | ohos.permission.GET_NETWORK_INFO | 97| function getSignalInformation(slotId: number, callback: AsyncCallback\<Array\<SignalInformation>>): void; | Get the signal list of the specified card slot | None | 98| function getNetworkState(slotId: number, callback: AsyncCallback\<NetworkState>): void; | Get the network status of the specified card slot | ohos.permission.GET_NETWORK_INFO | 99| function getISOCountryCodeForNetwork(slotId: number, callback: AsyncCallback\<string>): void; | Get the network country code of the specified card slot | None | 100| function getNetworkSearchInformation(slotId: number, callback: AsyncCallback\<NetworkSearchResult>): void; | Get the manual search results of the specified card slot | ohos.permission.GET_TELEPHONY_STATE | 101| function getNetworkSelectionMode(slotId: number, callback: AsyncCallback\<NetworkSelectionMode>): void; | Get the network selection mode of the specified card slot | None | 102| function setNetworkSelectionMode(options: NetworkSelectionModeOptions, callback: AsyncCallback\<void>): void; | Set the network selection mode of the specified card slot | ohos.permission.SET_TELEPHONY_STATE | 103| function isRadioOn(callback: AsyncCallback\<boolean>): void; | Determine whether Radio is turned on | ohos.permission.GET_NETWORK_INFO | 104| function turnOnRadio(callback: AsyncCallback\<void>): void; | Turn on Radio | ohos.permission.SET_TELEPHONY_STATE | 105| function turnOffRadio(callback: AsyncCallback\<void>): void; | Turn off Radio | ohos.permission.SET_TELEPHONY_STATE | 106| function getOperatorName(slotId: number, callback: AsyncCallback\<string>): void; | Get the operator name of the specified card slot | None | 107| function setPreferredNetwork(slotId: number, networkMode: PreferredNetworkMode, callback: AsyncCallback\<void>): void; | Set the preferred network mode of the specified card slot | None | 108| function getPreferredNetwork(slotId: number, callback: AsyncCallback\<PreferredNetworkMode>): void; | Get the preferred network mode of the specified card slot | None | 109| function getCellInformation(slotId: number, callback: AsyncCallback<Array\<CellInformation>>) | Get cell information list | ohos.permission.LOCATION | 110| function sendUpdateCellLocationRequest(callback: AsyncCallback\<void>) | Request cell location | ohos.permission.LOCATION | 111| function getIMEI(slotId: number, callback: AsyncCallback\<string>) | Get Imei | ohos.permission.GET_TELEPHONY_STATE | 112| function getMeId(slotId: number, callback: AsyncCallback\<string>) | Get Meid | ohos.permission.GET_TELEPHONY_STATE | 113| function getUniqueDeviceId(slotId: number, callback: AsyncCallback\<string>) | Get the unique identification code of the device | ohos.permission.GET_TELEPHONY_STATE | 114| function getNrOptionMode(slotId: number, callback: AsyncCallback\<NrOptionMode>) | Get 5G mode | ohos.permission.GET_TELEPHONY_STATE | 115| function isNrSupported: boolean; | Whether to support 5g network | None | 116 117>**NOTE:** 118>The RIL Manager does not provide external APIs and can only be called by modules of the Telephony subsystem. 119 120## Usage Guidelines<a name="section370mcpsimp"></a> 121 122### Network Search<a name="section393mcpsimp"></a> 123 124The function of obtaining the network status is used as an example. The process is as follows: 125 1261. Query the SIM card in the slot specified by **slotId**. If **slotId** is not set, information about the primary card is queried by default. 1272. Call the **GetNetworkStatus** method in callback or Promise mode. 1283. Obtain the network status information. The **GetNetworkStatus** method works in asynchronous mode. The execution result is returned through the callback. 129 130 ```js 131 import radio from "@ohos.telephony.radio"; 132 133 // Set the value of slotId. 134 let slotId = 0; 135 136 // Call the API in callback mode. 137 radio.GetNetworkStatus(slotId, (err, value) => { 138 if (err) { 139 // If the API call failed, err is not empty. 140 console.error(`failed to GetNetworkStatus because ${err.message}`); 141 return; 142 } 143 // If the API call succeeded, err is empty. 144 console.log(`success to GetNetworkStatus: ${value}`); 145 }); 146 147 // Call the API in Promise mode. 148 let promise = radio.GetNetworkStatus(slotId); 149 promise.then((value) => { 150 // The API call succeeded. 151 console.log(`success to GetNetworkStatus: ${value}`); 152 }).catch((err) => { 153 // The API call failed. 154 console.error(`failed to GetNetworkStatus because ${err.message}`); 155 }); 156 ``` 157 158 159### SIM Card<a name="section402mcpsimp"></a> 160 161The function of querying the status of a specified SIM card is used as an example. The process is as follows: 162 1631. Set the value of **slotId**. 1642. Call the **getSimState** method in callback or Promise mode to obtain the SIM card status information. 1653. This method works in asynchronous mode. The execution result is returned through the callback. 166 167 ```js 168 import sim from "@ohos.telephony.sim"; 169 170 // Set the value of slotId. 171 let slotId = 0; 172 173 // Call the API in callback mode. 174 sim.getSimState(slotId, (err, value) => { 175 if (err) { 176 // If the API call failed, err is not empty. 177 console.error(`failed to getSimState because ${err.message}`); 178 return; 179 } 180 // If the API call succeeded, err is empty. 181 console.log(`success to getSimState: ${value}`); 182 }); 183 184 // Call the API in Promise mode. 185 let promise = sim.getSimState(slotId); 186 promise.then((value) => { 187 // The API call succeeded. 188 console.log(`success to getSimState: ${value}`); 189 }).catch((err) => { 190 // The API call failed. 191 console.error(`failed to getSimState because ${err.message}`); 192 }); 193 ``` 194 195 196## Repositories Involved<a name="section409mcpsimp"></a> 197 198[Telephony](https://gitee.com/openharmony/docs/blob/master/en/readme/telephony.md) 199 200**telephony_core_service** 201 202[telephony_sms_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md)