• Home
Name Date Size #Lines LOC

..--

common/12-May-2024-1,273978

config/12-May-2024-8079

figures/12-May-2024-

opkey/12-May-2024-701492

pdp_profile/12-May-2024-799580

signature/12-May-2024-

sim/12-May-2024-821585

sms_mms/12-May-2024-1,006746

test/12-May-2024-1,2911,037

BUILD.gnD12-May-20242.8 KiB8174

LICENSED12-May-20249.9 KiB177150

README.mdD12-May-20249.7 KiB241188

README_zh.mdD12-May-20249.4 KiB239186

bundle.jsonD12-May-20241.7 KiB6463

data_storage_ability_runtime.gniD12-May-2024802 1715

README.md

1# Data Storage<a name="EN-US_TOPIC_0000001152064139"></a>
2
3-   [Introduction](#section117mcpsimp)
4-   [Directory Structure](#section124mcpsimp)
5-   [Constraints](#section128mcpsimp)
6-   [Usage](#section134mcpsimp)
7    -   [Available APIs](#section136mcpsimp)
8    -   [Permissions]( #section137mcpsimp)
9
10-   [Usage Guidelines](#section163mcpsimp)
11    -   [Parameters of the Insert API](#section1099113151207)
12    -   [Parameters of the Delete API](#section1098113151208)
13    -   [Parameters of the Update API](#section1099113151207)
14    -   [Parameters of the Query API](#section1096113151208)
15    -   [Sample Code](#section1558565082915)
16
17-   [Repositories Involved](#section206mcpsimp)
18
19## Introduction<a name="section117mcpsimp"></a>
20
21The data storage module stores persistent data of key modules of the Telephony subsystem, such as the SIM cards and SMS modules, and provides the **DataAbility** API for data access.
22
23**Figure 1** Architecture of the data storage module<a name="fig13267152558"></a>
24
25![](figures/en-us_architecture-of-the-data-storage-module.png)
26
27## Directory Structure<a name="section124mcpsimp"></a>
28
29```
30/base/telephony/data_storage     # Data storage
31├─ BUILD.gn                         # Build script (gn)
32├─ README.md                        # Readme
33├─ common                           # Public and common files
34│  ├─ include
35│  └─ src
36├─ opkey                            # opkey framework
37│  ├─ include
38│  └─ src
39├─ pdp_profile                      # Network carrier
40│  ├─ include
41│  └─ src
42├─ sim                              # SIM card
43│  ├─ include
44│  └─ src
45├─ sms_mms                          # SMS/MMS
46│  ├─ include
47│  └─ src
48├─ ohos.build                       # Build code
49└─ test                             # Test code
50```
51
52## Constraints<a name="section128mcpsimp"></a>
53
54- Programming language: C++
55
56- Software constraints: This module must work with the Utils and Application Framework subsystems.
57
58- Hardware constraints: none
59
60- Use case: When a user needs to edit the persistent data stored in Telephony subsystem modules, such as the SIM card and SMS/MMS modules, your application can call the **Insert**, **Delete**, **Update**, and **Query** APIs provided by **DataAbilityHelper** as demanded.
61
62  You need to declare the corresponding permission for access to the specified URI.
63
64## Usage<a name="section134mcpsimp"></a>
65
66### Available APIs<a name="section136mcpsimp"></a>
67
68**Table 1** APIs provided by DataAbilityHelper
69
70<a name="table165976561598"></a>
71
72| API Definition                                                    | **Description**|
73| ------------------------------------------------------------ | ------------ |
74| int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) | Inserts data.     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
75| int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) | Deletes data.     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
76| int Update( const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates) | Updates data.     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
77| std::shared_ptr\<NativeRdb::AbsSharedResultSet\> Query( const Uri &uri, const std::vector\<std::string\> &columns, const NativeRdb::DataAbilityPredicates &predicates) | Queries data.     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
78
79**Table 2** Required permissions
80
81<a name="table165976561598"></a>
82
83| Module          | **Required Permission**                                                |
84| -------------- | ------------------------------------------------------------ |
85| SMS/MMS module    | ohos.permission.READ_MESSAGES                                |
86| SIM card module     | ohos.permission.GET_TELEPHONY_STATE<br>ohos.permission.SET_TELEPHONY_STATE |
87| Network carrier module| ohos.permission.GET_TELEPHONY_STATE<br>ohos.permission.SET_TELEPHONY_STATE |
88| opkey module| ohos.permission.GET_TELEPHONY_STATE<br>ohos.permission.SET_TELEPHONY_STATE |
89
90## Usage Guidelines<a name="section163mcpsimp"></a>
91
92### Parameters of the Insert API<a name="section1099113151207"></a>
93
94**Table 3** Parameters of the Insert API
95
96<a name="table1234838197"></a>
97
98| Parameter | **Description**                             |
99| ----- | ------------------------------------- |
100| uri   | Resource path.                             |
101| value | Data set. This field corresponds to the table structure field on which the current operation is performed.|
102
103### Parameters of the Delete API<a name="section1098113151208"></a>
104
105**Table 4** Parameters of the Delete API
106
107<a name="table1234838197"></a>
108
109| Parameter      | Description                                 |
110| ---------- | ------------------------------------- |
111| uri        | Resource path.                             |
112| value      | Data set. This field corresponds to the table structure field on which the current operation is performed.|
113| predicates | Conditions for data deletion.                             |
114
115### Parameters of the Update API<a name="section1097113151210"></a>
116
117**Table 5** Parameters of the Update API
118
119<a name="table1234838197"></a>
120
121| Parameter      | Description    |
122| ---------- | -------- |
123| uri        | Resource path.|
124| predicates | Conditions for data updating.|
125
126### Parameters of the Query API<a name="section1096113151208"></a>
127
128**Table 6** Parameters of the Query API
129
130<a name="table1234838197"></a>
131
132| Parameter      | Description          |
133| ---------- | -------------- |
134| uri        | Resource path.      |
135| columns    | Fields in the query result.|
136| predicates | Conditions for data query.      |
137
138### Sample Code<a name="section1558565082915"></a>
139
140The following provides the procedure and sample code for you to query, insert, delete, or update SMS/MMS data:
141
1421. Call **SystemAbilityManagerClient** to obtain a **SystemAbilityManager** object.
1432. Call **saManager** to obtain an **IRemoteObject** object based on the specified service ID.
1443. Call **IRemoteObject** to create a **DataAbilityHelper** object.
1454. Call **DataAbilityHelper::Query** to query data, and call the other related APIs to process data.
146
147   Sample code for creating a **DataAbilityHelper** instance:
148   ```
149   std::shared_ptr<AppExecFwk::DataAbilityHelper> CreateDataAHelper(int32_t systemAbilityId)
150   {
151       // Obtain a SystemAbilityManager instance through SystemAbilityManagerClient.
152       auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
153       if (saManager == nullptr) {
154           DATA_STORAGE_LOGE("DataSimRdbHelper Get system ability mgr failed.");
155           return nullptr;
156       }
157       // Obtain an IRemoteObject.
158       auto remoteObj = saManager->GetSystemAbility(systemAbilityId);
159       while (remoteObj == nullptr) {
160           DATA_STORAGE_LOGE("DataSimRdbHelper GetSystemAbility Service Failed.");
161           return nullptr;
162       }
163       // Create a DataAbilityHelper instance.
164       return AppExecFwk::DataAbilityHelper::Creator(remoteObj);
165   }
166   ```
167   Sample code for querying SMS/MMS messages:
168   ```
169   std::shared_ptr<NativeRdb::AbsSharedResultSet> SmsSelect(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
170   {
171       // Resource path
172       Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
173       // Fields in the query result
174       std::vector<std::string> colume;
175       // Phone number of the message sender
176       colume.push_back("sender_number");
177       // Message title
178       colume.push_back("msg_title");
179       // Message content
180       colume.push_back("msg_content");
181       // Query predicates
182       NativeRdb::DataAbilityPredicates predicates;
183       // Call the DataAbilityHelper::Query API to query data.
184       return helper->Query(uri, colume, predicates);
185   }
186   ```
187   Sample code for inserting SMS/MMS messages:
188   ```
189   int SmsInsert(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
190   {
191       Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
192       NativeRdb::ValuesBucket value;
193       // Phone number of the message recipient
194       value.PutString(SmsMmsInfo::RECEIVER_NUMBER, "138XXXXXXXX");
195       // Message content
196       value.PutString(SmsMmsInfo::MSG_CONTENT, "ceshi");
197       value.PutInt(SmsMmsInfo::GROUP_ID, 1);
198       return helper->Insert(uri, value);
199   }
200   ```
201   Sample code for deleting SMS/MMS messages:
202   ```
203    int SmsDelete(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
204    {
205        Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
206        NativeRdb::DataAbilityPredicates predicates;
207        // Delete the message whose MSG_ID is 1.
208        predicates.EqualTo(SmsMmsInfo::MSG_ID, "1");
209        return helper->Delete(uri, predicates);
210    }
211   ```
212   Sample code for updating SMS/MMS messages:
213   ```
214   int SmsUpdate(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
215   {
216       Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
217       NativeRdb::ValuesBucket values;
218       // Message content
219       values.PutString(SmsMmsInfo::MSG_CONTENT, "hi ohos");
220       NativeRdb::DataAbilityPredicates predicates;
221       // Message ID
222       predicates.EqualTo(SmsMmsInfo::MSG_ID, "1");
223       return helper->Update(uri, values, predicates);
224   }
225   ```
226
227
228## Repositories Involved<a name="section206mcpsimp"></a>
229
230[Telephony Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/%E7%94%B5%E8%AF%9D%E6%9C%8D%E5%8A%A1%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
231
232**telephony_data_storage**
233
234[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README.md)
235
236[telephony_sms_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README.md)
237
238[telephony_cellular_call](https://gitee.com/openharmony/telephony_cellular_call/blob/master/README.md)
239
240[telephony_call_manager](https://gitee.com/openharmony/telephony_call_manager/blob/master/README.md)
241

README_zh.md

1# 数据库及持久化<a name="ZH-CN_TOPIC_0000001152064139"></a>
2
3-   [简介](#section117mcpsimp)
4-   [目录](#section124mcpsimp)
5-   [约束](#section128mcpsimp)
6-   [接口说明](#section136mcpsimp)
7
8-   [使用说明](#section163mcpsimp)
9    -   [插入接口参数说明](#section1099113151207)
10    -   [删除接口参数说明](#section1098113151208)
11    -   [更新接口参数说明](#section1099113151207)
12    -   [查询接口参数说明](#section1096113151208)
13    -   [接口调用代码示例](#section1558565082915)
14
15-   [相关仓](#section206mcpsimp)
16
17## 简介<a name="section117mcpsimp"></a>
18
19数据库及持久化模块负责电话服务子系统中的SIM卡/短彩信等模块持久化数据存储,提供DataAbility访问接口。
20
21**图 1**  数据库及持久化架构图<a name="fig13267152558"></a>
22
23![](figures/zh-cn_architecture-of-the-data-storage-module.png)
24
25## 目录<a name="section124mcpsimp"></a>
26
27```
28/base/telephony/data_storage     # 数据库及持久化
29├─ common                           # 通用文件
30│  ├─ include                      # 头文件目录
31│  └─ src                          # 实现代码目录
32├─ config                           # config.json配置文件
33├─ figures                          # Readme资源文件
34├─ opkey                            # 随卡框架
35│  ├─ include                  # 头文件目录
36│  └─ src                    # 实现代码目录
37├─ pdp_profile                      # 网络运营商
38│  ├─ include                      # 头文件目录
39│  └─ src                          # 实现代码目录
40├─ signature                        # 签名文件
41├─ sim                              # sim卡
42│  ├─ include                      # 头文件目录
43│  └─ src                          # 实现代码目录
44├─ sms_mms                          # 短彩信
45│  ├─ include                      # 头文件目录
46│  └─ src                          # 实现代码目录
47└─ test                             # 测试相关
48   └── unit_test                   # 单元测试相关代码
49```
50
51## 约束<a name="section128mcpsimp"></a>
52
53- 开发语言:C++
54
55- 软件约束:需要与以下服务配合使用:公共基础子库系统,应用框架子系统。
56
57- 硬件约束:无
58
59- 使用场景:当用户需要获取电话服务子系统中的SIM卡/短彩信等模块持久化数据时,可通过DataAbilityHelper提供的增/删/改/查接口来获取数据。
60
61  访问时需要提供对应的权限和URI。
62
63### 接口说明<a name="section136mcpsimp"></a>
64
65**表 1**  增/删/改/查接口
66
67<a name="table165976561598"></a>
68
69| 接口定义                                                     | **接口描述** |
70| ------------------------------------------------------------ | ------------ |
71| int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) | 插入数据     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
72| int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) | 删除数据     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
73| int Update( const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates) | 更新数据     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
74| std::shared_ptr\<NativeRdb::AbsSharedResultSet\> Query( const Uri &uri, const std::vector\<std::string\> &columns, const NativeRdb::DataAbilityPredicates &predicates) | 查询数据     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
75
76**表 2**  权限说明
77
78<a name="table165976561598"></a>
79
80| 模块           | **所需权限**                                                 |
81| -------------- | ------------------------------------------------------------ |
82| 短彩信模块     | ohos.permission.READ_MESSAGES                                |
83| SIM卡模块      | ohos.permission.GET_TELEPHONY_STATE<br />ohos.permission.SET_TELEPHONY_STATE |
84| 网络运营商模块 | ohos.permission.GET_TELEPHONY_STATE<br />ohos.permission.SET_TELEPHONY_STATE |
85| 随卡框架模块 | ohos.permission.GET_TELEPHONY_STATE<br />ohos.permission.SET_TELEPHONY_STATE |
86
87## 使用说明<a name="section163mcpsimp"></a>
88
89### 插入接口参数说明<a name="section1099113151207"></a>
90
91**表 3**  Insert接口参数说明
92
93<a name="table1234838197"></a>
94
95| 参数  | **说明**                              |
96| ----- | ------------------------------------- |
97| uri   | 资源路径                              |
98| value | 数据集合,字段对应当前操作的表结构字段 |
99
100### 删除接口参数说明<a name="section1098113151208"></a>
101
102**表 4**  Delete接口参数说明
103
104<a name="table1234838197"></a>
105
106| 参数       | 说明                                  |
107| ---------- | ------------------------------------- |
108| uri        | 资源路径                              |
109| value      | 数据集合,字段对应当前操作的表结构字段 |
110| predicates | 删除条件                              |
111
112### 更新接口参数说明<a name="section1097113151210"></a>
113
114**表 5**  Update接口参数说明
115
116<a name="table1234838197"></a>
117
118| 参数       | 说明     |
119| ---------- | -------- |
120| uri        | 资源路径 |
121| predicates | 更新条件 |
122
123### 查询接口参数说明<a name="section1096113151208"></a>
124
125**表 6**  Query接口参数说明
126
127<a name="table1234838197"></a>
128
129| 参数       | 说明           |
130| ---------- | -------------- |
131| uri        | 资源路径       |
132| columns    | 查询返回的字段 |
133| predicates | 查询条件       |
134
135### 接口调用代码示例<a name="section1558565082915"></a>
136
137以查询/插入/删除/更新短彩信数据为例,主要步骤和代码如下:
138
1391. 使用SystemAbilityManagerClient获得SystemAbilityManager对象。
1402. 使用saManager获得指定服务Id的IRemoteObject对象。
1413. 使用IRemoteObject创建DataAbilityHelper对象。
1424. 调用DataAbilityHelper::Query接口访问,并接收处理返回的数据。
143
144   创建DataAbilityHelper:
145   ```
146   std::shared_ptr<AppExecFwk::DataAbilityHelper> CreateDataAHelper(int32_t systemAbilityId)
147   {
148       //通过SystemAbilityManagerClient获得SystemAbilityManager
149       auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
150       if (saManager == nullptr) {
151           DATA_STORAGE_LOGE("DataSimRdbHelper Get system ability mgr failed.");
152           return nullptr;
153       }
154       // 获得IRemoteObject
155       auto remoteObj = saManager->GetSystemAbility(systemAbilityId);
156       while (remoteObj == nullptr) {
157           DATA_STORAGE_LOGE("DataSimRdbHelper GetSystemAbility Service Failed.");
158           return nullptr;
159       }
160       // 创建DataAbilityHelper
161       return AppExecFwk::DataAbilityHelper::Creator(remoteObj);
162   }
163   ```
164   查询短彩信信息:
165   ```
166   std::shared_ptr<NativeRdb::AbsSharedResultSet> SmsSelect(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
167   {
168       // 资源路径
169       Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
170       //查询返回的字段
171       std::vector<std::string> colume;
172       // 发送者号码
173       colume.push_back("sender_number");
174       // 消息标题
175       colume.push_back("msg_title");
176       // 消息内容
177       colume.push_back("msg_content");
178       // 查询谓词
179       NativeRdb::DataAbilityPredicates predicates;
180       // 调用DataAbilityHelper::Query接口查询
181       return helper->Query(uri, colume, predicates);
182   }
183   ```
184   插入短彩信信息:
185   ```
186   int SmsInsert(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
187   {
188       Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
189       NativeRdb::ValuesBucket value;
190       // 接收者号码
191       value.PutString(SmsMmsInfo::RECEIVER_NUMBER, "138XXXXXXXX");
192       // 消息内容
193       value.PutString(SmsMmsInfo::MSG_CONTENT, "ceshi");
194       value.PutInt(SmsMmsInfo::GROUP_ID, 1);
195       return helper->Insert(uri, value);
196   }
197   ```
198   删除短彩信信息:
199   ```
200    int SmsDelete(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
201    {
202        Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
203        NativeRdb::DataAbilityPredicates predicates;
204        // 删除MSG_ID为1的信息
205        predicates.EqualTo(SmsMmsInfo::MSG_ID, "1");
206        return helper->Delete(uri, predicates);
207    }
208   ```
209   更新短彩信信息:
210   ```
211   int SmsUpdate(std::shared_ptr<AppExecFwk::DataAbilityHelper> helper)
212   {
213       Uri uri("dataability:///com.ohos.smsmmsability/sms_mms/sms_mms_info");
214       NativeRdb::ValuesBucket values;
215       // 信息内容
216       values.PutString(SmsMmsInfo::MSG_CONTENT, "hi ohos");
217       NativeRdb::DataAbilityPredicates predicates;
218       // 信息Id
219       predicates.EqualTo(SmsMmsInfo::MSG_ID, "1");
220       return helper->Update(uri, values, predicates);
221   }
222   ```
223
224
225## 相关仓<a name="section206mcpsimp"></a>
226
227[电话服务子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E7%94%B5%E8%AF%9D%E6%9C%8D%E5%8A%A1%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
228
229**telephony_data_storage**
230
231[telephony_core_service](https://gitee.com/openharmony/telephony_core_service/blob/master/README_zh.md)
232
233[telephony_sms_mms](https://gitee.com/openharmony/telephony_sms_mms/blob/master/README_zh.md)
234
235[telephony_cellular_call](https://gitee.com/openharmony/telephony_cellular_call/blob/master/README_zh.md)
236
237[telephony_call_manager](https://gitee.com/openharmony/telephony_call_manager/blob/master/README_zh.md)
238
239