From 896ef1a981693f95ed01470a8551ebd3ca9544cf Mon Sep 17 00:00:00 2001 From: "g00536918 (GeorgeT)" Date: Thu, 28 Nov 2024 16:10:17 +0800 Subject: [PATCH] Contact api cj-native part independent from ts-native Change-Id: I861637fbda3c66797284762d4c65a106d70b6a3c Signed-off-by: George Timoshenko --- bundle.json | 3 +- contacts/BUILD.gn | 1 + contacts/src/contacts_api.cpp | 2 + contactsCJ/BUILD.gn | 9 +- contactsCJ/include/contacts.h | 2 + contactsCJ/include/contacts_control.h | 67 +++++++++++ contactsCJ/include/contacts_permission.h | 39 +++++++ contactsCJ/include/contacts_utils.h | 30 ++++- contactsCJ/include/hilog_wrapper_api.h | 61 ++++++++++ contactsCJ/src/contacts.cpp | 113 ++++++++++-------- contactsCJ/src/contacts_control.cpp | 142 +++++++++++++++++++++++ contactsCJ/src/contacts_permission.cpp | 91 +++++++++++++++ contactsCJ/src/contacts_utils.cpp | 121 ++++++++++--------- 13 files changed, 565 insertions(+), 116 deletions(-) create mode 100644 contactsCJ/include/contacts_control.h create mode 100644 contactsCJ/include/contacts_permission.h create mode 100644 contactsCJ/include/hilog_wrapper_api.h create mode 100644 contactsCJ/src/contacts_control.cpp create mode 100644 contactsCJ/src/contacts_permission.cpp diff --git a/bundle.json b/bundle.json index 733897b..67bb6d5 100644 --- a/bundle.json +++ b/bundle.json @@ -44,7 +44,8 @@ "os_account", "preferences", "relational_store", - "safwk" + "safwk", + "ace_engine" ], "third_party": [ "jsoncpp" diff --git a/contacts/BUILD.gn b/contacts/BUILD.gn index 783a28b..d74568c 100644 --- a/contacts/BUILD.gn +++ b/contacts/BUILD.gn @@ -115,6 +115,7 @@ ohos_shared_library("contact") { ] public_deps = [] + relative_install_dir = "module" part_name = "contacts_data" subsystem_name = "applications" } diff --git a/contacts/src/contacts_api.cpp b/contacts/src/contacts_api.cpp index 1a658ef..a5f5a20 100644 --- a/contacts/src/contacts_api.cpp +++ b/contacts/src/contacts_api.cpp @@ -939,6 +939,8 @@ void LocalExecuteIsMyCard(napi_env env, ExecuteHelper *executeHelper) executeHelper->resultData = isMyCard; return; } + int rowCount = 0; + resultSet->GetRowCount(rowCount); int resultSetNum = resultSet->GoToFirstRow(); if (resultSetNum == OHOS::NativeRdb::E_OK) { isMyCard = 1; diff --git a/contactsCJ/BUILD.gn b/contactsCJ/BUILD.gn index 0de4af3..d2eb498 100644 --- a/contactsCJ/BUILD.gn +++ b/contactsCJ/BUILD.gn @@ -17,14 +17,14 @@ import("//build/ohos.gni") ohos_shared_library("contact_cj") { sources = [ "src/contacts.cpp", + "src/contacts_control.cpp", "src/contacts_ffi.cpp", + "src/contacts_permission.cpp", "src/contacts_utils.cpp", ] include_dirs = [ "include" ] - deps = [ "${CONTACT_ROOT}/contacts:contact" ] - sanitize = { cfi = true cfi_cross_dso = true @@ -38,11 +38,16 @@ ohos_shared_library("contact_cj") { "ability_runtime:abilitykit_native", "ability_runtime:app_context", "ability_runtime:napi_base_context", + "ability_runtime:ui_extension", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "ace_engine:ace_uicontent", "c_utils:utils", "data_share:cj_data_share_predicates_ffi", "data_share:datashare_consumer", "hilog:libhilog", "ipc:ipc_core", + "napi:ace_napi", "napi:cj_bind_ffi", "napi:cj_bind_native", ] diff --git a/contactsCJ/include/contacts.h b/contactsCJ/include/contacts.h index 9fca2a4..912bca2 100644 --- a/contactsCJ/include/contacts.h +++ b/contactsCJ/include/contacts.h @@ -25,6 +25,8 @@ namespace ContactsFfi { class Contacts { public: + static const int INVALID_CONTACT_ID = -1; + Contacts() {} ~Contacts() = default; diff --git a/contactsCJ/include/contacts_control.h b/contactsCJ/include/contacts_control.h new file mode 100644 index 0000000..c51a922 --- /dev/null +++ b/contactsCJ/include/contacts_control.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021-2022 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 "datashare_helper.h" +#include "datashare_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" + +namespace OHOS { +namespace ContactsFfi { +class ContactsControl { +public: + ContactsControl(); + ~ContactsControl(); + int RawContactInsert(std::shared_ptr dataShareHelper, + DataShare::DataShareValuesBucket rawContactValues); + int ContactDataInsert(std::shared_ptr dataShareHelper, + std::vector contactsDataValues); + int RawContactUpdate(std::shared_ptr dataShareHelper, + DataShare::DataShareValuesBucket updateValues, DataShare::DataSharePredicates predicates); + int ContactDataUpdate(std::shared_ptr dataShareHelper, + DataShare::DataShareValuesBucket updateValues, DataShare::DataSharePredicates predicates); + int ContactDelete(std::shared_ptr dataShareHelper, + DataShare::DataSharePredicates predicates); + int ContactDataDelete(std::shared_ptr dataShareHelper, + DataShare::DataSharePredicates predicates); + std::shared_ptr ContactQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates); + std::shared_ptr ContactDataQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates); + std::shared_ptr GroupsQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates); + std::shared_ptr MyCardQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates); + std::shared_ptr HolderQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates); +}; +} // namespace ContactsApi +} // namespace OHOS +#endif // CONTACT_CONTROL_H diff --git a/contactsCJ/include/contacts_permission.h b/contactsCJ/include/contacts_permission.h new file mode 100644 index 0000000..aa908ac --- /dev/null +++ b/contactsCJ/include/contacts_permission.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 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 CONTACTS_PERMISSION_H +#define CONTACTS_PERMISSION_H + +#include + +namespace OHOS { +namespace ContactsFfi { +namespace Permission { +static constexpr const char *READ_CONTACTS = "ohos.permission.READ_CONTACTS"; +static constexpr const char *WRITE_CONTACTS = "ohos.permission.WRITE_CONTACTS"; +static constexpr const char *WRITE_CALL_LOG = "ohos.permission.WRITE_CALL_LOG"; +static constexpr const char *READ_CALL_LOG = "ohos.permission.READ_CALL_LOG"; +static constexpr const char *OHOS_PERMISSION_MANAGE_VOICEMAIL = "ohos.permission.MANAGE_VOICEMAIL"; +} // namespace Permission + +class ContactsTelephonyPermission { +public: + ContactsTelephonyPermission(); + ~ContactsTelephonyPermission(); + static bool CheckPermission(const std::string &permissionName); +}; +} // namespace Telephony +} // namespace OHOS +#endif // PERMISSION_H \ No newline at end of file diff --git a/contactsCJ/include/contacts_utils.h b/contactsCJ/include/contacts_utils.h index 365c058..2adfac6 100644 --- a/contactsCJ/include/contacts_utils.h +++ b/contactsCJ/include/contacts_utils.h @@ -19,8 +19,7 @@ #include #include "errors.h" -#include "hilog_wrapper_api.h" // from contacts_data/contacts - +#include "hilog_wrapper_api.h" #include "data_share_predicates_utils.h" #include "datashare_result_set.h" #include "datashare_values_bucket.h" @@ -49,6 +48,33 @@ constexpr int BUCKET_COUNT_5 = 5; constexpr int BUCKET_COUNT_10 = 10; constexpr int BUCKET_COUNT_11 = 11; +const std::string CONTACTS_DATA_URI = "datashare:///com.ohos.contactsdataability"; + +// 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; + +constexpr int ERROR = -1; +constexpr int SUCCESS = 0; + +constexpr int PERMISSION_ERROR = 201; +constexpr int PARAMETER_ERROR = 401; + struct ValuesBucket { char** key = NULL; DataShare::CValueType* value = NULL; diff --git a/contactsCJ/include/hilog_wrapper_api.h b/contactsCJ/include/hilog_wrapper_api.h new file mode 100644 index 0000000..246e8ea --- /dev/null +++ b/contactsCJ/include/hilog_wrapper_api.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2021-2022 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_APP, LOG_DOMAIN, CONTACTSDATA_LOG_TAG}; + +#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 diff --git a/contactsCJ/src/contacts.cpp b/contactsCJ/src/contacts.cpp index 563350b..540e186 100644 --- a/contactsCJ/src/contacts.cpp +++ b/contactsCJ/src/contacts.cpp @@ -16,13 +16,11 @@ #include "ability_runtime/cj_ability_context.h" #include "data_share_predicates_impl.h" #include "contacts.h" -#include "contacts_api.h" // from contacts_data/contacts -#include "contacts_control.h" // from contacts_data/contacts -#include "contacts_napi_common.h" // from contacts_data/contacts -#include "contacts_telephony_permission.h" // from contacts_data/contacts +#include "contacts_control.h" +#include "contacts_permission.h" #include "datashare_helper.h" #include "datashare_predicates.h" -#include "hilog_wrapper_api.h" // from contacts_data/contacts +#include "hilog_wrapper_api.h" #include "native/ffi_remote_data.h" using namespace OHOS; @@ -43,7 +41,7 @@ bool IsInvalidId(int id) std::shared_ptr dsHelperFromContext(int64_t contextId) { sptr context = FFIData::GetData(contextId); - return DataShareHelper::Creator(context->GetToken(), ContactsApi::CONTACTS_DATA_URI); + return DataShareHelper::Creator(context->GetToken(), CONTACTS_DATA_URI); } int64_t Contacts::CJaddContact(int64_t contextId, DataShareValuesBucket rawContact, @@ -54,11 +52,11 @@ int64_t Contacts::CJaddContact(int64_t contextId, DataShareValuesBucket rawConta std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJaddContact Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; - return ContactsApi::Contacts::INVALID_CONTACT_ID; + *errCode = PERMISSION_ERROR; + return Contacts::INVALID_CONTACT_ID; } - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; int rawId = contactsControl.RawContactInsert(dataShareHelper, rawContact); unsigned int size = contactData.size(); @@ -72,12 +70,12 @@ int64_t Contacts::CJaddContact(int64_t contextId, DataShareValuesBucket rawConta dataShareHelper = nullptr; *errCode = code; - if (code == ContactsApi::SUCCESS) { + if (code == SUCCESS) { HILOG_INFO("CJaddContact returns id = %{public}d", rawId); return rawId; } else { HILOG_ERROR("CJaddContact gets errCode = %{public}d and returns id = -1", code); - return ContactsApi::Contacts::INVALID_CONTACT_ID; + return Contacts::INVALID_CONTACT_ID; } } @@ -86,14 +84,14 @@ void Contacts::CJdeleteContact(int64_t contextId, int64_t predicatesId, int32_t std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJdeleteContact Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return; } std::shared_ptr predicates = FFIData::GetData(predicatesId)->GetPredicates(); - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; int code = contactsControl.ContactDelete(dataShareHelper, *predicates); dataShareHelper->Release(); @@ -116,24 +114,39 @@ DataSharePredicates buildQueryDataPredicates(int64_t contactId) return predicates; } +int GetRawIdByResultSet(const std::shared_ptr &resultSet) +{ + if (resultSet == nullptr) { + return -1; + } + int resultSetNum = resultSet->GoToFirstRow(); + int intValue = 0; + while (resultSetNum == OHOS::NativeRdb::E_OK) { + resultSet->GetInt(0, intValue); + resultSetNum = resultSet->GoToNextRow(); + } + resultSet->Close(); + return intValue; +} + void Contacts::CJupdateContact(int64_t contextId, int64_t contactId, std::vector contactData, int64_t predicatesId, int32_t *errCode) { std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJupdateContact Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return; } if (IsInvalidId(contactId)) { HILOG_ERROR("CJupdateContact Parameter invalid! %{public}lld", static_cast(contactId)); - *errCode = ContactsApi::PARAMETER_ERROR; + *errCode = PARAMETER_ERROR; return; } std::shared_ptr deletePredicates = FFIData::GetData(predicatesId)->GetPredicates(); - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; // query raw_contact_id std::vector queryDataColumns; @@ -142,10 +155,10 @@ void Contacts::CJupdateContact(int64_t contextId, int64_t contactId, std::vector std::shared_ptr resultSet = contactsControl.ContactQuery(dataShareHelper, queryDataColumns, queryDataPredicates); - int rawId = ContactsApi::GetRawIdByResultSet(resultSet); + int rawId = GetRawIdByResultSet(resultSet); if (rawId <= 0) { HILOG_ERROR("CJupdateContact contact rawId equals %{public}d", rawId); - *errCode = ContactsApi::ERROR; + *errCode = ERROR; dataShareHelper->Release(); dataShareHelper = nullptr; @@ -189,26 +202,26 @@ DataSharePredicates buildIsLocalContactPredicates(int64_t id) bool Contacts::CJisLocalContact(int64_t contextId, int64_t contactId, int32_t *errCode) { - ContactsApi::ContactsTelephonyPermission permission; - if (!permission.CheckPermission(ContactsApi::Permission::READ_CONTACTS)) { + ContactsTelephonyPermission permission; + if (!permission.CheckPermission(Permission::READ_CONTACTS)) { HILOG_ERROR("CJisLocalContact Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return false; } if (IsInvalidId(contactId)) { HILOG_ERROR("CJisLocalContact Parameter invalid! %{public}lld", static_cast(contactId)); - *errCode = ContactsApi::PARAMETER_ERROR; + *errCode = PARAMETER_ERROR; return false; } std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJisLocalContact Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return false; } - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; DataSharePredicates predicates = buildIsLocalContactPredicates(contactId); std::vector columns; @@ -240,26 +253,26 @@ DataSharePredicates buildIsMyCardPredicates(int64_t id) bool Contacts::CJisMyCard(int64_t contextId, int64_t contactId, int32_t *errCode) { - ContactsApi::ContactsTelephonyPermission permission; - if (!permission.CheckPermission(ContactsApi::Permission::READ_CONTACTS)) { + ContactsTelephonyPermission permission; + if (!permission.CheckPermission(Permission::READ_CONTACTS)) { HILOG_ERROR("CJisMyCard Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return false; } if (IsInvalidId(contactId)) { HILOG_ERROR("CJisMyCard Parameter invalid! %{public}lld", static_cast(contactId)); - *errCode = ContactsApi::PARAMETER_ERROR; + *errCode = PARAMETER_ERROR; return false; } std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJisMyCard Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return false; } - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; DataSharePredicates predicates = buildIsMyCardPredicates(contactId); std::vector columns; @@ -282,23 +295,23 @@ bool Contacts::CJisMyCard(int64_t contextId, int64_t contactId, int32_t *errCode ContactsData* Contacts::CJqueryMyCard(int64_t contextId, int64_t predicatesId, int32_t *errCode) { - ContactsApi::ContactsTelephonyPermission permission; - if (!permission.CheckPermission(ContactsApi::Permission::READ_CONTACTS)) { + ContactsTelephonyPermission permission; + if (!permission.CheckPermission(Permission::READ_CONTACTS)) { HILOG_ERROR("CJqueryMyCard Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJqueryMyCard Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } std::shared_ptr predicates = FFIData::GetData(predicatesId)->GetPredicates(); - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; std::vector columns; std::shared_ptr resultSet = contactsControl.MyCardQuery(dataShareHelper, columns, *predicates); @@ -312,23 +325,23 @@ ContactsData* Contacts::CJqueryMyCard(int64_t contextId, int64_t predicatesId, i GroupsData* Contacts::CJqueryGroups(int64_t contextId, int64_t predicatesId, int32_t *errCode) { - ContactsApi::ContactsTelephonyPermission permission; - if (!permission.CheckPermission(ContactsApi::Permission::READ_CONTACTS)) { + ContactsTelephonyPermission permission; + if (!permission.CheckPermission(Permission::READ_CONTACTS)) { HILOG_ERROR("CJqueryGroups Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJqueryGroups Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } std::shared_ptr predicates = FFIData::GetData(predicatesId)->GetPredicates(); - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; std::vector columns; std::shared_ptr resultSet = contactsControl.GroupsQuery(dataShareHelper, columns, *predicates); @@ -342,21 +355,21 @@ GroupsData* Contacts::CJqueryGroups(int64_t contextId, int64_t predicatesId, int HoldersData* Contacts::CJqueryHolders(int64_t contextId, int32_t *errCode) { - ContactsApi::ContactsTelephonyPermission permission; - if (!permission.CheckPermission(ContactsApi::Permission::READ_CONTACTS)) { + ContactsTelephonyPermission permission; + if (!permission.CheckPermission(Permission::READ_CONTACTS)) { HILOG_ERROR("CJqueryHolders Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJqueryHolders Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; DataSharePredicates predicates; std::vector columns; @@ -371,23 +384,23 @@ HoldersData* Contacts::CJqueryHolders(int64_t contextId, int32_t *errCode) ContactsData* Contacts::CJqueryContacts(int64_t contextId, int64_t predicatesId, int32_t *errCode) { - ContactsApi::ContactsTelephonyPermission permission; - if (!permission.CheckPermission(ContactsApi::Permission::READ_CONTACTS)) { + ContactsTelephonyPermission permission; + if (!permission.CheckPermission(Permission::READ_CONTACTS)) { HILOG_ERROR("CJqueryContacts Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } std::shared_ptr dataShareHelper = dsHelperFromContext(contextId); if (dataShareHelper == nullptr) { HILOG_ERROR("CJqueryContacts Permission denied!"); - *errCode = ContactsApi::PERMISSION_ERROR; + *errCode = PERMISSION_ERROR; return nullptr; } std::shared_ptr predicates = FFIData::GetData(predicatesId)->GetPredicates(); - ContactsApi::ContactsControl contactsControl; + ContactsControl contactsControl; std::vector columns; std::shared_ptr resultSet = diff --git a/contactsCJ/src/contacts_control.cpp b/contactsCJ/src/contacts_control.cpp new file mode 100644 index 0000000..b78f738 --- /dev/null +++ b/contactsCJ/src/contacts_control.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2021-2022 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 ContactsFfi { +ContactsControl::ContactsControl(void) +{ +} + +ContactsControl::~ContactsControl() +{ +} + +int ContactsControl::RawContactInsert(std::shared_ptr dataShareHelper, + DataShare::DataShareValuesBucket rawContactValues) +{ + int code = 0; + OHOS::Uri uriRawContact("datashare:///com.ohos.contactsdataability/contacts/raw_contact"); + code = dataShareHelper->Insert(uriRawContact, rawContactValues); + HILOG_INFO("ContactsControl::RawContactInsert insert code %{public}d", code); + rawContactValues.Clear(); + return code; +} + +int ContactsControl::ContactDataInsert(std::shared_ptr dataShareHelper, + std::vector contactDataValues) +{ + int code = 0; + OHOS::Uri uriContactData("datashare:///com.ohos.contactsdataability/contacts/contact_data"); + code = dataShareHelper->BatchInsert(uriContactData, contactDataValues); + HILOG_INFO("ContactsControl::ContactDataInsert insert code %{public}d", code); + contactDataValues.clear(); + return code; +} +int ContactsControl::ContactDataDelete(std::shared_ptr dataShareHelper, + DataShare::DataSharePredicates predicates) +{ + int code = 0; + OHOS::Uri uriContactData("datashare:///com.ohos.contactsdataability/contacts/contact_data"); + code = dataShareHelper->Delete(uriContactData, predicates); + HILOG_INFO("ContactsControl::ContactDataDelete delete code %{public}d", code); + return code; +} + +int ContactsControl::RawContactUpdate(std::shared_ptr dataShareHelper, + DataShare::DataShareValuesBucket updateValues, DataShare::DataSharePredicates predicates) +{ + int code = 0; + OHOS::Uri uriRawContact("datashare:///com.ohos.contactsdataability/contacts/raw_contact"); + code = dataShareHelper->Update(uriRawContact, predicates, updateValues); + HILOG_INFO("ContactsControl::RawContactUpdate Update code %{public}d", code); + return code; +} + +int ContactsControl::ContactDataUpdate(std::shared_ptr dataShareHelper, + DataShare::DataShareValuesBucket updateValues, DataShare::DataSharePredicates predicates) +{ + int code = 0; + OHOS::Uri uriContactData("datashare:///com.ohos.contactsdataability/contacts/contact_data"); + code = dataShareHelper->Update(uriContactData, predicates, updateValues); + HILOG_INFO("ContactsControl::ContactDataUpdate Update code %{public}d", code); + return code; +} + +int ContactsControl::ContactDelete(std::shared_ptr dataShareHelper, + DataShare::DataSharePredicates predicates) +{ + int code = 0; + OHOS::Uri uriContact("datashare:///com.ohos.contactsdataability/contacts/contact"); + code = dataShareHelper->Delete(uriContact, predicates); + HILOG_INFO("ContactsControl::ContactDelete Delete code %{public}d", code); + return code; +} + +std::shared_ptr ContactsControl::HolderQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates) +{ + std::shared_ptr resultSet; + OHOS::Uri uriContact("datashare:///com.ohos.contactsdataability/contacts/account"); + resultSet = dataShareHelper->Query(uriContact, predicates, columns); + return resultSet; +} + +std::shared_ptr ContactsControl::ContactQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates) +{ + HILOG_INFO("ContactsControl::ContactQuery is start"); + std::shared_ptr resultSet; + OHOS::Uri uriContact("datashare:///com.ohos.contactsdataability/contacts/contact_data"); + resultSet = dataShareHelper->Query(uriContact, predicates, columns); + return resultSet; +} + +std::shared_ptr ContactsControl::ContactDataQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates) +{ + std::shared_ptr resultSet; + OHOS::Uri uriContactData("datashare:///com.ohos.contactsdataability/contacts/contact_data"); + resultSet = dataShareHelper->Query(uriContactData, predicates, columns); + return resultSet; +} + +std::shared_ptr ContactsControl::GroupsQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates) +{ + std::shared_ptr resultSet; + OHOS::Uri uriGroups("datashare:///com.ohos.contactsdataability/contacts/groups"); + resultSet = dataShareHelper->Query(uriGroups, predicates, columns); + return resultSet; +} + +std::shared_ptr ContactsControl::MyCardQuery( + std::shared_ptr dataShareHelper, std::vector columns, + DataShare::DataSharePredicates predicates) +{ + std::shared_ptr resultSet; + OHOS::Uri uriProfileContact("datashare:///com.ohos.contactsdataability/profile/contact_data"); + resultSet = dataShareHelper->Query(uriProfileContact, predicates, columns); + return resultSet; +} +} // namespace ContactsApi +} // namespace OHOS \ No newline at end of file diff --git a/contactsCJ/src/contacts_permission.cpp b/contactsCJ/src/contacts_permission.cpp new file mode 100644 index 0000000..de9324f --- /dev/null +++ b/contactsCJ/src/contacts_permission.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2023 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_permission.h" + +#include "accesstoken_kit.h" +#include "bundle_mgr_interface.h" +#include "hilog_wrapper.h" +#include "iservice_registry.h" +#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" +#include "system_ability_definition.h" +#include "privacy_kit.h" +#include "tokenid_kit.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace ContactsFfi { + +using namespace Security::AccessToken; + +ContactsTelephonyPermission::ContactsTelephonyPermission(void) +{ +} + +ContactsTelephonyPermission::~ContactsTelephonyPermission() +{ +} + +/** + * @brief Permission check by callingUid. + * @param permissionName permission name. + * @return Returns true on success, false on failure. + */ +bool ContactsTelephonyPermission::CheckPermission(const std::string &permissionName) +{ + if (permissionName.empty()) { + HILOG_ERROR("ContactsTelephonyPermission check failed, permission name is empty."); + return false; + } + + auto callerToken = IPCSkeleton::GetCallingTokenID(); + auto callerPid = IPCSkeleton::GetCallingPid(); + HILOG_INFO("contactsCheckPermission,get callerPid = %{public}d,permission = %{public}s,ts = %{public}lld", + callerPid, permissionName.c_str(), time(NULL)); + auto tokenType = AccessTokenKit::GetTokenTypeFlag(callerToken); + int result = PermissionState::PERMISSION_DENIED; + if (tokenType == ATokenTypeEnum::TOKEN_NATIVE) { + result = PermissionState::PERMISSION_GRANTED; + } else if (tokenType == ATokenTypeEnum::TOKEN_HAP) { + result = AccessTokenKit::VerifyAccessToken(callerToken, permissionName); + } else { + HILOG_ERROR("ContactsTelephonyPermission check failed"); + } + + if (permissionName == Permission::READ_CALL_LOG + || permissionName == Permission::READ_CONTACTS || permissionName == Permission::WRITE_CONTACTS + || permissionName == Permission::OHOS_PERMISSION_MANAGE_VOICEMAIL) { + if (tokenType == ATokenTypeEnum::TOKEN_HAP) { + bool status = result == PermissionState::PERMISSION_GRANTED; + int32_t successCount = status ? 1 : 0; + int32_t failCount = status ? 0 : 1; + int32_t ret = PrivacyKit::AddPermissionUsedRecord(callerToken, permissionName, successCount, failCount); + if (ret != 0) { + HILOG_INFO("AddPermissionUsedRecord failed, permissionName = %{public}s, callerPid = %{public}d," + "successCount = %{public}d,failCount = %{public}d,ret = %{public}d", permissionName.c_str(), + callerPid, successCount, failCount, ret); + } + } + } + + if (result != PermissionState::PERMISSION_GRANTED) { + HILOG_ERROR("ContactsTelephonyPermission check failed"); + return false; + } + return true; +} +} // namespace Telephony +} // namespace OHOS \ No newline at end of file diff --git a/contactsCJ/src/contacts_utils.cpp b/contactsCJ/src/contacts_utils.cpp index e370237..90cda33 100644 --- a/contactsCJ/src/contacts_utils.cpp +++ b/contactsCJ/src/contacts_utils.cpp @@ -14,7 +14,6 @@ */ #include "securec.h" -#include "contacts_napi_common.h" // from contacts_data/contacts #include "contacts_utils.h" using namespace OHOS; @@ -27,20 +26,20 @@ namespace ContactsFfi { // return true if succeeded; after it b is fully allocated or completely empty with errCode set bool allocBucket(ValuesBucket* b, int total, int32_t *errCode) { - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { return false; } if (total > 0) { b->size = total; b->key = (char**) malloc(total * sizeof(char*)); if (b->key == nullptr) { - *errCode = ContactsApi::ERROR; + *errCode = ERROR; b->freeContent(); // actually. there is nothing to free, just set size to 0 return false; } b->value = (struct CValueType*) malloc(total * sizeof(struct CValueType)); if (b->value == nullptr) { - *errCode = ContactsApi::ERROR; + *errCode = ERROR; b->freeContent(); return false; } @@ -118,11 +117,11 @@ char* TransformFromString(std::string &str, int32_t* errCode) int64_t len = str.size() + 1; char* retValue = static_cast(malloc(len)); if (retValue == nullptr) { - *errCode = ContactsApi::ERROR; + *errCode = ERROR; return nullptr; } *errCode = memcpy_s(retValue, len, str.c_str(), len); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { free(retValue); retValue = nullptr; } @@ -132,7 +131,7 @@ char* TransformFromString(std::string &str, int32_t* errCode) void PutSingleString(ValuesBucket &bucket, int idx, std::string key, std::string val, int32_t *errCode) { bucket.key[idx] = TransformFromString(key, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { return; } bucket.value[idx].tag = static_cast(DataType::TYPE_STRING); @@ -148,7 +147,7 @@ ValuesBucket singleStringAsValueBucket(std::string contentType, std::string valu PutSingleString(b, BUCKET_IDX_0, "content_type", contentType, errCode); PutSingleString(b, BUCKET_IDX_1, "detail_info", value, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -165,7 +164,7 @@ void PutResultValue(ValuesBucket &bucket, int idx, std::string contentStoreKey, resultSet->GetDataType(columnIndex, columnType); bucket.key[idx] = TransformFromString(contentStoreKey, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { return; } @@ -176,7 +175,7 @@ void PutResultValue(ValuesBucket &bucket, int idx, std::string contentStoreKey, std::string stringValue; resultSet->GetString(columnIndex, stringValue); bucket.value[idx].string = TransformFromString(stringValue, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { return; } } else if (columnType == DataType::TYPE_INTEGER) { @@ -212,7 +211,7 @@ ValuesBucket resultSetAsEmail(std::shared_ptr &resultSet, in PutResultValue(b, BUCKET_IDX_3, resultSet, "custom_data", errCode); PutResultValue(b, BUCKET_IDX_4, resultSet, "extend7", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -241,7 +240,7 @@ ValuesBucket resultSetAsName(std::shared_ptr &resultSet, int PutResultValue(b, BUCKET_IDX_8, resultSet, "given_name_phonetic", errCode); PutResultValue(b, BUCKET_IDX_9, resultSet, "phonetic_name", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -262,7 +261,7 @@ ValuesBucket resultSetAsPortrait(std::shared_ptr &resultSet, PutSingleString(b, BUCKET_IDX_0, "content_type", "photo", errCode); PutResultValue(b, BUCKET_IDX_1, resultSet, "detail_info", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -285,7 +284,7 @@ ValuesBucket resultSetAsEvent(std::shared_ptr &resultSet, in PutResultValue(b, BUCKET_IDX_2, resultSet, "custom_data", errCode); PutResultValue(b, BUCKET_IDX_3, resultSet, "extend7", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -307,7 +306,7 @@ ValuesBucket resultSetAsGroup(std::shared_ptr &resultSet, in PutResultValue(b, BUCKET_IDX_1, resultSet, "detail_info", errCode); PutResultValue(b, BUCKET_IDX_2, resultSet, "group_name", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -330,7 +329,7 @@ ValuesBucket resultSetAsImAddress(std::shared_ptr &resultSet PutResultValue(b, BUCKET_IDX_2, resultSet, "custom_data", errCode); PutResultValue(b, BUCKET_IDX_3, resultSet, "extend7", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -353,7 +352,7 @@ ValuesBucket resultSetAsPhone(std::shared_ptr &resultSet, in PutResultValue(b, BUCKET_IDX_2, resultSet, "custom_data", errCode); PutResultValue(b, BUCKET_IDX_3, resultSet, "extend7", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -383,7 +382,7 @@ ValuesBucket resultSetAsPostAddress(std::shared_ptr &resultS PutResultValue(b, BUCKET_IDX_9, resultSet, "custom_data", errCode); PutResultValue(b, BUCKET_IDX_10, resultSet, "extend7", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -406,7 +405,7 @@ ValuesBucket resultSetAsRelation(std::shared_ptr &resultSet, PutResultValue(b, BUCKET_IDX_2, resultSet, "custom_data", errCode); PutResultValue(b, BUCKET_IDX_3, resultSet, "extend7", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -429,7 +428,7 @@ ValuesBucket resultSetAsSipAddress(std::shared_ptr &resultSe PutResultValue(b, BUCKET_IDX_2, resultSet, "custom_data", errCode); PutResultValue(b, BUCKET_IDX_3, resultSet, "extend7", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -450,7 +449,7 @@ ValuesBucket resultSetAsWebsite(std::shared_ptr &resultSet, PutSingleString(b, BUCKET_IDX_0, "content_type", "website", errCode); PutResultValue(b, BUCKET_IDX_1, resultSet, "detail_info", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -471,7 +470,7 @@ ValuesBucket resultSetAsNickname(std::shared_ptr &resultSet, PutSingleString(b, BUCKET_IDX_0, "content_type", "nickname", errCode); PutResultValue(b, BUCKET_IDX_1, resultSet, "detail_info", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -492,7 +491,7 @@ ValuesBucket resultSetAsNote(std::shared_ptr &resultSet, int PutSingleString(b, BUCKET_IDX_0, "content_type", "note", errCode); PutResultValue(b, BUCKET_IDX_1, resultSet, "detail_info", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -514,7 +513,7 @@ ValuesBucket resultSetAsOrganization(std::shared_ptr &result PutResultValue(b, BUCKET_IDX_1, resultSet, "detail_info", errCode); PutResultValue(b, BUCKET_IDX_2, resultSet, "position", errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { b.freeContent(); return b; } @@ -534,20 +533,20 @@ void addResultSetAsValuesBucket(std::vector contactData, resultSet->GetColumnIndex(typeId, columnIndexType); resultSet->GetInt(columnIndexType, typeIdValue); switch (typeIdValue) { - case ContactsApi::EMAIL: contactData.push_back(resultSetAsEmail(resultSet, errCode)); return; - case ContactsApi::NAME: contactData.push_back(resultSetAsName(resultSet, errCode)); return; - case ContactsApi::PHOTO: contactData.push_back(resultSetAsPortrait(resultSet, errCode)); return; - case ContactsApi::CONTACT_EVENT: contactData.push_back(resultSetAsEvent(resultSet, errCode)); return; - case ContactsApi::GROUP_MEMBERSHIP: contactData.push_back(resultSetAsGroup(resultSet, errCode)); return; - case ContactsApi::IM: contactData.push_back(resultSetAsImAddress(resultSet, errCode)); return; - case ContactsApi::PHONE: contactData.push_back(resultSetAsPhone(resultSet, errCode)); return; - case ContactsApi::POSTAL_ADDRESS: contactData.push_back(resultSetAsPostAddress(resultSet, errCode)); return; - case ContactsApi::RELATION: contactData.push_back(resultSetAsRelation(resultSet, errCode)); return; - case ContactsApi::SIP_ADDRESS: contactData.push_back(resultSetAsSipAddress(resultSet, errCode)); return; - case ContactsApi::WEBSITE: contactData.push_back(resultSetAsWebsite(resultSet, errCode)); return; - case ContactsApi::NICKNAME: contactData.push_back(resultSetAsNickname(resultSet, errCode)); return; - case ContactsApi::NOTE: contactData.push_back(resultSetAsNote(resultSet, errCode)); return; - case ContactsApi::ORGANIZATION: contactData.push_back(resultSetAsOrganization(resultSet, errCode)); return; + case EMAIL: contactData.push_back(resultSetAsEmail(resultSet, errCode)); return; + case NAME: contactData.push_back(resultSetAsName(resultSet, errCode)); return; + case PHOTO: contactData.push_back(resultSetAsPortrait(resultSet, errCode)); return; + case CONTACT_EVENT: contactData.push_back(resultSetAsEvent(resultSet, errCode)); return; + case GROUP_MEMBERSHIP: contactData.push_back(resultSetAsGroup(resultSet, errCode)); return; + case IM: contactData.push_back(resultSetAsImAddress(resultSet, errCode)); return; + case PHONE: contactData.push_back(resultSetAsPhone(resultSet, errCode)); return; + case POSTAL_ADDRESS: contactData.push_back(resultSetAsPostAddress(resultSet, errCode)); return; + case RELATION: contactData.push_back(resultSetAsRelation(resultSet, errCode)); return; + case SIP_ADDRESS: contactData.push_back(resultSetAsSipAddress(resultSet, errCode)); return; + case WEBSITE: contactData.push_back(resultSetAsWebsite(resultSet, errCode)); return; + case NICKNAME: contactData.push_back(resultSetAsNickname(resultSet, errCode)); return; + case NOTE: contactData.push_back(resultSetAsNote(resultSet, errCode)); return; + case ORGANIZATION: contactData.push_back(resultSetAsOrganization(resultSet, errCode)); return; default: return; } } @@ -559,14 +558,14 @@ bool allocateDataForContact(ContactsData* allContacts, int contactIndex, int con int bucketIndex = 0; // consider passing contactId as integer value ValuesBucket idBucket = singleStringAsValueBucket("id", std::to_string(contactId), errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { free(allContacts->contactsData[contactIndex].data); allContacts->contactsData[contactIndex].bucketCount = 0; allContacts->contactsData[contactIndex].data = nullptr; return false; } ValuesBucket searchKeyBucket = singleStringAsValueBucket("key", searchKey, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { idBucket.freeContent(); free(allContacts->contactsData[contactIndex].data); allContacts->contactsData[contactIndex].bucketCount = 0; @@ -622,7 +621,7 @@ ContactsData* allocCollectedContacts(std::map> re ContactsData* allContacts = (struct ContactsData*) malloc(sizeof(struct ContactsData)); if (allContacts == nullptr) { HILOG_ERROR("ContactUtils::allocCollectedContacts fail to mem alloc"); - *errCode = ContactsApi::ERROR; + *errCode = ERROR; return nullptr; } @@ -636,7 +635,7 @@ ContactsData* allocCollectedContacts(std::map> re if (allContacts->contactsData == nullptr) { free(allContacts); HILOG_ERROR("ContactUtils::allocCollectedContacts fail to mem alloc"); - *errCode = ContactsApi::ERROR; + *errCode = ERROR; return nullptr; } allContacts->contactsCount = totalContacts; @@ -648,7 +647,7 @@ ContactsData* allocCollectedContacts(std::map> re std::vector contactDataVector = it->second; std::string searchKey = quickSearchMap.find(contactId)->second; - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { allContacts->contactsData[contactIndex].bucketCount = 0; allContacts->contactsData[contactIndex].data = nullptr; continue; @@ -658,14 +657,14 @@ ContactsData* allocCollectedContacts(std::map> re allContacts->contactsData[contactIndex].data = (struct ValuesBucket*) malloc(totalBuckets * sizeof(struct ValuesBucket)); if (allContacts->contactsData[contactIndex].data == nullptr) { - *errCode = ContactsApi::ERROR; + *errCode = ERROR; continue; } allocateDataForContact(allContacts, contactIndex, contactId, searchKey, contactDataVector, errCode); } - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { releaseAllContacts(allContacts); releaseRresultSetMapBuckets(resultSetMap); return nullptr; @@ -700,7 +699,7 @@ ContactsData* parseResultSetForContacts(std::shared_ptr &res std::vector contactData = GetResultMapValue(resultSetMap, contactIdValue); PutQuickSearchKey(resultSet, quickSearchMap, contactIdValue); addResultSetAsValuesBucket(contactData, resultSet, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { HILOG_ERROR("ContactUtils::parseResultSetForContacts fail to mem alloc"); break; } @@ -708,7 +707,7 @@ ContactsData* parseResultSetForContacts(std::shared_ptr &res } resultSet->Close(); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { std::map>::iterator it; for (it = resultSetMap.begin(); it != resultSetMap.end(); it++) { std::vector contactDataVector = it->second; @@ -731,7 +730,7 @@ void resultSetAsGroup(ValuesBucket* groups, int idx, std::shared_ptr &resultS GroupsData* allGroups = (GroupsData*) malloc(sizeof(GroupsData)); if (allGroups == nullptr) { HILOG_ERROR("ContactUtils::parseResultSetForGroups fail to mem alloc"); - *errCode = ContactsApi::ERROR; + *errCode = ERROR; return nullptr; } allGroups->data = (struct ValuesBucket*) malloc(totalGroups * sizeof(struct ValuesBucket)); if (allGroups->data == nullptr) { free(allGroups); HILOG_ERROR("ContactUtils::parseResultSetForGroups fail to mem alloc"); - *errCode = ContactsApi::ERROR; + *errCode = ERROR; return NULL; } allGroups->bucketCount = totalGroups; @@ -825,7 +824,7 @@ GroupsData* parseResultSetForGroups(std::shared_ptr &resultS int count = 0; while (resultSetNum == 0) { resultSetAsGroup(allGroups->data, count, resultSet, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { break; } resultSetNum = resultSet->GoToNextRow(); @@ -833,7 +832,7 @@ GroupsData* parseResultSetForGroups(std::shared_ptr &resultS } resultSet->Close(); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { allGroups->freeContent(); free(allGroups); allGroups = nullptr; @@ -859,14 +858,14 @@ HoldersData* parseResultSetForHolders(std::shared_ptr &resul HoldersData* allHolders = (HoldersData*) malloc(sizeof(HoldersData)); if (allHolders == nullptr) { HILOG_ERROR("ContactUtils::parseResultSetForHolders fail to mem alloc"); - *errCode = ContactsApi::ERROR; + *errCode = ERROR; return nullptr; } allHolders->data = (struct ValuesBucket*) malloc(totalHolders * sizeof(struct ValuesBucket)); if (allHolders->data == nullptr) { free(allHolders); HILOG_ERROR("ContactUtils::parseResultSetForHolders fail to mem alloc"); - *errCode = ContactsApi::ERROR; + *errCode = ERROR; return nullptr; } allHolders->bucketCount = totalHolders; @@ -875,7 +874,7 @@ HoldersData* parseResultSetForHolders(std::shared_ptr &resul int count = 0; while (resultSetNum == 0) { resultSetAsHolder(allHolders->data, count, resultSet, errCode); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { break; } resultSetNum = resultSet->GoToNextRow(); @@ -883,7 +882,7 @@ HoldersData* parseResultSetForHolders(std::shared_ptr &resul } resultSet->Close(); - if (*errCode != ContactsApi::SUCCESS) { + if (*errCode != SUCCESS) { allHolders->freeContent(); free(allHolders); allHolders = nullptr; -- Gitee