1# Cellular Data<a name="EN-US_TOPIC_0000001105538940"></a> 2 3- [Introduction](#section117mcpsimp) 4- [Directory Structure](#section121mcpsimp) 5- [Constraints](#section125mcpsimp) 6- [Available APIs](#section131mcpsimp) 7- [Usage Guidelines](#section160mcpsimp) 8 - [Checking the Cellular Data Status](#section192mcpsimp) 9 - [Obtaining the Cellular Data Status](#section213mcpsimp) 10 11- [Repositories Involved](#section234mcpsimp) 12 13## Introduction<a name="section117mcpsimp"></a> 14 15The cellular data module is a tailorable component of the Telephony subsystem. It depends on the telephony core service \(core\_service\) and RIL Adapter \(ril\_adapter\). The module provides functions such as cellular data activation, cellular data fault detection and rectification, cellular data status management, cellular data switch management, cellular data roaming management, APN management, and network management and interaction. 16 17**Figure 1** Architecture of the cellular data module<a name="fig332493822512"></a> 18 19 20## Directory Structure<a name="section121mcpsimp"></a> 21 22``` 23base/telephony/cellular_data/ 24├── figures 25├── frameworks 26│ ├── js 27│ │ └── napi 28│ │ ├── include # js head files 29│ │ └── src # js source files 30│ └── native 31├── interfaces # externally exposed interface 32│ ├── innerkits 33│ └── kits 34│ └── js 35│ └── declaration # external JS API interfaces 36├── sa_profile # SA profiles 37├── services 38│ ├── include # head files 39│ │ ├── apn_manager 40│ │ ├── common 41│ │ ├── state_machine 42│ │ └── utils 43│ └── src # source files 44│ ├── apn_manager 45│ ├── state_machine 46│ └── utils 47└── test 48 └── unit_test # unit test code 49 50``` 51 52## Constraints<a name="section125mcpsimp"></a> 53 54- Programming language: JavaScript 55- In terms of software, this module needs to work with the telephony core service \(core\_service\) and RIL Adapter \(call\_manger\). 56- In terms of hardware, the accommodating device must be equipped with a modem and a SIM card capable of independent cellular communication. 57 58## Available APIs<a name="section131mcpsimp"></a> 59 60**Table 1** External APIs provided by the cellular data module 61 62<a name="table133mcpsimp"></a> 63 64| API | Description | Required Permission | 65| ------------------------------------------------------------ | ------------------------------------------- | -------------------------------- | 66| function isCellularDataEnabled(callback: AsyncCallback\<boolean>): void; | Checks whether the cellular data is enabled | ohos.permission.GET_NETWORK_INFO | 67| function getCellularDataState(callback: AsyncCallback\<DataConnectState>): void; | Obtains the cellular data status. | ohos.permission.GET_NETWORK_INFO | 68 69 70## Usage Guidelines<a name="section160mcpsimp"></a> 71 72### Checking the Cellular Data Status<a name="section192mcpsimp"></a> 73 741. Call the **IsCellularDataEnabled** method in callback or Promise mode to check whether the cellular data is enabled. 752. This method works in asynchronous mode. The execution result is returned through the callback. 76 77 ``` 78 import data from "@ohos.telephony.data"; 79 80 // Call the API in callback mode. 81 data.isCellularDataEnabled((err, value) => { 82 if (err) { 83 // If the API call failed, err is not empty. 84 console.error(`failed to isCellularDataEnabled because ${err.message}`); 85 return; 86 } 87 // If the API call succeeded, err is empty. 88 console.log(`success to isCellularDataEnabled: ${value}`); 89 }); 90 91 // Call the API in Promise mode. 92 let promise = data.isCellularDataEnabled(); 93 promise.then((value) => { 94 // The API call succeeded. 95 console.log(`success to isCellularDataEnabled: ${value}`); 96 }).catch((err) => { 97 // The API call failed. 98 console.error(`failed to isCellularDataEnabled because ${err.message}`); 99 }); 100 ``` 101 102 103### Obtaining the Cellular Data Status<a name="section213mcpsimp"></a> 104 105**Table 2** Description of DataConnectState enum values 106 107<a name="table21531410101919"></a> 108 109| Name | ValueDescription | | 110| ----------------------- | ---------------- | ------------ | 111| DATA_STATE_UNKNOWN | -1 | Unknown | 112| DATA_STATE_DISCONNECTED | 0 | Disconnected | 113| DATA_STATE_CONNECTING | 1 | Connecting | 114| DATA_STATE_CONNECTED | 2 | Connected | 115| DATA_STATE_SUSPENDED | 3 | Suspended | 116 117 1181. Call the **getCellularDataState** method in callback or Promise mode to obtain the cellular data status. 1192. This method works in asynchronous mode. The execution result is returned through the callback. 120 121 ``` 122 import data from "@ohos.telephony.data"; 123 124 // Call the API in callback mode. 125 data.getCellularDataState((err, value) => { 126 if (err) { 127 // If the API call failed, err is not empty. 128 console.error(`failed to getCellularDataState because ${err.message}`); 129 return; 130 } 131 // If the API call succeeded, err is empty. 132 console.log(`success to getCellularDataState: ${value}`); 133 }); 134 135 // Call the API in Promise mode. 136 let promise = data.getCellularDataState(); 137 promise.then((value) => { 138 // The API call succeeded. 139 console.log(`success to getCellularDataState: ${value}`); 140 }).catch((err) => { 141 // The API call failed. 142 console.error(`failed to getCellularDataState because ${err.message}`); 143 }); 144 ``` 145 146 147## Repositories Involved<a name="section234mcpsimp"></a> 148 149Telephony 150 151telephony_cellular_data 152 153telephony_core_service 154 155telephony_ril_adapter 156