• Home
  • History
  • Annotate
Name
Date
Size
#Lines
LOC

..17-Mar-2025-

figures/H17-Mar-2025-

frameworks/H17-Mar-2025-2,4222,060

interfaces/H17-Mar-2025-1,278346

sa_profile/H17-Mar-2025-3533

services/H17-Mar-2025-13,06510,777

test/H17-Mar-2025-9,7357,255

BUILD.gnH A D17-Mar-20254.7 KiB137125

LICENSEH A D17-Mar-20259.9 KiB177150

OAT.xmlH A D17-Mar-20251.3 KiB3011

README.mdH A D17-Mar-20258.2 KiB199152

README_zh.mdH A D17-Mar-20258.3 KiB189144

bundle.jsonH A D17-Mar-20252.7 KiB8685

README.md

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    -   [Check if cellular mobile data service is enabled](#section234mcpsimp)
11    -   [Check if cellular data roaming is enabled](#section255mcpsimp)
12
13-   [Repositories Involved](#section234mcpsimp)
14
15## Introduction<a name="section117mcpsimp"></a>
16
17The 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.
18
19**Figure  1**  Architecture of the cellular data module<a name="fig332493822512"></a>
20![](figures/en-us_architecture-of-the-cellular-data-module.png)
21
22## Directory Structure<a name="section121mcpsimp"></a>
23
24```
25base/telephony/cellular_data/
26├── figures
27├── frameworks
28│   ├── js
29│   │   └── napi
30│   │       ├── include                  #  js head files
31│   │       └── src                      #  js source files
32│   └── native
33├── interfaces                           # externally exposed interface
34│   ├── innerkits
35│   └── kits
36│       └── js
37│           └── declaration              # external JS API interfaces
38├── sa_profile                           # SA profiles
39├── services
40│   ├── include                          # head files
41│   │   ├── apn_manager
42│   │   ├── common
43│   │   ├── state_machine
44│   │   └── utils
45│   └── src                              # source files
46│       ├── apn_manager
47│       ├── state_machine
48│       └── utils
49└── test
50    └── unit_test                        # unit test code
51
52```
53
54## Constraints<a name="section125mcpsimp"></a>
55
56-   Programming language: JavaScript
57-   In terms of software, this module needs to work with the telephony core service \(core\_service\) and RIL Adapter \(call\_manger\).
58-   In terms of hardware, the accommodating device must be equipped with a modem and a SIM card capable of independent cellular communication.
59
60## Available APIs<a name="section131mcpsimp"></a>
61
62**Table  1**  External APIs provided by the cellular data module
63
64<a name="table133mcpsimp"></a>
65
66| API                                                          | Description                                                  | Required Permission              |
67| ------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------------- |
68| function isCellularDataEnabled(callback: AsyncCallback\<boolean>): void; | Checks whether the cellular data is enabled                  | ohos.permission.GET_NETWORK_INFO |
69| function getCellularDataState(callback: AsyncCallback\<DataConnectState>): void; | Obtains the cellular data status.                            | ohos.permission.GET_NETWORK_INFO |
70| function isCellularDataEnabledSync(): boolean;               | Checks if cellular mobile data service is enabled.           | ohos.permission.GET_NETWORK_INFO |
71| function isCellularDataRoamingEnabledSync(slotId: number): boolean; | Checks if cellular data roaming is enabled(The parameter slotId is the SIM card id, 0 represents card one, and 1 represents card two). | ohos.permission.GET_NETWORK_INFO |
72
73
74## Usage Guidelines<a name="section160mcpsimp"></a>
75
76### Checking the Cellular Data Status<a name="section192mcpsimp"></a>
77
781.  Call the  **IsCellularDataEnabled**  method in callback or Promise mode to check whether the cellular data is enabled.
792.  This method works in asynchronous mode. The execution result is returned through the callback.
80
81    ```
82    import data from "@ohos.telephony.data";
83
84    // Call the API in callback mode.
85    data.isCellularDataEnabled((err, value) => {
86      if (err) {
87        // If the API call failed, err is not empty.
88        console.error(`failed to isCellularDataEnabled because ${err.message}`);
89        return;
90      }
91      // If the API call succeeded, err is empty.
92      console.log(`success to isCellularDataEnabled: ${value}`);
93    });
94
95    // Call the API in Promise mode.
96    let promise = data.isCellularDataEnabled();
97    promise.then((value) => {
98      // The API call succeeded.
99      console.log(`success to isCellularDataEnabled: ${value}`);
100    }).catch((err) => {
101      // The API call failed.
102      console.error(`failed to isCellularDataEnabled because ${err.message}`);
103    });
104    ```
105
106### Check if cellular mobile data service is enabled<a name="section234mcpsimp"></a>
107
1081. You can determine if cellular data services are enabled by calling isCellularDataEnabledSync.
109
1102. This interface is synchronous, and the relevant execution results will be returned from isCellularDataEnabledSync.
111
112   ```
113   import data from "@ohos.telephony.data";
114
115   try {
116   	// Call the interface [Sync method]
117   	let isEnabled: boolean = data.isCellularDataEnabledSync();
118   	// Call the interface successfully
119       console.log(`isCellularDataEnabledSync success : ${isEnabled}`);
120   } catch (error) {
121   	// Call the interface failed
122       console.log(`isCellularDataEnabledSync failed`);
123   }
124   ```
125
126### Check if cellular data roaming is enabled<a name="section255mcpsimp"></a>
127
1281. You can determine if cellular data roaming services are enabled by calling isCellularDataRoamingEnabledSync.
129
1302. This interface is synchronous, and the relevant execution results will be returned from isCellularDataRoamingEnabledSync.
131
132   ```
133   import data from "@ohos.telephony.data";
134
135   try {
136   	// Call the interface [Sync method]
137   	let isEnabled: boolean = data.isCellularDataRoamingEnabledSync(0);
138   	// Call the interface successfully
139       console.log(`isCellularDataRoamingEnabledSync success : ${isEnabled}`);
140   } catch (error) {
141   	// Call the interface failed
142       console.log(`isCellularDataRoamingEnabledSync failed`);
143   }
144   ```
145
146### Obtaining the Cellular Data Status<a name="section213mcpsimp"></a>
147
148**Table  2**  Description of DataConnectState enum values
149
150<a name="table21531410101919"></a>
151
152| Name                    | ValueDescription |              |
153| ----------------------- | ---------------- | ------------ |
154| DATA_STATE_UNKNOWN      | -1               | Unknown      |
155| DATA_STATE_DISCONNECTED | 0                | Disconnected |
156| DATA_STATE_CONNECTING   | 1                | Connecting   |
157| DATA_STATE_CONNECTED    | 2                | Connected    |
158| DATA_STATE_SUSPENDED    | 3                | Suspended    |
159
160
1611.  Call the  **getCellularDataState**  method in callback or Promise mode to obtain the cellular data status.
1622.  This method works in asynchronous mode. The execution result is returned through the callback.
163
164    ```
165    import data from "@ohos.telephony.data";
166
167    // Call the API in callback mode.
168    data.getCellularDataState((err, value) => {
169      if (err) {
170        // If the API call failed, err is not empty.
171        console.error(`failed to getCellularDataState because ${err.message}`);
172        return;
173      }
174      // If the API call succeeded, err is empty.
175      console.log(`success to getCellularDataState: ${value}`);
176    });
177
178    // Call the API in Promise mode.
179    let promise = data.getCellularDataState();
180    promise.then((value) => {
181      // The API call succeeded.
182      console.log(`success to getCellularDataState: ${value}`);
183    }).catch((err) => {
184      // The API call failed.
185      console.error(`failed to getCellularDataState because ${err.message}`);
186    });
187    ```
188
189
190## Repositories Involved<a name="section234mcpsimp"></a>
191
192Telephony
193
194telephony_cellular_data
195
196telephony_core_service
197
198telephony_ril_adapter
199

README_zh.md

1# 蜂窝数据<a name="ZH-CN_TOPIC_0000001105538940"></a>
2
3-   [简介](#section117mcpsimp)
4-   [目录](#section121mcpsimp)
5-   [约束](#section125mcpsimp)
6-   [接口说明](#section131mcpsimp)
7-   [使用说明](#section160mcpsimp)
8    -   [获取蜂窝数据开关是否打开](#section192mcpsimp)
9    -   [获取蜂窝数据状态](#section213mcpsimp)
10    - [获取蜂窝移动数据是否启用](#section234mcpsimp)
11
12      [获取蜂窝数据漫游是否启用](#section255mcpsimp)
13
14-   [相关仓](#section234mcpsimp)
15
16## 简介<a name="section117mcpsimp"></a>
17
18蜂窝数据模块作为电话子系统可裁剪部件,依赖于core\_service核心服务、ril\_adapter。 具有蜂窝数据激活、蜂窝数据异常检测与恢复、蜂窝数据状态管理、蜂窝数据开关管理、蜂窝数据漫游管理、APN管理、网络管理交互等功能。
19
20**图 1**  蜂窝数据模块架构图<a name="fig332493822512"></a>
21![](figures/zh-cn_architecture-of-the-cellular-data-module.png)
22
23## 目录<a name="section121mcpsimp"></a>
24
25```
26base/telephony/cellular_data/
27├── figures                              # Readme资源文件
28├── frameworks                           # 框架层目录
29│   ├── js                               # js相关代码
30│   └── native                           # native相关代码
31├── interfaces                           # 接口目录
32│   ├── innerkits                        # 部件间的内部接口
33│   └── kits                             # 对应用提供的接口(例如JS接口)
34├── sa_profile                           # SA配置
35├── services                             # 蜂窝数据服务代码目录
36│   ├── include                          # 蜂窝数据服务头文件目录
37│   └── src                              # 蜂窝数据服务实现代码目录
38│       ├── apn_manager                  # APN管理代码目录
39│       ├── state_machine                # 数据连接状态机代码目录
40│       └── utils                        # 蜂窝数据工具代码目录
41└── test                                 # 蜂窝数据测试代码目录
42    └── unit_test                        # 单元测试相关代码
43```
44
45## 约束<a name="section125mcpsimp"></a>
46
47-   开发语言:Java Script。
48-   软件上,需要与以下服务配合使用:Telephony核心服务(core\_service)、RIL适配(ril\_adapter)。
49-   硬件上,需要搭载的设备支持以下硬件:可以进行独立蜂窝通信的Modem以及SIM卡。
50
51## 接口说明<a name="section131mcpsimp"></a>
52
53**表 1**  蜂窝数据对外提供的接口
54
55<a name="table133mcpsimp"></a>
56
57| 接口名称                                                     | 接口描述                                                     | 所需权限                         |
58| ------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------------- |
59| function isCellularDataEnabled(callback: AsyncCallback\<boolean>): void; | 获取蜂窝数据开关是否打开                                     | ohos.permission.GET_NETWORK_INFO |
60| function getCellularDataState(callback: AsyncCallback\<DataConnectState>): void; | 获取蜂窝数据状态                                             | ohos.permission.GET_NETWORK_INFO |
61| function isCellularDataEnabledSync(): boolean;               | 获取蜂窝移动数据服务是否启用                                 | ohos.permission.GET_NETWORK_INFO |
62| function isCellularDataRoamingEnabledSync(slotId: number): boolean; | 获取蜂窝数据漫游服务是否启用(参数slotId为SIM卡id,0表示卡一,1表示卡二) | ohos.permission.GET_NETWORK_INFO |
63
64完整的JS API说明以及实例代码请参考:[蜂窝数据](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-telephony-kit/js-apis-telephony-data.md)65
66## 使用说明<a name="section160mcpsimp"></a>
67
68### 获取蜂窝数据开关是否打开<a name="section192mcpsimp"></a>
69
701.  可以通过callback或者Promise的方式调用isCellularDataEnabled获取蜂窝数据开关是否打开。
712.  该接口为异步接口,相关执行结果会从callback中返回。
72
73    ```
74    import data from "@ohos.telephony.data";
75
76    // 调用接口【callback方式】
77    data.isCellularDataEnabled((err, value) => {
78      if (err) {
79        // 接口调用失败,err非空
80        console.error(`failed to isCellularDataEnabled because ${err.message}`);
81        return;
82      }
83      // 接口调用成功,err为空
84      console.log(`success to isCellularDataEnabled: ${value}`);
85    });
86
87    // 调用接口【Promise方式】
88    let promise = data.isCellularDataEnabled();
89    promise.then((value) => {
90      // 接口调用成功,此处可以实现成功场景分支代码。
91      console.log(`success to isCellularDataEnabled: ${value}`);
92    }).catch((err) => {
93      // 接口调用失败,此处可以实现失败场景分支代码。
94      console.error(`failed to isCellularDataEnabled because ${err.message}`);
95    });
96    ```
97
98### 获取蜂窝移动数据服务是否启用<a name="section234mcpsimp"></a>
99
1001.  可以通过调用isCellularDataEnabledSync获取蜂窝移动数据服务是否启用。
1012.  该接口为同步接口,相关执行结果会从isCellularDataEnabledSync中返回。
102
103    ```
104    import data from "@ohos.telephony.data";
105
106    try {
107    	// 调用接口【Sync方式】
108    	let isEnabled: boolean = data.isCellularDataEnabledSync();
109    	// 调用接口成功
110        console.log(`isCellularDataEnabledSync success : ${isEnabled}`);
111    } catch (error) {
112    	// 调用接口失败
113        console.log(`isCellularDataEnabledSync failed`);
114    }
115    ```
116
117### 获取蜂窝数据漫游服务是否启用<a name="section255mcpsimp"></a>
118
1191.  可以通过调用isCellularDataRoamingEnabledSync获取蜂窝数据漫游服务是否启用。
1202.  该接口为同步接口,相关执行结果会从isCellularDataRoamingEnabledSync中返回。
121
122    ```
123    import data from "@ohos.telephony.data";
124
125    try {
126    	// 调用接口【Sync方式】
127    	let isEnabled: boolean = data.isCellularDataRoamingEnabledSync(0);
128    	// 调用接口成功
129        console.log(`isCellularDataRoamingEnabledSync success : ${isEnabled}`);
130    } catch (error) {
131    	// 调用接口失败
132        console.log(`isCellularDataRoamingEnabledSync failed`);
133    }
134    ```
135
136### 获取蜂窝数据状态<a name="section213mcpsimp"></a>
137
138**表 2**  DataConnectState枚举值
139
140<a name="table21531410101919"></a>
141
142| 名称                    | 值   | 说明     |
143| ----------------------- | ---- | -------- |
144| DATA_STATE_UNKNOWN      | -1   | 未知     |
145| DATA_STATE_DISCONNECTED | 0    | 连接断开 |
146| DATA_STATE_CONNECTING   | 1    | 连接中   |
147| DATA_STATE_CONNECTED    | 2    | 已连接   |
148| DATA_STATE_SUSPENDED    | 3    | 已挂起   |
149
150
1511.  可以通过callback或者Promise的方式调用getCellularDataState获取蜂窝数据状态。
1522.  该接口为异步接口,相关执行结果会从callback中返回。
153
154    ```
155    import data from "@ohos.telephony.data";
156
157    // 调用接口【callback方式】
158    data.getCellularDataState((err, value) => {
159      if (err) {
160        // 接口调用失败,err非空
161        console.error(`failed to getCellularDataState because ${err.message}`);
162        return;
163      }
164      // 接口调用成功,err为空
165      console.log(`success to getCellularDataState: ${value}`);
166    });
167
168    // 调用接口【Promise方式】
169    let promise = data.getCellularDataState();
170    promise.then((value) => {
171      // 接口调用成功,此处可以实现成功场景分支代码。
172      console.log(`success to getCellularDataState: ${value}`);
173    }).catch((err) => {
174      // 接口调用失败,此处可以实现失败场景分支代码。
175      console.error(`failed to getCellularDataState because ${err.message}`);
176    });
177    ```
178
179## 相关仓<a name="section234mcpsimp"></a>
180
181[电话服务子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/电话服务子系统.md)
182
183telephony_cellular_data
184
185[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README_zh.md)
186
187[telephony_ril_adapter](https://gitee.com/openharmony/telephony_ril_adapter/blob/master/README_zh.md)
188
189