mirror of
https://github.com/openharmony/applications_contacts_data.git
synced 2026-07-01 10:24:31 -04:00
@@ -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 }}}
|
||||
@@ -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
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 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.
|
||||
|
||||
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
|
||||
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile></licensefile>
|
||||
<policylist>
|
||||
<policy name="projectPolicy" desc="">
|
||||
</policy>
|
||||
</policylist>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<filteritem type="filename" name="*.cfg" desc="The JSON format does not support comments."/>
|
||||
</filefilter>
|
||||
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
|
||||
<filteritem type="filename" name="*.cfg" desc="The JSON format does not support comments."/>
|
||||
</filefilter>
|
||||
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
|
||||
</filefilter>
|
||||
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
|
||||
</filefilter>
|
||||
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
|
||||
<filteritem type="filename" name="*.png" desc="Image for markdown doc"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
<licensematcherlist>
|
||||
</licensematcherlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
+34
-26
@@ -1,36 +1,44 @@
|
||||
# applications_contactsdata
|
||||
# applications_contactsdata<a name="ZH-CN_TOPIC_0000001122925147"></a>
|
||||
|
||||
#### 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<a name="section1166054159366"></a>
|
||||
|
||||
#### 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<a name="section1619419895966"></a>
|
||||
|
||||
#### Instructions
|
||||

|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
#### 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<a name="section1371113476307"></a>
|
||||
|
||||
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
|
||||
@@ -1,39 +1,521 @@
|
||||
# 联系人数据库子系统
|
||||
# applications_contactsdata
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
- [简介](#section1166054159366)
|
||||
- [架构图](#section1619419895966)
|
||||
- [目录](#section161941989596)
|
||||
- [相关仓](#section1371113476307)
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
## 简介<a name="section1166054159366"></a>
|
||||
|
||||
联系人数据库应用是每一个用户管理联系人数据库的不可缺少的一个管理信息应用,
|
||||
它的内容对于用户管理者来说是至关重要的,所以联系人数据库应该能够为每一个
|
||||
用户的管理提供充足的信息和快捷查询手段,大大方便用户合理的管理联系人数据库信息。
|
||||
|
||||
#### 安装教程
|
||||
## 架构图<a name="section1619419895966"></a>
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||

|
||||
|
||||
#### 使用说明
|
||||
## 目录<a name="section161941989596"></a>
|
||||
|
||||
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 |
|
||||
## 相关仓<a name="section1371113476307"></a>
|
||||
|
||||
系统应用
|
||||
|
||||
applications_contactsdata
|
||||
@@ -0,0 +1,4 @@
|
||||
# Ignore everything in this directory
|
||||
..
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -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
|
||||
@@ -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 <string>
|
||||
|
||||
#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<OHOS::AccountSA::OhosAccountInfo> 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
|
||||
@@ -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 <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class AccountEventManager {
|
||||
public:
|
||||
static std::shared_ptr<AccountEventManager> GetInstance();
|
||||
~AccountEventManager();
|
||||
void PublishEvent(std::string data);
|
||||
void SubscriberAccountEvent();
|
||||
|
||||
private:
|
||||
static std::shared_ptr<AccountEventManager> instance_;
|
||||
const static std::string EVENT;
|
||||
AccountEventManager();
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // ACCOUNT_EVENT_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
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<AccountSync> GetInstance();
|
||||
static std::shared_ptr<ContactsDataBase> contactsDataBase_;
|
||||
static std::shared_ptr<ProfileDatabase> profileDataBase_;
|
||||
// Update account synchronously
|
||||
void SyncUpdateAccount(std::vector<OHOS::AccountSA::OhosAccountInfo> sysAccounts, bool isProfile);
|
||||
|
||||
private:
|
||||
AccountSync();
|
||||
static std::shared_ptr<AccountSync> instance_;
|
||||
int ClearData(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int accountId);
|
||||
void getShouldUpdateAndAddAccounts(std::vector<OHOS::AccountSA::OhosAccountInfo> systemAccounts,
|
||||
std::vector<AccountDataCollection> localAccounts,
|
||||
std::vector<OHOS::AccountSA::OhosAccountInfo> &shouldUpdateAccounts,
|
||||
std::vector<OHOS::AccountSA::OhosAccountInfo> &shouldAddAccounts);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // ACCOUNT_SYNC_H
|
||||
@@ -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 = AccountSync::GetInstance();
|
||||
std::vector<OHOS::AccountSA::OhosAccountInfo> sysAccounts;
|
||||
std::vector<std::string> accountObjVec = ContactsStringUtils::SplitStr(data.GetData(), SPLIT_SYMBOL_VERTICAL);
|
||||
for (size_t i = 0; i < accountObjVec.size(); i++) {
|
||||
std::vector<std::string> 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
|
||||
@@ -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 <vector>
|
||||
|
||||
#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<OHOS::AccountSA::OhosAccountInfo> 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
|
||||
@@ -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 <mutex>
|
||||
|
||||
#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> AccountEventManager::instance_ = nullptr;
|
||||
|
||||
AccountEventManager::AccountEventManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
AccountEventManager::~AccountEventManager()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<AccountEventManager> 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<AccountChangeEvent> subscriber = std::make_shared<AccountChangeEvent>(subscriberInfo);
|
||||
OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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 = ContactsAccount::GetInstance();
|
||||
int accountId = contactsAccount->LookupAccountTypeId(
|
||||
ContactsDataBase::store_, AccountData::ACCOUNT_NAME, AccountData::ACCOUNT_TYPE);
|
||||
return accountId;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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 <mutex>
|
||||
|
||||
#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<ContactsDataBase> AccountSync::contactsDataBase_ = nullptr;
|
||||
std::shared_ptr<ProfileDatabase> AccountSync::profileDataBase_ = nullptr;
|
||||
std::shared_ptr<AccountSync> AccountSync::instance_ = nullptr;
|
||||
std::shared_ptr<ContactsAccount> g_contactsAccount = nullptr;
|
||||
|
||||
std::shared_ptr<AccountSync> 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<OHOS::AccountSA::OhosAccountInfo> systemAccounts,
|
||||
std::vector<AccountDataCollection> localAccounts,
|
||||
std::vector<OHOS::AccountSA::OhosAccountInfo> &shouldUpdateAccounts,
|
||||
std::vector<OHOS::AccountSA::OhosAccountInfo> &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<OHOS::AccountSA::OhosAccountInfo> sysAccounts, bool isProfile)
|
||||
{
|
||||
g_mtx.lock();
|
||||
if (sysAccounts.empty()) {
|
||||
HILOG_ERROR("AccountSync::SyncUpdateAccount sysAccounts is null");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> 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<AccountDataCollection> accounts = g_contactsAccount->GetAccountFromLoacl(store);
|
||||
std::vector<AccountDataCollection> notInSysAccounts;
|
||||
std::vector<AccountDataCollection> 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<OHOS::AccountSA::OhosAccountInfo> shouldUpdateAccounts;
|
||||
std::vector<OHOS::AccountSA::OhosAccountInfo> 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<OHOS::NativeRdb::RdbStore> 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
|
||||
@@ -0,0 +1,4 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
@@ -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 <string>
|
||||
|
||||
#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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 <atomic>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#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<AsyncTaskMutex> lk(mtx);
|
||||
while (que.size() > 0)
|
||||
que.pop();
|
||||
}
|
||||
|
||||
// que empty
|
||||
bool Empty() const
|
||||
{
|
||||
std::lock_guard<AsyncTaskMutex> lk(mtx);
|
||||
return que.empty();
|
||||
}
|
||||
|
||||
size_t Size() const
|
||||
{
|
||||
std::lock_guard<AsyncTaskMutex> lk(mtx);
|
||||
return que.size();
|
||||
}
|
||||
|
||||
size_t GetThreads() const
|
||||
{
|
||||
return threads;
|
||||
}
|
||||
|
||||
bool Push(AsyncItem *item)
|
||||
{
|
||||
std::lock_guard<AsyncTaskMutex> 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<AsyncItem *> que;
|
||||
AsyncTaskQueue()
|
||||
{
|
||||
this->maxSize = 0;
|
||||
}
|
||||
|
||||
bool Pop(AsyncItem **item)
|
||||
{
|
||||
std::lock_guard<AsyncTaskMutex> lk(mtx);
|
||||
if (que.empty()) {
|
||||
return false;
|
||||
}
|
||||
*item = que.front();
|
||||
que.pop();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// impl run
|
||||
class AsyncTask : public AsyncItem {
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store;
|
||||
std::vector<int> rawContactIdVector;
|
||||
bool isDeleted;
|
||||
|
||||
public:
|
||||
void Run()
|
||||
{
|
||||
ContactsUpdateHelper contactsUpdateHelper;
|
||||
contactsUpdateHelper.UpdateCallLogByPhoneNum(rawContactIdVector, store, isDeleted);
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
contactsDataBase->InsertMergeData(store, rawContactIdVector);
|
||||
contactsDataBase->MarkMerge(store);
|
||||
}
|
||||
|
||||
public:
|
||||
AsyncTask(std::shared_ptr<OHOS::NativeRdb::RdbStore> &store, std::vector<int> &rawContactIdVector, bool isDeleted)
|
||||
{
|
||||
this->store = store;
|
||||
this->rawContactIdVector = rawContactIdVector;
|
||||
this->isDeleted = isDeleted;
|
||||
}
|
||||
|
||||
public:
|
||||
AsyncTask()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class AsyncDeleteContactsTask : public AsyncItem {
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> queryValuesBucket;
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store;
|
||||
|
||||
public:
|
||||
void Run()
|
||||
{
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
contactsDataBase->DeleteRecordInsert(store, queryValuesBucket);
|
||||
}
|
||||
|
||||
public:
|
||||
AsyncDeleteContactsTask(std::shared_ptr<OHOS::NativeRdb::RdbStore> &store,
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> &queryValuesBucket)
|
||||
{
|
||||
this->queryValuesBucket = queryValuesBucket;
|
||||
this->store = store;
|
||||
}
|
||||
|
||||
public:
|
||||
AsyncDeleteContactsTask()
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // CONTACTSDATAABILITY_ASYNC_TASK_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<ContactsCommonEvent> 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<OHOS::EventFwk::CommonEventSubscriber> 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
|
||||
@@ -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 <string>
|
||||
|
||||
#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<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertResultSet(Json::Value &arrayValue, std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void GetValue(std::vector<std::string> &columnNames, int &index, Json::Value &data,
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_JSON_UTILS_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 <string>
|
||||
|
||||
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
|
||||
@@ -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 <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ContactsStringUtils {
|
||||
public:
|
||||
ContactsStringUtils();
|
||||
~ContactsStringUtils();
|
||||
static std::string &Trim(std::string &str);
|
||||
static std::vector<std::string> SplitStr(std::string str, std::string spSymbol);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // STRING_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 <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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
|
||||
@@ -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<std::string> QueryRawContactByType(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, int typeId);
|
||||
std::set<std::string> QueryDataDetailInfo(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> &rawIds, int typeId);
|
||||
std::set<std::string> QueryDataExecute(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> rawIds, int typeId);
|
||||
std::vector<int> QueryByDataName(
|
||||
int rawId, std::set<std::string> data, std::shared_ptr<OHOS::NativeRdb::RdbStore> store);
|
||||
bool SetEqual(std::set<std::string> setLeft, std::set<std::string> setRight);
|
||||
void AddHasJudgeForRawId(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, OHOS::NativeRdb::ValuesBucket &value);
|
||||
void GetRawIdsByRawId(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, std::set<int> &rawIds);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // MERGE_UTILS_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
|
||||
@@ -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 <string>
|
||||
|
||||
#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
|
||||
@@ -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 <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class UriUtils {
|
||||
public:
|
||||
UriUtils();
|
||||
~UriUtils();
|
||||
std::vector<std::string> split(const std::string &str, const std::string &split);
|
||||
std::map<std::string, std::string> getQueryParameter(OHOS::Uri &uri);
|
||||
int UriParse(OHOS::Uri &uri, std::map<std::string, int> &keyMap);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // URI_UTILS_H
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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 "contacts_common_event.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
std::shared_ptr<ContactsCommonEvent> ContactsCommonEvent::subscriber = nullptr;
|
||||
|
||||
void ContactsCommonEvent::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
|
||||
{
|
||||
OHOS::AAFwk::Want want = data.GetWant();
|
||||
std::string action = data.GetWant().GetAction();
|
||||
HILOG_INFO("ContactsCommonEvent::OnReceiveEvent action = %{public}s", action.c_str());
|
||||
int msgCode = data.GetCode();
|
||||
std::string msgData = data.GetData();
|
||||
HILOG_INFO("ContactsCommonEvent::OnReceiveEvent msgData = %{public}s", msgData.c_str());
|
||||
HILOG_INFO("ContactsCommonEvent::OnReceiveEvent msgCode = %{public}d", msgCode);
|
||||
}
|
||||
|
||||
bool ContactsCommonEvent::PublishContactEvent(
|
||||
const OHOS::AAFwk::Want &want, int eventCode, const std::string &eventData)
|
||||
{
|
||||
OHOS::EventFwk::CommonEventData data;
|
||||
data.SetWant(want);
|
||||
data.SetCode(eventCode);
|
||||
data.SetData(eventData);
|
||||
OHOS::EventFwk::CommonEventPublishInfo publishInfo;
|
||||
publishInfo.SetOrdered(true);
|
||||
bool publishResult = OHOS::EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
|
||||
HILOG_INFO("PublishContactEvent end publishResult = %{public}d", publishResult);
|
||||
return publishResult;
|
||||
}
|
||||
|
||||
void ContactsCommonEvent::UnregisterSubscriber(std::shared_ptr<OHOS::EventFwk::CommonEventSubscriber> subscriber)
|
||||
{
|
||||
if (subscriber != nullptr) {
|
||||
bool subscribeResult = OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriber);
|
||||
subscriber = nullptr;
|
||||
HILOG_INFO("UnregisterSubscriber contacts end###subscribeResult = %{public}d", subscribeResult);
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsCommonEvent::RegisterSubscriber()
|
||||
{
|
||||
OHOS::EventFwk::MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(CONTACT_EVENT);
|
||||
matchingSkills.AddEvent(CALL_LOG_EVENT);
|
||||
matchingSkills.AddEvent(VOICEMAIL_EVENT);
|
||||
OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
subscriber = std::make_shared<ContactsCommonEvent>(subscriberInfo);
|
||||
bool subscribeResult = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
|
||||
HILOG_INFO("RegisterSubscriber contacts end###subscribeResult = %{public}d", subscribeResult);
|
||||
}
|
||||
|
||||
void ContactsCommonEvent::SendContactChange(int actionCode)
|
||||
{
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t eventCode = CONTACT_EVENT_CODE;
|
||||
want.SetParam("contactsActionCode", actionCode);
|
||||
want.SetAction(CONTACT_EVENT);
|
||||
std::string eventData("ContactChange");
|
||||
PublishContactEvent(want, eventCode, eventData);
|
||||
}
|
||||
|
||||
void ContactsCommonEvent::SendCallLogChange(int actionCode)
|
||||
{
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t eventCode = CALL_LOG_EVENT_CODE;
|
||||
want.SetParam("contactsActionCode", actionCode);
|
||||
want.SetAction(CALL_LOG_EVENT);
|
||||
std::string eventData("CallLogChange");
|
||||
PublishContactEvent(want, eventCode, eventData);
|
||||
}
|
||||
|
||||
void ContactsCommonEvent::SendVoiceMailChange(int actionCode)
|
||||
{
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t eventCode = VOICEMAIL_EVENT_CODE;
|
||||
want.SetParam("contactsActionCode", actionCode);
|
||||
want.SetAction(VOICEMAIL_EVENT);
|
||||
std::string eventData("voicemailChange");
|
||||
PublishContactEvent(want, eventCode, eventData);
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 "contacts_json_utils.h"
|
||||
|
||||
#include "contacts_columns.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
ContactsJsonUtils::ContactsJsonUtils(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsJsonUtils::~ContactsJsonUtils()
|
||||
{
|
||||
}
|
||||
|
||||
std::string ContactsJsonUtils::GetDeleteData(std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
Json::Value dataResult;
|
||||
Json::Value arrayValue;
|
||||
ConvertResultSet(arrayValue, resultSet);
|
||||
dataResult[AliasName::DATA] = arrayValue;
|
||||
Json::StreamWriterBuilder builder;
|
||||
const std::string personal_ringtone = Json::writeString(builder, dataResult);
|
||||
return personal_ringtone;
|
||||
}
|
||||
|
||||
void ContactsJsonUtils::ConvertResultSet(
|
||||
Json::Value &arrayValue, std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
std::vector<std::string> columnNames;
|
||||
resultSet->GetAllColumnNames(columnNames);
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
Json::Value data;
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
GetValue(columnNames, i, data, resultSet);
|
||||
}
|
||||
arrayValue.append(data);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsJsonUtils::GetValue(std::vector<std::string> &columnNames, int &index, Json::Value &data,
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
std::string typeValue = columnNames[index];
|
||||
int columnIndex;
|
||||
resultSet->GetColumnIndex(typeValue, columnIndex);
|
||||
OHOS::NativeRdb::ColumnType columnType;
|
||||
resultSet->GetColumnType(columnIndex, columnType);
|
||||
if (columnType == OHOS::NativeRdb::ColumnType::TYPE_INTEGER) {
|
||||
int intValue;
|
||||
resultSet->GetInt(columnIndex, intValue);
|
||||
data[typeValue] = intValue;
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_FLOAT) {
|
||||
double doubleValue;
|
||||
resultSet->GetDouble(columnIndex, doubleValue);
|
||||
data[typeValue] = doubleValue;
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_STRING) {
|
||||
std::string stringValue;
|
||||
resultSet->GetString(columnIndex, stringValue);
|
||||
if (!stringValue.empty()) {
|
||||
data[typeValue] = stringValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 "contacts_path.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
std::string ContactsPath::RDB_PATH = "";
|
||||
std::string ContactsPath::DUMP_PATH = "";
|
||||
std::string ContactsPath::RDB_BACKUP_PATH = "";
|
||||
|
||||
ContactsPath::ContactsPath(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsPath::~ContactsPath()
|
||||
{
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 "contacts_string_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
ContactsStringUtils::ContactsStringUtils()
|
||||
{
|
||||
}
|
||||
|
||||
ContactsStringUtils::~ContactsStringUtils()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::string> ContactsStringUtils::SplitStr(std::string str, std::string spSymbol)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
std::string::size_type i = 0;
|
||||
Trim(str);
|
||||
std::string::size_type found = str.find(spSymbol);
|
||||
if (found != std::string::npos) {
|
||||
while (found != std::string::npos) {
|
||||
std::string value = str.substr(i, found - i);
|
||||
Trim(value);
|
||||
if (!value.empty()) {
|
||||
result.push_back(value);
|
||||
}
|
||||
i = found + spSymbol.size();
|
||||
found = str.find(spSymbol, i);
|
||||
}
|
||||
std::string lastv = str.substr(i, str.size() - i);
|
||||
Trim(lastv);
|
||||
if (!lastv.empty()) {
|
||||
result.push_back(lastv);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string &ContactsStringUtils::Trim(std::string &str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return str;
|
||||
}
|
||||
str.erase(0, str.find_first_not_of(" "));
|
||||
str.erase(str.find_last_not_of(" ") + 1);
|
||||
return str;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 "file_utils.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
FileUtils::FileUtils(void)
|
||||
{
|
||||
}
|
||||
|
||||
FileUtils::~FileUtils()
|
||||
{
|
||||
}
|
||||
|
||||
int FileUtils::IsFolderExist(std::string path)
|
||||
{
|
||||
DIR *dp;
|
||||
if ((dp = opendir(path.c_str())) == NULL) {
|
||||
HILOG_ERROR("FileUtils file NULL");
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
closedir(dp);
|
||||
return OPERATION_OK;
|
||||
}
|
||||
|
||||
void FileUtils::Mkdir(std::string path)
|
||||
{
|
||||
if (IsFolderExist(path) == OPERATION_ERROR) {
|
||||
int isCreate = ::mkdir(path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IRWXO);
|
||||
HILOG_INFO("FileUtils : mkdir = %{public}d", isCreate);
|
||||
}
|
||||
}
|
||||
|
||||
void FileUtils::WriteStringToFileAppend(std::string dirStr, const std::string str)
|
||||
{
|
||||
time_t backupTime = time(nullptr);
|
||||
if (backupTime == 0) {
|
||||
HILOG_ERROR("FileUtils : WriteStringToFileAppend time_t null");
|
||||
return;
|
||||
}
|
||||
dirStr.append("/").append(std::to_string(backupTime)).append(".log");
|
||||
std::ofstream OsWrite(dirStr, std::ofstream::app);
|
||||
OsWrite << str;
|
||||
OsWrite << std::endl;
|
||||
OsWrite.close();
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* 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 "merge_utils.h"
|
||||
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_database.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
MergeUtils::MergeUtils(void)
|
||||
{
|
||||
}
|
||||
|
||||
MergeUtils::~MergeUtils()
|
||||
{
|
||||
}
|
||||
|
||||
std::set<std::string> MergeUtils::QueryRawContactByType(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, int typeId)
|
||||
{
|
||||
std::string sql = "SELECT ";
|
||||
sql.append(ContactPublicColumns::ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" = (SELECT ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ?")
|
||||
.append(" AND is_deleted = 0 )");
|
||||
std::vector<std::string> selectionArgs;
|
||||
selectionArgs.push_back(std::to_string(rawId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> rawIdsSet = store->QuerySql(sql, selectionArgs);
|
||||
std::set<int> rawIds;
|
||||
int resultSetNum = rawIdsSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int value = 0;
|
||||
rawIdsSet->GetInt(0, value);
|
||||
rawIds.insert(value);
|
||||
resultSetNum = rawIdsSet->GoToNextRow();
|
||||
}
|
||||
rawIdsSet->Close();
|
||||
return QueryDataExecute(store, rawIds, typeId);
|
||||
}
|
||||
|
||||
std::set<std::string> MergeUtils::QueryDataExecute(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> rawIds, int typeId)
|
||||
{
|
||||
std::set<std::string> result;
|
||||
int size = rawIds.size();
|
||||
if (size <= 0) {
|
||||
return result;
|
||||
}
|
||||
std::string query = "SELECT ";
|
||||
query.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::CONTACT_DATA)
|
||||
.append(" WHERE ");
|
||||
for (auto rawId = rawIds.begin(); rawId != rawIds.end(); ++rawId) {
|
||||
query.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(*rawId))
|
||||
.append(" AND ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ? ");
|
||||
if (*rawId != *rawIds.rbegin()) {
|
||||
query.append(" OR ");
|
||||
}
|
||||
}
|
||||
std::vector<std::string> selectionArgs;
|
||||
selectionArgs.push_back(std::to_string(typeId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(query, selectionArgs);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
std::string value;
|
||||
resultSet->GetString(0, value);
|
||||
if (!value.empty()) {
|
||||
result.insert(value);
|
||||
}
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<int> MergeUtils::QueryByDataName(
|
||||
int rawId, std::set<std::string> data, std::shared_ptr<OHOS::NativeRdb::RdbStore> store)
|
||||
{
|
||||
std::vector<int> ids;
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
for (auto it = data.begin(); it != data.end(); it++) {
|
||||
std::string query = "SELECT ";
|
||||
query.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(" = '")
|
||||
.append(*it)
|
||||
.append("' AND ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(nameType))
|
||||
.append(" AND is_deleted = 0");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(query);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int value = 0;
|
||||
resultSet->GetInt(0, value);
|
||||
if (value != rawId) {
|
||||
ids.push_back(value);
|
||||
}
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
bool MergeUtils::SetEqual(std::set<std::string> setLeft, std::set<std::string> setRight)
|
||||
{
|
||||
if (setLeft.size() != setRight.size()) {
|
||||
return false;
|
||||
}
|
||||
std::map<std::set<std::string>, std::string> mTemp;
|
||||
mTemp[setLeft] = "1";
|
||||
if (mTemp.find(setRight) == mTemp.end()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MergeUtils::AddHasJudgeForRawId(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, OHOS::NativeRdb::ValuesBucket &values)
|
||||
{
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
int phoneType = contactsDataBase->GetTypeId(ContentTypeData::PHONE);
|
||||
int emailType = contactsDataBase->GetTypeId(ContentTypeData::EMAIL);
|
||||
int groupType = contactsDataBase->GetTypeId(ContentTypeData::GROUP_MEMBERSHIP);
|
||||
std::vector<int> types;
|
||||
types.push_back(nameType);
|
||||
types.push_back(phoneType);
|
||||
types.push_back(emailType);
|
||||
types.push_back(groupType);
|
||||
int size = types.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::string sql = "SELECT 1 FROM contact_data WHERE type_id = " + std::to_string(types[i]);
|
||||
sql.append(" AND raw_contact_id = " + std::to_string(rawId)).append(" LIMIT 1");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sql);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
if (resultSetNum == 0) {
|
||||
switch (i) {
|
||||
case HAS_NAME:
|
||||
values.Delete(ContactColumns::HAS_DISPLAY_NAME);
|
||||
values.PutInt(ContactColumns::HAS_DISPLAY_NAME, 1);
|
||||
break;
|
||||
case HAS_PHONE:
|
||||
values.Delete(ContactColumns::HAS_PHONE_NUMBER);
|
||||
values.PutInt(ContactColumns::HAS_PHONE_NUMBER, 1);
|
||||
break;
|
||||
case HAS_EMAIL:
|
||||
values.Delete(ContactColumns::HAS_EMAIL);
|
||||
values.PutInt(ContactColumns::HAS_EMAIL, 1);
|
||||
break;
|
||||
case HAS_GROUP:
|
||||
values.Delete(ContactColumns::HAS_GROUP);
|
||||
values.PutInt(ContactColumns::HAS_GROUP, 1);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("AddHasJudge switch code error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MergeUtils::GetRawIdsByRawId(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, std::set<int> &rawIds)
|
||||
{
|
||||
std::string queryMergeId = "SELECT ";
|
||||
queryMergeId.append(ContactPublicColumns::ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(" (SELECT ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ? ")
|
||||
.append(" ) AND is_deleted = 0");
|
||||
std::vector<std::string> selectionArgs;
|
||||
selectionArgs.push_back(std::to_string(rawId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> rawIdsSet = store->QuerySql(queryMergeId, selectionArgs);
|
||||
int resultSetNum = rawIdsSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int value = 0;
|
||||
rawIdsSet->GetInt(0, value);
|
||||
if (value != rawId) {
|
||||
rawIds.insert(value);
|
||||
}
|
||||
resultSetNum = rawIdsSet->GoToNextRow();
|
||||
}
|
||||
rawIdsSet->Close();
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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 "predicates_convert.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
PredicatesConvert::PredicatesConvert(void)
|
||||
{
|
||||
}
|
||||
|
||||
PredicatesConvert::~PredicatesConvert()
|
||||
{
|
||||
}
|
||||
|
||||
OHOS::NativeRdb::RdbPredicates PredicatesConvert::ConvertPredicates(
|
||||
std::string tableName, OHOS::NativeRdb::DataAbilityPredicates &dataPredicates)
|
||||
{
|
||||
OHOS::NativeRdb::RdbPredicates predicates(tableName);
|
||||
OHOS::NativeRdb::PredicatesUtils::SetWhereClauseAndArgs(
|
||||
&predicates, dataPredicates.GetWhereClause(), dataPredicates.GetWhereArgs());
|
||||
OHOS::NativeRdb::PredicatesUtils::SetAttributes(&predicates, dataPredicates.IsDistinct(), dataPredicates.GetIndex(),
|
||||
dataPredicates.GetGroup(), dataPredicates.GetOrder(), dataPredicates.GetLimit(), dataPredicates.GetOffset());
|
||||
return predicates;
|
||||
}
|
||||
|
||||
OHOS::NativeRdb::RdbPredicates PredicatesConvert::CopyPredicates(
|
||||
std::string tableName, OHOS::NativeRdb::RdbPredicates &oldRdbPredicates)
|
||||
{
|
||||
OHOS::NativeRdb::RdbPredicates predicates(tableName);
|
||||
OHOS::NativeRdb::PredicatesUtils::SetWhereClauseAndArgs(
|
||||
&predicates, oldRdbPredicates.GetWhereClause(), oldRdbPredicates.GetWhereArgs());
|
||||
OHOS::NativeRdb::PredicatesUtils::SetAttributes(&predicates, oldRdbPredicates.IsDistinct(),
|
||||
oldRdbPredicates.GetIndex(), oldRdbPredicates.GetGroup(), oldRdbPredicates.GetOrder(),
|
||||
oldRdbPredicates.GetLimit(), oldRdbPredicates.GetOffset());
|
||||
return predicates;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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 "sql_analyzer.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
constexpr int POS_ADD_TWO = 2;
|
||||
|
||||
SqlAnalyzer::SqlAnalyzer()
|
||||
{
|
||||
}
|
||||
|
||||
SqlAnalyzer::~SqlAnalyzer()
|
||||
{
|
||||
}
|
||||
|
||||
bool SqlAnalyzer::CheckValuesBucket(const NativeRdb::ValuesBucket &value)
|
||||
{
|
||||
std::map<std::string, NativeRdb::ValueObject> valuesMap;
|
||||
value.GetAll(valuesMap);
|
||||
for (auto it = valuesMap.begin(); it != valuesMap.end(); ++it) {
|
||||
std::string key = it->first;
|
||||
bool isKey = FindIllegalWords(key);
|
||||
if (isKey) {
|
||||
HILOG_ERROR("SqlAnalyzer CheckValuesBucket key is %{public}s error", key.c_str());
|
||||
return false;
|
||||
}
|
||||
NativeRdb::ValueObject value = it->second;
|
||||
if (value.GetType() == NativeRdb::ValueObjectType::TYPE_STRING) {
|
||||
std::string str;
|
||||
value.GetString(str);
|
||||
bool isValue = FindIllegalWords(str);
|
||||
if (isValue) {
|
||||
HILOG_ERROR("SqlAnalyzer CheckValuesBucket value is %{public}s error", str.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqlAnalyzer::CharCheck(char &ch, std::string sql, std::size_t &pos)
|
||||
{
|
||||
if (ch == '[') {
|
||||
pos++;
|
||||
std::size_t found = sql.find(']', pos);
|
||||
if (found == std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
if (ch == '-' && PickChar(sql, pos + 1) == '-') {
|
||||
pos += POS_ADD_TWO;
|
||||
std::size_t found = sql.find('\n', pos);
|
||||
if (found == std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
if (ch == '/' && PickChar(sql, pos + 1) == '*') {
|
||||
pos += POS_ADD_TWO;
|
||||
std::size_t found = sql.find("*/", pos);
|
||||
if (found == std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
pos += POS_ADD_TWO;
|
||||
}
|
||||
if (ch == ';') {
|
||||
return true;
|
||||
}
|
||||
pos++;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SqlAnalyzer::StrCheck(char &ch, std::size_t strlen, std::string sql, std::size_t &pos)
|
||||
{
|
||||
if (IsInStr(ch, "'\"`") == 0) {
|
||||
pos++;
|
||||
while (pos < strlen) {
|
||||
std::size_t found = sql.find(ch, pos);
|
||||
if (found == std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
if (PickChar(sql, pos + 1) != ch) {
|
||||
break;
|
||||
}
|
||||
pos += POS_ADD_TWO;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SqlAnalyzer::FindIllegalWords(std::string sql)
|
||||
{
|
||||
if (sql.empty()) {
|
||||
return false;
|
||||
}
|
||||
std::size_t pos = 0;
|
||||
std::size_t strlen = sql.length();
|
||||
while (pos < strlen) {
|
||||
char ch = PickChar(sql, pos);
|
||||
if (IsLetter(ch)) {
|
||||
std::size_t start = pos;
|
||||
pos++;
|
||||
while (IsLetterNumber(PickChar(sql, pos))) {
|
||||
pos++;
|
||||
}
|
||||
std::size_t count = pos - start + 1;
|
||||
sql.substr(start, count);
|
||||
}
|
||||
if (IsInStr(ch, "'\"`") == 0) {
|
||||
if (StrCheck(ch, strlen, sql, pos)) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (CharCheck(ch, sql, pos)) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 "uri_utils.h"
|
||||
#include "common.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
UriUtils::UriUtils(void)
|
||||
{
|
||||
}
|
||||
|
||||
UriUtils::~UriUtils()
|
||||
{
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> UriUtils::getQueryParameter(OHOS::Uri &uri)
|
||||
{
|
||||
std::map<std::string, std::string> mapQuery;
|
||||
std::string query = uri.GetQuery();
|
||||
if (query.empty()) {
|
||||
return mapQuery;
|
||||
}
|
||||
std::vector<std::string> tempVector = split(query, "&");
|
||||
int size = tempVector.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::vector<std::string> childTempVector = split(tempVector[i], "=");
|
||||
size_t size = childTempVector.size();
|
||||
if (size != REQUEST_PARAMS_NUM) {
|
||||
HILOG_ERROR("UriUtils uriParse getQueryParameter query parameter error");
|
||||
break;
|
||||
}
|
||||
std::string key = childTempVector[0];
|
||||
std::string value = childTempVector[1];
|
||||
mapQuery.insert(std::make_pair(key, value));
|
||||
}
|
||||
return mapQuery;
|
||||
}
|
||||
|
||||
std::vector<std::string> UriUtils::split(const std::string &str, const std::string &split)
|
||||
{
|
||||
char *saveChar = nullptr;
|
||||
char *token = strtok_r(const_cast<char *>(str.c_str()), split.c_str(), &saveChar);
|
||||
std::vector<std::string> result;
|
||||
while (token != nullptr) {
|
||||
result.emplace_back(token);
|
||||
token = strtok_r(nullptr, split.c_str(), &saveChar);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int UriUtils::UriParse(OHOS::Uri &uri, std::map<std::string, int> &keyMap)
|
||||
{
|
||||
std::string path = uri.GetPath();
|
||||
if (path.empty()) {
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
std::map<std::string, int>::iterator iterator = keyMap.find(path);
|
||||
if (iterator != keyMap.end()) {
|
||||
return iterator->second;
|
||||
}
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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 DATABASE_DISASTER_RECOVERY_H
|
||||
#define DATABASE_DISASTER_RECOVERY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "rdb_store.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class DataBaseDisasterRecovery {
|
||||
public:
|
||||
static std::shared_ptr<DataBaseDisasterRecovery> GetInstance();
|
||||
~DataBaseDisasterRecovery();
|
||||
int SQLliteCheckDb();
|
||||
int BackDatabase();
|
||||
int BackDatabase(std::string dataBaseName);
|
||||
std::string GetBackUpDatabase(const std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_);
|
||||
int RecoveryDatabase(std::string dataBaseName);
|
||||
|
||||
private:
|
||||
DataBaseDisasterRecovery();
|
||||
static std::shared_ptr<DataBaseDisasterRecovery> instance_;
|
||||
static std::map<std::string, std::shared_ptr<OHOS::NativeRdb::RdbStore>> redbStoreMap;
|
||||
int SQLliteCheckDb(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string dataBaseName);
|
||||
static const std::string BACKUP_LINK_SYMBOL;
|
||||
static const std::string BACKUP_SUFFIX;
|
||||
static const std::string DB_OK;
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // DATABASE_DISASTER_RECOVERY_H
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* 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 "database_disaster_recovery.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "calllog_database.h"
|
||||
#include "contacts_database.h"
|
||||
#include "file_utils.h"
|
||||
#include "profile_database.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
namespace {
|
||||
std::mutex mtx_;
|
||||
}
|
||||
|
||||
const std::string DataBaseDisasterRecovery::BACKUP_LINK_SYMBOL = "_";
|
||||
const std::string DataBaseDisasterRecovery::BACKUP_SUFFIX = ".db";
|
||||
const std::string DataBaseDisasterRecovery::DB_OK = "ok";
|
||||
std::shared_ptr<DataBaseDisasterRecovery> DataBaseDisasterRecovery::instance_ = nullptr;
|
||||
std::map<std::string, std::shared_ptr<OHOS::NativeRdb::RdbStore>> DataBaseDisasterRecovery::redbStoreMap;
|
||||
|
||||
std::shared_ptr<DataBaseDisasterRecovery> DataBaseDisasterRecovery::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
instance_.reset(new DataBaseDisasterRecovery());
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
DataBaseDisasterRecovery::DataBaseDisasterRecovery()
|
||||
{
|
||||
}
|
||||
|
||||
DataBaseDisasterRecovery::~DataBaseDisasterRecovery()
|
||||
{
|
||||
}
|
||||
|
||||
int DataBaseDisasterRecovery::SQLliteCheckDb()
|
||||
{
|
||||
mtx_.lock();
|
||||
int ret = OPERATION_ERROR;
|
||||
HILOG_INFO("DataBaseDisasterRecovery SQLliteCheck start.");
|
||||
redbStoreMap.clear();
|
||||
if (redbStoreMap.empty()) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery redbStoreMap init. nullptr");
|
||||
std::shared_ptr<ProfileDatabase> profile = ProfileDatabase::GetInstance();
|
||||
std::shared_ptr<ContactsDataBase> contacts = ContactsDataBase::GetInstance();
|
||||
redbStoreMap.insert(std::make_pair(PROFILE_DATABASE_NAME, profile->store_));
|
||||
redbStoreMap.insert(std::make_pair(CONTACT_DATABASE_NAME, contacts->contactStore_));
|
||||
}
|
||||
if (redbStoreMap.empty()) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery SQLliteCheck redbStoreMap is empty");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
for (auto &kv : redbStoreMap) {
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store_ = kv.second;
|
||||
ret = SQLliteCheckDb(store_, kv.first);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery SQLliteCheckDb ERROR.");
|
||||
mtx_.unlock();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
mtx_.unlock();
|
||||
HILOG_INFO("DataBaseDisasterRecovery SQLliteCheck end.");
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
|
||||
int DataBaseDisasterRecovery::SQLliteCheckDb(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string dataBaseName)
|
||||
{
|
||||
// default switch
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery SQLliteCheck %{public}s store_ is nullptr", dataBaseName.c_str());
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
std::string result;
|
||||
store_->ExecuteAndGetString(result, "PRAGMA quick_check(0)");
|
||||
HILOG_INFO("DataBaseDisasterRecovery check %{public}s result is %{public}s", dataBaseName.c_str(), result.c_str());
|
||||
if (result == DB_OK) {
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
|
||||
int DataBaseDisasterRecovery::BackDatabase()
|
||||
{
|
||||
// Recovery
|
||||
HILOG_INFO("entry DataBaseDisasterRecovery");
|
||||
FileUtils fileUtils;
|
||||
fileUtils.Mkdir(ContactsPath::RDB_BACKUP_PATH);
|
||||
redbStoreMap.clear();
|
||||
if (redbStoreMap.empty()) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery redbStoreMap init. nullptr");
|
||||
std::shared_ptr<ProfileDatabase> profile = ProfileDatabase::GetInstance();
|
||||
std::shared_ptr<ContactsDataBase> contacts = ContactsDataBase::GetInstance();
|
||||
redbStoreMap.insert(std::make_pair(PROFILE_DATABASE_NAME, profile->store_));
|
||||
redbStoreMap.insert(std::make_pair(CONTACT_DATABASE_NAME, contacts->contactStore_));
|
||||
}
|
||||
if (redbStoreMap.empty()) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery SQLliteCheck redbStoreMap is empty");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
for (auto &kv : redbStoreMap) {
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store_ = kv.second;
|
||||
int version;
|
||||
store_->GetVersion(version);
|
||||
HILOG_INFO("backup version is %{public}d", version);
|
||||
int ret = BackDatabase(kv.first);
|
||||
HILOG_INFO("BackDatabase %{public}s status is %{public}d", kv.first.c_str(), ret);
|
||||
}
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
|
||||
int DataBaseDisasterRecovery::BackDatabase(std::string dataBaseName)
|
||||
{
|
||||
mtx_.lock();
|
||||
auto iter = redbStoreMap.find(dataBaseName);
|
||||
HILOG_INFO("DataBaseDisasterRecovery BackDatabase redbStoreMap size is %{public}d", redbStoreMap.size());
|
||||
if (iter != redbStoreMap.end()) {
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store_ = iter->second;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery BackDatabase %{public}s store_ is nullptr", dataBaseName.c_str());
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
std::string dbPath = ContactsPath::RDB_BACKUP_PATH + dataBaseName + BACKUP_SUFFIX;
|
||||
int64_t outRowId = 0;
|
||||
OHOS::NativeRdb::ValuesBucket values;
|
||||
values.PutString(DatabaseBackupColumns::BACKUP_PATH, dbPath);
|
||||
int ret = store_->Insert(outRowId, ContactTableName::DATABASE_BACKUP_TASK, values);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery Insert filed, status is %{public}d.", ret);
|
||||
mtx_.unlock();
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
OHOS::NativeRdb::RdbHelper::DeleteRdbStore(dbPath);
|
||||
ret = store_->Backup(dbPath, std::vector<uint8_t>());
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("DataBaseDisasterRecovery Backup filed, status is %{public}d.", ret);
|
||||
mtx_.unlock();
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
}
|
||||
mtx_.unlock();
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
|
||||
std::string DataBaseDisasterRecovery::GetBackUpDatabase(const std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_)
|
||||
{
|
||||
std::string sql = "select backup_path from ";
|
||||
sql.append(ContactTableName::DATABASE_BACKUP_TASK).append(" order by backup_time desc limit 0,1");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> result = store_->QuerySql(sql, std::vector<std::string>());
|
||||
int resultSetNum = result->GoToFirstRow();
|
||||
std::string currValue;
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int currValueIndex;
|
||||
result->GetColumnIndex(DatabaseBackupColumns::BACKUP_PATH, currValueIndex);
|
||||
result->GetString(currValueIndex, currValue);
|
||||
resultSetNum = result->GoToNextRow();
|
||||
break;
|
||||
}
|
||||
result->Close();
|
||||
return currValue;
|
||||
}
|
||||
|
||||
int DataBaseDisasterRecovery::RecoveryDatabase(std::string dataBaseName)
|
||||
{
|
||||
if (dataBaseName == PROFILE_DATABASE_NAME) {
|
||||
std::string buckupPath = ContactsPath::RDB_BACKUP_PATH + dataBaseName + BACKUP_SUFFIX;
|
||||
ProfileDatabase::DestroyInstanceAndRestore(buckupPath);
|
||||
} else if (dataBaseName == CONTACT_DATABASE_NAME) {
|
||||
std::string buckupPath = ContactsPath::RDB_BACKUP_PATH + dataBaseName + BACKUP_SUFFIX;
|
||||
ContactsDataBase::DestroyInstanceAndRestore(buckupPath);
|
||||
}
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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 CANDIDATE_H
|
||||
#define CANDIDATE_H
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class Candidate {
|
||||
public:
|
||||
Candidate();
|
||||
~Candidate();
|
||||
std::set<int> autoIds_;
|
||||
std::set<int> manualIds_;
|
||||
int mergeMode_ = 0;
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CANDIDATE_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 CANDIDATESCORE_H
|
||||
#define CANDIDATESCORE_H
|
||||
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
#include "candidate.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class CandidateStatus {
|
||||
public:
|
||||
CandidateStatus();
|
||||
~CandidateStatus();
|
||||
Candidate QueryAllForMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
|
||||
private:
|
||||
int PhoneMatch(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<std::string> phones, int id);
|
||||
bool IsMerged(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
bool IsNeedMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
bool IsMergeStatus(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
bool JudgeDataDifferent(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::vector<int> ids, int rawId);
|
||||
void AddMergedStatus(Candidate &candidate);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CANDIDATESCORE_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 MATCHCANDIDATE_H
|
||||
#define MATCHCANDIDATE_H
|
||||
|
||||
#include "candidate_status.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class MatchCandidate {
|
||||
public:
|
||||
MatchCandidate();
|
||||
~MatchCandidate();
|
||||
int FindMatchContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
int Split(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
void AddHasByRawId(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
|
||||
private:
|
||||
int UpdateSearch(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, int contactsId);
|
||||
int ExecuteUpdateMode(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> Ids, int mode);
|
||||
int UpdateMergeMode(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, Candidate candidate);
|
||||
int64_t AddNewContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId);
|
||||
int UpdateRawContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, int64_t contactsId);
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> ResultSetToValuesBucket(
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // MATCHCANDIDATE_H
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 MERGERCONTACT_H
|
||||
#define MERGERCONTACT_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class MergerContacts {
|
||||
public:
|
||||
MergerContacts();
|
||||
~MergerContacts();
|
||||
int ForceContactMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore>, std::set<int>);
|
||||
int ContactMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore>);
|
||||
int ReContactMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore>, const OHOS::NativeRdb::DataAbilityPredicates &);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> SelectCandidate(std::shared_ptr<OHOS::NativeRdb::RdbStore>);
|
||||
|
||||
private:
|
||||
void UpdateIdsByName(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore>, std::set<std::string>, std::set<int>, std::vector<std::set<int>> &);
|
||||
std::vector<std::set<int>> SelectIdsByName(std::shared_ptr<OHOS::NativeRdb::RdbStore>, std::set<int>);
|
||||
void UpdateCandidate(std::shared_ptr<OHOS::NativeRdb::RdbStore>, std::vector<int>, std::vector<std::set<int>> &);
|
||||
int MergeCircle(std::shared_ptr<OHOS::NativeRdb::RdbStore>, std::vector<std::set<int>>);
|
||||
std::vector<std::set<int>> QueryMergeContacts(std::shared_ptr<OHOS::NativeRdb::RdbStore>, int);
|
||||
std::string QueryCandidateName(std::shared_ptr<OHOS::NativeRdb::RdbStore>, int);
|
||||
void UpdateRawContacts(std::shared_ptr<OHOS::NativeRdb::RdbStore>, int, std::set<int>);
|
||||
void UpdateRawContactsExecute(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int minContactId, std::set<int> Ids);
|
||||
std::set<int> HandleIds(std::shared_ptr<OHOS::NativeRdb::RdbStore>, std::set<int>);
|
||||
int DeleteContacts(std::shared_ptr<OHOS::NativeRdb::RdbStore>, int, std::set<int>);
|
||||
std::set<int> QueryTargetName(std::shared_ptr<OHOS::NativeRdb::RdbStore>, int, std::set<std::string>);
|
||||
bool isNameMatch(std::shared_ptr<OHOS::NativeRdb::RdbStore>, std::set<int>);
|
||||
int ManualMergeOperation(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int minId, std::set<int> handledIds);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // MERGERCONTACT_H
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 "candidate.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
Candidate::Candidate()
|
||||
{
|
||||
}
|
||||
|
||||
Candidate::~Candidate()
|
||||
{
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* 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 "candidate_status.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_database.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "merge_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
CandidateStatus::CandidateStatus()
|
||||
{
|
||||
}
|
||||
|
||||
CandidateStatus::~CandidateStatus()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Query operation for merge candidate
|
||||
*
|
||||
* @param store Conditions for query operation
|
||||
* @param rawId Contacts's raw_contact_id to query
|
||||
*
|
||||
* @return Candidate contact raw_contact_id collection
|
||||
*/
|
||||
Candidate CandidateStatus::QueryAllForMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
Candidate candidate;
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
int phoneType = contactsDataBase->GetTypeId(ContentTypeData::PHONE);
|
||||
MergeUtils mergeUtils;
|
||||
std::set<std::string> names = mergeUtils.QueryRawContactByType(store, rawId, nameType);
|
||||
// query other name same raw_contact_id
|
||||
std::vector<int> nameIds = mergeUtils.QueryByDataName(rawId, names, store);
|
||||
// query current phone
|
||||
std::set<std::string> phones = mergeUtils.QueryRawContactByType(store, rawId, phoneType);
|
||||
std::set<int> autoIds;
|
||||
std::set<int> manualIds;
|
||||
int size = nameIds.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (!IsNeedMerge(store, nameIds[i]) || !IsMergeStatus(store, nameIds[i])) {
|
||||
continue;
|
||||
}
|
||||
std::set<std::string> otherPhones = mergeUtils.QueryRawContactByType(store, nameIds[i], phoneType);
|
||||
if (phones.empty() && otherPhones.empty()) {
|
||||
autoIds.insert(nameIds[i]);
|
||||
}
|
||||
if (phones.empty() || otherPhones.empty()) {
|
||||
manualIds.insert(nameIds[i]);
|
||||
}
|
||||
if (mergeUtils.SetEqual(phones, otherPhones)) {
|
||||
autoIds.insert(nameIds[i]);
|
||||
} else {
|
||||
manualIds.insert(nameIds[i]);
|
||||
}
|
||||
}
|
||||
candidate.autoIds_ = autoIds;
|
||||
candidate.manualIds_ = manualIds;
|
||||
AddMergedStatus(candidate);
|
||||
HILOG_INFO("QueryAllForMerge mode is : %{public}d ", candidate.mergeMode_);
|
||||
candidate.autoIds_.insert(rawId);
|
||||
candidate.manualIds_.insert(rawId);
|
||||
HILOG_INFO("QueryAllForMerge size is : %{public}d ", candidate.autoIds_.size());
|
||||
HILOG_INFO("QueryAllForMerge candidate.manualIds_ is : %{public}d ", candidate.manualIds_.size());
|
||||
return candidate;
|
||||
}
|
||||
|
||||
void CandidateStatus::AddMergedStatus(Candidate &candidate)
|
||||
{
|
||||
if (!candidate.autoIds_.empty()) {
|
||||
candidate.mergeMode_ = MERGE_MODE_AUTO;
|
||||
} else if (!candidate.manualIds_.empty()) {
|
||||
candidate.mergeMode_ = MERGE_MODE_MANUAL;
|
||||
} else {
|
||||
candidate.mergeMode_ = MERGE_MODE_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Query operation for ensure if candidate need merge
|
||||
*
|
||||
* @param store Conditions for query operation
|
||||
* @param rawId Contacts's raw_contact_id to query
|
||||
*
|
||||
* @return The result returned by the update operation
|
||||
*/
|
||||
bool CandidateStatus::IsNeedMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
std::string isNeedMergeSql = "SELECT ";
|
||||
isNeedMergeSql.append(RawContactColumns::IS_NEED_MERGE)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(rawId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> isNeedMergeSet = store->QuerySql(isNeedMergeSql);
|
||||
bool isNeedMerge = false;
|
||||
int resultSetNum = isNeedMergeSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int value = 0;
|
||||
isNeedMergeSet->GetInt(0, value);
|
||||
if (value == 1) {
|
||||
isNeedMerge = true;
|
||||
} else {
|
||||
isNeedMerge = false;
|
||||
}
|
||||
resultSetNum = isNeedMergeSet->GoToNextRow();
|
||||
}
|
||||
isNeedMergeSet->Close();
|
||||
return isNeedMerge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Query operation for ensure if candidate has ture merge_status
|
||||
*
|
||||
* @param store Conditions for query operation
|
||||
* @param rawId Contacts's raw_contact_id to query
|
||||
*
|
||||
* @return The result returned by the update operation
|
||||
*/
|
||||
bool CandidateStatus::IsMergeStatus(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
std::string isMergeSwitchSql = "SELECT ";
|
||||
isMergeSwitchSql.append(RawContactColumns::MERGE_STATUS)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(rawId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> MergeSwitchSet = store->QuerySql(isMergeSwitchSql);
|
||||
bool isMergeSwitch = false;
|
||||
int resultSetNum = MergeSwitchSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int value = 0;
|
||||
MergeSwitchSet->GetInt(0, value);
|
||||
if (value == 1) {
|
||||
isMergeSwitch = true;
|
||||
} else {
|
||||
isMergeSwitch = false;
|
||||
}
|
||||
resultSetNum = MergeSwitchSet->GoToNextRow();
|
||||
}
|
||||
MergeSwitchSet->Close();
|
||||
return isMergeSwitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Query operation for ensure if candidate has merged
|
||||
*
|
||||
* @param store Conditions for query operation
|
||||
* @param rawId Contacts's raw_contact_id to query
|
||||
*
|
||||
* @return The result returned by the update operation
|
||||
*/
|
||||
bool CandidateStatus::IsMerged(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
std::string isNeedMergeSql = "SELECT ";
|
||||
isNeedMergeSql.append(RawContactColumns::MERGE_MODE)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(rawId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> isNeedMergeSet = store->QuerySql(isNeedMergeSql);
|
||||
bool mergeMode = false;
|
||||
int resultSetNum = isNeedMergeSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int value = 0;
|
||||
isNeedMergeSet->GetInt(0, value);
|
||||
if (value == 0) {
|
||||
mergeMode = true;
|
||||
} else {
|
||||
mergeMode = false;
|
||||
}
|
||||
resultSetNum = isNeedMergeSet->GoToNextRow();
|
||||
}
|
||||
isNeedMergeSet->Close();
|
||||
bool isMerged = mergeMode && !IsNeedMerge(store, rawId);
|
||||
return isMerged;
|
||||
}
|
||||
|
||||
bool CandidateStatus::JudgeDataDifferent(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::vector<int> ids, int rawId)
|
||||
{
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
MergeUtils mergeUtils;
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
int phoneType = contactsDataBase->GetTypeId(ContentTypeData::PHONE);
|
||||
std::set<std::string> names = mergeUtils.QueryRawContactByType(store, rawId, nameType);
|
||||
std::set<std::string> phones = mergeUtils.QueryRawContactByType(store, rawId, phoneType);
|
||||
int size = ids.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
MergeUtils mergeIdUtils;
|
||||
std::set<std::string> idNames = mergeIdUtils.QueryRawContactByType(store, ids[i], nameType);
|
||||
std::set<std::string> idPhones = mergeIdUtils.QueryRawContactByType(store, ids[i], phoneType);
|
||||
if (names != idNames || phones != idPhones) {
|
||||
HILOG_INFO("CandidateStatus::JudgeDataDifferent is true");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* 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 "match_candidate.h"
|
||||
|
||||
#include "candidate.h"
|
||||
#include "common.h"
|
||||
#include "contacts.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_database.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "merge_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
MatchCandidate::MatchCandidate()
|
||||
{
|
||||
}
|
||||
|
||||
MatchCandidate::~MatchCandidate()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Query operation for update candidate's merge_mode
|
||||
*
|
||||
* @param store Conditions for query operation
|
||||
* @param rawId Contacts's raw_contact_id to query
|
||||
*
|
||||
* @return The result returned by the update operation
|
||||
*/
|
||||
int MatchCandidate::FindMatchContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
CandidateStatus candidateStatus;
|
||||
// Query candidates
|
||||
Candidate candidate = candidateStatus.QueryAllForMerge(store, rawId);
|
||||
if (candidate.autoIds_.size() > 1) {
|
||||
int minAutoid = -1;
|
||||
minAutoid = *candidate.autoIds_.begin();
|
||||
if (minAutoid != -1) {
|
||||
std::string updateMergeTarget = "UPDATE ";
|
||||
updateMergeTarget.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::IS_MERGE_TARGET)
|
||||
.append(" = 1 ")
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(minAutoid));
|
||||
int code = store->ExecuteSql(updateMergeTarget);
|
||||
if (code != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("update is_merge_target error code is : %{public}d ", code);
|
||||
}
|
||||
}
|
||||
}
|
||||
// update merge_mode
|
||||
int retCode = UpdateMergeMode(store, candidate);
|
||||
HILOG_INFO("MatchCandidate::FindMatchContact retCode : %{public}d ", retCode);
|
||||
return retCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Split operation for already merged contacts
|
||||
*
|
||||
* @param store Conditions for split operation
|
||||
* @param rawId Contacts's raw_contact_id to split
|
||||
*
|
||||
* @return The result returned by the split operation
|
||||
*/
|
||||
int MatchCandidate::Split(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
if (store == nullptr) {
|
||||
HILOG_ERROR("MatchCandidate::Split store is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
std::set<int> rawIds;
|
||||
MergeUtils mergeUtils;
|
||||
mergeUtils.GetRawIdsByRawId(store, rawId, rawIds);
|
||||
if (rawIds.size() < 1) {
|
||||
HILOG_ERROR("MatchCandidate::Split is error");
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
int code = RDB_EXECUTE_FAIL;
|
||||
for (auto newRawId = rawIds.begin(); newRawId != rawIds.end(); ++newRawId) {
|
||||
int contactsId = AddNewContact(store, *newRawId);
|
||||
if (contactsId <= 0) {
|
||||
continue;
|
||||
}
|
||||
code = UpdateRawContact(store, *newRawId, contactsId);
|
||||
UpdateSearch(store, *newRawId, contactsId);
|
||||
FindMatchContact(store, *newRawId);
|
||||
}
|
||||
AddHasByRawId(store, rawId);
|
||||
return code;
|
||||
}
|
||||
|
||||
void MatchCandidate::AddHasByRawId(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
MergeUtils mergeUtils;
|
||||
OHOS::NativeRdb::ValuesBucket values;
|
||||
values.PutInt(ContactColumns::HAS_DISPLAY_NAME, 0);
|
||||
values.PutInt(ContactColumns::HAS_PHONE_NUMBER, 0);
|
||||
values.PutInt(ContactColumns::HAS_EMAIL, 0);
|
||||
values.PutInt(ContactColumns::HAS_GROUP, 0);
|
||||
mergeUtils.AddHasJudgeForRawId(store, rawId, values);
|
||||
Contacts contacts;
|
||||
int contactsRet = contacts.UpdateContact(rawId, store, values);
|
||||
HILOG_INFO("MatchCandidate::AddHasByRawId UpdateContact ret is : %{public}d", contactsRet);
|
||||
}
|
||||
|
||||
int MatchCandidate::UpdateSearch(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, int contactsId)
|
||||
{
|
||||
std::string sql = "UPDATE ";
|
||||
sql.append(ContactTableName::SEARCH_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(SearchContactColumns::CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(contactsId))
|
||||
.append(" WHERE ")
|
||||
.append(SearchContactColumns::RAW_CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(rawId));
|
||||
int ret = store->ExecuteSql(sql);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int64_t MatchCandidate::AddNewContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId)
|
||||
{
|
||||
MergeUtils mergeUtils;
|
||||
std::string sql = "SELECT ";
|
||||
sql.append(ContactColumns::PHOTO_ID)
|
||||
.append(", ")
|
||||
.append(ContactColumns::PHOTO_FILE_ID)
|
||||
.append(", ")
|
||||
.append(ContactColumns::PERSONAL_RINGTONE)
|
||||
.append(", ")
|
||||
.append(ContactColumns::COMPANY)
|
||||
.append(", ")
|
||||
.append(ContactColumns::POSITION)
|
||||
.append(", ")
|
||||
.append(ContactColumns::READ_ONLY)
|
||||
.append(", ")
|
||||
.append(ContactColumns::PERSONAL_NOTIFICATION_RINGTONE)
|
||||
.append(", ")
|
||||
.append(ContactColumns::IS_TRANSFER_VOICEMAIL)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(rawId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sql);
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> value = ResultSetToValuesBucket(resultSet);
|
||||
value[0].PutInt(ContactColumns::NAME_RAW_CONTACT_ID, rawId);
|
||||
mergeUtils.AddHasJudgeForRawId(store, rawId, value[0]);
|
||||
int64_t rawIdTemp = rawId;
|
||||
int64_t contactsId = 0;
|
||||
Contacts contacts;
|
||||
int contactsRet = contacts.InsertContact(store, rawIdTemp, value[0], contactsId);
|
||||
if (contactsRet != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("MatchCandidate AddNewContact is error %{public}d", contactsRet);
|
||||
}
|
||||
return contactsId;
|
||||
}
|
||||
|
||||
int MatchCandidate::ExecuteUpdateMode(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> Ids, int mode)
|
||||
{
|
||||
int ret = RDB_EXECUTE_FAIL;
|
||||
if (Ids.size() < 1) {
|
||||
HILOG_ERROR("MatchCandidate::ExecuteUpdateMode Ids.size() < 1");
|
||||
return ret;
|
||||
}
|
||||
std::string sql = "UPDATE ";
|
||||
sql.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::MERGE_MODE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(mode))
|
||||
.append(" WHERE ");
|
||||
for (auto it = Ids.begin(); it != Ids.end(); it++) {
|
||||
sql.append("id = ").append(std::to_string(*it));
|
||||
if (*it != *Ids.rbegin()) {
|
||||
sql.append(" OR ");
|
||||
}
|
||||
}
|
||||
ret = store->ExecuteSql(sql);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MatchCandidate::UpdateMergeMode(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, Candidate candidate)
|
||||
{
|
||||
HILOG_INFO("MatchCandidate::UpdateMergeMode is start mode :%{public}d ", candidate.mergeMode_);
|
||||
int error = RDB_EXECUTE_FAIL;
|
||||
switch (candidate.mergeMode_) {
|
||||
case MERGE_MODE_DEFAULT:
|
||||
error = ExecuteUpdateMode(store, candidate.manualIds_, MERGE_MODE_DEFAULT);
|
||||
break;
|
||||
case MERGE_MODE_MANUAL:
|
||||
error = ExecuteUpdateMode(store, candidate.manualIds_, MERGE_MODE_MANUAL);
|
||||
break;
|
||||
case MERGE_MODE_AUTO:
|
||||
error = ExecuteUpdateMode(store, candidate.autoIds_, MERGE_MODE_AUTO);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("UpdateMergeMode mode error");
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
int MatchCandidate::UpdateRawContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, int64_t contactsId)
|
||||
{
|
||||
std::string sql = "UPDATE ";
|
||||
sql.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(contactsId))
|
||||
.append(", ")
|
||||
.append(RawContactColumns::MERGE_MODE)
|
||||
.append(" = 0, ")
|
||||
.append(RawContactColumns::IS_NEED_MERGE)
|
||||
.append(" = 1")
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(rawId));
|
||||
int code = store->ExecuteSql(sql);
|
||||
return code;
|
||||
}
|
||||
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> MatchCandidate::ResultSetToValuesBucket(
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
std::vector<std::string> columnNames;
|
||||
resultSet->GetAllColumnNames(columnNames);
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> vectorQueryData;
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
OHOS::NativeRdb::ValuesBucket valuesBucketElement;
|
||||
int size = columnNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::string typeValue = columnNames[i];
|
||||
int columnIndex = 0;
|
||||
resultSet->GetColumnIndex(typeValue, columnIndex);
|
||||
OHOS::NativeRdb::ColumnType columnType;
|
||||
resultSet->GetColumnType(columnIndex, columnType);
|
||||
if (columnType == OHOS::NativeRdb::ColumnType::TYPE_INTEGER) {
|
||||
int intValue = 0;
|
||||
resultSet->GetInt(columnIndex, intValue);
|
||||
valuesBucketElement.PutInt(typeValue, intValue);
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_FLOAT) {
|
||||
double doubleValue = 0;
|
||||
resultSet->GetDouble(columnIndex, doubleValue);
|
||||
valuesBucketElement.PutDouble(typeValue, doubleValue);
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_STRING) {
|
||||
std::string stringValue;
|
||||
resultSet->GetString(columnIndex, stringValue);
|
||||
valuesBucketElement.PutString(typeValue, stringValue);
|
||||
}
|
||||
}
|
||||
vectorQueryData.push_back(valuesBucketElement);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
return vectorQueryData;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,631 @@
|
||||
/*
|
||||
* 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 "merger_contacts.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_database.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "match_candidate.h"
|
||||
#include "merge_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
static int g_isNeedMergeNum[2] = {0, 1};
|
||||
static int g_isNeedMergeTargetNum[2] = {0, 1};
|
||||
|
||||
MergerContacts::MergerContacts()
|
||||
{
|
||||
}
|
||||
|
||||
MergerContacts::~MergerContacts()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AutoMerge operation for candidate contacts
|
||||
*
|
||||
* @param store Conditions for split operation
|
||||
*
|
||||
* @return The result returned by the AutoMerge operation
|
||||
*/
|
||||
int MergerContacts::ContactMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore> store)
|
||||
{
|
||||
if (store == nullptr) {
|
||||
HILOG_ERROR("stroe is empty");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
HILOG_INFO("MergerContacts::ContactMerge is starting");
|
||||
// query all ids with merge_mode = 2
|
||||
std::vector<std::set<int>> candidates = QueryMergeContacts(store, MERGE_MODE_AUTO);
|
||||
int ret = RDB_EXECUTE_FAIL;
|
||||
ret = MergeCircle(store, candidates);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MergerContacts::MergeCircle(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::vector<std::set<int>> candidates)
|
||||
{
|
||||
if (candidates.empty()) {
|
||||
HILOG_ERROR("Merge candidate is empty");
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
bool isModeHasError = false;
|
||||
for (auto it = candidates.begin(); it != candidates.end(); ++it) {
|
||||
std::set<int> ids = *it;
|
||||
if (ids.size() == 1) {
|
||||
HILOG_ERROR("MergeCircle continue ");
|
||||
isModeHasError = true;
|
||||
continue;
|
||||
}
|
||||
auto minIdPosition = ids.begin();
|
||||
int minId = *minIdPosition;
|
||||
UpdateRawContacts(store, minId, ids);
|
||||
std::string sql = "UPDATE ";
|
||||
sql.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::IS_NEED_MERGE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(g_isNeedMergeNum[1]))
|
||||
.append(", ")
|
||||
.append(RawContactColumns::IS_MERGE_TARGET)
|
||||
.append(" = ")
|
||||
.append(std::to_string(g_isNeedMergeTargetNum[0]))
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(minId));
|
||||
int error = store->ExecuteSql(sql);
|
||||
if (error != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("MergeCircle ExecuteSql error : %{public}d ", error);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
MatchCandidate matchCandidate;
|
||||
matchCandidate.AddHasByRawId(store, minId);
|
||||
matchCandidate.FindMatchContact(store, minId);
|
||||
}
|
||||
if (isModeHasError) {
|
||||
HILOG_ERROR("MergerContacts::MergeCircle only one candidate has auto_merge_mode");
|
||||
return RDB_EXECUTE_FAIL;
|
||||
} else {
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int MergerContacts::DeleteContacts(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int minId, std::set<int> handledIds)
|
||||
{
|
||||
int ret = store->ExecuteSql("PRAGMA foreign_keys = OFF");
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("DeleteContacts foreign_keys close fail");
|
||||
return ret;
|
||||
}
|
||||
std::set<int> ids;
|
||||
std::string sql = "DELETE FROM ";
|
||||
sql.append(ContactTableName::CONTACT).append(" WHERE ");
|
||||
for (auto it = handledIds.begin(); it != handledIds.end(); ++it) {
|
||||
if (*it != minId) {
|
||||
ids.insert(*it);
|
||||
}
|
||||
}
|
||||
for (auto id = ids.begin(); id != ids.end(); ++id) {
|
||||
sql.append(ContactColumns::NAME_RAW_CONTACT_ID).append(" = ").append(std::to_string(*id));
|
||||
if (*id != *ids.rbegin()) {
|
||||
sql.append(" OR ");
|
||||
}
|
||||
}
|
||||
int code = store->ExecuteSql(sql);
|
||||
ret = store->ExecuteSql("PRAGMA foreign_keys = ON");
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("DeleteContacts foreign_keys open fail");
|
||||
return ret;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
std::set<int> MergerContacts::HandleIds(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> ids)
|
||||
{
|
||||
std::set<int> rawIds;
|
||||
for (auto id = ids.begin(); id != ids.end(); ++id) {
|
||||
if (*id != *ids.rbegin()) {
|
||||
std::string sqlBuilder = "SELECT ";
|
||||
sqlBuilder.append(ContactPublicColumns::ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" = (SELECT ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(*id))
|
||||
.append(")");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sqlBuilder);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int rawId = 0;
|
||||
resultSet->GetInt(0, rawId);
|
||||
rawIds.insert(rawId);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
} else {
|
||||
rawIds.insert(*id);
|
||||
}
|
||||
}
|
||||
return rawIds;
|
||||
}
|
||||
|
||||
void MergerContacts::UpdateRawContacts(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int minRawId, std::set<int> Ids)
|
||||
{
|
||||
std::string sqlBuilder = "SELECT ";
|
||||
sqlBuilder.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(minRawId))
|
||||
.append(" AND ")
|
||||
.append(RawContactColumns::IS_DELETED)
|
||||
.append(" = 0");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sqlBuilder);
|
||||
int minContactId = 0;
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
resultSet->GetInt(0, minContactId);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
UpdateRawContactsExecute(store, minContactId, Ids);
|
||||
DeleteContacts(store, minRawId, Ids);
|
||||
}
|
||||
|
||||
void MergerContacts::UpdateRawContactsExecute(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int minContactId, std::set<int> Ids)
|
||||
{
|
||||
int size = Ids.size();
|
||||
if (size < 0) {
|
||||
return;
|
||||
}
|
||||
std::string updateRawContact = "UPDATE ";
|
||||
updateRawContact.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(minContactId))
|
||||
.append(", ")
|
||||
.append(RawContactColumns::MERGE_MODE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(MERGE_MODE_DEFAULT))
|
||||
.append(", ")
|
||||
.append(RawContactColumns::IS_NEED_MERGE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(g_isNeedMergeNum[0]))
|
||||
.append(" WHERE ( ");
|
||||
std::string updateSearchSql = "UPDATE ";
|
||||
updateSearchSql.append(ContactTableName::SEARCH_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(minContactId))
|
||||
.append(" WHERE ");
|
||||
for (auto it = Ids.begin(); it != Ids.end(); ++it) {
|
||||
updateRawContact.append("id = ").append(std::to_string(*it));
|
||||
updateSearchSql.append("id = ").append(std::to_string(*it));
|
||||
if (*it != *Ids.rbegin()) {
|
||||
updateRawContact.append(" OR ");
|
||||
updateSearchSql.append(" OR ");
|
||||
}
|
||||
}
|
||||
updateRawContact.append(" ) AND is_deleted = 0");
|
||||
int ret = store->ExecuteSql(updateRawContact);
|
||||
int code = store->ExecuteSql(updateSearchSql);
|
||||
if (ret != RDB_EXECUTE_OK || code != RDB_EXECUTE_OK) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::string MergerContacts::QueryCandidateName(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int id)
|
||||
{
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
std::string sqlBuilder = "SELECT ";
|
||||
sqlBuilder.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(id))
|
||||
.append(" AND ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(nameType));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sqlBuilder);
|
||||
std::string candidateName;
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
resultSet->GetString(0, candidateName);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
return candidateName;
|
||||
}
|
||||
|
||||
std::set<int> MergerContacts::QueryTargetName(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int rawId, std::set<std::string> data)
|
||||
{
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
std::set<int> ids;
|
||||
for (auto it = data.begin(); it != data.end(); it++) {
|
||||
std::string query = "SELECT ";
|
||||
query.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(" = '")
|
||||
.append(*it)
|
||||
.append("' AND ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(nameType))
|
||||
.append(" AND is_deleted = 0");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(query);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int value = 0;
|
||||
resultSet->GetInt(0, value);
|
||||
if (value != rawId) {
|
||||
ids.insert(value);
|
||||
}
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
std::vector<std::set<int>> MergerContacts::QueryMergeContacts(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int mode)
|
||||
{
|
||||
std::string sqlBuilder = "SELECT ";
|
||||
sqlBuilder.append(ContactPublicColumns::ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::IS_MERGE_TARGET)
|
||||
.append(" = ")
|
||||
.append(std::to_string(g_isNeedMergeTargetNum[1]))
|
||||
.append(" AND ")
|
||||
.append(RawContactColumns::IS_DELETED)
|
||||
.append(" = 0")
|
||||
.append(" AND ")
|
||||
.append(RawContactColumns::MERGE_MODE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(mode));
|
||||
std::vector<int> currentIds;
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sqlBuilder);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int currentId = 0;
|
||||
resultSet->GetInt(0, currentId);
|
||||
currentIds.push_back(currentId);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
HILOG_INFO("QueryMergeContacts currentIds' size = %{public}d", currentIds.size());
|
||||
std::vector<std::set<int>> candidates;
|
||||
UpdateCandidate(store, currentIds, candidates);
|
||||
return candidates;
|
||||
}
|
||||
|
||||
void MergerContacts::UpdateCandidate(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::vector<int> currentIds,
|
||||
std::vector<std::set<int>> &candidates)
|
||||
{
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
int phoneType = contactsDataBase->GetTypeId(ContentTypeData::PHONE);
|
||||
MergeUtils mergeUtils;
|
||||
for (auto rawId : currentIds) {
|
||||
std::set<std::string> names = mergeUtils.QueryRawContactByType(store, rawId, nameType);
|
||||
std::set<std::string> phones = mergeUtils.QueryRawContactByType(store, rawId, phoneType);
|
||||
if (names.empty()) {
|
||||
HILOG_ERROR("MergerContacts::UpdateCandidate target names is empty");
|
||||
break;
|
||||
}
|
||||
std::set<int> nameIds = QueryTargetName(store, rawId, names);
|
||||
std::set<int> rawIds;
|
||||
rawIds.insert(rawId);
|
||||
for (auto nameId = nameIds.begin(); nameId != nameIds.end(); nameId++) {
|
||||
std::set<std::string> otherPhones = mergeUtils.QueryRawContactByType(store, *nameId, phoneType);
|
||||
bool isMatch = mergeUtils.SetEqual(phones, otherPhones);
|
||||
if (isMatch) {
|
||||
rawIds.insert(*nameId);
|
||||
}
|
||||
}
|
||||
HILOG_INFO("rawIds' size = %{public}d", rawIds.size());
|
||||
candidates.push_back(rawIds);
|
||||
}
|
||||
HILOG_INFO("candidates' size = %{public}d", candidates.size());
|
||||
}
|
||||
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> MergerContacts::SelectCandidate(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store)
|
||||
{
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet;
|
||||
if (store == nullptr) {
|
||||
HILOG_ERROR("MergerContacts SelectCandidate store is nullptr");
|
||||
return resultSet;
|
||||
}
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
int phoneType = contactsDataBase->GetTypeId(ContentTypeData::PHONE);
|
||||
std::string sql = "SELECT ";
|
||||
sql.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(", ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(", ")
|
||||
.append(ContentTypeColumns::CONTENT_TYPE)
|
||||
.append(", ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(", ")
|
||||
.append(RawContactColumns::DISPLAY_NAME)
|
||||
.append(", ")
|
||||
.append(RawContactColumns::PHOTO_FIRST_NAME)
|
||||
.append(", ")
|
||||
.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(" FROM ")
|
||||
.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" IN(SELECT ")
|
||||
.append(RawContactColumns::ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::IS_DELETED)
|
||||
.append(" = 0")
|
||||
.append(" AND ")
|
||||
.append(RawContactColumns::MERGE_MODE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(MERGE_MODE_MANUAL))
|
||||
.append(") AND ( ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(phoneType))
|
||||
.append(" OR ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(nameType))
|
||||
.append(" ) GROUP BY ")
|
||||
.append(RawContactColumns::CONTACT_ID);
|
||||
resultSet = store->QuerySql(sql);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ManualMerge operation for candidate contacts
|
||||
*
|
||||
* @param store Conditions for split operation
|
||||
* @param predicates Conditions for update operation
|
||||
*
|
||||
* @return The result returned by the ManualMerge operation
|
||||
*/
|
||||
int MergerContacts::ReContactMerge(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, const OHOS::NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
HILOG_INFO("MergerContacts::ReContactMerge is starting");
|
||||
std::vector<std::string> whereArgs = predicates.GetWhereArgs();
|
||||
std::set<int> ids;
|
||||
for (auto value : whereArgs) {
|
||||
ids.insert(atoi(value.c_str()));
|
||||
}
|
||||
if (ids.size() == 0) {
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
std::vector<std::set<int>> selectedIds = SelectIdsByName(store, ids);
|
||||
int minId = 0;
|
||||
bool isModeHasError = false;
|
||||
std::set<int> currentIds;
|
||||
for (auto it = selectedIds.begin(); it != selectedIds.end(); ++it) {
|
||||
currentIds = *it;
|
||||
std::set<int> handledIds = HandleIds(store, currentIds);
|
||||
HILOG_INFO("ReContactMerge size = :%{public}d", handledIds.size());
|
||||
if (handledIds.size() == 1) {
|
||||
HILOG_ERROR("MergeCircle continue ");
|
||||
isModeHasError = true;
|
||||
continue;
|
||||
}
|
||||
auto minIdPosition = handledIds.begin();
|
||||
minId = *minIdPosition;
|
||||
int ret = ManualMergeOperation(store, minId, handledIds);
|
||||
if (ret != RDB_EXECUTE_OK) {
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
MatchCandidate matchCandidate;
|
||||
matchCandidate.FindMatchContact(store, minId);
|
||||
}
|
||||
if (isModeHasError) {
|
||||
HILOG_ERROR("MergerContacts::MergeCircle only one candidate has manual_merge_mode");
|
||||
return RDB_EXECUTE_FAIL;
|
||||
} else {
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int MergerContacts::ManualMergeOperation(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, int minId, std::set<int> handledIds)
|
||||
{
|
||||
UpdateRawContacts(store, minId, handledIds);
|
||||
DeleteContacts(store, minId, handledIds);
|
||||
std::string sql = "UPDATE ";
|
||||
sql.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::IS_NEED_MERGE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(g_isNeedMergeNum[1]))
|
||||
.append(", ")
|
||||
.append(RawContactColumns::IS_MERGE_TARGET)
|
||||
.append(" = ")
|
||||
.append(std::to_string(g_isNeedMergeTargetNum[0]))
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(minId));
|
||||
int error = store->ExecuteSql(sql);
|
||||
if (error != RDB_EXECUTE_OK) {
|
||||
HILOG_ERROR("MergerContacts::ReContactMerge errorcode :%{public}d", error);
|
||||
return error;
|
||||
}
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
|
||||
std::vector<std::set<int>> MergerContacts::SelectIdsByName(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> ids)
|
||||
{
|
||||
HILOG_INFO("MergerContacts::SelectIdsByName is starting");
|
||||
std::vector<std::set<int>> selectedIds;
|
||||
std::set<std::string> names;
|
||||
std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int nameType = contactsDataBase->GetTypeId(ContentTypeData::NAME);
|
||||
for (auto id : ids) {
|
||||
std::string sql = "SELECT ";
|
||||
sql.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(id))
|
||||
.append(" AND ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(nameType));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sql);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
std::string name;
|
||||
resultSet->GetString(0, name);
|
||||
names.insert(name);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
}
|
||||
UpdateIdsByName(store, names, ids, selectedIds);
|
||||
return selectedIds;
|
||||
}
|
||||
|
||||
void MergerContacts::UpdateIdsByName(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<std::string> names,
|
||||
std::set<int> ids, std::vector<std::set<int>> &selectedIds)
|
||||
{
|
||||
for (auto name : names) {
|
||||
std::string sqlBuilder = "SELECT ";
|
||||
sqlBuilder.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(" = '")
|
||||
.append(name)
|
||||
.append("' AND ")
|
||||
.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" IN(");
|
||||
for (auto id = ids.begin(); id != ids.end(); ++id) {
|
||||
if (*id == *ids.rbegin()) {
|
||||
sqlBuilder.append(std::to_string(*id)).append(")");
|
||||
} else {
|
||||
sqlBuilder.append(std::to_string(*id)).append(", ");
|
||||
}
|
||||
}
|
||||
std::set<int> currentIds;
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store->QuerySql(sqlBuilder);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int id = 0;
|
||||
resultSet->GetInt(0, id);
|
||||
currentIds.insert(id);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
selectedIds.push_back(currentIds);
|
||||
}
|
||||
}
|
||||
|
||||
bool MergerContacts::isNameMatch(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> ids)
|
||||
{
|
||||
std::set<std::string> names;
|
||||
for (auto it : ids) {
|
||||
std::string name = QueryCandidateName(store, it);
|
||||
names.insert(name);
|
||||
}
|
||||
if (names.size() == 1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Force contact merge for candidate contacts
|
||||
*
|
||||
* @param store Conditions for split operation
|
||||
* @param ids Conditions for update operation
|
||||
*
|
||||
* @return The result returned by the ForceContactMerge operation
|
||||
*/
|
||||
int MergerContacts::ForceContactMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore> store, std::set<int> ids)
|
||||
{
|
||||
if (store == nullptr) {
|
||||
HILOG_ERROR("stroe is empty");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int minId = 0;
|
||||
if (isNameMatch(store, ids)) {
|
||||
std::set<int> handledIds = HandleIds(store, ids);
|
||||
HILOG_INFO("ForceContactMerge size = %{public}d", handledIds.size());
|
||||
auto minIdPosition = handledIds.begin();
|
||||
minId = *minIdPosition;
|
||||
UpdateRawContacts(store, minId, handledIds);
|
||||
DeleteContacts(store, minId, handledIds);
|
||||
} else {
|
||||
HILOG_ERROR("Invalid parameter passed");
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
std::string sql = "UPDATE ";
|
||||
sql.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET ")
|
||||
.append(RawContactColumns::IS_NEED_MERGE)
|
||||
.append(" = ")
|
||||
.append(std::to_string(g_isNeedMergeNum[1]))
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(minId));
|
||||
int error = store->ExecuteSql(sql);
|
||||
if (error != RDB_EXECUTE_OK) {
|
||||
HILOG_ERROR("MergerContacts::ForceMerge errorcode :%{public}d", error);
|
||||
return error;
|
||||
}
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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 CHARACTER_TRANSLITERATE_H
|
||||
#define CHARACTER_TRANSLITERATE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
struct ChineseTable {
|
||||
// The first letter of Pinyin
|
||||
std::string initials;
|
||||
// Pinyin
|
||||
std::string nameFullFight_;
|
||||
std::string chineseCharacters_;
|
||||
};
|
||||
|
||||
struct Container {
|
||||
// The container of first letter
|
||||
std::vector<std::vector<std::wstring>> initialsContainer_;
|
||||
// Pinyin container
|
||||
std::vector<std::vector<std::wstring>> nameFullFightContainer_;
|
||||
};
|
||||
|
||||
class CharacterTransliterate {
|
||||
public:
|
||||
CharacterTransliterate();
|
||||
~CharacterTransliterate();
|
||||
static ChineseTable chineseTable_[];
|
||||
bool IsChineseCharacter(wchar_t chineseCharacter);
|
||||
Container GetContainer(std::wstring wChinese);
|
||||
std::wstring Join(std::vector<std::vector<std::wstring>> strVector, std::wstring split);
|
||||
void GetCommonPronunciation(
|
||||
std::wstring &chineseCharacter, std::vector<std::wstring> &initials, std::vector<std::wstring> &nameFullFights);
|
||||
std::vector<std::vector<std::wstring>> GetCombinedVector(std::vector<std::vector<std::wstring>> sourceVector);
|
||||
std::wstring StringToWstring(std::string str);
|
||||
std::string WstringToString(std::wstring str);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CHARACTER_TRANSLITERATE_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 CONSTRUCTION_NAME_H
|
||||
#define CONSTRUCTION_NAME_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ConstructionName {
|
||||
public:
|
||||
ConstructionName();
|
||||
~ConstructionName();
|
||||
int sortFirstLetterCode_ = 0;
|
||||
// The first letter
|
||||
std::string initials_;
|
||||
// Full-Pinyin
|
||||
std::string nameFullFight_;
|
||||
std::string sortFirstLetter_;
|
||||
std::string disPlayName_;
|
||||
std::string photoFirstName_;
|
||||
static std::string local;
|
||||
ConstructionName GetConstructionName(std::string &chineseCharacter, ConstructionName &constructionName);
|
||||
ConstructionName GetPhotoFirstName(ConstructionName &constructionName);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CONSTRUCTION_NAME_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 "construction_name.h"
|
||||
|
||||
#include "character_transliterate.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
std::string ConstructionName::local = "zh-CN";
|
||||
ConstructionName::ConstructionName()
|
||||
{
|
||||
}
|
||||
|
||||
ConstructionName::~ConstructionName()
|
||||
{
|
||||
}
|
||||
|
||||
ConstructionName ConstructionName::GetConstructionName(
|
||||
std::string &chineseCharacter, ConstructionName &constructionName)
|
||||
{
|
||||
CharacterTransliterate characterTransliterate;
|
||||
if (strcmp(local.c_str(), "zh-CN") == 0) {
|
||||
Container container =
|
||||
characterTransliterate.GetContainer(characterTransliterate.StringToWstring(chineseCharacter));
|
||||
std::wstring split(L"||");
|
||||
std::wstring initials = characterTransliterate.Join(container.initialsContainer_, split);
|
||||
std::wstring nameFullFight = characterTransliterate.Join(container.nameFullFightContainer_, split);
|
||||
constructionName.initials_ = characterTransliterate.WstringToString(initials);
|
||||
constructionName.nameFullFight_ = characterTransliterate.WstringToString(nameFullFight);
|
||||
const wchar_t *nameFullFightInitials = nameFullFight.c_str();
|
||||
if ((nameFullFightInitials[0] >= L'a' && nameFullFightInitials[0] <= L'z') ||
|
||||
(nameFullFightInitials[0] >= L'A' && nameFullFightInitials[0] <= L'Z')) {
|
||||
std::string sortFirstLetterTemp = characterTransliterate.WstringToString(nameFullFight.substr(0, 1));
|
||||
std::transform(
|
||||
sortFirstLetterTemp.begin(), sortFirstLetterTemp.end(), sortFirstLetterTemp.begin(), std::toupper);
|
||||
constructionName.sortFirstLetter_ = sortFirstLetterTemp;
|
||||
int code = constructionName.sortFirstLetter_.c_str()[0];
|
||||
constructionName.sortFirstLetterCode_ = code;
|
||||
HILOG_INFO(" GetConstructionName sortFirstLetterCode :%{public}d", code);
|
||||
} else {
|
||||
std::wstring sortFirstLetter(L"#");
|
||||
constructionName.sortFirstLetter_ = characterTransliterate.WstringToString(sortFirstLetter);
|
||||
constructionName.sortFirstLetterCode_ = -1;
|
||||
}
|
||||
} else {
|
||||
constructionName.initials_ = chineseCharacter;
|
||||
constructionName.nameFullFight_ = chineseCharacter;
|
||||
if ((chineseCharacter[0] >= 'a' && chineseCharacter[0] <= 'z') ||
|
||||
(chineseCharacter[0] >= 'A' && chineseCharacter[0] <= 'Z')) {
|
||||
std::string sortFirstLetterTemp = chineseCharacter.substr(0, 1);
|
||||
std::transform(
|
||||
sortFirstLetterTemp.begin(), sortFirstLetterTemp.end(), sortFirstLetterTemp.begin(), std::toupper);
|
||||
constructionName.sortFirstLetter_ = sortFirstLetterTemp;
|
||||
int code = constructionName.sortFirstLetter_.c_str()[0];
|
||||
constructionName.sortFirstLetterCode_ = code;
|
||||
HILOG_INFO(" GetConstructionName sortFirstLetterCode1 :%{public}d", code);
|
||||
} else {
|
||||
std::string sortFirstLetter("#");
|
||||
constructionName.sortFirstLetter_ = sortFirstLetter;
|
||||
constructionName.sortFirstLetterCode_ = -1;
|
||||
}
|
||||
}
|
||||
constructionName.disPlayName_ = chineseCharacter;
|
||||
return GetPhotoFirstName(constructionName);
|
||||
}
|
||||
|
||||
ConstructionName ConstructionName::GetPhotoFirstName(ConstructionName &constructionName)
|
||||
{
|
||||
if (!constructionName.disPlayName_.empty()) {
|
||||
CharacterTransliterate characterTransliterate;
|
||||
std::wstring nameWstr = characterTransliterate.StringToWstring(constructionName.disPlayName_);
|
||||
int len = nameWstr.size();
|
||||
for (int index = 0; index < len; index++) {
|
||||
if (characterTransliterate.IsChineseCharacter(nameWstr[index])) {
|
||||
std::wstring childwChineseCharacter = nameWstr.substr(index, 1);
|
||||
constructionName.photoFirstName_ = characterTransliterate.WstringToString(childwChineseCharacter);
|
||||
return constructionName;
|
||||
}
|
||||
}
|
||||
if ((constructionName.disPlayName_[0] >= 'a' && constructionName.disPlayName_[0] <= 'z') ||
|
||||
(constructionName.disPlayName_[0] >= 'A' && constructionName.disPlayName_[0] <= 'Z')) {
|
||||
constructionName.photoFirstName_ = constructionName.disPlayName_[0];
|
||||
}
|
||||
}
|
||||
return constructionName;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.contactsdataability",
|
||||
"vendor": "ohos",
|
||||
"version": {
|
||||
"code": 1,
|
||||
"name": "1.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 3,
|
||||
"target": 3
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "com.ohos.contactsdataability",
|
||||
"name": ".ContactsDataAbility",
|
||||
|
||||
"deviceType": [
|
||||
"smartVision"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry"
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"permissions": [
|
||||
"com.ohos.contactsdataability.DataAbilityShellProvider.PROVIDER"
|
||||
],
|
||||
"name": "ContactsDataAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "dataability_description",
|
||||
"type": "data",
|
||||
"uri": "dataability://com.ohos.contactsdataability",
|
||||
"visible":true,
|
||||
"srcLanguage":"c++"
|
||||
},
|
||||
{
|
||||
"permissions": [
|
||||
"com.ohos.voicemailability.DataAbilityShellProvider.PROVIDER"
|
||||
],
|
||||
"name": "VoiceMailAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "dataability_description",
|
||||
"type": "data",
|
||||
"uri": "dataability://com.ohos.voicemailability",
|
||||
"visible":true,
|
||||
"srcLanguage":"c++"
|
||||
},
|
||||
{
|
||||
"permissions": [
|
||||
"com.ohos.calllogability.DataAbilityShellProvider.PROVIDER"
|
||||
],
|
||||
"name": "CallLogAbility",
|
||||
"icon": "$media:icon",
|
||||
"description": "dataability_description",
|
||||
"type": "data",
|
||||
"uri": "dataability://com.ohos.calllogability",
|
||||
"visible":true,
|
||||
"srcLanguage":"c++"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
# 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 contactsapi.so {{{
|
||||
config("contactsapi_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
]
|
||||
cflags = [ ]
|
||||
}
|
||||
|
||||
ohos_shared_library("contactsapi") {
|
||||
sources = [
|
||||
"src/native_module.cpp",
|
||||
"src/result_convert.cpp",
|
||||
"src/contacts_api.cpp",
|
||||
"src/contacts_build.cpp",
|
||||
"src/contacts_control.cpp"
|
||||
]
|
||||
|
||||
include_dirs=[
|
||||
"//utils/system/safwk/native/include",
|
||||
"//utils/native/base/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/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/interfaces/innerkits/base/include/ohos/aafwk/base",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native",
|
||||
"//utils/native/base:utils",
|
||||
"//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",
|
||||
]
|
||||
|
||||
public_configs = [ ":contactsapi_public_config" ]
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:want",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"eventhandler:libeventhandler",
|
||||
"ipc:ipc_core",
|
||||
"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 contactsapi.so }}}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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_API_H
|
||||
#define CONTACT_API_H
|
||||
|
||||
#include "contacts_build.h"
|
||||
#include "contacts_napi_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
void Init(napi_env env, napi_value exports);
|
||||
napi_value AddContact(napi_env env, napi_callback_info info);
|
||||
napi_value DeleteContact(napi_env env, napi_callback_info info);
|
||||
napi_value UpdateContact(napi_env env, napi_callback_info info);
|
||||
napi_value QueryContact(napi_env env, napi_callback_info info);
|
||||
napi_value QueryContacts(napi_env env, napi_callback_info info);
|
||||
napi_value QueryContactsByEmail(napi_env env, napi_callback_info info);
|
||||
napi_value QueryContactsByPhoneNumber(napi_env env, napi_callback_info info);
|
||||
napi_value QueryGroups(napi_env env, napi_callback_info info);
|
||||
napi_value QueryHolders(napi_env env, napi_callback_info info);
|
||||
napi_value QueryKey(napi_env env, napi_callback_info info);
|
||||
napi_value QueryMyCard(napi_env env, napi_callback_info info);
|
||||
napi_value IsMyCard(napi_env env, napi_callback_info info);
|
||||
napi_value IsLocalContact(napi_env env, napi_callback_info info);
|
||||
void Execute(napi_env env, void *data);
|
||||
void ExecuteAsync(napi_env env, void *data);
|
||||
void ExecuteDone(napi_env env, napi_status status, void *data);
|
||||
void ExecuteSyncDone(napi_env env, napi_status status, void *data);
|
||||
int GetMethodType(napi_env env, napi_callback_info info);
|
||||
int GetRawIdByResultSet(const std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
napi_value CreateAsyncWork(napi_env env, ExecuteHelper *executeHelper, napi_callback_info info);
|
||||
napi_value LocalExecute(napi_env env, ExecuteHelper *executeHelper);
|
||||
void LocalExecuteAddContact(napi_env env, ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteDeleteContact(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteQueryContact(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteQueryContactsOrKey(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteQueryContactsByData(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteQueryGroup(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteQueryHolders(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteQueryMyCard(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteUpdateContact(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteIsLocalContact(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
void LocalExecuteIsMyCard(napi_env env, const ExecuteHelper *executeHelper, napi_value &result);
|
||||
napi_value Scheduling(napi_env env, napi_callback_info info, ExecuteHelper *executeHelper, int actionCode);
|
||||
void SetChildActionCodeAndConvertParams(napi_env env, napi_callback_info info, ExecuteHelper *executeHelper);
|
||||
NativeRdb::DataAbilityPredicates ConvertParamsSwitchSplit(
|
||||
int code, napi_env env, napi_value &key, napi_value &hold, napi_value &attr);
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> GetDataAbilityHelper(napi_env env);
|
||||
void HolderPredicates(const Holder &holder, NativeRdb::DataAbilityPredicates &predicates);
|
||||
void AttributesPredicates(ContactAttributes &attrs, NativeRdb::DataAbilityPredicates &predicates);
|
||||
NativeRdb::DataAbilityPredicates BuildQureyContactPredicates(
|
||||
napi_env env, std::string key, napi_value hold, napi_value attr);
|
||||
NativeRdb::DataAbilityPredicates BuildUpdateContactPredicates(napi_env env, napi_value contacts, napi_value attr);
|
||||
NativeRdb::DataAbilityPredicates BuildQuerytContactData(napi_env env, napi_value &contactsObject,
|
||||
napi_value &attrObject, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
std::vector<std::string> BuildUpdateContactColumns();
|
||||
void BuildUpdateContactConvertParams(
|
||||
napi_env env, napi_value &contacts, napi_value &attr, ExecuteHelper &executeHelper);
|
||||
NativeRdb::DataAbilityPredicates BuildQureyContactsPredicates(napi_env env, napi_value hold, napi_value attr);
|
||||
NativeRdb::DataAbilityPredicates BuildQureyContactsByEmailPredicates(
|
||||
napi_env env, std::string email, napi_value hold, napi_value attr);
|
||||
NativeRdb::DataAbilityPredicates BuildQureyContactsByPhoneNumberPredicates(
|
||||
napi_env env, std::string phoneNumber, napi_value hold, napi_value attr);
|
||||
NativeRdb::DataAbilityPredicates BuildQureyGroupsPredicates(napi_env env, napi_value hold);
|
||||
NativeRdb::DataAbilityPredicates BuildQureyKeyPredicates(napi_env env, int id, napi_value hold);
|
||||
NativeRdb::DataAbilityPredicates BuildQueryMyCardPredicates(napi_env env, napi_value attr);
|
||||
NativeRdb::DataAbilityPredicates BuildIsLocalContactPredicates(napi_env env, napi_value id);
|
||||
NativeRdb::DataAbilityPredicates BuildIsMyCardPredicates(napi_env env, napi_value id);
|
||||
NativeRdb::DataAbilityPredicates BuildDeleteContactDataPredicates(napi_env env, int rawId, napi_value attr);
|
||||
NativeRdb::DataAbilityPredicates BuildDeleteContactPredicates(napi_env env, napi_callback_info info);
|
||||
void ObjectInit(napi_env env, napi_value object, napi_value &hold, napi_value &attr, napi_value &contacts);
|
||||
void ObjectInitId(napi_env env, napi_value object, napi_value &id);
|
||||
void ObjectInitString(napi_env env, napi_value object, napi_value &key);
|
||||
int GetType(napi_env env, napi_value value);
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // CONTACT_API_H
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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_BUILD_H
|
||||
#define CONTACT_BUILD_H
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_context.h"
|
||||
#include "context.h"
|
||||
#include "data_ability_helper.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
#include "contacts_napi_common.h"
|
||||
#include "contacts_napi_object.h"
|
||||
#include "hilog_wrapper_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
class ContactsBuild {
|
||||
public:
|
||||
ContactsBuild();
|
||||
~ContactsBuild();
|
||||
void GetContactDataByObject(napi_env env, napi_value object, Contacts &contacts);
|
||||
int GetInt(napi_env env, napi_value id);
|
||||
void GetContactData(napi_env env, napi_callback_info info, std::vector<NativeRdb::ValuesBucket> &valueContact,
|
||||
std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
std::string NapiGetValueString(napi_env env, napi_value value);
|
||||
ContactAttributes GetContactAttributes(napi_env env, napi_value object);
|
||||
Holder GetHolder(napi_env env, napi_value object);
|
||||
void BuildValueContactDataByType(
|
||||
Contacts &contacts, int typeId, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
|
||||
private:
|
||||
void TypeSwitchSplit(int typeId, Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
napi_value GetArrayByKey(napi_env env, napi_value valueObject, std::string key);
|
||||
napi_value GetObjectByKey(napi_env env, napi_value object, std::string key);
|
||||
std::string GetStringValueByKey(napi_env env, napi_value valueObject, std::string key);
|
||||
int GetIntValueByKey(napi_env env, napi_value valueObject, std::string key);
|
||||
Name GetName(napi_env env, napi_value object);
|
||||
Portrait GetUri(napi_env env, napi_value object);
|
||||
std::vector<Email> GetEmails(napi_env env, napi_value object);
|
||||
std::vector<Event> GetEvent(napi_env env, napi_value object);
|
||||
std::vector<Group> GetGroup(napi_env env, napi_value object);
|
||||
std::vector<ImAddress> GetImAddress(napi_env env, napi_value object);
|
||||
std::vector<PhoneNumber> GetPhoneNumbers(napi_env env, napi_value object);
|
||||
std::vector<PostalAddress> GetPostalAddress(napi_env env, napi_value object);
|
||||
std::vector<Relation> GetRelation(napi_env env, napi_value object);
|
||||
std::vector<SipAddress> GetSipAddress(napi_env env, napi_value object);
|
||||
std::vector<Website> GetWebsite(napi_env env, napi_value object);
|
||||
NickName GetNickName(napi_env env, napi_value object);
|
||||
Note GetNote(napi_env env, napi_value object);
|
||||
Organization GetOrganization(napi_env env, napi_value object);
|
||||
// structure parameter and ValuesBucket
|
||||
void BuildValueContact(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContact);
|
||||
void BuildValueContactData(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketEmail(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketEvent(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketGroup(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketImAddress(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketPortrait(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketPhoneNumber(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketPostalAddress(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketRelation(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketSipAddress(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketWebsite(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketName(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketNickName(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketNote(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
void GetValuesBucketOrganization(Contacts &contacts, std::vector<NativeRdb::ValuesBucket> &valueContactData);
|
||||
};
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_BUILD_H
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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_CONTROL_H
|
||||
#define CONTACT_CONTROL_H
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_context.h"
|
||||
#include "context.h"
|
||||
#include "data_ability_helper.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
#include "contacts_napi_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
class ContactsControl {
|
||||
public:
|
||||
ContactsControl();
|
||||
~ContactsControl();
|
||||
int64_t RawContactInsert(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues);
|
||||
int ContactDataInsert(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> contactsDataValues);
|
||||
int RawContactUpdate(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::ValuesBucket updateValues, OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
int ContactDataUpdate(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::ValuesBucket updateValues, OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
int ContactDelete(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
int ContactDataDelete(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactDataQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> GroupsQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> MyCardQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> HolderQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
};
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_CONTROL_H
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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_NAPI_COMMON_H
|
||||
#define CONTACT_NAPI_COMMON_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "data_ability_helper.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "rdb_store.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
constexpr int MAX_PARAMS = 6;
|
||||
constexpr int ERROR = -1;
|
||||
|
||||
constexpr int NAPI_GET_STRING_SIZE = 256;
|
||||
constexpr int REQUEST_PARAMS_COUNT_ONE = 1;
|
||||
|
||||
// NAPI type
|
||||
constexpr int TYPE_NAPI_ERROR = -1;
|
||||
constexpr int TYPE_NAPI_NUMBER = 0;
|
||||
constexpr int TYPE_NAPI_STRING = 1;
|
||||
constexpr int TYPE_HOLDER = 2;
|
||||
constexpr int TYPE_ATTR = 3;
|
||||
constexpr int TYPE_CONTACT = 4;
|
||||
|
||||
// Execute action code
|
||||
constexpr int ADD_CONTACT = 1001;
|
||||
constexpr int DELETE_CONTACT = 2001;
|
||||
constexpr int UPDATE_CONTACT = 3001;
|
||||
|
||||
constexpr int QUERY_CONTACTS = 4001;
|
||||
constexpr int QUERY_CONTACT = 4008;
|
||||
|
||||
constexpr int QUERY_CONTACTS_BY_EMAIL = 4002;
|
||||
constexpr int QUERY_CONTACTS_BY_PHONE_NUMBER = 4003;
|
||||
constexpr int QUERY_GROUPS = 4004;
|
||||
constexpr int QUERY_HOLDERS = 4005;
|
||||
constexpr int QUERY_KEY = 4006;
|
||||
constexpr int QUERY_MY_CARD = 4007;
|
||||
constexpr int IS_LOCAL_CONTACT = 5008;
|
||||
constexpr int IS_MY_CARD = 5009;
|
||||
|
||||
// contactsData type
|
||||
constexpr int EMAIL = 1;
|
||||
constexpr int IM = 2;
|
||||
constexpr int NICKNAME = 3;
|
||||
constexpr int ORGANIZATION = 4;
|
||||
constexpr int PHONE = 5;
|
||||
constexpr int NAME = 6;
|
||||
constexpr int POSTAL_ADDRESS = 7;
|
||||
constexpr int PHOTO = 8;
|
||||
constexpr int GROUP_MEMBERSHIP = 9;
|
||||
constexpr int NOTE = 10;
|
||||
constexpr int CONTACT_EVENT = 11;
|
||||
constexpr int WEBSITE = 12;
|
||||
constexpr int RELATION = 13;
|
||||
constexpr int CONTACT_MISC = 14;
|
||||
constexpr int HICALL_DEVICE = 15;
|
||||
constexpr int CAMCARD = 16;
|
||||
constexpr int SIP_ADDRESS = 17;
|
||||
|
||||
struct ExecuteHelper {
|
||||
ExecuteHelper()
|
||||
: work(nullptr), deferred(nullptr), dataValue(nullptr), sync(1), argc(0), actionCode(-1), callBack(nullptr),
|
||||
info(nullptr), childActionCode(0) {};
|
||||
napi_async_work work;
|
||||
napi_deferred deferred;
|
||||
napi_value dataValue;
|
||||
int sync;
|
||||
int argc;
|
||||
int actionCode;
|
||||
napi_ref callBack;
|
||||
napi_callback_info info;
|
||||
int childActionCode;
|
||||
napi_value promise;
|
||||
// query
|
||||
std::vector<std::string> columns;
|
||||
// condition
|
||||
NativeRdb::DataAbilityPredicates predicates;
|
||||
// update
|
||||
std::vector<NativeRdb::ValuesBucket> valueUpdateContact;
|
||||
// insert
|
||||
std::vector<NativeRdb::ValuesBucket> valueContact;
|
||||
// insertContactData
|
||||
std::vector<NativeRdb::ValuesBucket> valueContactData;
|
||||
// dataAbilityHelper
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper;
|
||||
};
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_NAPI_COMMON_H
|
||||
@@ -0,0 +1,854 @@
|
||||
/*
|
||||
* 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_NAPI_OBJECT_H
|
||||
#define CONTACT_NAPI_OBJECT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
enum class Attribute {
|
||||
/**
|
||||
* Indicates the contact event.
|
||||
*/
|
||||
ATTR_CONTACT_EVENT,
|
||||
|
||||
/**
|
||||
* Indicates the email address.
|
||||
*/
|
||||
ATTR_EMAIL,
|
||||
|
||||
/**
|
||||
* Indicates the contact group.
|
||||
*/
|
||||
ATTR_GROUP_MEMBERSHIP,
|
||||
|
||||
/**
|
||||
* Indicates the instant messaging (IM) address.
|
||||
*/
|
||||
ATTR_IM,
|
||||
|
||||
/**
|
||||
* Indicates the name.
|
||||
*/
|
||||
ATTR_NAME,
|
||||
|
||||
/**
|
||||
* Indicates the nickname.
|
||||
*/
|
||||
ATTR_NICKNAME,
|
||||
|
||||
/**
|
||||
* Indicates the note.
|
||||
*/
|
||||
ATTR_NOTE,
|
||||
|
||||
/**
|
||||
* Indicates the organization.
|
||||
*/
|
||||
ATTR_ORGANIZATION,
|
||||
|
||||
/**
|
||||
* Indicates the phone number.
|
||||
*/
|
||||
ATTR_PHONE,
|
||||
|
||||
/**
|
||||
* Indicates the portrait.
|
||||
*/
|
||||
ATTR_PORTRAIT,
|
||||
|
||||
/**
|
||||
* Indicates the postal address.
|
||||
*/
|
||||
ATTR_POSTAL_ADDRESS,
|
||||
|
||||
/**
|
||||
* Indicates the relation.
|
||||
*/
|
||||
ATTR_RELATION,
|
||||
|
||||
/**
|
||||
* Indicates the Session Initiation Protocol (SIP) address.
|
||||
*/
|
||||
ATTR_SIP_ADDRESS,
|
||||
|
||||
/**
|
||||
* Indicates the website.
|
||||
*/
|
||||
ATTR_WEBSITE
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for contact attributes information
|
||||
*/
|
||||
class ContactAttributes {
|
||||
public:
|
||||
/**
|
||||
* Indicates the contact attributes.
|
||||
*/
|
||||
std::vector<int> attributes;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for email information
|
||||
*/
|
||||
class Email {
|
||||
public:
|
||||
/**
|
||||
* Indicates a custom label.
|
||||
*/
|
||||
int CUSTOM_LABEL = 0;
|
||||
|
||||
/**
|
||||
* Indicates a home email.
|
||||
*/
|
||||
int EMAIL_HOME = 1;
|
||||
|
||||
/**
|
||||
* Indicates a work email.
|
||||
*/
|
||||
int EMAIL_WORK = 2;
|
||||
|
||||
/**
|
||||
* Indicates an email of the OTHER type.
|
||||
*/
|
||||
int EMAIL_OTHER = 3;
|
||||
|
||||
/**
|
||||
* Indicates an invalid label ID.
|
||||
*/
|
||||
int INVALID_LABEL_ID = -1;
|
||||
|
||||
/**
|
||||
* Indicates the email address.
|
||||
*/
|
||||
std::string email;
|
||||
|
||||
/**
|
||||
* Indicates the label name of an attribute.
|
||||
*/
|
||||
std::string labelName;
|
||||
|
||||
/**
|
||||
* Indicates the displayed email name.
|
||||
*/
|
||||
std::string displayName;
|
||||
|
||||
/**
|
||||
* Indicates the label id.
|
||||
*/
|
||||
int labelId = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for event information
|
||||
*/
|
||||
class Event {
|
||||
public:
|
||||
/**
|
||||
* Indicates a custom label.
|
||||
*/
|
||||
int CUSTOM_LABEL = 0;
|
||||
|
||||
/**
|
||||
* Indicates an anniversary event.
|
||||
*/
|
||||
int EVENT_ANNIVERSARY = 1;
|
||||
|
||||
/**
|
||||
* Indicates an event of the OTHER type.
|
||||
*/
|
||||
int EVENT_OTHER = 2;
|
||||
|
||||
/**
|
||||
* Indicates an birthday event.
|
||||
*/
|
||||
int EVENT_BIRTHDAY = 3;
|
||||
|
||||
/**
|
||||
* Indicates an invalid label ID.
|
||||
*/
|
||||
int INVALID_LABEL_ID = -1;
|
||||
|
||||
/**
|
||||
* Indicates the event date.
|
||||
*/
|
||||
std::string eventDate;
|
||||
|
||||
/**
|
||||
* Indicates the label name of an attribute.
|
||||
*/
|
||||
std::string labelName;
|
||||
|
||||
/**
|
||||
* Indicates the label id.
|
||||
*/
|
||||
int labelId = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for group information
|
||||
*/
|
||||
class Group {
|
||||
public:
|
||||
/**
|
||||
* Indicates the contact group ID.
|
||||
*/
|
||||
int groupId = -1;
|
||||
|
||||
/**
|
||||
* Indicates the contact group title.
|
||||
*/
|
||||
std::string title;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for holder information
|
||||
*/
|
||||
class Holder {
|
||||
public:
|
||||
/**
|
||||
* Indicates the bundle name of a contact holder.
|
||||
*/
|
||||
std::string bundleName;
|
||||
|
||||
/**
|
||||
* Indicates the displayed name of a contact holder.
|
||||
*/
|
||||
std::string displayName;
|
||||
|
||||
/**
|
||||
* Indicates the holder ID.
|
||||
*/
|
||||
int holderId = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for ImAddress information
|
||||
*/
|
||||
class ImAddress {
|
||||
public:
|
||||
/**
|
||||
* Indicates a custom label.
|
||||
*/
|
||||
int CUSTOM_LABEL = -1;
|
||||
|
||||
/**
|
||||
* Indicates an AIM instant message.
|
||||
*/
|
||||
int IM_AIM = 0;
|
||||
|
||||
/**
|
||||
* Indicates a Windows Live instant message.
|
||||
*/
|
||||
int IM_MSN = 1;
|
||||
|
||||
/**
|
||||
* Indicates a Yahoo instant message.
|
||||
*/
|
||||
int IM_YAHOO = 2;
|
||||
|
||||
/**
|
||||
* Indicates a Skype instant message.
|
||||
*/
|
||||
int IM_SKYPE = 3;
|
||||
|
||||
/**
|
||||
* Indicates a QQ instant message.
|
||||
*/
|
||||
int IM_QQ = 4;
|
||||
|
||||
/**
|
||||
* Indicates an ICQ instant message.
|
||||
*/
|
||||
int IM_ICQ = 6;
|
||||
|
||||
/**
|
||||
* Indicates a Jabber instant message.
|
||||
*/
|
||||
int IM_JABBER = 7;
|
||||
|
||||
/**
|
||||
* Indicates an invalid label ID.
|
||||
*/
|
||||
int INVALID_LABEL_ID = -2;
|
||||
|
||||
/**
|
||||
* Indicates the IM address.
|
||||
*/
|
||||
std::string imAddress;
|
||||
|
||||
/**
|
||||
* Indicates the label name of an attribute.
|
||||
*/
|
||||
std::string labelName;
|
||||
|
||||
/**
|
||||
* Indicates the label id.
|
||||
*/
|
||||
int labelId = -1;
|
||||
};
|
||||
/**
|
||||
* Provides methods for name information
|
||||
*/
|
||||
class Name {
|
||||
public:
|
||||
/**
|
||||
* Indicates the family name of the contact.
|
||||
*/
|
||||
std::string familyName;
|
||||
|
||||
/**
|
||||
* Indicates the phonetic family name of the contact.
|
||||
*/
|
||||
std::string familyNamePhonetic;
|
||||
|
||||
/**
|
||||
* Indicates the full name of the contact.
|
||||
*/
|
||||
std::string fullName;
|
||||
|
||||
/**
|
||||
* Indicates the given name of the contact.
|
||||
*/
|
||||
std::string givenName;
|
||||
|
||||
/**
|
||||
* Indicates the phonetic given name of the contact.
|
||||
*/
|
||||
std::string givenNamePhonetic;
|
||||
|
||||
/**
|
||||
* Indicates the middle name of the contact.
|
||||
*/
|
||||
std::string middleName;
|
||||
|
||||
/**
|
||||
* Indicates the phonetic middle name of the contact.
|
||||
*/
|
||||
std::string middleNamePhonetic;
|
||||
|
||||
/**
|
||||
* Indicates the prefix of the contact name.
|
||||
*/
|
||||
std::string namePrefix;
|
||||
|
||||
/**
|
||||
* Indicates the suffix of this contact name.
|
||||
*/
|
||||
std::string nameSuffix;
|
||||
};
|
||||
/**
|
||||
* Provides methods for nick name information
|
||||
*/
|
||||
class NickName {
|
||||
public:
|
||||
/**
|
||||
* Indicates the nickname of the contact.
|
||||
*/
|
||||
std::string nickName;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for note information
|
||||
*/
|
||||
class Note {
|
||||
public:
|
||||
/**
|
||||
* Indicates the note content.
|
||||
*/
|
||||
std::string noteContent;
|
||||
};
|
||||
/**
|
||||
* Provides methods for organization information
|
||||
*/
|
||||
class Organization {
|
||||
public:
|
||||
/**
|
||||
* Indicates the name of the organization to which the contact belongs.
|
||||
*/
|
||||
std::string name;
|
||||
|
||||
/**
|
||||
* Indicates the title of the contact.
|
||||
*/
|
||||
std::string title;
|
||||
};
|
||||
/**
|
||||
* Provides methods for phone number information
|
||||
*/
|
||||
class PhoneNumber {
|
||||
public:
|
||||
/**
|
||||
* Indicates a custom label.
|
||||
*/
|
||||
int CUSTOM_LABEL = 0;
|
||||
|
||||
/**
|
||||
* Indicates a home number.
|
||||
*/
|
||||
int NUM_HOME = 1;
|
||||
|
||||
/**
|
||||
* Indicates a mobile phone number.
|
||||
*/
|
||||
int NUM_MOBILE = 2;
|
||||
|
||||
/**
|
||||
* Indicates a work number.
|
||||
*/
|
||||
int NUM_WORK = 3;
|
||||
|
||||
/**
|
||||
* Indicates a work fax number.
|
||||
*/
|
||||
int NUM_FAX_WORK = 4;
|
||||
|
||||
/**
|
||||
* Indicates a home fax number.
|
||||
*/
|
||||
int NUM_FAX_HOME = 5;
|
||||
|
||||
/**
|
||||
* Indicates a pager number.
|
||||
*/
|
||||
int NUM_PAGER = 6;
|
||||
|
||||
/**
|
||||
* Indicates a number of the OTHER type.
|
||||
*/
|
||||
int NUM_OTHER = 7;
|
||||
|
||||
/**
|
||||
* Indicates a callback number.
|
||||
*/
|
||||
int NUM_CALLBACK = 8;
|
||||
|
||||
/**
|
||||
* Indicates a car number.
|
||||
*/
|
||||
int NUM_CAR = 9;
|
||||
|
||||
/**
|
||||
* Indicates a company director number.
|
||||
*/
|
||||
int NUM_COMPANY_MAIN = 10;
|
||||
|
||||
/**
|
||||
* Indicates an Integrated Services Digital Network (ISDN) number.
|
||||
*/
|
||||
int NUM_ISDN = 11;
|
||||
|
||||
/**
|
||||
* Indicates a main number.
|
||||
*/
|
||||
int NUM_MAIN = 12;
|
||||
|
||||
/**
|
||||
* Indicates a number of the OTHER_FAX type.
|
||||
*/
|
||||
int NUM_OTHER_FAX = 13;
|
||||
|
||||
/**
|
||||
* Indicates a radio number.
|
||||
*/
|
||||
int NUM_RADIO = 14;
|
||||
|
||||
/**
|
||||
* Indicates a telex number.
|
||||
*/
|
||||
int NUM_TELEX = 15;
|
||||
|
||||
/**
|
||||
* Indicates a teletypewriter (TTY) or test-driven development (TDD) number.
|
||||
*/
|
||||
int NUM_TTY_TDD = 16;
|
||||
|
||||
/**
|
||||
* Indicates a work mobile phone number.
|
||||
*/
|
||||
int NUM_WORK_MOBILE = 17;
|
||||
|
||||
/**
|
||||
* Indicates a work pager number.
|
||||
*/
|
||||
int NUM_WORK_PAGER = 18;
|
||||
|
||||
/**
|
||||
* Indicates an assistant number.
|
||||
*/
|
||||
int NUM_ASSISTANT = 19;
|
||||
|
||||
/**
|
||||
* Indicates an MMS number.
|
||||
*/
|
||||
int NUM_MMS = 20;
|
||||
|
||||
/**
|
||||
* Indicates an invalid label ID.
|
||||
*/
|
||||
int INVALID_LABEL_ID = -1;
|
||||
|
||||
/**
|
||||
* Indicates the label name of an attribute.
|
||||
*/
|
||||
std::string labelName;
|
||||
|
||||
/**
|
||||
* Indicates the phone number of the contact.
|
||||
*/
|
||||
std::string phoneNumber;
|
||||
|
||||
/**
|
||||
* Indicates the label id.
|
||||
*/
|
||||
int labelId = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for portrait information
|
||||
*/
|
||||
class Portrait {
|
||||
public:
|
||||
/**
|
||||
* Indicates the uri of the contact portrait.
|
||||
*/
|
||||
std::string uri;
|
||||
};
|
||||
/**
|
||||
* Provides methods for postal address information
|
||||
*/
|
||||
class PostalAddress {
|
||||
public:
|
||||
/**
|
||||
* Indicates a custom label.
|
||||
*/
|
||||
int CUSTOM_LABEL = 0;
|
||||
|
||||
/**
|
||||
* Indicates a home address.
|
||||
*/
|
||||
int ADDR_HOME = 1;
|
||||
|
||||
/**
|
||||
* Indicates a work address.
|
||||
*/
|
||||
int ADDR_WORK = 2;
|
||||
|
||||
/**
|
||||
* Indicates an address of the OTHER type.
|
||||
*/
|
||||
int ADDR_OTHER = 3;
|
||||
|
||||
/**
|
||||
* Indicates an invalid label ID.
|
||||
*/
|
||||
int INVALID_LABEL_ID = -1;
|
||||
|
||||
/**
|
||||
* Indicates the city where this contact is located.
|
||||
*/
|
||||
std::string city;
|
||||
|
||||
/**
|
||||
* Indicates the country/region where this contact is located.
|
||||
*/
|
||||
std::string country;
|
||||
|
||||
/**
|
||||
* Indicates the label name of an attribute.
|
||||
*/
|
||||
std::string labelName;
|
||||
|
||||
/**
|
||||
* Indicates the neighborhood where this contact is located.
|
||||
*/
|
||||
std::string neighborhood;
|
||||
|
||||
/**
|
||||
* Indicates the post box of this contact.
|
||||
*/
|
||||
std::string pobox;
|
||||
|
||||
/**
|
||||
* Indicates the postal address of this contact.
|
||||
*/
|
||||
std::string postalAddress;
|
||||
|
||||
/**
|
||||
* Indicates the postal code of this contact.
|
||||
*/
|
||||
std::string postcode;
|
||||
|
||||
/**
|
||||
* Indicates the area where this contact is located.
|
||||
*/
|
||||
std::string region;
|
||||
|
||||
/**
|
||||
* Indicates the street where this contact is located.
|
||||
*/
|
||||
std::string street;
|
||||
|
||||
/**
|
||||
* Indicates the label id.
|
||||
*/
|
||||
int labelId = -1;
|
||||
};
|
||||
|
||||
class Relation {
|
||||
public:
|
||||
/**
|
||||
* Indicates a custom label.
|
||||
*/
|
||||
int CUSTOM_LABEL = 0;
|
||||
|
||||
/**
|
||||
* Indicates an assistant.
|
||||
*/
|
||||
int RELATION_ASSISTANT = 1;
|
||||
|
||||
/**
|
||||
* Indicates a brother.
|
||||
*/
|
||||
int RELATION_BROTHER = 2;
|
||||
|
||||
/**
|
||||
* Indicates a child.
|
||||
*/
|
||||
int RELATION_CHILD = 3;
|
||||
|
||||
/**
|
||||
* Indicates a domestic partner.
|
||||
*/
|
||||
int RELATION_DOMESTIC_PARTNER = 4;
|
||||
|
||||
/**
|
||||
* Indicates a father.
|
||||
*/
|
||||
int RELATION_FATHER = 5;
|
||||
|
||||
/**
|
||||
* Indicates a friend.
|
||||
*/
|
||||
int RELATION_FRIEND = 6;
|
||||
|
||||
/**
|
||||
* Indicates a manager.
|
||||
*/
|
||||
int RELATION_MANAGER = 7;
|
||||
|
||||
/**
|
||||
* Indicates a mother.
|
||||
*/
|
||||
int RELATION_MOTHER = 8;
|
||||
|
||||
/**
|
||||
* Indicates a parent.
|
||||
*/
|
||||
int RELATION_PARENT = 9;
|
||||
|
||||
/**
|
||||
* Indicates a partner.
|
||||
*/
|
||||
int RELATION_PARTNER = 10;
|
||||
|
||||
/**
|
||||
* Indicates a referrer.
|
||||
*/
|
||||
int RELATION_REFERRED_BY = 11;
|
||||
|
||||
/**
|
||||
* Indicates a relative.
|
||||
*/
|
||||
int RELATION_RELATIVE = 12;
|
||||
|
||||
/**
|
||||
* Indicates a sister.
|
||||
*/
|
||||
int RELATION_SISTER = 13;
|
||||
|
||||
/**
|
||||
* Indicates a spouse.
|
||||
*/
|
||||
int RELATION_SPOUSE = 14;
|
||||
|
||||
/**
|
||||
* Indicates an invalid label ID.
|
||||
*/
|
||||
int INVALID_LABEL_ID = -1;
|
||||
|
||||
/**
|
||||
* Indicates the label name of an attribute.
|
||||
*/
|
||||
std::string labelName;
|
||||
|
||||
/**
|
||||
* Indicates the relation name.
|
||||
*/
|
||||
std::string relationName;
|
||||
|
||||
/**
|
||||
* Indicates the label id.
|
||||
*/
|
||||
int labelId = -1;
|
||||
};
|
||||
|
||||
class SipAddress {
|
||||
public:
|
||||
/**
|
||||
* Indicates a custom label.
|
||||
*/
|
||||
int CUSTOM_LABEL = 0;
|
||||
|
||||
/**
|
||||
* Indicates a home SIP address.
|
||||
*/
|
||||
int SIP_HOME = 1;
|
||||
|
||||
/**
|
||||
* Indicates a work SIP address.
|
||||
*/
|
||||
int SIP_WORK = 2;
|
||||
|
||||
/**
|
||||
* Indicates an SIP address of the OTHER type.
|
||||
*/
|
||||
int SIP_OTHER = 3;
|
||||
|
||||
/**
|
||||
* Indicates an invalid label ID.
|
||||
*/
|
||||
int INVALID_LABEL_ID = -1;
|
||||
|
||||
/**
|
||||
* Indicates the label name of an attribute.
|
||||
*/
|
||||
std::string labelName;
|
||||
|
||||
/**
|
||||
* Indicates the SIP address.
|
||||
*/
|
||||
std::string sipAddress;
|
||||
|
||||
/**
|
||||
* Indicates the label id.
|
||||
*/
|
||||
int labelId = -1;
|
||||
};
|
||||
|
||||
class Website {
|
||||
public:
|
||||
std::string website;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides methods for contact information
|
||||
*/
|
||||
class Contacts {
|
||||
public:
|
||||
/**
|
||||
* Indicates the contact ID.
|
||||
*/
|
||||
static int INVALID_CONTACT_ID;
|
||||
|
||||
/**
|
||||
* Indicates the contact ID.
|
||||
*/
|
||||
int id;
|
||||
|
||||
/**
|
||||
* Indicates the query key that identifies the contact.
|
||||
*/
|
||||
std::string key;
|
||||
|
||||
/**
|
||||
* Indicates the contact attributes.
|
||||
*/
|
||||
ContactAttributes contactAttributes;
|
||||
|
||||
/**
|
||||
* Indicates an email address of the contact.
|
||||
*/
|
||||
std::vector<Email> emails;
|
||||
|
||||
/**
|
||||
* Indicates an event (special date) of the contact.
|
||||
*/
|
||||
std::vector<Event> events;
|
||||
|
||||
/**
|
||||
* Indicates a group of the contact.
|
||||
*/
|
||||
std::vector<Group> groups;
|
||||
|
||||
/**
|
||||
* Indicates an IM address of the contact.
|
||||
*/
|
||||
std::vector<ImAddress> imAddresses;
|
||||
|
||||
/**
|
||||
* Indicates a phone number of the contact.
|
||||
*/
|
||||
std::vector<PhoneNumber> phoneNumbers;
|
||||
|
||||
/**
|
||||
* Indicates the contact portrait.
|
||||
*/
|
||||
Portrait portrait;
|
||||
|
||||
/**
|
||||
* Indicates a postal address of the contact.
|
||||
*/
|
||||
std::vector<PostalAddress> postalAddresses;
|
||||
|
||||
/**
|
||||
* Indicates a relation of the contact.
|
||||
*/
|
||||
std::vector<Relation> relations;
|
||||
|
||||
/**
|
||||
* Indicates a Session Initiation Protocol (SIP) address of the contact.
|
||||
*/
|
||||
std::vector<SipAddress> sipAddresses;
|
||||
|
||||
/**
|
||||
* Indicates a website of the contact.
|
||||
*/
|
||||
std::vector<Website> websites;
|
||||
|
||||
/**
|
||||
* Indicates the contact name.
|
||||
*/
|
||||
Name name;
|
||||
|
||||
/**
|
||||
* Indicates the contact nickname.
|
||||
*/
|
||||
NickName nickName;
|
||||
/**
|
||||
* Indicates the contact note.
|
||||
*/
|
||||
Note note;
|
||||
/**
|
||||
* Indicates organization information about the contact.
|
||||
*/
|
||||
Organization organization;
|
||||
};
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_NAPI_OBJECT_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_API_H
|
||||
#define HILOG_WRAPPER_API_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, "ContactsApi===>"};
|
||||
|
||||
#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_API_H
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 RESULT_CONVERT_H
|
||||
#define RESULT_CONVERT_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "contacts_napi_common.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "result_set.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
class ResultConvert {
|
||||
public:
|
||||
ResultConvert();
|
||||
~ResultConvert();
|
||||
napi_value GetNapiValue(napi_env env, const std::string keyChar, napi_value object);
|
||||
napi_value GetNapiElementArray(napi_env env, napi_value object, const std::string keyChar);
|
||||
napi_value GetNapiElementObject(napi_env env, napi_value object, const std::string keyChar);
|
||||
napi_value GetResultValue(
|
||||
napi_env env, std::string &contentKey, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
napi_value ResultSetToHolder(napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
napi_value ResultSetToGroup(napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
napi_value ResultSetToObject(napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
napi_value ConvertContactArray(
|
||||
napi_env env, std::map<int, napi_value> &resultSetMap, std::map<int, std::string> &quickSearchMap);
|
||||
void PutQuickSearchKey(napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet,
|
||||
std::map<int, std::string> &quickSearchMap, int contactsIdValue);
|
||||
void ConvertContactObject(
|
||||
napi_env env, napi_value napiObject, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
napi_value GetResultMapValue(napi_env env, std::map<int, napi_value> &resultSetMap, int &contactsId);
|
||||
void ConvertEmail(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertName(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertUri(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertEvent(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertGroup(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertImAddress(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertPhoneNumber(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertPostalAddress(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertRelation(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertSipAddress(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertWebsite(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertNickName(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertNote(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void ConvertOrganization(napi_env env, napi_value napiObject, int &typeId,
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
napi_value CreateNapiStringValue(napi_env env, const std::string key);
|
||||
bool IsEmpty(std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
};
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
#endif // RESULT_CONVERT_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,845 @@
|
||||
/*
|
||||
* 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 "contacts_build.h"
|
||||
|
||||
#include "result_convert.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
ContactsBuild::ContactsBuild(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsBuild::~ContactsBuild()
|
||||
{
|
||||
}
|
||||
|
||||
void ContactsBuild::GetContactDataByObject(napi_env env, napi_value object, Contacts &contact)
|
||||
{
|
||||
contact.id = GetIntValueByKey(env, object, "id");
|
||||
contact.key = GetStringValueByKey(env, object, "key");
|
||||
contact.emails = GetEmails(env, object);
|
||||
contact.events = GetEvent(env, object);
|
||||
contact.groups = GetGroup(env, object);
|
||||
contact.imAddresses = GetImAddress(env, object);
|
||||
contact.phoneNumbers = GetPhoneNumbers(env, object);
|
||||
contact.portrait = GetUri(env, object);
|
||||
contact.relations = GetRelation(env, object);
|
||||
contact.sipAddresses = GetSipAddress(env, object);
|
||||
contact.websites = GetWebsite(env, object);
|
||||
contact.name = GetName(env, object);
|
||||
contact.nickName = GetNickName(env, object);
|
||||
contact.note = GetNote(env, object);
|
||||
contact.organization = GetOrganization(env, object);
|
||||
contact.postalAddresses = GetPostalAddress(env, object);
|
||||
}
|
||||
|
||||
void ContactsBuild::GetContactData(napi_env env, napi_callback_info info,
|
||||
std::vector<NativeRdb::ValuesBucket> &valueContact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
napi_value argv[MAX_PARAMS];
|
||||
size_t argc = MAX_PARAMS;
|
||||
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||
ContactsBuild contactsBuild;
|
||||
if (argc < 0) {
|
||||
HILOG_ERROR("GetContactData napi_callback_info is nullptr");
|
||||
return;
|
||||
}
|
||||
Contacts contact;
|
||||
GetContactDataByObject(env, argv[0], contact);
|
||||
BuildValueContact(contact, valueContact);
|
||||
BuildValueContactData(contact, valueContactData);
|
||||
}
|
||||
|
||||
void ContactsBuild::BuildValueContact(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContact)
|
||||
{
|
||||
NativeRdb::ValuesBucket valuesBucketContact;
|
||||
if (!contact.name.fullName.empty() || contact.name.fullName != "") {
|
||||
valuesBucketContact.PutString("display_name", contact.name.fullName);
|
||||
}
|
||||
if (!contact.organization.name.empty() || contact.organization.name != "") {
|
||||
valuesBucketContact.PutString("company", contact.organization.name);
|
||||
}
|
||||
if (!contact.organization.title.empty() || contact.organization.title != "") {
|
||||
valuesBucketContact.PutString("position", contact.organization.title);
|
||||
}
|
||||
valueContact.push_back(valuesBucketContact);
|
||||
}
|
||||
|
||||
void ContactsBuild::BuildValueContactData(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
GetValuesBucketEmail(contact, valueContactData);
|
||||
GetValuesBucketEvent(contact, valueContactData);
|
||||
GetValuesBucketGroup(contact, valueContactData);
|
||||
GetValuesBucketImAddress(contact, valueContactData);
|
||||
GetValuesBucketPortrait(contact, valueContactData);
|
||||
GetValuesBucketPhoneNumber(contact, valueContactData);
|
||||
GetValuesBucketPostalAddress(contact, valueContactData);
|
||||
GetValuesBucketRelation(contact, valueContactData);
|
||||
GetValuesBucketSipAddress(contact, valueContactData);
|
||||
GetValuesBucketWebsite(contact, valueContactData);
|
||||
GetValuesBucketName(contact, valueContactData);
|
||||
GetValuesBucketNickName(contact, valueContactData);
|
||||
GetValuesBucketNote(contact, valueContactData);
|
||||
GetValuesBucketOrganization(contact, valueContactData);
|
||||
}
|
||||
|
||||
void ContactsBuild::BuildValueContactDataByType(
|
||||
Contacts &contact, int typeId, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
switch (typeId) {
|
||||
case EMAIL:
|
||||
GetValuesBucketEmail(contact, valueContactData);
|
||||
break;
|
||||
case IM:
|
||||
GetValuesBucketImAddress(contact, valueContactData);
|
||||
break;
|
||||
case NICKNAME:
|
||||
GetValuesBucketNickName(contact, valueContactData);
|
||||
break;
|
||||
case ORGANIZATION:
|
||||
GetValuesBucketOrganization(contact, valueContactData);
|
||||
break;
|
||||
case PHONE:
|
||||
GetValuesBucketPhoneNumber(contact, valueContactData);
|
||||
break;
|
||||
case NAME:
|
||||
GetValuesBucketName(contact, valueContactData);
|
||||
break;
|
||||
case POSTAL_ADDRESS:
|
||||
GetValuesBucketPostalAddress(contact, valueContactData);
|
||||
break;
|
||||
default:
|
||||
TypeSwitchSplit(typeId, contact, valueContactData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsBuild::TypeSwitchSplit(
|
||||
int typeId, Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
switch (typeId) {
|
||||
case PHOTO:
|
||||
GetValuesBucketPortrait(contact, valueContactData);
|
||||
break;
|
||||
case GROUP_MEMBERSHIP:
|
||||
GetValuesBucketGroup(contact, valueContactData);
|
||||
break;
|
||||
case NOTE:
|
||||
GetValuesBucketNote(contact, valueContactData);
|
||||
break;
|
||||
case CONTACT_EVENT:
|
||||
GetValuesBucketEvent(contact, valueContactData);
|
||||
break;
|
||||
case WEBSITE:
|
||||
GetValuesBucketWebsite(contact, valueContactData);
|
||||
break;
|
||||
case RELATION:
|
||||
GetValuesBucketRelation(contact, valueContactData);
|
||||
break;
|
||||
case CONTACT_MISC:
|
||||
HILOG_INFO("TypeSwitchSplit is CONTACT_MISC ");
|
||||
break;
|
||||
case HICALL_DEVICE:
|
||||
HILOG_INFO("TypeSwitchSplit is HICALL_DEVICE ");
|
||||
break;
|
||||
case CAMCARD:
|
||||
case SIP_ADDRESS:
|
||||
GetValuesBucketSipAddress(contact, valueContactData);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("TypeSwitchSplit type is error ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in EMAIL case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketEmail(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int emailsSize = contact.emails.size();
|
||||
for (int i = 0; i < emailsSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketEmail;
|
||||
valuesBucketEmail.PutString("detail_info", contact.emails[i].email);
|
||||
valuesBucketEmail.PutString("extend7", std::to_string(contact.emails[i].labelId));
|
||||
valuesBucketEmail.PutString("custom_data", contact.emails[i].labelName);
|
||||
valuesBucketEmail.PutString("alias_detail_info", contact.emails[i].displayName);
|
||||
valuesBucketEmail.PutString("content_type", "email");
|
||||
valueContactData.push_back(valuesBucketEmail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in CONTACT_EVENT case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketEvent(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int eventsSize = contact.events.size();
|
||||
for (int i = 0; i < eventsSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketEvent;
|
||||
valuesBucketEvent.PutString("detail_info", contact.events[i].eventDate);
|
||||
valuesBucketEvent.PutString("extend7", std::to_string(contact.events[i].labelId));
|
||||
valuesBucketEvent.PutString("custom_data", contact.events[i].labelName);
|
||||
valuesBucketEvent.PutString("content_type", "contact_event");
|
||||
valueContactData.push_back(valuesBucketEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in GROUP_MEMBERSHIP case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketGroup(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int groupsSize = contact.groups.size();
|
||||
for (int i = 0; i < groupsSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketGroup;
|
||||
valuesBucketGroup.PutString("detail_info", std::to_string(contact.groups[i].groupId));
|
||||
valuesBucketGroup.PutString("alias_detail_info", contact.groups[i].title);
|
||||
valuesBucketGroup.PutString("content_type", "group_membership");
|
||||
valueContactData.push_back(valuesBucketGroup);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in Im case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketImAddress(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int imAddressSize = contact.imAddresses.size();
|
||||
for (int i = 0; i < imAddressSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketImAddress;
|
||||
valuesBucketImAddress.PutString("detail_info", contact.imAddresses[i].imAddress);
|
||||
valuesBucketImAddress.PutString("extend7", std::to_string(contact.imAddresses[i].labelId));
|
||||
valuesBucketImAddress.PutString("custom_data", contact.imAddresses[i].labelName);
|
||||
valuesBucketImAddress.PutString("content_type", "im");
|
||||
valueContactData.push_back(valuesBucketImAddress);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in PHOTO case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketPortrait(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
if (!contact.portrait.uri.empty() || contact.portrait.uri != "") {
|
||||
NativeRdb::ValuesBucket valuesBucketPortrait;
|
||||
valuesBucketPortrait.PutString("detail_info", contact.portrait.uri);
|
||||
valuesBucketPortrait.PutString("content_type", "photo");
|
||||
valueContactData.push_back(valuesBucketPortrait);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in PHONE case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketPhoneNumber(
|
||||
Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int phoneNumbersSize = contact.phoneNumbers.size();
|
||||
for (int i = 0; i < phoneNumbersSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketPhoneNumber;
|
||||
valuesBucketPhoneNumber.PutString("detail_info", contact.phoneNumbers[i].phoneNumber);
|
||||
valuesBucketPhoneNumber.PutString("extend7", std::to_string(contact.phoneNumbers[i].labelId));
|
||||
valuesBucketPhoneNumber.PutString("custom_data", contact.phoneNumbers[i].labelName);
|
||||
valuesBucketPhoneNumber.PutString("content_type", "phone");
|
||||
valueContactData.push_back(valuesBucketPhoneNumber);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in POSTAL_ADDRESS case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketPostalAddress(
|
||||
Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int postalAddressesSize = contact.postalAddresses.size();
|
||||
for (int i = 0; i < postalAddressesSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketPostalAddress;
|
||||
valuesBucketPostalAddress.PutString("detail_info", contact.postalAddresses[i].postalAddress);
|
||||
valuesBucketPostalAddress.PutString("extend7", std::to_string(contact.postalAddresses[i].labelId));
|
||||
valuesBucketPostalAddress.PutString("custom_data", contact.postalAddresses[i].labelName);
|
||||
valuesBucketPostalAddress.PutString("neighborhood", contact.postalAddresses[i].neighborhood);
|
||||
valuesBucketPostalAddress.PutString("pobox", contact.postalAddresses[i].pobox);
|
||||
valuesBucketPostalAddress.PutString("postcode", contact.postalAddresses[i].postcode);
|
||||
valuesBucketPostalAddress.PutString("region", contact.postalAddresses[i].region);
|
||||
valuesBucketPostalAddress.PutString("street", contact.postalAddresses[i].street);
|
||||
valuesBucketPostalAddress.PutString("city", contact.postalAddresses[i].city);
|
||||
valuesBucketPostalAddress.PutString("content_type", "postal_address");
|
||||
valueContactData.push_back(valuesBucketPostalAddress);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in RELATION case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketRelation(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int relationsSize = contact.relations.size();
|
||||
for (int i = 0; i < relationsSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketRelation;
|
||||
valuesBucketRelation.PutString("detail_info", contact.relations[i].relationName);
|
||||
valuesBucketRelation.PutString("extend7", std::to_string(contact.relations[i].labelId));
|
||||
valuesBucketRelation.PutString("custom_data", contact.relations[i].labelName);
|
||||
valuesBucketRelation.PutString("content_type", "relation");
|
||||
valueContactData.push_back(valuesBucketRelation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in SIP_ADDRESS case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketSipAddress(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int sipAddressesSize = contact.sipAddresses.size();
|
||||
for (int i = 0; i < sipAddressesSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketSipAddress;
|
||||
valuesBucketSipAddress.PutString("detail_info", contact.sipAddresses[i].sipAddress);
|
||||
valuesBucketSipAddress.PutString("extend7", std::to_string(contact.sipAddresses[i].labelId));
|
||||
valuesBucketSipAddress.PutString("custom_data", contact.sipAddresses[i].labelName);
|
||||
valuesBucketSipAddress.PutString("content_type", "sip_address");
|
||||
valueContactData.push_back(valuesBucketSipAddress);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in WEBSITE case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketWebsite(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
int websitesSize = contact.websites.size();
|
||||
for (int i = 0; i < websitesSize; i++) {
|
||||
NativeRdb::ValuesBucket valuesBucketWebsite;
|
||||
valuesBucketWebsite.PutString("detail_info", contact.websites[i].website);
|
||||
valuesBucketWebsite.PutString("content_type", "website");
|
||||
valueContactData.push_back(valuesBucketWebsite);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in NAME case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketName(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
if (!contact.name.fullName.empty() || contact.name.fullName != "") {
|
||||
NativeRdb::ValuesBucket valuesBucketName;
|
||||
valuesBucketName.PutString("detail_info", contact.name.fullName);
|
||||
valuesBucketName.PutString("alpha_name", contact.name.namePrefix);
|
||||
valuesBucketName.PutString("other_lan_last_name", contact.name.middleName);
|
||||
valuesBucketName.PutString("other_lan_first_name", contact.name.nameSuffix);
|
||||
valuesBucketName.PutString("family_name", contact.name.familyName);
|
||||
valuesBucketName.PutString("middle_name_phonetic", contact.name.middleNamePhonetic);
|
||||
valuesBucketName.PutString("given_name", contact.name.givenName);
|
||||
valuesBucketName.PutString("given_name_phonetic", contact.name.givenNamePhonetic);
|
||||
valuesBucketName.PutString("phonetic_name", contact.name.familyNamePhonetic);
|
||||
valuesBucketName.PutString("content_type", "name");
|
||||
valueContactData.push_back(valuesBucketName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in NICKNAME case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketNickName(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
if (!contact.nickName.nickName.empty() || contact.nickName.nickName != "") {
|
||||
NativeRdb::ValuesBucket valuesBucketNickName;
|
||||
valuesBucketNickName.PutString("detail_info", contact.nickName.nickName);
|
||||
valuesBucketNickName.PutString("content_type", "nickname");
|
||||
valueContactData.push_back(valuesBucketNickName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in NOTE case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketNote(Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
if (!contact.note.noteContent.empty() || contact.note.noteContent != "") {
|
||||
NativeRdb::ValuesBucket valuesBucketNote;
|
||||
valuesBucketNote.PutString("detail_info", contact.note.noteContent);
|
||||
valuesBucketNote.PutString("content_type", "note");
|
||||
valueContactData.push_back(valuesBucketNote);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Establish ValuesBucket condition in ORGANIZATION case
|
||||
*
|
||||
* @param contact Conditions for establish ValuesBucket operation
|
||||
* @param valueContactData Conditions for establish ValuesBucket operation
|
||||
*/
|
||||
void ContactsBuild::GetValuesBucketOrganization(
|
||||
Contacts &contact, std::vector<NativeRdb::ValuesBucket> &valueContactData)
|
||||
{
|
||||
NativeRdb::ValuesBucket valuesBucketData;
|
||||
if (!contact.organization.name.empty() || contact.organization.name != "") {
|
||||
valuesBucketData.PutString("detail_info", contact.organization.name);
|
||||
valuesBucketData.PutString("content_type", "organization");
|
||||
}
|
||||
if (!contact.organization.title.empty() || contact.organization.title != "") {
|
||||
valuesBucketData.PutString("position", contact.organization.title);
|
||||
valuesBucketData.PutString("content_type", "organization");
|
||||
}
|
||||
valueContactData.push_back(valuesBucketData);
|
||||
}
|
||||
|
||||
napi_value ContactsBuild::GetObjectByKey(napi_env env, napi_value object, std::string key)
|
||||
{
|
||||
ResultConvert resultConvert;
|
||||
return resultConvert.GetNapiValue(env, key.c_str(), object);
|
||||
}
|
||||
|
||||
napi_value ContactsBuild::GetArrayByKey(napi_env env, napi_value valueObject, std::string key)
|
||||
{
|
||||
ResultConvert resultConvert;
|
||||
napi_value array = resultConvert.GetNapiValue(env, key.c_str(), valueObject);
|
||||
bool isArray = false;
|
||||
napi_is_array(env, array, &isArray);
|
||||
if (!isArray) {
|
||||
HILOG_INFO("ContactsBuild GetArrayByKey value is not array");
|
||||
return nullptr;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
std::string ContactsBuild::GetStringValueByKey(napi_env env, napi_value valueObject, std::string key)
|
||||
{
|
||||
ResultConvert resultConvert;
|
||||
napi_value value = resultConvert.GetNapiValue(env, key.c_str(), valueObject);
|
||||
std::string result = NapiGetValueString(env, value);
|
||||
return result;
|
||||
}
|
||||
|
||||
int ContactsBuild::GetIntValueByKey(napi_env env, napi_value valueObject, std::string key)
|
||||
{
|
||||
ResultConvert resultConvert;
|
||||
napi_value value = resultConvert.GetNapiValue(env, key.c_str(), valueObject);
|
||||
int64_t result;
|
||||
napi_get_value_int64(env, value, &result);
|
||||
int code = result;
|
||||
return code;
|
||||
}
|
||||
|
||||
Name ContactsBuild::GetName(napi_env env, napi_value object)
|
||||
{
|
||||
HILOG_INFO("ContactsBuild into GetName");
|
||||
Name name;
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetName nameKey is null ");
|
||||
return name;
|
||||
}
|
||||
napi_value nameObj = GetObjectByKey(env, object, "name");
|
||||
napi_valuetype valueType;
|
||||
napi_typeof(env, nameObj, &valueType);
|
||||
if (nameObj == nullptr || valueType != napi_object) {
|
||||
HILOG_ERROR("ContactsBuild GetName nameObj is null or object type is not object");
|
||||
return name;
|
||||
}
|
||||
name.familyName = GetStringValueByKey(env, nameObj, "familyName");
|
||||
name.middleNamePhonetic = GetStringValueByKey(env, nameObj, "middleNamePhonetic");
|
||||
name.givenName = GetStringValueByKey(env, nameObj, "givenName");
|
||||
name.givenNamePhonetic = GetStringValueByKey(env, nameObj, "givenNamePhonetic");
|
||||
name.familyNamePhonetic = GetStringValueByKey(env, nameObj, "familyNamePhonetic");
|
||||
name.fullName = GetStringValueByKey(env, nameObj, "fullName");
|
||||
name.middleName = GetStringValueByKey(env, nameObj, "middleName");
|
||||
name.namePrefix = GetStringValueByKey(env, nameObj, "namePrefix");
|
||||
name.nameSuffix = GetStringValueByKey(env, nameObj, "nameSuffix");
|
||||
return name;
|
||||
}
|
||||
|
||||
Portrait ContactsBuild::GetUri(napi_env env, napi_value object)
|
||||
{
|
||||
HILOG_INFO("ContactsBuild into GetUri");
|
||||
Portrait portrait;
|
||||
napi_value portraitKey = GetObjectByKey(env, object, "portrait");
|
||||
if (portraitKey == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetUri portraitKey is null ");
|
||||
return portrait;
|
||||
}
|
||||
napi_value portraitValue;
|
||||
napi_get_property(env, object, portraitKey, &portraitValue);
|
||||
napi_valuetype valueType;
|
||||
napi_typeof(env, portraitValue, &valueType);
|
||||
if (portraitValue == nullptr || valueType != napi_object) {
|
||||
HILOG_ERROR("ContactsBuild GetUri portraitValue is null or object type is not object");
|
||||
return portrait;
|
||||
}
|
||||
napi_value portraitKeyNames;
|
||||
napi_get_property_names(env, portraitValue, &portraitKeyNames);
|
||||
napi_value uriKey = GetObjectByKey(env, portraitKeyNames, "uri");
|
||||
if (uriKey == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetUri uriKey is null ");
|
||||
return portrait;
|
||||
}
|
||||
napi_value uriValue;
|
||||
napi_get_property(env, portraitValue, uriKey, &uriValue);
|
||||
if (uriValue == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetUri uriValue is null ");
|
||||
return portrait;
|
||||
}
|
||||
portrait.uri = NapiGetValueString(env, uriValue);
|
||||
return portrait;
|
||||
}
|
||||
|
||||
std::vector<Email> ContactsBuild::GetEmails(napi_env env, napi_value object)
|
||||
{
|
||||
std::vector<Email> emailVec;
|
||||
napi_value EamilArray = GetArrayByKey(env, object, "emails");
|
||||
if (EamilArray == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetEmail napiValueEamil is null ");
|
||||
return emailVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, EamilArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
Email email;
|
||||
napi_value object;
|
||||
napi_get_element(env, EamilArray, i, &object);
|
||||
email.email = GetStringValueByKey(env, object, "email");
|
||||
email.labelName = GetStringValueByKey(env, object, "labelName");
|
||||
email.displayName = GetStringValueByKey(env, object, "displayName");
|
||||
email.labelId = GetIntValueByKey(env, object, "labelId");
|
||||
emailVec.push_back(email);
|
||||
}
|
||||
return emailVec;
|
||||
}
|
||||
|
||||
std::vector<Event> ContactsBuild::GetEvent(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value eventArray = GetArrayByKey(env, object, "events");
|
||||
if (eventArray == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetEvent arrKey is null ");
|
||||
return std::vector<Event>();
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, eventArray, &size);
|
||||
std::vector<Event> resultVec;
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value obj;
|
||||
napi_get_element(env, eventArray, i, &obj);
|
||||
Event eventObj;
|
||||
eventObj.eventDate = GetStringValueByKey(env, obj, "eventDate");
|
||||
eventObj.labelName = GetStringValueByKey(env, obj, "labelName");
|
||||
eventObj.labelId = GetIntValueByKey(env, obj, "labelId");
|
||||
resultVec.push_back(eventObj);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
std::vector<Group> ContactsBuild::GetGroup(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value groupArray = GetArrayByKey(env, object, "groups");
|
||||
std::vector<Group> resultVec;
|
||||
if (groupArray == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetGroup arrKey is null ");
|
||||
return resultVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, groupArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value obj;
|
||||
napi_get_element(env, groupArray, i, &obj);
|
||||
Group groupObj;
|
||||
groupObj.groupId = GetIntValueByKey(env, obj, "groupId");
|
||||
groupObj.title = GetStringValueByKey(env, obj, "title");
|
||||
resultVec.push_back(groupObj);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
std::vector<ImAddress> ContactsBuild::GetImAddress(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value imAddressArray = GetArrayByKey(env, object, "imAddresses");
|
||||
std::vector<ImAddress> resultVec;
|
||||
if (imAddressArray == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetImAddress arrKey is null ");
|
||||
return resultVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, imAddressArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value obj;
|
||||
napi_get_element(env, imAddressArray, i, &obj);
|
||||
ImAddress targetObj;
|
||||
targetObj.imAddress = GetStringValueByKey(env, obj, "imAddress");
|
||||
targetObj.labelName = GetStringValueByKey(env, obj, "labelName");
|
||||
targetObj.labelId = GetIntValueByKey(env, obj, "labelId");
|
||||
resultVec.push_back(targetObj);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
std::vector<PhoneNumber> ContactsBuild::GetPhoneNumbers(napi_env env, napi_value object)
|
||||
{
|
||||
std::vector<PhoneNumber> resultVec;
|
||||
napi_value phoneNumberArray = GetArrayByKey(env, object, "phoneNumbers");
|
||||
if (phoneNumberArray == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetPhoneNumber napiValuePhoneNumber is null ");
|
||||
return resultVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, phoneNumberArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
PhoneNumber phones;
|
||||
napi_value obj;
|
||||
napi_get_element(env, phoneNumberArray, i, &obj);
|
||||
phones.phoneNumber = GetStringValueByKey(env, obj, "phoneNumber");
|
||||
phones.labelName = GetStringValueByKey(env, obj, "labelName");
|
||||
phones.labelId = GetIntValueByKey(env, obj, "labelId");
|
||||
resultVec.push_back(phones);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
std::vector<PostalAddress> ContactsBuild::GetPostalAddress(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value postalAddressArray = GetArrayByKey(env, object, "postalAddresses");
|
||||
std::vector<PostalAddress> resultVec;
|
||||
if (postalAddressArray == nullptr) {
|
||||
HILOG_ERROR("GetPostalAddress arrKey is null ");
|
||||
return resultVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, postalAddressArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value obj;
|
||||
napi_get_element(env, postalAddressArray, i, &obj);
|
||||
PostalAddress targetObj;
|
||||
targetObj.city = GetStringValueByKey(env, obj, "city");
|
||||
targetObj.country = GetStringValueByKey(env, obj, "country");
|
||||
targetObj.labelName = GetStringValueByKey(env, obj, "labelName");
|
||||
targetObj.neighborhood = GetStringValueByKey(env, obj, "neighborhood");
|
||||
targetObj.pobox = GetStringValueByKey(env, obj, "pobox");
|
||||
targetObj.postalAddress = GetStringValueByKey(env, obj, "postalAddress");
|
||||
targetObj.postcode = GetStringValueByKey(env, obj, "postcode");
|
||||
targetObj.region = GetStringValueByKey(env, obj, "region");
|
||||
targetObj.street = GetStringValueByKey(env, obj, "street");
|
||||
resultVec.push_back(targetObj);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
std::vector<Relation> ContactsBuild::GetRelation(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value relationArray = GetArrayByKey(env, object, "relations");
|
||||
std::vector<Relation> resultVec;
|
||||
if (relationArray == nullptr) {
|
||||
HILOG_ERROR("GetRelation arrKey is null ");
|
||||
return resultVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, relationArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value obj;
|
||||
napi_get_element(env, relationArray, i, &obj);
|
||||
Relation targetObj;
|
||||
targetObj.relationName = GetStringValueByKey(env, obj, "relationName");
|
||||
targetObj.labelName = GetStringValueByKey(env, obj, "labelName");
|
||||
targetObj.labelId = GetIntValueByKey(env, obj, "labelId");
|
||||
resultVec.push_back(targetObj);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
std::vector<SipAddress> ContactsBuild::GetSipAddress(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value sipAddressArray = GetArrayByKey(env, object, "sipAddresses");
|
||||
std::vector<SipAddress> resultVec;
|
||||
if (sipAddressArray == nullptr) {
|
||||
HILOG_ERROR("GetSipAddress arrKey is null ");
|
||||
return resultVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, sipAddressArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value obj;
|
||||
napi_get_element(env, sipAddressArray, i, &obj);
|
||||
SipAddress targetObj;
|
||||
targetObj.sipAddress = GetStringValueByKey(env, obj, "sipAddress");
|
||||
targetObj.labelName = GetStringValueByKey(env, obj, "labelName");
|
||||
targetObj.labelId = GetIntValueByKey(env, obj, "labelId");
|
||||
resultVec.push_back(targetObj);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
std::vector<Website> ContactsBuild::GetWebsite(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value websiteArray = GetArrayByKey(env, object, "websites");
|
||||
std::vector<Website> resultVec;
|
||||
if (websiteArray == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetWebsite arrKey is null ");
|
||||
return resultVec;
|
||||
}
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, websiteArray, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value obj;
|
||||
napi_get_element(env, websiteArray, i, &obj);
|
||||
Website targetObj;
|
||||
targetObj.website = GetStringValueByKey(env, obj, "website");
|
||||
resultVec.push_back(targetObj);
|
||||
}
|
||||
return resultVec;
|
||||
}
|
||||
|
||||
NickName ContactsBuild::GetNickName(napi_env env, napi_value object)
|
||||
{
|
||||
HILOG_INFO("ContactsBuild into GetNickName");
|
||||
napi_value nickNameObj = GetObjectByKey(env, object, "nickName");
|
||||
NickName resultObj;
|
||||
if (nickNameObj == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild GetNickName nickNameKey is null ");
|
||||
return resultObj;
|
||||
}
|
||||
resultObj.nickName = GetStringValueByKey(env, nickNameObj, "nickName");
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
Note ContactsBuild::GetNote(napi_env env, napi_value object)
|
||||
{
|
||||
Note resultObj;
|
||||
napi_value noteObj = GetObjectByKey(env, object, "note");
|
||||
if (noteObj == nullptr) {
|
||||
HILOG_ERROR("GetNote noteKey is null ");
|
||||
return resultObj;
|
||||
}
|
||||
resultObj.noteContent = GetStringValueByKey(env, noteObj, "noteContent");
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
Organization ContactsBuild::GetOrganization(napi_env env, napi_value object)
|
||||
{
|
||||
napi_value organizationObject = GetObjectByKey(env, object, "organization");
|
||||
Organization resultObj;
|
||||
if (organizationObject == nullptr) {
|
||||
HILOG_ERROR("GetOrganization noteKey is null ");
|
||||
return resultObj;
|
||||
}
|
||||
resultObj.name = GetStringValueByKey(env, organizationObject, "name");
|
||||
resultObj.title = GetStringValueByKey(env, organizationObject, "title");
|
||||
return resultObj;
|
||||
}
|
||||
|
||||
int ContactsBuild::GetInt(napi_env env, napi_value id)
|
||||
{
|
||||
int64_t value = 0;
|
||||
if (id == nullptr) {
|
||||
HILOG_ERROR("GetInt id is 0");
|
||||
return value;
|
||||
}
|
||||
napi_get_value_int64(env, id, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
Holder ContactsBuild::GetHolder(napi_env env, napi_value object)
|
||||
{
|
||||
Holder holder;
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("GetHolder Holoder is null ");
|
||||
return holder;
|
||||
}
|
||||
holder.bundleName = GetStringValueByKey(env, object, "bundleName");
|
||||
holder.displayName = GetStringValueByKey(env, object, "displayName");
|
||||
holder.holderId = GetIntValueByKey(env, object, "holderId");
|
||||
HILOG_INFO(" ContactsBuild::GetHolder int id = %{public}d", holder.holderId);
|
||||
return holder;
|
||||
}
|
||||
|
||||
ContactAttributes ContactsBuild::GetContactAttributes(napi_env env, napi_value object)
|
||||
{
|
||||
ContactAttributes contactAttributes;
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("GetContactAttributes object is null ");
|
||||
return contactAttributes;
|
||||
}
|
||||
napi_value napiValueAttr = GetArrayByKey(env, object, "attributes");
|
||||
std::vector<int> attrVector;
|
||||
uint32_t size = 0;
|
||||
napi_get_array_length(env, napiValueAttr, &size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
napi_value intValue;
|
||||
napi_get_element(env, napiValueAttr, i, &intValue);
|
||||
int64_t intNapiValue;
|
||||
napi_get_value_int64(env, intValue, &intNapiValue);
|
||||
if (intNapiValue != 0) {
|
||||
attrVector.push_back(intNapiValue);
|
||||
}
|
||||
}
|
||||
contactAttributes.attributes = attrVector;
|
||||
return contactAttributes;
|
||||
}
|
||||
|
||||
std::string ContactsBuild::NapiGetValueString(napi_env env, napi_value value)
|
||||
{
|
||||
if (value == nullptr) {
|
||||
HILOG_ERROR("ContactsBuild NapiGetValueString value is nullptr");
|
||||
return "";
|
||||
}
|
||||
std::string resultValue = "";
|
||||
char valueString[NAPI_GET_STRING_SIZE];
|
||||
size_t valueSize = NAPI_GET_STRING_SIZE;
|
||||
size_t resultSize = 0;
|
||||
napi_get_value_string_utf8(env, value, valueString, valueSize, &resultSize);
|
||||
resultValue = valueString;
|
||||
if (resultValue == "") {
|
||||
HILOG_ERROR("ContactsBuild NapiGetValueString Data error");
|
||||
return "";
|
||||
}
|
||||
return resultValue;
|
||||
}
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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 "contacts_control.h"
|
||||
|
||||
#include "hilog_wrapper_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
ContactsControl::ContactsControl(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsControl::~ContactsControl()
|
||||
{
|
||||
}
|
||||
|
||||
int64_t ContactsControl::RawContactInsert(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues)
|
||||
{
|
||||
int code = 0;
|
||||
OHOS::Uri uriRawContact("dataability:///com.ohos.contactsdataability/contacts/raw_contact");
|
||||
code = dataAbilityHelper->Insert(uriRawContact, rawContactValues);
|
||||
HILOG_INFO(" ContactsControl::RawContactInsert insert code %{public}d", code);
|
||||
rawContactValues.Clear();
|
||||
return code;
|
||||
}
|
||||
|
||||
int ContactsControl::ContactDataInsert(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> contactDataValues)
|
||||
{
|
||||
int code = 0;
|
||||
OHOS::Uri uriContactData("dataability:///com.ohos.contactsdataability/contacts/contact_data");
|
||||
code = dataAbilityHelper->BatchInsert(uriContactData, contactDataValues);
|
||||
HILOG_INFO(" ContactsControl::ContactDataInsert insert code %{public}d", code);
|
||||
contactDataValues.clear();
|
||||
return code;
|
||||
}
|
||||
int ContactsControl::ContactDataDelete(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
int code = 0;
|
||||
OHOS::Uri uriContactData("dataability:///com.ohos.contactsdataability/contacts/contact_data");
|
||||
code = dataAbilityHelper->Delete(uriContactData, predicates);
|
||||
HILOG_INFO(" ContactsControl::ContactDataDelete insert code %{public}d", code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int ContactsControl::RawContactUpdate(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::ValuesBucket updateValues, OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
int code = 0;
|
||||
OHOS::Uri uriRawContact("dataability:///com.ohos.contactsdataability/contacts/raw_contact");
|
||||
code = dataAbilityHelper->Update(uriRawContact, updateValues, predicates);
|
||||
return code;
|
||||
}
|
||||
|
||||
int ContactsControl::ContactDataUpdate(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::ValuesBucket updateValues, OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
int code = 0;
|
||||
OHOS::Uri uriContactData("dataability:///com.ohos.contactsdataability/contacts/contact_data");
|
||||
code = dataAbilityHelper->Update(uriContactData, updateValues, predicates);
|
||||
return code;
|
||||
}
|
||||
|
||||
int ContactsControl::ContactDelete(std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
int code = 0;
|
||||
OHOS::Uri uriContact("dataability:///com.ohos.contactsdataability/contacts/contact");
|
||||
code = dataAbilityHelper->Delete(uriContact, predicates);
|
||||
return code;
|
||||
}
|
||||
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactsControl::HolderQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet;
|
||||
OHOS::Uri uriContact("dataability:///com.ohos.contactsdataability/contacts/account");
|
||||
resultSet = dataAbilityHelper->Query(uriContact, columns, predicates);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactsControl::ContactQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
HILOG_INFO("ContactsControl::ContactQuery is start");
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet;
|
||||
OHOS::Uri uriContact("dataability:///com.ohos.contactsdataability/contacts/contact_data");
|
||||
resultSet = dataAbilityHelper->Query(uriContact, columns, predicates);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactsControl::ContactDataQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet;
|
||||
OHOS::Uri uriContactData("dataability:///com.ohos.contactsdataability/contacts/contact_data");
|
||||
resultSet = dataAbilityHelper->Query(uriContactData, columns, predicates);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactsControl::GroupsQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet;
|
||||
OHOS::Uri uriGroups("dataability:///com.ohos.contactsdataability/contacts/groups");
|
||||
resultSet = dataAbilityHelper->Query(uriGroups, columns, predicates);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactsControl::MyCardQuery(
|
||||
std::shared_ptr<OHOS::AppExecFwk::DataAbilityHelper> dataAbilityHelper, std::vector<std::string> columns,
|
||||
OHOS::NativeRdb::DataAbilityPredicates predicates)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet;
|
||||
OHOS::Uri uriProfileContact("dataability:///com.ohos.contactsdataability/profile/contact_data");
|
||||
resultSet = dataAbilityHelper->Query(uriProfileContact, columns, predicates);
|
||||
return resultSet;
|
||||
}
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 <napi/native_api.h>
|
||||
|
||||
#include "contacts_api.h"
|
||||
#include "hilog_wrapper_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
static napi_value ModuleInit(napi_env env, napi_value exports)
|
||||
{
|
||||
OHOS::ContactsApi::Init(env, exports);
|
||||
return exports;
|
||||
}
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module module = {
|
||||
.nm_version = 1, // NAPI v1
|
||||
.nm_flags = 0, // normal
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = ModuleInit,
|
||||
.nm_modname = "ContactsApi",
|
||||
.nm_priv = nullptr,
|
||||
.reserved = {}
|
||||
};
|
||||
napi_module_register(&module);
|
||||
}
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,744 @@
|
||||
/*
|
||||
* 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 "result_convert.h"
|
||||
|
||||
#include "hilog_wrapper_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace ContactsApi {
|
||||
ResultConvert::ResultConvert(void)
|
||||
{
|
||||
}
|
||||
|
||||
ResultConvert::~ResultConvert()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get object array by resultSet
|
||||
*
|
||||
* @param env Conditions for convert operation
|
||||
* @param resultSet Conditions for convert operation
|
||||
*
|
||||
* @return The result returned by convert operation
|
||||
*/
|
||||
napi_value ResultConvert::ResultSetToObject(
|
||||
napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (resultSet == nullptr) {
|
||||
HILOG_ERROR("ResultConvert::ResultSetToObject resultSet is nullptr");
|
||||
napi_value array;
|
||||
napi_create_array(env, &array);
|
||||
return array;
|
||||
}
|
||||
int rowCount = 0;
|
||||
resultSet->GetRowCount(rowCount);
|
||||
HILOG_INFO("ResultSetToObject GetRowCount is %{public}d", rowCount);
|
||||
if (rowCount == 0) {
|
||||
napi_value array;
|
||||
napi_create_array(env, &array);
|
||||
resultSet->Close();
|
||||
return array;
|
||||
}
|
||||
std::map<int, napi_value> resultSetMap;
|
||||
std::map<int, std::string> quickSearchMap;
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == 0) {
|
||||
int contactIdValue = 0;
|
||||
std::string contactIdKey = "contact_id";
|
||||
int contactIndex = 0;
|
||||
resultSet->GetColumnIndex(contactIdKey, contactIndex);
|
||||
resultSet->GetInt(contactIndex, contactIdValue);
|
||||
napi_value napiObject = GetResultMapValue(env, resultSetMap, contactIdValue);
|
||||
PutQuickSearchKey(env, resultSet, quickSearchMap, contactIdValue);
|
||||
ConvertContactObject(env, napiObject, resultSet);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
napi_value array = ConvertContactArray(env, resultSetMap, quickSearchMap);
|
||||
return array;
|
||||
}
|
||||
|
||||
void ResultConvert::PutQuickSearchKey(napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet,
|
||||
std::map<int, std::string> &quickSearchMap, int contactIdValue)
|
||||
{
|
||||
std::string quickSearchValue = "";
|
||||
std::string quickSearchKey = "quick_search_key";
|
||||
int columnIndex = 0;
|
||||
resultSet->GetColumnIndex(quickSearchKey, columnIndex);
|
||||
resultSet->GetString(columnIndex, quickSearchValue);
|
||||
if (quickSearchMap.count(contactIdValue) <= 0) {
|
||||
napi_value napiQuickSearchValue;
|
||||
napi_create_string_utf8(env, quickSearchValue.c_str(), NAPI_AUTO_LENGTH, &napiQuickSearchValue);
|
||||
quickSearchMap.insert(std::pair<int, std::string>(contactIdValue, quickSearchValue));
|
||||
}
|
||||
}
|
||||
|
||||
napi_value ResultConvert::ConvertContactArray(
|
||||
napi_env env, std::map<int, napi_value> &resultSetMap, std::map<int, std::string> &quickSearchMap)
|
||||
{
|
||||
napi_value array;
|
||||
napi_create_array(env, &array);
|
||||
int count = 0;
|
||||
std::map<int, napi_value>::iterator it;
|
||||
for (it = resultSetMap.begin(); it != resultSetMap.end(); ++it) {
|
||||
napi_value elementObject = it->second;
|
||||
if (quickSearchMap.count(it->first) > 0) {
|
||||
napi_value keyValue;
|
||||
napi_create_string_utf8(env, quickSearchMap[it->first].c_str(), NAPI_AUTO_LENGTH, &keyValue);
|
||||
napi_value napiQuickKey;
|
||||
napi_create_string_utf8(env, "key", NAPI_AUTO_LENGTH, &napiQuickKey);
|
||||
napi_set_property(env, elementObject, napiQuickKey, keyValue);
|
||||
}
|
||||
napi_value keyValue;
|
||||
napi_create_int64(env, it->first, &keyValue);
|
||||
napi_value napiIdKey;
|
||||
napi_create_string_utf8(env, "id", NAPI_AUTO_LENGTH, &napiIdKey);
|
||||
napi_set_property(env, elementObject, napiIdKey, keyValue);
|
||||
napi_set_element(env, array, count, elementObject);
|
||||
++count;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converting NaPi objects to C++ objects
|
||||
*
|
||||
* @param env Conditions for convert operation
|
||||
* @param napiObject Conditions for convert operation
|
||||
* @param resultSet Target of convert operation
|
||||
*/
|
||||
void ResultConvert::ConvertContactObject(
|
||||
napi_env env, napi_value napiObject, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
int typeIdValue = 0;
|
||||
std::string typeId = "type_id";
|
||||
int columnIndexType = 0;
|
||||
resultSet->GetColumnIndex(typeId, columnIndexType);
|
||||
resultSet->GetInt(columnIndexType, typeIdValue);
|
||||
ConvertEmail(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertName(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertUri(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertEvent(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertGroup(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertImAddress(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertPhoneNumber(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertPostalAddress(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertRelation(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertSipAddress(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertWebsite(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertNickName(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertNote(env, napiObject, typeIdValue, resultSet);
|
||||
ConvertOrganization(env, napiObject, typeIdValue, resultSet);
|
||||
}
|
||||
|
||||
bool ResultConvert::IsEmpty(std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (resultSet == nullptr) {
|
||||
HILOG_ERROR("ResultSetToHolder resultSet is nullptr");
|
||||
return true;
|
||||
}
|
||||
int rowCount = 0;
|
||||
resultSet->GetRowCount(rowCount);
|
||||
if (rowCount == 0) {
|
||||
resultSet->Close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::ResultSetToHolder(
|
||||
napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
napi_value array;
|
||||
napi_create_array(env, &array);
|
||||
if (IsEmpty(resultSet)) {
|
||||
return array;
|
||||
}
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
int count = 0;
|
||||
while (resultSetNum == 0) {
|
||||
napi_value elementObject;
|
||||
napi_create_object(env, &elementObject);
|
||||
int idValue;
|
||||
std::string id = "id";
|
||||
int idIndex = 0;
|
||||
resultSet->GetColumnIndex(id, idIndex);
|
||||
resultSet->GetInt(idIndex, idValue);
|
||||
napi_value napiIdKey;
|
||||
napi_create_string_utf8(env, "holderId", NAPI_AUTO_LENGTH, &napiIdKey);
|
||||
napi_value napiValue;
|
||||
napi_create_int64(env, idValue, &napiValue);
|
||||
napi_set_property(env, elementObject, napiIdKey, napiValue);
|
||||
std::string displayName = "account_name";
|
||||
std::string displayNameValue;
|
||||
int displayNameIndex = 0;
|
||||
resultSet->GetColumnIndex(displayName, displayNameIndex);
|
||||
resultSet->GetString(displayNameIndex, displayNameValue);
|
||||
napi_value napiDisplayNameKey;
|
||||
napi_create_string_utf8(env, "displayName", NAPI_AUTO_LENGTH, &napiDisplayNameKey);
|
||||
napi_value napiDisplayNameValue;
|
||||
napi_create_string_utf8(env, displayNameValue.c_str(), NAPI_AUTO_LENGTH, &napiDisplayNameValue);
|
||||
napi_set_property(env, elementObject, napiDisplayNameKey, napiDisplayNameValue);
|
||||
std::string bundleName = "account_type";
|
||||
std::string bundleNameValue;
|
||||
int bundleNameIndex = 0;
|
||||
resultSet->GetColumnIndex(bundleName, bundleNameIndex);
|
||||
resultSet->GetString(bundleNameIndex, bundleNameValue);
|
||||
napi_value napiBundleNameKey;
|
||||
napi_create_string_utf8(env, "bundleName", NAPI_AUTO_LENGTH, &napiBundleNameKey);
|
||||
napi_value napiBundleNameValue;
|
||||
napi_create_string_utf8(env, bundleNameValue.c_str(), NAPI_AUTO_LENGTH, &napiBundleNameValue);
|
||||
napi_set_property(env, elementObject, napiBundleNameKey, napiBundleNameValue);
|
||||
napi_set_element(env, array, count, elementObject);
|
||||
++count;
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
return array;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::ResultSetToGroup(
|
||||
napi_env env, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
napi_value array;
|
||||
NAPI_CALL(env, napi_create_array(env, &array));
|
||||
if (resultSet == nullptr) {
|
||||
HILOG_ERROR("ResultSetToGroup resultSet is nullptr");
|
||||
return array;
|
||||
}
|
||||
int rowCount = 0;
|
||||
resultSet->GetRowCount(rowCount);
|
||||
HILOG_INFO("ResultSetToGroup GetRowCount is %{public}d", rowCount);
|
||||
if (rowCount == 0) {
|
||||
resultSet->Close();
|
||||
return array;
|
||||
}
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
HILOG_INFO("ResultSetToGroup resultSetNum is %{public}d", resultSetNum);
|
||||
int count = 0;
|
||||
while (resultSetNum == 0) {
|
||||
napi_value elementObject;
|
||||
napi_create_object(env, &elementObject);
|
||||
int idValue;
|
||||
std::string id = "id";
|
||||
int idIndex = 0;
|
||||
resultSet->GetColumnIndex(id, idIndex);
|
||||
resultSet->GetInt(idIndex, idValue);
|
||||
napi_value napiIdKey;
|
||||
napi_create_string_utf8(env, "id", NAPI_AUTO_LENGTH, &napiIdKey);
|
||||
napi_value napiValue;
|
||||
napi_create_int64(env, idValue, &napiValue);
|
||||
napi_set_property(env, elementObject, napiIdKey, napiValue);
|
||||
std::string title = "group_name";
|
||||
std::string titleValue;
|
||||
int titleIndex = 0;
|
||||
resultSet->GetColumnIndex(title, titleIndex);
|
||||
resultSet->GetString(titleIndex, titleValue);
|
||||
napi_value napiTitleKey;
|
||||
napi_create_string_utf8(env, "title", NAPI_AUTO_LENGTH, &napiTitleKey);
|
||||
napi_value napiTitleValue;
|
||||
napi_create_string_utf8(env, titleValue.c_str(), NAPI_AUTO_LENGTH, &napiTitleValue);
|
||||
napi_set_property(env, elementObject, napiTitleKey, napiTitleValue);
|
||||
napi_set_element(env, array, count, elementObject);
|
||||
++count;
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
return array;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::GetResultMapValue(napi_env env, std::map<int, napi_value> &resultSetMap, int &contactId)
|
||||
{
|
||||
napi_value napiObject;
|
||||
if (resultSetMap.count(contactId) > 0) {
|
||||
std::map<int, napi_value>::iterator it = resultSetMap.find(contactId);
|
||||
napiObject = it->second;
|
||||
} else {
|
||||
napi_create_object(env, &napiObject);
|
||||
resultSetMap.insert(std::pair<int, napi_value>(contactId, napiObject));
|
||||
std::map<int, napi_value>::iterator it = resultSetMap.find(contactId);
|
||||
napiObject = it->second;
|
||||
}
|
||||
return napiObject;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::GetNapiValue(napi_env env, const std::string keyChar, napi_value napiObject)
|
||||
{
|
||||
if (napiObject == nullptr) {
|
||||
HILOG_ERROR("ResultConvert::GetNapiValue object is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value key;
|
||||
napi_create_string_utf8(env, keyChar.c_str(), NAPI_AUTO_LENGTH, &key);
|
||||
bool result = false;
|
||||
napi_has_property(env, napiObject, key, &result);
|
||||
if (result) {
|
||||
napi_value value = nullptr;
|
||||
napi_get_property(env, napiObject, key, &value);
|
||||
return value;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::GetNapiElementObject(napi_env env, napi_value napiObject, const std::string valueChar)
|
||||
{
|
||||
napi_value objectElement = GetNapiValue(env, valueChar, napiObject);
|
||||
if (objectElement == nullptr) {
|
||||
napi_create_object(env, &objectElement);
|
||||
}
|
||||
return objectElement;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::GetNapiElementArray(napi_env env, napi_value napiObject, const std::string valueChar)
|
||||
{
|
||||
napi_value emailArray = GetNapiValue(env, valueChar, napiObject);
|
||||
if (emailArray == nullptr) {
|
||||
napi_create_array(env, &emailArray);
|
||||
}
|
||||
return emailArray;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::GetResultValue(
|
||||
napi_env env, std::string &contentKey, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
int columnIndex = ERROR;
|
||||
resultSet->GetColumnIndex(contentKey, columnIndex);
|
||||
OHOS::NativeRdb::ColumnType columnType;
|
||||
resultSet->GetColumnType(columnIndex, columnType);
|
||||
napi_value napiValue = nullptr;
|
||||
if (columnType == OHOS::NativeRdb::ColumnType::TYPE_NULL) {
|
||||
return napiValue;
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_BLOB) {
|
||||
return napiValue;
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_INTEGER) {
|
||||
int intValue = 0;
|
||||
resultSet->GetInt(columnIndex, intValue);
|
||||
napi_create_int64(env, intValue, &napiValue);
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_FLOAT) {
|
||||
double doubleValue = 0;
|
||||
resultSet->GetDouble(columnIndex, doubleValue);
|
||||
napi_create_double(env, doubleValue, &napiValue);
|
||||
} else if (columnType == OHOS::NativeRdb::ColumnType::TYPE_STRING) {
|
||||
std::string stringValue;
|
||||
resultSet->GetString(columnIndex, stringValue);
|
||||
napi_create_string_utf8(env, stringValue.c_str(), NAPI_AUTO_LENGTH, &napiValue);
|
||||
}
|
||||
return napiValue;
|
||||
}
|
||||
|
||||
napi_value ResultConvert::CreateNapiStringValue(napi_env env, const std::string key)
|
||||
{
|
||||
napi_value keyValue;
|
||||
napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &keyValue);
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertEmail(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == EMAIL) {
|
||||
const std::string emails = "emails";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, emails);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
std::string aliasDetailInfoKey = "alias_detail_info";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
napi_value aliasDetailInfoValue = GetResultValue(env, aliasDetailInfoKey, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "email");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_value napiDisplayNameIdKey = CreateNapiStringValue(env, "displayName");
|
||||
napi_set_property(env, objectElement, napiDisplayNameIdKey, aliasDetailInfoValue);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, emails.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertName(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == NAME) {
|
||||
const std::string name = "name";
|
||||
napi_value objectElement = GetNapiElementObject(env, napiObject, name);
|
||||
std::string fullNameKey = "detail_info";
|
||||
std::string familyNameKey = "family_name";
|
||||
std::string familyNamePhoneticKey = "phonetic_name";
|
||||
std::string givenNameKey = "given_name";
|
||||
std::string givenNamePhoneticKey = "given_name_phonetic";
|
||||
std::string middleNamePhoneticKey = "middle_name_phonetic";
|
||||
std::string middleNameKey = "other_lan_last_name";
|
||||
std::string namePrefixKey = "alpha_name";
|
||||
std::string nameSuffixKey = "other_lan_first_name";
|
||||
napi_value fullNameValue = GetResultValue(env, fullNameKey, resultSet);
|
||||
napi_value familyNameValue = GetResultValue(env, familyNameKey, resultSet);
|
||||
napi_value familyNamePhoneticValue = GetResultValue(env, familyNamePhoneticKey, resultSet);
|
||||
napi_value givenNameValue = GetResultValue(env, givenNameKey, resultSet);
|
||||
napi_value givenNamePhoneticValue = GetResultValue(env, givenNamePhoneticKey, resultSet);
|
||||
napi_value middleNamePhoneticValue = GetResultValue(env, middleNamePhoneticKey, resultSet);
|
||||
napi_value middleNameValue = GetResultValue(env, middleNameKey, resultSet);
|
||||
napi_value namePrefixValue = GetResultValue(env, namePrefixKey, resultSet);
|
||||
napi_value nameSuffixValue = GetResultValue(env, nameSuffixKey, resultSet);
|
||||
napi_value napiFullNameKey = CreateNapiStringValue(env, "fullName");
|
||||
napi_set_property(env, objectElement, napiFullNameKey, fullNameValue);
|
||||
napi_value napifamilyNameKey = CreateNapiStringValue(env, "familyName");
|
||||
napi_set_property(env, objectElement, napifamilyNameKey, familyNameValue);
|
||||
napi_value napiFamilyNamePhoneticKey = CreateNapiStringValue(env, "phonetic_name");
|
||||
napi_set_property(env, objectElement, napiFamilyNamePhoneticKey, familyNamePhoneticValue);
|
||||
napi_value napiGivenNameKey = CreateNapiStringValue(env, "givenName");
|
||||
napi_set_property(env, objectElement, napiGivenNameKey, givenNameValue);
|
||||
napi_value napiGivenNamePhoneticKey = CreateNapiStringValue(env, "givenNamePhonetic");
|
||||
napi_set_property(env, objectElement, napiGivenNamePhoneticKey, givenNamePhoneticValue);
|
||||
napi_value napiMiddleNamePhoneticKey = CreateNapiStringValue(env, "middleNamePhoneticKey");
|
||||
napi_set_property(env, objectElement, napiMiddleNamePhoneticKey, middleNamePhoneticValue);
|
||||
napi_value napiMiddleNameKey = CreateNapiStringValue(env, "middleName");
|
||||
napi_set_property(env, objectElement, napiMiddleNameKey, middleNameValue);
|
||||
napi_value napiNamePrefixKey = CreateNapiStringValue(env, "namePrefixKey");
|
||||
napi_set_property(env, objectElement, napiNamePrefixKey, namePrefixValue);
|
||||
napi_value napiNameSuffixKey = CreateNapiStringValue(env, "nameSuffixKey");
|
||||
napi_set_property(env, objectElement, napiNameSuffixKey, nameSuffixValue);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, name.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, objectElement);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertUri(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == PHOTO) {
|
||||
const std::string portrait = "portrait";
|
||||
napi_value objectElement = GetNapiElementObject(env, napiObject, portrait);
|
||||
std::string uri = "detail_info";
|
||||
napi_value uriValue = GetResultValue(env, uri, resultSet);
|
||||
napi_value napiUri = CreateNapiStringValue(env, "uri");
|
||||
napi_set_property(env, objectElement, napiUri, uriValue);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, portrait.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, objectElement);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertEvent(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == CONTACT_EVENT) {
|
||||
const std::string events = "events";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, events);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "eventDate");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, events.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertGroup(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == GROUP_MEMBERSHIP) {
|
||||
const std::string groups = "groups";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, groups);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string groupNameKey = "group_name";
|
||||
napi_value groupNameValue = GetResultValue(env, groupNameKey, resultSet);
|
||||
napi_value napiGroupNameKey = CreateNapiStringValue(env, "title");
|
||||
napi_set_property(env, objectElement, napiGroupNameKey, groupNameValue);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "groupId");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, groups.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertImAddress(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == IM) {
|
||||
const std::string imAddresses = "imAddresses";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, imAddresses);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "imAddress");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, imAddresses.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertPhoneNumber(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == PHONE) {
|
||||
const std::string phoneNumbers = "phoneNumbers";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, phoneNumbers);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "phoneNumber");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, phoneNumbers.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertPostalAddress(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == POSTAL_ADDRESS) {
|
||||
const std::string postalAddresses = "postalAddresses";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, postalAddresses);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
std::string neighborhoodKey = "neighborhood";
|
||||
std::string poboxKey = "pobox";
|
||||
std::string postcodeKey = "postcode";
|
||||
std::string regionKey = "region";
|
||||
std::string streetKey = "street";
|
||||
std::string cityKey = "city";
|
||||
napi_value neighborhoodKeyValue = GetResultValue(env, streetKey, resultSet);
|
||||
napi_value cityKeyValue = GetResultValue(env, cityKey, resultSet);
|
||||
napi_value poboxKeyValue = GetResultValue(env, poboxKey, resultSet);
|
||||
napi_value postcodeKeyValue = GetResultValue(env, postcodeKey, resultSet);
|
||||
napi_value regionKeyValue = GetResultValue(env, regionKey, resultSet);
|
||||
napi_value streetKeyValue = GetResultValue(env, streetKey, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "postalAddress");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_set_property(
|
||||
env, objectElement, CreateNapiStringValue(env, neighborhoodKey.c_str()), neighborhoodKeyValue);
|
||||
napi_set_property(env, objectElement, CreateNapiStringValue(env, cityKey.c_str()), cityKeyValue);
|
||||
napi_set_property(env, objectElement, CreateNapiStringValue(env, poboxKey.c_str()), poboxKeyValue);
|
||||
napi_set_property(env, objectElement, CreateNapiStringValue(env, postcodeKey.c_str()), postcodeKeyValue);
|
||||
napi_set_property(env, objectElement, CreateNapiStringValue(env, regionKey.c_str()), regionKeyValue);
|
||||
napi_set_property(env, objectElement, CreateNapiStringValue(env, streetKey.c_str()), streetKeyValue);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey = CreateNapiStringValue(env, postalAddresses);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertRelation(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == RELATION) {
|
||||
const std::string relations = "relations";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, relations);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "relationName");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, relations.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertSipAddress(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == SIP_ADDRESS) {
|
||||
const std::string sipAddresses = "sipAddresses";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, sipAddresses);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "relationName");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, sipAddresses.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertWebsite(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == WEBSITE) {
|
||||
const std::string websites = "websites";
|
||||
napi_value emailArray = GetNapiElementArray(env, napiObject, websites);
|
||||
uint32_t count = 0;
|
||||
napi_get_array_length(env, emailArray, &count);
|
||||
napi_value objectElement;
|
||||
napi_create_object(env, &objectElement);
|
||||
std::string detailInfoKey = "detail_info";
|
||||
std::string customDataKey = "custom_data";
|
||||
std::string extend7Key = "extend7";
|
||||
napi_value detailInfoValue = GetResultValue(env, detailInfoKey, resultSet);
|
||||
napi_value customValue = GetResultValue(env, customDataKey, resultSet);
|
||||
napi_value extend7Value = GetResultValue(env, extend7Key, resultSet);
|
||||
napi_value napiDetailInfoKey = CreateNapiStringValue(env, "website");
|
||||
napi_set_property(env, objectElement, napiDetailInfoKey, detailInfoValue);
|
||||
napi_value napiLabelNameKey = CreateNapiStringValue(env, "labelName");
|
||||
napi_set_property(env, objectElement, napiLabelNameKey, customValue);
|
||||
napi_value napiLabelIdKey = CreateNapiStringValue(env, "labelId");
|
||||
napi_set_property(env, objectElement, napiLabelIdKey, extend7Value);
|
||||
napi_set_element(env, emailArray, count, objectElement);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, websites.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, emailArray);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertNickName(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == NICKNAME) {
|
||||
const std::string nickName = "nickName";
|
||||
napi_value objectElement = GetNapiElementObject(env, napiObject, nickName);
|
||||
std::string name = "detail_info";
|
||||
napi_value uriValue = GetResultValue(env, name, resultSet);
|
||||
napi_value napiUri = CreateNapiStringValue(env, "nickName");
|
||||
napi_set_property(env, objectElement, napiUri, uriValue);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, nickName.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, objectElement);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertNote(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == NOTE) {
|
||||
const std::string note = "note";
|
||||
napi_value objectElement = GetNapiElementObject(env, napiObject, note);
|
||||
std::string name = "detail_info";
|
||||
napi_value noteValue = GetResultValue(env, name, resultSet);
|
||||
napi_value noteKey = CreateNapiStringValue(env, "noteContent");
|
||||
napi_set_property(env, objectElement, noteKey, noteValue);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, note.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, objectElement);
|
||||
}
|
||||
}
|
||||
|
||||
void ResultConvert::ConvertOrganization(
|
||||
napi_env env, napi_value napiObject, int &typeId, std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
if (typeId == ORGANIZATION) {
|
||||
const std::string organization = "organization";
|
||||
napi_value objectElement = GetNapiElementObject(env, napiObject, organization);
|
||||
std::string company = "detail_info";
|
||||
std::string position = "position";
|
||||
napi_value companyValue = GetResultValue(env, company, resultSet);
|
||||
napi_value positionValue = GetResultValue(env, position, resultSet);
|
||||
napi_value napiNameValueKey = CreateNapiStringValue(env, "name");
|
||||
napi_set_property(env, objectElement, napiNameValueKey, companyValue);
|
||||
napi_value napiTitleValueKey = CreateNapiStringValue(env, "title");
|
||||
napi_set_property(env, objectElement, napiTitleValueKey, positionValue);
|
||||
napi_value napiElementKey;
|
||||
napi_create_string_utf8(env, organization.c_str(), NAPI_AUTO_LENGTH, &napiElementKey);
|
||||
napi_set_property(env, napiObject, napiElementKey, objectElement);
|
||||
}
|
||||
}
|
||||
} // namespace ContactsApi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 CALLLOG_ABILITY_H
|
||||
#define CALLLOG_ABILITY_H
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_loader.h"
|
||||
#include "want.h"
|
||||
|
||||
#include "calllog_database.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class CallLogAbility : public Ability {
|
||||
public:
|
||||
CallLogAbility();
|
||||
~CallLogAbility();
|
||||
virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override;
|
||||
virtual int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) override;
|
||||
virtual void OnStart(const Want &want) override;
|
||||
virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
|
||||
const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(const Uri &uri,
|
||||
const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual void Dump(const std::string &extra) override;
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Contacts::CallLogDataBase> callLogDataBase_;
|
||||
static std::map<std::string, int> uriValueMap_;
|
||||
int UriParse(Uri &uri);
|
||||
int InsertExecute(const Uri &uri, const NativeRdb::ValuesBucket &value);
|
||||
void DataBaseNotifyChange(int code, Uri uri);
|
||||
bool IsBeginTransactionOK(int code, std::mutex &mutex);
|
||||
bool IsCommitOk(int code, std::mutex &mutex);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // CALLLOG_ABILITY_H
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 CALLLOG_DATABASE_H
|
||||
#define CALLLOG_DATABASE_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
#include "value_object.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class CallLogDataBase {
|
||||
public:
|
||||
static std::shared_ptr<CallLogDataBase> GetInstance();
|
||||
static std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
|
||||
int64_t InsertCallLog(OHOS::NativeRdb::ValuesBucket insertValues);
|
||||
int UpdateCallLog(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteCallLog(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> Query(
|
||||
OHOS::NativeRdb::RdbPredicates &rdbPredicates, std::vector<std::string> columns);
|
||||
int BeginTransaction();
|
||||
int Commit();
|
||||
int RollBack();
|
||||
void QueryContactsByInsertCalls(OHOS::NativeRdb::ValuesBucket &insertValues);
|
||||
|
||||
private:
|
||||
CallLogDataBase();
|
||||
CallLogDataBase(const CallLogDataBase &);
|
||||
const CallLogDataBase &operator=(const CallLogDataBase &);
|
||||
static std::shared_ptr<CallLogDataBase> callLogDataBase_;
|
||||
int UpdateTopContact(OHOS::NativeRdb::ValuesBucket &insertValues);
|
||||
};
|
||||
|
||||
class SqliteOpenHelperCallLogCallback : public OHOS::NativeRdb::RdbOpenCallback {
|
||||
public:
|
||||
int OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
|
||||
int OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
|
||||
int OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // CALLLOG_DATABASE_H
|
||||
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* 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 "calllog_ability.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "common.h"
|
||||
#include "contacts_common_event.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "file_utils.h"
|
||||
#include "predicates_convert.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "sql_analyzer.h"
|
||||
#include "uri_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
REGISTER_AA(CallLogAbility);
|
||||
namespace {
|
||||
std::mutex g_mutex;
|
||||
}
|
||||
std::shared_ptr<Contacts::CallLogDataBase> CallLogAbility::callLogDataBase_ = nullptr;
|
||||
std::map<std::string, int> CallLogAbility::uriValueMap_ = {
|
||||
{"/com.ohos.calllogability/calls/calllog", Contacts::CALLLOG}
|
||||
};
|
||||
|
||||
CallLogAbility::CallLogAbility()
|
||||
{
|
||||
}
|
||||
|
||||
CallLogAbility::~CallLogAbility()
|
||||
{
|
||||
}
|
||||
|
||||
void CallLogAbility::Dump(const std::string &extra)
|
||||
{
|
||||
HILOG_ERROR("CallLogAbility ====>Dump:%{public}s", extra.c_str());
|
||||
Contacts::FileUtils fileUtils;
|
||||
std::string dirStr = Contacts::ContactsPath::DUMP_PATH;
|
||||
fileUtils.WriteStringToFileAppend(dirStr, extra);
|
||||
}
|
||||
|
||||
void CallLogAbility::OnStart(const Want &want)
|
||||
{
|
||||
std::string basePath = GetDatabaseDir();
|
||||
Contacts::ContactsPath::RDB_PATH = basePath + "/";
|
||||
Contacts::ContactsPath::RDB_BACKUP_PATH = basePath + "/backup/";
|
||||
Contacts::ContactsPath::DUMP_PATH = GetFilesDir() + "/";
|
||||
}
|
||||
|
||||
int CallLogAbility::UriParse(Uri &uri)
|
||||
{
|
||||
Contacts::UriUtils uriUtils;
|
||||
int parseCode = uriUtils.UriParse(uri, uriValueMap_);
|
||||
return parseCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallLogAbility BeginTransaction emptiness problems
|
||||
*
|
||||
* @param code the return number of BeginTransaction
|
||||
* @param mutex transmission parameter : lock
|
||||
*
|
||||
* @return BeginTransaction emptiness true or false
|
||||
*/
|
||||
bool CallLogAbility::IsBeginTransactionOK(int code, std::mutex &mutex)
|
||||
{
|
||||
mutex.try_lock();
|
||||
if (code != 0) {
|
||||
HILOG_ERROR("IsBeginTransactionOK fail");
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallLogAbility Commit emptiness problems
|
||||
*
|
||||
* @param code the return number of Commit
|
||||
* @param mutex transmission parameter : lock
|
||||
*
|
||||
* @return Commit emptiness true or false
|
||||
*/
|
||||
bool CallLogAbility::IsCommitOk(int code, std::mutex &mutex)
|
||||
{
|
||||
mutex.try_lock();
|
||||
if (code != 0) {
|
||||
HILOG_ERROR("IsCommitOk fail");
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallLogAbility Insert database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param value Insert the data value of the database
|
||||
*
|
||||
* @return Insert database results code
|
||||
*/
|
||||
int CallLogAbility::Insert(const Uri &uri, const NativeRdb::ValuesBucket &value)
|
||||
{
|
||||
Contacts::SqlAnalyzer sqlAnalyzer;
|
||||
bool isOk = sqlAnalyzer.CheckValuesBucket(value);
|
||||
if (!isOk) {
|
||||
HILOG_ERROR("CallLogAbility CheckValuesBucket is error");
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
callLogDataBase_ = Contacts::CallLogDataBase::GetInstance();
|
||||
int ret = callLogDataBase_->BeginTransaction();
|
||||
if (!IsBeginTransactionOK(ret, g_mutex)) {
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
int resultId = InsertExecute(uri, value);
|
||||
if (resultId == Contacts::OPERATION_ERROR) {
|
||||
ret = callLogDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::OPERATION_ERROR;
|
||||
}
|
||||
ret = callLogDataBase_->Commit();
|
||||
if (!IsCommitOk(ret, g_mutex)) {
|
||||
callLogDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_INSERT, uri);
|
||||
return resultId;
|
||||
}
|
||||
|
||||
int CallLogAbility::InsertExecute(const Uri &uri, const NativeRdb::ValuesBucket &value)
|
||||
{
|
||||
int rowId = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int parseCode = UriParse(uriTemp);
|
||||
switch (parseCode) {
|
||||
case Contacts::CALLLOG:
|
||||
rowId = callLogDataBase_->InsertCallLog(value);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("CallLogAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
return rowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallLogAbility BatchInsert database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param value Insert the data values of the database
|
||||
*
|
||||
* @return Insert database results code
|
||||
*/
|
||||
int CallLogAbility::BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values)
|
||||
{
|
||||
int rowRet = Contacts::RDB_EXECUTE_FAIL;
|
||||
int size = values.size();
|
||||
if (size <= 0) {
|
||||
HILOG_ERROR("BatchInsert value is error");
|
||||
return rowRet;
|
||||
}
|
||||
g_mutex.lock();
|
||||
callLogDataBase_ = Contacts::CallLogDataBase::GetInstance();
|
||||
int ret = callLogDataBase_->BeginTransaction();
|
||||
if (!IsBeginTransactionOK(ret, g_mutex)) {
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
++count;
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues = values[i];
|
||||
int code = InsertExecute(uri, rawContactValues);
|
||||
if (code == Contacts::RDB_EXECUTE_FAIL) {
|
||||
callLogDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return code;
|
||||
}
|
||||
if (count % Contacts::BATCH_INSERT_COUNT == 0) {
|
||||
int markRet = callLogDataBase_->Commit();
|
||||
int beginRet = callLogDataBase_->BeginTransaction();
|
||||
if (!IsCommitOk(markRet, g_mutex) || !IsBeginTransactionOK(beginRet, g_mutex)) {
|
||||
callLogDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
int markRet = callLogDataBase_->Commit();
|
||||
if (!IsCommitOk(markRet, g_mutex)) {
|
||||
callLogDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_INSERT, uri);
|
||||
return Contacts::RDB_EXECUTE_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallLogAbility Update database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param predicates Update the data value of the condition
|
||||
*
|
||||
* @return Update database results code
|
||||
*/
|
||||
int CallLogAbility::Update(
|
||||
const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
Contacts::SqlAnalyzer sqlAnalyzer;
|
||||
bool isOk = sqlAnalyzer.CheckValuesBucket(value);
|
||||
if (!isOk) {
|
||||
HILOG_ERROR("CallLogAbility CheckValuesBucket is error");
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
callLogDataBase_ = Contacts::CallLogDataBase::GetInstance();
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
int ret = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int parseCode = UriParse(uriTemp);
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (parseCode) {
|
||||
case Contacts::CALLLOG:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::CALLLOG, dataAbilityPredicates);
|
||||
ret = callLogDataBase_->UpdateCallLog(value, rdbPredicates);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("CallLogAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_UPDATE, uri);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallLogAbility Delete database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param predicates Delete the data values of the condition
|
||||
*
|
||||
* @return Delete database results code
|
||||
*/
|
||||
int CallLogAbility::Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
g_mutex.lock();
|
||||
callLogDataBase_ = Contacts::CallLogDataBase::GetInstance();
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
int ret = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int parseCode = UriParse(uriTemp);
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (parseCode) {
|
||||
case Contacts::CALLLOG:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::CALLLOG, dataAbilityPredicates);
|
||||
ret = callLogDataBase_->DeleteCallLog(rdbPredicates);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("ContactsDataAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_DELETE, uri);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CallLogAbility Query database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param columns Columns returned by query
|
||||
* @param predicates Query the data values of the condition
|
||||
*
|
||||
* @return Query database results
|
||||
*/
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> CallLogAbility::Query(
|
||||
const Uri &uri, const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
HILOG_INFO("ContactsDataAbility ====>Query start");
|
||||
callLogDataBase_ = Contacts::CallLogDataBase::GetInstance();
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> result;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
Contacts::UriUtils uriUtils;
|
||||
int parseCode = uriUtils.UriParse(uriTemp, uriValueMap_);
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
std::vector<std::string> columnsTemp = columns;
|
||||
switch (parseCode) {
|
||||
case Contacts::CALLLOG:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::CALLLOG, dataAbilityPredicates);
|
||||
result = callLogDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("CallLogAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> sharedPtrResult = std::move(result);
|
||||
HILOG_INFO("ContactsDataAbility ====>Query end");
|
||||
return sharedPtrResult;
|
||||
}
|
||||
|
||||
void CallLogAbility::DataBaseNotifyChange(int code, Uri uri)
|
||||
{
|
||||
Contacts::ContactsCommonEvent::SendCallLogChange(code);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* 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 "calllog_database.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_database.h"
|
||||
#include "contacts_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
std::shared_ptr<CallLogDataBase> CallLogDataBase::callLogDataBase_ = nullptr;
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> CallLogDataBase::store_ = nullptr;
|
||||
static std::string g_databaseName;
|
||||
|
||||
CallLogDataBase::CallLogDataBase()
|
||||
{
|
||||
g_databaseName = ContactsPath::RDB_PATH + "calls.db";
|
||||
HILOG_INFO("CallLogDataBase g_databaseName :%{public}s", g_databaseName.c_str());
|
||||
int errCode = OHOS::NativeRdb::E_OK;
|
||||
OHOS::NativeRdb::RdbStoreConfig config(g_databaseName);
|
||||
SqliteOpenHelperCallLogCallback sqliteOpenHelperCallback;
|
||||
store_ = OHOS::NativeRdb::RdbHelper::GetRdbStore(config, DATABASE_OPEN_VERSION, sqliteOpenHelperCallback, errCode);
|
||||
if (errCode != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("CallLogDataBase errCode :%{public}d", errCode);
|
||||
} else {
|
||||
HILOG_INFO("CallLogDataBase errCode :%{public}d", errCode);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<CallLogDataBase> CallLogDataBase::GetInstance()
|
||||
{
|
||||
if (callLogDataBase_ == nullptr) {
|
||||
callLogDataBase_.reset(new CallLogDataBase());
|
||||
return callLogDataBase_;
|
||||
}
|
||||
return callLogDataBase_;
|
||||
}
|
||||
|
||||
int CallLogDataBase::BeginTransaction()
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("CallLogDataBase BeginTransaction store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->BeginTransaction();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("CallLogDataBase BeginTransaction fail :%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CallLogDataBase::Commit()
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR(" CallLogDataBase Commit store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->Commit();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR(" CallLogDataBase Commit fail :%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CallLogDataBase::RollBack()
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR(" CallLogDataBase RollBack store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->RollBack();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR(" CallLogDataBase RollBack fail :%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SqliteOpenHelperCallLogCallback::OnCreate(OHOS::NativeRdb::RdbStore &store)
|
||||
{
|
||||
std::vector<int> judgeSuccess;
|
||||
judgeSuccess.push_back(store.ExecuteSql(CREATE_VOICEMAIL));
|
||||
judgeSuccess.push_back(store.ExecuteSql(CREATE_CALLLOG));
|
||||
judgeSuccess.push_back(store.ExecuteSql(CREATE_REPLYING));
|
||||
judgeSuccess.push_back(store.ExecuteSql(CREATE_DATABASE_BACKUP_TASK));
|
||||
judgeSuccess.push_back(store.ExecuteSql(CREATE_INSERT_BACKUP_TIME));
|
||||
judgeSuccess.push_back(store.ExecuteSql(CALL_LOG_PHONE_NUMBER_INDEX));
|
||||
int size = judgeSuccess.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (judgeSuccess[i] != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("SqliteOpenHelperCallLogCallback create table error : %{public}d", judgeSuccess[i]);
|
||||
}
|
||||
}
|
||||
return OHOS::NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
int SqliteOpenHelperCallLogCallback::OnUpgrade(OHOS::NativeRdb::RdbStore &store, int oldVersion, int newVersion)
|
||||
{
|
||||
HILOG_INFO("OnUpgrade oldVersion is %{public}d , newVersion is %{public}d", oldVersion, newVersion);
|
||||
if (oldVersion < newVersion && newVersion == DATABASE_NEW_VERSION) {
|
||||
store.ExecuteSql("ALTER TABLE database_backup_task ADD COLUMN sync TEXT");
|
||||
}
|
||||
store.SetVersion(newVersion);
|
||||
return OHOS::NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
int SqliteOpenHelperCallLogCallback::OnDowngrade(OHOS::NativeRdb::RdbStore &store, int oldVersion, int newVersion)
|
||||
{
|
||||
HILOG_INFO("OnDowngrade oldVersion is %{public}d , newVersion is %{public}d", oldVersion, newVersion);
|
||||
if (oldVersion > newVersion && newVersion == DATABASE_OPEN_VERSION) {
|
||||
store.ExecuteSql(
|
||||
"CREATE TABLE IF NOT EXISTS database_backup (id INTEGER PRIMARY KEY AUTOINCREMENT, backup_time "
|
||||
"TEXT, backup_path TEXT, remarks TEXT)");
|
||||
store.ExecuteSql(
|
||||
"INSERT INTO database_backup(id, backup_time, backup_path, remarks) SELECT id, "
|
||||
"backup_time, backup_path, remarks FROM database_backup_task");
|
||||
store.ExecuteSql("DROP table database_backup_task");
|
||||
store.ExecuteSql("ALTER table database_backup RENAME TO database_backup_task");
|
||||
store.ExecuteSql(CREATE_INSERT_BACKUP_TIME);
|
||||
}
|
||||
int ret = store.SetVersion(newVersion);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief InsertCallLog operation
|
||||
*
|
||||
* @param insertValues Conditions for update operation
|
||||
*
|
||||
* @return InsertCallLog operation results
|
||||
*/
|
||||
int64_t CallLogDataBase::InsertCallLog(OHOS::NativeRdb::ValuesBucket insertValues)
|
||||
{
|
||||
int64_t outRowId = RDB_EXECUTE_FAIL;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("CallLogDataBase Insert store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
QueryContactsByInsertCalls(insertValues);
|
||||
int ret = store_->Insert(outRowId, CallsTableName::CALLLOG, insertValues);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("CallLogDataBase InsertCallLog ret :%{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return outRowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UpdateCallLog operation
|
||||
*
|
||||
* @param values Conditions for update operation
|
||||
* @param predicates Conditions for update operation
|
||||
*
|
||||
* @return UpdateCallLog operation results
|
||||
*/
|
||||
int CallLogDataBase::UpdateCallLog(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &predicates)
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("CallLogDataBase Update store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (values.HasColumn(CallLogColumns::PHONE_NUMBER)) {
|
||||
QueryContactsByInsertCalls(values);
|
||||
}
|
||||
int changeRow;
|
||||
int ret = store_->Update(changeRow, values, predicates);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("CallLogDataBase UpdateCallLog ret :%{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeleteCallLog operation
|
||||
*
|
||||
* @param predicates Conditions for delete operation
|
||||
*
|
||||
* @return DeleteCallLog operation results
|
||||
*/
|
||||
int CallLogDataBase::DeleteCallLog(OHOS::NativeRdb::RdbPredicates &predicates)
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("CallLogDataBase Delete store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int deleteRow;
|
||||
int ret = store_->Delete(deleteRow, predicates);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("CallLogDataBase DeleteCallLog ret :%{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QueryContacts operation
|
||||
*
|
||||
* @param predicates Conditions for query operation
|
||||
* @param columns Conditions for query operation
|
||||
*
|
||||
* @return Query database results
|
||||
*/
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> CallLogDataBase::Query(
|
||||
OHOS::NativeRdb::RdbPredicates &predicates, std::vector<std::string> columns)
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("CallLogDataBase Delete store_ is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> result = store_->Query(predicates, columns);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QueryContacts By InsertCallLog get name and phone to UpdateTopContact
|
||||
*
|
||||
* @param insertValues Inserted data values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void CallLogDataBase::QueryContactsByInsertCalls(OHOS::NativeRdb::ValuesBucket &insertValues)
|
||||
{
|
||||
if (!insertValues.HasColumn(CallLogColumns::PHONE_NUMBER)) {
|
||||
HILOG_ERROR("QueryContactsByInsertCalls phone_number is required");
|
||||
return;
|
||||
}
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
insertValues.GetObject(CallLogColumns::PHONE_NUMBER, value);
|
||||
std::string phoneNumber;
|
||||
value.GetString(phoneNumber);
|
||||
ContactsType contactsType;
|
||||
static std::shared_ptr<ContactsDataBase> contactsDataBase = ContactsDataBase::GetInstance();
|
||||
int typeNameId = contactsType.LookupTypeId(contactsDataBase->contactStore_, ContentTypeData::PHONE);
|
||||
std::string sql = "SELECT display_name, contact_id FROM ";
|
||||
sql.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE raw_contact_id = ")
|
||||
.append("(SELECT min(raw_contact_id) FROM ")
|
||||
.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE detail_info = ?")
|
||||
.append(" AND is_deleted = 0")
|
||||
.append(") AND type_id = ")
|
||||
.append(std::to_string(typeNameId))
|
||||
.append(" AND is_deleted = 0");
|
||||
std::vector<std::string> selectionArgs;
|
||||
selectionArgs.push_back(phoneNumber);
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet =
|
||||
contactsDataBase->contactStore_->QuerySql(sql, selectionArgs);
|
||||
std::string quickSearchKey;
|
||||
std::string name;
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
resultSet->GetString(0, name);
|
||||
resultSet->GetString(1, quickSearchKey);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
insertValues.Delete(CallLogColumns::DISPLAY_NAME);
|
||||
insertValues.PutString(CallLogColumns::DISPLAY_NAME, name);
|
||||
insertValues.Delete(CallLogColumns::QUICK_SEARCH_KEY);
|
||||
insertValues.PutString(CallLogColumns::QUICK_SEARCH_KEY, quickSearchKey);
|
||||
break;
|
||||
}
|
||||
resultSet->Close();
|
||||
int ret = UpdateTopContact(insertValues);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("QueryContactsByInsertCalls UpdateTopContact is error");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the callLog contact frequency and contact time
|
||||
*
|
||||
* @param insertValues Get contact time
|
||||
* @param phoneNumber phoneNumber To select callLog
|
||||
*
|
||||
* @return update frequency and time result code
|
||||
*/
|
||||
int CallLogDataBase::UpdateTopContact(OHOS::NativeRdb::ValuesBucket &insertValues)
|
||||
{
|
||||
if (!insertValues.HasColumn(CallLogColumns::BEGIN_TIME)) {
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
insertValues.GetObject(CallLogColumns::BEGIN_TIME, value);
|
||||
int contactedTime;
|
||||
value.GetInt(contactedTime);
|
||||
std::string sqlBuild = "UPDATE ";
|
||||
sqlBuild.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" SET lastest_contacted_time = ")
|
||||
.append(std::to_string(contactedTime))
|
||||
.append(", contacted_count = (contacted_count + 1) ")
|
||||
.append(" WHERE contact_id = ")
|
||||
.append("(SELECT DISTINCT min(contact_id) FROM ")
|
||||
.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE detail_info = ? ")
|
||||
.append(")");
|
||||
std::vector<OHOS::NativeRdb::ValueObject> bindArgs;
|
||||
OHOS::NativeRdb::ValueObject phone;
|
||||
insertValues.GetObject(CallLogColumns::PHONE_NUMBER, phone);
|
||||
bindArgs.push_back(phone);
|
||||
int ret = ContactsDataBase::GetInstance()->contactStore_->ExecuteSql(sqlBuild, bindArgs);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("store ExecuteSql error");
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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_H
|
||||
#define CONTACT_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_store.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class Contacts {
|
||||
public:
|
||||
Contacts();
|
||||
~Contacts();
|
||||
int InsertContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, const int64_t &outRawContactId,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues, int64_t &contactId);
|
||||
OHOS::NativeRdb::ValuesBucket StructureContactDataValueBucket(OHOS::NativeRdb::ValuesBucket rawContactValues);
|
||||
int UpdateContact(const int &rawContactId, std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore,
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues);
|
||||
int DeleteContactById(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int needDeleteContactId);
|
||||
|
||||
private:
|
||||
int ContactValueBucketGetInt(OHOS::NativeRdb::ValuesBucket rawContactValues, std::string ColumnName);
|
||||
std::string ContactValueBucketGetString(OHOS::NativeRdb::ValuesBucket rawContactValues, std::string ColumnName);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef CONTACT_ACCOUNT_H
|
||||
#define CONTACT_ACCOUNT_H
|
||||
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
#include "account_data_collection.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ContactsAccount {
|
||||
public:
|
||||
static std::shared_ptr<ContactsAccount> GetInstance();
|
||||
~ContactsAccount();
|
||||
int64_t Insert(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string accountName, std::string accountType);
|
||||
int LookupAccountTypeId(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string accountName, std::string accountType);
|
||||
void PrepopulateCommonAccountTypes(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore);
|
||||
std::vector<AccountDataCollection> GetAccountFromLoacl(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore);
|
||||
int GetNotExistAccount(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, AccountDataCollection collection);
|
||||
int DeleteDataByRawId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int needDeleteRawContactId);
|
||||
int DeleteGroupsByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId);
|
||||
int DeleteAccountByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId);
|
||||
int StopForegin(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore);
|
||||
int OpenForegin(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore);
|
||||
|
||||
private:
|
||||
ContactsAccount();
|
||||
static std::shared_ptr<ContactsAccount> instance_;
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // CONTACT_ACCOUNT_H
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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_DATA_ABILITY_TEST_H
|
||||
#define CONTACTSDATAABILITY_CONTACT_DATA_ABILITY_TEST_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_loader.h"
|
||||
#include "predicates_convert.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "want.h"
|
||||
|
||||
#include "contacts_database.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class ContactsDataAbility : public Ability {
|
||||
public:
|
||||
ContactsDataAbility();
|
||||
~ContactsDataAbility();
|
||||
virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override;
|
||||
virtual int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) override;
|
||||
virtual void OnStart(const Want &want) override;
|
||||
virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
|
||||
const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(const Uri &uri,
|
||||
const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual void Dump(const std::string &extra) override;
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Contacts::ContactsDataBase> contactDataBase_;
|
||||
static std::shared_ptr<Contacts::ProfileDatabase> profileDataBase_;
|
||||
static std::map<std::string, int> uriValueMap_;
|
||||
int InsertExecute(int &code, const NativeRdb::ValuesBucket &value);
|
||||
int UriParseAndSwitch(Uri &uri);
|
||||
void SwitchProfile(Uri &uri);
|
||||
void QueryExecute(std::shared_ptr<NativeRdb::AbsSharedResultSet> &result,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates, std::vector<std::string> &columnsTemp,
|
||||
int &parseCode);
|
||||
void QueryExecuteSwitchSplit(std::shared_ptr<NativeRdb::AbsSharedResultSet> &result,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates, std::vector<std::string> &columnsTemp,
|
||||
int &parseCode);
|
||||
void UpdateExecute(int &retCode, int code, const NativeRdb::ValuesBucket &value,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates);
|
||||
void SwitchUpdate(int &retCode, int &code, const NativeRdb::ValuesBucket &value,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates);
|
||||
void DeleteExecute(int &retCode, int code, OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates);
|
||||
void DataBaseNotifyChange(int code, Uri uri);
|
||||
bool IsBeginTransactionOK(int code, std::mutex &mutex);
|
||||
bool IsCommitOK(int code, std::mutex &mutex);
|
||||
int BackUp();
|
||||
int Recover(int &code);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // CONTACTSDATAABILITY_CONTACT_DATA_ABILITY_TEST_H
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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_DATABASE_H
|
||||
#define CONTACT_DATABASE_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
#include "calllog_database.h"
|
||||
#include "profile_database.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ContactsDataBase {
|
||||
public:
|
||||
static std::shared_ptr<ContactsDataBase> GetInstance();
|
||||
static std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
|
||||
static std::shared_ptr<OHOS::NativeRdb::RdbStore> contactStore_;
|
||||
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> ResultSetToValuesBucket(
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
void GetContactByValue(int &rawContactId, OHOS::NativeRdb::ValueObject &value);
|
||||
int64_t InsertRawContact(std::string table, OHOS::NativeRdb::ValuesBucket value);
|
||||
int64_t InsertContactData(std::string table, OHOS::NativeRdb::ValuesBucket value);
|
||||
int64_t InsertGroup(std::string table, OHOS::NativeRdb::ValuesBucket value);
|
||||
int64_t InsertBlockList(std::string table, OHOS::NativeRdb::ValuesBucket value);
|
||||
int UpdateContactData(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int UpdateRawContact(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int UpdateGroup(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int UpdateBlockList(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteGroup(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteContactData(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteContact(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteRawContact(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteBlockList(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> Query(
|
||||
OHOS::NativeRdb::RdbPredicates &rdbPredicates, std::vector<std::string> &columns);
|
||||
int CompletelyDelete(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int BeginTransaction();
|
||||
int Commit();
|
||||
int RollBack();
|
||||
static void DestroyInstanceAndRestore(std::string restorePath);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> SelectCandidate();
|
||||
int Split(OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
int ContactMerge();
|
||||
int ReContactMerge(OHOS::NativeRdb::DataAbilityPredicates predicates);
|
||||
int DeleteRecord(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int GetTypeId(std::string typeText);
|
||||
void DeleteExecute(std::shared_ptr<OHOS::NativeRdb::RdbStore> &store,
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> queryValuesBucket);
|
||||
void InsertMergeData(std::shared_ptr<OHOS::NativeRdb::RdbStore> &store, std::vector<int> &rawContactIdVector);
|
||||
void MarkMerge(std::shared_ptr<OHOS::NativeRdb::RdbStore> &store);
|
||||
void MergeUpdateTask(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store, std::vector<int> &rawContactIdVector, bool isDeleted);
|
||||
void DeleteRecordInsert(std::shared_ptr<OHOS::NativeRdb::RdbStore> &store,
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> &queryValuesBucket);
|
||||
void DeletedAsyncTask(std::shared_ptr<OHOS::NativeRdb::RdbStore> &store,
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> &queryValuesBucket);
|
||||
|
||||
private:
|
||||
ContactsDataBase();
|
||||
ContactsDataBase(const ContactsDataBase &);
|
||||
static std::shared_ptr<ContactsDataBase> contactDataBase_;
|
||||
static std::shared_ptr<CallLogDataBase> callLogDataBase_;
|
||||
|
||||
std::vector<int> QueryContactDataRawContactId(
|
||||
OHOS::NativeRdb::RdbPredicates &rdbPredicates, std::vector<std::string> &types);
|
||||
std::string StructureDeleteContactJson(
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues, std::string rawContactIdColumn, int rawContactId);
|
||||
int DeleteExecute(std::vector<OHOS::NativeRdb::ValuesBucket> &queryValuesBucket);
|
||||
int DeleteRawContactLocal(int contactId, int rawContactId, std::string backupData, std::string disPlayName);
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> DeleteContactQuery(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
std::vector<OHOS::NativeRdb::ValuesBucket> DeleteRawContactQuery(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteLocal(int rawContactId, std::string contactId);
|
||||
static bool Restore(std::string restorePath);
|
||||
int GetTypeText(
|
||||
OHOS::NativeRdb::ValuesBucket &contactDataValues, int &typeId, int &rawContactId, std::string &typeText);
|
||||
int CompletelyDeleteCommit(int retCode);
|
||||
};
|
||||
|
||||
class SqliteOpenHelperContactCallback : public OHOS::NativeRdb::RdbOpenCallback {
|
||||
public:
|
||||
int OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
|
||||
int OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
|
||||
int OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_DATABASE_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 CONTACT_TYPE_H
|
||||
#define CONTACT_TYPE_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ContactsType {
|
||||
public:
|
||||
ContactsType();
|
||||
~ContactsType();
|
||||
int64_t Insert(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string typeValue, int typeId);
|
||||
int LookupTypeId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string typeValue);
|
||||
void PrepopulateCommonTypes(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore);
|
||||
std::string GetTypeText(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int typeId);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_TYPE_H
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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_UPDATE_HELPER_H
|
||||
#define CONTACT_UPDATE_HELPER_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_store.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ContactsUpdateHelper {
|
||||
public:
|
||||
ContactsUpdateHelper();
|
||||
~ContactsUpdateHelper();
|
||||
int UpdateDisplay(std::vector<int> rawContactIdVector, std::vector<std::string> types,
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, OHOS::NativeRdb::ValuesBucket linkDataDataValues,
|
||||
bool isDelete);
|
||||
OHOS::NativeRdb::ValuesBucket GetUpdateDisPlayNameValuesBucket(
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete);
|
||||
OHOS::NativeRdb::ValuesBucket GetUpdateSearchNameValuesBucket(
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete);
|
||||
OHOS::NativeRdb::ValuesBucket GetUpdateCompanyValuesBucket(
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete);
|
||||
int UpdateName(OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete, int rawId, std::string type,
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore);
|
||||
void UpdateCallLogByPhoneNum(
|
||||
std::vector<int> &rawContactIdVector, std::shared_ptr<OHOS::NativeRdb::RdbStore> &rdbStore, bool isDelete);
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> QueryDataForCallLog(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &rdbStore, int contactId);
|
||||
void DataToUpdateCallLog(
|
||||
bool isDelete, int contactId, std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet);
|
||||
int UpdateCallLog(
|
||||
std::string &phoneNumber, std::string &name, std::string &quickSearch, bool isDelete, bool isCallLog);
|
||||
int UpdateCallLogNameNull(std::string &name, std::string &quickSearch, bool isCallLog);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // CONTACT_UPDATE_HELPER_H
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 PROFILE_DATABASE_H
|
||||
#define PROFILE_DATABASE_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ProfileDatabase {
|
||||
public:
|
||||
static std::shared_ptr<ProfileDatabase> GetInstance();
|
||||
static std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
|
||||
int BeginTransaction();
|
||||
int Commit();
|
||||
int RollBack();
|
||||
static void DestroyInstanceAndRestore(std::string restorePath);
|
||||
|
||||
private:
|
||||
ProfileDatabase();
|
||||
static bool Restore(std::string restorePath);
|
||||
ProfileDatabase(const ProfileDatabase &);
|
||||
const ProfileDatabase &operator=(const ProfileDatabase &);
|
||||
static std::shared_ptr<ProfileDatabase> profileDatabase_;
|
||||
};
|
||||
|
||||
class SqliteOpenHelperProfileCallback : public OHOS::NativeRdb::RdbOpenCallback {
|
||||
public:
|
||||
int OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
|
||||
int OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
|
||||
int OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // PROFILE_DATABASE_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 RAW_CONTACT_H
|
||||
#define RAW_CONTACT_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_store.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class RawContacts {
|
||||
public:
|
||||
RawContacts();
|
||||
~RawContacts();
|
||||
int InsertRawContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int64_t &outRawContactId,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues);
|
||||
int UpdateRawContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues, std::string whereClause, std::vector<std::string> whereArgs);
|
||||
int UpdateRawContactById(int &rawContactId, std::string type, std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues);
|
||||
int GetDeleteContactIdByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId);
|
||||
int GetDeleteRawContactIdByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId);
|
||||
int DeleteRawcontactByRawId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int needDeleteRawContactId);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // RAW_CONTACT_H
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 "contacts.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
Contacts::Contacts(void)
|
||||
{
|
||||
}
|
||||
|
||||
Contacts::~Contacts()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Insert the raw_contact table at the same time as the contact table
|
||||
*
|
||||
* @param rdbStore Database operation object
|
||||
* @param outRawContactId raw_conatct table id
|
||||
* @param rawContactValues insert raw_contact values
|
||||
* @param contactId contact_id address
|
||||
*
|
||||
* @return insert contact error or success code
|
||||
*/
|
||||
int Contacts::InsertContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, const int64_t &outRawContactId,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues, int64_t &contactId)
|
||||
{
|
||||
OHOS::NativeRdb::ValuesBucket contactValues = StructureContactDataValueBucket(rawContactValues);
|
||||
contactValues.PutInt(ContactColumns::NAME_RAW_CONTACT_ID, outRawContactId);
|
||||
int rowContactRet = rdbStore->Insert(contactId, ContactTableName::CONTACT, contactValues);
|
||||
return rowContactRet;
|
||||
}
|
||||
|
||||
int Contacts::UpdateContact(const int &rawContactId, std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore,
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues)
|
||||
{
|
||||
std::string upWhereClause;
|
||||
upWhereClause.append(ContactColumns::NAME_RAW_CONTACT_ID).append(" = ?");
|
||||
std::vector<std::string> upWhereArgs;
|
||||
upWhereArgs.push_back(std::to_string(rawContactId));
|
||||
int changedRows = OHOS::NativeRdb::E_OK;
|
||||
int ret = rdbStore->Update(changedRows, ContactTableName::CONTACT, linkDataDataValues, upWhereClause, upWhereArgs);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateSearchContact fail:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Build conatct data
|
||||
*
|
||||
* @param rawContactValues insert contact values
|
||||
*
|
||||
* @return contact table values
|
||||
*/
|
||||
OHOS::NativeRdb::ValuesBucket Contacts::StructureContactDataValueBucket(OHOS::NativeRdb::ValuesBucket rawContactValues)
|
||||
{
|
||||
OHOS::NativeRdb::ValuesBucket contactValueBucket;
|
||||
if (rawContactValues.HasColumn(RawContactColumns::PHOTO_FILE_ID)) {
|
||||
int result = ContactValueBucketGetInt(rawContactValues, RawContactColumns::PHOTO_FILE_ID);
|
||||
contactValueBucket.PutInt(ContactColumns::PHOTO_FILE_ID, result);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::READ_ONLY)) {
|
||||
int result = ContactValueBucketGetInt(rawContactValues, RawContactColumns::READ_ONLY);
|
||||
contactValueBucket.PutInt(ContactColumns::READ_ONLY, result);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::PHOTO_ID)) {
|
||||
int result = ContactValueBucketGetInt(rawContactValues, RawContactColumns::PHOTO_ID);
|
||||
contactValueBucket.PutInt(ContactColumns::PHOTO_ID, result);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::IS_TRANSFER_VOICEMAIL)) {
|
||||
int result = ContactValueBucketGetInt(rawContactValues, RawContactColumns::IS_TRANSFER_VOICEMAIL);
|
||||
contactValueBucket.PutInt(ContactColumns::IS_TRANSFER_VOICEMAIL, result);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::COMPANY)) {
|
||||
std::string result = ContactValueBucketGetString(rawContactValues, RawContactColumns::COMPANY);
|
||||
contactValueBucket.PutString(ContactColumns::COMPANY, result);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::POSITION)) {
|
||||
std::string result = ContactValueBucketGetString(rawContactValues, RawContactColumns::POSITION);
|
||||
contactValueBucket.PutString(ContactColumns::POSITION, result);
|
||||
}
|
||||
return contactValueBucket;
|
||||
}
|
||||
|
||||
int Contacts::ContactValueBucketGetInt(OHOS::NativeRdb::ValuesBucket rawContactValues, std::string columnName)
|
||||
{
|
||||
int result = OHOS::NativeRdb::E_OK;
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
rawContactValues.GetObject(columnName, value);
|
||||
value.GetInt(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Contacts::ContactValueBucketGetString(
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues, std::string columnName)
|
||||
{
|
||||
std::string result;
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
rawContactValues.GetObject(columnName, value);
|
||||
value.GetString(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int Contacts::DeleteContactById(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int needDeleteContactId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store = rdbStore;
|
||||
if (store == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount DeletecontactById store is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (needDeleteContactId < ID_EMPTITY) {
|
||||
HILOG_ERROR("ContactsAccount DeleteDataByRawId needDeleteContactId illegal");
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
int rowId = OHOS::NativeRdb::E_OK;
|
||||
std::vector<std::string> whereArgs;
|
||||
whereArgs.push_back(std::to_string(needDeleteContactId));
|
||||
std::string whereCase;
|
||||
whereCase.append(ContactColumns::ID).append(" = ?");
|
||||
int delContact = store->Delete(rowId, ContactTableName::CONTACT, whereCase, whereArgs);
|
||||
return delContact;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* 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 "contacts_account.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
std::shared_ptr<ContactsAccount> ContactsAccount::instance_ = nullptr;
|
||||
|
||||
std::shared_ptr<ContactsAccount> ContactsAccount::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
instance_.reset(new ContactsAccount());
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
ContactsAccount::ContactsAccount(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsAccount::~ContactsAccount()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsAccount insert database
|
||||
*
|
||||
* @param rdbStore Insert operation based on radStore
|
||||
* @param accountName Pass in parameter accountName
|
||||
* @param accountType Pass in parameter accountType
|
||||
*
|
||||
* @return Insert database results code
|
||||
*/
|
||||
int64_t ContactsAccount::Insert(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string accountName, std::string accountType)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
OHOS::NativeRdb::ValuesBucket values;
|
||||
values.PutString(AccountColumns::ACCOUNT_NAME, accountName);
|
||||
values.PutString(AccountColumns::ACCOUNT_TYPE, accountType);
|
||||
int64_t outRowId = OHOS::NativeRdb::E_OK;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount insert store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->Insert(outRowId, ContactTableName::ACCOUNT, values);
|
||||
HILOG_INFO(" ContactsAccount insert ret :%{public}d", ret);
|
||||
return outRowId;
|
||||
};
|
||||
|
||||
void ContactsAccount::PrepopulateCommonAccountTypes(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore)
|
||||
{
|
||||
int typeResult = LookupAccountTypeId(rdbStore, AccountData::ACCOUNT_NAME, AccountData::ACCOUNT_TYPE);
|
||||
if (typeResult == RDB_EXECUTE_FAIL) {
|
||||
Insert(rdbStore, AccountData::ACCOUNT_NAME, AccountData::ACCOUNT_TYPE);
|
||||
} else {
|
||||
HILOG_INFO("ContactsAccount account is exist");
|
||||
}
|
||||
}
|
||||
|
||||
int ContactsAccount::LookupAccountTypeId(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string accountName, std::string accountType)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
std::string sqlBuilder = "SELECT * FROM ";
|
||||
sqlBuilder.append(ContactTableName::ACCOUNT)
|
||||
.append(" WHERE ")
|
||||
.append(AccountColumns::ACCOUNT_NAME)
|
||||
.append(" = ")
|
||||
.append("'")
|
||||
.append(accountName)
|
||||
.append("'")
|
||||
.append(" AND ")
|
||||
.append(AccountColumns::ACCOUNT_TYPE)
|
||||
.append(" = ")
|
||||
.append("'")
|
||||
.append(accountType)
|
||||
.append("'");
|
||||
std::vector<std::string> selectionArgs;
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store_->QuerySql(sqlBuilder, selectionArgs);
|
||||
int ret = resultSet->GoToFirstRow();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
resultSet->Close();
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
int columnIndex = 0;
|
||||
resultSet->GetColumnIndex(ContactPublicColumns::ID, columnIndex);
|
||||
int accountId = 0;
|
||||
resultSet->GetInt(columnIndex, accountId);
|
||||
resultSet->Close();
|
||||
return accountId;
|
||||
}
|
||||
|
||||
std::vector<AccountDataCollection> ContactsAccount::GetAccountFromLoacl(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
std::vector<AccountDataCollection> values;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount GetAccountFromLoacl store_ is nullptr");
|
||||
return values;
|
||||
}
|
||||
std::string buildQuery = "";
|
||||
buildQuery.append("select ")
|
||||
.append(AccountColumns::ACCOUNT_NAME)
|
||||
.append(",")
|
||||
.append(AccountColumns::ACCOUNT_TYPE)
|
||||
.append(",")
|
||||
.append(AccountColumns::DATA_INFO)
|
||||
.append(" from ")
|
||||
.append(ContactTableName::ACCOUNT);
|
||||
std::vector<std::string> selectArgs;
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> result = store_->QuerySql(buildQuery, selectArgs);
|
||||
int resultSetNum = result->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
std::string accountName;
|
||||
std::string accountType;
|
||||
std::string accountCollection;
|
||||
int accountNameIndex = 0;
|
||||
int accountTypeIndex = 0;
|
||||
int accountCollectionIndex = 0;
|
||||
result->GetColumnIndex(AccountColumns::ACCOUNT_NAME, accountNameIndex);
|
||||
result->GetColumnIndex(AccountColumns::ACCOUNT_TYPE, accountTypeIndex);
|
||||
result->GetColumnIndex(AccountColumns::DATA_INFO, accountCollectionIndex);
|
||||
result->GetString(accountNameIndex, accountName);
|
||||
result->GetString(accountTypeIndex, accountType);
|
||||
result->GetString(accountCollectionIndex, accountCollection);
|
||||
AccountDataCollection collection = AccountDataCollection(accountName, accountType, accountCollection);
|
||||
values.push_back(collection);
|
||||
resultSetNum = result->GoToNextRow();
|
||||
}
|
||||
result->Close();
|
||||
return values;
|
||||
}
|
||||
|
||||
int ContactsAccount::GetNotExistAccount(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, AccountDataCollection collection)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount GetNotExistAccount store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (collection.GetcAccountName() != "" || collection.GetcAccountType() != "") {
|
||||
std::vector<std::string> selectArgs;
|
||||
std::string buildSql = "";
|
||||
buildSql.append("select ")
|
||||
.append(AccountColumns::ID)
|
||||
.append(" from ")
|
||||
.append(ContactTableName::ACCOUNT)
|
||||
.append(" where ")
|
||||
.append(AccountColumns::ACCOUNT_NAME)
|
||||
.append(" = ? and ")
|
||||
.append(AccountColumns::ACCOUNT_TYPE)
|
||||
.append(" = ? and (")
|
||||
.append(AccountColumns::DATA_INFO)
|
||||
.append(" IS NULL or ")
|
||||
.append(AccountColumns::DATA_INFO)
|
||||
.append(" = ?)");
|
||||
selectArgs.push_back(collection.GetcAccountName());
|
||||
selectArgs.push_back(collection.GetcAccountType());
|
||||
selectArgs.push_back(collection.GetcDataCollection());
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> result = store_->QuerySql(buildSql, selectArgs);
|
||||
int resultSetNum = result->GoToFirstRow();
|
||||
int reValue = RDB_EXECUTE_FAIL;
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int reValueIndex = 0;
|
||||
result->GetColumnIndex(AccountColumns::ID, reValueIndex);
|
||||
if (reValueIndex < 0) {
|
||||
break;
|
||||
}
|
||||
result->GetInt(reValueIndex, reValue);
|
||||
resultSetNum = result->GoToNextRow();
|
||||
break;
|
||||
}
|
||||
result->Close();
|
||||
return reValue;
|
||||
}
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
|
||||
int ContactsAccount::DeleteAccountByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount DeleteAccountByAccountId store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (accountId < ID_EMPTITY) {
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
int rowId = 0;
|
||||
std::vector<std::string> whereArgs;
|
||||
whereArgs.push_back(std::to_string(accountId));
|
||||
std::string whereCase;
|
||||
whereCase.append(AccountColumns::ID).append(" = ?");
|
||||
int delAccount = store_->Delete(rowId, ContactTableName::ACCOUNT, whereCase, whereArgs);
|
||||
return delAccount;
|
||||
}
|
||||
|
||||
int ContactsAccount::DeleteDataByRawId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int needDeleteRawContactId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount DeleteDataByRawId store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (needDeleteRawContactId < ID_EMPTITY) {
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
int rowId = 0;
|
||||
std::vector<std::string> whereArgs;
|
||||
whereArgs.push_back(std::to_string(needDeleteRawContactId));
|
||||
std::string whereCase;
|
||||
whereCase.append(ContactDataColumns::RAW_CONTACT_ID).append(" = ?");
|
||||
int delData = store_->Delete(rowId, ContactTableName::CONTACT_DATA, whereCase, whereArgs);
|
||||
return delData;
|
||||
}
|
||||
|
||||
int ContactsAccount::DeleteGroupsByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount DeleteGroupsByAccountId store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (accountId < ID_EMPTITY) {
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
int rowId = 0;
|
||||
std::vector<std::string> whereArgs;
|
||||
whereArgs.push_back(std::to_string(accountId));
|
||||
std::string whereCase;
|
||||
whereCase.append(GroupsColumns::ACCOUNT_ID).append(" = ? ");
|
||||
int delGroup = store_->Delete(rowId, ContactTableName::GROUPS, whereCase, whereArgs);
|
||||
return delGroup;
|
||||
}
|
||||
|
||||
int ContactsAccount::StopForegin(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount StopForegin store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
return store_->ExecuteSql("PRAGMA foreign_keys = OFF");
|
||||
}
|
||||
|
||||
int ContactsAccount::OpenForegin(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsAccount OpenForegin store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
return store_->ExecuteSql("PRAGMA foreign_keys = ON");
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,608 @@
|
||||
/*
|
||||
* 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 "contacts_data_ability.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_common_event.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "database_disaster_recovery.h"
|
||||
#include "file_utils.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "profile_database.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "sql_analyzer.h"
|
||||
#include "uri_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
REGISTER_AA(ContactsDataAbility);
|
||||
namespace {
|
||||
std::mutex g_mutex;
|
||||
}
|
||||
std::shared_ptr<Contacts::ContactsDataBase> ContactsDataAbility::contactDataBase_ = nullptr;
|
||||
std::shared_ptr<Contacts::ProfileDatabase> ContactsDataAbility::profileDataBase_ = nullptr;
|
||||
std::map<std::string, int> ContactsDataAbility::uriValueMap_ = {
|
||||
{"/com.ohos.contactsdataability/contacts/contact", Contacts::CONTACTS_CONTACT},
|
||||
{"/com.ohos.contactsdataability/contacts/deleted_raw_contact", Contacts::CONTACTS_DELETE},
|
||||
{"/com.ohos.contactsdataability/contacts/deleted_raw_contact_record", Contacts::CONTACTS_DELETE_RECORD},
|
||||
{"/com.ohos.contactsdataability/contacts/raw_contact", Contacts::CONTACTS_RAW_CONTACT},
|
||||
{"/com.ohos.contactsdataability/contacts/account", Contacts::ACCOUNT},
|
||||
{"/com.ohos.contactsdataability/contacts/raw_contact/query_merge_list", Contacts::QUERY_MERGE_LIST},
|
||||
{"/com.ohos.contactsdataability/contacts/raw_contact/split_contact", Contacts::SPLIT_CONTACT},
|
||||
{"/com.ohos.contactsdataability/contacts/raw_contact/manual_merge", Contacts::MANUAL_MERGE},
|
||||
{"/com.ohos.contactsdataability/contacts/raw_contact/auto_merge", Contacts::AUTO_MERGE},
|
||||
{"/com.ohos.contactsdataability/contacts/contact_data", Contacts::CONTACTS_CONTACT_DATA},
|
||||
{"/com.ohos.contactsdataability/contacts/contact_type", Contacts::CONTACT_TYPE},
|
||||
{"/com.ohos.contactsdataability/contacts/groups", Contacts::CONTACTS_GROUPS},
|
||||
{"/com.ohos.contactsdataability/contacts/contact_blocklist", Contacts::CONTACTS_BLOCKLIST},
|
||||
{"/com.ohos.contactsdataability/contacts/photo_files", Contacts::CONTACTS_PHOTO_FILES},
|
||||
{"/com.ohos.contactsdataability/contacts/search_contact", Contacts::CONTACTS_SEARCH_CONTACT},
|
||||
{"/com.ohos.contactsdataability/contacts/backup", Contacts::CONTACT_BACKUP},
|
||||
{"/com.ohos.contactsdataability/profile/backup", Contacts::PROFILE_BACKUP},
|
||||
{"/com.ohos.contactsdataability/contacts/recover", Contacts::CONTACT_RECOVER},
|
||||
{"/com.ohos.contactsdataability/profile/recover", Contacts::PROFILE_RECOVER},
|
||||
{"/com.ohos.contactsdataability/profile/contact", Contacts::PROFILE_CONTACT},
|
||||
{"/com.ohos.contactsdataability/profile/raw_contact", Contacts::PROFILE_RAW_CONTACT},
|
||||
{"/com.ohos.contactsdataability/profile/contact_data", Contacts::PROFILE_CONTACT_DATA},
|
||||
{"/com.ohos.contactsdataability/profile/groups", Contacts::PROFILE_GROUPS},
|
||||
{"/com.ohos.contactsdataability/profile/contact_blocklist", Contacts::PROFILE_BLOCKLIST},
|
||||
{"/com.ohos.contactsdataability/profile/photo_files", Contacts::PROFILE_PHOTO_FILES},
|
||||
{"/com.ohos.contactsdataability/profile/search_contact", Contacts::PROFILE_SEARCH_CONTACT},
|
||||
{"/com.ohos.contactsdataability/profile/deleted_raw_contact_record", Contacts::PROFILE_DELETE_RECORD},
|
||||
{"/com.ohos.contactsdataability/profile/deleted_raw_contact", Contacts::PROFILE_DELETE},
|
||||
{"/com.ohos.contactsdataability/profile/contact_type", Contacts::PROFILE_TYPE}
|
||||
};
|
||||
|
||||
ContactsDataAbility::ContactsDataAbility(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsDataAbility::~ContactsDataAbility()
|
||||
{
|
||||
}
|
||||
|
||||
void ContactsDataAbility::OnStart(const Want &want)
|
||||
{
|
||||
Ability::OnStart(want);
|
||||
std::string basePath = GetDatabaseDir();
|
||||
Contacts::ContactsPath::RDB_PATH = basePath + "/";
|
||||
Contacts::ContactsPath::RDB_BACKUP_PATH = basePath + "/backup/";
|
||||
Contacts::ContactsPath::DUMP_PATH = GetFilesDir() + "/";
|
||||
}
|
||||
|
||||
void ContactsDataAbility::Dump(const std::string &extra)
|
||||
{
|
||||
Contacts::FileUtils fileUtils;
|
||||
std::string dirStr = Contacts::ContactsPath::DUMP_PATH;
|
||||
fileUtils.WriteStringToFileAppend(dirStr, extra);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataAbility BeginTransaction emptiness problems
|
||||
*
|
||||
* @param code the return number of BeginTransaction
|
||||
* @param mutex transmission parameter : lock
|
||||
*
|
||||
* @return BeginTransaction emptiness true or false
|
||||
*/
|
||||
bool ContactsDataAbility::IsBeginTransactionOK(int code, std::mutex &mutex)
|
||||
{
|
||||
mutex.try_lock();
|
||||
if (code != 0) {
|
||||
HILOG_ERROR("IsBeginTransactionOK fail");
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataAbility Commit emptiness problems
|
||||
*
|
||||
* @param code the return number of Commit
|
||||
* @param mutex transmission parameter : lock
|
||||
*
|
||||
* @return Commit emptiness true or false
|
||||
*/
|
||||
bool ContactsDataAbility::IsCommitOK(int code, std::mutex &mutex)
|
||||
{
|
||||
mutex.try_lock();
|
||||
if (code != 0) {
|
||||
HILOG_ERROR("IsCommitOK fail");
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataAbility insert database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param value Insert the data value of the database
|
||||
*
|
||||
* @return Insert database results code
|
||||
*/
|
||||
int ContactsDataAbility::Insert(const Uri &uri, const NativeRdb::ValuesBucket &value)
|
||||
{
|
||||
HILOG_INFO("Insert start");
|
||||
Contacts::SqlAnalyzer sqlAnalyzer;
|
||||
bool isOk = sqlAnalyzer.CheckValuesBucket(value);
|
||||
if (!isOk) {
|
||||
HILOG_ERROR("ContactsDataAbility CheckValuesBucket is error");
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
contactDataBase_ = Contacts::ContactsDataBase::GetInstance();
|
||||
profileDataBase_ = Contacts::ProfileDatabase::GetInstance();
|
||||
int resultId = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int code = UriParseAndSwitch(uriTemp);
|
||||
int ret = contactDataBase_->BeginTransaction();
|
||||
if (!IsBeginTransactionOK(ret, g_mutex)) {
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
resultId = InsertExecute(code, value);
|
||||
HILOG_INFO("Insert id = %{public}d", resultId);
|
||||
if (resultId == Contacts::OPERATION_ERROR) {
|
||||
contactDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::OPERATION_ERROR;
|
||||
}
|
||||
ret = contactDataBase_->Commit();
|
||||
if (!IsCommitOK(ret, g_mutex)) {
|
||||
contactDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_INSERT, uri);
|
||||
HILOG_INFO("Insert end");
|
||||
return resultId;
|
||||
}
|
||||
|
||||
int ContactsDataAbility::InsertExecute(int &code, const NativeRdb::ValuesBucket &value)
|
||||
{
|
||||
int rowId = Contacts::RDB_EXECUTE_FAIL;
|
||||
switch (code) {
|
||||
case Contacts::CONTACTS_RAW_CONTACT:
|
||||
case Contacts::PROFILE_RAW_CONTACT:
|
||||
// contact Basic Information
|
||||
rowId = contactDataBase_->InsertRawContact(Contacts::ContactTableName::RAW_CONTACT, value);
|
||||
break;
|
||||
case Contacts::CONTACTS_CONTACT_DATA:
|
||||
case Contacts::PROFILE_CONTACT_DATA:
|
||||
// contact Information add
|
||||
rowId = contactDataBase_->InsertContactData(Contacts::ContactTableName::CONTACT_DATA, value);
|
||||
break;
|
||||
case Contacts::CONTACTS_GROUPS:
|
||||
case Contacts::PROFILE_GROUPS:
|
||||
// insert group
|
||||
rowId = contactDataBase_->InsertGroup(Contacts::ContactTableName::GROUPS, value);
|
||||
break;
|
||||
case Contacts::CONTACTS_BLOCKLIST:
|
||||
case Contacts::PROFILE_BLOCKLIST:
|
||||
// add blocklist
|
||||
rowId = contactDataBase_->InsertBlockList(Contacts::ContactTableName::CONTACT_BLOCKLIST, value);
|
||||
break;
|
||||
default:
|
||||
rowId = Contacts::OPERATION_ERROR;
|
||||
HILOG_INFO("ContactsDataAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
return rowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataAbility BatchInsert database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param value Insert the data values of the database
|
||||
*
|
||||
* @return BatchInsert database results code
|
||||
*/
|
||||
int ContactsDataAbility::BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values)
|
||||
{
|
||||
int size = values.size();
|
||||
if (size <= 0) {
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
contactDataBase_ = Contacts::ContactsDataBase::GetInstance();
|
||||
profileDataBase_ = Contacts::ProfileDatabase::GetInstance();
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int code = UriParseAndSwitch(uriTemp);
|
||||
int ret = contactDataBase_->BeginTransaction();
|
||||
if (!IsBeginTransactionOK(ret, g_mutex)) {
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
++count;
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues = values[i];
|
||||
int rowRet = InsertExecute(code, rawContactValues);
|
||||
if (rowRet == Contacts::OPERATION_ERROR) {
|
||||
contactDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return rowRet;
|
||||
}
|
||||
if (count % Contacts::BATCH_INSERT_COUNT == 0) {
|
||||
int markRet = contactDataBase_->Commit();
|
||||
int beginRet = contactDataBase_->BeginTransaction();
|
||||
if (!IsCommitOK(markRet, g_mutex) || !IsBeginTransactionOK(beginRet, g_mutex)) {
|
||||
contactDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
int markRet = contactDataBase_->Commit();
|
||||
if (!IsCommitOK(markRet, g_mutex)) {
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
DataBaseNotifyChange(Contacts::CONTACT_INSERT, uri);
|
||||
g_mutex.unlock();
|
||||
return Contacts::OPERATION_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataAbility Update database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param predicates Update the data value of the condition
|
||||
*
|
||||
* @return Update database results code
|
||||
*/
|
||||
int ContactsDataAbility::Update(
|
||||
const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
Contacts::SqlAnalyzer sqlAnalyzer;
|
||||
bool isOk = sqlAnalyzer.CheckValuesBucket(value);
|
||||
if (!isOk) {
|
||||
HILOG_ERROR("ContactsDataAbility CheckValuesBucket is error");
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
contactDataBase_ = Contacts::ContactsDataBase::GetInstance();
|
||||
profileDataBase_ = Contacts::ProfileDatabase::GetInstance();
|
||||
int retCode = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int code = UriParseAndSwitch(uriTemp);
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
UpdateExecute(retCode, code, value, dataAbilityPredicates);
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_UPDATE, uri);
|
||||
return retCode;
|
||||
}
|
||||
|
||||
void ContactsDataAbility::UpdateExecute(int &retCode, int code, const NativeRdb::ValuesBucket &value,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates)
|
||||
{
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (code) {
|
||||
case Contacts::CONTACTS_CONTACT:
|
||||
case Contacts::PROFILE_CONTACT:
|
||||
break;
|
||||
case Contacts::CONTACTS_RAW_CONTACT:
|
||||
case Contacts::PROFILE_RAW_CONTACT:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::RAW_CONTACT, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->UpdateRawContact(value, rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_CONTACT_DATA:
|
||||
case Contacts::PROFILE_CONTACT_DATA:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::CONTACT_DATA, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->UpdateContactData(value, rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_GROUPS:
|
||||
case Contacts::PROFILE_GROUPS:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::GROUPS, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->UpdateGroup(value, rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_BLOCKLIST:
|
||||
case Contacts::PROFILE_BLOCKLIST:
|
||||
rdbPredicates = predicatesConvert.ConvertPredicates(
|
||||
Contacts::ContactTableName::CONTACT_BLOCKLIST, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->UpdateBlockList(value, rdbPredicates);
|
||||
break;
|
||||
default:
|
||||
SwitchUpdate(retCode, code, value, dataAbilityPredicates);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsDataAbility::SwitchUpdate(int &retCode, int &code, const NativeRdb::ValuesBucket &value,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates)
|
||||
{
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (code) {
|
||||
case Contacts::SPLIT_CONTACT:
|
||||
retCode = contactDataBase_->Split(dataAbilityPredicates);
|
||||
break;
|
||||
case Contacts::MANUAL_MERGE:
|
||||
retCode = contactDataBase_->ReContactMerge(dataAbilityPredicates);
|
||||
break;
|
||||
case Contacts::AUTO_MERGE:
|
||||
retCode = contactDataBase_->ContactMerge();
|
||||
break;
|
||||
case Contacts::CONTACT_BACKUP:
|
||||
case Contacts::PROFILE_BACKUP:
|
||||
retCode = BackUp();
|
||||
break;
|
||||
case Contacts::CONTACT_RECOVER:
|
||||
case Contacts::PROFILE_RECOVER:
|
||||
retCode = Recover(code);
|
||||
break;
|
||||
default:
|
||||
retCode = Contacts::RDB_EXECUTE_FAIL;
|
||||
HILOG_ERROR("ContactsDataAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataAbility Delete database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param predicates Delete the data values of the condition
|
||||
*
|
||||
* @return Delete database results code
|
||||
*/
|
||||
int ContactsDataAbility::Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
HILOG_INFO("ContactsDataAbility ====>Delete");
|
||||
g_mutex.lock();
|
||||
contactDataBase_ = Contacts::ContactsDataBase::GetInstance();
|
||||
profileDataBase_ = Contacts::ProfileDatabase::GetInstance();
|
||||
int retCode = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int code = UriParseAndSwitch(uriTemp);
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
DeleteExecute(retCode, code, dataAbilityPredicates);
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_DELETE, uri);
|
||||
return retCode;
|
||||
}
|
||||
|
||||
void ContactsDataAbility::DeleteExecute(
|
||||
int &retCode, int code, OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates)
|
||||
{
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (code) {
|
||||
case Contacts::CONTACTS_CONTACT:
|
||||
case Contacts::PROFILE_CONTACT:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::CONTACT, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->DeleteContact(rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_RAW_CONTACT:
|
||||
case Contacts::PROFILE_RAW_CONTACT:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::RAW_CONTACT, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->DeleteRawContact(rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_CONTACT_DATA:
|
||||
case Contacts::PROFILE_CONTACT_DATA:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::CONTACT_DATA, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->DeleteContactData(rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_GROUPS:
|
||||
case Contacts::PROFILE_GROUPS:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::GROUPS, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->DeleteGroup(rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_BLOCKLIST:
|
||||
case Contacts::PROFILE_BLOCKLIST:
|
||||
rdbPredicates = predicatesConvert.ConvertPredicates(
|
||||
Contacts::ContactTableName::CONTACT_BLOCKLIST, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->DeleteBlockList(rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_DELETE:
|
||||
case Contacts::PROFILE_DELETE:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ViewName::VIEW_DELETED, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->CompletelyDelete(rdbPredicates);
|
||||
break;
|
||||
case Contacts::CONTACTS_DELETE_RECORD:
|
||||
case Contacts::PROFILE_DELETE_RECORD:
|
||||
rdbPredicates = predicatesConvert.ConvertPredicates(
|
||||
Contacts::ContactTableName::DELETE_RAW_CONTACT, dataAbilityPredicates);
|
||||
retCode = contactDataBase_->DeleteRecord(rdbPredicates);
|
||||
break;
|
||||
default:
|
||||
retCode = Contacts::OPERATION_ERROR;
|
||||
HILOG_ERROR("ContactsDataAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataAbility query database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param columns Conditions for query operation
|
||||
* @param predicates Query the data values of the condition
|
||||
*
|
||||
* @return Query database results
|
||||
*/
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> ContactsDataAbility::Query(
|
||||
const Uri &uri, const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
HILOG_INFO("ContactsDataAbility ====>Query start");
|
||||
g_mutex.lock();
|
||||
contactDataBase_ = Contacts::ContactsDataBase::GetInstance();
|
||||
profileDataBase_ = Contacts::ProfileDatabase::GetInstance();
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> result;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int parseCode = UriParseAndSwitch(uriTemp);
|
||||
std::vector<std::string> columnsTemp = columns;
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
QueryExecute(result, dataAbilityPredicates, columnsTemp, parseCode);
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> sharedPtrResult = std::move(result);
|
||||
g_mutex.unlock();
|
||||
HILOG_INFO("ContactsDataAbility ====>Query end");
|
||||
return sharedPtrResult;
|
||||
}
|
||||
|
||||
void ContactsDataAbility::QueryExecute(std::shared_ptr<NativeRdb::AbsSharedResultSet> &result,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates, std::vector<std::string> &columnsTemp,
|
||||
int &parseCode)
|
||||
{
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (parseCode) {
|
||||
case Contacts::CONTACTS_CONTACT:
|
||||
case Contacts::PROFILE_CONTACT:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ViewName::VIEW_CONTACT, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::CONTACTS_RAW_CONTACT:
|
||||
case Contacts::PROFILE_RAW_CONTACT:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ViewName::VIEW_RAW_CONTACT, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::CONTACTS_CONTACT_DATA:
|
||||
case Contacts::PROFILE_CONTACT_DATA:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ViewName::VIEW_CONTACT_DATA, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::CONTACTS_GROUPS:
|
||||
case Contacts::PROFILE_GROUPS:
|
||||
rdbPredicates = predicatesConvert.ConvertPredicates(Contacts::ViewName::VIEW_GROUPS, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
default:
|
||||
QueryExecuteSwitchSplit(result, dataAbilityPredicates, columnsTemp, parseCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsDataAbility::QueryExecuteSwitchSplit(std::shared_ptr<NativeRdb::AbsSharedResultSet> &result,
|
||||
OHOS::NativeRdb::DataAbilityPredicates &dataAbilityPredicates, std::vector<std::string> &columnsTemp,
|
||||
int &parseCode)
|
||||
{
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (parseCode) {
|
||||
case Contacts::CONTACTS_BLOCKLIST:
|
||||
case Contacts::PROFILE_BLOCKLIST:
|
||||
rdbPredicates = predicatesConvert.ConvertPredicates(
|
||||
Contacts::ContactTableName::CONTACT_BLOCKLIST, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::CONTACTS_DELETE:
|
||||
case Contacts::PROFILE_DELETE:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ViewName::VIEW_DELETED, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::CONTACTS_SEARCH_CONTACT:
|
||||
case Contacts::PROFILE_SEARCH_CONTACT:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ViewName::SEARCH_CONTACT_VIEW, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::QUERY_MERGE_LIST:
|
||||
result = contactDataBase_->SelectCandidate();
|
||||
break;
|
||||
case Contacts::CONTACT_TYPE:
|
||||
case Contacts::PROFILE_TYPE:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::CONTACT_TYPE, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::ACCOUNT:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::ContactTableName::ACCOUNT, dataAbilityPredicates);
|
||||
result = contactDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("ContactsDataAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int ContactsDataAbility::UriParseAndSwitch(Uri &uri)
|
||||
{
|
||||
Contacts::UriUtils uriUtils;
|
||||
int parseCode = uriUtils.UriParse(uri, uriValueMap_);
|
||||
if (parseCode != Contacts::OPERATION_ERROR) {
|
||||
SwitchProfile(uri);
|
||||
}
|
||||
return parseCode;
|
||||
}
|
||||
|
||||
void ContactsDataAbility::SwitchProfile(Uri &uri)
|
||||
{
|
||||
std::vector<std::string> pathVector;
|
||||
uri.GetPathSegments(pathVector);
|
||||
if (pathVector.size() > 1 && pathVector[1].find("profile") == std::string::npos) {
|
||||
contactDataBase_ = Contacts::ContactsDataBase::GetInstance();
|
||||
contactDataBase_->store_ = contactDataBase_->contactStore_;
|
||||
} else {
|
||||
profileDataBase_ = Contacts::ProfileDatabase::GetInstance();
|
||||
contactDataBase_->store_ = profileDataBase_->store_;
|
||||
}
|
||||
}
|
||||
|
||||
int ContactsDataAbility::BackUp()
|
||||
{
|
||||
int retCode = Contacts::RDB_EXECUTE_FAIL;
|
||||
std::shared_ptr<OHOS::Contacts::DataBaseDisasterRecovery> instance =
|
||||
OHOS::Contacts::DataBaseDisasterRecovery::GetInstance();
|
||||
retCode = instance->SQLliteCheckDb();
|
||||
if (retCode == 0) {
|
||||
retCode = instance->BackDatabase();
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
int ContactsDataAbility::Recover(int &code)
|
||||
{
|
||||
std::string name = Contacts::PROFILE_DATABASE_NAME;
|
||||
if (code == Contacts::CONTACT_RECOVER) {
|
||||
name = Contacts::CONTACT_DATABASE_NAME;
|
||||
}
|
||||
std::shared_ptr<OHOS::Contacts::DataBaseDisasterRecovery> instance =
|
||||
OHOS::Contacts::DataBaseDisasterRecovery::GetInstance();
|
||||
int retCode = instance->RecoveryDatabase(name);
|
||||
contactDataBase_ = Contacts::ContactsDataBase::GetInstance();
|
||||
profileDataBase_ = Contacts::ProfileDatabase::GetInstance();
|
||||
return retCode;
|
||||
}
|
||||
|
||||
void ContactsDataAbility::DataBaseNotifyChange(int code, Uri uri)
|
||||
{
|
||||
Contacts::ContactsCommonEvent::SendContactChange(code);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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 "contacts_type.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_database.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
ContactsType::ContactsType(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsType::~ContactsType()
|
||||
{
|
||||
}
|
||||
|
||||
int64_t ContactsType::Insert(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string typeValue, int typeId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
OHOS::NativeRdb::ValuesBucket values;
|
||||
values.PutString(ContentTypeColumns::CONTENT_TYPE, typeValue);
|
||||
if (typeId != RDB_OBJECT_EMPTY) {
|
||||
values.PutInt(ContentTypeColumns::ID, typeId);
|
||||
}
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("ContactsType insert store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int64_t outRowId = RDB_EXECUTE_FAIL;
|
||||
int ret = store_->Insert(outRowId, ContactTableName::CONTACT_TYPE, values);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsType insert ret :%{public}d", ret);
|
||||
}
|
||||
return outRowId;
|
||||
}
|
||||
|
||||
void ContactsType::PrepopulateCommonTypes(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore)
|
||||
{
|
||||
std::vector<std::string> vectorType;
|
||||
vectorType.push_back(ContentTypeData::EMAIL);
|
||||
vectorType.push_back(ContentTypeData::IM);
|
||||
vectorType.push_back(ContentTypeData::NICKNAME);
|
||||
vectorType.push_back(ContentTypeData::ORGANIZATION);
|
||||
vectorType.push_back(ContentTypeData::PHONE);
|
||||
vectorType.push_back(ContentTypeData::NAME);
|
||||
vectorType.push_back(ContentTypeData::ADDRESS);
|
||||
vectorType.push_back(ContentTypeData::PHOTO);
|
||||
vectorType.push_back(ContentTypeData::GROUP_MEMBERSHIP);
|
||||
vectorType.push_back(ContentTypeData::NOTE);
|
||||
vectorType.push_back(ContentTypeData::CONTACT_EVENT);
|
||||
vectorType.push_back(ContentTypeData::WEBSITE);
|
||||
vectorType.push_back(ContentTypeData::RELATION);
|
||||
vectorType.push_back(ContentTypeData::CONTACT_MISC);
|
||||
vectorType.push_back(ContentTypeData::HICALL_DEVICE);
|
||||
vectorType.push_back(ContentTypeData::CAMCARD);
|
||||
vectorType.push_back(ContentTypeData::SIP_ADDRESS);
|
||||
int size = vectorType.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::string typeValue = vectorType[i];
|
||||
int error = LookupTypeId(rdbStore, typeValue);
|
||||
char *typeChar = nullptr;
|
||||
typeChar = (char *)typeValue.data();
|
||||
if (error == RDB_EXECUTE_FAIL) {
|
||||
int typeId = i + 1;
|
||||
Insert(rdbStore, typeValue, typeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ContactsType::LookupTypeId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, std::string typeValue)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
std::string sqlBuilder = "SELECT * FROM ";
|
||||
sqlBuilder.append(ContactTableName::CONTACT_TYPE)
|
||||
.append(" WHERE ")
|
||||
.append(ContentTypeColumns::CONTENT_TYPE)
|
||||
.append(" = ? ");
|
||||
std::vector<std::string> selectionArgs;
|
||||
selectionArgs.push_back(typeValue);
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store_->QuerySql(sqlBuilder, selectionArgs);
|
||||
int ret = resultSet->GoToFirstRow();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsType lookupTypeId ret :%{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
int columnIndex = RDB_EXECUTE_FAIL;
|
||||
resultSet->GetColumnIndex(ContactPublicColumns::ID, columnIndex);
|
||||
int typeId = RDB_EXECUTE_FAIL;
|
||||
resultSet->GetInt(columnIndex, typeId);
|
||||
resultSet->Close();
|
||||
return typeId;
|
||||
}
|
||||
|
||||
std::string ContactsType::GetTypeText(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int typeId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
std::string sqlBuilder = "SELECT * FROM ";
|
||||
sqlBuilder.append(ContactTableName::CONTACT_TYPE)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ?");
|
||||
std::vector<std::string> selectionArgs;
|
||||
selectionArgs.push_back(std::to_string(typeId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store_->QuerySql(sqlBuilder, selectionArgs);
|
||||
int ret = resultSet->GoToFirstRow();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
resultSet->Close();
|
||||
HILOG_ERROR("ContactsType lookupTypeText ret :%{public}d", ret);
|
||||
}
|
||||
std::string TypeText;
|
||||
int columnIndex = RDB_EXECUTE_FAIL;
|
||||
resultSet->GetColumnIndex(ContentTypeColumns::CONTENT_TYPE, columnIndex);
|
||||
resultSet->GetString(columnIndex, TypeText);
|
||||
resultSet->Close();
|
||||
return TypeText;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,422 @@
|
||||
/*
|
||||
* 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 "contacts_update_helper.h"
|
||||
|
||||
#include "calllog_database.h"
|
||||
#include "character_transliterate.h"
|
||||
#include "common.h"
|
||||
#include "construction_name.h"
|
||||
#include "contacts.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_database.h"
|
||||
#include "contacts_search.h"
|
||||
#include "contacts_type.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "raw_contacts.h"
|
||||
#include "voicemail_database.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
ContactsUpdateHelper::ContactsUpdateHelper(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsUpdateHelper::~ContactsUpdateHelper()
|
||||
{
|
||||
}
|
||||
|
||||
int ContactsUpdateHelper::UpdateDisplay(std::vector<int> rawContactIdVector, std::vector<std::string> types,
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, OHOS::NativeRdb::ValuesBucket contactDataDataValues,
|
||||
bool isDelete)
|
||||
{
|
||||
int ret = RDB_EXECUTE_OK;
|
||||
int count = rawContactIdVector.size();
|
||||
int countType = types.size();
|
||||
if (countType != count) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay Illegal rawContactId size type:%{public}d", count);
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay Illegal type size :%{public}d", countType);
|
||||
return ret;
|
||||
}
|
||||
ContactsSearch contactsSearch;
|
||||
RawContacts rawContacts;
|
||||
Contacts contactsContact;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int rawContactId = rawContactIdVector[i];
|
||||
std::string type = types[i];
|
||||
if (strcmp(type.c_str(), ContentTypeData::ORGANIZATION) == 0) {
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues =
|
||||
GetUpdateCompanyValuesBucket(contactDataDataValues, isDelete);
|
||||
if (rawContactValues.Size() <= 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = rawContacts.UpdateRawContactById(rawContactId, type, rdbStore, rawContactValues);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateRawContact fail type:%{public}s", type.c_str());
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateRawContact fail:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
OHOS::NativeRdb::ValuesBucket contactValues = GetUpdateCompanyValuesBucket(contactDataDataValues, isDelete);
|
||||
if (contactValues.Size() <= 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = contactsContact.UpdateContact(rawContactId, rdbStore, contactValues);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateContact fail type:%{public}s", type.c_str());
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateContact fail:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
} else if (strcmp(type.c_str(), ContentTypeData::NAME) == 0) {
|
||||
ret = UpdateName(contactDataDataValues, isDelete, rawContactId, type, rdbStore);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateRawContact fail type:%{public}s", type.c_str());
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateRawContact fail:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
ret = RDB_EXECUTE_OK;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ContactsUpdateHelper::UpdateName(OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete, int rawContactId,
|
||||
std::string type, std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore)
|
||||
{
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues = GetUpdateDisPlayNameValuesBucket(linkDataDataValues, isDelete);
|
||||
OHOS::NativeRdb::ValuesBucket searchContactValues = GetUpdateSearchNameValuesBucket(linkDataDataValues, isDelete);
|
||||
std::string disPlayName;
|
||||
OHOS::NativeRdb::ValueObject typeValue;
|
||||
rawContactValues.GetObject(RawContactColumns::DISPLAY_NAME, typeValue);
|
||||
typeValue.GetString(disPlayName);
|
||||
if (!disPlayName.empty()) {
|
||||
ConstructionName name;
|
||||
name.GetConstructionName(disPlayName, name);
|
||||
std::string searchName;
|
||||
searchName.append(disPlayName);
|
||||
if (!name.nameFullFight_.empty()) {
|
||||
searchName.append("||");
|
||||
searchName.append(name.nameFullFight_);
|
||||
}
|
||||
if (!name.initials_.empty()) {
|
||||
searchName.append("||");
|
||||
searchName.append(name.initials_);
|
||||
}
|
||||
if (!searchName.empty()) {
|
||||
searchContactValues.PutString(SearchContactColumns::SEARCH_NAME, searchName);
|
||||
}
|
||||
if (!name.photoFirstName_.empty()) {
|
||||
rawContactValues.PutString(RawContactColumns::PHOTO_FIRST_NAME, name.photoFirstName_);
|
||||
}
|
||||
if (!name.sortFirstLetter_.empty()) {
|
||||
// add sort and sort_first_letter
|
||||
rawContactValues.PutString(RawContactColumns::SORT_FIRST_LETTER, name.sortFirstLetter_);
|
||||
rawContactValues.PutString(RawContactColumns::SORT, std::to_string(name.sortFirstLetterCode_));
|
||||
}
|
||||
}
|
||||
int ret = RDB_EXECUTE_OK;
|
||||
if (rawContactValues.Size() > 0) {
|
||||
RawContacts rawContacts;
|
||||
rawContacts.UpdateRawContactById(rawContactId, type, rdbStore, rawContactValues);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateRawContact fail type:%{public}s", type.c_str());
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateRawContact fail:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (searchContactValues.Size() > 0) {
|
||||
// update SearchContact name
|
||||
ContactsSearch contactsSearch;
|
||||
ret = contactsSearch.UpdateSearchContact(rawContactId, type, rdbStore, searchContactValues);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateSearchContact fail type:%{public}s", type.c_str());
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateSearchContact fail:%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsUpdateHelper update table calllog by phoneNumber
|
||||
*
|
||||
* @param rawContactIdVector Contacts ID collection to update
|
||||
* @param rdbStore Conditions to update calllog
|
||||
* @param isDelete Contacts field value to update
|
||||
*
|
||||
* @return Update calllog results code
|
||||
*/
|
||||
void ContactsUpdateHelper::UpdateCallLogByPhoneNum(
|
||||
std::vector<int> &rawContactIdVector, std::shared_ptr<OHOS::NativeRdb::RdbStore> &rdbStore, bool isDelete)
|
||||
{
|
||||
std::shared_ptr<ContactsDataBase> contactDataBase_ = ContactsDataBase::GetInstance();
|
||||
if (rdbStore != contactDataBase_->contactStore_) {
|
||||
HILOG_ERROR("UpdateCallLogByPhoneNum rdbStore is profile, not need update");
|
||||
return;
|
||||
}
|
||||
int count = rawContactIdVector.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
std::string queryContactIdSql;
|
||||
queryContactIdSql.append(" SELECT ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ViewName::VIEW_RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(ContactPublicColumns::ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(rawContactIdVector[i]));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> rawContactResultSet =
|
||||
rdbStore->QuerySql(queryContactIdSql);
|
||||
int rawContactResultSetNum = rawContactResultSet->GoToFirstRow();
|
||||
int contactId = 0;
|
||||
while (rawContactResultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
std::string columnName = RawContactColumns::CONTACT_ID;
|
||||
int columnIndex = 0;
|
||||
rawContactResultSet->GetColumnIndex(columnName, columnIndex);
|
||||
rawContactResultSet->GetInt(columnIndex, contactId);
|
||||
rawContactResultSetNum = rawContactResultSet->GoToNextRow();
|
||||
break;
|
||||
}
|
||||
rawContactResultSet->Close();
|
||||
if (contactId <= 0) {
|
||||
return;
|
||||
}
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = QueryDataForCallLog(rdbStore, contactId);
|
||||
DataToUpdateCallLog(isDelete, contactId, resultSet);
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsUpdateHelper::DataToUpdateCallLog(
|
||||
bool isDelete, int contactId, std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> &resultSet)
|
||||
{
|
||||
int rowCount = 0;
|
||||
resultSet->GetRowCount(rowCount);
|
||||
int resultSetNum = resultSet->GoToFirstRow();
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
std::string phoneNumber;
|
||||
std::string name;
|
||||
std::string quickSearch;
|
||||
// not delete contact
|
||||
if (!isDelete) {
|
||||
resultSet->GetString(0, name);
|
||||
}
|
||||
resultSet->GetString(RESEULT_GET_ONE, phoneNumber);
|
||||
resultSet->GetString(RESEULT_GET_TWO, quickSearch);
|
||||
UpdateCallLog(phoneNumber, name, quickSearch, isDelete, true);
|
||||
UpdateCallLog(phoneNumber, name, quickSearch, isDelete, false);
|
||||
resultSetNum = resultSet->GoToNextRow();
|
||||
}
|
||||
resultSet->Close();
|
||||
if (rowCount == 0) {
|
||||
// not find contact data update callLog
|
||||
std::string quickSearch = std::to_string(contactId);
|
||||
std::string name;
|
||||
UpdateCallLogNameNull(name, quickSearch, true);
|
||||
UpdateCallLogNameNull(name, quickSearch, false);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> ContactsUpdateHelper::QueryDataForCallLog(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &rdbStore, int contactId)
|
||||
{
|
||||
ContactsType contactsType;
|
||||
int typeNameId = contactsType.LookupTypeId(rdbStore, ContentTypeData::PHONE);
|
||||
std::string sql;
|
||||
sql.append("SELECT ")
|
||||
.append(RawContactColumns::DISPLAY_NAME)
|
||||
.append(",")
|
||||
.append(ContactDataColumns::DETAIL_INFO)
|
||||
.append(",")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(" = (SELECT min(")
|
||||
.append(ContactDataColumns::RAW_CONTACT_ID)
|
||||
.append(") FROM ")
|
||||
.append(ViewName::VIEW_CONTACT_DATA)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(contactId))
|
||||
.append(" AND ")
|
||||
.append(ContentTypeColumns::CONTENT_TYPE)
|
||||
.append(" = '")
|
||||
.append(ContentTypeData::PHONE)
|
||||
.append("') AND ")
|
||||
.append(ContactDataColumns::TYPE_ID)
|
||||
.append(" = ")
|
||||
.append(std::to_string(typeNameId));
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = rdbStore->QuerySql(sql);
|
||||
if (resultSet == nullptr) {
|
||||
HILOG_ERROR("ContactsUpdateHelper QueryDataForCallLog resultSet is nullptr ");
|
||||
}
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
int ContactsUpdateHelper::UpdateCallLogNameNull(std::string &name, std::string &quickSearch, bool isCallLog)
|
||||
{
|
||||
std::shared_ptr<CallLogDataBase> callLogDataBase = CallLogDataBase::GetInstance();
|
||||
OHOS::NativeRdb::ValuesBucket updateCallLogValues;
|
||||
updateCallLogValues.PutNull(CallLogColumns::DISPLAY_NAME);
|
||||
updateCallLogValues.PutNull(CallLogColumns::QUICK_SEARCH_KEY);
|
||||
std::string tabName = CallsTableName::VOICEMAIL;
|
||||
if (isCallLog) {
|
||||
tabName = CallsTableName::CALLLOG;
|
||||
}
|
||||
auto predicates = OHOS::NativeRdb::RdbPredicates(tabName);
|
||||
std::string updateWheres;
|
||||
updateWheres.append(CallLogColumns::QUICK_SEARCH_KEY).append(" = ? ");
|
||||
std::vector<std::string> updateArgs;
|
||||
updateArgs.push_back(quickSearch);
|
||||
predicates.SetWhereClause(updateWheres);
|
||||
predicates.SetWhereArgs(updateArgs);
|
||||
int ret = RDB_EXECUTE_FAIL;
|
||||
if (isCallLog) {
|
||||
ret = callLogDataBase->UpdateCallLog(updateCallLogValues, predicates);
|
||||
} else {
|
||||
ret = VoiceMailDataBase::GetInstance()->UpdateVoiceMail(updateCallLogValues, predicates);
|
||||
}
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("UpdateCallLogPhone name error from phone is %{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsUpdateHelper update table calllog
|
||||
*
|
||||
* @param phoneNumber Contacts's phone number
|
||||
* @param name CallLog name to update
|
||||
* @param quickSearch Contacts's quick search key
|
||||
* @param isDelete Contacts field value to update
|
||||
* @param isCallLog Contacts field value to update
|
||||
*
|
||||
* @return Update calllog results code
|
||||
*/
|
||||
int ContactsUpdateHelper::UpdateCallLog(
|
||||
std::string &phoneNumber, std::string &name, std::string &quickSearch, bool isDelete, bool isCallLog)
|
||||
{
|
||||
if (phoneNumber.empty()) {
|
||||
return RDB_EXECUTE_OK;
|
||||
}
|
||||
std::shared_ptr<CallLogDataBase> callLogDataBase = CallLogDataBase::GetInstance();
|
||||
OHOS::NativeRdb::ValuesBucket updateCallLogValues;
|
||||
if (isDelete) {
|
||||
updateCallLogValues.PutNull(CallLogColumns::DISPLAY_NAME);
|
||||
updateCallLogValues.PutNull(CallLogColumns::QUICK_SEARCH_KEY);
|
||||
} else {
|
||||
updateCallLogValues.PutString(CallLogColumns::DISPLAY_NAME, name);
|
||||
updateCallLogValues.PutString(CallLogColumns::QUICK_SEARCH_KEY, quickSearch);
|
||||
}
|
||||
updateCallLogValues.PutString(CallLogColumns::PHONE_NUMBER, phoneNumber);
|
||||
std::string tabName = CallsTableName::VOICEMAIL;
|
||||
if (isCallLog) {
|
||||
tabName = CallsTableName::CALLLOG;
|
||||
}
|
||||
auto predicates = OHOS::NativeRdb::RdbPredicates(tabName);
|
||||
std::string updateWheres;
|
||||
updateWheres.append(CallLogColumns::PHONE_NUMBER).append(" = ? ");
|
||||
std::vector<std::string> updateArgs;
|
||||
updateArgs.push_back(phoneNumber);
|
||||
predicates.SetWhereClause(updateWheres);
|
||||
predicates.SetWhereArgs(updateArgs);
|
||||
int ret = RDB_EXECUTE_FAIL;
|
||||
if (isCallLog) {
|
||||
ret = callLogDataBase->UpdateCallLog(updateCallLogValues, predicates);
|
||||
} else {
|
||||
ret = VoiceMailDataBase::GetInstance()->UpdateVoiceMail(updateCallLogValues, predicates);
|
||||
}
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("UpdateCallLogPhone name error from phone is %{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
OHOS::NativeRdb::ValuesBucket ContactsUpdateHelper::GetUpdateDisPlayNameValuesBucket(
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete)
|
||||
{
|
||||
OHOS::NativeRdb::ValuesBucket valuesBucket;
|
||||
if (isDelete) {
|
||||
valuesBucket.PutNull(RawContactColumns::DISPLAY_NAME);
|
||||
valuesBucket.PutNull(RawContactColumns::SORT_FIRST_LETTER);
|
||||
valuesBucket.PutNull(RawContactColumns::SORT);
|
||||
return valuesBucket;
|
||||
}
|
||||
std::string displayName;
|
||||
if (linkDataDataValues.HasColumn(ContactDataColumns::DETAIL_INFO)) {
|
||||
OHOS::NativeRdb::ValueObject typeValue;
|
||||
linkDataDataValues.GetObject(ContactDataColumns::DETAIL_INFO, typeValue);
|
||||
typeValue.GetString(displayName);
|
||||
}
|
||||
valuesBucket.PutString(RawContactColumns::DISPLAY_NAME, displayName);
|
||||
std::string phoneticName;
|
||||
if (linkDataDataValues.HasColumn(RawContactColumns::PHONETIC_NAME)) {
|
||||
OHOS::NativeRdb::ValueObject typeValue;
|
||||
linkDataDataValues.GetObject(ContactDataColumns::PHONETIC_NAME, typeValue);
|
||||
typeValue.GetString(phoneticName);
|
||||
}
|
||||
valuesBucket.PutString(RawContactColumns::PHONETIC_NAME, phoneticName);
|
||||
return valuesBucket;
|
||||
}
|
||||
|
||||
OHOS::NativeRdb::ValuesBucket ContactsUpdateHelper::GetUpdateSearchNameValuesBucket(
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete)
|
||||
{
|
||||
OHOS::NativeRdb::ValuesBucket valuesBucket;
|
||||
if (isDelete) {
|
||||
valuesBucket.PutNull(SearchContactColumns::SEARCH_NAME);
|
||||
return valuesBucket;
|
||||
}
|
||||
std::string displayName;
|
||||
if (linkDataDataValues.HasColumn(ContactDataColumns::DETAIL_INFO)) {
|
||||
OHOS::NativeRdb::ValueObject typeValue;
|
||||
linkDataDataValues.GetObject(ContactDataColumns::DETAIL_INFO, typeValue);
|
||||
typeValue.GetString(displayName);
|
||||
}
|
||||
valuesBucket.PutString(RawContactColumns::DISPLAY_NAME, displayName);
|
||||
return valuesBucket;
|
||||
}
|
||||
|
||||
OHOS::NativeRdb::ValuesBucket ContactsUpdateHelper::GetUpdateCompanyValuesBucket(
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues, bool isDelete)
|
||||
{
|
||||
OHOS::NativeRdb::ValuesBucket valuesBucket;
|
||||
if (isDelete) {
|
||||
valuesBucket.PutNull(RawContactColumns::COMPANY);
|
||||
valuesBucket.PutNull(RawContactColumns::POSITION);
|
||||
return valuesBucket;
|
||||
}
|
||||
if (linkDataDataValues.HasColumn(ContactDataColumns::DETAIL_INFO)) {
|
||||
std::string commpany;
|
||||
OHOS::NativeRdb::ValueObject typeValue;
|
||||
linkDataDataValues.GetObject(ContactDataColumns::DETAIL_INFO, typeValue);
|
||||
typeValue.GetString(commpany);
|
||||
valuesBucket.PutString(RawContactColumns::COMPANY, commpany);
|
||||
}
|
||||
if (linkDataDataValues.HasColumn(ContactDataColumns::POSITION)) {
|
||||
std::string position;
|
||||
OHOS::NativeRdb::ValueObject typeValue;
|
||||
linkDataDataValues.GetObject(ContactDataColumns::POSITION, typeValue);
|
||||
typeValue.GetString(position);
|
||||
valuesBucket.PutString(RawContactColumns::POSITION, position);
|
||||
}
|
||||
return valuesBucket;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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 "profile_database.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_account.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_type.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
std::shared_ptr<ProfileDatabase> ProfileDatabase::profileDatabase_ = nullptr;
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> ProfileDatabase::store_ = nullptr;
|
||||
static std::string g_databaseName;
|
||||
namespace {
|
||||
std::mutex g_mtx;
|
||||
} // namespace
|
||||
|
||||
ProfileDatabase::ProfileDatabase()
|
||||
{
|
||||
int errCode = OHOS::NativeRdb::E_OK;
|
||||
g_databaseName = ContactsPath::RDB_PATH + "profile.db";
|
||||
OHOS::NativeRdb::RdbStoreConfig config(g_databaseName);
|
||||
HILOG_INFO("ProfileDatabase g_databaseName :%{public}s", g_databaseName.c_str());
|
||||
SqliteOpenHelperProfileCallback sqliteOpenHelperCallback;
|
||||
store_ = OHOS::NativeRdb::RdbHelper::GetRdbStore(config, DATABASE_OPEN_VERSION, sqliteOpenHelperCallback, errCode);
|
||||
if (errCode != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ProfileDatabase errCode :%{public}d", errCode);
|
||||
} else {
|
||||
HILOG_INFO("ProfileDatabase errCode :%{public}d", errCode);
|
||||
}
|
||||
if (errCode != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ProfileDatabase rebase open error :%{public}d", errCode);
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<ContactsAccount> contactsAccount = ContactsAccount::GetInstance();
|
||||
contactsAccount->PrepopulateCommonAccountTypes(store_);
|
||||
ContactsType contactsType;
|
||||
contactsType.PrepopulateCommonTypes(store_);
|
||||
}
|
||||
|
||||
std::shared_ptr<ProfileDatabase> ProfileDatabase::GetInstance()
|
||||
{
|
||||
if (profileDatabase_ == nullptr) {
|
||||
g_mtx.lock();
|
||||
profileDatabase_.reset(new ProfileDatabase());
|
||||
g_mtx.unlock();
|
||||
}
|
||||
return profileDatabase_;
|
||||
}
|
||||
|
||||
void ProfileDatabase::DestroyInstanceAndRestore(std::string restorePath)
|
||||
{
|
||||
g_mtx.lock();
|
||||
if (access(restorePath.c_str(), F_OK) != 0) {
|
||||
HILOG_ERROR("Restore file %{public}s does not exist", restorePath.c_str());
|
||||
g_mtx.unlock();
|
||||
return;
|
||||
}
|
||||
OHOS::NativeRdb::RdbHelper::DeleteRdbStore(g_databaseName);
|
||||
OHOS::NativeRdb::RdbHelper::ClearCache();
|
||||
profileDatabase_ = nullptr;
|
||||
Restore(restorePath);
|
||||
g_mtx.unlock();
|
||||
}
|
||||
|
||||
bool ProfileDatabase::Restore(std::string restorePath)
|
||||
{
|
||||
if (rename(restorePath.c_str(), g_databaseName.c_str())) {
|
||||
HILOG_ERROR("Restore rename oldFileName = %{public}s to newFileName %{public}s", restorePath.c_str(),
|
||||
g_databaseName.c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int SqliteOpenHelperProfileCallback::OnCreate(OHOS::NativeRdb::RdbStore &store)
|
||||
{
|
||||
store.ExecuteSql(CREATE_CONTACT);
|
||||
store.ExecuteSql(CREATE_CONTACT_INDEX);
|
||||
store.ExecuteSql(CREATE_RAW_CONTACT);
|
||||
store.ExecuteSql(CREATE_RAW_CONTACT_INDEX);
|
||||
store.ExecuteSql(CREATE_CONTACT_DATA);
|
||||
store.ExecuteSql(CREATE_CONTACT_INDEX_DATA1);
|
||||
store.ExecuteSql(CREATE_CONTACT_INDEX_DATA2);
|
||||
store.ExecuteSql(CREATE_CONTACT_BLOCKLIST);
|
||||
store.ExecuteSql(CREATE_LOCAL_LANG);
|
||||
store.ExecuteSql(CREATE_ACCOUNT);
|
||||
store.ExecuteSql(CREATE_PHOTO_FILES);
|
||||
store.ExecuteSql(CREATE_CONTACT_TYPE);
|
||||
store.ExecuteSql(CREATE_GROUPS);
|
||||
store.ExecuteSql(CREATE_DELETED_RAW_CONTACT);
|
||||
store.ExecuteSql(CREATE_SEARCH_CONTACT);
|
||||
store.ExecuteSql(CREATE_SEARCH_CONTACT_INDEX1);
|
||||
store.ExecuteSql(CREATE_SEARCH_CONTACT_INDEX2);
|
||||
store.ExecuteSql(CREATE_SEARCH_CONTACT_VIEW);
|
||||
store.ExecuteSql(MERGE_INFO);
|
||||
store.ExecuteSql(CREATE_VIEW_CONTACT_DATA);
|
||||
store.ExecuteSql(CREATE_VIEW_RAW_CONTACT);
|
||||
store.ExecuteSql(CREATE_VIEW_CONTACT);
|
||||
store.ExecuteSql(CREATE_VIEW_GROUPS);
|
||||
store.ExecuteSql(CREATE_VIEW_DELETED);
|
||||
store.ExecuteSql(INSERT_DELETE_RAW_CONTACT);
|
||||
store.ExecuteSql(UPDATE_RAW_CONTACT_VERSION);
|
||||
store.ExecuteSql(UPDATE_CONTACT_DATA_VERSION);
|
||||
store.ExecuteSql(INSERT_CONTACT_QUICK_SEARCH);
|
||||
store.ExecuteSql(CREATE_DATABASE_BACKUP_TASK);
|
||||
store.ExecuteSql(CREATE_INSERT_BACKUP_TIME);
|
||||
store.ExecuteSql(UPDATE_CONTACT_BY_INSERT_CONTACT_DATA);
|
||||
store.ExecuteSql(UPDATE_CONTACT_BY_DELETE_CONTACT_DATA);
|
||||
store.ExecuteSql(UPDATE_CONTACT_BY_UPDATE_CONTACT_DATA);
|
||||
store.ExecuteSql(MERGE_INFO_INDEX);
|
||||
return OHOS::NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
int SqliteOpenHelperProfileCallback::OnUpgrade(OHOS::NativeRdb::RdbStore &store, int oldVersion, int newVersion)
|
||||
{
|
||||
HILOG_INFO("OnUpgrade oldVersion is %{public}d , newVersion is %{public}d", oldVersion, newVersion);
|
||||
if (oldVersion < newVersion && newVersion == DATABASE_NEW_VERSION) {
|
||||
store.ExecuteSql("ALTER TABLE database_backup_task ADD COLUMN sync TEXT");
|
||||
}
|
||||
store.SetVersion(newVersion);
|
||||
return OHOS::NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
int SqliteOpenHelperProfileCallback::OnDowngrade(OHOS::NativeRdb::RdbStore &store, int oldVersion, int newVersion)
|
||||
{
|
||||
HILOG_INFO("OnDowngrade oldVersion is %{public}d , newVersion is %{public}d", oldVersion, newVersion);
|
||||
if (oldVersion > newVersion && newVersion == DATABASE_OPEN_VERSION) {
|
||||
store.ExecuteSql(
|
||||
"CREATE TABLE IF NOT EXISTS database_backup (id INTEGER PRIMARY KEY AUTOINCREMENT, backup_time "
|
||||
"TEXT, backup_path TEXT, remarks TEXT)");
|
||||
store.ExecuteSql(
|
||||
"INSERT INTO database_backup(id, backup_time, backup_path, remarks) SELECT id, "
|
||||
"backup_time, backup_path, remarks FROM database_backup_task");
|
||||
store.ExecuteSql("DROP table database_backup_task");
|
||||
store.ExecuteSql("ALTER table database_backup RENAME TO database_backup_task");
|
||||
store.ExecuteSql(CREATE_INSERT_BACKUP_TIME);
|
||||
}
|
||||
int ret = store.SetVersion(newVersion);
|
||||
return ret;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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 "raw_contacts.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
RawContacts::RawContacts(void)
|
||||
{
|
||||
}
|
||||
|
||||
RawContacts::~RawContacts()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RawContacts insert table raw_contact
|
||||
*
|
||||
* @param rdbStore Insert operation based on radStore
|
||||
* @param rawContactValues Pass in parameter rawContactValues
|
||||
*
|
||||
* @return Insert database results code
|
||||
*/
|
||||
int RawContacts::InsertRawContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int64_t &outRawContactId,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues)
|
||||
{
|
||||
int rowRet = rdbStore->Insert(outRawContactId, ContactTableName::RAW_CONTACT, rawContactValues);
|
||||
if (rowRet != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("RawContacts InsertRawContact fail:%{public}d", rowRet);
|
||||
}
|
||||
return rowRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RawContacts update table raw_contact
|
||||
*
|
||||
* @param rdbStore Update operation based on radStore
|
||||
* @param upRawContactValues Pass in parameter upRawContactValues
|
||||
* @param whereClause Conditions for update operation
|
||||
* @param whereArgs Conditions for update operation
|
||||
*
|
||||
* @return Insert database results code
|
||||
*/
|
||||
int RawContacts::UpdateRawContact(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore,
|
||||
OHOS::NativeRdb::ValuesBucket upRawContactValues, std::string whereClause, std::vector<std::string> whereArgs)
|
||||
{
|
||||
int changedRows = OHOS::NativeRdb::E_OK;
|
||||
int ret = rdbStore->Update(changedRows, ContactTableName::RAW_CONTACT, upRawContactValues, whereClause, whereArgs);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("RawContacts UpdateRawContact fail:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RawContacts::UpdateRawContactById(int &rawContactId, std::string type,
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, OHOS::NativeRdb::ValuesBucket rawContactValues)
|
||||
{
|
||||
std::string upWhereClause;
|
||||
upWhereClause.append(ContactPublicColumns::ID).append(" = ?");
|
||||
std::vector<std::string> upWhereArgs;
|
||||
upWhereArgs.push_back(std::to_string(rawContactId));
|
||||
int changedRows = OHOS::NativeRdb::E_OK;
|
||||
int ret =
|
||||
rdbStore->Update(changedRows, ContactTableName::RAW_CONTACT, rawContactValues, upWhereClause, upWhereArgs);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("RawContacts UpdateRawContactById fail:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RawContacts::GetDeleteContactIdByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("RawContacts GetDeleteContactIdByAccountId store_ is nullptr or accountId illegal");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (accountId < ID_EMPTITY) {
|
||||
HILOG_ERROR("RawContacts GetDeleteContactIdByAccountId accountId illegal");
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
std::vector<std::string> selectArgs;
|
||||
selectArgs.push_back(std::to_string(accountId));
|
||||
selectArgs.push_back(std::to_string(accountId));
|
||||
std::string sql = "";
|
||||
sql.append("SELECT ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::ACCOUNT_ID)
|
||||
.append(" = ? AND ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" NOT NULL AND ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" NOT IN (")
|
||||
.append(" SELECT ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::ACCOUNT_ID)
|
||||
.append(" != ?")
|
||||
.append(" AND ")
|
||||
.append(RawContactColumns::CONTACT_ID)
|
||||
.append(" NOT NULL )");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> rawResult = store_->QuerySql(sql, selectArgs);
|
||||
int resultSetNum = rawResult->GoToFirstRow();
|
||||
int currConcactIdValue = 0;
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
int currValueIndex = 0;
|
||||
rawResult->GetColumnIndex(RawContactColumns::CONTACT_ID, currValueIndex);
|
||||
rawResult->GetInt(currValueIndex, currConcactIdValue);
|
||||
if (currConcactIdValue > 0) {
|
||||
break;
|
||||
}
|
||||
resultSetNum = rawResult->GoToNextRow();
|
||||
}
|
||||
rawResult->Close();
|
||||
return currConcactIdValue;
|
||||
}
|
||||
|
||||
int RawContacts::GetDeleteRawContactIdByAccountId(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int accountId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("RawContacts GetDeleteRawContactIdByAccountId store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (accountId < ID_EMPTITY) {
|
||||
HILOG_ERROR("RawContacts GetDeleteContactIdByAccountId accountId illegal");
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
std::vector<std::string> selectArgs;
|
||||
selectArgs.push_back(std::to_string(accountId));
|
||||
std::string sql = "";
|
||||
sql.append("SELECT ")
|
||||
.append(RawContactColumns::ID)
|
||||
.append(" FROM ")
|
||||
.append(ContactTableName::RAW_CONTACT)
|
||||
.append(" WHERE ")
|
||||
.append(RawContactColumns::ACCOUNT_ID)
|
||||
.append(" = ?")
|
||||
.append(" AND ")
|
||||
.append(RawContactColumns::ACCOUNT_ID)
|
||||
.append(" NOT NULL");
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> rawResult = store_->QuerySql(sql, selectArgs);
|
||||
int resultSetNum = rawResult->GoToFirstRow();
|
||||
int currConcactIdValue = 0;
|
||||
while (resultSetNum == OHOS::NativeRdb::E_OK) {
|
||||
rawResult->GetInt(0, currConcactIdValue);
|
||||
if (currConcactIdValue > 0) {
|
||||
break;
|
||||
}
|
||||
resultSetNum = rawResult->GoToNextRow();
|
||||
}
|
||||
rawResult->Close();
|
||||
return currConcactIdValue;
|
||||
}
|
||||
|
||||
int RawContacts::DeleteRawcontactByRawId(
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int needDeleteRawContactId)
|
||||
{
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> &store_ = rdbStore;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("RawContacts DeleteRawcontactByRawId store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (needDeleteRawContactId < ID_EMPTITY) {
|
||||
HILOG_ERROR("RawContacts DeleteRawcontactByRawId needDeleteRawContactId illegal");
|
||||
return OPERATION_ERROR;
|
||||
}
|
||||
int rowId = OHOS::NativeRdb::E_OK;
|
||||
std::vector<std::string> whereArgs;
|
||||
whereArgs.push_back(std::to_string(needDeleteRawContactId));
|
||||
std::string whereCase;
|
||||
whereCase.append(RawContactColumns::ID).append(" = ?");
|
||||
int delRawContact = store_->Delete(rowId, ContactTableName::RAW_CONTACT, whereCase, whereArgs);
|
||||
HILOG_INFO("DeleteRawcontactByRawId : status is %{public}d", delRawContact);
|
||||
return delRawContact;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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 CONTACT_SEARCH_H
|
||||
#define CONTACT_SEARCH_H
|
||||
|
||||
#include "rdb_store.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class ContactsSearch {
|
||||
public:
|
||||
ContactsSearch();
|
||||
~ContactsSearch();
|
||||
int64_t Insert(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int64_t contactId, int64_t rawContactId,
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues, int64_t &searchContactId);
|
||||
// Convert the rawcontact table insert parameter to the searchcontact table parameter
|
||||
OHOS::NativeRdb::ValuesBucket StructureSearchContactDataValueBucket(
|
||||
OHOS::NativeRdb::ValuesBucket searchContactValues);
|
||||
int UpdateSearchContact(int rawContactId, std::string type, std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore,
|
||||
OHOS::NativeRdb::ValuesBucket linkDataDataValues);
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // CONTACT_SEARCH_H
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 "contacts_search.h"
|
||||
|
||||
#include "rdb_errno.h"
|
||||
#include "result_set.h"
|
||||
|
||||
#include "character_transliterate.h"
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
ContactsSearch::ContactsSearch(void)
|
||||
{
|
||||
}
|
||||
|
||||
ContactsSearch::~ContactsSearch()
|
||||
{
|
||||
}
|
||||
|
||||
int64_t ContactsSearch::Insert(std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, int64_t contactId,
|
||||
int64_t rawContactId, OHOS::NativeRdb::ValuesBucket rawContactValues, int64_t &searchContactId)
|
||||
{
|
||||
// searchContact insert data
|
||||
OHOS::NativeRdb::ValuesBucket searchContactValues = StructureSearchContactDataValueBucket(rawContactValues);
|
||||
// add raw_contact_id
|
||||
searchContactValues.PutInt(SearchContactColumns::RAW_CONTACT_ID, rawContactId);
|
||||
// add contact_id
|
||||
searchContactValues.PutInt(SearchContactColumns::CONTACT_ID, contactId);
|
||||
int rowSearchContactRet = rdbStore->Insert(searchContactId, ContactTableName::SEARCH_CONTACT, searchContactValues);
|
||||
return rowSearchContactRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContactsDataBase update by quick_search_key
|
||||
*
|
||||
* @param rawContactId Parameters to be passed for update operation
|
||||
* @param type Parameters to be passed for update operation
|
||||
* @param rdbStore Conditions for update operation
|
||||
* @param searchContactValues Parameters to be passed for update operation
|
||||
*
|
||||
* @return The result returned by the update operation
|
||||
*/
|
||||
int ContactsSearch::UpdateSearchContact(int rawContactId, std::string type,
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore, OHOS::NativeRdb::ValuesBucket searchContactValues)
|
||||
{
|
||||
int ret = OHOS::NativeRdb::E_OK;
|
||||
std::string upWhereClause;
|
||||
upWhereClause.append(SearchContactColumns::RAW_CONTACT_ID).append(" = ?");
|
||||
std::vector<std::string> upWhereArgs;
|
||||
upWhereArgs.push_back(std::to_string(rawContactId));
|
||||
int changedRows;
|
||||
// update search_contact table name
|
||||
ret = rdbStore->Update(
|
||||
changedRows, ContactTableName::SEARCH_CONTACT, searchContactValues, upWhereClause, upWhereArgs);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("ContactsUpdateHelper UpdateDisplay UpdateSearchContact fail:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert the rawcontact table insert parameter to the searchcontact table parameter
|
||||
*
|
||||
* @param rawContactValues Parameters to be passed for convert operation
|
||||
*
|
||||
* @return The result returned by the convert operation
|
||||
*/
|
||||
OHOS::NativeRdb::ValuesBucket ContactsSearch::StructureSearchContactDataValueBucket(
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues)
|
||||
{
|
||||
// Will raw_ Convert contact table data to searchcontact table data
|
||||
OHOS::NativeRdb::ValuesBucket searchContactValueBucket;
|
||||
if (rawContactValues.HasColumn(RawContactColumns::ACCOUNT_ID)) {
|
||||
int accountId;
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
rawContactValues.GetObject(RawContactColumns::ACCOUNT_ID, value);
|
||||
value.GetInt(accountId);
|
||||
searchContactValueBucket.PutInt(SearchContactColumns::ACCOUNT_ID, accountId);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::DISPLAY_NAME)) {
|
||||
std::string disPlayName;
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
rawContactValues.GetObject(RawContactColumns::DISPLAY_NAME, value);
|
||||
value.GetString(disPlayName);
|
||||
searchContactValueBucket.PutString(SearchContactColumns::DISPLAY_NAME, disPlayName);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::PHONETIC_NAME)) {
|
||||
std::string phoneticName;
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
rawContactValues.GetObject(RawContactColumns::PHONETIC_NAME, value);
|
||||
value.GetString(phoneticName);
|
||||
searchContactValueBucket.PutString(SearchContactColumns::PHONETIC_NAME, phoneticName);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::PHOTO_FILE_ID)) {
|
||||
int photoFileId;
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
rawContactValues.GetObject(RawContactColumns::PHOTO_FILE_ID, value);
|
||||
value.GetInt(photoFileId);
|
||||
searchContactValueBucket.PutInt(SearchContactColumns::PHOTO_FILE_ID, photoFileId);
|
||||
}
|
||||
if (rawContactValues.HasColumn(RawContactColumns::PHOTO_ID)) {
|
||||
int photoId;
|
||||
OHOS::NativeRdb::ValueObject value;
|
||||
rawContactValues.GetObject(RawContactColumns::PHOTO_ID, value);
|
||||
value.GetInt(photoId);
|
||||
searchContactValueBucket.PutInt(SearchContactColumns::PHOTO_ID, photoId);
|
||||
}
|
||||
return searchContactValueBucket;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef VOICEMAIL_ABILITY_H
|
||||
#define VOICEMAIL_ABILITY_H
|
||||
|
||||
#include "ability.h"
|
||||
#include "ability_loader.h"
|
||||
#include "voicemail_database.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class VoiceMailAbility : public Ability {
|
||||
public:
|
||||
VoiceMailAbility();
|
||||
~VoiceMailAbility();
|
||||
virtual int Insert(const Uri &uri, const NativeRdb::ValuesBucket &value) override;
|
||||
virtual int BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values) override;
|
||||
virtual void OnStart(const Want &want) override;
|
||||
virtual int Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
|
||||
const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual int Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual std::shared_ptr<NativeRdb::AbsSharedResultSet> Query(const Uri &uri,
|
||||
const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates) override;
|
||||
virtual void Dump(const std::string &extra) override;
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Contacts::VoiceMailDataBase> voiceMailDataBase_;
|
||||
static std::map<std::string, int> uriValueMap_;
|
||||
int InsertExecute(const OHOS::Uri &uri, const NativeRdb::ValuesBucket &value);
|
||||
void DataBaseNotifyChange(int code, Uri uri);
|
||||
bool IsBeginTransactionOK(int code, std::mutex &mutex);
|
||||
bool IsCommitOK(int code, std::mutex &mutex);
|
||||
int UriParse(Uri &uri);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // VOICEMAIL_ABILITY_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 VOICEMAIL_DATABASE_H
|
||||
#define VOICEMAIL_DATABASE_H
|
||||
|
||||
#include "data_ability_predicates.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "rdb_open_callback.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "rdb_store.h"
|
||||
#include "result_set.h"
|
||||
#include "value_object.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
class VoiceMailDataBase {
|
||||
public:
|
||||
static std::shared_ptr<VoiceMailDataBase> GetInstance();
|
||||
static std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
|
||||
int64_t InsertVoiceMail(std::string tableName, OHOS::NativeRdb::ValuesBucket insertValues);
|
||||
int UpdateVoiceMail(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
int DeleteVoiceMail(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> Query(
|
||||
OHOS::NativeRdb::RdbPredicates &rdbPredicates, const std::vector<std::string> columns);
|
||||
int BeginTransaction();
|
||||
int Commit();
|
||||
int RollBack();
|
||||
|
||||
private:
|
||||
VoiceMailDataBase();
|
||||
VoiceMailDataBase(const VoiceMailDataBase &);
|
||||
const VoiceMailDataBase &operator=(const VoiceMailDataBase &);
|
||||
static std::shared_ptr<VoiceMailDataBase> voiceMailDataBase_;
|
||||
};
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
#endif // VOICEMAIL_DATABASE_H
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* 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 "voicemail_ability.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "common.h"
|
||||
#include "contacts_columns.h"
|
||||
#include "contacts_common_event.h"
|
||||
#include "data_ability_predicates.h"
|
||||
#include "file_utils.h"
|
||||
#include "predicates_convert.h"
|
||||
#include "rdb_predicates.h"
|
||||
#include "sql_analyzer.h"
|
||||
#include "uri_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
REGISTER_AA(VoiceMailAbility);
|
||||
namespace {
|
||||
std::mutex g_mutex;
|
||||
}
|
||||
std::shared_ptr<Contacts::VoiceMailDataBase> VoiceMailAbility::voiceMailDataBase_ = nullptr;
|
||||
std::map<std::string, int> VoiceMailAbility::uriValueMap_ = {
|
||||
{"/com.ohos.voicemailability/calls/voicemail", Contacts::VOICEMAIL},
|
||||
{"/com.ohos.voicemailability/calls/replaying", Contacts::REPLAYING}
|
||||
};
|
||||
|
||||
VoiceMailAbility::VoiceMailAbility()
|
||||
{
|
||||
}
|
||||
|
||||
VoiceMailAbility::~VoiceMailAbility()
|
||||
{
|
||||
}
|
||||
|
||||
void VoiceMailAbility::Dump(const std::string &extra)
|
||||
{
|
||||
HILOG_ERROR("VoiceMailAbility ====>Dump:%{public}s", extra.c_str());
|
||||
Contacts::FileUtils fileUtils;
|
||||
std::string dirStr = Contacts::ContactsPath::DUMP_PATH;
|
||||
fileUtils.WriteStringToFileAppend(dirStr, extra);
|
||||
}
|
||||
|
||||
void VoiceMailAbility::OnStart(const Want &want)
|
||||
{
|
||||
Ability::OnStart(want);
|
||||
std::string basePath = GetDatabaseDir();
|
||||
Contacts::ContactsPath::RDB_PATH = basePath + "/";
|
||||
Contacts::ContactsPath::RDB_BACKUP_PATH = basePath + "/backup/";
|
||||
Contacts::ContactsPath::DUMP_PATH = GetFilesDir() + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VoiceMailAbility BeginTransaction emptiness problems
|
||||
*
|
||||
* @param code the return number of BeginTransaction
|
||||
* @param mutex transmission parameter : lock
|
||||
*
|
||||
* @return BeginTransaction emptiness true or false
|
||||
*/
|
||||
bool VoiceMailAbility::IsBeginTransactionOK(int code, std::mutex &mutex)
|
||||
{
|
||||
mutex.try_lock();
|
||||
if (code != 0) {
|
||||
HILOG_ERROR("IsBeginTransactionOK fail");
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VoiceMailAbility Commit emptiness problems
|
||||
*
|
||||
* @param code the return number of Commit
|
||||
* @param mutex transmission parameter : lock
|
||||
*
|
||||
* @return Commit emptiness true or false
|
||||
*/
|
||||
bool VoiceMailAbility::IsCommitOK(int code, std::mutex &mutex)
|
||||
{
|
||||
mutex.try_lock();
|
||||
if (code != 0) {
|
||||
HILOG_ERROR("IsCommitOK fail");
|
||||
mutex.unlock();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VoiceMailAbility Insert database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param value Insert the data value of the database
|
||||
*
|
||||
* @return Insert database results code
|
||||
*/
|
||||
int VoiceMailAbility::Insert(const Uri &uri, const NativeRdb::ValuesBucket &value)
|
||||
{
|
||||
Contacts::SqlAnalyzer sqlAnalyzer;
|
||||
bool isOk = sqlAnalyzer.CheckValuesBucket(value);
|
||||
if (!isOk) {
|
||||
HILOG_ERROR("VoiceMailAbility CheckValuesBucket is error");
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
voiceMailDataBase_ = Contacts::VoiceMailDataBase::GetInstance();
|
||||
int rowRet = Contacts::RDB_EXECUTE_FAIL;
|
||||
int ret = voiceMailDataBase_->BeginTransaction();
|
||||
if (!IsBeginTransactionOK(ret, g_mutex)) {
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
rowRet = InsertExecute(uri, value);
|
||||
if (rowRet == Contacts::OPERATION_ERROR) {
|
||||
ret = voiceMailDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::OPERATION_ERROR;
|
||||
}
|
||||
ret = voiceMailDataBase_->Commit();
|
||||
if (!IsCommitOK(ret, g_mutex)) {
|
||||
voiceMailDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_INSERT, uri);
|
||||
return rowRet;
|
||||
}
|
||||
|
||||
int VoiceMailAbility::UriParse(Uri &uri)
|
||||
{
|
||||
Contacts::UriUtils uriUtils;
|
||||
int parseCode = uriUtils.UriParse(uri, uriValueMap_);
|
||||
return parseCode;
|
||||
}
|
||||
|
||||
int VoiceMailAbility::InsertExecute(const OHOS::Uri &uri, const NativeRdb::ValuesBucket &initialValues)
|
||||
{
|
||||
int rowId = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int code = UriParse(uriTemp);
|
||||
switch (code) {
|
||||
case Contacts::VOICEMAIL:
|
||||
rowId = voiceMailDataBase_->InsertVoiceMail(Contacts::CallsTableName::VOICEMAIL, initialValues);
|
||||
break;
|
||||
case Contacts::REPLAYING:
|
||||
rowId = voiceMailDataBase_->InsertVoiceMail(Contacts::CallsTableName::REPLYING, initialValues);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("VoiceMailAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
return rowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VoiceMailAbility BatchInsert database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param value Insert the data values of the database
|
||||
*
|
||||
* @return BatchInsert database results code
|
||||
*/
|
||||
int VoiceMailAbility::BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values)
|
||||
{
|
||||
int size = values.size();
|
||||
if (size <= 0) {
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
voiceMailDataBase_ = Contacts::VoiceMailDataBase::GetInstance();
|
||||
int ret = voiceMailDataBase_->BeginTransaction();
|
||||
if (!IsBeginTransactionOK(ret, g_mutex)) {
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
++count;
|
||||
OHOS::NativeRdb::ValuesBucket rawContactValues = values[i];
|
||||
int code = InsertExecute(uri, rawContactValues);
|
||||
if (code == Contacts::OPERATION_ERROR) {
|
||||
voiceMailDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return code;
|
||||
}
|
||||
if (count % Contacts::BATCH_INSERT_COUNT == 0) {
|
||||
int markRet = voiceMailDataBase_->Commit();
|
||||
int beginRet = voiceMailDataBase_->BeginTransaction();
|
||||
if (!IsCommitOK(markRet, g_mutex) || !IsBeginTransactionOK(beginRet, g_mutex)) {
|
||||
voiceMailDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
int markRet = voiceMailDataBase_->Commit();
|
||||
if (!IsCommitOK(markRet, g_mutex) ) {
|
||||
voiceMailDataBase_->RollBack();
|
||||
g_mutex.unlock();
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_INSERT, uri);
|
||||
return Contacts::RDB_EXECUTE_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VoiceMailAbility Update database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param predicates Update the data value of the condition
|
||||
*
|
||||
* @return Update database results code
|
||||
*/
|
||||
int VoiceMailAbility::Update(
|
||||
const Uri &uri, const NativeRdb::ValuesBucket &value, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
Contacts::SqlAnalyzer sqlAnalyzer;
|
||||
bool isOk = sqlAnalyzer.CheckValuesBucket(value);
|
||||
if (!isOk) {
|
||||
HILOG_ERROR("VoiceMailAbility CheckValuesBucket is error");
|
||||
return Contacts::RDB_EXECUTE_FAIL;
|
||||
}
|
||||
g_mutex.lock();
|
||||
voiceMailDataBase_ = Contacts::VoiceMailDataBase::GetInstance();
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
int ret = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int code = UriParse(uriTemp);
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (code) {
|
||||
case Contacts::VOICEMAIL:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::VOICEMAIL, dataAbilityPredicates);
|
||||
ret = voiceMailDataBase_->UpdateVoiceMail(value, rdbPredicates);
|
||||
break;
|
||||
case Contacts::REPLAYING:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::REPLYING, dataAbilityPredicates);
|
||||
ret = voiceMailDataBase_->UpdateVoiceMail(value, rdbPredicates);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("VoiceMailAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_UPDATE, uri);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VoiceMailAbility Delete database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param predicates Delete the data values of the condition
|
||||
*
|
||||
* @return Delete database results code
|
||||
*/
|
||||
int VoiceMailAbility::Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
g_mutex.lock();
|
||||
voiceMailDataBase_ = Contacts::VoiceMailDataBase::GetInstance();
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
int ret = Contacts::RDB_EXECUTE_FAIL;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int parseCode = UriParse(uriTemp);
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
switch (parseCode) {
|
||||
case Contacts::VOICEMAIL:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::VOICEMAIL, dataAbilityPredicates);
|
||||
ret = voiceMailDataBase_->DeleteVoiceMail(rdbPredicates);
|
||||
break;
|
||||
case Contacts::REPLAYING:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::REPLYING, dataAbilityPredicates);
|
||||
ret = voiceMailDataBase_->DeleteVoiceMail(rdbPredicates);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("VoiceMailAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
g_mutex.unlock();
|
||||
DataBaseNotifyChange(Contacts::CONTACT_DELETE, uri);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VoiceMailAbility Query database
|
||||
*
|
||||
* @param uri Determine the data table name based on the URI
|
||||
* @param columns Columns returned by query
|
||||
* @param predicates Query the data values of the condition
|
||||
*
|
||||
* @return Query database results
|
||||
*/
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> VoiceMailAbility::Query(
|
||||
const Uri &uri, const std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates)
|
||||
{
|
||||
HILOG_ERROR("VoiceMailAbility ====>Query start");
|
||||
voiceMailDataBase_ = Contacts::VoiceMailDataBase::GetInstance();
|
||||
Contacts::PredicatesConvert predicatesConvert;
|
||||
OHOS::Uri uriTemp = uri;
|
||||
int parseCode = UriParse(uriTemp);
|
||||
std::shared_ptr<NativeRdb::AbsSharedResultSet> result;
|
||||
OHOS::NativeRdb::DataAbilityPredicates dataAbilityPredicates = predicates;
|
||||
OHOS::NativeRdb::RdbPredicates rdbPredicates("");
|
||||
std::vector<std::string> columnsTemp = columns;
|
||||
switch (parseCode) {
|
||||
case Contacts::VOICEMAIL:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::VOICEMAIL, dataAbilityPredicates);
|
||||
result = voiceMailDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
case Contacts::REPLAYING:
|
||||
rdbPredicates =
|
||||
predicatesConvert.ConvertPredicates(Contacts::CallsTableName::REPLYING, dataAbilityPredicates);
|
||||
result = voiceMailDataBase_->Query(rdbPredicates, columnsTemp);
|
||||
break;
|
||||
default:
|
||||
HILOG_ERROR("VoiceMailAbility ====>no match uri action");
|
||||
break;
|
||||
}
|
||||
std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> sharedPtrResult = std::move(result);
|
||||
HILOG_ERROR("VoiceMailAbility ====>Query end");
|
||||
return sharedPtrResult;
|
||||
}
|
||||
|
||||
void VoiceMailAbility::DataBaseNotifyChange(int code, Uri uri)
|
||||
{
|
||||
Contacts::ContactsCommonEvent::SendCallLogChange(code);
|
||||
std::string path = uri.GetPath();
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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 "voicemail_database.h"
|
||||
|
||||
#include "calllog_database.h"
|
||||
#include "predicates_convert.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Contacts {
|
||||
std::shared_ptr<VoiceMailDataBase> VoiceMailDataBase::voiceMailDataBase_ = nullptr;
|
||||
std::shared_ptr<OHOS::NativeRdb::RdbStore> VoiceMailDataBase::store_ = nullptr;
|
||||
|
||||
VoiceMailDataBase::VoiceMailDataBase()
|
||||
{
|
||||
store_ = CallLogDataBase::GetInstance()->store_;
|
||||
}
|
||||
|
||||
std::shared_ptr<VoiceMailDataBase> VoiceMailDataBase::GetInstance()
|
||||
{
|
||||
if (voiceMailDataBase_ == nullptr) {
|
||||
voiceMailDataBase_.reset(new VoiceMailDataBase());
|
||||
return voiceMailDataBase_;
|
||||
}
|
||||
return voiceMailDataBase_;
|
||||
}
|
||||
|
||||
int64_t VoiceMailDataBase::InsertVoiceMail(std::string tableName, OHOS::NativeRdb::ValuesBucket insertValues)
|
||||
{
|
||||
int64_t outRowId = RDB_EXECUTE_FAIL;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("VoiceMailDataBase Insert store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
CallLogDataBase::GetInstance()->QueryContactsByInsertCalls(insertValues);
|
||||
int ret = store_->Insert(outRowId, tableName, insertValues);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("VoiceMailDataBase InsertVoiceMail ret :%{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return outRowId;
|
||||
}
|
||||
|
||||
int VoiceMailDataBase::UpdateVoiceMail(
|
||||
OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates)
|
||||
{
|
||||
int changedRows = RDB_EXECUTE_FAIL;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("VoiceMailDataBase Update store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
if (values.HasColumn(CallLogColumns::PHONE_NUMBER)) {
|
||||
CallLogDataBase::GetInstance()->QueryContactsByInsertCalls(values);
|
||||
}
|
||||
int ret = store_->Update(changedRows, values, rdbPredicates);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("VoiceMailDataBase Update ret :%{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int VoiceMailDataBase::DeleteVoiceMail(OHOS::NativeRdb::RdbPredicates &rdbPredicates)
|
||||
{
|
||||
int deletedRows = RDB_EXECUTE_FAIL;
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("VoiceMailDataBase Delete store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->Delete(deletedRows, rdbPredicates);
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("VoiceMailDataBase Delete ret :%{public}d", ret);
|
||||
return RDB_EXECUTE_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> VoiceMailDataBase::Query(
|
||||
OHOS::NativeRdb::RdbPredicates &rdbPredicates, const std::vector<std::string> columns)
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("CallLogDataBase Delete store_ is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> resultSet = store_->Query(rdbPredicates, columns);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
int VoiceMailDataBase::BeginTransaction()
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR("VoiceMailDataBase BeginTransaction store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->BeginTransaction();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR("VoiceMailDataBase BeginTransaction fail :%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int VoiceMailDataBase::Commit()
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR(" VoiceMailDataBase Commit store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->Commit();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR(" VoiceMailDataBase Commit fail :%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int VoiceMailDataBase::RollBack()
|
||||
{
|
||||
if (store_ == nullptr) {
|
||||
HILOG_ERROR(" VoiceMailDataBase RollBack store_ is nullptr");
|
||||
return RDB_OBJECT_EMPTY;
|
||||
}
|
||||
int ret = store_->RollBack();
|
||||
if (ret != OHOS::NativeRdb::E_OK) {
|
||||
HILOG_ERROR(" VoiceMailDataBase RollBack fail :%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace Contacts
|
||||
} // namespace OHOS
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,558 @@
|
||||
/*
|
||||
* 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 featureAbility from '@ohos.ability.featureAbility';
|
||||
import ohos_data_ability from '@ohos.data.dataability';
|
||||
import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from 'deccjsunit/index'
|
||||
|
||||
const URI_CONTACTS = "dataability:///com.ohos.contactsdataability";
|
||||
const groupUri = "dataability:///com.ohos.contactsdataability/contacts/groups";
|
||||
import common from './common.js';
|
||||
|
||||
describe('GroupsTest', function() {
|
||||
console.info('logMessage GroupsTest start! ');
|
||||
|
||||
var array_two = 2;
|
||||
|
||||
async function groupsQuery(map, tag)
|
||||
{
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info(tag + ': groupsQuery start ! DAHelper = ' + DAHelper);
|
||||
var resultColumns = [];
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("id", map.get("id"));
|
||||
try {
|
||||
var resultSet = await DAHelper.query(groupUri, resultColumns, condition);
|
||||
if (resultSet.rowCount > 0) {
|
||||
if (resultSet.goToFirstRow()) {
|
||||
do {
|
||||
for (var [key, value] of map) {
|
||||
var dbresult = resultSet.getString(resultSet.getColumnIndex(key));
|
||||
console.info(tag + ': logMessage groupsQuery key =' + key + 'dbresult :' + dbresult +
|
||||
' value : ' + value);
|
||||
expect(value == dbresult).assertTrue();
|
||||
}
|
||||
} while (resultSet.goToNextRow());
|
||||
}
|
||||
}
|
||||
resultSet.close();
|
||||
} catch (error) {
|
||||
console.info(tag + ': logMessage groupsQuery: error = ' + error);
|
||||
}
|
||||
}
|
||||
|
||||
async function queryIdForDelete(map, tag)
|
||||
{
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info(tag + ': queryIdForDelete start ! DAHelper = ' + DAHelper);
|
||||
var resultColumns = common.getCallLogResultColumns();
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("id", map.get("id"));
|
||||
try {
|
||||
var resultSet = await DAHelper.query(groupUri, resultColumns, condition);
|
||||
expect(resultSet.goToFirstRow() == false).assertTrue();
|
||||
console.info(tag + " :logMessage queryIdForDelete: goToFirstRow " + resultSet.goToFirstRow());
|
||||
resultSet.close();
|
||||
} catch (error) {
|
||||
console.info(tag + " :logMessage queryIdForDelete: error = " + error);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteAll(uri, tag)
|
||||
{
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.greaterThan("id", "0");
|
||||
var deleteCode = await DAHelper.delete(uri, condition);
|
||||
console.info(tag + ': deleteAll deleteCode = ' + deleteCode);
|
||||
expect(deleteCode == 0).assertTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number group_insert_test_100
|
||||
* @tc.name Insert group
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_insert_test_100", 0, async function(done) {
|
||||
console.info("---------logMessage group_insert_test_100 is starting!----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, common.getProfileGroup());
|
||||
console.info("logMessage group_insert_test_100: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
var map = common.getProfileGroupMap();
|
||||
map.set("id", groupId.toString());
|
||||
await groupsQuery(map, "group_insert_test_100");
|
||||
await deleteAll(groupUri, "group_insert_test_100");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_insert_test_100: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number group_update_test_500
|
||||
* @tc.name Update group
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_update_test_500", 0, async function(done) {
|
||||
console.info("---------logMessage group_update_test_500 is starting!----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, common.getProfileGroup());
|
||||
console.info("logMessage group_update_test_500: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
await GroupUpdate();
|
||||
await deleteAll(groupUri, "group_update_test_500");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_update_test_500: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
|
||||
async function GroupUpdate()
|
||||
{
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("id", groupId.toString());
|
||||
try {
|
||||
var updateCode = await DAHelper.update(groupUri, common.getProfileUpdateGroup(), condition);
|
||||
console.info("logMessage group_update_test_500: updateCode = " + updateCode);
|
||||
expect(updateCode == 0).assertTrue();
|
||||
var map = common.getProfileUpdateGroupMap();
|
||||
map.set("id", groupId.toStirng());
|
||||
await groupsQuery(map, "group_update_test_500");
|
||||
} catch (error) {
|
||||
console.info("logMessage group_update_test_500: update error = " + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number group_delete_test_200
|
||||
* @tc.name Delete group
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_delete_test_200", 0, async function(done) {
|
||||
console.info("---------logMessage group_delete_test_200 is starting!----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, common.getProfileGroup());
|
||||
console.info("logMessage group_delete_test_200: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
await GroupDelete();
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_delete_test_200: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
async function GroupDelete()
|
||||
{
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("id", groupId.toString());
|
||||
try {
|
||||
var deleteCode = await DAHelper.delete(groupUri, condition);
|
||||
console.info("logMessage group_delete_test_200 : deleteCode = " + deleteCode);
|
||||
expect(deleteCode == 0).assertTrue();
|
||||
var map = new Map();
|
||||
map.set("id", groupId.toString());
|
||||
await queryIdForDelete(map, "group_delete_test_200");
|
||||
} catch (error) {
|
||||
console.info("logMessage group_delete_test_200 : delete error = " + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number group_query_test_300
|
||||
* @tc.name Query a group
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_query_test_300", 0, async function(done) {
|
||||
console.info("------------logMessage group_query_test_300 is starting!-----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, common.getProfileGroup());
|
||||
console.info("logMessage group_query_test_300: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
var map = common.getProfileGroupMap();
|
||||
map.set("id", groupId.toString());
|
||||
await groupsQuery(map, "logMessage group_query_test_300");
|
||||
await deleteAll(groupUri, "group_query_test_300");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_query_test_300: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number group_query_test_400
|
||||
* @tc.name Query all groups
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_query_test_400", 0, async function(done) {
|
||||
console.info("------------logMessage group_query_test_400 is starting!-----------");
|
||||
console.info("---------logMessage getDbHelper start!----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
console.info('logMessage uri = ' + URI_CONTACTS);
|
||||
var groupUri = "dataability:///com.ohos.contactsdataability/contacts/groups";
|
||||
|
||||
var insertValues = {"group_name" : "ManagerSecondGroup"};
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, insertValues);
|
||||
console.info("logMessage group_query_test_400: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
await GroupQuery();
|
||||
await deleteAll(groupUri, "group_query_test_400");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_query_test_400: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
|
||||
async function GroupQuery()
|
||||
{
|
||||
var resultColumns = [ "id", "group_name" ];
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.greaterThan("id", "0");
|
||||
try {
|
||||
var resultSet = await DAHelper.query(groupUri, resultColumns, condition);
|
||||
console.info("logMessage group_query_test_400: resultSet.rowCount = " + resultSet.rowCount);
|
||||
expect(resultSet.rowCount == 1).assertTrue();
|
||||
resultSet.close();
|
||||
} catch (error) {
|
||||
console.info("group_query_test_400 resultSet query error = " + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number abnormal_group_insert_test_600
|
||||
* @tc.name abnormal insert
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("abnormal_group_insert_test_600", 0, async function(done) {
|
||||
console.info("---------logMessage abnormal_group_insert_test_600 is starting!----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
const errorUri = "dataability:///com.ohos.contactsdataability/contacts/groupssss";
|
||||
try {
|
||||
var groupId = await DAHelper.insert(errorUri, common.getProfileGroup());
|
||||
console.info("logMessage abnormal_group_insert_test_600: groupId = " + groupId);
|
||||
expect(groupId == -1).assertTrue();
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage abnormal_group_insert_test_600: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number abnormal_group_update_test_700
|
||||
* @tc.name abnormal update
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("abnormal_group_update_test_700", 0, async function(done) {
|
||||
console.info("---------logMessage abnormal_group_update_test_700 is starting!----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, common.getProfileGroup());
|
||||
console.info("logMessage abnormal_group_update_test_700: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
await GroupUpdate();
|
||||
await deleteAll(groupUri, "abnormal_group_update_test_700");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage abnormal_group_update_test_700: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
|
||||
async function GroupUpdate()
|
||||
{
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("id", groupId.toString());
|
||||
var updateValue = { "group_notesss" : "6666" }
|
||||
try {
|
||||
var updateCode = await DAHelper.update(groupUri, updateValue, condition);
|
||||
console.info("logMessage abnormal_group_update_test_700: updateCode = " + updateCode);
|
||||
expect(updateCode == -1).assertTrue();
|
||||
var map = common.getProfileUpdateGroupMap();
|
||||
map.set("id", groupId.toStirng());
|
||||
await groupsQuery(map, "abnormal_group_update_test_700");
|
||||
} catch (error) {
|
||||
console.info("logMessage abnormal_group_update_test_700: update error = " + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number abnormal_group_delete_test_800
|
||||
* @tc.name abnormal delete
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("abnormal_group_delete_test_800", 0, async function(done) {
|
||||
console.info("---------logMessage abnormal_group_delete_test_800 is starting!----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, common.getProfileGroup());
|
||||
console.info("logMessage abnormal_group_delete_test_800: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
await GroupDelete();
|
||||
await deleteAll(groupUri, "abnormal_group_delete_test_800");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage abnormal_group_delete_test_800: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
async function GroupDelete()
|
||||
{
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("idss", groupId.toString());
|
||||
try {
|
||||
var deleteCode = await DAHelper.delete(groupUri, condition);
|
||||
console.info("logMessage abnormal_group_delete_test_800 : deleteCode = " + deleteCode);
|
||||
expect(deleteCode == -1).assertTrue();
|
||||
var map = common.getProfileUpdateGroupMap();
|
||||
map.set("id", groupId.toStirng());
|
||||
await groupsQuery(map, "abnormal_group_delete_test_800");
|
||||
} catch (error) {
|
||||
console.info("logMessage abnormal_group_delete_test_800 : delete error = " + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number abnormal_group_query_test_900
|
||||
* @tc.name abnormal query
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("abnormal_group_query_test_900", 0, async function(done) {
|
||||
console.info("------------logMessage abnormal_group_query_test_900 is starting!-----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
|
||||
var insertValues = {"group_name" : "PersonnelDepartment"};
|
||||
try {
|
||||
var groupId = await DAHelper.insert(groupUri, insertValues);
|
||||
console.info("logMessage abnormal_group_query_test_900: groupId = " + groupId);
|
||||
expect(groupId > 0).assertTrue();
|
||||
await GroupQuery(DAHelper);
|
||||
await deleteAll(groupUri, "abnormal_group_query_test_900");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage abnormal_group_query_test_900: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
|
||||
async function GroupQuery(DAHelper)
|
||||
{
|
||||
var resultColumns = [ "id", "group_namesss" ];
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("id", groupId.toString());
|
||||
try {
|
||||
var resultSet = await DAHelper.query(groupUri, resultColumns, condition);
|
||||
console.info('abnormal_group_query_test_900 resultSet.goToFirstRow() = ' + resultSet.goToFirstRow());
|
||||
expect(resultSet.goToFirstRow() == false).assertTrue();
|
||||
resultSet.close();
|
||||
} catch (error) {
|
||||
console.info('abnormal_group_query_test_900 query error ' + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number group_insert_test_1000
|
||||
* @tc.name Adding multiple groups
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_insert_test_1000", 0, async function(done) {
|
||||
console.info("------------logMessage group_insert_test_1000 is starting!-----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
|
||||
var insertValuesOne = {"group_name" : "test1000"};
|
||||
var insertValuesTwo = {"group_name" : "test1000"};
|
||||
var insertValuesThree = {"group_name" : "test1000"};
|
||||
var array = []
|
||||
array[0] = insertValuesOne;
|
||||
array[1] = insertValuesTwo;
|
||||
array[array_two] = insertValuesThree;
|
||||
try {
|
||||
var code = await DAHelper.batchInsert(groupUri, array);
|
||||
console.info("logMessage group_insert_test_1000: batchInsert code = " + code);
|
||||
expect(code == 0).assertTrue();
|
||||
await GroupQuery(DAHelper);
|
||||
await deleteAll(groupUri, "group_insert_test_1000");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_insert_test_1000: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
|
||||
async function GroupQuery(DAHelper)
|
||||
{
|
||||
var groupSize = 3;
|
||||
var resultColumns = [ "id", "group_name" ];
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("group_name", "test1000");
|
||||
try {
|
||||
var resultSet = await DAHelper.query(groupUri, resultColumns, condition);
|
||||
console.info('group_insert_test_1000 resultSet.rowCount = ' + resultSet.rowCount);
|
||||
expect(resultSet.rowCount == groupSize).assertTrue();
|
||||
resultSet.close();
|
||||
} catch (error) {
|
||||
console.info('group_insert_test_1000 query error ' + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number group_delete_test_1100
|
||||
* @tc.name delete multiple groups
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_delete_test_1100", 0, async function(done) {
|
||||
console.info("------------logMessage group_delete_test_1100 is starting!-----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
|
||||
var insertValuesOne = {"group_name" : "test1100"};
|
||||
var insertValuesTwo = {"group_name" : "test1100"};
|
||||
var insertValuesThree = {"group_name" : "test1100"};
|
||||
var array = []
|
||||
array[0] = insertValuesOne;
|
||||
array[1] = insertValuesTwo;
|
||||
array[array_two] = insertValuesThree;
|
||||
try {
|
||||
var code = await DAHelper.batchInsert(groupUri, array);
|
||||
console.info("logMessage group_delete_test_1100: batchInsert code = " + code);
|
||||
expect(code == 0).assertTrue();
|
||||
await deleteAll(groupUri, "group_delete_test_1100");
|
||||
await GroupQuery(DAHelper);
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_delete_test_1100: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
|
||||
async function GroupQuery(DAHelper)
|
||||
{
|
||||
var groupSize = 0;
|
||||
var resultColumns = [ "id", "group_name" ];
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("group_name", "test1100");
|
||||
try {
|
||||
var resultSet = await DAHelper.query(groupUri, resultColumns, condition);
|
||||
console.info('group_delete_test_1100 resultSet.rowCount = ' + resultSet.rowCount);
|
||||
expect(resultSet.rowCount == groupSize).assertTrue();
|
||||
resultSet.close();
|
||||
} catch (error) {
|
||||
console.info('group_delete_test_1100 query error ' + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @tc.number group_update_test_1200
|
||||
* @tc.name update multiple groups
|
||||
* @tc.desc Function test
|
||||
*/
|
||||
it("group_update_test_1200", 0, async function(done) {
|
||||
console.info("------------logMessage group_update_test_1200 is starting!-----------");
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
console.info('logMessage get DAHelper success! DAHelper = ' + DAHelper);
|
||||
|
||||
var insertValuesOne = {"group_name" : "test1200"};
|
||||
var insertValuesTwo = {"group_name" : "test1200"};
|
||||
var insertValuesThree = {"group_name" : "test1200"};
|
||||
var array = []
|
||||
array[0] = insertValuesOne;
|
||||
array[1] = insertValuesTwo;
|
||||
array[array_two] = insertValuesThree;
|
||||
try {
|
||||
var code = await DAHelper.batchInsert(groupUri, array);
|
||||
console.info("logMessage group_update_test_1200: batchInsert code = " + code);
|
||||
expect(code == 0).assertTrue();
|
||||
await GroupUpdateThree(DAHelper);
|
||||
await GroupQuery(DAHelper);
|
||||
await deleteAll(groupUri, "group_update_test_1200");
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_update_test_1200: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
|
||||
async function GroupQuery(DAHelper)
|
||||
{
|
||||
var groupSize = 3;
|
||||
var resultColumns = [ "id", "group_name" ];
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("group_name", "test120000");
|
||||
try {
|
||||
var resultSet = await DAHelper.query(groupUri, resultColumns, condition);
|
||||
console.info("logMessage group_update_test_1200: resultSet.rowCount = " + resultSet.rowCount);
|
||||
expect(resultSet.rowCount == groupSize).assertTrue();
|
||||
resultSet.close();
|
||||
} catch (error) {
|
||||
console.info('group_update_test_1200 query error ' + error);
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function GroupUpdateThree(DAHelper)
|
||||
{
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.equalTo("group_name", "test1200");
|
||||
var updateValue = { "group_name" : "test120000" }
|
||||
try {
|
||||
var updateCode = await DAHelper.update(groupUri, updateValue, condition);
|
||||
console.info("logMessage group_update_test_1200: updateCode = " + updateCode);
|
||||
expect(updateCode == 0).assertTrue();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_update_test_1200: update error = " + error);
|
||||
}
|
||||
}
|
||||
|
||||
afterAll(async function(done) {
|
||||
var DAHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS);
|
||||
var condition = new ohos_data_ability.DataAbilityPredicates();
|
||||
condition.notEqualTo("id", "0");
|
||||
try {
|
||||
var deleteCode = await DAHelper.delete(groupUri, condition);
|
||||
console.info("logMessage group_deleted : deleteCode = " + deleteCode);
|
||||
done();
|
||||
} catch (error) {
|
||||
console.info("logMessage group_deleted: group insert error = " + error);
|
||||
done();
|
||||
}
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,11 @@
|
||||
//require('./ObjectInterface_test.js');
|
||||
//require('./ObjectCallback.js');
|
||||
//require('./Calllog_test.js');
|
||||
//require('./Voicemail_test.js');
|
||||
//require('./Groups_test.js');
|
||||
//require('./Contacts_test.js');
|
||||
//require('./ContactCard_test.js');
|
||||
require('./ContactMerge_test.js');
|
||||
require('./Performance_test.js');
|
||||
require('./Stability_test.js');
|
||||
require('./recovery_test.js');
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user