• Home
Name Date Size #Lines LOC

..--

figures/12-May-2024-

frameworks/12-May-2024-2,0301,651

interfaces/12-May-2024-987238

sa_profile/12-May-2024-3533

services/12-May-2024-9,6367,654

test/12-May-2024-3,5842,787

BUILD.gnD12-May-20243.5 KiB9691

LICENSED12-May-20249.9 KiB177150

README.mdD12-May-20246.1 KiB156118

README_zh.mdD12-May-20246.3 KiB147110

bundle.jsonD12-May-20242.5 KiB8382

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
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![](figures/en-us_architecture-of-the-cellular-data-module.png)
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

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