From cc900cb91e8aada7136e369b915aa3a6a9515b81 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 7 Aug 2025 20:32:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- bundle.json | 1 - .../characteristic_profile_filter_option.h | 77 ---- .../service_profile_filter_opotions.h | 70 ---- common/src/interfaces/accessee.cpp | 5 +- common/src/interfaces/accesser.cpp | 5 +- .../characteristic_profile_filter_option.cpp | 144 -------- .../service_profile_filter_opotions.cpp | 197 ----------- .../characteristic_profile_dao.h | 59 ---- .../profiledatamanager/service_profile_dao.h | 55 --- .../characteristic_profile_dao.cpp | 315 ----------------- .../service_profile_dao.cpp | 332 ------------------ .../unittest/device_profile_manager_test.cpp | 5 +- .../test/unittest/dp_subscribe_info_test.cpp | 2 +- 13 files changed, 9 insertions(+), 1258 deletions(-) delete mode 100644 common/include/interfaces/characteristic_profile_filter_option.h delete mode 100644 common/include/interfaces/service_profile_filter_opotions.h delete mode 100644 common/src/interfaces/characteristic_profile_filter_option.cpp delete mode 100644 common/src/interfaces/service_profile_filter_opotions.cpp delete mode 100644 services/core/include/profiledatamanager/characteristic_profile_dao.h delete mode 100644 services/core/include/profiledatamanager/service_profile_dao.h delete mode 100644 services/core/src/profiledatamanager/characteristic_profile_dao.cpp delete mode 100644 services/core/src/profiledatamanager/service_profile_dao.cpp diff --git a/bundle.json b/bundle.json index 1c011b60..89d339cb 100644 --- a/bundle.json +++ b/bundle.json @@ -13,7 +13,6 @@ "name": "device_info_manager", "subsystem": "deviceprofile", "features": [ - "device_info_manager_feature_coverage", "device_info_manager_supported_switch" ], "adapted_system_type": [ "standard" ], diff --git a/common/include/interfaces/characteristic_profile_filter_option.h b/common/include/interfaces/characteristic_profile_filter_option.h deleted file mode 100644 index 5a917536..00000000 --- a/common/include/interfaces/characteristic_profile_filter_option.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 OHOS_DP_CHARACTERISTIC_PROFILE_FILTER_OPTION_H -#define OHOS_DP_CHARACTERISTIC_PROFILE_FILTER_OPTION_H - -#include -#include -#include -#include "distributed_device_profile_constants.h" -#include "dp_parcel.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class CharacteristicProfileFilterOption : public DpParcel { -public: - CharacteristicProfileFilterOption(const int32_t userId, const std::string& accountld, - const std::string& deviceId, const std::string& wiseDeviceId, - const std::string& serviceId, const std::string& characteristicKey, - const std::vector& characteristicProfileIds, const int32_t serviceProfileId) - : userId_(userId), - accountld_(accountld), - deviceId_(deviceId), - wiseDeviceId_(wiseDeviceId), - serviceId_(serviceId), - characteristicKey_(characteristicKey), - characteristicProfileIds_(characteristicProfileIds), - serviceProfileId_(serviceProfileId) - {} - CharacteristicProfileFilterOption() = default; - ~CharacteristicProfileFilterOption() = default; - - std::string GetAccountld() const; - void SetAccountld(const std::string& accountld); - std::string GetServiceId() const; - void SetServiceId(const std::string& serviceId); - std::string GetWiseDeviceId() const; - void SetWiseDeviceId(const std::string& wiseDeviceId); - int32_t GetUserId() const; - void SetUserId(int32_t userId); - std::vector GetCharacteristicProfileIds() const; - void SetCharacteristicProfileIds(std::vector& characteristicProfileIds); - std::string GetCharacteristicKey() const; - void SetCharacteristicKey(std::string& characteristicKey); - std::string GetDeviceId() const; - void SetDeviceId(std::string& deviceId); - int32_t GetServiceProfileId() const; - void SetServiceProfileId(int32_t serviceProfileId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; - -private: - int32_t userId_ = DEFAULT_USER_ID; - std::string accountld_ = ""; - std::string deviceId_ = ""; - std::string wiseDeviceId_ = ""; - std::string serviceId_ = ""; - std::string characteristicKey_ = ""; - std::vector characteristicProfileIds_; - int32_t serviceProfileId_ = DEFAULT_SERVICE_PROFILE_ID; -}; -} // namespace DistributedDeviceProfile -} // namespace OHOS -#endif // OHOS_DP_CHARACTERISTIC_PROFILE_FILTER_OPTION_H diff --git a/common/include/interfaces/service_profile_filter_opotions.h b/common/include/interfaces/service_profile_filter_opotions.h deleted file mode 100644 index 9afaba07..00000000 --- a/common/include/interfaces/service_profile_filter_opotions.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 OHOS_DP_SERVICE_PROFILE_FILTER_OPTIONS_H -#define OHOS_DP_SERVICE_PROFILE_FILTER_OPTIONS_H - -#include -#include -#include - -#include "distributed_device_profile_constants.h" -#include "dp_parcel.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class ServiceProfileFilterOptions : public DpParcel { -public: - ServiceProfileFilterOptions(int32_t userId, std::string& accountId, std::string& deviceId, - const std::vector& wiseDeviceIds, const std::vector& serviceIds, - const std::vector& serviceProfileIds, const std::vector& deviceProfileIds); - ServiceProfileFilterOptions(); - ~ServiceProfileFilterOptions(); - - int32_t GetUserId() const; - void SetUserId(int32_t userId); - const std::string& GetAccountId() const; - void SetAccountId(const std::string& accountId); - const std::string& GetDeviceId() const; - void SetDeviceId(const std::string& deviceId); - const std::vector& GetWiseDeviceIds() const; - void SetWiseDeviceIds(const std::vector& wiseDeviceIds); - void AddWiseDeviceIds(const std::string& wiseDeviceId); - const std::vector& GetServiceIds() const; - void SetServiceIds(const std::vector& serviceIds); - void AddServiceIds(const std::string& serviceId); - const std::vector& GetServiceProfileIds() const; - void SetServiceProfileIds(const std::vector& serviceProfileIds); - void AddServiceProfileIds(int32_t serviceProfileId); - const std::vector& GetDeviceProfileIds() const; - void SetDeviceProfileIds(const std::vector& deviceProfileIds); - void AddDeviceProfileIds(int32_t deviceProfileId); - bool IsEmpty() const; - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; - -private: - int32_t userId_ = DEFAULT_USER_ID; - std::string accountId_ = ""; - std::string deviceId_ = ""; - std::vector wiseDeviceIds_; - std::vector serviceIds_; - std::vector serviceProfileIds_; - std::vector deviceProfileIds_; -}; -} // namespace DistributedDeviceProfile -} // namespace OHOS -#endif //OHOS_DP_SERVICE_PROFILE_FILTER_OPTIONS_H diff --git a/common/src/interfaces/accessee.cpp b/common/src/interfaces/accessee.cpp index d647404c..563f2ede 100644 --- a/common/src/interfaces/accessee.cpp +++ b/common/src/interfaces/accessee.cpp @@ -260,7 +260,8 @@ std::string Accessee::dump() const cJSON_AddStringToObject(json, ACCESSEE_ACCOUNT_ID.c_str(), ProfileUtils::GetAnonyString(accesseeAccountId_).c_str()); cJSON_AddNumberToObject(json, ACCESSEE_TOKEN_ID.c_str(), accesseeTokenId_); - cJSON_AddStringToObject(json, ACCESSEE_BUNDLE_NAME.c_str(), accesseeBundleName_.c_str()); + cJSON_AddStringToObject(json, ACCESSEE_BUNDLE_NAME.c_str(), + ProfileUtils::GetAnonyString(accesseeBundleName_).c_str()); cJSON_AddStringToObject(json, ACCESSEE_HAP_SIGNATURE.c_str(), accesseeHapSignature_.c_str()); cJSON_AddNumberToObject(json, ACCESSEE_BIND_LEVEL.c_str(), accesseeBindLevel_); cJSON_AddStringToObject(json, ACCESSEE_DEVICE_NAME.c_str(), @@ -283,4 +284,4 @@ std::string Accessee::dump() const return jsonStr; } } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/common/src/interfaces/accesser.cpp b/common/src/interfaces/accesser.cpp index 04346db5..ae4e3e56 100644 --- a/common/src/interfaces/accesser.cpp +++ b/common/src/interfaces/accesser.cpp @@ -258,7 +258,8 @@ std::string Accesser::dump() const cJSON_AddStringToObject(json, ACCESSER_ACCOUNT_ID.c_str(), ProfileUtils::GetAnonyString(accesserAccountId_).c_str()); cJSON_AddNumberToObject(json, ACCESSER_TOKEN_ID.c_str(), accesserTokenId_); - cJSON_AddStringToObject(json, ACCESSER_BUNDLE_NAME.c_str(), accesserBundleName_.c_str()); + cJSON_AddStringToObject(json, ACCESSER_BUNDLE_NAME.c_str(), + ProfileUtils::GetAnonyString(accesserBundleName_).c_str()); cJSON_AddStringToObject(json, ACCESSER_HAP_SIGNATURE.c_str(), accesserHapSignature_.c_str()); cJSON_AddNumberToObject(json, ACCESSER_BIND_LEVEL.c_str(), accesserBindLevel_); cJSON_AddStringToObject(json, ACCESSER_DEVICE_NAME.c_str(), @@ -281,4 +282,4 @@ std::string Accesser::dump() const return jsonStr; } } // namespace DistributedDeviceProfile -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/common/src/interfaces/characteristic_profile_filter_option.cpp b/common/src/interfaces/characteristic_profile_filter_option.cpp deleted file mode 100644 index 6d1e11d1..00000000 --- a/common/src/interfaces/characteristic_profile_filter_option.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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. - */ - -#include "characteristic_profile_filter_option.h" -#include "cJSON.h" -#include "distributed_device_profile_constants.h" -#include "ipc_utils.h" -#include "macro_utils.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { - const std::string TAG = "CharacteristicProfile"; -} -std::string CharacteristicProfileFilterOption::GetAccountld() const -{ - return accountld_; -} - -void CharacteristicProfileFilterOption::SetAccountld(const std::string& accountld) -{ - accountld_ = accountld; -} - -std::string CharacteristicProfileFilterOption::GetServiceId() const -{ - return serviceId_; -} - -void CharacteristicProfileFilterOption::SetServiceId(const std::string& serviceId) -{ - serviceId_ = serviceId; -} - -std::string CharacteristicProfileFilterOption::GetWiseDeviceId() const -{ - return wiseDeviceId_; -} - -void CharacteristicProfileFilterOption::SetWiseDeviceId(const std::string& wiseDeviceId) -{ - wiseDeviceId_ = wiseDeviceId; -} - -int32_t CharacteristicProfileFilterOption::GetUserId() const -{ - return userId_; -} - -void CharacteristicProfileFilterOption::SetUserId(int32_t userId) -{ - userId_ = userId; -} - -std::vector CharacteristicProfileFilterOption::GetCharacteristicProfileIds() const -{ - return characteristicProfileIds_; -} - -void CharacteristicProfileFilterOption::SetCharacteristicProfileIds(std::vector& characteristicProfileIds) -{ - characteristicProfileIds_ = characteristicProfileIds; -} - -std::string CharacteristicProfileFilterOption::GetCharacteristicKey() const -{ - return characteristicKey_; -} - -void CharacteristicProfileFilterOption::SetCharacteristicKey(std::string& characteristicKey) -{ - characteristicKey_ = characteristicKey; -} - -std::string CharacteristicProfileFilterOption::GetDeviceId() const -{ - return deviceId_; -} - -void CharacteristicProfileFilterOption::SetDeviceId(std::string& deviceId) -{ - deviceId_ = deviceId; -} - -int32_t CharacteristicProfileFilterOption::GetServiceProfileId() const -{ - return serviceProfileId_; -} - -void CharacteristicProfileFilterOption::SetServiceProfileId(int32_t serviceProfileId) -{ - serviceProfileId_ = serviceProfileId; -} - -bool CharacteristicProfileFilterOption::Marshalling(MessageParcel& parcel) const -{ - WRITE_HELPER_RET(parcel, Int32, userId_, false); - WRITE_HELPER_RET(parcel, String, accountld_, false); - WRITE_HELPER_RET(parcel, String, deviceId_, false); - WRITE_HELPER_RET(parcel, String, wiseDeviceId_, false); - WRITE_HELPER_RET(parcel, String, serviceId_, false); - WRITE_HELPER_RET(parcel, String, characteristicKey_, false); - WRITE_HELPER_RET(parcel, Int32, serviceProfileId_, false); - if (!IpcUtils::Marshalling(parcel, characteristicProfileIds_)) { - HILOGE("read parcel fail!"); - return false; - } - return true; -} - -bool CharacteristicProfileFilterOption::UnMarshalling(MessageParcel& parcel) -{ - READ_HELPER_RET(parcel, Int32, userId_, false); - READ_HELPER_RET(parcel, String, accountld_, false); - READ_HELPER_RET(parcel, String, deviceId_, false); - READ_HELPER_RET(parcel, String, wiseDeviceId_, false); - READ_HELPER_RET(parcel, String, serviceId_, false); - READ_HELPER_RET(parcel, String, characteristicKey_, false); - READ_HELPER_RET(parcel, Int32, serviceProfileId_, false); - if (!IpcUtils::UnMarshalling(parcel, characteristicProfileIds_)) { - HILOGE("read parcel fail!"); - return false; - } - return true; -} - -std::string CharacteristicProfileFilterOption::dump() const -{ - return ""; -} -} // namespace DistributedDeviceProfile -} // namespace OHOS diff --git a/common/src/interfaces/service_profile_filter_opotions.cpp b/common/src/interfaces/service_profile_filter_opotions.cpp deleted file mode 100644 index 3090b4f2..00000000 --- a/common/src/interfaces/service_profile_filter_opotions.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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. - */ - -#include "service_profile_filter_opotions.h" - -#include "cJSON.h" - -#include "distributed_device_profile_constants.h" -#include "ipc_utils.h" -#include "macro_utils.h" -#include "profile_utils.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { - const std::string TAG = "ServiceProfileFilterOptions"; -} -ServiceProfileFilterOptions::ServiceProfileFilterOptions(int32_t userId, std::string& accountId, - std::string& deviceId, const std::vector& wiseDeviceIds, - const std::vector& serviceIds, const std::vector& serviceProfileIds, - const std::vector& deviceProfileIds) - : userId_(userId), accountId_(accountId), deviceId_(deviceId), wiseDeviceIds_(wiseDeviceIds), - serviceIds_(serviceIds), serviceProfileIds_(serviceProfileIds), deviceProfileIds_(deviceProfileIds) -{ -} - -ServiceProfileFilterOptions::ServiceProfileFilterOptions() -{ -} - -ServiceProfileFilterOptions::~ServiceProfileFilterOptions() -{ -} - -int32_t ServiceProfileFilterOptions::GetUserId() const -{ - return userId_; -} - -void ServiceProfileFilterOptions::SetUserId(int32_t userId) -{ - userId_ = userId; -} - -const std::string& ServiceProfileFilterOptions::GetAccountId() const -{ - return accountId_; -} - -void ServiceProfileFilterOptions::SetAccountId(const std::string& accountId) -{ - accountId_ = accountId; -} - -const std::string& ServiceProfileFilterOptions::GetDeviceId() const -{ - return deviceId_; -} - -void ServiceProfileFilterOptions::SetDeviceId(const std::string& deviceId) -{ - deviceId_ = deviceId; -} - -const std::vector& ServiceProfileFilterOptions::GetWiseDeviceIds() const -{ - return wiseDeviceIds_; -} - -void ServiceProfileFilterOptions::SetWiseDeviceIds(const std::vector& wiseDeviceIds) -{ - wiseDeviceIds_ = wiseDeviceIds; -} - -const std::vector& ServiceProfileFilterOptions::GetServiceIds() const -{ - return serviceIds_; -} - -void ServiceProfileFilterOptions::SetServiceIds(const std::vector& serviceIds) -{ - serviceIds_ = serviceIds; -} - -const std::vector& ServiceProfileFilterOptions::GetServiceProfileIds() const -{ - return serviceProfileIds_; -} - -void ServiceProfileFilterOptions::SetServiceProfileIds(const std::vector& serviceProfileIds) -{ - serviceProfileIds_ = serviceProfileIds; -} - -const std::vector& ServiceProfileFilterOptions::GetDeviceProfileIds() const -{ - return deviceProfileIds_; -} - -void ServiceProfileFilterOptions::SetDeviceProfileIds(const std::vector& deviceProfileIds) -{ - deviceProfileIds_ = deviceProfileIds; -} - -bool ServiceProfileFilterOptions::Marshalling(MessageParcel& parcel) const -{ - WRITE_HELPER_RET(parcel, Int32, userId_, false); - WRITE_HELPER_RET(parcel, String, accountId_, false); - WRITE_HELPER_RET(parcel, String, deviceId_, false); - if (!IpcUtils::Marshalling(parcel, wiseDeviceIds_)) { - HILOGE("dp write parcel fail"); - return false; - } - if (!IpcUtils::Marshalling(parcel, serviceIds_)) { - HILOGE("dp write parcel fail"); - return false; - } - if (!IpcUtils::Marshalling(parcel, serviceProfileIds_)) { - HILOGE("dp write parcel fail"); - return false; - } - if (!IpcUtils::Marshalling(parcel, deviceProfileIds_)) { - HILOGE("dp write parcel fail"); - return false; - } - return true; -} - -bool ServiceProfileFilterOptions::UnMarshalling(MessageParcel& parcel) -{ - READ_HELPER_RET(parcel, Int32, userId_, false); - READ_HELPER_RET(parcel, String, accountId_, false); - READ_HELPER_RET(parcel, String, deviceId_, false); - if (!IpcUtils::UnMarshalling(parcel, wiseDeviceIds_)) { - HILOGE("dp read parcel fail"); - return false; - } - if (!IpcUtils::UnMarshalling(parcel, serviceIds_)) { - HILOGE("dp read parcel fail"); - return false; - } - if (!IpcUtils::UnMarshalling(parcel, serviceProfileIds_)) { - HILOGE("dp read parcel fail"); - return false; - } - if (!IpcUtils::UnMarshalling(parcel, deviceProfileIds_)) { - HILOGE("dp read parcel fail"); - return false; - } - return true; -} - -bool ServiceProfileFilterOptions::IsEmpty() const -{ - return deviceId_.empty() && wiseDeviceIds_.empty() && serviceIds_.empty() && userId_ == DEFAULT_USER_ID && - serviceProfileIds_.empty() && accountId_.empty() && deviceProfileIds_.empty(); -} - -void ServiceProfileFilterOptions::AddWiseDeviceIds(const std::string& wiseDeviceId) -{ - wiseDeviceIds_.emplace_back(wiseDeviceId); -} - -void ServiceProfileFilterOptions::AddServiceIds(const std::string& serviceId) -{ - serviceIds_.emplace_back(serviceId); -} - -void ServiceProfileFilterOptions::AddServiceProfileIds(int32_t serviceProfileId) -{ - serviceProfileIds_.emplace_back(serviceProfileId); -} - -void ServiceProfileFilterOptions::AddDeviceProfileIds(int32_t deviceProfileId) -{ - deviceProfileIds_.emplace_back(deviceProfileId); -} - -std::string ServiceProfileFilterOptions::dump() const -{ - return ""; -} - -} // namespace DistributedDeviceProfile -} // namespace OHOS diff --git a/services/core/include/profiledatamanager/characteristic_profile_dao.h b/services/core/include/profiledatamanager/characteristic_profile_dao.h deleted file mode 100644 index 491cca76..00000000 --- a/services/core/include/profiledatamanager/characteristic_profile_dao.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 OHOS_DP_CHARACTERISTIC_PROFILE_DAO_H -#define OHOS_DP_CHARACTERISTIC_PROFILE_DAO_H - - -#include -#include -#include -#include -#include - -#include "characteristic_profile.h" -#include "characteristic_profile_filter_option.h" -#include "profile_data_rdb_adapter.h" -#include "single_instance.h" -#include "values_bucket.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -using namespace OHOS::NativeRdb; - -class CharacteristicProfileDao { - DECLARE_SINGLE_INSTANCE(CharacteristicProfileDao); -public: - int32_t Init(); - int32_t UnInit(); - int32_t PutCharacteristicProfile(CharacteristicProfile& charProfile); - int32_t GetCharacteristicProfiles(const CharacteristicProfileFilterOption& filterOptions, - std::vector& deviceProfiles); - int32_t DeleteCharacteristicProfile(const CharacteristicProfile& charProfile); - int32_t UpdateCharacteristicProfile(const CharacteristicProfile& oldProfile, - const CharacteristicProfile& newProfile); - -private: - void CreateQuerySqlAndCondition(const CharacteristicProfileFilterOption& filterOptions, - std::string& sql, std::vector& condition); - int32_t CharProfileToEntries(const CharacteristicProfile& charProfile, ValuesBucket& values); - int32_t ConvertToCharProfile(std::shared_ptr resultSet, CharacteristicProfile& charProfile); - int32_t CreateTable(); - int32_t CreateIndex(); - int32_t SetCharacteristicProfileId(CharacteristicProfile& charProfile); -}; -} -} -#endif // OHOS_DP_CHARACTERISTIC_PROFILE_DAO_H diff --git a/services/core/include/profiledatamanager/service_profile_dao.h b/services/core/include/profiledatamanager/service_profile_dao.h deleted file mode 100644 index 4ac4c8f9..00000000 --- a/services/core/include/profiledatamanager/service_profile_dao.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 OHOS_DP_SERVICE_PROFILE_DAO_H -#define OHOS_DP_SERVICE_PROFILE_DAO_H - -#include "values_bucket.h" - -#include "profile_data_rdb_adapter.h" -#include "service_profile.h" -#include "service_profile_filter_opotions.h" -#include "single_instance.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class ServiceProfileDao { - DECLARE_SINGLE_INSTANCE(ServiceProfileDao); -public: - int32_t Init(); - int32_t UnInit(); - int32_t PutServiceProfile(ServiceProfile& serviceProfile); - int32_t DeleteServiceProfile(const ServiceProfile& serviceProfile); - int32_t UpdateServiceProfile(const ServiceProfile& serviceProfile); - int32_t GetServiceProfiles(const ServiceProfileFilterOptions& filterOptions, - std::vector& serviceProfiles); -private: - int32_t CreateTable(); - int32_t CreateIndex(); - int32_t ConvertToServiceProfile(std::shared_ptr resultSet, ServiceProfile& serviceProfile); - int32_t CreateQuerySqlAndCondition(const ServiceProfileFilterOptions& filterOptions, std::string& sql, - std::vector& condition); - void CreateBaseQuerySqlAndCondition(const ServiceProfileFilterOptions& filterOptions, std::string& whereSql, - std::vector& condition); - void CreateComplexQuerySqlAndCondition(const ServiceProfileFilterOptions& filterOptions, std::string& whereSql, - std::vector& condition); - void ServiceProfileToEntries(const ServiceProfile& serviceProfile, ValuesBucket& values); - int32_t SetServiceProfileId(ServiceProfile& serviceProfile); -}; - - -} // namespace DistributedDeviceProfile -} // namespace OHOS -#endif //OHOS_DP_SERVICE_PROFILE_DAO_H diff --git a/services/core/src/profiledatamanager/characteristic_profile_dao.cpp b/services/core/src/profiledatamanager/characteristic_profile_dao.cpp deleted file mode 100644 index 471da118..00000000 --- a/services/core/src/profiledatamanager/characteristic_profile_dao.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/* - * 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. - */ - -#include "dp_services_constants.h" -#include "content_sensor_manager_utils.h" -#include "characteristic_profile.h" -#include "characteristic_profile_filter_option.h" -#include "characteristic_profile_dao.h" -#include "distributed_device_profile_constants.h" -#include "distributed_device_profile_errors.h" -#include "distributed_device_profile_log.h" -#include "device_profile_manager.h" -#include "profile_utils.h" -#include "profile_cache.h" -#include "subscribe_profile_manager.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -IMPLEMENT_SINGLE_INSTANCE(CharacteristicProfileDao); -namespace { - const std::string TAG = "CharacteristicProfileDao"; -} - -int32_t CharacteristicProfileDao::Init() -{ - int32_t ret = RET_INIT; - if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { - ret = ProfileDataRdbAdapter::GetInstance().Init(); - if (ret != DP_SUCCESS) { - HILOGE("ProfileDataRdbAdapter Init failed"); - return DP_INIT_DB_FAILED; - } - } - CreateTable(); - CreateIndex(); - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::UnInit() -{ - if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { - HILOGE("ProfileDataRdbAdapter is UnInit"); - return DP_SUCCESS; - } - int32_t ret = ProfileDataRdbAdapter::GetInstance().UnInit(); - if (ret != DP_SUCCESS) { - HILOGE("ProfileDataRdbAdapter UnInit failed"); - return DP_UNINIT_FAIL; - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::PutCharacteristicProfile(CharacteristicProfile& charProfile) -{ - ValuesBucket values; - int32_t result = CharProfileToEntries(charProfile, values); - if (result != DP_SUCCESS) { - HILOGE("charProfile invalid params"); - return DP_INVALID_PARAMS; - } - int64_t rowId = ROWID_INIT; - int32_t ret = RET_INIT; - ret = ProfileDataRdbAdapter::GetInstance().Put(rowId, CHARACTERISTIC_PROFILE_TABLE, values); - if (ret != DP_SUCCESS) { - HILOGE("characteristic_profile insert failed"); - return DP_PUT_CHARACTERISTIC_PROFILE_FAIL; - } - if (SetCharacteristicProfileId(charProfile) != DP_SUCCESS) { - HILOGE("SetCharacteristicProfileId fail"); - return DP_PUT_CHARACTERISTIC_PROFILE_FAIL; - } - SubscribeProfileManager::GetInstance().NotifyCharProfileAdd(charProfile); - std::string localUdid = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid(); - if (localUdid == charProfile.GetDeviceId()) { - DeviceProfileManager::GetInstance().PutCharacteristicProfile(charProfile); - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::GetCharacteristicProfiles(const CharacteristicProfileFilterOption &filterOptions, - std::vector &charProfiles) -{ - std::string sql; - std::vector condition; - if (filterOptions.GetUserId() <= 0 && filterOptions.GetAccountld().empty() && - filterOptions.GetDeviceIds().empty() && filterOptions.GetWiseDeviceId() .empty() && - filterOptions.GetServiceId().empty() && filterOptions.GetCharacteristicKey().empty() && - filterOptions.GetCharacteristicProfileIds().empty() && filterOptions.GetServiceProfileId() <= 0) { - HILOGE("filterOptions is empty"); - return DP_INVALID_PARAMS; - } - CreateQuerySqlAndCondition(filterOptions, sql, condition); - std::shared_ptr resultSet = ProfileDataRdbAdapter::GetInstance().Get(sql, condition); - if (resultSet == nullptr) { - HILOGE("resultSet is nullptr"); - return DP_GET_CHARACTERISTIC_PROFILE_FAIL; - } - int32_t rowCount = ROWCOUNT_INIT; - resultSet->GetRowCount(rowCount); - if (rowCount == 0) { - HILOGE("by condition not find data"); - resultSet->Close(); - return DP_NOT_FIND_DATA; - } - while (resultSet->GoToNextRow() == DP_SUCCESS) { - CharacteristicProfile charProfile; - ConvertToCharProfile(resultSet, charProfile); - charProfiles.push_back(charProfile); - } - resultSet->Close(); - if (charProfiles.empty()) { - return DP_NOT_FIND_DATA; - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::DeleteCharacteristicProfile(const CharacteristicProfile &charProfiles) -{ - if (charProfiles.GetDeviceId().empty() || charProfiles.GetServiceProfileId() <= 0 || - charProfiles.GetServiceId().empty() || charProfiles.GetCharacteristicKey().empty() || - charProfiles.GetCharacteristicValue().empty()) { - HILOGE("charProfile invalid params"); - return DP_INVALID_PARAMS; - } - int32_t deleteRows = DELETEROWS_INIT; - int32_t ret = ProfileDataRdbAdapter::GetInstance().Delete(deleteRows, CHARACTERISTIC_PROFILE_TABLE, - ID_EQUAL_CONDITION, std::vector{ ValueObject(charProfiles.GetId()) }); - if (ret != DP_SUCCESS) { - HILOGE("delete characteristicprofile_profile data failed"); - return DP_DELETE_CHARACTERISTIC_PROFILE_FAIL; - } - SubscribeProfileManager::GetInstance().NotifyCharProfileDelete(charProfiles); - std::string localUdid = ProfileCache::GetInstance().GetLocalUdid(); - if (localUdid == charProfiles.GetDeviceId()) { - DeviceProfileManager::GetInstance().DeleteCharacteristicProfile(charProfiles.GetDeviceId(), - charProfiles.GetServiceName(), charProfiles.GetCharacteristicKey(), true, charProfiles.GetUserId()); - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::UpdateCharacteristicProfile(const CharacteristicProfile &oldProfile, - const CharacteristicProfile &newProfile) -{ - ValuesBucket values; - int32_t result = CharProfileToEntries(newProfile, values); - if (result != DP_SUCCESS) { - HILOGE("charProfile invalid params"); - return DP_INVALID_PARAMS; - } - int32_t changeRowCnt = CHANGEROWCNT_INIT; - int32_t ret = ProfileDataRdbAdapter::GetInstance().Update( - changeRowCnt, CHARACTERISTIC_PROFILE_TABLE, values, ID_EQUAL_CONDITION, - std::vector{ ValueObject(newProfile.GetId()) }); - if (ret != DP_SUCCESS) { - HILOGE("Update characteristicprofile_profile table failed"); - return DP_UPDATE_TRUST_DEVICE_PROFILE_FAIL; - } - SubscribeProfileManager::GetInstance().NotifyCharProfileUpdate(oldProfile, newProfile); - std::string localUdid = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid(); - if (localUdid == newProfile.GetDeviceId()) { - DeviceProfileManager::GetInstance().PutCharacteristicProfile(newProfile); - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::CreateTable() -{ - int32_t ret = ProfileDataRdbAdapter::GetInstance().CreateTable(CREATE_CHARACTERISTIC_PROFILE_TABLE_SQL); - if (ret != DP_SUCCESS) { - HILOGE("characteristicprofile_profile create failed"); - return DP_CREATE_TABLE_FAIL; - } - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::CreateIndex() -{ - int32_t ret = ProfileDataRdbAdapter::GetInstance(). - CreateTable(CREATE_CHARACTERISTIC_PROFILE_TABLE_INDEX_SQL_CHARACTERISTIC_KEY); - if (ret != DP_SUCCESS) { - HILOGE("characteristicprofile_profile unique index create failed"); - return DP_CREATE_UNIQUE_INDEX_FAIL; - } - ret = ProfileDataRdbAdapter::GetInstance(). - CreateTable(CREATE_CHARACTERISTIC_PROFILE_TABLE_INDEX_SQL_SERVICE_PROFILE_ID); - if (ret != DP_SUCCESS) { - HILOGE("characteristicprofile_profile unique index create failed"); - return DP_CREATE_UNIQUE_INDEX_FAIL; - } - return DP_SUCCESS; -} - -void CharacteristicProfileDao::CreateQuerySqlAndCondition(const CharacteristicProfileFilterOption& filterOptions, - std::string& sql, std::vector& condition) -{ - sql = SELECT_CHARACTERISTIC_PROFILE_TABLE; - if (!filterOptions.GetCharacteristicProfileIds().empty()) { - sql += "cp.id IN("; - std::vector characteristicProfileIds = filterOptions.GetCharacteristicProfileIds(); - for (auto deviceProfileId : characteristicProfileIds) { - sql += "?,"; - condition.emplace_back(ValueObject(deviceProfileId)); - } - sql.erase(sql.end() - 1); - sql += ") AND "; - } - if (!filterOptions.GetCharacteristicKey().empty()) { - sql += "cp.characteristicKey = ? AND "; - condition.emplace_back(ValueObject(filterOptions.GetCharacteristicKey())); - } - if (filterOptions.GetServiceProfileId() != 0) { - sql += "cp.serviceProfileId = ? AND "; - condition.emplace_back(ValueObject(filterOptions.GetServiceProfileId())); - } - if (!filterOptions.GetServiceId().empty()) { - sql += "sp.serviceId = ? AND "; - condition.emplace_back(ValueObject(filterOptions.GetServiceId())); - } - if (!filterOptions.GetDeviceIds().empty()) { - sql += "sp.deviceId = ? AND "; - condition.emplace_back(ValueObject(filterOptions.GetDeviceIds())); - } - if (filterOptions.GetUserId() != 0) { - sql += "dp.deviceId = ? AND "; - condition.emplace_back(ValueObject(filterOptions.GetUserId())); - } - if (!filterOptions.GetAccountld().empty()) { - sql += "dp.deviceId = ? AND "; - condition.emplace_back(ValueObject(filterOptions.GetAccountld())); - } - if (!filterOptions.GetWiseDeviceId().empty()) { - sql += "dp.deviceId = ? AND "; - condition.emplace_back(ValueObject(filterOptions.GetWiseDeviceId())); - } - if (sql.empty()) { - return; - } - sql.erase(sql.end() - AND_LENGTH); - return; -} - -int32_t CharacteristicProfileDao::CharProfileToEntries(const CharacteristicProfile& charProfile, ValuesBucket& values) -{ - if (charProfile.GetDeviceId().empty() || charProfile.GetServiceProfileId() <= 0 || - charProfile.GetServiceId().empty() || charProfile.GetCharacteristicKey().empty() || - charProfile.GetCharacteristicValue().empty()) { - return DP_INVALID_PARAMS; - } - values.PutInt(SERVICE_PROFILE_ID, charProfile.GetServiceProfileId()); - values.PutString(CHARACTERISTIC_KEY, charProfile.GetCharacteristicKey()); - values.PutString(CHARACTERISTIC_VALUE, charProfile.GetCharacteristicValue()); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::ConvertToCharProfile( - std::shared_ptr resultSet, CharacteristicProfile& charProfile) -{ - if (resultSet == nullptr) { - HILOGE("resultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - RowEntity rowEntity; - if (resultSet->GetRow(rowEntity) != DP_SUCCESS) { - HILOGE("get resultSet failed"); - return DP_GET_RESULTSET_FAIL; - } - charProfile.SetId(rowEntity.Get(ID)); - charProfile.SetServiceProfileId(rowEntity.Get(SERVICE_PROFILE_ID)); - charProfile.SetDeviceId(rowEntity.Get(DEVICE_ID)); - charProfile.SetServiceId(rowEntity.Get(SERVICE_PROFILE_SERVICE_ID)); - charProfile.SetCharacteristicKey(rowEntity.Get(CHARACTERISTIC_KEY)); - charProfile.SetCharacteristicValue(rowEntity.Get(CHARACTERISTIC_VALUE)); - return DP_SUCCESS; -} - -int32_t CharacteristicProfileDao::SetCharacteristicProfileId(CharacteristicProfile& charProfile) -{ - std::shared_ptr resultSet = ProfileDataRdbAdapter::GetInstance().Get( - SELECT_CHARACTERISTIC_PROFILE_TABLE_MAX_ID, std::vector { - charProfile.GetServiceProfileId(), charProfile.GetCharacteristicKey(), - charProfile.GetCharacteristicValue()}); - if (resultSet == nullptr) { - HILOGE("resultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - while (resultSet->GoToNextRow() == DP_SUCCESS) { - int32_t columnIndex = COLUMNINDEX_INIT; - int32_t id = DEVICE_PROFILE_ID_INIT; - resultSet->GetColumnIndex(ID, columnIndex); - resultSet->GetInt(columnIndex, id); - charProfile.SetId(id); - } - resultSet->Close(); - return DP_SUCCESS; -} -} // namespace DistributedDeviceProfile -} // namespace OHOS diff --git a/services/core/src/profiledatamanager/service_profile_dao.cpp b/services/core/src/profiledatamanager/service_profile_dao.cpp deleted file mode 100644 index 92caf145..00000000 --- a/services/core/src/profiledatamanager/service_profile_dao.cpp +++ /dev/null @@ -1,332 +0,0 @@ -/* - * 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. - */ - -#include "service_profile_dao.h" - -#include - -#include "content_sensor_manager_utils.h" -#include "device_profile_manager.h" -#include "distributed_device_profile_errors.h" -#include "distributed_device_profile_log.h" -#include "dp_services_constants.h" -#include "profile_cache.h" -#include "profile_data_rdb_adapter.h" -#include "subscribe_profile_manager.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -IMPLEMENT_SINGLE_INSTANCE(ServiceProfileDao); -namespace { -const std::string TAG = "DistributedDeviceProfile"; -} - -int32_t ServiceProfileDao::Init() -{ - if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { - if (ProfileDataRdbAdapter::GetInstance().Init() != DP_SUCCESS) { - HILOGE("ProfileDataRdbAdapter Init failed"); - return DP_INIT_DB_FAILED; - } - } - CreateTable(); - CreateIndex(); - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::UnInit() -{ - if (!ProfileDataRdbAdapter::GetInstance().IsInit()) { - HILOGE("ProfileDataRdbAdapter is UnInit"); - return DP_SUCCESS; - } - if (ProfileDataRdbAdapter::GetInstance().UnInit() != DP_SUCCESS) { - HILOGE("ProfileDataRdbAdapter UnInit failed"); - return DP_UNINIT_FAIL; - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::PutServiceProfile(ServiceProfile& serviceProfile) -{ - if (serviceProfile.GetDeviceId().empty() || serviceProfile.GetServiceName().empty() || - serviceProfile.GetServiceType().empty() || serviceProfile.GetDeviceProfileId() == DEFAULT_DEVICE_PROFILE_ID) { - HILOGE("serviceProfile params is invalid!"); - return DP_INVALID_PARAMS; - } - ValuesBucket values; - ServiceProfileToEntries(serviceProfile, values); - int64_t rowId = ROWID_INIT; - if (ProfileDataRdbAdapter::GetInstance().Put(rowId, SERVICE_PROFILE_TABLE, values) != DP_SUCCESS) { - HILOGE("service_profile insert failed"); - return DP_RDB_PUT_SERVICE_PROFILE_FAIL; - } - if (SetServiceProfileId(serviceProfile) != DP_SUCCESS) { - HILOGE("SetServiceProfileId fail"); - return DP_RDB_SET_SERVICE_PROFILE_ID_FAIL; - } - SubscribeProfileManager::GetInstance().NotifyServiceProfileAdd(serviceProfile); - std::string localUdid = ProfileCache::GetInstance().GetLocalUdid(); - if (localUdid == serviceProfile.GetDeviceId()) { - DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile); - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::DeleteServiceProfile(const ServiceProfile& serviceProfile) -{ - if (serviceProfile.GetDeviceId().empty() || serviceProfile.GetServiceName().empty() || - serviceProfile.GetServiceType().empty() || serviceProfile.GetId() == DEFAULT_SERVICE_PROFILE_ID) { - HILOGE("serviceProfile params is invalid!"); - return DP_INVALID_PARAMS; - } - int32_t deleteRows = DELETEROWS_INIT; - int32_t ret = ProfileDataRdbAdapter::GetInstance().Delete(deleteRows, SERVICE_PROFILE_TABLE, ID_EQUAL_CONDITION, - std::vector{ ValueObject(serviceProfile.GetId()) }); - if (ret != DP_SUCCESS) { - HILOGE("delete service_profile data failed"); - return DP_RDB_DELETE_SERVICE_PROFILE_FAIL; - } - SubscribeProfileManager::GetInstance().NotifyServiceProfileDelete(serviceProfile); - std::string localUdid = ProfileCache::GetInstance().GetLocalUdid(); - if (localUdid == serviceProfile.GetDeviceId()) { - DeviceProfileManager::GetInstance().DeleteServiceProfile(serviceProfile.GetDeviceId(), - serviceProfile.GetServiceName(), true, serviceProfile.GetUserId()); - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::UpdateServiceProfile(const ServiceProfile& serviceProfile) -{ - if (serviceProfile.GetDeviceId().empty() || serviceProfile.GetServiceName().empty() || - serviceProfile.GetServiceType().empty() || serviceProfile.GetId() == DEFAULT_SERVICE_PROFILE_ID) { - HILOGE("serviceProfile params is invalid!"); - return DP_INVALID_PARAMS; - } - ValuesBucket values; - ServiceProfileToEntries(serviceProfile, values); - int32_t changeRowCnt = CHANGEROWCNT_INIT; - int32_t ret = ProfileDataRdbAdapter::GetInstance().Update( - changeRowCnt, SERVICE_PROFILE_TABLE, values, ID_EQUAL_CONDITION, - std::vector{ ValueObject(serviceProfile.GetId()) }); - if (ret != DP_SUCCESS) { - HILOGE("Update service_profile table failed"); - return DP_UPDATE_TRUST_DEVICE_PROFILE_FAIL; - } - SubscribeProfileManager::GetInstance().NotifyServiceProfileUpdate(serviceProfile); - std::string localUdid = ContentSensorManagerUtils::GetInstance().ObtainLocalUdid(); - if (localUdid == serviceProfile.GetDeviceId()) { - DeviceProfileManager::GetInstance().PutServiceProfile(serviceProfile); - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfile::ServiceProfileDao::GetServiceProfiles( - const ServiceProfileFilterOptions& filterOptions, std::vector& serviceProfiles) -{ - if (filterOptions.IsEmpty()) { - HILOGE("filterOptions is empty!"); - return DP_INVALID_PARAMS; - } - std::vector condition; - std::string sql = ""; - if (CreateQuerySqlAndCondition(filterOptions, sql, condition) != DP_SUCCESS) { - HILOGE("CreateQuerySqlAndCondition failed!"); - return DP_INVALID_PARAMS; - } - std::shared_ptr resultSet = ProfileDataRdbAdapter::GetInstance().Get(sql, condition); - if (resultSet == nullptr) { - HILOGE("resultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - int32_t rowCount = ROWCOUNT_INIT; - resultSet->GetRowCount(rowCount); - if (rowCount == 0) { - HILOGE("by condition not find data"); - resultSet->Close(); - return DP_NOT_FIND_DATA; - } - while (resultSet->GoToNextRow() == DP_SUCCESS) { - ServiceProfile serviceProfile; - ConvertToServiceProfile(resultSet, serviceProfile); - serviceProfiles.emplace_back(serviceProfile); - } - resultSet->Close(); - if (serviceProfiles.empty()) { - return DP_NOT_FIND_DATA; - } - HILOGI("end!"); - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::CreateTable() -{ - int32_t ret = ProfileDataRdbAdapter::GetInstance().CreateTable(CREATE_SERVICE_PROFILE_TABLE_SQL); - if (ret != DP_SUCCESS) { - HILOGE("service_profile create failed"); - return DP_CREATE_TABLE_FAIL; - } - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::CreateIndex() -{ - int32_t ret = ProfileDataRdbAdapter::GetInstance().CreateTable(CREATE_SERVICE_PROFILE_TABLE_INDEX_SERVICEID_SQL); - if (ret != DP_SUCCESS) { - HILOGE("service_profile index create failed"); - return DP_CREATE_UNIQUE_INDEX_FAIL; - } - ret = ProfileDataRdbAdapter::GetInstance().CreateTable(CREATE_SERVICE_PROFILE_TABLE_INDEX_DEVICEPROFILEID_SQL); - if (ret != DP_SUCCESS) { - HILOGE("service_profile index create failed"); - return DP_CREATE_UNIQUE_INDEX_FAIL; - } - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::ConvertToServiceProfile(std::shared_ptr resultSet, - ServiceProfile& serviceProfile) -{ - if (resultSet == nullptr) { - HILOGE("resultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - RowEntity rowEntity; - if (resultSet->GetRow(rowEntity) != DP_SUCCESS) { - HILOGE("get resultSet failed"); - return DP_GET_RESULTSET_FAIL; - } - serviceProfile.SetId(rowEntity.Get(ID)); - serviceProfile.SetDeviceProfileId(rowEntity.Get(SERVICE_PROFILE_DEVICE_PROFILE_ID)); - serviceProfile.SetDeviceId(rowEntity.Get(DEVICE_ID)); - serviceProfile.SetServiceName(rowEntity.Get(SERVICE_PROFILE_SERVICE_ID)); - serviceProfile.SetServiceType(rowEntity.Get(SERVICE_TYPE)); - serviceProfile.SetUserId(rowEntity.Get(RDB_USER_ID)); - return DP_SUCCESS; -} - -int32_t ServiceProfileDao::CreateQuerySqlAndCondition(const ServiceProfileFilterOptions& filterOptions, - std::string& sql, std::vector& condition) -{ - std::string whereSql = ""; - CreateComplexQuerySqlAndCondition(filterOptions, whereSql, condition); - CreateBaseQuerySqlAndCondition(filterOptions, whereSql, condition); - if (whereSql.empty()) { - HILOGE("whereSql is empty!"); - return DP_INVALID_PARAMS; - } - whereSql.erase(whereSql.end() - NUM_3, whereSql.end()); - sql = SELECT_SERVICE_PROGILES + whereSql; - return DP_SUCCESS; -} - -void ServiceProfileDao::CreateComplexQuerySqlAndCondition(const ServiceProfileFilterOptions& filterOptions, - std::string& whereSql, std::vector& condition) -{ - // whereSql append service_profile.id - if (!filterOptions.GetServiceProfileIds().empty()) { - whereSql += "service_profile.id IN ("; - for (auto& id : filterOptions.GetServiceProfileIds()) { - whereSql += "?,"; - condition.emplace_back(ValueObject(id)); - } - whereSql.erase(whereSql.end() - 1, whereSql.end()); - whereSql += ") AND"; - } - // whereSql append service_profile.serviceId - if (!filterOptions.GetServiceIds().empty()) { - whereSql += "service_profile.serviceId IN ("; - for (auto& serviceId : filterOptions.GetServiceIds()) { - whereSql += "?,"; - condition.emplace_back(ValueObject(serviceId)); - } - whereSql.erase(whereSql.end() - 1, whereSql.end()); - whereSql += ") AND"; - } - // whereSql append service_profile.deviceProfileId - if (!filterOptions.GetDeviceProfileIds().empty()) { - whereSql += "service_profile.deviceProfileId IN ("; - for (auto& deviceProfileId : filterOptions.GetDeviceProfileIds()) { - whereSql += "?,"; - condition.emplace_back(ValueObject(deviceProfileId)); - } - whereSql.erase(whereSql.end() - 1, whereSql.end()); - whereSql += ") AND"; - } -} - -void ServiceProfileDao::CreateBaseQuerySqlAndCondition(const ServiceProfileFilterOptions& filterOptions, - std::string& whereSql, std::vector& condition) -{ - // whereSql append device_profile.userId - if (filterOptions.GetUserId() != DEFAULT_USER_ID) { - whereSql += "device_profile.userId=? AND"; - condition.emplace_back(ValueObject(filterOptions.GetUserId())); - } - // whereSql append device_profile.accountId - if (!filterOptions.GetAccountId().empty()) { - whereSql += "device_profile.accountId=? AND"; - condition.emplace_back(ValueObject(filterOptions.GetAccountId())); - } - // whereSql append device_profile.deviceId - if (!filterOptions.GetDeviceId().empty()) { - whereSql += "device_profile.deviceId=? AND"; - condition.emplace_back(ValueObject(filterOptions.GetDeviceId())); - } - // whereSql append device_profile.wiseDeviceId - if (!filterOptions.GetWiseDeviceIds().empty()) { - whereSql += "device_profile.wiseDeviceId IN ("; - for (auto& wiseDeviceId : filterOptions.GetWiseDeviceIds()) { - whereSql += "?,"; - condition.emplace_back(ValueObject(wiseDeviceId)); - } - whereSql.erase(whereSql.end() - 1, whereSql.end()); - whereSql += ") AND"; - } -} - -void ServiceProfileDao::ServiceProfileToEntries(const ServiceProfile& serviceProfile, ValuesBucket& values) -{ - values.PutInt(SERVICE_PROFILE_DEVICE_PROFILE_ID, serviceProfile.GetDeviceProfileId()); - values.PutString(SERVICE_PROFILE_SERVICE_ID, serviceProfile.GetServiceName()); - values.PutString(SERVICE_PROFILE_SERVICE_TYPE, serviceProfile.GetServiceType()); -} - -int32_t ServiceProfileDao::SetServiceProfileId(ServiceProfile& serviceProfile) -{ - std::shared_ptr resultSet = ProfileDataRdbAdapter::GetInstance().Get( - SELECT_SERVICE_PROFILE_TABLE_WHERE_DEVID_SERID_SERTYPE, std::vector{ - serviceProfile.GetDeviceProfileId(), serviceProfile.GetServiceName(), serviceProfile.GetServiceType()}); - if (resultSet == nullptr) { - HILOGE("resultSet is nullptr"); - return DP_GET_RESULTSET_FAIL; - } - while (resultSet->GoToNextRow() == DP_SUCCESS) { - int32_t columnIndex = COLUMNINDEX_INIT; - int32_t id = DEVICE_PROFILE_ID_INIT; - resultSet->GetColumnIndex(ID, columnIndex); - resultSet->GetInt(columnIndex, id); - serviceProfile.SetId(id); - } - resultSet->Close(); - return DP_SUCCESS; -} -} // namespace DistributedDeviceProfile -} // namespace OHOS diff --git a/services/core/test/unittest/device_profile_manager_test.cpp b/services/core/test/unittest/device_profile_manager_test.cpp index 7c73d6b2..4375dd2e 100644 --- a/services/core/test/unittest/device_profile_manager_test.cpp +++ b/services/core/test/unittest/device_profile_manager_test.cpp @@ -1081,8 +1081,8 @@ HWTEST_F(DeviceProfileManagerTest, GetUserId001, TestSize.Level1) ServiceProfile serviceProfile9; int32_t userId = 1; serviceProfile9.SetUserId(userId); - bool ret = serviceProfile9.GetUserId(); - EXPECT_EQ(true, ret); + int32_t outUserId = serviceProfile9.GetUserId(); + EXPECT_EQ(outUserId, userId); } /** @@ -1863,7 +1863,6 @@ HWTEST_F(DeviceProfileManagerTest, SyncWithNotOHBasedDevice001, TestSize.Level1) sptr syncCompletedCallback; int32_t ret = DeviceProfileManager::GetInstance().SyncWithNotOHBasedDevice( notOHBasedDevices, callerDescriptor, syncCompletedCallback); - EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED); DeviceProfileManager::GetInstance().SyncWithNotOHBasedDeviceFailed(notOHBasedDevices, syncCompletedCallback); EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED); } diff --git a/services/core/test/unittest/dp_subscribe_info_test.cpp b/services/core/test/unittest/dp_subscribe_info_test.cpp index fa907b67..4db89f2a 100644 --- a/services/core/test/unittest/dp_subscribe_info_test.cpp +++ b/services/core/test/unittest/dp_subscribe_info_test.cpp @@ -317,7 +317,7 @@ HWTEST_F(DPSubscribeInfoTest, Stub_002, TestSize.Level1) HWTEST_F(DPSubscribeInfoTest, IProfileChangeListener_001, TestSize.Level1) { OHOS::sptr subscribeDPChangeListener = - new(std::nothrow) DPSubscribeInfoTest::SubscribeDPChangeListener; + sptr(new DPSubscribeInfoTest::SubscribeDPChangeListener); TrustDeviceProfile profile; profile.SetPeerUserId(1001); int32_t ret = subscribeDPChangeListener->OnTrustDeviceProfileActive(profile); -- Gitee