diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 0000000..0172d9b
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,148 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//build/lite/config/component/lite_component.gni")
+
+## Build Contacts_DataAbility.hap
+ohos_hap("Contacts_DataAbility") {
+ hap_profile = "./config.json"
+ shared_libraries = [
+ ":contactsdataability",
+ ]
+ certificate_profile = "./signature/contactsdata.p7b"
+ hap_name = "Contacts_DataAbility"
+ part_name = "contactsdata_hap"
+ subsystem_name = "applications"
+}
+
+## Build contactsdataability.so {{{
+config("contactsdataability_public_config") {
+ visibility = [ ":*" ]
+ include_dirs = [
+ "//third_party/node/src",
+ "ability/common/include",
+ "ability/common/utils/include/",
+ "dataBusiness/voicemail/include",
+ "dataBusiness/calllog/include",
+ "dataBusiness/contacts/include",
+ "ability/account/include",
+ "dataBusiness/quicksearch/include",
+ "ability/sinicization/include",
+ "ability/account/include",
+ "ability/merge/include",
+ "ability/datadisasterrecovery/include",
+ ]
+ cflags = [ ]
+}
+
+ohos_shared_library("contactsdataability") {
+ sources = [
+ "dataBusiness/calllog/src/calllog_ability.cpp",
+ "dataBusiness/calllog/src/calllog_database.cpp",
+ "dataBusiness/voicemail/src/voicemail_ability.cpp",
+ "dataBusiness/voicemail/src/voicemail_database.cpp",
+ "dataBusiness/contacts/src/contacts_database.cpp",
+ "dataBusiness/contacts/src/contacts_account.cpp",
+ "dataBusiness/contacts/src/contacts_type.cpp",
+ "dataBusiness/contacts/src/contacts_data_ability.cpp",
+ "ability/common/utils/src/merge_utils.cpp",
+ "ability/common/utils/src/uri_utils.cpp",
+ "ability/common/utils/src/file_utils.cpp",
+ "ability/common/utils/src/contacts_path.cpp",
+ "ability/common/utils/src/predicates_convert.cpp",
+ "ability/merge/src/candidate_status.cpp",
+ "ability/merge/src/merger_contacts.cpp",
+ "ability/merge/src/match_candidate.cpp",
+ "ability/merge/src/candidate.cpp",
+ "ability/common/utils/src/contacts_json_utils.cpp",
+ "ability/common/utils/src/contacts_common_event.cpp",
+ "ability/common/utils/src/sql_analyzer.cpp",
+ "dataBusiness/contacts/src/contacts_update_helper.cpp",
+ "dataBusiness/contacts/src/raw_contacts.cpp",
+ "dataBusiness/contacts/src/contacts.cpp",
+ "dataBusiness/quicksearch/src/contacts_search.cpp",
+ "ability/sinicization/src/construction_name.cpp",
+ "ability/sinicization/src/character_transliterate.cpp",
+ "ability/common/utils/src/contacts_string_utils.cpp",
+ "ability/account/src/account_data_collection.cpp",
+ "ability/account/src/account_sync.cpp",
+ "ability/account/src/account_manager.cpp",
+ "dataBusiness/contacts/src/profile_database.cpp",
+ "ability/datadisasterrecovery/src/database_disaster_recovery.cpp"
+ ]
+include_dirs=[
+ "//utils/native/base/include",
+ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
+ "//third_party/jsoncpp",
+ "//third_party/jsoncpp/include/json",
+ "//base/account/os_account/interfaces/innerkits/ohosaccount/native/include/",
+ "//base/account/os_account/interfaces/kits/napi/distributedaccount/include/",
+ "//base/account/os_account/interfaces/innerkits/include",
+ "//foundation/aafwk/standard/interfaces/innerkits/want/include",
+ "//foundation/appexecfwk/standard/kits/appkit/native/app",
+ "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content",
+ "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
+ "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
+ "//foundation/aafwk/standard/services/abilitymgr/include",
+ "//foundation/appexecfwk/standard/common/log/include",
+ "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
+ "//foundation/aafwk/standard/frameworks/kits/ability/native/include",
+ "//base/notification/ces_standard/interfaces/innerkits/native/include/"
+ ]
+
+deps = [
+ "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
+ "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native",
+ "//utils/native/base:utils",
+ "//foundation/ace/napi:ace_napi",
+ "//third_party/jsoncpp:jsoncpp",
+ "//base/notification/ces_standard/frameworks/core:cesfwk_core",
+ "//base/notification/ces_standard/frameworks/native:cesfwk_innerkits",
+ "//base/notification/ces_standard/services:cesfwk_services",
+ "//foundation/aafwk/standard/interfaces/innerkits/want/:want",
+ "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
+ "//foundation/aafwk/standard/frameworks/kits/ability/native:dummy_classes",
+ "//foundation/appexecfwk/standard/common:libappexecfwk_common",
+ "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
+ "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
+ "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
+ "//utils/native/base:utilsbase",
+ ]
+
+ public_configs = [ ":contactsdataability_public_config" ]
+ external_deps = [
+ "ability_runtime:ability_manager",
+ "ability_runtime:want",
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "eventhandler:libeventhandler",
+ "ipc:ipc_core",
+ "ces_standard:cesfwk_innerkits",
+ "native_appdatamgr:native_appdatafwk",
+ "native_appdatamgr:native_dataability",
+ "native_appdatamgr:native_preferences",
+ "native_appdatamgr:native_rdb",
+ ]
+ if (is_standard_system) {
+ external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
+ } else {
+ external_deps += [ "hilog:libhilog" ]
+ }
+
+ public_deps = []
+ relative_install_dir = "module"
+ part_name = "contactsdata_hap"
+ subsystem_name = "applications"
+}
+## Build contactsdataability.so }}}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..4947287
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/OAT.xml b/OAT.xml
new file mode 100644
index 0000000..850de47
--- /dev/null
+++ b/OAT.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.en.md b/README.en.md
index 7da05f2..d801960 100644
--- a/README.en.md
+++ b/README.en.md
@@ -1,36 +1,44 @@
-# applications_contactsdata
+# applications_contactsdata
-#### Description
-{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
+- [Introduction](#section1166054159366)
+- [Image architecture](#section1619419895966)
+- [Directory Structure](#section161941989596)
+- [Repositories Involved](#section1371113476307)
-#### Software Architecture
-Software architecture description
+## Introduction
-#### Installation
+The contact database application is an indispensable management information application for every user to manage the contact database.
+Its content is very important for user managers, so the contact database should be able to provide sufficient information and quick
+query means for each user's management, which greatly facilitates users to reasonably manage the contact database information.
-1. xxxx
-2. xxxx
-3. xxxx
+## Image architecture
-#### Instructions
+
-1. xxxx
-2. xxxx
-3. xxxx
+## Directory Structure
-#### Contribution
+```
+/foundation/contactsdataability/
+├── ability
+│ ├── account #Account Management
+│ ├── checkpermission #Permission Check
+│ ├── common #Public Method
+│ ├── datadisasterrecovery #Data Corruption Recovery
+│ ├── merge #Contacts Merge
+│ └── sinicization #Chinese Characters to Pinyin Related
+├── contacts #NAPI
+├── dataBusiness
+│ ├── calllog #Call Records
+│ ├── contacts #Contacts Person
+│ ├── quicksearch #Quick Search
+│ └── voicemail #Voicemail
+├── test #Test Catalog
+├── BUILD.gn
+└── ohos.build
+```
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
+## Repositories Involved
+system applications
-#### Gitee Feature
-
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+applications_contactsdata
\ No newline at end of file
diff --git a/README.md b/README.md
index b0466b6..41fb02f 100644
--- a/README.md
+++ b/README.md
@@ -1,39 +1,521 @@
+# 联系人数据库子系统
# applications_contactsdata
-#### 介绍
-{**以下是 Gitee 平台说明,您可以替换此简介**
-Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
-无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
+- [简介](#section1166054159366)
+- [架构图](#section1619419895966)
+- [目录](#section161941989596)
+- [相关仓](#section1371113476307)
-#### 软件架构
-软件架构说明
+## 简介
+联系人数据库应用是每一个用户管理联系人数据库的不可缺少的一个管理信息应用,
+它的内容对于用户管理者来说是至关重要的,所以联系人数据库应该能够为每一个
+用户的管理提供充足的信息和快捷查询手段,大大方便用户合理的管理联系人数据库信息。
-#### 安装教程
+## 架构图
-1. xxxx
-2. xxxx
-3. xxxx
+
-#### 使用说明
+## 目录
-1. xxxx
-2. xxxx
-3. xxxx
+```
+/foundation/contactsdataability/
+├── ability
+│ ├── account #账户管理
+│ ├── checkpermission #权限检测
+│ ├── common #公共方法:log,utils等
+│ ├── datadisasterrecovery #数据损坏恢复
+│ ├── merge #联系人合并
+│ └── sinicization #汉字转拼音相关
+├── contacts #NAPI
+├── dataBusiness
+│ ├── calllog #通话记录
+│ ├── contacts #联系人
+│ ├── quicksearch #快速检索
+│ └── voicemail #语音信箱
+├── test #测试目录
+├── BUILD.gn
+└── ohos.build
+```
+## 使用说明
-#### 参与贡献
+### 概述
-1. Fork 本仓库
-2. 新建 Feat_xxx 分支
-3. 提交代码
-4. 新建 Pull Request
+提供联系人数据和通话记录以及语音信箱增、删、改、查、等接口。
+接口参数主要有string类型的uri和对象类型的value、DataAbilityPredicates
+使用功能接口前,需要导入相关模块。
-#### 特技
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+```
+### 通话记录
-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+#### DAHelper.insert(uri: string, value: ValuesBucket)
+
+- 接口说明
+
+ 通话记录插入
+
+- insert参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
+
+返回值为 通话记录id
+
+更新示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var calllogDAhelperUri= "dataability:///com.ohos.calllogability";
+var calllogUri = "dataability:///com.ohos.calllogability/calls/calllog";
+var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(calllogDAhelperUri);
+// 调用insert方法
+DAHelper.insert(calllogUri, value).then((data) => {
+ console.info("calllogId = " + data);
+});
+```
+#### DAHelper.update(uri: string, value: ValuesBucket, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 通话记录修改
+
+- update参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
+ | condition | 只读 | DataAbilityPredicates | 是 | 更新条件 |
+
+返回值为 成功为0否则为-1
+
+修改示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var calllogDAhelperUri= "dataability:///com.ohos.calllogability";
+var calllogUri = "dataability:///com.ohos.calllogability/calls/calllog";
+var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(calllogDAhelperUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+// 调用update方法
+DAHelper.update(calllogUri, value, condition).then((data) => {
+ console.info("resultCode = " + data);
+});
+```
+
+#### DAHelper.delete(uri: string, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 通话记录删除
+
+- delete参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | condition | 只读 | DataAbilityPredicates | 是 | 删除条件 |
+
+返回值为 成功为0否则为-1
+
+删除示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var calllogDAhelperUri= "dataability:///com.ohos.calllogability";
+var calllogUri = "dataability:///com.ohos.calllogability/calls/calllog";
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(calllogDAhelperUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+// 调用delete方法
+DAHelper.delete(calllogUri, condition).then((data) => {
+ console.info("deleteCode = " + data);
+});
+```
+
+#### DAHelper.query(uri: string, resultColumns: array, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 通话记录查询
+
+- 查询参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | resultColumns | 只读 | array | 是 | 需要查询的列字段名称 |
+ | condition | 只读 | DataAbilityPredicates | 是 | 查询条件 |
+
+返回值为 ResultSet 查询结果集
+
+查询示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var calllogDAhelperUri= "dataability:///com.ohos.calllogability";
+var calllogUri = "dataability:///com.ohos.calllogability/calls/calllog";
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(calllogDAhelperUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+var resultColumns = [ "id", "display_name", "phone_number"];
+// 调用query方法
+DAHelper.query(calllogUri, resultColumns, condition).then((data) => {
+ if (resultSet.goToFirstRow()) {
+ do {
+ var displayName = resultSet.getString(resultSet.getColumnIndex("display_name"));
+ var id = resultSet.getInt(resultSet.getColumnIndex("id"));
+ var phoneNumber = resultSet.getString(resultSet.getColumnIndex("phone_number"));
+ } while (resultSet.goToNextRow());
+ }
+ resultSet.close();
+});
+```
+返回值为 ResultSet 查询结果集
+
+### 语音信箱
+
+#### DAHelper.insert(uri: string, value: ValuesBucket)
+
+- 接口说明
+
+ 语音信箱插入
+
+- insert参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
+
+返回值为 语音信箱表id
+
+更新示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var voicemailDAhelperUri= "dataability:///com.ohos.voicemailability";
+var voicemaiUri = "dataability:///com.ohos.voicemailability/calls/voicemail";
+var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(voicemailDAhelperUri);
+// 调用insert方法
+DAHelper.insert(voicemaiUri, value).then((data) => {
+ console.info("calllogId = " + data);
+});
+```
+#### DAHelper.update(uri: string, value: ValuesBucket, condition:DataAbilityPredicates)
+
+- 接口说明
+
+ 语音信箱修改
+
+- update参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
+ | condition | 只读 | DataAbilityPredicates | 是 | 更新条件 |
+
+返回值为 成功为0否则为-1
+
+修改示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var voicemailDAhelperUri= "dataability:///com.ohos.voicemailability";
+var voicemaiUri = "dataability:///com.ohos.voicemailability/calls/voicemail";
+var value = {"phone_number" : "xxxxx","display_name" : "xxx"};
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(voicemailDAhelperUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+// 调用update方法
+DAHelper.update(voicemaiUri, value, condition).then((data) => {
+ console.info("resultCode = " + data);
+});
+```
+
+#### DAHelper.delete(uri: string, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 语音信箱删除
+
+- delete参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | condition | 只读 | DataAbilityPredicates | 是 | 删除条件 |
+
+返回值为 成功为0否则为-1
+
+删除示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var voicemailDAhelperUri= "dataability:///com.ohos.voicemailability";
+var voicemaiUri = "dataability:///com.ohos.voicemailability/calls/voicemail";
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(voicemailDAhelperUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+// 调用delete方法
+DAHelper.delete(voicemaiUri, condition).then((data) => {
+ console.info("deleteCode = " + data);
+});
+```
+
+#### DAHelper.query(uri: string, resultColumns:array, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 语音信箱查询
+
+- 查询参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | resultColumns | 只读 | array | 是 | 需要查询的列字段名称 |
+ | condition | 只读 | DataAbilityPredicates | 是 | 查询条件 |
+
+返回值为 ResultSet 查询结果集
+
+查询示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var voicemailDAhelperUri= "dataability:///com.ohos.voicemailability";
+var voicemaiUri = "dataability:///com.ohos.voicemailability/calls/voicemail";
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(calllogDAhelperUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+var resultColumns = [ "id", "display_name", "phone_number"];
+// 调用query方法
+DAHelper.query(voicemaiUri, resultColumns, condition).then((data) => {
+ if (resultSet.goToFirstRow()) {
+ do {
+ var displayName = resultSet.getString(resultSet.getColumnIndex("display_name"));
+ var id = resultSet.getInt(resultSet.getColumnIndex("id"));
+ var phoneNumber = resultSet.getString(resultSet.getColumnIndex("phone_number"));
+ } while (resultSet.goToNextRow());
+ }
+ resultSet.close();
+});
+```
+
+### 联系人
+
+#### DAHelper.insert(uri: string, value: ValuesBucket)
+
+- 接口说明
+
+ 联系人插入
+
+- insert参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
+
+返回值为 联系人数据表id
+
+更新示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var contactsUri= "dataability:///com.ohos.contactsdataability";
+var rawContactUri = "dataability:///com.ohos.contactsdataability/contacts/raw_contact";
+var contactDataUri = "dataability:///com.ohos.contactsdataability/contacts/contact_data";
+var value = {"display_name" : "xxx"};
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(contactsUri);
+// 调用insert方法
+DAHelper.insert(rawContactUri, value).then((rawContactId) => {
+ console.info("rawContactId = " + rawContactId);
+ // 联系人详细信息插入
+ var contactDataValues = {
+ "raw_contact_id" : rawContactId,
+ "content_type" : "name",
+ "detail_info" : "xxxxxxx"
+ };
+ DAHelper.insert(contactDataUri, contactDataValues).then((contactDataId) => {
+ console.info("rawContactId = " + contactDataId);
+ };
+});
+```
+#### DAHelper.update(uri: string, value: ValuesBucket, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 联系人修改
+
+- update参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | value | 只读 | ValuesBucket | 是 | 数据库字段key-value对象 |
+ | condition | 只读 | DataAbilityPredicates | 是 | 更新条件 |
+
+返回值为 成功为0否则为-1
+
+修改示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var contactsUri= "dataability:///com.ohos.contactsdataability";
+var rawContactUri = "dataability:///com.ohos.contactsdataability/contacts/raw_contact";
+var contactDataUri = "dataability:///com.ohos.contactsdataability/contacts/contact_data";
+var value = {"display_name" : "xxx"};
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(contactsUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+// 调用update方法
+DAHelper.update(rawContactUri, value, condition).then((data) => {
+ console.info("resultCode = " + data);
+});
+```
+
+#### DAHelper.delete(uri: string, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 联系人删除
+
+- delete参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | condition | 只读 | DataAbilityPredicates | 是 | 删除条件 |
+
+返回值为 成功为0否则为-1
+
+删除示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var contactsUri= "dataability:///com.ohos.contactsdataability";
+var rawContactUri = "dataability:///com.ohos.contactsdataability/contacts/raw_contact";
+var contactDataUri = "dataability:///com.ohos.contactsdataability/contacts/contact_data";
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(contactsUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+// 调用delete方法
+DAHelper.delete(contactDataUri, condition).then((data) => {
+ console.info("deleteCode = " + data);
+});
+```
+#### DAHelper.query(uri: string, resultColumns: array, condition: DataAbilityPredicates)
+
+- 接口说明
+
+ 联系人查询
+
+- 查询参数描述
+
+ | 名称 | 读写属性 | 类型 | 必填 | 描述 |
+ | -------- | -------- | ---------------------- | ---- | ------------------------------ |
+ | uri | 只读 | string | 是 | 具体操作的uri |
+ | resultColumns | 只读 | array | 是 | 需要查询的列字段名称 |
+ | condition | 只读 | DataAbilityPredicates | 是 | 查询条件 |
+
+返回值为 ResultSet 查询结果集
+
+查询示例
+```js
+import featureAbility from '@ohos.ability.featureAbility';
+import ohos_data_ability from '@ohos.data.dataability';
+var contactsUri= "dataability:///com.ohos.contactsdataability";
+var rawContactUri = "dataability:///com.ohos.contactsdataability/contacts/raw_contact";
+// 获取DAHelper
+var DAHelper = featureAbility.acquireDataAbilityHelper(contactsUri);
+// 条件参数
+var condition = new ohos_data_ability.DataAbilityPredicates();
+condition.equalTo("id", "xxx");
+var resultColumns = [ "id", "display_name"];
+// 调用query方法
+DAHelper.query(rawContactUri, resultColumns, condition).then((data) => {
+ if (resultSet.goToFirstRow()) {
+ do {
+ var displayName = resultSet.getString(resultSet.getColumnIndex("display_name"));
+ } while (resultSet.goToNextRow());
+ }
+ resultSet.close();
+});
+```
+| 系统公共uri |
+| --------------------------------------------------------- |
+| dataability:///com.ohos.contactsdataability |
+| dataability:///com.ohos.contactsdataability/contacts/contact |
+| dataability:///com.ohos.contactsdataability/contacts/raw_contact |
+| dataability:///com.ohos.contactsdataability/contacts/contact_data |
+| dataability:///com.ohos.contactsdataability/contacts/raw_contact/query_merge_list|
+| dataability:///com.ohos.contactsdataability/contacts/raw_contact/split_contact |
+| dataability:///com.ohos.contactsdataability/contacts/raw_contact/manual_merge |
+| dataability:///com.ohos.contactsdataability/contacts/raw_contact/auto_merge |
+| dataability:///com.ohos.contactsdataability/contacts/contact_type |
+| dataability:///com.ohos.contactsdataability/contacts/groups |
+| dataability:///com.ohos.contactsdataability/contacts/photo_files |
+| dataability:///com.ohos.contactsdataability/contacts/contact_blocklist |
+| dataability:///com.ohos.contactsdataability/contacts/deleted_raw_contact |
+| dataability:///com.ohos.contactsdataability/contacts/search_contact |
+| dataability:///com.ohos.contactsdataability/contacts/deleted_raw_contact |
+| dataability:///com.ohos.contactsdataability/contacts/deleted_raw_contact_record |
+| dataability:///com.ohos.contactsdataability/contacts/backup |
+| dataability:///com.ohos.contactsdataability/contacts/recover |
+| dataability:///com.ohos.contactsdataability/profile/contact |
+| dataability:///com.ohos.contactsdataability/profile/raw_contact |
+| dataability:///com.ohos.contactsdataability/profile/contact_data |
+| dataability:///com.ohos.contactsdataability/profile/raw_contact/query_merge_list |
+| dataability:///com.ohos.contactsdataability/profile/raw_contact/split_contact |
+| dataability:///com.ohos.contactsdataability/profile/raw_contact/manual_merge |
+| dataability:///com.ohos.contactsdataability/profile/raw_contact/auto_merge |
+| dataability:///com.ohos.contactsdataability/profile/contact_type |
+| dataability:///com.ohos.contactsdataability/profile/groups |
+| dataability:///com.ohos.contactsdataability/profile/photo_files |
+| dataability:///com.ohos.contactsdataability/profile/contact_blocklist |
+| dataability:///com.ohos.contactsdataability/profile/deleted_raw_contact |
+| dataability:///com.ohos.contactsdataability/profile/search_contact |
+| dataability:///com.ohos.contactsdataability/profile/deleted_raw_contact |
+| dataability:///com.ohos.contactsdataability/profile/deleted_raw_contact_record |
+| dataability:///com.ohos.contactsdataability/profile/backup |
+| dataability:///com.ohos.contactsdataability/profile/recover |
+| dataability:///com.ohos.calllogability |
+| dataability:///com.ohos.calllogability/calls/calllog |
+| dataability:///com.ohos.voicemailability |
+| dataability:///com.ohos.voicemailability/calls/voicemail |
+## 相关仓
+
+系统应用
+
+applications_contactsdata
\ No newline at end of file
diff --git a/ability/account/.gitignore b/ability/account/.gitignore
new file mode 100644
index 0000000..0e9778b
--- /dev/null
+++ b/ability/account/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+..
+# Except this file
+!.gitignore
\ No newline at end of file
diff --git a/ability/account/include/account_change_event.h b/ability/account/include/account_change_event.h
new file mode 100644
index 0000000..7933a6a
--- /dev/null
+++ b/ability/account/include/account_change_event.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACCOUNT_CHANGE_EVENT_H
+#define ACCOUNT_CHANGE_EVENT_H
+
+#include "common_event.h"
+#include "common_event_manager.h"
+
+namespace OHOS {
+namespace Contacts {
+class AccountChangeEvent : public OHOS::EventFwk::CommonEventSubscriber {
+public:
+ ~AccountChangeEvent();
+ AccountChangeEvent(const OHOS::EventFwk::CommonEventSubscribeInfo &sp);
+ void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
+private:
+ const static std::string SPLIT_SYMBOL_VERTICAL = "||";
+ const static std::string SPLIT_SYMBOL_COMMA = ",";
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // ACCOUNT_CHANGE_EVENT_H
diff --git a/ability/account/include/account_data_collection.h b/ability/account/include/account_data_collection.h
new file mode 100644
index 0000000..b356bf9
--- /dev/null
+++ b/ability/account/include/account_data_collection.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACCOUNT_DATA_COLLECTION_H
+#define ACCOUNT_DATA_COLLECTION_H
+
+#include
+
+#include "account_info.h"
+
+namespace OHOS {
+namespace Contacts {
+class AccountDataCollection {
+public:
+ AccountDataCollection();
+ ~AccountDataCollection();
+ AccountDataCollection(std::string accountName, std::string accountType, std::string dataColletion);
+ // Judge whether local account
+ bool IsDefualtAccount();
+ // Judge whether the system account
+ bool ContainSysAccounts(std::vector sysAccounts);
+ std::string GetcAccountName();
+ std::string GetcAccountType();
+ std::string GetcDataCollection();
+
+private:
+ std::string cAccountName_;
+ std::string cAccountType_;
+ std::string cDataCollection_;
+};
+} // namespace Contacts
+} // namespace OHOS
+
+#endif // ACCOUNT_DATA_COLLECTION_H
diff --git a/ability/account/include/account_event_manager.h b/ability/account/include/account_event_manager.h
new file mode 100644
index 0000000..a31a5fb
--- /dev/null
+++ b/ability/account/include/account_event_manager.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACCOUNT_EVENT_MANAGER_H
+#define ACCOUNT_EVENT_MANAGER_H
+
+#include
+
+namespace OHOS {
+namespace Contacts {
+class AccountEventManager {
+public:
+ static std::shared_ptr GetInstance();
+ ~AccountEventManager();
+ void PublishEvent(std::string data);
+ void SubscriberAccountEvent();
+
+private:
+ static std::shared_ptr instance_;
+ const static std::string EVENT;
+ AccountEventManager();
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // ACCOUNT_EVENT_MANAGER_H
diff --git a/ability/account/include/account_manager.h b/ability/account/include/account_manager.h
new file mode 100644
index 0000000..cbcf17f
--- /dev/null
+++ b/ability/account/include/account_manager.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACCOUNT_MANAGER_H
+#define ACCOUNT_MANAGER_H
+
+namespace OHOS {
+namespace Contacts {
+class AccountManager {
+public:
+ AccountManager();
+ ~AccountManager();
+ int GetAccount();
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // ACCOUNT_MANAGER_H
diff --git a/ability/account/include/account_sync.h b/ability/account/include/account_sync.h
new file mode 100644
index 0000000..9a7bc6a
--- /dev/null
+++ b/ability/account/include/account_sync.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ACCOUNT_SYNC_H
+#define ACCOUNT_SYNC_H
+
+#include
+
+#include "account_info.h"
+
+#include "account_data_collection.h"
+#include "contacts_database.h"
+#include "profile_database.h"
+
+namespace OHOS {
+namespace Contacts {
+class AccountSync {
+public:
+ ~AccountSync();
+ static std::shared_ptr GetInstance();
+ static std::shared_ptr contactsDataBase_;
+ static std::shared_ptr profileDataBase_;
+ // Update account synchronously
+ void SyncUpdateAccount(std::vector sysAccounts, bool isProfile);
+
+private:
+ AccountSync();
+ static std::shared_ptr instance_;
+ int ClearData(std::shared_ptr store, int accountId);
+ void getShouldUpdateAndAddAccounts(std::vector systemAccounts,
+ std::vector localAccounts,
+ std::vector &shouldUpdateAccounts,
+ std::vector &shouldAddAccounts);
+};
+} // namespace Contacts
+} // namespace OHOS
+
+#endif // ACCOUNT_SYNC_H
\ No newline at end of file
diff --git a/ability/account/src/account_change_event.cpp b/ability/account/src/account_change_event.cpp
new file mode 100644
index 0000000..e8629ae
--- /dev/null
+++ b/ability/account/src/account_change_event.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "account_change_event.h"
+
+#include "account_sync.h"
+#include "common.h"
+#include "contacts_string_utils.h"
+#include "hilog_wrapper.h"
+
+namespace OHOS {
+namespace Contacts {
+AccountChangeEvent::AccountChangeEvent(const OHOS::EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp)
+{
+}
+
+AccountChangeEvent::~AccountChangeEvent()
+{
+}
+
+void AccountChangeEvent::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
+{
+ std::shared_ptr accountSync = AccountSync::GetInstance();
+ std::vector sysAccounts;
+ std::vector accountObjVec = ContactsStringUtils::SplitStr(data.GetData(), SPLIT_SYMBOL_VERTICAL);
+ for (size_t i = 0; i < accountObjVec.size(); i++) {
+ std::vector accountObj = ContactsStringUtils::SplitStr(accountObjVec[i], SPLIT_SYMBOL_COMMA);
+ OHOS::AccountSA::OhosAccountInfo var;
+ var.name_ = accountObj[0];
+ var.uid_ = accountObj[1];
+ sysAccounts.push_back(var);
+ }
+ accountSync->SyncUpdateAccount(sysAccounts, true);
+ HILOG_INFO("AccountChangeEvent OnReceiveEvent update profile successful");
+ accountSync->SyncUpdateAccount(sysAccounts, false);
+ HILOG_INFO("AccountChangeEvent OnReceiveEvent update local successful");
+}
+} // namespace Contacts
+} // namespace OHOS
\ No newline at end of file
diff --git a/ability/account/src/account_data_collection.cpp b/ability/account/src/account_data_collection.cpp
new file mode 100644
index 0000000..c1cf2fd
--- /dev/null
+++ b/ability/account/src/account_data_collection.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "account_data_collection.h"
+
+#include
+
+#include "contacts_columns.h"
+
+namespace OHOS {
+namespace Contacts {
+AccountDataCollection::AccountDataCollection(void)
+{
+}
+
+AccountDataCollection::~AccountDataCollection()
+{
+}
+
+AccountDataCollection::AccountDataCollection(
+ std::string accountName, std::string accountType, std::string dataCollection)
+{
+ this->cAccountName_ = accountName;
+ this->cAccountType_ = accountType;
+ this->cDataCollection_ = dataCollection;
+}
+
+std::string AccountDataCollection::GetcAccountName()
+{
+ return this->cAccountName_;
+}
+
+std::string AccountDataCollection::GetcAccountType()
+{
+ return this->cAccountType_;
+}
+
+std::string AccountDataCollection::GetcDataCollection()
+{
+ return this->cDataCollection_;
+}
+
+bool AccountDataCollection::IsDefualtAccount()
+{
+ return AccountData::ACCOUNT_NAME == this->cAccountName_ && AccountData::ACCOUNT_TYPE == this->cAccountType_;
+}
+
+bool AccountDataCollection::ContainSysAccounts(std::vector sysAccounts)
+{
+ for (auto iter = sysAccounts.begin(); iter != sysAccounts.end(); ++iter) {
+ if (iter->name_ == this->cAccountName_ && iter->uid_ == this->cAccountType_) {
+ return true;
+ }
+ }
+ return false;
+}
+} // namespace Contacts
+} // namespace OHOS
diff --git a/ability/account/src/account_event_manager.cpp b/ability/account/src/account_event_manager.cpp
new file mode 100644
index 0000000..1884068
--- /dev/null
+++ b/ability/account/src/account_event_manager.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "account_event_manager.h"
+
+#include
+
+#include "common_event_manager.h"
+#include "want.h"
+
+#include "account_change_event.h"
+
+namespace OHOS {
+namespace Contacts {
+namespace {
+std::mutex g_mtx;
+}
+const std::string AccountEventManager::EVENT = "com.test.account.change.event";
+std::shared_ptr AccountEventManager::instance_ = nullptr;
+
+AccountEventManager::AccountEventManager(void)
+{
+}
+
+AccountEventManager::~AccountEventManager()
+{
+}
+
+std::shared_ptr AccountEventManager::GetInstance()
+{
+ if (instance_ == nullptr) {
+ instance_.reset(new AccountEventManager());
+ }
+ return instance_;
+}
+
+void AccountEventManager::PublishEvent(std::string data)
+{
+ // make a want
+ OHOS::AAFwk::Want want;
+ want.SetAction(EVENT);
+ // make common event
+ OHOS::EventFwk::CommonEventData event;
+ event.SetWant(want);
+ event.SetData(data);
+
+ // lock the mutex
+ g_mtx.lock();
+ // publish a common event
+ OHOS::EventFwk::CommonEventManager::PublishCommonEvent(event);
+ g_mtx.unlock();
+}
+
+void AccountEventManager::SubscriberAccountEvent()
+{
+ OHOS::EventFwk::MatchingSkills matchingSkills;
+ matchingSkills.AddEvent(EVENT);
+ OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
+ std::shared_ptr subscriber = std::make_shared(subscriberInfo);
+ OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
+}
+} // namespace Contacts
+} // namespace OHOS
\ No newline at end of file
diff --git a/ability/account/src/account_manager.cpp b/ability/account/src/account_manager.cpp
new file mode 100644
index 0000000..ad2cd70
--- /dev/null
+++ b/ability/account/src/account_manager.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "account_manager.h"
+
+#include "contacts_account.h"
+#include "contacts_columns.h"
+#include "contacts_database.h"
+
+namespace OHOS {
+namespace Contacts {
+AccountManager::AccountManager(void)
+{
+}
+
+AccountManager::~AccountManager()
+{
+}
+
+int AccountManager::GetAccount()
+{
+ // query accountId
+ std::shared_ptr contactsAccount = ContactsAccount::GetInstance();
+ int accountId = contactsAccount->LookupAccountTypeId(
+ ContactsDataBase::store_, AccountData::ACCOUNT_NAME, AccountData::ACCOUNT_TYPE);
+ return accountId;
+}
+} // namespace Contacts
+} // namespace OHOS
\ No newline at end of file
diff --git a/ability/account/src/account_sync.cpp b/ability/account/src/account_sync.cpp
new file mode 100644
index 0000000..232349c
--- /dev/null
+++ b/ability/account/src/account_sync.cpp
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "account_sync.h"
+
+#include
+
+#include "common.h"
+#include "contacts.h"
+#include "contacts_account.h"
+#include "contacts_columns.h"
+#include "contacts_database.h"
+#include "contacts_string_utils.h"
+#include "hilog_wrapper.h"
+#include "raw_contacts.h"
+
+namespace OHOS {
+namespace Contacts {
+namespace {
+std::mutex g_mtx;
+}
+std::shared_ptr AccountSync::contactsDataBase_ = nullptr;
+std::shared_ptr AccountSync::profileDataBase_ = nullptr;
+std::shared_ptr AccountSync::instance_ = nullptr;
+std::shared_ptr g_contactsAccount = nullptr;
+
+std::shared_ptr AccountSync::GetInstance()
+{
+ if (instance_ == nullptr) {
+ instance_.reset(new AccountSync());
+ }
+ return instance_;
+}
+
+AccountSync::AccountSync()
+{
+ contactsDataBase_ = ContactsDataBase::GetInstance();
+ g_contactsAccount = ContactsAccount::GetInstance();
+ profileDataBase_ = ProfileDatabase::GetInstance();
+}
+
+AccountSync::~AccountSync()
+{
+}
+
+void AccountSync::getShouldUpdateAndAddAccounts(std::vector systemAccounts,
+ std::vector localAccounts,
+ std::vector &shouldUpdateAccounts,
+ std::vector &shouldAddAccounts)
+{
+ for (size_t i = 0; i < systemAccounts.size(); i++) {
+ for (size_t j = 0; j < localAccounts.size(); j++) {
+ if (systemAccounts[i].uid_ == localAccounts[j].GetcAccountType() &&
+ systemAccounts[i].uid_ == localAccounts[j].GetcAccountType()) {
+ break;
+ }
+ if (j == localAccounts.size() - 1) {
+ shouldAddAccounts.push_back(systemAccounts[i]);
+ }
+ }
+ }
+}
+
+void AccountSync::SyncUpdateAccount(std::vector sysAccounts, bool isProfile)
+{
+ g_mtx.lock();
+ if (sysAccounts.empty()) {
+ HILOG_ERROR("AccountSync::SyncUpdateAccount sysAccounts is null");
+ return;
+ }
+ std::shared_ptr store = nullptr;
+ if (isProfile) {
+ store = profileDataBase_->store_;
+ HILOG_INFO("AccountSync::SyncUpdateAccount this is profileDataBase_ operation");
+ } else {
+ store = contactsDataBase_->contactStore_;
+ HILOG_INFO("AccountSync::SyncUpdateAccount this is contactsDataBase_ operation");
+ }
+ if (store == nullptr) {
+ HILOG_ERROR("SyncUpdateAccount isProfile values is %{public}d this database store ponit is null", isProfile);
+ return;
+ }
+ std::vector accounts = g_contactsAccount->GetAccountFromLoacl(store);
+ std::vector notInSysAccounts;
+ std::vector needAddAccount;
+ for (size_t i = 0; i < accounts.size(); i++) {
+ auto iter = accounts[i];
+ // if account is not default and not in sysAccounts then this should remove
+ if (!iter.IsDefualtAccount() && !iter.ContainSysAccounts(sysAccounts)) {
+ notInSysAccounts.push_back(iter);
+ }
+ }
+ HILOG_INFO("SyncUpdateAccount getNotExistAccount notInSysAccounts size is :%{public}d", notInSysAccounts.size());
+ std::vector shouldUpdateAccounts;
+ std::vector shouldAddAccounts;
+ getShouldUpdateAndAddAccounts(sysAccounts, accounts, shouldUpdateAccounts, shouldAddAccounts);
+ HILOG_INFO("SyncUpdateAccount:%{public}d, :%{public}d", shouldUpdateAccounts.size(), shouldAddAccounts.size());
+ store->BeginTransaction();
+ if (!notInSysAccounts.empty()) {
+ g_contactsAccount->StopForegin(store);
+ store->Commit();
+ for (size_t i = 0; i < notInSysAccounts.size(); i++) {
+ int accountId = g_contactsAccount->GetNotExistAccount(store, notInSysAccounts[i]);
+ HILOG_INFO("SyncUpdateAccount getNotExistAccount value is :%{public}d", accountId);
+ ClearData(store, accountId);
+ }
+ }
+ for (size_t i = 0; i < shouldAddAccounts.size(); i++) {
+ g_contactsAccount->Insert(store, shouldAddAccounts[i].name_, shouldAddAccounts[i].uid_);
+ store->Commit();
+ }
+ g_contactsAccount->OpenForegin(store);
+ store->Commit();
+ g_mtx.unlock();
+}
+
+int AccountSync::ClearData(std::shared_ptr store, int accountId)
+{
+ RawContacts contactsRawContact;
+ Contacts contactsContact;
+ if (accountId > ID_EMPTITY) {
+ int needDeleteRawContactId = contactsRawContact.GetDeleteRawContactIdByAccountId(store, accountId);
+ HILOG_INFO("GetDeleteRawContactIdByAccountId successfuly , needDeleteRawContactId is %{public}d",
+ needDeleteRawContactId);
+ int needDeleteContactId = contactsRawContact.GetDeleteContactIdByAccountId(store, accountId);
+ HILOG_INFO("GetDeleteContactIdByAccountId successfuly needDeleteContactId is %{public}d", needDeleteContactId);
+ g_contactsAccount->DeleteDataByRawId(store, needDeleteRawContactId);
+ int ret = store->Commit();
+ HILOG_INFO("DeleteDataByRawId successfuly commit ret %{public}d", ret);
+ contactsRawContact.DeleteRawcontactByRawId(store, needDeleteRawContactId);
+ ret = store->Commit();
+ HILOG_INFO("DeleteRawcontactByRawId successfuly commit ret %{public}d", ret);
+ contactsContact.DeleteContactById(store, needDeleteContactId);
+ ret = store->Commit();
+ HILOG_INFO("DeletecontactsById successfuly commit ret %{public}d", ret);
+ g_contactsAccount->DeleteGroupsByAccountId(store, accountId);
+ ret = store->Commit();
+ HILOG_INFO("DeleteGroupsByAccountId successfuly commit ret %{public}d", ret);
+ g_contactsAccount->DeleteAccountByAccountId(store, accountId);
+ ret = store->Commit();
+ HILOG_INFO("DeleteAccountByAccountId successfuly commit ret %{public}d", ret);
+ }
+ return RDB_EXECUTE_OK;
+}
+} // namespace Contacts
+} // namespace OHOS
\ No newline at end of file
diff --git a/ability/checkpermission/.gitignore b/ability/checkpermission/.gitignore
new file mode 100644
index 0000000..86d0cb2
--- /dev/null
+++ b/ability/checkpermission/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
\ No newline at end of file
diff --git a/ability/common/include/common.h b/ability/common/include/common.h
new file mode 100644
index 0000000..9fdfb14
--- /dev/null
+++ b/ability/common/include/common.h
@@ -0,0 +1,892 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include
+
+#include "contacts_path.h"
+
+namespace OHOS {
+namespace Contacts {
+// error code
+constexpr int RDB_EXECUTE_OK = 0;
+constexpr int RDB_EXECUTE_FAIL = -1;
+constexpr int OPERATION_ERROR = -1;
+constexpr int OPERATION_OK = 0;
+constexpr int RDB_OBJECT_EMPTY = -1;
+constexpr int PARAMETER_EMPTY = -1;
+
+constexpr int DELETE_MARK = 1;
+constexpr int ID_EMPTITY = 0;
+constexpr int BATCH_INSERT_COUNT = 40;
+
+// ResultSet get Num
+constexpr int RESEULT_GET_ONE = 1;
+constexpr int RESEULT_GET_TWO = 2;
+
+// contact table has Judge
+constexpr int HAS_NAME = 1;
+constexpr int HAS_PHONE = 2;
+constexpr int HAS_EMAIL = 3;
+constexpr int HAS_GROUP = 4;
+
+// Contacts DataBase Code
+constexpr int CONTACTS_CONTACT = 10000;
+constexpr int CONTACTS_RAW_CONTACT = 10001;
+constexpr int CONTACTS_CONTACT_DATA = 10002;
+constexpr int CONTACTS_CONTACT_TYPE = 10003;
+constexpr int CONTACTS_DELETED_RAW_CONTACT = 10004;
+constexpr int CONTACTS_GROUPS = 10005;
+constexpr int CONTACTS_ACCOUNT = 10006;
+constexpr int CONTACTS_BLOCKLIST = 10007;
+constexpr int CONTACTS_SEARCH_CONTACT = 10008;
+constexpr int CONTACTS_SYNC_STATUS = 10009;
+constexpr int CONTACTS_PHOTO_FILES = 100010;
+constexpr int CONTACTS_LOCAL_LANG = 10011;
+constexpr int CONTACTS_DATABASE_BACKUP_TASK = 10012;
+constexpr int CONTACTS_DELETE = 10013;
+constexpr int QUERY_MERGE_LIST = 10014;
+constexpr int SPLIT_CONTACT = 10015;
+constexpr int MANUAL_MERGE = 10016;
+constexpr int AUTO_MERGE = 10017;
+constexpr int CONTACTS_DELETE_RECORD = 10018;
+constexpr int CONTACT_TYPE = 10019;
+constexpr int CONTACT_BACKUP = 10020;
+constexpr int CONTACT_RECOVER = 10021;
+
+constexpr int ACCOUNT = 10020;
+constexpr int CALLLOG = 20000;
+constexpr int VOICEMAIL = 20001;
+constexpr int REPLAYING = 20002;
+
+// PROFILE DATABASE CODE
+constexpr int PROFILE_CONTACT = 30000;
+constexpr int PROFILE_RAW_CONTACT = 30001;
+constexpr int PROFILE_CONTACT_DATA = 30002;
+constexpr int PROFILE_CONTACT_TYPE = 30003;
+constexpr int PROFILE_DELETED_RAW_CONTACT = 30004;
+constexpr int PROFILE_GROUPS = 30005;
+constexpr int PROFILE_ACCOUNT = 30006;
+constexpr int PROFILE_BLOCKLIST = 30007;
+constexpr int PROFILE_SEARCH_CONTACT = 30008;
+constexpr int PROFILE_SYNC_STATUS = 30009;
+constexpr int PROFILE_PHOTO_FILES = 300010;
+constexpr int PROFILE_LOCAL_LANG = 30011;
+constexpr int PROFILE_DATABASE_BACKUP_TASK = 30012;
+constexpr int PROFILE_DELETE_RECORD = 30013;
+constexpr int PROFILE_TYPE = 30014;
+constexpr int PROFILE_DELETE = 30015;
+constexpr int PROFILE_BACKUP = 30016;
+constexpr int PROFILE_RECOVER = 30017;
+
+// DATABASE OPEN VERSION
+constexpr int DATABASE_OPEN_VERSION = 1;
+
+// DATABASE NEW VERSION
+constexpr int DATABASE_NEW_VERSION = 2;
+
+// REQUEST PARAMS ARGS NUM
+constexpr int REQUEST_PARAMS_NUM = 2;
+
+constexpr const char *PROFILE_DATABASE_NAME = "profile";
+constexpr const char *CONTACT_DATABASE_NAME = "contacts";
+
+// Rebase
+constexpr int REBASE_SETTING = 0;
+constexpr int REBASE_COUNT = 5;
+
+// MergeMode Number
+constexpr int MERGE_MODE_DEFAULT = 0;
+constexpr int MERGE_MODE_MANUAL = 1;
+constexpr int MERGE_MODE_AUTO = 2;
+
+// Uri
+constexpr const char *CONTACT_URI = "dataability:///com.ohos.contactsdataability";
+constexpr const char *VOICEMAIL_URI = "dataability:///com.ohos.voicemailability";
+constexpr const char *CALL_LOG_URI = "dataability:///com.ohos.calllogability";
+
+constexpr const char *CREATE_CALLLOG =
+ "CREATE TABLE IF NOT EXISTS [calllog]("
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[phone_number] TEXT, "
+ "[display_name] TEXT, "
+ "[call_direction] INTEGER NOT NULL DEFAULT 0, "
+ "[voicemail_uri] TEXT, "
+ "[sim_type] INTEGER , "
+ "[is_hd] INTEGER , "
+ "[is_read] INTEGER NOT NULL DEFAULT 0, "
+ "[ring_duration] INTEGER NOT NULL DEFAULT 0, "
+ "[talk_duration] INTEGER NOT NULL DEFAULT 0, "
+ "[format_number] TEXT, "
+ "[quicksearch_key] TEXT, "
+ "[number_type] INTEGER, "
+ "[number_type_name] TEXT, "
+ "[begin_time] INTEGER NOT NULL DEFAULT 0, "
+ "[end_time] INTEGER NOT NULL DEFAULT 0, "
+ "[answer_state] INTEGER , "
+ "[create_time] INTEGER, "
+ "[number_location] TEXT, "
+ "[photo_id] INTEGER, "
+ "[photo_uri] TEXT, "
+ "[country_iso_code] INTEGER, "
+ "[extra1] TEXT, "
+ "[extra2] TEXT, "
+ "[extra3] TEXT, "
+ "[extra4] TEXT, "
+ "[extra5] TEXT, "
+ "[extra6] TEXT)";
+
+constexpr const char *CREATE_VOICEMAIL =
+ "CREATE TABLE IF NOT EXISTS [voicemail]("
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[phone_number] TEXT, "
+ "[quicksearch_key] TEXT, "
+ "[display_name] TEXT, "
+ "[voicemail_uri] TEXT, "
+ "[voicemail_type] INTEGER NOT NULL DEFAULT 0, "
+ "[voice_file_size] INTEGER NOT NULL DEFAULT 0, "
+ "[voice_duration] INTEGER NOT NULL DEFAULT 0, "
+ "[voice_status] INTEGER NOT NULL DEFAULT 0, "
+ "[origin_type] TEXT, "
+ "[create_time] INTEGER);";
+
+constexpr const char *CREATE_REPLYING =
+ "CREATE TABLE [replying]("
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[name] TEXT, "
+ "[replying_uri] TEXT, "
+ "[replying_path] TEXT, "
+ "[phone_account_id] TEXT, "
+ "[has_content] NOT NULL DEFAULT 0, "
+ "[duration] INTEGER NOT NULL DEFAULT 0, "
+ "[content_type] TEXT, "
+ "[last_modified] INTEGER NOT NULL DEFAULT 0, "
+ "[synced] INTEGER NOT NULL DEFAULT 0 );";
+
+constexpr const char *CREATE_CONTACT =
+ "CREATE TABLE IF NOT EXISTS [contact]("
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[name_raw_contact_id] INTEGER REFERENCES raw_contact(id), "
+ "[photo_id] INTEGER, "
+ "[photo_file_id] INTEGER REFERENCES [photo_files]([id]), "
+ "[personal_ringtone] TEXT, "
+ "[is_transfer_voicemail] INTEGER NOT NULL DEFAULT 0, "
+ "[company] TEXT, "
+ "[position] TEXT, "
+ "[quick_search_key] TEXT, "
+ "[read_only] INTEGER NOT NULL DEFAULT 0, "
+ "[personal_notification_ringtone] TEXT, "
+ "[has_phone_number] INTEGER NOT NULL DEFAULT 0, "
+ "[has_display_name] INTEGER NOT NULL DEFAULT 0, "
+ "[has_email] INTEGER NOT NULL DEFAULT 0, "
+ "[has_group] INTEGER NOT NULL DEFAULT 0)";
+
+constexpr const char *CREATE_CONTACT_INDEX =
+ "CREATE INDEX IF NOT EXISTS [contact_name_raw_contact_id_index] "
+ "ON [contact] ([name_raw_contact_id])";
+
+constexpr const char *CREATE_RAW_CONTACT =
+ "CREATE TABLE IF NOT EXISTS [raw_contact]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[contact_id] INTEGER REFERENCES [contact]([id]), "
+ "[photo_id] INTEGER, "
+ "[photo_file_id] INTEGER REFERENCES [photo_files]([id]), "
+ "[is_transfer_voicemail] INTEGER NOT NULL DEFAULT 0, "
+ "[personal_ringtone] TEXT, "
+ "[is_deleted] INTEGER NOT NULL DEFAULT 0, "
+ "[personal_notification_ringtone] TEXT, "
+ "[photo_first_name] TEXT, "
+ "[account_id] INTEGER, "
+ "[version] INTEGER NOT NULL DEFAULT 0, "
+ "[display_name] TEXT, "
+ "[sort] TEXT, "
+ "[contacted_count] INTEGER NOT NULL DEFAULT 0, "
+ "[lastest_contacted_time] INTEGER NOT NULL DEFAULT 0, "
+ "[favorite] INTEGER NOT NULL DEFAULT 0, "
+ "[favorite_order] TEXT, "
+ "[phonetic_name] TEXT, "
+ "[phonetic_name_type] INTEGER , "
+ "[company] TEXT, "
+ "[position] TEXT, "
+ "[read_only] INTEGER NOT NULL DEFAULT 0, "
+ "[sort_first_letter] TEXT, "
+ "[merge_mode] INTEGER NOT NULL DEFAULT 0, "
+ "[is_need_merge] INTEGER NOT NULL DEFAULT 1, "
+ "[merge_status] INTEGER NOT NULL DEFAULT 1, "
+ "[is_merge_target] INTEGER NOT NULL DEFAULT 0, "
+ "[vibration_setting] INTEGER NOT NULL DEFAULT 0, "
+ "[sync_id] INTEGER, "
+ "[syn_1] TEXT, "
+ "[syn_2] TEXT, "
+ "[syn_3] TEXT)";
+
+constexpr const char *CREATE_CONTACT_DATA =
+ "CREATE TABLE IF NOT EXISTS [contact_data]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[type_id] INTEGER REFERENCES [contact_type]([id]), "
+ "[raw_contact_id] INTEGER REFERENCES [raw_contact]([id]), "
+ "[read_only] INTEGER NOT NULL DEFAULT 0, "
+ "[version] INTEGER NOT NULL DEFAULT 0, "
+ "[is_preferred_number] INTEGER NOT NULL DEFAULT 0, "
+ "[detail_info] TEXT, "
+ "[family_name] TEXT, "
+ "[middle_name_phonetic] TEXT, "
+ "[given_name] TEXT, "
+ "[given_name_phonetic] TEXT, "
+ "[alias_detail_info] TEXT, "
+ "[phonetic_name] TEXT, "
+ "[position] TEXT, "
+ "[extend1] TEXT, "
+ "[extend2] TEXT, "
+ "[extend3] TEXT, "
+ "[extend4] TEXT, "
+ "[city] TEXT, "
+ "[country] TEXT, "
+ "[neighborhood] TEXT, "
+ "[pobox] TEXT, "
+ "[postcode] TEXT, "
+ "[region] TEXT, "
+ "[street] TEXT, "
+ "[alpha_name] TEXT, "
+ "[other_lan_last_name] TEXT, "
+ "[other_lan_first_name] TEXT, "
+ "[extend5] TEXT, "
+ "[lan_style] TEXT, "
+ "[custom_data] TEXT, "
+ "[extend6] TEXT, "
+ "[extend7] TEXT, "
+ "[blob_data] BLOB, "
+ "[syn_1] TEXT, "
+ "[syn_2] TEXT, "
+ "[syn_3] TEXT)";
+constexpr const char *CREATE_CONTACT_TYPE =
+ "CREATE TABLE IF NOT EXISTS [contact_type]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[content_type] TEXT )";
+
+constexpr const char *CREATE_DELETED_RAW_CONTACT =
+ "CREATE TABLE IF NOT EXISTS [deleted_raw_contact]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[contact_id] INTEGER REFERENCES [contact]([id]),"
+ "[raw_contact_id] INTEGER REFERENCES [raw_contact]([id]), "
+ "[delete_source] TEXT, "
+ "[delete_time] INTEGER NOT NULL DEFAULT 0, "
+ "[display_name] TEXT, "
+ "[delete_account] TEXT, "
+ "[backup_data] TEXT, "
+ "[delete_date] TEXT, "
+ "[is_deleted] INTEGER NOT NULL DEFAULT 0)";
+
+constexpr const char *CREATE_GROUPS =
+ "CREATE TABLE IF NOT EXISTS [groups]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[account_id] INTEGER REFERENCES [account]([id]), "
+ "[group_name] TEXT, "
+ "[group_notes] TEXT, "
+ "[is_deleted] INTEGER NOT NULL DEFAULT 0, "
+ "[group_ringtone] TEXT, "
+ "[ringtone_modify_time] INTEGER NOT NULL DEFAULT 0, "
+ "[lastest_modify_time] INTEGER NOT NULL DEFAULT 0)";
+
+constexpr const char *CREATE_ACCOUNT =
+ "CREATE TABLE IF NOT EXISTS [account]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[account_name] TEXT, "
+ "[account_type] TEXT, "
+ "[data_info] TEXT)";
+
+constexpr const char *CREATE_CONTACT_BLOCKLIST =
+ "CREATE TABLE IF NOT EXISTS [contact_blocklist]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[types] INTEGER NOT NULL DEFAULT 0, "
+ "[phone_number] TEXT, "
+ "[content] TEXT, "
+ "[time_stamp] INTEGER NOT NULL DEFAULT 0)";
+
+constexpr const char *CREATE_SEARCH_CONTACT =
+ "CREATE TABLE IF NOT EXISTS [search_contact]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[account_id] INTEGER REFERENCES [account]([id]), "
+ "[contact_id] INTEGER REFERENCES [contact]([id]), "
+ "[raw_contact_id] INTEGER REFERENCES [raw_contact]([id]), "
+ "[search_name] TEXT, "
+ "[display_name] TEXT, "
+ "[phonetic_name] TEXT, "
+ "[photo_id] TEXT, "
+ "[photo_file_id] INTEGER REFERENCES [photo_files]([id]))";
+
+constexpr const char *CREATE_PHOTO_FILES =
+ "CREATE TABLE IF NOT EXISTS [photo_files]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[file_height] INTEGER NOT NULL DEFAULT 0, "
+ "[file_width] INTEGER NOT NULL DEFAULT 0, "
+ "[file_size] INTEGER NOT NULL DEFAULT 0)";
+
+constexpr const char *CREATE_LOCAL_LANG =
+ "CREATE TABLE IF NOT EXISTS[local_lang]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[local] TEXT)";
+
+constexpr const char *CREATE_DATABASE_BACKUP_TASK =
+ "CREATE TABLE IF NOT EXISTS[database_backup_task]( "
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[backup_time] TEXT, "
+ "[backup_path] TEXT, "
+ "[remarks] TEXT)";
+
+constexpr const char *CREATE_INSERT_BACKUP_TIME =
+ "CREATE TRIGGER [insert_database_backup_task] AFTER INSERT ON [database_backup_task] "
+ " BEGIN "
+ " UPDATE "
+ " [database_backup_task] "
+ " SET "
+ " [backup_time] = STRFTIME ('%s', 'now') "
+ " WHERE "
+ " [id] = [NEW].[id]; "
+ " END ";
+
+constexpr const char *CREATE_CONTACT_INDEX_DATA1 =
+ "CREATE INDEX IF NOT EXISTS [contact_data_type_contact_data_index] "
+ "ON [contact_data] ([type_id],[detail_info])";
+constexpr const char *CREATE_CONTACT_INDEX_DATA2 =
+ "CREATE INDEX IF NOT EXISTS [contact_data_raw_contact_id] "
+ "ON [contact_data] ([raw_contact_id])";
+
+constexpr const char *CREATE_SEARCH_CONTACT_INDEX1 =
+ "CREATE INDEX IF NOT EXISTS [search_contact_id_index] "
+ "ON [search_contact] ([contact_id])";
+constexpr const char *CREATE_SEARCH_CONTACT_INDEX2 =
+ "CREATE INDEX IF NOT EXISTS [search_raw_contact_id_index] "
+ "ON [search_contact] ([raw_contact_id])";
+
+constexpr const char *CREATE_RAW_CONTACT_INDEX =
+ "CREATE INDEX IF NOT EXISTS [raw_contact_id_index] "
+ "ON [raw_contact] ([contact_id])";
+
+constexpr const char *CREATE_VIEW_CONTACT =
+ "CREATE VIEW IF NOT EXISTS[view_contact] AS SELECT "
+ "[contact].[id] AS [id], "
+ "[contact].[photo_id] AS [photo_id], "
+ "[contact].[photo_file_id] AS [photo_file_id], "
+ "[contact].[quick_search_key] AS [quick_search_key], "
+ "[contact].[has_phone_number] AS [has_phone_number], "
+ "[contact].[has_display_name] AS [has_display_name], "
+ "[contact].[has_email] AS [has_email], "
+ "[contact].[has_group] AS [has_group], "
+ "[name_raw_contact_id], "
+ "[name_raw_contact].[account_id] AS [account_id], "
+ "[name_raw_contact].[is_transfer_voicemail] AS [is_transfer_voicemail], "
+ "[name_raw_contact].[personal_ringtone] AS [personal_ringtone], "
+ "[name_raw_contact].[is_deleted] AS [is_deleted], "
+ "[name_raw_contact].[photo_first_name] AS [photo_first_name], "
+ "[name_raw_contact].[version] AS [version], "
+ "[name_raw_contact].[display_name] AS [display_name], "
+ "[name_raw_contact].[sort] AS [sort], "
+ "[name_raw_contact].[contacted_count] AS [contacted_count], "
+ "[name_raw_contact].[lastest_contacted_time] AS [lastest_contacted_time], "
+ "[name_raw_contact].[favorite] AS [favorite], "
+ "[name_raw_contact].[favorite_order] AS [favorite_order], "
+ "[name_raw_contact].[phonetic_name] AS [phonetic_name], "
+ "[name_raw_contact].[phonetic_name_type] AS [phonetic_name_type], "
+ "[name_raw_contact].[company] AS [company], "
+ "[name_raw_contact].[position] AS [position], "
+ "[name_raw_contact].[read_only] AS [read_only], "
+ "[name_raw_contact].[sort_first_letter] AS [sort_first_letter], "
+ "[name_raw_contact].[merge_mode] AS [merge_mode], "
+ "[name_raw_contact].[personal_notification_ringtone] AS [personal_notification_ringtone], "
+ "[name_raw_contact].[is_need_merge] AS [is_need_merge], "
+ "[name_raw_contact].[merge_status] AS [merge_status], "
+ "[name_raw_contact].[is_merge_target] AS [is_merge_target], "
+ "[name_raw_contact].[vibration_setting] AS [vibration_setting], "
+ "[name_raw_contact].[sync_id] AS [sync_id], "
+ "[name_raw_contact].[syn_1] AS [syn_1], "
+ "[name_raw_contact].[syn_2] AS [syn_2], "
+ "[name_raw_contact].[syn_3] AS [syn_3], "
+ "[account].[account_name] AS [account_name], "
+ "[account].[account_type] AS [account_type], "
+ "[photo_files].[file_size] AS [file_size], "
+ "[photo_files].[file_height] AS [file_height], "
+ "[photo_files].[file_width] AS [file_width] "
+ "FROM [contact] "
+ "JOIN [raw_contact] AS [name_raw_contact] "
+ "ON ([name_raw_contact_id] = [name_raw_contact].[id]) "
+ "LEFT JOIN [account] ON "
+ "([name_raw_contact].[account_id] = [account].[id]) "
+ "LEFT JOIN [photo_files] ON "
+ "([photo_files].[id] = [contact].[photo_file_id])";
+
+constexpr const char *CREATE_VIEW_RAW_CONTACT =
+ "CREATE VIEW IF NOT EXISTS [view_raw_contact] AS SELECT "
+ "[contact_id], "
+ "[raw_contact].[id] AS [id], "
+ "[raw_contact].[account_id] AS [account_id], "
+ "[raw_contact].[photo_id] AS [photo_id], "
+ "[raw_contact].[photo_file_id] AS [photo_file_id], "
+ "[raw_contact].[is_transfer_voicemail] AS [is_transfer_voicemail], "
+ "[raw_contact].[personal_ringtone] AS [personal_ringtone], "
+ "[raw_contact].[is_deleted] AS [is_deleted], "
+ "[raw_contact].[photo_first_name] AS [photo_first_name], "
+ "[raw_contact].[version] AS [version], "
+ "[raw_contact].[display_name] AS [display_name], "
+ "[raw_contact].[sort] AS [sort], "
+ "[raw_contact].[contacted_count] AS [contacted_count], "
+ "[raw_contact].[lastest_contacted_time] AS [lastest_contacted_time], "
+ "[raw_contact].[favorite] AS [favorite], "
+ "[raw_contact].[favorite_order] AS [favorite_order], "
+ "[raw_contact].[phonetic_name] AS [phonetic_name], "
+ "[raw_contact].[phonetic_name_type] AS [phonetic_name_type], "
+ "[raw_contact].[company] AS [company], "
+ "[raw_contact].[position] AS [position], "
+ "[raw_contact].[read_only] AS [read_only], "
+ "[raw_contact].[sort_first_letter] AS [sort_first_letter], "
+ "[raw_contact].[merge_mode] AS [merge_mode], "
+ "[raw_contact].[is_need_merge] AS [is_need_merge], "
+ "[raw_contact].[merge_status] AS [merge_status], "
+ "[raw_contact].[is_merge_target] AS [is_merge_target], "
+ "[raw_contact].[vibration_setting] AS [vibration_setting], "
+ "[raw_contact].[sync_id] AS [sync_id], "
+ "[raw_contact].[personal_notification_ringtone] AS [personal_notification_ringtone], "
+ "[raw_contact].[syn_1] AS [syn_1], "
+ "[raw_contact].[syn_2] AS [syn_2], "
+ "[raw_contact].[syn_3] AS [syn_3], "
+ "[photo_files].[file_size] AS [file_size], "
+ "[photo_files].[file_height] AS [file_height], "
+ "[photo_files].[file_width] AS [file_width], "
+ "[account].[account_name] AS [account_name], "
+ "[account].[account_type] AS [account_type] "
+ "FROM [raw_contact] "
+ "LEFT JOIN [account] ON "
+ "([raw_contact].[account_id] = [account].[id]) "
+ "LEFT JOIN [photo_files] ON "
+ "([photo_files].[id] = [photo_file_id])";
+
+constexpr const char *CREATE_VIEW_CONTACT_DATA =
+ "CREATE VIEW IF NOT EXISTS [view_contact_data] AS SELECT "
+ "[contact_data].[id] AS [id], "
+ "[contact_data].[type_id] AS [type_id], "
+ "[contact_data].[raw_contact_id] AS [raw_contact_id], "
+ "[contact_data].[read_only] AS [read_only], "
+ "[contact_data].[version] AS [version], "
+ "[contact_data].[family_name] AS [family_name], "
+ "[contact_data].[middle_name_phonetic] AS [middle_name_phonetic], "
+ "[contact_data].[given_name] AS [given_name], "
+ "[contact_data].[given_name_phonetic] AS [given_name_phonetic], "
+ "[contact_data].[is_preferred_number] AS [is_preferred_number], "
+ "[contact_data].[phonetic_name] AS [phonetic_name], "
+ "[contact_data].[detail_info] AS [detail_info], "
+ "[contact_data].[alias_detail_info] AS [alias_detail_info], "
+ "[contact_data].[position] AS [position], "
+ "[contact_data].[extend1] AS [extend1], "
+ "[contact_data].[extend2] AS [extend2], "
+ "[contact_data].[extend3] AS [extend3], "
+ "[contact_data].[extend4] AS [extend4], "
+ "[contact_data].[alpha_name] AS [alpha_name], "
+ "[contact_data].[other_lan_last_name] AS [other_lan_last_name], "
+ "[contact_data].[other_lan_first_name] AS [other_lan_first_name], "
+ "[contact_data].[extend5] AS [extend5], "
+ "[contact_data].[lan_style] AS [lan_style], "
+ "[contact_data].[custom_data] AS [custom_data], "
+ "[contact_data].[extend6] AS [extend6], "
+ "[contact_data].[extend7] AS [extend7], "
+ "[contact_data].[blob_data] AS [blob_data], "
+ "[contact_data].[syn_1] AS [syn_1], "
+ "[contact_data].[city] AS [city], "
+ "[contact_data].[syn_2] AS [syn_2], "
+ "[contact_data].[syn_3] AS [syn_3], "
+ "[contact_data].[country] AS [country], "
+ "[contact_data].[neighborhood] AS [neighborhood], "
+ "[contact_data].[pobox] AS [pobox], "
+ "[contact_data].[postcode] AS [postcode], "
+ "[contact_data].[region] AS [region], "
+ "[contact_data].[street] AS [street], "
+ "[contact_type].[content_type] AS [content_type], "
+ "[account].[account_name] AS [account_name], "
+ "[account].[account_type] AS [account_type], "
+ "[account].[data_info] AS [data_info], "
+ "[account].[id] AS [account_id], "
+ "[groups].[id] AS [group_id], "
+ "[groups].[group_name] AS [group_name], "
+ "[groups].[group_notes] AS [group_notes], "
+ "[groups].[is_deleted] AS [group_is_deleted], "
+ "[groups].[group_ringtone] AS [group_ringtone], "
+ "[groups].[ringtone_modify_time] AS [ringtone_modify_time], "
+ "[groups].[lastest_modify_time] AS [lastest_modify_time], "
+ "[photo_files].[file_size] AS [file_size], "
+ "[photo_files].[file_height] AS [file_height], "
+ "[photo_files].[file_width] AS [file_width], "
+ "[contact].[id] AS [contact_id], "
+ "[contact].[photo_id] AS [photo_id], "
+ "[contact].[photo_file_id] AS [photo_file_id], "
+ "[contact].[personal_ringtone] AS [personal_ringtone], "
+ "[contact].[is_transfer_voicemail] AS [is_transfer_voicemail], "
+ "[contact].[company] AS [company], "
+ "[contact].[quick_search_key] AS [quick_search_key], "
+ "[contact].[personal_notification_ringtone] AS "
+ "[personal_notification_ringtone], "
+ "[contact].[has_phone_number] AS [has_phone_number], "
+ "[contact].[has_display_name] AS [has_display_name], "
+ "[contact].[has_email] AS [has_email], "
+ "[contact].[has_group] AS [has_group], "
+ "[raw_contact].[contacted_count] AS [contacted_count], "
+ "[raw_contact].[lastest_contacted_time] AS [lastest_contacted_time], "
+ "[raw_contact].[favorite] AS [favorite], "
+ "[raw_contact].[favorite_order] AS [favorite_order], "
+ "[raw_contact].[display_name] AS [display_name], "
+ "[raw_contact].[sort] AS [sort], "
+ "[raw_contact].[sort_first_letter] AS [sort_first_letter], "
+ "[raw_contact].[is_deleted] AS [is_deleted], "
+ "[raw_contact].[phonetic_name_type] AS [phonetic_name_type], "
+ "[raw_contact].[photo_first_name] AS [photo_first_name] "
+ "FROM [contact_data] "
+ "JOIN [raw_contact] ON "
+ "([contact_data].[raw_contact_id] = [raw_contact].[id]) "
+ "JOIN [contact] ON ([contact].[id] = [raw_contact].[contact_id]) "
+ "JOIN [raw_contact] AS [name_raw_contact] ON "
+ "([name_raw_contact_id] = [name_raw_contact].[id]) "
+ "LEFT JOIN [account] ON "
+ "([raw_contact].[account_id] = [account].[id]) "
+ "LEFT JOIN [contact_type] ON "
+ "([contact_type].[id] = [contact_data].[type_id]) "
+ "LEFT JOIN [groups] ON "
+ "([contact_type].[content_type] = 'group_membership' "
+ "AND [groups].[id] = [contact_data].[detail_info]) "
+ "LEFT JOIN [photo_files] ON "
+ "([contact_type].[content_type] = 'photo' "
+ "AND [photo_files].[id] = [raw_contact].[photo_file_id])";
+
+constexpr const char *CREATE_SEARCH_CONTACT_VIEW =
+ "CREATE VIEW IF NOT EXISTS [search_contact_view] AS SELECT "
+ "[search_contact].[id] AS [id], "
+ "[search_contact].[account_id] AS [account_id], "
+ "[search_contact].[contact_id] AS [contact_id], "
+ "[search_contact].[raw_contact_id] AS [raw_contact_id], "
+ "[search_contact].[search_name] AS [search_name], "
+ "[search_contact].[photo_id] AS [photo_id], "
+ "[search_contact].[photo_file_id] AS [photo_file_id], "
+ "[contact_type].[content_type] AS [content_type], "
+ "[account].[account_name] AS [account_name], "
+ "[account].[account_type] AS [account_type], "
+ "[account].[data_info] AS [data_info], "
+ "[groups].[group_name] AS [group_name], "
+ "[groups].[group_notes] AS [group_notes], "
+ "[groups].[is_deleted] AS [group_is_deleted], "
+ "[groups].[group_ringtone] AS [group_ringtone], "
+ "[groups].[ringtone_modify_time] AS [ringtone_modify_time], "
+ "[groups].[lastest_modify_time] AS [lastest_modify_time], "
+ "[photo_files].[file_size] AS [file_size], "
+ "[photo_files].[file_height] AS [file_height], "
+ "[photo_files].[file_width] AS [file_width], "
+ "[contact].[personal_ringtone] AS [personal_ringtone], "
+ "[contact].[is_transfer_voicemail] AS [is_transfer_voicemail], "
+ "[contact].[personal_notification_ringtone] AS "
+ "[personal_notification_ringtone], "
+ "[contact].[has_phone_number] AS [has_phone_number], "
+ "[contact].[has_display_name] AS [has_display_name], "
+ "[contact].[has_email] AS [has_email], "
+ "[contact].[has_group] AS [has_group], "
+ "[raw_contact].[contacted_count] AS [contacted_count], "
+ "[raw_contact].[favorite] AS [favorite], "
+ "[raw_contact].[favorite_order] AS [favorite_order], "
+ "[raw_contact].[display_name] AS [display_name], "
+ "[raw_contact].[lastest_contacted_time] AS [lastest_contacted_time], "
+ "[raw_contact].[sort_first_letter] AS [sort_first_letter], "
+ "[raw_contact].[sort] AS [sort], "
+ "[raw_contact].[photo_first_name] AS [photo_first_name], "
+ "[raw_contact].[personal_notification_ringtone] AS [personal_notification_ringtone], "
+ "[raw_contact].[is_deleted] AS [is_deleted], "
+ "[contact_data].[type_id] AS [type_id], "
+ "[contact_data].[phonetic_name] AS [phonetic_name], "
+ "[contact_data].[raw_contact_id] AS [raw_contact_id], "
+ "[contact_data].[read_only] AS [read_only], "
+ "[contact_data].[version] AS [version], "
+ "[contact_data].[alias_detail_info] AS [alias_detail_info], "
+ "[contact_data].[is_preferred_number] AS [is_preferred_number], "
+ "[contact_data].[detail_info] AS [detail_info], "
+ "[contact_data].[city] AS [city], "
+ "[contact_data].[position] AS [position], "
+ "[contact_data].[middle_name_phonetic] AS [middle_name_phonetic], "
+ "[contact_data].[given_name] AS [given_name], "
+ "[contact_data].[family_name] AS [family_name], "
+ "[contact_data].[given_name_phonetic] AS [given_name_phonetic], "
+ "[contact_data].[country] AS [country], "
+ "[contact_data].[neighborhood] AS [neighborhood], "
+ "[contact_data].[pobox] AS [pobox], "
+ "[contact_data].[postcode] AS [postcode], "
+ "[contact_data].[region] AS [region], "
+ "[contact_data].[street] AS [street], "
+ "[contact_data].[extend1] AS [extend1], "
+ "[contact_data].[extend2] AS [extend2], "
+ "[contact_data].[extend3] AS [extend3], "
+ "[contact_data].[extend4] AS [extend4], "
+ "[contact_data].[alpha_name] AS [alpha_name], "
+ "[contact_data].[other_lan_last_name] AS [other_lan_last_name], "
+ "[contact_data].[other_lan_first_name] AS [other_lan_first_name], "
+ "[contact_data].[extend5] AS [extend5], "
+ "[contact_data].[lan_style] AS [lan_style], "
+ "[contact_data].[custom_data] AS [custom_data], "
+ "[contact_data].[extend6] AS [extend6], "
+ "[contact_data].[extend7] AS [extend7], "
+ "[contact_data].[blob_data] AS [blob_data], "
+ "[contact_data].[syn_1] AS [syn_1], "
+ "[contact_data].[syn_2] AS [syn_2], "
+ "[contact_data].[syn_3] AS [syn_3] "
+ "FROM [search_contact] "
+ "JOIN [raw_contact] ON "
+ "([search_contact].[raw_contact_id] = [raw_contact].[id]) "
+ "JOIN [contact] ON "
+ "([contact].[id] = [raw_contact].[contact_id]) "
+ "JOIN [raw_contact] AS [name_raw_contact] ON "
+ "([name_raw_contact_id] = [name_raw_contact].[id]) "
+ "LEFT JOIN [account] ON "
+ "([search_contact].[account_id] = [account].[id]) "
+ "LEFT JOIN [contact_data] ON "
+ "([contact_data].[raw_contact_id] = [raw_contact].[id]) "
+ "LEFT JOIN [contact_type] ON "
+ "([contact_data].[type_id] = [contact_type].[id]) "
+ "LEFT JOIN [groups] ON "
+ "([contact_type].[content_type] = 'group_membership' "
+ "AND [groups].[id] = [contact_data].[detail_info]) "
+ "LEFT JOIN [photo_files] ON "
+ "([contact_type].[content_type] = 'photo' "
+ "AND [photo_files].[id] = [search_contact].[photo_file_id])";
+
+constexpr const char *CREATE_VIEW_GROUPS =
+ "CREATE VIEW IF NOT EXISTS [view_groups] "
+ "AS SELECT "
+ "[groups].[id] AS [id], "
+ "[groups].[account_id] AS [account_id], "
+ "[account].[account_name] AS [account_name], "
+ "[account].[account_type] AS [account_type], "
+ "[groups].[group_name] AS [group_name] , "
+ "[groups].[group_notes] AS [group_notes] , "
+ "[groups].[is_deleted] AS [is_deleted] , "
+ "[groups].[group_ringtone] AS [group_ringtone], "
+ "[groups].[ringtone_modify_time] AS [ringtone_modify_time] , "
+ "[groups].[lastest_modify_time] AS [lastest_modify_time] "
+ "FROM [groups] "
+ "LEFT JOIN [account] ON ([groups].[account_id] = [account].[id])";
+
+constexpr const char *CREATE_VIEW_DELETED =
+ "CREATE VIEW IF NOT EXISTS [view_deleted] "
+ "AS SELECT "
+ "[deleted_raw_contact].[id] AS [id], "
+ "[contact].[id] AS [contact_id], "
+ "[contact].[photo_id] AS [photo_id], "
+ "[contact].[photo_file_id] AS [photo_file_id], "
+ "[contact].[quick_search_key] AS [quick_search_key], "
+ "[contact].[has_phone_number] AS [has_phone_number], "
+ "[contact].[has_display_name] AS [has_display_name], "
+ "[contact].[has_email] AS [has_email], "
+ "[contact].[has_group] AS [has_group], "
+ "[name_raw_contact].[account_id] AS [account_id], "
+ "[name_raw_contact].[id] AS [raw_contact_id], "
+ "[name_raw_contact].[is_transfer_voicemail] AS [is_transfer_voicemail], "
+ "[name_raw_contact].[personal_ringtone] AS [personal_ringtone], "
+ "[name_raw_contact].[is_deleted] AS [is_deleted], "
+ "[name_raw_contact].[version] AS [version], "
+ "[name_raw_contact].[display_name] AS [display_name], "
+ "[name_raw_contact].[sort] AS [sort], "
+ "[name_raw_contact].[contacted_count] AS [contacted_count], "
+ "[name_raw_contact].[lastest_contacted_time] AS [lastest_contacted_time], "
+ "[name_raw_contact].[favorite] AS [favorite], "
+ "[name_raw_contact].[favorite_order] AS [favorite_order], "
+ "[name_raw_contact].[personal_notification_ringtone] AS [personal_notification_ringtone], "
+ "[name_raw_contact].[phonetic_name] AS [phonetic_name], "
+ "[name_raw_contact].[phonetic_name_type] AS [phonetic_name_type], "
+ "[name_raw_contact].[company] AS [company], "
+ "[name_raw_contact].[position] AS [position], "
+ "[name_raw_contact].[read_only] AS [read_only], "
+ "[name_raw_contact].[sort_first_letter] AS [sort_first_letter], "
+ "[name_raw_contact].[merge_mode] AS [merge_mode], "
+ "[name_raw_contact].[is_need_merge] AS [is_need_merge], "
+ "[name_raw_contact].[merge_status] AS [merge_status], "
+ "[name_raw_contact].[is_merge_target] AS [is_merge_target], "
+ "[name_raw_contact].[vibration_setting] AS [vibration_setting], "
+ "[name_raw_contact].[photo_first_name] AS [photo_first_name], "
+ "[name_raw_contact].[sync_id] AS [sync_id], "
+ "[name_raw_contact].[syn_1] AS [syn_1], "
+ "[name_raw_contact].[syn_2] AS [syn_2], "
+ "[name_raw_contact].[syn_3] AS [syn_3], "
+ "[deleted_raw_contact].[delete_source] AS [delete_source],"
+ "[deleted_raw_contact].[delete_time] AS [delete_time], "
+ "[deleted_raw_contact].[delete_account] AS [delete_account], "
+ "[deleted_raw_contact].[backup_data] AS [backup_data], "
+ "[account].[account_name] AS [account_name], "
+ "[account].[account_type] AS [account_type], "
+ "[photo_files].[file_size] AS [file_size], "
+ "[photo_files].[file_height] AS [file_height], "
+ "[photo_files].[file_width] AS [file_width] "
+ "FROM [deleted_raw_contact] "
+ "LEFT JOIN [contact] ON ([contact].[id] = [deleted_raw_contact].[contact_id]) "
+ "LEFT JOIN [raw_contact] AS [name_raw_contact] ON ([name_raw_contact].[id] = "
+ "[deleted_raw_contact].[raw_contact_id] "
+ "AND [name_raw_contact].[is_deleted] = 1)"
+ "LEFT JOIN [account] ON ([name_raw_contact].[account_id] = [account].[id]) "
+ "LEFT JOIN [photo_files] ON ([photo_files].[id] = [name_raw_contact].[photo_file_id]) ";
+
+constexpr const char *UPDATE_CONTACT_BY_INSERT_CONTACT_DATA =
+ "CREATE TRIGGER IF NOT EXISTS [update_contact_by_insert_contact_data] AFTER INSERT ON [contact_data] FOR EACH ROW "
+ "BEGIN "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_display_name] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 6 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_email] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 1 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_group] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 9 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_phone_number] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 5 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "END";
+
+constexpr const char *UPDATE_CONTACT_BY_DELETE_CONTACT_DATA =
+ "CREATE TRIGGER IF NOT EXISTS [update_contact_by_delete_contact_data] AFTER DELETE ON [contact_data] FOR EACH ROW "
+ "BEGIN "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_display_name] = 0 "
+ "WHERE "
+ "[OLD].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [OLD].[type_id] = 6; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_email] = 0 "
+ "WHERE "
+ "[OLD].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [OLD].[type_id] = 1; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_group] = 0 "
+ "WHERE "
+ "[OLD].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [OLD].[type_id] = 9; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_phone_number] = 0 "
+ "WHERE "
+ "[OLD].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [OLD].[type_id] = 5; "
+ "END";
+
+constexpr const char *UPDATE_CONTACT_BY_UPDATE_CONTACT_DATA =
+ "CREATE TRIGGER IF NOT EXISTS [update_contact_by_update_contact_data] AFTER UPDATE ON [contact_data] FOR EACH ROW "
+ "BEGIN "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_display_name] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 6 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_email] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 1 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_group] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 9 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "UPDATE "
+ "[contact] "
+ "SET "
+ "[has_phone_number] = 1 "
+ "WHERE "
+ "[NEW].[raw_contact_id] = [name_raw_contact_id] "
+ "AND [NEW].[type_id] = 5 "
+ "AND [NEW].[detail_info] IS NOT NULL; "
+ "END";
+
+constexpr const char *INSERT_DELETE_RAW_CONTACT =
+ "CREATE TRIGGER IF NOT EXISTS insert_delete_raw_contact AFTER INSERT ON deleted_raw_contact "
+ "BEGIN "
+ "UPDATE deleted_raw_contact SET delete_time = STRFTIME('%s','now') WHERE id = NEW.id; "
+ "END";
+
+constexpr const char *UPDATE_RAW_CONTACT_VERSION =
+ "CREATE TRIGGER IF NOT EXISTS [update_raw_contact_version] AFTER UPDATE ON [raw_contact] "
+ "BEGIN "
+ "UPDATE "
+ "[raw_contact] "
+ "SET "
+ "[version] = [OLD].[version] + 1 "
+ "WHERE "
+ "[id] = [OLD].[id] AND [NEW].[is_deleted] != [OLD].[is_deleted]; "
+ "END";
+
+constexpr const char *UPDATE_CONTACT_DATA_VERSION =
+ "CREATE TRIGGER IF NOT EXISTS [update_contact_data_version] AFTER UPDATE ON [contact_data] "
+ "BEGIN "
+ "UPDATE "
+ "[contact_data] "
+ "SET "
+ "[version] = [OLD].[version] + 1 "
+ "WHERE "
+ "[id] = [OLD].[id]; "
+ "END";
+
+constexpr const char *INSERT_CONTACT_QUICK_SEARCH =
+ "CREATE TRIGGER IF NOT EXISTS [insert_contact_quick_search]AFTER INSERT ON [contact] BEGIN "
+ "UPDATE [contact] SET [quick_search_key] = [NEW].[id] WHERE [id] = [NEW].[id]; END";
+
+constexpr const char *CALL_LOG_PHONE_NUMBER_INDEX =
+ "CREATE INDEX IF NOT EXISTS [calllog_phone_number_index] ON [calllog] ([phone_number])";
+
+constexpr const char *MERGE_INFO =
+ "CREATE TABLE IF NOT EXISTS [merge_info]("
+ "[id] INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "[raw_contact_id] INTEGER NOT NULL DEFAULT 0 )";
+
+constexpr const char *MERGE_INFO_INDEX =
+ "CREATE INDEX IF NOT EXISTS [merge_info_index] ON [merge_info] ([raw_contact_id])";
+} // namespace Contacts
+} // namespace OHOS
+#endif // COMMON_H
\ No newline at end of file
diff --git a/ability/common/include/contacts_columns.h b/ability/common/include/contacts_columns.h
new file mode 100644
index 0000000..8aad569
--- /dev/null
+++ b/ability/common/include/contacts_columns.h
@@ -0,0 +1,301 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CONTACT_COLUMNS_H
+#define CONTACT_COLUMNS_H
+
+namespace OHOS {
+namespace Contacts {
+class ContactTableName {
+public:
+ ~ContactTableName();
+ static constexpr const char *ACCOUNT = "account";
+ static constexpr const char *CONTACT_TYPE = "contact_type";
+ static constexpr const char *DELETE_RAW_CONTACT = "deleted_raw_contact";
+ static constexpr const char *GROUPS = "groups";
+ static constexpr const char *CONTACT = "contact";
+ static constexpr const char *CONTACT_BLOCKLIST = "contact_blocklist";
+ static constexpr const char *CONTACT_DATA = "contact_data";
+ static constexpr const char *LOCAL_LANG = "local_lang";
+ static constexpr const char *PHOTO_FILES = "photo_files";
+ static constexpr const char *RAW_CONTACT = "raw_contact";
+ static constexpr const char *SEARCH_CONTACT = "search_contact";
+ static constexpr const char *DATABASE_BACKUP_TASK = "database_backup_task";
+ static constexpr const char *MERGE_INFO = "merge_info";
+};
+
+class CallLogColumns {
+public:
+ ~CallLogColumns();
+ static constexpr const char *DISPLAY_NAME = "display_name";
+ static constexpr const char *QUICK_SEARCH_KEY = "quicksearch_key";
+ static constexpr const char *PHONE_NUMBER = "phone_number";
+ static constexpr const char *BEGIN_TIME = "begin_time";
+};
+
+class DatabaseBackupColumns {
+public:
+ ~DatabaseBackupColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *BACKUP_TIME = "backup_time";
+ static constexpr const char *BACKUP_PATH = "backup_path";
+ static constexpr const char *REMARKS = "remarks";
+};
+
+class CallsTableName {
+public:
+ ~CallsTableName();
+ static constexpr const char *CALLLOG = "calllog";
+ static constexpr const char *VOICEMAIL = "voicemail";
+ static constexpr const char *REPLYING = "replying";
+};
+
+class ViewName {
+public:
+ ~ViewName();
+ static constexpr const char *SEARCH_CONTACT_VIEW = "search_contact_view";
+ static constexpr const char *VIEW_CONTACT_DATA = "view_contact_data";
+ static constexpr const char *VIEW_CONTACT = "view_contact";
+ static constexpr const char *VIEW_RAW_CONTACT = "view_raw_contact";
+ static constexpr const char *VIEW_GROUPS = "view_groups";
+ static constexpr const char *VIEW_DELETED = "view_deleted";
+};
+
+class AliasName {
+public:
+ ~AliasName();
+ static constexpr const char *ACCOUNT_DEFAULT = "accountDefault";
+ static constexpr const char *NAME_RAW_CONTACT = "name_raw_contact";
+ static constexpr const char *DATA_ID = "data_id";
+ static constexpr const char *CONTACT = "contact";
+ static constexpr const char *DATA = "data";
+};
+
+class ContactPublicColumns {
+public:
+ ~ContactPublicColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *COUNT = "count";
+};
+
+class AccountColumns {
+public:
+ ~AccountColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *ACCOUNT_NAME = "account_name";
+ static constexpr const char *ACCOUNT_TYPE = "account_type";
+ static constexpr const char *DATA_INFO = "data_info";
+};
+
+class ContentTypeColumns {
+public:
+ ~ContentTypeColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *CONTENT_TYPE = "content_type";
+};
+
+class DeleteRawContactColumns {
+public:
+ ~DeleteRawContactColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *CONTACT_ID = "contact_id";
+ static constexpr const char *RAW_CONTACT_ID = "raw_contact_id";
+ static constexpr const char *DELETE_SOURCE = "delete_source";
+ static constexpr const char *DELETE_TIME = "delete_time";
+ static constexpr const char *DISPLAY_NAME = "display_name";
+ static constexpr const char *DELETE_ACCOUNT = "delete_account";
+ static constexpr const char *BACKUP_DATA = "backup_data";
+ static constexpr const char *DELETE_DATE = "delete_date";
+ static constexpr const char *IS_DELETED = "is_deleted";
+};
+
+class GroupsColumns {
+public:
+ ~GroupsColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *ACCOUNT_ID = "account_id";
+ static constexpr const char *GROUP_NAME = "group_name";
+ static constexpr const char *GROUP_NOTES = "group_notes";
+ static constexpr const char *IS_DELETED = "is_deleted";
+ static constexpr const char *GROUP_RINGTONE = "group_ringtone";
+ static constexpr const char *RINGTONE_MODIFY_TIME = "ringtone_modify_time";
+ static constexpr const char *LASTEST_MODIFY_TIME = "lastest_modify_time";
+};
+
+class ContactColumns {
+public:
+ ~ContactColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *NAME_RAW_CONTACT_ID = "name_raw_contact_id";
+ static constexpr const char *PHOTO_FILE_ID = "photo_file_id";
+ static constexpr const char *PHOTO_ID = "photo_id";
+ static constexpr const char *PERSONAL_RINGTONE = "personal_ringtone";
+ static constexpr const char *IS_TRANSFER_VOICEMAIL = "is_transfer_voicemail";
+ static constexpr const char *COMPANY = "company";
+ static constexpr const char *POSITION = "position";
+ static constexpr const char *QUICK_SEARCH_KEY = "quick_search_key";
+ static constexpr const char *CONTACTED_COUNT = "contacted_count";
+ static constexpr const char *LASTEST_CONTACTED_TIME = "lastest_contacted_time";
+ static constexpr const char *FAVORITE = "favorite";
+ static constexpr const char *FAVORITE_ORDER = "favorite_order";
+ static constexpr const char *READ_ONLY = "read_only";
+ static constexpr const char *PERSONAL_NOTIFICATION_RINGTONE = "personal_notification_ringtone";
+ static constexpr const char *HAS_PHONE_NUMBER = "has_phone_number";
+ static constexpr const char *HAS_DISPLAY_NAME = "has_display_name";
+ static constexpr const char *HAS_EMAIL = "has_email";
+ static constexpr const char *HAS_GROUP = "has_group";
+};
+
+class ContactBlockListColumns {
+public:
+ ~ContactBlockListColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *TYPES = "types";
+ static constexpr const char *PHONE_NUMBER = "phone_number";
+ static constexpr const char *CONTENT = "content";
+ static constexpr const char *TIME_STAMP = "time_stamp";
+};
+
+class ContactDataColumns {
+public:
+ ~ContactDataColumns();
+ static constexpr const char *TYPE_ID = "type_id";
+ static constexpr const char *RAW_CONTACT_ID = "raw_contact_id";
+ static constexpr const char *READ_ONLY = "read_only";
+ static constexpr const char *VERSION = "version";
+ static constexpr const char *IS_PERFERRED_NUMBER = "is_preferred_number";
+ static constexpr const char *DETAIL_INFO = "detail_info";
+ static constexpr const char *POSITION = "position";
+ static constexpr const char *EXTEND1 = "extend1";
+ static constexpr const char *EXTEND2 = "extend2";
+ static constexpr const char *EXTEND3 = "extend3";
+ static constexpr const char *EXTEND4 = "extend4";
+ static constexpr const char *ALPHA_NAME = "alpha_name";
+ static constexpr const char *OTHRE_LAN_LAST_NAME = "other_lan_last_name";
+ static constexpr const char *OTHRE_LAN_FIRST_NAME = "other_lan_first_name";
+ static constexpr const char *EXTEND5 = "extend5";
+ static constexpr const char *PHONETIC_NAME = "phonetic_name";
+ static constexpr const char *LAN_STYLE = "lan_style";
+ static constexpr const char *CUSTOM_DATA = "custom_data";
+ static constexpr const char *EXTEND6 = "extend6";
+ static constexpr const char *EXTEND7 = "extend7";
+ static constexpr const char *BLOB_DATA = "blob_data";
+ static constexpr const char *SYNC_1 = "sync_1";
+ static constexpr const char *SYNC_2 = "sync_2";
+ static constexpr const char *SYNC_3 = "sync_3";
+};
+
+class LocalLanguageColumns {
+public:
+ ~LocalLanguageColumns();
+ static constexpr const char *LOCAL = "local";
+};
+
+class PhotoFilesColumns {
+public:
+ ~PhotoFilesColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *FILE_WIDTH = "file_width";
+ static constexpr const char *FILE_HEIGHT = "file_height";
+ static constexpr const char *FILE_SIZE = "file_size";
+};
+
+class RawContactColumns {
+public:
+ ~RawContactColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *CONTACT_ID = "contact_id";
+ static constexpr const char *PHOTO_ID = "photo_id";
+ static constexpr const char *PHOTO_FILE_ID = "photo_file_id";
+ static constexpr const char *IS_TRANSFER_VOICEMAIL = "is_transfer_voicemail";
+ static constexpr const char *PERSONAL_RINGTONE = "personal_ringtone";
+ static constexpr const char *IS_DELETED = "is_deleted";
+ static constexpr const char *PHOTO_FIRST_NAME = "photo_first_name";
+ static constexpr const char *ACCOUNT_ID = "account_id";
+ static constexpr const char *VERSION = "version";
+ static constexpr const char *DISPLAY_NAME = "display_name";
+ static constexpr const char *SORT = "sort";
+ static constexpr const char *CONTACTED_COUNT = "contacted_count";
+ static constexpr const char *LASTEST_CONTACTED_TIME = "lastest_contacted_time";
+ static constexpr const char *FAVORITE = "favorite";
+ static constexpr const char *FAVORITE_ORDER = "favorite_order";
+ static constexpr const char *PHONETIC_NAME = "phonetic_name";
+ static constexpr const char *PHONETIC_NAME_TYPE = "phonetic_name_type";
+ static constexpr const char *COMPANY = "company";
+ static constexpr const char *POSITION = "position";
+ static constexpr const char *READ_ONLY = "read_only";
+ static constexpr const char *SORT_FIRST_LETTER = "sort_first_letter";
+ static constexpr const char *MERGE_MODE = "merge_mode";
+ static constexpr const char *IS_NEED_MERGE = "is_need_merge";
+ static constexpr const char *MERGE_STATUS = "merge_status";
+ static constexpr const char *IS_MERGE_TARGET = "is_merge_target";
+ static constexpr const char *VIBRATION_SETTING = "vibration_setting";
+ static constexpr const char *SYNC_ID = "sync_id";
+ static constexpr const char *SYNC_1 = "sync_1";
+ static constexpr const char *SYNC_2 = "sync_2";
+ static constexpr const char *SYNC_3 = "sync_3";
+};
+
+class SearchContactColumns {
+public:
+ ~SearchContactColumns();
+ static constexpr const char *ID = "id";
+ static constexpr const char *ACCOUNT_ID = "account_id";
+ static constexpr const char *CONTACT_ID = "contact_id";
+ static constexpr const char *RAW_CONTACT_ID = "raw_contact_id";
+ static constexpr const char *SEARCH_NAME = "search_name";
+ static constexpr const char *DISPLAY_NAME = "display_name";
+ static constexpr const char *PHONETIC_NAME = "phonetic_name";
+ static constexpr const char *FAVORITE = "favorite";
+ static constexpr const char *PHOTO_ID = "photo_id";
+ static constexpr const char *PHOTO_FILE_ID = "photo_file_id";
+};
+
+class AccountData {
+public:
+ ~AccountData();
+ static constexpr const char *ACCOUNT_NAME = "phone";
+ static constexpr const char *ACCOUNT_TYPE = "com.ohos.contacts";
+};
+
+class ContentTypeData {
+public:
+ ~ContentTypeData();
+ static constexpr const char *EMAIL = "email";
+ static constexpr const char *IM = "im";
+ static constexpr const char *NICKNAME = "nickname";
+ static constexpr const char *ORGANIZATION = "organization";
+ static constexpr const char *PHONE = "phone";
+ static constexpr const char *NAME = "name";
+ static constexpr const char *ADDRESS = "postal_address";
+ static constexpr const char *PHOTO = "photo";
+ static constexpr const char *GROUP_MEMBERSHIP = "group_membership";
+ static constexpr const char *NOTE = "note";
+ static constexpr const char *CONTACT_EVENT = "contact_event";
+ static constexpr const char *WEBSITE = "website";
+ static constexpr const char *RELATION = "relation";
+ static constexpr const char *CONTACT_MISC = "contact_misc";
+ static constexpr const char *HICALL_DEVICE = "hicall_device";
+ static constexpr const char *CAMCARD = "camcard";
+ static constexpr const char *SIP_ADDRESS = "sip_address";
+};
+class MergeInfo {
+public:
+ ~MergeInfo();
+ static constexpr const char *RAW_CONTACT_ID = "raw_contact_id";
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // CONTACT_COLUMNS_H
diff --git a/ability/common/include/hilog_wrapper.h b/ability/common/include/hilog_wrapper.h
new file mode 100644
index 0000000..2450a8b
--- /dev/null
+++ b/ability/common/include/hilog_wrapper.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HILOG_WRAPPER_H
+#define HILOG_WRAPPER_H
+
+#define CONFIG_HILOG
+#ifdef CONFIG_HILOG
+
+#include "hilog/log.h"
+
+#ifdef HILOG_FATAL
+#undef HILOG_FATAL
+#endif
+
+#ifdef HILOG_ERROR
+#undef HILOG_ERROR
+#endif
+
+#ifdef HILOG_WARN
+#undef HILOG_WARN
+#endif
+
+#ifdef HILOG_INFO
+#undef HILOG_INFO
+#endif
+
+#ifdef HILOG_DEBUG
+#undef HILOG_DEBUG
+#endif
+
+static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, 0, "ContactsDataAbility===>"};
+
+#define HILOG_FATAL(...) (void)OHOS::HiviewDFX::HiLog::Fatal(LOG_LABEL, __VA_ARGS__)
+#define HILOG_ERROR(...) (void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, __VA_ARGS__)
+#define HILOG_WARN(...) (void)OHOS::HiviewDFX::HiLog::Warn(LOG_LABEL, __VA_ARGS__)
+#define HILOG_INFO(...) (void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, __VA_ARGS__)
+#define HILOG_DEBUG(...) (void)OHOS::HiviewDFX::HiLog::Debug(LOG_LABEL, __VA_ARGS__)
+#else
+
+#define HILOG_FATAL(...)
+#define HILOG_ERROR(...)
+#define HILOG_WARN(...)
+#define HILOG_INFO(...)
+#define HILOG_DEBUG(...)
+
+#endif // CONFIG_HILOG
+
+#endif // HILOG_WRAPPER_H
\ No newline at end of file
diff --git a/ability/common/utils/include/async_task.h b/ability/common/utils/include/async_task.h
new file mode 100644
index 0000000..016187b
--- /dev/null
+++ b/ability/common/utils/include/async_task.h
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CONTACTSDATAABILITY_ASYNC_TASK_H
+#define CONTACTSDATAABILITY_ASYNC_TASK_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "common.h"
+#include "contacts_database.h"
+#include "contacts_update_helper.h"
+#include "hilog_wrapper.h"
+#include "match_candidate.h"
+
+namespace OHOS {
+namespace Contacts {
+class AsyncItem {
+public:
+ virtual ~AsyncItem()
+ {
+ }
+
+ virtual void Run() = 0;
+};
+
+class AsyncTaskMutex {
+public:
+ void lock()
+ {
+ while (flag.test_and_set(std::memory_order_acquire))
+ ;
+ }
+
+ void unlock()
+ {
+ flag.clear(std::memory_order_release);
+ }
+
+private:
+ std::atomic_flag flag = ATOMIC_FLAG_INIT;
+};
+
+class AsyncTaskQueue {
+public:
+ // single instance
+ static AsyncTaskQueue *Instance()
+ {
+ static AsyncTaskQueue obj;
+ return &obj;
+ }
+
+public:
+ // clear task
+ void Clear()
+ {
+ std::lock_guard lk(mtx);
+ while (que.size() > 0)
+ que.pop();
+ }
+
+ // que empty
+ bool Empty() const
+ {
+ std::lock_guard lk(mtx);
+ return que.empty();
+ }
+
+ size_t Size() const
+ {
+ std::lock_guard lk(mtx);
+ return que.size();
+ }
+
+ size_t GetThreads() const
+ {
+ return threads;
+ }
+
+ bool Push(AsyncItem *item)
+ {
+ std::lock_guard lk(mtx);
+ if (maxSize > 0 && que.size() >= maxSize) {
+ HILOG_ERROR("AsyncTask maxSize error");
+ return false;
+ }
+ que.push(item);
+ return true;
+ }
+
+ // startTask
+ void Start(size_t threads = 1, size_t maxSize = 1000000)
+ {
+ if (this->threads > 0) {
+ return;
+ }
+ this->threads = threads;
+ this->maxSize = maxSize;
+ for (size_t i = 0; i < this->threads; i++) {
+ std::thread(std::bind(&AsyncTaskQueue::Run, this)).detach();
+ }
+ }
+
+public:
+ void Run()
+ {
+ AsyncItem *item = nullptr;
+ while (this->threads > 0) {
+ if (Pop(&item)) {
+ if (item != nullptr) {
+ item->Run();
+ delete item;
+ item = nullptr;
+ }
+ } else {
+ std::chrono::milliseconds dura(1);
+ std::this_thread::sleep_for(dura);
+ }
+ }
+ }
+
+private:
+ size_t maxSize;
+ size_t threads;
+ mutable AsyncTaskMutex mtx;
+ std::queue que;
+ AsyncTaskQueue()
+ {
+ this->maxSize = 0;
+ }
+
+ bool Pop(AsyncItem **item)
+ {
+ std::lock_guard lk(mtx);
+ if (que.empty()) {
+ return false;
+ }
+ *item = que.front();
+ que.pop();
+ return true;
+ }
+};
+
+// impl run
+class AsyncTask : public AsyncItem {
+ std::shared_ptr store;
+ std::vector rawContactIdVector;
+ bool isDeleted;
+
+public:
+ void Run()
+ {
+ ContactsUpdateHelper contactsUpdateHelper;
+ contactsUpdateHelper.UpdateCallLogByPhoneNum(rawContactIdVector, store, isDeleted);
+ std::shared_ptr contactsDataBase = ContactsDataBase::GetInstance();
+ contactsDataBase->InsertMergeData(store, rawContactIdVector);
+ contactsDataBase->MarkMerge(store);
+ }
+
+public:
+ AsyncTask(std::shared_ptr &store, std::vector &rawContactIdVector, bool isDeleted)
+ {
+ this->store = store;
+ this->rawContactIdVector = rawContactIdVector;
+ this->isDeleted = isDeleted;
+ }
+
+public:
+ AsyncTask()
+ {
+ }
+};
+
+class AsyncDeleteContactsTask : public AsyncItem {
+ std::vector queryValuesBucket;
+ std::shared_ptr store;
+
+public:
+ void Run()
+ {
+ std::shared_ptr contactsDataBase = ContactsDataBase::GetInstance();
+ contactsDataBase->DeleteRecordInsert(store, queryValuesBucket);
+ }
+
+public:
+ AsyncDeleteContactsTask(std::shared_ptr &store,
+ std::vector &queryValuesBucket)
+ {
+ this->queryValuesBucket = queryValuesBucket;
+ this->store = store;
+ }
+
+public:
+ AsyncDeleteContactsTask()
+ {
+ }
+};
+} // namespace Contacts
+} // namespace OHOS
+
+#endif // CONTACTSDATAABILITY_ASYNC_TASK_H
diff --git a/ability/common/utils/include/contacts_common_event.h b/ability/common/utils/include/contacts_common_event.h
new file mode 100644
index 0000000..7e1245e
--- /dev/null
+++ b/ability/common/utils/include/contacts_common_event.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CONTACT_COMMON_EVENT_H
+#define CONTACT_COMMON_EVENT_H
+
+#include "common_event_manager.h"
+#include "common_event_subscriber.h"
+#include "hilog_wrapper.h"
+
+namespace OHOS {
+namespace Contacts {
+constexpr const char *CONTACT_EVENT = "com.ohos.contactsdataability";
+constexpr const char *CALL_LOG_EVENT = "com.ohos.calllogability";
+constexpr const char *VOICEMAIL_EVENT = "com.ohos.voicemailability";
+constexpr int CONTACT_EVENT_CODE = 10000;
+constexpr int CALL_LOG_EVENT_CODE = 20000;
+constexpr int VOICEMAIL_EVENT_CODE = 30000;
+
+// action
+constexpr int CONTACT_INSERT = 0;
+constexpr int CONTACT_UPDATE = 1;
+constexpr int CONTACT_DELETE = 2;
+
+class ContactsCommonEvent : public OHOS::EventFwk::CommonEventSubscriber {
+public:
+ ContactsCommonEvent(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo)
+ : CommonEventSubscriber(subscriberInfo)
+ {
+ }
+ ~ContactsCommonEvent() = default;
+ static std::shared_ptr subscriber;
+ void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data);
+ static bool PublishContactEvent(const OHOS::AAFwk::Want &want, int eventCode, const std::string &eventData);
+ static void UnregisterSubscriber(std::shared_ptr subscriber);
+ static void RegisterSubscriber();
+ static void SendContactChange(int actionCode);
+ static void SendCallLogChange(int actionCode);
+ static void SendVoiceMailChange(int actionCode);
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // CONTACT_COMMON_EVENT_H
\ No newline at end of file
diff --git a/ability/common/utils/include/contacts_json_utils.h b/ability/common/utils/include/contacts_json_utils.h
new file mode 100644
index 0000000..3a992d6
--- /dev/null
+++ b/ability/common/utils/include/contacts_json_utils.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CONTACT_JSON_UTILS_H
+#define CONTACT_JSON_UTILS_H
+
+#include
+
+#include "json.h"
+#include "json_utils.h"
+#include "rdb_errno.h"
+#include "rdb_open_callback.h"
+#include "result_set.h"
+
+namespace OHOS {
+namespace Contacts {
+class ContactsJsonUtils {
+public:
+ ContactsJsonUtils();
+ ~ContactsJsonUtils();
+ std::string GetDeleteData(std::unique_ptr &resultSet);
+ void ConvertResultSet(Json::Value &arrayValue, std::unique_ptr &resultSet);
+ void GetValue(std::vector &columnNames, int &index, Json::Value &data,
+ std::unique_ptr &resultSet);
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // CONTACT_JSON_UTILS_H
diff --git a/ability/common/utils/include/contacts_path.h b/ability/common/utils/include/contacts_path.h
new file mode 100644
index 0000000..4a66af5
--- /dev/null
+++ b/ability/common/utils/include/contacts_path.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CONTACTSDATAABILITY_CONTACT_PATH_H
+#define CONTACTSDATAABILITY_CONTACT_PATH_H
+
+#include
+
+namespace OHOS {
+namespace Contacts {
+class ContactsPath {
+public:
+ ContactsPath();
+ ~ContactsPath();
+ static std::string RDB_PATH;
+ static std::string RDB_BACKUP_PATH;
+ static std::string DUMP_PATH;
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // CONTACTSDATAABILITY_CONTACT_PATH_H
diff --git a/ability/common/utils/include/contacts_string_utils.h b/ability/common/utils/include/contacts_string_utils.h
new file mode 100644
index 0000000..4f8df18
--- /dev/null
+++ b/ability/common/utils/include/contacts_string_utils.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CONTACT_STRING_UTILS_H
+#define CONTACT_STRING_UTILS_H
+
+#include
+#include
+
+namespace OHOS {
+namespace Contacts {
+class ContactsStringUtils {
+public:
+ ContactsStringUtils();
+ ~ContactsStringUtils();
+ static std::string &Trim(std::string &str);
+ static std::vector SplitStr(std::string str, std::string spSymbol);
+};
+} // namespace Contacts
+} // namespace OHOS
+
+#endif // STRING_UTILS_H
\ No newline at end of file
diff --git a/ability/common/utils/include/file_utils.h b/ability/common/utils/include/file_utils.h
new file mode 100644
index 0000000..a78b1a2
--- /dev/null
+++ b/ability/common/utils/include/file_utils.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef FILE_UTILS_H
+#define FILE_UTILS_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace OHOS {
+namespace Contacts {
+class FileUtils {
+public:
+ FileUtils();
+ ~FileUtils();
+ int IsFolderExist(std::string path);
+ void Mkdir(std::string path);
+ void WriteStringToFileAppend(std::string dirStr, const std::string str);
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // FILE_UTILS_H
\ No newline at end of file
diff --git a/ability/common/utils/include/merge_utils.h b/ability/common/utils/include/merge_utils.h
new file mode 100644
index 0000000..d8ec4fb
--- /dev/null
+++ b/ability/common/utils/include/merge_utils.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MERGE_UTILS_H
+#define MERGE_UTILS_H
+
+#include "candidate.h"
+#include "common.h"
+#include "contacts_columns.h"
+#include "hilog_wrapper.h"
+#include "rdb_errno.h"
+#include "rdb_store.h"
+#include "result_set.h"
+
+namespace OHOS {
+namespace Contacts {
+class MergeUtils {
+public:
+ MergeUtils();
+ ~MergeUtils();
+ std::set QueryRawContactByType(
+ std::shared_ptr store, int rawId, int typeId);
+ std::set QueryDataDetailInfo(
+ std::shared_ptr store, std::set &rawIds, int typeId);
+ std::set QueryDataExecute(
+ std::shared_ptr store, std::set rawIds, int typeId);
+ std::vector QueryByDataName(
+ int rawId, std::set data, std::shared_ptr store);
+ bool SetEqual(std::set setLeft, std::set setRight);
+ void AddHasJudgeForRawId(
+ std::shared_ptr store, int rawId, OHOS::NativeRdb::ValuesBucket &value);
+ void GetRawIdsByRawId(std::shared_ptr store, int rawId, std::set &rawIds);
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // MERGE_UTILS_H
diff --git a/ability/common/utils/include/predicates_convert.h b/ability/common/utils/include/predicates_convert.h
new file mode 100644
index 0000000..3a5d4b5
--- /dev/null
+++ b/ability/common/utils/include/predicates_convert.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PREDICATES_CONVERT_H
+#define PREDICATES_CONVERT_H
+
+#include "data_ability_predicates.h"
+#include "predicates_utils.h"
+#include "rdb_predicates.h"
+
+namespace OHOS {
+namespace Contacts {
+class PredicatesConvert {
+public:
+ PredicatesConvert();
+ ~PredicatesConvert();
+ OHOS::NativeRdb::RdbPredicates ConvertPredicates(
+ std::string tableName, OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates);
+ OHOS::NativeRdb::RdbPredicates CopyPredicates(
+ std::string tableName, OHOS::NativeRdb::RdbPredicates &oldRdbPredicates);
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // PREDICATES_CONVERT_H
\ No newline at end of file
diff --git a/ability/common/utils/include/sql_analyzer.h b/ability/common/utils/include/sql_analyzer.h
new file mode 100644
index 0000000..387b063
--- /dev/null
+++ b/ability/common/utils/include/sql_analyzer.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SQL_ANALYZER_H
+#define SQL_ANALYZER_H
+
+#include
+
+#include "values_bucket.h"
+
+#include "common.h"
+
+namespace OHOS {
+namespace Contacts {
+class SqlAnalyzer {
+public:
+ SqlAnalyzer();
+ ~SqlAnalyzer();
+
+ bool CheckValuesBucket(const NativeRdb::ValuesBucket &value);
+ bool FindIllegalWords(std::string sql);
+ bool StrCheck(char &ch, std::size_t strlen, std::string sql, std::size_t &pos);
+ bool CharCheck(char &ch, std::string sql, std::size_t &pos);
+
+private:
+ inline bool IsNumber(char ch)
+ {
+ return (ch >= '0' && ch <= '9');
+ }
+ inline bool IsLetter(char ch)
+ {
+ return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_');
+ }
+ inline bool IsLetterNumber(char ch)
+ {
+ return IsNumber(ch) || IsLetter(ch);
+ }
+ inline char PickChar(std::string str, std::size_t index)
+ {
+ if (index < str.length()) {
+ return str.at(index);
+ }
+ return '\0';
+ }
+ inline int IsInStr(char ch, std::string str)
+ {
+ std::size_t pos = str.find(ch);
+ if (pos == std::string::npos) {
+ return OPERATION_ERROR;
+ }
+ return 0;
+ }
+};
+} // namespace Contacts
+} // namespace OHOS
+#endif // SQL_ANALYZER_H
diff --git a/ability/common/utils/include/uri_utils.h b/ability/common/utils/include/uri_utils.h
new file mode 100644
index 0000000..dca8006
--- /dev/null
+++ b/ability/common/utils/include/uri_utils.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef URI_UTILS_H
+#define URI_UTILS_H
+
+#include "uri.h"
+
+#include