From 512d642d6901b7b3f7c0c39cff345c591bf0c741 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 4 May 2023 21:07:20 +0800 Subject: [PATCH 001/437] feat:Support cloud based data schema settings Signed-off-by: htt1997 --- .../distributeddataservice/framework/BUILD.gn | 1 + .../framework/cloud/cloud_event.cpp | 33 +++ .../framework/cloud/cloud_info.cpp | 2 + .../framework/include/cloud/cloud_event.h | 50 ++++ .../framework/include/cloud/cloud_info.h | 1 + .../framework/include/eventcenter/event.h | 3 +- .../framework/include/store/auto_cache.h | 5 +- .../framework/store/auto_cache.cpp | 18 ++ .../distributeddataservice/service/BUILD.gn | 8 +- .../service/cloud/cloud_service_impl.cpp | 252 ++++++++++++++++++ .../service/cloud/cloud_service_impl.h | 56 ++++ .../service/cloud/cloud_service_stub.cpp | 104 ++++++++ .../service/cloud/cloud_service_stub.h | 37 +++ .../service/cloud/cloud_syncer.cpp | 28 ++ .../service/cloud/cloud_syncer.h | 30 +++ .../service/rdb/rdb_general_store.cpp | 110 ++++++++ .../service/rdb/rdb_general_store.h | 58 ++++ .../service/rdb/rdb_service_impl.cpp | 135 ++++++++-- .../service/rdb/rdb_service_impl.h | 12 +- .../service/rdb/rdb_service_stub.cpp | 22 +- .../service/rdb/rdb_service_stub.h | 9 +- .../service/test/cloud_data_test.cpp | 113 ++++++++ 22 files changed, 1057 insertions(+), 30 deletions(-) create mode 100644 services/distributeddataservice/framework/cloud/cloud_event.cpp create mode 100644 services/distributeddataservice/framework/include/cloud/cloud_event.h create mode 100644 services/distributeddataservice/service/cloud/cloud_service_impl.cpp create mode 100644 services/distributeddataservice/service/cloud/cloud_service_impl.h create mode 100644 services/distributeddataservice/service/cloud/cloud_service_stub.cpp create mode 100644 services/distributeddataservice/service/cloud/cloud_service_stub.h create mode 100644 services/distributeddataservice/service/cloud/cloud_syncer.cpp create mode 100644 services/distributeddataservice/service/cloud/cloud_syncer.h create mode 100644 services/distributeddataservice/service/rdb/rdb_general_store.cpp create mode 100644 services/distributeddataservice/service/rdb/rdb_general_store.h create mode 100644 services/distributeddataservice/service/test/cloud_data_test.cpp diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 4ce626b7..ea3b510f 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("distributeddatasvcfwk") { "checker/checker_manager.cpp", "cloud/asset_loader.cpp", "cloud/cloud_db.cpp", + "cloud/cloud_event.cpp", "cloud/cloud_info.cpp", "cloud/cloud_server.cpp", "cloud/schema_meta.cpp", diff --git a/services/distributeddataservice/framework/cloud/cloud_event.cpp b/services/distributeddataservice/framework/cloud/cloud_event.cpp new file mode 100644 index 00000000..11f43a39 --- /dev/null +++ b/services/distributeddataservice/framework/cloud/cloud_event.cpp @@ -0,0 +1,33 @@ +/* + * 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 "cloud/cloud_event.h" + +namespace OHOS::DistributedData { +CloudEvent::CloudEvent(int32_t evtId, CloudEvent::StoreInfo storeInfo, const std::string &featureName) + : Event(evtId), featureName_(featureName), storeInfo_(storeInfo) +{ +} + +std::string CloudEvent::GetFeatureName() const +{ + return featureName_; +} + +CloudEvent::StoreInfo CloudEvent::GetStoreInfo() const +{ + return storeInfo_; +} +} \ No newline at end of file diff --git a/services/distributeddataservice/framework/cloud/cloud_info.cpp b/services/distributeddataservice/framework/cloud/cloud_info.cpp index f3f141eb..d3560bb8 100644 --- a/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -44,6 +44,7 @@ bool CloudInfo::AppInfo::Marshal(Serializable::json &node) const SetValue(node[GET_NAME(bundleName)], bundleName); SetValue(node[GET_NAME(appId)], appId); SetValue(node[GET_NAME(version)], version); + SetValue(node[GET_NAME(instanceId)], instanceId); SetValue(node[GET_NAME(cloudSwitch)], cloudSwitch); return true; } @@ -53,6 +54,7 @@ bool CloudInfo::AppInfo::Unmarshal(const Serializable::json &node) GetValue(node, GET_NAME(bundleName), bundleName); GetValue(node, GET_NAME(appId), appId); GetValue(node, GET_NAME(version), version); + GetValue(node, GET_NAME(instanceId), instanceId); GetValue(node, GET_NAME(cloudSwitch), cloudSwitch); return true; } diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h new file mode 100644 index 00000000..d01ab0f2 --- /dev/null +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_EVENT_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_EVENT_H + +#include +#include "eventcenter/event.h" + +namespace OHOS::DistributedData { +class API_EXPORT CloudEvent : public Event { +public: + enum : int32_t { + FEATURE_INIT = EVT_CLOUD, + GET_SCHEMA, + NEED_CREATE, + CLOUD_BUTT + }; + + struct StoreInfo{ + uint32_t tokenId = 0; + std::string bundleName; + std::string storeName; + int32_t instanceId = 0; + int32_t schemaVersion = -1; + }; + + CloudEvent(int32_t evtId, StoreInfo storeInfo, const std::string &featureName = "relational_store"); + ~CloudEvent() = default; + std::string GetFeatureName() const; + StoreInfo GetStoreInfo() const; + +private: + std::string featureName_; + StoreInfo storeInfo_; +}; +} // namespace OHOS::DistributedData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_EVENT_H diff --git a/services/distributeddataservice/framework/include/cloud/cloud_info.h b/services/distributeddataservice/framework/include/cloud/cloud_info.h index 5576bca8..d16c8cfc 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_info.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_info.h @@ -23,6 +23,7 @@ public: std::string bundleName = ""; std::string appId = ""; uint64_t version = 0; + int32_t instanceId = 0; bool cloudSwitch = false; bool Marshal(json &node) const override; diff --git a/services/distributeddataservice/framework/include/eventcenter/event.h b/services/distributeddataservice/framework/include/eventcenter/event.h index d574e0f5..27bf9df2 100644 --- a/services/distributeddataservice/framework/include/eventcenter/event.h +++ b/services/distributeddataservice/framework/include/eventcenter/event.h @@ -27,7 +27,8 @@ public: EVT_INVALID, EVT_INITED, EVT_UPDATE, - EVT_CUSTOM = 0x1000 + EVT_CUSTOM = 0x1000, + EVT_CLOUD = 0x2000 }; API_EXPORT Event(int32_t evtId); API_EXPORT Event(Event &&) noexcept = delete; diff --git a/services/distributeddataservice/framework/include/store/auto_cache.h b/services/distributeddataservice/framework/include/store/auto_cache.h index ffed302f..0dd4e15d 100644 --- a/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/services/distributeddataservice/framework/include/store/auto_cache.h @@ -27,6 +27,7 @@ #include "store/general_watcher.h" #include "visibility.h" namespace OHOS::DistributedData { +class SchemaMeta; class AutoCache { public: using Error = GeneralError; @@ -44,7 +45,9 @@ public: API_EXPORT void Bind(std::shared_ptr executor); API_EXPORT Store GetStore(const StoreMetaData &meta, const Watchers &watchers); - + + API_EXPORT int32_t CreateTable(const StoreMetaData &storeMetaData, const SchemaMeta &schemaMeta); + API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId); API_EXPORT void CloseExcept(const std::set &users); diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index 212f6c1b..76ec3966 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -79,6 +79,24 @@ AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers & return store; } +int32_t AutoCache::CreateTable(const StoreMetaData &storeMetaData, const SchemaMeta &schemaMeta) +{ + stores_.Compute(storeMetaData.tokenId, + [this, &storeMetaData, &schemaMeta](auto &, std::map &stores) -> bool { + auto it = stores.find(storeMetaData.storeId); + if (it != stores.end()) { + //it->second->CreateTable(schemaMeta) + return true; + } + auto *dbStore = creators_[storeMetaData.storeType](storeMetaData); + if (dbStore != nullptr) { + //dbStore->CreateTable(schemaMeta) + } + return false; + }); + return 0; +} + void AutoCache::CloseStore(uint32_t tokenId, const std::string &storeId) { stores_.ComputeIfPresent(tokenId, [&storeId](auto &key, std::map &delegates) { diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index d05b54c5..ee18efff 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -21,6 +21,7 @@ config("module_public_config") { include_dirs = [ "backup/include", "bootstrap/include", + "cloud", "config/include", "crypto/include", "datashare", @@ -51,12 +52,15 @@ config("module_public_config") { ohos_shared_library("distributeddatasvc") { include_dirs = [ "../../../../data_object/frameworks/innerkitsimpl/include", + "../../../../relational_store/interfaces/inner_api/cloud_data/include", "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb/include", - "//foundation/distributeddatamgr/kv_store/frameworks/libs/distributeddb/include/distributeddb", ] sources = [ "backup/src/backup_manager.cpp", "bootstrap/src/bootstrap.cpp", + "cloud/cloud_service_impl.cpp", + "cloud/cloud_service_stub.cpp", + "cloud/cloud_syncer.cpp", "config/src/config_factory.cpp", "config/src/model/backup_config.cpp", "config/src/model/checker_config.cpp", @@ -94,6 +98,7 @@ ohos_shared_library("distributeddatasvc") { "object/object_service_impl.cpp", "object/object_service_stub.cpp", "permission/src/permit_delegate.cpp", + "rdb/rdb_general_store.cpp", "rdb/rdb_notifier_proxy.cpp", "rdb/rdb_result_set_impl.cpp", "rdb/rdb_result_set_stub.cpp", @@ -129,6 +134,7 @@ ohos_shared_library("distributeddatasvc") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", + "relational_store:cloud_data", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", "resource_management:global_resmgr", diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp new file mode 100644 index 00000000..fafc5c9e --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -0,0 +1,252 @@ +/* + * 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. + */ + +#define LOG_TAG "CloudServiceImpl" + +#include "cloud_service_impl.h" + +#include "account/account_delegate.h" +#include "checker/checker_manager.h" +#include "cloud/cloud_event.h" +#include "cloud/cloud_server.h" +#include "cloud_syncer.h" +#include "communicator/device_manager_adapter.h" +#include "eventcenter/event_center.h" +#include "feature/feature_system.h" +#include "ipc_skeleton.h" +#include "log_print.h" +#include "metadata/meta_data_manager.h" +#include "metadata/store_meta_data.h" +#include "utils/anonymous.h" +#include "store/auto_cache.h" + +namespace OHOS::CloudData { +using namespace DistributedData; +using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +__attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; +CloudServiceImpl::Factory::Factory() +{ + FeatureSystem::GetInstance().RegisterCreator(CloudServiceImpl::SERVICE_NAME, [this]() { + if (product_ == nullptr) { + product_ = std::make_shared(); + } + return product_; + }); +} + +CloudServiceImpl::Factory::~Factory() {} + +CloudServiceImpl::CloudServiceImpl() +{ + EventCenter::GetInstance().Subscribe(CloudEvent::FEATURE_INIT, [this](const Event &event) { + auto &rdbEvent = static_cast(event); + CloudInfo cloudInfo; + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); + if (GetServerInfo(cloudInfo) != SUCCESS) { + ZLOGE("failed, user:%{public}d", cloudInfo.user); + return; + } + UpdateCloudInfo(cloudInfo); + AddSchema(cloudInfo); + }); + + EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { + auto &rdbEvent = static_cast(event); + CloudInfo cloudInfo; + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); + if (GetServerInfo(cloudInfo) != SUCCESS) { + ZLOGE("failed, user:%{public}d", cloudInfo.user); + return; + } + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + return; + } + SchemaMeta schemaMeta; + std::string schemaKey = cloudInfo.GetSchemaKey(rdbEvent.GetStoreInfo().bundleName); + if (!MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true) || + schemaMeta.version != rdbEvent.GetStoreInfo().schemaVersion) { + schemaMeta = instance->GetAppSchema(cloudInfo.user, rdbEvent.GetStoreInfo().bundleName); + MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); + } + StoreMetaData storeMetaData; + storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + storeMetaData.user = std::to_string(cloudInfo.user); + storeMetaData.bundleName = rdbEvent.GetStoreInfo().bundleName; + storeMetaData.storeId = rdbEvent.GetStoreInfo().storeName; + storeMetaData.instanceId = rdbEvent.GetStoreInfo().instanceId; + if (!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData, true)) { + return; + } + AutoCache::GetInstance().CreateTable(storeMetaData, schemaMeta); + for (auto &database : schemaMeta.databases) { + if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync*/) { + continue; + } + auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); + //do sync + } + }); +} + +int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) +{ + CloudInfo cloudInfo; + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { + return INVALID_ARGUMENT; + } + cloudInfo.enableCloud = true; + for (const auto &item : switches) { + auto it = std::find_if(cloudInfo.apps.begin(), cloudInfo.apps.end(), + [&item](const CloudInfo::AppInfo &appInfo) -> bool { + return appInfo.bundleName == item.first; + }); + if (it == cloudInfo.apps.end()) { + continue; + } + (*it).cloudSwitch = item.second; + } + if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { + return ERROR; + } + return SUCCESS; +} + +int32_t CloudServiceImpl::DisableCloud(const std::string &id) +{ + CloudInfo cloudInfo; + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { + return INVALID_ARGUMENT; + } + cloudInfo.enableCloud = false; + if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { + return ERROR; + } + return SUCCESS; +} + +int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) +{ + CloudInfo cloudInfo; + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { + return INVALID_ARGUMENT; + } + auto it = std::find_if(cloudInfo.apps.begin(), cloudInfo.apps.end(), + [&bundleName](const CloudInfo::AppInfo &appInfo) -> bool { + return appInfo.bundleName == bundleName; + }); + if (it == cloudInfo.apps.end()) { + ZLOGE("bundleName:%{public}s", bundleName.c_str()); + return INVALID_ARGUMENT; + } + (*it).cloudSwitch = appSwitch; + if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { + return ERROR; + } + return SUCCESS; +} + +int32_t CloudServiceImpl::Clean(const std::string &id, const std::map &actions) +{ + CloudInfo cloudInfo; + cloudInfo.id = id; + if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { + ZLOGE("id:%{public}s", Anonymous::Change(id).c_str()); + return INVALID_ARGUMENT; + } + auto keys = cloudInfo.GetSchemaKey(); + for (const auto &action : actions) { + if (!cloudInfo.IsExist(action.first)) { + continue; + } + SchemaMeta schemaMeta; + if (MetaDataManager::GetInstance().LoadMeta(keys[action.first], schemaMeta, true)) { + } + } + return SUCCESS; +} + +int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::string &bundleName) +{ + return 0; +} + +int32_t CloudServiceImpl::GetCloudInfo(CloudInfo &cloudInfo) +{ + auto tokenId = IPCSkeleton::GetCallingTokenID(); + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); + if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { + ZLOGE("invalid argument id:%{public}s, user:%{public}d", Anonymous::Change(cloudInfo.id).c_str(), + cloudInfo.user); + return ERROR; + } + return SUCCESS; +} + +int32_t CloudServiceImpl::GetServerInfo(CloudInfo &cloudInfo) +{ + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + return SERVER_UNAVAILABLE; + } + cloudInfo = instance->GetServerInfo(cloudInfo.user); + if (!cloudInfo.IsValid()) { + return ERROR; + } + return SUCCESS; +} + +void CloudServiceImpl::UpdateCloudInfo(CloudInfo &cloudInfo) +{ + CloudInfo oldInfo; + if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), oldInfo, true)) { + MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); + return; + } + oldInfo.totalSpace = cloudInfo.totalSpace; + oldInfo.remainSpace = cloudInfo.remainSpace; + oldInfo.apps = std::move(cloudInfo.apps); + cloudInfo = oldInfo; + MetaDataManager::GetInstance().SaveMeta(oldInfo.GetKey(), oldInfo, true); +} + +void CloudServiceImpl::AddSchema(CloudInfo &cloudInfo) +{ + auto keys = cloudInfo.GetSchemaKey(); + for (const auto &key : keys) { + SchemaMeta schemaMeta; + if (MetaDataManager::GetInstance().LoadMeta(key.second, schemaMeta, true)) { + continue; + } + if (GetAppSchema(cloudInfo.user, key.first, schemaMeta) != SUCCESS) { + continue; + } + MetaDataManager::GetInstance().SaveMeta(key.second, schemaMeta, true); + } +} + +int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta) +{ + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + return SERVER_UNAVAILABLE; + } + schemaMeta = instance->GetAppSchema(user, bundleName); + return SUCCESS; +} +} // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h new file mode 100644 index 00000000..9fa2ec68 --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SERVICE_IMPL_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SERVICE_IMPL_H + +#include +#include "cloud_service_stub.h" +#include "cloud/cloud_info.h" +#include "cloud/schema_meta.h" + +namespace OHOS::CloudData { +class CloudServiceImpl : public CloudServiceStub { +public: + CloudServiceImpl(); + ~CloudServiceImpl() = default; + int32_t EnableCloud(const std::string &id, const std::map &switches) override; + int32_t DisableCloud(const std::string &id) override; + int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; + int32_t Clean(const std::string &id, const std::map &actions) override; + int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; + +private: + class Factory { + public: + Factory(); + ~Factory(); + private: + std::shared_ptr product_; + }; + static Factory factory_; + + using CloudInfo = DistributedData::CloudInfo; + using SchemaMeta = DistributedData::SchemaMeta; + + void UpdateCloudInfo(CloudInfo &cloudInfo); + void AddSchema(CloudInfo &cloudInfo); + int32_t GetCloudInfo(CloudInfo &cloudInfo); + int32_t GetServerInfo(CloudInfo &cloudInfo); + int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); +}; +} // namespace OHOS::DistributedData + +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SERVICE_IMPL_H diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp new file mode 100644 index 00000000..2ccf869e --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -0,0 +1,104 @@ +/* + * 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. + */ +#define LOG_TAG "CloudServiceStub" +#include "cloud_service_stub.h" + +#include "ipc_skeleton.h" +#include "itypes_util.h" +#include "log_print.h" +#include "utils/anonymous.h" +namespace OHOS::CloudData { +using namespace DistributedData; +const CloudServiceStub::Handler CloudServiceStub::HANDLERS[TRANS_BUTT] = { + &CloudServiceStub::OnEnableCloud, + &CloudServiceStub::OnDisableCloud, + &CloudServiceStub::OnChangeAppSwitch, + &CloudServiceStub::OnClean, + &CloudServiceStub::OnNotifyDataChange, +}; + +int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) +{ + ZLOGI("code:%{public}u callingPid:%{public}u", code, IPCSkeleton::GetCallingPid()); + std::u16string local = CloudServiceStub::GetDescriptor(); + std::u16string remote = data.ReadInterfaceToken(); + if (local != remote) { + ZLOGE("local is not equal to remote"); + return -1; + } + + if (TRANS_HEAD > code || code >= TRANS_BUTT || HANDLERS[code] == nullptr) { + ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); + return -1; + } + std::string id; + if (!ITypesUtil::Unmarshal(data, id)) { + ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); + return IPC_STUB_INVALID_DATA_ERR; + } + return (this->*HANDLERS[code])(id, data, reply); +} + +int32_t CloudServiceStub::OnEnableCloud(const std::string &id, MessageParcel &data, MessageParcel &reply) +{ + std::map switches; + if (!ITypesUtil::Unmarshal(data, switches)) { + ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); + return IPC_STUB_INVALID_DATA_ERR; + } + auto result = EnableCloud(id, switches); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} + +int32_t CloudServiceStub::OnDisableCloud(const std::string &id, MessageParcel &data, MessageParcel &reply) +{ + auto result = DisableCloud(id); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} + +int32_t CloudServiceStub::OnChangeAppSwitch(const std::string &id, MessageParcel &data, MessageParcel &reply) +{ + std::string bundleName; + int32_t appSwitch = SWITCH_OFF; + if (!ITypesUtil::Unmarshal(data, bundleName, appSwitch)) { + ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); + return IPC_STUB_INVALID_DATA_ERR; + } + auto result = ChangeAppSwitch(id, bundleName, appSwitch); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} + +int32_t CloudServiceStub::OnClean(const std::string &id, MessageParcel &data, MessageParcel &reply) +{ + std::map actions; + if (!ITypesUtil::Unmarshal(data, actions)) { + ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); + return IPC_STUB_INVALID_DATA_ERR; + } + auto result = Clean(id, actions); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} + +int32_t CloudServiceStub::OnNotifyDataChange(const std::string &id, MessageParcel &data, MessageParcel &reply) +{ + std::string bundleName; + if (!ITypesUtil::Unmarshal(data, bundleName)) { + ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); + return IPC_STUB_INVALID_DATA_ERR; + } + auto result = NotifyDataChange(id, bundleName); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; +} +} // namespace OHOS::CloudData diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.h b/services/distributeddataservice/service/cloud/cloud_service_stub.h new file mode 100644 index 00000000..4175015d --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SERVICE_STUB_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SERVICE_STUB_H +#include "cloud_service.h" +#include "feature/feature_system.h" +#include "iremote_broker.h" +namespace OHOS::CloudData { +class CloudServiceStub : public CloudService, public DistributedData::FeatureSystem::Feature { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.CloudData.CloudServer"); + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override; + +private: + using Handler = int32_t (CloudServiceStub::*)(const std::string &id, MessageParcel &data, MessageParcel &reply); + int32_t OnEnableCloud(const std::string &id, MessageParcel &data, MessageParcel &reply); + int32_t OnDisableCloud(const std::string &id, MessageParcel &data, MessageParcel &reply); + int32_t OnChangeAppSwitch(const std::string &id, MessageParcel &data, MessageParcel &reply); + int32_t OnClean(const std::string &id, MessageParcel &data, MessageParcel &reply); + int32_t OnNotifyDataChange(const std::string &id, MessageParcel &data, MessageParcel &reply); + static const Handler HANDLERS[TRANS_BUTT]; +}; +} // namespace OHOS::CloudData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SERVICE_STUB_H diff --git a/services/distributeddataservice/service/cloud/cloud_syncer.cpp b/services/distributeddataservice/service/cloud/cloud_syncer.cpp new file mode 100644 index 00000000..f920c5ec --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_syncer.cpp @@ -0,0 +1,28 @@ +/* + * 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 "cloud_syncer.h" + +namespace OHOS::CloudData { +CloudSyncer &CloudSyncer::GetInstance() +{ + static CloudSyncer instance; + return instance; +} + +void CloudSyncer::Sync(const DistributedData::CloudInfo &cloudInfo) +{ +} +} // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_syncer.h b/services/distributeddataservice/service/cloud/cloud_syncer.h new file mode 100644 index 00000000..c9dd7971 --- /dev/null +++ b/services/distributeddataservice/service/cloud/cloud_syncer.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H + +#include "cloud/cloud_info.h" + +namespace OHOS::CloudData { +class CloudSyncer { +public: + static CloudSyncer &GetInstance(); + void Sync(const DistributedData::CloudInfo &cloudInfo); + +private: +}; +} // namespace OHOS::CloudData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp new file mode 100644 index 00000000..ab5f74e1 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -0,0 +1,110 @@ +/* + * 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. + */ +#define LOG_TAG "RdbGeneralStore" +#include "rdb_general_store.h" + +#include "crypto_manager.h" +#include "log_print.h" +#include "metadata/meta_data_manager.h" +#include "metadata/secret_key_meta_data.h" +#include "rdb_helper.h" +#include "relational_store_manager.h" +namespace OHOS::DistributedRdb { +using namespace DistributedData; +using namespace OHOS::NativeRdb; +class RdbOpenCallbackImpl : public RdbOpenCallback { +public: + int OnCreate(RdbStore &rdbStore) override + { + return NativeRdb::E_OK; + } + int OnUpgrade(RdbStore &rdbStore, int oldVersion, int newVersion) override + { + return NativeRdb::E_OK; + } +}; +RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appId, meta.user, meta.instanceId) +{ +} + +int32_t RdbGeneralStore::Close() +{ + return 0; +} + +int32_t RdbGeneralStore::Execute(const std::string &table, const std::string &sql) +{ + return GeneralError::E_OK; +} + +int32_t RdbGeneralStore::BatchInsert(const std::string &table, VBuckets &&values) +{ + return 0; +} + +int32_t RdbGeneralStore::BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) +{ + return 0; +} + +int32_t RdbGeneralStore::Delete(const std::string &table, const std::string &sql, Values &&args) +{ + return 0; +} + +std::shared_ptr RdbGeneralStore::Query(const std::string &table, const std::string &sql, Values &&args) +{ + return std::shared_ptr(); +} + +std::shared_ptr RdbGeneralStore::Query(const std::string &table, const GenQuery &query) +{ + return std::shared_ptr(); +} + +int32_t RdbGeneralStore::Watch(int32_t origin, Watcher &watcher) +{ + return 0; +} + +int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) +{ + return 0; +} + +int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, const GenQuery &query, Async async, int32_t wait) +{ + return 0; +} + +NativeRdb::ValuesBucket RdbGeneralStore::Convert(VBucket &&bucket) +{ + ValuesBucket rdbVBucket; + return rdbVBucket; +} + +NativeRdb::ValueObject RdbGeneralStore::Convert(Value &&value) +{ + ValueObject rdbValue; + return rdbValue; +} + +DistributedData::Value RdbGeneralStore::Convert(ValueObject &&rdbValue) +{ + DistributedData::Value value; + return value; +} + +} // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h new file mode 100644 index 00000000..272f7fcd --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_RDB_GENERAL_STORE_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_RDB_GENERAL_STORE_H +#include +#include "relational_store_delegate.h" +#include "relational_store_manager.h" + +#include "rdb_store.h" +#include "store/general_store.h" +#include "metadata/store_meta_data.h" +namespace OHOS::DistributedRdb { +class API_EXPORT RdbGeneralStore : public DistributedData::GeneralStore { +public: + using Cursor = DistributedData::Cursor; + using GenQuery = DistributedData::GenQuery; + using VBucket = DistributedData::VBucket; + using VBuckets = DistributedData::VBuckets; + using Values = DistributedData::Values; + using StoreMetaData = DistributedData::StoreMetaData; + using RdbStore = OHOS::NativeRdb::RdbStore; + using RdbDelegate = DistributedDB::RelationalStoreDelegate; + using RdbManager = DistributedDB::RelationalStoreManager; + RdbGeneralStore(const StoreMetaData &metaData); + int32_t Close() override; + int32_t Execute(const std::string &table, const std::string &sql) override; + int32_t BatchInsert(const std::string &table, VBuckets &&values) override; + int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; + int32_t Delete(const std::string &table, const std::string &sql, Values &&args) override; + std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; + std::shared_ptr Query(const std::string &table, const GenQuery &query) override; + int32_t Watch(int32_t origin, Watcher &watcher) override; + int32_t Unwatch(int32_t origin, Watcher &watcher) override; + int32_t Sync(const Devices &devices, int32_t mode, const GenQuery &query, Async async, int32_t wait) override; + +private: + NativeRdb::ValuesBucket Convert(DistributedData::VBucket &&bucket); + NativeRdb::ValueObject Convert(DistributedData::Value &&value); + DistributedData::Value Convert(NativeRdb::ValueObject &&rdbValue); + + RdbManager manager_; + std::shared_ptr store_; +}; +} // namespace OHOS::DistributedRdb +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_RDB_GENERAL_STORE_H diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 6f7eb43c..69181184 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -17,22 +17,31 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "checker/checker_manager.h" +#include "cloud/cloud_event.h" #include "communicator/device_manager_adapter.h" #include "crypto_manager.h" +#include "directory_manager.h" +#include "eventcenter/event_center.h" #include "ipc_skeleton.h" #include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "permission/permission_validator.h" #include "rdb_notifier_proxy.h" +#include "store/auto_cache.h" #include "types_export.h" #include "utils/anonymous.h" +#include "utils/constant.h" +#include "utils/converter.h" +#include "cloud/schema_meta.h" +#include "rdb_general_store.h" using OHOS::DistributedKv::AccountDelegate; using OHOS::DistributedData::CheckerManager; using OHOS::DistributedData::MetaDataManager; using OHOS::DistributedData::StoreMetaData; using OHOS::DistributedData::Anonymous; using namespace OHOS::DistributedData; +using namespace OHOS::Security::AccessToken; using DistributedDB::RelationalStoreManager; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; @@ -41,8 +50,12 @@ namespace OHOS::DistributedRdb { __attribute__((used)) RdbServiceImpl::Factory RdbServiceImpl::factory_; RdbServiceImpl::Factory::Factory() { - FeatureSystem::GetInstance().RegisterCreator("relational_store", - []() { return std::make_shared(); }); + FeatureSystem::GetInstance().RegisterCreator("relational_store", []() { + return std::make_shared(); + }); + AutoCache::GetInstance().RegCreator(RDB_DEVICE_COLLABORATION, [](const StoreMetaData &metaData) -> GeneralStore* { + return new RdbGeneralStore(metaData); + }); } RdbServiceImpl::Factory::~Factory() @@ -136,13 +149,13 @@ void RdbServiceImpl::OnClientDied(pid_t pid) }); } -bool RdbServiceImpl::CheckAccess(const RdbSyncerParam ¶m) +bool RdbServiceImpl::CheckAccess(const std::string& bundleName, const std::string& storeName) { CheckerManager::StoreInfo storeInfo; storeInfo.uid = IPCSkeleton::GetCallingUid(); storeInfo.tokenId = IPCSkeleton::GetCallingTokenID(); - storeInfo.bundleName = param.bundleName_; - storeInfo.storeId = RdbSyncer::RemoveSuffix(param.storeName_); + storeInfo.bundleName = bundleName; + storeInfo.storeId = RdbSyncer::RemoveSuffix(storeName); auto instanceId = RdbSyncer::GetInstIndex(storeInfo.tokenId, storeInfo.bundleName); if (instanceId != 0) { return false; @@ -161,15 +174,18 @@ std::string RdbServiceImpl::ObtainDistributedTableName(const std::string &device return DistributedDB::RelationalStoreManager::GetDistributedTableName(uuid, table); } -int32_t RdbServiceImpl::InitNotifier(const RdbSyncerParam& param, const sptr notifier) +int32_t RdbServiceImpl::InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) { - if (!CheckAccess(param)) { + if (!CheckAccess(param.bundleName_, "")) { ZLOGE("permission error"); return RDB_ERROR; } - + if (notifier == nullptr) { + ZLOGE("notifier is null"); + return RDB_ERROR; + } pid_t pid = IPCSkeleton::GetCallingPid(); - auto recipient = new(std::nothrow) DeathRecipientImpl([this, pid] { + auto recipient = new (std::nothrow) DeathRecipientImpl([this, pid] { OnClientDied(pid); }); if (recipient == nullptr) { @@ -278,7 +294,7 @@ std::shared_ptr RdbServiceImpl::GetRdbSyncer(const RdbSyncerParam &pa int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const std::vector &tables) { ZLOGI("enter"); - if (!CheckAccess(param)) { + if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } @@ -292,7 +308,7 @@ int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const int32_t RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, const SyncOption &option, const RdbPredicates &predicates, SyncResult &result) { - if (!CheckAccess(param)) { + if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } @@ -315,7 +331,7 @@ void RdbServiceImpl::OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResul int32_t RdbServiceImpl::DoAsync(const RdbSyncerParam ¶m, uint32_t seqNum, const SyncOption &option, const RdbPredicates &predicates) { - if (!CheckAccess(param)) { + if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } @@ -325,10 +341,9 @@ int32_t RdbServiceImpl::DoAsync(const RdbSyncerParam ¶m, uint32_t seqNum, co if (syncer == nullptr) { return RDB_ERROR; } - return syncer->DoAsync(option, predicates, - [this, pid, seqNum] (const SyncResult& result) { - OnAsyncComplete(pid, seqNum, result); - }); + return syncer->DoAsync(option, predicates, [this, pid, seqNum](const SyncResult &result) { + OnAsyncComplete(pid, seqNum, result); + }); } std::string RdbServiceImpl::TransferStringToHex(const std::string &origStr) @@ -379,7 +394,7 @@ int32_t RdbServiceImpl::DoUnSubscribe(const RdbSyncerParam& param) int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet) { - if (!CheckAccess(param)) { + if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } @@ -394,7 +409,7 @@ int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::stri int32_t RdbServiceImpl::CreateRDBTable( const RdbSyncerParam ¶m, const std::string &writePermission, const std::string &readPermission) { - if (!CheckAccess(param)) { + if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } @@ -422,7 +437,7 @@ int32_t RdbServiceImpl::CreateRDBTable( int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) { - if (!CheckAccess(param)) { + if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } @@ -446,4 +461,86 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) delete syncer; return RDB_OK; } + +int32_t RdbServiceImpl::OnInitialize() +{ + CloudEvent::StoreInfo storeInfo = { IPCSkeleton::GetCallingTokenID() }; + auto initEvt = std::make_unique(CloudEvent::FEATURE_INIT, storeInfo); + EventCenter::GetInstance().PostEvent(std::move(initEvt)); + return RDB_OK; +} + +int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) +{ + if (!CheckAccess(param.bundleName_, param.storeName_)) { + ZLOGE("permission error"); + return RDB_ERROR; + } + + if (param.schemaVersion == -1) { + return RDB_OK; + } + + auto storeMeta = GetStoreMetaData(param); + StoreMetaData oldMeta; + bool isCreated = MetaDataManager::GetInstance().LoadMeta(storeMeta.GetKey(), oldMeta, true); + if (isCreated && (oldMeta.storeType != storeMeta.storeType || + Constant::NotEqual(oldMeta.isEncrypt, storeMeta.isEncrypt) || + oldMeta.area != storeMeta.area)) { + ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " + "area:%{public}d->%{public}d", + storeMeta.bundleName.c_str(), storeMeta.storeId.c_str(), oldMeta.storeType, storeMeta.storeType, + oldMeta.isEncrypt, storeMeta.isEncrypt, oldMeta.area, storeMeta.area); + return RDB_ERROR; + } + auto saved = MetaDataManager::GetInstance().SaveMeta(storeMeta.GetKey(), storeMeta, true); + if (!saved) { + return RDB_ERROR; + } + CloudEvent::StoreInfo storeInfo{ IPCSkeleton::GetCallingTokenID(), param.bundleName_, param.storeName_, + storeMeta.instanceId, param.schemaVersion }; + auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); + EventCenter::GetInstance().PostEvent(move(event)); + return RDB_OK; +} + +StoreMetaData RdbServiceImpl::GetStoreMetaData(const RdbSyncerParam ¶m) +{ + StoreMetaData metaData; + metaData.uid = IPCSkeleton::GetCallingUid(); + metaData.tokenId = IPCSkeleton::GetCallingTokenID(); + metaData.instanceId = GetInstIndex(metaData.tokenId, param.bundleName_, param.storeName_); + metaData.bundleName = param.bundleName_; + metaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + metaData.storeId = param.storeName_; + metaData.user = std::to_string(AccountDelegate::GetInstance()->GetUserByToken(metaData.tokenId)); + metaData.storeType = param.type_; + metaData.securityLevel = param.level_; + metaData.area = param.area_; + metaData.appId = CheckerManager::GetInstance().GetAppId(Converter::ConvertToStoreInfo(metaData)); + metaData.appType = "harmony"; + metaData.hapName = param.hapName_; + metaData.dataDir = DirectoryManager::GetInstance().GetStorePath(metaData) + "/" + param.storeName_; + metaData.account = AccountDelegate::GetInstance()->GetCurrentAccountId(); + metaData.isEncrypt = param.isEncrypt_; + return metaData; +} + +int32_t RdbServiceImpl::GetInstIndex(uint32_t tokenId, const std::string &bundleName, const std::string &storeName) +{ + if (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP) { + return 0; + } + + HapTokenInfo tokenInfo; + tokenInfo.instIndex = -1; + int errCode = AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo); + if (errCode != RET_SUCCESS) { + ZLOGE("GetHapTokenInfo error:%{public}d, tokenId:0x%{public}x bundleName:%{public}s storeName:%{public}s", + errCode, tokenId, bundleName.c_str(), storeName.c_str()); + return -1; + } + return tokenInfo.instIndex; +} + } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 35f93b7c..ae939cd9 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -41,7 +41,7 @@ public: /* IPC interface */ std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; - int32_t InitNotifier(const RdbSyncerParam& param, const sptr notifier) override; + int32_t InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) override; int32_t SetDistributedTables(const RdbSyncerParam& param, const std::vector& tables) override; @@ -56,6 +56,10 @@ public: int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; + int32_t OnInitialize() override; + + int32_t GetSchema(const RdbSyncerParam ¶m) override; + protected: int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, const RdbPredicates& predicates, SyncResult& result) override; @@ -70,7 +74,7 @@ protected: private: std::string GenIdentifier(const RdbSyncerParam& param); - bool CheckAccess(const RdbSyncerParam& param); + bool CheckAccess(const std::string& bundleName, const std::string& storeName); void SyncerTimeout(std::shared_ptr syncer); @@ -78,6 +82,10 @@ private: void OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResult& result); + StoreMetaData GetStoreMetaData(const RdbSyncerParam& param); + + int32_t GetInstIndex(uint32_t tokenId, const std::string &appId, const std::string &storeName); + class DeathRecipientImpl : public IRemoteObject::DeathRecipient { public: using DeathCallback = std::function; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 931792ac..39fd62d4 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -40,15 +40,31 @@ int32_t RdbServiceStub::OnRemoteObtainDistributedTableName(MessageParcel &data, return RDB_OK; } -int32_t RdbServiceStub::OnRemoteInitNotifier(MessageParcel &data, MessageParcel &reply) +int32_t RdbServiceStub::OnGetSchema(MessageParcel &data, MessageParcel &reply) { RdbSyncerParam param; - sptr notifier; - if (!ITypesUtil::Unmarshal(data, param, notifier) || notifier == nullptr) { + if (!ITypesUtil::Unmarshal(data, param)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), param.storeName_.c_str()); return IPC_STUB_INVALID_DATA_ERR; } + auto status = GetSchema(param); + if (!ITypesUtil::Marshal(reply, status)) { + ZLOGE("Marshal status:0x%{public}x", status); + return IPC_STUB_WRITE_PARCEL_ERR; + } + return RDB_OK; +} + +int32_t RdbServiceStub::OnRemoteInitNotifier(MessageParcel &data, MessageParcel &reply) +{ + RdbSyncerParam param; + sptr notifier; + if (!ITypesUtil::Unmarshal(data, param, notifier) || param.bundleName_.empty() || notifier == nullptr) { + ZLOGE("Unmarshal bundleName:%{public}s notifier is nullptr:%{public}d", param.bundleName_.c_str(), + notifier == nullptr); + return IPC_STUB_INVALID_DATA_ERR; + } auto status = InitNotifier(param, notifier); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.h b/services/distributeddataservice/service/rdb/rdb_service_stub.h index 901a7d6e..16f4c169 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.h +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.h @@ -50,9 +50,11 @@ private: int32_t OnRemoteObtainDistributedTableName(MessageParcel& data, MessageParcel& reply); - int32_t OnRemoteInitNotifier(MessageParcel&data, MessageParcel& reply); + int32_t OnGetSchema(MessageParcel& data, MessageParcel& reply); - int32_t OnRemoteSetDistributedTables(MessageParcel &data, MessageParcel &reply); + int32_t OnRemoteInitNotifier(MessageParcel& data, MessageParcel& reply); + + int32_t OnRemoteSetDistributedTables(MessageParcel& data, MessageParcel& reply); int32_t OnRemoteDoSync(MessageParcel& data, MessageParcel& reply); @@ -79,7 +81,8 @@ private: [RDB_SERVICE_CMD_UNSUBSCRIBE] = &RdbServiceStub::OnRemoteDoUnSubscribe, [RDB_SERVICE_CMD_REMOTE_QUERY] = &RdbServiceStub::OnRemoteDoRemoteQuery, [RDB_SERVICE_CREATE_RDB_TABLE] = &RdbServiceStub::OnRemoteDoCreateTable, - [RDB_SERVICE_DESTROY_RDB_TABLE] = &RdbServiceStub::OnRemoteDoDestroyTable + [RDB_SERVICE_DESTROY_RDB_TABLE] = &RdbServiceStub::OnRemoteDoDestroyTable, + [RDB_SERVICE_CMD_GET_SCHEMA] = &RdbServiceStub::OnGetSchema }; }; } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp new file mode 100644 index 00000000..5794d6d8 --- /dev/null +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -0,0 +1,113 @@ +/* +* Copyright (c) 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 "account/account_delegate.h" +#include "metadata/meta_data_manager.h" +#include "metadata/store_meta_data.h" +#include "cloud/cloud_server.h" +#include "gtest/gtest.h" +#include "cloud/cloud_event.h" +#include "eventcenter/event_center.h" +#include "communicator/device_manager_adapter.h" +using namespace testing::ext; +using namespace OHOS::DistributedData; +using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +class CloudServerMock : public CloudServer { +public: + CloudInfo GetServerInfo(int32_t userId) override; + SchemaMeta GetAppSchema(int32_t userId, const std::string &bundleName) override; + static constexpr uint64_t REMAINSPACE = 1000; + static constexpr uint64_t TATALSPACE = 2000; +}; + +class CloudDataTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + auto cloudServerMock = new CloudServerMock(); + ASSERT_TRUE(CloudServer::RegisterCloudInstance(cloudServerMock)); + } + static void TearDownTestCase(void) + { + } + void SetUp() + { + } + void TearDown() + { + } +}; + + +CloudInfo CloudServerMock::GetServerInfo(int32_t userId) +{ + CloudInfo cloudInfo; + cloudInfo.user = userId; + cloudInfo.id = "test_cloud_id"; + cloudInfo.remainSpace = REMAINSPACE; + cloudInfo.totalSpace = TATALSPACE; + cloudInfo.enableCloud = true; + + CloudInfo::AppInfo appInfo; + appInfo.bundleName = "test_cloud_bundleName"; + appInfo.appId = "test_cloud_appid"; + appInfo.version = 1; + appInfo.cloudSwitch = true; + + cloudInfo.apps.emplace_back(std::move(appInfo)); + return cloudInfo; +} + +SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bundleName) +{ + SchemaMeta::Field field1; + field1.colName = "test_cloud_field_name1"; + field1.alias = "test_cloud_field_alias1"; + SchemaMeta::Field field2; + field2.colName = "test_cloud_field_name2"; + field2.alias = "test_cloud_field_alias2"; + + SchemaMeta::Table table; + table.name = "test_cloud_table_name"; + table.alias = "test_cloud_table_alias"; + table.fields.emplace_back(field1); + table.fields.emplace_back(field2); + + SchemaMeta::Database database; + database.name = "test_cloud_database_name"; + database.alias = "test_cloud_database_alias"; + database.tables.emplace_back(table); + + SchemaMeta schemaMeta; + schemaMeta.version = 1; + schemaMeta.databases.emplace_back(database); + + return schemaMeta; +} + +HWTEST_F(CloudDataTest, GlobalConfig, TestSize.Level0) +{ + CloudEvent::StoreInfo storeInfo{ 0, "test_cloud_bundleName", "test_cloud_database_name", 0, 1 }; + auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); + EventCenter::GetInstance().PostEvent(move(event)); + StoreMetaData storeMetaData; + storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + storeMetaData.user = OHOS::DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(0); + storeMetaData.bundleName = "test_cloud_bundleName"; + storeMetaData.storeId = "test_cloud_database_name"; + storeMetaData.instanceId = 0; + ASSERT_TRUE(MetaDataManager::GetInstance().DelMeta(storeMetaData.GetKey(), true)); + ASSERT_TRUE(MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData, true)); +} + -- Gitee From 52d1ad07278e118ab633628fd611ff26bb8b79e1 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 9 May 2023 09:29:15 +0800 Subject: [PATCH 002/437] test:add ut Signed-off-by: htt1997 --- .../framework/cloud/cloud_db.cpp | 4 +- .../framework/include/cloud/cloud_db.h | 4 +- .../framework/include/store/general_store.h | 8 +- .../service/rdb/rdb_general_store.cpp | 4 +- .../service/rdb/rdb_general_store.h | 4 +- .../service/test/BUILD.gn | 30 +++++ .../service/test/cloud_data_test.cpp | 126 +++++++++++++----- .../service/test/mock/db_store_mock.cpp | 2 +- 8 files changed, 137 insertions(+), 45 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_db.cpp b/services/distributeddataservice/framework/cloud/cloud_db.cpp index ea4d041d..d80a6d36 100644 --- a/services/distributeddataservice/framework/cloud/cloud_db.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_db.cpp @@ -45,12 +45,12 @@ std::shared_ptr CloudDB::Query(const std::string &table, const std::stri return nullptr; } -std::shared_ptr CloudDB::Query(const std::string &table, const GenQuery &query) +std::shared_ptr CloudDB::Query(const std::string &table, GenQuery &query) { return nullptr; } -int32_t CloudDB::Sync(const Devices &devices, int32_t mode, const GenQuery &query, Async async, int32_t wait) +int32_t CloudDB::Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) { return E_NOT_SUPPORT; } diff --git a/services/distributeddataservice/framework/include/cloud/cloud_db.h b/services/distributeddataservice/framework/include/cloud/cloud_db.h index 9b67c9a4..6d963661 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_db.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_db.h @@ -26,8 +26,8 @@ public: int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; int32_t Delete(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; - std::shared_ptr Query(const std::string &table, const GenQuery &query) override; - int32_t Sync(const Devices &devices, int32_t mode, const GenQuery &query, Async async, int32_t wait) override; + std::shared_ptr Query(const std::string &table, GenQuery &query) override; + int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 3b88c4f4..3c12f288 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -29,8 +29,6 @@ public: virtual ~GeneralStore() = default; - virtual int32_t Close() = 0; - virtual int32_t Execute(const std::string &table, const std::string &sql) = 0; virtual int32_t BatchInsert(const std::string &table, VBuckets &&values) = 0; @@ -41,13 +39,15 @@ public: virtual std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) = 0; - virtual std::shared_ptr Query(const std::string &table, const GenQuery &query) = 0; + virtual std::shared_ptr Query(const std::string &table, GenQuery &query) = 0; - virtual int32_t Sync(const Devices &devices, int32_t mode, const GenQuery &query, Async async, int32_t wait) = 0; + virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) = 0; virtual int32_t Watch(int32_t origin, Watcher &watcher) = 0; virtual int32_t Unwatch(int32_t origin, Watcher &watcher) = 0; + + virtual int32_t Close() = 0; }; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_STORE_H diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index ab5f74e1..decce6c9 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -69,7 +69,7 @@ std::shared_ptr RdbGeneralStore::Query(const std::string &table, const s return std::shared_ptr(); } -std::shared_ptr RdbGeneralStore::Query(const std::string &table, const GenQuery &query) +std::shared_ptr RdbGeneralStore::Query(const std::string &table, GenQuery &query) { return std::shared_ptr(); } @@ -84,7 +84,7 @@ int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) return 0; } -int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, const GenQuery &query, Async async, int32_t wait) +int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) { return 0; } diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 272f7fcd..7f10e2ce 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -41,10 +41,10 @@ public: int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; int32_t Delete(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; - std::shared_ptr Query(const std::string &table, const GenQuery &query) override; + std::shared_ptr Query(const std::string &table, GenQuery &query) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; - int32_t Sync(const Devices &devices, int32_t mode, const GenQuery &query, Async async, int32_t wait) override; + int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) override; private: NativeRdb::ValuesBucket Convert(DistributedData::VBucket &&bucket); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 70ad6fdd..478ac4ad 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos_var.gni") import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") module_output_path = "datamgr_service/distributeddatafwk" @@ -35,6 +36,34 @@ config("module_private_config") { ] } +ohos_unittest("CloudDataTest") { + module_out_path = module_output_path + sources = [ + "cloud_data_test.cpp", + "mock/db_change_data_mock.cpp", + "mock/db_store_mock.cpp", + ] + + configs = [ ":module_private_config" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + ] + + deps = [ + "../../adapter:distributeddata_adapter", + "../../framework:distributeddatasvcfwk", + "../../service:distributeddatasvc", + "${kv_store_distributeddb_path}:distributeddb", + "//third_party/googletest:gtest_main", + ] +} + ohos_unittest("ConfigFactoryTest") { module_out_path = module_output_path sources = [ "config_factory_test.cpp" ] @@ -146,6 +175,7 @@ group("unittest") { deps = [] deps += [ + ":CloudDataTest", ":ConfigFactoryTest", ":CryptoManagerTest", ":DeviceMatrixTest", diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 5794d6d8..82b84b73 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -12,44 +12,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define LOG_TAG "CloudDataTest" #include "account/account_delegate.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" +#include "feature/feature_system.h" #include "cloud/cloud_server.h" #include "gtest/gtest.h" #include "cloud/cloud_event.h" #include "eventcenter/event_center.h" #include "communicator/device_manager_adapter.h" +#include "metadata/store_meta_data_local.h" +#include "ipc_skeleton.h" +#include "log_print.h" +#include "mock/db_store_mock.h" +#include "device_matrix.h" using namespace testing::ext; using namespace OHOS::DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; + +static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; +static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; +static constexpr const char *TEST_CLOUD_STORE = "test_cloud_database_name"; + class CloudServerMock : public CloudServer { public: CloudInfo GetServerInfo(int32_t userId) override; SchemaMeta GetAppSchema(int32_t userId, const std::string &bundleName) override; + virtual ~CloudServerMock() = default; static constexpr uint64_t REMAINSPACE = 1000; static constexpr uint64_t TATALSPACE = 2000; }; -class CloudDataTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - auto cloudServerMock = new CloudServerMock(); - ASSERT_TRUE(CloudServer::RegisterCloudInstance(cloudServerMock)); - } - static void TearDownTestCase(void) - { - } - void SetUp() - { - } - void TearDown() - { - } -}; - - CloudInfo CloudServerMock::GetServerInfo(int32_t userId) { CloudInfo cloudInfo; @@ -60,8 +54,8 @@ CloudInfo CloudServerMock::GetServerInfo(int32_t userId) cloudInfo.enableCloud = true; CloudInfo::AppInfo appInfo; - appInfo.bundleName = "test_cloud_bundleName"; - appInfo.appId = "test_cloud_appid"; + appInfo.bundleName = TEST_CLOUD_BUNDLE; + appInfo.appId = TEST_CLOUD_APPID; appInfo.version = 1; appInfo.cloudSwitch = true; @@ -76,7 +70,7 @@ SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bund field1.alias = "test_cloud_field_alias1"; SchemaMeta::Field field2; field2.colName = "test_cloud_field_name2"; - field2.alias = "test_cloud_field_alias2"; + field2.alias = "test_cloud_field_alias2"; SchemaMeta::Table table; table.name = "test_cloud_table_name"; @@ -85,7 +79,7 @@ SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bund table.fields.emplace_back(field2); SchemaMeta::Database database; - database.name = "test_cloud_database_name"; + database.name = TEST_CLOUD_STORE; database.alias = "test_cloud_database_alias"; database.tables.emplace_back(table); @@ -96,18 +90,86 @@ SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bund return schemaMeta; } -HWTEST_F(CloudDataTest, GlobalConfig, TestSize.Level0) +class CloudDataTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + +protected: + static constexpr const char *TEST_DISTRIBUTEDDATA_BUNDLE = "test_distributeddata"; + static constexpr const char *TEST_DISTRIBUTEDDATA_STORE = "test_service_meta"; + static constexpr const char *TEST_DISTRIBUTEDDATA_USER = "-1"; + + void InitMetaData(); + static std::shared_ptr dbStoreMock_; + StoreMetaData metaData_; +}; + +std::shared_ptr CloudDataTest::dbStoreMock_ = std::make_shared(); + +void CloudDataTest::InitMetaData() { - CloudEvent::StoreInfo storeInfo{ 0, "test_cloud_bundleName", "test_cloud_database_name", 0, 1 }; - auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); - EventCenter::GetInstance().PostEvent(move(event)); + metaData_.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + metaData_.appId = TEST_DISTRIBUTEDDATA_BUNDLE; + metaData_.bundleName = TEST_DISTRIBUTEDDATA_BUNDLE; + metaData_.user = TEST_DISTRIBUTEDDATA_USER; + metaData_.area = OHOS::DistributedKv::EL1; + metaData_.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + metaData_.instanceId = 0; + metaData_.isAutoSync = true; + metaData_.storeType = 1; + metaData_.storeId = TEST_DISTRIBUTEDDATA_STORE; + PolicyValue value; + value.type = OHOS::DistributedKv::PolicyType::IMMEDIATE_SYNC_ON_ONLINE; +} + +void CloudDataTest::SetUpTestCase(void) +{ + MetaDataManager::GetInstance().Initialize(dbStoreMock_, nullptr, [](const auto &, auto) { + DeviceMatrix::GetInstance().OnChanged(DeviceMatrix::META_STORE_MASK); + }); + + auto cloudServerMock = new CloudServerMock(); + ASSERT_TRUE(CloudServer::RegisterCloudInstance(cloudServerMock)); + FeatureSystem::GetInstance().GetCreator("cloud")(); +} + +void CloudDataTest::TearDownTestCase() {} + +void CloudDataTest::SetUp() +{ + InitMetaData(); + MetaDataManager::GetInstance().SaveMeta(metaData_.GetKey(), metaData_); + StoreMetaData storeMetaData; storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - storeMetaData.user = OHOS::DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(0); - storeMetaData.bundleName = "test_cloud_bundleName"; - storeMetaData.storeId = "test_cloud_database_name"; + storeMetaData.user = -1; + storeMetaData.bundleName = TEST_CLOUD_BUNDLE; + storeMetaData.storeId = TEST_CLOUD_STORE; storeMetaData.instanceId = 0; - ASSERT_TRUE(MetaDataManager::GetInstance().DelMeta(storeMetaData.GetKey(), true)); - ASSERT_TRUE(MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData, true)); + storeMetaData.isAutoSync = true; + storeMetaData.storeType = 1; + storeMetaData.area = OHOS::DistributedKv::EL1; + storeMetaData.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + MetaDataManager::GetInstance().SaveMeta(storeMetaData.GetKey(), storeMetaData); } +void CloudDataTest::TearDown() {} + +HWTEST_F(CloudDataTest, GlobalConfig, TestSize.Level0) +{ + ZLOGI("CloudDataTest start"); + std::shared_ptr cloudServerMock = std::make_shared(); + auto cloudInfo = cloudServerMock->GetServerInfo(-1); + ASSERT_TRUE(MetaDataManager::GetInstance().DelMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), true)); + StoreMetaData storeMetaData; + ASSERT_FALSE( + MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); + CloudEvent::StoreInfo storeInfo{ 0, TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0, 1 }; + auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); + EventCenter::GetInstance().PostEvent(move(event)); + ASSERT_TRUE( + MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); +} diff --git a/services/distributeddataservice/service/test/mock/db_store_mock.cpp b/services/distributeddataservice/service/test/mock/db_store_mock.cpp index 87639965..edc1cb3b 100644 --- a/services/distributeddataservice/service/test/mock/db_store_mock.cpp +++ b/services/distributeddataservice/service/test/mock/db_store_mock.cpp @@ -273,7 +273,7 @@ DBStatus DBStoreMock::GetEntries(ConcurrentMap &store, const Key &ke DBStatus DBStoreMock::PutBatch(ConcurrentMap &store, const std::vector &entries) { for (auto &entry : entries) { - entries_.InsertOrAssign(entry.key, entry.value); + store.InsertOrAssign(entry.key, entry.value); } DBChangeDataMock changeData({}, entries, {}); observers_.ForEachCopies([&changeData](const auto &observer, auto &keys) mutable { -- Gitee From 966aa02b3b57bce56cf6b8cb00460a861f5c0d26 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 9 May 2023 14:30:01 +0800 Subject: [PATCH 003/437] fix:add bind Signed-off-by: htt1997 --- datamgr_service.gni | 1 + .../distributeddataservice/service/BUILD.gn | 2 +- .../service/rdb/rdb_general_store.cpp | 19 +++------------ .../service/rdb/rdb_general_store.h | 23 +++++++++++-------- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/datamgr_service.gni b/datamgr_service.gni index 6ec402a1..c3fa0d49 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -26,6 +26,7 @@ datashare_path = "//foundation/distributeddatamgr/data_share" ipc_core_path = "//foundation/communication/ipc/interfaces/innerkits/ipc_core" device_manager_path = "//foundation/distributedhardware/device_manager" + declare_args() { datamgr_service_power = true if (!defined(global_parts_info.power_manager_native_powermgr_client) || diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 62317e78..d60d41f0 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -55,7 +55,7 @@ ohos_shared_library("distributeddatasvc") { include_dirs = [ "../../../../data_object/frameworks/innerkitsimpl/include", "../../../../relational_store/interfaces/inner_api/cloud_data/include", - "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb/include", + "../../../../relational_store/interfaces/inner_api/rdb/include", "${kv_store_distributeddb_path}", ] sources = [ diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index decce6c9..53cfb7d5 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -89,22 +89,9 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu return 0; } -NativeRdb::ValuesBucket RdbGeneralStore::Convert(VBucket &&bucket) +int32_t RdbGeneralStore::Bind(std::shared_ptr cloudDb) { - ValuesBucket rdbVBucket; - return rdbVBucket; -} - -NativeRdb::ValueObject RdbGeneralStore::Convert(Value &&value) -{ - ValueObject rdbValue; - return rdbValue; -} - -DistributedData::Value RdbGeneralStore::Convert(ValueObject &&rdbValue) -{ - DistributedData::Value value; - return value; + cloudDb_ = std::move(cloudDb); + return 0; } - } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 7f10e2ce..8970e5ca 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_RDB_GENERAL_STORE_H -#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_RDB_GENERAL_STORE_H +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H #include #include "relational_store_delegate.h" #include "relational_store_manager.h" @@ -29,30 +29,33 @@ public: using GenQuery = DistributedData::GenQuery; using VBucket = DistributedData::VBucket; using VBuckets = DistributedData::VBuckets; + using Value = DistributedData::Value; using Values = DistributedData::Values; using StoreMetaData = DistributedData::StoreMetaData; + using CloudDB = DistributedData::CloudDB; using RdbStore = OHOS::NativeRdb::RdbStore; - using RdbDelegate = DistributedDB::RelationalStoreDelegate; - using RdbManager = DistributedDB::RelationalStoreManager; + using RdbDelegate = DistributedDB::RelationalStoreDelegate; + using RdbManager = DistributedDB::RelationalStoreManager; + RdbGeneralStore(const StoreMetaData &metaData); - int32_t Close() override; + int32_t Bind(std::shared_ptr cloudDb) override; int32_t Execute(const std::string &table, const std::string &sql) override; int32_t BatchInsert(const std::string &table, VBuckets &&values) override; int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; int32_t Delete(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, GenQuery &query) override; + int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; - int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) override; + int32_t Close() override; private: - NativeRdb::ValuesBucket Convert(DistributedData::VBucket &&bucket); - NativeRdb::ValueObject Convert(DistributedData::Value &&value); - DistributedData::Value Convert(NativeRdb::ValueObject &&rdbValue); + static constexpr uint32_t ITERATE_TIMES = 10000; RdbManager manager_; std::shared_ptr store_; + std::shared_ptr cloudDb_; }; } // namespace OHOS::DistributedRdb -#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_RDB_GENERAL_STORE_H +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H -- Gitee From 5593ba7eac5bec8424018e811d67ec9d549bf3a5 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 9 May 2023 16:02:19 +0800 Subject: [PATCH 004/437] fix:codecheck Signed-off-by: htt1997 --- services/distributeddataservice/service/BUILD.gn | 2 +- .../distributeddataservice/service/test/cloud_data_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index d60d41f0..0e136c63 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -159,8 +159,8 @@ ohos_shared_library("distributeddatasvc") { "hiviewdfx_hilog_native:libhilog", "huks:libhukssdk", "ipc:ipc_core", - "relational_store:cloud_data", "kv_store:distributeddata_inner", + "relational_store:cloud_data", "relational_store:native_rdb", "relational_store:rdb_bms_adapter", "relational_store:rdb_data_share_adapter", diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 82b84b73..b40cbe17 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -158,7 +158,7 @@ void CloudDataTest::SetUp() void CloudDataTest::TearDown() {} -HWTEST_F(CloudDataTest, GlobalConfig, TestSize.Level0) +HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) { ZLOGI("CloudDataTest start"); std::shared_ptr cloudServerMock = std::make_shared(); -- Gitee From eb4b5f2cf4bb1bb21b4f229c1939eb84c04171fe Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 9 May 2023 16:15:24 +0800 Subject: [PATCH 005/437] fix:storeMeta load from sync table Signed-off-by: htt1997 --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index fafc5c9e..7c6a67c1 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -87,7 +87,7 @@ CloudServiceImpl::CloudServiceImpl() storeMetaData.bundleName = rdbEvent.GetStoreInfo().bundleName; storeMetaData.storeId = rdbEvent.GetStoreInfo().storeName; storeMetaData.instanceId = rdbEvent.GetStoreInfo().instanceId; - if (!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData, true)) { + if (!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData)) { return; } AutoCache::GetInstance().CreateTable(storeMetaData, schemaMeta); -- Gitee From cb577fc375c003d2f55f51e4347fb8752c0928dc Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 9 May 2023 16:17:05 +0800 Subject: [PATCH 006/437] fix:format check Signed-off-by: htt1997 --- services/distributeddataservice/service/test/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 478ac4ad..0c5173a0 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -56,10 +56,10 @@ ohos_unittest("CloudDataTest") { ] deps = [ + "${kv_store_distributeddb_path}:distributeddb", "../../adapter:distributeddata_adapter", "../../framework:distributeddatasvcfwk", "../../service:distributeddatasvc", - "${kv_store_distributeddb_path}:distributeddb", "//third_party/googletest:gtest_main", ] } -- Gitee From df20a1638e2729bb5b55e78e43e0983319c68f8a Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 9 May 2023 22:33:52 +0800 Subject: [PATCH 007/437] fix:change Signed-off-by: htt1997 --- .../framework/cloud/cloud_info.cpp | 12 +++- .../framework/include/cloud/cloud_db.h | 2 + .../framework/include/cloud/cloud_event.h | 1 - .../framework/include/cloud/cloud_info.h | 4 +- .../framework/include/store/auto_cache.h | 4 +- .../framework/include/store/general_store.h | 3 + .../framework/store/auto_cache.cpp | 26 ++----- .../distributeddataservice/service/BUILD.gn | 2 +- .../service/cloud/cloud_service_impl.cpp | 70 +++++++++++++------ .../service/cloud/cloud_service_impl.h | 4 ++ .../service/rdb/rdb_general_store.cpp | 6 ++ .../service/rdb/rdb_general_store.h | 4 +- .../service/rdb/rdb_service_impl.cpp | 2 +- .../service/test/cloud_data_test.cpp | 23 +++--- 14 files changed, 100 insertions(+), 63 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_info.cpp b/services/distributeddataservice/framework/cloud/cloud_info.cpp index d3560bb8..2f44ff85 100644 --- a/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -68,15 +68,21 @@ std::map CloudInfo::GetSchemaKey() const { std::map keys; for (const auto &app : apps) { - const auto key = GetKey(SCHEMA_PREFIX, { std::to_string(user), id, app.bundleName }); + const auto key = GetKey( + SCHEMA_PREFIX, { std::to_string(user), app.bundleName, std::to_string(app.instanceId) }); keys.insert_or_assign(app.bundleName, key); } return keys; } -std::string CloudInfo::GetSchemaKey(std::string bundleName) const +std::string CloudInfo::GetSchemaKey(const std::string &bundleName, const int32_t instanceId) const { - return GetKey(SCHEMA_PREFIX, { std::to_string(user), id, bundleName }); + return GetKey(SCHEMA_PREFIX, { std::to_string(user), bundleName, std::to_string(instanceId) }); +} + +std::string CloudInfo::GetSchemaKey(const StoreMetaData &meta) +{ + return GetKey(SCHEMA_PREFIX, { meta.user, meta.bundleName, std::to_string(meta.instanceId) }); } bool CloudInfo::IsValid() const diff --git a/services/distributeddataservice/framework/include/cloud/cloud_db.h b/services/distributeddataservice/framework/include/cloud/cloud_db.h index 57d15f5c..c7599bda 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_db.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_db.h @@ -28,6 +28,8 @@ public: using Watcher = GeneralWatcher; using Async = std::function>)>; using Devices = std::vector; + virtual ~CloudDB() = default; + virtual int32_t Execute(const std::string &table, const std::string &sql, const VBucket &extend); virtual int32_t BatchInsert(const std::string &table, VBuckets &&values, VBuckets &extends); diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h index d01ab0f2..5a5efc87 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -34,7 +34,6 @@ public: std::string bundleName; std::string storeName; int32_t instanceId = 0; - int32_t schemaVersion = -1; }; CloudEvent(int32_t evtId, StoreInfo storeInfo, const std::string &featureName = "relational_store"); diff --git a/services/distributeddataservice/framework/include/cloud/cloud_info.h b/services/distributeddataservice/framework/include/cloud/cloud_info.h index d16c8cfc..dc732027 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_info.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_info.h @@ -15,6 +15,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_INFO_H #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_INFO_H +#include "metadata/store_meta_data.h" #include "serializable/serializable.h" namespace OHOS::DistributedData { class API_EXPORT CloudInfo final : public Serializable { @@ -38,7 +39,8 @@ public: std::string GetKey() const; std::map GetSchemaKey() const; - std::string GetSchemaKey(std::string bundleName) const; + std::string GetSchemaKey(const std::string &bundleName, const int32_t instanceId = 0) const; + static std::string GetSchemaKey(const StoreMetaData &meta); bool IsValid() const; bool IsExist(const std::string &bundleName) const; static std::string GetPrefix(const std::initializer_list &field); diff --git a/services/distributeddataservice/framework/include/store/auto_cache.h b/services/distributeddataservice/framework/include/store/auto_cache.h index 3a957e2a..8884a789 100644 --- a/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/services/distributeddataservice/framework/include/store/auto_cache.h @@ -44,9 +44,7 @@ public: API_EXPORT void Bind(std::shared_ptr executor); - API_EXPORT Store GetStore(const StoreMetaData &meta, const Watchers &watchers); - - API_EXPORT int32_t CreateTable(const StoreMetaData &storeMetaData, const SchemaMeta &schemaMeta); + API_EXPORT Store GetStore(const StoreMetaData &meta, const Watchers &watchers, bool setWatchers = true); API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId); diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 56cdcf87..097f8d9a 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -23,6 +23,7 @@ #include "store/general_watcher.h" namespace OHOS::DistributedData { class CloudDB; +class SchemaMeta; class GeneralStore { public: using Watcher = GeneralWatcher; @@ -33,6 +34,8 @@ public: virtual int32_t Bind(std::shared_ptr cloudDb) = 0; + virtual int32_t SetSchema(const SchemaMeta &schemaMeta) = 0; + virtual int32_t Execute(const std::string &table, const std::string &sql) = 0; virtual int32_t BatchInsert(const std::string &table, VBuckets &&values) = 0; diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index 11dedf24..bb22477f 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -52,7 +52,7 @@ AutoCache::~AutoCache() } } -AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers &watchers) +AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers &watchers, bool setWatchers) { Store store; if (meta.storeType >= MAX_CREATOR_NUM || !creators_[meta.storeType]) { @@ -60,10 +60,12 @@ AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers & } stores_.Compute(meta.tokenId, - [this, &meta, &watchers, &store](auto &, std::map &stores) -> bool { + [this, &meta, &watchers, &store, setWatchers](auto &, std::map &stores) -> bool { auto it = stores.find(meta.storeId); if (it != stores.end()) { - it->second.SetObservers(watchers); + if (setWatchers) { + it->second.SetObservers(watchers); + } store = it->second; return !stores.empty(); } @@ -79,24 +81,6 @@ AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers & return store; } -int32_t AutoCache::CreateTable(const StoreMetaData &storeMetaData, const SchemaMeta &schemaMeta) -{ - stores_.Compute(storeMetaData.tokenId, - [this, &storeMetaData, &schemaMeta](auto &, std::map &stores) -> bool { - auto it = stores.find(storeMetaData.storeId); - if (it != stores.end()) { - //it->second->CreateTable(schemaMeta) - return true; - } - auto *dbStore = creators_[storeMetaData.storeType](storeMetaData); - if (dbStore != nullptr) { - //dbStore->CreateTable(schemaMeta) - } - return false; - }); - return 0; -} - void AutoCache::CloseStore(uint32_t tokenId, const std::string &storeId) { stores_.ComputeIfPresent(tokenId, [&storeId](auto &key, std::map &delegates) { diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 0e136c63..59998168 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -142,6 +142,7 @@ ohos_shared_library("distributeddatasvc") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", + "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/cloud_data:cloud_data_inner", ] external_deps = [ @@ -160,7 +161,6 @@ ohos_shared_library("distributeddatasvc") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", - "relational_store:cloud_data", "relational_store:native_rdb", "relational_store:rdb_bms_adapter", "relational_store:rdb_data_share_adapter", diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 7c6a67c1..e1474659 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -64,40 +64,30 @@ CloudServiceImpl::CloudServiceImpl() EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { auto &rdbEvent = static_cast(event); - CloudInfo cloudInfo; - cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); - if (GetServerInfo(cloudInfo) != SUCCESS) { - ZLOGE("failed, user:%{public}d", cloudInfo.user); - return; - } + auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); + auto schemaMeta = GetSchemaMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); + auto storeMeta = GetStoreMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, + rdbEvent.GetStoreInfo().instanceId); + + AutoCache::Watchers watchers; + auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers, false); + store->SetSchema(schemaMeta); auto instance = CloudServer::GetInstance(); if (instance == nullptr) { + ZLOGE("instance is nullptr"); return; } - SchemaMeta schemaMeta; - std::string schemaKey = cloudInfo.GetSchemaKey(rdbEvent.GetStoreInfo().bundleName); - if (!MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true) || - schemaMeta.version != rdbEvent.GetStoreInfo().schemaVersion) { - schemaMeta = instance->GetAppSchema(cloudInfo.user, rdbEvent.GetStoreInfo().bundleName); - MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); - } - StoreMetaData storeMetaData; - storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - storeMetaData.user = std::to_string(cloudInfo.user); - storeMetaData.bundleName = rdbEvent.GetStoreInfo().bundleName; - storeMetaData.storeId = rdbEvent.GetStoreInfo().storeName; - storeMetaData.instanceId = rdbEvent.GetStoreInfo().instanceId; - if (!MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData)) { - return; - } - AutoCache::GetInstance().CreateTable(storeMetaData, schemaMeta); for (auto &database : schemaMeta.databases) { if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync*/) { continue; } auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); + if (cloudDB != nullptr) { + store->Bind(cloudDB); + } //do sync } + return; }); } @@ -249,4 +239,38 @@ int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleNa schemaMeta = instance->GetAppSchema(user, bundleName); return SUCCESS; } + +SchemaMeta CloudServiceImpl::GetSchemaMata(int32_t userId, const std::string &bundleName, int32_t instanceId) +{ + SchemaMeta schemaMeta; + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGE("instance is nullptr"); + return schemaMeta; + } + auto cloudInfo = instance->GetServerInfo(userId); + if (!cloudInfo.IsValid()) { + ZLOGE("cloudInfo is invalid"); + return schemaMeta; + } + std::string schemaKey = cloudInfo.GetSchemaKey(bundleName, instanceId); + if (!MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true)) { + schemaMeta = instance->GetAppSchema(cloudInfo.user, bundleName); + MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); + } + return schemaMeta; +} + +StoreMetaData CloudServiceImpl::GetStoreMata(int32_t userId, const std::string &bundleName, + const std::string &storeName, int32_t instanceId) +{ + StoreMetaData storeMetaData; + storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + storeMetaData.user = std::to_string(userId); + storeMetaData.bundleName = bundleName; + storeMetaData.storeId = storeName; + storeMetaData.instanceId = instanceId; + MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData); + return storeMetaData; +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 9fa2ec68..d4086f5f 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -24,6 +24,7 @@ namespace OHOS::CloudData { class CloudServiceImpl : public CloudServiceStub { public: + using StoreMetaData = DistributedData::StoreMetaData; CloudServiceImpl(); ~CloudServiceImpl() = default; int32_t EnableCloud(const std::string &id, const std::map &switches) override; @@ -47,6 +48,9 @@ private: void UpdateCloudInfo(CloudInfo &cloudInfo); void AddSchema(CloudInfo &cloudInfo); + SchemaMeta GetSchemaMata(int32_t userId, const std::string &bundleName, int32_t instanceId); + StoreMetaData GetStoreMata(int32_t userId, const std::string &bundleName, const std::string &storeName, + int32_t instanceId); int32_t GetCloudInfo(CloudInfo &cloudInfo); int32_t GetServerInfo(CloudInfo &cloudInfo); int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 53cfb7d5..a6745e3d 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -94,4 +94,10 @@ int32_t RdbGeneralStore::Bind(std::shared_ptr cloudDb) cloudDb_ = std::move(cloudDb); return 0; } + +int32_t RdbGeneralStore::SetSchema(const SchemaMeta &schemaMeta) +{ + //delegate_->SetSchema(schemaMeta); + return GeneralError::E_OK; +} } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 8970e5ca..c0051fab 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -23,7 +23,7 @@ #include "store/general_store.h" #include "metadata/store_meta_data.h" namespace OHOS::DistributedRdb { -class API_EXPORT RdbGeneralStore : public DistributedData::GeneralStore { +class RdbGeneralStore : public DistributedData::GeneralStore { public: using Cursor = DistributedData::Cursor; using GenQuery = DistributedData::GenQuery; @@ -32,6 +32,7 @@ public: using Value = DistributedData::Value; using Values = DistributedData::Values; using StoreMetaData = DistributedData::StoreMetaData; + using SchemaMeta = DistributedData::SchemaMeta; using CloudDB = DistributedData::CloudDB; using RdbStore = OHOS::NativeRdb::RdbStore; using RdbDelegate = DistributedDB::RelationalStoreDelegate; @@ -39,6 +40,7 @@ public: RdbGeneralStore(const StoreMetaData &metaData); int32_t Bind(std::shared_ptr cloudDb) override; + int32_t SetSchema(const SchemaMeta &schemaMeta) override; int32_t Execute(const std::string &table, const std::string &sql) override; int32_t BatchInsert(const std::string &table, VBuckets &&values) override; int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index c2dddd0f..1b38797b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -500,7 +500,7 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) return RDB_ERROR; } CloudEvent::StoreInfo storeInfo{ IPCSkeleton::GetCallingTokenID(), param.bundleName_, param.storeName_, - storeMeta.instanceId, param.schemaVersion }; + storeMeta.instanceId }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); EventCenter::GetInstance().PostEvent(move(event)); return RDB_OK; diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index b40cbe17..988cee18 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -14,19 +14,19 @@ */ #define LOG_TAG "CloudDataTest" #include "account/account_delegate.h" -#include "metadata/meta_data_manager.h" -#include "metadata/store_meta_data.h" -#include "feature/feature_system.h" -#include "cloud/cloud_server.h" -#include "gtest/gtest.h" #include "cloud/cloud_event.h" -#include "eventcenter/event_center.h" +#include "cloud/cloud_server.h" #include "communicator/device_manager_adapter.h" -#include "metadata/store_meta_data_local.h" +#include "device_matrix.h" +#include "eventcenter/event_center.h" +#include "feature/feature_system.h" +#include "gtest/gtest.h" #include "ipc_skeleton.h" #include "log_print.h" +#include "metadata/meta_data_manager.h" +#include "metadata/store_meta_data.h" +#include "metadata/store_meta_data_local.h" #include "mock/db_store_mock.h" -#include "device_matrix.h" using namespace testing::ext; using namespace OHOS::DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; @@ -158,6 +158,13 @@ void CloudDataTest::SetUp() void CloudDataTest::TearDown() {} +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) { ZLOGI("CloudDataTest start"); -- Gitee From c7c7a00c7fa3f2e6e99bde302a3afc808906ce15 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 10:01:55 +0800 Subject: [PATCH 008/437] fix:code check Signed-off-by: htt1997 --- datamgr_service.gni | 2 ++ services/distributeddataservice/service/BUILD.gn | 2 +- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 2 +- .../distributeddataservice/service/rdb/rdb_general_store.h | 2 +- .../distributeddataservice/service/rdb/rdb_service_impl.cpp | 4 ---- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/datamgr_service.gni b/datamgr_service.gni index c3fa0d49..15f8ddfc 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -15,6 +15,8 @@ distributedfilejs_path = "//foundation/distributeddatamgr/distributedfile" kv_store_path = "//foundation/distributeddatamgr/kv_store" +relational_store_path = "//foundation/distributeddatamgr/relational_store" + kv_store_common_path = "${kv_store_path}/frameworks/common" kv_store_distributeddb_path = "${kv_store_path}/frameworks/libs/distributeddb" diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 59998168..49e56b7d 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -142,7 +142,7 @@ ohos_shared_library("distributeddatasvc") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", - "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/cloud_data:cloud_data_inner", + "${relational_store_path}/interfaces/inner_api/cloud_data:cloud_data_inner", ] external_deps = [ diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index a6745e3d..15debe6e 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -97,7 +97,7 @@ int32_t RdbGeneralStore::Bind(std::shared_ptr cloudDb) int32_t RdbGeneralStore::SetSchema(const SchemaMeta &schemaMeta) { - //delegate_->SetSchema(schemaMeta); + //SetSchema; return GeneralError::E_OK; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index c0051fab..af8ca7d9 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -38,7 +38,7 @@ public: using RdbDelegate = DistributedDB::RelationalStoreDelegate; using RdbManager = DistributedDB::RelationalStoreManager; - RdbGeneralStore(const StoreMetaData &metaData); + explicit RdbGeneralStore(const StoreMetaData &metaData); int32_t Bind(std::shared_ptr cloudDb) override; int32_t SetSchema(const SchemaMeta &schemaMeta) override; int32_t Execute(const std::string &table, const std::string &sql) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 1b38797b..209ee447 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -479,10 +479,6 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) return RDB_ERROR; } - if (param.schemaVersion == -1) { - return RDB_OK; - } - auto storeMeta = GetStoreMetaData(param); StoreMetaData oldMeta; bool isCreated = MetaDataManager::GetInstance().LoadMeta(storeMeta.GetKey(), oldMeta, true); -- Gitee From 00db61da3384f7a23a43cd4cc6ff06786d8e6ef1 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 10:29:03 +0800 Subject: [PATCH 009/437] fix:code check Signed-off-by: htt1997 --- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 15debe6e..bb69635c 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -97,7 +97,7 @@ int32_t RdbGeneralStore::Bind(std::shared_ptr cloudDb) int32_t RdbGeneralStore::SetSchema(const SchemaMeta &schemaMeta) { - //SetSchema; + //SetSchema return GeneralError::E_OK; } } // namespace OHOS::DistributedRdb -- Gitee From 45d3e2a47b097706ed59b728a626b7192f206d8d Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 11:27:41 +0800 Subject: [PATCH 010/437] fix:code check Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 5 +++-- .../service/rdb/rdb_service_impl.cpp | 4 ++-- .../service/test/cloud_data_test.cpp | 8 ++++---- .../service/test/mock/db_store_mock.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index e1474659..d45c8808 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -78,14 +78,14 @@ CloudServiceImpl::CloudServiceImpl() return; } for (auto &database : schemaMeta.databases) { - if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync*/) { + if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync */) { continue; } auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); if (cloudDB != nullptr) { store->Bind(cloudDB); } - //do sync + // do sync } return; }); @@ -166,6 +166,7 @@ int32_t CloudServiceImpl::Clean(const std::string &id, const std::mapGetUserByToken(token); std::string appId = CheckerManager::GetInstance().GetAppId(storeInfo); std::string identifier = RelationalStoreManager::GetRelationalStoreIdentifier( @@ -495,7 +495,7 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) if (!saved) { return RDB_ERROR; } - CloudEvent::StoreInfo storeInfo{ IPCSkeleton::GetCallingTokenID(), param.bundleName_, param.storeName_, + CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, param.storeName_, storeMeta.instanceId }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); EventCenter::GetInstance().PostEvent(move(event)); diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 988cee18..ffce5e23 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -13,6 +13,9 @@ * limitations under the License. */ #define LOG_TAG "CloudDataTest" +#include "gtest/gtest.h" +#include "log_print.h" +#include "ipc_skeleton.h" #include "account/account_delegate.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" @@ -20,9 +23,6 @@ #include "device_matrix.h" #include "eventcenter/event_center.h" #include "feature/feature_system.h" -#include "gtest/gtest.h" -#include "ipc_skeleton.h" -#include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "metadata/store_meta_data_local.h" @@ -174,7 +174,7 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) StoreMetaData storeMetaData; ASSERT_FALSE( MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); - CloudEvent::StoreInfo storeInfo{ 0, TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0, 1 }; + CloudEvent::StoreInfo storeInfo { 0, TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0, 1 }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); EventCenter::GetInstance().PostEvent(move(event)); ASSERT_TRUE( diff --git a/services/distributeddataservice/service/test/mock/db_store_mock.cpp b/services/distributeddataservice/service/test/mock/db_store_mock.cpp index edc1cb3b..e4f0f3b2 100644 --- a/services/distributeddataservice/service/test/mock/db_store_mock.cpp +++ b/services/distributeddataservice/service/test/mock/db_store_mock.cpp @@ -263,7 +263,7 @@ DBStatus DBStoreMock::GetEntries(ConcurrentMap &store, const Key &ke store.ForEach([&entries, &keyPrefix](const Key &key, Value &value) { auto it = std::search(key.begin(), key.end(), keyPrefix.begin(), keyPrefix.end()); if (it == key.begin()) { - entries.push_back({ key, value }); + entries.push_back( { key, value } ); } return false; }); @@ -275,7 +275,7 @@ DBStatus DBStoreMock::PutBatch(ConcurrentMap &store, const std::vect for (auto &entry : entries) { store.InsertOrAssign(entry.key, entry.value); } - DBChangeDataMock changeData({}, entries, {}); + DBChangeDataMock changeData( {}, entries, {} ); observers_.ForEachCopies([&changeData](const auto &observer, auto &keys) mutable { if (observer) { observer->OnChange(changeData); @@ -287,13 +287,13 @@ DBStatus DBStoreMock::PutBatch(ConcurrentMap &store, const std::vect DBStatus DBStoreMock::DeleteBatch(ConcurrentMap &store, const std::vector &keys) { - DBChangeDataMock changeData({}, {}, {}); + DBChangeDataMock changeData( {}, {}, {} ); for (auto &key : keys) { auto it = store.Find(key); if (!it.first) { continue; } - changeData.AddEntry({key, std::move(it.second)}); + changeData.AddEntry( {key, std::move(it.second)} ); store.Erase(key); } -- Gitee From d3a8bbd4492df2837646adead545146b8e19463a Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 14:47:51 +0800 Subject: [PATCH 011/437] fix:code check Signed-off-by: htt1997 --- .../framework/include/cloud/cloud_event.h | 2 +- .../service/rdb/rdb_general_store.cpp | 13 +------ .../service/test/cloud_data_test.cpp | 36 +++++++++---------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h index 5a5efc87..e6cff13a 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -29,7 +29,7 @@ public: CLOUD_BUTT }; - struct StoreInfo{ + struct StoreInfo { uint32_t tokenId = 0; std::string bundleName; std::string storeName; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index bb69635c..e57cc2ea 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -24,17 +24,6 @@ namespace OHOS::DistributedRdb { using namespace DistributedData; using namespace OHOS::NativeRdb; -class RdbOpenCallbackImpl : public RdbOpenCallback { -public: - int OnCreate(RdbStore &rdbStore) override - { - return NativeRdb::E_OK; - } - int OnUpgrade(RdbStore &rdbStore, int oldVersion, int newVersion) override - { - return NativeRdb::E_OK; - } -}; RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appId, meta.user, meta.instanceId) { } @@ -97,7 +86,7 @@ int32_t RdbGeneralStore::Bind(std::shared_ptr cloudDb) int32_t RdbGeneralStore::SetSchema(const SchemaMeta &schemaMeta) { - //SetSchema + // SetSchema return GeneralError::E_OK; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index ffce5e23..6830b375 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -35,6 +35,23 @@ static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; static constexpr const char *TEST_CLOUD_STORE = "test_cloud_database_name"; +class CloudDataTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + +protected: + static constexpr const char *TEST_DISTRIBUTEDDATA_BUNDLE = "test_distributeddata"; + static constexpr const char *TEST_DISTRIBUTEDDATA_STORE = "test_service_meta"; + static constexpr const char *TEST_DISTRIBUTEDDATA_USER = "-1"; + + void InitMetaData(); + static std::shared_ptr dbStoreMock_; + StoreMetaData metaData_; +}; + class CloudServerMock : public CloudServer { public: CloudInfo GetServerInfo(int32_t userId) override; @@ -90,23 +107,6 @@ SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bund return schemaMeta; } -class CloudDataTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - -protected: - static constexpr const char *TEST_DISTRIBUTEDDATA_BUNDLE = "test_distributeddata"; - static constexpr const char *TEST_DISTRIBUTEDDATA_STORE = "test_service_meta"; - static constexpr const char *TEST_DISTRIBUTEDDATA_USER = "-1"; - - void InitMetaData(); - static std::shared_ptr dbStoreMock_; - StoreMetaData metaData_; -}; - std::shared_ptr CloudDataTest::dbStoreMock_ = std::make_shared(); void CloudDataTest::InitMetaData() @@ -174,7 +174,7 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) StoreMetaData storeMetaData; ASSERT_FALSE( MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); - CloudEvent::StoreInfo storeInfo { 0, TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0, 1 }; + CloudEvent::StoreInfo storeInfo { 0, TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); EventCenter::GetInstance().PostEvent(move(event)); ASSERT_TRUE( -- Gitee From 6c7fd3069cf9ba9ae9afb182d6f2d8607bffe281 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 16:18:50 +0800 Subject: [PATCH 012/437] fix:clouddata test Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 5 ++++- .../service/cloud/cloud_service_impl.h | 2 +- .../distributeddataservice/service/test/cloud_data_test.cpp | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index d45c8808..d75c0ac3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -36,7 +36,7 @@ namespace OHOS::CloudData { using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; -CloudServiceImpl::Factory::Factory() +CloudServiceImpl::Factory::Factory() noexcept { FeatureSystem::GetInstance().RegisterCreator(CloudServiceImpl::SERVICE_NAME, [this]() { if (product_ == nullptr) { @@ -71,6 +71,9 @@ CloudServiceImpl::CloudServiceImpl() AutoCache::Watchers watchers; auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers, false); + if (store == nullptr) { + ZLOGE("store is nullptr"); + } store->SetSchema(schemaMeta); auto instance = CloudServer::GetInstance(); if (instance == nullptr) { diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index d4086f5f..b71bbf4d 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -36,7 +36,7 @@ public: private: class Factory { public: - Factory(); + Factory() noexcept; ~Factory(); private: std::shared_ptr product_; diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 6830b375..1fda4965 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ #define LOG_TAG "CloudDataTest" -#include "gtest/gtest.h" +#include #include "log_print.h" #include "ipc_skeleton.h" #include "account/account_delegate.h" @@ -134,6 +134,7 @@ void CloudDataTest::SetUpTestCase(void) auto cloudServerMock = new CloudServerMock(); ASSERT_TRUE(CloudServer::RegisterCloudInstance(cloudServerMock)); FeatureSystem::GetInstance().GetCreator("cloud")(); + FeatureSystem::GetInstance().GetCreator("relational_store")(); } void CloudDataTest::TearDownTestCase() {} -- Gitee From 52e2a894b5a6f8ea1b5567ccce464335b818cf10 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 18:15:29 +0800 Subject: [PATCH 013/437] fix:code check Signed-off-by: htt1997 --- .../distributeddataservice/framework/store/auto_cache.cpp | 2 +- .../service/cloud/cloud_service_impl.cpp | 1 + services/distributeddataservice/service/test/BUILD.gn | 1 + .../service/test/cloud_data_test.cpp | 8 +++++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index bb22477f..37aff132 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -55,7 +55,7 @@ AutoCache::~AutoCache() AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers &watchers, bool setWatchers) { Store store; - if (meta.storeType >= MAX_CREATOR_NUM || !creators_[meta.storeType]) { + if (meta.storeType >= MAX_CREATOR_NUM || meta.storeType < 0 || !creators_[meta.storeType]) { return store; } diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index d75c0ac3..70efa85e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -73,6 +73,7 @@ CloudServiceImpl::CloudServiceImpl() auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers, false); if (store == nullptr) { ZLOGE("store is nullptr"); + return; } store->SetSchema(schemaMeta); auto instance = CloudServer::GetInstance(); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 0c5173a0..cb562215 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("CloudDataTest") { "mock/db_change_data_mock.cpp", "mock/db_store_mock.cpp", ] + include_dirs = [ "../../../../../relational_store/interfaces/inner_api/rdb/include" ] configs = [ ":module_private_config" ] diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 1fda4965..f640631a 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -27,10 +27,14 @@ #include "metadata/store_meta_data.h" #include "metadata/store_meta_data_local.h" #include "mock/db_store_mock.h" +#include "rdb_types.h" using namespace testing::ext; using namespace OHOS::DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +namespace OHOS { +namespace DistributedDataTest { + static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; static constexpr const char *TEST_CLOUD_STORE = "test_cloud_database_name"; @@ -151,7 +155,7 @@ void CloudDataTest::SetUp() storeMetaData.storeId = TEST_CLOUD_STORE; storeMetaData.instanceId = 0; storeMetaData.isAutoSync = true; - storeMetaData.storeType = 1; + storeMetaData.storeType = DistributedRdb::RDB_DEVICE_COLLABORATION; storeMetaData.area = OHOS::DistributedKv::EL1; storeMetaData.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); MetaDataManager::GetInstance().SaveMeta(storeMetaData.GetKey(), storeMetaData); @@ -181,3 +185,5 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) ASSERT_TRUE( MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); } +} // namespace DistributedDataTest +} // namespace OHOS -- Gitee From d219683c1807c5d058bc7554ebd2d9ea10b2c1d0 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 10 May 2023 19:19:07 +0800 Subject: [PATCH 014/437] support map and pointer in serializable Signed-off-by: Sven Wang --- .../include/serializable/serializable.h | 139 ++++++++++++------ .../framework/serializable/serializable.cpp | 18 ++- .../framework/test/serializable_test.cpp | 74 ++++++++++ 3 files changed, 184 insertions(+), 47 deletions(-) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 4b16f8dd..b2e3ac87 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -32,6 +32,7 @@ public: using json = nlohmann::json; using size_type = nlohmann::json::size_type; using error_handler_t = nlohmann::detail::error_handler_t; + API_EXPORT json Marshall() const; template static std::string Marshall(T &values) @@ -64,60 +65,114 @@ public: API_EXPORT static bool SetValue(json &node, const int32_t &value); API_EXPORT static bool SetValue(json &node, const int64_t &value); API_EXPORT static bool SetValue(json &node, const uint64_t &value); - API_EXPORT static bool SetValue(json &node, const bool &value); + // Use bool & to forbid the const T * auto convert to bool, const bool will convert to const uint32_t &value; + API_EXPORT static bool SetValue(json &node, bool &value); API_EXPORT static bool SetValue(json &node, const std::vector &value); API_EXPORT static bool SetValue(json &node, const Serializable &value); protected: API_EXPORT ~Serializable() = default; template - static bool GetValue(const json &node, const std::string &name, T *&value) - { - auto &subNode = GetSubNode(node, name); - if (subNode.is_null()) { - return false; - } - value = new(std::nothrow) T(); - if (value == nullptr) { - return false; - } - bool result = GetValue(subNode, "", *value); - if (!result) { - delete value; - value = nullptr; - } - return result; - } + static bool GetValue(const json &node, const std::string &name, std::vector &values); + template - static bool GetValue(const json &node, const std::string &name, std::vector &values) - { - auto &subNode = GetSubNode(node, name); - if (subNode.is_null() || !subNode.is_array()) { - return false; - } - bool result = true; - values.resize(subNode.size()); - for (size_type i = 0; i < subNode.size(); ++i) { - result = GetValue(subNode[i], "", values[i]) && result; - } - return result; - } + static bool SetValue(json &node, const std::vector &values); template - static bool SetValue(json &node, const std::vector &values) - { - bool result = true; - size_type i = 0; - node = json::value_t::array; - for (const auto &value : values) { - result = SetValue(node[i], value) && result; - i++; - } - return result; - } + static bool GetValue(const json &node, const std::string &name, std::map &values); + + template + static bool SetValue(json &node, const std::map &values); + + template + static bool GetValue(const json &node, const std::string &name, T *&value); + + template + static bool SetValue(json &node, const T *value); API_EXPORT static const json &GetSubNode(const json &node, const std::string &name); }; + +template +bool Serializable::GetValue(const json &node, const std::string &name, std::vector &values) +{ + auto &subNode = GetSubNode(node, name); + if (subNode.is_null() || !subNode.is_array()) { + return false; + } + bool result = true; + values.resize(subNode.size()); + for (size_type i = 0; i < subNode.size(); ++i) { + result = GetValue(subNode[i], "", values[i]) && result; + } + return result; +} + +template +bool Serializable::SetValue(json &node, const std::vector &values) +{ + bool result = true; + size_type i = 0; + node = json::value_t::array; + for (const auto &value : values) { + result = SetValue(node[i], value) && result; + i++; + } + return result; +} + +template +bool Serializable::GetValue(const json &node, const std::string &name, std::map &values) +{ + auto &subNode = GetSubNode(node, name); + if (subNode.is_null() || !subNode.is_object()) { + return false; + } + bool result = true; + for (auto object = subNode.begin(); object != subNode.end(); ++object) { + result = GetValue(object.value(), "", values[object.key()]) && result; + } + return result; +} + +template +bool Serializable::SetValue(json &node, const std::map &values) +{ + bool result = true; + node = json::value_t::object; + for (const auto &[key, value] : values) { + result = SetValue(node[key], value) && result; + } + return result; +} + +template +bool Serializable::GetValue(const json &node, const std::string &name, T *&value) +{ + auto &subNode = GetSubNode(node, name); + if (subNode.is_null()) { + return false; + } + value = new(std::nothrow) T(); + if (value == nullptr) { + return false; + } + bool result = GetValue(subNode, "", *value); + if (!result) { + delete value; + value = nullptr; + } + return result; +} + +template +bool Serializable::SetValue(json &node, const T *value) +{ + if (value == nullptr) { + return false; + } + return SetValue(node, *value); +} } // namespace DistributedData } // namespace OHOS #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H diff --git a/services/distributeddataservice/framework/serializable/serializable.cpp b/services/distributeddataservice/framework/serializable/serializable.cpp index 509880a8..c1c7ca8b 100644 --- a/services/distributeddataservice/framework/serializable/serializable.cpp +++ b/services/distributeddataservice/framework/serializable/serializable.cpp @@ -116,11 +116,19 @@ bool Serializable::GetValue(const json &node, const std::string &name, uint64_t bool Serializable::GetValue(const json &node, const std::string &name, bool &value) { auto &subNode = GetSubNode(node, name); - if (subNode.is_null() || !subNode.is_boolean()) { - return false; + if (subNode.is_boolean()) { + subNode.get_to(value); + return true; } - subNode.get_to(value); - return true; + + if (subNode.is_number_unsigned()) { + uint32_t number = 0; + subNode.get_to(number); + value = number != 0; + return true; + } + + return false; } bool Serializable::GetValue(const json &node, const std::string &name, std::vector &value) @@ -172,7 +180,7 @@ bool Serializable::SetValue(json &node, const uint64_t &value) return true; } -bool Serializable::SetValue(json &node, const bool &value) +bool Serializable::SetValue(json &node, bool &value) { node = value; return true; diff --git a/services/distributeddataservice/framework/test/serializable_test.cpp b/services/distributeddataservice/framework/test/serializable_test.cpp index 95c0154b..07199d39 100644 --- a/services/distributeddataservice/framework/test/serializable_test.cpp +++ b/services/distributeddataservice/framework/test/serializable_test.cpp @@ -159,3 +159,77 @@ HWTEST_F(SerializableTest, GetMutilVal, TestSize.Level2) normal1.Unmarshall(jstr); ASSERT_TRUE(normalEx == normal1) << normal1.name; } + +/** +* @tc.name: GetMap +* @tc.desc: mutil value case. +* @tc.type: FUNC +* @tc.require: +* @tc.author: Sven Wang +*/ +HWTEST_F(SerializableTest, GetMap, TestSize.Level2) +{ + ZLOGI("SerializableSuite GetMapVals begin."); + std::map marshData; + NormalEx normalEx; + normalEx.normals = {Normal()}; + normalEx.name = "normalEx"; + marshData.insert(std::pair{"test1", normalEx}); + auto jsonData = NormalEx::Marshall(marshData); + + std::map unmarshData; + NormalEx::Unmarshall(jsonData, unmarshData); + ASSERT_TRUE((marshData["test1"] == unmarshData["test1"])) << jsonData; +} + +/** +* @tc.name: GetMapInStruct +* @tc.desc: mutil value case. +* @tc.type: FUNC +* @tc.require: +* @tc.author: Sven Wang +*/ +HWTEST_F(SerializableTest, GetMapInStruct, TestSize.Level2) +{ + struct TestMeta : public Serializable { + std::map data; + std::map *index = nullptr; + std::vector> others; + ~TestMeta() { + delete index; + } + bool Marshal(json &node) const + { + SetValue(node[GET_NAME(data)], data); + SetValue(node[GET_NAME(index)], index); + SetValue(node[GET_NAME(others)], others); + return true; + } + + bool Unmarshal(const json &node) + { + GetValue(node, GET_NAME(data), data); + GetValue(node, GET_NAME(index), index); + GetValue(node, GET_NAME(others), others); + return true; + } + }; + ZLOGI("SerializableSuite GetMapVals begin."); + TestMeta marData; + NormalEx normalEx; + normalEx.normals = {Normal()}; + normalEx.name = "normalEx"; + marData.data.insert(std::pair{"test1", normalEx}); + marData.others.push_back({std::pair{"test2", normalEx}}); + marData.index = new (std::nothrow) std::map; + ASSERT_NE(marData.index, nullptr); + marData.index->insert(std::pair{"test1", true}); + marData.index->insert(std::pair{"test2", true}); + auto jsonData = NormalEx::Marshall(marData); + TestMeta unmarData; + NormalEx::Unmarshall(jsonData, unmarData); + ASSERT_TRUE((marData.data == unmarData.data)) << jsonData; + ASSERT_TRUE((marData.others == unmarData.others)) << jsonData; + ASSERT_NE(unmarData.index, nullptr); + ASSERT_TRUE((*marData.index == *unmarData.index)) << jsonData; +} \ No newline at end of file -- Gitee From 60ef71efe5306cce8a613e3f888c58e46fb70cb0 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 20:30:42 +0800 Subject: [PATCH 015/437] fix:ut Signed-off-by: htt1997 --- .../service/test/cloud_data_test.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index f640631a..031ea345 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -34,11 +34,9 @@ using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; namespace OHOS { namespace DistributedDataTest { - static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; static constexpr const char *TEST_CLOUD_STORE = "test_cloud_database_name"; - class CloudDataTest : public testing::Test { public: static void SetUpTestCase(void); @@ -49,7 +47,6 @@ public: protected: static constexpr const char *TEST_DISTRIBUTEDDATA_BUNDLE = "test_distributeddata"; static constexpr const char *TEST_DISTRIBUTEDDATA_STORE = "test_service_meta"; - static constexpr const char *TEST_DISTRIBUTEDDATA_USER = "-1"; void InitMetaData(); static std::shared_ptr dbStoreMock_; @@ -118,9 +115,9 @@ void CloudDataTest::InitMetaData() metaData_.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; metaData_.appId = TEST_DISTRIBUTEDDATA_BUNDLE; metaData_.bundleName = TEST_DISTRIBUTEDDATA_BUNDLE; - metaData_.user = TEST_DISTRIBUTEDDATA_USER; - metaData_.area = OHOS::DistributedKv::EL1; metaData_.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + metaData_.user = std::to_string(DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(metaData_.tokenId)); + metaData_.area = OHOS::DistributedKv::EL1; metaData_.instanceId = 0; metaData_.isAutoSync = true; metaData_.storeType = 1; @@ -150,7 +147,6 @@ void CloudDataTest::SetUp() StoreMetaData storeMetaData; storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - storeMetaData.user = -1; storeMetaData.bundleName = TEST_CLOUD_BUNDLE; storeMetaData.storeId = TEST_CLOUD_STORE; storeMetaData.instanceId = 0; @@ -158,6 +154,8 @@ void CloudDataTest::SetUp() storeMetaData.storeType = DistributedRdb::RDB_DEVICE_COLLABORATION; storeMetaData.area = OHOS::DistributedKv::EL1; storeMetaData.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + storeMetaData.user = + std::to_string(DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(storeMetaData.tokenId)); MetaDataManager::GetInstance().SaveMeta(storeMetaData.GetKey(), storeMetaData); } @@ -174,12 +172,13 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) { ZLOGI("CloudDataTest start"); std::shared_ptr cloudServerMock = std::make_shared(); - auto cloudInfo = cloudServerMock->GetServerInfo(-1); + auto cloudInfo = cloudServerMock->GetServerInfo( + DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(OHOS::IPCSkeleton::GetCallingTokenID())); ASSERT_TRUE(MetaDataManager::GetInstance().DelMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), true)); StoreMetaData storeMetaData; ASSERT_FALSE( MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); - CloudEvent::StoreInfo storeInfo { 0, TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; + CloudEvent::StoreInfo storeInfo { OHOS::IPCSkeleton::GetCallingTokenID(), TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); EventCenter::GetInstance().PostEvent(move(event)); ASSERT_TRUE( -- Gitee From 0153e063364f43661a24ff9b544a5e153e855702 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 10 May 2023 20:37:46 +0800 Subject: [PATCH 016/437] fixed code style Signed-off-by: Sven Wang --- .../framework/test/serializable_test.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/framework/test/serializable_test.cpp b/services/distributeddataservice/framework/test/serializable_test.cpp index 07199d39..697b33b5 100644 --- a/services/distributeddataservice/framework/test/serializable_test.cpp +++ b/services/distributeddataservice/framework/test/serializable_test.cpp @@ -172,9 +172,9 @@ HWTEST_F(SerializableTest, GetMap, TestSize.Level2) ZLOGI("SerializableSuite GetMapVals begin."); std::map marshData; NormalEx normalEx; - normalEx.normals = {Normal()}; + normalEx.normals = { Normal() }; normalEx.name = "normalEx"; - marshData.insert(std::pair{"test1", normalEx}); + marshData.insert(std::pair{ "test1", normalEx }); auto jsonData = NormalEx::Marshall(marshData); std::map unmarshData; @@ -195,7 +195,8 @@ HWTEST_F(SerializableTest, GetMapInStruct, TestSize.Level2) std::map data; std::map *index = nullptr; std::vector> others; - ~TestMeta() { + ~TestMeta() + { delete index; } bool Marshal(json &node) const @@ -217,14 +218,14 @@ HWTEST_F(SerializableTest, GetMapInStruct, TestSize.Level2) ZLOGI("SerializableSuite GetMapVals begin."); TestMeta marData; NormalEx normalEx; - normalEx.normals = {Normal()}; + normalEx.normals = { Normal() }; normalEx.name = "normalEx"; - marData.data.insert(std::pair{"test1", normalEx}); - marData.others.push_back({std::pair{"test2", normalEx}}); + marData.data.insert(std::pair{ "test1", normalEx }); + marData.others.push_back({ std::pair{ "test2", normalEx } }); marData.index = new (std::nothrow) std::map; ASSERT_NE(marData.index, nullptr); - marData.index->insert(std::pair{"test1", true}); - marData.index->insert(std::pair{"test2", true}); + marData.index->insert(std::pair{ "test1", true }); + marData.index->insert(std::pair{ "test2", true }); auto jsonData = NormalEx::Marshall(marData); TestMeta unmarData; NormalEx::Unmarshall(jsonData, unmarData); -- Gitee From ab284a0ea8933201a66a483a45175d83ea82bfaf Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 10 May 2023 20:55:04 +0800 Subject: [PATCH 017/437] add map Signed-off-by: Sven Wang --- .../framework/include/serializable/serializable.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index b2e3ac87..e358decc 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -15,6 +15,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H +#include #include #include #include "visibility.h" -- Gitee From b8581ae7a2d2173e4349bbf22d71e120eaede79e Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 10 May 2023 21:51:20 +0800 Subject: [PATCH 018/437] fix:format check Signed-off-by: htt1997 --- .../framework/include/store/auto_cache.h | 2 +- .../distributeddataservice/service/BUILD.gn | 3 +- .../service/cloud/cloud_service_impl.cpp | 1 - .../service/cloud/cloud_syncer.cpp | 28 ----------------- .../service/cloud/cloud_syncer.h | 30 ------------------- .../service/test/BUILD.gn | 3 +- 6 files changed, 4 insertions(+), 63 deletions(-) delete mode 100644 services/distributeddataservice/service/cloud/cloud_syncer.cpp delete mode 100644 services/distributeddataservice/service/cloud/cloud_syncer.h diff --git a/services/distributeddataservice/framework/include/store/auto_cache.h b/services/distributeddataservice/framework/include/store/auto_cache.h index 8884a789..b01834a5 100644 --- a/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/services/distributeddataservice/framework/include/store/auto_cache.h @@ -45,7 +45,7 @@ public: API_EXPORT void Bind(std::shared_ptr executor); API_EXPORT Store GetStore(const StoreMetaData &meta, const Watchers &watchers, bool setWatchers = true); - + API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId); API_EXPORT void CloseExcept(const std::set &users); diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 49e56b7d..0aaaf8f6 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -63,7 +63,6 @@ ohos_shared_library("distributeddatasvc") { "bootstrap/src/bootstrap.cpp", "cloud/cloud_service_impl.cpp", "cloud/cloud_service_stub.cpp", - "cloud/cloud_syncer.cpp", "config/src/config_factory.cpp", "config/src/model/backup_config.cpp", "config/src/model/checker_config.cpp", @@ -139,10 +138,10 @@ ohos_shared_library("distributeddatasvc") { deps = [ "${kv_store_distributeddb_path}:distributeddb", + "${relational_store_path}/interfaces/inner_api/cloud_data:cloud_data_inner", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", - "${relational_store_path}/interfaces/inner_api/cloud_data:cloud_data_inner", ] external_deps = [ diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 70efa85e..8b45fd18 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -21,7 +21,6 @@ #include "checker/checker_manager.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" -#include "cloud_syncer.h" #include "communicator/device_manager_adapter.h" #include "eventcenter/event_center.h" #include "feature/feature_system.h" diff --git a/services/distributeddataservice/service/cloud/cloud_syncer.cpp b/services/distributeddataservice/service/cloud/cloud_syncer.cpp deleted file mode 100644 index f920c5ec..00000000 --- a/services/distributeddataservice/service/cloud/cloud_syncer.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 "cloud_syncer.h" - -namespace OHOS::CloudData { -CloudSyncer &CloudSyncer::GetInstance() -{ - static CloudSyncer instance; - return instance; -} - -void CloudSyncer::Sync(const DistributedData::CloudInfo &cloudInfo) -{ -} -} // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_syncer.h b/services/distributeddataservice/service/cloud/cloud_syncer.h deleted file mode 100644 index c9dd7971..00000000 --- a/services/distributeddataservice/service/cloud/cloud_syncer.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H -#define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H - -#include "cloud/cloud_info.h" - -namespace OHOS::CloudData { -class CloudSyncer { -public: - static CloudSyncer &GetInstance(); - void Sync(const DistributedData::CloudInfo &cloudInfo); - -private: -}; -} // namespace OHOS::CloudData -#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SYNCER_H diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index cb562215..7cda59fa 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -43,7 +43,8 @@ ohos_unittest("CloudDataTest") { "mock/db_change_data_mock.cpp", "mock/db_store_mock.cpp", ] - include_dirs = [ "../../../../../relational_store/interfaces/inner_api/rdb/include" ] + include_dirs = + [ "../../../../../relational_store/interfaces/inner_api/rdb/include" ] configs = [ ":module_private_config" ] -- Gitee From aff16fba7a15c4603d19ecd1ced846dc340cde98 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Thu, 11 May 2023 10:12:10 +0800 Subject: [PATCH 019/437] fix dfx test Signed-off-by: renjiecui --- .../adapter/dfx/test/BUILD.gn | 5 ++++- .../unittest/distributeddata_dfx_ut_test.cpp | 16 ++++++++++------ .../adapter/include/dfx/reporter.h | 11 +++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/adapter/dfx/test/BUILD.gn b/services/distributeddataservice/adapter/dfx/test/BUILD.gn index de03ed06..0c2a6050 100755 --- a/services/distributeddataservice/adapter/dfx/test/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/test/BUILD.gn @@ -118,6 +118,9 @@ group("unittest") { testonly = true deps = [] - deps += [ ":DistributeddataDfxMSTTest" ] + deps += [ + ":DistributeddataDfxMSTTest", + ":DistributeddataDfxUTTest", + ] } ############################################################################### diff --git a/services/distributeddataservice/adapter/dfx/test/unittest/distributeddata_dfx_ut_test.cpp b/services/distributeddataservice/adapter/dfx/test/unittest/distributeddata_dfx_ut_test.cpp index b93b5632..f4887d3c 100644 --- a/services/distributeddataservice/adapter/dfx/test/unittest/distributeddata_dfx_ut_test.cpp +++ b/services/distributeddataservice/adapter/dfx/test/unittest/distributeddata_dfx_ut_test.cpp @@ -35,21 +35,25 @@ public: void DistributedataDfxUTTest::SetUpTestCase() { - size_t max = 12; - size_t min = 5; - Reporter::GetInstance()->SetThreadPool(std::make_shared(max, min)); FakeHivew::Clear(); } void DistributedataDfxUTTest::TearDownTestCase() { - Reporter::GetInstance()->SetThreadPool(nullptr); FakeHivew::Clear(); } -void DistributedataDfxUTTest::SetUp() {} +void DistributedataDfxUTTest::SetUp() +{ + size_t max = 12; + size_t min = 5; + Reporter::GetInstance()->SetThreadPool(std::make_shared(max, min)); +} -void DistributedataDfxUTTest::TearDown() {} +void DistributedataDfxUTTest::TearDown() +{ + Reporter::GetInstance()->SetThreadPool(nullptr); +} /** * @tc.name: Dfx001 diff --git a/services/distributeddataservice/adapter/include/dfx/reporter.h b/services/distributeddataservice/adapter/include/dfx/reporter.h index f84af98a..c2537b57 100644 --- a/services/distributeddataservice/adapter/include/dfx/reporter.h +++ b/services/distributeddataservice/adapter/include/dfx/reporter.h @@ -43,6 +43,17 @@ public: void SetThreadPool(std::shared_ptr executors) { executors_ = executors; + if (executors == nullptr) { + ServiceFault(); + RuntimeFault(); + DatabaseFault(); + CommunicationFault(); + DatabaseStatistic(); + VisitStatistic(); + TrafficStatistic(); + ApiPerformanceStatistic(); + BehaviourReporter(); + } }; private: -- Gitee From aee94dab5f248d8299f16bd42bb8cdb9398eda0d Mon Sep 17 00:00:00 2001 From: htt1997 Date: Fri, 12 May 2023 10:49:18 +0800 Subject: [PATCH 020/437] fix:Review comments modification Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 119 ++++++++++-------- .../service/cloud/cloud_service_impl.h | 6 +- .../service/cloud/cloud_service_stub.cpp | 8 ++ .../service/rdb/rdb_service_impl.cpp | 48 ++----- .../service/rdb/rdb_service_impl.h | 2 - .../service/test/BUILD.gn | 1 + 6 files changed, 89 insertions(+), 95 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 8b45fd18..55bcde15 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -50,46 +50,12 @@ CloudServiceImpl::Factory::~Factory() {} CloudServiceImpl::CloudServiceImpl() { EventCenter::GetInstance().Subscribe(CloudEvent::FEATURE_INIT, [this](const Event &event) { - auto &rdbEvent = static_cast(event); - CloudInfo cloudInfo; - cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); - if (GetServerInfo(cloudInfo) != SUCCESS) { - ZLOGE("failed, user:%{public}d", cloudInfo.user); - return; - } - UpdateCloudInfo(cloudInfo); - AddSchema(cloudInfo); + FeatureInit(event); + return; }); EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { - auto &rdbEvent = static_cast(event); - auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); - auto schemaMeta = GetSchemaMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); - auto storeMeta = GetStoreMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, - rdbEvent.GetStoreInfo().instanceId); - - AutoCache::Watchers watchers; - auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers, false); - if (store == nullptr) { - ZLOGE("store is nullptr"); - return; - } - store->SetSchema(schemaMeta); - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("instance is nullptr"); - return; - } - for (auto &database : schemaMeta.databases) { - if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync */) { - continue; - } - auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); - if (cloudDB != nullptr) { - store->Bind(cloudDB); - } - // do sync - } + GetSchema(event); return; }); } @@ -97,8 +63,7 @@ CloudServiceImpl::CloudServiceImpl() int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) { CloudInfo cloudInfo; - cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { + if (GetCloudInfo(IPCSkeleton::GetCallingTokenID(), id, cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } cloudInfo.enableCloud = true; @@ -110,7 +75,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::mapcloudSwitch = item.second; } if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; @@ -121,8 +86,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &actions) { CloudInfo cloudInfo; - cloudInfo.id = id; - if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { - ZLOGE("id:%{public}s", Anonymous::Change(id).c_str()); + if (GetCloudInfo(IPCSkeleton::GetCallingTokenID(), id, cloudInfo) != SUCCESS) { return INVALID_ARGUMENT; } auto keys = cloudInfo.GetSchemaKey(); @@ -180,14 +141,18 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str return 0; } -int32_t CloudServiceImpl::GetCloudInfo(CloudInfo &cloudInfo) +int32_t CloudServiceImpl::GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo) { - auto tokenId = IPCSkeleton::GetCallingTokenID(); cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); - if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { - ZLOGE("invalid argument id:%{public}s, user:%{public}d", Anonymous::Change(cloudInfo.id).c_str(), - cloudInfo.user); - return ERROR; + if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true) && + GetServerInfo(cloudInfo ) != SUCCESS) { + ZLOGE("invalid args, user:%{public}d", cloudInfo.user); + return INVALID_ARGUMENT; + } + if (cloudInfo.id != id) { + ZLOGE("invalid args, [input] id:%{public}s, [exist] id:%{public}s", + Anonymous::Change(id).c_str(), Anonymous::Change(cloudInfo.id).c_str()); + return INVALID_ARGUMENT; } return SUCCESS; } @@ -277,4 +242,52 @@ StoreMetaData CloudServiceImpl::GetStoreMata(int32_t userId, const std::string & MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData); return storeMetaData; } + +void CloudServiceImpl::FeatureInit(const Event &event) +{ + CloudInfo cloudInfo; + std::vector users; + if (!DistributedKv::AccountDelegate::GetInstance()->QueryUsers(users) || users.empty()) { + return; + } + cloudInfo.user = *users.begin(); + if (GetServerInfo(cloudInfo) != SUCCESS) { + ZLOGE("failed, user:%{public}d", cloudInfo.user); + return; + } + UpdateCloudInfo(cloudInfo); + AddSchema(cloudInfo); +} + +void CloudServiceImpl::GetSchema(const Event &event) { + auto &rdbEvent = static_cast(event); + auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); + auto schemaMeta = GetSchemaMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); + auto storeMeta = GetStoreMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, + rdbEvent.GetStoreInfo().instanceId); + + AutoCache::Watchers watchers; + auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers, false); + if (store == nullptr) { + ZLOGE("store is nullptr"); + return; + } + store->SetSchema(schemaMeta); + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGE("instance is nullptr"); + return; + } + for (auto &database : schemaMeta.databases) { + if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync */) { + continue; + } + auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); + if (cloudDB != nullptr) { + store->Bind(cloudDB); + } + // do sync + } + return; +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index b71bbf4d..26ed17e7 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -20,6 +20,7 @@ #include "cloud_service_stub.h" #include "cloud/cloud_info.h" #include "cloud/schema_meta.h" +#include "cloud/cloud_event.h" namespace OHOS::CloudData { class CloudServiceImpl : public CloudServiceStub { @@ -45,15 +46,18 @@ private: using CloudInfo = DistributedData::CloudInfo; using SchemaMeta = DistributedData::SchemaMeta; + using Event = DistributedData::Event; void UpdateCloudInfo(CloudInfo &cloudInfo); void AddSchema(CloudInfo &cloudInfo); SchemaMeta GetSchemaMata(int32_t userId, const std::string &bundleName, int32_t instanceId); StoreMetaData GetStoreMata(int32_t userId, const std::string &bundleName, const std::string &storeName, int32_t instanceId); - int32_t GetCloudInfo(CloudInfo &cloudInfo); + int32_t GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo); int32_t GetServerInfo(CloudInfo &cloudInfo); int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); + void FeatureInit(const Event &event); + void GetSchema(const Event &event); }; } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 2ccf869e..15556684 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -19,8 +19,10 @@ #include "itypes_util.h" #include "log_print.h" #include "utils/anonymous.h" +#include "tokenid_kit.h" namespace OHOS::CloudData { using namespace DistributedData; +using namespace OHOS::Security::AccessToken; const CloudServiceStub::Handler CloudServiceStub::HANDLERS[TRANS_BUTT] = { &CloudServiceStub::OnEnableCloud, &CloudServiceStub::OnDisableCloud, @@ -43,6 +45,12 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); return -1; } + + if(!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())){ + ZLOGE("permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); + return -1; + } + std::string id; if (!ITypesUtil::Unmarshal(data, id)) { ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index ab255d06..1f6722eb 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -54,7 +54,7 @@ RdbServiceImpl::Factory::Factory() return std::make_shared(); }); AutoCache::GetInstance().RegCreator(RDB_DEVICE_COLLABORATION, [](const StoreMetaData &metaData) -> GeneralStore* { - return new RdbGeneralStore(metaData); + return new (std::nothrow) RdbGeneralStore(metaData); }); } @@ -466,8 +466,7 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) int32_t RdbServiceImpl::OnInitialize() { - CloudEvent::StoreInfo storeInfo = { IPCSkeleton::GetCallingTokenID() }; - auto initEvt = std::make_unique(CloudEvent::FEATURE_INIT, storeInfo); + auto initEvt = std::make_unique(CloudEvent::FEATURE_INIT, CloudEvent::StoreInfo()); EventCenter::GetInstance().PostEvent(std::move(initEvt)); return RDB_OK; } @@ -478,25 +477,13 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) ZLOGE("permission error"); return RDB_ERROR; } - - auto storeMeta = GetStoreMetaData(param); - StoreMetaData oldMeta; - bool isCreated = MetaDataManager::GetInstance().LoadMeta(storeMeta.GetKey(), oldMeta, true); - if (isCreated && (oldMeta.storeType != storeMeta.storeType || - Constant::NotEqual(oldMeta.isEncrypt, storeMeta.isEncrypt) || - oldMeta.area != storeMeta.area)) { - ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " - "area:%{public}d->%{public}d", - storeMeta.bundleName.c_str(), storeMeta.storeId.c_str(), oldMeta.storeType, storeMeta.storeType, - oldMeta.isEncrypt, storeMeta.isEncrypt, oldMeta.area, storeMeta.area); - return RDB_ERROR; - } - auto saved = MetaDataManager::GetInstance().SaveMeta(storeMeta.GetKey(), storeMeta, true); - if (!saved) { + auto syncer = GetRdbSyncer(param); + if (syncer == nullptr) { return RDB_ERROR; } - CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, param.storeName_, - storeMeta.instanceId }; + CloudEvent::StoreInfo storeInfo{ IPCSkeleton::GetCallingTokenID(), param.bundleName_, + RdbSyncer::RemoveSuffix(param.storeName_), + RdbSyncer::GetInstIndex(IPCSkeleton::GetCallingTokenID(), param.bundleName_) }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); EventCenter::GetInstance().PostEvent(move(event)); return RDB_OK; @@ -507,10 +494,10 @@ StoreMetaData RdbServiceImpl::GetStoreMetaData(const RdbSyncerParam ¶m) StoreMetaData metaData; metaData.uid = IPCSkeleton::GetCallingUid(); metaData.tokenId = IPCSkeleton::GetCallingTokenID(); - metaData.instanceId = GetInstIndex(metaData.tokenId, param.bundleName_, param.storeName_); + metaData.instanceId = RdbSyncer::GetInstIndex(metaData.tokenId, param.bundleName_); metaData.bundleName = param.bundleName_; metaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - metaData.storeId = param.storeName_; + metaData.storeId = RdbSyncer::RemoveSuffix(param.storeName_); metaData.user = std::to_string(AccountDelegate::GetInstance()->GetUserByToken(metaData.tokenId)); metaData.storeType = param.type_; metaData.securityLevel = param.level_; @@ -524,23 +511,6 @@ StoreMetaData RdbServiceImpl::GetStoreMetaData(const RdbSyncerParam ¶m) return metaData; } -int32_t RdbServiceImpl::GetInstIndex(uint32_t tokenId, const std::string &bundleName, const std::string &storeName) -{ - if (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP) { - return 0; - } - - HapTokenInfo tokenInfo; - tokenInfo.instIndex = -1; - int errCode = AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo); - if (errCode != RET_SUCCESS) { - ZLOGE("GetHapTokenInfo error:%{public}d, tokenId:0x%{public}x bundleName:%{public}s storeName:%{public}s", - errCode, tokenId, bundleName.c_str(), storeName.c_str()); - return -1; - } - return tokenInfo.instIndex; -} - int32_t RdbServiceImpl::OnExecutor(std::shared_ptr executors) { executors_ = executors; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index c5af1b9d..9d3b22b2 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -84,8 +84,6 @@ private: StoreMetaData GetStoreMetaData(const RdbSyncerParam& param); - int32_t GetInstIndex(uint32_t tokenId, const std::string &appId, const std::string &storeName); - class DeathRecipientImpl : public IRemoteObject::DeathRecipient { public: using DeathCallback = std::function; diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 7cda59fa..5a7ff143 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("CloudDataTest") { "mock/db_change_data_mock.cpp", "mock/db_store_mock.cpp", ] + include_dirs = [ "../../../../../relational_store/interfaces/inner_api/rdb/include" ] -- Gitee From d2bb6eaae76fc7956cd8de6ba3f551216bacf8fb Mon Sep 17 00:00:00 2001 From: htt1997 Date: Fri, 12 May 2023 11:09:58 +0800 Subject: [PATCH 021/437] fix:code check Signed-off-by: htt1997 --- services/distributeddataservice/service/BUILD.gn | 1 + .../service/cloud/cloud_service_impl.cpp | 9 +++++---- .../service/cloud/cloud_service_stub.cpp | 6 +++--- .../service/rdb/rdb_service_impl.cpp | 2 +- services/distributeddataservice/service/test/BUILD.gn | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 0aaaf8f6..1d29c1ef 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -150,6 +150,7 @@ ohos_shared_library("distributeddatasvc") { "ability_runtime:ability_manager", "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 55bcde15..e9e932fc 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -145,13 +145,13 @@ int32_t CloudServiceImpl::GetCloudInfo(uint32_t tokenId, const std::string &id, { cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true) && - GetServerInfo(cloudInfo ) != SUCCESS) { + GetServerInfo(cloudInfo) != SUCCESS) { ZLOGE("invalid args, user:%{public}d", cloudInfo.user); return INVALID_ARGUMENT; } if (cloudInfo.id != id) { - ZLOGE("invalid args, [input] id:%{public}s, [exist] id:%{public}s", - Anonymous::Change(id).c_str(), Anonymous::Change(cloudInfo.id).c_str()); + ZLOGE("invalid args, [input] id:%{public}s, [exist] id:%{public}s", Anonymous::Change(id).c_str(), + Anonymous::Change(cloudInfo.id).c_str()); return INVALID_ARGUMENT; } return SUCCESS; @@ -259,7 +259,8 @@ void CloudServiceImpl::FeatureInit(const Event &event) AddSchema(cloudInfo); } -void CloudServiceImpl::GetSchema(const Event &event) { +void CloudServiceImpl::GetSchema(const Event &event) +{ auto &rdbEvent = static_cast(event); auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); auto schemaMeta = GetSchemaMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 15556684..61e9dc63 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -45,12 +45,12 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); return -1; } - - if(!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())){ + + if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) { ZLOGE("permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); return -1; } - + std::string id; if (!ITypesUtil::Unmarshal(data, id)) { ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 1f6722eb..1938c504 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -481,7 +481,7 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) if (syncer == nullptr) { return RDB_ERROR; } - CloudEvent::StoreInfo storeInfo{ IPCSkeleton::GetCallingTokenID(), param.bundleName_, + CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, RdbSyncer::RemoveSuffix(param.storeName_), RdbSyncer::GetInstIndex(IPCSkeleton::GetCallingTokenID(), param.bundleName_) }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 5a7ff143..97d837b7 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -43,7 +43,7 @@ ohos_unittest("CloudDataTest") { "mock/db_change_data_mock.cpp", "mock/db_store_mock.cpp", ] - + include_dirs = [ "../../../../../relational_store/interfaces/inner_api/rdb/include" ] -- Gitee From 259eebf63053d97fad1b945a12c85c69fbf61e7d Mon Sep 17 00:00:00 2001 From: srr101 Date: Fri, 12 May 2023 11:29:33 +0800 Subject: [PATCH 022/437] bug fix Signed-off-by: srr101 --- .../service/data_share/strategies/query_strategy.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp index c2e2852a..6e16f1a7 100644 --- a/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp @@ -34,6 +34,7 @@ std::shared_ptr QueryStrategy::Execute( ZLOGE("get strategy fail, maybe memory not enough"); return nullptr; } + context->isRead = true; if (!(*preProcess)(context)) { errCode = context->errCode; ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); -- Gitee From 22476a1cca9c10626689816141ee6f2d2356cbe7 Mon Sep 17 00:00:00 2001 From: srr101 Date: Fri, 12 May 2023 16:33:33 +0800 Subject: [PATCH 023/437] =?UTF-8?q?=E7=BB=99errorcode=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- .../service/data_share/common/rdb_delegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.h b/services/distributeddataservice/service/data_share/common/rdb_delegate.h index b8fdcd92..c30ceac8 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.h +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.h @@ -45,7 +45,7 @@ public: private: static std::atomic resultSetCount; std::shared_ptr store_; - int errCode_; + int errCode_ = E_OK; }; class DefaultOpenCallback : public RdbOpenCallback { public: -- Gitee From 285d9f41e8647a2d4391f33eb72aa57f1f7a5df1 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Fri, 12 May 2023 16:34:10 +0800 Subject: [PATCH 024/437] modify executors_ initializing position Signed-off-by: renjiecui --- .../app/src/kvstore_data_service.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index ee5ef9e7..a1853289 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -68,12 +68,24 @@ KvStoreDataService::KvStoreDataService(bool runOnCreate) : SystemAbility(runOnCreate), mutex_(), clients_() { ZLOGI("begin."); + if (executors_ == nullptr) { + constexpr size_t MAX = 12; + constexpr size_t MIN = 5; + executors_ = std::make_shared(MAX, MIN); + DistributedDB::RuntimeConfig::SetThreadPool(std::make_shared(executors_)); + } } KvStoreDataService::KvStoreDataService(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate), mutex_(), clients_() { ZLOGI("begin"); + if (executors_ == nullptr) { + constexpr size_t MAX = 12; + constexpr size_t MIN = 5; + executors_ = std::make_shared(MAX, MIN); + DistributedDB::RuntimeConfig::SetThreadPool(std::make_shared(executors_)); + } } KvStoreDataService::~KvStoreDataService() @@ -91,7 +103,6 @@ void KvStoreDataService::Initialize() #endif auto communicator = std::make_shared(RouteHeadHandlerImpl::Create); auto ret = KvStoreDelegateManager::SetProcessCommunicator(communicator); - DistributedDB::RuntimeConfig::SetThreadPool(std::make_shared(executors_)); ZLOGI("set communicator ret:%{public}d.", static_cast(ret)); AppDistributedKv::CommunicationProvider::GetInstance(); @@ -233,9 +244,6 @@ void KvStoreDataService::OnStart() { ZLOGI("distributeddata service onStart"); EventCenter::Defer defer; - constexpr size_t MAX = 12; - constexpr size_t MIN = 5; - executors_ = std::make_shared(MAX, MIN); Reporter::GetInstance()->SetThreadPool(executors_); AccountDelegate::GetInstance()->BindExecutor(executors_); AccountDelegate::GetInstance()->RegisterHashFunc(Crypto::Sha256); -- Gitee From fbcff23d662d8250584b0660fe67dfe751e666cd Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 13 May 2023 15:46:20 +0800 Subject: [PATCH 025/437] system api Signed-off-by: ylq121 --- .../service/cloud/cloud_service_stub.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 61e9dc63..b14485f4 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -48,7 +48,8 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) { ZLOGE("permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); - return -1; + auto result = static_cast(PERMISSION_DENIED); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; } std::string id; -- Gitee From ef5b92e6731bf9efe365c700bad77a93b40091c2 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 13 May 2023 16:56:16 +0800 Subject: [PATCH 026/437] feat:Delete schemata during HAP update Signed-off-by: htt1997 --- .../app/src/feature_stub_impl.cpp | 8 ++ .../app/src/feature_stub_impl.h | 1 + .../app/src/kvstore_data_service.cpp | 10 ++ .../app/src/kvstore_data_service.h | 2 + .../app/src/uninstaller/uninstaller_impl.cpp | 109 ++++++++++++------ .../app/src/uninstaller/uninstaller_impl.h | 8 +- .../framework/feature/feature_system.cpp | 6 + .../include/feature/feature_system.h | 1 + .../service/cloud/cloud_service_impl.cpp | 6 + 9 files changed, 113 insertions(+), 38 deletions(-) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index 01171f95..0e640edd 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -57,6 +57,14 @@ int32_t FeatureStubImpl::OnAppUninstall(const std::string &bundleName, int32_t u return featureImpl_->OnAppUninstall(bundleName, user, index, tokenId); } +int32_t FeatureStubImpl::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) +{ + if (featureImpl_ == nullptr) { + return -1; + } + return featureImpl_->OnAppUpdate(bundleName, user, index, tokenId); +} + int32_t FeatureStubImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) { if (featureImpl_ == nullptr) { diff --git a/services/distributeddataservice/app/src/feature_stub_impl.h b/services/distributeddataservice/app/src/feature_stub_impl.h index 6fc9c824..b00646bc 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/services/distributeddataservice/app/src/feature_stub_impl.h @@ -33,6 +33,7 @@ public: int32_t OnInitialize(std::shared_ptr executor); int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName); int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); + int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); int32_t Online(const std::string &device); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index ee5ef9e7..2e190156 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -716,4 +716,14 @@ int32_t KvStoreDataService::OnUninstall(const std::string &bundleName, int32_t u }); return 0; } + +int32_t KvStoreDataService::OnUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) +{ + features_.ForEachCopies( + [bundleName, user, index, tokenId](const auto &, sptr &value) { + value->OnAppUpdate(bundleName, user, index, tokenId); + return false; + }); + return 0; +} } // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index fae1dbac..60aac352 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -76,6 +76,8 @@ public: int32_t OnUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); + int32_t OnUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); + private: void NotifyAccountEvent(const AccountEventInfo &eventInfo); class KvStoreClientDeathObserverImpl { diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index 81072e46..12aa99db 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -27,6 +27,7 @@ #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "permit_delegate.h" +#include "cloud/cloud_info.h" #include "utils/block_integer.h" namespace OHOS::DistributedKv { @@ -36,26 +37,28 @@ using namespace OHOS::AppExecFwk; using namespace OHOS::DistributedData; using namespace OHOS::EventFwk; -UninstallEventSubscriber::UninstallEventSubscriber(const CommonEventSubscribeInfo &info, - UninstallEventCallback callback) - : CommonEventSubscriber(info), callback_(callback) -{} +UninstallEventSubscriber::UninstallEventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) +{ +} void UninstallEventSubscriber::OnReceiveEvent(const CommonEventData &event) { ZLOGI("Intent Action Rec"); Want want = event.GetWant(); std::string action = want.GetAction(); - if (action != CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED && - action != OHOS::AppExecFwk::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED) { - return; - } - - std::string bundleName = want.GetElement().GetBundleName(); - int32_t userId = want.GetIntParam(USER_ID, -1); - int32_t appIndex = want.GetIntParam(SANDBOX_APP_INDEX, 0); - ZLOGI("bundleName:%s, user:%d, appIndex:%d", bundleName.c_str(), userId, appIndex); - callback_(bundleName, userId, appIndex); + callbacks_.ComputeIfPresent(action, [&want](const auto& key, auto &callback) { + std::string bundleName = want.GetElement().GetBundleName(); + int32_t userId = want.GetIntParam(USER_ID, -1); + int32_t appIndex = want.GetIntParam(SANDBOX_APP_INDEX, 0); + ZLOGI("bundleName:%{public}s, user:%{public}d, appIndex:%{public}d", bundleName.c_str(), userId, appIndex); + callback(bundleName, userId, appIndex); + return true; + }); +} +int32_t UninstallEventSubscriber::RegisterCallback(const std::string &action, UninstallEventCallback callback) +{ + callbacks_.InsertOrAssign(action, std::move(callback)); + return Status::SUCCESS; } UninstallerImpl::~UninstallerImpl() @@ -84,34 +87,30 @@ Status UninstallerImpl::Init(KvStoreDataService *kvStoreDataService, std::shared MatchingSkills matchingSkills; matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); matchingSkills.AddEvent(OHOS::AppExecFwk::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED); CommonEventSubscribeInfo info(matchingSkills); - auto callback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { + + auto subscriber = std::make_shared(info); + auto removedCallback = [this, kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { kvStoreDataService->OnUninstall(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); - std::string prefix = StoreMetaData::GetPrefix({ DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, - std::to_string(userId), "default", bundleName }); - std::vector storeMetaData; - if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { - ZLOGE("load meta failed!"); - return; - } - for (auto &meta : storeMetaData) { - if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { - ZLOGI("uninstalled bundleName:%s, stordId:%s", bundleName.c_str(), meta.storeId.c_str()); - MetaDataManager::GetInstance().DelMeta(meta.GetKey()); - MetaDataManager::GetInstance().DelMeta(meta.GetSecretKey(), true); - MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey()); - MetaDataManager::GetInstance().DelMeta(meta.appId, true); - MetaDataManager::GetInstance().DelMeta(meta.GetKeyLocal(), true); - PermitDelegate::GetInstance().DelCache(meta.GetKey()); - } - } + OnUninstall(bundleName, userId, appIndex); }; - auto subscriber = std::make_shared(info, callback); + + auto updatedCallback = [this, kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { + kvStoreDataService->OnUpdate(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); + OnUpdate(bundleName, userId, appIndex); + }; + + subscriber->RegisterCallback(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, removedCallback); + subscriber->RegisterCallback(OHOS::AppExecFwk::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED, removedCallback); + subscriber->RegisterCallback(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED, updatedCallback); + subscriber_ = subscriber; executors_ = executors; executors_->Execute(GetTask()); return Status::SUCCESS; } + ExecutorPool::Task UninstallerImpl::GetTask() { return [this] { @@ -120,11 +119,51 @@ ExecutorPool::Task UninstallerImpl::GetTask() ZLOGI("subscribe uninstall event success"); return; } - ZLOGE("subscribe uninstall event fail, try times:%d", retryTime_); + ZLOGE("subscribe common event fail, try times:%{public}d", retryTime_); if (retryTime_++ >= RETRY_TIME) { return; } executors_->Schedule(std::chrono::milliseconds(RETRY_INTERVAL), GetTask()); }; } + +void UninstallerImpl::OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex) +{ + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); + std::vector storeMetaData; + if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { + ZLOGE("load meta failed!"); + return; + } + for (auto &meta : storeMetaData) { + if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { + ZLOGI("uninstalled bundleName:%{public}s stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + MetaDataManager::GetInstance().DelMeta(meta.GetKey()); + MetaDataManager::GetInstance().DelMeta(meta.GetSecretKey(), true); + MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey()); + MetaDataManager::GetInstance().DelMeta(meta.appId, true); + MetaDataManager::GetInstance().DelMeta(meta.GetKeyLocal(), true); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); + PermitDelegate::GetInstance().DelCache(meta.GetKey()); + } + } +} + +void UninstallerImpl::OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex) +{ + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); + std::vector storeMetaData; + if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { + ZLOGE("load meta failed!"); + return; + } + for (auto &meta : storeMetaData) { + if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { + ZLOGI("updated bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); + } + } +} } // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index 50ec5fe3..9607f58b 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -25,8 +25,8 @@ using UninstallEventCallback = std::function callbacks_; }; class UninstallerImpl : public Uninstaller { public: @@ -47,6 +47,8 @@ public: private: static constexpr int32_t RETRY_TIME = 300; static constexpr int32_t RETRY_INTERVAL = 100; + void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); + void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex); int32_t retryTime_; ExecutorPool::Task GetTask(); std::shared_ptr subscriber_ {}; diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index 6bfd3d23..49b69e8c 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -76,6 +76,12 @@ int32_t FeatureSystem::Feature::OnAppUninstall(const std::string &bundleName, in return E_OK; } +int32_t FeatureSystem::Feature::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, + uint32_t tokenId) +{ + return E_OK; +} + int32_t FeatureSystem::Feature::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) { return E_OK; diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index 8aa732cf..6bb34530 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -42,6 +42,7 @@ public: virtual int32_t OnExecutor(std::shared_ptr executors); virtual int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName); virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); + virtual int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); virtual int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); virtual int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account); virtual int32_t Online(const std::string &device); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index e9e932fc..e6875348 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -262,6 +262,9 @@ void CloudServiceImpl::FeatureInit(const Event &event) void CloudServiceImpl::GetSchema(const Event &event) { auto &rdbEvent = static_cast(event); + ZLOGD("Start GetSchema, bundleName:%{public}s, storeName:%{public}s, instanceId:%{public}d", + rdbEvent.GetStoreInfo().bundleName.c_str(), rdbEvent.GetStoreInfo().storeName.c_str(), + rdbEvent.GetStoreInfo().instanceId); auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); auto schemaMeta = GetSchemaMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); auto storeMeta = GetStoreMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, @@ -287,6 +290,9 @@ void CloudServiceImpl::GetSchema(const Event &event) if (cloudDB != nullptr) { store->Bind(cloudDB); } + for (auto &table : database.tables) { + ZLOGD("table: %{public}s sync start", table.name.c_str()); + } // do sync } return; -- Gitee From de830f45ca2435849b41e95de09272936f38679f Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 13 May 2023 18:13:13 +0800 Subject: [PATCH 027/437] f Signed-off-by: hanlu --- .../include/serializable/serializable.h | 68 ++- .../distributeddataservice/service/BUILD.gn | 6 + .../service/data_share/common/db_delegate.cpp | 16 +- .../service/data_share/common/db_delegate.h | 28 +- .../service/data_share/common/kv_delegate.cpp | 121 ++++- .../service/data_share/common/kv_delegate.h | 4 + .../data_share/common/rdb_delegate.cpp | 5 +- .../data_share/common/template_manager.cpp | 480 ++++++++++++++++++ .../data_share/common/template_manager.h | 118 +++++ .../service/data_share/common/uri_utils.h | 2 +- .../data_share/data/json_formatter.cpp | 38 ++ .../service/data_share/data/json_formatter.h | 36 ++ .../data_share/data/published_data.cpp | 126 +++++ .../service/data_share/data/published_data.h | 54 ++ .../data/resultset_json_formatter.cpp | 48 ++ .../data/resultset_json_formatter.h | 35 ++ .../service/data_share/data/template_data.cpp | 140 +++++ .../service/data_share/data/template_data.h | 67 +++ .../data_share/data_share_service_impl.cpp | 132 ++++- .../data_share/data_share_service_impl.h | 10 +- .../data_share/strategies/get_data_strategy.h | 2 + .../strategies/publish_strategy.cpp | 28 +- .../data_share/strategies/publish_strategy.h | 6 +- .../strategies/subscribe_strategy.cpp | 1 + 24 files changed, 1516 insertions(+), 55 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/common/template_manager.cpp create mode 100644 services/distributeddataservice/service/data_share/common/template_manager.h create mode 100644 services/distributeddataservice/service/data_share/data/json_formatter.cpp create mode 100644 services/distributeddataservice/service/data_share/data/json_formatter.h create mode 100644 services/distributeddataservice/service/data_share/data/published_data.cpp create mode 100644 services/distributeddataservice/service/data_share/data/published_data.h create mode 100644 services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp create mode 100644 services/distributeddataservice/service/data_share/data/resultset_json_formatter.h create mode 100644 services/distributeddataservice/service/data_share/data/template_data.cpp create mode 100644 services/distributeddataservice/service/data_share/data/template_data.h diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index e358decc..47d1805e 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -15,13 +15,13 @@ #ifndef OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H #define OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H -#include #include #include #include "visibility.h" #ifndef JSON_NOEXCEPTION #define JSON_NOEXCEPTION #endif +#include #include namespace OHOS { namespace DistributedData { @@ -70,6 +70,12 @@ public: API_EXPORT static bool SetValue(json &node, bool &value); API_EXPORT static bool SetValue(json &node, const std::vector &value); API_EXPORT static bool SetValue(json &node, const Serializable &value); + + template + API_EXPORT static bool SetValue(json &node, const std::variant<_Types...> &input); + + template + API_EXPORT static bool GetValue(const json &node, const std::string &name, std::variant<_Types...> &value); protected: API_EXPORT ~Serializable() = default; @@ -91,6 +97,17 @@ protected: template static bool SetValue(json &node, const T *value); + template + static bool ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output); + + template + static bool ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output); + + template + static bool WriteVariant(json &node, uint32_t step, const _InTp &input); + + template + static bool WriteVariant(json &node, uint32_t step, const _InTp &input); API_EXPORT static const json &GetSubNode(const json &node, const std::string &name); }; @@ -174,6 +191,55 @@ bool Serializable::SetValue(json &node, const T *value) } return SetValue(node, *value); } + +template +bool Serializable::SetValue(json &node, const std::variant<_Types...> &input) +{ + node[GET_NAME(type)] = input.index(); + return WriteVariant(node, 0, input); +} + +template +bool Serializable::GetValue(const json &node, const std::string &name, std::variant<_Types...> &value) +{ + uint32_t index; + bool ret = GetValue(node, GET_NAME(type), index); + if (!ret) { + return ret; + } + + return Serializable::ReadVariant(node, name, 0, index, value); +} + +template +bool Serializable::WriteVariant(json &node, uint32_t step, const _InTp &input) +{ + return false; +} + +template +bool Serializable::ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output) +{ + if (step == index) { + return Serializable::GetValue(node, name, std::get<_First>(output)); + } + return Serializable::ReadVariant<_OutTp, _Rest...>(node, name, step + 1, index, output); +} + +template +bool Serializable::WriteVariant(json &node, uint32_t step, const _InTp &input) +{ + if (step == input.index()) { + return Serializable::SetValue(node, std::get<_First>(input)); + } + return WriteVariant<_InTp, _Rest...>(node, step + 1, input); +} + +template +bool Serializable::ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output) +{ + return false; +} } // namespace DistributedData } // namespace OHOS #endif // OHOS_DISTRIBUTED_DATA_FRAMEWORKS_COMMON_SERIALIZABLE_H diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 1d29c1ef..62ccc155 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -78,7 +78,12 @@ ohos_shared_library("distributeddatasvc") { "data_share/common/kv_delegate.cpp", "data_share/common/rdb_delegate.cpp", "data_share/common/seq_strategy.cpp", + "data_share/common/template_manager.cpp", "data_share/common/uri_utils.cpp", + "data_share/data/json_formatter.cpp", + "data_share/data/published_data.cpp", + "data_share/data/resultset_json_formatter.cpp", + "data_share/data/template_data.cpp", "data_share/data_share_obs_proxy.cpp", "data_share/data_share_service_impl.cpp", "data_share/data_share_service_stub.cpp", @@ -142,6 +147,7 @@ ohos_shared_library("distributeddatasvc") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", + "data_share/gaussdb_rd:gaussdb_rd", ] external_deps = [ diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index 97e451bc..7008e5fd 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -34,15 +34,6 @@ std::shared_ptr KvDBDelegate::GetInstance(bool reInit, const std:: return delegate; } -bool KvData::Marshal(DistributedData::Serializable::json &node) const -{ - auto ret = SetValue(node, *GetId()); - if (HasVersion()) { - ret &= SetValue(node, GetVersion()); - } - return ret & SetValue(node, GetValue()); -} - bool Id::Marshal(DistributedData::Serializable::json &node) const { return SetValue(node[GET_NAME(_id)], _id); @@ -66,4 +57,11 @@ bool VersionData::Marshal(DistributedData::Serializable::json &node) const { return SetValue(node[GET_NAME(version)], version); } + +const std::string &KvData::GetId() const +{ + return id; +} + +KvData::KvData(const Id &id) : id(DistributedData::Serializable::Marshall(id)) {} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index e6ec2721..716c4f32 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -46,11 +46,16 @@ struct RdbStoreContext { int version; }; -struct Id final: public DistributedData::Serializable { +class Id : public DistributedData::Serializable { +public: explicit Id(const std::string &id); ~Id() = default; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; + operator std::string() + { + return DistributedData::Serializable::Marshall(*this); + } private: std::string _id; @@ -61,12 +66,11 @@ public: explicit VersionData(int version); bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; - VersionData &operator=(int inputVersion) + virtual void SetVersion(int ver) { - version = inputVersion; - return *this; + version = ver; }; - operator int() + virtual int GetVersion() const { return version; }; @@ -75,12 +79,16 @@ private: int version; }; -struct KvData : public DistributedData::Serializable { - virtual std::shared_ptr GetId() const = 0; +class KvData { +public: + explicit KvData(const Id &id); + const std::string &GetId() const; virtual bool HasVersion() const = 0; - virtual VersionData GetVersion() const = 0; - virtual const Serializable &GetValue() const = 0; - bool Marshal(json &node) const override; + virtual int GetVersion() const = 0; + virtual std::string GetValue() const = 0; + +private: + std::string id; }; class KvDBDelegate { diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index cbbb3fcd..f75a3d6d 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -16,17 +16,41 @@ #include "kv_delegate.h" #include "datashare_errno.h" #include "directory_manager.h" +#include "grd_document/grd_document_api.h" +#include "grd_base/grd_error.h" #include "ipc_skeleton.h" #include "log_print.h" namespace OHOS::DataShare { int64_t KvDelegate::Upsert(const std::string &collectionName, const std::string &filter, const std::string &value) { + std::lock_guard lock(mutex_); + if (!Init()) { + ZLOGE("init failed, %{public}s", collectionName.c_str()); + return E_ERROR; + } + int count = GRD_UpsertDoc(db_, collectionName.c_str(), filter.c_str(), value.c_str(), 0); + if (count <= 0) { + ZLOGE("GRD_UpSertDoc failed,status %{public}d", count); + return count; + } + Flush(); return E_OK; } int64_t KvDelegate::Delete(const std::string &collectionName, const std::string &filter) { + std::lock_guard lock(mutex_); + if (!Init()) { + ZLOGE("init failed, %{public}s", collectionName.c_str()); + return E_ERROR; + } + int count = GRD_DeleteDoc(db_, collectionName.c_str(), filter.c_str(), 0); + if (count <= 0) { + ZLOGE("GRD_UpSertDoc failed,status %{public}d", count); + return count; + } + Flush(); return E_OK; } @@ -35,24 +59,53 @@ bool KvDelegate::Init() if (isInitDone_) { return true; } + ZLOGE("hanlu init %{public}s", path_.c_str()); + int status = GRD_DBOpen((path_ + "/dataShare.db").c_str(), nullptr, GRD_DB_OPEN_CREATE, &db_); + if (status != GRD_OK || db_ == nullptr) { + ZLOGE("GRD_DBOpen failed,status %{public}d", status); + return false; + } + + status = GRD_CreateCollection(db_, TEMPLATE_TABLE, nullptr, 0); + if (status != GRD_OK) { + ZLOGE("GRD_CreateCollection template table failed,status %{public}d", status); + return false; + } + + status = GRD_CreateCollection(db_, DATA_TABLE, nullptr, 0); + if (status != GRD_OK) { + ZLOGE("GRD_CreateCollection data table failed,status %{public}d", status); + return false; + } isInitDone_ = true; return true; } +KvDelegate::~KvDelegate() +{ + std::lock_guard lock(mutex_); + if (isInitDone_) { + int status = GRD_DBClose(db_, 0); + if (status != GRD_OK) { + ZLOGE("GRD_DBClose failed,status %{public}d", status); + } + } +} + int32_t KvDelegate::Upsert(const std::string &collectionName, const KvData &value) { - std::string id = DistributedData::Serializable::Marshall(*value.GetId()); + std::string id = value.GetId(); if (value.HasVersion() && value.GetVersion() != 0) { int version = -1; if (GetVersion(collectionName, id, version)) { if (value.GetVersion() <= version) { ZLOGE("GetVersion failed,%{public}s id %{private}s %{public}d %{public}d", collectionName.c_str(), - id.c_str(), static_cast(value.GetVersion()), version); + id.c_str(), value.GetVersion(), version); return E_VERSION_NOT_NEWER; } } } - return Upsert(collectionName, id, DistributedData::Serializable::Marshall(value.GetValue())); + return Upsert(collectionName, id, value.GetValue()); } int32_t KvDelegate::DeleteById(const std::string &collectionName, const Id &id) @@ -82,23 +135,83 @@ bool KvDelegate::GetVersion(const std::string &collectionName, const std::string ZLOGE("Unmarshall failed,data %{public}s", value.c_str()); return false; } - version = data; + version = data.GetVersion(); return true; } int32_t KvDelegate::Get( const std::string &collectionName, const std::string &filter, const std::string &projection, std::string &result) { + std::lock_guard lock(mutex_); + if (!Init()) { + ZLOGE("init failed, %{public}s", collectionName.c_str()); + return E_ERROR; + } + Query query; + query.filter = filter.c_str(); + query.projection = projection.c_str(); + GRD_ResultSet *resultSet = nullptr; + int status = GRD_FindDoc(db_, collectionName.c_str(), query, 0, &resultSet); + if (status != GRD_OK || resultSet == nullptr) { + ZLOGE("GRD_FindDoc failed,status %{public}d", status); + return status; + } + status = GRD_Next(resultSet); + if (status != GRD_OK) { + GRD_FreeResultSet(resultSet); + ZLOGE("GRD_Next failed,status %{public}d", status); + return status; + } + char *value = nullptr; + status = GRD_GetValue(resultSet, &value); + if (status != GRD_OK || value == nullptr) { + GRD_FreeResultSet(resultSet); + ZLOGE("GRD_GetValue failed,status %{public}d", status); + return status; + } + result = value; + GRD_FreeValue(value); + GRD_FreeResultSet(resultSet); return E_OK; } void KvDelegate::Flush() { + int status = GRD_Flush(db_, GRD_DB_FLUSH_ASYNC); + if (status != GRD_OK) { + ZLOGE("GRD_Flush failed,status %{public}d", status); + } } int32_t KvDelegate::GetBatch(const std::string &collectionName, const std::string &filter, const std::string &projection, std::vector &result) { + std::lock_guard lock(mutex_); + if (!Init()) { + ZLOGE("init failed, %{public}s", collectionName.c_str()); + return E_ERROR; + } + Query query; + query.filter = filter.c_str(); + query.projection = projection.c_str(); + GRD_ResultSet *resultSet; + int status = GRD_FindDoc(db_, collectionName.c_str(), query, 0, &resultSet); + if (status != GRD_OK || resultSet == nullptr) { + ZLOGE("GRD_UpSertDoc failed,status %{public}d", status); + return status; + } + char *value = nullptr; + while (GRD_Next(resultSet) == GRD_OK) { + status = GRD_GetValue(resultSet, &value); + if (status != GRD_OK || value == nullptr) { + GRD_FreeResultSet(resultSet); + ZLOGE("GRD_GetValue failed,status %{public}d", status); + return status; + } + result.emplace_back(value); + GRD_FreeValue(value); + } + GRD_FreeResultSet(resultSet); return E_OK; } diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.h b/services/distributeddataservice/service/data_share/common/kv_delegate.h index fe111337..e490a249 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.h +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.h @@ -20,11 +20,13 @@ #include #include "db_delegate.h" +#include "grd_base/grd_db_api.h" namespace OHOS::DataShare { class KvDelegate final : public KvDBDelegate { public: explicit KvDelegate(const std::string &path); + ~KvDelegate() override; int32_t Upsert(const std::string &collectionName, const KvData &value) override; int32_t DeleteById(const std::string &collectionName, const Id &id) override; int32_t Get(const std::string &collectionName, const Id &id, std::string &value) override; @@ -40,7 +42,9 @@ private: int64_t Upsert(const std::string &collectionName, const std::string &filter, const std::string &value); int64_t Delete(const std::string &collectionName, const std::string &filter); void Flush(); + std::mutex mutex_; std::string path_; + GRD_DB *db_ = nullptr; bool isInitDone_ = false; }; } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index a5e6ad21..e4c9b2be 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -15,7 +15,9 @@ #define LOG_TAG "RdbAdaptor" #include "rdb_delegate.h" +#include "data/resultset_json_formatter.h" #include "log_print.h" +#include "rdb_utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { @@ -120,7 +122,8 @@ std::shared_ptr RdbDelegate::Query( ZLOGE("Query failed %{private}s", sql.c_str()); return nullptr; } - return nullptr; + + return std::make_shared(resultSet); } int RdbDelegate::ExecuteSql(const std::string &sql) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp new file mode 100644 index 00000000..9a22d067 --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -0,0 +1,480 @@ +/* + * 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. + */ +#define LOG_TAG "TemplateManager" + +#include "template_manager.h" + +#include "db_delegate.h" +#include "json_formatter.h" +#include "log_print.h" +#include "published_data.h" +#include "template_data.h" +#include "uri_utils.h" +#include "utils/anonymous.h" + +namespace OHOS::DataShare { +bool TemplateManager::GetTemplate( + const std::string &uri, const int64_t subscriberId, const std::string &bundleName, Template &tpl) +{ + return TemplateData::Query(Id(TemplateData::GenId(uri, bundleName, subscriberId)), tpl) == E_OK; +} + +bool TemplateManager::AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return false; + } + TemplateData data(uri, tplId.bundleName_, tplId.subscriberId_, tpl); + auto status = delegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); + if (status != E_OK) { + ZLOGE("db Upsert failed, %{public}d", status); + return false; + } + return true; +} + +bool TemplateManager::DelTemplate(const std::string &uri, const TemplateId &tplId) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return false; + } + auto status = delegate->DeleteById( + KvDBDelegate::TEMPLATE_TABLE, Id(TemplateData::GenId(uri, tplId.bundleName_, tplId.subscriberId_))); + if (status != E_OK) { + ZLOGE("db DeleteById failed, %{public}d", status); + return false; + } + return true; +} + +Key::Key(const std::string &uri, const int64_t subscriberId, const std::string &bundleName) + : uri(uri), subscriberId(subscriberId), bundleName(bundleName) +{ +} + +bool Key::operator==(const Key &rhs) const +{ + return uri == rhs.uri && subscriberId == rhs.subscriberId && bundleName == rhs.bundleName; +} + +bool Key::operator!=(const Key &rhs) const +{ + return !(rhs == *this); +} +bool Key::operator<(const Key &rhs) const +{ + if (uri < rhs.uri) { + return true; + } + if (rhs.uri < uri) { + return false; + } + if (subscriberId < rhs.subscriberId) { + return true; + } + if (rhs.subscriberId < subscriberId) { + return false; + } + return bundleName < rhs.bundleName; +} +bool Key::operator>(const Key &rhs) const +{ + return rhs < *this; +} +bool Key::operator<=(const Key &rhs) const +{ + return !(rhs < *this); +} +bool Key::operator>=(const Key &rhs) const +{ + return !(*this < rhs); +} + +TemplateManager::TemplateManager() {} + +TemplateManager &TemplateManager::GetInstance() +{ + static TemplateManager manager; + return manager; +} + +RdbSubscriberManager &RdbSubscriberManager::GetInstance() +{ + static RdbSubscriberManager manager; + return manager; +} + +int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const TemplateId &tplId, + const sptr observer, std::shared_ptr context) +{ + int result = E_OK; + Key key(uri, tplId.subscriberId_, tplId.bundleName_); + rdbCache_.Compute(key, [&observer, &context, &result, this](const auto &key, std::vector &value) { + ZLOGI("add subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), context->callerTokenId); + std::vector node; + node.emplace_back(observer, context->callerTokenId); + result = Notify(key, node, context->calledSourceDir, context->version); + if (result != E_OK) { + return false; + } + value.emplace_back(observer, context->callerTokenId); + return true; + }); + return result; +} + +int RdbSubscriberManager::DelRdbSubscriber( + const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId) +{ + Key key(uri, tplId.subscriberId_, tplId.bundleName_); + auto result = + rdbCache_.ComputeIfPresent(key, [&callerTokenId, this](const auto &key, std::vector &value) { + ZLOGI("delete subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), callerTokenId); + for (auto it = value.begin(); it != value.end();) { + if (it->callerTokenId == callerTokenId) { + ZLOGI("erase start"); + it = value.erase(it); + } else { + it++; + } + } + return !value.empty(); + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +int RdbSubscriberManager::DisableRdbSubscriber( + const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId) +{ + Key key(uri, tplId.subscriberId_, tplId.bundleName_); + auto result = + rdbCache_.ComputeIfPresent(key, [&callerTokenId, this](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + if (it->callerTokenId == callerTokenId) { + it->enabled = false; + } + } + return true; + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +int RdbSubscriberManager::EnableRdbSubscriber( + const std::string &uri, const TemplateId &tplId, std::shared_ptr context) +{ + Key key(uri, tplId.subscriberId_, tplId.bundleName_); + auto result = rdbCache_.ComputeIfPresent(key, [&context, this](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + if (it->callerTokenId == context->callerTokenId) { + it->enabled = true; + std::vector node; + node.emplace_back(it->observer, context->callerTokenId); + Notify(key, node, context->calledSourceDir, context->version); + } + } + return true; + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +void RdbSubscriberManager::Emit(const std::string &uri, std::shared_ptr context) +{ + if (!URIUtils::IsDataProxyURI(uri)) { + return; + } + rdbCache_.ForEach([&uri, &context, this](const Key &key, std::vector &val) { + if (key.uri != uri) { + return false; + } + Notify(key, val, context->calledSourceDir, context->version); + return false; + }); +} + +std::vector RdbSubscriberManager::GetKeysByUri(const std::string &uri) +{ + std::vector results; + rdbCache_.ForEach([&uri, &results](const Key &key, std::vector &val) { + if (key.uri != uri) { + return false; + } + results.emplace_back(key); + return false; + }); + return results; +} + +void RdbSubscriberManager::EmitByKey(const Key &key, const std::string &rdbPath, int version) +{ + if (!URIUtils::IsDataProxyURI(key.uri)) { + return; + } + rdbCache_.ComputeIfPresent(key, [&rdbPath, &version, this](const Key &key, std::vector &val) { + Notify(key, val, rdbPath, version); + return true; + }); +} + +int RdbSubscriberManager::GetObserverCount(const Key &key) +{ + auto pair = rdbCache_.Find(key); + if (!pair.first) { + return 0; + } + return pair.second.size(); +} + +int RdbSubscriberManager::GetEnableObserverCount(const Key &key) +{ + auto pair = rdbCache_.Find(key); + if (!pair.first) { + return 0; + } + int count = 0; + for (const auto &observer : pair.second) { + if (observer.enabled) { + count++; + } + } + return count; +} + +int RdbSubscriberManager::Notify( + const Key &key, std::vector &val, const std::string &rdbDir, int rdbVersion) +{ + Template tpl; + if (!TemplateManager::GetInstance().GetTemplate(key.uri, key.subscriberId, key.bundleName, tpl)) { + ZLOGE("template undefined, %{public}s, %{public}" PRId64 ", %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); + return E_TEMPLATE_NOT_EXIST; + } + auto delegate = DBDelegate::Create(rdbDir, rdbVersion); + if (delegate == nullptr) { + ZLOGE("Create fail %{public}s %{public}s", DistributedData::Anonymous::Change(key.uri).c_str(), + key.bundleName.c_str()); + return E_ERROR; + } + RdbChangeNode changeNode; + changeNode.uri_ = key.uri; + changeNode.templateId_.subscriberId_ = key.subscriberId; + changeNode.templateId_.bundleName_ = key.bundleName; + for (const auto &predicate : tpl.predicates_) { + JsonFormatter formatter(predicate.key_, delegate->Query(predicate.selectSql_)); + changeNode.data_.emplace_back(DistributedData::Serializable::Marshall(formatter)); + } + + ZLOGI("emit, size %{public}d %{private}s", val.size(), changeNode.uri_.c_str()); + for (auto &callback : val) { + if (callback.enabled && callback.observer != nullptr) { + callback.observer->OnChangeFromRdb(changeNode); + } + } + return E_OK; +} + +PublishedDataSubscriberManager &PublishedDataSubscriberManager::GetInstance() +{ + static PublishedDataSubscriberManager manager; + return manager; +} + +int PublishedDataSubscriberManager::AddSubscriber(const std::string &key, const std::string &callerBundleName, + const int64_t subscriberId, const sptr observer, const uint32_t callerTokenId) +{ + PublishedDataKey publishedDataKey(key, callerBundleName, subscriberId); + publishedDataCache.Compute(publishedDataKey, + [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { + ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); + value.emplace_back(observer, callerTokenId); + return true; + }); + return E_OK; +} + +int PublishedDataSubscriberManager::DelSubscriber(const std::string &uri, const std::string &callerBundleName, + const int64_t subscriberId, const uint32_t callerTokenId) +{ + PublishedDataKey key(uri, callerBundleName, subscriberId); + auto result = + publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end();) { + if (it->callerTokenId == callerTokenId) { + it = value.erase(it); + } else { + it++; + } + } + return !value.empty(); + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +int PublishedDataSubscriberManager::DisableSubscriber(const std::string &uri, const std::string &callerBundleName, + const int64_t subscriberId, const uint32_t callerTokenId) +{ + PublishedDataKey key(uri, callerBundleName, subscriberId); + auto result = + publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + if (it->callerTokenId == callerTokenId) { + it->enabled = false; + } + } + return true; + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +int PublishedDataSubscriberManager::EnableSubscriber(const std::string &uri, const std::string &callerBundleName, + const int64_t subscriberId, const uint32_t callerTokenId) +{ + PublishedDataKey key(uri, callerBundleName, subscriberId); + auto result = + publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + if (it->callerTokenId == callerTokenId) { + it->enabled = true; + } + } + return true; + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +void PublishedDataSubscriberManager::Emit(const std::vector &keys, + const std::string &ownerBundleName, const sptr observer) +{ + int32_t status; + // key is bundleName, value is change node + std::map, std::string>> publishedResult; + std::map, std::vector> callbacks; + publishedDataCache.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, this]( + const PublishedDataKey &key, std::vector &val) { + for (auto &data : keys) { + if (key != data || publishedResult.count(key) != 0) { + continue; + } + status = PublishedData::Query( + Id(PublishedData::GenId(key.key, key.bundleName, key.subscriberId)), publishedResult[key]); + if (status != E_OK) { + ZLOGE("query fail %{public}s %{public}s %{public}" PRId64, data.bundleName.c_str(), data.key.c_str(), + data.subscriberId); + publishedResult.erase(key); + continue; + } + PutInto(callbacks, val, key, observer); + break; + } + return false; + }); + PublishedDataChangeNode result; + for (auto &[callback, keys] : callbacks) { + result.datas_.clear(); + for (auto &key : keys) { + if (publishedResult.count(key) != 0) { + result.datas_.emplace_back(key.key, key.subscriberId, publishedResult[key]); + } + } + if (result.datas_.empty()) { + continue; + } + result.ownerBundleName_ = ownerBundleName; + callback->OnChangeFromPublishedData(result); + } +} + +void PublishedDataSubscriberManager::PutInto( + std::map, std::vector> &callbacks, + std::vector &val, const PublishedDataKey &key, const sptr observer) +{ + for (auto &callback : val) { + if (callback.enabled && callback.observer != nullptr) { + // callback the observer, others do not call + if (observer != nullptr && callback.observer != observer) { + continue; + } + callbacks[callback.observer].emplace_back(key); + } + } +} + +PublishedDataKey::PublishedDataKey(const std::string &key, const std::string &bundle, const int64_t subscriberId) + : key(key), bundleName(bundle), subscriberId(subscriberId) +{ + /* private published data can use key as simple uri */ + /* etc: datashareproxy://{bundleName}/meeting can use meeting replaced */ + /* if key is normal uri, bundleName is from uri */ + if (URIUtils::IsDataProxyURI(key)) { + URIUtils::GetBundleNameFromProxyURI(key, bundleName); + } +} + +bool PublishedDataKey::operator<(const PublishedDataKey &rhs) const +{ + if (key < rhs.key) { + return true; + } + if (rhs.key < key) { + return false; + } + if (bundleName < rhs.bundleName) { + return true; + } + if (rhs.bundleName < bundleName) { + return false; + } + return subscriberId < rhs.subscriberId; +} + +bool PublishedDataKey::operator>(const PublishedDataKey &rhs) const +{ + return rhs < *this; +} + +bool PublishedDataKey::operator<=(const PublishedDataKey &rhs) const +{ + return !(rhs < *this); +} + +bool PublishedDataKey::operator>=(const PublishedDataKey &rhs) const +{ + return !(*this < rhs); +} + +bool PublishedDataKey::operator==(const PublishedDataKey &rhs) const +{ + return key == rhs.key && bundleName == rhs.bundleName && subscriberId == rhs.subscriberId; +} + +bool PublishedDataKey::operator!=(const PublishedDataKey &rhs) const +{ + return !(rhs == *this); +} + +RdbSubscriberManager::ObserverNode::ObserverNode(const sptr &observer, uint32_t callerTokenId) + : observer(observer), callerTokenId(callerTokenId) +{ +} + +PublishedDataSubscriberManager::ObserverNode::ObserverNode( + const sptr &observer, uint32_t callerTokenId) + : observer(observer), callerTokenId(callerTokenId) +{ +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h new file mode 100644 index 00000000..f6b4e5a5 --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -0,0 +1,118 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_TEMPLATE_MANAGER_H +#define DATASHARESERVICE_TEMPLATE_MANAGER_H + +#include +#include + +#include "concurrent_map.h" +#include "datashare_template.h" +#include "data_proxy_observer.h" +#include "context.h" +namespace OHOS::DataShare { +struct Key { + Key(const std::string &uri, const int64_t subscriberId, const std::string &bundleName); + bool operator==(const Key &rhs) const; + bool operator!=(const Key &rhs) const; + bool operator<(const Key &rhs) const; + bool operator>(const Key &rhs) const; + bool operator<=(const Key &rhs) const; + bool operator>=(const Key &rhs) const; + const std::string uri; + const int64_t subscriberId; + const std::string bundleName; +}; +class TemplateManager { +public: + static TemplateManager &GetInstance(); + bool AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl); + bool DelTemplate(const std::string &uri, const TemplateId &tplId); + bool GetTemplate(const std::string &uri, int64_t subscriberId, const std::string &bundleName, Template &tpl); + +private: + TemplateManager(); + friend class RdbSubscriberManager; +}; + +class RdbSubscriberManager { +public: + static RdbSubscriberManager &GetInstance(); + int AddRdbSubscriber(const std::string &uri, const TemplateId &tplId, const sptr observer, + std::shared_ptr context); + int DelRdbSubscriber(const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId); + int DisableRdbSubscriber( + const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId); + int EnableRdbSubscriber(const std::string &uri, const TemplateId &tplId, std::shared_ptr context); + void Emit(const std::string &uri, std::shared_ptr context); + void EmitByKey(const Key &key, const std::string &rdbPath, int version); + int GetObserverCount(const Key &key); + std::vector GetKeysByUri(const std::string &uri); + +private: + struct ObserverNode { + ObserverNode(const sptr &observer, uint32_t callerTokenId); + sptr observer; + uint32_t callerTokenId; + bool enabled = true; + }; + + RdbSubscriberManager() = default; + ConcurrentMap> rdbCache_; + int Notify(const Key &key, std::vector &val, const std::string &rdbDir, int rdbVersion); + int GetEnableObserverCount(const Key &key); +}; + +struct PublishedDataKey { + PublishedDataKey(const std::string &key, const std::string &bundleName, const int64_t subscriberId); + bool operator<(const PublishedDataKey &rhs) const; + bool operator>(const PublishedDataKey &rhs) const; + bool operator<=(const PublishedDataKey &rhs) const; + bool operator>=(const PublishedDataKey &rhs) const; + bool operator==(const PublishedDataKey &rhs) const; + bool operator!=(const PublishedDataKey &rhs) const; + std::string key; + std::string bundleName; + int64_t subscriberId; +}; + +class PublishedDataSubscriberManager { +public: + static PublishedDataSubscriberManager &GetInstance(); + int AddSubscriber(const std::string &key, const std::string &callerBundleName, const int64_t subscriberId, + const sptr observer, const uint32_t callerTokenId); + int DelSubscriber(const std::string &uri, const std::string &callerBundleName, const int64_t subscriberId, + const uint32_t callerTokenId); + int DisableSubscriber(const std::string &uri, const std::string &callerBundleName, const int64_t subscriberId, + const uint32_t callerTokenId); + int EnableSubscriber(const std::string &uri, const std::string &callerBundleName, const int64_t subscriberId, + const uint32_t callerTokenId); + void Emit(const std::vector &keys, const std::string &ownerBundleName, + const sptr observer = nullptr); +private: + struct ObserverNode { + ObserverNode(const sptr &observer, uint32_t callerTokenId); + sptr observer; + uint32_t callerTokenId; + bool enabled = true; + }; + PublishedDataSubscriberManager() = default; + void PutInto(std::map, std::vector> &, + std::vector &, const PublishedDataKey &, const sptr); + ConcurrentMap> publishedDataCache; +}; +} // namespace OHOS::DataShare +#endif diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.h b/services/distributeddataservice/service/data_share/common/uri_utils.h index 0bf62d16..17ee8698 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.h +++ b/services/distributeddataservice/service/data_share/common/uri_utils.h @@ -33,7 +33,7 @@ public: static bool IsDataProxyURI(const std::string &uri); static constexpr const char *DATA_SHARE_SCHEMA = "datashare:///";; static constexpr const char DATA_PROXY_SCHEMA[] = "datashareproxy://"; - static constexpr int DATA_PROXY_SCHEMA_LEN = sizeof(DATA_PROXY_SCHEMA); + static constexpr int DATA_PROXY_SCHEMA_LEN = sizeof(DATA_PROXY_SCHEMA) - 1; private: enum PATH_PARAM : int32_t { diff --git a/services/distributeddataservice/service/data_share/data/json_formatter.cpp b/services/distributeddataservice/service/data_share/data/json_formatter.cpp new file mode 100644 index 00000000..db190824 --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/json_formatter.cpp @@ -0,0 +1,38 @@ +/* + * 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. + */ +#define LOG_TAG "JsonFormatter" +#include "json_formatter.h" + +#include "log_print.h" + +namespace OHOS::DataShare { +bool JsonFormatter::Marshal(json &node) const +{ + if (value_ == nullptr) { + ZLOGE("null value %{public}s", key_.c_str()); + return false; + } + return SetValue(node[key_], *value_); +} + +bool JsonFormatter::Unmarshal(const json &node) +{ + if (value_ == nullptr) { + ZLOGE("null value %{public}s", key_.c_str()); + return false; + } + return GetValue(node, key_, *value_); +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/json_formatter.h b/services/distributeddataservice/service/data_share/data/json_formatter.h new file mode 100644 index 00000000..7c41e197 --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/json_formatter.h @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_JSON_FORMATTER_H +#define DATASHARESERVICE_JSON_FORMATTER_H + +#include "serializable/serializable.h" + +namespace OHOS::DataShare { +class JsonFormatter : public DistributedData::Serializable { +public: + JsonFormatter(const std::string &key, const std::shared_ptr &value) + : key_(key), value_(value) + { + } + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + +private: + std::string key_; + std::shared_ptr value_; +}; +} // namespace OHOS::DataShare +#endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp new file mode 100644 index 00000000..4dd329be --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -0,0 +1,126 @@ +/* + * 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. + */ +#define LOG_TAG "PublishedData" +#include "published_data.h" + +#include "log_print.h" + +namespace OHOS::DataShare { +bool PublishedData::HasVersion() const +{ + return true; +} + +int PublishedData::GetVersion() const +{ + return value.GetVersion(); +} + +std::string PublishedData::GetValue() const +{ + return DistributedData::Serializable::Marshall(value); +} + +PublishedData::PublishedData(const std::string &key, const std::string &bundleName, int64_t subscriberId, + const std::variant, std::string> &inputValue, const int version) + : KvData(Id(GenId(key, bundleName, subscriberId))), + value(key, bundleName, subscriberId, inputValue) +{ + value.SetVersion(version); +} +/* +std::vector PublishedData::Query(const std::string &bundleName) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return std::vector(); + } + std::vector queryResults; + json filter; + filter["bundleName"] = bundleName; + int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, filter.dump(), "{}", queryResults); + if (status != E_OK) { + ZLOGE("db Upsert failed, %{public}s %{public}d", bundleName.c_str(), status); + return std::vector(); + } + std::vector results; + for (auto &result : queryResults) { + PublishedData data; + if (data.Unmarshall(result)) { + results.push_back(std::move(data)); + } + } + return results; +} */ + +bool PublishedDataNode::Marshal(DistributedData::Serializable::json &node) const +{ + bool ret = SetValue(node[GET_NAME(key)], key); + ret = ret && SetValue(node[GET_NAME(bundleName)], bundleName); + ret = ret && SetValue(node[GET_NAME(subscriberId)], subscriberId); + ret = ret && SetValue(node[GET_NAME(value)], value); + ret = ret && SetValue(node[GET_NAME(timestamp)], timestamp); + return ret && VersionData::Marshal(node); +} + +bool PublishedDataNode::Unmarshal(const DistributedData::Serializable::json &node) +{ + bool ret = GetValue(node, GET_NAME(key), key); + ret = ret && GetValue(node, GET_NAME(bundleName), bundleName); + ret = ret && GetValue(node, GET_NAME(subscriberId), subscriberId); + ret = ret && GetValue(node, GET_NAME(value), value); + ret = ret && GetValue(node, GET_NAME(timestamp), timestamp); + return ret && VersionData::Unmarshal(node); +} + +PublishedDataNode::PublishedDataNode(const std::string &key, const std::string &bundleName, + int64_t subscriberId, const std::variant, std::string> &value) + : VersionData(-1), key(key), bundleName(bundleName), subscriberId(subscriberId), value(std::move(value)) +{ + auto now = time(nullptr); + if (now > 0) { + timestamp = now; + } +} + +PublishedDataNode::PublishedDataNode() : VersionData(-1) {} + +int32_t PublishedData::Query(const std::string &filter, std::variant, std::string> &publishedData) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return E_ERROR; + } + std::string queryResult; + int32_t status = delegate->Get(KvDBDelegate::DATA_TABLE, filter, "{}", queryResult); + if (status != E_OK) { + ZLOGE("db Get failed, %{public}s %{public}d", filter.c_str(), status); + return status; + } + PublishedDataNode data; + if (!PublishedDataNode::Unmarshall(queryResult, data)) { + ZLOGE("Unmarshall failed, %{private}s", queryResult.c_str()); + return E_ERROR; + } + publishedData = std::move(data.value); + return E_OK; +} +std::string PublishedData::GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId) +{ + return key + "_" + std::to_string(subscriberId) + "_" + bundleName; +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h new file mode 100644 index 00000000..daa7d667 --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_PUBLISHED_DATA_H +#define DATASHARESERVICE_PUBLISHED_DATA_H + +#include "db_delegate.h" +#include "serializable/serializable.h" + +namespace OHOS::DataShare { +class PublishedDataNode final : public VersionData { +public: + PublishedDataNode(); + PublishedDataNode(const std::string &key, const std::string &bundleName, int64_t subscriberId, + const std::variant, std::string> &value); + ~PublishedDataNode() = default; + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + std::string key; + std::string bundleName; + int64_t subscriberId; + std::variant, std::string> value; + std::time_t timestamp = 0; +}; + +class PublishedData final : public KvData { +public: + // static std::vector Query(const std::string &bundleName); + static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); + static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); + PublishedData(const std::string &key, const std::string &bundleName, int64_t subscriberId, + const std::variant, std::string> &value, const int version); + ~PublishedData() = default; + bool HasVersion() const override; + int GetVersion() const override; + std::string GetValue() const override; + +private: + PublishedDataNode value; +}; +} // namespace OHOS::DataShare +#endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H diff --git a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp new file mode 100644 index 00000000..931a4d54 --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp @@ -0,0 +1,48 @@ +/* + * 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. + */ +#define LOG_TAG "ResultSetJsonFormatter" +#include "resultset_json_formatter.h" + +#include "rdb_errno.h" +#include "log_print.h" + +namespace OHOS::DataShare { +bool ResultSetJsonFormatter::Marshal(json &node) const +{ + int columnCount = 0; + auto result = resultSet->GetColumnCount(columnCount); + if (result != NativeRdb::E_OK) { + ZLOGE("GetColumnCount err, %{public}d", result); + return false; + } + while (resultSet->GoToNextRow() == NativeRdb::E_OK) { + json result; + for (int i = 0; i < columnCount; i++) { + std::string columnName; + std::string value; + resultSet->GetColumnName(i, columnName); + resultSet->GetString(i, value); + SetValue(result[columnName], value); + } + node.push_back(result); + } + return true; +} + +bool ResultSetJsonFormatter::Unmarshal(const DistributedData::Serializable::json &node) +{ + return false; +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.h b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.h new file mode 100644 index 00000000..0dfcabdf --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_RESULTSET_JSON_FORMATTER_H +#define DATASHARESERVICE_RESULTSET_JSON_FORMATTER_H + +#include "datashare_template.h" +#include "rdb_utils.h" +#include "serializable/serializable.h" + +namespace OHOS::DataShare { +class ResultSetJsonFormatter final : public DistributedData::Serializable { +public: + explicit ResultSetJsonFormatter(const std::shared_ptr &resultSet) : resultSet(resultSet) {} + ~ResultSetJsonFormatter() {} + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + +private: + std::shared_ptr resultSet; +}; +} // namespace OHOS::DataShare +#endif // DATASHARESERVICE_RESULTSET_JSON_FORMATTER_H diff --git a/services/distributeddataservice/service/data_share/data/template_data.cpp b/services/distributeddataservice/service/data_share/data/template_data.cpp new file mode 100644 index 00000000..ca52ba1a --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/template_data.cpp @@ -0,0 +1,140 @@ +/* + * 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. + */ +#define LOG_TAG "TemplateData" +#include "template_data.h" +#include "log_print.h" +namespace OHOS::DataShare { +bool TemplateNode::Marshal(DistributedData::Serializable::json &node) const +{ + bool ret = SetValue(node[GET_NAME(predicates)], predicates); + ret = ret && SetValue(node[GET_NAME(scheduler)], scheduler); + return ret; +} + +bool TemplateNode::Unmarshal(const DistributedData::Serializable::json &node) +{ + bool ret = GetValue(node, GET_NAME(predicates), predicates); + return ret && GetValue(node, GET_NAME(scheduler), scheduler); +} + +TemplateNode::TemplateNode(const Template &tpl) : scheduler(tpl.scheduler_) +{ + for (auto &item:tpl.predicates_) { + predicates.emplace_back(item.key_, item.selectSql_); + } +} + +Template TemplateNode::ToTemplate() const +{ + std::vector nodes; + for (const auto &predicate: predicates) { + nodes.emplace_back(predicate.key, predicate.selectSql); + } + return Template(nodes, scheduler); +} + +bool TemplateRootNode::Marshal(DistributedData::Serializable::json &node) const +{ + bool ret = SetValue(node[GET_NAME(uri)], uri); + ret = ret && SetValue(node[GET_NAME(bundleName)], bundleName); + ret = ret && SetValue(node[GET_NAME(subscriberId)], subscriberId); + ret = ret && SetValue(node[GET_NAME(templat)], tpl); + return ret; +} + +bool TemplateRootNode::Unmarshal(const DistributedData::Serializable::json &node) +{ + bool ret = GetValue(node, GET_NAME(uri), uri); + ret = ret && GetValue(node, GET_NAME(bundleName), bundleName); + ret = ret && GetValue(node, GET_NAME(subscriberId), subscriberId); + ret = ret && GetValue(node, GET_NAME(templat), tpl); + return ret; +} + +TemplateRootNode::TemplateRootNode( + const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl) + : uri(uri), bundleName(bundleName), subscriberId(subscriberId), tpl(tpl) +{ +} + +bool TemplateData::HasVersion() const +{ + return false; +} + +std::string TemplateData::GetValue() const +{ + return DistributedData::Serializable::Marshall(value); +} + +TemplateData::TemplateData( + const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl) + :KvData(Id(GenId(uri, bundleName, subscriberId))), value(uri, bundleName, subscriberId, tpl) +{ +} + +int TemplateData::GetVersion() const +{ + return 0; +} + +std::string TemplateData::GenId(const std::string &uri, const std::string &bundleName, int64_t subscriberId) +{ + return uri + "_" + std::to_string(subscriberId) + "_" + bundleName; +} + +int32_t TemplateData::Query(const std::string &filter, Template &aTemplate) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return E_ERROR; + } + std::string queryResult; + int32_t status = delegate->Get(KvDBDelegate::TEMPLATE_TABLE, filter, "{}", queryResult); + if (status != E_OK) { + ZLOGE("db Get failed, %{public}s %{public}d", filter.c_str(), status); + return status; + } + TemplateRootNode data; + if (!DistributedData::Serializable::Unmarshall(queryResult, data)) { + ZLOGE("Unmarshall failed, %{private}s", queryResult.c_str()); + return E_ERROR; + } + aTemplate = data.ToTemplate(); + return E_OK; +} + +Template TemplateRootNode::ToTemplate() const +{ + return tpl.ToTemplate(); +} + +PredicatesNode::PredicatesNode(const std::string &key, const std::string &selectSql) : key(key), selectSql(selectSql) +{ +} +bool PredicatesNode::Marshal(DistributedData::Serializable::json &node) const +{ + bool ret = SetValue(node[GET_NAME(key)], key); + ret = ret && SetValue(node[GET_NAME(selectSql)], selectSql); + return ret; +} +bool PredicatesNode::Unmarshal(const DistributedData::Serializable::json &node) +{ + bool ret = GetValue(node, GET_NAME(key), key); + ret = ret && GetValue(node, GET_NAME(selectSql), selectSql); + return ret; +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/template_data.h b/services/distributeddataservice/service/data_share/data/template_data.h new file mode 100644 index 00000000..2de90d8f --- /dev/null +++ b/services/distributeddataservice/service/data_share/data/template_data.h @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_TEMPLATE_DATA_H +#define DATASHARESERVICE_TEMPLATE_DATA_H + +#include "datashare_template.h" +#include "db_delegate.h" +#include "serializable/serializable.h" + +namespace OHOS::DataShare { +struct PredicatesNode final: public DistributedData::Serializable { + PredicatesNode() = default; + PredicatesNode(const std::string &key, const std::string &selectSql); + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + std::string key; + std::string selectSql; +}; +struct TemplateNode final: public DistributedData::Serializable { + TemplateNode() = default; + explicit TemplateNode(const Template &tpl); + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + Template ToTemplate() const; +private: + std::vector predicates; + std::string scheduler; +}; + +struct TemplateRootNode final: public DistributedData::Serializable { + TemplateRootNode() = default; + TemplateRootNode(const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl); + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + Template ToTemplate() const; +private: + std::string uri; + std::string bundleName; + int64_t subscriberId; + TemplateNode tpl; +}; + +struct TemplateData final : public KvData { + TemplateData(const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl); + static int32_t Query(const std::string &filter, Template &aTemplate); + static std::string GenId(const std::string &uri, const std::string &bundleName, int64_t subscriberId); + bool HasVersion() const override; + int GetVersion() const override; + std::string GetValue() const override; +private: + TemplateRootNode value; +}; +} // namespace OHOS::DataShare +#endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 833de07f..6c198e7b 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -20,6 +20,7 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "bootstrap.h" +#include "common/kv_delegate.h" #include "dataobs_mgr_client.h" #include "datashare_errno.h" #include "datashare_template.h" @@ -33,6 +34,7 @@ #include "publish_strategy.h" #include "query_strategy.h" #include "subscribe_strategy.h" +#include "template_manager.h" #include "update_strategy.h" #include "utils/anonymous.h" @@ -55,6 +57,7 @@ int32_t DataShareServiceImpl::Insert(const std::string &uri, const DataShareValu auto ret = InsertStrategy::Execute(context, valuesBucket); if (ret) { NotifyChange(uri); + RdbSubscriberManager::GetInstance().Emit(uri, context); return ret; } return ret; @@ -84,6 +87,7 @@ int32_t DataShareServiceImpl::Update(const std::string &uri, const DataSharePred auto ret = UpdateStrategy::Execute(context, predicate, valuesBucket); if (ret) { NotifyChange(uri); + RdbSubscriberManager::GetInstance().Emit(uri, context); return ret; } return ret; @@ -96,6 +100,7 @@ int32_t DataShareServiceImpl::Delete(const std::string &uri, const DataSharePred auto ret = DeleteStrategy::Execute(context, predicate); if (ret) { NotifyChange(uri); + RdbSubscriberManager::GetInstance().Emit(uri, context); return ret; } return ret; @@ -117,7 +122,7 @@ int32_t DataShareServiceImpl::AddTemplate(const std::string &uri, const int64_t ZLOGE("get bundleName error, %{public}s", DistributedData::Anonymous::Change(uri).c_str()); return ERROR; } - return ERROR; + return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); } int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t subscriberId) @@ -128,7 +133,7 @@ int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t ZLOGE("get bundleName error, %{public}s", DistributedData::Anonymous::Change(uri).c_str()); return ERROR; } - return ERROR; + return TemplateManager::GetInstance().DelTemplate(uri, tpltId); } bool DataShareServiceImpl::GetCallerBundleName(std::string &bundleName) @@ -149,18 +154,48 @@ bool DataShareServiceImpl::GetCallerBundleName(std::string &bundleName) std::vector DataShareServiceImpl::Publish(const Data &data, const std::string &bundleNameOfProvider) { - return std::vector(); + std::vector results; + std::vector publishedData; + std::string callerBundleName; + GetCallerBundleName(callerBundleName); + for (const auto &item : data.datas_) { + auto context = std::make_shared(item.key_); + context->version = data.version_; + context->callerBundleName = callerBundleName; + context->calledBundleName = bundleNameOfProvider; + int32_t result = publishStrategy_.Execute(context, item); + results.emplace_back(item.key_, result); + if (result != EOK) { + ZLOGE("publish error, key is %{public}s", DistributedData::Anonymous::Change(item.key_).c_str()); + continue; + } + publishedData.emplace_back(context->uri, callerBundleName, item.subscriberId_); + } + PublishedDataSubscriberManager::GetInstance().Emit(publishedData, callerBundleName); + return results; } Data DataShareServiceImpl::GetData(const std::string &bundleNameOfProvider) { - return Data(); + std::string callerBundleName; + GetCallerBundleName(callerBundleName); + auto context = std::make_shared(); + context->callerBundleName = callerBundleName; + context->calledBundleName = bundleNameOfProvider; + return GetDataStrategy::Execute(context); } std::vector DataShareServiceImpl::SubscribeRdbData( const std::vector &uris, const TemplateId &id, const sptr observer) { - return std::vector(); + std::vector results; + for (const auto &uri : uris) { + auto context = std::make_shared(uri); + results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &observer, &context]() -> bool { + return RdbSubscriberManager::GetInstance().AddRdbSubscriber(context->uri, id, observer, context); + })); + } + return results; } std::vector DataShareServiceImpl::UnsubscribeRdbData( @@ -170,7 +205,7 @@ std::vector DataShareServiceImpl::UnsubscribeRdbData( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &context]() -> bool { - return true; + return RdbSubscriberManager::GetInstance().DelRdbSubscriber(context->uri, id, context->callerTokenId); })); } return results; @@ -183,7 +218,7 @@ std::vector DataShareServiceImpl::EnableRdbSubs( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &context]() -> bool { - return true; + return RdbSubscriberManager::GetInstance().EnableRdbSubscriber(context->uri, id, context); })); } return results; @@ -196,7 +231,7 @@ std::vector DataShareServiceImpl::DisableRdbSubs( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &context]() -> bool { - return true; + return RdbSubscriberManager::GetInstance().DisableRdbSubscriber(context->uri, id, context->callerTokenId); })); } return results; @@ -205,25 +240,94 @@ std::vector DataShareServiceImpl::DisableRdbSubs( std::vector DataShareServiceImpl::SubscribePublishedData(const std::vector &uris, const int64_t subscriberId, const sptr observer) { - return std::vector(); + std::vector results; + std::string callerBundleName; + GetCallerBundleName(callerBundleName); + std::vector publishedKeys; + int32_t result; + for (const auto &uri : uris) { + auto context = std::make_shared(uri); + PublishedDataKey key(uri, callerBundleName, subscriberId); + context->callerBundleName = callerBundleName; + context->calledBundleName = key.bundleName; + result = SubscribeStrategy::Execute( + context, [&subscriberId, &observer, &callerBundleName, &context]() -> bool { + return PublishedDataSubscriberManager::GetInstance().AddSubscriber( + context->uri, callerBundleName, subscriberId, observer, context->callerTokenId); + }); + results.emplace_back(uri, result); + if (result == E_OK) { + publishedKeys.emplace_back(key); + } + } + PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, callerBundleName, observer); + return results; } std::vector DataShareServiceImpl::UnsubscribePublishedData(const std::vector &uris, const int64_t subscriberId) { - return std::vector(); + std::vector results; + std::string callerBundleName; + GetCallerBundleName(callerBundleName); + for (const auto &uri : uris) { + auto context = std::make_shared(uri); + PublishedDataKey key(uri, callerBundleName, subscriberId); + context->callerBundleName = callerBundleName; + context->calledBundleName = key.bundleName; + results.emplace_back( + uri, SubscribeStrategy::Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + return PublishedDataSubscriberManager::GetInstance().DelSubscriber( + context->uri, callerBundleName, subscriberId, context->callerTokenId); + })); + } + return results; } std::vector DataShareServiceImpl::EnablePubSubs(const std::vector &uris, const int64_t subscriberId) { - return std::vector(); + std::vector results; + std::string callerBundleName; + GetCallerBundleName(callerBundleName); + std::vector publishedKeys; + int32_t result; + for (const auto &uri : uris) { + auto context = std::make_shared(uri); + PublishedDataKey key(uri, callerBundleName, subscriberId); + context->callerBundleName = callerBundleName; + context->calledBundleName = key.bundleName; + result = SubscribeStrategy::Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + return PublishedDataSubscriberManager::GetInstance().EnableSubscriber( + context->uri, callerBundleName, subscriberId, context->callerTokenId); + }); + results.emplace_back(uri, result); + if (result == E_OK) { + publishedKeys.emplace_back(key); + } + } + PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, callerBundleName); + return results; } std::vector DataShareServiceImpl::DisablePubSubs(const std::vector &uris, const int64_t subscriberId) { - return std::vector(); + std::vector results; + std::string callerBundleName; + GetCallerBundleName(callerBundleName); + for (const auto &uri : uris) { + auto context = std::make_shared(uri); + PublishedDataKey key(uri, callerBundleName, subscriberId); + context->callerBundleName = callerBundleName; + context->calledBundleName = key.bundleName; + results.emplace_back( + uri, SubscribeStrategy::Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + return PublishedDataSubscriberManager::GetInstance().DisableSubscriber( + context->uri, callerBundleName, subscriberId, context->callerTokenId); + })); + } + return results; } enum DataShareKvStoreType : int32_t { @@ -252,6 +356,7 @@ int32_t DataShareServiceImpl::OnInitialize() saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); + ZLOGE("hanlu init %{public}s", saveMeta.dataDir.c_str()); KvDBDelegate::GetInstance(false, saveMeta.dataDir); return EOK; } @@ -276,7 +381,8 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - KvDBDelegate::GetInstance(true, saveMeta.dataDir); + ZLOGE("hanlu init2 %{public}s", saveMeta.dataDir.c_str()); + KvDBDelegate::GetInstance(false, saveMeta.dataDir); return EOK; } } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 6cf14030..6ae6a0ae 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -18,11 +18,13 @@ #include +#include "data_proxy_observer.h" #include "data_share_service_stub.h" #include "datashare_template.h" -#include "data_proxy_observer.h" +#include "db_delegate.h" #include "uri_utils.h" #include "visibility.h" +#include "publish_strategy.h" namespace OHOS::DataShare { class API_EXPORT DataShareServiceImpl : public DataShareServiceStub { @@ -64,15 +66,11 @@ private: ~Factory(); }; - enum class PermissionType { - READ_PERMISSION = 1, - WRITE_PERMISSION - }; - bool NotifyChange(const std::string &uri); bool GetCallerBundleName(std::string &bundleName); static Factory factory_; static constexpr int32_t ERROR = -1; + PublishStrategy publishStrategy_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h index 062f2a79..9200ad9b 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h @@ -19,6 +19,8 @@ #include #include "data_proxy_observer.h" +#include "datashare_template.h" +#include "published_data.h" #include "seq_strategy.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index d658954c..db4a1c63 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -20,6 +20,7 @@ #include "general/load_config_common_strategy.h" #include "general/permission_strategy.h" #include "log_print.h" +#include "published_data.h" #include "utils/anonymous.h" namespace OHOS::DataShare { @@ -30,33 +31,44 @@ int32_t PublishStrategy::Execute(std::shared_ptr context, const Publish ZLOGE("get strategy fail, maybe memory not enough"); return -1; } + if (!(*preProcess)(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return -1; } - return 0; + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return -1; + } + PublishedData data(context->uri, context->calledBundleName, item.subscriberId_, item.GetData(), context->version); + int32_t status = delegate->Upsert(KvDBDelegate::DATA_TABLE, data); + if (status != E_OK) { + ZLOGE("db Upsert failed, %{public}s %{public}s %{public}d", context->calledBundleName.c_str(), + DistributedData::Anonymous::Change(context->uri).c_str(), status); + return -1; + } + return E_OK; } Strategy *PublishStrategy::GetStrategy() { - static std::mutex mutex; - static SeqStrategy strategies; - std::lock_guard lock(mutex); - if (!strategies.IsEmpty()) { - return &strategies; + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return &strategies_; } std::initializer_list list = { new (std::nothrow) LoadConfigCommonStrategy(), new (std::nothrow) LoadConfigFromDataProxyNodeStrategy(), new (std::nothrow) PermissionStrategy() }; - auto ret = strategies.Init(list); + auto ret = strategies_.Init(list); if (!ret) { std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); return nullptr; } - return &strategies; + return &strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.h b/services/distributeddataservice/service/data_share/strategies/publish_strategy.h index 70acdf7c..c518f722 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.h @@ -24,10 +24,12 @@ namespace OHOS::DataShare { class PublishStrategy final { public: - static int32_t Execute(std::shared_ptr context, const PublishedDataItem &item); + int32_t Execute(std::shared_ptr context, const PublishedDataItem &item); private: - static Strategy *GetStrategy(); + Strategy *GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp index 3835435c..cdad8087 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp @@ -31,6 +31,7 @@ int32_t SubscribeStrategy::Execute(std::shared_ptr context, std::functi ZLOGE("get strategy fail, maybe memory not enough"); return -1; } + context->isRead = true; if (!(*preProcess)(context)) { ZLOGE("pre process fail, uri_: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return context->errCode; -- Gitee From c894e900a386673fbac564832941a95311fe2246 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Sat, 13 May 2023 18:20:56 +0800 Subject: [PATCH 028/437] add scheduler Signed-off-by: niudongyao --- .../distributeddataservice/service/BUILD.gn | 1 + .../service/data_share/common/db_delegate.cpp | 4 +- .../service/data_share/common/db_delegate.h | 11 +- .../data_share/common/rdb_delegate.cpp | 27 ++- .../service/data_share/common/rdb_delegate.h | 14 +- .../data_share/common/scheduler_manager.cpp | 164 ++++++++++++++++++ .../data_share/common/scheduler_manager.h | 49 ++++++ .../data_share/common/template_manager.cpp | 16 +- .../data_share/data_share_service_impl.cpp | 6 +- 9 files changed, 272 insertions(+), 20 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/common/scheduler_manager.cpp create mode 100644 services/distributeddataservice/service/data_share/common/scheduler_manager.h diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 62ccc155..cd798b5c 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -77,6 +77,7 @@ ohos_shared_library("distributeddatasvc") { "data_share/common/div_strategy.cpp", "data_share/common/kv_delegate.cpp", "data_share/common/rdb_delegate.cpp", + "data_share/common/scheduler_manager.cpp", "data_share/common/seq_strategy.cpp", "data_share/common/template_manager.cpp", "data_share/common/uri_utils.cpp", diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index 7008e5fd..fb80825d 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -18,9 +18,9 @@ #include "kv_delegate.h" #include "rdb_delegate.h" namespace OHOS::DataShare { -std::shared_ptr DBDelegate::Create(const std::string &dir, int version) +std::shared_ptr DBDelegate::Create(const std::string &dir, int version, bool registerFunction) { - return std::make_shared(dir, version); + return std::make_shared(dir, version, registerFunction); } std::shared_ptr KvDBDelegate::GetInstance(bool reInit, const std::string &dir) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index 716c4f32..b28b5a58 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -18,6 +18,7 @@ #include +#include "abs_shared_result_set.h" #include "concurrent_map.h" #include "datashare_predicates.h" #include "datashare_result_set.h" @@ -28,7 +29,7 @@ namespace OHOS::DataShare { class DBDelegate { public: - static std::shared_ptr Create(const std::string &dir, int version); + static std::shared_ptr Create(const std::string &dir, int version, bool registerFunction = false); virtual int64_t Insert(const std::string &tableName, const DataShareValuesBucket &valuesBucket) = 0; virtual int64_t Update(const std::string &tableName, const DataSharePredicates &predicate, const DataShareValuesBucket &valuesBucket) = 0; @@ -37,13 +38,7 @@ public: const DataSharePredicates &predicates, const std::vector &columns, int &errCode) = 0; virtual std::shared_ptr Query( const std::string &sql, const std::vector &selectionArgs = std::vector()) = 0; - virtual int ExecuteSql(const std::string &sql) = 0; -}; - -struct RdbStoreContext { - RdbStoreContext(const std::string &dir, int version) : dir(dir), version(version) {} - std::string dir; - int version; + virtual std::unique_ptr QuerySql(const std::string &sql) = 0; }; class Id : public DistributedData::Serializable { diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index e4c9b2be..6859b3aa 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -23,10 +23,29 @@ namespace OHOS::DataShare { constexpr static int32_t MAX_RESULTSET_COUNT = 16; std::atomic RdbDelegate::resultSetCount = 0; -RdbDelegate::RdbDelegate(const std::string &dir, int version) +std::string RemindTimerFunc(const std::vector &args) +{ + int size = args.size(); + if (size != ARGS_SIZE) { + ZLOGE("RemindTimerFunc args size error, %{public}d", size); + return ""; + } + std::string dbPath = args[ARG_DB_PATH]; + int version = std::strtol(args[ARG_VERSION].c_str(), nullptr, 0); + Key key(args[ARG_URI], std::strtoll(args[ARG_SUBSCRIBER_ID].c_str(), nullptr, 0), args[ARG_BUNDLE_NAME]); + int64_t reminderTime = std::strtoll(args[ARG_TIME].c_str(), nullptr, 0); + + SchedulerManager::GetInstance().SetTimer(dbPath, version, key, reminderTime); + return args[ARG_TIME]; +} + +RdbDelegate::RdbDelegate(const std::string &dir, int version, bool registerFunction) { RdbStoreConfig config(dir); config.SetCreateNecessary(false); + if (registerFunction) { + config.SetScalarFunction("remindTimer", ARGS_SIZE, RemindTimerFunc); + } DefaultOpenCallback callback; store_ = RdbHelper::GetRdbStore(config, version, callback, errCode_); if (errCode_ != E_OK) { @@ -126,12 +145,12 @@ std::shared_ptr RdbDelegate::Query( return std::make_shared(resultSet); } -int RdbDelegate::ExecuteSql(const std::string &sql) +std::unique_ptr RdbDelegate::QuerySql(const std::string &sql) { if (store_ == nullptr) { ZLOGE("store is null"); - return -1; + return nullptr; } - return store_->ExecuteSql(sql); + return store_->QuerySql(sql); } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.h b/services/distributeddataservice/service/data_share/common/rdb_delegate.h index c30ceac8..836eb03c 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.h +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.h @@ -29,9 +29,19 @@ namespace OHOS::DataShare { using namespace OHOS::NativeRdb; +enum REMIND_TIMER_ARGS : int32_t { + ARG_DB_PATH = 0, + ARG_VERSION, + ARG_URI, + ARG_SUBSCRIBER_ID, + ARG_BUNDLE_NAME, + ARG_TIME, + ARGS_SIZE +}; + class RdbDelegate final : public DBDelegate { public: - explicit RdbDelegate(const std::string &dir, int version); + explicit RdbDelegate(const std::string &dir, int version, bool registerFunction); int64_t Insert(const std::string &tableName, const DataShareValuesBucket &valuesBucket) override; int64_t Update(const std::string &tableName, const DataSharePredicates &predicate, const DataShareValuesBucket &valuesBucket) override; @@ -40,7 +50,7 @@ public: const std::vector &columns, int &errCode) override; std::shared_ptr Query( const std::string &sql, const std::vector &selectionArgs) override; - int ExecuteSql(const std::string &sql) override; + std::unique_ptr QuerySql(const std::string &sql) override; private: static std::atomic resultSetCount; diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp new file mode 100644 index 00000000..d1f134e8 --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -0,0 +1,164 @@ +/* + * 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. + */ +#define LOG_TAG "SchedulerManager" + +#include "scheduler_manager.h" + +#include "log_print.h" +#include "uri_utils.h" +#include "utils/anonymous.h" + +namespace OHOS::DataShare { +SchedulerManager &SchedulerManager::GetInstance() +{ + static SchedulerManager instance; + return instance; +} + +void SchedulerManager::Execute(const std::string &uri, const std::string &rdbDir, int version) +{ + if (!URIUtils::IsDataProxyURI(uri)) { + return; + } + auto delegate = DBDelegate::Create(rdbDir, version, true); + if (delegate == nullptr) { + ZLOGE("malloc fail %{public}s", DistributedData::Anonymous::Change(uri).c_str()); + return; + } + std::vector keys = RdbSubscriberManager::GetInstance().GetKeysByUri(uri); + for (auto &key : keys) { + if (RdbSubscriberManager::GetInstance().GetObserverCount(key) == 0) { + continue; + } + ExecuteSchedulerSQL(rdbDir, version, key, delegate); + } +} + +void SchedulerManager::Execute(const Key &key, const std::string &rdbDir, int version) +{ + auto delegate = DBDelegate::Create(rdbDir, version, true); + if (delegate == nullptr) { + ZLOGE("malloc fail %{public}s", DistributedData::Anonymous::Change(key.uri).c_str()); + return; + } + ExecuteSchedulerSQL(rdbDir, version, key, delegate); +} + +void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Key &key, int64_t reminderTime) +{ + std::lock_guard lock(mutex_); + if (scheduler_ == nullptr) { + scheduler_ = std::make_shared(TIME_TASK_NUM, "remind_timer"); + } + auto it = timerCache_.find(key); + if (it != timerCache_.end()) { + // has current timer, reset time + ZLOGD("has current taskId, uri is %{public}s, subscriberId is %{public}" PRId64 ", bundleName is %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); + // scheduler_->Reset(it->second, std::chrono::seconds(reminderTime - time(nullptr))); + scheduler_->Reset(it->second, std::chrono::seconds(7)); + return; + } + // not find task in map, create new timer + // auto taskId = scheduler_->At(TaskScheduler::Clock::now() + std::chrono::seconds(reminderTime - time(nullptr)), + auto taskId = scheduler_->At(TaskScheduler::Clock::now() + std::chrono::seconds(7), + [key, dbPath, version, this]() { + timerCache_.erase(key); + // 1. execute schedulerSQL in next time + Execute(key, dbPath, version); + // 2. notify + RdbSubscriberManager::GetInstance().EmitByKey(key, dbPath, version); + }); + if (taskId == TaskScheduler::INVALID_TASK_ID) { + ZLOGE("create timer failed, over the max capacity"); + return; + } + ZLOGI("create new task success, uri is %{public}s, subscriberId is %{public}" PRId64 ", bundleName is %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); + timerCache_.emplace(key, taskId); +} + +void SchedulerManager::ExecuteSchedulerSQL(const std::string &rdbDir, int version, const Key &key, + std::shared_ptr delegate) +{ + Template tpl; + if (!TemplateManager::GetInstance().GetTemplate(key.uri, key.subscriberId, key.bundleName, tpl)) { + ZLOGE("template undefined, %{public}s, %{public}" PRId64 ", %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); + return; + } + if (tpl.scheduler_.empty()) { + ZLOGW("template scheduler_ empty, %{public}s, %{public}" PRId64 ", %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); + return; + } + GenRemindTimerFuncParams(rdbDir, version, key, tpl.scheduler_); + auto resultSet = delegate->QuerySql(tpl.scheduler_); + if (resultSet == nullptr) { + ZLOGE("resultSet is nullptr, %{public}s, %{public}" PRId64 ", %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); + return; + } + int count; + int errCode = resultSet->GetRowCount(count); + if (errCode != E_OK || count == 0) { + ZLOGE("GetRowCount error, %{public}s, %{public}" PRId64 ", %{public}s, errorCode is %{public}d, count is " + "%{public}d", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str(), errCode, + count); + return; + } + errCode = resultSet->GoToFirstRow(); + if (errCode != E_OK) { + ZLOGE("GoToFirstRow error, %{public}s, %{public}" PRId64 ", %{public}s, errCode is %{public}d", + DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str(), errCode); + } +} + +void SchedulerManager::GenRemindTimerFuncParams(const std::string &rdbDir, int version, const Key &key, + std::string &schedulerSQL) +{ + auto index = schedulerSQL.find(REMIND_TIMER_FUNC); + if (index == -1) { + ZLOGW("not find remindTimer, sql is %{public}s", schedulerSQL.c_str()); + return; + } + index += REMIND_TIMER_FUNC_LEN; + std::string keyStr = "'" + rdbDir + "', " + std::to_string(version) + ", '" + key.uri + "', " + + std::to_string(key.subscriberId) + ", '" + key.bundleName + "', "; + schedulerSQL.insert(index, keyStr); + return; +} + +void SchedulerManager::RemoveTimer(const Key &key) +{ + std::lock_guard lock(mutex_); + if (scheduler_ == nullptr) { + ZLOGD("scheduler_ is nullptr"); + return; + } + auto it = timerCache_.find(key); + if (it != timerCache_.end()) { + ZLOGD("RemoveTimer %{public}s %{public}s %{public}" PRId64, + DistributedData::Anonymous::Change(key.uri).c_str(), key.bundleName.c_str(), key.subscriberId); + scheduler_->Remove(it->second); + timerCache_.erase(key); + if (timerCache_.empty()) { + scheduler_ = nullptr; + } + } +} +} // namespace OHOS::DataShare + diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.h b/services/distributeddataservice/service/data_share/common/scheduler_manager.h new file mode 100644 index 00000000..546d77be --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef SCHEDULER_MANAGER_H +#define SCHEDULER_MANAGER_H + +#include + +#include "db_delegate.h" +#include "task_scheduler.h" +#include "template_manager.h" + +namespace OHOS::DataShare { +class SchedulerManager { +public: + static SchedulerManager &GetInstance(); + void Execute(const std::string &uri, const std::string &rdbDir, int version); + void Execute(const Key &key, const std::string &rdbDir, int version); + void SetTimer(const std::string &dbPath, int version, const Key &key, int64_t reminderTime); + void RemoveTimer(const Key &key); + +private: + static constexpr const char *REMIND_TIMER_FUNC = "remindTimer("; + static constexpr int REMIND_TIMER_FUNC_LEN = 12; + static constexpr size_t TIME_TASK_NUM = 10; + SchedulerManager() = default; + ~SchedulerManager() = default; + void GenRemindTimerFuncParams(const std::string &rdbDir, int version, const Key &key, std::string &schedulerSQL); + void ExecuteSchedulerSQL(const std::string &rdbDir, int version, const Key &key, + std::shared_ptr delegate); + + std::mutex mutex_; + std::map timerCache_; + std::shared_ptr scheduler_ = nullptr; +}; +} // namespace OHOS::DataShare +#endif // SCHEDULER_MANAGER_H diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 9a22d067..9833fe2f 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -23,6 +23,7 @@ #include "template_data.h" #include "uri_utils.h" #include "utils/anonymous.h" +#include "scheduler_manager.h" namespace OHOS::DataShare { bool TemplateManager::GetTemplate( @@ -60,6 +61,7 @@ bool TemplateManager::DelTemplate(const std::string &uri, const TemplateId &tplI ZLOGE("db DeleteById failed, %{public}d", status); return false; } + SchedulerManager::GetInstance().RemoveTimer(Key(uri, tplId.subscriberId_, tplId.bundleName_)); return true; } @@ -134,6 +136,9 @@ int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const Templat return false; } value.emplace_back(observer, context->callerTokenId); + if (GetEnableObserverCount(key) == 1) { + SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); + } return true; }); return result; @@ -154,6 +159,9 @@ int RdbSubscriberManager::DelRdbSubscriber( it++; } } + if (GetEnableObserverCount(key) == 0) { + SchedulerManager::GetInstance().RemoveTimer(key); + } return !value.empty(); }); return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; @@ -170,6 +178,9 @@ int RdbSubscriberManager::DisableRdbSubscriber( it->enabled = false; } } + if (GetEnableObserverCount(key) == 0) { + SchedulerManager::GetInstance().RemoveTimer(key); + } return true; }); return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; @@ -187,6 +198,9 @@ int RdbSubscriberManager::EnableRdbSubscriber( node.emplace_back(it->observer, context->callerTokenId); Notify(key, node, context->calledSourceDir, context->version); } + if (GetEnableObserverCount(key) == 1) { + SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); + } } return true; }); @@ -264,7 +278,7 @@ int RdbSubscriberManager::Notify( DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); return E_TEMPLATE_NOT_EXIST; } - auto delegate = DBDelegate::Create(rdbDir, rdbVersion); + auto delegate = DBDelegate::Create(rdbDir, rdbVersion, true); if (delegate == nullptr) { ZLOGE("Create fail %{public}s %{public}s", DistributedData::Anonymous::Change(key.uri).c_str(), key.bundleName.c_str()); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 6c198e7b..d277f2e4 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -58,7 +58,7 @@ int32_t DataShareServiceImpl::Insert(const std::string &uri, const DataShareValu if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - return ret; + SchedulerManager::GetInstance().Execute(uri, context->calledSourceDir, context->version); } return ret; } @@ -88,7 +88,7 @@ int32_t DataShareServiceImpl::Update(const std::string &uri, const DataSharePred if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - return ret; + SchedulerManager::GetInstance().Execute(uri, context->calledSourceDir, context->version); } return ret; } @@ -101,7 +101,7 @@ int32_t DataShareServiceImpl::Delete(const std::string &uri, const DataSharePred if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - return ret; + SchedulerManager::GetInstance().Execute(uri, context->calledSourceDir, context->version); } return ret; } -- Gitee From 94d6509080da1c104bc4fad93560544877faeefa Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 13 May 2023 18:31:58 +0800 Subject: [PATCH 029/437] fix:change to static Signed-off-by: htt1997 --- .../app/src/uninstaller/uninstaller_impl.cpp | 4 ++-- .../app/src/uninstaller/uninstaller_impl.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index 12aa99db..80f0686a 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -91,12 +91,12 @@ Status UninstallerImpl::Init(KvStoreDataService *kvStoreDataService, std::shared CommonEventSubscribeInfo info(matchingSkills); auto subscriber = std::make_shared(info); - auto removedCallback = [this, kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { + auto removedCallback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { kvStoreDataService->OnUninstall(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); OnUninstall(bundleName, userId, appIndex); }; - auto updatedCallback = [this, kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { + auto updatedCallback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { kvStoreDataService->OnUpdate(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); OnUpdate(bundleName, userId, appIndex); }; diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index 9607f58b..4de54f49 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -47,8 +47,8 @@ public: private: static constexpr int32_t RETRY_TIME = 300; static constexpr int32_t RETRY_INTERVAL = 100; - void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); - void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex); + static void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); + static void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex); int32_t retryTime_; ExecutorPool::Task GetTask(); std::shared_ptr subscriber_ {}; -- Gitee From a649fe849b63c1a3bad70febac80abf946b06a7a Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 13 May 2023 18:46:18 +0800 Subject: [PATCH 030/437] f Signed-off-by: hanlu --- services/distributeddataservice/service/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 62ccc155..9254d279 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -144,10 +144,10 @@ ohos_shared_library("distributeddatasvc") { deps = [ "${kv_store_distributeddb_path}:distributeddb", "${relational_store_path}/interfaces/inner_api/cloud_data:cloud_data_inner", + "data_share/gaussdb_rd:gaussdb_rd", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", - "data_share/gaussdb_rd:gaussdb_rd", ] external_deps = [ -- Gitee From 2db5e5056ea10561179eb61019d63f7ab0ac692f Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 13 May 2023 18:47:45 +0800 Subject: [PATCH 031/437] f Signed-off-by: hanlu --- .../service/data_share/common/scheduler_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index d1f134e8..52501eee 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -67,8 +67,7 @@ void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Ke // has current timer, reset time ZLOGD("has current taskId, uri is %{public}s, subscriberId is %{public}" PRId64 ", bundleName is %{public}s", DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); - // scheduler_->Reset(it->second, std::chrono::seconds(reminderTime - time(nullptr))); - scheduler_->Reset(it->second, std::chrono::seconds(7)); + scheduler_->Reset(it->second, std::chrono::seconds(reminderTime - time(nullptr))); return; } // not find task in map, create new timer -- Gitee From e58a88da9fd89d93a16b04ab655b94349889209a Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 13 May 2023 19:12:12 +0800 Subject: [PATCH 032/437] f Signed-off-by: hanlu --- .../include/serializable/serializable.h | 15 +++++-- .../service/data_share/common/db_delegate.h | 2 +- .../data_share/common/rdb_delegate.cpp | 45 +++++++++++-------- .../service/data_share/common/rdb_delegate.h | 13 +----- .../data_share/common/template_manager.cpp | 4 +- .../data_share/data/json_formatter.cpp | 12 +---- .../service/data_share/data/json_formatter.h | 4 +- .../data_share/data_share_service_impl.cpp | 3 +- 8 files changed, 47 insertions(+), 51 deletions(-) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 47d1805e..3dda5678 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -195,20 +195,27 @@ bool Serializable::SetValue(json &node, const T *value) template bool Serializable::SetValue(json &node, const std::variant<_Types...> &input) { - node[GET_NAME(type)] = input.index(); - return WriteVariant(node, 0, input); + bool ret = SetValue(node[GET_NAME(type)], input.index()); + if (!ret) { + return ret; + } + return WriteVariant(node[GET_NAME(value)], 0, input); } template bool Serializable::GetValue(const json &node, const std::string &name, std::variant<_Types...> &value) { + auto &subNode = GetSubNode(node, name); + if (subNode.is_null()) { + return false; + } uint32_t index; - bool ret = GetValue(node, GET_NAME(type), index); + bool ret = GetValue(subNode, GET_NAME(type), index); if (!ret) { return ret; } - return Serializable::ReadVariant(node, name, 0, index, value); + return Serializable::ReadVariant(subNode, GET_NAME(value), 0, index, value); } template diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index b28b5a58..d8b9df90 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -36,7 +36,7 @@ public: virtual int64_t Delete(const std::string &tableName, const DataSharePredicates &predicate) = 0; virtual std::shared_ptr Query(const std::string &tableName, const DataSharePredicates &predicates, const std::vector &columns, int &errCode) = 0; - virtual std::shared_ptr Query( + virtual std::string Query( const std::string &sql, const std::vector &selectionArgs = std::vector()) = 0; virtual std::unique_ptr QuerySql(const std::string &sql) = 0; }; diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 6859b3aa..0e8a5b95 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -18,25 +18,36 @@ #include "data/resultset_json_formatter.h" #include "log_print.h" #include "rdb_utils.h" +#include "scheduler_manager.h" #include "utils/anonymous.h" namespace OHOS::DataShare { constexpr static int32_t MAX_RESULTSET_COUNT = 16; std::atomic RdbDelegate::resultSetCount = 0; +enum REMIND_TIMER_ARGS : int32_t +{ + ARG_DB_PATH = 0, + ARG_VERSION, + ARG_URI, + ARG_SUBSCRIBER_ID, + ARG_BUNDLE_NAME, + ARG_TIME, + ARGS_SIZE +}; std::string RemindTimerFunc(const std::vector &args) { - int size = args.size(); - if (size != ARGS_SIZE) { - ZLOGE("RemindTimerFunc args size error, %{public}d", size); - return ""; - } - std::string dbPath = args[ARG_DB_PATH]; - int version = std::strtol(args[ARG_VERSION].c_str(), nullptr, 0); - Key key(args[ARG_URI], std::strtoll(args[ARG_SUBSCRIBER_ID].c_str(), nullptr, 0), args[ARG_BUNDLE_NAME]); - int64_t reminderTime = std::strtoll(args[ARG_TIME].c_str(), nullptr, 0); + int size = args.size(); + if (size != ARGS_SIZE) { + ZLOGE("RemindTimerFunc args size error, %{public}d", size); + return ""; + } + std::string dbPath = args[ARG_DB_PATH]; + int version = std::strtol(args[ARG_VERSION].c_str(), nullptr, 0); + Key key(args[ARG_URI], std::strtoll(args[ARG_SUBSCRIBER_ID].c_str(), nullptr, 0), args[ARG_BUNDLE_NAME]); + int64_t reminderTime = std::strtoll(args[ARG_TIME].c_str(), nullptr, 0); - SchedulerManager::GetInstance().SetTimer(dbPath, version, key, reminderTime); - return args[ARG_TIME]; + SchedulerManager::GetInstance().SetTimer(dbPath, version, key, reminderTime); + return args[ARG_TIME]; } RdbDelegate::RdbDelegate(const std::string &dir, int version, bool registerFunction) @@ -98,9 +109,8 @@ int64_t RdbDelegate::Delete(const std::string &tableName, const DataSharePredica } return changeCount; } -std::shared_ptr RdbDelegate::Query( - const std::string &tableName, const DataSharePredicates &predicates, - const std::vector &columns, int &errCode) +std::shared_ptr RdbDelegate::Query(const std::string &tableName, + const DataSharePredicates &predicates, const std::vector &columns, int &errCode) { if (store_ == nullptr) { ZLOGE("store is null"); @@ -129,8 +139,7 @@ std::shared_ptr RdbDelegate::Query( }); } -std::shared_ptr RdbDelegate::Query( - const std::string &sql, const std::vector &selectionArgs) +std::string RdbDelegate::Query(const std::string &sql, const std::vector &selectionArgs) { if (store_ == nullptr) { ZLOGE("store is null"); @@ -141,8 +150,8 @@ std::shared_ptr RdbDelegate::Query( ZLOGE("Query failed %{private}s", sql.c_str()); return nullptr; } - - return std::make_shared(resultSet); + ResultSetJsonFormatter formatter(resultSet); + return DistributedData::Serializable::Marshall(formatter); } std::unique_ptr RdbDelegate::QuerySql(const std::string &sql) diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.h b/services/distributeddataservice/service/data_share/common/rdb_delegate.h index 836eb03c..2a68d15b 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.h +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.h @@ -29,16 +29,6 @@ namespace OHOS::DataShare { using namespace OHOS::NativeRdb; -enum REMIND_TIMER_ARGS : int32_t { - ARG_DB_PATH = 0, - ARG_VERSION, - ARG_URI, - ARG_SUBSCRIBER_ID, - ARG_BUNDLE_NAME, - ARG_TIME, - ARGS_SIZE -}; - class RdbDelegate final : public DBDelegate { public: explicit RdbDelegate(const std::string &dir, int version, bool registerFunction); @@ -48,8 +38,7 @@ public: int64_t Delete(const std::string &tableName, const DataSharePredicates &predicate) override; std::shared_ptr Query(const std::string &tableName, const DataSharePredicates &predicates, const std::vector &columns, int &errCode) override; - std::shared_ptr Query( - const std::string &sql, const std::vector &selectionArgs) override; + std::string Query(const std::string &sql, const std::vector &selectionArgs) override; std::unique_ptr QuerySql(const std::string &sql) override; private: diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 9833fe2f..e876a77e 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -20,10 +20,10 @@ #include "json_formatter.h" #include "log_print.h" #include "published_data.h" +#include "scheduler_manager.h" #include "template_data.h" #include "uri_utils.h" #include "utils/anonymous.h" -#include "scheduler_manager.h" namespace OHOS::DataShare { bool TemplateManager::GetTemplate( @@ -199,7 +199,7 @@ int RdbSubscriberManager::EnableRdbSubscriber( Notify(key, node, context->calledSourceDir, context->version); } if (GetEnableObserverCount(key) == 1) { - SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); + SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); } } return true; diff --git a/services/distributeddataservice/service/data_share/data/json_formatter.cpp b/services/distributeddataservice/service/data_share/data/json_formatter.cpp index db190824..b3c38832 100644 --- a/services/distributeddataservice/service/data_share/data/json_formatter.cpp +++ b/services/distributeddataservice/service/data_share/data/json_formatter.cpp @@ -20,19 +20,11 @@ namespace OHOS::DataShare { bool JsonFormatter::Marshal(json &node) const { - if (value_ == nullptr) { - ZLOGE("null value %{public}s", key_.c_str()); - return false; - } - return SetValue(node[key_], *value_); + return SetValue(node[key_], value_); } bool JsonFormatter::Unmarshal(const json &node) { - if (value_ == nullptr) { - ZLOGE("null value %{public}s", key_.c_str()); - return false; - } - return GetValue(node, key_, *value_); + return GetValue(node, key_, value_); } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/json_formatter.h b/services/distributeddataservice/service/data_share/data/json_formatter.h index 7c41e197..0b718493 100644 --- a/services/distributeddataservice/service/data_share/data/json_formatter.h +++ b/services/distributeddataservice/service/data_share/data/json_formatter.h @@ -21,7 +21,7 @@ namespace OHOS::DataShare { class JsonFormatter : public DistributedData::Serializable { public: - JsonFormatter(const std::string &key, const std::shared_ptr &value) + JsonFormatter(const std::string &key, const std::string &value) : key_(key), value_(value) { } @@ -30,7 +30,7 @@ public: private: std::string key_; - std::shared_ptr value_; + std::string value_; }; } // namespace OHOS::DataShare #endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index d277f2e4..14b957db 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -20,7 +20,6 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "bootstrap.h" -#include "common/kv_delegate.h" #include "dataobs_mgr_client.h" #include "datashare_errno.h" #include "datashare_template.h" @@ -31,8 +30,8 @@ #include "insert_strategy.h" #include "ipc_skeleton.h" #include "log_print.h" -#include "publish_strategy.h" #include "query_strategy.h" +#include "scheduler_manager.h" #include "subscribe_strategy.h" #include "template_manager.h" #include "update_strategy.h" -- Gitee From 1aa7433994ccf49d8d24bb77802404456cded8ab Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sat, 13 May 2023 20:38:03 +0800 Subject: [PATCH 033/437] on cloud datachange Signed-off-by: zuojiangjiang --- .../framework/cloud/cloud_info.cpp | 2 +- .../framework/include/cloud/cloud_event.h | 3 +- .../distributeddataservice/service/BUILD.gn | 2 + .../service/cloud/cloud_service_impl.cpp | 132 +++++++++++++----- .../service/cloud/cloud_service_impl.h | 6 +- .../service/rdb/rdb_general_store.cpp | 64 ++++++++- .../service/rdb/rdb_general_store.h | 2 + .../service/rdb/rdb_query.cpp | 23 +++ .../service/rdb/rdb_query.h | 34 +++++ .../service/rdb/rdb_service_impl.cpp | 97 ++++++++++++- .../service/rdb/rdb_service_stub.cpp | 5 +- .../service/rdb/rdb_syncer.h | 3 +- .../service/rdb/rdb_watcher.cpp | 43 ++++++ .../service/rdb/rdb_watcher.h | 37 +++++ 14 files changed, 401 insertions(+), 52 deletions(-) create mode 100644 services/distributeddataservice/service/rdb/rdb_query.cpp create mode 100644 services/distributeddataservice/service/rdb/rdb_query.h create mode 100644 services/distributeddataservice/service/rdb/rdb_watcher.cpp create mode 100644 services/distributeddataservice/service/rdb/rdb_watcher.h diff --git a/services/distributeddataservice/framework/cloud/cloud_info.cpp b/services/distributeddataservice/framework/cloud/cloud_info.cpp index 2f44ff85..a50f4d69 100644 --- a/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -61,7 +61,7 @@ bool CloudInfo::AppInfo::Unmarshal(const Serializable::json &node) std::string CloudInfo::GetKey() const { - return GetKey(INFO_PREFIX, { std::to_string(user), id }); + return GetKey(INFO_PREFIX, { std::to_string(user) }); } std::map CloudInfo::GetSchemaKey() const diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h index e6cff13a..47c873c9 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -25,7 +25,7 @@ public: enum : int32_t { FEATURE_INIT = EVT_CLOUD, GET_SCHEMA, - NEED_CREATE, + DATA_CHANGE, CLOUD_BUTT }; @@ -34,6 +34,7 @@ public: std::string bundleName; std::string storeName; int32_t instanceId = 0; + int32_t user = 0; }; CloudEvent(int32_t evtId, StoreInfo storeInfo, const std::string &featureName = "relational_store"); diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 1d29c1ef..46cae1d6 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -123,12 +123,14 @@ ohos_shared_library("distributeddatasvc") { "permission/src/permit_delegate.cpp", "rdb/rdb_general_store.cpp", "rdb/rdb_notifier_proxy.cpp", + "rdb/rdb_query.cpp", "rdb/rdb_result_set_impl.cpp", "rdb/rdb_result_set_stub.cpp", "rdb/rdb_service_impl.cpp", "rdb/rdb_service_stub.cpp", "rdb/rdb_store_observer_impl.cpp", "rdb/rdb_syncer.cpp", + "rdb/rdb_watcher.cpp", ] cflags = [ "-Wno-multichar" ] diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index e9e932fc..5a131f5c 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -37,23 +37,22 @@ using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; CloudServiceImpl::Factory::Factory() noexcept { - FeatureSystem::GetInstance().RegisterCreator(CloudServiceImpl::SERVICE_NAME, [this]() { - if (product_ == nullptr) { - product_ = std::make_shared(); - } - return product_; - }); + FeatureSystem::GetInstance().RegisterCreator( + CloudServiceImpl::SERVICE_NAME, + [this]() { + if (product_ == nullptr) { + product_ = std::make_shared(); + } + return product_; + }, + FeatureSystem::BIND_NOW); } CloudServiceImpl::Factory::~Factory() {} CloudServiceImpl::CloudServiceImpl() { - EventCenter::GetInstance().Subscribe(CloudEvent::FEATURE_INIT, [this](const Event &event) { - FeatureInit(event); - return; - }); - + FeatureInit(); EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { GetSchema(event); return; @@ -63,8 +62,9 @@ CloudServiceImpl::CloudServiceImpl() int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) { CloudInfo cloudInfo; - if (GetCloudInfo(IPCSkeleton::GetCallingTokenID(), id, cloudInfo) != SUCCESS) { - return INVALID_ARGUMENT; + auto status = GetCloudInfo(IPCSkeleton::GetCallingTokenID(), id, cloudInfo); + if (status != SUCCESS) { + return status; } cloudInfo.enableCloud = true; for (const auto &item : switches) { @@ -86,8 +86,9 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map bool { @@ -120,8 +122,10 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri int32_t CloudServiceImpl::Clean(const std::string &id, const std::map &actions) { CloudInfo cloudInfo; - if (GetCloudInfo(IPCSkeleton::GetCallingTokenID(), id, cloudInfo) != SUCCESS) { - return INVALID_ARGUMENT; + auto tokenId = IPCSkeleton::GetCallingTokenID(); + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); + if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS) { + return ERROR; } auto keys = cloudInfo.GetSchemaKey(); for (const auto &action : actions) { @@ -138,16 +142,60 @@ int32_t CloudServiceImpl::Clean(const std::string &id, const std::mapGetUserByToken(tokenId); + if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS) { + return ERROR; + } + if (cloudInfo.id != id) { + ZLOGE("invalid args, [input] id:%{public}s, [exist] id:%{public}s", Anonymous::Change(id).c_str(), + Anonymous::Change(cloudInfo.id).c_str()); + return INVALID_ARGUMENT; + } + if (!cloudInfo.enableCloud) { + return CLOUD_DISABLE; + } + auto it = std::find_if(cloudInfo.apps.begin(), cloudInfo.apps.end(), + [&bundleName](const CloudInfo::AppInfo &appInfo) -> bool { + return appInfo.bundleName == bundleName; + }); + if (it == cloudInfo.apps.end()) { + ZLOGE("bundleName:%{public}s", bundleName.c_str()); + return INVALID_ARGUMENT; + } + if (!it->cloudSwitch) { + return CLOUD_DISABLE_SWITCH; + } + + auto key = cloudInfo.GetSchemaKey(bundleName); + SchemaMeta schemaMeta; + if (!MetaDataManager::GetInstance().LoadMeta(key, schemaMeta, true)) { + ZLOGE("bundleName:%{public}s", bundleName.c_str()); + return INVALID_ARGUMENT; + } + for (const auto &database : schemaMeta.databases) { + EventCenter::Defer defer; + CloudEvent::StoreInfo storeInfo; + storeInfo.bundleName = it->bundleName; + storeInfo.instanceId = it->instanceId; + storeInfo.user = cloudInfo.user; + storeInfo.storeName = database.name; + auto evt = std::make_unique(CloudEvent::DATA_CHANGE, storeInfo); + EventCenter::GetInstance().PostEvent(std::move(evt)); + } + return SUCCESS; } int32_t CloudServiceImpl::GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo) { cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); - if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true) && - GetServerInfo(cloudInfo) != SUCCESS) { - ZLOGE("invalid args, user:%{public}d", cloudInfo.user); - return INVALID_ARGUMENT; + if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS) { + auto status = GetCloudInfoFromServer(cloudInfo); + if (status != SUCCESS) { + ZLOGE("user:%{public}d", cloudInfo.user); + return status; + } } if (cloudInfo.id != id) { ZLOGE("invalid args, [input] id:%{public}s, [exist] id:%{public}s", Anonymous::Change(id).c_str(), @@ -157,16 +205,23 @@ int32_t CloudServiceImpl::GetCloudInfo(uint32_t tokenId, const std::string &id, return SUCCESS; } -int32_t CloudServiceImpl::GetServerInfo(CloudInfo &cloudInfo) +int32_t CloudServiceImpl::GetCloudInfoFromMeta(CloudInfo &cloudInfo) +{ + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); + if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { + ZLOGE("no exist meta, user:%{public}d", cloudInfo.user); + return ERROR; + } + return SUCCESS; +} + +int32_t CloudServiceImpl::GetCloudInfoFromServer(CloudInfo &cloudInfo) { auto instance = CloudServer::GetInstance(); if (instance == nullptr) { - return SERVER_UNAVAILABLE; + return NOT_SUPPORT; } cloudInfo = instance->GetServerInfo(cloudInfo.user); - if (!cloudInfo.IsValid()) { - return ERROR; - } return SUCCESS; } @@ -243,20 +298,25 @@ StoreMetaData CloudServiceImpl::GetStoreMata(int32_t userId, const std::string & return storeMetaData; } -void CloudServiceImpl::FeatureInit(const Event &event) +void CloudServiceImpl::FeatureInit() { CloudInfo cloudInfo; std::vector users; if (!DistributedKv::AccountDelegate::GetInstance()->QueryUsers(users) || users.empty()) { return; } - cloudInfo.user = *users.begin(); - if (GetServerInfo(cloudInfo) != SUCCESS) { - ZLOGE("failed, user:%{public}d", cloudInfo.user); - return; + for (const auot &user : users) { + if (user == USER_ID) { + continue; + } + cloudInfo.user = user; + if (GetCloudInfoFromServer(cloudInfo) != SUCCESS) { + ZLOGE("failed, user:%{public}d", user); + continue; + } + UpdateCloudInfo(cloudInfo); + AddSchema(cloudInfo); } - UpdateCloudInfo(cloudInfo); - AddSchema(cloudInfo); } void CloudServiceImpl::GetSchema(const Event &event) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 26ed17e7..8b79e73b 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -35,6 +35,7 @@ public: int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; private: + static const inline int USER_ID = 0; class Factory { public: Factory() noexcept; @@ -54,9 +55,10 @@ private: StoreMetaData GetStoreMata(int32_t userId, const std::string &bundleName, const std::string &storeName, int32_t instanceId); int32_t GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo); - int32_t GetServerInfo(CloudInfo &cloudInfo); + int32_t GetCloudInfoFromMeta(CloudInfo &cloudInfo); + int32_t GetCloudInfoFromServer(CloudInfo &cloudInfo); int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); - void FeatureInit(const Event &event); + void FeatureInit(); void GetSchema(const Event &event); }; } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index e57cc2ea..496878bc 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -20,12 +20,53 @@ #include "metadata/meta_data_manager.h" #include "metadata/secret_key_meta_data.h" #include "rdb_helper.h" +#include "rdb_query.h" +#include "rdb_syncer.h" #include "relational_store_manager.h" +#include "store/general_watcher.h" namespace OHOS::DistributedRdb { using namespace DistributedData; +using namespace DistributedDB; using namespace OHOS::NativeRdb; +class RdbOpenCallbackImpl : public RdbOpenCallback { +public: + int OnCreate(RdbStore &rdbStore) override + { + return NativeRdb::E_OK; + } + int OnUpgrade(RdbStore &rdbStore, int oldVersion, int newVersion) override + { + return NativeRdb::E_OK; + } +}; + RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appId, meta.user, meta.instanceId) { + RelationalStoreDelegate::Option option; + if (meta.isEncrypt) { + std::string key = meta.GetSecretKey(); + SecretKeyMetaData secretKeyMeta; + MetaDataManager::GetInstance().LoadMeta(key, secretKeyMeta, true); + std::vector decryptKey; + CryptoManager::GetInstance().Decrypt(secretKeyMeta.sKey, decryptKey); + if (option.passwd.SetValue(decryptKey.data(), decryptKey.size()) != CipherPassword::OK) { + std::fill(decryptKey.begin(), decryptKey.end(), 0); + } + std::fill(decryptKey.begin(), decryptKey.end(), 0); + option.isEncryptedDb = meta.isEncrypt; + option.iterateTimes = ITERATE_TIMES; + option.cipher = CipherType::AES_256_GCM; + } + option.observer = nullptr; + manager_.OpenStore(meta.dataDir, meta.storeId, option, delegate_); + RdbStoreConfig config(meta.dataDir); + config.SetCreateNecessary(false); + RdbOpenCallbackImpl callback; + int32_t errCode = NativeRdb::E_OK; + store_ = RdbHelper::GetRdbStore(config, meta.version, callback, errCode); + if (errCode != NativeRdb::E_OK) { + ZLOGE("GetRdbStore failed, errCode is %{public}d, storeId is %{public}s", errCode, meta.storeId.c_str()); + } } int32_t RdbGeneralStore::Close() @@ -65,7 +106,8 @@ std::shared_ptr RdbGeneralStore::Query(const std::string &table, GenQuer int32_t RdbGeneralStore::Watch(int32_t origin, Watcher &watcher) { - return 0; + watcher_ = &watcher; + return GeneralError::E_NOT_SUPPORT; } int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) @@ -75,7 +117,25 @@ int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) { - return 0; + RdbQuery *rdbQuery = nullptr; + auto ret = query.QueryInterface(rdbQuery); + if (ret != GeneralError::E_OK || rdbQuery == nullptr) { + return GeneralError::E_OK; + } + auto status = delegate_->Sync( + devices, DistributedDB::SyncMode(mode), RdbSyncer::MakeQuery(rdbQuery->predicates_.GetDistributedPredicates()), + [async](const std::map> &result) { + std::map> detail; + for (auto &[key, tables] : result) { + auto value = detail[key]; + for (auto &table : tables) { + value[std::move(table.tableName)] = table.status; + } + } + async(std::move(detail)); + }, + wait); + return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } int32_t RdbGeneralStore::Bind(std::shared_ptr cloudDb) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index af8ca7d9..f1bd92cd 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -56,8 +56,10 @@ private: static constexpr uint32_t ITERATE_TIMES = 10000; RdbManager manager_; + RdbDelegate *delegate_ = nullptr; std::shared_ptr store_; std::shared_ptr cloudDb_; + Watcher *watcher_; }; } // namespace OHOS::DistributedRdb #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H diff --git a/services/distributeddataservice/service/rdb/rdb_query.cpp b/services/distributeddataservice/service/rdb/rdb_query.cpp new file mode 100644 index 00000000..fc990eb1 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_query.cpp @@ -0,0 +1,23 @@ +/* + * 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 "rdb_query.h" +namespace OHOS::DistributedRdb { +using namespace DistributedData; +bool RdbQuery::IsEqual(uint64_t tid) +{ + return tid == TYPE_ID; +} +} // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_query.h b/services/distributeddataservice/service/rdb/rdb_query.h new file mode 100644 index 00000000..fdeed511 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_query.h @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H +#include "rdb_predicates.h" +#include "store/general_value.h" +namespace OHOS::DistributedRdb { +class RdbQuery : public DistributedData::GenQuery { +public: + using Predicates = NativeRdb::RdbPredicates; + static constexpr uint64_t TYPE_ID = 0; + RdbQuery() = default; + + ~RdbQuery() override = default; + + bool IsEqual(uint64_t tid) override; + + NativeRdb::RdbPredicates predicates_ {""}; +}; +} // namespace OHOS::DistributedRdb +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 1938c504..1250c43f 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -27,8 +27,9 @@ #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "permission/permission_validator.h" +#include "rdb_watcher.h" #include "rdb_notifier_proxy.h" -#include "store/auto_cache.h" +#include "rdb_query.h" #include "types_export.h" #include "utils/anonymous.h" #include "utils/constant.h" @@ -88,6 +89,31 @@ RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) [this](const std::string& identifier, DistributedDB::AutoLaunchParam ¶m) { return ResolveAutoLaunch(identifier, param); }); + EventCenter::GetInstance().Subscribe(CloudEvent::DATA_CHANGE, [this](const Event &event) { + auto &evt = static_cast(event); + auto storeInfo = evt.GetStoreInfo(); + StoreMetaData meta; + meta.storeId = storeInfo.storeName; + meta.bundleName = storeInfo.bundleName; + meta.user = std::to_string(storeInfo.user); + meta.instanceId = storeInfo.instanceId; + meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + ZLOGE("meta key:%{public}s", meta.GetKey().c_str()); + if (!MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)) { + ZLOGE("meta empty, bundleName:%{public}s, storeId:%{public}s", + meta.bundleName.c_str(), meta.storeId.c_str()); + return; + } + auto watchers = GetWatchers(meta.tokenId, meta.storeId); + auto store = AutoCache::GetInstance().GetStore(meta, watchers); + if (store == nullptr) { + ZLOGE("store null, storeId:%{public}s", meta.storeId.c_str()); + return; + } + for (const auto &watcher : watchers) { // mock for datachange + watcher->OnChange(GeneralWatcher::Origin::ORIGIN_CLOUD, {}); + } + }); } int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) @@ -376,15 +402,74 @@ std::string RdbServiceImpl::GenIdentifier(const RdbSyncerParam ¶m) return TransferStringToHex(identifier); } -int32_t RdbServiceImpl::DoSubscribe(const RdbSyncerParam& param) +int32_t RdbServiceImpl::DoSubscribe(const RdbSyncerParam& param, const SubscribeOption &option) { pid_t pid = IPCSkeleton::GetCallingPid(); - auto identifier = GenIdentifier(param); - ZLOGI("%{public}s %{public}.6s %{public}d", param.storeName_.c_str(), identifier.c_str(), pid); - identifiers_.Insert(identifier, pid); + auto tokenId = IPCSkeleton::GetCallingTokenID(); + switch (option.mode) { + case SubscribeMode::REMOTE: { + auto identifier = GenIdentifier(param); + ZLOGI("%{public}s %{public}.6s %{public}d", param.storeName_.c_str(), identifier.c_str(), pid); + identifiers_.Insert(identifier, pid); + break; + } + case SubscribeMode::CLOUD: // fallthrough + case SubscribeMode::CLOUD_DETAIL: { + syncAgents_.Compute(tokenId, [this, pid, tokenId, ¶m, &option](auto &key, SyncAgent &value) { + if (pid != value.pid_) { + value.ReInit(pid, param.bundleName_); + } + auto storeName = RdbSyncer::RemoveSuffix(param.storeName_); + auto it = value.watchers_.find(storeName); + if (it == value.watchers_.end()) { + auto watcher = std::make_shared(this, tokenId, storeName); + value.watchers_[storeName] = { watcher }; + value.mode_[storeName] = option.mode; + } + return true; + }); + break; + } + default: + return RDB_ERROR; + } return RDB_OK; } +void RdbServiceImpl::OnChange(uint32_t tokenId, const std::string &storeName) +{ + pid_t pid = 0; + syncAgents_.ComputeIfPresent(tokenId, [&pid, &storeName](auto &key, SyncAgent &value) { + pid = value.pid_; + return true; + }); + notifiers_.ComputeIfPresent(pid, [&storeName](const auto& key, const sptr& value) { + value->OnChange(storeName, { storeName }); + return true; + }); +} + +AutoCache::Watchers RdbServiceImpl::GetWatchers(uint32_t tokenId, const std::string &storeName) +{ + AutoCache::Watchers watchers; + syncAgents_.ComputeIfPresent(tokenId, [&storeName, &watchers](auto, SyncAgent &agent) { + auto it = agent.watchers_.find(storeName); + if (it != agent.watchers_.end()) { + watchers = it->second; + } + return true; + }); + return watchers; +} + +void RdbServiceImpl::SyncAgent::ReInit(pid_t pid, const std::string &bundleName) +{ + pid_ = pid; + bundleName_ = bundleName; + watchers_.clear(); + mode_.clear(); +} + int32_t RdbServiceImpl::DoUnSubscribe(const RdbSyncerParam& param) { auto identifier = GenIdentifier(param); @@ -466,8 +551,6 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) int32_t RdbServiceImpl::OnInitialize() { - auto initEvt = std::make_unique(CloudEvent::FEATURE_INIT, CloudEvent::StoreInfo()); - EventCenter::GetInstance().PostEvent(std::move(initEvt)); return RDB_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 39fd62d4..ccc864ae 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -134,13 +134,14 @@ int32_t RdbServiceStub::OnRemoteDoAsync(MessageParcel &data, MessageParcel &repl int32_t RdbServiceStub::OnRemoteDoSubscribe(MessageParcel &data, MessageParcel &reply) { RdbSyncerParam param; - if (!ITypesUtil::Unmarshal(data, param)) { + SubscribeOption option; + if (!ITypesUtil::Unmarshal(data, param, option)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), param.storeName_.c_str()); return IPC_STUB_INVALID_DATA_ERR; } - auto status = DoSubscribe(param); + auto status = DoSubscribe(param, option); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.h b/services/distributeddataservice/service/rdb/rdb_syncer.h index 42602bdb..f5f23885 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -63,6 +63,8 @@ public: static bool GetPassword(const StoreMetaData &metaData, DistributedDB::CipherPassword &password); + static DistributedDB::Query MakeQuery(const RdbPredicates& predicates); + private: std::string GetUserId() const; @@ -92,7 +94,6 @@ private: static void HandleSyncStatus(const std::map>& SyncStatus, SyncResult& result); - static DistributedDB::Query MakeQuery(const RdbPredicates& predicates); static void EqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); static void NotEqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); static void And(const RdbPredicateOperation& operation, DistributedDB::Query& query); diff --git a/services/distributeddataservice/service/rdb/rdb_watcher.cpp b/services/distributeddataservice/service/rdb/rdb_watcher.cpp new file mode 100644 index 00000000..01572668 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_watcher.cpp @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#define LOG_TAG "RdbWatcher" + +#include "rdb_watcher.h" +#include "log_print.h" +#include "error/general_error.h" + +namespace OHOS::DistributedRdb { +using namespace DistributedData; +using Err = DistributedData::GeneralError; +RdbWatcher::RdbWatcher(RdbServiceImpl *rdbService, uint32_t tokenId, const std::string &storeName) + : rdbService_(rdbService), tokenId_(tokenId), storeName_(storeName) +{ +} + +int32_t RdbWatcher::OnChange(Origin origin, const std::string &id) +{ + if (rdbService_ == nullptr) { + return Err::E_ERROR; + } + rdbService_->OnChange(tokenId_, storeName_); + return Err::E_OK; +} + +int32_t RdbWatcher::OnChange(Origin origin, const std::string &id, const std::vector &values) +{ + return Err::E_NOT_SUPPORT; +} +} // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_watcher.h b/services/distributeddataservice/service/rdb/rdb_watcher.h new file mode 100644 index 00000000..65af0216 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_watcher.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_WATCHER_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_WATCHER_H +#include "rdb_service_impl.h" +#include "store/general_value.h" +#include "store/general_watcher.h" + +namespace OHOS::DistributedRdb { +class RdbServiceImpl; +class RdbWatcher : public DistributedData::GeneralWatcher { +public: + explicit RdbWatcher(RdbServiceImpl *rdbService, uint32_t tokenId, const std::string &storeName); + int32_t OnChange(Origin origin, const std::string &id) override; + int32_t OnChange(Origin origin, const std::string &id, + const std::vector &values) override; + +private: + RdbServiceImpl* rdbService_ {}; + uint32_t tokenId_ = 0; + std::string storeName_ {}; +}; +} // namespace OHOS::DistributedRdb +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_WATCHER_H -- Gitee From f622f78c81bc34532c6d2a7ff98c6cf61e68a560 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 13 May 2023 20:49:39 +0800 Subject: [PATCH 034/437] fix:change Signed-off-by: htt1997 --- .../app/src/uninstaller/uninstaller_impl.cpp | 112 ++++++++---------- .../app/src/uninstaller/uninstaller_impl.h | 14 ++- 2 files changed, 58 insertions(+), 68 deletions(-) diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index 80f0686a..e8d815a4 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -37,8 +37,13 @@ using namespace OHOS::AppExecFwk; using namespace OHOS::DistributedData; using namespace OHOS::EventFwk; -UninstallEventSubscriber::UninstallEventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) +UninstallEventSubscriber::UninstallEventSubscriber(const CommonEventSubscribeInfo &info, + KvStoreDataService *kvStoreDataService) + : CommonEventSubscriber(info), kvStoreDataService_(kvStoreDataService) { + callbacks_ = { { CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, &UninstallEventSubscriber::OnUninstall }, + { OHOS::AppExecFwk::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED, &UninstallEventSubscriber::OnUninstall }, + { CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED, &UninstallEventSubscriber::OnUpdate } }; } void UninstallEventSubscriber::OnReceiveEvent(const CommonEventData &event) @@ -46,21 +51,57 @@ void UninstallEventSubscriber::OnReceiveEvent(const CommonEventData &event) ZLOGI("Intent Action Rec"); Want want = event.GetWant(); std::string action = want.GetAction(); - callbacks_.ComputeIfPresent(action, [&want](const auto& key, auto &callback) { + auto it = callbacks_.find(action); + if (it != callbacks_.end()) { std::string bundleName = want.GetElement().GetBundleName(); int32_t userId = want.GetIntParam(USER_ID, -1); int32_t appIndex = want.GetIntParam(SANDBOX_APP_INDEX, 0); ZLOGI("bundleName:%{public}s, user:%{public}d, appIndex:%{public}d", bundleName.c_str(), userId, appIndex); - callback(bundleName, userId, appIndex); - return true; - }); + (this->*it->second)(bundleName, userId, appIndex); + } } -int32_t UninstallEventSubscriber::RegisterCallback(const std::string &action, UninstallEventCallback callback) + +void UninstallEventSubscriber::OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex) { - callbacks_.InsertOrAssign(action, std::move(callback)); - return Status::SUCCESS; + kvStoreDataService_->OnUninstall(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); + std::vector storeMetaData; + if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { + ZLOGE("load meta failed!"); + return; + } + for (auto &meta : storeMetaData) { + if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { + ZLOGI("uninstalled bundleName:%{public}s stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + MetaDataManager::GetInstance().DelMeta(meta.GetKey()); + MetaDataManager::GetInstance().DelMeta(meta.GetSecretKey(), true); + MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey()); + MetaDataManager::GetInstance().DelMeta(meta.appId, true); + MetaDataManager::GetInstance().DelMeta(meta.GetKeyLocal(), true); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); + PermitDelegate::GetInstance().DelCache(meta.GetKey()); + } + } } +void UninstallEventSubscriber::OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex) +{ + kvStoreDataService_->OnUpdate(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); + std::string prefix = StoreMetaData::GetPrefix( + { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); + std::vector storeMetaData; + if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { + ZLOGE("load meta failed!"); + return; + } + for (auto &meta : storeMetaData) { + if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { + ZLOGI("updated bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); + } + } +} UninstallerImpl::~UninstallerImpl() { ZLOGD("destruct"); @@ -90,21 +131,7 @@ Status UninstallerImpl::Init(KvStoreDataService *kvStoreDataService, std::shared matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED); CommonEventSubscribeInfo info(matchingSkills); - auto subscriber = std::make_shared(info); - auto removedCallback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { - kvStoreDataService->OnUninstall(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); - OnUninstall(bundleName, userId, appIndex); - }; - - auto updatedCallback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { - kvStoreDataService->OnUpdate(bundleName, userId, appIndex, IPCSkeleton::GetCallingTokenID()); - OnUpdate(bundleName, userId, appIndex); - }; - - subscriber->RegisterCallback(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, removedCallback); - subscriber->RegisterCallback(OHOS::AppExecFwk::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED, removedCallback); - subscriber->RegisterCallback(CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED, updatedCallback); - + auto subscriber = std::make_shared(info, kvStoreDataService); subscriber_ = subscriber; executors_ = executors; executors_->Execute(GetTask()); @@ -127,43 +154,4 @@ ExecutorPool::Task UninstallerImpl::GetTask() }; } -void UninstallerImpl::OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex) -{ - std::string prefix = StoreMetaData::GetPrefix( - { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); - std::vector storeMetaData; - if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { - ZLOGE("load meta failed!"); - return; - } - for (auto &meta : storeMetaData) { - if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { - ZLOGI("uninstalled bundleName:%{public}s stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); - MetaDataManager::GetInstance().DelMeta(meta.GetKey()); - MetaDataManager::GetInstance().DelMeta(meta.GetSecretKey(), true); - MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey()); - MetaDataManager::GetInstance().DelMeta(meta.appId, true); - MetaDataManager::GetInstance().DelMeta(meta.GetKeyLocal(), true); - MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); - PermitDelegate::GetInstance().DelCache(meta.GetKey()); - } - } -} - -void UninstallerImpl::OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex) -{ - std::string prefix = StoreMetaData::GetPrefix( - { DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); - std::vector storeMetaData; - if (!MetaDataManager::GetInstance().LoadMeta(prefix, storeMetaData)) { - ZLOGE("load meta failed!"); - return; - } - for (auto &meta : storeMetaData) { - if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { - ZLOGI("updated bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); - MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); - } - } -} } // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index 4de54f49..da7a498b 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -21,12 +21,12 @@ #include "uninstaller.h" namespace OHOS::DistributedKv { -using UninstallEventCallback = std::function; class UninstallEventSubscriber : public EventFwk::CommonEventSubscriber { public: - explicit UninstallEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info); - int32_t RegisterCallback(const std::string &action, UninstallEventCallback callback); +using UninstallEventCallback = void (UninstallEventSubscriber::*) + (const std::string &bundleName, int32_t userId, int32_t appIndex); + UninstallEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info, KvStoreDataService *kvStoreDataService); ~UninstallEventSubscriber() {} void OnReceiveEvent(const EventFwk::CommonEventData &event) override; @@ -34,8 +34,12 @@ public: private: static constexpr const char *USER_ID = "userId"; static constexpr const char *SANDBOX_APP_INDEX = "sandbox_app_index"; - ConcurrentMap callbacks_; + void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); + void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex); + std::map callbacks_; + KvStoreDataService *kvStoreDataService_; }; + class UninstallerImpl : public Uninstaller { public: ~UninstallerImpl(); @@ -47,8 +51,6 @@ public: private: static constexpr int32_t RETRY_TIME = 300; static constexpr int32_t RETRY_INTERVAL = 100; - static void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); - static void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex); int32_t retryTime_; ExecutorPool::Task GetTask(); std::shared_ptr subscriber_ {}; -- Gitee From abc4be15a34c17fae611c1c4268b347c26c5b71c Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sat, 13 May 2023 21:50:58 +0800 Subject: [PATCH 035/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 3 +-- .../service/rdb/rdb_service_impl.h | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 5a131f5c..4af50389 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -207,7 +207,6 @@ int32_t CloudServiceImpl::GetCloudInfo(uint32_t tokenId, const std::string &id, int32_t CloudServiceImpl::GetCloudInfoFromMeta(CloudInfo &cloudInfo) { - cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { ZLOGE("no exist meta, user:%{public}d", cloudInfo.user); return ERROR; @@ -305,7 +304,7 @@ void CloudServiceImpl::FeatureInit() if (!DistributedKv::AccountDelegate::GetInstance()->QueryUsers(users) || users.empty()) { return; } - for (const auot &user : users) { + for (const auto &user : users) { if (user == USER_ID) { continue; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 9d3b22b2..af2d788d 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -27,6 +27,7 @@ #include "rdb_notifier_proxy.h" #include "rdb_syncer.h" #include "store_observer.h" +#include "store/auto_cache.h" #include "visibility.h" namespace OHOS::DistributedRdb { class API_EXPORT RdbServiceImpl : public RdbServiceStub { @@ -49,6 +50,8 @@ public: void OnDataChange(pid_t pid, const DistributedDB::StoreChangedData& data); + void OnChange(uint32_t tokenId, const std::string &storeName); + int32_t CreateRDBTable( const RdbSyncerParam ¶m, const std::string &writePermission, const std::string &readPermission) override; int32_t DestroyRDBTable(const RdbSyncerParam ¶m) override; @@ -67,11 +70,22 @@ protected: int32_t DoAsync(const RdbSyncerParam& param, uint32_t seqNum, const SyncOption& option, const RdbPredicates& predicates) override; - int32_t DoSubscribe(const RdbSyncerParam& param) override; + int32_t DoSubscribe(const RdbSyncerParam& param, const SubscribeOption &option) override; int32_t DoUnSubscribe(const RdbSyncerParam& param) override; private: + using Watchers = DistributedData::AutoCache::Watchers; + struct SyncAgent { + pid_t pid_ = 0; + std::string bundleName_; + std::map mode_; + std::map watchers_; + void ReInit(pid_t pid, const std::string &bundleName); + }; + + Watchers GetWatchers(uint32_t tokenId, const std::string &storeName); + std::string GenIdentifier(const RdbSyncerParam& param); bool CheckAccess(const std::string& bundleName, const std::string& storeName); @@ -114,6 +128,7 @@ private: static constexpr int32_t MAX_SYNCER_PER_PROCESS = 10; static constexpr int32_t SYNCER_TIMEOUT = 60 * 1000; // ms std::shared_ptr executors_; + ConcurrentMap syncAgents_; }; } // namespace OHOS::DistributedRdb #endif -- Gitee From 0a503385483d2a12a54efc6ffe7e12597724b841 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 13 May 2023 22:02:07 +0800 Subject: [PATCH 036/437] fit:some change Signed-off-by: htt1997 --- .../app/src/uninstaller/uninstaller_impl.cpp | 2 -- .../app/src/uninstaller/uninstaller_impl.h | 1 - .../framework/include/store/auto_cache.h | 2 +- .../distributeddataservice/framework/store/auto_cache.cpp | 6 +++--- .../distributeddataservice/service/rdb/rdb_service_stub.cpp | 6 +++--- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index e8d815a4..f0f570f5 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -28,7 +28,6 @@ #include "metadata/store_meta_data.h" #include "permit_delegate.h" #include "cloud/cloud_info.h" -#include "utils/block_integer.h" namespace OHOS::DistributedKv { using namespace OHOS::AppDistributedKv; @@ -153,5 +152,4 @@ ExecutorPool::Task UninstallerImpl::GetTask() executors_->Schedule(std::chrono::milliseconds(RETRY_INTERVAL), GetTask()); }; } - } // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index da7a498b..3922fbad 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -21,7 +21,6 @@ #include "uninstaller.h" namespace OHOS::DistributedKv { - class UninstallEventSubscriber : public EventFwk::CommonEventSubscriber { public: using UninstallEventCallback = void (UninstallEventSubscriber::*) diff --git a/services/distributeddataservice/framework/include/store/auto_cache.h b/services/distributeddataservice/framework/include/store/auto_cache.h index b01834a5..ca1a5e80 100644 --- a/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/services/distributeddataservice/framework/include/store/auto_cache.h @@ -44,7 +44,7 @@ public: API_EXPORT void Bind(std::shared_ptr executor); - API_EXPORT Store GetStore(const StoreMetaData &meta, const Watchers &watchers, bool setWatchers = true); + API_EXPORT Store GetStore(const StoreMetaData &meta, const Watchers &watchers); API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId); diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index 37aff132..db51ad5c 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -52,7 +52,7 @@ AutoCache::~AutoCache() } } -AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers &watchers, bool setWatchers) +AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers &watchers) { Store store; if (meta.storeType >= MAX_CREATOR_NUM || meta.storeType < 0 || !creators_[meta.storeType]) { @@ -60,10 +60,10 @@ AutoCache::Store AutoCache::GetStore(const StoreMetaData &meta, const Watchers & } stores_.Compute(meta.tokenId, - [this, &meta, &watchers, &store, setWatchers](auto &, std::map &stores) -> bool { + [this, &meta, &watchers, &store](auto &, std::map &stores) -> bool { auto it = stores.find(meta.storeId); if (it != stores.end()) { - if (setWatchers) { + if (!watchers.empty()) { it->second.SetObservers(watchers); } store = it->second; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 39fd62d4..7e1bcdb4 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -60,9 +60,9 @@ int32_t RdbServiceStub::OnRemoteInitNotifier(MessageParcel &data, MessageParcel { RdbSyncerParam param; sptr notifier; - if (!ITypesUtil::Unmarshal(data, param, notifier) || param.bundleName_.empty() || notifier == nullptr) { - ZLOGE("Unmarshal bundleName:%{public}s notifier is nullptr:%{public}d", param.bundleName_.c_str(), - notifier == nullptr); + if (!ITypesUtil::Unmarshal(data, param, notifier) || notifier == nullptr) { + ZLOGE("Unmarshal bundleName:%{public}s storeName_:%{public}s notifier is nullptr:%{public}d", + param.bundleName_.c_str(), param.storeName_.c_str(), notifier == nullptr); return IPC_STUB_INVALID_DATA_ERR; } auto status = InitNotifier(param, notifier); -- Gitee From 1fab541689be5d696b042ad92eca68a1813b54fe Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 13 May 2023 22:20:57 +0800 Subject: [PATCH 037/437] fit:some change Signed-off-by: htt1997 --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index e6875348..a77ef04a 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -271,7 +271,7 @@ void CloudServiceImpl::GetSchema(const Event &event) rdbEvent.GetStoreInfo().instanceId); AutoCache::Watchers watchers; - auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers, false); + auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers); if (store == nullptr) { ZLOGE("store is nullptr"); return; -- Gitee From 728009dedd1de229de3634fe27c063a1fa370b80 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 13 May 2023 22:25:59 +0800 Subject: [PATCH 038/437] fit:some change Signed-off-by: htt1997 --- .../app/src/uninstaller/uninstaller_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index f0f570f5..8e45606d 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -56,7 +56,7 @@ void UninstallEventSubscriber::OnReceiveEvent(const CommonEventData &event) int32_t userId = want.GetIntParam(USER_ID, -1); int32_t appIndex = want.GetIntParam(SANDBOX_APP_INDEX, 0); ZLOGI("bundleName:%{public}s, user:%{public}d, appIndex:%{public}d", bundleName.c_str(), userId, appIndex); - (this->*it->second)(bundleName, userId, appIndex); + (this->(*it->second))(bundleName, userId, appIndex); } } -- Gitee From 7367fdd0cb25bf5049f222b86290e9c4747c9d24 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 13 May 2023 22:34:55 +0800 Subject: [PATCH 039/437] fit:some change Signed-off-by: htt1997 --- .../app/src/uninstaller/uninstaller_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index 8e45606d..cb6142eb 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -56,7 +56,7 @@ void UninstallEventSubscriber::OnReceiveEvent(const CommonEventData &event) int32_t userId = want.GetIntParam(USER_ID, -1); int32_t appIndex = want.GetIntParam(SANDBOX_APP_INDEX, 0); ZLOGI("bundleName:%{public}s, user:%{public}d, appIndex:%{public}d", bundleName.c_str(), userId, appIndex); - (this->(*it->second))(bundleName, userId, appIndex); + (this->*(it->second))(bundleName, userId, appIndex); } } -- Gitee From ff8ac6419a717fb05a7a1f44a13d1e384ce75ed3 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 14 May 2023 10:39:31 +0800 Subject: [PATCH 040/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 7 ++++++- .../service/cloud/cloud_service_impl.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 4af50389..4d239517 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -52,13 +52,18 @@ CloudServiceImpl::Factory::~Factory() {} CloudServiceImpl::CloudServiceImpl() { - FeatureInit(); EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { GetSchema(event); return; }); } +int32_t CloudServiceImpl::OnInitialize() +{ + FeatureInit(); + return SUCCESS; +} + int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) { CloudInfo cloudInfo; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 8b79e73b..ec5bc9ce 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -33,6 +33,7 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; + int32_t OnInitialize() override; private: static const inline int USER_ID = 0; -- Gitee From 65607b7295dd4fee72ccad0f5c5593f48b9d6479 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 14 May 2023 10:42:28 +0800 Subject: [PATCH 041/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/rdb/rdb_service_impl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 1250c43f..525aed43 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -98,7 +98,6 @@ RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) meta.user = std::to_string(storeInfo.user); meta.instanceId = storeInfo.instanceId; meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - ZLOGE("meta key:%{public}s", meta.GetKey().c_str()); if (!MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)) { ZLOGE("meta empty, bundleName:%{public}s, storeId:%{public}s", meta.bundleName.c_str(), meta.storeId.c_str()); -- Gitee From 1654fd0002be56ceca257ba68e0b9249d2c64ad4 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sun, 14 May 2023 10:46:35 +0800 Subject: [PATCH 042/437] f Signed-off-by: hanlu --- .../service/data_share/common/rdb_delegate.cpp | 3 +-- .../service/data_share/common/scheduler_manager.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 0e8a5b95..8a0287a4 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -24,8 +24,7 @@ namespace OHOS::DataShare { constexpr static int32_t MAX_RESULTSET_COUNT = 16; std::atomic RdbDelegate::resultSetCount = 0; -enum REMIND_TIMER_ARGS : int32_t -{ +enum REMIND_TIMER_ARGS : int32_t { ARG_DB_PATH = 0, ARG_VERSION, ARG_URI, diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index 52501eee..85d7e530 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -71,8 +71,7 @@ void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Ke return; } // not find task in map, create new timer - // auto taskId = scheduler_->At(TaskScheduler::Clock::now() + std::chrono::seconds(reminderTime - time(nullptr)), - auto taskId = scheduler_->At(TaskScheduler::Clock::now() + std::chrono::seconds(7), + auto taskId = scheduler_->At(TaskScheduler::Clock::now() + std::chrono::seconds(reminderTime - time(nullptr)), [key, dbPath, version, this]() { timerCache_.erase(key); // 1. execute schedulerSQL in next time -- Gitee From 20d8bf350337594e8dfc6deeea4e488ac5d2c971 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sun, 14 May 2023 14:06:47 +0800 Subject: [PATCH 043/437] f Signed-off-by: hanlu --- .../framework/include/serializable/serializable.h | 7 ++++++- .../service/data_share/data_share_service_impl.cpp | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 3dda5678..8a729354 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -228,7 +228,12 @@ template bool Serializable::ReadVariant(const json &node, const std::string &name, uint32_t step, uint32_t index, _OutTp &output) { if (step == index) { - return Serializable::GetValue(node, name, std::get<_First>(output)); + _First result; + if(!Serializable::GetValue(node, name, result)) { + return false; + } + output = result; + return true; } return Serializable::ReadVariant<_OutTp, _Rest...>(node, name, step + 1, index, output); } diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 14b957db..8cc30e87 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -337,6 +337,11 @@ enum DataShareKvStoreType : int32_t { int32_t DataShareServiceImpl::OnInitialize() { auto token = IPCSkeleton::GetCallingTokenID(); + auto type = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(token); + if (type != OHOS::Security::AccessToken::TOKEN_NATIVE && type != OHOS::Security::AccessToken::TOKEN_SHELL) { + ZLOGE("hanlu init app"); + return EOK; + } const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); const auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(token); DistributedData::StoreMetaData saveMeta; -- Gitee From 71bc84f26b077e3f41dda8e6fb4e223a9f2daff9 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sun, 14 May 2023 15:03:43 +0800 Subject: [PATCH 044/437] f Signed-off-by: hanlu --- .../framework/include/serializable/serializable.h | 2 +- .../service/data_share/common/rdb_delegate.cpp | 8 ++++---- .../service/data_share/common/rdb_delegate.h | 2 +- .../service/data_share/common/template_manager.cpp | 3 ++- .../service/data_share/data_share_service_impl.cpp | 5 +++++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index 8a729354..f652a684 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -229,7 +229,7 @@ bool Serializable::ReadVariant(const json &node, const std::string &name, uint32 { if (step == index) { _First result; - if(!Serializable::GetValue(node, name, result)) { + if (!Serializable::GetValue(node, name, result)) { return false; } output = result; diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 8a0287a4..174e2343 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -144,21 +144,21 @@ std::string RdbDelegate::Query(const std::string &sql, const std::vector resultSet = store_->QueryByStep(sql, selectionArgs); + auto resultSet = store_->QueryByStep(sql, selectionArgs); if (resultSet == nullptr) { ZLOGE("Query failed %{private}s", sql.c_str()); return nullptr; } - ResultSetJsonFormatter formatter(resultSet); + ResultSetJsonFormatter formatter(std::move(resultSet)); return DistributedData::Serializable::Marshall(formatter); } -std::unique_ptr RdbDelegate::QuerySql(const std::string &sql) +std::shared_ptr RdbDelegate::QuerySql(const std::string &sql) { if (store_ == nullptr) { ZLOGE("store is null"); return nullptr; } - return store_->QuerySql(sql); + return std::move(store_->QuerySql(sql)); } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.h b/services/distributeddataservice/service/data_share/common/rdb_delegate.h index 2a68d15b..39e2c119 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.h +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.h @@ -39,7 +39,7 @@ public: std::shared_ptr Query(const std::string &tableName, const DataSharePredicates &predicates, const std::vector &columns, int &errCode) override; std::string Query(const std::string &sql, const std::vector &selectionArgs) override; - std::unique_ptr QuerySql(const std::string &sql) override; + std::shared_ptr QuerySql(const std::string &sql) override; private: static std::atomic resultSetCount; diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index e876a77e..7cd18c7d 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -289,7 +289,8 @@ int RdbSubscriberManager::Notify( changeNode.templateId_.subscriberId_ = key.subscriberId; changeNode.templateId_.bundleName_ = key.bundleName; for (const auto &predicate : tpl.predicates_) { - JsonFormatter formatter(predicate.key_, delegate->Query(predicate.selectSql_)); + std::string result = delegate->Query(predicate.selectSql_); + JsonFormatter formatter(predicate.key_, result); changeNode.data_.emplace_back(DistributedData::Serializable::Marshall(formatter)); } diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 8cc30e87..5b7b716d 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -368,6 +368,11 @@ int32_t DataShareServiceImpl::OnInitialize() int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { auto token = IPCSkeleton::GetCallingTokenID(); + auto type = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(token); + if (type != OHOS::Security::AccessToken::TOKEN_NATIVE && type != OHOS::Security::AccessToken::TOKEN_SHELL) { + ZLOGE("hanlu init app"); + return EOK; + } const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); DistributedData::StoreMetaData saveMeta; saveMeta.appType = "default"; -- Gitee From d3999e6f4f6ad9fffe0fdeeb75b6453cd9c5a356 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 15:24:20 +0800 Subject: [PATCH 045/437] do subscribe and print the details Signed-off-by: Sven Wang --- .../distributeddataservice/framework/BUILD.gn | 1 + .../framework/cloud/subscription.cpp | 49 ++++++++ .../framework/include/cloud/subscription.h | 35 ++++++ .../service/cloud/cloud_service_impl.cpp | 108 ++++++++++++++++-- .../service/cloud/cloud_service_impl.h | 11 ++ 5 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 services/distributeddataservice/framework/cloud/subscription.cpp create mode 100644 services/distributeddataservice/framework/include/cloud/subscription.h diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 56855ff8..09a242ba 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("distributeddatasvcfwk") { "cloud/cloud_info.cpp", "cloud/cloud_server.cpp", "cloud/schema_meta.cpp", + "cloud/subscription.cpp", "eventcenter/event.cpp", "eventcenter/event_center.cpp", "feature/feature_system.cpp", diff --git a/services/distributeddataservice/framework/cloud/subscription.cpp b/services/distributeddataservice/framework/cloud/subscription.cpp new file mode 100644 index 00000000..635c8571 --- /dev/null +++ b/services/distributeddataservice/framework/cloud/subscription.cpp @@ -0,0 +1,49 @@ +/* + * 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 "cloud/subscription.h" +#include "utils/constant.h" +namespace OHOS::DistributedData { +bool Subscription::Marshal(json &node) const +{ + SetValue(node[GET_NAME(userId)], userId); + SetValue(node[GET_NAME(id)], id); + SetValue(node[GET_NAME(expiresTime)], expiresTime); + return true; +} + +bool Subscription::Unmarshal(const json &node) +{ + GetValue(node, GET_NAME(userId), userId); + GetValue(node, GET_NAME(id), id); + GetValue(node, GET_NAME(expiresTime), expiresTime); + return true; +} + +std::string Subscription::GetKey() +{ + return GetKey(userId); +} + +std::string Subscription::GetKey(int32_t userId) +{ + return Constant::Join(PREFIX, Constant::KEY_SEPARATOR, { std::to_string(userId) }); +} + +std::string Subscription::GetPrefix(const std::initializer_list &fields) +{ + return Constant::Join(PREFIX, Constant::KEY_SEPARATOR, fields); +} +} // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/cloud/subscription.h b/services/distributeddataservice/framework/include/cloud/subscription.h new file mode 100644 index 00000000..cd86b9de --- /dev/null +++ b/services/distributeddataservice/framework/include/cloud/subscription.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SUBSCRIPTION_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SUBSCRIPTION_H +#include "serializable/serializable.h" +namespace OHOS::DistributedData { +struct API_EXPORT Subscription final : public Serializable { + int32_t userId = 0; + std::string id; + std::map expiresTime; + + bool Marshal(Serializable::json &node) const; + bool Unmarshal(const Serializable::json &node); + std::string GetKey(); + static std::string GetKey(int32_t userId); + static std::string GetPrefix(const std::initializer_list &fields); +private: + static constexpr const char *PREFIX = "CLOUD_SUBSCRIPTION"; + static constexpr uint64_t INVALID_TIME = 0; +}; +} // namespace OHOS::DistributedData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SUBSCRIPTION_H diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index e9e932fc..40d7b712 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -18,9 +18,11 @@ #include "cloud_service_impl.h" #include "account/account_delegate.h" +#include "account_delegate.h" #include "checker/checker_manager.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" +#include "cloud/subscription.h" #include "communicator/device_manager_adapter.h" #include "eventcenter/event_center.h" #include "feature/feature_system.h" @@ -28,21 +30,24 @@ #include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" -#include "utils/anonymous.h" #include "store/auto_cache.h" - +#include "utils/anonymous.h" namespace OHOS::CloudData { using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +using Account = OHOS::DistributedKv::AccountDelegate; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; CloudServiceImpl::Factory::Factory() noexcept { - FeatureSystem::GetInstance().RegisterCreator(CloudServiceImpl::SERVICE_NAME, [this]() { - if (product_ == nullptr) { - product_ = std::make_shared(); - } - return product_; - }); + FeatureSystem::GetInstance().RegisterCreator( + CloudServiceImpl::SERVICE_NAME, + [this]() { + if (product_ == nullptr) { + product_ = std::make_shared(); + } + return product_; + }, + FeatureSystem::BIND_NOW); } CloudServiceImpl::Factory::~Factory() {} @@ -141,6 +146,28 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str return 0; } +int32_t CloudServiceImpl::OnInitialize() +{ + executor_->Execute(GetCloudTask(0, 0)); + return E_OK; +} + +int32_t CloudServiceImpl::OnExecutor(std::shared_ptr executor) +{ + if (executor_ != nullptr || executor == nullptr) { + return E_INVALID_ARGS; + } + + executor_ = std::move(executor); + return E_OK; +} + +int32_t CloudServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) +{ + executor_->Execute(GetCloudTask(0, atoi(user.c_str()))); + return E_OK; +} + int32_t CloudServiceImpl::GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo) { cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); @@ -209,6 +236,33 @@ int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleNa return SUCCESS; } +ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) +{ + return [this, retry, user]() -> void { + if (retry >= RETRY_TIMES) { + return; + } + + bool finished = true; + std::vector users; + if (user == 0) { + finished = Account::GetInstance()->QueryUsers(users); + } else { + users.push_back(user); + } + + for (auto user : users) { + Subscription subscription; + subscription.userId = user; + MetaDataManager::GetInstance().LoadMeta(subscription.GetKey(), subscription, true); + finished = Subscribe(subscription) && finished; + } + if (!finished) { + executor_->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1, user)); + } + }; +} + SchemaMeta CloudServiceImpl::GetSchemaMata(int32_t userId, const std::string &bundleName, int32_t instanceId) { SchemaMeta schemaMeta; @@ -291,4 +345,42 @@ void CloudServiceImpl::GetSchema(const Event &event) } return; } + +bool CloudServiceImpl::Subscribe(const Subscription &subscription) +{ + CloudInfo cloudInfo; + cloudInfo.user = subscription.userId; + auto exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.id, cloudInfo, true); + if (!exits) { + ZLOGW("error, there is no cloud info for user(%{public}d)", subscription.userId); + return false; + } + + ZLOGD("begin to subscribe user:%{public}d apps:%{public}zu", subscription.userId, cloudInfo.apps.size()); + if (CloudServer::GetInstance() == nullptr || cloudInfo.apps.empty()) { + return true; + } + + bool finished = true; + auto now = std::chrono::system_clock::now() + std::chrono::hours(7 * 24); + std::map> dbs; + for (auto &app : cloudInfo.apps) { + auto it = subscription.expiresTime.find(app.bundleName); + if (it != subscription.expiresTime.end() && it->second <= now.time_since_epoch().count()) { + continue; + } + + SchemaMeta schemaMeta; + exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(app.bundleName), schemaMeta, true); + if (exits) { + dbs[it->first] = std::move(schemaMeta.databases); + continue; + } + finished = false; + } + ZLOGI("Subscribe user%{public}d, size:%{public}zu", subscription.userId, dbs.size()); + ZLOGD("Subscribe user%{public}d, details:%{public}s", subscription.userId, Serializable::Marshall(dbs).c_str()); + auto ret = CloudServer::GetInstance()->Subscribe(subscription.userId, dbs); + return (ret == E_OK && finished); +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 26ed17e7..67d33612 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -21,6 +21,7 @@ #include "cloud/cloud_info.h" #include "cloud/schema_meta.h" #include "cloud/cloud_event.h" +#include "cloud/subscription.h" namespace OHOS::CloudData { class CloudServiceImpl : public CloudServiceStub { @@ -33,6 +34,9 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; + int32_t OnInitialize() override; + int32_t OnExecutor(std::shared_ptr executor) override; + int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; private: class Factory { @@ -47,6 +51,10 @@ private: using CloudInfo = DistributedData::CloudInfo; using SchemaMeta = DistributedData::SchemaMeta; using Event = DistributedData::Event; + using Subscription = DistributedData::Subscription; + + static constexpr int32_t RETRY_TIMES = 10; + static constexpr int32_t RETRY_INTERVAL = 30; void UpdateCloudInfo(CloudInfo &cloudInfo); void AddSchema(CloudInfo &cloudInfo); @@ -58,6 +66,9 @@ private: int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); void FeatureInit(const Event &event); void GetSchema(const Event &event); + ExecutorPool::Task GetCloudTask(int32_t retry, int32_t user); + bool Subscribe(const Subscription &subscription); + std::shared_ptr executor_; }; } // namespace OHOS::DistributedData -- Gitee From 4511389f446928b869274ba2c0f3f28e3c27e8b1 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sun, 14 May 2023 15:30:05 +0800 Subject: [PATCH 046/437] f Signed-off-by: hanlu --- .../service/data_share/common/db_delegate.h | 2 +- .../service/data_share/common/rdb_delegate.cpp | 7 ++++--- .../strategies/general/load_config_data_info_strategy.cpp | 2 +- .../data_share/strategies/general/permission_strategy.cpp | 1 + .../service/data_share/strategies/subscribe_strategy.cpp | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index d8b9df90..fd81af57 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -38,7 +38,7 @@ public: const DataSharePredicates &predicates, const std::vector &columns, int &errCode) = 0; virtual std::string Query( const std::string &sql, const std::vector &selectionArgs = std::vector()) = 0; - virtual std::unique_ptr QuerySql(const std::string &sql) = 0; + virtual std::shared_ptr QuerySql(const std::string &sql) = 0; }; class Id : public DistributedData::Serializable { diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 174e2343..383fac2a 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -142,12 +142,12 @@ std::string RdbDelegate::Query(const std::string &sql, const std::vectorQueryByStep(sql, selectionArgs); if (resultSet == nullptr) { ZLOGE("Query failed %{private}s", sql.c_str()); - return nullptr; + return ""; } ResultSetJsonFormatter formatter(std::move(resultSet)); return DistributedData::Serializable::Marshall(formatter); @@ -159,6 +159,7 @@ std::shared_ptr RdbDelegate::QuerySql(const std:: ZLOGE("store is null"); return nullptr; } - return std::move(store_->QuerySql(sql)); + auto result = store_->QuerySql(sql); + return std::move(result); } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index 39285621..0aab4f83 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -49,7 +49,7 @@ static bool QueryMetaData(const std::string &bundleName, const std::string &stor bool LoadConfigNormalDataInfoStrategy::operator()(std::shared_ptr context) { if (context->type != "rdb") { - return false; + return true; } DistributedData::StoreMetaData metaData; if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { diff --git a/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp index 86a4ffba..49823bd8 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp @@ -23,6 +23,7 @@ namespace OHOS::DataShare { bool PermissionStrategy::operator()(std::shared_ptr context) { if (context->permission == "reject") { + ZLOGE("reject permission"); return false; } if (!context->permission.empty()) { diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp index cdad8087..ef9ad6b0 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp @@ -49,7 +49,8 @@ Strategy *SubscribeStrategy::GetStrategy() std::initializer_list list = { new (std::nothrow)LoadConfigCommonStrategy(), new (std::nothrow)LoadConfigFromDataProxyNodeStrategy(), - new (std::nothrow)PermissionStrategy() + new (std::nothrow)PermissionStrategy(), + new (std::nothrow)LoadConfigDataInfoStrategy() }; auto ret = strategies.Init(list); if (!ret) { -- Gitee From e75d999b0c156f2a264b059bba6761ea974fa1a8 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 15:38:19 +0800 Subject: [PATCH 047/437] fixed the not support cloud server scene Signed-off-by: Sven Wang --- .../service/cloud/cloud_service_impl.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 40d7b712..95f89d4c 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -348,6 +348,11 @@ void CloudServiceImpl::GetSchema(const Event &event) bool CloudServiceImpl::Subscribe(const Subscription &subscription) { + if (CloudServer::GetInstance() == nullptr) { + ZLOGI("not support cloud server"); + return true; + } + CloudInfo cloudInfo; cloudInfo.user = subscription.userId; auto exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.id, cloudInfo, true); @@ -357,10 +362,6 @@ bool CloudServiceImpl::Subscribe(const Subscription &subscription) } ZLOGD("begin to subscribe user:%{public}d apps:%{public}zu", subscription.userId, cloudInfo.apps.size()); - if (CloudServer::GetInstance() == nullptr || cloudInfo.apps.empty()) { - return true; - } - bool finished = true; auto now = std::chrono::system_clock::now() + std::chrono::hours(7 * 24); std::map> dbs; @@ -380,7 +381,10 @@ bool CloudServiceImpl::Subscribe(const Subscription &subscription) } ZLOGI("Subscribe user%{public}d, size:%{public}zu", subscription.userId, dbs.size()); ZLOGD("Subscribe user%{public}d, details:%{public}s", subscription.userId, Serializable::Marshall(dbs).c_str()); - auto ret = CloudServer::GetInstance()->Subscribe(subscription.userId, dbs); - return (ret == E_OK && finished); + if (!dbs.empty()) { + auto ret = CloudServer::GetInstance()->Subscribe(subscription.userId, dbs); + finished = (ret == E_OK) ? finished : false; + } + return finished; } } // namespace OHOS::CloudData \ No newline at end of file -- Gitee From b8602dd0272e8bd44c724a0be859b6792785632b Mon Sep 17 00:00:00 2001 From: hanlu Date: Sun, 14 May 2023 16:18:00 +0800 Subject: [PATCH 048/437] y Signed-off-by: hanlu --- .../service/data_share/common/kv_delegate.cpp | 1 - .../service/data_share/data_share_service_impl.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index f75a3d6d..fe645eba 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -59,7 +59,6 @@ bool KvDelegate::Init() if (isInitDone_) { return true; } - ZLOGE("hanlu init %{public}s", path_.c_str()); int status = GRD_DBOpen((path_ + "/dataShare.db").c_str(), nullptr, GRD_DB_OPEN_CREATE, &db_); if (status != GRD_OK || db_ == nullptr) { ZLOGE("GRD_DBOpen failed,status %{public}d", status); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 5b7b716d..d4bb77ee 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -339,7 +339,6 @@ int32_t DataShareServiceImpl::OnInitialize() auto token = IPCSkeleton::GetCallingTokenID(); auto type = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(token); if (type != OHOS::Security::AccessToken::TOKEN_NATIVE && type != OHOS::Security::AccessToken::TOKEN_SHELL) { - ZLOGE("hanlu init app"); return EOK; } const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); @@ -360,7 +359,6 @@ int32_t DataShareServiceImpl::OnInitialize() saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - ZLOGE("hanlu init %{public}s", saveMeta.dataDir.c_str()); KvDBDelegate::GetInstance(false, saveMeta.dataDir); return EOK; } @@ -370,7 +368,6 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use auto token = IPCSkeleton::GetCallingTokenID(); auto type = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(token); if (type != OHOS::Security::AccessToken::TOKEN_NATIVE && type != OHOS::Security::AccessToken::TOKEN_SHELL) { - ZLOGE("hanlu init app"); return EOK; } const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); @@ -390,7 +387,6 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - ZLOGE("hanlu init2 %{public}s", saveMeta.dataDir.c_str()); KvDBDelegate::GetInstance(false, saveMeta.dataDir); return EOK; } -- Gitee From 830743e4c430a49f5e47563b1690b51d415ce954 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 16:48:34 +0800 Subject: [PATCH 049/437] add unsubscribe scene Signed-off-by: Sven Wang --- .../service/cloud/cloud_service_impl.cpp | 50 +++++++++++++------ .../service/cloud/cloud_service_impl.h | 3 +- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 95f89d4c..23a74da9 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -85,6 +85,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::mapExecute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -98,6 +99,7 @@ int32_t CloudServiceImpl::DisableCloud(const std::string &id) if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } + executor_->Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -119,6 +121,7 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } + executor_->Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -255,7 +258,7 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) Subscription subscription; subscription.userId = user; MetaDataManager::GetInstance().LoadMeta(subscription.GetKey(), subscription, true); - finished = Subscribe(subscription) && finished; + finished = DoSubscribe(subscription) && finished; } if (!finished) { executor_->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1, user)); @@ -346,7 +349,7 @@ void CloudServiceImpl::GetSchema(const Event &event) return; } -bool CloudServiceImpl::Subscribe(const Subscription &subscription) +bool CloudServiceImpl::DoSubscribe(const Subscription &subscription) { if (CloudServer::GetInstance() == nullptr) { ZLOGI("not support cloud server"); @@ -361,30 +364,45 @@ bool CloudServiceImpl::Subscribe(const Subscription &subscription) return false; } - ZLOGD("begin to subscribe user:%{public}d apps:%{public}zu", subscription.userId, cloudInfo.apps.size()); - bool finished = true; - auto now = std::chrono::system_clock::now() + std::chrono::hours(7 * 24); - std::map> dbs; + ZLOGD("begin cloud:%{public}d user:%{public}d apps:%{public}zu", cloudInfo.enableCloud, subscription.userId, + cloudInfo.apps.size()); + auto onThreshold = (std::chrono::system_clock::now() + std::chrono::hours(EXPIRE_INTERVAL)).time_since_epoch(); + auto offThreshold = std::chrono::system_clock::now().time_since_epoch(); + std::map> subDbs; + std::map> unsubDbs; for (auto &app : cloudInfo.apps) { + auto enabled = cloudInfo.enableCloud && app.cloudSwitch; + auto &dbs = enabled ? subDbs : unsubDbs; auto it = subscription.expiresTime.find(app.bundleName); - if (it != subscription.expiresTime.end() && it->second <= now.time_since_epoch().count()) { + + // cloud is enabled, but the subscription won't expire + if (enabled && (it != subscription.expiresTime.end() && it->second >= onThreshold.count())) { + continue; + } + // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. + if (!enabled && (it == subscription.expiresTime.end() || it->second <= offThreshold.count())) { continue; } SchemaMeta schemaMeta; exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(app.bundleName), schemaMeta, true); - if (exits) { - dbs[it->first] = std::move(schemaMeta.databases); + if (!exits) { continue; } - finished = false; + dbs[it->first] = std::move(schemaMeta.databases); + } + + ZLOGI("cloud switch:%{public}d user%{public}d, sub:%{public}zu, unsub:%{public}zu", cloudInfo.enableCloud, + subscription.userId, subDbs.size(), unsubDbs.size()); + ZLOGD("Subscribe user%{public}d, details:%{public}s", subscription.userId, Serializable::Marshall(subDbs).c_str()); + ZLOGD("Unsubscribe user%{public}d, details:%{public}s", subscription.userId, + Serializable::Marshall(unsubDbs).c_str()); + if (!subDbs.empty()) { + CloudServer::GetInstance()->Subscribe(subscription.userId, subDbs); } - ZLOGI("Subscribe user%{public}d, size:%{public}zu", subscription.userId, dbs.size()); - ZLOGD("Subscribe user%{public}d, details:%{public}s", subscription.userId, Serializable::Marshall(dbs).c_str()); - if (!dbs.empty()) { - auto ret = CloudServer::GetInstance()->Subscribe(subscription.userId, dbs); - finished = (ret == E_OK) ? finished : false; + if (!unsubDbs.empty()) { + CloudServer::GetInstance()->Subscribe(subscription.userId, unsubDbs); } - return finished; + return subDbs.empty() && unsubDbs.empty(); } } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 67d33612..b43655ff 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -55,6 +55,7 @@ private: static constexpr int32_t RETRY_TIMES = 10; static constexpr int32_t RETRY_INTERVAL = 30; + static constexpr int32_t EXPIRE_INTERVAL = 7 * 24; // 7 day void UpdateCloudInfo(CloudInfo &cloudInfo); void AddSchema(CloudInfo &cloudInfo); @@ -67,7 +68,7 @@ private: void FeatureInit(const Event &event); void GetSchema(const Event &event); ExecutorPool::Task GetCloudTask(int32_t retry, int32_t user); - bool Subscribe(const Subscription &subscription); + bool DoSubscribe(const Subscription &subscription); std::shared_ptr executor_; }; } // namespace OHOS::DistributedData -- Gitee From 07b1cb2d21911cd952764fd44f8bdebbe3920a82 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 16:55:04 +0800 Subject: [PATCH 050/437] fixed code style Signed-off-by: Sven Wang --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 23a74da9..0a894588 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -374,7 +374,6 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &subscription) auto enabled = cloudInfo.enableCloud && app.cloudSwitch; auto &dbs = enabled ? subDbs : unsubDbs; auto it = subscription.expiresTime.find(app.bundleName); - // cloud is enabled, but the subscription won't expire if (enabled && (it != subscription.expiresTime.end() && it->second >= onThreshold.count())) { continue; -- Gitee From cfe3a02855fc7dae6daa756d9bd093a3fd024f37 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 14 May 2023 17:29:39 +0800 Subject: [PATCH 051/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index a5527354..26fcf7f3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -18,7 +18,6 @@ #include "cloud_service_impl.h" #include "account/account_delegate.h" -#include "account_delegate.h" #include "checker/checker_manager.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" -- Gitee From 2b6384b986c49cc6744543cce7f0115b87ef4ac2 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 17:30:27 +0800 Subject: [PATCH 052/437] remove unused header Signed-off-by: Sven Wang --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 0a894588..89093551 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -18,7 +18,6 @@ #include "cloud_service_impl.h" #include "account/account_delegate.h" -#include "account_delegate.h" #include "checker/checker_manager.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" -- Gitee From 3d1aadb7fcf61b85523f70edc2b17e123809c536 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 17:51:07 +0800 Subject: [PATCH 053/437] add nullptr check Signed-off-by: Sven Wang --- .../service/cloud/cloud_service_impl.cpp | 23 +++++++++++++------ .../service/cloud/cloud_service_impl.h | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 89093551..cf4a5b25 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -84,7 +84,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::mapExecute(GetCloudTask(0, cloudInfo.user)); + Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -98,7 +98,7 @@ int32_t CloudServiceImpl::DisableCloud(const std::string &id) if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } - executor_->Execute(GetCloudTask(0, cloudInfo.user)); + Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -120,7 +120,7 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } - executor_->Execute(GetCloudTask(0, cloudInfo.user)); + Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -150,7 +150,7 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str int32_t CloudServiceImpl::OnInitialize() { - executor_->Execute(GetCloudTask(0, 0)); + Execute(GetCloudTask(0, 0)); return E_OK; } @@ -166,7 +166,7 @@ int32_t CloudServiceImpl::OnExecutor(std::shared_ptr executor) int32_t CloudServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { - executor_->Execute(GetCloudTask(0, atoi(user.c_str()))); + Execute(GetCloudTask(0, atoi(user.c_str()))); return E_OK; } @@ -241,7 +241,8 @@ int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleNa ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) { return [this, retry, user]() -> void { - if (retry >= RETRY_TIMES) { + auto executor = executor_; + if (retry >= RETRY_TIMES || executor == nullptr) { return; } @@ -260,7 +261,7 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) finished = DoSubscribe(subscription) && finished; } if (!finished) { - executor_->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1, user)); + executor->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1, user)); } }; } @@ -403,4 +404,12 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &subscription) } return subDbs.empty() && unsubDbs.empty(); } +void CloudServiceImpl::Execute(ExecutorPool::Task task) +{ + auto executor = executor_; + if (executor == nullptr) { + return; + } + executor->Execute(std::move(task)); +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index b43655ff..2e8b7c9b 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -68,6 +68,7 @@ private: void FeatureInit(const Event &event); void GetSchema(const Event &event); ExecutorPool::Task GetCloudTask(int32_t retry, int32_t user); + void Execute(ExecutorPool::Task task); bool DoSubscribe(const Subscription &subscription); std::shared_ptr executor_; }; -- Gitee From c10da293dbe972902882d8439fa452db4e59c82b Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 14 May 2023 18:03:05 +0800 Subject: [PATCH 054/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 24 +++++++++++++------ .../service/cloud/cloud_service_impl.h | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 26fcf7f3..ee924220 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -80,7 +80,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::mapExecute(GetCloudTask(0, cloudInfo.user)); + Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -95,7 +95,7 @@ int32_t CloudServiceImpl::DisableCloud(const std::string &id) if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } - executor_->Execute(GetCloudTask(0, cloudInfo.user)); + Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -118,7 +118,7 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } - executor_->Execute(GetCloudTask(0, cloudInfo.user)); + Execute(GetCloudTask(0, cloudInfo.user)); return SUCCESS; } @@ -193,7 +193,7 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str int32_t CloudServiceImpl::OnInitialize() { FeatureInit(); - executor_->Execute(GetCloudTask(0, 0)); + Execute(GetCloudTask(0, 0)); return E_OK; } @@ -209,7 +209,7 @@ int32_t CloudServiceImpl::OnExecutor(std::shared_ptr executor) int32_t CloudServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { - executor_->Execute(GetCloudTask(0, atoi(user.c_str()))); + Execute(GetCloudTask(0, atoi(user.c_str()))); return E_OK; } @@ -292,7 +292,8 @@ int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleNa ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) { return [this, retry, user]() -> void { - if (retry >= RETRY_TIMES) { + auto executor = executor_; + if (retry >= RETRY_TIMES || executor == nullptr) { return; } @@ -311,7 +312,7 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) finished = DoSubscribe(subscription) && finished; } if (!finished) { - executor_->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1, user)); + executor->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1, user)); } }; } @@ -459,4 +460,13 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &subscription) } return subDbs.empty() && unsubDbs.empty(); } + +void CloudServiceImpl::Execute(ExecutorPool::Task task) +{ + auto executor = executor_; + if (executor == nullptr) { + return; + } + executor->Execute(std::move(task)); +} } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index e9e3e50c..116a32ce 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -70,6 +70,7 @@ private: void FeatureInit(); void GetSchema(const Event &event); ExecutorPool::Task GetCloudTask(int32_t retry, int32_t user); + void Execute(ExecutorPool::Task task); bool DoSubscribe(const Subscription &subscription); std::shared_ptr executor_; }; -- Gitee From 6cc5839d94004a7a4861414d0a670a44946f5c2d Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 20:22:44 +0800 Subject: [PATCH 055/437] add relation info Signed-off-by: Sven Wang --- .../framework/cloud/subscription.cpp | 26 +++++++++++++++++++ .../framework/include/cloud/subscription.h | 15 +++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/subscription.cpp b/services/distributeddataservice/framework/cloud/subscription.cpp index 635c8571..7bddb52c 100644 --- a/services/distributeddataservice/framework/cloud/subscription.cpp +++ b/services/distributeddataservice/framework/cloud/subscription.cpp @@ -16,6 +16,22 @@ #include "cloud/subscription.h" #include "utils/constant.h" namespace OHOS::DistributedData { +bool Subscription::Relation::Marshal(json &node) const +{ + SetValue(node[GET_NAME(id)], id); + SetValue(node[GET_NAME(bundleName)], bundleName); + SetValue(node[GET_NAME(relations)], relations); + return true; +} + +bool Subscription::Relation::Unmarshal(const json &node) +{ + GetValue(node, GET_NAME(id), id); + GetValue(node, GET_NAME(bundleName), bundleName); + GetValue(node, GET_NAME(relations), relations); + return true; +} + bool Subscription::Marshal(json &node) const { SetValue(node[GET_NAME(userId)], userId); @@ -37,11 +53,21 @@ std::string Subscription::GetKey() return GetKey(userId); } +std::string Subscription::GetRelationKey(const std::string &bundleName) +{ + return GetRelationKey(userId, bundleName); +} + std::string Subscription::GetKey(int32_t userId) { return Constant::Join(PREFIX, Constant::KEY_SEPARATOR, { std::to_string(userId) }); } +std::string Subscription::GetRelationKey(int32_t userId, const std::string &bundleName) +{ + return Constant::Join(RELATION_PREFIX, Constant::KEY_SEPARATOR, { std::to_string(userId), bundleName }); +} + std::string Subscription::GetPrefix(const std::initializer_list &fields) { return Constant::Join(PREFIX, Constant::KEY_SEPARATOR, fields); diff --git a/services/distributeddataservice/framework/include/cloud/subscription.h b/services/distributeddataservice/framework/include/cloud/subscription.h index cd86b9de..c0e8dec5 100644 --- a/services/distributeddataservice/framework/include/cloud/subscription.h +++ b/services/distributeddataservice/framework/include/cloud/subscription.h @@ -22,13 +22,24 @@ struct API_EXPORT Subscription final : public Serializable { std::string id; std::map expiresTime; - bool Marshal(Serializable::json &node) const; - bool Unmarshal(const Serializable::json &node); + struct API_EXPORT Relation final : public Serializable { + std::string id; + std::string bundleName; + std::map relations; + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + }; + + bool Marshal(json &node) const; + bool Unmarshal(const json &node); std::string GetKey(); + std::string GetRelationKey(const std::string &bundleName); static std::string GetKey(int32_t userId); + static std::string GetRelationKey(int32_t userId, const std::string &bundleName); static std::string GetPrefix(const std::initializer_list &fields); private: static constexpr const char *PREFIX = "CLOUD_SUBSCRIPTION"; + static constexpr const char *RELATION_PREFIX = "CLOUD_RELATION"; static constexpr uint64_t INVALID_TIME = 0; }; } // namespace OHOS::DistributedData -- Gitee From 25b4f26d12fe12a94ad7b09fcc4ef5961c0c437f Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Sun, 14 May 2023 20:42:37 +0800 Subject: [PATCH 056/437] update Signed-off-by: Sven Wang --- .../service/cloud/cloud_service_impl.cpp | 37 ++++++++----------- .../service/cloud/cloud_service_impl.h | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index cf4a5b25..4fcf3fd6 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -349,7 +349,7 @@ void CloudServiceImpl::GetSchema(const Event &event) return; } -bool CloudServiceImpl::DoSubscribe(const Subscription &subscription) +bool CloudServiceImpl::DoSubscribe(const Subscription &sub) { if (CloudServer::GetInstance() == nullptr) { ZLOGI("not support cloud server"); @@ -357,14 +357,14 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &subscription) } CloudInfo cloudInfo; - cloudInfo.user = subscription.userId; - auto exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.id, cloudInfo, true); + cloudInfo.user = sub.userId; + auto exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true); if (!exits) { - ZLOGW("error, there is no cloud info for user(%{public}d)", subscription.userId); + ZLOGW("error, there is no cloud info for user(%{public}d)", sub.userId); return false; } - ZLOGD("begin cloud:%{public}d user:%{public}d apps:%{public}zu", cloudInfo.enableCloud, subscription.userId, + ZLOGD("begin cloud:%{public}d user:%{public}d apps:%{public}zu", cloudInfo.enableCloud, sub.userId, cloudInfo.apps.size()); auto onThreshold = (std::chrono::system_clock::now() + std::chrono::hours(EXPIRE_INTERVAL)).time_since_epoch(); auto offThreshold = std::chrono::system_clock::now().time_since_epoch(); @@ -373,37 +373,32 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &subscription) for (auto &app : cloudInfo.apps) { auto enabled = cloudInfo.enableCloud && app.cloudSwitch; auto &dbs = enabled ? subDbs : unsubDbs; - auto it = subscription.expiresTime.find(app.bundleName); + auto it = sub.expiresTime.find(app.bundleName); // cloud is enabled, but the subscription won't expire - if (enabled && (it != subscription.expiresTime.end() && it->second >= onThreshold.count())) { + if (enabled && (it != sub.expiresTime.end() && it->second >= onThreshold.count())) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. - if (!enabled && (it == subscription.expiresTime.end() || it->second <= offThreshold.count())) { + if (!enabled && (it == sub.expiresTime.end() || it->second <= offThreshold.count())) { continue; } SchemaMeta schemaMeta; exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(app.bundleName), schemaMeta, true); - if (!exits) { - continue; + if (exits) { + dbs[it->first] = std::move(schemaMeta.databases); } - dbs[it->first] = std::move(schemaMeta.databases); } ZLOGI("cloud switch:%{public}d user%{public}d, sub:%{public}zu, unsub:%{public}zu", cloudInfo.enableCloud, - subscription.userId, subDbs.size(), unsubDbs.size()); - ZLOGD("Subscribe user%{public}d, details:%{public}s", subscription.userId, Serializable::Marshall(subDbs).c_str()); - ZLOGD("Unsubscribe user%{public}d, details:%{public}s", subscription.userId, - Serializable::Marshall(unsubDbs).c_str()); - if (!subDbs.empty()) { - CloudServer::GetInstance()->Subscribe(subscription.userId, subDbs); - } - if (!unsubDbs.empty()) { - CloudServer::GetInstance()->Subscribe(subscription.userId, unsubDbs); - } + sub.userId, subDbs.size(), unsubDbs.size()); + ZLOGD("Subscribe user%{public}d details:%{public}s", sub.userId, Serializable::Marshall(subDbs).c_str()); + ZLOGD("Unsubscribe user%{public}d details:%{public}s", sub.userId, Serializable::Marshall(unsubDbs).c_str()); + CloudServer::GetInstance()->Subscribe(sub.userId, subDbs); + CloudServer::GetInstance()->Unsubscribe(sub.userId, unsubDbs); return subDbs.empty() && unsubDbs.empty(); } + void CloudServiceImpl::Execute(ExecutorPool::Task task) { auto executor = executor_; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 2e8b7c9b..638d2db9 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -69,7 +69,7 @@ private: void GetSchema(const Event &event); ExecutorPool::Task GetCloudTask(int32_t retry, int32_t user); void Execute(ExecutorPool::Task task); - bool DoSubscribe(const Subscription &subscription); + bool DoSubscribe(const Subscription &sub); std::shared_ptr executor_; }; } // namespace OHOS::DistributedData -- Gitee From 8359157ec5ac07f9597ad5cb1388dc5becefd17b Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sun, 14 May 2023 22:32:11 +0800 Subject: [PATCH 057/437] gix:save cloudInfo to meta Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index a77ef04a..52f1a56b 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -217,9 +217,21 @@ SchemaMeta CloudServiceImpl::GetSchemaMata(int32_t userId, const std::string &bu ZLOGE("instance is nullptr"); return schemaMeta; } - auto cloudInfo = instance->GetServerInfo(userId); - if (!cloudInfo.IsValid()) { - ZLOGE("cloudInfo is invalid"); + CloudInfo cloudInfo; + cloudInfo.user = userId; + if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { + cloudInfo = instance->GetServerInfo(userId); + if (!cloudInfo.IsValid()) { + ZLOGE("cloudInfo is invalid"); + return schemaMeta; + } + MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); + } + if (std::find_if(cloudInfo.apps.begin(), cloudInfo.apps.end(), + [&bundleName, &instanceId](const CloudInfo::AppInfo &appInfo) { + return appInfo.bundleName == bundleName && appInfo.instanceId == instanceId; + }) == cloudInfo.apps.end()) { + ZLOGE("bundleName:%{public}s instanceId:%{public}d", bundleName.c_str(), instanceId); return schemaMeta; } std::string schemaKey = cloudInfo.GetSchemaKey(bundleName, instanceId); @@ -286,6 +298,7 @@ void CloudServiceImpl::GetSchema(const Event &event) if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync */) { continue; } + ZLOGD("database: %{public}s sync start", database.name.c_str()); auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); if (cloudDB != nullptr) { store->Bind(cloudDB); -- Gitee From 4bdce19355f6c73cfb353f3d965e803c8a0e9f51 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sun, 14 May 2023 23:07:23 +0800 Subject: [PATCH 058/437] style:code check Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 52f1a56b..c6f60a6e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -228,9 +228,9 @@ SchemaMeta CloudServiceImpl::GetSchemaMata(int32_t userId, const std::string &bu MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); } if (std::find_if(cloudInfo.apps.begin(), cloudInfo.apps.end(), - [&bundleName, &instanceId](const CloudInfo::AppInfo &appInfo) { - return appInfo.bundleName == bundleName && appInfo.instanceId == instanceId; - }) == cloudInfo.apps.end()) { + [&bundleName, &instanceId](const CloudInfo::AppInfo &appInfo) { + return appInfo.bundleName == bundleName && appInfo.instanceId == instanceId; + }) == cloudInfo.apps.end()) { ZLOGE("bundleName:%{public}s instanceId:%{public}d", bundleName.c_str(), instanceId); return schemaMeta; } @@ -279,6 +279,9 @@ void CloudServiceImpl::GetSchema(const Event &event) rdbEvent.GetStoreInfo().instanceId); auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); auto schemaMeta = GetSchemaMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); + if (schemaMeta.databases.empty()) { + return; + } auto storeMeta = GetStoreMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, rdbEvent.GetStoreInfo().instanceId); @@ -299,10 +302,7 @@ void CloudServiceImpl::GetSchema(const Event &event) continue; } ZLOGD("database: %{public}s sync start", database.name.c_str()); - auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); - if (cloudDB != nullptr) { - store->Bind(cloudDB); - } + //ConnectCloudDB and Bind to store for (auto &table : database.tables) { ZLOGD("table: %{public}s sync start", table.name.c_str()); } -- Gitee From 5aa2bb6994ee0bcd95bf5b745dda4a01ccb1b83e Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sun, 14 May 2023 23:25:54 +0800 Subject: [PATCH 059/437] style:code check Signed-off-by: htt1997 --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index c6f60a6e..11c7d183 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -302,7 +302,7 @@ void CloudServiceImpl::GetSchema(const Event &event) continue; } ZLOGD("database: %{public}s sync start", database.name.c_str()); - //ConnectCloudDB and Bind to store + // ConnectCloudDB and Bind to store for (auto &table : database.tables) { ZLOGD("table: %{public}s sync start", table.name.c_str()); } -- Gitee From 795f7783aad855faa1dd45ad72d8b11c10e3f335 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Mon, 15 May 2023 11:09:15 +0800 Subject: [PATCH 060/437] fixed bundleName bugs Signed-off-by: Sven Wang --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 4fcf3fd6..3a6b07d0 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -386,7 +386,7 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &sub) SchemaMeta schemaMeta; exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(app.bundleName), schemaMeta, true); if (exits) { - dbs[it->first] = std::move(schemaMeta.databases); + dbs[app.bundleName] = std::move(schemaMeta.databases); } } -- Gitee From 723f63707dd1b4bfb18b6521d066192ee9250ff3 Mon Sep 17 00:00:00 2001 From: lianhuix Date: Mon, 15 May 2023 19:25:41 +0800 Subject: [PATCH 061/437] Fix attribute Signed-off-by: lianhuix --- .../data_share/gaussdb_rd/include/grd_base/grd_type_export.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h b/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h index baa98144..d116ea22 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h @@ -21,7 +21,7 @@ extern "C" { #endif // __cplusplus #ifndef _WIN32 -#define GRD_API __attribute__((visibility("default"), weak)) +#define GRD_API __attribute__((visibility("default"))) #endif typedef struct GRD_DB GRD_DB; -- Gitee From d6419d96ad52cf5f6f9c749a1ce79788901a8f32 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Wed, 17 May 2023 15:38:44 +0800 Subject: [PATCH 062/437] fix warn Signed-off-by: niudongyao --- .../service/data_share/data_share_types_util.h | 4 ++-- .../load_config_from_data_share_bundle_info_strategy.cpp | 2 +- .../strategies/general/connect_extension_strategy.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_types_util.h b/services/distributeddataservice/service/data_share/data_share_types_util.h index 4f4ebf9b..b1e0a476 100644 --- a/services/distributeddataservice/service/data_share/data_share_types_util.h +++ b/services/distributeddataservice/service/data_share/data_share_types_util.h @@ -42,7 +42,7 @@ template<> bool Unmarshalling(PublishedDataItem &dataItem, MessageParcel &parcel); template<> -bool Marshalling(const PublishedDataItem &templateId, MessageParcel &parcel); +bool Marshalling(const PublishedDataItem &dataItem, MessageParcel &parcel); template<> bool Unmarshalling(Data &data, MessageParcel &parcel); @@ -63,7 +63,7 @@ template<> bool Marshalling(const OperationResult &operationResult, MessageParcel &parcel); template<> -bool Marshalling(const TemplateId &changeNode, MessageParcel &parcel); +bool Marshalling(const TemplateId &templateId, MessageParcel &parcel); }; #endif // DATASHARESERVICE_DATA_SHARE_TYPES_UTIL_H diff --git a/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp index 5df4f1bb..9ff57d27 100644 --- a/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp @@ -53,7 +53,7 @@ bool LoadConfigFromDataShareBundleInfoStrategy::LoadConfigFromProfile( "/" + context->calledStoreName; std::string tableUri = storeUri + "/" + context->calledTableName; ConfigData result; - for (auto &item : profileInfo.tableConfig) { + for (auto const &item : profileInfo.tableConfig) { if (item.uri == tableUri) { result.SetCrossUserMode(ConfigData::TABLE_MATCH_PRIORITY, item.crossUserMode); continue; diff --git a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp index eecd0c38..1561140c 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp @@ -23,7 +23,7 @@ namespace OHOS::DataShare { bool ConnectExtensionStrategy::operator()(std::shared_ptr context) { - for (auto &extension: context->bundleInfo.extensionInfos) { + for (auto const &extension: context->bundleInfo.extensionInfos) { if (extension.type == AppExecFwk::ExtensionAbilityType::DATASHARE) { return Connect(context); } -- Gitee From 9c5b515100050f1839cd6fb60a21660911156d21 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 17 May 2023 16:06:51 +0800 Subject: [PATCH 063/437] refactor:Decoupling syncer and meta Signed-off-by: htt1997 --- .../service/rdb/rdb_service_impl.cpp | 103 ++++++++++++------ .../service/rdb/rdb_service_impl.h | 13 ++- .../service/rdb/rdb_service_stub.cpp | 12 +- .../service/rdb/rdb_syncer.cpp | 83 +------------- .../service/rdb/rdb_syncer.h | 7 +- .../service/test/cloud_data_test.cpp | 58 +++++----- 6 files changed, 116 insertions(+), 160 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 525aed43..f7a9b2c7 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -24,6 +24,7 @@ #include "eventcenter/event_center.h" #include "ipc_skeleton.h" #include "log_print.h" +#include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "permission/permission_validator.h" @@ -45,14 +46,18 @@ using namespace OHOS::DistributedData; using namespace OHOS::Security::AccessToken; using DistributedDB::RelationalStoreManager; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +using system_clock = std::chrono::system_clock; constexpr uint32_t ITERATE_TIMES = 10000; namespace OHOS::DistributedRdb { __attribute__((used)) RdbServiceImpl::Factory RdbServiceImpl::factory_; RdbServiceImpl::Factory::Factory() { - FeatureSystem::GetInstance().RegisterCreator("relational_store", []() { - return std::make_shared(); + FeatureSystem::GetInstance().RegisterCreator(RdbServiceImpl::SERVICE_NAME, [this]() { + if (product_ == nullptr) { + product_ = std::make_shared(); + } + return product_; }); AutoCache::GetInstance().RegCreator(RDB_DEVICE_COLLABORATION, [](const StoreMetaData &metaData) -> GeneralStore* { return new (std::nothrow) RdbGeneralStore(metaData); @@ -284,12 +289,8 @@ std::shared_ptr RdbServiceImpl::GetRdbSyncer(const RdbSyncerParam &pa } syncers.erase(storeId); } - if (syncers.size() >= MAX_SYNCER_PER_PROCESS) { - ZLOGE("%{public}d exceed MAX_PROCESS_SYNCER_NUM", pid); - return !syncers.empty(); - } - if (syncerNum_ >= MAX_SYNCER_NUM) { - ZLOGE("no available syncer"); + if (syncers.size() >= MAX_SYNCER_PER_PROCESS || syncerNum_ >= MAX_SYNCER_NUM) { + ZLOGE("pid: %{public}d, syncers size: %{public}zu. syncerNum: %{public}d", pid, syncers.size(), syncerNum_); return !syncers.empty(); } auto rdbObserver = new (std::nothrow) RdbStoreObserverImpl(this, pid); @@ -297,7 +298,9 @@ std::shared_ptr RdbServiceImpl::GetRdbSyncer(const RdbSyncerParam &pa return !syncers.empty(); } auto syncer_ = std::make_shared(param, rdbObserver); - if (syncer_->Init(pid, uid, tokenId) != 0) { + StoreMetaData storeMetaData = GetStoreMetaData(param); + MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData); + if (syncer_->Init(pid, uid, tokenId, storeMetaData) != 0) { return !syncers.empty(); } syncers[storeId] = syncer_; @@ -492,8 +495,7 @@ int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::stri return syncer->RemoteQuery(device, sql, selectionArgs, resultSet); } -int32_t RdbServiceImpl::CreateRDBTable( - const RdbSyncerParam ¶m, const std::string &writePermission, const std::string &readPermission) +int32_t RdbServiceImpl::CreateRDBTable(const RdbSyncerParam ¶m) { if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); @@ -512,7 +514,9 @@ int32_t RdbServiceImpl::CreateRDBTable( } auto uid = IPCSkeleton::GetCallingUid(); auto tokenId = IPCSkeleton::GetCallingTokenID(); - if (syncer->Init(pid, uid, tokenId, writePermission, readPermission) != RDB_OK) { + StoreMetaData storeMetaData = GetStoreMetaData(param); + MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData); + if (syncer->Init(pid, uid, tokenId, storeMetaData) != RDB_OK) { ZLOGE("Init error"); delete syncer; return RDB_ERROR; @@ -527,25 +531,8 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) ZLOGE("permission error"); return RDB_ERROR; } - pid_t pid = IPCSkeleton::GetCallingPid(); - auto rdbObserver = new (std::nothrow) RdbStoreObserverImpl(this, pid); - if (rdbObserver == nullptr) { - return RDB_ERROR; - } - auto syncer = new (std::nothrow) RdbSyncer(param, rdbObserver); - if (syncer == nullptr) { - ZLOGE("new syncer error"); - return RDB_ERROR; - } - - StoreMetaData meta; - if (syncer->DestroyMetaData(meta) != RDB_OK) { - ZLOGE("destroy meta data error"); - delete syncer; - return RDB_ERROR; - } - delete syncer; - return RDB_OK; + auto meta = GetStoreMetaData(param); + return MetaDataManager::GetInstance().DelMeta(meta.GetKey()) ? RDB_OK : RDB_ERROR; } int32_t RdbServiceImpl::OnInitialize() @@ -559,10 +546,12 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) ZLOGE("permission error"); return RDB_ERROR; } - auto syncer = GetRdbSyncer(param); - if (syncer == nullptr) { + StoreMetaData storeMeta; + if (CreateMetaData(param, storeMeta) != RDB_OK) { return RDB_ERROR; } + + EventCenter::Defer defer; CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, RdbSyncer::RemoveSuffix(param.storeName_), RdbSyncer::GetInstIndex(IPCSkeleton::GetCallingTokenID(), param.bundleName_) }; @@ -593,9 +582,53 @@ StoreMetaData RdbServiceImpl::GetStoreMetaData(const RdbSyncerParam ¶m) return metaData; } +int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaData &old) +{ + auto meta = GetStoreMetaData(param); + bool isCreated = MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), old); + if (isCreated && (old.storeType != meta.storeType || Constant::NotEqual(old.isEncrypt, meta.isEncrypt) || + old.area != meta.area)) { + ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " + "area:%{public}d->%{public}d", + meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, + meta.isEncrypt, old.area, meta.area); + return RDB_ERROR; + } + + auto saved = MetaDataManager::GetInstance().SaveMeta(meta.GetKey(), meta); + if (!saved) { + return RDB_ERROR; + } + AppIDMetaData appIdMeta; + appIdMeta.bundleName = meta.bundleName; + appIdMeta.appId = meta.appId; + saved = MetaDataManager::GetInstance().SaveMeta(appIdMeta.GetKey(), appIdMeta, true); + if (!saved) { + return RDB_ERROR; + } + if (!param.isEncrypt_ || param.password_.empty()) { + return RDB_OK; + } + return SetSecretKey(param, meta); +} + +bool RdbServiceImpl::SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta) +{ + SecretKeyMetaData newSecretKey; + newSecretKey.storeType = meta.storeType; + newSecretKey.sKey = CryptoManager::GetInstance().Encrypt(param.password_); + if (newSecretKey.sKey.empty()) { + ZLOGE("encrypt work key error."); + return RDB_ERROR; + } + auto time = system_clock::to_time_t(system_clock::now()); + newSecretKey.time = { reinterpret_cast(&time), reinterpret_cast(&time) + sizeof(time) }; + return MetaDataManager::GetInstance().SaveMeta(meta.GetSecretKey(), newSecretKey, true) ? RDB_OK : RDB_ERROR; +} + int32_t RdbServiceImpl::OnExecutor(std::shared_ptr executors) { - executors_ = executors; - return 0; + executors_ = std::move(executors); + return RDB_OK; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index af2d788d..c9f3eb54 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -52,16 +52,17 @@ public: void OnChange(uint32_t tokenId, const std::string &storeName); - int32_t CreateRDBTable( - const RdbSyncerParam ¶m, const std::string &writePermission, const std::string &readPermission) override; + int32_t CreateRDBTable(const RdbSyncerParam ¶m) override; + int32_t DestroyRDBTable(const RdbSyncerParam ¶m) override; int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; + int32_t OnExecutor(std::shared_ptr executors) override; + int32_t OnInitialize() override; int32_t GetSchema(const RdbSyncerParam ¶m) override; - int32_t OnExecutor(std::shared_ptr executors) override; protected: int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, @@ -96,7 +97,9 @@ private: void OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResult& result); - StoreMetaData GetStoreMetaData(const RdbSyncerParam& param); + int32_t CreateMetaData(const RdbSyncerParam ¶m, StoreMetaData &old); + StoreMetaData GetStoreMetaData(const RdbSyncerParam ¶m); + bool SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta); class DeathRecipientImpl : public IRemoteObject::DeathRecipient { public: @@ -111,6 +114,8 @@ private: public: Factory(); ~Factory(); + private: + std::shared_ptr product_; }; using StoreSyncersType = std::map>; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 52ae7851..e879c523 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -215,17 +215,13 @@ int RdbServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageP int32_t RdbServiceStub::OnRemoteDoCreateTable(MessageParcel &data, MessageParcel &reply) { RdbSyncerParam param; - std::string writePermission; - std::string readPermission; - if (!ITypesUtil::Unmarshal(data, param, writePermission, readPermission)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s writePermission:%{public}s " - "readPermission:%{public}s", param.bundleName_.c_str(), param.storeName_.c_str(), - DistributedData::Anonymous::Change(writePermission).c_str(), - DistributedData::Anonymous::Change(readPermission).c_str()); + if (!ITypesUtil::Unmarshal(data, param)) { + ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), + param.storeName_.c_str()); return IPC_STUB_INVALID_DATA_ERR; } - int32_t status = CreateRDBTable(param, writePermission, readPermission); + int32_t status = CreateRDBTable(param); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index f8f6192a..1d1d1c35 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -102,26 +102,19 @@ std::string RdbSyncer::GetStoreId() const return RemoveSuffix(param_.storeName_); } -int32_t RdbSyncer::Init( - pid_t pid, pid_t uid, uint32_t token, const std::string &writePermission, const std::string &readPermission) +int32_t RdbSyncer::Init(pid_t pid, pid_t uid, uint32_t token, const StoreMetaData &meta) { ZLOGI("enter"); pid_ = pid; uid_ = uid; token_ = token; - StoreMetaData oldMeta; - StoreMetaData meta; - if (CreateMetaData(meta, oldMeta) != RDB_OK) { - ZLOGE("create meta data failed"); - return RDB_ERROR; - } if (InitDBDelegate(meta) != RDB_OK) { ZLOGE("delegate is nullptr"); return RDB_ERROR; } - if (oldMeta.storeType == RDB_DEVICE_COLLABORATION && oldMeta.version < StoreMetaData::UUID_CHANGED_TAG) { + if (meta.storeType == RDB_DEVICE_COLLABORATION && meta.version < StoreMetaData::UUID_CHANGED_TAG) { delegate_->RemoveDeviceData(); } @@ -129,78 +122,6 @@ int32_t RdbSyncer::Init( return RDB_OK; } -int32_t RdbSyncer::DestroyMetaData(StoreMetaData &meta) -{ - FillMetaData(meta); - auto deleted = MetaDataManager::GetInstance().DelMeta(meta.GetKey(), true); - return deleted ? RDB_OK : RDB_ERROR; -} - -void RdbSyncer::FillMetaData(StoreMetaData &meta) -{ - meta.uid = uid_; - meta.tokenId = token_; - meta.instanceId = GetInstIndex(token_, param_.bundleName_); - meta.bundleName = param_.bundleName_; - meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - meta.storeId = RemoveSuffix(param_.storeName_); - meta.user = std::to_string(AccountDelegate::GetInstance()->GetUserByToken(token_)); - meta.storeType = param_.type_; - meta.securityLevel = param_.level_; - meta.area = param_.area_; - meta.appId = CheckerManager::GetInstance().GetAppId(Converter::ConvertToStoreInfo(meta)); - meta.appType = "harmony"; - meta.hapName = param_.hapName_; - meta.dataDir = DirectoryManager::GetInstance().GetStorePath(meta) + "/" + param_.storeName_; - meta.account = AccountDelegate::GetInstance()->GetCurrentAccountId(); - meta.isEncrypt = param_.isEncrypt_; -} - -int32_t RdbSyncer::CreateMetaData(StoreMetaData &meta, StoreMetaData &old) -{ - FillMetaData(meta); - bool isCreated = MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), old); - if (isCreated && (old.storeType != meta.storeType || Constant::NotEqual(old.isEncrypt, meta.isEncrypt) || - old.area != meta.area)) { - ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " - "area:%{public}d->%{public}d", - meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, - meta.isEncrypt, old.area, meta.area); - return RDB_ERROR; - } - - auto saved = MetaDataManager::GetInstance().SaveMeta(meta.GetKey(), meta); - if (!saved) { - return RDB_ERROR; - } - AppIDMetaData appIdMeta; - appIdMeta.bundleName = meta.bundleName; - appIdMeta.appId = meta.appId; - saved = MetaDataManager::GetInstance().SaveMeta(appIdMeta.GetKey(), appIdMeta, true); - if (!saved) { - return RDB_ERROR; - } - if (!param_.isEncrypt_ || param_.password_.empty()) { - return RDB_OK; - } - return SetSecretKey(meta); -} - -bool RdbSyncer::SetSecretKey(const StoreMetaData &meta) -{ - SecretKeyMetaData newSecretKey; - newSecretKey.storeType = meta.storeType; - newSecretKey.sKey = CryptoManager::GetInstance().Encrypt(param_.password_); - if (newSecretKey.sKey.empty()) { - ZLOGE("encrypt work key error."); - return RDB_ERROR; - } - param_.password_.assign(param_.password_.size(), 0); - auto time = system_clock::to_time_t(system_clock::now()); - newSecretKey.time = { reinterpret_cast(&time), reinterpret_cast(&time) + sizeof(time) }; - return MetaDataManager::GetInstance().SaveMeta(meta.GetSecretKey(), newSecretKey, true) ? RDB_OK : RDB_ERROR; -} - bool RdbSyncer::GetPassword(const StoreMetaData &metaData, DistributedDB::CipherPassword &password) { if (!metaData.isEncrypt) { diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.h b/services/distributeddataservice/service/rdb/rdb_syncer.h index f5f23885..68d1e44f 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -34,8 +34,7 @@ public: RdbSyncer(const RdbSyncerParam& param, RdbStoreObserverImpl* observer); ~RdbSyncer() noexcept; - int32_t Init(pid_t pid, pid_t uid, uint32_t token, const std::string &writePermission = "", - const std::string &readPermission = ""); + int32_t Init(pid_t pid, pid_t uid, uint32_t token, const StoreMetaData &meta); pid_t GetPid() const; @@ -56,7 +55,6 @@ public: int32_t RemoteQuery(const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet); - int32_t DestroyMetaData(StoreMetaData &meta); static std::string RemoveSuffix(const std::string& name); static int32_t GetInstIndex(uint32_t tokenId, const std::string &bundleName); @@ -72,10 +70,7 @@ private: std::string GetAppId() const; - int32_t CreateMetaData(StoreMetaData &meta, StoreMetaData &old); - void FillMetaData(StoreMetaData &meta); int32_t InitDBDelegate(const StoreMetaData &meta); - bool SetSecretKey(const StoreMetaData &meta); DistributedDB::RelationalStoreDelegate* GetDelegate(); diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 031ea345..ddee440e 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -44,11 +44,13 @@ public: void SetUp(); void TearDown(); + static SchemaMeta schemaMeta_; protected: static constexpr const char *TEST_DISTRIBUTEDDATA_BUNDLE = "test_distributeddata"; static constexpr const char *TEST_DISTRIBUTEDDATA_STORE = "test_service_meta"; void InitMetaData(); + void InitSchemaMeta(); static std::shared_ptr dbStoreMock_; StoreMetaData metaData_; }; @@ -83,29 +85,7 @@ CloudInfo CloudServerMock::GetServerInfo(int32_t userId) SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bundleName) { - SchemaMeta::Field field1; - field1.colName = "test_cloud_field_name1"; - field1.alias = "test_cloud_field_alias1"; - SchemaMeta::Field field2; - field2.colName = "test_cloud_field_name2"; - field2.alias = "test_cloud_field_alias2"; - - SchemaMeta::Table table; - table.name = "test_cloud_table_name"; - table.alias = "test_cloud_table_alias"; - table.fields.emplace_back(field1); - table.fields.emplace_back(field2); - - SchemaMeta::Database database; - database.name = TEST_CLOUD_STORE; - database.alias = "test_cloud_database_alias"; - database.tables.emplace_back(table); - - SchemaMeta schemaMeta; - schemaMeta.version = 1; - schemaMeta.databases.emplace_back(database); - - return schemaMeta; + return CloudDataTest::schemaMeta_; } std::shared_ptr CloudDataTest::dbStoreMock_ = std::make_shared(); @@ -126,6 +106,30 @@ void CloudDataTest::InitMetaData() value.type = OHOS::DistributedKv::PolicyType::IMMEDIATE_SYNC_ON_ONLINE; } +void CloudDataTest::InitSchemaMeta() +{ + SchemaMeta::Field field1; + field1.colName = "test_cloud_field_name1"; + field1.alias = "test_cloud_field_alias1"; + SchemaMeta::Field field2; + field2.colName = "test_cloud_field_name2"; + field2.alias = "test_cloud_field_alias2"; + + SchemaMeta::Table table; + table.name = "test_cloud_table_name"; + table.alias = "test_cloud_table_alias"; + table.fields.emplace_back(field1); + table.fields.emplace_back(field2); + + SchemaMeta::Database database; + database.name = TEST_CLOUD_STORE; + database.alias = "test_cloud_database_alias"; + database.tables.emplace_back(table); + + schemaMeta_.version = 1; + schemaMeta_.databases.emplace_back(database); +} + void CloudDataTest::SetUpTestCase(void) { MetaDataManager::GetInstance().Initialize(dbStoreMock_, nullptr, [](const auto &, auto) { @@ -157,6 +161,7 @@ void CloudDataTest::SetUp() storeMetaData.user = std::to_string(DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(storeMetaData.tokenId)); MetaDataManager::GetInstance().SaveMeta(storeMetaData.GetKey(), storeMetaData); + InitSchemaMeta(); } void CloudDataTest::TearDown() {} @@ -175,14 +180,15 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) auto cloudInfo = cloudServerMock->GetServerInfo( DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(OHOS::IPCSkeleton::GetCallingTokenID())); ASSERT_TRUE(MetaDataManager::GetInstance().DelMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), true)); - StoreMetaData storeMetaData; + SchemaMeta schemaMeta; ASSERT_FALSE( - MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); + MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); CloudEvent::StoreInfo storeInfo { OHOS::IPCSkeleton::GetCallingTokenID(), TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); EventCenter::GetInstance().PostEvent(move(event)); ASSERT_TRUE( - MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); + MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); + ASSERT_EQ(to_string(schemaMeta.Marshall()), to_string(schemaMeta_.Marshall())); } } // namespace DistributedDataTest } // namespace OHOS -- Gitee From 3bdbe182391e07a64447f81a8116d5e65ec8c85c Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 17 May 2023 18:01:13 +0800 Subject: [PATCH 064/437] refactor:optimize per and fix:test Signed-off-by: htt1997 --- .../framework/cloud/cloud_event.cpp | 2 +- .../framework/include/cloud/cloud_event.h | 2 +- .../framework/include/store/general_store.h | 4 +-- .../service/cloud/cloud_service_impl.cpp | 36 +++++++++++-------- .../service/rdb/rdb_general_store.cpp | 8 +---- .../service/rdb/rdb_general_store.h | 3 +- .../service/test/cloud_data_test.cpp | 1 + 7 files changed, 27 insertions(+), 29 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_event.cpp b/services/distributeddataservice/framework/cloud/cloud_event.cpp index 11f43a39..cb2604bd 100644 --- a/services/distributeddataservice/framework/cloud/cloud_event.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_event.cpp @@ -26,7 +26,7 @@ std::string CloudEvent::GetFeatureName() const return featureName_; } -CloudEvent::StoreInfo CloudEvent::GetStoreInfo() const +const CloudEvent::StoreInfo& CloudEvent::GetStoreInfo() const { return storeInfo_; } diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h index 47c873c9..e1f04f41 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -40,7 +40,7 @@ public: CloudEvent(int32_t evtId, StoreInfo storeInfo, const std::string &featureName = "relational_store"); ~CloudEvent() = default; std::string GetFeatureName() const; - StoreInfo GetStoreInfo() const; + const StoreInfo& GetStoreInfo() const; private: std::string featureName_; diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 097f8d9a..e31eb889 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -32,9 +32,7 @@ public: virtual ~GeneralStore() = default; - virtual int32_t Bind(std::shared_ptr cloudDb) = 0; - - virtual int32_t SetSchema(const SchemaMeta &schemaMeta) = 0; + virtual int32_t Bind(const SchemaMeta &schemaMeta, std::shared_ptr cloudDb) = 0; virtual int32_t Execute(const std::string &table, const std::string &sql) = 0; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 0163dfb8..f8fc003c 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -397,28 +397,34 @@ void CloudServiceImpl::GetSchema(const Event &event) } auto storeMeta = GetStoreMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, rdbEvent.GetStoreInfo().instanceId); + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGE("instance is nullptr"); + return; + } + auto database = std::find_if(schemaMeta.databases.begin(),schemaMeta.databases.end(), + [&rdbEvent](const auto &database){ + return database.name == rdbEvent.GetStoreInfo().storeName; + }); + if (database == schemaMeta.databases.end()) { + return; + } + ZLOGD("database: %{public}s sync start", database->name.c_str()); + auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, *database); + if (cloudDB == nullptr) { + ZLOGE("cloudDB is nullptr"); + return; + } AutoCache::Watchers watchers; auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers); if (store == nullptr) { ZLOGE("store is nullptr"); return; } - store->SetSchema(schemaMeta); - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("instance is nullptr"); - return; - } - for (auto &database : schemaMeta.databases) { - if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync */) { - continue; - } - ZLOGD("database: %{public}s sync start", database.name.c_str()); - // ConnectCloudDB and Bind to store - for (auto &table : database.tables) { - ZLOGD("table: %{public}s sync start", table.name.c_str()); - } + store->Bind(schemaMeta, cloudDB); + for (const auto &table : database->tables) { + ZLOGD("table: %{public}s sync start", table.name.c_str()); // do sync } return; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 496878bc..bd1f118c 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -138,15 +138,9 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } -int32_t RdbGeneralStore::Bind(std::shared_ptr cloudDb) +int32_t RdbGeneralStore::Bind(const SchemaMeta &schemaMeta, std::shared_ptr cloudDb) { cloudDb_ = std::move(cloudDb); return 0; } - -int32_t RdbGeneralStore::SetSchema(const SchemaMeta &schemaMeta) -{ - // SetSchema - return GeneralError::E_OK; -} } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index f1bd92cd..3d2fda30 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -39,8 +39,7 @@ public: using RdbManager = DistributedDB::RelationalStoreManager; explicit RdbGeneralStore(const StoreMetaData &metaData); - int32_t Bind(std::shared_ptr cloudDb) override; - int32_t SetSchema(const SchemaMeta &schemaMeta) override; + int32_t Bind(const SchemaMeta &schemaMeta, std::shared_ptr cloudDb) override; int32_t Execute(const std::string &table, const std::string &sql) override; int32_t BatchInsert(const std::string &table, VBuckets &&values) override; int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index ddee440e..781ed158 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -19,6 +19,7 @@ #include "account/account_delegate.h" #include "cloud/cloud_event.h" #include "cloud/cloud_server.h" +#include "cloud/schema_meta.h" #include "communicator/device_manager_adapter.h" #include "device_matrix.h" #include "eventcenter/event_center.h" -- Gitee From f5ae3f6fc8ca2175552b1183e982f084566575c8 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 18 May 2023 10:03:41 +0800 Subject: [PATCH 065/437] fix:ut test Signed-off-by: htt1997 --- .../distributeddataservice/service/test/cloud_data_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 781ed158..32057e30 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -90,6 +90,7 @@ SchemaMeta CloudServerMock::GetAppSchema(int32_t userId, const std::string &bund } std::shared_ptr CloudDataTest::dbStoreMock_ = std::make_shared(); +SchemaMeta CloudDataTest::schemaMeta_; void CloudDataTest::InitMetaData() { @@ -148,6 +149,7 @@ void CloudDataTest::TearDownTestCase() {} void CloudDataTest::SetUp() { InitMetaData(); + InitSchemaMeta(); MetaDataManager::GetInstance().SaveMeta(metaData_.GetKey(), metaData_); StoreMetaData storeMetaData; @@ -162,7 +164,6 @@ void CloudDataTest::SetUp() storeMetaData.user = std::to_string(DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(storeMetaData.tokenId)); MetaDataManager::GetInstance().SaveMeta(storeMetaData.GetKey(), storeMetaData); - InitSchemaMeta(); } void CloudDataTest::TearDown() {} -- Gitee From c429575805d7941d1c27754162bcf3dbb18d9985 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 18 May 2023 10:07:02 +0800 Subject: [PATCH 066/437] style:code check Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index f8fc003c..cd3c8d16 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -402,10 +402,10 @@ void CloudServiceImpl::GetSchema(const Event &event) ZLOGE("instance is nullptr"); return; } - auto database = std::find_if(schemaMeta.databases.begin(),schemaMeta.databases.end(), - [&rdbEvent](const auto &database){ - return database.name == rdbEvent.GetStoreInfo().storeName; - }); + auto database = + std::find_if(schemaMeta.databases.begin(), schemaMeta.databases.end(), [&rdbEvent](const auto &database) { + return database.name == rdbEvent.GetStoreInfo().storeName; + }); if (database == schemaMeta.databases.end()) { return; } -- Gitee From f9e8a5693ebbf14e68283c503573166fe3fc4bee Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 18 May 2023 20:51:52 +0800 Subject: [PATCH 067/437] style:Review comments modification Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 10 ++++++---- .../service/cloud/cloud_service_impl.h | 4 ++-- .../service/rdb/rdb_service_impl.cpp | 4 ++-- .../service/rdb/rdb_service_impl.h | 4 +++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index cd3c8d16..dc263d78 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -317,7 +317,7 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) }; } -SchemaMeta CloudServiceImpl::GetSchemaMata(int32_t userId, const std::string &bundleName, int32_t instanceId) +SchemaMeta CloudServiceImpl::GetSchemaMeta(int32_t userId, const std::string &bundleName, int32_t instanceId) { SchemaMeta schemaMeta; auto instance = CloudServer::GetInstance(); @@ -350,7 +350,7 @@ SchemaMeta CloudServiceImpl::GetSchemaMata(int32_t userId, const std::string &bu return schemaMeta; } -StoreMetaData CloudServiceImpl::GetStoreMata(int32_t userId, const std::string &bundleName, +StoreMetaData CloudServiceImpl::GetStoreMeta(int32_t userId, const std::string &bundleName, const std::string &storeName, int32_t instanceId) { StoreMetaData storeMetaData; @@ -391,11 +391,12 @@ void CloudServiceImpl::GetSchema(const Event &event) rdbEvent.GetStoreInfo().bundleName.c_str(), rdbEvent.GetStoreInfo().storeName.c_str(), rdbEvent.GetStoreInfo().instanceId); auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); - auto schemaMeta = GetSchemaMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); + auto schemaMeta = GetSchemaMeta(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); if (schemaMeta.databases.empty()) { + ZLOGD("bundleName:%{public}s no cloud database", rdbEvent.GetStoreInfo().bundleName.c_str()); return; } - auto storeMeta = GetStoreMata(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, + auto storeMeta = GetStoreMeta(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, rdbEvent.GetStoreInfo().instanceId); auto instance = CloudServer::GetInstance(); if (instance == nullptr) { @@ -407,6 +408,7 @@ void CloudServiceImpl::GetSchema(const Event &event) return database.name == rdbEvent.GetStoreInfo().storeName; }); if (database == schemaMeta.databases.end()) { + ZLOGD("database: %{public}s is not cloud database", database->name.c_str()); return; } diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 35121c57..d78ec9a4 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -60,8 +60,8 @@ private: void UpdateCloudInfo(CloudInfo &cloudInfo); void AddSchema(CloudInfo &cloudInfo); - SchemaMeta GetSchemaMata(int32_t userId, const std::string &bundleName, int32_t instanceId); - StoreMetaData GetStoreMata(int32_t userId, const std::string &bundleName, const std::string &storeName, + SchemaMeta GetSchemaMeta(int32_t userId, const std::string &bundleName, int32_t instanceId); + StoreMetaData GetStoreMeta(int32_t userId, const std::string &bundleName, const std::string &storeName, int32_t instanceId); int32_t GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo); int32_t GetCloudInfoFromMeta(CloudInfo &cloudInfo); diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index f7a9b2c7..1dfcc49b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -300,7 +300,7 @@ std::shared_ptr RdbServiceImpl::GetRdbSyncer(const RdbSyncerParam &pa auto syncer_ = std::make_shared(param, rdbObserver); StoreMetaData storeMetaData = GetStoreMetaData(param); MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData); - if (syncer_->Init(pid, uid, tokenId, storeMetaData) != 0) { + if (syncer_->Init(pid, uid, tokenId, storeMetaData) != RDB_OK) { return !syncers.empty(); } syncers[storeId] = syncer_; @@ -612,7 +612,7 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat return SetSecretKey(param, meta); } -bool RdbServiceImpl::SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta) +int32_t RdbServiceImpl::SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta) { SecretKeyMetaData newSecretKey; newSecretKey.storeType = meta.storeType; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index c9f3eb54..18dd29b2 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -98,8 +98,10 @@ private: void OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResult& result); int32_t CreateMetaData(const RdbSyncerParam ¶m, StoreMetaData &old); + StoreMetaData GetStoreMetaData(const RdbSyncerParam ¶m); - bool SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta); + + int32_t SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta); class DeathRecipientImpl : public IRemoteObject::DeathRecipient { public: -- Gitee From 31e0148bdcc8abf61172f4faa7a2f9a6da47b179 Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 18 May 2023 21:47:02 +0800 Subject: [PATCH 068/437] f Signed-off-by: hanlu --- conf/config.json | 3 + services/distributeddataservice/app/BUILD.gn | 1 + .../app/src/feature_stub_impl.cpp | 6 +- .../framework/feature/feature_system.cpp | 2 +- .../include/feature/feature_system.h | 6 +- .../distributeddataservice/service/BUILD.gn | 49 +------- .../service/data_share/BUILD.gn | 110 ++++++++++++++++++ .../data_share/common/rdb_delegate.cpp | 2 +- .../data_share/common/template_manager.cpp | 2 +- .../data_share/data_share_service_impl.cpp | 21 ++-- .../data_share/data_share_service_impl.h | 3 +- .../service/directory/BUILD.gn | 52 +++++++++ .../service/object/object_service_impl.cpp | 2 +- .../service/object/object_service_impl.h | 2 +- 14 files changed, 192 insertions(+), 69 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/BUILD.gn create mode 100644 services/distributeddataservice/service/directory/BUILD.gn diff --git a/conf/config.json b/conf/config.json index 6f13c2cf..cf89a760 100644 --- a/conf/config.json +++ b/conf/config.json @@ -20,6 +20,9 @@ }, { "lib": "libudmf_server.z.so" + }, + { + "lib": "libdata_share_service.z.so" } ], "bundleChecker": { diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 6fa9ba6a..70ac16dd 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -108,6 +108,7 @@ ohos_shared_library("distributeddataservice") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src/uninstaller:distributeddata_uninstaller_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:distributeddatasvc", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:distributeddata_directory", ] external_deps = [ diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index 0e640edd..ec203bea 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -13,6 +13,9 @@ * limitations under the License. */ #include "feature_stub_impl.h" + +#include "bootstrap.h" +#include "ipc_skeleton.h" namespace OHOS::DistributedData { FeatureStubImpl::FeatureStubImpl(std::shared_ptr feature) : featureImpl_(std::move(feature)) @@ -38,7 +41,8 @@ int32_t FeatureStubImpl::OnInitialize(std::shared_ptr executor) return -1; } featureImpl_->OnExecutor(std::move(executor)); - return featureImpl_->OnInitialize(); + return featureImpl_->OnInitialize( + { Bootstrap::GetInstance().GetProcessLabel(), static_cast(IPCSkeleton::GetSelfTokenID()) }); } int32_t FeatureStubImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index 49b69e8c..c1acd0ec 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -55,7 +55,7 @@ FeatureSystem::Feature::~Feature() { } -int32_t FeatureSystem::Feature::OnInitialize() +int32_t FeatureSystem::Feature::OnInitialize(const BinderInfo &binderInfo) { return E_OK; } diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index 6bb34530..2863d0ab 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -36,9 +36,13 @@ public: }; class API_EXPORT Feature { public: + struct BinderInfo { + std::string bundleName; + uint32_t localTokenId; + }; virtual ~Feature(); virtual int OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) = 0; - virtual int32_t OnInitialize(); + virtual int32_t OnInitialize(const BinderInfo &binderInfo); virtual int32_t OnExecutor(std::shared_ptr executors); virtual int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName); virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 8225d0a7..f2edaa30 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -25,10 +25,6 @@ config("module_public_config") { "cloud", "config/include", "crypto/include", - "data_share", - "data_share/strategies", - "data_share/common", - "data_share/data", "directory/include", "kvdb", "matrix/include", @@ -72,42 +68,6 @@ ohos_shared_library("distributeddatasvc") { "config/src/model/network_config.cpp", "config/src/model/protocol_config.cpp", "crypto/src/crypto_manager.cpp", - "data_share/common/bundle_mgr_proxy.cpp", - "data_share/common/db_delegate.cpp", - "data_share/common/div_strategy.cpp", - "data_share/common/kv_delegate.cpp", - "data_share/common/rdb_delegate.cpp", - "data_share/common/scheduler_manager.cpp", - "data_share/common/seq_strategy.cpp", - "data_share/common/template_manager.cpp", - "data_share/common/uri_utils.cpp", - "data_share/data/json_formatter.cpp", - "data_share/data/published_data.cpp", - "data_share/data/resultset_json_formatter.cpp", - "data_share/data/template_data.cpp", - "data_share/data_share_obs_proxy.cpp", - "data_share/data_share_service_impl.cpp", - "data_share/data_share_service_stub.cpp", - "data_share/data_share_types_util.cpp", - "data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp", - "data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp", - "data_share/strategies/delete_strategy.cpp", - "data_share/strategies/general/check_is_data_proxy_strategy.cpp", - "data_share/strategies/general/check_is_single_app_strategy.cpp", - "data_share/strategies/general/connect_extension_strategy.cpp", - "data_share/strategies/general/empty_strategy.cpp", - "data_share/strategies/general/load_config_common_strategy.cpp", - "data_share/strategies/general/load_config_data_info_strategy.cpp", - "data_share/strategies/general/load_config_from_bundle_info_strategy.cpp", - "data_share/strategies/general/permission_strategy.cpp", - "data_share/strategies/general/process_single_app_user_cross_strategy.cpp", - "data_share/strategies/get_data_strategy.cpp", - "data_share/strategies/insert_strategy.cpp", - "data_share/strategies/publish_strategy.cpp", - "data_share/strategies/query_strategy.cpp", - "data_share/strategies/subscribe_strategy.cpp", - "data_share/strategies/update_strategy.cpp", - "directory/src/directory_manager.cpp", "kvdb/auth_delegate.cpp", "kvdb/executor_factory.cpp", "kvdb/kvdb_exporter.cpp", @@ -147,7 +107,7 @@ ohos_shared_library("distributeddatasvc") { deps = [ "${kv_store_distributeddb_path}:distributeddb", "${relational_store_path}/interfaces/inner_api/cloud_data:cloud_data_inner", - "data_share/gaussdb_rd:gaussdb_rd", + "directory:distributeddata_directory", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", @@ -160,10 +120,7 @@ ohos_shared_library("distributeddatasvc") { "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", "c_utils:utils", - "data_share:datashare_common", "device_auth:deviceauth_sdk", "device_manager:devicemanagersdk", "hiviewdfx_hilog_native:libhilog", @@ -171,10 +128,6 @@ ohos_shared_library("distributeddatasvc") { "ipc:ipc_core", "kv_store:distributeddata_inner", "relational_store:native_rdb", - "relational_store:rdb_bms_adapter", - "relational_store:rdb_data_share_adapter", - "resource_management:global_resmgr", - "samgr:samgr_proxy", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn new file mode 100644 index 00000000..c192973b --- /dev/null +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -0,0 +1,110 @@ +# 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. +import("//build/ohos.gni") +import("//build/ohos_var.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") +config("module_public_config") { + visibility = [ ":*" ] + include_dirs = [ + ".", + "strategies", + "common", + "data", + "../directory/include", + "//third_party/json/single_include", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/include", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework/include", + "${datashare_path}/frameworks/native/common/include", + "${datashare_path}/interfaces/inner_api/common/include", + "${datashare_path}/interfaces/inner_api/consumer/include", + ] +} +group("build_module") { + deps = [ ":data_share_service" ] +} +ohos_shared_library("data_share_service") { + sources = [ + "common/bundle_mgr_proxy.cpp", + "common/db_delegate.cpp", + "common/div_strategy.cpp", + "common/kv_delegate.cpp", + "common/rdb_delegate.cpp", + "common/scheduler_manager.cpp", + "common/seq_strategy.cpp", + "common/template_manager.cpp", + "common/uri_utils.cpp", + "data/json_formatter.cpp", + "data/published_data.cpp", + "data/resultset_json_formatter.cpp", + "data/template_data.cpp", + "data_share_obs_proxy.cpp", + "data_share_service_impl.cpp", + "data_share_service_stub.cpp", + "data_share_types_util.cpp", + "strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp", + "strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp", + "strategies/delete_strategy.cpp", + "strategies/general/check_is_data_proxy_strategy.cpp", + "strategies/general/check_is_single_app_strategy.cpp", + "strategies/general/connect_extension_strategy.cpp", + "strategies/general/empty_strategy.cpp", + "strategies/general/load_config_common_strategy.cpp", + "strategies/general/load_config_data_info_strategy.cpp", + "strategies/general/load_config_from_bundle_info_strategy.cpp", + "strategies/general/permission_strategy.cpp", + "strategies/general/process_single_app_user_cross_strategy.cpp", + "strategies/get_data_strategy.cpp", + "strategies/insert_strategy.cpp", + "strategies/publish_strategy.cpp", + "strategies/query_strategy.cpp", + "strategies/subscribe_strategy.cpp", + "strategies/update_strategy.cpp", + ] + cflags = [ "-Wno-multichar" ] + + cflags_cc = [ "-fvisibility=hidden" ] + + configs = [ ":module_public_config" ] + + deps = [ + "gaussdb_rd:gaussdb_rd", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:distributeddata_directory", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_common", + "device_manager:devicemanagersdk", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "relational_store:native_rdb", + "relational_store:rdb_bms_adapter", + "relational_store:rdb_data_share_adapter", + "samgr:samgr_proxy", + ] + subsystem_name = "distributeddatamgr" + + part_name = "datamgr_service" +} diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 383fac2a..3965a58f 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -15,7 +15,7 @@ #define LOG_TAG "RdbAdaptor" #include "rdb_delegate.h" -#include "data/resultset_json_formatter.h" +#include "resultset_json_formatter.h" #include "log_print.h" #include "rdb_utils.h" #include "scheduler_manager.h" diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 7cd18c7d..f7541ef5 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -294,7 +294,7 @@ int RdbSubscriberManager::Notify( changeNode.data_.emplace_back(DistributedData::Serializable::Marshall(formatter)); } - ZLOGI("emit, size %{public}d %{private}s", val.size(), changeNode.uri_.c_str()); + ZLOGI("emit, size %{public}ul %{private}s", val.size(), changeNode.uri_.c_str()); for (auto &callback : val) { if (callback.enabled && callback.observer != nullptr) { callback.observer->OnChangeFromRdb(changeNode); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index d4bb77ee..921618e7 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -19,7 +19,6 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" -#include "bootstrap.h" #include "dataobs_mgr_client.h" #include "datashare_errno.h" #include "datashare_template.h" @@ -334,26 +333,22 @@ enum DataShareKvStoreType : int32_t { DISTRIBUTED_TYPE_BUTT }; -int32_t DataShareServiceImpl::OnInitialize() +int32_t DataShareServiceImpl::OnInitialize(const BinderInfo &binderInfo) { - auto token = IPCSkeleton::GetCallingTokenID(); - auto type = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(token); - if (type != OHOS::Security::AccessToken::TOKEN_NATIVE && type != OHOS::Security::AccessToken::TOKEN_SHELL) { - return EOK; - } + binderInfo_ = binderInfo; const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); - const auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(token); + const auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(binderInfo.localTokenId); DistributedData::StoreMetaData saveMeta; saveMeta.appType = "default"; saveMeta.storeId = "data_share_data_"; saveMeta.isAutoSync = false; saveMeta.isBackup = false; saveMeta.isEncrypt = false; - saveMeta.bundleName = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); - saveMeta.appId = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); + saveMeta.bundleName = binderInfo.bundleName; + saveMeta.appId = binderInfo.bundleName; saveMeta.user = std::to_string(userId); saveMeta.account = accountId; - saveMeta.tokenId = token; + saveMeta.tokenId = binderInfo.localTokenId; saveMeta.securityLevel = DistributedKv::SecurityLevel::S1; saveMeta.area = 1; saveMeta.uid = IPCSkeleton::GetCallingUid(); @@ -377,8 +372,8 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use saveMeta.isAutoSync = false; saveMeta.isBackup = false; saveMeta.isEncrypt = false; - saveMeta.bundleName = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); - saveMeta.appId = DistributedData::Bootstrap::GetInstance().GetProcessLabel(); + saveMeta.bundleName = binderInfo_.bundleName; + saveMeta.appId = binderInfo_.bundleName; saveMeta.user = user; saveMeta.account = account; saveMeta.tokenId = token; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 6ae6a0ae..2033008e 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -56,7 +56,7 @@ public: const int64_t subscriberId) override; std::vector DisablePubSubs(const std::vector &uris, const int64_t subscriberId) override; - int32_t OnInitialize() override; + int32_t OnInitialize(const BinderInfo &binderInfo) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; private: @@ -71,6 +71,7 @@ private: static Factory factory_; static constexpr int32_t ERROR = -1; PublishStrategy publishStrategy_; + BinderInfo binderInfo_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/directory/BUILD.gn b/services/distributeddataservice/service/directory/BUILD.gn new file mode 100644 index 00000000..aa216d78 --- /dev/null +++ b/services/distributeddataservice/service/directory/BUILD.gn @@ -0,0 +1,52 @@ +# 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. +import("//build/ohos.gni") +import("//build/ohos_var.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +config("module_public_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/include", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework/include", + ] +} + +group("build_module") { + deps = [ ":distributeddata_directory" ] +} + +ohos_shared_library("distributeddata_directory") { + sources = [ "src/directory_manager.cpp" ] + cflags = [ "-Wno-multichar" ] + + cflags_cc = [ "-fvisibility=hidden" ] + + configs = [ ":module_public_config" ] + + deps = [ + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] + subsystem_name = "distributeddatamgr" + part_name = "datamgr_service" +} diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index 7ae417c3..b2f98214 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -71,7 +71,7 @@ int32_t ObjectServiceImpl::ObjectStoreSave(const std::string &bundleName, const return status; } -int32_t ObjectServiceImpl::OnInitialize() +int32_t ObjectServiceImpl::OnInitialize(const BinderInfo &binderInfo) { ZLOGI("Initialize"); auto localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; diff --git a/services/distributeddataservice/service/object/object_service_impl.h b/services/distributeddataservice/service/object/object_service_impl.h index 932ea29a..2a49e78e 100644 --- a/services/distributeddataservice/service/object/object_service_impl.h +++ b/services/distributeddataservice/service/object/object_service_impl.h @@ -41,7 +41,7 @@ public: void Clear(); int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; - int32_t OnInitialize() override; + int32_t OnInitialize(const BinderInfo &binderInfo) override; int32_t OnExecutor(std::shared_ptr executors) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; -- Gitee From ddf038473d88335927e7f0286ecd9376ea2c4e04 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 09:16:36 +0800 Subject: [PATCH 069/437] f Signed-off-by: hanlu --- .../distributeddataservice/service/rdb/rdb_service_impl.cpp | 2 +- services/distributeddataservice/service/rdb/rdb_service_impl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 525aed43..0190060d 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -548,7 +548,7 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) return RDB_OK; } -int32_t RdbServiceImpl::OnInitialize() +int32_t RdbServiceImpl::OnInitialize(const BinderInfo &binderInfo) { return RDB_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index af2d788d..b4619846 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -58,7 +58,7 @@ public: int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; - int32_t OnInitialize() override; + int32_t OnInitialize(const BinderInfo &binderInfo) override; int32_t GetSchema(const RdbSyncerParam ¶m) override; int32_t OnExecutor(std::shared_ptr executors) override; -- Gitee From dc82e209c635f1aced721715770c1823f971f437 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 09:26:07 +0800 Subject: [PATCH 070/437] f Signed-off-by: hanlu --- services/distributeddataservice/app/BUILD.gn | 2 +- .../distributeddataservice/service/data_share/BUILD.gn | 8 ++++---- .../distributeddataservice/service/directory/BUILD.gn | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 70ac16dd..8dfef646 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -108,7 +108,7 @@ ohos_shared_library("distributeddataservice") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src/uninstaller:distributeddata_uninstaller_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:distributeddatasvc", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:distributeddata_directory", + "../service/directory:distributeddata_directory", ] external_deps = [ diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index c192973b..1daed73b 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -79,10 +79,10 @@ ohos_shared_library("data_share_service") { deps = [ "gaussdb_rd:gaussdb_rd", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:distributeddata_directory", + "../../adapter:distributeddata_adapter", + "../../adapter/utils:distributeddata_utils_static", + "../../framework:distributeddatasvcfwk", + "../directory:distributeddata_directory", ] external_deps = [ diff --git a/services/distributeddataservice/service/directory/BUILD.gn b/services/distributeddataservice/service/directory/BUILD.gn index aa216d78..db1b14c6 100644 --- a/services/distributeddataservice/service/directory/BUILD.gn +++ b/services/distributeddataservice/service/directory/BUILD.gn @@ -37,9 +37,9 @@ ohos_shared_library("distributeddata_directory") { configs = [ ":module_public_config" ] deps = [ - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", + "../../adapter:distributeddata_adapter", + "../../adapter/utils:distributeddata_utils_static", + "../../framework:distributeddatasvcfwk", ] external_deps = [ -- Gitee From eb4e86a87a648bdc5d84cb9053aeae2693d830f9 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 09:34:30 +0800 Subject: [PATCH 071/437] f Signed-off-by: hanlu --- services/distributeddataservice/service/data_share/BUILD.gn | 6 +++--- services/distributeddataservice/service/directory/BUILD.gn | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 1daed73b..caa9c27b 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -22,9 +22,9 @@ config("module_public_config") { "data", "../directory/include", "//third_party/json/single_include", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/include", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework/include", + "../../adapter/include", + "../../app/src", + "../../framework/include", "${datashare_path}/frameworks/native/common/include", "${datashare_path}/interfaces/inner_api/common/include", "${datashare_path}/interfaces/inner_api/consumer/include", diff --git a/services/distributeddataservice/service/directory/BUILD.gn b/services/distributeddataservice/service/directory/BUILD.gn index db1b14c6..7e2477fa 100644 --- a/services/distributeddataservice/service/directory/BUILD.gn +++ b/services/distributeddataservice/service/directory/BUILD.gn @@ -18,9 +18,9 @@ config("module_public_config") { visibility = [ ":*" ] include_dirs = [ "include", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/include", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework/include", + "../../adapter/include", + "../../app/src", + "../../framework/include", ] } -- Gitee From 571b921b971a0dd76ec89bda60c7ff4821931074 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 09:49:54 +0800 Subject: [PATCH 072/437] f Signed-off-by: hanlu --- bundle.json | 4 +++- services/distributeddataservice/service/data_share/BUILD.gn | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bundle.json b/bundle.json index a5d2bd57..caee502d 100644 --- a/bundle.json +++ b/bundle.json @@ -90,7 +90,9 @@ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:build_module", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:build_module", "//foundation/distributeddatamgr/datamgr_service/conf:build_module", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share/gaussdb_rd:build_module" + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:build_module", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share/gaussdb_rd:build_module" ], "inner_kits": [], "test": [ diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index caa9c27b..4dafa8e0 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -78,11 +78,11 @@ ohos_shared_library("data_share_service") { configs = [ ":module_public_config" ] deps = [ - "gaussdb_rd:gaussdb_rd", "../../adapter:distributeddata_adapter", "../../adapter/utils:distributeddata_utils_static", "../../framework:distributeddatasvcfwk", "../directory:distributeddata_directory", + "gaussdb_rd:gaussdb_rd", ] external_deps = [ -- Gitee From 3054e8b79084933adeb9f812529e1a2b25028a0e Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 10:00:19 +0800 Subject: [PATCH 073/437] f Signed-off-by: hanlu --- services/distributeddataservice/app/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 8dfef646..53f2884e 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -100,6 +100,7 @@ ohos_shared_library("distributeddataservice") { configs = [ ":module_private_config" ] deps = [ "${kv_store_distributeddb_path}:distributeddb", + "../service/directory:distributeddata_directory", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/broadcaster:distributeddata_broadcaster_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", @@ -108,7 +109,6 @@ ohos_shared_library("distributeddataservice") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/app/src/uninstaller:distributeddata_uninstaller_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:distributeddatasvc", - "../service/directory:distributeddata_directory", ] external_deps = [ -- Gitee From 96c33757a17e9bb26a5d3149db49ae2444d56269 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 10:36:58 +0800 Subject: [PATCH 074/437] f Signed-off-by: hanlu --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- .../distributeddataservice/service/cloud/cloud_service_impl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 0163dfb8..5744ed0e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -190,7 +190,7 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str return SUCCESS; } -int32_t CloudServiceImpl::OnInitialize() +int32_t CloudServiceImpl::OnInitialize(const BinderInfo &binderInfo) { FeatureInit(); Execute(GetCloudTask(0, 0)); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 35121c57..2d94fcc8 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -34,7 +34,7 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; - int32_t OnInitialize() override; + int32_t OnInitialize(const BinderInfo &binderInfo) override; int32_t OnExecutor(std::shared_ptr executor) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; -- Gitee From 184f05d4e9296d807d19678bba005d73daa5a4e4 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 11:31:33 +0800 Subject: [PATCH 075/437] f Signed-off-by: hanlu --- services/distributeddataservice/service/test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 97d837b7..beb45336 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -111,6 +111,7 @@ ohos_unittest("DirectoryManagerTest") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:distributeddatasvc", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:distributeddata_directory", "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] -- Gitee From 845124732d1ff10aaee9565b967f1cd2f8cf0a34 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 19 May 2023 11:42:15 +0800 Subject: [PATCH 076/437] warn fix Signed-off-by: niudongyao --- .../service/data_share/common/template_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 7cd18c7d..9c069076 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -294,7 +294,7 @@ int RdbSubscriberManager::Notify( changeNode.data_.emplace_back(DistributedData::Serializable::Marshall(formatter)); } - ZLOGI("emit, size %{public}d %{private}s", val.size(), changeNode.uri_.c_str()); + ZLOGI("emit, size %{public}lu %{private}s", val.size(), changeNode.uri_.c_str()); for (auto &callback : val) { if (callback.enabled && callback.observer != nullptr) { callback.observer->OnChangeFromRdb(changeNode); -- Gitee From a1f407977ad94a9eacceff838f82e0a6f8206544 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 14:19:21 +0800 Subject: [PATCH 077/437] f Signed-off-by: hanlu --- bundle.json | 1 - services/distributeddataservice/app/BUILD.gn | 1 - .../app/src/kvstore_meta_manager.cpp | 2 +- .../distributeddataservice/framework/BUILD.gn | 6 ++- .../directory}/directory_manager.cpp | 5 +- .../include/directory}/directory_manager.h | 0 .../distributeddataservice/service/BUILD.gn | 2 - .../service/backup/src/backup_manager.cpp | 5 +- .../service/bootstrap/src/bootstrap.cpp | 5 +- .../config/include/model/directory_config.h | 2 +- .../service/data_share/BUILD.gn | 1 - .../service/data_share/common/kv_delegate.cpp | 5 +- .../data_share/common/template_manager.cpp | 2 +- .../data_share/data_share_service_impl.cpp | 2 +- .../service/directory/BUILD.gn | 52 ------------------- .../service/kvdb/kvdb_exporter.cpp | 2 +- .../service/kvdb/kvdb_service_impl.cpp | 4 +- .../service/kvdb/store_cache.cpp | 3 +- .../service/kvdb/upgrade.cpp | 6 +-- .../service/object/object_service_impl.cpp | 2 +- .../service/rdb/rdb_service_impl.cpp | 2 +- .../service/rdb/rdb_syncer.cpp | 2 +- .../service/test/BUILD.gn | 1 - .../service/test/directory_manager_test.cpp | 2 +- 24 files changed, 32 insertions(+), 83 deletions(-) rename services/distributeddataservice/{service/directory/src => framework/directory}/directory_manager.cpp (99%) rename services/distributeddataservice/{service/directory/include => framework/include/directory}/directory_manager.h (100%) delete mode 100644 services/distributeddataservice/service/directory/BUILD.gn diff --git a/bundle.json b/bundle.json index caee502d..2c97e047 100644 --- a/bundle.json +++ b/bundle.json @@ -91,7 +91,6 @@ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:build_module", "//foundation/distributeddatamgr/datamgr_service/conf:build_module", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:build_module", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share/gaussdb_rd:build_module" ], "inner_kits": [], diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 53f2884e..6fa9ba6a 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -100,7 +100,6 @@ ohos_shared_library("distributeddataservice") { configs = [ ":module_private_config" ] deps = [ "${kv_store_distributeddb_path}:distributeddb", - "../service/directory:distributeddata_directory", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/broadcaster:distributeddata_broadcaster_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index 7fb54c86..c281c7a2 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -28,7 +28,7 @@ #include "crypto_manager.h" #include "device_manager_adapter.h" #include "device_matrix.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "dump_helper.h" #include "eventcenter/event_center.h" #include "kvstore_data_service.h" diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 09a242ba..d9293018 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("distributeddatasvcfwk") { "cloud/cloud_server.cpp", "cloud/schema_meta.cpp", "cloud/subscription.cpp", + "directory/directory_manager.cpp", "eventcenter/event.cpp", "eventcenter/event_center.cpp", "feature/feature_system.cpp", @@ -84,7 +85,10 @@ ohos_shared_library("distributeddatasvcfwk") { deps = [ "//third_party/openssl:libcrypto_shared" ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "access_token:libaccesstoken_sdk", + ] subsystem_name = "distributeddatamgr" part_name = "datamgr_service" diff --git a/services/distributeddataservice/service/directory/src/directory_manager.cpp b/services/distributeddataservice/framework/directory/directory_manager.cpp similarity index 99% rename from services/distributeddataservice/service/directory/src/directory_manager.cpp rename to services/distributeddataservice/framework/directory/directory_manager.cpp index bba79049..a3b0458b 100644 --- a/services/distributeddataservice/service/directory/src/directory_manager.cpp +++ b/services/distributeddataservice/framework/directory/directory_manager.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ #define LOG_TAG "DirectoryManager" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include -#include - #include +#include #include "accesstoken_kit.h" #include "log_print.h" diff --git a/services/distributeddataservice/service/directory/include/directory_manager.h b/services/distributeddataservice/framework/include/directory/directory_manager.h similarity index 100% rename from services/distributeddataservice/service/directory/include/directory_manager.h rename to services/distributeddataservice/framework/include/directory/directory_manager.h diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index f2edaa30..77641b8d 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -25,7 +25,6 @@ config("module_public_config") { "cloud", "config/include", "crypto/include", - "directory/include", "kvdb", "matrix/include", "object", @@ -107,7 +106,6 @@ ohos_shared_library("distributeddatasvc") { deps = [ "${kv_store_distributeddb_path}:distributeddb", "${relational_store_path}/interfaces/inner_api/cloud_data:cloud_data_inner", - "directory:distributeddata_directory", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", diff --git a/services/distributeddataservice/service/backup/src/backup_manager.cpp b/services/distributeddataservice/service/backup/src/backup_manager.cpp index 5c52cbd7..0a904e1b 100644 --- a/services/distributeddataservice/service/backup/src/backup_manager.cpp +++ b/services/distributeddataservice/service/backup/src/backup_manager.cpp @@ -18,10 +18,11 @@ #include #include #include + #include "backuprule/backup_rule_manager.h" -#include "device_manager_adapter.h" #include "crypto_manager.h" -#include "directory_manager.h" +#include "device_manager_adapter.h" +#include "directory/directory_manager.h" #include "log_print.h" #include "metadata/meta_data_manager.h" #include "types.h" diff --git a/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp b/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp index 6cdd57ab..8f958cf3 100644 --- a/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp +++ b/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp @@ -16,11 +16,12 @@ #include "bootstrap.h" #include -#include "backuprule/backup_rule_manager.h" + #include "backup_manager.h" +#include "backuprule/backup_rule_manager.h" #include "checker/checker_manager.h" #include "config_factory.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "log_print.h" namespace OHOS { namespace DistributedData { diff --git a/services/distributeddataservice/service/config/include/model/directory_config.h b/services/distributeddataservice/service/config/include/model/directory_config.h index baa7b05c..03422499 100644 --- a/services/distributeddataservice/service/config/include/model/directory_config.h +++ b/services/distributeddataservice/service/config/include/model/directory_config.h @@ -15,7 +15,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_DIRECTORY_CONFIG_H #define OHOS_DISTRIBUTED_DATA_SERVICES_CONFIG_MODEL_DIRECTORY_CONFIG_H -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "serializable/serializable.h" namespace OHOS { namespace DistributedData { diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 4dafa8e0..b8efaf61 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -81,7 +81,6 @@ ohos_shared_library("data_share_service") { "../../adapter:distributeddata_adapter", "../../adapter/utils:distributeddata_utils_static", "../../framework:distributeddatasvcfwk", - "../directory:distributeddata_directory", "gaussdb_rd:gaussdb_rd", ] diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index fe645eba..c17166cd 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -14,10 +14,11 @@ */ #define LOG_TAG "KvAdaptor" #include "kv_delegate.h" + #include "datashare_errno.h" -#include "directory_manager.h" -#include "grd_document/grd_document_api.h" +#include "directory/directory_manager.h" #include "grd_base/grd_error.h" +#include "grd_document/grd_document_api.h" #include "ipc_skeleton.h" #include "log_print.h" diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index f7541ef5..4b573349 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -294,7 +294,7 @@ int RdbSubscriberManager::Notify( changeNode.data_.emplace_back(DistributedData::Serializable::Marshall(formatter)); } - ZLOGI("emit, size %{public}ul %{private}s", val.size(), changeNode.uri_.c_str()); + ZLOGI("emit, size %{public}zu %{private}s", val.size(), changeNode.uri_.c_str()); for (auto &callback : val) { if (callback.enabled && callback.observer != nullptr) { callback.observer->OnChangeFromRdb(changeNode); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 921618e7..7604b8a3 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -23,7 +23,7 @@ #include "datashare_errno.h" #include "datashare_template.h" #include "delete_strategy.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "get_data_strategy.h" #include "hap_token_info.h" #include "insert_strategy.h" diff --git a/services/distributeddataservice/service/directory/BUILD.gn b/services/distributeddataservice/service/directory/BUILD.gn deleted file mode 100644 index 7e2477fa..00000000 --- a/services/distributeddataservice/service/directory/BUILD.gn +++ /dev/null @@ -1,52 +0,0 @@ -# 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. -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") - -config("module_public_config") { - visibility = [ ":*" ] - include_dirs = [ - "include", - "../../adapter/include", - "../../app/src", - "../../framework/include", - ] -} - -group("build_module") { - deps = [ ":distributeddata_directory" ] -} - -ohos_shared_library("distributeddata_directory") { - sources = [ "src/directory_manager.cpp" ] - cflags = [ "-Wno-multichar" ] - - cflags_cc = [ "-fvisibility=hidden" ] - - configs = [ ":module_public_config" ] - - deps = [ - "../../adapter:distributeddata_adapter", - "../../adapter/utils:distributeddata_utils_static", - "../../framework:distributeddatasvcfwk", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - ] - subsystem_name = "distributeddatamgr" - part_name = "datamgr_service" -} diff --git a/services/distributeddataservice/service/kvdb/kvdb_exporter.cpp b/services/distributeddataservice/service/kvdb/kvdb_exporter.cpp index 4b0c2e7f..22532d53 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_exporter.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_exporter.cpp @@ -16,7 +16,7 @@ #include "kvdb_exporter.h" #include "backup_manager.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "log_print.h" #include "reporter.h" #include "store_cache.h" diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 8428cb58..ccb683f7 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -26,15 +26,15 @@ #include "communication_strategy.h" #include "crypto_manager.h" #include "device_manager_adapter.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "eventcenter/event_center.h" #include "ipc_skeleton.h" #include "log_print.h" #include "matrix_event.h" #include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" -#include "query_helper.h" #include "permit_delegate.h" +#include "query_helper.h" #include "upgrade.h" #include "utils/anonymous.h" #include "utils/constant.h" diff --git a/services/distributeddataservice/service/kvdb/store_cache.cpp b/services/distributeddataservice/service/kvdb/store_cache.cpp index 093e8e5a..620c5e9e 100644 --- a/services/distributeddataservice/service/kvdb/store_cache.cpp +++ b/services/distributeddataservice/service/kvdb/store_cache.cpp @@ -14,10 +14,11 @@ */ #define LOG_TAG "StoreCache" #include "store_cache.h" + #include "account/account_delegate.h" #include "crypto_manager.h" #include "device_matrix.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/secret_key_meta_data.h" diff --git a/services/distributeddataservice/service/kvdb/upgrade.cpp b/services/distributeddataservice/service/kvdb/upgrade.cpp index ea40a6bd..38a370e8 100644 --- a/services/distributeddataservice/service/kvdb/upgrade.cpp +++ b/services/distributeddataservice/service/kvdb/upgrade.cpp @@ -18,14 +18,14 @@ #include #include +#include "accesstoken_kit.h" #include "crypto_manager.h" -#include "metadata/secret_key_meta_data.h" #include "device_manager_adapter.h" +#include "directory/directory_manager.h" #include "log_print.h" #include "metadata/meta_data_manager.h" +#include "metadata/secret_key_meta_data.h" #include "store_cache.h" -#include "accesstoken_kit.h" -#include "directory_manager.h" namespace OHOS::DistributedKv { using namespace OHOS::DistributedData; using system_clock = std::chrono::system_clock; diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index b2f98214..c17e1d03 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -23,7 +23,7 @@ #include "bootstrap.h" #include "checker/checker_manager.h" #include "device_manager_adapter.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "log_print.h" #include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 0190060d..5a73ff78 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -20,7 +20,7 @@ #include "cloud/cloud_event.h" #include "communicator/device_manager_adapter.h" #include "crypto_manager.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "eventcenter/event_center.h" #include "ipc_skeleton.h" #include "log_print.h" diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index f8f6192a..b03c65ca 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -22,7 +22,7 @@ #include "checker/checker_manager.h" #include "crypto_manager.h" #include "device_manager_adapter.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "kvstore_utils.h" #include "log_print.h" #include "metadata/appid_meta_data.h" diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index beb45336..97d837b7 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -111,7 +111,6 @@ ohos_unittest("DirectoryManagerTest") { "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:distributeddatasvc", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/directory:distributeddata_directory", "//foundation/distributeddatamgr/kv_store/interfaces/innerkits/distributeddata:distributeddata_inner", "//third_party/googletest:gtest_main", ] diff --git a/services/distributeddataservice/service/test/directory_manager_test.cpp b/services/distributeddataservice/service/test/directory_manager_test.cpp index ae9cb648..d9eed29a 100644 --- a/services/distributeddataservice/service/test/directory_manager_test.cpp +++ b/services/distributeddataservice/service/test/directory_manager_test.cpp @@ -16,7 +16,7 @@ #include #include "accesstoken_kit.h" #include "bootstrap.h" -#include "directory_manager.h" +#include "directory/directory_manager.h" #include "nativetoken_kit.h" #include "types.h" -- Gitee From 4932d3bbe288b682649486e006e8dbc5f0c6c79a Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 14:23:05 +0800 Subject: [PATCH 078/437] f Signed-off-by: hanlu --- services/distributeddataservice/framework/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index d9293018..c051f1eb 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -86,8 +86,8 @@ ohos_shared_library("distributeddatasvcfwk") { deps = [ "//third_party/openssl:libcrypto_shared" ] external_deps = [ - "hiviewdfx_hilog_native:libhilog", "access_token:libaccesstoken_sdk", + "hiviewdfx_hilog_native:libhilog", ] subsystem_name = "distributeddatamgr" -- Gitee From 5d3fcfbf7cc407d293122cb4e513126725490c2e Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 16:09:28 +0800 Subject: [PATCH 079/437] f Signed-off-by: hanlu --- .../app/src/feature_stub_impl.cpp | 6 +++--- .../framework/feature/feature_system.cpp | 12 ++++++------ .../framework/include/feature/feature_system.h | 11 ++++++----- .../service/cloud/cloud_service_impl.cpp | 8 ++++---- .../service/cloud/cloud_service_impl.h | 4 ++-- .../service/data_share/BUILD.gn | 1 - .../service/data_share/common/template_manager.cpp | 7 ++----- .../service/data_share/data_share_service_impl.cpp | 14 +++++++------- .../service/data_share/data_share_service_impl.h | 4 ++-- .../service/kvdb/kvdb_service_impl.cpp | 10 +++++----- .../service/kvdb/kvdb_service_impl.h | 2 +- .../service/object/object_service_impl.cpp | 7 +------ .../service/object/object_service_impl.h | 4 +--- .../service/rdb/rdb_service_impl.cpp | 6 +++--- .../service/rdb/rdb_service_impl.h | 4 ++-- 15 files changed, 45 insertions(+), 55 deletions(-) diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index ec203bea..f1f52b91 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -40,9 +40,9 @@ int32_t FeatureStubImpl::OnInitialize(std::shared_ptr executor) if (featureImpl_ == nullptr) { return -1; } - featureImpl_->OnExecutor(std::move(executor)); - return featureImpl_->OnInitialize( - { Bootstrap::GetInstance().GetProcessLabel(), static_cast(IPCSkeleton::GetSelfTokenID()) }); + featureImpl_->OnBind({ Bootstrap::GetInstance().GetProcessLabel(), + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor)}); + return featureImpl_->OnInitialize(); } int32_t FeatureStubImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index c1acd0ec..74907ec8 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -55,12 +55,7 @@ FeatureSystem::Feature::~Feature() { } -int32_t FeatureSystem::Feature::OnInitialize(const BinderInfo &binderInfo) -{ - return E_OK; -} - -int32_t FeatureSystem::Feature::OnExecutor(std::shared_ptr executors) +int32_t FeatureSystem::Feature::OnInitialize() { return E_OK; } @@ -106,5 +101,10 @@ int32_t FeatureSystem::Feature::OnReady(const std::string &device) { return E_OK; } + +int32_t FeatureSystem::Feature::OnBind(const FeatureSystem::Feature::BindInfo &bindInfo) +{ + return E_OK; +} } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index 2863d0ab..d549cc6d 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -36,14 +36,15 @@ public: }; class API_EXPORT Feature { public: - struct BinderInfo { - std::string bundleName; - uint32_t localTokenId; + struct BindInfo { + std::string selfName; + uint32_t selfTokenId; + std::shared_ptr executors; }; virtual ~Feature(); virtual int OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply) = 0; - virtual int32_t OnInitialize(const BinderInfo &binderInfo); - virtual int32_t OnExecutor(std::shared_ptr executors); + virtual int32_t OnInitialize(); + virtual int32_t OnBind(const BindInfo &bindInfo); virtual int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName); virtual int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); virtual int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 5744ed0e..b605daf5 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -190,20 +190,20 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str return SUCCESS; } -int32_t CloudServiceImpl::OnInitialize(const BinderInfo &binderInfo) +int32_t CloudServiceImpl::OnInitialize() { FeatureInit(); Execute(GetCloudTask(0, 0)); return E_OK; } -int32_t CloudServiceImpl::OnExecutor(std::shared_ptr executor) +int32_t CloudServiceImpl::OnBind(const BindInfo &info) { - if (executor_ != nullptr || executor == nullptr) { + if (executor_ != nullptr || info.executors == nullptr) { return E_INVALID_ARGS; } - executor_ = std::move(executor); + executor_ = std::move(info.executors); return E_OK; } diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 2d94fcc8..5bbc2507 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -34,8 +34,8 @@ public: int32_t ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) override; int32_t Clean(const std::string &id, const std::map &actions) override; int32_t NotifyDataChange(const std::string &id, const std::string &bundleName) override; - int32_t OnInitialize(const BinderInfo &binderInfo) override; - int32_t OnExecutor(std::shared_ptr executor) override; + int32_t OnInitialize() override; + int32_t OnBind(const BindInfo &info) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; private: diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index b8efaf61..b9490bbc 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -20,7 +20,6 @@ config("module_public_config") { "strategies", "common", "data", - "../directory/include", "//third_party/json/single_include", "../../adapter/include", "../../app/src", diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 4b573349..fabed5f1 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -127,14 +127,11 @@ int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const Templat { int result = E_OK; Key key(uri, tplId.subscriberId_, tplId.bundleName_); - rdbCache_.Compute(key, [&observer, &context, &result, this](const auto &key, std::vector &value) { + rdbCache_.Compute(key, [&observer, &context, this](const auto &key, std::vector &value) { ZLOGI("add subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), context->callerTokenId); std::vector node; node.emplace_back(observer, context->callerTokenId); - result = Notify(key, node, context->calledSourceDir, context->version); - if (result != E_OK) { - return false; - } + Notify(key, node, context->calledSourceDir, context->version); value.emplace_back(observer, context->callerTokenId); if (GetEnableObserverCount(key) == 1) { SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 7604b8a3..3209b7cc 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -333,22 +333,22 @@ enum DataShareKvStoreType : int32_t { DISTRIBUTED_TYPE_BUTT }; -int32_t DataShareServiceImpl::OnInitialize(const BinderInfo &binderInfo) +int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) { binderInfo_ = binderInfo; const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); - const auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(binderInfo.localTokenId); + const auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(binderInfo.selfTokenId); DistributedData::StoreMetaData saveMeta; saveMeta.appType = "default"; saveMeta.storeId = "data_share_data_"; saveMeta.isAutoSync = false; saveMeta.isBackup = false; saveMeta.isEncrypt = false; - saveMeta.bundleName = binderInfo.bundleName; - saveMeta.appId = binderInfo.bundleName; + saveMeta.bundleName = binderInfo.selfName; + saveMeta.appId = binderInfo.selfName; saveMeta.user = std::to_string(userId); saveMeta.account = accountId; - saveMeta.tokenId = binderInfo.localTokenId; + saveMeta.tokenId = binderInfo.selfTokenId; saveMeta.securityLevel = DistributedKv::SecurityLevel::S1; saveMeta.area = 1; saveMeta.uid = IPCSkeleton::GetCallingUid(); @@ -372,8 +372,8 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use saveMeta.isAutoSync = false; saveMeta.isBackup = false; saveMeta.isEncrypt = false; - saveMeta.bundleName = binderInfo_.bundleName; - saveMeta.appId = binderInfo_.bundleName; + saveMeta.bundleName = binderInfo_.selfName; + saveMeta.appId = binderInfo_.selfName; saveMeta.user = user; saveMeta.account = account; saveMeta.tokenId = token; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 2033008e..74dc44b3 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -56,7 +56,7 @@ public: const int64_t subscriberId) override; std::vector DisablePubSubs(const std::vector &uris, const int64_t subscriberId) override; - int32_t OnInitialize(const BinderInfo &binderInfo) override; + int32_t OnBind(const BindInfo &binderInfo) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; private: @@ -71,7 +71,7 @@ private: static Factory factory_; static constexpr int32_t ERROR = -1; PublishStrategy publishStrategy_; - BinderInfo binderInfo_; + BindInfo binderInfo_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index ccb683f7..e63f2dcd 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -790,12 +790,12 @@ size_t KVDBServiceImpl::GetSyncDataSize(const std::string &deviceId) return totalSize; } -int32_t KVDBServiceImpl::OnExecutor(std::shared_ptr executors) +int32_t KVDBServiceImpl::OnBind(const BindInfo &bindInfo) { - executors_ = executors; - storeCache_.SetThreadPool(executors); - KvStoreSyncManager::GetInstance()->SetThreadPool(executors); - ZLOGE("onexecutor:%{public}p", executors.get()); + executors_ = bindInfo.executors; + storeCache_.SetThreadPool(bindInfo.executors); + KvStoreSyncManager::GetInstance()->SetThreadPool(bindInfo.executors); + ZLOGE("onexecutor:%{public}p", bindInfo.executors.get()); return 0; } } // namespace OHOS::DistributedKv \ No newline at end of file diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index b1c3e5fd..861cd068 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -53,7 +53,7 @@ public: Status Subscribe(const AppId &appId, const StoreId &storeId, sptr observer) override; Status Unsubscribe(const AppId &appId, const StoreId &storeId, sptr observer) override; Status GetBackupPassword(const AppId &appId, const StoreId &storeId, std::vector &password) override; - int32_t OnExecutor(std::shared_ptr executors) override; + int32_t OnBind(const BindInfo &bindInfo) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index c17e1d03..ccd1e57a 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -71,7 +71,7 @@ int32_t ObjectServiceImpl::ObjectStoreSave(const std::string &bundleName, const return status; } -int32_t ObjectServiceImpl::OnInitialize(const BinderInfo &binderInfo) +int32_t ObjectServiceImpl::OnInitialize() { ZLOGI("Initialize"); auto localDeviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; @@ -277,9 +277,4 @@ int32_t ObjectServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, con ObjectServiceImpl::ObjectServiceImpl() { } -int32_t ObjectServiceImpl::OnExecutor(std::shared_ptr executors) -{ - executors_ = executors; - return 0; -} } // namespace OHOS::DistributedObject diff --git a/services/distributeddataservice/service/object/object_service_impl.h b/services/distributeddataservice/service/object/object_service_impl.h index 2a49e78e..a7f40e51 100644 --- a/services/distributeddataservice/service/object/object_service_impl.h +++ b/services/distributeddataservice/service/object/object_service_impl.h @@ -41,8 +41,7 @@ public: void Clear(); int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &appId) override; - int32_t OnInitialize(const BinderInfo &binderInfo) override; - int32_t OnExecutor(std::shared_ptr executors) override; + int32_t OnInitialize() override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; @@ -53,7 +52,6 @@ private: ~Factory(); }; static Factory factory_; - std::shared_ptr executors_; }; } // namespace OHOS::DistributedObject #endif diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 5a73ff78..88f79bc6 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -548,7 +548,7 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) return RDB_OK; } -int32_t RdbServiceImpl::OnInitialize(const BinderInfo &binderInfo) +int32_t RdbServiceImpl::OnInitialize() { return RDB_OK; } @@ -593,9 +593,9 @@ StoreMetaData RdbServiceImpl::GetStoreMetaData(const RdbSyncerParam ¶m) return metaData; } -int32_t RdbServiceImpl::OnExecutor(std::shared_ptr executors) +int32_t RdbServiceImpl::OnBind(const BindInfo &bindInfo) { - executors_ = executors; + executors_ = bindInfo.executors; return 0; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index b4619846..8a34c712 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -58,10 +58,10 @@ public: int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; - int32_t OnInitialize(const BinderInfo &binderInfo) override; + int32_t OnInitialize() override; int32_t GetSchema(const RdbSyncerParam ¶m) override; - int32_t OnExecutor(std::shared_ptr executors) override; + int32_t OnBind(const BindInfo &bindInfo) override; protected: int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, -- Gitee From 0513a3b19256119be35af7649e0ab9b46c8109c1 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 19 May 2023 18:41:30 +0800 Subject: [PATCH 080/437] f Signed-off-by: hanlu --- .../distributeddataservice/service/test/config_factory_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/config_factory_test.cpp b/services/distributeddataservice/service/test/config_factory_test.cpp index 70a6a5ad..02106109 100644 --- a/services/distributeddataservice/service/test/config_factory_test.cpp +++ b/services/distributeddataservice/service/test/config_factory_test.cpp @@ -61,7 +61,7 @@ HWTEST_F(ConfigFactoryTest, ComponentConfig, TestSize.Level0) { auto *components = ConfigFactory::GetInstance().GetComponentConfig(); ASSERT_NE(components, nullptr); - ASSERT_EQ(components->size(), 3); + ASSERT_EQ(components->size(), 4); const ComponentConfig &config = (*components)[0]; ASSERT_EQ(config.description, "3rd party adapter"); ASSERT_EQ(config.lib, "libconfigdemo.z.so"); -- Gitee From 97b9299b301c77645086f0c59a9500c8df483a45 Mon Sep 17 00:00:00 2001 From: wellinleo Date: Sun, 21 May 2023 10:26:28 +0800 Subject: [PATCH 081/437] modify codecheck Signed-off-by: wellinleo --- .../app/src/dump_helper.cpp | 38 +++++++++---------- .../data_share/common/bundle_mgr_proxy.cpp | 2 +- .../data_share/common/rdb_delegate.cpp | 2 +- .../test/unittest/api/documentdb_api_test.cpp | 14 +++---- .../api/documentdb_collection_test.cpp | 2 +- .../unittest/api/documentdb_data_test.cpp | 12 +++--- .../unittest/api/documentdb_find_test.cpp | 2 +- .../unittest/api/documentdb_insert_test.cpp | 8 ++-- .../documentdb_json_common_test.cpp | 38 +++++++++---------- .../oh_adapter/documentdb_jsonobject_test.cpp | 2 +- .../service/kvdb/ref_count.h | 2 +- .../service/kvdb/store_cache.h | 4 +- .../service/test/mock/db_store_mock.cpp | 8 ++-- 13 files changed, 67 insertions(+), 67 deletions(-) diff --git a/services/distributeddataservice/app/src/dump_helper.cpp b/services/distributeddataservice/app/src/dump_helper.cpp index f718164e..225a0e17 100644 --- a/services/distributeddataservice/app/src/dump_helper.cpp +++ b/services/distributeddataservice/app/src/dump_helper.cpp @@ -112,25 +112,25 @@ void DumpHelper::ShowHelp(int fd) { std::string result; result.append("Usage:dump [options]\n") - .append("Description:\n") - .append(CMD_USER_INFO) - .append(" ") - .append("dump all user information in the system\n") - .append(CMD_APP_INFO) - .append(" ") - .append("dump list of all app information in the system\n") - .append(CMD_APP_INFO) - .append(" [appID] ") - .append("dump information about the specified app in the system\n") - .append(CMD_STORE_INFO) - .append(" ") - .append("dump list of all store information in the system\n") - .append(CMD_STORE_INFO) - .append(" [storeID] ") - .append("dump information about the specified store in the system\n") - .append(CMD_ERROR_INFO) - .append(" ") - .append("dump the recent errors information in the system\n"); + .append("Description:\n") + .append(CMD_USER_INFO) + .append(" ") + .append("dump all user information in the system\n") + .append(CMD_APP_INFO) + .append(" ") + .append("dump list of all app information in the system\n") + .append(CMD_APP_INFO) + .append(" [appID] ") + .append("dump information about the specified app in the system\n") + .append(CMD_STORE_INFO) + .append(" ") + .append("dump list of all store information in the system\n") + .append(CMD_STORE_INFO) + .append(" [storeID] ") + .append("dump information about the specified store in the system\n") + .append(CMD_ERROR_INFO) + .append(" ") + .append("dump the recent errors information in the system\n"); dprintf(fd, "%s\n", result.c_str()); } diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp index 4519382f..65319772 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp @@ -85,7 +85,7 @@ BundleMgrProxy::~BundleMgrProxy() std::shared_ptr BundleMgrProxy::GetInstance() { - static std::shared_ptr proxy(new BundleMgrProxy()); + static std::shared_ptr proxy(std::make_shared()); return proxy; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 383fac2a..2d3dd071 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -131,7 +131,7 @@ std::shared_ptr RdbDelegate::Query(const std::string &tableN return nullptr; } auto bridge = RdbDataShareAdapter::RdbUtils::ToResultSetBridge(resultSet); - return std::shared_ptr(new DataShareResultSet(bridge), [](auto p) { + return std::shared_ptr(std::make_shared(bridge), [](auto p) { ZLOGD("release resultset"); resultSetCount--; delete p; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp index 3e0c86f7..22fe15ee 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_api_test.cpp @@ -65,7 +65,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBTest001, TestSize.Level0) EXPECT_EQ(GRD_CreateCollection(db, "student", "", 0), GRD_OK); - EXPECT_EQ(GRD_UpsertDoc(db, "student", R""({"_id":"10001"})"", R""({"name":"Tom","age":23})"", 0), 1); + EXPECT_EQ(GRD_UpsertDoc(db, "student", R""({"_id":"10001"})"", R""({"name":"Tom", "age":23})"", 0), 1); EXPECT_EQ(GRD_DropCollection(db, "student", 0), GRD_OK); @@ -245,7 +245,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigMaxConnNumTest001, TestSize.Level0) R""({"maxConnNum":1000000007})"", R""({"maxConnNum":"16"})"", R""({"maxConnNum":{"value":17}})"", - R""({"maxConnNum":[16,17,18]})"", + R""({"maxConnNum":[16, 17, 18]})"", }; for (const auto &config : configList) { GLOGD("OpenDBConfigMaxConnNumTest001: test with config:%s", config.c_str()); @@ -363,7 +363,7 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigPageSizeTest001, TestSize.Level0) R""({"pageSize":1000000007})"", R""({"pageSize":"4"})"", R""({"pageSize":{"value":8}})"", - R""({"pageSize":[16,32,64]})"", + R""({"pageSize":[16, 32, 64]})"", }; for (const auto &config : configList) { GLOGD("OpenDBConfigPageSizeTest001: test with config:%s", config.c_str()); @@ -500,11 +500,11 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigBufferPoolTest001, TestSize.Level0) GRD_DB *db = nullptr; std::string path = "./document.db"; - int status = GRD_DBOpen(path.c_str(), R""({"pageSize":64,"bufferPoolSize":4096})"", GRD_DB_OPEN_CREATE, &db); + int status = GRD_DBOpen(path.c_str(), R""({"pageSize":64, "bufferPoolSize":4096})"", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); EXPECT_EQ(GRD_DBClose(db, 0), GRD_OK); - status = GRD_DBOpen(path.c_str(), R""({"pageSize":64,"bufferPoolSize":4095})"", GRD_DB_OPEN_CREATE, &db); + status = GRD_DBOpen(path.c_str(), R""({"pageSize":64, "bufferPoolSize":4095})"", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_INVALID_ARGS); status = GRD_DBOpen(path.c_str(), R""({"bufferPoolSize":1023})"", GRD_DB_OPEN_CREATE, &db); @@ -526,11 +526,11 @@ HWTEST_F(DocumentDBApiTest, OpenDBConfigPubBuffTest001, TestSize.Level0) GRD_DB *db = nullptr; std::string path = "./document.db"; - int status = GRD_DBOpen(path.c_str(), R""({"pageSize":64,"redopubbufsize":4033})"", GRD_DB_OPEN_CREATE, &db); + int status = GRD_DBOpen(path.c_str(), R""({"pageSize":64, "redopubbufsize":4033})"", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_OK); EXPECT_EQ(GRD_DBClose(db, 0), GRD_OK); - status = GRD_DBOpen(path.c_str(), R""({"pageSize":64,"redopubbufsize":4032})"", GRD_DB_OPEN_CREATE, &db); + status = GRD_DBOpen(path.c_str(), R""({"pageSize":64, "redopubbufsize":4032})"", GRD_DB_OPEN_CREATE, &db); EXPECT_EQ(status, GRD_INVALID_ARGS); status = GRD_DBOpen(path.c_str(), R""({"redopubbufsize":255})"", GRD_DB_OPEN_CREATE, &db); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp index 92aedcd5..04431be4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_collection_test.cpp @@ -157,7 +157,7 @@ HWTEST_F(DocumentDBCollectionTest, CollectionTest005, TestSize.Level0) R""({"maxDoc":0})"", R""({"maxDoc":"123"})"", R""({"maxDoc":{"value":1024}})"", - R""({"maxDoc":[1,2,4,8]})"", + R""({"maxDoc":[1, 2, 4, 8]})"", R""({"minDoc":1024})"", }; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index d43519a7..064f8004 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -149,7 +149,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest006, TestSize.Level0) HWTEST_F(DocumentDBDataTest, UpsertDataTest007, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; - std::string val = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; + std::string val = R""({"name":"Tmono", "age":18, "addr":{"city":"shanghai", "postal":200001}})""; EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_INVALID_ARGS); } @@ -164,10 +164,10 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest007, TestSize.Level0) HWTEST_F(DocumentDBDataTest, UpsertDataTest008, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; - std::string document = R""({"name":"Tmn","age":18,"addr":{"city":"shanghai","postal":200001}})""; + std::string document = R""({"name":"Tmn", "age":18, "addr":{"city":"shanghai", "postal":200001}})""; EXPECT_EQ(GRD_UpsertDoc(g_db, g_coll, filter.c_str(), document.c_str(), GRD_DOC_REPLACE), 1); - std::string updateDoc = R""({"name":"Xue","case":2,"age":28,"addr":{"city":"shenzhen","postal":518000}})""; + std::string updateDoc = R""({"name":"Xue", "case":2, "age":28, "addr":{"city":"shenzhen", "postal":518000}})""; EXPECT_EQ(GRD_UpsertDoc(g_db, g_coll, filter.c_str(), updateDoc.c_str(), GRD_DOC_APPEND), 1); } @@ -272,7 +272,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest005, TestSize.Level0) {} HWTEST_F(DocumentDBDataTest, UpdateDataTest006, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; - std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; + std::string document = R""({"name":"Tmono", "age":18, "addr":{"city":"shanghai", "postal":200001}})""; std::vector invalidFlags = { 2, 4, 8, 1024, UINT32_MAX }; for (auto flag : invalidFlags) { GLOGD("UpdateDataTest006: update data with flag: %u", flag); @@ -293,7 +293,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest007, TestSize.Level0) HWTEST_F(DocumentDBDataTest, UpdateDataTest008, TestSize.Level0) { const char *updateStr = - R""({"field2":{"c_field":{"cc_field":{"ccc_field":{"ccc_field":[1,false,1.234e2,["hello world!"]]}}}}})""; + R""({"field2":{"c_field":{"cc_field":{"ccc_field":{"ccc_field":[1, false, 1.234e2, ["hello world!"]]}}}}})""; int result = GRD_UpdateDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); int result2 = GRD_UpsertDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); EXPECT_EQ(result, GRD_INVALID_ARGS); @@ -318,7 +318,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest009, TestSize.Level0) char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); string valueStr = value; - string repectStr = R""({"_id":"1234","field1":1,"field2":2,"FIELD1":[1,true,1.23456789,"hello world!",null]})""; + string repectStr = R""({"_id":"1234", "field1":1, "field2":2, "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; EXPECT_EQ((valueStr == repectStr), 1); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 3fa8c92d..f773add4 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -49,7 +49,7 @@ static const char *g_document4 = "{\"_id\" : \"4\", \"name\":\"doc4\",\"item\":\ static const char *g_document5 = "{\"_id\" : \"5\", \"name\":\"doc5\",\"item\":\"journal\",\"personInfo\":\ [{\"sex\" : \"woma\", \"school\" : \"B\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document6 = "{\"_id\" : \"6\", \"name\":\"doc6\",\"item\":false,\"personInfo\":\ - [{\"school\":\"B\", \"teacher\" : \"mike\",\"age\" : 15}, {\"school\":\"C\", \"teacher\" : \"moon\",\"age\":20}]}"; + [{\"school\":\"B\", \"teacher\" : \"mike\", \"age\" : 15}, {\"school\":\"C\", \"teacher\" : \"moon\", \"age\":20}]}"; static const char *g_document7 = "{\"_id\" : \"7\", \"name\":\"doc7\",\"item\":\"fruit\",\"other_Info\":\ [{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document8 = "{\"_id\" : \"8\", \"name\":\"doc8\",\"item\":true,\"personInfo\":\ diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp index 54be32da..7ce58327 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_insert_test.cpp @@ -330,14 +330,14 @@ HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest014, TestSize.Level1) * @tc.expected:step1.GRD_INVALID_ARGS */ const char *document2 = R""({"level1" : {"level2" : {"level3" : [{ "level5" : "level5_1val", - "level5_2":"level5_2_val"}, "level4_val1","level4_val2"], "level3_2" : "level3_2_val"}},"_id":"14"})""; + "level5_2":"level5_2_val"}, "level4_val1","level4_val2"], "level3_2" : "level3_2_val"}}, "_id":"14"})""; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document2, 0), GRD_INVALID_ARGS); /** * @tc.steps:step1.document's JSON depth is 4 * @tc.expected:step1.GRD_OK */ const char *document3 = R""({"level1" : {"level2" : {"level3" : { "level4" : "level5_1val"}, - "level3_2" : "level3_2_val"}},"_id":"14"})""; + "level3_2" : "level3_2_val"}}, "_id":"14"})""; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document3, 0), GRD_OK); } @@ -563,8 +563,8 @@ HWTEST_F(DocumentDBInsertTest, DocumentDBInsertTest025, TestSize.Level1) * @tc.steps:step1.documents JSON depth is 4, which is allowed. * @tc.expected:step1.GRD_OK. */ - const char *document1 = "{\"_id\" : \"25_0\", \"level1\" : { \"level2\" : {\"level3\" :\ - {\"level4\" : \"level4Val\" } } } , \"level1_2\" : \"level1_2Val\" }"; + const char *document1 = "{\"_id\" : \"25_0\", \"level1\" : {\"level2\" : {\"level3\" :\ + {\"level4\" : \"level4Val\"}}} , \"level1_2\" : \"level1_2Val\" }"; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document1, 0), GRD_OK); /** * @tc.steps:step2.documents JSON depth is exactly 4. diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp index aca10555..9b9a892c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -44,9 +44,9 @@ void DocumentDBJsonCommonTest::TearDown(void) {} HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) { - std::string document = R""({"name":"Tmn","age":18,"addr":{"city":"shanghai","postal":200001}})""; - std::string updateDoc = R""({"name":"Xue","case":{"field1":1,"field2":"string","field3":[1,2,3]}, - "age":28,"addr":{"city":"shenzhen","postal":518000}})""; + std::string document = R""({"name":"Tmn", "age":18, "addr":{"city":"shanghai", "postal":200001}})""; + std::string updateDoc = R""({"name":"Xue", "case":{"field1":1, "field2":"string", "field3":[1, 2, 3]}, + "age":28, "addr":{"city":"shenzhen", "postal":518000}})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -68,9 +68,9 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest002, TestSize.Level0) { - std::string document = R""({"name":"Tmn","case":2,"age":[1,2,3],"addr":{"city":"shanghai","postal":200001}})""; - std::string updateDoc = R""({"name":["Xue","Neco","Lip"],"grade":99,"age":18,"addr": - [{"city":"shanghai","postal":200001},{"city":"beijing","postal":100000}]})""; + std::string document = R""({"name":"Tmn", "case":2, "age":[1, 2, 3], "addr":{"city":"shanghai", "postal":200001}})""; + std::string updateDoc = R""({"name":["Xue", "Neco", "Lip"], "grade":99, "age":18, "addr": + [{"city":"shanghai", "postal":200001}, {"city":"beijing", "postal":100000}]})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -91,10 +91,10 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest002, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest003, TestSize.Level0) { - std::string document = R""({"name":["Tmn","BB","Alice"],"age":[1,2,3],"addr":[{"city":"shanghai","postal":200001}, - {"city":"wuhan","postal":430000}]})""; - std::string updateDoc = R""({"name":["Xue","Neco","Lip"],"age":18,"addr":[{"city":"shanghai","postal":200001}, - {"city":"beijing","postal":100000}]})""; + std::string document = R""({"name":["Tmn", "BB", "Alice"], "age":[1, 2, 3], "addr":[{"city":"shanghai", "postal":200001}, + {"city":"wuhan", "postal":430000}]})""; + std::string updateDoc = R""({"name":["Xue", "Neco", "Lip"], "age":18, "addr":[{"city":"shanghai", "postal":200001}, + {"city":"beijing", "postal":100000}]})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -129,7 +129,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest004, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) { - std::string document = R""({"name":["Tmn","BB","Alice"]})""; + std::string document = R""({"name":["Tmn", "BB", "Alice"]})""; std::string updateDoc = R""({"name.2":"GG"})""; int errCode = E_OK; @@ -148,7 +148,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest006, TestSize.Level0) { - std::string document = R""({"name":{"first":"Tno","last":"moray"}})""; + std::string document = R""({"name":{"first":"Tno", "last":"moray"}})""; std::string updateDoc = R""({"name":{"midle.AA":"GG"}})""; int errCode = E_OK; @@ -167,7 +167,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest006, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest007, TestSize.Level0) { - std::string document = R""({"name":{"first":["XX","CC"],"last":"moray"}})""; + std::string document = R""({"name":{"first":["XX", "CC"], "last":"moray"}})""; std::string updateDoc = R""({"name.first.0":"LL"})""; int errCode = E_OK; @@ -186,8 +186,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest007, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest008, TestSize.Level0) { - std::string document = R""({"name":{"first":"XX","last":"moray"}})""; - std::string updateDoc = R""({"name":{"first":["XXX","BBB","CCC"]}})""; + std::string document = R""({"name":{"first":"XX", "last":"moray"}})""; + std::string updateDoc = R""({"name":{"first":["XXX", "BBB", "CCC"]}})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -205,7 +205,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest008, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest009, TestSize.Level0) { - std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; + std::string document = R""({"name":{"first":["XXX", "BBB", "CCC"], "last":"moray"}})""; std::string updateDoc = R""({"name":{"first":"XX"}})""; int errCode = E_OK; @@ -286,7 +286,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest013, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) { - std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; + std::string document = R""({"name":{"first":"Xue", "second":"Lang"}})""; std::string updateDoc = R""({"name.0":"GG"})""; int errCode = E_OK; @@ -301,7 +301,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest015, TestSize.Level0) { std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; - std::string updateDoc = R""({"name.first":["GG","MM"]})""; + std::string updateDoc = R""({"name.first":["GG", "MM"]})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); @@ -459,7 +459,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest012, TestSize.Leve { std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; - std::string filter = R""({"instock" : {"warehose" : "A", "bad" : "2" ,"qty" : 5}})""; + std::string filter = R""({"instock" : {"warehose" : "A", "bad" : "2" , "qty" : 5}})""; int errCode = E_OK; JsonObject srcObj = JsonObject::Parse(document, errCode); EXPECT_EQ(errCode, E_OK); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp index 93d46974..604f2c38 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_jsonobject_test.cpp @@ -49,7 +49,7 @@ void DocumentDBJsonObjectTest::TearDown(void) {} */ HWTEST_F(DocumentDBJsonObjectTest, JsonObjectTest001, TestSize.Level0) { - const std::string config = R""({"a":123,"b":{"c":234,"d":"12345"}})""; + const std::string config = R""({"a":123, "b":{"c":234, "d":"12345"}})""; int ret = E_OK; JsonObject conf = JsonObject::Parse(config, ret); diff --git a/services/distributeddataservice/service/kvdb/ref_count.h b/services/distributeddataservice/service/kvdb/ref_count.h index 89ee9dd6..3ec72fe4 100644 --- a/services/distributeddataservice/service/kvdb/ref_count.h +++ b/services/distributeddataservice/service/kvdb/ref_count.h @@ -27,7 +27,7 @@ public: RefCount(RefCount &&other) noexcept; RefCount &operator=(const RefCount &other); RefCount &operator=(RefCount &&other) noexcept; - operator bool () const; + operator bool() const; private: std::shared_ptr ref_; diff --git a/services/distributeddataservice/service/kvdb/store_cache.h b/services/distributeddataservice/service/kvdb/store_cache.h index 2e4d726c..37e5133d 100644 --- a/services/distributeddataservice/service/kvdb/store_cache.h +++ b/services/distributeddataservice/service/kvdb/store_cache.h @@ -33,9 +33,9 @@ public: template struct Less { public: - bool operator()(const sptr &__x, const sptr &__y) const + bool operator()(const sptr &x, const sptr &y) const { - return __x.GetRefPtr() < __y.GetRefPtr(); + return x.GetRefPtr() < y.GetRefPtr(); } }; using DBStatus = DistributedDB::DBStatus; diff --git a/services/distributeddataservice/service/test/mock/db_store_mock.cpp b/services/distributeddataservice/service/test/mock/db_store_mock.cpp index e4f0f3b2..55d9ca88 100644 --- a/services/distributeddataservice/service/test/mock/db_store_mock.cpp +++ b/services/distributeddataservice/service/test/mock/db_store_mock.cpp @@ -263,7 +263,7 @@ DBStatus DBStoreMock::GetEntries(ConcurrentMap &store, const Key &ke store.ForEach([&entries, &keyPrefix](const Key &key, Value &value) { auto it = std::search(key.begin(), key.end(), keyPrefix.begin(), keyPrefix.end()); if (it == key.begin()) { - entries.push_back( { key, value } ); + entries.push_back({key, value}); } return false; }); @@ -275,7 +275,7 @@ DBStatus DBStoreMock::PutBatch(ConcurrentMap &store, const std::vect for (auto &entry : entries) { store.InsertOrAssign(entry.key, entry.value); } - DBChangeDataMock changeData( {}, entries, {} ); + DBChangeDataMock changeData({}, entries, {}); observers_.ForEachCopies([&changeData](const auto &observer, auto &keys) mutable { if (observer) { observer->OnChange(changeData); @@ -287,13 +287,13 @@ DBStatus DBStoreMock::PutBatch(ConcurrentMap &store, const std::vect DBStatus DBStoreMock::DeleteBatch(ConcurrentMap &store, const std::vector &keys) { - DBChangeDataMock changeData( {}, {}, {} ); + DBChangeDataMock changeData({}, {}, {}); for (auto &key : keys) { auto it = store.Find(key); if (!it.first) { continue; } - changeData.AddEntry( {key, std::move(it.second)} ); + changeData.AddEntry({key, std::move(it.second)}); store.Erase(key); } -- Gitee From 005f04042ab14c76abdab0b5b0b63bb531b3e99a Mon Sep 17 00:00:00 2001 From: wellinleo Date: Sun, 21 May 2023 10:40:00 +0800 Subject: [PATCH 082/437] modify codecheck Signed-off-by: wellinleo --- .../distributeddataservice/app/src/dump_helper.cpp | 12 ++++++------ .../service/data_share/common/bundle_mgr_proxy.cpp | 2 +- .../service/data_share/common/rdb_delegate.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/app/src/dump_helper.cpp b/services/distributeddataservice/app/src/dump_helper.cpp index 225a0e17..0c5f77a5 100644 --- a/services/distributeddataservice/app/src/dump_helper.cpp +++ b/services/distributeddataservice/app/src/dump_helper.cpp @@ -114,22 +114,22 @@ void DumpHelper::ShowHelp(int fd) result.append("Usage:dump [options]\n") .append("Description:\n") .append(CMD_USER_INFO) - .append(" ") + .append(" ") .append("dump all user information in the system\n") .append(CMD_APP_INFO) - .append(" ") + .append(" ") .append("dump list of all app information in the system\n") .append(CMD_APP_INFO) - .append(" [appID] ") + .append(" [appID] ") .append("dump information about the specified app in the system\n") .append(CMD_STORE_INFO) - .append(" ") + .append(" ") .append("dump list of all store information in the system\n") .append(CMD_STORE_INFO) - .append(" [storeID] ") + .append(" [storeID] ") .append("dump information about the specified store in the system\n") .append(CMD_ERROR_INFO) - .append(" ") + .append(" ") .append("dump the recent errors information in the system\n"); dprintf(fd, "%s\n", result.c_str()); } diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp index 65319772..58da8094 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp @@ -85,7 +85,7 @@ BundleMgrProxy::~BundleMgrProxy() std::shared_ptr BundleMgrProxy::GetInstance() { - static std::shared_ptr proxy(std::make_shared()); + static std::shared_ptr proxy = std::make_shared(); return proxy; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 2d3dd071..383fac2a 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -131,7 +131,7 @@ std::shared_ptr RdbDelegate::Query(const std::string &tableN return nullptr; } auto bridge = RdbDataShareAdapter::RdbUtils::ToResultSetBridge(resultSet); - return std::shared_ptr(std::make_shared(bridge), [](auto p) { + return std::shared_ptr(new DataShareResultSet(bridge), [](auto p) { ZLOGD("release resultset"); resultSetCount--; delete p; -- Gitee From 58d5c083cbf14d3d214d4ff1ee022f0a85a38ca3 Mon Sep 17 00:00:00 2001 From: wellinleo Date: Sun, 21 May 2023 11:01:54 +0800 Subject: [PATCH 083/437] update Signed-off-by: wellinleo --- .../gaussdb_rd/test/unittest/api/documentdb_data_test.cpp | 3 ++- .../gaussdb_rd/test/unittest/api/documentdb_find_test.cpp | 3 ++- .../unittest/oh_adapter/documentdb_json_common_test.cpp | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index 064f8004..1ea370b5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -318,7 +318,8 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest009, TestSize.Level0) char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); string valueStr = value; - string repectStr = R""({"_id":"1234", "field1":1, "field2":2, "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; + string repectStr = R""({"_id":"1234", "field1":1, "field2":2, + "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; EXPECT_EQ((valueStr == repectStr), 1); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index f773add4..0530f99c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -49,7 +49,8 @@ static const char *g_document4 = "{\"_id\" : \"4\", \"name\":\"doc4\",\"item\":\ static const char *g_document5 = "{\"_id\" : \"5\", \"name\":\"doc5\",\"item\":\"journal\",\"personInfo\":\ [{\"sex\" : \"woma\", \"school\" : \"B\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document6 = "{\"_id\" : \"6\", \"name\":\"doc6\",\"item\":false,\"personInfo\":\ - [{\"school\":\"B\", \"teacher\" : \"mike\", \"age\" : 15}, {\"school\":\"C\", \"teacher\" : \"moon\", \"age\":20}]}"; + [{\"school\":\"B\", \"teacher\" : \"mike\", \"age\" : 15}, + {\"school\":\"C\", \"teacher\" : \"moon\", \"age\" : 20}]}"; static const char *g_document7 = "{\"_id\" : \"7\", \"name\":\"doc7\",\"item\":\"fruit\",\"other_Info\":\ [{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document8 = "{\"_id\" : \"8\", \"name\":\"doc8\",\"item\":true,\"personInfo\":\ diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp index 9b9a892c..bec7c70a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -68,7 +68,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest002, TestSize.Level0) { - std::string document = R""({"name":"Tmn", "case":2, "age":[1, 2, 3], "addr":{"city":"shanghai", "postal":200001}})""; + std::string document = R""({"name":"Tmn", "case":2, "age":[1, 2, 3], + "addr":{"city":"shanghai", "postal":200001}})""; std::string updateDoc = R""({"name":["Xue", "Neco", "Lip"], "grade":99, "age":18, "addr": [{"city":"shanghai", "postal":200001}, {"city":"beijing", "postal":100000}]})""; @@ -91,8 +92,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest002, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest003, TestSize.Level0) { - std::string document = R""({"name":["Tmn", "BB", "Alice"], "age":[1, 2, 3], "addr":[{"city":"shanghai", "postal":200001}, - {"city":"wuhan", "postal":430000}]})""; + std::string document = R""({"name":["Tmn", "BB", "Alice"], "age":[1, 2, 3], + "addr":[{"city":"shanghai", "postal":200001}, {"city":"wuhan", "postal":430000}]})""; std::string updateDoc = R""({"name":["Xue", "Neco", "Lip"], "age":18, "addr":[{"city":"shanghai", "postal":200001}, {"city":"beijing", "postal":100000}]})""; -- Gitee From 723296216632cf4baa9ac6211e9cade47aafc47c Mon Sep 17 00:00:00 2001 From: wellinleo Date: Sun, 21 May 2023 11:10:03 +0800 Subject: [PATCH 084/437] update Signed-off-by: wellinleo --- .../service/data_share/common/bundle_mgr_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp index 58da8094..4519382f 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp @@ -85,7 +85,7 @@ BundleMgrProxy::~BundleMgrProxy() std::shared_ptr BundleMgrProxy::GetInstance() { - static std::shared_ptr proxy = std::make_shared(); + static std::shared_ptr proxy(new BundleMgrProxy()); return proxy; } } // namespace OHOS::DataShare \ No newline at end of file -- Gitee From 0d19568e68879ec1ae69e87e022980785f201562 Mon Sep 17 00:00:00 2001 From: wellinleo Date: Sun, 21 May 2023 11:26:03 +0800 Subject: [PATCH 085/437] update Signed-off-by: wellinleo --- .../gaussdb_rd/test/unittest/api/documentdb_find_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 0530f99c..f77761d8 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -49,8 +49,9 @@ static const char *g_document4 = "{\"_id\" : \"4\", \"name\":\"doc4\",\"item\":\ static const char *g_document5 = "{\"_id\" : \"5\", \"name\":\"doc5\",\"item\":\"journal\",\"personInfo\":\ [{\"sex\" : \"woma\", \"school\" : \"B\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document6 = "{\"_id\" : \"6\", \"name\":\"doc6\",\"item\":false,\"personInfo\":\ - [{\"school\":\"B\", \"teacher\" : \"mike\", \"age\" : 15}, + [{\"school\":\"B\", \"teacher\" : \"mike\", \"age\" : 15},\ {\"school\":\"C\", \"teacher\" : \"moon\", \"age\" : 20}]}"; + static const char *g_document7 = "{\"_id\" : \"7\", \"name\":\"doc7\",\"item\":\"fruit\",\"other_Info\":\ [{\"school\":\"BX\", \"age\" : 15}, {\"school\":\"C\", \"age\" : 35}]}"; static const char *g_document8 = "{\"_id\" : \"8\", \"name\":\"doc8\",\"item\":true,\"personInfo\":\ -- Gitee From b38ddba9780facb86f5e8b06428b4f7866215b9d Mon Sep 17 00:00:00 2001 From: e Date: Sun, 21 May 2023 15:23:36 +0800 Subject: [PATCH 086/437] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: e --- .../distributeddataservice/app/src/kvstore_data_service.h | 2 +- services/distributeddataservice/app/src/task_manager.cpp | 3 +-- .../app/src/uninstaller/uninstaller_impl.h | 2 +- .../distributeddataservice/service/rdb/rdb_general_store.h | 4 ++-- .../distributeddataservice/service/rdb/rdb_service_impl.cpp | 2 +- .../distributeddataservice/service/test/cloud_data_test.cpp | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 60aac352..cbb4ae01 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -121,7 +121,7 @@ private: Status AppExit(pid_t uid, pid_t pid, uint32_t token, const AppId &appId); bool ResolveAutoLaunchParamByIdentifier(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m); - void ResolveAutoLaunchCompatible(const StoreMetaData &meta, const std::string &identifier); + void ResolveAutoLaunchCompatible(const StoreMetaData &storeMeta, const std::string &identifier); static DistributedDB::SecurityOption ConvertSecurity(int securityLevel); static Status InitNbDbOption(const Options &options, const std::vector &cipherKey, DistributedDB::KvStoreNbDelegate::Option &dbOption); diff --git a/services/distributeddataservice/app/src/task_manager.cpp b/services/distributeddataservice/app/src/task_manager.cpp index 1332fc20..ec06928e 100644 --- a/services/distributeddataservice/app/src/task_manager.cpp +++ b/services/distributeddataservice/app/src/task_manager.cpp @@ -15,9 +15,8 @@ #include "task_manager.h" namespace OHOS::DistributedData { -TaskManager::TaskManager(std::shared_ptr executors) +TaskManager::TaskManager(std::shared_ptr executors) : executors_(executors) { - executors_ = executors; } TaskManager::~TaskManager() diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index 3922fbad..e6498a67 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -50,7 +50,7 @@ public: private: static constexpr int32_t RETRY_TIME = 300; static constexpr int32_t RETRY_INTERVAL = 100; - int32_t retryTime_; + int32_t retryTime_ = 0; ExecutorPool::Task GetTask(); std::shared_ptr subscriber_ {}; std::shared_ptr executors_; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index f1bd92cd..c85014cc 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -38,7 +38,7 @@ public: using RdbDelegate = DistributedDB::RelationalStoreDelegate; using RdbManager = DistributedDB::RelationalStoreManager; - explicit RdbGeneralStore(const StoreMetaData &metaData); + explicit RdbGeneralStore(const StoreMetaData &meta); int32_t Bind(std::shared_ptr cloudDb) override; int32_t SetSchema(const SchemaMeta &schemaMeta) override; int32_t Execute(const std::string &table, const std::string &sql) override; @@ -59,7 +59,7 @@ private: RdbDelegate *delegate_ = nullptr; std::shared_ptr store_; std::shared_ptr cloudDb_; - Watcher *watcher_; + Watcher *watcher_ = nullptr; }; } // namespace OHOS::DistributedRdb #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 525aed43..96c30eda 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -438,7 +438,7 @@ int32_t RdbServiceImpl::DoSubscribe(const RdbSyncerParam& param, const Subscribe void RdbServiceImpl::OnChange(uint32_t tokenId, const std::string &storeName) { pid_t pid = 0; - syncAgents_.ComputeIfPresent(tokenId, [&pid, &storeName](auto &key, SyncAgent &value) { + syncAgents_.ComputeIfPresent(tokenId, [&pid, &storeName](auto &key, const SyncAgent &value) { pid = value.pid_; return true; }); diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 031ea345..79f12f85 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -32,7 +32,7 @@ using namespace testing::ext; using namespace OHOS::DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; -namespace OHOS { +namespace OHOS::Test { namespace DistributedDataTest { static constexpr const char *TEST_CLOUD_BUNDLE = "test_cloud_bundleName"; static constexpr const char *TEST_CLOUD_APPID = "test_cloud_appid"; @@ -185,4 +185,4 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); } } // namespace DistributedDataTest -} // namespace OHOS +} // namespace OHOS::Test -- Gitee From 4a89dc3b04ba0baff80d618bef39e020faa53f2d Mon Sep 17 00:00:00 2001 From: e Date: Mon, 22 May 2023 10:30:05 +0800 Subject: [PATCH 087/437] =?UTF-8?q?=E9=83=A8=E4=BB=B6=E5=8C=96=E9=81=97?= =?UTF-8?q?=E7=95=99=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: e --- bundle.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bundle.json b/bundle.json index d7325b51..98a7a3bc 100644 --- a/bundle.json +++ b/bundle.json @@ -1,6 +1,6 @@ { - "name": "@ohos/distributeddatamgr_datamgr_service", - "version": "1.0.0", + "name": "@ohos/datamgr_service", + "version": "3.2.0", "description": "Distributed data manager that provides the capability to store data in the databases of different devices", "homePage": "https://gitee.com/openharmony", "license": "Apache V2", @@ -46,8 +46,8 @@ "adapted_system_type": [ "standard" ], - "rom": "", - "ram": "", + "rom": "5120KB", + "ram": "8192KB", "hisysevent_config": [ "//foundation/distributeddatamgr/datamgr_service/hisysevent.yaml" ], -- Gitee From 2d205223069cc0bf9dcc6092932465ba65599d1a Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 22 May 2023 14:57:28 +0800 Subject: [PATCH 088/437] fix backup Signed-off-by: zuojiangjiang --- .../service/backup/src/backup_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/backup/src/backup_manager.cpp b/services/distributeddataservice/service/backup/src/backup_manager.cpp index 0a904e1b..0c05825c 100644 --- a/services/distributeddataservice/service/backup/src/backup_manager.cpp +++ b/services/distributeddataservice/service/backup/src/backup_manager.cpp @@ -290,7 +290,7 @@ void BackupManager::CopyFile(const std::string &oldPath, const std::string &newP fout.open(newPath, std::ios_base::out | std::ios_base::trunc); } char buf[COPY_SIZE] = {0}; - while (!fin.eof()) { + while (fin.good()) { fin.read(buf, COPY_SIZE); fout.write(buf, fin.gcount()); } -- Gitee From c82d4084d740da6b8133451f39a0fa5d0b7c75ee Mon Sep 17 00:00:00 2001 From: lianhuix Date: Mon, 22 May 2023 10:41:39 +0800 Subject: [PATCH 089/437] Fix compile issues Signed-off-by: lianhuix --- .../service/data_share/BUILD.gn | 3 ++- .../data_share/datamgr_service_data_share.gni | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 services/distributeddataservice/service/data_share/datamgr_service_data_share.gni diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index b9490bbc..be7efa51 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -13,6 +13,7 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") +import("datamgr_service_data_share.gni") config("module_public_config") { visibility = [ ":*" ] include_dirs = [ @@ -77,10 +78,10 @@ ohos_shared_library("data_share_service") { configs = [ ":module_public_config" ] deps = [ + "${gaussrd_path}:gaussdb_rd", "../../adapter:distributeddata_adapter", "../../adapter/utils:distributeddata_utils_static", "../../framework:distributeddatasvcfwk", - "gaussdb_rd:gaussdb_rd", ] external_deps = [ diff --git a/services/distributeddataservice/service/data_share/datamgr_service_data_share.gni b/services/distributeddataservice/service/data_share/datamgr_service_data_share.gni new file mode 100644 index 00000000..5ac6d628 --- /dev/null +++ b/services/distributeddataservice/service/data_share/datamgr_service_data_share.gni @@ -0,0 +1,23 @@ +# 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. + +declare_args() { + gaussrd_path = "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share/gaussdb_rd" + if (defined(global_parts_info) && + defined(global_parts_info.distributeddatamgr_kv_store_lite)) { + gaussrd_path = "//foundation/distributeddatamgr/kv_store_lite/gaussdb_rd" + gaussrd_enchance = true + } else { + gaussrd_enchance = false + } +} -- Gitee From baad2794739deecead51c7b0f4b0d09f9f70e0d1 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Mon, 22 May 2023 15:41:49 +0800 Subject: [PATCH 090/437] fix warn Signed-off-by: niudongyao --- .../service/data_share/common/scheduler_manager.cpp | 2 +- .../service/data_share/common/scheduler_manager.h | 3 ++- .../service/data_share/common/template_manager.cpp | 4 ++-- .../service/data_share/common/template_manager.h | 2 +- .../service/data_share/data/published_data.h | 2 +- .../service/data_share/data_share_service_stub.cpp | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index 85d7e530..86032a1b 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -38,7 +38,7 @@ void SchedulerManager::Execute(const std::string &uri, const std::string &rdbDir return; } std::vector keys = RdbSubscriberManager::GetInstance().GetKeysByUri(uri); - for (auto &key : keys) { + for (auto const &key : keys) { if (RdbSubscriberManager::GetInstance().GetObserverCount(key) == 0) { continue; } diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.h b/services/distributeddataservice/service/data_share/common/scheduler_manager.h index 546d77be..d5e5479b 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.h +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.h @@ -37,7 +37,8 @@ private: static constexpr size_t TIME_TASK_NUM = 10; SchedulerManager() = default; ~SchedulerManager() = default; - void GenRemindTimerFuncParams(const std::string &rdbDir, int version, const Key &key, std::string &schedulerSQL); + static void GenRemindTimerFuncParams(const std::string &rdbDir, int version, const Key &key, + std::string &schedulerSQL); void ExecuteSchedulerSQL(const std::string &rdbDir, int version, const Key &key, std::shared_ptr delegate); diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index fabed5f1..67e435e8 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -413,9 +413,9 @@ void PublishedDataSubscriberManager::Emit(const std::vector &k void PublishedDataSubscriberManager::PutInto( std::map, std::vector> &callbacks, - std::vector &val, const PublishedDataKey &key, const sptr observer) + const std::vector &val, const PublishedDataKey &key, const sptr observer) { - for (auto &callback : val) { + for (auto const &callback : val) { if (callback.enabled && callback.observer != nullptr) { // callback the observer, others do not call if (observer != nullptr && callback.observer != observer) { diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index f6b4e5a5..72af2ca4 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -111,7 +111,7 @@ private: }; PublishedDataSubscriberManager() = default; void PutInto(std::map, std::vector> &, - std::vector &, const PublishedDataKey &, const sptr); + const std::vector &, const PublishedDataKey &, const sptr); ConcurrentMap> publishedDataCache; }; } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index daa7d667..ebc633bf 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -41,7 +41,7 @@ public: static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); PublishedData(const std::string &key, const std::string &bundleName, int64_t subscriberId, - const std::variant, std::string> &value, const int version); + const std::variant, std::string> &inputValue, const int version); ~PublishedData() = default; bool HasVersion() const override; int GetVersion() const override; diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 023f4e75..edfa7b88 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -317,7 +317,7 @@ int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me if (!CheckInterfaceToken(data)) { return DATA_SHARE_ERROR; } - if (code >= 0 && code < DATA_SHARE_SERVICE_CMD_MAX) { + if (code < DATA_SHARE_SERVICE_CMD_MAX) { return (this->*HANDLERS[code])(data, reply); } return -1; -- Gitee From d8c9e2941e1af1e7f301b7182109f46c0e55af0c Mon Sep 17 00:00:00 2001 From: niudongyao Date: Mon, 22 May 2023 16:03:58 +0800 Subject: [PATCH 091/437] fix warn Signed-off-by: niudongyao --- .../service/data_share/common/template_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 67e435e8..f47ad59a 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -413,7 +413,8 @@ void PublishedDataSubscriberManager::Emit(const std::vector &k void PublishedDataSubscriberManager::PutInto( std::map, std::vector> &callbacks, - const std::vector &val, const PublishedDataKey &key, const sptr observer) + const std::vector &val, const PublishedDataKey &key, + const sptr observer) { for (auto const &callback : val) { if (callback.enabled && callback.observer != nullptr) { -- Gitee From 48fc64136c67e30220df961442db657db7f1e498 Mon Sep 17 00:00:00 2001 From: hanlu Date: Mon, 22 May 2023 21:21:24 +0800 Subject: [PATCH 092/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 1 - .../data_share/common/template_manager.cpp | 4 +-- .../data_share/data/json_formatter.cpp | 30 ---------------- .../service/data_share/data/json_formatter.h | 36 ------------------- 4 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 services/distributeddataservice/service/data_share/data/json_formatter.cpp delete mode 100644 services/distributeddataservice/service/data_share/data/json_formatter.h diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index b9490bbc..f47d5b04 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -43,7 +43,6 @@ ohos_shared_library("data_share_service") { "common/seq_strategy.cpp", "common/template_manager.cpp", "common/uri_utils.cpp", - "data/json_formatter.cpp", "data/published_data.cpp", "data/resultset_json_formatter.cpp", "data/template_data.cpp", diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index fabed5f1..d2514c15 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -17,7 +17,6 @@ #include "template_manager.h" #include "db_delegate.h" -#include "json_formatter.h" #include "log_print.h" #include "published_data.h" #include "scheduler_manager.h" @@ -287,8 +286,7 @@ int RdbSubscriberManager::Notify( changeNode.templateId_.bundleName_ = key.bundleName; for (const auto &predicate : tpl.predicates_) { std::string result = delegate->Query(predicate.selectSql_); - JsonFormatter formatter(predicate.key_, result); - changeNode.data_.emplace_back(DistributedData::Serializable::Marshall(formatter)); + changeNode.data_.emplace_back("{\"" + predicate.key_ + "\":" + result + "}"); } ZLOGI("emit, size %{public}zu %{private}s", val.size(), changeNode.uri_.c_str()); diff --git a/services/distributeddataservice/service/data_share/data/json_formatter.cpp b/services/distributeddataservice/service/data_share/data/json_formatter.cpp deleted file mode 100644 index b3c38832..00000000 --- a/services/distributeddataservice/service/data_share/data/json_formatter.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - */ -#define LOG_TAG "JsonFormatter" -#include "json_formatter.h" - -#include "log_print.h" - -namespace OHOS::DataShare { -bool JsonFormatter::Marshal(json &node) const -{ - return SetValue(node[key_], value_); -} - -bool JsonFormatter::Unmarshal(const json &node) -{ - return GetValue(node, key_, value_); -} -} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/json_formatter.h b/services/distributeddataservice/service/data_share/data/json_formatter.h deleted file mode 100644 index 0b718493..00000000 --- a/services/distributeddataservice/service/data_share/data/json_formatter.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ - -#ifndef DATASHARESERVICE_JSON_FORMATTER_H -#define DATASHARESERVICE_JSON_FORMATTER_H - -#include "serializable/serializable.h" - -namespace OHOS::DataShare { -class JsonFormatter : public DistributedData::Serializable { -public: - JsonFormatter(const std::string &key, const std::string &value) - : key_(key), value_(value) - { - } - bool Marshal(json &node) const override; - bool Unmarshal(const json &node) override; - -private: - std::string key_; - std::string value_; -}; -} // namespace OHOS::DataShare -#endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H -- Gitee From 1e67af684ad8fa3c8b89ef8f101742a996e56d9d Mon Sep 17 00:00:00 2001 From: htt1997 Date: Mon, 22 May 2023 22:10:41 +0800 Subject: [PATCH 093/437] refactor:delete unused code Signed-off-by: htt1997 --- .../framework/cloud/cloud_event.cpp | 2 +- .../framework/include/cloud/cloud_event.h | 2 +- .../service/rdb/rdb_service_impl.cpp | 40 ------------------- .../service/rdb/rdb_service_impl.h | 4 -- .../service/rdb/rdb_service_stub.cpp | 33 --------------- .../service/rdb/rdb_service_stub.h | 6 --- 6 files changed, 2 insertions(+), 85 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_event.cpp b/services/distributeddataservice/framework/cloud/cloud_event.cpp index cb2604bd..cdd0e02e 100644 --- a/services/distributeddataservice/framework/cloud/cloud_event.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_event.cpp @@ -21,7 +21,7 @@ CloudEvent::CloudEvent(int32_t evtId, CloudEvent::StoreInfo storeInfo, const std { } -std::string CloudEvent::GetFeatureName() const +const std::string& CloudEvent::GetFeatureName() const { return featureName_; } diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h index e1f04f41..fbb09716 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -39,7 +39,7 @@ public: CloudEvent(int32_t evtId, StoreInfo storeInfo, const std::string &featureName = "relational_store"); ~CloudEvent() = default; - std::string GetFeatureName() const; + const std::string& GetFeatureName() const; const StoreInfo& GetStoreInfo() const; private: diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 1dfcc49b..d1a9d782 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -495,46 +495,6 @@ int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::stri return syncer->RemoteQuery(device, sql, selectionArgs, resultSet); } -int32_t RdbServiceImpl::CreateRDBTable(const RdbSyncerParam ¶m) -{ - if (!CheckAccess(param.bundleName_, param.storeName_)) { - ZLOGE("permission error"); - return RDB_ERROR; - } - - pid_t pid = IPCSkeleton::GetCallingPid(); - auto rdbObserver = new (std::nothrow) RdbStoreObserverImpl(this, pid); - if (rdbObserver == nullptr) { - return RDB_ERROR; - } - auto syncer = new (std::nothrow) RdbSyncer(param, rdbObserver); - if (syncer == nullptr) { - ZLOGE("new syncer error"); - return RDB_ERROR; - } - auto uid = IPCSkeleton::GetCallingUid(); - auto tokenId = IPCSkeleton::GetCallingTokenID(); - StoreMetaData storeMetaData = GetStoreMetaData(param); - MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData); - if (syncer->Init(pid, uid, tokenId, storeMetaData) != RDB_OK) { - ZLOGE("Init error"); - delete syncer; - return RDB_ERROR; - } - delete syncer; - return RDB_OK; -} - -int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) -{ - if (!CheckAccess(param.bundleName_, param.storeName_)) { - ZLOGE("permission error"); - return RDB_ERROR; - } - auto meta = GetStoreMetaData(param); - return MetaDataManager::GetInstance().DelMeta(meta.GetKey()) ? RDB_OK : RDB_ERROR; -} - int32_t RdbServiceImpl::OnInitialize() { return RDB_OK; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 18dd29b2..24472677 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -52,10 +52,6 @@ public: void OnChange(uint32_t tokenId, const std::string &storeName); - int32_t CreateRDBTable(const RdbSyncerParam ¶m) override; - - int32_t DestroyRDBTable(const RdbSyncerParam ¶m) override; - int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; int32_t OnExecutor(std::shared_ptr executors) override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index e879c523..224109f0 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -212,37 +212,4 @@ int RdbServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageP return RDB_ERROR; } -int32_t RdbServiceStub::OnRemoteDoCreateTable(MessageParcel &data, MessageParcel &reply) -{ - RdbSyncerParam param; - if (!ITypesUtil::Unmarshal(data, param)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); - return IPC_STUB_INVALID_DATA_ERR; - } - - int32_t status = CreateRDBTable(param); - if (!ITypesUtil::Marshal(reply, status)) { - ZLOGE("Marshal status:0x%{public}x", status); - return IPC_STUB_WRITE_PARCEL_ERR; - } - return RDB_OK; -} - -int32_t RdbServiceStub::OnRemoteDoDestroyTable(MessageParcel &data, MessageParcel &reply) -{ - RdbSyncerParam param; - if (!ITypesUtil::Unmarshal(data, param)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); - return IPC_STUB_INVALID_DATA_ERR; - } - - int32_t status = DestroyRDBTable(param); - if (!ITypesUtil::Marshal(reply, status)) { - ZLOGE("Marshal status:0x%{public}x", status); - return IPC_STUB_WRITE_PARCEL_ERR; - } - return RDB_OK; -} } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.h b/services/distributeddataservice/service/rdb/rdb_service_stub.h index 16f4c169..04c57e57 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.h +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.h @@ -66,10 +66,6 @@ private: int32_t OnRemoteDoRemoteQuery(MessageParcel& data, MessageParcel& reply); - int32_t OnRemoteDoCreateTable(MessageParcel& data, MessageParcel& reply); - - int32_t OnRemoteDoDestroyTable(MessageParcel& data, MessageParcel& reply); - using RequestHandle = int (RdbServiceStub::*)(MessageParcel &, MessageParcel &); static constexpr RequestHandle HANDLERS[RDB_SERVICE_CMD_MAX] = { [RDB_SERVICE_CMD_OBTAIN_TABLE] = &RdbServiceStub::OnRemoteObtainDistributedTableName, @@ -80,8 +76,6 @@ private: [RDB_SERVICE_CMD_SUBSCRIBE] = &RdbServiceStub::OnRemoteDoSubscribe, [RDB_SERVICE_CMD_UNSUBSCRIBE] = &RdbServiceStub::OnRemoteDoUnSubscribe, [RDB_SERVICE_CMD_REMOTE_QUERY] = &RdbServiceStub::OnRemoteDoRemoteQuery, - [RDB_SERVICE_CREATE_RDB_TABLE] = &RdbServiceStub::OnRemoteDoCreateTable, - [RDB_SERVICE_DESTROY_RDB_TABLE] = &RdbServiceStub::OnRemoteDoDestroyTable, [RDB_SERVICE_CMD_GET_SCHEMA] = &RdbServiceStub::OnGetSchema }; }; -- Gitee From 0e8fc8f6fad92c6fdeea4139d4c3fe3fe3aca7d7 Mon Sep 17 00:00:00 2001 From: zwtmichael Date: Tue, 23 May 2023 10:49:11 +0800 Subject: [PATCH 094/437] user specific declaration Signed-off-by: zwtmichael --- services/distributeddataservice/service/rdb/rdb_syncer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index b03c65ca..9a38687a 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -434,7 +434,8 @@ int32_t RdbSyncer::DoSync(const SyncOption &option, const RdbPredicates &predica ZLOGI("delegate sync"); return delegate->Sync(devices, static_cast(option.mode), - MakeQuery(predicates), [&result] (const auto& syncStatus) { + MakeQuery(predicates), [&result] (const std::map> &syncStatus) { HandleSyncStatus(syncStatus, result); }, true); } @@ -456,7 +457,8 @@ int32_t RdbSyncer::DoAsync(const SyncOption &option, const RdbPredicates &predic ZLOGI("delegate sync"); return delegate->Sync(devices, static_cast(option.mode), - MakeQuery(predicates), [callback] (const auto& syncStatus) { + MakeQuery(predicates), [callback] (const std::map> &syncStatus) { SyncResult result; HandleSyncStatus(syncStatus, result); callback(result); -- Gitee From 0b1520f5602cd5a1410a4fe3c52624232505fdcd Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 23 May 2023 10:54:55 +0800 Subject: [PATCH 095/437] style:code check Signed-off-by: htt1997 --- .../distributeddataservice/service/rdb/rdb_service_impl.cpp | 2 +- .../distributeddataservice/service/rdb/rdb_service_stub.cpp | 1 - services/distributeddataservice/service/rdb/rdb_syncer.cpp | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 46955dc6..b4980b4a 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -126,7 +126,7 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib ZLOGI("%{public}.6s", identifierHex.c_str()); std::vector entries; auto localId = DmAdapter::GetInstance().GetLocalDevice().uuid; - if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ localId }), entries)) { + if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix( { localId } ), entries)) { ZLOGE("get meta failed"); return false; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 224109f0..034e9822 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -211,5 +211,4 @@ int RdbServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageP } return RDB_ERROR; } - } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 96318c06..55f44b5a 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -94,7 +94,7 @@ std::string RdbSyncer::GetBundleName() const std::string RdbSyncer::GetAppId() const { - return DistributedData::CheckerManager::GetInstance().GetAppId({ uid_, token_, param_.bundleName_ }); + return DistributedData::CheckerManager::GetInstance().GetAppId( { uid_, token_, param_.bundleName_ } ); } std::string RdbSyncer::GetStoreId() const -- Gitee From 9bfeaf8e7ff4489542a738294ded7b2f41575c83 Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 23 May 2023 14:35:01 +0800 Subject: [PATCH 096/437] f Signed-off-by: hanlu --- .../data_share/data/published_data.cpp | 20 +++++++----- .../service/data_share/data/published_data.h | 4 ++- .../data_share/data_share_service_impl.cpp | 2 +- .../data_share/data_share_service_impl.h | 4 ++- .../strategies/get_data_strategy.cpp | 32 +++++++++++-------- .../data_share/strategies/get_data_strategy.h | 6 ++-- .../strategies/publish_strategy.cpp | 15 ++++----- .../data_share/strategies/publish_strategy.h | 2 +- .../service/object/object_callback_proxy.cpp | 4 +-- 9 files changed, 52 insertions(+), 37 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 4dd329be..6d710629 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -40,7 +40,12 @@ PublishedData::PublishedData(const std::string &key, const std::string &bundleNa { value.SetVersion(version); } -/* + +PublishedData::PublishedData(PublishedDataNode node) + : KvData(Id(GenId(node.key, node.bundleName, node.subscriberId))), value(node) +{ +} + std::vector PublishedData::Query(const std::string &bundleName) { auto delegate = KvDBDelegate::GetInstance(); @@ -49,22 +54,21 @@ std::vector PublishedData::Query(const std::string &bundleName) return std::vector(); } std::vector queryResults; - json filter; - filter["bundleName"] = bundleName; - int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, filter.dump(), "{}", queryResults); + int32_t status = + delegate->GetBatch(KvDBDelegate::DATA_TABLE, "{\"bundleName\":\"" + bundleName + "\"}", "{}", queryResults); if (status != E_OK) { ZLOGE("db Upsert failed, %{public}s %{public}d", bundleName.c_str(), status); return std::vector(); } std::vector results; for (auto &result : queryResults) { - PublishedData data; - if (data.Unmarshall(result)) { - results.push_back(std::move(data)); + PublishedDataNode data; + if (PublishedDataNode::Unmarshall(result, data)) { + results.emplace_back(data); } } return results; -} */ +} bool PublishedDataNode::Marshal(DistributedData::Serializable::json &node) const { diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index daa7d667..b94ce1a1 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -37,7 +37,8 @@ public: class PublishedData final : public KvData { public: - // static std::vector Query(const std::string &bundleName); + explicit PublishedData(PublishedDataNode node); + static std::vector Query(const std::string &bundleName); static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); PublishedData(const std::string &key, const std::string &bundleName, int64_t subscriberId, @@ -46,6 +47,7 @@ public: bool HasVersion() const override; int GetVersion() const override; std::string GetValue() const override; + friend class GetDataStrategy; private: PublishedDataNode value; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 3209b7cc..e84508eb 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -180,7 +180,7 @@ Data DataShareServiceImpl::GetData(const std::string &bundleNameOfProvider) auto context = std::make_shared(); context->callerBundleName = callerBundleName; context->calledBundleName = bundleNameOfProvider; - return GetDataStrategy::Execute(context); + return getDataStrategy_.Execute(context); } std::vector DataShareServiceImpl::SubscribeRdbData( diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 74dc44b3..1b1b6e0e 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -22,9 +22,10 @@ #include "data_share_service_stub.h" #include "datashare_template.h" #include "db_delegate.h" +#include "get_data_strategy.h" +#include "publish_strategy.h" #include "uri_utils.h" #include "visibility.h" -#include "publish_strategy.h" namespace OHOS::DataShare { class API_EXPORT DataShareServiceImpl : public DataShareServiceStub { @@ -71,6 +72,7 @@ private: static Factory factory_; static constexpr int32_t ERROR = -1; PublishStrategy publishStrategy_; + GetDataStrategy getDataStrategy_; BindInfo binderInfo_; }; } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp index 2d5e432b..1f204186 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp @@ -25,38 +25,44 @@ namespace OHOS::DataShare { Data GetDataStrategy::Execute(std::shared_ptr context) { - auto preProcess = GetStrategy(); - if (preProcess == nullptr) { + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); return Data(); } - if (!(*preProcess)(context)) { + if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return Data(); } - return Data(); + auto result = PublishedData::Query(context->calledBundleName); + Data data; + for (const auto &item:result) { + if (item.GetVersion() > data.version_) { + data.version_ = item.GetVersion(); + } + data.datas_.emplace_back(item.value.key, item.value.subscriberId, item.value.value); + } + return data; } -Strategy *GetDataStrategy::GetStrategy() +SeqStrategy &GetDataStrategy::GetStrategy() { - static std::mutex mutex; - static SeqStrategy strategies; - std::lock_guard lock(mutex); - if (!strategies.IsEmpty()) { - return &strategies; + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; } std::initializer_list list = { new (std::nothrow) LoadConfigCommonStrategy(), new (std::nothrow) LoadConfigFromDataProxyNodeStrategy(), new (std::nothrow) PermissionStrategy() }; - auto ret = strategies.Init(list); + auto ret = strategies_.Init(list); if (!ret) { std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); - return nullptr; + return strategies_; } - return &strategies; + return strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h index 9200ad9b..53a24199 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h @@ -26,10 +26,12 @@ namespace OHOS::DataShare { class GetDataStrategy final { public: - static Data Execute(std::shared_ptr context); + Data Execute(std::shared_ptr context); private: - static Strategy *GetStrategy(); + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index db4a1c63..433d51cd 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -26,13 +26,12 @@ namespace OHOS::DataShare { int32_t PublishStrategy::Execute(std::shared_ptr context, const PublishedDataItem &item) { - auto preProcess = GetStrategy(); - if (preProcess == nullptr) { + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); return -1; } - - if (!(*preProcess)(context)) { + if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return -1; } @@ -51,11 +50,11 @@ int32_t PublishStrategy::Execute(std::shared_ptr context, const Publish return E_OK; } -Strategy *PublishStrategy::GetStrategy() +SeqStrategy &PublishStrategy::GetStrategy() { std::lock_guard lock(mutex_); if (!strategies_.IsEmpty()) { - return &strategies_; + return strategies_; } std::initializer_list list = { new (std::nothrow) LoadConfigCommonStrategy(), @@ -67,8 +66,8 @@ Strategy *PublishStrategy::GetStrategy() std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); - return nullptr; + return strategies_; } - return &strategies_; + return strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.h b/services/distributeddataservice/service/data_share/strategies/publish_strategy.h index c518f722..92cebcf9 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.h @@ -27,7 +27,7 @@ public: int32_t Execute(std::shared_ptr context, const PublishedDataItem &item); private: - Strategy *GetStrategy(); + SeqStrategy &GetStrategy(); std::mutex mutex_; SeqStrategy strategies_; }; diff --git a/services/distributeddataservice/service/object/object_callback_proxy.cpp b/services/distributeddataservice/service/object/object_callback_proxy.cpp index 4e88e7dc..0eb7942b 100644 --- a/services/distributeddataservice/service/object/object_callback_proxy.cpp +++ b/services/distributeddataservice/service/object/object_callback_proxy.cpp @@ -15,8 +15,8 @@ #define LOG_TAG "IObjectCallbackProxy" #include "object_callback_proxy.h" -#include -#include + +#include "ipc_skeleton.h" #include "itypes_util.h" #include "log_print.h" -- Gitee From a10ec873d3edf6d916d6c8ee7b4ebb8c94b4f79c Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 23 May 2023 14:35:29 +0800 Subject: [PATCH 097/437] task_scheduler -> executor_pool Signed-off-by: niudongyao --- .../data_share/common/scheduler_manager.cpp | 25 +++++++++++-------- .../data_share/common/scheduler_manager.h | 8 +++--- .../data_share/data_share_service_impl.cpp | 2 ++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index 86032a1b..d694b011 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -59,19 +59,20 @@ void SchedulerManager::Execute(const Key &key, const std::string &rdbDir, int ve void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Key &key, int64_t reminderTime) { std::lock_guard lock(mutex_); - if (scheduler_ == nullptr) { - scheduler_ = std::make_shared(TIME_TASK_NUM, "remind_timer"); + if (executor_ == nullptr) { + ZLOGE("executor_ is nullptr"); + return; } auto it = timerCache_.find(key); if (it != timerCache_.end()) { // has current timer, reset time ZLOGD("has current taskId, uri is %{public}s, subscriberId is %{public}" PRId64 ", bundleName is %{public}s", DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); - scheduler_->Reset(it->second, std::chrono::seconds(reminderTime - time(nullptr))); + executor_->Reset(it->second, std::chrono::seconds(reminderTime - time(nullptr))); return; } // not find task in map, create new timer - auto taskId = scheduler_->At(TaskScheduler::Clock::now() + std::chrono::seconds(reminderTime - time(nullptr)), + auto taskId = executor_->Schedule(std::chrono::seconds(reminderTime - time(nullptr)), [key, dbPath, version, this]() { timerCache_.erase(key); // 1. execute schedulerSQL in next time @@ -79,7 +80,7 @@ void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Ke // 2. notify RdbSubscriberManager::GetInstance().EmitByKey(key, dbPath, version); }); - if (taskId == TaskScheduler::INVALID_TASK_ID) { + if (taskId == ExecutorPool::INVALID_TASK_ID) { ZLOGE("create timer failed, over the max capacity"); return; } @@ -143,20 +144,22 @@ void SchedulerManager::GenRemindTimerFuncParams(const std::string &rdbDir, int v void SchedulerManager::RemoveTimer(const Key &key) { std::lock_guard lock(mutex_); - if (scheduler_ == nullptr) { - ZLOGD("scheduler_ is nullptr"); + if (executor_ == nullptr) { + ZLOGE("executor_ is nullptr"); return; } auto it = timerCache_.find(key); if (it != timerCache_.end()) { ZLOGD("RemoveTimer %{public}s %{public}s %{public}" PRId64, DistributedData::Anonymous::Change(key.uri).c_str(), key.bundleName.c_str(), key.subscriberId); - scheduler_->Remove(it->second); + executor_->Remove(it->second); timerCache_.erase(key); - if (timerCache_.empty()) { - scheduler_ = nullptr; - } } } + +void SchedulerManager::SetExecutorPool(std::shared_ptr executor) +{ + executor_ = executor; +} } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.h b/services/distributeddataservice/service/data_share/common/scheduler_manager.h index d5e5479b..05a75fa3 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.h +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.h @@ -19,7 +19,7 @@ #include #include "db_delegate.h" -#include "task_scheduler.h" +#include "executor_pool.h" #include "template_manager.h" namespace OHOS::DataShare { @@ -30,11 +30,11 @@ public: void Execute(const Key &key, const std::string &rdbDir, int version); void SetTimer(const std::string &dbPath, int version, const Key &key, int64_t reminderTime); void RemoveTimer(const Key &key); + void SetExecutorPool(std::shared_ptr executor); private: static constexpr const char *REMIND_TIMER_FUNC = "remindTimer("; static constexpr int REMIND_TIMER_FUNC_LEN = 12; - static constexpr size_t TIME_TASK_NUM = 10; SchedulerManager() = default; ~SchedulerManager() = default; static void GenRemindTimerFuncParams(const std::string &rdbDir, int version, const Key &key, @@ -43,8 +43,8 @@ private: std::shared_ptr delegate); std::mutex mutex_; - std::map timerCache_; - std::shared_ptr scheduler_ = nullptr; + std::map timerCache_; + std::shared_ptr executor_ = nullptr; }; } // namespace OHOS::DataShare #endif // SCHEDULER_MANAGER_H diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 3209b7cc..dedfcb72 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -336,6 +336,7 @@ enum DataShareKvStoreType : int32_t { int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) { binderInfo_ = binderInfo; + SchedulerManager::GetInstance().SetExecutorPool(binderInfo.executors); const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); const auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(binderInfo.selfTokenId); DistributedData::StoreMetaData saveMeta; @@ -355,6 +356,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); KvDBDelegate::GetInstance(false, saveMeta.dataDir); + SchedulerManager::GetInstance().SetExecutorPool(binderInfo.executors); return EOK; } -- Gitee From a95a8ac2a68f5bddec1ff424a5174b1fd1263f56 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 23 May 2023 14:36:36 +0800 Subject: [PATCH 098/437] task_scheduler -> executor_pool Signed-off-by: niudongyao --- .../service/data_share/data_share_service_impl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index dedfcb72..c947256a 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -336,7 +336,6 @@ enum DataShareKvStoreType : int32_t { int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) { binderInfo_ = binderInfo; - SchedulerManager::GetInstance().SetExecutorPool(binderInfo.executors); const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); const auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(binderInfo.selfTokenId); DistributedData::StoreMetaData saveMeta; -- Gitee From da5fdf1f6fd907082ccce1bdcdf7e3c92014dbcb Mon Sep 17 00:00:00 2001 From: e Date: Tue, 23 May 2023 15:11:11 +0800 Subject: [PATCH 099/437] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: e --- .../app/src/kvstore_data_service.cpp | 2 +- .../framework/store/auto_cache.cpp | 11 +++++------ .../service/kvdb/kvdb_service_impl.cpp | 1 - .../service/kvdb/store_cache.cpp | 11 +++++------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 4c5dc06f..8138acdc 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -161,7 +161,7 @@ void KvStoreDataService::LoadFeatures() { ZLOGI("begin."); auto features = FeatureSystem::GetInstance().GetFeatureName(FeatureSystem::BIND_NOW); - for (auto &feature : features) { + for (auto const &feature : features) { GetFeatureInterface(feature); } } diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index db51ad5c..53f671ee 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -174,13 +174,12 @@ bool AutoCache::Delegate::Close() std::unique_lock lock(mutex_); if (store_ != nullptr) { store_->Unwatch(ORIGIN_ALL, *this); + auto status = store_->Close(); + if (status == Error::E_BUSY) { + return false; + } + store_ = nullptr; } - - auto status = store_->Close(); - if (status == Error::E_BUSY) { - return false; - } - store_ = nullptr; return true; } diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 8428cb58..3a51a06f 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -795,7 +795,6 @@ int32_t KVDBServiceImpl::OnExecutor(std::shared_ptr executors) executors_ = executors; storeCache_.SetThreadPool(executors); KvStoreSyncManager::GetInstance()->SetThreadPool(executors); - ZLOGE("onexecutor:%{public}p", executors.get()); return 0; } } // namespace OHOS::DistributedKv \ No newline at end of file diff --git a/services/distributeddataservice/service/kvdb/store_cache.cpp b/services/distributeddataservice/service/kvdb/store_cache.cpp index 093e8e5a..786f528d 100644 --- a/services/distributeddataservice/service/kvdb/store_cache.cpp +++ b/services/distributeddataservice/service/kvdb/store_cache.cpp @@ -234,13 +234,12 @@ bool StoreCache::DBStoreDelegate::Close(DBManager &manager) std::unique_lock lock(mutex_); if (delegate_ != nullptr) { delegate_->UnRegisterObserver(this); + auto status = manager.CloseKvStore(delegate_); + if (status == DBStatus::BUSY) { + return false; + } + delegate_ = nullptr; } - - auto status = manager.CloseKvStore(delegate_); - if (status == DBStatus::BUSY) { - return false; - } - delegate_ = nullptr; return true; } -- Gitee From 49f0dfb80579887f86b0b0708f623094fbcfec79 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 23 May 2023 15:42:47 +0800 Subject: [PATCH 100/437] fix:Review comments modification Signed-off-by: htt1997 --- .../framework/cloud/schema_meta.cpp | 14 ++-- .../framework/include/cloud/schema_meta.h | 56 +++++++------ .../framework/include/store/general_store.h | 21 ++++- .../framework/include/store/general_value.h | 24 ++++++ .../service/cloud/cloud_service_impl.cpp | 2 +- .../service/rdb/rdb_general_store.cpp | 84 ++++++++++++------- .../service/rdb/rdb_general_store.h | 12 +-- 7 files changed, 140 insertions(+), 73 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/schema_meta.cpp b/services/distributeddataservice/framework/cloud/schema_meta.cpp index b6a8cd4b..d5454361 100644 --- a/services/distributeddataservice/framework/cloud/schema_meta.cpp +++ b/services/distributeddataservice/framework/cloud/schema_meta.cpp @@ -29,7 +29,7 @@ bool SchemaMeta::Unmarshal(const Serializable::json &node) return true; } -bool SchemaMeta::Database::Marshal(Serializable::json &node) const +bool Database::Marshal(Serializable::json &node) const { SetValue(node[GET_NAME(name)], name); SetValue(node[GET_NAME(alias)], alias); @@ -37,7 +37,7 @@ bool SchemaMeta::Database::Marshal(Serializable::json &node) const return true; } -bool SchemaMeta::Database::Unmarshal(const Serializable::json &node) +bool Database::Unmarshal(const Serializable::json &node) { GetValue(node, GET_NAME(name), name); GetValue(node, GET_NAME(alias), alias); @@ -45,7 +45,7 @@ bool SchemaMeta::Database::Unmarshal(const Serializable::json &node) return true; } -bool SchemaMeta::Table::Marshal(Serializable::json &node) const +bool Table::Marshal(Serializable::json &node) const { SetValue(node[GET_NAME(name)], name); SetValue(node[GET_NAME(alias)], alias); @@ -53,7 +53,7 @@ bool SchemaMeta::Table::Marshal(Serializable::json &node) const return true; } -bool SchemaMeta::Table::Unmarshal(const Serializable::json &node) +bool Table::Unmarshal(const Serializable::json &node) { GetValue(node, GET_NAME(name), name); GetValue(node, GET_NAME(alias), alias); @@ -61,7 +61,7 @@ bool SchemaMeta::Table::Unmarshal(const Serializable::json &node) return true; } -bool SchemaMeta::Field::Marshal(Serializable::json &node) const +bool Field::Marshal(Serializable::json &node) const { SetValue(node[GET_NAME(colName)], colName); SetValue(node[GET_NAME(alias)], alias); @@ -71,7 +71,7 @@ bool SchemaMeta::Field::Marshal(Serializable::json &node) const return true; } -bool SchemaMeta::Field::Unmarshal(const Serializable::json &node) +bool Field::Unmarshal(const Serializable::json &node) { GetValue(node, GET_NAME(colName), colName); GetValue(node, GET_NAME(alias), alias); @@ -81,7 +81,7 @@ bool SchemaMeta::Field::Unmarshal(const Serializable::json &node) return true; } -SchemaMeta::Database SchemaMeta::GetDataBase(const std::string &storeId) +Database SchemaMeta::GetDataBase(const std::string &storeId) { for (const auto &database : databases) { if (database.name == storeId) { diff --git a/services/distributeddataservice/framework/include/cloud/schema_meta.h b/services/distributeddataservice/framework/include/cloud/schema_meta.h index 188a0132..d2064961 100644 --- a/services/distributeddataservice/framework/include/cloud/schema_meta.h +++ b/services/distributeddataservice/framework/include/cloud/schema_meta.h @@ -17,39 +17,43 @@ #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SCHEMA_META_H #include "serializable/serializable.h" namespace OHOS::DistributedData { +struct API_EXPORT Field final : public Serializable { + std::string colName; + std::string alias; + int32_t type = 0; + bool primary = false; + bool nullable = true; + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; +}; + +struct API_EXPORT Table final : public Serializable { + std::string name; + std::string alias; + std::vector fields; + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; +}; + +struct API_EXPORT Database final : public Serializable { + std::string name = ""; + std::string alias; + std::vector tables; + + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; +}; + class API_EXPORT SchemaMeta final : public Serializable { public: + using Database = Database; + using Table = Table; + using Field = Field; static constexpr const char *DELETE_FIELD = "#_deleted"; static constexpr const char *GID_FIELD = "#_gid"; static constexpr const char *CREATE_FIELD = "#_createTime"; static constexpr const char *MODIFY_FIELD = "#_modifyTime"; static constexpr const char *CURSOR_FIELD = "#_cursor"; - struct API_EXPORT Field final : public Serializable { - std::string colName; - std::string alias; - int32_t type = 0; - bool primary = false; - bool nullable = true; - bool Marshal(json &node) const override; - bool Unmarshal(const json &node) override; - }; - - struct API_EXPORT Table final : public Serializable { - std::string name; - std::string alias; - std::vector fields; - bool Marshal(json &node) const override; - bool Unmarshal(const json &node) override; - }; - - struct API_EXPORT Database final : public Serializable { - std::string name = ""; - std::string alias; - std::vector
tables; - - bool Marshal(json &node) const override; - bool Unmarshal(const json &node) override; - }; int32_t version = 0; std::vector databases; diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index e31eb889..579634d2 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -18,21 +18,32 @@ #include #include +#include "cloud/schema_meta.h" #include "store/cursor.h" #include "store/general_value.h" #include "store/general_watcher.h" namespace OHOS::DistributedData { class CloudDB; -class SchemaMeta; +class AssetLoader; +struct Database; class GeneralStore { public: using Watcher = GeneralWatcher; - using Async = std::function>)>; + using AsyncDetail = std::function; + using AsyncStatus = std::function>)>; using Devices = std::vector; + struct BindInfo { + BindInfo(std::shared_ptr db = nullptr, std::shared_ptr loader = nullptr) + : db_(std::move(db)), loader_(std::move(loader)) + { + } + std::shared_ptr db_; + std::shared_ptr loader_; + }; virtual ~GeneralStore() = default; - virtual int32_t Bind(const SchemaMeta &schemaMeta, std::shared_ptr cloudDb) = 0; + virtual int32_t Bind(const Database &database, BindInfo bindInfo) = 0; virtual int32_t Execute(const std::string &table, const std::string &sql) = 0; @@ -46,7 +57,9 @@ public: virtual std::shared_ptr Query(const std::string &table, GenQuery &query) = 0; - virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) = 0; + virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncDetail async, int32_t wait) = 0; + + virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncStatus async, int32_t wait) = 0; virtual int32_t Watch(int32_t origin, Watcher &watcher) = 0; diff --git a/services/distributeddataservice/framework/include/store/general_value.h b/services/distributeddataservice/framework/include/store/general_value.h index 05d4766d..9ec68794 100644 --- a/services/distributeddataservice/framework/include/store/general_value.h +++ b/services/distributeddataservice/framework/include/store/general_value.h @@ -24,6 +24,30 @@ #include "error/general_error.h" #include "traits.h" namespace OHOS::DistributedData { +enum Progress { + SYNC_BEGIN, + SYNC_IN_PROGRESS, + SYNC_FINISH, +}; + +struct Statistic { + int32_t total; + int32_t success; + int32_t failed; + int32_t untreated; +}; + +struct TableDetails { + Statistic upload; + Statistic download; +}; + +struct ProgressDetails { + int32_t progress; + int32_t code; + std::map details; +}; + struct Asset { uint32_t version; std::string name; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index f6d8c224..18ce3437 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -424,7 +424,7 @@ void CloudServiceImpl::GetSchema(const Event &event) ZLOGE("store is nullptr"); return; } - store->Bind(schemaMeta, cloudDB); + store->Bind(*database, cloudDB); for (const auto &table : database->tables) { ZLOGD("table: %{public}s sync start", table.name.c_str()); // do sync diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index bd1f118c..c5bf2b39 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -15,6 +15,9 @@ #define LOG_TAG "RdbGeneralStore" #include "rdb_general_store.h" +#include "cloud/asset_loader.h" +#include "cloud/cloud_db.h" +#include "cloud/schema_meta.h" #include "crypto_manager.h" #include "log_print.h" #include "metadata/meta_data_manager.h" @@ -23,11 +26,13 @@ #include "rdb_query.h" #include "rdb_syncer.h" #include "relational_store_manager.h" -#include "store/general_watcher.h" namespace OHOS::DistributedRdb { using namespace DistributedData; using namespace DistributedDB; -using namespace OHOS::NativeRdb; +using namespace NativeRdb; +using DBField = DistributedDB::Field; +using DBTable = DistributedDB::TableSchema; +using DBSchema = DistributedDB::DataBaseSchema; class RdbOpenCallbackImpl : public RdbOpenCallback { public: int OnCreate(RdbStore &rdbStore) override @@ -69,8 +74,47 @@ RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appI } } +RdbGeneralStore::~RdbGeneralStore() +{ + manager_.CloseStore(delegate_); + delegate_ = nullptr; + store_ = nullptr; + bindInfo_.loader_ = nullptr; + bindInfo_.db_->Close(); + bindInfo_.db_ = nullptr; +} + +int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) +{ + bindInfo_ = std::move(bindInfo); + // SetCloudDB + DBSchema schema; + schema.tables.resize(database.tables.size()); + for (size_t i = 0; i < database.tables.size(); i++) { + const Table &table = database.tables[i]; + DBTable &dbTable = schema.tables[i]; + dbTable.name = table.name; + for (auto &field : table.fields) { + DBField dbField; + dbField.colName = field.colName; + dbField.type = field.type; + dbField.primary = field.primary; + dbField.nullable = field.nullable; + dbTable.fields.push_back(std::move(dbField)); + } + } + // SetCloudDbSchema + return GeneralError::E_NOT_SUPPORT; +} + int32_t RdbGeneralStore::Close() { + manager_.CloseStore(delegate_); + delegate_ = nullptr; + store_ = nullptr; + bindInfo_.loader_ = nullptr; + bindInfo_.db_->Close(); + bindInfo_.db_ = nullptr; return 0; } @@ -104,43 +148,25 @@ std::shared_ptr RdbGeneralStore::Query(const std::string &table, GenQuer return std::shared_ptr(); } -int32_t RdbGeneralStore::Watch(int32_t origin, Watcher &watcher) +int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncDetail async, int32_t wait) { - watcher_ = &watcher; return GeneralError::E_NOT_SUPPORT; + } -int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) +int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncStatus async, int32_t wait) { - return 0; + return GeneralError::E_NOT_SUPPORT; + } -int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) +int32_t RdbGeneralStore::Watch(int32_t origin, Watcher &watcher) { - RdbQuery *rdbQuery = nullptr; - auto ret = query.QueryInterface(rdbQuery); - if (ret != GeneralError::E_OK || rdbQuery == nullptr) { - return GeneralError::E_OK; - } - auto status = delegate_->Sync( - devices, DistributedDB::SyncMode(mode), RdbSyncer::MakeQuery(rdbQuery->predicates_.GetDistributedPredicates()), - [async](const std::map> &result) { - std::map> detail; - for (auto &[key, tables] : result) { - auto value = detail[key]; - for (auto &table : tables) { - value[std::move(table.tableName)] = table.status; - } - } - async(std::move(detail)); - }, - wait); - return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; + return GeneralError::E_NOT_SUPPORT; } -int32_t RdbGeneralStore::Bind(const SchemaMeta &schemaMeta, std::shared_ptr cloudDb) +int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) { - cloudDb_ = std::move(cloudDb); - return 0; + return GeneralError::E_NOT_SUPPORT; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 3d2fda30..f337fe56 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -32,21 +32,22 @@ public: using Value = DistributedData::Value; using Values = DistributedData::Values; using StoreMetaData = DistributedData::StoreMetaData; - using SchemaMeta = DistributedData::SchemaMeta; - using CloudDB = DistributedData::CloudDB; + using Database = DistributedData::Database; using RdbStore = OHOS::NativeRdb::RdbStore; using RdbDelegate = DistributedDB::RelationalStoreDelegate; using RdbManager = DistributedDB::RelationalStoreManager; explicit RdbGeneralStore(const StoreMetaData &metaData); - int32_t Bind(const SchemaMeta &schemaMeta, std::shared_ptr cloudDb) override; + ~RdbGeneralStore(); + int32_t Bind(const Database &database, BindInfo bindInfo) override; int32_t Execute(const std::string &table, const std::string &sql) override; int32_t BatchInsert(const std::string &table, VBuckets &&values) override; int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; int32_t Delete(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, GenQuery &query) override; - int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, Async async, int32_t wait) override; + int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncDetail async, int32_t wait) override; + int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncStatus async, int32_t wait) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; int32_t Close() override; @@ -57,8 +58,7 @@ private: RdbManager manager_; RdbDelegate *delegate_ = nullptr; std::shared_ptr store_; - std::shared_ptr cloudDb_; - Watcher *watcher_; + BindInfo bindInfo_; }; } // namespace OHOS::DistributedRdb #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H -- Gitee From 4df4f4d96f456a1ac3b36404b43c8127297da463 Mon Sep 17 00:00:00 2001 From: e Date: Tue, 23 May 2023 16:11:48 +0800 Subject: [PATCH 101/437] change4 Signed-off-by: e --- .../distributeddataservice/app/src/flowctrl_manager/BUILD.gn | 1 - .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn b/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn index 61f30728..eae2ee83 100755 --- a/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn +++ b/services/distributeddataservice/app/src/flowctrl_manager/BUILD.gn @@ -23,7 +23,6 @@ ohos_static_library("distributeddata_flowctrl_static") { "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", "${kv_store_path}/interfaces/innerkits/distributeddata/include", "//third_party/json/single_include", - "//commonlibrary/c_utils/base/include", ] cflags_cc = [ "-fvisibility=hidden" ] diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index b605daf5..9ec87a5e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -447,7 +447,6 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &sub) std::map> unsubDbs; for (auto &app : cloudInfo.apps) { auto enabled = cloudInfo.enableCloud && app.cloudSwitch; - auto &dbs = enabled ? subDbs : unsubDbs; auto it = sub.expiresTime.find(app.bundleName); // cloud is enabled, but the subscription won't expire if (enabled && (it != sub.expiresTime.end() && it->second >= onThreshold.count())) { @@ -461,6 +460,7 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &sub) SchemaMeta schemaMeta; exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(app.bundleName), schemaMeta, true); if (exits) { + auto &dbs = enabled ? subDbs : unsubDbs; dbs[app.bundleName] = std::move(schemaMeta.databases); } } -- Gitee From 7720440fe9e92f578d8ba6f8220f331099c1ba13 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 23 May 2023 17:13:38 +0800 Subject: [PATCH 102/437] fix warn Signed-off-by: niudongyao --- .../distributeddataservice/service/data_share/common/context.h | 2 +- .../service/data_share/common/rdb_delegate.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/context.h b/services/distributeddataservice/service/data_share/common/context.h index d506e4b1..062319c3 100644 --- a/services/distributeddataservice/service/data_share/common/context.h +++ b/services/distributeddataservice/service/data_share/common/context.h @@ -38,7 +38,7 @@ public: std::string uri; int32_t currentUserId = -1; std::string permission; - uint32_t callerTokenId = -1; + uint32_t callerTokenId = 0; std::string callerBundleName; std::string calledBundleName; std::string calledModuleName; diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 3965a58f..7a331e2a 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -35,7 +35,7 @@ enum REMIND_TIMER_ARGS : int32_t { }; std::string RemindTimerFunc(const std::vector &args) { - int size = args.size(); + size_t size = args.size(); if (size != ARGS_SIZE) { ZLOGE("RemindTimerFunc args size error, %{public}d", size); return ""; -- Gitee From 420a7e1c20aefd6db3c526ad6d0fdc896467b635 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 23 May 2023 17:16:33 +0800 Subject: [PATCH 103/437] fix warn Signed-off-by: niudongyao --- .../service/data_share/common/rdb_delegate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 7a331e2a..8dcd025d 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -37,7 +37,7 @@ std::string RemindTimerFunc(const std::vector &args) { size_t size = args.size(); if (size != ARGS_SIZE) { - ZLOGE("RemindTimerFunc args size error, %{public}d", size); + ZLOGE("RemindTimerFunc args size error, %{public}zu", size); return ""; } std::string dbPath = args[ARG_DB_PATH]; -- Gitee From 2e391f680ae6708bea343419e4843cc3274abe0c Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 23 May 2023 17:19:28 +0800 Subject: [PATCH 104/437] f Signed-off-by: hanlu --- .../data_share/data/published_data.cpp | 2 +- .../service/data_share/data/published_data.h | 2 +- ...d_config_from_data_proxy_node_strategy.cpp | 5 +++ .../strategies/get_data_strategy.cpp | 36 ++++++++++++++++--- .../data_share/strategies/get_data_strategy.h | 1 + 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 6d710629..d179ba4c 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -41,7 +41,7 @@ PublishedData::PublishedData(const std::string &key, const std::string &bundleNa value.SetVersion(version); } -PublishedData::PublishedData(PublishedDataNode node) +PublishedData::PublishedData(const PublishedDataNode &node) : KvData(Id(GenId(node.key, node.bundleName, node.subscriberId))), value(node) { } diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index b94ce1a1..0752d969 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -37,7 +37,7 @@ public: class PublishedData final : public KvData { public: - explicit PublishedData(PublishedDataNode node); + explicit PublishedData(const PublishedDataNode &node); static std::vector Query(const std::string &bundleName); static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); diff --git a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp index d2ad30b5..843966da 100644 --- a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp @@ -31,8 +31,13 @@ bool LoadConfigFromDataProxyNodeStrategy::operator()(std::shared_ptr co if (!BundleMgrProxy::GetInstance()->GetBundleInfoFromBMS( context->calledBundleName, context->currentUserId, context->bundleInfo)) { ZLOGE("GetBundleInfoFromBMS failed! bundleName: %{public}s", context->calledBundleName.c_str()); + context->errCode = E_BUNDLE_NAME_NOT_EXIST; return false; } + if (context->uri.empty()) { + context->permission = "reject"; + return true; + } for (auto &hapModuleInfo : context->bundleInfo.hapModuleInfos) { auto proxyDatas = hapModuleInfo.proxyDatas; for (auto &proxyData : proxyDatas) { diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp index 1f204186..15166cb1 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp @@ -16,9 +16,9 @@ #include "get_data_strategy.h" -#include "general/load_config_common_strategy.h" -#include "general/permission_strategy.h" +#include "accesstoken_kit.h" #include "data_proxy/load_config_from_data_proxy_node_strategy.h" +#include "general/load_config_common_strategy.h" #include "log_print.h" #include "utils/anonymous.h" @@ -37,6 +37,10 @@ Data GetDataStrategy::Execute(std::shared_ptr context) auto result = PublishedData::Query(context->calledBundleName); Data data; for (const auto &item:result) { + if (!CheckPermission(context, item.value.key)) { + ZLOGI("uri: %{private}s not allowed", context->uri.c_str()); + continue; + } if (item.GetVersion() > data.version_) { data.version_ = item.GetVersion(); } @@ -53,8 +57,7 @@ SeqStrategy &GetDataStrategy::GetStrategy() } std::initializer_list list = { new (std::nothrow) LoadConfigCommonStrategy(), - new (std::nothrow) LoadConfigFromDataProxyNodeStrategy(), - new (std::nothrow) PermissionStrategy() + new (std::nothrow) LoadConfigFromDataProxyNodeStrategy() }; auto ret = strategies_.Init(list); if (!ret) { @@ -65,4 +68,29 @@ SeqStrategy &GetDataStrategy::GetStrategy() } return strategies_; } + +bool GetDataStrategy::CheckPermission(std::shared_ptr context, const std::string &key) +{ + if (context->callerBundleName == context->calledBundleName) { + ZLOGI("access private data, caller and called is same, go"); + return true; + } + for (const auto &moduleInfo:context->bundleInfo.hapModuleInfos) { + auto proxyDatas = moduleInfo.proxyDatas; + for (auto &proxyData : proxyDatas) { + if (proxyData.uri != key) { + continue; + } + int status = + Security::AccessToken::AccessTokenKit::VerifyAccessToken(context->callerTokenId, proxyData.requiredReadPermission); + if (status != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + ZLOGE("Verify permission denied! callerTokenId:%{public}u permission:%{public}s", + context->callerTokenId, proxyData.requiredReadPermission.c_str()); + return false; + } + return true; + } + } + return false; +} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h index 53a24199..1f7a4189 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h @@ -32,6 +32,7 @@ private: SeqStrategy &GetStrategy(); std::mutex mutex_; SeqStrategy strategies_; + bool CheckPermission(std::shared_ptr context, const std::string &key); }; } // namespace OHOS::DataShare #endif -- Gitee From b66cc3a2ccc99aa40e0108623541aed775a4d71a Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 23 May 2023 17:21:21 +0800 Subject: [PATCH 105/437] fix warn Signed-off-by: niudongyao --- .../strategies/general/load_config_data_info_strategy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index 0aab4f83..4ad67991 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -64,7 +64,7 @@ bool LoadConfigNormalDataInfoStrategy::operator()(std::shared_ptr conte } } context->calledSourceDir = metaData.dataDir; - context->version = metaData.version; + context->version = static_cast(metaData.version); return true; } -- Gitee From 4495b4e517ca8259d3d72801de97688b133f8226 Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 23 May 2023 19:18:29 +0800 Subject: [PATCH 106/437] f Signed-off-by: hanlu --- .../service/data_share/strategies/get_data_strategy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp index 15166cb1..5965bf25 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp @@ -75,17 +75,17 @@ bool GetDataStrategy::CheckPermission(std::shared_ptr context, const st ZLOGI("access private data, caller and called is same, go"); return true; } - for (const auto &moduleInfo:context->bundleInfo.hapModuleInfos) { + for (const auto &moduleInfo : context->bundleInfo.hapModuleInfos) { auto proxyDatas = moduleInfo.proxyDatas; for (auto &proxyData : proxyDatas) { if (proxyData.uri != key) { continue; } - int status = - Security::AccessToken::AccessTokenKit::VerifyAccessToken(context->callerTokenId, proxyData.requiredReadPermission); + int status = Security::AccessToken::AccessTokenKit::VerifyAccessToken( + context->callerTokenId, proxyData.requiredReadPermission); if (status != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { ZLOGE("Verify permission denied! callerTokenId:%{public}u permission:%{public}s", - context->callerTokenId, proxyData.requiredReadPermission.c_str()); + context->callerTokenId, proxyData.requiredReadPermission.c_str()); return false; } return true; -- Gitee From ef23c76641ebadbf916a5a31db1d27c7b4027d23 Mon Sep 17 00:00:00 2001 From: e Date: Tue, 23 May 2023 20:01:11 +0800 Subject: [PATCH 107/437] change5 Signed-off-by: e --- .../distributeddataservice/service/rdb/rdb_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 42ff8350..88f79bc6 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -438,7 +438,7 @@ int32_t RdbServiceImpl::DoSubscribe(const RdbSyncerParam& param, const Subscribe void RdbServiceImpl::OnChange(uint32_t tokenId, const std::string &storeName) { pid_t pid = 0; - syncAgents_.ComputeIfPresent(tokenId, [&pid, &storeName](auto &key, const SyncAgent &value) { + syncAgents_.ComputeIfPresent(tokenId, [&pid, &storeName](auto &key, SyncAgent &value) { pid = value.pid_; return true; }); -- Gitee From 30fac883a22c6a9255fbe620bc29d236b48d9ebb Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 23 May 2023 20:51:54 +0800 Subject: [PATCH 108/437] f Signed-off-by: hanlu --- .../service/data_share/strategies/get_data_strategy.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp index 5965bf25..c4962d78 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp @@ -81,6 +81,10 @@ bool GetDataStrategy::CheckPermission(std::shared_ptr context, const st if (proxyData.uri != key) { continue; } + if (proxyData.requiredReadPermission.empty()) { + ZLOGE("no read permission"); + return false; + } int status = Security::AccessToken::AccessTokenKit::VerifyAccessToken( context->callerTokenId, proxyData.requiredReadPermission); if (status != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { -- Gitee From a030f394b02dba1d8a92b7c3e51f9640e2a6010e Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 23 May 2023 21:17:59 +0800 Subject: [PATCH 109/437] fix:Review comments modification Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 3 +- .../service/rdb/rdb_general_store.cpp | 2 - .../service/rdb/rdb_service_impl.cpp | 44 ++++++++++++++++--- .../service/rdb/rdb_service_impl.h | 2 + .../service/rdb/rdb_syncer.cpp | 19 ++++++-- .../service/rdb/rdb_syncer.h | 2 + 6 files changed, 59 insertions(+), 13 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 18ce3437..35fdbccf 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -415,7 +415,8 @@ void CloudServiceImpl::GetSchema(const Event &event) ZLOGD("database: %{public}s sync start", database->name.c_str()); auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, *database); if (cloudDB == nullptr) { - ZLOGE("cloudDB is nullptr"); + ZLOGE("cloudDB is nullptr, bundleName:%{public}s user:%{public}d database:%{public}s", + rdbEvent.GetStoreInfo().bundleName.c_str(), rdbEvent.GetStoreInfo().user, database->name.c_str()); return; } AutoCache::Watchers watchers; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index c5bf2b39..8ccc8d1d 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -151,13 +151,11 @@ std::shared_ptr RdbGeneralStore::Query(const std::string &table, GenQuer int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncDetail async, int32_t wait) { return GeneralError::E_NOT_SUPPORT; - } int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncStatus async, int32_t wait) { return GeneralError::E_NOT_SUPPORT; - } int32_t RdbGeneralStore::Watch(int32_t origin, Watcher &watcher) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index b4980b4a..4e38a5aa 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -554,16 +554,22 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } - - auto saved = MetaDataManager::GetInstance().SaveMeta(meta.GetKey(), meta); - if (!saved) { - return RDB_ERROR; + if (!isCreated || meta != old) { + Upgrade(param, meta, old); + ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " + "area:%{public}d->%{public}d", + meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, + meta.isEncrypt, old.area, meta.area); + MetaDataManager::GetInstance().SaveMeta(meta.GetKey(), meta); } AppIDMetaData appIdMeta; appIdMeta.bundleName = meta.bundleName; appIdMeta.appId = meta.appId; - saved = MetaDataManager::GetInstance().SaveMeta(appIdMeta.GetKey(), appIdMeta, true); - if (!saved) { + if (!MetaDataManager::GetInstance().SaveMeta(appIdMeta.GetKey(), appIdMeta, true)) { + ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " + "area:%{public}d->%{public}d", + meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, + meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } if (!param.isEncrypt_ || param.password_.empty()) { @@ -586,6 +592,32 @@ int32_t RdbServiceImpl::SetSecretKey(const RdbSyncerParam ¶m, const StoreMet return MetaDataManager::GetInstance().SaveMeta(meta.GetSecretKey(), newSecretKey, true) ? RDB_OK : RDB_ERROR; } +int32_t RdbServiceImpl::Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &meta, const StoreMetaData &old) +{ + if (old.storeType == RDB_DEVICE_COLLABORATION && old.version < StoreMetaData::UUID_CHANGED_TAG) { + pid_t pid = IPCSkeleton::GetCallingPid(); + auto rdbObserver = new (std::nothrow) RdbStoreObserverImpl(this, pid); + if (rdbObserver == nullptr) { + return RDB_ERROR; + } + auto syncer = new (std::nothrow) RdbSyncer(param, rdbObserver); + if (syncer == nullptr) { + ZLOGE("new syncer error"); + return RDB_ERROR; + } + auto uid = IPCSkeleton::GetCallingUid(); + auto tokenId = IPCSkeleton::GetCallingTokenID(); + if (syncer->Init(pid, uid, tokenId, meta) != RDB_OK) { + ZLOGE("Init error"); + delete syncer; + return RDB_ERROR; + } + syncer->RemoveDeviceData(); + delete syncer; + } + return RDB_OK; +} + int32_t RdbServiceImpl::OnBind(const BindInfo &bindInfo) { executors_ = bindInfo.executors; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 75e0cbab..b3de8bba 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -99,6 +99,8 @@ private: int32_t SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta); + int32_t Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &meta, const StoreMetaData &old); + class DeathRecipientImpl : public IRemoteObject::DeathRecipient { public: using DeathCallback = std::function; diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 55f44b5a..f969ce43 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -114,10 +114,6 @@ int32_t RdbSyncer::Init(pid_t pid, pid_t uid, uint32_t token, const StoreMetaDat return RDB_ERROR; } - if (meta.storeType == RDB_DEVICE_COLLABORATION && meta.version < StoreMetaData::UUID_CHANGED_TAG) { - delegate_->RemoveDeviceData(); - } - ZLOGI("success"); return RDB_OK; } @@ -409,4 +405,19 @@ int32_t RdbSyncer::RemoteQuery(const std::string& device, const std::string& sql } return RDB_OK; } + +int32_t RdbSyncer::RemoveDeviceData() +{ + auto* delegate = GetDelegate(); + if (delegate == nullptr) { + ZLOGE("delegate is nullptr"); + return RDB_ERROR; + } + DistributedDB::DBStatus status = delegate->RemoveDeviceData(); + if (status != DistributedDB::DBStatus::OK) { + ZLOGE("DistributedDB RemoveDeviceData failed, status is %{public}d.", status); + return RDB_ERROR; + } + return RDB_OK; +} } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.h b/services/distributeddataservice/service/rdb/rdb_syncer.h index 68d1e44f..30dc8402 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -55,6 +55,8 @@ public: int32_t RemoteQuery(const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet); + int32_t RemoveDeviceData(); + static std::string RemoveSuffix(const std::string& name); static int32_t GetInstIndex(uint32_t tokenId, const std::string &bundleName); -- Gitee From a9785b51fac7f1e7c4ec27f58b5381b636bfcf12 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 11:22:58 +0800 Subject: [PATCH 110/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 1 + .../data_share/common/app_connect_manager.cpp | 50 +++++++++++++++++++ .../data_share/common/app_connect_manager.h | 36 +++++++++++++ .../data_share/data_share_service_impl.cpp | 7 +++ .../data_share/data_share_service_impl.h | 1 + .../data_share/data_share_service_stub.cpp | 6 +++ .../data_share/data_share_service_stub.h | 4 +- .../service/data_share/idata_share_service.h | 2 + .../general/connect_extension_strategy.cpp | 27 +++------- .../general/connect_extension_strategy.h | 2 +- .../load_config_data_info_strategy.cpp | 11 ++-- 11 files changed, 119 insertions(+), 28 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/common/app_connect_manager.cpp create mode 100644 services/distributeddataservice/service/data_share/common/app_connect_manager.h diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index f47d5b04..11302dcb 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -34,6 +34,7 @@ group("build_module") { } ohos_shared_library("data_share_service") { sources = [ + "common/app_connect_manager.cpp", "common/bundle_mgr_proxy.cpp", "common/db_delegate.cpp", "common/div_strategy.cpp", diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp new file mode 100644 index 00000000..1b2921e8 --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ +#define LOG_TAG "AppConnectManager" +#include "app_connect_manager.h" +#include "log_print.h" + +namespace OHOS::DataShare { +ConcurrentMap &> AppConnectManager::blockCache_; +bool AppConnectManager::Wait( + const std::string &bundleName, int maxWaitTimeMs, std::function connect) +{ + BlockData block(maxWaitTimeMs, false); + blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) -> BlockData & { + return block; + }); + bool result = connect(); + if (!result) { + ZLOGE("connect failed %{public}s", bundleName.c_str()); + return false; + } + ZLOGI("start wait %{public}s", bundleName.c_str()); + result = block.GetValue(); + ZLOGI("end wait %{public}s", bundleName.c_str()); + blockCache_.ComputeIfPresent(bundleName, [](const std::string &key, BlockData &value) -> bool { + return false; + }); + return result; +} + +void AppConnectManager::Notify(const std::string &bundleName) +{ + ZLOGI("notify %{public}s", bundleName.c_str()); + blockCache_.ComputeIfPresent(bundleName, [](const std::string &key, BlockData &value) -> bool { + value.SetValue(true); + return true; + }); +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.h b/services/distributeddataservice/service/data_share/common/app_connect_manager.h new file mode 100644 index 00000000..0bf765b4 --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.h @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_APP_CONNECT_MANAGER_H +#define DATASHARESERVICE_APP_CONNECT_MANAGER_H + +#include +#include + +#include "block_data.h" +#include "concurrent_map.h" + +namespace OHOS::DataShare { +class AppConnectManager { +public: + static bool Wait( + const std::string &bundleName, int maxWaitTimeMs, std::function connect); + static void Notify(const std::string &bundleName); + +private: + static ConcurrentMap &> blockCache_; +}; +} // namespace OHOS::DataShare +#endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index e84508eb..d2c525f5 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -19,6 +19,7 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" +#include "app_connect_manager.h" #include "dataobs_mgr_client.h" #include "datashare_errno.h" #include "datashare_template.h" @@ -385,4 +386,10 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use KvDBDelegate::GetInstance(false, saveMeta.dataDir); return EOK; } + +void DataShareServiceImpl::OnConnectDone() { + std::string callerBundleName; + GetCallerBundleName(callerBundleName); + AppConnectManager::Notify(callerBundleName); +} } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 1b1b6e0e..77109969 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -57,6 +57,7 @@ public: const int64_t subscriberId) override; std::vector DisablePubSubs(const std::vector &uris, const int64_t subscriberId) override; + void OnConnectDone() override; int32_t OnBind(const BindInfo &binderInfo) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 023f4e75..c32034b1 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -311,6 +311,12 @@ int32_t DataShareServiceStub::OnRemoteDisablePubSubs(MessageParcel &data, Messag return 0; } +int32_t DataShareServiceStub::OnRemoteNotifyConnectDone(MessageParcel &data, MessageParcel &reply) +{ + OnConnectDone(); + return 0; +} + int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) { ZLOGD("code:%{public}u, callingPid:%{public}d", code, IPCSkeleton::GetCallingPid()); diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.h b/services/distributeddataservice/service/data_share/data_share_service_stub.h index b786529f..d7e1dc27 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.h +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.h @@ -43,6 +43,7 @@ private: int32_t OnRemoteUnsubscribePublishedData(MessageParcel& data, MessageParcel& reply); int32_t OnRemoteEnablePubSubs(MessageParcel& data, MessageParcel& reply); int32_t OnRemoteDisablePubSubs(MessageParcel& data, MessageParcel& reply); + int32_t OnRemoteNotifyConnectDone(MessageParcel& data, MessageParcel& reply); using RequestHandle = int (DataShareServiceStub::*)(MessageParcel &, MessageParcel &); static constexpr RequestHandle HANDLERS[DATA_SHARE_SERVICE_CMD_MAX] = { &DataShareServiceStub::OnRemoteInsert, @@ -60,7 +61,8 @@ private: &DataShareServiceStub::OnRemoteSubscribePublishedData, &DataShareServiceStub::OnRemoteUnsubscribePublishedData, &DataShareServiceStub::OnRemoteEnablePubSubs, - &DataShareServiceStub::OnRemoteDisablePubSubs }; + &DataShareServiceStub::OnRemoteDisablePubSubs, + &DataShareServiceStub::OnRemoteNotifyConnectDone }; }; } // namespace DataShare } // namespace OHOS diff --git a/services/distributeddataservice/service/data_share/idata_share_service.h b/services/distributeddataservice/service/data_share/idata_share_service.h index 6d465247..a4e22949 100644 --- a/services/distributeddataservice/service/data_share/idata_share_service.h +++ b/services/distributeddataservice/service/data_share/idata_share_service.h @@ -45,6 +45,7 @@ public: DATA_SHARE_SERVICE_CMD_UNSUBSCRIBE_PUBLISHED, DATA_SHARE_SERVICE_CMD_ENABLE_SUBSCRIBE_PUBLISHED, DATA_SHARE_SERVICE_CMD_DISABLE_SUBSCRIBE_PUBLISHED, + DATA_SHARE_SERVICE_CMD_NOTIFY, DATA_SHARE_SERVICE_CMD_MAX }; @@ -77,6 +78,7 @@ public: const int64_t subscriberId) = 0; virtual std::vector DisablePubSubs(const std::vector &uris, const int64_t subscriberId) = 0; + virtual void OnConnectDone() = 0; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp index 1561140c..80001493 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp @@ -17,8 +17,10 @@ #include "connect_extension_strategy.h" #include -#include "log_print.h" + +#include "app_connect_manager.h" #include "callback_impl.h" +#include "log_print.h" namespace OHOS::DataShare { bool ConnectExtensionStrategy::operator()(std::shared_ptr context) @@ -59,26 +61,13 @@ bool ConnectExtensionStrategy::Connect(std::shared_ptr context) } bool ConnectExtensionStrategy::Execute( - std::shared_ptr context, std::function isFinished, int maxWaitTimeMs) + std::shared_ptr context, int maxWaitTimeMs) { - ConnectExtensionStrategy strategy; - if (!strategy(context)) { - return false; - } - if (isFinished == nullptr) { - return true; - } - int waitTime = 0; - static constexpr int retryTime = 500; - while (!isFinished()) { - if (waitTime > maxWaitTimeMs) { - ZLOGE("cannot finish work"); + return AppConnectManager::Wait(context->calledBundleName, maxWaitTimeMs, [&context]() { + ConnectExtensionStrategy strategy; + if (!strategy(context)) { return false; } - ZLOGI("has wait %{public}d ms", waitTime); - std::this_thread::sleep_for(std::chrono::milliseconds(retryTime)); - waitTime += retryTime; - } - return true; + }); } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.h b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.h index 57d76c48..2493287b 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.h @@ -23,7 +23,7 @@ class ConnectExtensionStrategy final : public Strategy { public: ConnectExtensionStrategy(); bool operator()(std::shared_ptr context) override; - static bool Execute(std::shared_ptr context, std::function isFinished, int maxWaitTimeMs = 2000); + static bool Execute(std::shared_ptr context, int maxWaitTimeMs = 2000); private: inline bool Connect(std::shared_ptr context); std::mutex mutex_; diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index 0aab4f83..82df1325 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -54,10 +54,8 @@ bool LoadConfigNormalDataInfoStrategy::operator()(std::shared_ptr conte DistributedData::StoreMetaData metaData; if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { // connect extension and retry - if (!ConnectExtensionStrategy::Execute(context, [&context, &metaData]() { - return QueryMetaData( - context->calledBundleName, context->calledStoreName, metaData, context->currentUserId); - })) { + if (!ConnectExtensionStrategy::Execute(context) && + !QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { ZLOGE("QueryMetaData fail, %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); context->errCode = NativeRdb::E_DB_NOT_EXIST; return false; @@ -73,9 +71,8 @@ bool LoadConfigSingleDataInfoStrategy::operator()(std::shared_ptr conte DistributedData::StoreMetaData metaData; if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0)) { // connect extension and retry - if (!ConnectExtensionStrategy::Execute(context, [&context, &metaData]() { - return QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0); - })) { + if (!ConnectExtensionStrategy::Execute(context) && + !QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0)) { ZLOGE("QueryMetaData fail, %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); context->errCode = NativeRdb::E_DB_NOT_EXIST; return false; -- Gitee From 1f7c6bfadc3d3a113906e5329f1eefa18b4c521c Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 11:28:31 +0800 Subject: [PATCH 111/437] f Signed-off-by: hanlu --- .../strategies/general/connect_extension_strategy.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp index 80001493..e3133f25 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp @@ -65,9 +65,7 @@ bool ConnectExtensionStrategy::Execute( { return AppConnectManager::Wait(context->calledBundleName, maxWaitTimeMs, [&context]() { ConnectExtensionStrategy strategy; - if (!strategy(context)) { - return false; - } + return strategy(context); }); } } // namespace OHOS::DataShare \ No newline at end of file -- Gitee From 5fb997945e22bcb8bb8194407efd4e8614267b0f Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Wed, 24 May 2023 11:31:47 +0800 Subject: [PATCH 112/437] update json document db feature Signed-off-by: Jeremyzz --- .../src/common/include/document_type.h | 34 ++ .../src/common/include/json_common.h | 6 +- .../gaussdb_rd/src/common/src/db_config.cpp | 12 +- .../gaussdb_rd/src/common/src/json_common.cpp | 182 +++--- .../src/executor/document/check_common.h | 8 +- .../src/interface/include/document_store.h | 15 +- .../src/interface/include/result_set.h | 17 +- .../src/interface/include/result_set_common.h | 5 +- .../src/interface/src/collection.cpp | 7 +- .../src/interface/src/document_store.cpp | 525 +++++++++++------- .../src/interface/src/projection_tree.cpp | 2 +- .../src/interface/src/result_set.cpp | 135 +++-- .../src/interface/src/result_set_common.cpp | 20 +- .../src/oh_adapter/src/json_object.cpp | 26 +- .../src/oh_adapter/src/kv_store_manager.cpp | 5 +- .../src/sqlite_store_executor_impl.cpp | 5 +- .../src/oh_adapter/src/sqlite_utils.cpp | 1 - 17 files changed, 576 insertions(+), 429 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h new file mode 100644 index 00000000..ff525ecb --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h @@ -0,0 +1,34 @@ +/* +* 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. +*/ + +#ifndef DOCUMENT_TYPE_H +#define DOCUMENT_TYPE_H + +#include + +#include "projection_tree.h" + +namespace DocumentDB { +struct QueryContext { + std::string collectionName; + std::string filter; + std::vector> projectionPath; + ProjectionTree projectionTree; + bool ifShowId = false; + bool viewType = false; + bool isOnlyId = false; +}; +} // namespace DocumentDB +#endif // DOCUMENT_TYPE_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h index 119d76da..a3a2b61d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h @@ -39,12 +39,14 @@ public: static bool IsJsonNodeMatch(const JsonObject &src, const JsonObject &target, int &errCode); private: - static bool JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); + static bool JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, + bool &isCollapse, int &isMatchFlag); static bool CheckNode(JsonObject &Node); static bool CheckProjectionNode(JsonObject &Node, bool isFirstLevel, int &errCode); static void CheckLeafNode(const JsonObject &Node, std::vector &leafValue); static bool IsArrayMatch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched); + static bool IsObjectItemMatch(const JsonObject &srcItem, const JsonObject &item, int &isAlreadyMatched, + bool &isCollapse, int &isMatchFlag); }; } // namespace DocumentDB #endif // JSON_COMMON_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp index 674dd361..44ce39b6 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/db_config.cpp @@ -27,12 +27,12 @@ namespace DocumentDB { namespace { -const int MIN_REDO_BUFFER_SIZE = 256; -const int MAX_REDO_BUFFER_SIZE = 16384; -const int MIN_CONNECTION_NUM = 16; -const int MAX_CONNECTION_NUM = 1024; -const int MIN_BUFFER_POOL_SIZE = 1024; -const int MAX_BUFFER_POOL_SIZE = 4 * 1024 * 1024; +constexpr int MIN_REDO_BUFFER_SIZE = 256; +constexpr int MAX_REDO_BUFFER_SIZE = 16384; +constexpr int MIN_CONNECTION_NUM = 16; +constexpr int MAX_CONNECTION_NUM = 1024; +constexpr int MIN_BUFFER_POOL_SIZE = 1024; +constexpr int MAX_BUFFER_POOL_SIZE = 4 * 1024 * 1024; constexpr const char *DB_CONFIG_PAGESIZE = "pagesize"; constexpr const char *DB_CONFIG_REDO_FLUSH_BY_TRX = "redoflushbytrx"; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 5b0d2561..61f29c65 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -82,12 +82,11 @@ std::vector JsonCommon::GetLeafValue(const JsonObject &node) bool JsonCommon::CheckNode(JsonObject &node) { - std::string fieldName; while (!node.IsNull()) { int ret = 0; std::set fieldSet; bool isFieldNameExist = true; - fieldName = node.GetItemField(ret); + std::string fieldName = node.GetItemField(ret); if (ret != E_OK) { isFieldNameExist = false; } @@ -130,11 +129,10 @@ bool JsonCommon::CheckJsonField(JsonObject &jsonObj) bool JsonCommon::CheckProjectionNode(JsonObject &node, bool isFirstLevel, int &errCode) { - std::string fieldName; while (!node.IsNull()) { int ret = 0; std::set fieldSet; - fieldName = node.GetItemField(ret); + std::string fieldName = node.GetItemField(ret); if (fieldName.empty()) { errCode = -E_INVALID_ARGS; return false; @@ -236,9 +234,6 @@ std::vector> JsonCommon::ParsePath(const JsonObject &ro { std::vector> resultPath; JsonObject projectionJson = root.GetChild(); - if (projectionJson.IsNull()) { - GLOGE("projectionJson is null"); - } std::vector singlePath; errCode = ParseNode(projectionJson, singlePath, resultPath, true); return resultPath; @@ -369,7 +364,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie while (!hitPath.empty()) { abandonPath.emplace_back(hitPath.back()); JsonObject srcFatherItem = src.FindItem(hitPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS) { + if (errCode == E_OK) { break; } if (!srcFatherItem.IsNull()) { @@ -412,7 +407,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, const JsonObject &father, const JsonObject &item, int &externErrCode) { - int errCode = 0; + int errCode = E_OK; JsonFieldPath granPaPath = fatherPath; if (!granPaPath.empty()) { granPaPath.pop_back(); @@ -453,7 +448,7 @@ bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, co bool JsonNodeReplace(const JsonObject &src, const JsonFieldPath &itemPath, const JsonObject &father, const JsonObject &item, int &externErrCode) { - int errCode = 0; + int errCode = E_OK; JsonFieldPath fatherPath = itemPath; fatherPath.pop_back(); if (!fatherPath.empty()) { @@ -498,21 +493,63 @@ bool JsonNodeReplace(const JsonObject &src, const JsonFieldPath &itemPath, const } return true; } + +bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const JsonObject &father, const JsonObject &item, + int &externErrCode) +{ + bool isCollapse = false; + JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); + JsonFieldPath fatherPath = itemPath; + fatherPath.pop_back(); + + int errCode = E_OK; + JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); + std::string lastFieldName = itemPath.back(); + int isAddedFlag = false; + if (errCode != E_OK) { + isAddedFlag = true; + AddSpliteField(src, item, itemPath, externErrCode); + return false; + } + // This condition is to determine that the path has a point operator, + // and the name of the last path cannot be a number or the srcItem to be added is an array, otherwise. + // adding a node with the number fieldName does not legal. + if (isCollapse && (!IsNumber(lastFieldName) || srcFatherItem.GetType() == JsonObject::Type::JSON_ARRAY)) { + errCode = srcFatherItem.AddItemToObject(lastFieldName, item); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Add item to object failed. %d", errCode); + return false; + } + isAddedFlag = true; + return false; + } + if (!isCollapse) { + bool ret = JsonValueReplace(src, fatherPath, father, item, externErrCode); + if (!ret) { + return false; // replace failed + } + isAddedFlag = true; + return false; // Different node types, overwrite directly, skip child node + } + if (!isAddedFlag) { + GLOGE("Add nothing because data conflict"); + externErrCode = -E_DATA_CONFLICT; + } + return false; // Source path not exist, overwrite directly, skip child node +} } // namespace int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isReplace) { int externErrCode = E_OK; - bool isAddedFlag = false; JsonObjectIterator(add, {}, - [&src, &externErrCode, &isReplace, &isAddedFlag](const JsonFieldPath &path, const JsonObject &father, + [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, const JsonObject &item) { - bool isCollapse = false; + bool isCollapse = false; // Whether there is a path generated by the dot operator, such as t1.t2.t3 JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); - JsonFieldPath fatherPath = itemPath; - fatherPath.pop_back(); - int errCode = E_OK; if (src.IsFieldExists(itemPath)) { + int errCode = E_OK; JsonObject srcItem = src.FindItem(itemPath, errCode); if (errCode != E_OK) { externErrCode = (externErrCode == E_OK ? errCode : externErrCode); @@ -523,7 +560,6 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl if (!ret) { return false; } - isAddedFlag = true; return false; } else { if (isReplace) { @@ -531,38 +567,7 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl externErrCode = -E_NO_DATA; return false; } - JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); - std::string lastFieldName = itemPath.back(); - if (errCode != E_OK) { - isAddedFlag = true; - AddSpliteField(src, item, itemPath, externErrCode); - return false; - } else { - if (isCollapse && - (!IsNumber(itemPath.back()) || srcFatherItem.GetType() == JsonObject::Type::JSON_ARRAY)) { - errCode = srcFatherItem.AddItemToObject(itemPath.back(), item); - if (errCode != E_OK) { - externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - GLOGE("Add item to object failed. %d", errCode); - return false; - } - isAddedFlag = true; - return false; - } - if (!isCollapse) { - bool ret = JsonValueReplace(src, fatherPath, father, item, externErrCode); - if (!ret) { - return false; // replace failed - } - isAddedFlag = true; - return false; // Different node types, overwrite directly, skip child node - } - } - if (!isAddedFlag) { - GLOGE("Add nothing because data conflict"); - externErrCode = -E_DATA_CONFLICT; - } - return false; // Source path not exist, overwrite directly, skip child node + return JsonNodeAppend(src, path, father, item, externErrCode); } }); return externErrCode; @@ -590,7 +595,7 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i JsonObject srcChild = src.GetChild(); JsonObject targetObj = target; bool isMatch = false; - int errCode = 0; + int errCode = E_OK; while (!srcChild.IsNull()) { if (srcChild.GetType() == JsonObject::Type::JSON_OBJECT && target.GetType() == JsonObject::Type::JSON_OBJECT && (IsJsonNodeMatch(srcChild, target, errCode))) { // The return value reflects the value of errCode @@ -603,36 +608,12 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i return isMatch; } -bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag) +bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject &item, int &isAlreadyMatched, + bool &isCollapse, int &isMatchFlag) { - int errCode; - JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { - isMatchFlag = true; - isAlreadyMatched = 1; - return false; - } - JsonFieldPath granpaPath = itemPath; - std::string lastFieldName = granpaPath.back(); - granpaPath.pop_back(); - JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { - JsonObject fatherItem = granpaItem.GetChild(); - while (!fatherItem.IsNull()) { - if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK - isMatchFlag = true; - isAlreadyMatched = 1; - break; - } - isMatchFlag = false; - fatherItem = fatherItem.GetNext(); - } - return false; - } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY && item.GetType() == JsonObject::Type::JSON_ARRAY && !isAlreadyMatched) { - bool isEqual = (srcItem.Print() == item.Print()); + bool isEqual = (srcItem == item); if (!isEqual) { // Filter value is No equal with src isMatchFlag = isEqual; } @@ -646,7 +627,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, isMatchFlag = isEqual; } isAlreadyMatched = isMatchFlag; - return false; // Both leaf node, no need iterate + return false; // Both leaf node, no need iterate } else if (srcItem.GetType() != item.GetType()) { if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { // srcItem Type is ARRAY, item Type is not ARRAY bool isEqual = IsArrayMatch(srcItem, item, isAlreadyMatched); @@ -658,14 +639,45 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, isMatchFlag = false; return false; // Different node types, overwrite directly, skip child node } - return true; // Both array or object + return true; // Both array or object +} + +bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, + bool &isCollapse, int &isMatchFlag) +{ + int errCode; + int isAlreadyMatched = 0; + JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); + if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { + isMatchFlag = true; + isAlreadyMatched = 1; + return false; + } + JsonFieldPath granpaPath = itemPath; + std::string lastFieldName = granpaPath.back(); + granpaPath.pop_back(); + JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); + if (errCode != -E_JSON_PATH_NOT_EXISTS && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { + JsonObject fatherItem = granpaItem.GetChild(); + while (!fatherItem.IsNull()) { + if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK + isAlreadyMatched = 1; + isMatchFlag = true; + break; + } + isMatchFlag = false; + fatherItem = fatherItem.GetNext(); + } + return false; + } + return IsObjectItemMatch(srcItem, item, isAlreadyMatched, isCollapse, isMatchFlag); } bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target, int &errCode) { errCode = E_OK; int isMatchFlag = true; - JsonObjectIterator(target, {}, [&src, &isMatchFlag, &errCode](JsonFieldPath &path, const JsonObject &item) { + JsonObjectIterator(target, {}, [&src, &isMatchFlag, &errCode](const JsonFieldPath &path, const JsonObject &item) { int isAlreadyMatched = 0; bool isCollapse = false; if (isMatchFlag == false) { @@ -674,14 +686,14 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target JsonFieldPath itemPath = SplitePath(path, isCollapse); if (src.IsFieldExistsPowerMode(itemPath)) { if (isCollapse) { - return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); + return JsonEqualJudge(itemPath, src, item, isCollapse, isMatchFlag); } else { JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (errCode != E_OK) { return false; } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { - return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); + return JsonEqualJudge(itemPath, src, item, isCollapse, isMatchFlag); } if (srcItem == item) { isMatchFlag = true; @@ -693,11 +705,9 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target } } else { std::vector ItemLeafValue = GetLeafValue(item); - int isNULLFlag = true; for (auto ValueItem : ItemLeafValue) { - if (ValueItem.GetValueType() != ValueObject::ValueType::VALUE_NULL) { // leaf value is not null - isNULLFlag = false; - } else { // filter leaf is null, Src leaf is dont exist + // filter leaf is null, Src leaf is dont exist. + if (ValueItem.GetValueType() == ValueObject::ValueType::VALUE_NULL) { isMatchFlag = true; return false; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h index ec81d50d..2985bd67 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h @@ -29,10 +29,10 @@ public: ~CheckCommon() = default; static bool CheckCollectionName(const std::string &collectionName, std::string &formattedName, int &errCode); - static int CheckFilter(JsonObject &document, bool &isOnlyId, std::vector> &filterPath); - static int CheckIdFormat(JsonObject &data, bool &isIdExisit); - static int CheckDocument(JsonObject &document); - static int CheckUpdata(JsonObject &updata, std::vector> &path); + static int CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector> &filterPath); + static int CheckIdFormat(JsonObject &filterJson, bool &isIdExisit); + static int CheckDocument(JsonObject &documentObj); + static int CheckUpdata(JsonObject &updataObj, std::vector> &path); static int CheckProjection(JsonObject &projectionObj, std::vector> &path); }; using Key = std::vector; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h index de0ce2d8..cefdc9e3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h @@ -21,6 +21,7 @@ #include #include "collection.h" +#include "document_type.h" #include "kv_store_executor.h" struct GRD_ResultSet; @@ -49,9 +50,9 @@ public: Collection GetCollection(std::string &collectionName); - bool IsCollectionOpening(const std::string collection); + bool IsExistResultSet(const std::string &collection); - int EraseCollection(const std::string collectionName); + int EraseCollection(const std::string &collectionName); void OnClose(const std::function ¬ifier); @@ -66,7 +67,15 @@ public: std::mutex dbMutex_; private: - int GetViewType(JsonObject &jsonObj, bool &viewType); + int UpdateDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, const std::string &update, + bool &isReplace); + int UpsertDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, JsonObject &documentObj, + bool &isReplace); + int InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj); + int DeleteDataFromDB(std::shared_ptr &context, JsonObject &filterObj); + int InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr &context); + int CheckUpsertConflict(bool &isIdExist, std::shared_ptr &context, JsonObject &filterObj, + std::string &docId, Collection &coll); KvStoreExecutor *executor_ = nullptr; std::map collections_; std::function closeNotifier_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index 2cd7bbd8..65956e09 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -24,17 +24,13 @@ #include "document_store.h" #include "grd_base/grd_type_export.h" #include "json_object.h" -#include "projection_tree.h" namespace DocumentDB { class ResultSet { public: ResultSet(); ~ResultSet(); - - int Init(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId); - int Init(DocumentStore *store, const std::string collectionName, const std::string &filter); + int Init(std::shared_ptr &context, DocumentStore *store, bool ifField); int GetNext(bool isNeedTransaction = false, bool isNeedCheckTable = false); int GetValue(char **value); int GetKey(std::string &key); @@ -45,17 +41,12 @@ private: int CutJsonBranch(std::string &jsonData); int CheckCutNode(JsonObject *node, std::vector singleCutPath, std::vector> &allCutPath); + int GetNextWithField(); + DocumentStore *store_ = nullptr; - std::string collectionName_; - ValueObject key_; - std::string filter_; - bool ifShowId_ = false; - bool viewType_ = false; bool ifField_ = false; - bool isOnlyId_ = false; - ProjectionTree projectionTree_; - std::vector> projectionPath_; size_t index_ = 0; + std::shared_ptr context_; std::vector> matchDatas_; }; } // namespace DocumentDB diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h index fa2c17c7..0a59f9ff 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h @@ -25,9 +25,6 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, ResultSet &resultSet, bool &isOnlyId); -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - ResultSet &resultSet); +int InitResultSet(std::shared_ptr &context, DocumentStore *store, ResultSet &resultSet, bool ifField); } // namespace DocumentDB #endif // RESULTSET_COMMON_H diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index a45056d0..1e6d04f2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -21,7 +21,7 @@ #include "log_print.h" namespace DocumentDB { -const int JSON_LENS_MAX = 1024 * 1024; +constexpr int JSON_LENS_MAX = 1024 * 1024; Collection::Collection(const std::string &name, KvStoreExecutor *executor) : executor_(executor) { @@ -158,9 +158,8 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen GLOGD("Append value failed. %d", errCode); return errCode; } - // kkk std::string valStr = originValue.Print(); - if (valStr.length() + 1 > JSON_LENS_MAX) { + if (valStr.length() >= JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; } @@ -214,7 +213,7 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update, return errCode; } std::string valStr = originValue.Print(); - if (valStr.length() + 1 > JSON_LENS_MAX) { + if (valStr.length() >= JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index 1821dbb2..cb1947eb 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -21,10 +21,11 @@ #include "grd_base/grd_type_export.h" #include "grd_resultset_inner.h" #include "log_print.h" +#include "result_set.h" #include "result_set_common.h" namespace DocumentDB { -const int JSON_LENS_MAX = 1024 * 1024; +constexpr int JSON_LENS_MAX = 1024 * 1024; constexpr const char *KEY_ID = "_id"; DocumentStore::DocumentStore(KvStoreExecutor *executor) : executor_(executor) {} @@ -127,8 +128,18 @@ END: return errCode; } -int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, - uint32_t flags) +int TranFilter(JsonObject &filterObj, std::vector> &filterAllPath, bool &isOnlyId) +{ + int errCode = E_OK; + filterAllPath = JsonCommon::ParsePath(filterObj, errCode); + if (errCode != E_OK) { + GLOGE("filter ParsePath failed"); + return errCode; + } + return CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); +} + +int UpdateArgsCheck(const std::string &collection, const std::string &filter, const std::string &update, uint32_t flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -162,41 +173,31 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - GLOGE("filter ParsePath failed"); - return errCode; - } - bool isOnlyId = true; - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; - } - bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); + return errCode; +} + +int DocumentStore::UpdateDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, + const std::string &update, bool &isReplace) +{ std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - errCode = executor_->StartTransaction(); + int errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } std::string docId; int count = 0; - auto coll = Collection(collection, executor_); - if (isOnlyId) { + auto coll = Collection(context->collectionName, executor_); + if (context->isOnlyId) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); docId = idValue.GetStringValue(); } else { ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); + std::string filter = filterObj.Print(); + InitResultSet(context, this, resultSet, true); // no start transaction inner errCode = resultSet.GetNext(false, true); if (errCode == -E_NO_DATA) { @@ -223,8 +224,34 @@ END: return (errCode == E_OK) ? count : errCode; } -int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, - const std::string &document, uint32_t flags) +int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, + uint32_t flags) +{ + int errCode = UpdateArgsCheck(collection, filter, update, flags); + if (errCode != E_OK) { + return errCode; + } + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + return errCode; + } + bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); + std::shared_ptr context = std::make_shared(); + context->collectionName = collection; + context->isOnlyId = isOnlyId; + context->filter = filter; + return UpdateDataIntoDB(context, filterObj, update, isReplace); +} + +int UpsertArgsCheck(const std::string &collection, const std::string &filter, const std::string &document, + uint32_t flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -236,87 +263,65 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri GLOGE("args length is too long"); return -E_OVER_LIMIT; } - JsonObject documentObj = JsonObject::Parse(document, errCode, true); - if (errCode != E_OK) { - GLOGE("document Parsed failed"); - return errCode; - } - std::vector> allPath; - if (document != "{}") { - allPath = JsonCommon::ParsePath(documentObj, errCode); - if (errCode != E_OK) { - return errCode; - } - errCode = CheckCommon::CheckUpdata(documentObj, allPath); - if (errCode != E_OK) { - GLOGE("UpsertDocument document format is illegal"); - return errCode; - } - } if (flags != GRD_DOC_APPEND && flags != GRD_DOC_REPLACE) { GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - return errCode; + return errCode; +} + +int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr &context, JsonObject &filterObj, + std::string &docId, Collection &coll) +{ + ResultSet resultSet; + InitResultSet(context, this, resultSet, true); + int errCode = resultSet.GetNext(false, true); + bool isfilterMatch = false; + if (errCode == E_OK) { + isfilterMatch = true; } - bool isOnlyId = true; - bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; + Value ValueDocument; + Key key(docId.begin(), docId.end()); + errCode = coll.GetDocument(key, ValueDocument); + if (errCode == E_OK && !(isfilterMatch)) { + GLOGE("id exist but filter does not match, data conflict"); + errCode = -E_DATA_CONFLICT; } + return errCode; +} + +int DocumentStore::UpsertDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, + JsonObject &documentObj, bool &isReplace) +{ std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - errCode = executor_->StartTransaction(); + int errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } - Collection coll = Collection(collection, executor_); + Collection coll = Collection(context->collectionName, executor_); int count = 0; std::string targetDocument; std::string docId; - if (isOnlyId) { - auto filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); - docId = idValue.GetStringValue(); - JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); - documentObj.InsertItemObject(0, idObj); - targetDocument = documentObj.Print(); - } else { - bool isIdExist; - auto filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); - if (!isIdExist) { - errCode = -E_INVALID_ARGS; - goto END; - } - ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); - errCode = resultSet.GetNext(false, true); - bool isfilterMatch = false; - if (errCode == E_OK) { - isfilterMatch = true; - } - docId = idValue.GetStringValue(); - JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); - documentObj.InsertItemObject(0, idObj); - targetDocument = documentObj.Print(); - Value ValueDocument; - Key key(docId.begin(), docId.end()); - errCode = coll.GetDocument(key, ValueDocument); - if (errCode == E_OK && !(isfilterMatch)) { - GLOGE("id exist but filter does not match, data conflict"); - errCode = -E_DATA_CONFLICT; + bool isIdExist; + auto filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); + docId = idValue.GetStringValue(); + JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); + documentObj.InsertItemObject(0, idObj); + targetDocument = documentObj.Print(); + if (!isIdExist) { + errCode = -E_INVALID_ARGS; + goto END; + } + if (!context->isOnlyId) { + errCode = CheckUpsertConflict(isIdExist, context, filterObj, docId, coll); + // There are only three return values, E_ OK and - E_ NO_DATA is a normal scenario, + // and that situation can continue to move forward + if (errCode == -E_DATA_CONFLICT) { + GLOGE("upsert data conflict"); goto END; } } @@ -335,7 +340,61 @@ END: return (errCode == E_OK) ? count : errCode; } -int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) +int UpsertDocumentFormatCheck(const std::string &document, JsonObject &documentObj) +{ + int errCode = E_OK; + std::vector> allPath; + if (document != "{}") { + allPath = JsonCommon::ParsePath(documentObj, errCode); + if (errCode != E_OK) { + return errCode; + } + errCode = CheckCommon::CheckUpdata(documentObj, allPath); + if (errCode != E_OK) { + GLOGE("UpsertDocument document format is illegal"); + return errCode; + } + } + return errCode; +} +int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, + const std::string &document, uint32_t flags) +{ + int errCode = UpsertArgsCheck(collection, filter, document, flags); + if (errCode != E_OK) { + return errCode; + } + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + JsonObject documentObj = JsonObject::Parse(document, errCode, true); + if (errCode != E_OK) { + GLOGE("document Parsed failed"); + return errCode; + } + errCode = UpsertDocumentFormatCheck(document, documentObj); + if (errCode != E_OK) { + GLOGE("document format is illegal"); + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + GLOGE("filter is invalid"); + return errCode; + } + std::shared_ptr context = std::make_shared(); + context->filter = filter; + context->isOnlyId = isOnlyId; + context->collectionName = collection; + bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); + return UpsertDataIntoDB(context, filterObj, documentObj, isReplace); +} + +int InsertArgsCheck(const std::string &collection, const std::string &document, uint32_t flags) { if (flags != 0u) { GLOGE("InsertDocument flags is not zero"); @@ -351,6 +410,27 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri GLOGE("document's length is too long"); return -E_OVER_LIMIT; } + return errCode; +} + +int DocumentStore::InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj) +{ + std::lock_guard lock(dbMutex_); + JsonObject documentObjChild = documentObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(documentObjChild, KEY_ID); + std::string id = idValue.GetStringValue(); + Key key(id.begin(), id.end()); + Value value(document.begin(), document.end()); + Collection coll = Collection(collection, executor_); + return coll.InsertDocument(key, value); +} + +int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) +{ + int errCode = InsertArgsCheck(collection, document, flags); + if (errCode != E_OK) { + return errCode; + } JsonObject documentObj = JsonObject::Parse(document, errCode, true); if (errCode != E_OK) { GLOGE("Document Parsed failed"); @@ -360,17 +440,10 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } - JsonObject documentObjChild = documentObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(documentObjChild, KEY_ID); - std::string id = idValue.GetStringValue(); - Key key(id.begin(), id.end()); - Value value(document.begin(), document.end()); - std::lock_guard lock(dbMutex_); - Collection coll = Collection(collection, executor_); - return coll.InsertDocument(key, value); + return InsertDataIntoDB(collection, document, documentObj); } -int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags) +int DeleteArgsCheck(const std::string &collection, const std::string &filter, uint32_t flags) { if (flags != 0u) { GLOGE("DeleteDocument flags is not zero"); @@ -390,38 +463,28 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri GLOGE("filter's length is too long"); return -E_OVER_LIMIT; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - return errCode; - } - bool isOnlyId = true; - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; - } + return errCode; +} + +int DocumentStore::DeleteDataFromDB(std::shared_ptr &context, JsonObject &filterObj) +{ std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - Collection coll = Collection(collection, executor_); - errCode = executor_->StartTransaction(); + Collection coll = Collection(context->collectionName, executor_); + int errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } std::string id; - if (isOnlyId) { + if (context->isOnlyId) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); id = idValue.GetStringValue(); } else { ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); + InitResultSet(context, this, resultSet, true); errCode = resultSet.GetNext(false, true); if (errCode != E_OK) { goto END; @@ -440,13 +503,96 @@ END: } return errCode; } +int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags) +{ + int errCode = DeleteArgsCheck(collection, filter, flags); + if (errCode != E_OK) { + return errCode; + } + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + if (errCode != E_OK) { + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + return errCode; + } + std::shared_ptr context = std::make_shared(); + context->filter = filter; + context->collectionName = collection; + context->isOnlyId = isOnlyId; + return DeleteDataFromDB(context, filterObj); +} Collection DocumentStore::GetCollection(std::string &collectionName) { return Collection(collectionName, executor_); } -int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, - const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) +int JudgeViewType(size_t &index, ValueObject &leafItem, bool &viewType) +{ + switch (leafItem.GetValueType()) { + case ValueObject::ValueType::VALUE_BOOL: + if (leafItem.GetBoolValue()) { + if (index != 0 && !viewType) { + return -E_INVALID_ARGS; + } + viewType = true; + } else { + if (index != 0 && viewType) { + return E_INVALID_ARGS; + } + viewType = false; + } + break; + case ValueObject::ValueType::VALUE_STRING: + if (leafItem.GetStringValue() == "") { + if (index != 0 && !viewType) { + return -E_INVALID_ARGS; + } + viewType = true; + } else { + return -E_INVALID_ARGS; + } + break; + case ValueObject::ValueType::VALUE_NUMBER: + if (leafItem.GetIntValue() == 0) { + if (index != 0 && viewType) { + return -E_INVALID_ARGS; + } + viewType = false; + } else { + if (index != 0 && !viewType) { + return E_INVALID_ARGS; + } + viewType = true; + } + break; + default: + return E_INVALID_ARGS; + } + return E_OK; +} + +int GetViewType(JsonObject &jsonObj, bool &viewType) +{ + std::vector leafValue = JsonCommon::GetLeafValue(jsonObj); + if (leafValue.size() == 0) { + return E_INVALID_ARGS; + } + int ret = E_OK; + for (size_t i = 0; i < leafValue.size(); i++) { + ret = JudgeViewType(i, leafValue[i], viewType); + if (ret != E_OK) { + return ret; + } + } + return ret; +} + +int FindArgsCheck(const std::string &collection, const std::string &filter, const std::string &projection, + uint32_t flags) { if (flags != 0u && flags != GRD_DOC_ID_DISPLAY) { GLOGE("FindDocument flags is illegal"); @@ -462,32 +608,23 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("args length is too long"); return -E_OVER_LIMIT; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - return errCode; - } - bool isOnlyId = true; - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; - } if (projection.length() >= JSON_LENS_MAX) { GLOGE("projection's length is too long"); return -E_OVER_LIMIT; } + return errCode; +} + +int FindProjectionInit(const std::string &projection, std::shared_ptr &context) +{ + int errCode = E_OK; + std::vector> allPath; JsonObject projectionObj = JsonObject::Parse(projection, errCode, true); if (errCode != E_OK) { GLOGE("projection Parsed failed"); return errCode; } bool viewType = false; - std::vector> allPath; if (projection != "{}") { allPath = JsonCommon::ParsePath(projectionObj, errCode); if (errCode != E_OK) { @@ -503,13 +640,17 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string return errCode; } } - bool ifShowId = false; - if (flags == GRD_DOC_ID_DISPLAY) { - ifShowId = true; - } + context->projectionPath = std::move(allPath); + context->viewType = viewType; + return errCode; +} + +int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr &context) +{ std::lock_guard lock(dbMutex_); - Collection coll = Collection(collection, executor_); - if (IsCollectionOpening(collection)) { + int errCode = E_OK; + Collection coll = Collection(context->collectionName, executor_); + if (IsExistResultSet(context->collectionName)) { return -E_RESOURCE_BUSY; } if (executor_ == nullptr) { @@ -526,9 +667,9 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string if (errCode != E_OK) { goto END; } - errCode = InitResultSet(this, collection, filter, allPath, ifShowId, viewType, grdResultSet->resultSet_, isOnlyId); + errCode = InitResultSet(context, this, grdResultSet->resultSet_, false); if (errCode == E_OK) { - collections_[collection] = nullptr; + collections_[context->collectionName] = nullptr; } END: if (errCode == E_OK) { @@ -539,7 +680,44 @@ END: return errCode; } -bool DocumentStore::IsCollectionOpening(const std::string collection) +int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, + const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) +{ + std::shared_ptr context = std::make_shared(); + int errCode = E_OK; + errCode = FindArgsCheck(collection, filter, projection, flags); + if (errCode != E_OK) { + GLOGE("delete arg is illegal"); + return errCode; + } + context->collectionName = collection; + context->filter = filter; + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + errCode = FindProjectionInit(projection, context); + if (errCode != E_OK) { + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + GLOGE("filter is invalid"); + return errCode; + } + context->isOnlyId = isOnlyId; + if (flags == GRD_DOC_ID_DISPLAY) { + context->ifShowId = true; + } else { + context->ifShowId = false; + } + return InitFindResultSet(grdResultSet, context); +} + +bool DocumentStore::IsExistResultSet(const std::string &collection) { if (collections_.find(collection) != collections_.end()) { GLOGE("DB is resource busy"); @@ -548,7 +726,7 @@ bool DocumentStore::IsCollectionOpening(const std::string collection) return false; } -int DocumentStore::EraseCollection(const std::string collectionName) +int DocumentStore::EraseCollection(const std::string &collectionName) { std::lock_guard lock(dbMutex_); if (collections_.find(collectionName) != collections_.end()) { @@ -559,57 +737,6 @@ int DocumentStore::EraseCollection(const std::string collectionName) return E_INVALID_ARGS; } -int DocumentStore::GetViewType(JsonObject &jsonObj, bool &viewType) -{ - std::vector leafValue = JsonCommon::GetLeafValue(jsonObj); - if (leafValue.size() == 0) { - return E_INVALID_ARGS; - } - for (size_t i = 0; i < leafValue.size(); i++) { - switch (leafValue[i].GetValueType()) { - case ValueObject::ValueType::VALUE_BOOL: - if (leafValue[i].GetBoolValue()) { - if (i != 0 && !viewType) { - return -E_INVALID_ARGS; - } - viewType = true; - } else { - if (i != 0 && viewType) { - return E_INVALID_ARGS; - } - viewType = false; - } - break; - case ValueObject::ValueType::VALUE_STRING: - if (leafValue[i].GetStringValue() == "") { - if (i != 0 && !viewType) { - return -E_INVALID_ARGS; - } - viewType = true; - } else { - return -E_INVALID_ARGS; - } - break; - case ValueObject::ValueType::VALUE_NUMBER: - if (leafValue[i].GetIntValue() == 0) { - if (i != 0 && viewType) { - return -E_INVALID_ARGS; - } - viewType = false; - } else { - if (i != 0 && !viewType) { - return E_INVALID_ARGS; - } - viewType = true; - } - break; - default: - return E_INVALID_ARGS; - } - } - return E_OK; -} - void DocumentStore::OnClose(const std::function ¬ifier) { closeNotifier_ = notifier; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp index 265ca61d..94c56b6f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -15,7 +15,7 @@ #include "projection_tree.h" namespace DocumentDB { -const int JSON_DEEP_MAX = 4; +constexpr int JSON_DEEP_MAX = 4; int ProjectionTree::ParseTree(std::vector> &path) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 8e37e106..cadbf670 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -22,37 +22,69 @@ namespace DocumentDB { constexpr const char *KEY_ID = "_id"; ResultSet::ResultSet() {} -ResultSet::~ResultSet() {} +ResultSet::~ResultSet() +{ + context_ = nullptr; +} int ResultSet::EraseCollection() { if (store_ != nullptr) { - store_->EraseCollection(collectionName_); + store_->EraseCollection(context_->collectionName); } return E_OK; } -int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId) +int ResultSet::Init(std::shared_ptr &context, DocumentStore *store, bool ifField) { - isOnlyId_ = isOnlyId; + ifField_ = ifField; + context_ = context; store_ = store; - collectionName_ = collectionName; - filter_ = filter; - projectionPath_ = path; - if (projectionTree_.ParseTree(path) == -E_INVALID_ARGS) { - GLOGE("Parse ProjectionTree failed"); - return -E_INVALID_ARGS; - } - ifShowId_ = ifShowId; - viewType_ = viewType; return E_OK; } -int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter) +int ResultSet::GetNextWithField() { - ifField_ = true; - store_ = store; - collectionName_ = collectionName; - filter_ = filter; + int errCode = E_OK; + if (context_->isOnlyId) { + JsonObject filterObj = JsonObject::Parse(context_->filter, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + JsonObject filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); + std::string idKey = idValue.GetStringValue(); + if (idKey.empty()) { + return -E_NO_DATA; + } + Key key(idKey.begin(), idKey.end()); + Value document; + Collection coll = store_->GetCollection(context_->collectionName); + errCode = coll.GetDocument(key, document); + if (errCode == -E_NOT_FOUND) { + return -E_NO_DATA; + } + std::string jsonData(document.begin(), document.end()); + CutJsonBranch(jsonData); + std::vector> values; + values.emplace_back(std::make_pair(idKey, jsonData)); + matchDatas_ = values; + } else { + Collection coll = store_->GetCollection(context_->collectionName); + std::vector> values; + JsonObject filterObj = JsonObject::Parse(context_->filter, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + errCode = coll.GetMatchedDocument(filterObj, values); + if (errCode == -E_NOT_FOUND) { + return -E_NO_DATA; + } + for (size_t i = 0; i < values.size(); i++) { + CutJsonBranch(values[i].second); + } + matchDatas_ = values; + } return E_OK; } @@ -60,7 +92,7 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) { int errCode = E_OK; if (isNeedCheckTable) { - std::string lowerCaseName = collectionName_; + std::string lowerCaseName = context_->collectionName; std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), [](unsigned char c) { return std::tolower(c); }); @@ -73,51 +105,14 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) } } if (!ifField_ && index_ == 0) { - if (isOnlyId_) { - JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); - std::string idKey = idValue.GetStringValue(); - if (idKey.empty()) { - return -E_NO_DATA; - } - Key key(idKey.begin(), idKey.end()); - Value document; - Collection coll = store_->GetCollection(collectionName_); - errCode = coll.GetDocument(key, document); - if (errCode == -E_NOT_FOUND) { - return -E_NO_DATA; - } - std::string jsonData(document.begin(), document.end()); - CutJsonBranch(jsonData); - std::vector> values; - values.emplace_back(std::pair(idKey, jsonData)); - matchDatas_ = values; - } else { - Collection coll = store_->GetCollection(collectionName_); - std::vector> values; - JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - errCode = coll.GetMatchedDocument(filterObj, values); - if (errCode == -E_NOT_FOUND) { - return -E_NO_DATA; - } - for (size_t i = 0; i < values.size(); i++) { - CutJsonBranch(values[i].second); - } - matchDatas_ = values; + errCode = GetNextWithField(); + if (errCode != E_OK) { + return errCode; } } else if (index_ == 0) { - Collection coll = store_->GetCollection(collectionName_); + Collection coll = store_->GetCollection(context_->collectionName); std::vector> values; - JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + JsonObject filterObj = JsonObject::Parse(context_->filter, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -197,7 +192,7 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat } singlePath.emplace_back(node->GetItemField()); int index = 0; - if (!projectionTree_.SearchTree(singlePath, index) && index == 0) { + if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { allCutPath.emplace_back(singlePath); } if (!node->GetChild().IsNull()) { @@ -219,26 +214,26 @@ int ResultSet::CutJsonBranch(std::string &jsonData) GLOGE("jsonData Parsed failed"); return errCode; } - std::vector> allCutPath; - if (viewType_) { + if (context_->viewType) { std::vector singlePath; JsonObject cjsonObjChild = cjsonObj.GetChild(); + std::vector> allCutPath; errCode = CheckCutNode(&cjsonObjChild, singlePath, allCutPath); if (errCode != E_OK) { GLOGE("The node in CheckCutNode is nullptr"); return errCode; } - for (auto singleCutPaht : allCutPath) { - if (!ifShowId_ || singleCutPaht[0] != KEY_ID) { + for (const auto &singleCutPaht : allCutPath) { + if (!context_->ifShowId || singleCutPaht[0] != KEY_ID) { cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } } } - if (!viewType_) { - for (auto singleCutPaht : projectionPath_) { + if (!context_->viewType) { + for (const auto &singleCutPaht : context_->projectionPath) { cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } - if (!ifShowId_) { + if (!context_->ifShowId) { std::vector idPath; idPath.emplace_back(KEY_ID); cjsonObj.DeleteItemDeeplyOnTarget(idPath); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp index c34c4a80..d6e070aa 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -15,23 +15,19 @@ #include "result_set_common.h" -#include -#include - #include "doc_errno.h" #include "grd_base/grd_error.h" namespace DocumentDB { class ValueObject; -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, ResultSet &resultSet, bool &isOnlyId) -{ - return resultSet.Init(store, collectionName, filter, path, ifShowId, viewType, isOnlyId); -} - -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - ResultSet &resultSet) +int InitResultSet(std::shared_ptr &context, DocumentStore *store, ResultSet &resultSet, bool ifField) { - return resultSet.Init(store, collectionName, filter); + if (!ifField) { + if (context->projectionTree.ParseTree(context->projectionPath) == -E_INVALID_ARGS) { + GLOGE("Parse ProjectionTree failed"); + return -E_INVALID_ARGS; + } + } + return resultSet.Init(context, store, ifField); } } // namespace DocumentDB diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 7d2fefb8..7ac3a08c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -224,17 +224,12 @@ int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int if (subObj == nullptr) { return -E_INVALID_ARGS; } - int ret = E_OK; std::string fieldName; if (subObj->string != nullptr) { fieldName = subObj->string; } if (parentType == cJSON_Array) { - ret = CheckJsonRepeatField(subObj); - if (ret != E_OK) { - return ret; - } - return E_OK; + return CheckJsonRepeatField(subObj); } if (fieldName.empty()) { return -E_INVALID_JSON_FORMAT; @@ -242,16 +237,9 @@ int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int if (fieldSet.find(fieldName) == fieldSet.end()) { fieldSet.insert(fieldName); } else { - ret = -E_INVALID_JSON_FORMAT; - } - if (ret != E_OK) { - return ret; - } - ret = CheckJsonRepeatField(subObj); - if (ret != E_OK) { - return ret; + return -E_INVALID_JSON_FORMAT; } - return E_OK; + return CheckJsonRepeatField(subObj); } std::string JsonObject::Print() const @@ -512,11 +500,7 @@ std::string JsonObject::GetItemField() const std::string JsonObject::GetItemField(int &errCode) const { - if (cjson_ == nullptr) { - errCode = E_INVALID_ARGS; - return ""; - } - if (cjson_->string == nullptr) { + if (cjson_ == nullptr || cjson_->string == nullptr) { errCode = E_INVALID_ARGS; return ""; } @@ -627,6 +611,8 @@ JsonObject JsonObject::FindItem(const JsonFieldPath &jsonPath, int &errCode) con return item; } +// Compared with the non-powerMode mode, the node found by this function is an Array, and target is an object, +// if the Array contains the same object as the target, it can match this object in this mode. JsonObject JsonObject::FindItemPowerMode(const JsonFieldPath &jsonPath, int &errCode) const { if (jsonPath.empty()) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp index 5162ebf4..d038491f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/kv_store_manager.cpp @@ -45,6 +45,10 @@ int KvStoreManager::GetKvStore(const std::string &path, const DBConfig &config, errCode = sqliteExecutor->GetDBConfig(oriConfigStr); if (errCode == -E_NOT_FOUND) { errCode = sqliteExecutor->SetDBConfig(config.ToString()); + if (errCode != E_OK) { + GLOGE("Set db config failed. %d", errCode); + goto END; + } } else if (errCode != E_OK) { goto END; } else { @@ -65,7 +69,6 @@ int KvStoreManager::GetKvStore(const std::string &path, const DBConfig &config, END: delete sqliteExecutor; - sqliteExecutor = nullptr; return errCode; } } // namespace DocumentDB \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp index 295dfb17..1de43e0d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -280,7 +280,7 @@ int SqliteStoreExecutorImpl::CreateCollection(const std::string &name, const std if (errCode != E_OK) { GLOGE("[sqlite executor] Set collection option failed. err=%d", errCode); } - return E_OK; + return errCode; } int SqliteStoreExecutorImpl::DropCollection(const std::string &name, bool ignoreNonExists) @@ -306,9 +306,8 @@ int SqliteStoreExecutorImpl::DropCollection(const std::string &name, bool ignore int errCode = SQLiteUtils::ExecSql(dbHandle_, sql); if (errCode != E_OK) { GLOGE("[sqlite executor] Drop collection failed. err=%d", errCode); - return errCode; } - return E_OK; + return errCode; } bool SqliteStoreExecutorImpl::IsCollectionExists(const std::string &name, int &errCode) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp index 4daae0f1..0b40db95 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp @@ -291,7 +291,6 @@ int SQLiteUtils::ExecSql(sqlite3 *db, const std::string &sql, const std::functio while (true) { errCode = SQLiteUtils::StepWithRetry(stmt); if (errCode == SQLITE_DONE) { - errCode = E_OK; // Step finished break; } else if (errCode != SQLITE_ROW) { goto END; // Step return error -- Gitee From 122b48e7a26b893df5c38f42bb85a5f4ca8c7267 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 24 May 2023 15:26:16 +0800 Subject: [PATCH 113/437] fix:Review comments modification Signed-off-by: htt1997 --- .../service/rdb/rdb_service_impl.cpp | 26 +++++-------------- .../service/rdb/rdb_service_impl.h | 2 +- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 4e38a5aa..3b5baedb 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -555,8 +555,8 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat return RDB_ERROR; } if (!isCreated || meta != old) { - Upgrade(param, meta, old); - ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " + Upgrade(param, old); + ZLOGD("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, meta.isEncrypt, old.area, meta.area); @@ -592,28 +592,16 @@ int32_t RdbServiceImpl::SetSecretKey(const RdbSyncerParam ¶m, const StoreMet return MetaDataManager::GetInstance().SaveMeta(meta.GetSecretKey(), newSecretKey, true) ? RDB_OK : RDB_ERROR; } -int32_t RdbServiceImpl::Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &meta, const StoreMetaData &old) +int32_t RdbServiceImpl::Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &old) { if (old.storeType == RDB_DEVICE_COLLABORATION && old.version < StoreMetaData::UUID_CHANGED_TAG) { - pid_t pid = IPCSkeleton::GetCallingPid(); - auto rdbObserver = new (std::nothrow) RdbStoreObserverImpl(this, pid); - if (rdbObserver == nullptr) { - return RDB_ERROR; - } - auto syncer = new (std::nothrow) RdbSyncer(param, rdbObserver); + auto syncer = GetRdbSyncer(param); if (syncer == nullptr) { - ZLOGE("new syncer error"); - return RDB_ERROR; - } - auto uid = IPCSkeleton::GetCallingUid(); - auto tokenId = IPCSkeleton::GetCallingTokenID(); - if (syncer->Init(pid, uid, tokenId, meta) != RDB_OK) { - ZLOGE("Init error"); - delete syncer; + ZLOGE("syncer is null, bundleName:%{public}s storeName:%{public}s", param.bundleName_.c_str(), + param.storeName_.c_str()); return RDB_ERROR; } - syncer->RemoveDeviceData(); - delete syncer; + return syncer->RemoveDeviceData(); } return RDB_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index b3de8bba..01831def 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -99,7 +99,7 @@ private: int32_t SetSecretKey(const RdbSyncerParam ¶m, const StoreMetaData &meta); - int32_t Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &meta, const StoreMetaData &old); + int32_t Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &old); class DeathRecipientImpl : public IRemoteObject::DeathRecipient { public: -- Gitee From 5ad0af91f64f9a715e8dd7f8de2d1669214d9bec Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 15:27:45 +0800 Subject: [PATCH 114/437] f Signed-off-by: hanlu --- .../data_share/common/app_connect_manager.cpp | 14 +++++++++----- .../data_share/common/app_connect_manager.h | 2 +- .../service/data_share/data_share_service_impl.cpp | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp index 1b2921e8..be8c029d 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp @@ -22,8 +22,8 @@ bool AppConnectManager::Wait( const std::string &bundleName, int maxWaitTimeMs, std::function connect) { BlockData block(maxWaitTimeMs, false); - blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) -> BlockData & { - return block; + blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) { + return █ }); bool result = connect(); if (!result) { @@ -33,7 +33,7 @@ bool AppConnectManager::Wait( ZLOGI("start wait %{public}s", bundleName.c_str()); result = block.GetValue(); ZLOGI("end wait %{public}s", bundleName.c_str()); - blockCache_.ComputeIfPresent(bundleName, [](const std::string &key, BlockData &value) -> bool { + blockCache_.ComputeIfPresent(bundleName, [](const std::string &key, BlockData *value) { return false; }); return result; @@ -42,8 +42,12 @@ bool AppConnectManager::Wait( void AppConnectManager::Notify(const std::string &bundleName) { ZLOGI("notify %{public}s", bundleName.c_str()); - blockCache_.ComputeIfPresent(bundleName, [](const std::string &key, BlockData &value) -> bool { - value.SetValue(true); + blockCache_.ComputeIfPresent(bundleName, [&bundleName](const std::string &key, BlockData *value) { + if (value == nullptr) { + ZLOGI("nullptr %{public}s", bundleName.c_str()); + return false; + } + value->SetValue(true); return true; }); } diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.h b/services/distributeddataservice/service/data_share/common/app_connect_manager.h index 0bf765b4..f949f2c9 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.h +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.h @@ -30,7 +30,7 @@ public: static void Notify(const std::string &bundleName); private: - static ConcurrentMap &> blockCache_; + static ConcurrentMap *> blockCache_; }; } // namespace OHOS::DataShare #endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index d2c525f5..170ed9b9 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -387,7 +387,8 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use return EOK; } -void DataShareServiceImpl::OnConnectDone() { +void DataShareServiceImpl::OnConnectDone() +{ std::string callerBundleName; GetCallerBundleName(callerBundleName); AppConnectManager::Notify(callerBundleName); -- Gitee From 907d9ef1d4409bb91c4125dd82fbe65011b4699e Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 15:55:13 +0800 Subject: [PATCH 115/437] f Signed-off-by: hanlu --- .../service/data_share/common/app_connect_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp index be8c029d..3c3e75fa 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp @@ -17,7 +17,7 @@ #include "log_print.h" namespace OHOS::DataShare { -ConcurrentMap &> AppConnectManager::blockCache_; +ConcurrentMap *> AppConnectManager::blockCache_; bool AppConnectManager::Wait( const std::string &bundleName, int maxWaitTimeMs, std::function connect) { -- Gitee From 71a25295727eb73ae9d1da941ea756957b3eec7b Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 16:03:54 +0800 Subject: [PATCH 116/437] f Signed-off-by: hanlu --- .../strategies/general/load_config_data_info_strategy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index 82df1325..b60c693e 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -54,8 +54,8 @@ bool LoadConfigNormalDataInfoStrategy::operator()(std::shared_ptr conte DistributedData::StoreMetaData metaData; if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { // connect extension and retry - if (!ConnectExtensionStrategy::Execute(context) && - !QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { + ConnectExtensionStrategy::Execute(context); + if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { ZLOGE("QueryMetaData fail, %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); context->errCode = NativeRdb::E_DB_NOT_EXIST; return false; @@ -71,8 +71,8 @@ bool LoadConfigSingleDataInfoStrategy::operator()(std::shared_ptr conte DistributedData::StoreMetaData metaData; if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0)) { // connect extension and retry - if (!ConnectExtensionStrategy::Execute(context) && - !QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0)) { + ConnectExtensionStrategy::Execute(context); + if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0)) { ZLOGE("QueryMetaData fail, %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); context->errCode = NativeRdb::E_DB_NOT_EXIST; return false; -- Gitee From b8cee1694c888b982543b7e13ce8a26840d95780 Mon Sep 17 00:00:00 2001 From: wangdantong Date: Mon, 22 May 2023 08:44:33 +0000 Subject: [PATCH 117/437] =?UTF-8?q?=E4=BF=AE=E6=94=B9xml=E4=B8=BAjson?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangdantong Change-Id: Ibe2cefcdbb592befb4333311543d8566cdef7054 --- services/distributeddataservice/app/BUILD.gn | 2 +- .../app/distributed_data.cfg | 2 +- .../sa_profile/1301.json | 12 +++++++++ .../sa_profile/1301.xml | 26 ------------------- 4 files changed, 14 insertions(+), 28 deletions(-) create mode 100644 services/distributeddataservice/sa_profile/1301.json delete mode 100644 services/distributeddataservice/sa_profile/1301.xml diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 6fa9ba6a..5df04bdd 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -30,7 +30,7 @@ ohos_prebuilt_etc("distributed_data.cfg") { } ohos_sa_profile("distributeddata_profile") { - sources = [ "../sa_profile/1301.xml" ] + sources = [ "../sa_profile/1301.json" ] part_name = "datamgr_service" } diff --git a/services/distributeddataservice/app/distributed_data.cfg b/services/distributeddataservice/app/distributed_data.cfg index 3c0eb54e..45046b10 100644 --- a/services/distributeddataservice/app/distributed_data.cfg +++ b/services/distributeddataservice/app/distributed_data.cfg @@ -15,7 +15,7 @@ ], "services":[{ "name" : "distributeddata", - "path" : ["/system/bin/sa_main","/system/profile/distributeddata.xml"], + "path" : ["/system/bin/sa_main","/system/profile/distributeddata.json"], "uid" : "ddms", "gid" : ["system","shell","readproc","ddms"], "writepid":[ diff --git a/services/distributeddataservice/sa_profile/1301.json b/services/distributeddataservice/sa_profile/1301.json new file mode 100644 index 00000000..a625ee9f --- /dev/null +++ b/services/distributeddataservice/sa_profile/1301.json @@ -0,0 +1,12 @@ +{ + "process": "distributeddata", + "systemability": [ + { + "name": 1301, + "libpath": "libdistributeddataservice.z.so", + "run-on-create": true, + "distributed": false, + "dump_level": 1 + } + ] +} \ No newline at end of file diff --git a/services/distributeddataservice/sa_profile/1301.xml b/services/distributeddataservice/sa_profile/1301.xml deleted file mode 100644 index dd59c9ed..00000000 --- a/services/distributeddataservice/sa_profile/1301.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - distributeddata - - 1301 - libdistributeddataservice.z.so - true - false - 1 - - - -- Gitee From 601e9d431d2730b05505d8df33f93f5db22555cd Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 16:55:08 +0800 Subject: [PATCH 118/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 2 +- .../data_share/common/app_connect_manager.cpp | 10 ++-- .../data_share/common/app_connect_manager.h | 4 +- .../extension_connect_adaptor.cpp} | 53 ++++++++++++------- .../extension_connect_adaptor.h} | 15 +++--- .../load_config_data_info_strategy.cpp | 6 +-- 6 files changed, 54 insertions(+), 36 deletions(-) rename services/distributeddataservice/service/data_share/{strategies/general/connect_extension_strategy.cpp => common/extension_connect_adaptor.cpp} (58%) rename services/distributeddataservice/service/data_share/{strategies/general/connect_extension_strategy.h => common/extension_connect_adaptor.h} (66%) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 11302dcb..cf8620f1 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -38,6 +38,7 @@ ohos_shared_library("data_share_service") { "common/bundle_mgr_proxy.cpp", "common/db_delegate.cpp", "common/div_strategy.cpp", + "common/extension_connect_adaptor.cpp", "common/kv_delegate.cpp", "common/rdb_delegate.cpp", "common/scheduler_manager.cpp", @@ -56,7 +57,6 @@ ohos_shared_library("data_share_service") { "strategies/delete_strategy.cpp", "strategies/general/check_is_data_proxy_strategy.cpp", "strategies/general/check_is_single_app_strategy.cpp", - "strategies/general/connect_extension_strategy.cpp", "strategies/general/empty_strategy.cpp", "strategies/general/load_config_common_strategy.cpp", "strategies/general/load_config_data_info_strategy.cpp", diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp index 3c3e75fa..1035b2f9 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp @@ -18,8 +18,8 @@ namespace OHOS::DataShare { ConcurrentMap *> AppConnectManager::blockCache_; -bool AppConnectManager::Wait( - const std::string &bundleName, int maxWaitTimeMs, std::function connect) +bool AppConnectManager::Wait(const std::string &bundleName, + int maxWaitTimeMs, std::function connect, std::function disconnect) { BlockData block(maxWaitTimeMs, false); blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) { @@ -28,14 +28,14 @@ bool AppConnectManager::Wait( bool result = connect(); if (!result) { ZLOGE("connect failed %{public}s", bundleName.c_str()); + blockCache_.Erase(bundleName); return false; } ZLOGI("start wait %{public}s", bundleName.c_str()); result = block.GetValue(); ZLOGI("end wait %{public}s", bundleName.c_str()); - blockCache_.ComputeIfPresent(bundleName, [](const std::string &key, BlockData *value) { - return false; - }); + blockCache_.Erase(bundleName); + disconnect(); return result; } diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.h b/services/distributeddataservice/service/data_share/common/app_connect_manager.h index f949f2c9..4bdb07fa 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.h +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.h @@ -25,8 +25,8 @@ namespace OHOS::DataShare { class AppConnectManager { public: - static bool Wait( - const std::string &bundleName, int maxWaitTimeMs, std::function connect); + static bool Wait(const std::string &bundleName, int maxWaitTimeMs, std::function connect, + std::function disconnect); static void Notify(const std::string &bundleName); private: diff --git a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp similarity index 58% rename from services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp rename to services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index e3133f25..5fbdd551 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "ConnectExtensionStrategy" +#define LOG_TAG "ExtensionConnectAdaptor" -#include "connect_extension_strategy.h" +#include "extension_connect_adaptor.h" #include @@ -23,27 +23,27 @@ #include "log_print.h" namespace OHOS::DataShare { -bool ConnectExtensionStrategy::operator()(std::shared_ptr context) +bool ExtensionConnectAdaptor::Connect(std::shared_ptr context) { for (auto const &extension: context->bundleInfo.extensionInfos) { if (extension.type == AppExecFwk::ExtensionAbilityType::DATASHARE) { - return Connect(context); + return DoConnect(context); } } return false; } -ConnectExtensionStrategy::ConnectExtensionStrategy() : data_(1) {} +ExtensionConnectAdaptor::ExtensionConnectAdaptor() : data_(1) {} -bool ConnectExtensionStrategy::Connect(std::shared_ptr context) +bool ExtensionConnectAdaptor::DoConnect(std::shared_ptr context) { std::lock_guard lock(mutex_); AAFwk::Want want; want.SetUri(context->uri); data_.Clear(); - sptr callback = new CallbackImpl(data_); + callback_ = new CallbackImpl(data_); ZLOGI("Start connect %{public}s", context->uri.c_str()); - ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, callback, nullptr); + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, callback_, nullptr); if (ret != ERR_OK) { ZLOGE("connect ability failed, ret = %{public}d", ret); return false; @@ -52,20 +52,35 @@ bool ConnectExtensionStrategy::Connect(std::shared_ptr context) if (result) { ZLOGI("connect ability ended successfully"); } - data_.Clear(); - AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(callback); - if (!data_.GetValue()) { - ZLOGI("disconnect ability ended successfully"); - } return result; } -bool ConnectExtensionStrategy::Execute( - std::shared_ptr context, int maxWaitTimeMs) +bool ExtensionConnectAdaptor::TryAndWait(std::shared_ptr context, int maxWaitTimeMs) { - return AppConnectManager::Wait(context->calledBundleName, maxWaitTimeMs, [&context]() { - ConnectExtensionStrategy strategy; - return strategy(context); - }); + ExtensionConnectAdaptor strategy; + return AppConnectManager::Wait( + context->calledBundleName, maxWaitTimeMs, + [&context, &strategy]() { + return strategy.Connect(context); + }, + [&strategy]() { + strategy.Disconnect(); + return true; + }); +} + +void ExtensionConnectAdaptor::Disconnect() { + std::lock_guard lock(mutex_); + if (callback_ == nullptr) { + ZLOGE("callback null"); + return; + } + data_.Clear(); + ZLOGI("Start disconnect"); + AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(callback_); + if (!data_.GetValue()) { + ZLOGI("disconnect ability ended successfully"); + } + callback_ = nullptr; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.h b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h similarity index 66% rename from services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.h rename to services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h index 2493287b..8584021f 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/connect_extension_strategy.h +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h @@ -16,18 +16,21 @@ #ifndef DATASHARESERVICE_CONNECT_EXTENSION_STRAGETY_H #define DATASHARESERVICE_CONNECT_EXTENSION_STRAGETY_H +#include "ability_connect_callback_interface.h" #include "block_data.h" -#include "strategy.h" +#include "context.h" namespace OHOS::DataShare { -class ConnectExtensionStrategy final : public Strategy { +class ExtensionConnectAdaptor { public: - ConnectExtensionStrategy(); - bool operator()(std::shared_ptr context) override; - static bool Execute(std::shared_ptr context, int maxWaitTimeMs = 2000); + static bool TryAndWait(std::shared_ptr context, int maxWaitTimeMs = 2000); + ExtensionConnectAdaptor(); private: - inline bool Connect(std::shared_ptr context); + bool Connect(std::shared_ptr context); + void Disconnect(); + bool DoConnect(std::shared_ptr context); std::mutex mutex_; BlockData data_; + sptr callback_ = nullptr; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index b60c693e..03259623 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -16,8 +16,8 @@ #include "load_config_data_info_strategy.h" #include "check_is_single_app_strategy.h" -#include "connect_extension_strategy.h" #include "device_manager_adapter.h" +#include "extension_connect_adaptor.h" #include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" @@ -54,7 +54,7 @@ bool LoadConfigNormalDataInfoStrategy::operator()(std::shared_ptr conte DistributedData::StoreMetaData metaData; if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { // connect extension and retry - ConnectExtensionStrategy::Execute(context); + ExtensionConnectAdaptor::TryAndWait(context); if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, context->currentUserId)) { ZLOGE("QueryMetaData fail, %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); context->errCode = NativeRdb::E_DB_NOT_EXIST; @@ -71,7 +71,7 @@ bool LoadConfigSingleDataInfoStrategy::operator()(std::shared_ptr conte DistributedData::StoreMetaData metaData; if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0)) { // connect extension and retry - ConnectExtensionStrategy::Execute(context); + ExtensionConnectAdaptor::TryAndWait(context); if (!QueryMetaData(context->calledBundleName, context->calledStoreName, metaData, 0)) { ZLOGE("QueryMetaData fail, %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); context->errCode = NativeRdb::E_DB_NOT_EXIST; -- Gitee From fa19d238ac2e15be9f0bc809ec581097e9d84fd2 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 24 May 2023 17:11:02 +0800 Subject: [PATCH 119/437] style:Print anonymous storeId Signed-off-by: htt1997 --- .../app/src/kvstore_data_service.cpp | 3 +- .../app/src/uninstaller/uninstaller_impl.cpp | 7 +- .../service/kvdb/kvdb_service_impl.cpp | 44 ++++++------ .../service/kvdb/kvdb_service_stub.cpp | 70 +++++++++++-------- .../service/kvdb/store_cache.cpp | 3 +- 5 files changed, 73 insertions(+), 54 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 8138acdc..b552aa00 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -50,6 +50,7 @@ #include "upgrade.h" #include "upgrade_manager.h" #include "user_delegate.h" +#include "utils/anonymous.h" #include "utils/block_integer.h" #include "utils/crypto.h" @@ -340,7 +341,7 @@ void KvStoreDataService::OnStoreMetaChanged( StoreMetaData metaData; metaData.Unmarshall({ value.begin(), value.end() }); ZLOGD("meta data info appType:%{public}s, storeId:%{public}s isDirty:%{public}d", metaData.appType.c_str(), - metaData.storeId.c_str(), metaData.isDirty); + Anonymous::Change(metaData.storeId).c_str(), metaData.isDirty); auto deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; if (metaData.deviceId != deviceId || metaData.deviceId.empty()) { ZLOGD("ignore other device change or invalid meta device"); diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index cb6142eb..309ee950 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -28,6 +28,7 @@ #include "metadata/store_meta_data.h" #include "permit_delegate.h" #include "cloud/cloud_info.h" +#include "utils/anonymous.h" namespace OHOS::DistributedKv { using namespace OHOS::AppDistributedKv; @@ -72,7 +73,8 @@ void UninstallEventSubscriber::OnUninstall(const std::string &bundleName, int32_ } for (auto &meta : storeMetaData) { if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { - ZLOGI("uninstalled bundleName:%{public}s stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + ZLOGI("uninstalled bundleName:%{public}s stordId:%{public}s", bundleName.c_str(), + Anonymous::Change(meta.storeId).c_str()); MetaDataManager::GetInstance().DelMeta(meta.GetKey()); MetaDataManager::GetInstance().DelMeta(meta.GetSecretKey(), true); MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey()); @@ -96,7 +98,8 @@ void UninstallEventSubscriber::OnUpdate(const std::string &bundleName, int32_t u } for (auto &meta : storeMetaData) { if (meta.instanceId == appIndex && !meta.appId.empty() && !meta.storeId.empty()) { - ZLOGI("updated bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), meta.storeId.c_str()); + ZLOGI("updated bundleName:%{public}s, stordId:%{public}s", bundleName.c_str(), + Anonymous::Change(meta.storeId).c_str()); MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); } } diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 0c14ac98..91fca262 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -99,7 +99,8 @@ KVDBServiceImpl::KVDBServiceImpl() if (policy.IsValueEffect()) { syncInfo.delay = policy.valueUint; } - ZLOGI("[online] appId:%{public}s, storeId:%{public}s", data.bundleName.c_str(), data.storeId.c_str()); + ZLOGI("[online] appId:%{public}s, storeId:%{public}s", data.bundleName.c_str(), + Anonymous::Change(data.storeId).c_str()); auto delay = GetSyncDelayTime(syncInfo.delay, { data.storeId }); KvStoreSyncManager::GetInstance()->AddSyncOperation(uintptr_t(data.tokenId), delay, std::bind(&KVDBServiceImpl::DoSync, this, data, syncInfo, std::placeholders::_1, ACTION_SYNC), @@ -154,8 +155,8 @@ Status KVDBServiceImpl::Delete(const AppId &appId, const StoreId &storeId) MetaDataManager::GetInstance().DelMeta(metaData.GetKeyLocal(), true); PermitDelegate::GetInstance().DelCache(metaData.GetKey()); storeCache_.CloseStore(tokenId, storeId); - ZLOGD("appId:%{public}s storeId:%{public}s instanceId:%{public}d", appId.appId.c_str(), storeId.storeId.c_str(), - metaData.instanceId); + ZLOGD("appId:%{public}s storeId:%{public}s instanceId:%{public}d", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str(), metaData.instanceId); return SUCCESS; } @@ -170,7 +171,7 @@ Status KVDBServiceImpl::Sync(const AppId &appId, const StoreId &storeId, const S MetaDataManager::GetInstance().LoadMeta(metaData.GetKeyLocal(), localMeta, true); if (!localMeta.HasPolicy(IMMEDIATE_SYNC_ON_CHANGE)) { ZLOGW("appId:%{public}s storeId:%{public}s no IMMEDIATE_SYNC_ON_CHANGE ", appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return Status::SUCCESS; } } @@ -306,8 +307,8 @@ Status KVDBServiceImpl::RmvSubscribeInfo(const AppId &appId, const StoreId &stor Status KVDBServiceImpl::Subscribe(const AppId &appId, const StoreId &storeId, sptr observer) { auto tokenId = IPCSkeleton::GetCallingTokenID(); - ZLOGI("appId:%{public}s storeId:%{public}s tokenId:0x%{public}x", appId.appId.c_str(), storeId.storeId.c_str(), - tokenId); + ZLOGI("appId:%{public}s storeId:%{public}s tokenId:0x%{public}x", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str(), tokenId); syncAgents_.Compute(tokenId, [&appId, &storeId, &observer](auto &key, SyncAgent &value) { if (value.pid_ != IPCSkeleton::GetCallingPid()) { value.ReInit(IPCSkeleton::GetCallingPid(), appId); @@ -327,8 +328,8 @@ Status KVDBServiceImpl::Subscribe(const AppId &appId, const StoreId &storeId, sp Status KVDBServiceImpl::Unsubscribe(const AppId &appId, const StoreId &storeId, sptr observer) { auto tokenId = IPCSkeleton::GetCallingTokenID(); - ZLOGI("appId:%{public}s storeId:%{public}s tokenId:0x%{public}x", appId.appId.c_str(), storeId.storeId.c_str(), - tokenId); + ZLOGI("appId:%{public}s storeId:%{public}s tokenId:0x%{public}x", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str(), tokenId); syncAgents_.ComputeIfPresent(tokenId, [&appId, &storeId, &observer](auto &key, SyncAgent &value) { if (value.pid_ != IPCSkeleton::GetCallingPid()) { ZLOGW("agent already changed! old pid:%{public}d new pid:%{public}d appId:%{public}s", @@ -352,7 +353,8 @@ Status KVDBServiceImpl::GetBackupPassword(const AppId &appId, const StoreId &sto Status KVDBServiceImpl::BeforeCreate(const AppId &appId, const StoreId &storeId, const Options &options) { - ZLOGD("appId:%{public}s storeId:%{public}s to export data", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGD("appId:%{public}s storeId:%{public}s to export data", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); StoreMetaData meta = GetStoreMetaData(appId, storeId); AddOptions(options, meta); @@ -365,8 +367,8 @@ Status KVDBServiceImpl::BeforeCreate(const AppId &appId, const StoreId &storeId, old.area != meta.area || !options.persistent) { ZLOGE("meta appId:%{public}s storeId:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d persistent:%{public}d", - appId.appId.c_str(), storeId.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, meta.isEncrypt, - old.area, meta.area, options.persistent); + appId.appId.c_str(), Anonymous::Change(storeId.storeId).c_str(), old.storeType, meta.storeType, + old.isEncrypt, meta.isEncrypt, old.area, meta.area, options.persistent); return Status::STORE_META_CHANGED; } @@ -382,7 +384,7 @@ Status KVDBServiceImpl::AfterCreate(const AppId &appId, const StoreId &storeId, { if (!appId.IsValid() || !storeId.IsValid() || !options.IsValidType()) { ZLOGE("failed please check type:%{public}d appId:%{public}s storeId:%{public}s", options.kvStoreType, - appId.appId.c_str(), storeId.storeId.c_str()); + appId.appId.c_str(), Anonymous::Change(storeId.storeId).c_str()); return INVALID_ARGUMENT; } @@ -396,8 +398,8 @@ Status KVDBServiceImpl::AfterCreate(const AppId &appId, const StoreId &storeId, auto dbStatus = Upgrade::GetInstance().UpdateStore(oldMeta, metaData, password); ZLOGI("update status:%{public}d appId:%{public}s storeId:%{public}s inst:%{public}d " "type:%{public}d->%{public}d dir:%{public}s", - dbStatus, appId.appId.c_str(), storeId.storeId.c_str(), metaData.instanceId, oldMeta.storeType, - metaData.storeType, metaData.dataDir.c_str()); + dbStatus, appId.appId.c_str(), Anonymous::Change(storeId.storeId).c_str(), metaData.instanceId, + oldMeta.storeType, metaData.storeType, metaData.dataDir.c_str()); if (dbStatus != DBStatus::OK) { status = STORE_UPGRADE_FAILED; } @@ -413,7 +415,7 @@ Status KVDBServiceImpl::AfterCreate(const AppId &appId, const StoreId &storeId, SaveLocalMetaData(options, metaData); Upgrade::GetInstance().UpdatePassword(metaData, password); ZLOGI("appId:%{public}s storeId:%{public}s instanceId:%{public}d type:%{public}d dir:%{public}s", - appId.appId.c_str(), storeId.storeId.c_str(), metaData.instanceId, metaData.storeType, + appId.appId.c_str(), Anonymous::Change(storeId.storeId).c_str(), metaData.instanceId, metaData.storeType, metaData.dataDir.c_str()); return status; } @@ -442,7 +444,7 @@ int32_t KVDBServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m) { ZLOGI("user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), - param.appId.c_str(), param.storeId.c_str(), Anonymous::Change(identifier).c_str()); + param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), Anonymous::Change(identifier).c_str()); std::vector metaData; auto prefix = StoreMetaData::GetPrefix({ DMAdapter::GetInstance().GetLocalDevice().uuid, param.userId }); if (!MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { @@ -462,7 +464,7 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun auto observers = GetObservers(storeMeta.tokenId, storeMeta.storeId); ZLOGD("user:%{public}s appId:%{public}s storeId:%{public}s observers:%{public}zu", storeMeta.user.c_str(), - storeMeta.bundleName.c_str(), storeMeta.storeId.c_str(), (observers) ? observers->size() : size_t(0)); + storeMeta.bundleName.c_str(), Anonymous::Change(storeMeta.storeId).c_str(), (observers) ? observers->size() : size_t(0)); DBStatus status; storeCache_.GetStore(storeMeta, observers, status); } @@ -593,11 +595,11 @@ int32_t KVDBServiceImpl::GetInstIndex(uint32_t tokenId, const AppId &appId) Status KVDBServiceImpl::DoSync(const StoreMetaData &meta, const SyncInfo &info, const SyncEnd &complete, int32_t type) { ZLOGD("seqId:0x%{public}" PRIx64 " type:%{public}d remote:%{public}zu appId:%{public}s storeId:%{public}s", - info.seqId, type, info.devices.size(), meta.bundleName.c_str(), meta.storeId.c_str()); + info.seqId, type, info.devices.size(), meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str()); auto uuids = ConvertDevices(info.devices); if (uuids.empty()) { ZLOGW("no device online seqId:0x%{public}" PRIx64 " remote:%{public}zu appId:%{public}s storeId:%{public}s", - info.seqId, info.devices.size(), meta.bundleName.c_str(), meta.storeId.c_str()); + info.seqId, info.devices.size(), meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str()); return Status::ERROR; } @@ -606,7 +608,7 @@ Status KVDBServiceImpl::DoSync(const StoreMetaData &meta, const SyncInfo &info, auto store = storeCache_.GetStore(meta, observers, status); if (store == nullptr) { ZLOGE("failed! status:%{public}d appId:%{public}s storeId:%{public}s dir:%{public}s", status, - meta.bundleName.c_str(), meta.storeId.c_str(), meta.dataDir.c_str()); + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), meta.dataDir.c_str()); return ConvertDbStatus(status); } bool isSuccess = false; @@ -782,7 +784,7 @@ size_t KVDBServiceImpl::GetSyncDataSize(const std::string &deviceId) auto store = storeCache_.GetStore(data, observers, status); if (store == nullptr) { ZLOGE("failed! status:%{public}d appId:%{public}s storeId:%{public}s dir:%{public}s", status, - data.bundleName.c_str(), data.storeId.c_str(), data.dataDir.c_str()); + data.bundleName.c_str(), Anonymous::Change(data.storeId).c_str(), data.dataDir.c_str()); continue; } totalSize += store->GetSyncDataSize(deviceId); diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp index 61fdde59..8894c4ad 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp @@ -20,6 +20,7 @@ #include "itypes_util.h" #include "log_print.h" #include "utils/constant.h" +#include "utils/anonymous.h" namespace OHOS::DistributedKv { using namespace OHOS::DistributedData; const KVDBServiceStub::Handler KVDBServiceStub::HANDLERS[TRANS_BUTT] = { @@ -60,7 +61,8 @@ int KVDBServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message AppId appId; StoreId storeId; if (!ITypesUtil::Unmarshal(data, appId, storeId)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } appId.appId = Constant::TrimCopy(appId.appId); @@ -75,11 +77,11 @@ int KVDBServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message return (this->*HANDLERS[code])(appId, storeId, data, reply); } ZLOGE("PERMISSION_DENIED uid:%{public}d appId:%{public}s storeId:%{public}s", info.uid, info.bundleName.c_str(), - info.storeId.c_str()); + Anonymous::Change(info.storeId).c_str()); if (!ITypesUtil::Marshal(reply, static_cast(PERMISSION_DENIED))) { ZLOGE("Marshal PERMISSION_DENIED code:%{public}u appId:%{public}s storeId:%{public}s", code, - appId.appId.c_str(), storeId.storeId.c_str()); + appId.appId.c_str(), Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -102,13 +104,14 @@ int32_t KVDBServiceStub::OnBeforeCreate( { Options options; if (!ITypesUtil::Unmarshal(data, options)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } int32_t status = BeforeCreate(appId, storeId, options); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -120,14 +123,15 @@ int32_t KVDBServiceStub::OnAfterCreate( Options options; std::vector password; if (!ITypesUtil::Unmarshal(data, options, password)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } int32_t status = AfterCreate(appId, storeId, options, password); password.assign(password.size(), 0); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -138,7 +142,7 @@ int32_t KVDBServiceStub::OnDelete(const AppId &appId, const StoreId &storeId, Me int32_t status = Delete(appId, storeId); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -148,13 +152,14 @@ int32_t KVDBServiceStub::OnSync(const AppId &appId, const StoreId &storeId, Mess { SyncInfo syncInfo; if (!ITypesUtil::Unmarshal(data, syncInfo.seqId, syncInfo.mode, syncInfo.devices, syncInfo.delay, syncInfo.query)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } int32_t status = Sync(appId, storeId, syncInfo); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -165,14 +170,15 @@ int32_t KVDBServiceStub::OnRegisterCallback( { sptr remoteObj; if (!ITypesUtil::Unmarshal(data, remoteObj)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto syncCallback = (remoteObj == nullptr) ? nullptr : iface_cast(remoteObj); int32_t status = RegisterSyncCallback(appId, syncCallback); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -184,7 +190,7 @@ int32_t KVDBServiceStub::OnUnregisterCallback( int32_t status = UnregisterSyncCallback(appId); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -195,13 +201,14 @@ int32_t KVDBServiceStub::OnSetSyncParam( { KvSyncParam syncParam; if (!ITypesUtil::Unmarshal(data, syncParam.allowedDelayMs)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } int32_t status = SetSyncParam(appId, storeId, syncParam); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -214,7 +221,7 @@ int32_t KVDBServiceStub::OnGetSyncParam( int32_t status = GetSyncParam(appId, storeId, syncParam); if (!ITypesUtil::Marshal(reply, status, syncParam.allowedDelayMs)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -226,7 +233,7 @@ int32_t KVDBServiceStub::OnEnableCap( int32_t status = EnableCapability(appId, storeId); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -238,7 +245,7 @@ int32_t KVDBServiceStub::OnDisableCap( int32_t status = DisableCapability(appId, storeId); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -250,13 +257,14 @@ int32_t KVDBServiceStub::OnSetCapability( std::vector local; std::vector remote; if (!ITypesUtil::Unmarshal(data, local, remote)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } int32_t status = SetCapability(appId, storeId, local, remote); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -267,13 +275,14 @@ int32_t KVDBServiceStub::OnAddSubInfo(const AppId &appId, const StoreId &storeId { SyncInfo syncInfo; if (!ITypesUtil::Unmarshal(data, syncInfo.seqId, syncInfo.devices, syncInfo.query)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } int32_t status = AddSubscribeInfo(appId, storeId, syncInfo); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -284,13 +293,14 @@ int32_t KVDBServiceStub::OnRmvSubInfo(const AppId &appId, const StoreId &storeId { SyncInfo syncInfo; if (!ITypesUtil::Unmarshal(data, syncInfo.seqId, syncInfo.devices, syncInfo.query)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } int32_t status = RmvSubscribeInfo(appId, storeId, syncInfo); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -301,14 +311,15 @@ int32_t KVDBServiceStub::OnSubscribe( { sptr remoteObj; if (!ITypesUtil::Unmarshal(data, remoteObj)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto observer = (remoteObj == nullptr) ? nullptr : iface_cast(remoteObj); int32_t status = Subscribe(appId, storeId, observer); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -319,14 +330,15 @@ int32_t KVDBServiceStub::OnUnsubscribe( { sptr remoteObj; if (!ITypesUtil::Unmarshal(data, remoteObj)) { - ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), storeId.storeId.c_str()); + ZLOGE("Unmarshal appId:%{public}s storeId:%{public}s", appId.appId.c_str(), + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto observer = (remoteObj == nullptr) ? nullptr : iface_cast(remoteObj); int32_t status = Unsubscribe(appId, storeId, observer); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); return IPC_STUB_WRITE_PARCEL_ERR; } return ERR_NONE; @@ -339,7 +351,7 @@ int32_t KVDBServiceStub::OnGetBackupPassword( int32_t status = GetBackupPassword(appId, storeId, password); if (!ITypesUtil::Marshal(reply, status, password)) { ZLOGE("Marshal status:0x%{public}x appId:%{public}s storeId:%{public}s", status, appId.appId.c_str(), - storeId.storeId.c_str()); + Anonymous::Change(storeId.storeId).c_str()); password.assign(password.size(), 0); return IPC_STUB_WRITE_PARCEL_ERR; } diff --git a/services/distributeddataservice/service/kvdb/store_cache.cpp b/services/distributeddataservice/service/kvdb/store_cache.cpp index 8f4d8269..2bbaa358 100644 --- a/services/distributeddataservice/service/kvdb/store_cache.cpp +++ b/services/distributeddataservice/service/kvdb/store_cache.cpp @@ -23,6 +23,7 @@ #include "metadata/meta_data_manager.h" #include "metadata/secret_key_meta_data.h" #include "types.h" +#include "utils/anonymous.h" namespace OHOS::DistributedKv { using namespace OHOS::DistributedData; constexpr int64_t StoreCache::INTERVAL; @@ -105,7 +106,7 @@ void StoreCache::CloseExcept(const std::set &users) void StoreCache::SetObserver(uint32_t tokenId, const std::string &storeId, std::shared_ptr observers) { stores_.ComputeIfPresent(tokenId, [&storeId, &observers](auto &key, auto &stores) { - ZLOGD("tokenId:0x%{public}x storeId:%{public}s observers:%{public}zu", key, storeId.c_str(), + ZLOGD("tokenId:0x%{public}x storeId:%{public}s observers:%{public}zu", key, Anonymous::Change(storeId).c_str(), observers ? observers->size() : size_t(0)); auto it = stores.find(storeId); if (it != stores.end()) { -- Gitee From 232ec42990491a1e91b2d498cb99f52ccacbb7cf Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 24 May 2023 17:31:30 +0800 Subject: [PATCH 120/437] style:Print anonymous storeId Signed-off-by: htt1997 --- .../distributeddataservice/service/kvdb/kvdb_service_impl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 91fca262..db17f3ca 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -464,7 +464,8 @@ int32_t KVDBServiceImpl::ResolveAutoLaunch(const std::string &identifier, DBLaun auto observers = GetObservers(storeMeta.tokenId, storeMeta.storeId); ZLOGD("user:%{public}s appId:%{public}s storeId:%{public}s observers:%{public}zu", storeMeta.user.c_str(), - storeMeta.bundleName.c_str(), Anonymous::Change(storeMeta.storeId).c_str(), (observers) ? observers->size() : size_t(0)); + storeMeta.bundleName.c_str(), Anonymous::Change(storeMeta.storeId).c_str(), + (observers) ? observers->size() : size_t(0)); DBStatus status; storeCache_.GetStore(storeMeta, observers, status); } -- Gitee From 4ade26e089208232033b8e03e8c1505e3a9088c4 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 18:09:04 +0800 Subject: [PATCH 121/437] f Signed-off-by: hanlu --- .../service/data_share/common/extension_connect_adaptor.cpp | 5 +++-- .../service/data_share/common/extension_connect_adaptor.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index 5fbdd551..2961f5b1 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -25,7 +25,7 @@ namespace OHOS::DataShare { bool ExtensionConnectAdaptor::Connect(std::shared_ptr context) { - for (auto const &extension: context->bundleInfo.extensionInfos) { + for (auto const &extension : context->bundleInfo.extensionInfos) { if (extension.type == AppExecFwk::ExtensionAbilityType::DATASHARE) { return DoConnect(context); } @@ -69,7 +69,8 @@ bool ExtensionConnectAdaptor::TryAndWait(std::shared_ptr context, int m }); } -void ExtensionConnectAdaptor::Disconnect() { +void ExtensionConnectAdaptor::Disconnect() +{ std::lock_guard lock(mutex_); if (callback_ == nullptr) { ZLOGE("callback null"); diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h index 8584021f..0fc34990 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DATASHARESERVICE_CONNECT_EXTENSION_STRAGETY_H -#define DATASHARESERVICE_CONNECT_EXTENSION_STRAGETY_H +#ifndef DATASHARESERVICE_EXTENSION_CONNECT_ADAPTOR_H +#define DATASHARESERVICE_EXTENSION_CONNECT_ADAPTOR_H #include "ability_connect_callback_interface.h" #include "block_data.h" @@ -24,6 +24,7 @@ class ExtensionConnectAdaptor { public: static bool TryAndWait(std::shared_ptr context, int maxWaitTimeMs = 2000); ExtensionConnectAdaptor(); + private: bool Connect(std::shared_ptr context); void Disconnect(); -- Gitee From 8ee5048b16cd061cacd5021999ec167a8781c2ce Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 20:56:30 +0800 Subject: [PATCH 122/437] f Signed-off-by: hanlu --- .../data_share/common/app_connect_manager.cpp | 2 +- .../common/extension_connect_adaptor.cpp | 1 - .../common/extension_connect_adaptor.h | 1 - .../data_share/common/template_manager.cpp | 23 ++++++++++++++----- .../data_share/common/template_manager.h | 9 ++++---- .../data_share/data_share_service_impl.cpp | 8 ++++--- .../strategies/subscribe_strategy.cpp | 3 +-- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp index 1035b2f9..c15c28ab 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp @@ -25,13 +25,13 @@ bool AppConnectManager::Wait(const std::string &bundleName, blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) { return █ }); + ZLOGI("start connect %{public}s", bundleName.c_str()); bool result = connect(); if (!result) { ZLOGE("connect failed %{public}s", bundleName.c_str()); blockCache_.Erase(bundleName); return false; } - ZLOGI("start wait %{public}s", bundleName.c_str()); result = block.GetValue(); ZLOGI("end wait %{public}s", bundleName.c_str()); blockCache_.Erase(bundleName); diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index 2961f5b1..714140e1 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -37,7 +37,6 @@ ExtensionConnectAdaptor::ExtensionConnectAdaptor() : data_(1) {} bool ExtensionConnectAdaptor::DoConnect(std::shared_ptr context) { - std::lock_guard lock(mutex_); AAFwk::Want want; want.SetUri(context->uri); data_.Clear(); diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h index 0fc34990..4242b427 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h @@ -29,7 +29,6 @@ private: bool Connect(std::shared_ptr context); void Disconnect(); bool DoConnect(std::shared_ptr context); - std::mutex mutex_; BlockData data_; sptr callback_ = nullptr; }; diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index d2514c15..1bdb6f82 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -16,6 +16,8 @@ #include "template_manager.h" +#include "general/load_config_data_info_strategy.h" + #include "db_delegate.h" #include "log_print.h" #include "published_data.h" @@ -122,15 +124,21 @@ RdbSubscriberManager &RdbSubscriberManager::GetInstance() } int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const TemplateId &tplId, - const sptr observer, std::shared_ptr context) + const sptr observer, std::shared_ptr context, std::shared_ptr executorPool) { int result = E_OK; Key key(uri, tplId.subscriberId_, tplId.bundleName_); - rdbCache_.Compute(key, [&observer, &context, this](const auto &key, std::vector &value) { + rdbCache_.Compute(key, [&observer, &context, executorPool, this](const auto &key, std::vector &value) { ZLOGI("add subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), context->callerTokenId); std::vector node; node.emplace_back(observer, context->callerTokenId); - Notify(key, node, context->calledSourceDir, context->version); + ExecutorPool::Task task = [key, node, context, this]() { + LoadConfigDataInfoStrategy loadDataInfo; + if (loadDataInfo(context)) { + Notify(key, node, context->calledSourceDir, context->version); + } + }; + executorPool->Execute(task); value.emplace_back(observer, context->callerTokenId); if (GetEnableObserverCount(key) == 1) { SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); @@ -192,7 +200,10 @@ int RdbSubscriberManager::EnableRdbSubscriber( it->enabled = true; std::vector node; node.emplace_back(it->observer, context->callerTokenId); - Notify(key, node, context->calledSourceDir, context->version); + LoadConfigDataInfoStrategy loadDataInfo; + if (loadDataInfo(context)) { + Notify(key, node, context->calledSourceDir, context->version); + } } if (GetEnableObserverCount(key) == 1) { SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); @@ -266,7 +277,7 @@ int RdbSubscriberManager::GetEnableObserverCount(const Key &key) } int RdbSubscriberManager::Notify( - const Key &key, std::vector &val, const std::string &rdbDir, int rdbVersion) + const Key &key, const std::vector &val, const std::string &rdbDir, int rdbVersion) { Template tpl; if (!TemplateManager::GetInstance().GetTemplate(key.uri, key.subscriberId, key.bundleName, tpl)) { @@ -290,7 +301,7 @@ int RdbSubscriberManager::Notify( } ZLOGI("emit, size %{public}zu %{private}s", val.size(), changeNode.uri_.c_str()); - for (auto &callback : val) { + for (const auto &callback : val) { if (callback.enabled && callback.observer != nullptr) { callback.observer->OnChangeFromRdb(changeNode); } diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index f6b4e5a5..78d51dd7 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -20,9 +20,10 @@ #include #include "concurrent_map.h" -#include "datashare_template.h" -#include "data_proxy_observer.h" #include "context.h" +#include "data_proxy_observer.h" +#include "datashare_template.h" +#include "executor_pool.h" namespace OHOS::DataShare { struct Key { Key(const std::string &uri, const int64_t subscriberId, const std::string &bundleName); @@ -52,7 +53,7 @@ class RdbSubscriberManager { public: static RdbSubscriberManager &GetInstance(); int AddRdbSubscriber(const std::string &uri, const TemplateId &tplId, const sptr observer, - std::shared_ptr context); + std::shared_ptr context, std::shared_ptr executorPool); int DelRdbSubscriber(const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId); int DisableRdbSubscriber( const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId); @@ -72,7 +73,7 @@ private: RdbSubscriberManager() = default; ConcurrentMap> rdbCache_; - int Notify(const Key &key, std::vector &val, const std::string &rdbDir, int rdbVersion); + int Notify(const Key &key, const std::vector &val, const std::string &rdbDir, int rdbVersion); int GetEnableObserverCount(const Key &key); }; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 170ed9b9..15768fa2 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -190,9 +190,11 @@ std::vector DataShareServiceImpl::SubscribeRdbData( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &observer, &context]() -> bool { - return RdbSubscriberManager::GetInstance().AddRdbSubscriber(context->uri, id, observer, context); - })); + results.emplace_back( + uri, SubscribeStrategy::Execute(context, [&id, &observer, &context, this]() -> bool { + return RdbSubscriberManager::GetInstance().AddRdbSubscriber( + context->uri, id, observer, context, binderInfo_.executors); + })); } return results; } diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp index ef9ad6b0..cdad8087 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp @@ -49,8 +49,7 @@ Strategy *SubscribeStrategy::GetStrategy() std::initializer_list list = { new (std::nothrow)LoadConfigCommonStrategy(), new (std::nothrow)LoadConfigFromDataProxyNodeStrategy(), - new (std::nothrow)PermissionStrategy(), - new (std::nothrow)LoadConfigDataInfoStrategy() + new (std::nothrow)PermissionStrategy() }; auto ret = strategies.Init(list); if (!ret) { -- Gitee From 8b9f6e114863f241a05c7b5ee974cd83e9e8543b Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 21:04:57 +0800 Subject: [PATCH 123/437] f Signed-off-by: hanlu --- .../service/data_share/common/extension_connect_adaptor.cpp | 1 - .../service/data_share/common/template_manager.cpp | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index 714140e1..fcbf64a3 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -70,7 +70,6 @@ bool ExtensionConnectAdaptor::TryAndWait(std::shared_ptr context, int m void ExtensionConnectAdaptor::Disconnect() { - std::lock_guard lock(mutex_); if (callback_ == nullptr) { ZLOGE("callback null"); return; diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 1bdb6f82..ab2dbd19 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -124,7 +124,8 @@ RdbSubscriberManager &RdbSubscriberManager::GetInstance() } int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const TemplateId &tplId, - const sptr observer, std::shared_ptr context, std::shared_ptr executorPool) + const sptr observer, std::shared_ptr context, + std::shared_ptr executorPool) { int result = E_OK; Key key(uri, tplId.subscriberId_, tplId.bundleName_); -- Gitee From 76ed0597e752ed662f88d2c57c7483f13287424b Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 21:39:44 +0800 Subject: [PATCH 124/437] f Signed-off-by: hanlu --- .../service/data_share/common/template_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index ab2dbd19..24ae27aa 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -129,7 +129,8 @@ int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const Templat { int result = E_OK; Key key(uri, tplId.subscriberId_, tplId.bundleName_); - rdbCache_.Compute(key, [&observer, &context, executorPool, this](const auto &key, std::vector &value) { + rdbCache_.Compute(key, + [&observer, &context, executorPool, this](const auto &key, std::vector &value) { ZLOGI("add subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), context->callerTokenId); std::vector node; node.emplace_back(observer, context->callerTokenId); -- Gitee From 52fa99cfcb338a812dfbde50cd6668f456026439 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 24 May 2023 22:15:25 +0800 Subject: [PATCH 125/437] add cloud permission Signed-off-by: zuojiangjiang --- .../adapter/include/permission/permission_validator.h | 1 + .../adapter/permission/src/permission_validator.cpp | 7 +++++++ .../service/cloud/cloud_service_stub.cpp | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/adapter/include/permission/permission_validator.h b/services/distributeddataservice/adapter/include/permission/permission_validator.h index ab78f199..813413ee 100644 --- a/services/distributeddataservice/adapter/include/permission/permission_validator.h +++ b/services/distributeddataservice/adapter/include/permission/permission_validator.h @@ -27,6 +27,7 @@ public: // check whether the client process have enough privilege to share data with the other devices. // tokenId: client process tokenId API_EXPORT bool CheckSyncPermission(uint32_t tokenId); + API_EXPORT bool CheckCloudPermission(uint32_t tokenId); private: static constexpr const char *DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC"; diff --git a/services/distributeddataservice/adapter/permission/src/permission_validator.cpp b/services/distributeddataservice/adapter/permission/src/permission_validator.cpp index 93218763..fd371633 100644 --- a/services/distributeddataservice/adapter/permission/src/permission_validator.cpp +++ b/services/distributeddataservice/adapter/permission/src/permission_validator.cpp @@ -42,5 +42,12 @@ bool PermissionValidator::CheckSyncPermission(uint32_t tokenId) ZLOGE("token:0x%{public}x", tokenId); return false; } + +bool PermissionValidator::CheckCloudPermission(uint32_t tokenId) +{ + auto permit = AccessTokenKit::VerifyAccessToken(tokenId, CLOUD_DATA_CONFIG); + ZLOGD("cloud permit: %{public}d", permit); + return permit == PERMISSION_GRANTED; +} } // namespace DistributedKv } // namespace OHOS diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index b14485f4..1d8aff05 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -18,6 +18,7 @@ #include "ipc_skeleton.h" #include "itypes_util.h" #include "log_print.h" +#include "permission_validator.h" #include "utils/anonymous.h" #include "tokenid_kit.h" namespace OHOS::CloudData { @@ -46,7 +47,8 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, return -1; } - if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) { + if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID()) + && DistributedKv::PermissionValidator::GetInstance().CheckCloudPermission(IPCSkeleton::GetCallingTokenID()) { ZLOGE("permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); auto result = static_cast(PERMISSION_DENIED); return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; -- Gitee From 9d44fe7985c88dd1330839febb914a7b435f9677 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 24 May 2023 22:34:25 +0800 Subject: [PATCH 126/437] fix:check cloudInfo From server Signed-off-by: htt1997 --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index f3984e45..fca27edb 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -247,7 +247,7 @@ int32_t CloudServiceImpl::GetCloudInfoFromServer(CloudInfo &cloudInfo) return NOT_SUPPORT; } cloudInfo = instance->GetServerInfo(cloudInfo.user); - return SUCCESS; + return cloudInfo.IsValid() ? SUCCESS : ERROR; } void CloudServiceImpl::UpdateCloudInfo(CloudInfo &cloudInfo) -- Gitee From 372bf9bd752e62553fe5faa9e77335e101c470a8 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 25 May 2023 09:00:54 +0800 Subject: [PATCH 127/437] update Signed-off-by: zuojiangjiang --- .../adapter/include/permission/permission_validator.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/adapter/include/permission/permission_validator.h b/services/distributeddataservice/adapter/include/permission/permission_validator.h index 813413ee..6cf3f066 100644 --- a/services/distributeddataservice/adapter/include/permission/permission_validator.h +++ b/services/distributeddataservice/adapter/include/permission/permission_validator.h @@ -31,6 +31,7 @@ public: private: static constexpr const char *DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC"; + static constexpr const char *CLOUD_DATA_CONFIG = "ohos.permission.CLOUDDATA_CONFIG"; }; } // namespace DistributedKv } // namespace OHOS -- Gitee From 22b096d28ceb907a089402af0fad0632689e9e20 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 25 May 2023 09:47:25 +0800 Subject: [PATCH 128/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/cloud_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 1d8aff05..9f94d32d 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -18,7 +18,7 @@ #include "ipc_skeleton.h" #include "itypes_util.h" #include "log_print.h" -#include "permission_validator.h" +#include "permission/permission_validator.h" #include "utils/anonymous.h" #include "tokenid_kit.h" namespace OHOS::CloudData { -- Gitee From 94c0802252f20ce7e53ea9a953b01fad9f795a78 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 25 May 2023 10:21:39 +0800 Subject: [PATCH 129/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/cloud_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 9f94d32d..cc6ddace 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -48,7 +48,7 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, } if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID()) - && DistributedKv::PermissionValidator::GetInstance().CheckCloudPermission(IPCSkeleton::GetCallingTokenID()) { + && DistributedKv::PermissionValidator::GetInstance().CheckCloudPermission(IPCSkeleton::GetCallingTokenID())) { ZLOGE("permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); auto result = static_cast(PERMISSION_DENIED); return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; -- Gitee From a0e7c78790d9167d3eb3d6cc4f45bfbface83fd6 Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 25 May 2023 11:17:27 +0800 Subject: [PATCH 130/437] f Signed-off-by: hanlu --- .../service/data_share/common/app_connect_manager.cpp | 4 ++-- .../service/data_share/common/app_connect_manager.h | 2 +- .../service/data_share/common/extension_connect_adaptor.cpp | 4 ++-- .../service/data_share/common/extension_connect_adaptor.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp index c15c28ab..292f7f62 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp @@ -19,9 +19,9 @@ namespace OHOS::DataShare { ConcurrentMap *> AppConnectManager::blockCache_; bool AppConnectManager::Wait(const std::string &bundleName, - int maxWaitTimeMs, std::function connect, std::function disconnect) + int maxWaitTime, std::function connect, std::function disconnect) { - BlockData block(maxWaitTimeMs, false); + BlockData block(maxWaitTime, false); blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) { return █ }); diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.h b/services/distributeddataservice/service/data_share/common/app_connect_manager.h index 4bdb07fa..3c447f77 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.h +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.h @@ -25,7 +25,7 @@ namespace OHOS::DataShare { class AppConnectManager { public: - static bool Wait(const std::string &bundleName, int maxWaitTimeMs, std::function connect, + static bool Wait(const std::string &bundleName, int maxWaitTime, std::function connect, std::function disconnect); static void Notify(const std::string &bundleName); diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index fcbf64a3..ec9a85ef 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -54,11 +54,11 @@ bool ExtensionConnectAdaptor::DoConnect(std::shared_ptr context) return result; } -bool ExtensionConnectAdaptor::TryAndWait(std::shared_ptr context, int maxWaitTimeMs) +bool ExtensionConnectAdaptor::TryAndWait(std::shared_ptr context, int maxWaitTime) { ExtensionConnectAdaptor strategy; return AppConnectManager::Wait( - context->calledBundleName, maxWaitTimeMs, + context->calledBundleName, maxWaitTime, [&context, &strategy]() { return strategy.Connect(context); }, diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h index 4242b427..7ada7d56 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.h @@ -22,7 +22,7 @@ namespace OHOS::DataShare { class ExtensionConnectAdaptor { public: - static bool TryAndWait(std::shared_ptr context, int maxWaitTimeMs = 2000); + static bool TryAndWait(std::shared_ptr context, int maxWaitTime = 2); ExtensionConnectAdaptor(); private: -- Gitee From 8a9f8508d78138593c0609a35d9176d5af0ffeb1 Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 25 May 2023 14:05:48 +0800 Subject: [PATCH 131/437] f Signed-off-by: hanlu --- .../service/data_share/common/app_connect_manager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp index 292f7f62..edd6df8c 100644 --- a/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/app_connect_manager.cpp @@ -22,11 +22,15 @@ bool AppConnectManager::Wait(const std::string &bundleName, int maxWaitTime, std::function connect, std::function disconnect) { BlockData block(maxWaitTime, false); - blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) { + auto result = blockCache_.ComputeIfAbsent(bundleName, [&block](const std::string &key) { return █ }); + if (!result) { + ZLOGE("is running %{public}s", bundleName.c_str()); + return false; + } ZLOGI("start connect %{public}s", bundleName.c_str()); - bool result = connect(); + result = connect(); if (!result) { ZLOGE("connect failed %{public}s", bundleName.c_str()); blockCache_.Erase(bundleName); -- Gitee From 991d5848f52836c4eaedccffddf9f3a8a3ce8a7b Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 25 May 2023 14:40:10 +0800 Subject: [PATCH 132/437] update Signed-off-by: zuojiangjiang --- .../adapter/include/permission/permission_validator.h | 2 +- .../adapter/permission/src/permission_validator.cpp | 2 +- .../distributeddataservice/service/cloud/cloud_service_stub.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/adapter/include/permission/permission_validator.h b/services/distributeddataservice/adapter/include/permission/permission_validator.h index 6cf3f066..322d8b00 100644 --- a/services/distributeddataservice/adapter/include/permission/permission_validator.h +++ b/services/distributeddataservice/adapter/include/permission/permission_validator.h @@ -27,7 +27,7 @@ public: // check whether the client process have enough privilege to share data with the other devices. // tokenId: client process tokenId API_EXPORT bool CheckSyncPermission(uint32_t tokenId); - API_EXPORT bool CheckCloudPermission(uint32_t tokenId); + API_EXPORT bool IsCloudConfigPermit(uint32_t tokenId); private: static constexpr const char *DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC"; diff --git a/services/distributeddataservice/adapter/permission/src/permission_validator.cpp b/services/distributeddataservice/adapter/permission/src/permission_validator.cpp index fd371633..f4f58c6d 100644 --- a/services/distributeddataservice/adapter/permission/src/permission_validator.cpp +++ b/services/distributeddataservice/adapter/permission/src/permission_validator.cpp @@ -43,7 +43,7 @@ bool PermissionValidator::CheckSyncPermission(uint32_t tokenId) return false; } -bool PermissionValidator::CheckCloudPermission(uint32_t tokenId) +bool PermissionValidator::IsCloudConfigPermit(uint32_t tokenId) { auto permit = AccessTokenKit::VerifyAccessToken(tokenId, CLOUD_DATA_CONFIG); ZLOGD("cloud permit: %{public}d", permit); diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index cc6ddace..901baf98 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -48,7 +48,7 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, } if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID()) - && DistributedKv::PermissionValidator::GetInstance().CheckCloudPermission(IPCSkeleton::GetCallingTokenID())) { + || !DistributedKv::PermissionValidator::GetInstance().IsCloudConfigPermit(IPCSkeleton::GetCallingTokenID())) { ZLOGE("permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); auto result = static_cast(PERMISSION_DENIED); return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; -- Gitee From 7c01dd2d54483350e0d354176e2acae2ea92b13e Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 25 May 2023 14:41:16 +0800 Subject: [PATCH 133/437] style:code check Signed-off-by: htt1997 --- .../adapter/communicator/src/softbus_adapter_standard.cpp | 2 +- .../distributeddataservice/app/src/kvstore_data_service.cpp | 2 +- .../distributeddataservice/app/src/kvstore_meta_manager.h | 2 +- .../app/src/session_manager/upgrade_manager.cpp | 5 +++-- .../app/src/uninstaller/uninstaller_impl.h | 3 ++- .../framework/metadata/store_meta_data_local.cpp | 4 ++-- .../distributeddataservice/framework/store/auto_cache.cpp | 4 +++- .../distributeddataservice/service/kvdb/auth_delegate.cpp | 2 +- .../service/kvdb/kvstore_sync_manager.h | 4 ++-- services/distributeddataservice/service/kvdb/store_cache.cpp | 3 +-- services/distributeddataservice/service/kvdb/upgrade.h | 2 +- .../service/matrix/src/device_matrix.cpp | 2 +- .../service/test/mock/db_store_mock.cpp | 2 +- 13 files changed, 20 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp index e86d1945..d7c2d786 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp @@ -435,7 +435,7 @@ void SoftBusAdapter::SofBusDeviceChangeListenerImpl::OnDeviceChanged(const AppDi } CommunicationStrategy::GetInstance().SetStrategy(info.uuid, strategy, - [this](const std::string deviceId, Strategy strategy) { + [this](const std::string &deviceId, Strategy strategy) { std::shared_ptr conn = SoftBusAdapter::GetInstance()->GetConnect(deviceId); if (conn != nullptr) { conn->AfterStrategyUpdate(strategy); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index b552aa00..98e78074 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -351,7 +351,7 @@ void KvStoreDataService::OnStoreMetaChanged( if (!metaData.isDirty || metaData.appType != HARMONY_APP) { return; } - ZLOGI("dirty kv store. storeId:%{public}s", metaData.storeId.c_str()); + ZLOGI("dirty kv store. storeId:%{public}s", Anonymous::Change(metaData.storeId).c_str()); } bool KvStoreDataService::ResolveAutoLaunchParamByIdentifier( diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.h b/services/distributeddataservice/app/src/kvstore_meta_manager.h index 9fb69912..db977717 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.h +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.h @@ -83,7 +83,7 @@ private: void OnChange(const DistributedDB::KvStoreChangedData &data) override; std::map handlerMap_; private: - void HandleChanges(CHANGE_FLAG flag, const std::list &list); + void HandleChanges(CHANGE_FLAG flag, const std::list &entries); }; static constexpr int32_t RETRY_MAX_TIMES = 100; diff --git a/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp b/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp index 3d4db8d4..584fb918 100644 --- a/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp +++ b/services/distributeddataservice/app/src/session_manager/upgrade_manager.cpp @@ -116,8 +116,9 @@ void UpgradeManager::SetCompatibleIdentifyByType(DistributedDB::KvStoreNbDelegat auto syncIdentifier = DistributedDB::KvStoreDelegateManager::GetKvStoreIdentifier(compatibleUser, tuple.appId, tuple.storeId); - ZLOGI("set compatible identifier, store:%{public}s, user:%{public}s, device:%{public}.10s", tuple.storeId.c_str(), - compatibleUser.c_str(), DistributedData::Serializable::Marshall(devices).c_str()); + ZLOGI("set compatible identifier, store:%{public}s, user:%{public}s, device:%{public}.10s", + Anonymous::Change(tuple.storeId).c_str(), compatibleUser.c_str(), + DistributedData::Serializable::Marshall(devices).c_str()); storeDelegate->SetEqualIdentifier(syncIdentifier, devices); } diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index e6498a67..3b8a3a7d 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -41,6 +41,7 @@ private: class UninstallerImpl : public Uninstaller { public: + UninstallerImpl() = default; ~UninstallerImpl(); Status Init(KvStoreDataService *kvStoreDataService, std::shared_ptr executors) override; @@ -53,7 +54,7 @@ private: int32_t retryTime_ = 0; ExecutorPool::Task GetTask(); std::shared_ptr subscriber_ {}; - std::shared_ptr executors_; + std::shared_ptr executors_ {}; }; } // namespace OHOS::DistributedKv #endif // DISTRIBUTEDDATAMGR_UNINSTALLER_IMPL_H diff --git a/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp b/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp index 1725d66c..4b1cdf06 100644 --- a/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp +++ b/services/distributeddataservice/framework/metadata/store_meta_data_local.cpp @@ -40,7 +40,7 @@ bool PolicyValue::IsValueEffect() const bool StoreMetaDataLocal::HasPolicy(uint32_t type) { - for (auto &policy : policies) { + for (const auto &policy : policies) { if (policy.type == type) { return true; } @@ -50,7 +50,7 @@ bool StoreMetaDataLocal::HasPolicy(uint32_t type) PolicyValue StoreMetaDataLocal::GetPolicy(uint32_t type) { - for (auto &policy : policies) { + for (const auto &policy : policies) { if (policy.type == type) { return policy; } diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index 53f671ee..8b44d688 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -14,6 +14,7 @@ */ #define LOG_TAG "AutoCache" #include "store/auto_cache.h" +#include "utils/anonymous.h" #include "log_print.h" namespace OHOS::DistributedData { @@ -115,7 +116,8 @@ void AutoCache::CloseExcept(const std::set &users) void AutoCache::SetObserver(uint32_t tokenId, const std::string &storeId, const AutoCache::Watchers &watchers) { stores_.ComputeIfPresent(tokenId, [&storeId, &watchers](auto &key, auto &stores) { - ZLOGD("tokenId:0x%{public}x storeId:%{public}s observers:%{public}zu", key, storeId.c_str(), watchers.size()); + ZLOGD("tokenId:0x%{public}x storeId:%{public}s observers:%{public}zu", key, Anonymous::Change(storeId).c_str(), + watchers.size()); auto it = stores.find(storeId); if (it != stores.end()) { it->second.SetObservers(watchers); diff --git a/services/distributeddataservice/service/kvdb/auth_delegate.cpp b/services/distributeddataservice/service/kvdb/auth_delegate.cpp index b768416e..c50f1236 100644 --- a/services/distributeddataservice/service/kvdb/auth_delegate.cpp +++ b/services/distributeddataservice/service/kvdb/auth_delegate.cpp @@ -32,7 +32,7 @@ public: int localUserId, int peerUserId, const std::string &peerDeviceId, const std::string &appId) override; private: - bool IsUserActive(const std::vector &userStatus, int32_t userId); + bool IsUserActive(const std::vector &users, int32_t userId); static constexpr pid_t UID_CAPACITY = 10000; static constexpr int SYSTEM_USER = 0; }; diff --git a/services/distributeddataservice/service/kvdb/kvstore_sync_manager.h b/services/distributeddataservice/service/kvdb/kvstore_sync_manager.h index bad171c5..4f4fc19d 100644 --- a/services/distributeddataservice/service/kvdb/kvstore_sync_manager.h +++ b/services/distributeddataservice/service/kvdb/kvstore_sync_manager.h @@ -62,9 +62,9 @@ private: uint32_t DoRemoveSyncingOp(OpPred pred, std::list &syncingOps); Status RemoveSyncingOp(uint32_t opSeq, std::list &syncingOps); void AddTimer(const TimePoint &expireTime); - bool GetTimeoutSyncOps(const TimePoint &time, std::list &syncOps); + bool GetTimeoutSyncOps(const TimePoint ¤tTime, std::list &syncOps); void DoCheckSyncingTimeout(std::list &syncingOps); - void Schedule(const TimePoint &expireTime); + void Schedule(const TimePoint &time); static constexpr uint32_t SYNCING_TIMEOUT_MS = 5000; static constexpr uint32_t REALTIME_PRIOR_SYNCING_MS = 300; diff --git a/services/distributeddataservice/service/kvdb/store_cache.cpp b/services/distributeddataservice/service/kvdb/store_cache.cpp index 2bbaa358..3f9059e8 100644 --- a/services/distributeddataservice/service/kvdb/store_cache.cpp +++ b/services/distributeddataservice/service/kvdb/store_cache.cpp @@ -199,9 +199,8 @@ void StoreCache::SetThreadPool(std::shared_ptr executors) } StoreCache::DBStoreDelegate::DBStoreDelegate(DBStore *delegate, std::shared_ptr observers) - : delegate_(delegate) + : time_(std::chrono::steady_clock::now() + std::chrono::minutes(INTERVAL)), delegate_(delegate) { - time_ = std::chrono::steady_clock::now() + std::chrono::minutes(INTERVAL); SetObservers(std::move(observers)); } diff --git a/services/distributeddataservice/service/kvdb/upgrade.h b/services/distributeddataservice/service/kvdb/upgrade.h index b6d83b02..5e982380 100644 --- a/services/distributeddataservice/service/kvdb/upgrade.h +++ b/services/distributeddataservice/service/kvdb/upgrade.h @@ -39,7 +39,7 @@ public: API_EXPORT bool RegisterExporter(uint32_t version, Exporter exporter); API_EXPORT bool RegisterCleaner(uint32_t version, Cleaner cleaner); - DBStatus UpdateStore(const StoreMeta &old, const StoreMeta &metaData, const std::vector &pwd); + DBStatus UpdateStore(const StoreMeta &old, const StoreMeta &meta, const std::vector &pwd); DBStatus ExportStore(const StoreMeta &old, const StoreMeta &meta); void UpdatePassword(const StoreMeta &meta, const std::vector &password); DBStatus UpdateUuid(const StoreMeta &old, const StoreMeta &meta, const std::vector &pwd); diff --git a/services/distributeddataservice/service/matrix/src/device_matrix.cpp b/services/distributeddataservice/service/matrix/src/device_matrix.cpp index 2217be08..a1ee0235 100644 --- a/services/distributeddataservice/service/matrix/src/device_matrix.cpp +++ b/services/distributeddataservice/service/matrix/src/device_matrix.cpp @@ -217,7 +217,7 @@ uint16_t DeviceMatrix::ConvertMask(const std::string &device, uint16_t code) if (index >= meta.maskInfo.size()) { return result; } - auto &app = meta.maskInfo[index]; + const auto &app = meta.maskInfo[index]; for (size_t i = 0; i < maskApps_.size(); i++) { if (maskApps_[i] == app) { result |= SetMask(i); diff --git a/services/distributeddataservice/service/test/mock/db_store_mock.cpp b/services/distributeddataservice/service/test/mock/db_store_mock.cpp index 55d9ca88..cd1e2df6 100644 --- a/services/distributeddataservice/service/test/mock/db_store_mock.cpp +++ b/services/distributeddataservice/service/test/mock/db_store_mock.cpp @@ -136,7 +136,7 @@ DBStatus DBStoreMock::Sync(const std::vector &devices, SyncMode mod const std::function &)> &onComplete, bool wait) { std::map result; - for (auto &device : devices) { + for (const auto &device : devices) { result[device] = OK; } onComplete(result); -- Gitee From 83300678883aaa2f53ed04921237c714e1104812 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 25 May 2023 17:38:12 +0800 Subject: [PATCH 134/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_stub.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 901baf98..34a65dc1 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -47,13 +47,18 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, return -1; } - if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID()) - || !DistributedKv::PermissionValidator::GetInstance().IsCloudConfigPermit(IPCSkeleton::GetCallingTokenID())) { + if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) { ZLOGE("permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); auto result = static_cast(PERMISSION_DENIED); return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; } + if (!DistributedKv::PermissionValidator::GetInstance().IsCloudConfigPermit(IPCSkeleton::GetCallingTokenID())) { + ZLOGE("cloud config permission denied! code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); + auto result = static_cast(CLOUD_CONFIG_PERMISSION_DENIED); + return ITypesUtil::Marshal(reply, result) ? ERR_NONE : IPC_STUB_WRITE_PARCEL_ERR; + } + std::string id; if (!ITypesUtil::Unmarshal(data, id)) { ZLOGE("Unmarshal id:%{public}s", Anonymous::Change(id).c_str()); -- Gitee From 1c3f800ef45c665961b80a503bfa5ebc6ab1ad62 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Thu, 25 May 2023 17:38:58 +0800 Subject: [PATCH 135/437] warn fix Signed-off-by: niudongyao --- .../strategies/general/load_config_data_info_strategy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index 4ad67991..52a12242 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -82,7 +82,7 @@ bool LoadConfigSingleDataInfoStrategy::operator()(std::shared_ptr conte } } context->calledSourceDir = metaData.dataDir; - context->version = metaData.version; + context->version = static_cast(metaData.version); return true; } } // namespace OHOS::DataShare \ No newline at end of file -- Gitee From a20650bf69d215d0eb508c2c400a4941f901bedb Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 26 May 2023 09:44:33 +0800 Subject: [PATCH 136/437] f Signed-off-by: hanlu --- .../service/data_share/common/extension_connect_adaptor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index ec9a85ef..a7ba14fc 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -40,7 +40,11 @@ bool ExtensionConnectAdaptor::DoConnect(std::shared_ptr context) AAFwk::Want want; want.SetUri(context->uri); data_.Clear(); - callback_ = new CallbackImpl(data_); + callback_ = new (std::nothrow) CallbackImpl(data_); + if (callback_ == nullptr) { + ZLOGI("new failed"); + return false; + } ZLOGI("Start connect %{public}s", context->uri.c_str()); ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, callback_, nullptr); if (ret != ERR_OK) { -- Gitee From c35435b7b3716f52a3299678735be5cc60ed5321 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Fri, 26 May 2023 10:02:47 +0800 Subject: [PATCH 137/437] style:code check Signed-off-by: htt1997 --- services/distributeddataservice/framework/cloud/cloud_event.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_event.cpp b/services/distributeddataservice/framework/cloud/cloud_event.cpp index cdd0e02e..4cc139bd 100644 --- a/services/distributeddataservice/framework/cloud/cloud_event.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_event.cpp @@ -21,7 +21,7 @@ CloudEvent::CloudEvent(int32_t evtId, CloudEvent::StoreInfo storeInfo, const std { } -const std::string& CloudEvent::GetFeatureName() const +const std::string& CloudEvent::GetFeatureName() const { return featureName_; } -- Gitee From 0579c1184aa2bae7ef25b783db065a6583457ac2 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Fri, 26 May 2023 17:04:28 +0800 Subject: [PATCH 138/437] fix oh alarm Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/common/src/json_common.cpp | 10 ++++++++-- .../gaussdb_rd/src/interface/include/projection_tree.h | 3 +-- .../gaussdb_rd/src/interface/src/projection_tree.cpp | 2 +- .../gaussdb_rd/src/interface/src/result_set.cpp | 2 +- .../gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp | 7 +++++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 61f29c65..280f12d8 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -340,7 +340,7 @@ bool AddSpliteHitField(const JsonObject &src, const JsonObject &item, JsonFieldP return true; } - for (int i = abandonPath.size() - 1; i > -1; i--) { + for (size_t i = abandonPath.size() - 1; i < abandonPath.size() && i >= 0; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; @@ -352,6 +352,9 @@ bool AddSpliteHitField(const JsonObject &src, const JsonObject &item, JsonFieldP } errCode = (i == 0) ? hitItem.AddItemToObject(abandonPath[i], item) : hitItem.AddItemToObject(abandonPath[i]); externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + if (i == 0) { + break; + } } return false; } @@ -382,7 +385,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie return false; } JsonFieldPath newHitPath; - for (int i = abandonPath.size() - 1; i > -1; i--) { + for (size_t i = abandonPath.size() - 1; i < abandonPath.size() && i >= 0; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; @@ -400,6 +403,9 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie return false; } newHitPath.pop_back(); + if (i == 0) { + break; + } } return false; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h index f7c7b095..3cdca06d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h @@ -28,7 +28,6 @@ struct ProjectionNode { std::unordered_map sonNode; bool isDeepest; int Deep; - int ViewType; ProjectionNode() { Deep = 0; @@ -43,7 +42,7 @@ struct ProjectionNode { class ProjectionTree { public: int ParseTree(std::vector> &path); - bool SearchTree(std::vector &singlePath, int &index); + bool SearchTree(std::vector &singlePath, size_t &index); private: ProjectionNode node_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp index 94c56b6f..5c37b84b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -54,7 +54,7 @@ int ProjectionTree::ParseTree(std::vector> &path) return E_OK; } -bool ProjectionTree::SearchTree(std::vector &singlePath, int &index) +bool ProjectionTree::SearchTree(std::vector &singlePath, size_t &index) { ProjectionNode *node = &node_; for (size_t i = 0; i < singlePath.size(); i++) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index cadbf670..6c221daa 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -191,7 +191,7 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat return -E_NO_DATA; } singlePath.emplace_back(node->GetItemField()); - int index = 0; + size_t index = 0; if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { allCutPath.emplace_back(singlePath); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp index 0b40db95..64acd4a9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp @@ -295,8 +295,11 @@ int SQLiteUtils::ExecSql(sqlite3 *db, const std::string &sql, const std::functio } else if (errCode != SQLITE_ROW) { goto END; // Step return error } - if (resultCallback != nullptr && ((errCode = resultCallback(stmt)) != E_OK)) { - goto END; + if (resultCallback != nullptr) { + errCode = resultCallback(stmt); + if (errCode != E_OK) { + goto END; + } } } errCode = SQLiteUtils::ResetStatement(stmt, false); -- Gitee From a69875d17dd0e1e2ac6f9a3434a7028d291b5d93 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Fri, 26 May 2023 17:09:32 +0800 Subject: [PATCH 139/437] refactor:Getschema switch async Signed-off-by: htt1997 --- .../service/cloud/cloud_service_impl.cpp | 30 +++++++++++-------- .../service/rdb/rdb_service_impl.cpp | 8 +++-- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index fca27edb..5e554b82 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -320,14 +320,14 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) SchemaMeta CloudServiceImpl::GetSchemaMeta(int32_t userId, const std::string &bundleName, int32_t instanceId) { SchemaMeta schemaMeta; - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("instance is nullptr"); - return schemaMeta; - } CloudInfo cloudInfo; cloudInfo.user = userId; if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGE("instance is nullptr"); + return schemaMeta; + } cloudInfo = instance->GetServerInfo(userId); if (!cloudInfo.IsValid()) { ZLOGE("cloudInfo is invalid"); @@ -344,6 +344,11 @@ SchemaMeta CloudServiceImpl::GetSchemaMeta(int32_t userId, const std::string &bu } std::string schemaKey = cloudInfo.GetSchemaKey(bundleName, instanceId); if (!MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true)) { + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGE("instance is nullptr"); + return schemaMeta; + } schemaMeta = instance->GetAppSchema(cloudInfo.user, bundleName); MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); } @@ -396,13 +401,6 @@ void CloudServiceImpl::GetSchema(const Event &event) ZLOGD("bundleName:%{public}s no cloud database", rdbEvent.GetStoreInfo().bundleName.c_str()); return; } - auto storeMeta = GetStoreMeta(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, - rdbEvent.GetStoreInfo().instanceId); - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("instance is nullptr"); - return; - } auto database = std::find_if(schemaMeta.databases.begin(), schemaMeta.databases.end(), [&rdbEvent](const auto &database) { return database.name == rdbEvent.GetStoreInfo().storeName; @@ -412,6 +410,11 @@ void CloudServiceImpl::GetSchema(const Event &event) return; } + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGE("instance is nullptr"); + return; + } ZLOGD("database: %{public}s sync start", database->name.c_str()); auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, *database); if (cloudDB == nullptr) { @@ -419,6 +422,9 @@ void CloudServiceImpl::GetSchema(const Event &event) rdbEvent.GetStoreInfo().bundleName.c_str(), rdbEvent.GetStoreInfo().user, database->name.c_str()); return; } + + auto storeMeta = GetStoreMeta(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, + rdbEvent.GetStoreInfo().instanceId); AutoCache::Watchers watchers; auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers); if (store == nullptr) { diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 3b5baedb..e9c3fda3 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -511,12 +511,14 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) return RDB_ERROR; } - EventCenter::Defer defer; CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, RdbSyncer::RemoveSuffix(param.storeName_), RdbSyncer::GetInstIndex(IPCSkeleton::GetCallingTokenID(), param.bundleName_) }; - auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); - EventCenter::GetInstance().PostEvent(move(event)); + executors_->Execute([storeInfo]() { + auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); + EventCenter::GetInstance().PostEvent(move(event)); + }); + return RDB_OK; } -- Gitee From f6dc1cf5534c0a53f90db1b3b3f78f2cfb841944 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Fri, 26 May 2023 18:50:59 +0800 Subject: [PATCH 140/437] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp index 64acd4a9..66b0156b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp @@ -295,11 +295,9 @@ int SQLiteUtils::ExecSql(sqlite3 *db, const std::string &sql, const std::functio } else if (errCode != SQLITE_ROW) { goto END; // Step return error } - if (resultCallback != nullptr) { - errCode = resultCallback(stmt); - if (errCode != E_OK) { - goto END; - } + errCode = resultCallback(stmt); + if (resultCallback != nullptr && errCode != E_OK) { + goto END; } } errCode = SQLiteUtils::ResetStatement(stmt, false); -- Gitee From 2f35ee013ae1470562fc2bed07361e9fbb384c87 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 27 May 2023 11:23:46 +0800 Subject: [PATCH 141/437] refactor:refactor Signed-off-by: htt1997 --- .../service/rdb/rdb_service_impl.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index e9c3fda3..24b656da 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -511,13 +511,16 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) return RDB_ERROR; } - CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, + if (executors_ != nullptr) { + CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, RdbSyncer::RemoveSuffix(param.storeName_), RdbSyncer::GetInstIndex(IPCSkeleton::GetCallingTokenID(), param.bundleName_) }; - executors_->Execute([storeInfo]() { - auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "relational_store"); - EventCenter::GetInstance().PostEvent(move(event)); - }); + executors_->Execute([storeInfo]() { + auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), + "relational_store"); + EventCenter::GetInstance().PostEvent(move(event)); + }); + } return RDB_OK; } -- Gitee From b31d0d08e3c51220fab4bce231b6e38ad7ec5ddc Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 27 May 2023 14:46:16 +0800 Subject: [PATCH 142/437] fix code check opinion Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/common/src/json_common.cpp | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 280f12d8..26db0afb 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -339,23 +339,21 @@ bool AddSpliteHitField(const JsonObject &src, const JsonObject &item, JsonFieldP if (hitItem.IsNull()) { return true; } - - for (size_t i = abandonPath.size() - 1; i < abandonPath.size() && i >= 0; i--) { + size_t index = abandonPath.size() - 1; + do { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; return false; } - if (IsNumber(abandonPath[i])) { + if (IsNumber(abandonPath[index])) { externErrCode = -E_DATA_CONFLICT; return false; } - errCode = (i == 0) ? hitItem.AddItemToObject(abandonPath[i], item) : hitItem.AddItemToObject(abandonPath[i]); + errCode = (index == 0) ? hitItem.AddItemToObject(abandonPath[index], item) + : hitItem.AddItemToObject(abandonPath[index]); externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - if (i == 0) { - break; - } - } + } while (index-- != 0); return false; } @@ -385,28 +383,27 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie return false; } JsonFieldPath newHitPath; - for (size_t i = abandonPath.size() - 1; i < abandonPath.size() && i >= 0; i--) { + size_t index = abandonPath.size() - 1; + do { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; return false; } - if (IsNumber(abandonPath[i])) { + if (IsNumber(abandonPath[index])) { externErrCode = -E_DATA_CONFLICT; return false; } - errCode = (i == 0 ? hitItem.AddItemToObject(abandonPath[i], item) : hitItem.AddItemToObject(abandonPath[i])); + errCode = (index == 0 ? hitItem.AddItemToObject(abandonPath[index], item) + : hitItem.AddItemToObject(abandonPath[index])); externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - newHitPath.emplace_back(abandonPath[i]); + newHitPath.emplace_back(abandonPath[index]); hitItem = hitItem.FindItem(newHitPath, errCode); if (errCode != E_OK) { return false; } newHitPath.pop_back(); - if (i == 0) { - break; - } - } + } while (index-- != 0); return false; } -- Gitee From 26b39995e15d46ce6a3a6f7cfcb763e35b292a8c Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 27 May 2023 15:04:41 +0800 Subject: [PATCH 143/437] fix code check opinion Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp index 66b0156b..ca7332f3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp @@ -22,7 +22,7 @@ namespace DocumentDB { const int MAX_BLOB_READ_SIZE = 5 * 1024 * 1024; // 5M limit const int MAX_TEXT_READ_SIZE = 5 * 1024 * 1024; // 5M limit -const int BUSY_TIMEOUT_MS = 3000; // 3000ms for sqlite busy timeout. +const int BUSY_TIMEOUT_MS = 3000; // 3000ms for sqlite busy timeout. const std::string BEGIN_SQL = "BEGIN TRANSACTION"; const std::string BEGIN_IMMEDIATE_SQL = "BEGIN IMMEDIATE TRANSACTION"; const std::string COMMIT_SQL = "COMMIT TRANSACTION"; @@ -179,7 +179,7 @@ int SQLiteUtils::GetColumnBlobValue(sqlite3_stmt *statement, int index, std::vec if (keySize < 0 || keySize > MAX_BLOB_READ_SIZE) { GLOGW("[SQLiteUtils][Column blob] size over limit:%d", keySize); value.resize(MAX_BLOB_READ_SIZE + 1); // Reset value size to invalid - return E_OK; // Return OK for continue get data, but value is invalid + return E_OK; // Return OK for continue get data, but value is invalid } auto keyRead = static_cast(sqlite3_column_blob(statement, index)); @@ -218,7 +218,7 @@ int SQLiteUtils::GetColumnTextValue(sqlite3_stmt *statement, int index, std::str if (valSize < 0 || valSize > MAX_TEXT_READ_SIZE) { GLOGW("[SQLiteUtils][Column text] size over limit:%d", valSize); value.resize(MAX_TEXT_READ_SIZE + 1); // Reset value size to invalid - return E_OK; // Return OK for continue get data, but value is invalid + return E_OK; // Return OK for continue get data, but value is invalid } const unsigned char *val = sqlite3_column_text(statement, index); @@ -295,7 +295,9 @@ int SQLiteUtils::ExecSql(sqlite3 *db, const std::string &sql, const std::functio } else if (errCode != SQLITE_ROW) { goto END; // Step return error } - errCode = resultCallback(stmt); + if (resultCallback != nullptr) { + errCode = resultCallback(stmt); + } if (resultCallback != nullptr && errCode != E_OK) { goto END; } -- Gitee From ec8312d3e08152ae313ba6935d1ceb798b2fe105 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 27 May 2023 15:55:18 +0800 Subject: [PATCH 144/437] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/common/src/json_common.cpp | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 26db0afb..949f108b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -339,21 +339,20 @@ bool AddSpliteHitField(const JsonObject &src, const JsonObject &item, JsonFieldP if (hitItem.IsNull()) { return true; } - size_t index = abandonPath.size() - 1; - do { + + for (int32_t i = (int32_t)abandonPath.size() - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; return false; } - if (IsNumber(abandonPath[index])) { + if (IsNumber(abandonPath[i])) { externErrCode = -E_DATA_CONFLICT; return false; } - errCode = (index == 0) ? hitItem.AddItemToObject(abandonPath[index], item) - : hitItem.AddItemToObject(abandonPath[index]); + errCode = (i == 0) ? hitItem.AddItemToObject(abandonPath[i], item) : hitItem.AddItemToObject(abandonPath[i]); externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - } while (index-- != 0); + } return false; } @@ -383,27 +382,25 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie return false; } JsonFieldPath newHitPath; - size_t index = abandonPath.size() - 1; - do { + for (int32_t i = (int32_t)abandonPath.size() - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; return false; } - if (IsNumber(abandonPath[index])) { + if (IsNumber(abandonPath[i])) { externErrCode = -E_DATA_CONFLICT; return false; } - errCode = (index == 0 ? hitItem.AddItemToObject(abandonPath[index], item) - : hitItem.AddItemToObject(abandonPath[index])); + errCode = (i == 0 ? hitItem.AddItemToObject(abandonPath[i], item) : hitItem.AddItemToObject(abandonPath[i])); externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - newHitPath.emplace_back(abandonPath[index]); + newHitPath.emplace_back(abandonPath[i]); hitItem = hitItem.FindItem(newHitPath, errCode); if (errCode != E_OK) { return false; } newHitPath.pop_back(); - } while (index-- != 0); + } return false; } @@ -547,8 +544,7 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl { int externErrCode = E_OK; JsonObjectIterator(add, {}, - [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, - const JsonObject &item) { + [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, const JsonObject &item) { bool isCollapse = false; // Whether there is a path generated by the dot operator, such as t1.t2.t3 JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); if (src.IsFieldExists(itemPath)) { -- Gitee From 7f48098715f3431052ca7d726423d655fe6a9898 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 27 May 2023 17:29:48 +0800 Subject: [PATCH 145/437] fix code check Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 949f108b..8391997e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -544,7 +544,8 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl { int externErrCode = E_OK; JsonObjectIterator(add, {}, - [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, const JsonObject &item) { + [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, + const JsonObject &item) { bool isCollapse = false; // Whether there is a path generated by the dot operator, such as t1.t2.t3 JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); if (src.IsFieldExists(itemPath)) { -- Gitee From efe493b11e2097ee46424550ad1b59db2215bed1 Mon Sep 17 00:00:00 2001 From: e Date: Mon, 29 May 2023 11:10:32 +0800 Subject: [PATCH 146/437] =?UTF-8?q?syscap=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: e --- bundle.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bundle.json b/bundle.json index c0a31d6a..1748d179 100644 --- a/bundle.json +++ b/bundle.json @@ -37,11 +37,7 @@ "component": { "name": "datamgr_service", "subsystem": "distributeddatamgr", - "syscap": [ - "SystemCapability.DistributedDataManager.KVStore.Core", - "SystemCapability.DistributedDataManager.KVStore.Lite", - "SystemCapability.DistributedDataManager.KVStore.DistributedKVStore" - ], + "syscap": [], "features": [], "adapted_system_type": [ "standard" -- Gitee From 56e73a7cc991ff4e89b683c7ff224b87ca1e5520 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 29 May 2023 17:18:09 +0800 Subject: [PATCH 147/437] fix alarm Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/common/src/json_common.cpp | 14 +++----------- .../src/interface/src/document_store.cpp | 9 ++++----- .../test/unittest/api/documentdb_data_test.cpp | 3 +-- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 8391997e..820c7438 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -505,9 +505,7 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json int errCode = E_OK; JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); std::string lastFieldName = itemPath.back(); - int isAddedFlag = false; if (errCode != E_OK) { - isAddedFlag = true; AddSpliteField(src, item, itemPath, externErrCode); return false; } @@ -521,7 +519,6 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json GLOGE("Add item to object failed. %d", errCode); return false; } - isAddedFlag = true; return false; } if (!isCollapse) { @@ -529,13 +526,10 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json if (!ret) { return false; // replace failed } - isAddedFlag = true; return false; // Different node types, overwrite directly, skip child node } - if (!isAddedFlag) { - GLOGE("Add nothing because data conflict"); - externErrCode = -E_DATA_CONFLICT; - } + GLOGE("Add nothing because data conflict"); + externErrCode = -E_DATA_CONFLICT; return false; // Source path not exist, overwrite directly, skip child node } } // namespace @@ -646,11 +640,9 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject bool &isCollapse, int &isMatchFlag) { int errCode; - int isAlreadyMatched = 0; JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { isMatchFlag = true; - isAlreadyMatched = 1; return false; } JsonFieldPath granpaPath = itemPath; @@ -661,7 +653,6 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK - isAlreadyMatched = 1; isMatchFlag = true; break; } @@ -670,6 +661,7 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject } return false; } + int isAlreadyMatched = 0; // means no match anything return IsObjectItemMatch(srcItem, item, isAlreadyMatched, isCollapse, isMatchFlag); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index cb1947eb..1b50f92a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -156,8 +156,8 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co GLOGE("update Parsed failed"); return errCode; } - std::vector> allPath; if (update != "{}") { + std::vector> allPath; allPath = JsonCommon::ParsePath(updateObj, errCode); if (errCode != E_OK) { GLOGE("updateObj ParsePath failed"); @@ -196,7 +196,6 @@ int DocumentStore::UpdateDataIntoDB(std::shared_ptr &context, Json docId = idValue.GetStringValue(); } else { ResultSet resultSet; - std::string filter = filterObj.Print(); InitResultSet(context, this, resultSet, true); // no start transaction inner errCode = resultSet.GetNext(false, true); @@ -343,8 +342,8 @@ END: int UpsertDocumentFormatCheck(const std::string &document, JsonObject &documentObj) { int errCode = E_OK; - std::vector> allPath; if (document != "{}") { + std::vector> allPath; allPath = JsonCommon::ParsePath(documentObj, errCode); if (errCode != E_OK) { return errCode; @@ -530,7 +529,7 @@ Collection DocumentStore::GetCollection(std::string &collectionName) return Collection(collectionName, executor_); } -int JudgeViewType(size_t &index, ValueObject &leafItem, bool &viewType) +int JudgeViewType(const size_t &index, ValueObject &leafItem, bool &viewType) { switch (leafItem.GetValueType()) { case ValueObject::ValueType::VALUE_BOOL: @@ -615,7 +614,7 @@ int FindArgsCheck(const std::string &collection, const std::string &filter, cons return errCode; } -int FindProjectionInit(const std::string &projection, std::shared_ptr &context) +int FindProjectionInit(const std::string &projection, const std::shared_ptr &context) { int errCode = E_OK; std::vector> allPath; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index 1ea370b5..7fdb5a56 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -318,8 +318,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest009, TestSize.Level0) char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); string valueStr = value; - string repectStr = R""({"_id":"1234", "field1":1, "field2":2, - "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; + string repectStr = R""({"_id":"1234","field1":1,"field2":2,"FIELD1":[1,true,1.23456789,"hello world!",null]})""; EXPECT_EQ((valueStr == repectStr), 1); EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); -- Gitee From a93404c88a15ae183f9b0529af80abfc563aba7a Mon Sep 17 00:00:00 2001 From: srr101 Date: Mon, 29 May 2023 19:57:26 +0800 Subject: [PATCH 148/437] code check fix Signed-off-by: srr101 --- .../service/data_share/common/callback_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/callback_impl.h b/services/distributeddataservice/service/data_share/common/callback_impl.h index 07237909..2eb22014 100644 --- a/services/distributeddataservice/service/data_share/common/callback_impl.h +++ b/services/distributeddataservice/service/data_share/common/callback_impl.h @@ -22,7 +22,7 @@ namespace OHOS::DataShare { class CallbackImpl : public AAFwk::AbilityConnectionStub { public: - CallbackImpl(BlockData &data) : data_(data) {} + explicit CallbackImpl(BlockData &data) : data_(data) {} void OnAbilityConnectDone( const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override { -- Gitee From d92dc296398af5b08a3c7f67e15b5f2ed76f11a0 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 29 May 2023 21:18:29 +0800 Subject: [PATCH 149/437] fix code check Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 820c7438..d4cd878f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -340,7 +340,7 @@ bool AddSpliteHitField(const JsonObject &src, const JsonObject &item, JsonFieldP return true; } - for (int32_t i = (int32_t)abandonPath.size() - 1; i > -1; i--) { + for (int32_t i = static_cast(abandonPath.size()) - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; @@ -382,7 +382,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie return false; } JsonFieldPath newHitPath; - for (int32_t i = (int32_t)abandonPath.size() - 1; i > -1; i--) { + for (int32_t i = static_cast(abandonPath.size()) - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; -- Gitee From 9101762ce1880b66360d2036f343a0848e0cfd12 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 31 May 2023 17:45:16 +0800 Subject: [PATCH 150/437] f Signed-off-by: hanlu --- .../service/data_share/common/db_delegate.cpp | 5 ++-- .../service/data_share/common/db_delegate.h | 3 ++- .../service/data_share/common/kv_delegate.cpp | 24 ++++++++++++++++--- .../service/data_share/common/kv_delegate.h | 5 +++- .../data_share/data_share_service_impl.cpp | 11 +++------ 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index fb80825d..b05ca94c 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -23,13 +23,14 @@ std::shared_ptr DBDelegate::Create(const std::string &dir, int versi return std::make_shared(dir, version, registerFunction); } -std::shared_ptr KvDBDelegate::GetInstance(bool reInit, const std::string &dir) +std::shared_ptr KvDBDelegate::GetInstance( + bool reInit, const std::string &dir, const std::shared_ptr &executors) { static std::shared_ptr delegate = nullptr; static std::mutex mutex; std::lock_guard lock(mutex); if (delegate == nullptr || reInit) { - delegate = std::make_shared(dir); + delegate = std::make_shared(dir, executors); } return delegate; } diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index fd81af57..286e3cd1 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -23,6 +23,7 @@ #include "datashare_predicates.h" #include "datashare_result_set.h" #include "datashare_values_bucket.h" +#include "executor_pool.h" #include "result_set.h" #include "serializable/serializable.h" @@ -90,7 +91,7 @@ class KvDBDelegate { public: static constexpr const char *TEMPLATE_TABLE = "template_"; static constexpr const char *DATA_TABLE = "data_"; - static std::shared_ptr GetInstance(bool reInit = false, const std::string &dir = ""); + static std::shared_ptr GetInstance(bool reInit = false, const std::string &dir = "", const std::shared_ptr &executors = nullptr); virtual ~KvDBDelegate() = default; virtual int32_t Upsert(const std::string &collectionName, const KvData &value) = 0; virtual int32_t DeleteById(const std::string &collectionName, const Id &id) = 0; diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index c17166cd..58b75832 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -23,6 +23,7 @@ #include "log_print.h" namespace OHOS::DataShare { +constexpr int WAIT_TIME = 30; int64_t KvDelegate::Upsert(const std::string &collectionName, const std::string &filter, const std::string &value) { std::lock_guard lock(mutex_); @@ -58,14 +59,28 @@ int64_t KvDelegate::Delete(const std::string &collectionName, const std::string bool KvDelegate::Init() { if (isInitDone_) { + if (executors_ != nullptr) { + ZLOGE("hanlu reset"); + executors_->Reset(taskId_, std::chrono::seconds(WAIT_TIME)); + } return true; } - int status = GRD_DBOpen((path_ + "/dataShare.db").c_str(), nullptr, GRD_DB_OPEN_CREATE, &db_); + int status = GRD_DBOpen( + (path_ + "/dataShare.db").c_str(), nullptr, GRD_DB_OPEN_CREATE | GRD_DB_OPEN_CHECK_FOR_ABNORMAL, &db_); if (status != GRD_OK || db_ == nullptr) { ZLOGE("GRD_DBOpen failed,status %{public}d", status); return false; } - + if (executors_ != nullptr) { + taskId_ = executors_->Schedule(std::chrono::seconds(WAIT_TIME), [this]() { + std::lock_guard lock(mutex_); + GRD_DBClose(db_, GRD_DB_CLOSE); + db_ = nullptr; + isInitDone_ = false; + ZLOGE("hanlu Close"); + taskId_ = ExecutorPool::INVALID_TASK_ID; + }); + } status = GRD_CreateCollection(db_, TEMPLATE_TABLE, nullptr, 0); if (status != GRD_OK) { ZLOGE("GRD_CreateCollection template table failed,status %{public}d", status); @@ -214,6 +229,9 @@ int32_t KvDelegate::GetBatch(const std::string &collectionName, const std::strin GRD_FreeResultSet(resultSet); return E_OK; } +KvDelegate::KvDelegate(const std::string &path, const std::shared_ptr &executors) + : path_(path), executors_(executors) +{ +} -KvDelegate::KvDelegate(const std::string &path) : path_(path) {} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.h b/services/distributeddataservice/service/data_share/common/kv_delegate.h index e490a249..36a91043 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.h +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.h @@ -20,12 +20,13 @@ #include #include "db_delegate.h" +#include "executor_pool.h" #include "grd_base/grd_db_api.h" namespace OHOS::DataShare { class KvDelegate final : public KvDBDelegate { public: - explicit KvDelegate(const std::string &path); + KvDelegate(const std::string &path, const std::shared_ptr &executors); ~KvDelegate() override; int32_t Upsert(const std::string &collectionName, const KvData &value) override; int32_t DeleteById(const std::string &collectionName, const Id &id) override; @@ -46,6 +47,8 @@ private: std::string path_; GRD_DB *db_ = nullptr; bool isInitDone_ = false; + std::shared_ptr executors_ = nullptr; + ExecutorPool::TaskId taskId_ = ExecutorPool::INVALID_TASK_ID; }; } // namespace OHOS::DataShare #endif // DATASHARESERVICE_KV_DELEGATE_H diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 15768fa2..54601c9b 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -357,17 +357,12 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - KvDBDelegate::GetInstance(false, saveMeta.dataDir); + KvDBDelegate::GetInstance(false, saveMeta.dataDir, binderInfo.executors); return EOK; } int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { - auto token = IPCSkeleton::GetCallingTokenID(); - auto type = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(token); - if (type != OHOS::Security::AccessToken::TOKEN_NATIVE && type != OHOS::Security::AccessToken::TOKEN_SHELL) { - return EOK; - } const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); DistributedData::StoreMetaData saveMeta; saveMeta.appType = "default"; @@ -379,13 +374,13 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use saveMeta.appId = binderInfo_.selfName; saveMeta.user = user; saveMeta.account = account; - saveMeta.tokenId = token; + saveMeta.tokenId = binderInfo_.selfTokenId; saveMeta.securityLevel = DistributedKv::SecurityLevel::S1; saveMeta.area = 1; saveMeta.uid = IPCSkeleton::GetCallingUid(); saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - KvDBDelegate::GetInstance(false, saveMeta.dataDir); + KvDBDelegate::GetInstance(true, saveMeta.dataDir, binderInfo_.executors); return EOK; } -- Gitee From 81ee8388164841a74a3b7c474cc9a6bf2d3edc7e Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 31 May 2023 17:56:42 +0800 Subject: [PATCH 151/437] f Signed-off-by: hanlu --- .../service/data_share/common/extension_connect_adaptor.cpp | 2 +- .../service/data_share/common/kv_delegate.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index a7ba14fc..44725a69 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -42,7 +42,7 @@ bool ExtensionConnectAdaptor::DoConnect(std::shared_ptr context) data_.Clear(); callback_ = new (std::nothrow) CallbackImpl(data_); if (callback_ == nullptr) { - ZLOGI("new failed"); + ZLOGE("new failed"); return false; } ZLOGI("Start connect %{public}s", context->uri.c_str()); diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index 58b75832..da61d53d 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -60,7 +60,6 @@ bool KvDelegate::Init() { if (isInitDone_) { if (executors_ != nullptr) { - ZLOGE("hanlu reset"); executors_->Reset(taskId_, std::chrono::seconds(WAIT_TIME)); } return true; @@ -77,7 +76,6 @@ bool KvDelegate::Init() GRD_DBClose(db_, GRD_DB_CLOSE); db_ = nullptr; isInitDone_ = false; - ZLOGE("hanlu Close"); taskId_ = ExecutorPool::INVALID_TASK_ID; }); } -- Gitee From e524c7e783e88eb2aa2214bcda1158127bf319ad Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 31 May 2023 18:05:37 +0800 Subject: [PATCH 152/437] f Signed-off-by: hanlu --- .../service/data_share/common/db_delegate.h | 3 ++- .../service/data_share/common/kv_delegate.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index 286e3cd1..57d4a092 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -91,7 +91,8 @@ class KvDBDelegate { public: static constexpr const char *TEMPLATE_TABLE = "template_"; static constexpr const char *DATA_TABLE = "data_"; - static std::shared_ptr GetInstance(bool reInit = false, const std::string &dir = "", const std::shared_ptr &executors = nullptr); + static std::shared_ptr GetInstance( + bool reInit = false, const std::string &dir = "", const std::shared_ptr &executors = nullptr); virtual ~KvDBDelegate() = default; virtual int32_t Upsert(const std::string &collectionName, const KvData &value) = 0; virtual int32_t DeleteById(const std::string &collectionName, const Id &id) = 0; diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index da61d53d..8e79edd1 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -231,5 +231,4 @@ KvDelegate::KvDelegate(const std::string &path, const std::shared_ptr Date: Thu, 1 Jun 2023 15:26:26 +0800 Subject: [PATCH 153/437] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=99=A8=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: srr101 --- .../service/data_share/common/scheduler_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index d694b011..cb5c2635 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -130,7 +130,7 @@ void SchedulerManager::GenRemindTimerFuncParams(const std::string &rdbDir, int v std::string &schedulerSQL) { auto index = schedulerSQL.find(REMIND_TIMER_FUNC); - if (index == -1) { + if (index == std::string::npos) { ZLOGW("not find remindTimer, sql is %{public}s", schedulerSQL.c_str()); return; } -- Gitee From 8a2d06331d5d27cfa2f0a054d51e3466848a5292 Mon Sep 17 00:00:00 2001 From: wangkai Date: Thu, 1 Jun 2023 15:55:27 +0800 Subject: [PATCH 154/437] =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkai --- .../service/cloud/cloud_service_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 9ec87a5e..26c5488c 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -449,11 +449,11 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &sub) auto enabled = cloudInfo.enableCloud && app.cloudSwitch; auto it = sub.expiresTime.find(app.bundleName); // cloud is enabled, but the subscription won't expire - if (enabled && (it != sub.expiresTime.end() && it->second >= onThreshold.count())) { + if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count()))) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. - if (!enabled && (it == sub.expiresTime.end() || it->second <= offThreshold.count())) { + if (!enabled && (it == sub.expiresTime.end() || it->second <= static_cast(offThreshold.count()))) { continue; } -- Gitee From 50776287e2fbd9e7b31e77df0bd7f8a10fa0bb71 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 1 Jun 2023 16:50:39 +0800 Subject: [PATCH 155/437] fix oh alarm Signed-off-by: Jeremyzz --- .../unittest/api/documentdb_data_test.cpp | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index 7fdb5a56..25682e07 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -118,10 +118,6 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest003, TestSize.Level0) } } -HWTEST_F(DocumentDBDataTest, UpsertDataTest004, TestSize.Level0) {} - -HWTEST_F(DocumentDBDataTest, UpsertDataTest005, TestSize.Level0) {} - /** * @tc.name: UpsertDataTest006 * @tc.desc: Test upsert data with invalid flags @@ -244,24 +240,6 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest003, TestSize.Level0) } } -/** - * @tc.name: UpdateDataTest004 - * @tc.desc: Test update data with invalid filter - * @tc.type: FUNC - * @tc.require: - * @tc.author: lianhuix - */ -HWTEST_F(DocumentDBDataTest, UpdateDataTest004, TestSize.Level0) {} - -/** - * @tc.name: UpdateDataTest005 - * @tc.desc: Test update data with invalid doc - * @tc.type: FUNC - * @tc.require: - * @tc.author: lianhuix - */ -HWTEST_F(DocumentDBDataTest, UpdateDataTest005, TestSize.Level0) {} - /** * @tc.name: UpdateDataTest006 * @tc.desc: Test update data with invalid flag -- Gitee From 48f41e98d3a13338e3dc37afcbc57ea73e0396d2 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 3 Jun 2023 15:52:01 +0800 Subject: [PATCH 156/437] f Signed-off-by: hanlu --- .../service/data_share/common/kv_delegate.cpp | 1 + .../data_share/data_share_service_impl.cpp | 37 ++++++++++--------- .../data_share/data_share_service_impl.h | 11 ++++++ .../data_share/strategies/delete_strategy.cpp | 23 ++++++------ .../data_share/strategies/delete_strategy.h | 6 ++- .../load_config_data_info_strategy.cpp | 2 - .../data_share/strategies/insert_strategy.cpp | 22 +++++------ .../data_share/strategies/insert_strategy.h | 6 ++- .../data_share/strategies/query_strategy.cpp | 22 +++++------ .../data_share/strategies/query_strategy.h | 6 ++- .../strategies/subscribe_strategy.cpp | 25 ++++++------- .../strategies/subscribe_strategy.h | 6 ++- .../data_share/strategies/update_strategy.cpp | 22 +++++------ .../data_share/strategies/update_strategy.h | 6 ++- 14 files changed, 104 insertions(+), 91 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index 8e79edd1..21faf49e 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -227,6 +227,7 @@ int32_t KvDelegate::GetBatch(const std::string &collectionName, const std::strin GRD_FreeResultSet(resultSet); return E_OK; } + KvDelegate::KvDelegate(const std::string &path, const std::shared_ptr &executors) : path_(path), executors_(executors) { diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 0b74f59b..cfae14dc 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -23,18 +23,12 @@ #include "dataobs_mgr_client.h" #include "datashare_errno.h" #include "datashare_template.h" -#include "delete_strategy.h" #include "directory/directory_manager.h" -#include "get_data_strategy.h" #include "hap_token_info.h" -#include "insert_strategy.h" #include "ipc_skeleton.h" #include "log_print.h" -#include "query_strategy.h" #include "scheduler_manager.h" -#include "subscribe_strategy.h" #include "template_manager.h" -#include "update_strategy.h" #include "utils/anonymous.h" namespace OHOS::DataShare { @@ -53,7 +47,7 @@ int32_t DataShareServiceImpl::Insert(const std::string &uri, const DataShareValu { ZLOGD("Insert enter."); auto context = std::make_shared(uri); - auto ret = InsertStrategy::Execute(context, valuesBucket); + auto ret = insertStrategy_.Execute(context, valuesBucket); if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); @@ -83,7 +77,7 @@ int32_t DataShareServiceImpl::Update(const std::string &uri, const DataSharePred { ZLOGD("Update enter."); auto context = std::make_shared(uri); - auto ret = UpdateStrategy::Execute(context, predicate, valuesBucket); + auto ret = updateStrategy_.Execute(context, predicate, valuesBucket); if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); @@ -96,7 +90,7 @@ int32_t DataShareServiceImpl::Delete(const std::string &uri, const DataSharePred { ZLOGD("Delete enter."); auto context = std::make_shared(uri); - auto ret = DeleteStrategy::Execute(context, predicate); + auto ret = deleteStrategy_.Execute(context, predicate); if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); @@ -110,7 +104,7 @@ std::shared_ptr DataShareServiceImpl::Query(const std::strin { ZLOGD("Query enter."); auto context = std::make_shared(uri); - return QueryStrategy::Execute(context, predicates, columns, errCode); + return queryStrategy_.Execute(context, predicates, columns, errCode); } int32_t DataShareServiceImpl::AddTemplate(const std::string &uri, const int64_t subscriberId, const Template &tplt) @@ -191,7 +185,7 @@ std::vector DataShareServiceImpl::SubscribeRdbData( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back( - uri, SubscribeStrategy::Execute(context, [&id, &observer, &context, this]() -> bool { + uri, subscribeStrategy_.Execute(context, [&id, &observer, &context, this]() -> bool { return RdbSubscriberManager::GetInstance().AddRdbSubscriber( context->uri, id, observer, context, binderInfo_.executors); })); @@ -205,7 +199,7 @@ std::vector DataShareServiceImpl::UnsubscribeRdbData( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &context]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { return RdbSubscriberManager::GetInstance().DelRdbSubscriber(context->uri, id, context->callerTokenId); })); } @@ -218,7 +212,7 @@ std::vector DataShareServiceImpl::EnableRdbSubs( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &context]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { return RdbSubscriberManager::GetInstance().EnableRdbSubscriber(context->uri, id, context); })); } @@ -231,7 +225,7 @@ std::vector DataShareServiceImpl::DisableRdbSubs( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, SubscribeStrategy::Execute(context, [&id, &context]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { return RdbSubscriberManager::GetInstance().DisableRdbSubscriber(context->uri, id, context->callerTokenId); })); } @@ -251,7 +245,7 @@ std::vector DataShareServiceImpl::SubscribePublishedData(const PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - result = SubscribeStrategy::Execute( + result = subscribeStrategy_.Execute( context, [&subscriberId, &observer, &callerBundleName, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().AddSubscriber( context->uri, callerBundleName, subscriberId, observer, context->callerTokenId); @@ -277,7 +271,7 @@ std::vector DataShareServiceImpl::UnsubscribePublishedData(cons context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; results.emplace_back( - uri, SubscribeStrategy::Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + uri, subscribeStrategy_.Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().DelSubscriber( context->uri, callerBundleName, subscriberId, context->callerTokenId); })); @@ -298,7 +292,7 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - result = SubscribeStrategy::Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + result = subscribeStrategy_.Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().EnableSubscriber( context->uri, callerBundleName, subscriberId, context->callerTokenId); }); @@ -323,7 +317,7 @@ std::vector DataShareServiceImpl::DisablePubSubs(const std::vec context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; results.emplace_back( - uri, SubscribeStrategy::Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + uri, subscribeStrategy_.Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().DisableSubscriber( context->uri, callerBundleName, subscriberId, context->callerTokenId); })); @@ -391,4 +385,11 @@ void DataShareServiceImpl::OnConnectDone() GetCallerBundleName(callerBundleName); AppConnectManager::Notify(callerBundleName); } + +int32_t DataShareServiceImpl::OnAppUninstall( + const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) +{ + ZLOGI("%{public}s uninstalled", bundleName.c_str()); + return EOK; +} } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 77109969..e1a9138e 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -22,8 +22,13 @@ #include "data_share_service_stub.h" #include "datashare_template.h" #include "db_delegate.h" +#include "delete_strategy.h" #include "get_data_strategy.h" +#include "insert_strategy.h" #include "publish_strategy.h" +#include "query_strategy.h" +#include "subscribe_strategy.h" +#include "update_strategy.h" #include "uri_utils.h" #include "visibility.h" @@ -60,6 +65,7 @@ public: void OnConnectDone() override; int32_t OnBind(const BindInfo &binderInfo) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; + int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; private: class Factory { @@ -74,6 +80,11 @@ private: static constexpr int32_t ERROR = -1; PublishStrategy publishStrategy_; GetDataStrategy getDataStrategy_; + SubscribeStrategy subscribeStrategy_; + DeleteStrategy deleteStrategy_; + InsertStrategy insertStrategy_; + QueryStrategy queryStrategy_; + UpdateStrategy updateStrategy_; BindInfo binderInfo_; }; } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/strategies/delete_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/delete_strategy.cpp index 1fc64494..8d0ce624 100644 --- a/services/distributeddataservice/service/data_share/strategies/delete_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/delete_strategy.cpp @@ -28,12 +28,12 @@ namespace OHOS::DataShare { int64_t DeleteStrategy::Execute(std::shared_ptr context, const DataSharePredicates &predicate) { - auto preProcess = GetStrategy(); - if (preProcess == nullptr) { + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); return -1; } - if (!(*preProcess)(context)) { + if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return -1; } @@ -44,13 +44,12 @@ int64_t DeleteStrategy::Execute(std::shared_ptr context, const DataShar } return delegate->Delete(context->calledTableName, predicate); } -Strategy *DeleteStrategy::GetStrategy() + +SeqStrategy &DeleteStrategy::GetStrategy() { - static std::mutex mutex; - static SeqStrategy strategies; - std::lock_guard lock(mutex); - if (!strategies.IsEmpty()) { - return &strategies; + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; } std::initializer_list list = { new (std::nothrow)LoadConfigCommonStrategy(), @@ -59,13 +58,13 @@ Strategy *DeleteStrategy::GetStrategy() new (std::nothrow)LoadConfigDataInfoStrategy(), new (std::nothrow)ProcessSingleAppUserCrossStrategy() }; - auto ret = strategies.Init(list); + auto ret = strategies_.Init(list); if (!ret) { std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); - return nullptr; + return strategies_; } - return &strategies; + return strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/delete_strategy.h b/services/distributeddataservice/service/data_share/strategies/delete_strategy.h index 08e98e3f..ce9b4539 100644 --- a/services/distributeddataservice/service/data_share/strategies/delete_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/delete_strategy.h @@ -24,10 +24,12 @@ namespace OHOS::DataShare { class DeleteStrategy final { public: - static int64_t Execute(std::shared_ptr context, const DataSharePredicates &predicate); + int64_t Execute(std::shared_ptr context, const DataSharePredicates &predicate); private: - static Strategy *GetStrategy(); + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index 3ca6f348..bdf75cf7 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -62,7 +62,6 @@ bool LoadConfigNormalDataInfoStrategy::operator()(std::shared_ptr conte } } context->calledSourceDir = metaData.dataDir; - context->version = static_cast(metaData.version); return true; } @@ -79,7 +78,6 @@ bool LoadConfigSingleDataInfoStrategy::operator()(std::shared_ptr conte } } context->calledSourceDir = metaData.dataDir; - context->version = static_cast(metaData.version); return true; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/insert_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/insert_strategy.cpp index 792ead9c..3684bce5 100644 --- a/services/distributeddataservice/service/data_share/strategies/insert_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/insert_strategy.cpp @@ -28,12 +28,12 @@ namespace OHOS::DataShare { int64_t InsertStrategy::Execute(std::shared_ptr context, const DataShareValuesBucket &valuesBucket) { - auto preProcess = GetStrategy(); - if (preProcess == nullptr) { + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); return -1; } - if (!(*preProcess)(context)) { + if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return -1; } @@ -45,13 +45,11 @@ int64_t InsertStrategy::Execute(std::shared_ptr context, const DataShar return delegate->Insert(context->calledTableName, valuesBucket); } -Strategy *InsertStrategy::GetStrategy() +SeqStrategy &InsertStrategy::GetStrategy() { - static std::mutex mutex; - static SeqStrategy strategies; - std::lock_guard lock(mutex); - if (!strategies.IsEmpty()) { - return &strategies; + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; } std::initializer_list list = { new (std::nothrow)LoadConfigCommonStrategy(), @@ -60,13 +58,13 @@ Strategy *InsertStrategy::GetStrategy() new (std::nothrow)LoadConfigDataInfoStrategy(), new (std::nothrow)ProcessSingleAppUserCrossStrategy() }; - auto ret = strategies.Init(list); + auto ret = strategies_.Init(list); if (!ret) { std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); - return nullptr; + return strategies_; } - return &strategies; + return strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/insert_strategy.h b/services/distributeddataservice/service/data_share/strategies/insert_strategy.h index c5472018..61705316 100644 --- a/services/distributeddataservice/service/data_share/strategies/insert_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/insert_strategy.h @@ -23,10 +23,12 @@ namespace OHOS::DataShare { class InsertStrategy final { public: - static int64_t Execute(std::shared_ptr context, const DataShareValuesBucket &valuesBucket); + int64_t Execute(std::shared_ptr context, const DataShareValuesBucket &valuesBucket); private: - static Strategy *GetStrategy(); + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp index 6e16f1a7..fc86a748 100644 --- a/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/query_strategy.cpp @@ -29,13 +29,13 @@ std::shared_ptr QueryStrategy::Execute( std::shared_ptr context, const DataSharePredicates &predicates, const std::vector &columns, int &errCode) { - auto preProcess = GetStrategy(); - if (preProcess == nullptr) { + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); return nullptr; } context->isRead = true; - if (!(*preProcess)(context)) { + if (!preProcess(context)) { errCode = context->errCode; ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return nullptr; @@ -48,13 +48,11 @@ std::shared_ptr QueryStrategy::Execute( return delegate->Query(context->calledTableName, predicates, columns, errCode); } -Strategy *QueryStrategy::GetStrategy() +SeqStrategy &QueryStrategy::GetStrategy() { - static std::mutex mutex; - static SeqStrategy strategies; - std::lock_guard lock(mutex); - if (!strategies.IsEmpty()) { - return &strategies; + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; } std::initializer_list list = { new (std::nothrow)LoadConfigCommonStrategy(), @@ -63,13 +61,13 @@ Strategy *QueryStrategy::GetStrategy() new (std::nothrow)LoadConfigDataInfoStrategy(), new (std::nothrow)ProcessSingleAppUserCrossStrategy() }; - auto ret = strategies.Init(list); + auto ret = strategies_.Init(list); if (!ret) { std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); - return nullptr; + return strategies_; } - return &strategies; + return strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/query_strategy.h b/services/distributeddataservice/service/data_share/strategies/query_strategy.h index 13b0186f..6208089f 100644 --- a/services/distributeddataservice/service/data_share/strategies/query_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/query_strategy.h @@ -24,11 +24,13 @@ namespace OHOS::DataShare { class QueryStrategy final { public: - static std::shared_ptr Execute(std::shared_ptr context, + std::shared_ptr Execute(std::shared_ptr context, const DataSharePredicates &predicates, const std::vector &columns, int &errCode); private: - static Strategy *GetStrategy(); + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp index cdad8087..eaa60490 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp @@ -26,38 +26,37 @@ namespace OHOS::DataShare { int32_t SubscribeStrategy::Execute(std::shared_ptr context, std::function process) { - auto preProcess = GetStrategy(); - if (preProcess == nullptr) { + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); return -1; } context->isRead = true; - if (!(*preProcess)(context)) { - ZLOGE("pre process fail, uri_: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); + if (!preProcess(context)) { + ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return context->errCode; } return process(); } -Strategy *SubscribeStrategy::GetStrategy() + +SeqStrategy &SubscribeStrategy::GetStrategy() { - static std::mutex mutex; - static SeqStrategy strategies; - std::lock_guard lock(mutex); - if (!strategies.IsEmpty()) { - return &strategies; + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; } std::initializer_list list = { new (std::nothrow)LoadConfigCommonStrategy(), new (std::nothrow)LoadConfigFromDataProxyNodeStrategy(), new (std::nothrow)PermissionStrategy() }; - auto ret = strategies.Init(list); + auto ret = strategies_.Init(list); if (!ret) { std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); - return nullptr; + return strategies_; } - return &strategies; + return strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h index f11c4a6d..7395b90f 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h @@ -23,10 +23,12 @@ namespace OHOS::DataShare { class SubscribeStrategy final { public: - static int32_t Execute(std::shared_ptr context, std::function process); + int32_t Execute(std::shared_ptr context, std::function process); private: - static Strategy *GetStrategy(); + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/update_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/update_strategy.cpp index 800832ac..c24cd784 100644 --- a/services/distributeddataservice/service/data_share/strategies/update_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/update_strategy.cpp @@ -28,12 +28,12 @@ namespace OHOS::DataShare { int64_t UpdateStrategy::Execute( std::shared_ptr context, const DataSharePredicates &predicate, const DataShareValuesBucket &valuesBucket) { - auto preProcess = GetStrategy(); - if (preProcess == nullptr) { + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); return -1; } - if (!(*preProcess)(context)) { + if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return -1; } @@ -45,13 +45,11 @@ int64_t UpdateStrategy::Execute( return delegate->Update(context->calledTableName, predicate, valuesBucket); } -Strategy *UpdateStrategy::GetStrategy() +SeqStrategy &UpdateStrategy::GetStrategy() { - static std::mutex mutex; - static SeqStrategy strategies; - std::lock_guard lock(mutex); - if (!strategies.IsEmpty()) { - return &strategies; + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; } std::initializer_list list = { new (std::nothrow)LoadConfigCommonStrategy(), @@ -60,13 +58,13 @@ Strategy *UpdateStrategy::GetStrategy() new (std::nothrow)LoadConfigDataInfoStrategy(), new (std::nothrow)ProcessSingleAppUserCrossStrategy() }; - auto ret = strategies.Init(list); + auto ret = strategies_.Init(list); if (!ret) { std::for_each(list.begin(), list.end(), [](Strategy *item) { delete item; }); - return nullptr; + return strategies_; } - return &strategies; + return strategies_; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/update_strategy.h b/services/distributeddataservice/service/data_share/strategies/update_strategy.h index 4ee54764..38e4116f 100644 --- a/services/distributeddataservice/service/data_share/strategies/update_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/update_strategy.h @@ -25,11 +25,13 @@ namespace OHOS::DataShare { class UpdateStrategy final { public: - static int64_t Execute(std::shared_ptr context, const DataSharePredicates &predicate, + int64_t Execute(std::shared_ptr context, const DataSharePredicates &predicate, const DataShareValuesBucket &valuesBucket); private: - static Strategy *GetStrategy(); + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; }; } // namespace OHOS::DataShare #endif -- Gitee From c4938600e35ed17bca6890101310558bc89620d6 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 3 Jun 2023 17:29:15 +0800 Subject: [PATCH 157/437] f Signed-off-by: hanlu --- .../service/data_share/data_share_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index cfae14dc..d8e284ca 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -390,6 +390,6 @@ int32_t DataShareServiceImpl::OnAppUninstall( const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) { ZLOGI("%{public}s uninstalled", bundleName.c_str()); - return EOK; + return EOK; } } // namespace OHOS::DataShare -- Gitee From cda1aa0726e38d6042af8dde032f7a325587b533 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Sat, 3 Jun 2023 14:58:47 +0800 Subject: [PATCH 158/437] refactor:sync Signed-off-by: htt1997 --- .../framework/cloud/cloud_event.cpp | 9 +- .../framework/include/cloud/cloud_event.h | 6 +- .../framework/include/error/general_error.h | 2 + .../framework/include/store/auto_cache.h | 3 +- .../framework/include/store/general_store.h | 21 +- .../framework/include/store/general_value.h | 19 +- .../framework/include/store/general_watcher.h | 29 +- .../framework/store/auto_cache.cpp | 30 +- .../service/rdb/rdb_general_store.cpp | 7 +- .../service/rdb/rdb_general_store.h | 3 +- .../service/rdb/rdb_notifier_proxy.cpp | 2 +- .../service/rdb/rdb_notifier_proxy.h | 3 +- .../service/rdb/rdb_service_impl.cpp | 319 +++++++++--------- .../service/rdb/rdb_service_impl.h | 89 +++-- .../service/rdb/rdb_service_stub.cpp | 26 +- .../service/rdb/rdb_service_stub.h | 18 - .../service/rdb/rdb_store_observer_impl.cpp | 6 +- .../service/rdb/rdb_store_observer_impl.h | 7 +- .../service/rdb/rdb_syncer.cpp | 104 +++--- .../service/rdb/rdb_syncer.h | 17 +- .../service/rdb/rdb_watcher.cpp | 37 +- .../service/rdb/rdb_watcher.h | 18 +- .../service/test/cloud_data_test.cpp | 4 +- 23 files changed, 376 insertions(+), 403 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_event.cpp b/services/distributeddataservice/framework/cloud/cloud_event.cpp index 4cc139bd..8146446d 100644 --- a/services/distributeddataservice/framework/cloud/cloud_event.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_event.cpp @@ -16,16 +16,11 @@ #include "cloud/cloud_event.h" namespace OHOS::DistributedData { -CloudEvent::CloudEvent(int32_t evtId, CloudEvent::StoreInfo storeInfo, const std::string &featureName) - : Event(evtId), featureName_(featureName), storeInfo_(storeInfo) +CloudEvent::CloudEvent(int32_t evtId, CloudEvent::StoreInfo storeInfo) + : Event(evtId), storeInfo_(std::move(storeInfo)) { } -const std::string& CloudEvent::GetFeatureName() const -{ - return featureName_; -} - const CloudEvent::StoreInfo& CloudEvent::GetStoreInfo() const { return storeInfo_; diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h index fbb09716..ae67857f 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -26,6 +26,8 @@ public: FEATURE_INIT = EVT_CLOUD, GET_SCHEMA, DATA_CHANGE, + LOCAL_CHANGE, + CLOUD_SYNC, CLOUD_BUTT }; @@ -37,13 +39,11 @@ public: int32_t user = 0; }; - CloudEvent(int32_t evtId, StoreInfo storeInfo, const std::string &featureName = "relational_store"); + CloudEvent(int32_t evtId, StoreInfo storeInfo); ~CloudEvent() = default; - const std::string& GetFeatureName() const; const StoreInfo& GetStoreInfo() const; private: - std::string featureName_; StoreInfo storeInfo_; }; } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/framework/include/error/general_error.h b/services/distributeddataservice/framework/include/error/general_error.h index 8c60a916..27ec5595 100644 --- a/services/distributeddataservice/framework/include/error/general_error.h +++ b/services/distributeddataservice/framework/include/error/general_error.h @@ -25,6 +25,8 @@ enum GeneralError : int32_t { E_NOT_SUPPORT, E_ALREADY_CONSUMED, E_ALREADY_CLOSED, + E_UNOPENED, + E_RETRY_TIMEOUT, E_BUTT, }; } diff --git a/services/distributeddataservice/framework/include/store/auto_cache.h b/services/distributeddataservice/framework/include/store/auto_cache.h index ca1a5e80..b5e91e68 100644 --- a/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/services/distributeddataservice/framework/include/store/auto_cache.h @@ -64,8 +64,7 @@ private: bool Close(); int32_t GetUser() const; void SetObservers(const Watchers &watchers); - int32_t OnChange(Origin origin, const std::string &id) override; - int32_t OnChange(Origin origin, const std::string &id, const std::vector &values) override; + int32_t OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) override; private: mutable Time time_; diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 579634d2..ad7985ea 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -18,7 +18,6 @@ #include #include -#include "cloud/schema_meta.h" #include "store/cursor.h" #include "store/general_value.h" #include "store/general_watcher.h" @@ -29,9 +28,21 @@ struct Database; class GeneralStore { public: using Watcher = GeneralWatcher; - using AsyncDetail = std::function; - using AsyncStatus = std::function>)>; + using DetailAsync = GenAsync; using Devices = std::vector; + enum SyncMode { + NEARBY_BEGIN, + NEARBY_PUSH = NEARBY_BEGIN, + NEARBY_PULL, + NEARBY_PULL_PUSH, + NEARBY_END, + CLOUD_BEGIN = NEARBY_END, + CLOUD_TIME_FIRST = CLOUD_BEGIN, + CLOUD_NATIVE_FIRST, + CLOUD_ClOUD_FIRST, + CLOUD_END, + MODE_BUTT = CLOUD_END, + }; struct BindInfo { BindInfo(std::shared_ptr db = nullptr, std::shared_ptr loader = nullptr) @@ -57,9 +68,7 @@ public: virtual std::shared_ptr Query(const std::string &table, GenQuery &query) = 0; - virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncDetail async, int32_t wait) = 0; - - virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncStatus async, int32_t wait) = 0; + virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) = 0; virtual int32_t Watch(int32_t origin, Watcher &watcher) = 0; diff --git a/services/distributeddataservice/framework/include/store/general_value.h b/services/distributeddataservice/framework/include/store/general_value.h index 9ec68794..18df10a1 100644 --- a/services/distributeddataservice/framework/include/store/general_value.h +++ b/services/distributeddataservice/framework/include/store/general_value.h @@ -15,6 +15,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_VALUE_H #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_VALUE_H +#include #include #include #include @@ -24,28 +25,28 @@ #include "error/general_error.h" #include "traits.h" namespace OHOS::DistributedData { -enum Progress { +enum GenProgress { SYNC_BEGIN, SYNC_IN_PROGRESS, SYNC_FINISH, }; -struct Statistic { +struct GenStatistic { int32_t total; int32_t success; int32_t failed; int32_t untreated; }; -struct TableDetails { - Statistic upload; - Statistic download; +struct GenTableDetail { + GenStatistic upload; + GenStatistic download; }; -struct ProgressDetails { +struct GenProgressDetail { int32_t progress; int32_t code; - std::map details; + std::map details; }; struct Asset { @@ -61,6 +62,7 @@ struct Asset { struct GenQuery { virtual ~GenQuery() = default; virtual bool IsEqual(uint64_t tid) = 0; + virtual std::vector GetTables() = 0; template int32_t QueryInterface(T *&query) @@ -79,7 +81,8 @@ using Value = std::variant; using VBucket = std::map; using VBuckets = std::vector; - +using GenDetails = std::map; +using GenAsync = std::function; template inline constexpr size_t TYPE_INDEX = Traits::variant_index_of_v; diff --git a/services/distributeddataservice/framework/include/store/general_watcher.h b/services/distributeddataservice/framework/include/store/general_watcher.h index 52130eab..4583aa9d 100644 --- a/services/distributeddataservice/framework/include/store/general_watcher.h +++ b/services/distributeddataservice/framework/include/store/general_watcher.h @@ -21,24 +21,33 @@ namespace OHOS::DistributedData { class GeneralWatcher { public: - enum Origin : int32_t { - ORIGIN_CLOUD, - ORIGIN_LOCAL, - ORIGIN_REMOTE, - ORIGIN_ALL, - ORIGIN_BUTT, + struct Origin { + enum OriginType : int32_t { + ORIGIN_LOCAL, + ORIGIN_NEARBY, + ORIGIN_CLOUD, + ORIGIN_ALL, + ORIGIN_BUTT, + }; + int32_t origin = ORIGIN_BUTT; + // origin is ORIGIN_LOCAL, the id is empty + // origin is ORIGIN_NEARBY, the id is networkId; + // origin is ORIGIN_CLOUD, the id is the cloud account id + std::vector id; + std::string store; }; - enum ChangeOp : int32_t { OP_INSERT, OP_UPDATE, OP_DELETE, OP_BUTT, }; - + // PK primary key + using PRIValue = std::variant; + using PRIFields = std::map; + using ChangeInfo = std::map[OP_BUTT]>; virtual ~GeneralWatcher() = default; - virtual int32_t OnChange(Origin origin, const std::string &id) = 0; - virtual int32_t OnChange(Origin origin, const std::string &id, const std::vector &values) = 0; + virtual int32_t OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) = 0; }; } #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_WATCHER_H diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index 8b44d688..ec9dea51 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -147,14 +147,14 @@ AutoCache::Delegate::Delegate(GeneralStore *delegate, const Watchers &watchers, { time_ = std::chrono::steady_clock::now() + std::chrono::minutes(INTERVAL); if (store_ != nullptr) { - store_->Watch(ORIGIN_ALL, *this); + store_->Watch(Origin::ORIGIN_ALL, *this); } } AutoCache::Delegate::~Delegate() { if (store_ != nullptr) { - store_->Unwatch(ORIGIN_ALL, *this); + store_->Unwatch(Origin::ORIGIN_ALL, *this); store_->Close(); store_ = nullptr; } @@ -175,7 +175,7 @@ bool AutoCache::Delegate::Close() { std::unique_lock lock(mutex_); if (store_ != nullptr) { - store_->Unwatch(ORIGIN_ALL, *this); + store_->Unwatch(Origin::ORIGIN_ALL, *this); auto status = store_->Close(); if (status == Error::E_BUSY) { return false; @@ -196,34 +196,20 @@ int32_t AutoCache::Delegate::GetUser() const return user_; } -int32_t AutoCache::Delegate::OnChange(Origin origin, const std::string &id) +int32_t AutoCache::Delegate::OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) { Watchers watchers; { std::unique_lock lock(mutex_); watchers = watchers_; } - for (auto watcher : watchers) { + size_t remain = watchers.size(); + for (auto &watcher : watchers) { + remain--; if (watcher == nullptr) { continue; } - watcher->OnChange(origin, id); - } - return Error::E_OK; -} - -int32_t AutoCache::Delegate::OnChange(Origin origin, const std::string &id, const std::vector &values) -{ - Watchers watchers; - { - std::unique_lock lock(mutex_); - watchers = watchers_; - } - for (auto watcher : watchers) { - if (watcher == nullptr) { - continue; - } - watcher->OnChange(origin, id, values); + watcher->OnChange(origin, primaryFields, (remain != 0) ? ChangeInfo(values) : std::move(values)); } return Error::E_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 8ccc8d1d..91d58fbb 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -148,12 +148,7 @@ std::shared_ptr RdbGeneralStore::Query(const std::string &table, GenQuer return std::shared_ptr(); } -int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncDetail async, int32_t wait) -{ - return GeneralError::E_NOT_SUPPORT; -} - -int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncStatus async, int32_t wait) +int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) { return GeneralError::E_NOT_SUPPORT; } diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index f337fe56..30972e02 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -46,8 +46,7 @@ public: int32_t Delete(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, GenQuery &query) override; - int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncDetail async, int32_t wait) override; - int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, AsyncStatus async, int32_t wait) override; + int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; int32_t Close() override; diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index 8818a092..97ba6bea 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -27,7 +27,7 @@ RdbNotifierProxy::~RdbNotifierProxy() noexcept ZLOGI("destroy"); } -int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, const SyncResult &result) +int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, Details &&result) { MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h index 375cc745..d0d9c1cb 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h @@ -29,10 +29,9 @@ public: explicit RdbNotifierProxy(const sptr& object); virtual ~RdbNotifierProxy() noexcept; - int32_t OnComplete(uint32_t seqNum, const SyncResult& result) override; + int32_t OnComplete(uint32_t seqNum, Details &&result) override; int32_t OnChange(const std::string& storeName, const std::vector& devices) override; - private: static inline BrokerDelegator delegator_; }; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 24b656da..bf35f9ad 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -27,7 +27,6 @@ #include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" -#include "permission/permission_validator.h" #include "rdb_watcher.h" #include "rdb_notifier_proxy.h" #include "rdb_query.h" @@ -68,25 +67,6 @@ RdbServiceImpl::Factory::~Factory() { } -RdbServiceImpl::DeathRecipientImpl::DeathRecipientImpl(const DeathCallback& callback) - : callback_(callback) -{ - ZLOGI("construct"); -} - -RdbServiceImpl::DeathRecipientImpl::~DeathRecipientImpl() -{ - ZLOGI("destroy"); -} - -void RdbServiceImpl::DeathRecipientImpl::OnRemoteDied(const wptr &object) -{ - ZLOGI("enter"); - if (callback_) { - callback_(); - } -} - RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) { ZLOGI("construct"); @@ -94,7 +74,7 @@ RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) [this](const std::string& identifier, DistributedDB::AutoLaunchParam ¶m) { return ResolveAutoLaunch(identifier, param); }); - EventCenter::GetInstance().Subscribe(CloudEvent::DATA_CHANGE, [this](const Event &event) { + auto process = [this](const Event &event) { auto &evt = static_cast(event); auto storeInfo = evt.GetStoreInfo(); StoreMetaData meta; @@ -104,20 +84,18 @@ RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) meta.instanceId = storeInfo.instanceId; meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; if (!MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)) { - ZLOGE("meta empty, bundleName:%{public}s, storeId:%{public}s", - meta.bundleName.c_str(), meta.storeId.c_str()); + ZLOGE("meta empty, bundleName:%{public}s, storeId:%{public}s", meta.bundleName.c_str(), + Anonymous::Change(meta.storeId).c_str()); return; } auto watchers = GetWatchers(meta.tokenId, meta.storeId); auto store = AutoCache::GetInstance().GetStore(meta, watchers); if (store == nullptr) { - ZLOGE("store null, storeId:%{public}s", meta.storeId.c_str()); + ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); return; } - for (const auto &watcher : watchers) { // mock for datachange - watcher->OnChange(GeneralWatcher::Origin::ORIGIN_CLOUD, {}); - } - }); + }; + EventCenter::GetInstance().Subscribe(CloudEvent::CLOUD_SYNC, process); } int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) @@ -161,6 +139,12 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib return false; } +int32_t RdbServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) +{ + OnClientDied(pid); + return E_OK; +} + void RdbServiceImpl::OnClientDied(pid_t pid) { ZLOGI("client dead pid=%{public}d", pid); @@ -171,10 +155,10 @@ void RdbServiceImpl::OnClientDied(pid_t pid) } return false; }); - notifiers_.Erase(pid); - identifiers_.EraseIf([pid](const auto& key, pid_t& value) { - return pid == value; + identifiers_.EraseIf([pid](const auto &key, std::pair &value) { + return value.first == pid; }); + syncAgents_.EraseIf([pid](auto &key, SyncAgent &agent) { return agent.pid_ == pid; }); } bool RdbServiceImpl::CheckAccess(const std::string& bundleName, const std::string& storeName) @@ -184,7 +168,7 @@ bool RdbServiceImpl::CheckAccess(const std::string& bundleName, const std::strin storeInfo.tokenId = IPCSkeleton::GetCallingTokenID(); storeInfo.bundleName = bundleName; storeInfo.storeId = RdbSyncer::RemoveSuffix(storeName); - auto instanceId = RdbSyncer::GetInstIndex(storeInfo.tokenId, storeInfo.bundleName); + auto [instanceId, user] = RdbSyncer::GetInstIndexAndUser(storeInfo.tokenId, storeInfo.bundleName); if (instanceId != 0) { return false; } @@ -212,26 +196,23 @@ int32_t RdbServiceImpl::InitNotifier(const RdbSyncerParam ¶m, const sptr(notifier); pid_t pid = IPCSkeleton::GetCallingPid(); - auto recipient = new (std::nothrow) DeathRecipientImpl([this, pid] { - OnClientDied(pid); + uint32_t tokenId = IPCSkeleton::GetCallingTokenID(); + syncAgents_.Compute(tokenId, [¶m, notifierProxy, pid](auto, SyncAgent &agent) { + if (pid != agent.pid_) { + agent.ReInit(pid, param.bundleName_); + } + agent.SetNotifier(notifierProxy); + return true; }); - if (recipient == nullptr) { - ZLOGE("malloc recipient failed"); - return RDB_ERROR; - } - - if (!notifier->AddDeathRecipient(recipient)) { - ZLOGE("link to death failed"); - return RDB_ERROR; - } - notifiers_.Insert(pid, iface_cast(notifier)); - ZLOGI("success pid=%{public}d", pid); + ZLOGI("success tokenId:%{public}x, pid=%{public}d", tokenId, pid); return RDB_OK; } -void RdbServiceImpl::OnDataChange(pid_t pid, const DistributedDB::StoreChangedData &data) +void RdbServiceImpl::OnDataChange(pid_t pid, uint32_t tokenId, const DistributedDB::StoreChangedData &data) { DistributedDB::StoreProperty property; data.GetStoreProperty(property); @@ -239,20 +220,21 @@ void RdbServiceImpl::OnDataChange(pid_t pid, const DistributedDB::StoreChangedDa if (pid == 0) { auto identifier = RelationalStoreManager::GetRelationalStoreIdentifier(property.userId, property.appId, property.storeId); - auto pair = identifiers_.Find(TransferStringToHex(identifier)); - if (!pair.first) { + auto [success, info] = identifiers_.Find(TransferStringToHex(identifier)); + if (!success) { ZLOGI("client doesn't subscribe"); return; } - pid = pair.second; - ZLOGI("fixed pid=%{public}d", pid); + pid = info.first; + tokenId = info.second; + ZLOGI("fixed pid=%{public}d and tokenId=0x%{public}d", pid, tokenId); } - notifiers_.ComputeIfPresent(pid, [&data, &property] (const auto& key, const sptr& value) { + auto [success, agent] = syncAgents_.Find(tokenId); + if (success && agent.notifier_ != nullptr && pid == agent.pid_) { std::string device = data.GetDataChangeDevice(); auto networkId = DmAdapter::GetInstance().ToNetworkID(device); - value->OnChange(property.storeId, { networkId }); - return true; - }); + agent.notifier_->OnChange(property.storeId, { networkId }); + } } void RdbServiceImpl::SyncerTimeout(std::shared_ptr syncer) @@ -260,9 +242,10 @@ void RdbServiceImpl::SyncerTimeout(std::shared_ptr syncer) if (syncer == nullptr) { return; } - ZLOGI("%{public}s", syncer->GetStoreId().c_str()); - syncers_.ComputeIfPresent(syncer->GetPid(), [this, &syncer](const auto& key, StoreSyncersType& syncers) { - syncers.erase(syncer->GetStoreId()); + auto storeId = syncer->GetStoreId(); + ZLOGI("%{public}s", storeId.c_str()); + syncers_.ComputeIfPresent(syncer->GetPid(), [this, storeId](const auto& key, StoreSyncersType& syncers) { + syncers.erase(storeId); syncerNum_--; return true; }); @@ -293,7 +276,7 @@ std::shared_ptr RdbServiceImpl::GetRdbSyncer(const RdbSyncerParam &pa ZLOGE("pid: %{public}d, syncers size: %{public}zu. syncerNum: %{public}d", pid, syncers.size(), syncerNum_); return !syncers.empty(); } - auto rdbObserver = new (std::nothrow) RdbStoreObserverImpl(this, pid); + auto rdbObserver = new (std::nothrow) RdbStoreObserverImpl(this, pid, tokenId); if (rdbObserver == nullptr) { return !syncers.empty(); } @@ -314,14 +297,15 @@ std::shared_ptr RdbServiceImpl::GetRdbSyncer(const RdbSyncerParam &pa }); if (syncer != nullptr) { - identifiers_.Insert(syncer->GetIdentifier(), pid); + identifiers_.Insert(syncer->GetIdentifier(), { pid, tokenId }); } else { ZLOGE("syncer is nullptr"); } return syncer; } -int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const std::vector &tables) +int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const std::vector &tables, + int32_t type) { ZLOGI("enter"); if (!CheckAccess(param.bundleName_, param.storeName_)) { @@ -332,47 +316,48 @@ int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const if (syncer == nullptr) { return RDB_ERROR; } - return syncer->SetDistributedTables(tables); + return syncer->SetDistributedTables(tables, type); } -int32_t RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, const SyncOption &option, - const RdbPredicates &predicates, SyncResult &result) +std::pair RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, const Option &option, + const RdbPredicates &pred) { if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); - return RDB_ERROR; + return {RDB_ERROR, {}}; } auto syncer = GetRdbSyncer(param); if (syncer == nullptr) { - return RDB_ERROR; + return {RDB_ERROR, {}}; } - return syncer->DoSync(option, predicates, result); + Details details = {}; + auto status = syncer->DoSync(option, pred, [&details](auto &&result) mutable { details = std::move(result); }); + return { status, std::move(details) }; } -void RdbServiceImpl::OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResult &result) +void RdbServiceImpl::OnAsyncComplete(uint32_t tokenId, uint32_t seqNum, Details &&result) { - ZLOGI("pid=%{public}d seqnum=%{public}u", pid, seqNum); - notifiers_.ComputeIfPresent(pid, [seqNum, &result] (const auto& key, const sptr& value) { - value->OnComplete(seqNum, result); - return true; - }); + ZLOGI("pid=%{public}x seqnum=%{public}u", tokenId, seqNum); + auto [success, agent] = syncAgents_.Find(tokenId); + if (success && agent.notifier_ != nullptr) { + agent.notifier_->OnComplete(seqNum, std::move(result)); + } } -int32_t RdbServiceImpl::DoAsync(const RdbSyncerParam ¶m, uint32_t seqNum, const SyncOption &option, - const RdbPredicates &predicates) +int32_t RdbServiceImpl::DoAsync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &pred) { if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } - pid_t pid = IPCSkeleton::GetCallingPid(); - ZLOGI("seq num=%{public}u", seqNum); + auto tokenId = IPCSkeleton::GetCallingTokenID(); + ZLOGI("seq num=%{public}u", option.seqNum); auto syncer = GetRdbSyncer(param); if (syncer == nullptr) { return RDB_ERROR; } - return syncer->DoAsync(option, predicates, [this, pid, seqNum](const SyncResult &result) { - OnAsyncComplete(pid, seqNum, result); + return syncer->DoSync(option, pred, [this, tokenId, seqNum = option.seqNum](Details &&result) { + OnAsyncComplete(tokenId, seqNum, std::move(result)); }); } @@ -404,30 +389,91 @@ std::string RdbServiceImpl::GenIdentifier(const RdbSyncerParam ¶m) return TransferStringToHex(identifier); } -int32_t RdbServiceImpl::DoSubscribe(const RdbSyncerParam& param, const SubscribeOption &option) +AutoCache::Watchers RdbServiceImpl::GetWatchers(uint32_t tokenId, const std::string &storeName) +{ + auto [success, agent] = syncAgents_.Find(tokenId); + if (agent.watcher_ == nullptr) { + return {}; + } + return { agent.watcher_ }; +} + +void RdbServiceImpl::SyncAgent::ReInit(pid_t pid, const std::string &bundleName) +{ + pid_ = pid; + count_ = 0; + bundleName_ = bundleName; + notifier_ = nullptr; + if (watcher_ != nullptr) { + watcher_->SetNotifier(nullptr); + } +} + +void RdbServiceImpl::SyncAgent::SetNotifier(sptr notifier) +{ + notifier_ = notifier; + if (watcher_ != nullptr) { + watcher_->SetNotifier(notifier); + } +} + +void RdbServiceImpl::SyncAgent::SetWatcher(std::shared_ptr watcher) +{ + if (watcher_ != watcher) { + watcher_ = watcher; + watcher_->SetNotifier(notifier_); + } +} + +int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, + const std::vector& selectionArgs, sptr& resultSet) +{ + if (!CheckAccess(param.bundleName_, param.storeName_)) { + ZLOGE("permission error"); + return RDB_ERROR; + } + auto syncer = GetRdbSyncer(param); + if (syncer == nullptr) { + ZLOGE("syncer is null"); + return RDB_ERROR; + } + return syncer->RemoteQuery(device, sql, selectionArgs, resultSet); +} + +int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &predicates, + const AsyncDetail &async) +{ + if (!option.isAsync) { + auto [status, details] = DoSync(param, option, predicates); + async(std::move(details)); + return status; + } + return DoAsync(param, option, predicates); +} + +int32_t RdbServiceImpl::Subscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, + RdbStoreObserver *observer) { pid_t pid = IPCSkeleton::GetCallingPid(); auto tokenId = IPCSkeleton::GetCallingTokenID(); switch (option.mode) { case SubscribeMode::REMOTE: { auto identifier = GenIdentifier(param); - ZLOGI("%{public}s %{public}.6s %{public}d", param.storeName_.c_str(), identifier.c_str(), pid); - identifiers_.Insert(identifier, pid); + identifiers_.Insert(identifier, std::pair { pid, tokenId }); + ZLOGI("%{public}s %{public}.6s %{public}d", Anonymous::Change(param.storeName_).c_str(), + identifier.c_str(), pid); break; } case SubscribeMode::CLOUD: // fallthrough case SubscribeMode::CLOUD_DETAIL: { - syncAgents_.Compute(tokenId, [this, pid, tokenId, ¶m, &option](auto &key, SyncAgent &value) { - if (pid != value.pid_) { - value.ReInit(pid, param.bundleName_); + syncAgents_.Compute(tokenId, [pid, ¶m](auto &key, SyncAgent &agent) { + if (pid != agent.pid_) { + agent.ReInit(pid, param.bundleName_); } - auto storeName = RdbSyncer::RemoveSuffix(param.storeName_); - auto it = value.watchers_.find(storeName); - if (it == value.watchers_.end()) { - auto watcher = std::make_shared(this, tokenId, storeName); - value.watchers_[storeName] = { watcher }; - value.mode_[storeName] = option.mode; + if (agent.watcher_ == nullptr) { + agent.SetWatcher(std::make_shared()); } + agent.count_++; return true; }); break; @@ -438,63 +484,24 @@ int32_t RdbServiceImpl::DoSubscribe(const RdbSyncerParam& param, const Subscribe return RDB_OK; } -void RdbServiceImpl::OnChange(uint32_t tokenId, const std::string &storeName) -{ - pid_t pid = 0; - syncAgents_.ComputeIfPresent(tokenId, [&pid, &storeName](auto &key, SyncAgent &value) { - pid = value.pid_; - return true; - }); - notifiers_.ComputeIfPresent(pid, [&storeName](const auto& key, const sptr& value) { - value->OnChange(storeName, { storeName }); - return true; - }); -} - -AutoCache::Watchers RdbServiceImpl::GetWatchers(uint32_t tokenId, const std::string &storeName) -{ - AutoCache::Watchers watchers; - syncAgents_.ComputeIfPresent(tokenId, [&storeName, &watchers](auto, SyncAgent &agent) { - auto it = agent.watchers_.find(storeName); - if (it != agent.watchers_.end()) { - watchers = it->second; - } - return true; - }); - return watchers; -} - -void RdbServiceImpl::SyncAgent::ReInit(pid_t pid, const std::string &bundleName) -{ - pid_ = pid; - bundleName_ = bundleName; - watchers_.clear(); - mode_.clear(); -} - -int32_t RdbServiceImpl::DoUnSubscribe(const RdbSyncerParam& param) +int32_t RdbServiceImpl::UnSubscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, + RdbStoreObserver *observer) { auto identifier = GenIdentifier(param); ZLOGI("%{public}s %{public}.6s", param.storeName_.c_str(), identifier.c_str()); identifiers_.Erase(identifier); + syncAgents_.ComputeIfPresent(IPCSkeleton::GetCallingTokenID(), [](auto &key, SyncAgent &agent) { + if (agent.count_ > 0) { + agent.count_--; + } + if (agent.count_ == 0) { + agent.SetWatcher(nullptr); + } + return true; + }); return RDB_OK; } -int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, - const std::vector& selectionArgs, sptr& resultSet) -{ - if (!CheckAccess(param.bundleName_, param.storeName_)) { - ZLOGE("permission error"); - return RDB_ERROR; - } - auto syncer = GetRdbSyncer(param); - if (syncer == nullptr) { - ZLOGE("syncer is null"); - return RDB_ERROR; - } - return syncer->RemoteQuery(device, sql, selectionArgs, resultSet); -} - int32_t RdbServiceImpl::OnInitialize() { return RDB_OK; @@ -512,16 +519,19 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) } if (executors_ != nullptr) { - CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, - RdbSyncer::RemoveSuffix(param.storeName_), - RdbSyncer::GetInstIndex(IPCSkeleton::GetCallingTokenID(), param.bundleName_) }; + CloudEvent::StoreInfo storeInfo; + storeInfo.tokenId = IPCSkeleton::GetCallingTokenID(); + storeInfo.bundleName = param.bundleName_; + storeInfo.storeName = RdbSyncer::RemoveSuffix(param.storeName_); + auto [instanceId, user]= RdbSyncer::GetInstIndexAndUser(storeInfo.tokenId, param.bundleName_); + storeInfo.instanceId = instanceId; + storeInfo.user = user; executors_->Execute([storeInfo]() { - auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), - "relational_store"); + auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo)); EventCenter::GetInstance().PostEvent(move(event)); + return; }); } - return RDB_OK; } @@ -530,11 +540,12 @@ StoreMetaData RdbServiceImpl::GetStoreMetaData(const RdbSyncerParam ¶m) StoreMetaData metaData; metaData.uid = IPCSkeleton::GetCallingUid(); metaData.tokenId = IPCSkeleton::GetCallingTokenID(); - metaData.instanceId = RdbSyncer::GetInstIndex(metaData.tokenId, param.bundleName_); + auto [instanceId, user] = RdbSyncer::GetInstIndexAndUser(metaData.tokenId, param.bundleName_); + metaData.instanceId = instanceId; metaData.bundleName = param.bundleName_; metaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; metaData.storeId = RdbSyncer::RemoveSuffix(param.storeName_); - metaData.user = std::to_string(AccountDelegate::GetInstance()->GetUserByToken(metaData.tokenId)); + metaData.user = std::to_string(user); metaData.storeType = param.type_; metaData.securityLevel = param.level_; metaData.area = param.area_; @@ -555,16 +566,16 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat old.area != meta.area)) { ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, - meta.isEncrypt, old.area, meta.area); + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + old.isEncrypt, meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } if (!isCreated || meta != old) { Upgrade(param, old); ZLOGD("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, - meta.isEncrypt, old.area, meta.area); + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + old.isEncrypt, meta.isEncrypt, old.area, meta.area); MetaDataManager::GetInstance().SaveMeta(meta.GetKey(), meta); } AppIDMetaData appIdMeta; @@ -573,8 +584,8 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat if (!MetaDataManager::GetInstance().SaveMeta(appIdMeta.GetKey(), appIdMeta, true)) { ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), meta.storeId.c_str(), old.storeType, meta.storeType, old.isEncrypt, - meta.isEncrypt, old.area, meta.area); + meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + old.isEncrypt, meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } if (!param.isEncrypt_ || param.password_.empty()) { diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 01831def..a217cecb 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -26,8 +26,9 @@ #include "metadata/store_meta_data.h" #include "rdb_notifier_proxy.h" #include "rdb_syncer.h" -#include "store_observer.h" +#include "rdb_watcher.h" #include "store/auto_cache.h" +#include "store_observer.h" #include "visibility.h" namespace OHOS::DistributedRdb { class API_EXPORT RdbServiceImpl : public RdbServiceStub { @@ -41,45 +42,63 @@ public: /* IPC interface */ std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; - int32_t InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) override; + int32_t InitNotifier(const RdbSyncerParam ¶m, sptr notifier) override; - int32_t SetDistributedTables(const RdbSyncerParam& param, const std::vector& tables) override; + int32_t SetDistributedTables(const RdbSyncerParam ¶m, const std::vector &tables, + int32_t type = DISTRIBUTED_DEVICE) override; int32_t RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet) override; - void OnDataChange(pid_t pid, const DistributedDB::StoreChangedData& data); + int32_t Sync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &predicates, + const AsyncDetail &async) override; + + int32_t Subscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, RdbStoreObserver *observer) override; - void OnChange(uint32_t tokenId, const std::string &storeName); + int32_t UnSubscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, + RdbStoreObserver *observer) override; + + void OnDataChange(pid_t pid, uint32_t tokenId, const DistributedDB::StoreChangedData& data); int32_t ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) override; int32_t OnInitialize() override; + int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; + int32_t GetSchema(const RdbSyncerParam ¶m) override; int32_t OnBind(const BindInfo &bindInfo) override; -protected: - int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, - const RdbPredicates& predicates, SyncResult& result) override; - - int32_t DoAsync(const RdbSyncerParam& param, uint32_t seqNum, const SyncOption& option, - const RdbPredicates& predicates) override; - - int32_t DoSubscribe(const RdbSyncerParam& param, const SubscribeOption &option) override; - - int32_t DoUnSubscribe(const RdbSyncerParam& param) override; - private: using Watchers = DistributedData::AutoCache::Watchers; struct SyncAgent { pid_t pid_ = 0; + int32_t count_ = 0; std::string bundleName_; - std::map mode_; - std::map watchers_; + sptr notifier_ = nullptr; + std::shared_ptr watcher_ = nullptr; void ReInit(pid_t pid, const std::string &bundleName); + void SetNotifier(sptr notifier); + void SetWatcher(std::shared_ptr watcher); + }; + + class Factory { + public: + Factory(); + ~Factory(); + private: + std::shared_ptr product_; }; + using StoreSyncersType = std::map>; + + static constexpr int32_t MAX_SYNCER_NUM = 50; + static constexpr int32_t MAX_SYNCER_PER_PROCESS = 10; + static constexpr int32_t SYNCER_TIMEOUT = 60 * 1000; // ms + + std::pair DoSync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &pred); + + int32_t DoAsync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &pred); Watchers GetWatchers(uint32_t tokenId, const std::string &storeName); @@ -91,7 +110,7 @@ private: std::shared_ptr GetRdbSyncer(const RdbSyncerParam& param); - void OnAsyncComplete(pid_t pid, uint32_t seqNum, const SyncResult& result); + void OnAsyncComplete(uint32_t tokenId, uint32_t seqNum, Details&& result); int32_t CreateMetaData(const RdbSyncerParam ¶m, StoreMetaData &old); @@ -101,39 +120,15 @@ private: int32_t Upgrade(const RdbSyncerParam ¶m, const StoreMetaData &old); - class DeathRecipientImpl : public IRemoteObject::DeathRecipient { - public: - using DeathCallback = std::function; - explicit DeathRecipientImpl(const DeathCallback& callback); - ~DeathRecipientImpl() override; - void OnRemoteDied(const wptr &object) override; - private: - const DeathCallback callback_; - }; - class Factory { - public: - Factory(); - ~Factory(); - private: - std::shared_ptr product_; - }; + static std::string TransferStringToHex(const std::string& origStr); - using StoreSyncersType = std::map>; + static Factory factory_; int32_t syncerNum_ {}; ConcurrentMap syncers_; - ConcurrentMap> notifiers_; - ConcurrentMap identifiers_; + ConcurrentMap> identifiers_; + ConcurrentMap syncAgents_; RdbStoreObserverImpl autoLaunchObserver_; - - static Factory factory_; - - static std::string TransferStringToHex(const std::string& origStr); - - static constexpr int32_t MAX_SYNCER_NUM = 50; - static constexpr int32_t MAX_SYNCER_PER_PROCESS = 10; - static constexpr int32_t SYNCER_TIMEOUT = 60 * 1000; // ms std::shared_ptr executors_; - ConcurrentMap syncAgents_; }; } // namespace OHOS::DistributedRdb #endif diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 034e9822..87ec6b42 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -94,16 +94,16 @@ int32_t RdbServiceStub::OnRemoteSetDistributedTables(MessageParcel &data, Messag int32_t RdbServiceStub::OnRemoteDoSync(MessageParcel &data, MessageParcel &reply) { RdbSyncerParam param; - SyncOption option {}; + Option option {}; RdbPredicates predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str(), predicates.table_.c_str()); + ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables:%{public}zu", param.bundleName_.c_str(), + param.storeName_.c_str(), predicates.tables_.size()); return IPC_STUB_INVALID_DATA_ERR; } - SyncResult result; - auto status = DoSync(param, option, predicates, result); + Details result = {}; + auto status = Sync(param, option, predicates, [&result](Details &&details) { result = std::move(details); }); if (!ITypesUtil::Marshal(reply, status, result)) { ZLOGE("Marshal status:0x%{public}x result size:%{public}zu", status, result.size()); return IPC_STUB_WRITE_PARCEL_ERR; @@ -114,16 +114,15 @@ int32_t RdbServiceStub::OnRemoteDoSync(MessageParcel &data, MessageParcel &reply int32_t RdbServiceStub::OnRemoteDoAsync(MessageParcel &data, MessageParcel &reply) { RdbSyncerParam param; - uint32_t seqNum; - SyncOption option {}; + Option option {}; RdbPredicates predicates; - if (!ITypesUtil::Unmarshal(data, param, seqNum, option, predicates)) { + if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s seqNum:%{public}u tables:%{public}s", - param.bundleName_.c_str(), param.storeName_.c_str(), seqNum, predicates.table_.c_str()); + param.bundleName_.c_str(), param.storeName_.c_str(), option.seqNum, + (*(predicates.tables_.begin())).c_str()); return IPC_STUB_INVALID_DATA_ERR; } - - auto status = DoAsync(param, seqNum, option, predicates); + auto status = Sync(param, option, predicates, nullptr); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -141,7 +140,7 @@ int32_t RdbServiceStub::OnRemoteDoSubscribe(MessageParcel &data, MessageParcel & return IPC_STUB_INVALID_DATA_ERR; } - auto status = DoSubscribe(param, option); + auto status = Subscribe(param, option, nullptr); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -152,13 +151,14 @@ int32_t RdbServiceStub::OnRemoteDoSubscribe(MessageParcel &data, MessageParcel & int32_t RdbServiceStub::OnRemoteDoUnSubscribe(MessageParcel &data, MessageParcel &reply) { RdbSyncerParam param; + SubscribeOption option; if (!ITypesUtil::Unmarshal(data, param)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), param.storeName_.c_str()); return IPC_STUB_INVALID_DATA_ERR; } - auto status = DoUnSubscribe(param); + auto status = UnSubscribe(param, option, nullptr); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.h b/services/distributeddataservice/service/rdb/rdb_service_stub.h index 04c57e57..b67c3e5b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.h +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.h @@ -27,24 +27,6 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbService"); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override; - int32_t Sync(const RdbSyncerParam& param, const SyncOption& option, - const RdbPredicates& predicates, const SyncCallback& callback) override - { - return 0; - } - - int32_t Subscribe(const RdbSyncerParam& param, const SubscribeOption& option, - RdbStoreObserver *observer) override - { - return 0; - } - - int32_t UnSubscribe(const RdbSyncerParam& param, const SubscribeOption& option, - RdbStoreObserver *observer) override - { - return 0; - } - private: static bool CheckInterfaceToken(MessageParcel& data); diff --git a/services/distributeddataservice/service/rdb/rdb_store_observer_impl.cpp b/services/distributeddataservice/service/rdb/rdb_store_observer_impl.cpp index 036eedb8..e9e7ec53 100644 --- a/services/distributeddataservice/service/rdb/rdb_store_observer_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_store_observer_impl.cpp @@ -20,8 +20,8 @@ #include "log_print.h" namespace OHOS::DistributedRdb { -RdbStoreObserverImpl::RdbStoreObserverImpl(RdbServiceImpl* owner, pid_t pid) - : pid_(pid), owner_(owner) +RdbStoreObserverImpl::RdbStoreObserverImpl(RdbServiceImpl* owner, pid_t pid, uint32_t tokenId) + : pid_(pid), tokenId_(tokenId), owner_(owner) { ZLOGI("construct"); } @@ -35,7 +35,7 @@ void RdbStoreObserverImpl::OnChange(const DistributedDB::StoreChangedData &data) { ZLOGI("enter"); if (owner_ != nullptr) { - owner_->OnDataChange(pid_, data); + owner_->OnDataChange(pid_, tokenId_, data); } } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_store_observer_impl.h b/services/distributeddataservice/service/rdb/rdb_store_observer_impl.h index e0043f5f..0c7af901 100644 --- a/services/distributeddataservice/service/rdb/rdb_store_observer_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_store_observer_impl.h @@ -23,15 +23,16 @@ namespace OHOS::DistributedRdb { class RdbServiceImpl; class RdbStoreObserverImpl : public DistributedDB::StoreObserver { public: - explicit RdbStoreObserverImpl(RdbServiceImpl* owner, pid_t pid = 0); + explicit RdbStoreObserverImpl(RdbServiceImpl* owner, pid_t pid = 0, uint32_t tokenId = 0); ~RdbStoreObserverImpl() override; void OnChange(const DistributedDB::StoreChangedData &data) override; private: - pid_t pid_ {}; - RdbServiceImpl* owner_ {}; + pid_t pid_ = 0; + uint32_t tokenId_ = 0; + RdbServiceImpl* owner_ = nullptr; }; } // namespace OHOS::DistributedRdb #endif diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 5422c143..2ccbe7b7 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -22,19 +22,13 @@ #include "checker/checker_manager.h" #include "crypto_manager.h" #include "device_manager_adapter.h" -#include "directory/directory_manager.h" -#include "kvstore_utils.h" #include "log_print.h" -#include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" -#include "metadata/store_meta_data.h" +#include "rdb_query.h" #include "rdb_result_set_impl.h" -#include "types.h" -#include "utils/constant.h" -#include "utils/converter.h" +#include "store/general_store.h" #include "types_export.h" - -using OHOS::DistributedKv::KvStoreUtils; +#include "utils/anonymous.h" using OHOS::DistributedKv::AccountDelegate; using namespace OHOS::Security::AccessToken; using namespace OHOS::DistributedData; @@ -169,11 +163,11 @@ int32_t RdbSyncer::InitDBDelegate(const StoreMetaData &meta) } option.observer = observer_; std::string fileName = meta.dataDir; - ZLOGI("path=%{public}s storeId=%{public}s", fileName.c_str(), meta.storeId.c_str()); + ZLOGI("path=%{public}s storeId=%{public}s", fileName.c_str(), Anonymous::Change(meta.storeId).c_str()); auto status = manager_->OpenStore(fileName, meta.storeId, option, delegate_); if (status != DistributedDB::DBStatus::OK) { ZLOGE("open store failed, path=%{public}s storeId=%{public}s status=%{public}d", - fileName.c_str(), meta.storeId.c_str(), status); + fileName.c_str(), Anonymous::Change(meta.storeId).c_str(), status); return RDB_ERROR; } ZLOGI("open store success"); @@ -182,10 +176,10 @@ int32_t RdbSyncer::InitDBDelegate(const StoreMetaData &meta) return RDB_OK; } -int32_t RdbSyncer::GetInstIndex(uint32_t tokenId, const std::string &bundleName) +std::pair RdbSyncer::GetInstIndexAndUser(uint32_t tokenId, const std::string &bundleName) { if (AccessTokenKit::GetTokenTypeFlag(tokenId) != TOKEN_HAP) { - return 0; + return { 0, 0 }; } HapTokenInfo tokenInfo; @@ -194,9 +188,9 @@ int32_t RdbSyncer::GetInstIndex(uint32_t tokenId, const std::string &bundleName) if (errCode != RET_SUCCESS) { ZLOGE("GetHapTokenInfo error:%{public}d, tokenId:0x%{public}x appId:%{public}s", errCode, tokenId, bundleName.c_str()); - return -1; + return { -1, -1 }; } - return tokenInfo.instIndex; + return { tokenInfo.instIndex, tokenInfo.userID }; } DistributedDB::RelationalStoreDelegate* RdbSyncer::GetDelegate() @@ -205,7 +199,7 @@ DistributedDB::RelationalStoreDelegate* RdbSyncer::GetDelegate() return delegate_; } -int32_t RdbSyncer::SetDistributedTables(const std::vector &tables) +int32_t RdbSyncer::SetDistributedTables(const std::vector &tables, int32_t type) { auto* delegate = GetDelegate(); if (delegate == nullptr) { @@ -215,7 +209,7 @@ int32_t RdbSyncer::SetDistributedTables(const std::vector &tables) for (const auto& table : tables) { ZLOGI("%{public}s", table.c_str()); - auto dBStatus = delegate->CreateDistributedTable(table); + auto dBStatus = delegate->CreateDistributedTable(table, static_cast(type)); if (dBStatus != DistributedDB::DBStatus::OK) { ZLOGE("create distributed table failed, table:%{public}s, err:%{public}d", table.c_str(), dBStatus); return RDB_ERROR; @@ -234,7 +228,7 @@ std::vector RdbSyncer::GetConnectDevices() } ZLOGI("size=%{public}u", static_cast(devices.size())); for (const auto& device: devices) { - ZLOGI("%{public}s", KvStoreUtils::ToBeAnonymous(device).c_str()); + ZLOGI("%{public}s", Anonymous::Change(device).c_str()); } return devices; } @@ -245,19 +239,18 @@ std::vector RdbSyncer::NetworkIdToUUID(const std::vector %{public}s", KvStoreUtils::ToBeAnonymous(networkId).c_str(), - KvStoreUtils::ToBeAnonymous(uuid).c_str()); + ZLOGI("%{public}s <--> %{public}s", Anonymous::Change(networkId).c_str(), Anonymous::Change(uuid).c_str()); } return uuids; } -void RdbSyncer::HandleSyncStatus(const std::map> &syncStatus, - SyncResult &result) +Details RdbSyncer::HandleSyncStatus(const std::map> &syncStatus) { + Details details; for (const auto& status : syncStatus) { auto res = DistributedDB::DBStatus::OK; for (const auto& tableStatus : status.second) { @@ -272,8 +265,10 @@ void RdbSyncer::HandleSyncStatus(const std::map 1) { + query.FromTable(predicates.tables_); + } for (const auto& operation : predicates.operations_) { if (operation.operator_ >= 0 && operation.operator_ < OPERATOR_MAX) { HANDLES[operation.operator_](operation, query); @@ -333,7 +332,7 @@ DistributedDB::Query RdbSyncer::MakeQuery(const RdbPredicates &predicates) return query; } -int32_t RdbSyncer::DoSync(const SyncOption &option, const RdbPredicates &predicates, SyncResult &result) +int32_t RdbSyncer::DoSync(const Option &option, const RdbPredicates &predicates, const AsyncDetail &async) { ZLOGI("enter"); auto* delegate = GetDelegate(); @@ -342,44 +341,19 @@ int32_t RdbSyncer::DoSync(const SyncOption &option, const RdbPredicates &predica return RDB_ERROR; } - std::vector devices; - if (predicates.devices_.empty()) { - devices = NetworkIdToUUID(GetConnectDevices()); - } else { - devices = NetworkIdToUUID(predicates.devices_); + if (option.mode < DistributedData::GeneralStore::NEARBY_END) { + auto &networkIds = predicates.devices_; + auto devices = networkIds.empty() ? NetworkIdToUUID(GetConnectDevices()) : NetworkIdToUUID(networkIds); + return delegate->Sync( + devices, static_cast(option.mode), MakeQuery(predicates), + [async](const std::map> &syncStatus) { + async(HandleSyncStatus(syncStatus)); + }, + option.isAsync); + } else if (option.mode < DistributedData::GeneralStore::CLOUD_END) { + return RDB_OK; } - - ZLOGI("delegate sync"); - return delegate->Sync(devices, static_cast(option.mode), - MakeQuery(predicates), [&result] (const std::map> &syncStatus) { - HandleSyncStatus(syncStatus, result); - }, true); -} - -int32_t RdbSyncer::DoAsync(const SyncOption &option, const RdbPredicates &predicates, const SyncCallback& callback) -{ - auto* delegate = GetDelegate(); - if (delegate == nullptr) { - ZLOGE("delegate is nullptr"); - return RDB_ERROR; - } - - std::vector devices; - if (predicates.devices_.empty()) { - devices = NetworkIdToUUID(GetConnectDevices()); - } else { - devices = NetworkIdToUUID(predicates.devices_); - } - - ZLOGI("delegate sync"); - return delegate->Sync(devices, static_cast(option.mode), - MakeQuery(predicates), [callback] (const std::map> &syncStatus) { - SyncResult result; - HandleSyncStatus(syncStatus, result); - callback(result); - }, false); + return RDB_OK; } int32_t RdbSyncer::RemoteQuery(const std::string& device, const std::string& sql, @@ -417,7 +391,7 @@ int32_t RdbSyncer::RemoveDeviceData() } DistributedDB::DBStatus status = delegate->RemoveDeviceData(); if (status != DistributedDB::DBStatus::OK) { - ZLOGE("DistributedDB RemoveDeviceData failed, status is %{public}d.", status); + ZLOGE("DistributedDB RemoveDeviceData failed, status is %{public}d.", status); return RDB_ERROR; } return RDB_OK; diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.h b/services/distributeddataservice/service/rdb/rdb_syncer.h index 30dc8402..9b63b0f4 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -19,18 +19,20 @@ #include #include +#include "iremote_object.h" +#include "metadata/secret_key_meta_data.h" #include "metadata/store_meta_data.h" +#include "rdb_service.h" #include "rdb_store_observer_impl.h" #include "rdb_types.h" #include "relational_store_delegate.h" #include "relational_store_manager.h" -#include "metadata/secret_key_meta_data.h" -#include "iremote_object.h" namespace OHOS::DistributedRdb { class RdbSyncer { public: using StoreMetaData = OHOS::DistributedData::StoreMetaData; using SecretKeyMetaData = DistributedData::SecretKeyMetaData; + using Option = DistributedRdb::RdbService::Option; RdbSyncer(const RdbSyncerParam& param, RdbStoreObserverImpl* observer); ~RdbSyncer() noexcept; @@ -46,11 +48,9 @@ public: std::string GetIdentifier() const; - int32_t SetDistributedTables(const std::vector& tables); - - int32_t DoSync(const SyncOption& option, const RdbPredicates& predicates, SyncResult& result); + int32_t SetDistributedTables(const std::vector &tables, int32_t type); - int32_t DoAsync(const SyncOption& option, const RdbPredicates& predicates, const SyncCallback& callback); + int32_t DoSync(const Option &option, const RdbPredicates &predicates, const AsyncDetail &async); int32_t RemoteQuery(const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet); @@ -59,7 +59,7 @@ public: static std::string RemoveSuffix(const std::string& name); - static int32_t GetInstIndex(uint32_t tokenId, const std::string &bundleName); + static std::pair GetInstIndexAndUser(uint32_t tokenId, const std::string &bundleName); static bool GetPassword(const StoreMetaData &metaData, DistributedDB::CipherPassword &password); @@ -89,8 +89,7 @@ private: static std::vector GetConnectDevices(); static std::vector NetworkIdToUUID(const std::vector& networkIds); - static void HandleSyncStatus(const std::map>& SyncStatus, - SyncResult& result); + static Details HandleSyncStatus(const std::map> &SyncStatus); static void EqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); static void NotEqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); static void And(const RdbPredicateOperation& operation, DistributedDB::Query& query); diff --git a/services/distributeddataservice/service/rdb/rdb_watcher.cpp b/services/distributeddataservice/service/rdb/rdb_watcher.cpp index 01572668..6e712bc7 100644 --- a/services/distributeddataservice/service/rdb/rdb_watcher.cpp +++ b/services/distributeddataservice/service/rdb/rdb_watcher.cpp @@ -16,28 +16,43 @@ #define LOG_TAG "RdbWatcher" #include "rdb_watcher.h" -#include "log_print.h" + #include "error/general_error.h" +#include "log_print.h" namespace OHOS::DistributedRdb { using namespace DistributedData; -using Err = DistributedData::GeneralError; -RdbWatcher::RdbWatcher(RdbServiceImpl *rdbService, uint32_t tokenId, const std::string &storeName) - : rdbService_(rdbService), tokenId_(tokenId), storeName_(storeName) +using Error = DistributedData::GeneralError; +RdbWatcher::RdbWatcher() { } -int32_t RdbWatcher::OnChange(Origin origin, const std::string &id) +int32_t RdbWatcher::OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) { - if (rdbService_ == nullptr) { - return Err::E_ERROR; + auto notifier = GetNotifier(); + if (notifier == nullptr) { + return E_NOT_INIT; } - rdbService_->OnChange(tokenId_, storeName_); - return Err::E_OK; + DistributedRdb::Origin rdbOrigin; + rdbOrigin.origin = origin.origin; + rdbOrigin.id = origin.id; + rdbOrigin.store = origin.store; + // notifier OnChange() + return E_OK; } -int32_t RdbWatcher::OnChange(Origin origin, const std::string &id, const std::vector &values) +sptr RdbWatcher::GetNotifier() const { - return Err::E_NOT_SUPPORT; + std::shared_lock lock(mutex_); + return notifier_; +} + +void RdbWatcher::SetNotifier(sptr notifier) +{ + std::unique_lock lock(mutex_); + if (notifier_ == notifier) { + return; + } + notifier_ = notifier; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_watcher.h b/services/distributeddataservice/service/rdb/rdb_watcher.h index 65af0216..ac898854 100644 --- a/services/distributeddataservice/service/rdb/rdb_watcher.h +++ b/services/distributeddataservice/service/rdb/rdb_watcher.h @@ -15,23 +15,23 @@ #ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_WATCHER_H #define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_WATCHER_H -#include "rdb_service_impl.h" +#include +#include +#include "rdb_notifier_proxy.h" #include "store/general_value.h" #include "store/general_watcher.h" namespace OHOS::DistributedRdb { -class RdbServiceImpl; class RdbWatcher : public DistributedData::GeneralWatcher { public: - explicit RdbWatcher(RdbServiceImpl *rdbService, uint32_t tokenId, const std::string &storeName); - int32_t OnChange(Origin origin, const std::string &id) override; - int32_t OnChange(Origin origin, const std::string &id, - const std::vector &values) override; + RdbWatcher(); + int32_t OnChange(const Origin &origin, const PRIFields &primaryFields, ChangeInfo &&values) override; + sptr GetNotifier() const; + void SetNotifier(sptr notifier); private: - RdbServiceImpl* rdbService_ {}; - uint32_t tokenId_ = 0; - std::string storeName_ {}; + mutable std::shared_mutex mutex_; + sptr notifier_; }; } // namespace OHOS::DistributedRdb #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_WATCHER_H diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index d77bfb04..fcde19b4 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -170,7 +170,7 @@ void CloudDataTest::TearDown() {} /** * @tc.name: GetSchema -* @tc.desc: GetSchema from cloud. +* @tc.desc: GetSchema from cloud when no schema in meta. * @tc.type: FUNC * @tc.require: * @tc.author: ht @@ -186,7 +186,7 @@ HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) ASSERT_FALSE( MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); CloudEvent::StoreInfo storeInfo { OHOS::IPCSkeleton::GetCallingTokenID(), TEST_CLOUD_BUNDLE, TEST_CLOUD_STORE, 0 }; - auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo), "test_service"); + auto event = std::make_unique(CloudEvent::GET_SCHEMA, std::move(storeInfo)); EventCenter::GetInstance().PostEvent(move(event)); ASSERT_TRUE( MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), schemaMeta, true)); -- Gitee From 399e5eafb5e7fb5fe21b4ca1a512f32b5bfe2e2e Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 6 Jun 2023 10:42:01 +0800 Subject: [PATCH 159/437] f Signed-off-by: hanlu --- .../service/data_share/common/db_delegate.h | 2 +- .../service/data_share/common/kv_delegate.cpp | 27 +++++---- .../service/data_share/common/kv_delegate.h | 5 +- .../data_share/common/template_manager.cpp | 25 ++------- .../data_share/data/published_data.cpp | 56 ++++++++++++++++++- .../service/data_share/data/published_data.h | 3 +- .../service/data_share/data/template_data.cpp | 48 ++++++++++++++++ .../service/data_share/data/template_data.h | 5 ++ .../data_share/data_share_service_impl.cpp | 44 ++++++++++++--- 9 files changed, 170 insertions(+), 45 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index 57d4a092..b649c1a3 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -95,7 +95,7 @@ public: bool reInit = false, const std::string &dir = "", const std::shared_ptr &executors = nullptr); virtual ~KvDBDelegate() = default; virtual int32_t Upsert(const std::string &collectionName, const KvData &value) = 0; - virtual int32_t DeleteById(const std::string &collectionName, const Id &id) = 0; + virtual int32_t Delete(const std::string &collectionName, const std::string &filter) = 0; virtual int32_t Get(const std::string &collectionName, const Id &id, std::string &value) = 0; virtual int32_t Get(const std::string &collectionName, const std::string &filter, const std::string &projection, std::string &result) = 0; diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index 21faf49e..5a77b1ed 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -40,19 +40,29 @@ int64_t KvDelegate::Upsert(const std::string &collectionName, const std::string return E_OK; } -int64_t KvDelegate::Delete(const std::string &collectionName, const std::string &filter) +int32_t KvDelegate::Delete(const std::string &collectionName, const std::string &filter) { std::lock_guard lock(mutex_); if (!Init()) { ZLOGE("init failed, %{public}s", collectionName.c_str()); return E_ERROR; } - int count = GRD_DeleteDoc(db_, collectionName.c_str(), filter.c_str(), 0); - if (count <= 0) { - ZLOGE("GRD_UpSertDoc failed,status %{public}d", count); - return count; + std::vector queryResults; + + int32_t status = GetBatch(collectionName, filter, "{\"id_\": true}", queryResults); + if (status != E_OK) { + ZLOGE("db GetBatch failed, %{public}s %{public}d", filter.c_str(), status); + return status; + } + for (auto &result : queryResults) { + auto count = GRD_DeleteDoc(db_, collectionName.c_str(), result.c_str(), 0); + if (count < 0) { + ZLOGE("GRD_UpSertDoc failed,status %{public}d %{public}s", count, result.c_str()); + continue; + } } Flush(); + ZLOGI("Delete, %{public}s, count %{public}zu", collectionName.c_str(), queryResults.size()); return E_OK; } @@ -121,11 +131,6 @@ int32_t KvDelegate::Upsert(const std::string &collectionName, const KvData &valu return Upsert(collectionName, id, value.GetValue()); } -int32_t KvDelegate::DeleteById(const std::string &collectionName, const Id &id) -{ - return Delete(collectionName, DistributedData::Serializable::Marshall(id)); -} - int32_t KvDelegate::Get(const std::string &collectionName, const Id &id, std::string &value) { std::string filter = DistributedData::Serializable::Marshall(id); @@ -208,7 +213,7 @@ int32_t KvDelegate::GetBatch(const std::string &collectionName, const std::strin query.filter = filter.c_str(); query.projection = projection.c_str(); GRD_ResultSet *resultSet; - int status = GRD_FindDoc(db_, collectionName.c_str(), query, 0, &resultSet); + int status = GRD_FindDoc(db_, collectionName.c_str(), query, GRD_DOC_ID_DISPLAY, &resultSet); if (status != GRD_OK || resultSet == nullptr) { ZLOGE("GRD_UpSertDoc failed,status %{public}d", status); return status; diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.h b/services/distributeddataservice/service/data_share/common/kv_delegate.h index 36a91043..e3d19e08 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.h +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.h @@ -29,7 +29,7 @@ public: KvDelegate(const std::string &path, const std::shared_ptr &executors); ~KvDelegate() override; int32_t Upsert(const std::string &collectionName, const KvData &value) override; - int32_t DeleteById(const std::string &collectionName, const Id &id) override; + int32_t Delete(const std::string &collectionName, const std::string &filter) override; int32_t Get(const std::string &collectionName, const Id &id, std::string &value) override; int32_t Get(const std::string &collectionName, const std::string &filter, const std::string &projection, @@ -41,9 +41,8 @@ private: bool Init(); bool GetVersion(const std::string &collectionName, const std::string &filter, int &version); int64_t Upsert(const std::string &collectionName, const std::string &filter, const std::string &value); - int64_t Delete(const std::string &collectionName, const std::string &filter); void Flush(); - std::mutex mutex_; + std::recursive_mutex mutex_; std::string path_; GRD_DB *db_ = nullptr; bool isInitDone_ = false; diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index dd49ff1e..dd1966c7 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -18,7 +18,6 @@ #include "general/load_config_data_info_strategy.h" -#include "db_delegate.h" #include "log_print.h" #include "published_data.h" #include "scheduler_manager.h" @@ -35,15 +34,9 @@ bool TemplateManager::GetTemplate( bool TemplateManager::AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl) { - auto delegate = KvDBDelegate::GetInstance(); - if (delegate == nullptr) { - ZLOGE("db open failed"); - return false; - } - TemplateData data(uri, tplId.bundleName_, tplId.subscriberId_, tpl); - auto status = delegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); - if (status != E_OK) { - ZLOGE("db Upsert failed, %{public}d", status); + auto status = TemplateData::Add(uri, tplId.bundleName_, tplId.subscriberId_, tpl); + if (!status) { + ZLOGE("Add failed, %{public}d", status); return false; } return true; @@ -51,15 +44,9 @@ bool TemplateManager::AddTemplate(const std::string &uri, const TemplateId &tplI bool TemplateManager::DelTemplate(const std::string &uri, const TemplateId &tplId) { - auto delegate = KvDBDelegate::GetInstance(); - if (delegate == nullptr) { - ZLOGE("db open failed"); - return false; - } - auto status = delegate->DeleteById( - KvDBDelegate::TEMPLATE_TABLE, Id(TemplateData::GenId(uri, tplId.bundleName_, tplId.subscriberId_))); - if (status != E_OK) { - ZLOGE("db DeleteById failed, %{public}d", status); + auto status = TemplateData::Delete(uri, tplId.bundleName_, tplId.subscriberId_); + if (!status) { + ZLOGE("Delete failed, %{public}d", status); return false; } SchedulerManager::GetInstance().RemoveTimer(Key(uri, tplId.subscriberId_, tplId.bundleName_)); diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index d179ba4c..c7693d85 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -57,7 +57,7 @@ std::vector PublishedData::Query(const std::string &bundleName) int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, "{\"bundleName\":\"" + bundleName + "\"}", "{}", queryResults); if (status != E_OK) { - ZLOGE("db Upsert failed, %{public}s %{public}d", bundleName.c_str(), status); + ZLOGE("db GetBatch failed, %{public}s %{public}d", bundleName.c_str(), status); return std::vector(); } std::vector results; @@ -123,8 +123,62 @@ int32_t PublishedData::Query(const std::string &filter, std::variant queryResults; + int32_t status = + delegate->Delete(KvDBDelegate::DATA_TABLE, "{\"bundleName\":\"" + bundleName + "\"}"); + if (status != E_OK) { + ZLOGE("db Delete failed, %{public}s %{public}d", bundleName.c_str(), status); + } +} + +void PublishedData::ClearAging() +{ + auto lastValidData = + std::chrono::system_clock::now() - std::chrono::duration_cast(std::chrono::hours(240)); + auto lastValidTime = std::chrono::system_clock::to_time_t(lastValidData); + if (lastValidTime <= 0) { + return; + } + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return; + } + std::vector queryResults; + int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, "{}", "{}", queryResults); + if (status != E_OK) { + ZLOGE("db GetBatch failed %{public}d", status); + return; + } + for (auto &result : queryResults) { + PublishedDataNode data; + if (!PublishedDataNode::Unmarshall(result, data)) { + ZLOGE("Unmarshall %{public}s failed", result.c_str()); + continue; + } + + if (data.timestamp < lastValidTime) { + ZLOGI("aging %{public}s %{public}s", data.key.c_str(), data.bundleName.c_str()); + status = delegate->Delete( + KvDBDelegate::DATA_TABLE, Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId))); + if (status != E_OK) { + ZLOGE("db Delete failed, %{public}s %{public}s", data.key.c_str(), data.bundleName.c_str()); + } + } + } + return; +} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index edb384a0..d180670e 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -39,6 +39,8 @@ class PublishedData final : public KvData { public: explicit PublishedData(const PublishedDataNode &node); static std::vector Query(const std::string &bundleName); + static void Delete(const std::string &bundleName); + static void ClearAging(); static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); PublishedData(const std::string &key, const std::string &bundleName, int64_t subscriberId, @@ -48,7 +50,6 @@ public: int GetVersion() const override; std::string GetValue() const override; friend class GetDataStrategy; - private: PublishedDataNode value; }; diff --git a/services/distributeddataservice/service/data_share/data/template_data.cpp b/services/distributeddataservice/service/data_share/data/template_data.cpp index ca52ba1a..3805aca1 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.cpp +++ b/services/distributeddataservice/service/data_share/data/template_data.cpp @@ -117,6 +117,54 @@ int32_t TemplateData::Query(const std::string &filter, Template &aTemplate) return E_OK; } +bool TemplateData::Delete(const std::string &bundleName) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return false; + } + auto status = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, "{\"bundleName\":\"" + bundleName + "\"}"); + if (status != E_OK) { + ZLOGE("db DeleteById failed, %{public}d", status); + return false; + } + return true; +} + +bool TemplateData::Add( + const std::string &uri, const std::string &bundleName, const int64_t subsciriberId, const Template &aTemplate) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return false; + } + TemplateData data(uri, bundleName, subsciriberId, aTemplate); + auto status = delegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); + if (status != E_OK) { + ZLOGE("db Upsert failed, %{public}d", status); + return false; + } + return true; +} + +bool TemplateData::Delete(const std::string &uri, const std::string &bundleName, const int64_t subscriberId) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return false; + } + auto status = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, + static_cast(Id(TemplateData::GenId(uri, bundleName, subscriberId)))); + if (status != E_OK) { + ZLOGE("db DeleteById failed, %{public}d", status); + return false; + } + return true; +} + Template TemplateRootNode::ToTemplate() const { return tpl.ToTemplate(); diff --git a/services/distributeddataservice/service/data_share/data/template_data.h b/services/distributeddataservice/service/data_share/data/template_data.h index 2de90d8f..ba461524 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.h +++ b/services/distributeddataservice/service/data_share/data/template_data.h @@ -57,9 +57,14 @@ struct TemplateData final : public KvData { TemplateData(const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl); static int32_t Query(const std::string &filter, Template &aTemplate); static std::string GenId(const std::string &uri, const std::string &bundleName, int64_t subscriberId); + static bool Delete(const std::string &bundleName); + static bool Add( + const std::string &uri, const std::string &bundleName, const int64_t subsciriberId, const Template &aTemplate); + static bool Delete(const std::string &uri, const std::string &bundleName, const int64_t subscriberId); bool HasVersion() const override; int GetVersion() const override; std::string GetValue() const override; + private: TemplateRootNode value; }; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index d8e284ca..402cf719 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -30,6 +30,7 @@ #include "scheduler_manager.h" #include "template_manager.h" #include "utils/anonymous.h" +#include "template_data.h" namespace OHOS::DataShare { using FeatureSystem = DistributedData::FeatureSystem; @@ -112,7 +113,7 @@ int32_t DataShareServiceImpl::AddTemplate(const std::string &uri, const int64_t TemplateId tpltId; tpltId.subscriberId_ = subscriberId; if (!GetCallerBundleName(tpltId.bundleName_)) { - ZLOGE("get bundleName error, %{public}s", DistributedData::Anonymous::Change(uri).c_str()); + ZLOGE("get bundleName error, %{public}s", tpltId.bundleName_.c_str()); return ERROR; } return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); @@ -123,7 +124,7 @@ int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t TemplateId tpltId; tpltId.subscriberId_ = subscriberId; if (!GetCallerBundleName(tpltId.bundleName_)) { - ZLOGE("get bundleName error, %{public}s", DistributedData::Anonymous::Change(uri).c_str()); + ZLOGE("get bundleName error, %{public}s", tpltId.bundleName_.c_str()); return ERROR; } return TemplateManager::GetInstance().DelTemplate(uri, tpltId); @@ -150,7 +151,11 @@ std::vector DataShareServiceImpl::Publish(const Data &data, con std::vector results; std::vector publishedData; std::string callerBundleName; - GetCallerBundleName(callerBundleName); + if (!GetCallerBundleName(callerBundleName)) { + ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); + return results; + } + PublishedData::ClearAging(); for (const auto &item : data.datas_) { auto context = std::make_shared(item.key_); context->version = data.version_; @@ -171,7 +176,10 @@ std::vector DataShareServiceImpl::Publish(const Data &data, con Data DataShareServiceImpl::GetData(const std::string &bundleNameOfProvider) { std::string callerBundleName; - GetCallerBundleName(callerBundleName); + if (!GetCallerBundleName(callerBundleName)) { + ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); + return Data(); + } auto context = std::make_shared(); context->callerBundleName = callerBundleName; context->calledBundleName = bundleNameOfProvider; @@ -237,7 +245,10 @@ std::vector DataShareServiceImpl::SubscribePublishedData(const { std::vector results; std::string callerBundleName; - GetCallerBundleName(callerBundleName); + if (!GetCallerBundleName(callerBundleName)) { + ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); + return results; + } std::vector publishedKeys; int32_t result; for (const auto &uri : uris) { @@ -264,7 +275,10 @@ std::vector DataShareServiceImpl::UnsubscribePublishedData(cons { std::vector results; std::string callerBundleName; - GetCallerBundleName(callerBundleName); + if (!GetCallerBundleName(callerBundleName)) { + ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); + return results; + } for (const auto &uri : uris) { auto context = std::make_shared(uri); PublishedDataKey key(uri, callerBundleName, subscriberId); @@ -284,7 +298,10 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect { std::vector results; std::string callerBundleName; - GetCallerBundleName(callerBundleName); + if (!GetCallerBundleName(callerBundleName)) { + ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); + return results; + } std::vector publishedKeys; int32_t result; for (const auto &uri : uris) { @@ -310,7 +327,10 @@ std::vector DataShareServiceImpl::DisablePubSubs(const std::vec { std::vector results; std::string callerBundleName; - GetCallerBundleName(callerBundleName); + if (!GetCallerBundleName(callerBundleName)) { + ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); + return results; + } for (const auto &uri : uris) { auto context = std::make_shared(uri); PublishedDataKey key(uri, callerBundleName, subscriberId); @@ -382,7 +402,10 @@ int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &use void DataShareServiceImpl::OnConnectDone() { std::string callerBundleName; - GetCallerBundleName(callerBundleName); + if (!GetCallerBundleName(callerBundleName)) { + ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); + return; + } AppConnectManager::Notify(callerBundleName); } @@ -390,6 +413,9 @@ int32_t DataShareServiceImpl::OnAppUninstall( const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) { ZLOGI("%{public}s uninstalled", bundleName.c_str()); + PublishedData::Delete(bundleName); + PublishedData::ClearAging(); + TemplateData::Delete(bundleName); return EOK; } } // namespace OHOS::DataShare -- Gitee From 02846913b748e9f1a9a168cda093da271b482f81 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 6 Jun 2023 11:04:19 +0800 Subject: [PATCH 160/437] add deathRecipient Signed-off-by: niudongyao --- .../data_share/common/template_manager.cpp | 68 +++++++++++++++++++ .../data_share/common/template_manager.h | 42 ++++++++++++ 2 files changed, 110 insertions(+) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index dd49ff1e..0a659954 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -123,6 +123,40 @@ RdbSubscriberManager &RdbSubscriberManager::GetInstance() return manager; } +void RdbSubscriberManager::LinkToDeath(const Key &key, sptr observer) +{ + sptr deathRecipient = new (std::nothrow) ObserverNodeRecipient(this, key, observer); + if (deathRecipient == nullptr) { + ZLOGE("new ObserverNodeRecipient error, uri is %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str()); + return; + } + auto remote = observer->AsObject().GetRefPtr(); + if (!remote->AddDeathRecipient(deathRecipient)) { + ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.uri).c_str()); + return; + } + ZLOGD("link to death success, uri is %{public}s", DistributedData::Anonymous::Change(key.uri).c_str()); +} + +void RdbSubscriberManager::OnRemoteDied(const Key &key, sptr observer) +{ + rdbCache_.ComputeIfPresent(key, [&observer, this](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); ++it) { + if (it->observer->AsObject() == observer->AsObject()) { + value.erase(it); + ZLOGI("OnRemoteDied delete subscriber, uri is %{public}s", + DistributedData::Anonymous::Change(key.uri).c_str()); + break; + } + } + if (GetEnableObserverCount(key) == 0) { + SchedulerManager::GetInstance().RemoveTimer(key); + } + return !value.empty(); + }); +} + int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const TemplateId &tplId, const sptr observer, std::shared_ptr context, std::shared_ptr executorPool) @@ -142,6 +176,7 @@ int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const Templat }; executorPool->Execute(task); value.emplace_back(observer, context->callerTokenId); + LinkToDeath(key, observer); if (GetEnableObserverCount(key) == 1) { SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); } @@ -317,6 +352,38 @@ PublishedDataSubscriberManager &PublishedDataSubscriberManager::GetInstance() return manager; } +void PublishedDataSubscriberManager::LinkToDeath(const PublishedDataKey &key, + sptr observer) +{ + sptr deathRecipient = new (std::nothrow) ObserverNodeRecipient(this, key, observer); + if (deathRecipient == nullptr) { + ZLOGE("new ObserverNodeRecipient error. uri is %{public}s", + DistributedData::Anonymous::Change(key.key).c_str()); + return; + } + auto remote = observer->AsObject().GetRefPtr(); + if (!remote->AddDeathRecipient(deathRecipient)) { + ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); + return; + } + ZLOGD("link to death success, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); +} + +void PublishedDataSubscriberManager::OnRemoteDied(const PublishedDataKey &key, sptr observer) +{ + publishedDataCache.ComputeIfPresent(key, [&observer, this](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); ++it) { + if (it->observer->AsObject() == observer->AsObject()) { + value.erase(it); + ZLOGI("OnRemoteDied delete subscriber, uri is %{public}s", + DistributedData::Anonymous::Change(key.key).c_str()); + break; + } + } + return !value.empty(); + }); +} + int PublishedDataSubscriberManager::AddSubscriber(const std::string &key, const std::string &callerBundleName, const int64_t subscriberId, const sptr observer, const uint32_t callerTokenId) { @@ -324,6 +391,7 @@ int PublishedDataSubscriberManager::AddSubscriber(const std::string &key, const publishedDataCache.Compute(publishedDataKey, [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); + LinkToDeath(key, observer); value.emplace_back(observer, callerTokenId); return true; }); diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index bcb9c51f..167fb243 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -71,6 +71,26 @@ private: bool enabled = true; }; + class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { + public: + ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, sptr observer) + : owner_(owner), key_(key), observer_(observer){}; + + void OnRemoteDied(const wptr &object) override + { + if (owner_ != nullptr) { + owner_->OnRemoteDied(key_, observer_); + } + } + + private: + RdbSubscriberManager *owner_; + Key key_; + sptr observer_; + }; + + void LinkToDeath(const Key &key, sptr observer); + void OnRemoteDied(const Key &key, sptr observer); RdbSubscriberManager() = default; ConcurrentMap> rdbCache_; int Notify(const Key &key, const std::vector &val, const std::string &rdbDir, int rdbVersion); @@ -110,6 +130,28 @@ private: uint32_t callerTokenId; bool enabled = true; }; + class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { + public: + ObserverNodeRecipient(PublishedDataSubscriberManager *owner, const PublishedDataKey &key, + sptr observer) + : owner_(owner), key_(key), observer_(observer){}; + + void OnRemoteDied(const wptr &object) override + { + if (owner_ != nullptr) { + owner_->OnRemoteDied(key_, observer_); + } + } + + private: + PublishedDataSubscriberManager *owner_; + PublishedDataKey key_; + sptr observer_; + }; + + void LinkToDeath(const PublishedDataKey &key, sptr observer); + void OnRemoteDied(const PublishedDataKey &key, sptr observer); + PublishedDataSubscriberManager() = default; void PutInto(std::map, std::vector> &, const std::vector &, const PublishedDataKey &, const sptr); -- Gitee From 8ecbd3b7af2dee9345bcab72ee06b91a5906ebb1 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 6 Jun 2023 11:08:25 +0800 Subject: [PATCH 161/437] add deathRecipient Signed-off-by: niudongyao --- .../service/data_share/common/template_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 0a659954..ebcc0643 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -176,7 +176,7 @@ int RdbSubscriberManager::AddRdbSubscriber(const std::string &uri, const Templat }; executorPool->Execute(task); value.emplace_back(observer, context->callerTokenId); - LinkToDeath(key, observer); + LinkToDeath(key, observer); if (GetEnableObserverCount(key) == 1) { SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); } -- Gitee From 611fbe6dbd34ba2709df66607037f01caf595a45 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 6 Jun 2023 11:20:05 +0800 Subject: [PATCH 162/437] add deathRecipient Signed-off-by: niudongyao --- .../service/data_share/common/template_manager.cpp | 3 ++- .../service/data_share/common/template_manager.h | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index ebcc0643..9e80f741 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -369,7 +369,8 @@ void PublishedDataSubscriberManager::LinkToDeath(const PublishedDataKey &key, ZLOGD("link to death success, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); } -void PublishedDataSubscriberManager::OnRemoteDied(const PublishedDataKey &key, sptr observer) +void PublishedDataSubscriberManager::OnRemoteDied(const PublishedDataKey &key, + sptr observer) { publishedDataCache.ComputeIfPresent(key, [&observer, this](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); ++it) { diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index 167fb243..34be42cb 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -73,8 +73,8 @@ private: class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { public: - ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, sptr observer) - : owner_(owner), key_(key), observer_(observer){}; + ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, + sptr observer) : owner_(owner), key_(key), observer_(observer){}; void OnRemoteDied(const wptr &object) override { @@ -133,8 +133,7 @@ private: class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { public: ObserverNodeRecipient(PublishedDataSubscriberManager *owner, const PublishedDataKey &key, - sptr observer) - : owner_(owner), key_(key), observer_(observer){}; + sptr observer) : owner_(owner), key_(key), observer_(observer){}; void OnRemoteDied(const wptr &object) override { -- Gitee From f49e34d77c28beb2ea13023a47822f6fbdeb9afd Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 6 Jun 2023 11:31:27 +0800 Subject: [PATCH 163/437] add deathRecipient Signed-off-by: niudongyao --- .../service/data_share/common/template_manager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index 34be42cb..e2df7f6f 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -74,7 +74,7 @@ private: class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { public: ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, - sptr observer) : owner_(owner), key_(key), observer_(observer){}; + sptr observer) : owner_(owner), key_(key), observer_(observer) {}; void OnRemoteDied(const wptr &object) override { @@ -133,7 +133,7 @@ private: class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { public: ObserverNodeRecipient(PublishedDataSubscriberManager *owner, const PublishedDataKey &key, - sptr observer) : owner_(owner), key_(key), observer_(observer){}; + sptr observer) : owner_(owner), key_(key), observer_(observer) {}; void OnRemoteDied(const wptr &object) override { -- Gitee From a1c323e2db324f5d6025b25056cdd259489d8775 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 6 Jun 2023 16:20:20 +0800 Subject: [PATCH 164/437] refactor:observer Signed-off-by: htt1997 --- .../service/permission/src/permit_delegate.cpp | 2 +- .../service/rdb/rdb_notifier_proxy.cpp | 4 ++-- .../service/rdb/rdb_notifier_proxy.h | 3 ++- .../service/rdb/rdb_service_impl.cpp | 10 ++++++++-- .../distributeddataservice/service/rdb/rdb_syncer.cpp | 1 + 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/permission/src/permit_delegate.cpp b/services/distributeddataservice/service/permission/src/permit_delegate.cpp index 7a4bd29e..52b9af7c 100644 --- a/services/distributeddataservice/service/permission/src/permit_delegate.cpp +++ b/services/distributeddataservice/service/permission/src/permit_delegate.cpp @@ -79,7 +79,7 @@ bool PermitDelegate::SyncActivate(const ActiveParam ¶m) bool PermitDelegate::VerifyPermission(const CheckParam ¶m, uint8_t flag) { ZLOGI("user:%{public}s, appId:%{public}s, storeId:%{public}s, remote devId:%{public}s, instanceId:%{public}d," - "flag:%{public}u", param.userId.c_str(), param.appId.c_str(), param.storeId.c_str(), + "flag:%{public}u", param.userId.c_str(), param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), Anonymous::Change(param.deviceId).c_str(), param.instanceId, flag); auto devId = DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid; diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index 97ba6bea..bd9ce05b 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -47,14 +47,14 @@ int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, Details &&result) return RDB_OK; } -int RdbNotifierProxy::OnChange(const std::string &storeName, const std::vector &devices) +int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &primaries, ChangeInfo &&changeInfo) { MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { ZLOGE("write descriptor failed"); return RDB_ERROR; } - if (!ITypesUtil::Marshal(data, storeName, devices)) { + if (!ITypesUtil::Marshal(data, origin, primaries, changeInfo)) { ZLOGE("write store name or devices failed"); return RDB_ERROR; } diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h index d0d9c1cb..991fcae4 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h @@ -31,7 +31,8 @@ public: int32_t OnComplete(uint32_t seqNum, Details &&result) override; - int32_t OnChange(const std::string& storeName, const std::vector& devices) override; + int32_t OnChange(const Origin &origin, const PrimaryFields &primaries, ChangeInfo &&changeInfo) override; + private: static inline BrokerDelegator delegator_; }; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index bf35f9ad..e2d6de20 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -233,7 +233,11 @@ void RdbServiceImpl::OnDataChange(pid_t pid, uint32_t tokenId, const Distributed if (success && agent.notifier_ != nullptr && pid == agent.pid_) { std::string device = data.GetDataChangeDevice(); auto networkId = DmAdapter::GetInstance().ToNetworkID(device); - agent.notifier_->OnChange(property.storeId, { networkId }); + Origin origin; + origin.origin = Origin::ORIGIN_NEARBY; + origin.store = property.storeId; + origin.id.push_back(networkId); + agent.notifier_->OnChange(origin, {}, {}); } } @@ -445,7 +449,9 @@ int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, { if (!option.isAsync) { auto [status, details] = DoSync(param, option, predicates); - async(std::move(details)); + if (async != nullptr) { + async(std::move(details)); + } return status; } return DoAsync(param, option, predicates); diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 2ccbe7b7..2453d660 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -353,6 +353,7 @@ int32_t RdbSyncer::DoSync(const Option &option, const RdbPredicates &predicates, } else if (option.mode < DistributedData::GeneralStore::CLOUD_END) { return RDB_OK; } + ZLOGI("delegate sync"); return RDB_OK; } -- Gitee From 70123af04628db1c4e24b08ba3e0c667051fc043 Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 6 Jun 2023 17:37:54 +0800 Subject: [PATCH 165/437] f Signed-off-by: hanlu --- .../service/data_share/common/uri_utils.cpp | 41 ++++++++++++++----- .../service/data_share/common/uri_utils.h | 2 +- .../general/load_config_common_strategy.cpp | 21 ++++++++-- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.cpp b/services/distributeddataservice/service/data_share/common/uri_utils.cpp index 5d6a4ffb..abb53606 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.cpp +++ b/services/distributeddataservice/service/data_share/common/uri_utils.cpp @@ -22,6 +22,8 @@ #include "utils/anonymous.h" namespace OHOS::DataShare { +constexpr const char USER_PARAM[] = "user"; +constexpr const char TOKEN_ID_PARAM[] = "srcToken"; bool URIUtils::GetInfoFromURI(const std::string &uri, UriInfo &uriInfo) { Uri uriTemp(uri); @@ -60,18 +62,37 @@ bool URIUtils::GetBundleNameFromProxyURI(const std::string &uri, std::string &bu return true; } -bool URIUtils::GetUserIdFromProxyURI(const std::string &uri, int32_t &user) +bool URIUtils::GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32_t &callerTokenId) { - Uri uriTemp(uri); - std::vector splitUri; - SplitStr(uriTemp.GetQuery(), "=", splitUri); - for (auto iter = splitUri.begin(); iter < splitUri.end(); iter++) { - if (*iter == "user" && iter + 1 < splitUri.end()) { - const char *value = (iter + 1)->c_str(); - user = atoi(value); - return true; + auto queryPos = uri.find_first_of('?'); + if (queryPos == std::string::npos) { + return true; + } + std::string query = uri.substr(queryPos + 1); + std::string::size_type pos = 0; + std::string::size_type nextPos; + std::string::size_type valueStartPos; + while (pos != std::string::npos) { + valueStartPos = query.find_first_of('=', pos) + 1; + if (valueStartPos == std::string::npos) { + ZLOGE("parse failed %{public}s", query.c_str()); + return false; } + nextPos = query.find_first_of('&', pos); + std::string value = (nextPos == std::string::npos ? query.substr(valueStartPos) + : query.substr(valueStartPos, nextPos - valueStartPos)); + if (!value.empty()) { + if (query.compare(pos, sizeof(USER_PARAM) - 1, USER_PARAM) == 0) { + user = std::stoi(value); + } else if (query.compare(pos, sizeof(TOKEN_ID_PARAM) - 1, TOKEN_ID_PARAM) == 0) { + callerTokenId = std::stoi(value); + } + } + if (nextPos == std::string::npos) { + break; + } + pos = nextPos + 1; } - return false; + return true; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.h b/services/distributeddataservice/service/data_share/common/uri_utils.h index 17ee8698..f7960682 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.h +++ b/services/distributeddataservice/service/data_share/common/uri_utils.h @@ -29,7 +29,7 @@ class URIUtils { public: static bool GetInfoFromURI(const std::string &uri, UriInfo &uriInfo); static bool GetBundleNameFromProxyURI(const std::string &uri, std::string &bundleName); - static bool GetUserIdFromProxyURI(const std::string &uri, int32_t &user); + static bool GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32_t &callerTokenId); static bool IsDataProxyURI(const std::string &uri); static constexpr const char *DATA_SHARE_SCHEMA = "datashare:///";; static constexpr const char DATA_PROXY_SCHEMA[] = "datashareproxy://"; diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp index 5f9a931d..9873bb31 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp @@ -15,7 +15,9 @@ #define LOG_TAG "LoadConfigCommonStrategy" #include "load_config_common_strategy.h" +#include "accesstoken_kit.h" #include "account/account_delegate.h" +#include "hap_token_info.h" #include "ipc_skeleton.h" #include "log_print.h" #include "uri_utils.h" @@ -23,11 +25,24 @@ namespace OHOS::DataShare { bool LoadConfigCommonStrategy::operator()(std::shared_ptr context) { - context->callerTokenId = IPCSkeleton::GetCallingTokenID(); + if (context->callerTokenId == 0) { + context->callerTokenId = IPCSkeleton::GetCallingTokenID(); + } context->currentUserId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(context->callerTokenId); - // single app, userId is in uri + // sa, userId is in uri, caller token id is from first caller tokenId if (context->currentUserId == 0) { - URIUtils::GetUserIdFromProxyURI(context->uri, context->currentUserId); + URIUtils::GetInfoFromProxyURI(context->uri, context->currentUserId, context->callerTokenId); + ZLOGI("hanlu %{public}d", context->callerTokenId); + } + if (context->callerBundleName.empty()) { + Security::AccessToken::HapTokenInfo tokenInfo; + auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(context->callerTokenId, tokenInfo); + if (result != Security::AccessToken::RET_SUCCESS) { + ZLOGE("token:0x%{public}x, result:%{public}d", context->callerTokenId, result); + return false; + } + ZLOGI("hanlu %{public}s", tokenInfo.bundleName.c_str()); + context->callerBundleName = tokenInfo.bundleName; } FormatUri(context->uri); return true; -- Gitee From 476c139c8e5a04c6445553a0a28cfd4230db50e2 Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 6 Jun 2023 17:47:12 +0800 Subject: [PATCH 166/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 6 ++++-- .../service/data_share/data_share_service_impl.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index c7693d85..e3ac79b0 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -136,7 +136,6 @@ void PublishedData::Delete(const std::string &bundleName) ZLOGE("db open failed"); return; } - std::vector queryResults; int32_t status = delegate->Delete(KvDBDelegate::DATA_TABLE, "{\"bundleName\":\"" + bundleName + "\"}"); if (status != E_OK) { @@ -146,6 +145,7 @@ void PublishedData::Delete(const std::string &bundleName) void PublishedData::ClearAging() { + // published data is valid in 240 hours auto lastValidData = std::chrono::system_clock::now() - std::chrono::duration_cast(std::chrono::hours(240)); auto lastValidTime = std::chrono::system_clock::to_time_t(lastValidData); @@ -163,6 +163,7 @@ void PublishedData::ClearAging() ZLOGE("db GetBatch failed %{public}d", status); return; } + int32_t agingSize = 0; for (auto &result : queryResults) { PublishedDataNode data; if (!PublishedDataNode::Unmarshall(result, data)) { @@ -171,13 +172,14 @@ void PublishedData::ClearAging() } if (data.timestamp < lastValidTime) { - ZLOGI("aging %{public}s %{public}s", data.key.c_str(), data.bundleName.c_str()); status = delegate->Delete( KvDBDelegate::DATA_TABLE, Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId))); if (status != E_OK) { ZLOGE("db Delete failed, %{public}s %{public}s", data.key.c_str(), data.bundleName.c_str()); } + agingSize++; } + ZLOGI("aging count %{public}d", agingSize); } return; } diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 402cf719..ea9c3b91 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -257,9 +257,9 @@ std::vector DataShareServiceImpl::SubscribePublishedData(const context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; result = subscribeStrategy_.Execute( - context, [&subscriberId, &observer, &callerBundleName, &context]() -> bool { + context, [&subscriberId, &observer, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().AddSubscriber( - context->uri, callerBundleName, subscriberId, observer, context->callerTokenId); + context->uri, context->callerBundleName, subscriberId, observer, context->callerTokenId); }); results.emplace_back(uri, result); if (result == E_OK) { @@ -285,9 +285,9 @@ std::vector DataShareServiceImpl::UnsubscribePublishedData(cons context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; results.emplace_back( - uri, subscribeStrategy_.Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().DelSubscriber( - context->uri, callerBundleName, subscriberId, context->callerTokenId); + context->uri, context->callerBundleName, subscriberId, context->callerTokenId); })); } return results; -- Gitee From cc6d1ba1fc69077a47cbd4348e768b200d9f4e9e Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 6 Jun 2023 16:20:20 +0800 Subject: [PATCH 167/437] refactor:observer Signed-off-by: htt1997 --- .../service/permission/src/permit_delegate.cpp | 2 +- .../service/rdb/rdb_notifier_proxy.cpp | 4 ++-- .../service/rdb/rdb_notifier_proxy.h | 3 ++- .../service/rdb/rdb_service_impl.cpp | 10 ++++++++-- .../distributeddataservice/service/rdb/rdb_syncer.cpp | 1 + 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/permission/src/permit_delegate.cpp b/services/distributeddataservice/service/permission/src/permit_delegate.cpp index 7a4bd29e..52b9af7c 100644 --- a/services/distributeddataservice/service/permission/src/permit_delegate.cpp +++ b/services/distributeddataservice/service/permission/src/permit_delegate.cpp @@ -79,7 +79,7 @@ bool PermitDelegate::SyncActivate(const ActiveParam ¶m) bool PermitDelegate::VerifyPermission(const CheckParam ¶m, uint8_t flag) { ZLOGI("user:%{public}s, appId:%{public}s, storeId:%{public}s, remote devId:%{public}s, instanceId:%{public}d," - "flag:%{public}u", param.userId.c_str(), param.appId.c_str(), param.storeId.c_str(), + "flag:%{public}u", param.userId.c_str(), param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), Anonymous::Change(param.deviceId).c_str(), param.instanceId, flag); auto devId = DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid; diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index 97ba6bea..bd9ce05b 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -47,14 +47,14 @@ int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, Details &&result) return RDB_OK; } -int RdbNotifierProxy::OnChange(const std::string &storeName, const std::vector &devices) +int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &primaries, ChangeInfo &&changeInfo) { MessageParcel data; if (!data.WriteInterfaceToken(GetDescriptor())) { ZLOGE("write descriptor failed"); return RDB_ERROR; } - if (!ITypesUtil::Marshal(data, storeName, devices)) { + if (!ITypesUtil::Marshal(data, origin, primaries, changeInfo)) { ZLOGE("write store name or devices failed"); return RDB_ERROR; } diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h index d0d9c1cb..991fcae4 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.h @@ -31,7 +31,8 @@ public: int32_t OnComplete(uint32_t seqNum, Details &&result) override; - int32_t OnChange(const std::string& storeName, const std::vector& devices) override; + int32_t OnChange(const Origin &origin, const PrimaryFields &primaries, ChangeInfo &&changeInfo) override; + private: static inline BrokerDelegator delegator_; }; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index bf35f9ad..e2d6de20 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -233,7 +233,11 @@ void RdbServiceImpl::OnDataChange(pid_t pid, uint32_t tokenId, const Distributed if (success && agent.notifier_ != nullptr && pid == agent.pid_) { std::string device = data.GetDataChangeDevice(); auto networkId = DmAdapter::GetInstance().ToNetworkID(device); - agent.notifier_->OnChange(property.storeId, { networkId }); + Origin origin; + origin.origin = Origin::ORIGIN_NEARBY; + origin.store = property.storeId; + origin.id.push_back(networkId); + agent.notifier_->OnChange(origin, {}, {}); } } @@ -445,7 +449,9 @@ int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, { if (!option.isAsync) { auto [status, details] = DoSync(param, option, predicates); - async(std::move(details)); + if (async != nullptr) { + async(std::move(details)); + } return status; } return DoAsync(param, option, predicates); diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 2ccbe7b7..2453d660 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -353,6 +353,7 @@ int32_t RdbSyncer::DoSync(const Option &option, const RdbPredicates &predicates, } else if (option.mode < DistributedData::GeneralStore::CLOUD_END) { return RDB_OK; } + ZLOGI("delegate sync"); return RDB_OK; } -- Gitee From 824f7b556e0792492db71628a07f7fb91a13803e Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 6 Jun 2023 19:57:18 +0800 Subject: [PATCH 168/437] f Signed-off-by: hanlu --- .../strategies/general/load_config_common_strategy.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp index 9873bb31..0291284b 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp @@ -32,7 +32,6 @@ bool LoadConfigCommonStrategy::operator()(std::shared_ptr context) // sa, userId is in uri, caller token id is from first caller tokenId if (context->currentUserId == 0) { URIUtils::GetInfoFromProxyURI(context->uri, context->currentUserId, context->callerTokenId); - ZLOGI("hanlu %{public}d", context->callerTokenId); } if (context->callerBundleName.empty()) { Security::AccessToken::HapTokenInfo tokenInfo; @@ -41,7 +40,6 @@ bool LoadConfigCommonStrategy::operator()(std::shared_ptr context) ZLOGE("token:0x%{public}x, result:%{public}d", context->callerTokenId, result); return false; } - ZLOGI("hanlu %{public}s", tokenInfo.bundleName.c_str()); context->callerBundleName = tokenInfo.bundleName; } FormatUri(context->uri); -- Gitee From 703af4e694c7b1ebca9c68f418961aee6773be86 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Tue, 6 Jun 2023 21:18:02 +0800 Subject: [PATCH 169/437] fix Signed-off-by: niudongyao --- .../service/data_share/common/template_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 9e80f741..ece2ffb6 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -131,7 +131,7 @@ void RdbSubscriberManager::LinkToDeath(const Key &key, sptrAsObject().GetRefPtr(); + auto remote = observer->AsObject(); if (!remote->AddDeathRecipient(deathRecipient)) { ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.uri).c_str()); return; @@ -361,7 +361,7 @@ void PublishedDataSubscriberManager::LinkToDeath(const PublishedDataKey &key, DistributedData::Anonymous::Change(key.key).c_str()); return; } - auto remote = observer->AsObject().GetRefPtr(); + auto remote = observer->AsObject(); if (!remote->AddDeathRecipient(deathRecipient)) { ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); return; -- Gitee From 952c60d86364e139511978efa67bb2277026f4f4 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 7 Jun 2023 09:53:55 +0800 Subject: [PATCH 170/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 1 + .../service/data_share/common/context.h | 2 + .../data_share/data_share_service_impl.cpp | 39 ++++++++++--------- ...d_config_from_data_proxy_node_strategy.cpp | 4 ++ .../general/load_config_common_strategy.cpp | 2 +- .../general/permission_strategy.cpp | 2 +- .../general/white_permission_strategy.cpp | 38 ++++++++++++++++++ .../general/white_permission_strategy.h | 29 ++++++++++++++ .../strategies/publish_strategy.cpp | 2 + .../strategies/subscribe_strategy.cpp | 1 + 10 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.cpp create mode 100644 services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index f4aa8db9..aa4353d1 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -58,6 +58,7 @@ ohos_shared_library("data_share_service") { "strategies/delete_strategy.cpp", "strategies/general/check_is_data_proxy_strategy.cpp", "strategies/general/check_is_single_app_strategy.cpp", + "strategies/general/white_permission_strategy.cpp", "strategies/general/empty_strategy.cpp", "strategies/general/load_config_common_strategy.cpp", "strategies/general/load_config_data_info_strategy.cpp", diff --git a/services/distributeddataservice/service/data_share/common/context.h b/services/distributeddataservice/service/data_share/common/context.h index 062319c3..5f5cc343 100644 --- a/services/distributeddataservice/service/data_share/common/context.h +++ b/services/distributeddataservice/service/data_share/common/context.h @@ -48,6 +48,8 @@ public: int version = -1; int errCode = -1; bool isRead = false; + bool isInWhite = false; // can cross permission check, for special SA + bool needAutoLoadCallerBundleName = false; AccessSystemMode accessSystemMode = AccessSystemMode::UNDEFINED; OHOS::AppExecFwk::BundleInfo bundleInfo; std::string type = "rdb"; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index ea9c3b91..1e0c83d4 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -378,24 +378,27 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { - const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); - DistributedData::StoreMetaData saveMeta; - saveMeta.appType = "default"; - saveMeta.storeId = "data_share_data_"; - saveMeta.isAutoSync = false; - saveMeta.isBackup = false; - saveMeta.isEncrypt = false; - saveMeta.bundleName = binderInfo_.selfName; - saveMeta.appId = binderInfo_.selfName; - saveMeta.user = user; - saveMeta.account = account; - saveMeta.tokenId = binderInfo_.selfTokenId; - saveMeta.securityLevel = DistributedKv::SecurityLevel::S1; - saveMeta.area = 1; - saveMeta.uid = IPCSkeleton::GetCallingUid(); - saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; - saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - KvDBDelegate::GetInstance(true, saveMeta.dataDir, binderInfo_.executors); + ZLOGI("%{public}d OnUserChange %{public}d %{public}s", code, user.c_str()); + if (code == static_cast(DistributedKv::AccountStatus::DEVICE_ACCOUNT_SWITCHED)) { + const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); + DistributedData::StoreMetaData saveMeta; + saveMeta.appType = "default"; + saveMeta.storeId = "data_share_data_"; + saveMeta.isAutoSync = false; + saveMeta.isBackup = false; + saveMeta.isEncrypt = false; + saveMeta.bundleName = binderInfo_.selfName; + saveMeta.appId = binderInfo_.selfName; + saveMeta.user = user; + saveMeta.account = account; + saveMeta.tokenId = binderInfo_.selfTokenId; + saveMeta.securityLevel = DistributedKv::SecurityLevel::S1; + saveMeta.area = 1; + saveMeta.uid = IPCSkeleton::GetCallingUid(); + saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; + saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); + KvDBDelegate::GetInstance(true, saveMeta.dataDir, binderInfo_.executors); + } return EOK; } diff --git a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp index 843966da..85765a7a 100644 --- a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp @@ -64,6 +64,10 @@ bool LoadConfigFromDataProxyNodeStrategy::operator()(std::shared_ptr co ZLOGI("access private data, caller and called is same, go"); return true; } + if (context->isInWhite) { + ZLOGI("access has white permission, go"); + return true; + } context->errCode = E_URI_NOT_EXIST; ZLOGI("not find DataProperties! %{private}s is private", context->uri.c_str()); return false; diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp index 0291284b..70433c3e 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp @@ -33,7 +33,7 @@ bool LoadConfigCommonStrategy::operator()(std::shared_ptr context) if (context->currentUserId == 0) { URIUtils::GetInfoFromProxyURI(context->uri, context->currentUserId, context->callerTokenId); } - if (context->callerBundleName.empty()) { + if (context->needAutoLoadCallerBundleName && context->callerBundleName.empty()) { Security::AccessToken::HapTokenInfo tokenInfo; auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(context->callerTokenId, tokenInfo); if (result != Security::AccessToken::RET_SUCCESS) { diff --git a/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp index 49823bd8..50270a2f 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp @@ -26,7 +26,7 @@ bool PermissionStrategy::operator()(std::shared_ptr context) ZLOGE("reject permission"); return false; } - if (!context->permission.empty()) { + if (!context->isInWhite && !context->permission.empty()) { int status = Security::AccessToken::AccessTokenKit::VerifyAccessToken(context->callerTokenId, context->permission); if (status != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { diff --git a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.cpp new file mode 100644 index 00000000..33cce533 --- /dev/null +++ b/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.cpp @@ -0,0 +1,38 @@ +/* + * 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. + */ +#define LOG_TAG "WhitePermissionStrategy" + +#include "white_permission_strategy.h" + +#include "accesstoken_kit.h" +#include "log_print.h" + +namespace OHOS::DataShare { +bool WhitePermissionStrategy::operator()(std::shared_ptr context) +{ + for (const auto &permission : whitePermissions_) { + int status = Security::AccessToken::AccessTokenKit::VerifyAccessToken(context->callerTokenId, permission); + if (status == Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + context->isInWhite = true; + return true; + } + } + return true; +} +WhitePermissionStrategy::WhitePermissionStrategy(std::initializer_list permissions) +{ + whitePermissions_.insert(whitePermissions_.end(), permissions.begin(), permissions.end()); +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h b/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h new file mode 100644 index 00000000..5514f0de --- /dev/null +++ b/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h @@ -0,0 +1,29 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_WHITE_PERMISSION_STRAGETY_H +#define DATASHARESERVICE_WHITE_PERMISSION_STRAGETY_H + +#include "strategy.h" +namespace OHOS::DataShare { +class WhitePermissionStrategy final : public Strategy { +public: + WhitePermissionStrategy(std::initializer_list permissions); + bool operator()(std::shared_ptr context) override; +private: + std::vector whitePermissions_; +}; +} // namespace OHOS::DataShare +#endif diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index 433d51cd..adb18246 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -19,6 +19,7 @@ #include "data_proxy/load_config_from_data_proxy_node_strategy.h" #include "general/load_config_common_strategy.h" #include "general/permission_strategy.h" +#include "general/white_permission_strategy.h" #include "log_print.h" #include "published_data.h" #include "utils/anonymous.h" @@ -58,6 +59,7 @@ SeqStrategy &PublishStrategy::GetStrategy() } std::initializer_list list = { new (std::nothrow) LoadConfigCommonStrategy(), + new (std::nothrow) WhitePermissionStrategy({"ohos.permission.WRITE_APP_PUSH_DATA"}), new (std::nothrow) LoadConfigFromDataProxyNodeStrategy(), new (std::nothrow) PermissionStrategy() }; diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp index eaa60490..067c8cda 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp @@ -32,6 +32,7 @@ int32_t SubscribeStrategy::Execute(std::shared_ptr context, std::functi return -1; } context->isRead = true; + context->needAutoLoadCallerBundleName = true; if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return context->errCode; -- Gitee From d849eda9ca28d476c8c25e74d2727f2c91444913 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 7 Jun 2023 10:18:23 +0800 Subject: [PATCH 171/437] f Signed-off-by: hanlu --- .../service/data_share/data_share_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 1e0c83d4..6475b2b5 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -378,7 +378,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { - ZLOGI("%{public}d OnUserChange %{public}d %{public}s", code, user.c_str()); + ZLOGI("OnUserChange %{public}d %{public}s", code, user.c_str()); if (code == static_cast(DistributedKv::AccountStatus::DEVICE_ACCOUNT_SWITCHED)) { const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); DistributedData::StoreMetaData saveMeta; -- Gitee From c793c975c0ede9ae1372493dd3bb0d5008fd9348 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 7 Jun 2023 12:19:49 +0800 Subject: [PATCH 172/437] fix:anonymous Signed-off-by: htt1997 --- .../service/rdb/rdb_service_impl.cpp | 8 ++++-- .../service/rdb/rdb_service_stub.cpp | 28 +++++++++---------- .../service/rdb/rdb_watcher.cpp | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index e2d6de20..cc7108e4 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -247,7 +247,7 @@ void RdbServiceImpl::SyncerTimeout(std::shared_ptr syncer) return; } auto storeId = syncer->GetStoreId(); - ZLOGI("%{public}s", storeId.c_str()); + ZLOGI("%{public}s", Anonymous::Change(storeId).c_str()); syncers_.ComputeIfPresent(syncer->GetPid(), [this, storeId](const auto& key, StoreSyncersType& syncers) { syncers.erase(storeId); syncerNum_--; @@ -335,7 +335,11 @@ std::pair RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, return {RDB_ERROR, {}}; } Details details = {}; - auto status = syncer->DoSync(option, pred, [&details](auto &&result) mutable { details = std::move(result); }); + auto status = syncer->DoSync(option, pred, [&details, ¶m](auto &&result) mutable { + ZLOGD("Sync complete, bundleName:%{public}s, storeName:%{public}s", param.bundleName_.c_str(), + Anonymous::Change(param.storeName_).c_str()); + details = std::move(result); + }); return { status, std::move(details) }; } diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 87ec6b42..7c703fbf 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -22,13 +22,13 @@ #include "utils/anonymous.h" namespace OHOS::DistributedRdb { +using Anonymous = DistributedData::Anonymous; int32_t RdbServiceStub::OnRemoteObtainDistributedTableName(MessageParcel &data, MessageParcel &reply) { std::string device; std::string table; if (!ITypesUtil::Unmarshal(data, device, table)) { - ZLOGE("Unmarshal device:%{public}s table:%{public}s", DistributedData::Anonymous::Change(device).c_str(), - table.c_str()); + ZLOGE("Unmarshal device:%{public}s table:%{public}s", Anonymous::Change(device).c_str(), table.c_str()); return IPC_STUB_INVALID_DATA_ERR; } @@ -45,7 +45,7 @@ int32_t RdbServiceStub::OnGetSchema(MessageParcel &data, MessageParcel &reply) RdbSyncerParam param; if (!ITypesUtil::Unmarshal(data, param)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); + Anonymous::Change(param.storeName_).c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto status = GetSchema(param); @@ -62,7 +62,7 @@ int32_t RdbServiceStub::OnRemoteInitNotifier(MessageParcel &data, MessageParcel sptr notifier; if (!ITypesUtil::Unmarshal(data, param, notifier) || notifier == nullptr) { ZLOGE("Unmarshal bundleName:%{public}s storeName_:%{public}s notifier is nullptr:%{public}d", - param.bundleName_.c_str(), param.storeName_.c_str(), notifier == nullptr); + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), notifier == nullptr); return IPC_STUB_INVALID_DATA_ERR; } auto status = InitNotifier(param, notifier); @@ -79,7 +79,7 @@ int32_t RdbServiceStub::OnRemoteSetDistributedTables(MessageParcel &data, Messag std::vector tables; if (!ITypesUtil::Unmarshal(data, param, tables)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables size:%{public}zu", - param.bundleName_.c_str(), param.storeName_.c_str(), tables.size()); + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), tables.size()); return IPC_STUB_INVALID_DATA_ERR; } @@ -98,7 +98,7 @@ int32_t RdbServiceStub::OnRemoteDoSync(MessageParcel &data, MessageParcel &reply RdbPredicates predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables:%{public}zu", param.bundleName_.c_str(), - param.storeName_.c_str(), predicates.tables_.size()); + Anonymous::Change(param.storeName_).c_str(), predicates.tables_.size()); return IPC_STUB_INVALID_DATA_ERR; } @@ -117,9 +117,9 @@ int32_t RdbServiceStub::OnRemoteDoAsync(MessageParcel &data, MessageParcel &repl Option option {}; RdbPredicates predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s seqNum:%{public}u tables:%{public}s", - param.bundleName_.c_str(), param.storeName_.c_str(), option.seqNum, - (*(predicates.tables_.begin())).c_str()); + ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s seqNum:%{public}u table:%{public}s", + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), option.seqNum, + predicates.tables_.empty() ? "null" : predicates.tables_.begin()->c_str()); return IPC_STUB_INVALID_DATA_ERR; } auto status = Sync(param, option, predicates, nullptr); @@ -136,7 +136,7 @@ int32_t RdbServiceStub::OnRemoteDoSubscribe(MessageParcel &data, MessageParcel & SubscribeOption option; if (!ITypesUtil::Unmarshal(data, param, option)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); + Anonymous::Change(param.storeName_).c_str()); return IPC_STUB_INVALID_DATA_ERR; } @@ -154,7 +154,7 @@ int32_t RdbServiceStub::OnRemoteDoUnSubscribe(MessageParcel &data, MessageParcel SubscribeOption option; if (!ITypesUtil::Unmarshal(data, param)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", param.bundleName_.c_str(), - param.storeName_.c_str()); + Anonymous::Change(param.storeName_).c_str()); return IPC_STUB_INVALID_DATA_ERR; } @@ -174,9 +174,9 @@ int32_t RdbServiceStub::OnRemoteDoRemoteQuery(MessageParcel& data, MessageParcel std::vector selectionArgs; if (!ITypesUtil::Unmarshal(data, param, device, sql, selectionArgs)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s device:%{public}s sql:%{public}s " - "selectionArgs size:%{public}zu", param.bundleName_.c_str(), param.storeName_.c_str(), - DistributedData::Anonymous::Change(device).c_str(), - DistributedData::Anonymous::Change(sql).c_str(), selectionArgs.size()); + "selectionArgs size:%{public}zu", param.bundleName_.c_str(), + Anonymous::Change(param.storeName_).c_str(), Anonymous::Change(device).c_str(), + Anonymous::Change(sql).c_str(), selectionArgs.size()); return IPC_STUB_INVALID_DATA_ERR; } diff --git a/services/distributeddataservice/service/rdb/rdb_watcher.cpp b/services/distributeddataservice/service/rdb/rdb_watcher.cpp index 6e712bc7..c929a769 100644 --- a/services/distributeddataservice/service/rdb/rdb_watcher.cpp +++ b/services/distributeddataservice/service/rdb/rdb_watcher.cpp @@ -37,7 +37,7 @@ int32_t RdbWatcher::OnChange(const Origin &origin, const PRIFields &primaryField rdbOrigin.origin = origin.origin; rdbOrigin.id = origin.id; rdbOrigin.store = origin.store; - // notifier OnChange() + notifier->OnChange(rdbOrigin, primaryFields, std::move(values)); return E_OK; } -- Gitee From 122b55674586bc84a1a2cbef2b6f910c517580ed Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 7 Jun 2023 16:27:56 +0800 Subject: [PATCH 173/437] f Signed-off-by: hanlu --- .../service/data_share/data_share_service_impl.cpp | 1 + .../data_share/strategies/general/white_permission_strategy.h | 2 +- .../service/data_share/strategies/publish_strategy.cpp | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 6475b2b5..4c6f8adc 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -419,6 +419,7 @@ int32_t DataShareServiceImpl::OnAppUninstall( PublishedData::Delete(bundleName); PublishedData::ClearAging(); TemplateData::Delete(bundleName); + RdbHelper::ClearCache(); return EOK; } } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h b/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h index 5514f0de..dcc36858 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h @@ -20,7 +20,7 @@ namespace OHOS::DataShare { class WhitePermissionStrategy final : public Strategy { public: - WhitePermissionStrategy(std::initializer_list permissions); + explicit WhitePermissionStrategy(std::initializer_list permissions); bool operator()(std::shared_ptr context) override; private: std::vector whitePermissions_; diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index adb18246..a5f059f0 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -57,9 +57,10 @@ SeqStrategy &PublishStrategy::GetStrategy() if (!strategies_.IsEmpty()) { return strategies_; } + std::initializer_list whitePermissions = { "ohos.permission.WRITE_APP_PUSH_DATA" }; std::initializer_list list = { new (std::nothrow) LoadConfigCommonStrategy(), - new (std::nothrow) WhitePermissionStrategy({"ohos.permission.WRITE_APP_PUSH_DATA"}), + new (std::nothrow) WhitePermissionStrategy(whitePermissions), new (std::nothrow) LoadConfigFromDataProxyNodeStrategy(), new (std::nothrow) PermissionStrategy() }; -- Gitee From 1facbc99a60651b57b8f1ef1cedcece9bf8c2212 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 7 Jun 2023 16:33:07 +0800 Subject: [PATCH 174/437] fix:wait param Signed-off-by: htt1997 --- services/distributeddataservice/service/rdb/rdb_syncer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 2453d660..2faede55 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -349,7 +349,7 @@ int32_t RdbSyncer::DoSync(const Option &option, const RdbPredicates &predicates, [async](const std::map> &syncStatus) { async(HandleSyncStatus(syncStatus)); }, - option.isAsync); + !option.isAsync); } else if (option.mode < DistributedData::GeneralStore::CLOUD_END) { return RDB_OK; } -- Gitee From f6258e3fcaab80e024c80ec375aab8fbc680cab9 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 7 Jun 2023 16:56:44 +0800 Subject: [PATCH 175/437] f Signed-off-by: hanlu --- services/distributeddataservice/service/data_share/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index aa4353d1..7acbbb7a 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -58,13 +58,13 @@ ohos_shared_library("data_share_service") { "strategies/delete_strategy.cpp", "strategies/general/check_is_data_proxy_strategy.cpp", "strategies/general/check_is_single_app_strategy.cpp", - "strategies/general/white_permission_strategy.cpp", "strategies/general/empty_strategy.cpp", "strategies/general/load_config_common_strategy.cpp", "strategies/general/load_config_data_info_strategy.cpp", "strategies/general/load_config_from_bundle_info_strategy.cpp", "strategies/general/permission_strategy.cpp", "strategies/general/process_single_app_user_cross_strategy.cpp", + "strategies/general/white_permission_strategy.cpp", "strategies/get_data_strategy.cpp", "strategies/insert_strategy.cpp", "strategies/publish_strategy.cpp", -- Gitee From 0bd39a3ee263a7bcf5107780f496dbb8c3e532fb Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 7 Jun 2023 20:15:59 +0800 Subject: [PATCH 176/437] =?UTF-8?q?=E7=AB=AF=E4=BA=91=E5=90=8C=E6=AD=A5=20?= =?UTF-8?q?Signed-off-by:=20zuojiangjiang=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../distributeddataservice/framework/BUILD.gn | 2 + .../framework/cloud/cloud_info.cpp | 34 +- .../framework/cloud/schema_meta.cpp | 17 + .../framework/cloud/sync_event.cpp | 71 ++++ .../framework/include/cloud/change_event.h | 30 ++ .../framework/include/cloud/cloud_info.h | 8 +- .../framework/include/cloud/schema_meta.h | 4 +- .../framework/include/cloud/sync_event.h | 53 +++ .../framework/include/error/general_error.h | 1 + .../framework/include/store/cursor.h | 2 + .../framework/include/store/general_store.h | 4 +- .../include/utils}/ref_count.h | 4 +- .../kvdb => framework/utils}/ref_count.cpp | 4 +- .../distributeddataservice/service/BUILD.gn | 5 +- .../service/cloud/cloud_service_impl.cpp | 319 ++++++++--------- .../service/cloud/cloud_service_impl.h | 33 +- .../service/cloud/sync_manager.cpp | 305 ++++++++++++++++ .../service/cloud/sync_manager.h | 85 +++++ .../service/kvdb/kvdb_service_impl.h | 3 +- .../service/rdb/rdb_cloud.cpp | 127 +++++++ .../service/rdb/rdb_cloud.h | 47 +++ .../service/rdb/rdb_cursor.cpp | 110 ++++++ .../service/rdb/rdb_cursor.h | 42 +++ .../service/rdb/rdb_general_store.cpp | 157 ++++++++- .../service/rdb/rdb_general_store.h | 34 +- .../service/rdb/rdb_query.cpp | 5 + .../service/rdb/rdb_query.h | 7 +- .../service/rdb/rdb_service_impl.cpp | 6 +- .../service/rdb/rdb_service_impl.h | 6 +- .../service/rdb/rdb_service_stub.cpp | 4 +- .../service/rdb/rdb_syncer.cpp | 42 ++- .../service/rdb/rdb_syncer.h | 9 +- .../service/rdb/value_proxy.cpp | 332 ++++++++++++++++++ .../service/rdb/value_proxy.h | 181 ++++++++++ .../service/test/BUILD.gn | 30 ++ .../service/test/cloud_data_test.cpp | 9 +- .../service/test/value_proxy_test.cpp | 107 ++++++ 37 files changed, 2007 insertions(+), 232 deletions(-) create mode 100644 services/distributeddataservice/framework/cloud/sync_event.cpp create mode 100644 services/distributeddataservice/framework/include/cloud/change_event.h create mode 100644 services/distributeddataservice/framework/include/cloud/sync_event.h rename services/distributeddataservice/{service/kvdb => framework/include/utils}/ref_count.h (95%) rename services/distributeddataservice/{service/kvdb => framework/utils}/ref_count.cpp (95%) create mode 100644 services/distributeddataservice/service/cloud/sync_manager.cpp create mode 100644 services/distributeddataservice/service/cloud/sync_manager.h create mode 100644 services/distributeddataservice/service/rdb/rdb_cloud.cpp create mode 100644 services/distributeddataservice/service/rdb/rdb_cloud.h create mode 100644 services/distributeddataservice/service/rdb/rdb_cursor.cpp create mode 100644 services/distributeddataservice/service/rdb/rdb_cursor.h create mode 100644 services/distributeddataservice/service/rdb/value_proxy.cpp create mode 100644 services/distributeddataservice/service/rdb/value_proxy.h create mode 100644 services/distributeddataservice/service/test/value_proxy_test.cpp diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index c051f1eb..793c97b1 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("distributeddatasvcfwk") { "cloud/cloud_server.cpp", "cloud/schema_meta.cpp", "cloud/subscription.cpp", + "cloud/sync_event.cpp", "directory/directory_manager.cpp", "eventcenter/event.cpp", "eventcenter/event_center.cpp", @@ -74,6 +75,7 @@ ohos_shared_library("distributeddatasvcfwk") { "utils/constant.cpp", "utils/converter.cpp", "utils/crypto.cpp", + "utils/ref_count.cpp", ] cflags = [ "-Wno-multichar" ] diff --git a/services/distributeddataservice/framework/cloud/cloud_info.cpp b/services/distributeddataservice/framework/cloud/cloud_info.cpp index a50f4d69..5c58d34e 100644 --- a/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -67,19 +67,27 @@ std::string CloudInfo::GetKey() const std::map CloudInfo::GetSchemaKey() const { std::map keys; - for (const auto &app : apps) { + for (const auto &[bundle, app] : apps) { const auto key = GetKey( - SCHEMA_PREFIX, { std::to_string(user), app.bundleName, std::to_string(app.instanceId) }); + SCHEMA_PREFIX, { std::to_string(user), bundle, std::to_string(app.instanceId) }); keys.insert_or_assign(app.bundleName, key); } return keys; } -std::string CloudInfo::GetSchemaKey(const std::string &bundleName, const int32_t instanceId) const +std::string CloudInfo::GetSchemaKey(const std::string &bundleName, int32_t instanceId) const { return GetKey(SCHEMA_PREFIX, { std::to_string(user), bundleName, std::to_string(instanceId) }); } +std::string CloudInfo::GetSchemaPrefix(const std::string &bundleName) const +{ + if (bundleName.empty()) { + return GetKey(SCHEMA_PREFIX, { std::to_string(user) }); + } + return GetKey(SCHEMA_PREFIX, { std::to_string(user), bundleName}); +} + std::string CloudInfo::GetSchemaKey(const StoreMetaData &meta) { return GetKey(SCHEMA_PREFIX, { meta.user, meta.bundleName, std::to_string(meta.instanceId) }); @@ -90,14 +98,22 @@ bool CloudInfo::IsValid() const return !id.empty(); } -bool CloudInfo::IsExist(const std::string &bundleName) const +bool CloudInfo::Exist(const std::string &bundleName, int32_t instanceId) +{ + if (bundleName.empty()) { + return false; + } + auto it = apps.find(bundleName); + return it != apps.end() && it->second.bundleName == bundleName && it->second.instanceId == instanceId; +} + +bool CloudInfo::IsOn(const std::string &bundleName, int32_t instanceId) { - for (const auto &app : apps) { - if (app.bundleName == bundleName) { - return true; - } + if (bundleName.empty()) { + return false; } - return false; + auto it = apps.find(bundleName); + return it != apps.end() && it->second.instanceId == instanceId && it->second.cloudSwitch; } std::string CloudInfo::GetPrefix(const std::initializer_list &fields) diff --git a/services/distributeddataservice/framework/cloud/schema_meta.cpp b/services/distributeddataservice/framework/cloud/schema_meta.cpp index d5454361..af5ec17a 100644 --- a/services/distributeddataservice/framework/cloud/schema_meta.cpp +++ b/services/distributeddataservice/framework/cloud/schema_meta.cpp @@ -18,6 +18,7 @@ namespace OHOS::DistributedData { bool SchemaMeta::Marshal(Serializable::json &node) const { SetValue(node[GET_NAME(version)], version); + SetValue(node[GET_NAME(bundleName)], bundleName); SetValue(node[GET_NAME(databases)], databases); return true; } @@ -25,10 +26,21 @@ bool SchemaMeta::Marshal(Serializable::json &node) const bool SchemaMeta::Unmarshal(const Serializable::json &node) { GetValue(node, GET_NAME(version), version); + GetValue(node, GET_NAME(bundleName), bundleName); GetValue(node, GET_NAME(databases), databases); return true; } +std::vector Database::GetTableNames() const +{ + std::vector tableNames; + tableNames.reserve(tables.size()); + for (auto &table : tables) { + tableNames.push_back(table.name); + } + return tableNames; +} + bool Database::Marshal(Serializable::json &node) const { SetValue(node[GET_NAME(name)], name); @@ -90,4 +102,9 @@ Database SchemaMeta::GetDataBase(const std::string &storeId) } return {}; } + +bool SchemaMeta::IsValid() const +{ + return !bundleName.empty() && !databases.empty(); +} } // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/framework/cloud/sync_event.cpp b/services/distributeddataservice/framework/cloud/sync_event.cpp new file mode 100644 index 00000000..814b9681 --- /dev/null +++ b/services/distributeddataservice/framework/cloud/sync_event.cpp @@ -0,0 +1,71 @@ +/* + * 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 "cloud/sync_event.h" + +#include +namespace OHOS::DistributedData { +SyncEvent::EventInfo::EventInfo(int32_t mode, int32_t wait, std::shared_ptr query, GenAsync async) + : mode_(mode), wait_(wait), query_(std::move(query)), asyncDetail_(std::move(async)) +{ +} + +SyncEvent::EventInfo::EventInfo(SyncEvent::EventInfo &&info) noexcept +{ + operator=(std::move(info)); +} + +SyncEvent::EventInfo &SyncEvent::EventInfo::operator=(SyncEvent::EventInfo &&info) noexcept +{ + if (this == &info) { + return *this; + } + mode_ = info.mode_; + wait_ = info.wait_; + query_ = std::move(info.query_); + asyncDetail_ = std::move(info.asyncDetail_); + return *this; +} + +SyncEvent::SyncEvent(StoreInfo storeInfo, EventInfo info) + : CloudEvent(CLOUD_SYNC, std::move(storeInfo)), info_(std::move(info)) +{ +} + +SyncEvent::SyncEvent(int32_t evtId, StoreInfo storeInfo, EventInfo info) + : CloudEvent(evtId, std::move(storeInfo)), info_(std::move(info)) +{ +} + +int32_t SyncEvent::GetMode() const +{ + return info_.mode_; +} + +int32_t SyncEvent::GetWait() const +{ + return info_.wait_; +} + +std::shared_ptr SyncEvent::GetQuery() const +{ + return info_.query_; +} + +GenAsync SyncEvent::GetAsyncDetail() const +{ + return info_.asyncDetail_; +} +} // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/cloud/change_event.h b/services/distributeddataservice/framework/include/cloud/change_event.h new file mode 100644 index 00000000..b0b4e87a --- /dev/null +++ b/services/distributeddataservice/framework/include/cloud/change_event.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CHANGE_EVENT_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CHANGE_EVENT_H +#include "cloud/sync_event.h" +#include "store/general_value.h" +namespace OHOS::DistributedData { +class API_EXPORT ChangeEvent : public SyncEvent { +public: + ChangeEvent(StoreInfo storeInfo, EventInfo info) + : SyncEvent(LOCAL_CHANGE, std::move(storeInfo), std::move(info)) + { + }; + ~ChangeEvent() override = default; +}; +} // namespace OHOS::DistributedData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CHANGE_EVENT_H diff --git a/services/distributeddataservice/framework/include/cloud/cloud_info.h b/services/distributeddataservice/framework/include/cloud/cloud_info.h index dc732027..e27bae75 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_info.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_info.h @@ -35,14 +35,16 @@ public: uint64_t totalSpace = 0; uint64_t remainSpace = 0; bool enableCloud = false; - std::vector apps; + std::map apps; std::string GetKey() const; std::map GetSchemaKey() const; - std::string GetSchemaKey(const std::string &bundleName, const int32_t instanceId = 0) const; + std::string GetSchemaKey(const std::string &bundleName, int32_t instanceId = 0) const; + std::string GetSchemaPrefix(const std::string &bundleName) const; static std::string GetSchemaKey(const StoreMetaData &meta); bool IsValid() const; - bool IsExist(const std::string &bundleName) const; + bool Exist(const std::string &bundleName, int32_t instanceId = 0); + bool IsOn(const std::string &bundleName, int32_t instanceId = 0); static std::string GetPrefix(const std::initializer_list &field); bool Marshal(json &node) const override; diff --git a/services/distributeddataservice/framework/include/cloud/schema_meta.h b/services/distributeddataservice/framework/include/cloud/schema_meta.h index d2064961..49c15e18 100644 --- a/services/distributeddataservice/framework/include/cloud/schema_meta.h +++ b/services/distributeddataservice/framework/include/cloud/schema_meta.h @@ -39,7 +39,7 @@ struct API_EXPORT Database final : public Serializable { std::string name = ""; std::string alias; std::vector
tables; - + std::vector GetTableNames() const; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; }; @@ -55,10 +55,12 @@ public: static constexpr const char *MODIFY_FIELD = "#_modifyTime"; static constexpr const char *CURSOR_FIELD = "#_cursor"; int32_t version = 0; + std::string bundleName; std::vector databases; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; + bool IsValid() const; Database GetDataBase(const std::string &storeId); }; } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/framework/include/cloud/sync_event.h b/services/distributeddataservice/framework/include/cloud/sync_event.h new file mode 100644 index 00000000..b5b81202 --- /dev/null +++ b/services/distributeddataservice/framework/include/cloud/sync_event.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SYNC_EVENT_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SYNC_EVENT_H +#include "cloud/cloud_event.h" +#include "store/general_value.h" +#include "visibility.h" +namespace OHOS::DistributedData { +class API_EXPORT SyncEvent : public CloudEvent { +public: + class EventInfo { + public: + API_EXPORT EventInfo(int32_t mode, int32_t wait, std::shared_ptr query, GenAsync async); + API_EXPORT EventInfo(EventInfo &&info) noexcept; + EventInfo(const EventInfo &info) = default; + API_EXPORT EventInfo &operator=(EventInfo &&info) noexcept; + EventInfo &operator=(const EventInfo &info) = default; + private: + friend SyncEvent; + int32_t mode_ = -1; + int32_t wait_ = 0; + std::shared_ptr query_; + GenAsync asyncDetail_; + }; + SyncEvent(StoreInfo storeInfo, EventInfo info); + ~SyncEvent() override = default; + int32_t GetMode() const; + int32_t GetWait() const; + std::shared_ptr GetQuery() const; + GenAsync GetAsyncDetail() const; + +protected: + SyncEvent(int32_t evtId, StoreInfo storeInfo, EventInfo info); + +private: + EventInfo info_; +}; +} + +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SYNC_EVENT_H diff --git a/services/distributeddataservice/framework/include/error/general_error.h b/services/distributeddataservice/framework/include/error/general_error.h index 27ec5595..56fc4a8f 100644 --- a/services/distributeddataservice/framework/include/error/general_error.h +++ b/services/distributeddataservice/framework/include/error/general_error.h @@ -27,6 +27,7 @@ enum GeneralError : int32_t { E_ALREADY_CLOSED, E_UNOPENED, E_RETRY_TIMEOUT, + E_ALREADY_LOCKED, E_BUTT, }; } diff --git a/services/distributeddataservice/framework/include/store/cursor.h b/services/distributeddataservice/framework/include/store/cursor.h index e588c5fd..a631122e 100644 --- a/services/distributeddataservice/framework/include/store/cursor.h +++ b/services/distributeddataservice/framework/include/store/cursor.h @@ -46,6 +46,8 @@ public: virtual int32_t Get(const std::string &col, Value &value) = 0; virtual int32_t Close() = 0; + + virtual bool IsEnd() = 0; }; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_CURSOR_H diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index ad7985ea..fc52bd8d 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -35,7 +35,7 @@ public: NEARBY_PUSH = NEARBY_BEGIN, NEARBY_PULL, NEARBY_PULL_PUSH, - NEARBY_END, + NEARBY_END = 4, CLOUD_BEGIN = NEARBY_END, CLOUD_TIME_FIRST = CLOUD_BEGIN, CLOUD_NATIVE_FIRST, @@ -56,6 +56,8 @@ public: virtual int32_t Bind(const Database &database, BindInfo bindInfo) = 0; + virtual bool IsBound() = 0; + virtual int32_t Execute(const std::string &table, const std::string &sql) = 0; virtual int32_t BatchInsert(const std::string &table, VBuckets &&values) = 0; diff --git a/services/distributeddataservice/service/kvdb/ref_count.h b/services/distributeddataservice/framework/include/utils/ref_count.h similarity index 95% rename from services/distributeddataservice/service/kvdb/ref_count.h rename to services/distributeddataservice/framework/include/utils/ref_count.h index 3ec72fe4..f5522d85 100644 --- a/services/distributeddataservice/service/kvdb/ref_count.h +++ b/services/distributeddataservice/framework/include/utils/ref_count.h @@ -18,7 +18,7 @@ #include #include #include -namespace OHOS::DistributedKv { +namespace OHOS::DistributedData { class RefCount final { public: RefCount(); @@ -27,7 +27,7 @@ public: RefCount(RefCount &&other) noexcept; RefCount &operator=(const RefCount &other); RefCount &operator=(RefCount &&other) noexcept; - operator bool() const; + operator bool () const; private: std::shared_ptr ref_; diff --git a/services/distributeddataservice/service/kvdb/ref_count.cpp b/services/distributeddataservice/framework/utils/ref_count.cpp similarity index 95% rename from services/distributeddataservice/service/kvdb/ref_count.cpp rename to services/distributeddataservice/framework/utils/ref_count.cpp index fb36dcdb..977c817e 100644 --- a/services/distributeddataservice/service/kvdb/ref_count.cpp +++ b/services/distributeddataservice/framework/utils/ref_count.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "ref_count.h" -namespace OHOS::DistributedKv { +#include "utils/ref_count.h" +namespace OHOS::DistributedData { RefCount::RefCount() { } diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 77641b8d..aaab31bc 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -58,6 +58,7 @@ ohos_shared_library("distributeddatasvc") { "bootstrap/src/bootstrap.cpp", "cloud/cloud_service_impl.cpp", "cloud/cloud_service_stub.cpp", + "cloud/sync_manager.cpp", "config/src/config_factory.cpp", "config/src/model/backup_config.cpp", "config/src/model/checker_config.cpp", @@ -74,7 +75,6 @@ ohos_shared_library("distributeddatasvc") { "kvdb/kvdb_service_stub.cpp", "kvdb/kvstore_sync_manager.cpp", "kvdb/query_helper.cpp", - "kvdb/ref_count.cpp", "kvdb/store_cache.cpp", "kvdb/upgrade.cpp", "kvdb/user_delegate.cpp", @@ -86,6 +86,8 @@ ohos_shared_library("distributeddatasvc") { "object/object_service_impl.cpp", "object/object_service_stub.cpp", "permission/src/permit_delegate.cpp", + "rdb/rdb_cloud.cpp", + "rdb/rdb_cursor.cpp", "rdb/rdb_general_store.cpp", "rdb/rdb_notifier_proxy.cpp", "rdb/rdb_query.cpp", @@ -96,6 +98,7 @@ ohos_shared_library("distributeddatasvc") { "rdb/rdb_store_observer_impl.cpp", "rdb/rdb_syncer.cpp", "rdb/rdb_watcher.cpp", + "rdb/value_proxy.cpp", ] cflags = [ "-Wno-multichar" ] diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 0c0d99b9..c0686642 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -19,16 +19,12 @@ #include "account/account_delegate.h" #include "checker/checker_manager.h" -#include "cloud/cloud_event.h" #include "cloud/cloud_server.h" -#include "cloud/subscription.h" #include "communicator/device_manager_adapter.h" #include "eventcenter/event_center.h" -#include "feature/feature_system.h" #include "ipc_skeleton.h" #include "log_print.h" #include "metadata/meta_data_manager.h" -#include "metadata/store_meta_data.h" #include "store/auto_cache.h" #include "utils/anonymous.h" namespace OHOS::CloudData { @@ -36,6 +32,12 @@ using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using Account = OHOS::DistributedKv::AccountDelegate; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; +const CloudServiceImpl::Work CloudServiceImpl::HANDLERS[WORK_BUTT] = { + &CloudServiceImpl::DoSubscribe, + &CloudServiceImpl::UpdateCloudInfo, + &CloudServiceImpl::UpdateSchema, +}; + CloudServiceImpl::Factory::Factory() noexcept { FeatureSystem::GetInstance().RegisterCreator( @@ -55,7 +57,6 @@ CloudServiceImpl::CloudServiceImpl() { EventCenter::GetInstance().Subscribe(CloudEvent::GET_SCHEMA, [this](const Event &event) { GetSchema(event); - return; }); } @@ -67,20 +68,17 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map bool { - return appInfo.bundleName == item.first; - }); - if (it == cloudInfo.apps.end()) { + for (const auto &[bundle, value] : switches) { + if (!cloudInfo.Exist(bundle)) { continue; } - it->cloudSwitch = item.second; + cloudInfo.apps[bundle].cloudSwitch = (value == SWITCH_ON); } if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } Execute(GetCloudTask(0, cloudInfo.user)); + syncManager_.DoCloudSync({ cloudInfo.user }); return SUCCESS; } @@ -96,6 +94,7 @@ int32_t CloudServiceImpl::DisableCloud(const std::string &id) return ERROR; } Execute(GetCloudTask(0, cloudInfo.user)); + syncManager_.StopCloudSync(cloudInfo.user); return SUCCESS; } @@ -106,19 +105,18 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri if (status != SUCCESS) { return status; } - auto it = std::find_if(cloudInfo.apps.begin(), cloudInfo.apps.end(), - [&bundleName](const CloudInfo::AppInfo &appInfo) -> bool { - return appInfo.bundleName == bundleName; - }); - if (it == cloudInfo.apps.end()) { + if (!cloudInfo.Exist(bundleName)) { ZLOGE("bundleName:%{public}s", bundleName.c_str()); return INVALID_ARGUMENT; } - (*it).cloudSwitch = appSwitch; + cloudInfo.apps[bundleName].cloudSwitch = (appSwitch == SWITCH_ON); if (!MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true)) { return ERROR; } Execute(GetCloudTask(0, cloudInfo.user)); + if (cloudInfo.enableCloud && appSwitch == SWITCH_ON) { + syncManager_.DoCloudSync({ cloudInfo.user, bundleName }); + } return SUCCESS; } @@ -130,13 +128,14 @@ int32_t CloudServiceImpl::Clean(const std::string &id, const std::map bool { - return appInfo.bundleName == bundleName; - }); - if (it == cloudInfo.apps.end()) { + if (!cloudInfo.Exist(bundleName)) { ZLOGE("bundleName:%{public}s", bundleName.c_str()); return INVALID_ARGUMENT; } - if (!it->cloudSwitch) { + if (!cloudInfo.apps[bundleName].cloudSwitch) { return CLOUD_DISABLE_SWITCH; } - auto key = cloudInfo.GetSchemaKey(bundleName); SchemaMeta schemaMeta; if (!MetaDataManager::GetInstance().LoadMeta(key, schemaMeta, true)) { ZLOGE("bundleName:%{public}s", bundleName.c_str()); return INVALID_ARGUMENT; } + const auto &app = cloudInfo.apps[bundleName]; for (const auto &database : schemaMeta.databases) { EventCenter::Defer defer; CloudEvent::StoreInfo storeInfo; - storeInfo.bundleName = it->bundleName; - storeInfo.instanceId = it->instanceId; + storeInfo.bundleName = app.bundleName; + storeInfo.instanceId = app.instanceId; storeInfo.user = cloudInfo.user; storeInfo.storeName = database.name; auto evt = std::make_unique(CloudEvent::DATA_CHANGE, storeInfo); EventCenter::GetInstance().PostEvent(std::move(evt)); } + syncManager_.DoCloudSync(SyncManager::SyncInfo(cloudInfo.user, bundleName)); return SUCCESS; } int32_t CloudServiceImpl::OnInitialize() { - FeatureInit(); - Execute(GetCloudTask(0, 0)); + Execute(GetCloudTask(0, 0, { WORK_CLOUD_INFO_UPDATE, WORK_SCHEMA_UPDATE })); return E_OK; } @@ -204,12 +199,17 @@ int32_t CloudServiceImpl::OnBind(const BindInfo &info) } executor_ = std::move(info.executors); + syncManager_.Bind(executor_); return E_OK; } int32_t CloudServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { - Execute(GetCloudTask(0, atoi(user.c_str()))); + int32_t userId = atoi(user.c_str()); + if (code == static_cast(DistributedKv::AccountStatus::DEVICE_ACCOUNT_SWITCHED)) { + Execute(GetCloudTask(0, userId, { WORK_CLOUD_INFO_UPDATE, WORK_SCHEMA_UPDATE })); + } + syncManager_.StopCloudSync(userId); return E_OK; } @@ -244,54 +244,92 @@ int32_t CloudServiceImpl::GetCloudInfoFromServer(CloudInfo &cloudInfo) { auto instance = CloudServer::GetInstance(); if (instance == nullptr) { + ZLOGW("cloud server unavailable"); return NOT_SUPPORT; } cloudInfo = instance->GetServerInfo(cloudInfo.user); - return cloudInfo.IsValid() ? SUCCESS : ERROR; + if (!cloudInfo.IsValid()) { + ZLOGE("cloud is empty, user%{public}d", cloudInfo.user); + return ERROR; + } + return SUCCESS; } -void CloudServiceImpl::UpdateCloudInfo(CloudInfo &cloudInfo) +bool CloudServiceImpl::UpdateCloudInfo(int32_t user) { + CloudInfo cloudInfo; + cloudInfo.user = user; + if (GetCloudInfoFromServer(cloudInfo) != SUCCESS) { + ZLOGE("failed, user:%{public}d", user); + return false; + } CloudInfo oldInfo; if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), oldInfo, true)) { MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); - return; + return true; } - oldInfo.totalSpace = cloudInfo.totalSpace; - oldInfo.remainSpace = cloudInfo.remainSpace; - oldInfo.apps = std::move(cloudInfo.apps); - cloudInfo = oldInfo; - MetaDataManager::GetInstance().SaveMeta(oldInfo.GetKey(), oldInfo, true); + if (oldInfo.id != cloudInfo.id) { + ZLOGE("different id, [server] id:%{public}s, [meta] id:%{public}s", + Anonymous::Change(cloudInfo.id).c_str(), Anonymous::Change(oldInfo.id).c_str()); + std::map actions; + for (auto &[bundle, app] : cloudInfo.apps) { + actions[bundle] = CLEAR_CLOUD_INFO; + } + Clean(oldInfo.id, actions); + } + + MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); + return true; } -void CloudServiceImpl::AddSchema(CloudInfo &cloudInfo) +bool CloudServiceImpl::UpdateSchema(int32_t user) { + CloudInfo cloudInfo; + cloudInfo.user = user; + if (GetCloudInfoFromServer(cloudInfo) != SUCCESS) { + ZLOGE("failed, user:%{public}d", user); + return false; + } auto keys = cloudInfo.GetSchemaKey(); - for (const auto &key : keys) { + for (const auto &[bundle, key] : keys) { SchemaMeta schemaMeta; - if (MetaDataManager::GetInstance().LoadMeta(key.second, schemaMeta, true)) { + if (MetaDataManager::GetInstance().LoadMeta(key, schemaMeta, true)) { continue; } - if (GetAppSchema(cloudInfo.user, key.first, schemaMeta) != SUCCESS) { - continue; + if (GetAppSchema(cloudInfo.user, bundle, schemaMeta) != SUCCESS) { + return false; } - MetaDataManager::GetInstance().SaveMeta(key.second, schemaMeta, true); + MetaDataManager::GetInstance().SaveMeta(key, schemaMeta, true); } + return true; } int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta) { auto instance = CloudServer::GetInstance(); if (instance == nullptr) { + ZLOGW("cloud server unavailable"); return SERVER_UNAVAILABLE; } schemaMeta = instance->GetAppSchema(user, bundleName); return SUCCESS; } -ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) +CloudServiceImpl::Tasks CloudServiceImpl::GetCloudTask( + int32_t retry, int32_t user, const std::initializer_list &works) +{ + Tasks tasks; + tasks.reserve(works.size() + 1); + for (auto work : works) { + tasks.push_back(GenTask(retry, user, work)); + } + tasks.push_back(GenTask(retry, user, WORK_SUB)); + return tasks; +} + +ExecutorPool::Task CloudServiceImpl::GenTask(int32_t retry, int32_t user, AsyncWork work) { - return [this, retry, user]() -> void { + return [this, retry, user, work]() -> void { auto executor = executor_; if (retry >= RETRY_TIMES || executor == nullptr) { return; @@ -300,19 +338,17 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) bool finished = true; std::vector users; if (user == 0) { - finished = Account::GetInstance()->QueryUsers(users); + auto account = Account::GetInstance(); + finished = account == nullptr ? false : account->QueryUsers(users); } else { users.push_back(user); } for (auto user : users) { - Subscription subscription; - subscription.userId = user; - MetaDataManager::GetInstance().LoadMeta(subscription.GetKey(), subscription, true); - finished = DoSubscribe(subscription) && finished; + finished = (this->*HANDLERS[work])(user) && finished; } if (!finished) { - executor->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1, user)); + executor->Schedule(std::chrono::seconds(RETRY_INTERVAL), GenTask(retry + 1, user, work)); } }; } @@ -320,127 +356,70 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry, int32_t user) SchemaMeta CloudServiceImpl::GetSchemaMeta(int32_t userId, const std::string &bundleName, int32_t instanceId) { SchemaMeta schemaMeta; - CloudInfo cloudInfo; - cloudInfo.user = userId; - if (!MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("instance is nullptr"); - return schemaMeta; - } - cloudInfo = instance->GetServerInfo(userId); - if (!cloudInfo.IsValid()) { - ZLOGE("cloudInfo is invalid"); - return schemaMeta; - } - MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); + CloudInfo cloudInfo = GetCloudInfo(userId); + if (!cloudInfo.IsValid()) { + // GetCloudInfo has print the log info. so we don`t need print again. + return schemaMeta; } - if (std::find_if(cloudInfo.apps.begin(), cloudInfo.apps.end(), - [&bundleName, &instanceId](const CloudInfo::AppInfo &appInfo) { - return appInfo.bundleName == bundleName && appInfo.instanceId == instanceId; - }) == cloudInfo.apps.end()) { - ZLOGE("bundleName:%{public}s instanceId:%{public}d", bundleName.c_str(), instanceId); + + if (!bundleName.empty() && !cloudInfo.Exist(bundleName, instanceId)) { + ZLOGD("bundleName:%{public}s instanceId:%{public}d is not exist", bundleName.c_str(), instanceId); return schemaMeta; } std::string schemaKey = cloudInfo.GetSchemaKey(bundleName, instanceId); - if (!MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true)) { - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("instance is nullptr"); - return schemaMeta; - } - schemaMeta = instance->GetAppSchema(cloudInfo.user, bundleName); - MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); + if (MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true)) { + return schemaMeta; } - return schemaMeta; -} -StoreMetaData CloudServiceImpl::GetStoreMeta(int32_t userId, const std::string &bundleName, - const std::string &storeName, int32_t instanceId) -{ - StoreMetaData storeMetaData; - storeMetaData.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; - storeMetaData.user = std::to_string(userId); - storeMetaData.bundleName = bundleName; - storeMetaData.storeId = storeName; - storeMetaData.instanceId = instanceId; - MetaDataManager::GetInstance().LoadMeta(storeMetaData.GetKey(), storeMetaData); - return storeMetaData; + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGE("instance is nullptr"); + return schemaMeta; + } + schemaMeta = instance->GetAppSchema(userId, bundleName); + if (!schemaMeta.IsValid()) { + ZLOGE("download schema from cloud failed, user:%{public}s, bundleName:%{public}s", userId, bundleName.c_str()); + } + MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); + return schemaMeta; } -void CloudServiceImpl::FeatureInit() -{ +CloudInfo CloudServiceImpl::GetCloudInfo(int32_t userId) { CloudInfo cloudInfo; - std::vector users; - if (!DistributedKv::AccountDelegate::GetInstance()->QueryUsers(users) || users.empty()) { - return; + cloudInfo.user = userId; + if (MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { + return cloudInfo; } - for (const auto &user : users) { - if (user == USER_ID) { - continue; - } - cloudInfo.user = user; - if (GetCloudInfoFromServer(cloudInfo) != SUCCESS) { - ZLOGE("failed, user:%{public}d", user); - continue; - } - UpdateCloudInfo(cloudInfo); - AddSchema(cloudInfo); + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGD("no cloud server"); + return cloudInfo; } + + cloudInfo = instance->GetServerInfo(userId); + if (!cloudInfo.IsValid()) { + ZLOGE("no cloud info %{public}d", userId); + return cloudInfo; + } + + MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); + return cloudInfo; } void CloudServiceImpl::GetSchema(const Event &event) { auto &rdbEvent = static_cast(event); + auto &storeInfo = rdbEvent.GetStoreInfo(); ZLOGD("Start GetSchema, bundleName:%{public}s, storeName:%{public}s, instanceId:%{public}d", - rdbEvent.GetStoreInfo().bundleName.c_str(), rdbEvent.GetStoreInfo().storeName.c_str(), - rdbEvent.GetStoreInfo().instanceId); - auto userId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); - auto schemaMeta = GetSchemaMeta(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().instanceId); - if (schemaMeta.databases.empty()) { - ZLOGD("bundleName:%{public}s no cloud database", rdbEvent.GetStoreInfo().bundleName.c_str()); - return; - } - auto database = - std::find_if(schemaMeta.databases.begin(), schemaMeta.databases.end(), [&rdbEvent](const auto &database) { - return database.name == rdbEvent.GetStoreInfo().storeName; - }); - if (database == schemaMeta.databases.end()) { - ZLOGD("database: %{public}s is not cloud database", database->name.c_str()); - return; - } - - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGE("instance is nullptr"); - return; - } - ZLOGD("database: %{public}s sync start", database->name.c_str()); - auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, *database); - if (cloudDB == nullptr) { - ZLOGE("cloudDB is nullptr, bundleName:%{public}s user:%{public}d database:%{public}s", - rdbEvent.GetStoreInfo().bundleName.c_str(), rdbEvent.GetStoreInfo().user, database->name.c_str()); - return; - } - - auto storeMeta = GetStoreMeta(userId, rdbEvent.GetStoreInfo().bundleName, rdbEvent.GetStoreInfo().storeName, - rdbEvent.GetStoreInfo().instanceId); - AutoCache::Watchers watchers; - auto store = AutoCache::GetInstance().GetStore(storeMeta, watchers); - if (store == nullptr) { - ZLOGE("store is nullptr"); - return; - } - store->Bind(*database, cloudDB); - for (const auto &table : database->tables) { - ZLOGD("table: %{public}s sync start", table.name.c_str()); - // do sync - } - return; + storeInfo.bundleName.c_str(), storeInfo.storeName.c_str(), storeInfo.instanceId); + GetSchemaMeta(storeInfo.user, storeInfo.bundleName, storeInfo.instanceId); } -bool CloudServiceImpl::DoSubscribe(const Subscription &sub) +bool CloudServiceImpl::DoSubscribe(int32_t user) { + Subscription sub; + sub.userId = user; + MetaDataManager::GetInstance().LoadMeta(sub.GetKey(), sub, true); if (CloudServer::GetInstance() == nullptr) { ZLOGI("not support cloud server"); return true; @@ -460,23 +439,23 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &sub) auto offThreshold = std::chrono::system_clock::now().time_since_epoch(); std::map> subDbs; std::map> unsubDbs; - for (auto &app : cloudInfo.apps) { + for (auto &[bundle, app] : cloudInfo.apps) { auto enabled = cloudInfo.enableCloud && app.cloudSwitch; - auto it = sub.expiresTime.find(app.bundleName); + auto &dbs = enabled ? subDbs : unsubDbs; + auto it = sub.expiresTime.find(bundle); // cloud is enabled, but the subscription won't expire - if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count()))) { + if (enabled && (it != sub.expiresTime.end() && it->second >= onThreshold.count())) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. - if (!enabled && (it == sub.expiresTime.end() || it->second <= static_cast(offThreshold.count()))) { + if (!enabled && (it == sub.expiresTime.end() || it->second <= offThreshold.count())) { continue; } SchemaMeta schemaMeta; - exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(app.bundleName), schemaMeta, true); + exits = MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(bundle), schemaMeta, true); if (exits) { - auto &dbs = enabled ? subDbs : unsubDbs; - dbs[app.bundleName] = std::move(schemaMeta.databases); + dbs.insert_or_assign(bundle, std::move(schemaMeta.databases)); } } @@ -489,12 +468,14 @@ bool CloudServiceImpl::DoSubscribe(const Subscription &sub) return subDbs.empty() && unsubDbs.empty(); } -void CloudServiceImpl::Execute(ExecutorPool::Task task) +void CloudServiceImpl::Execute(Tasks tasks) { - auto executor = executor_; - if (executor == nullptr) { - return; + for (auto &task : tasks) { + auto executor = executor_; + if (executor == nullptr) { + return; + } + executor->Execute(std::move(task)); } - executor->Execute(std::move(task)); } } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index deb10b37..7bdbfe21 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -17,12 +17,12 @@ #define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_CLOUD_SERVICE_IMPL_H #include -#include "cloud_service_stub.h" +#include "cloud/cloud_event.h" #include "cloud/cloud_info.h" #include "cloud/schema_meta.h" -#include "cloud/cloud_event.h" #include "cloud/subscription.h" - +#include "cloud_service_stub.h" +#include "sync_manager.h" namespace OHOS::CloudData { class CloudServiceImpl : public CloudServiceStub { public: @@ -39,7 +39,6 @@ public: int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; private: - static const inline int USER_ID = 0; class Factory { public: Factory() noexcept; @@ -53,26 +52,36 @@ private: using SchemaMeta = DistributedData::SchemaMeta; using Event = DistributedData::Event; using Subscription = DistributedData::Subscription; + using Work = bool (CloudServiceImpl::*)(int32_t); + using Tasks = std::vector; + + enum AsyncWork : int32_t { + WORK_SUB = 0, + WORK_CLOUD_INFO_UPDATE, + WORK_SCHEMA_UPDATE, + WORK_BUTT, + }; static constexpr int32_t RETRY_TIMES = 10; static constexpr int32_t RETRY_INTERVAL = 30; static constexpr int32_t EXPIRE_INTERVAL = 7 * 24; // 7 day - void UpdateCloudInfo(CloudInfo &cloudInfo); - void AddSchema(CloudInfo &cloudInfo); + bool UpdateCloudInfo(int32_t user); + bool UpdateSchema(int32_t user); SchemaMeta GetSchemaMeta(int32_t userId, const std::string &bundleName, int32_t instanceId); - StoreMetaData GetStoreMeta(int32_t userId, const std::string &bundleName, const std::string &storeName, - int32_t instanceId); + CloudInfo GetCloudInfo(int32_t userId); int32_t GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo); int32_t GetCloudInfoFromMeta(CloudInfo &cloudInfo); int32_t GetCloudInfoFromServer(CloudInfo &cloudInfo); int32_t GetAppSchema(int32_t user, const std::string &bundleName, SchemaMeta &schemaMeta); - void FeatureInit(); void GetSchema(const Event &event); - ExecutorPool::Task GetCloudTask(int32_t retry, int32_t user); - void Execute(ExecutorPool::Task task); - bool DoSubscribe(const Subscription &sub); + Tasks GetCloudTask(int32_t retry, int32_t user, const std::initializer_list &works = {}); + ExecutorPool::Task GenTask(int32_t retry, int32_t user, AsyncWork work); + void Execute(Tasks tasks); + bool DoSubscribe(int32_t user); std::shared_ptr executor_; + SyncManager syncManager_; + static const Work HANDLERS[WORK_BUTT]; }; } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp new file mode 100644 index 00000000..f55515a7 --- /dev/null +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -0,0 +1,305 @@ +/* + * 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. + */ +#define LOG_TAG "SyncManager" +#include "sync_manager.h" + +#include "cloud/cloud_info.h" +#include "cloud/schema_meta.h" +#include "cloud/sync_event.h" +#include "device_manager_adapter.h" +#include "eventcenter/event_center.h" +#include "log_print.h" +#include "metadata/meta_data_manager.h" +#include "store/auto_cache.h" +#include "cloud/cloud_server.h" +namespace OHOS::CloudData { +using namespace DistributedData; +using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +SyncManager::SyncInfo::SyncInfo(int32_t user, const std::string &bundleName, const Store &store, const Tables &tables) + : user_(user), bundleName_(bundleName) +{ + if (!store.empty()) { + tables_[store] = tables; + } +} + +SyncManager::SyncInfo::SyncInfo(int32_t user, const std::string &bundleName, const Stores &stores) + : user_(user), bundleName_(bundleName) +{ + for (auto &store : stores) { + tables_[store] = {}; + } +} + +SyncManager::SyncInfo::SyncInfo(int32_t user, const std::string &bundleName, const MutliStoreTables &tables) + : user_(user), bundleName_(bundleName) +{ + tables_ = tables; +} + +void SyncManager::SyncInfo::SetMode(int32_t mode) +{ + mode_ = mode; +} + +void SyncManager::SyncInfo::SetWait(int32_t wait) +{ + wait_ = wait; +} + +void SyncManager::SyncInfo::SetAsyncDetail(GenAsync asyncDetail) +{ + async_ = std::move(asyncDetail); +} + +void SyncManager::SyncInfo::SetQuery(std::shared_ptr query) +{ + query_ = query; +} + +void SyncManager::SyncInfo::SetError(int32_t code) +{ + if (async_) { + GenDetails details; + auto &detail = details[id_]; + detail.progress = SYNC_FINISH; + detail.code = code; + async_(std::move(details)); + } +} + +std::shared_ptr SyncManager::SyncInfo::GenerateQuery(const std::string &store, const Tables &tables) +{ + if (query_ != nullptr) { + return query_; + } + class SyncQuery final : public GenQuery { + public: + SyncQuery(const std::vector &tables) : tables_(tables){}; + bool IsEqual(uint64_t tid) override + { + return false; + } + + std::vector GetTables() override + { + return tables_; + } + + private: + std::vector tables_; + }; + auto &syncTables = tables_[store]; + return std::make_shared(syncTables.empty() ? tables : syncTables); +} + +SyncManager::SyncManager() +{ + EventCenter::GetInstance().Subscribe(CloudEvent::LOCAL_CHANGE, GetClientChangeHandler()); +} + +SyncManager::~SyncManager() +{ + if (executor_ != nullptr) { + actives_.ForEachCopies([this](auto &syncId, auto &taskId) { + executor_->Remove(taskId); + return false; + }); + executor_ = nullptr; + } +} + +int32_t SyncManager::Bind(std::shared_ptr executor) +{ + executor_ = executor; + return E_OK; +} + +int32_t SyncManager::DoCloudSync(SyncInfo syncInfo) +{ + if (executor_ == nullptr) { + return E_NOT_INIT; + } + + actives_.Compute(GenSyncId(syncInfo.user_), [this, &syncInfo](const uint64_t &key, TaskId &taskId) mutable { + taskId = executor_->Execute(GetSyncTask(0, GenSyncRef(key), std::move(syncInfo))); + return true; + }); + + return E_OK; +} + +int32_t SyncManager::StopCloudSync(int32_t user) +{ + if (executor_ == nullptr) { + return E_NOT_INIT; + } + actives_.ForEachCopies([this, user](auto &syncId, auto &taskId) { + if (Compare(syncId, user) == 0) { + executor_->Remove(taskId); + } + return false; + }); + return E_OK; +} + +ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInfo &&syncInfo) +{ + retry++; + return [this, retry, ref = std::move(ref), info = std::move(syncInfo)]() mutable { + EventCenter::Defer defer(GetSyncHandler(), CloudEvent::CLOUD_SYNC); + CloudInfo cloud; + cloud.user = info.user_; + if (!MetaDataManager::GetInstance().LoadMeta(cloud.GetKey(), cloud, true)) { + info.SetError(E_NOT_INIT); + ZLOGE("no cloud info for user:%{public}d", info.user_); + return; + } + + if (!cloud.enableCloud || cloud.id != info.id_ || (!info.bundleName_.empty() && !cloud.IsOn(info.bundleName_))) { + info.SetError(E_UNOPENED); + ZLOGI("cloud off bundleName:%{public}s", info.bundleName_.c_str()); + return; + } + + std::vector schemas; + auto key = cloud.GetSchemaPrefix(info.bundleName_); + if (!MetaDataManager::GetInstance().LoadMeta(key, schemas, true)) { + DoRetry(retry, std::move(info)); + return; + } + + for (auto &schema : schemas) { + if (!cloud.IsOn(schema.bundleName)) { + continue; + } + + for (const auto &database : schema.databases) { + CloudEvent::StoreInfo storeInfo; + storeInfo.bundleName = schema.bundleName; + storeInfo.user = cloud.user; + storeInfo.storeName = database.name; + auto query = info.GenerateQuery(database.name, database.GetTableNames()); + auto evt = std::make_unique(std::move(storeInfo), + SyncEvent::EventInfo{ info.mode_, info.wait_, std::move(query), info.async_ }); + EventCenter::GetInstance().PostEvent(std::move(evt)); + } + } + }; +} + +std::function SyncManager::GetSyncHandler() +{ + return [](const Event &event) { + auto &evt = static_cast(event); + auto &storeInfo = evt.GetStoreInfo(); + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGD("not support cloud sync"); + return; + } + + StoreMetaData meta; + meta.storeId = storeInfo.storeName; + meta.bundleName = storeInfo.bundleName; + meta.user = std::to_string(storeInfo.user); + meta.instanceId = storeInfo.instanceId; + meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; + if (!MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)) { + ZLOGE("failed, no store meta bundleName:%{public}s, storeId:%{public}s", meta.bundleName.c_str(), + meta.storeId.c_str()); + return; + } + auto store = AutoCache::GetInstance().GetStore(meta, {}); + if (store == nullptr) { + ZLOGE("store null, storeId:%{public}s", meta.storeId.c_str()); + return; + } + + if (!store->IsBound()) { + CloudInfo info; + info.user = storeInfo.user; + SchemaMeta schemaMeta; + std::string schemaKey = info.GetSchemaKey(storeInfo.bundleName, storeInfo.instanceId); + if (!MetaDataManager::GetInstance().LoadMeta(std::move(schemaKey), schemaMeta, true)) { + ZLOGE("failed, no schema bundleName:%{public}s, storeId:%{public}s", storeInfo.bundleName.c_str(), + storeInfo.storeName.c_str()); + return; + } + auto dbMeta = schemaMeta.GetDataBase(storeInfo.storeName); + auto cloudDB = instance->ConnectCloudDB(storeInfo.tokenId, dbMeta); + if (cloudDB == nullptr) { + ZLOGE("failed, no cloud DB <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, + dbMeta.name.c_str(), dbMeta.alias.c_str()); + return; + } + store->Bind(dbMeta, std::move(cloudDB)); + } + ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), + storeInfo.storeName.c_str()); + store->Sync({ "default" }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); + }; +} + +std::function SyncManager::GetClientChangeHandler() +{ + return [this](const Event &event) { + auto &evt = static_cast(event); + auto store = evt.GetStoreInfo(); + SyncInfo syncInfo(store.user, store.bundleName, store.storeName); + syncInfo.SetMode(evt.GetMode()); + syncInfo.SetWait(evt.GetWait()); + syncInfo.SetAsyncDetail(evt.GetAsyncDetail()); + syncInfo.SetQuery(evt.GetQuery()); + auto task = GetSyncTask(RETRY_TIMES, RefCount(), std::move(syncInfo)); + task(); + }; +} + +uint64_t SyncManager::GenSyncId(int32_t user) +{ + uint64_t syncId = user; + return (syncId << 32) | (++syncId_); +} + +RefCount SyncManager::GenSyncRef(uint64_t syncId) +{ + return RefCount([syncId, this]() { + actives_.Erase(syncId); + }); +} + +int32_t SyncManager::Compare(uint64_t syncId, int32_t user) +{ + uint64_t inner = user; + return (syncId & USER_MARK) == (inner << 32); +} + +void SyncManager::DoRetry(int32_t retry, SyncInfo &&info) +{ + CloudEvent::StoreInfo storeInfo; + storeInfo.user = info.user_; + storeInfo.bundleName = info.bundleName_; + EventCenter::GetInstance().PostEvent(std::make_unique(CloudEvent::GET_SCHEMA, storeInfo)); + if (retry > RETRY_TIMES) { + info.SetError(E_RETRY_TIMEOUT); + return; + } + actives_.Compute(GenSyncId(info.user_), [this, retry, &info](const uint64_t &key, TaskId &value) mutable { + value = executor_->Schedule(RETRY_INTERVAL, GetSyncTask(retry, GenSyncRef(key), std::move(info))); + return true; + }); +} +} // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h new file mode 100644 index 00000000..a7333898 --- /dev/null +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -0,0 +1,85 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_SYNC_MANAGER_H +#define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_SYNC_MANAGER_H +#include "eventcenter/event.h" +#include "executor_pool.h" +#include "store/general_store.h" +#include "store/general_value.h" +#include "utils/ref_count.h" +#include "concurrent_map.h" +namespace OHOS::CloudData { +class SyncManager { +public: + using GenAsync = DistributedData::GenAsync; + using GenStore = DistributedData::GeneralStore; + using GenQuery = DistributedData::GenQuery; + using RefCount = DistributedData::RefCount; + class SyncInfo final { + public: + using Store = std::string; + using Stores = std::vector; + using Tables = std::vector; + using MutliStoreTables = std::map; + SyncInfo(int32_t user, const std::string &bundleName = "", const Store &store = "", const Tables &tables = {}); + SyncInfo(int32_t user, const std::string &bundleName, const Stores &stores); + SyncInfo(int32_t user, const std::string &bundleName, const MutliStoreTables &tables); + void SetMode(int32_t mode); + void SetWait(int32_t wait); + void SetAsyncDetail(GenAsync asyncDetail); + void SetQuery(std::shared_ptr query); + void SetError(int32_t code); + std::shared_ptr GenerateQuery(const std::string &store, const Tables &tables); + + private: + friend SyncManager; + int32_t mode_ = GenStore::CLOUD_TIME_FIRST; + int32_t user_ = 0; + int32_t wait_ = 0; + std::string id_ = "default"; + std::string bundleName_; + std::map> tables_; + GenAsync async_; + std::shared_ptr query_; + }; + SyncManager(); + ~SyncManager(); + int32_t Bind(std::shared_ptr executor); + int32_t DoCloudSync(SyncInfo syncInfo); + int32_t StopCloudSync(int32_t user = 0); + +private: + using Event = DistributedData::Event; + using Task = ExecutorPool::Task; + using TaskId = ExecutorPool::TaskId; + static constexpr ExecutorPool::Duration RETRY_INTERVAL = std::chrono::seconds(10); // second + static constexpr int32_t RETRY_TIMES = 6; // second + static constexpr uint64_t USER_MARK = 0xFFFFFFFF00000000; // high 32 bit + + Task GetSyncTask(int32_t retry, RefCount ref, SyncInfo &&syncInfo); + void DoRetry(int32_t retry, SyncInfo &&syncInfo); + std::function GetSyncHandler(); + std::function GetClientChangeHandler(); + uint64_t GenSyncId(int32_t user); + RefCount GenSyncRef(uint64_t syncId); + int32_t Compare(uint64_t syncId, int32_t user); + + std::atomic syncId_ = 0; + std::shared_ptr executor_; + ConcurrentMap actives_; +}; +} // namespace OHOS::CloudData +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_SYNC_MANAGER_H diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index 861cd068..d41b5aad 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -26,12 +26,13 @@ #include "metadata/store_meta_data.h" #include "metadata/store_meta_data_local.h" #include "metadata/strategy_meta_data.h" -#include "ref_count.h" +#include "utils/ref_count.h" #include "store_cache.h" namespace OHOS::DistributedKv { class API_EXPORT KVDBServiceImpl final : public KVDBServiceStub { public: using DBLaunchParam = DistributedDB::AutoLaunchParam; + using RefCount = DistributedData::RefCount; API_EXPORT KVDBServiceImpl(); virtual ~KVDBServiceImpl(); Status GetStoreIds(const AppId &appId, std::vector &storeIds) override; diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp new file mode 100644 index 00000000..1724e1ba --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -0,0 +1,127 @@ +/* + * 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. + */ + +#define LOG_TAG "RdbCloud" +#include "rdb_cloud.h" +#include "log_print.h" +#include "value_proxy.h" + +namespace OHOS::DistributedRdb { +using namespace DistributedDB; +using namespace DistributedData; +RdbCloud::RdbCloud(std::shared_ptr cloudDB) + : cloudDB_(std::move(cloudDB)) +{ +} + +DBStatus RdbCloud::BatchInsert( + const std::string &tableName, std::vector &&record, std::vector &extend) +{ + DistributedData::VBuckets extends; + auto error = cloudDB_->BatchInsert(tableName, ValueProxy::Convert(std::move(record)), extends); + if (error == GeneralError::E_OK) { + extend = ValueProxy::Convert(std::move(extends)); + } + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbCloud::BatchUpdate( + const std::string &tableName, std::vector &&record, std::vector &extend) +{ + auto error = cloudDB_->BatchUpdate( + tableName, ValueProxy::Convert(std::move(record)), ValueProxy::Convert(std::move(extend))); + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbCloud::BatchDelete(const std::string &tableName, std::vector &extend) +{ + auto error = cloudDB_->BatchDelete(tableName, ValueProxy::Convert(std::move(extend))); + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::vector &data) +{ + auto cursor = cloudDB_->Query(tableName, ValueProxy::Convert(std::move(extend))); + if (cursor == nullptr) { + ZLOGE("cursor is null, table:%{public}s, extend:%{public}zu", tableName.c_str(), extend.size()); + return ConvertStatus(static_cast(E_ERROR)); + } + int32_t count = cursor->GetCount(); + data.reserve(count); + auto err = cursor->MoveToFirst(); + while (err == E_OK && count > 0) { + DistributedData::VBucket entry; + err = cursor->GetEntry(entry); + if (err != E_OK) { + break; + } + data.emplace_back(ValueProxy::Convert(std::move(entry))); + err = cursor->MoveToNext(); + count--; + } + if (cursor->IsEnd()) { + ZLOGD("query end, table:%{public}s", tableName.c_str()); + return DBStatus::QUERY_END; + } + return ConvertStatus(static_cast(err)); +} + +std::pair RdbCloud::Lock() +{ + auto error = cloudDB_->Lock(); + return std::make_pair(ConvertStatus(static_cast(error)), cloudDB_->AliveTime() * 1000); // int64_t <-> uint32_t, s <-> ms +} + +DBStatus RdbCloud::UnLock() +{ + auto error = cloudDB_->Unlock(); + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbCloud::HeartBeat() +{ + auto error = cloudDB_->Heartbeat(); + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbCloud::Close() +{ + auto error = cloudDB_->Close(); + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbCloud::ConvertStatus(DistributedData::GeneralError error) +{ + switch (error) { + case GeneralError::E_OK: + return DBStatus::OK; + case GeneralError::E_BUSY: + return DBStatus::BUSY; + case GeneralError::E_INVALID_ARGS: + return DBStatus::INVALID_ARGS; + case GeneralError::E_NOT_SUPPORT: + return DBStatus::NOT_SUPPORT; + case GeneralError::E_ERROR: // fallthrough + case GeneralError::E_NOT_INIT: + case GeneralError::E_ALREADY_CONSUMED: + case GeneralError::E_ALREADY_CLOSED: + return DBStatus::CLOUD_ERROR; + default: + ZLOGE("unknown error:0x%{public}x", error); + break; + } + return DBStatus::CLOUD_ERROR; +} +} // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.h b/services/distributeddataservice/service/rdb/rdb_cloud.h new file mode 100644 index 00000000..30e4ee59 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_cloud.h @@ -0,0 +1,47 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_H +#include "cloud/cloud_db.h" +#include "cloud/cloud_store_types.h" +#include "cloud/icloud_db.h" +#include "error/general_error.h" + +namespace OHOS::DistributedRdb { +class RdbCloud : public DistributedDB::ICloudDb { +public: + using DBStatus = DistributedDB::DBStatus; + using DBVBucket = DistributedDB::VBucket; + + explicit RdbCloud(std::shared_ptr cloudDB); + virtual ~RdbCloud() = default; + DBStatus BatchInsert(const std::string &tableName, std::vector &&record, + std::vector &extend) override; + DBStatus BatchUpdate(const std::string &tableName, std::vector &&record, + std::vector &extend) override; + DBStatus BatchDelete(const std::string &tableName, std::vector &extend) override; + DBStatus Query(const std::string &tableName, DBVBucket &extend, std::vector &data) override; + std::pair Lock() override; + DBStatus UnLock() override; + DBStatus HeartBeat() override; + DBStatus Close() override; + DBStatus ConvertStatus(DistributedData::GeneralError error); + +private: + std::shared_ptr cloudDB_; +}; +} // namespace OHOS::DistributedRdb +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_H diff --git a/services/distributeddataservice/service/rdb/rdb_cursor.cpp b/services/distributeddataservice/service/rdb/rdb_cursor.cpp new file mode 100644 index 00000000..619e7d3a --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_cursor.cpp @@ -0,0 +1,110 @@ +/* + * 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 "rdb_cursor.h" + +#include "rdb_general_store.h" +#include "result_set.h" +#include "value_proxy.h" +namespace OHOS::DistributedRdb { +using namespace OHOS::DistributedData; +RdbCursor::RdbCursor(std::shared_ptr resultSet) + : resultSet_(std::move(resultSet)) +{ +} + +RdbCursor::~RdbCursor() +{ + if (resultSet_) { + resultSet_->Close(); + } + resultSet_ = nullptr; +} + +int32_t RdbCursor::GetColumnNames(std::vector &names) const +{ + return resultSet_->GetAllColumnNames(names); +} + +int32_t RdbCursor::GetColumnName(int32_t col, std::string &name) const +{ + return resultSet_->GetColumnName(col, name); +} + +int32_t RdbCursor::GetColumnType(int32_t col) const +{ + NativeRdb::ColumnType columnType; + resultSet_->GetColumnType(col, columnType); + return int32_t(columnType); +} + +int32_t RdbCursor::GetCount() const +{ + int32_t count = -1; + resultSet_->GetRowCount(count); + return count; +} + +int32_t RdbCursor::MoveToFirst() +{ + return resultSet_->GoToFirstRow(); +} + +int32_t RdbCursor::MoveToNext() +{ + return resultSet_->GoToNextRow(); +} + +int32_t RdbCursor::GetEntry(VBucket &entry) +{ + return GetRow(entry); +} + +int32_t RdbCursor::GetRow(VBucket &data) +{ + NativeRdb::RowEntity bucket; + auto ret = resultSet_->GetRow(bucket); + data = ValueProxy::Convert(NativeRdb::ValuesBucket(bucket.Steal())); + return ret; +} + +int32_t RdbCursor::Get(int32_t col, Value &value) +{ + NativeRdb::ValueObject object; + auto ret = resultSet_->Get(col, object); + value = ValueProxy::Convert(std::move(object)); + return ret; +} + +int32_t RdbCursor::Get(const std::string &col, Value &value) +{ + int32_t index = -1; + auto ret = resultSet_->GetColumnIndex(col, index); + if (ret != NativeRdb::E_OK) { + return ret; + } + return Get(index, value); +} + +int32_t RdbCursor::Close() +{ + return resultSet_->Close(); +} + +bool RdbCursor::IsEnd() +{ + return false; +} +} // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_cursor.h b/services/distributeddataservice/service/rdb/rdb_cursor.h new file mode 100644 index 00000000..dd184d49 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_cursor.h @@ -0,0 +1,42 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CURSOR_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CURSOR_H +#include "store/cursor.h" +#include "result_set.h" +namespace OHOS::DistributedRdb { +class RdbCursor : public DistributedData::Cursor { +public: + explicit RdbCursor(std::shared_ptr resultSet); + ~RdbCursor(); + int32_t GetColumnNames(std::vector &names) const override; + int32_t GetColumnName(int32_t col, std::string &name) const override; + int32_t GetColumnType(int32_t col) const override; + int32_t GetCount() const override; + int32_t MoveToFirst() override; + int32_t MoveToNext() override; + int32_t GetEntry(DistributedData::VBucket &entry) override; + int32_t GetRow(DistributedData::VBucket &data) override; + int32_t Get(int32_t col, DistributedData::Value &value) override; + int32_t Get(const std::string &col, DistributedData::Value &value) override; + int32_t Close() override; + bool IsEnd() override; + +private: + std::shared_ptr resultSet_; +}; +} // namespace OHOS::DistributedRdb +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CURSOR_H diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 91d58fbb..bcb98824 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -22,10 +22,12 @@ #include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/secret_key_meta_data.h" +#include "rdb_cursor.h" #include "rdb_helper.h" #include "rdb_query.h" #include "rdb_syncer.h" #include "relational_store_manager.h" +#include "value_proxy.h" namespace OHOS::DistributedRdb { using namespace DistributedData; using namespace DistributedDB; @@ -47,6 +49,7 @@ public: RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appId, meta.user, meta.instanceId) { + observer_.storeId_ = meta.storeId; RelationalStoreDelegate::Option option; if (meta.isEncrypt) { std::string key = meta.GetSecretKey(); @@ -68,7 +71,7 @@ RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appI config.SetCreateNecessary(false); RdbOpenCallbackImpl callback; int32_t errCode = NativeRdb::E_OK; - store_ = RdbHelper::GetRdbStore(config, meta.version, callback, errCode); + store_ = RdbHelper::GetRdbStore(config, -1, callback, errCode); if (errCode != NativeRdb::E_OK) { ZLOGE("GetRdbStore failed, errCode is %{public}d, storeId is %{public}s", errCode, meta.storeId.c_str()); } @@ -82,12 +85,26 @@ RdbGeneralStore::~RdbGeneralStore() bindInfo_.loader_ = nullptr; bindInfo_.db_->Close(); bindInfo_.db_ = nullptr; + rdbCloud_ = nullptr; } int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) { + if (bindInfo.db_ == nullptr) { + return GeneralError::E_INVALID_ARGS; + } + + if (isBound_.exchange(true)) { + return GeneralError::E_OK; + } + bindInfo_ = std::move(bindInfo); - // SetCloudDB + rdbCloud_ = std::make_shared(bindInfo_.db_); + if (rdbCloud_ == nullptr) { + ZLOGE("rdb_cloudDb is null"); + return GeneralError::E_ERROR; + } + delegate_->SetCloudDB(rdbCloud_); DBSchema schema; schema.tables.resize(database.tables.size()); for (size_t i = 0; i < database.tables.size(); i++) { @@ -103,18 +120,27 @@ int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) dbTable.fields.push_back(std::move(dbField)); } } - // SetCloudDbSchema - return GeneralError::E_NOT_SUPPORT; + delegate_->SetCloudDbSchema(std::move(schema)); + return GeneralError::E_OK; +} + +bool RdbGeneralStore::IsBound() +{ + return isBound_; } int32_t RdbGeneralStore::Close() { - manager_.CloseStore(delegate_); + auto status = manager_.CloseStore(delegate_); + if (status != DBStatus::OK) { + return status; + } delegate_ = nullptr; store_ = nullptr; bindInfo_.loader_ = nullptr; bindInfo_.db_->Close(); bindInfo_.db_ = nullptr; + rdbCloud_ = nullptr; return 0; } @@ -150,16 +176,131 @@ std::shared_ptr RdbGeneralStore::Query(const std::string &table, GenQuer int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) { - return GeneralError::E_NOT_SUPPORT; + DistributedDB::Query dbQuery; + RdbQuery *rdbQuery = nullptr; + auto ret = query.QueryInterface(rdbQuery); + if (ret != GeneralError::E_OK || rdbQuery == nullptr) { + dbQuery.FromTable(query.GetTables()); + } else { + dbQuery = rdbQuery->query_; + } + auto dbMode = DistributedDB::SyncMode(mode); + auto status = (mode < CLOUD_BEGIN) + ? delegate_->Sync(devices, dbMode, dbQuery, GetDBBriefCB(std::move(async)), wait) + : delegate_->Sync(devices, dbMode, dbQuery, GetDBProcessCB(std::move(async)), wait); + // mock + if (observer_.HasWatcher()) { + Watcher::Origin origin; + origin.origin = (mode < CLOUD_BEGIN) ? Watcher::Origin::ORIGIN_NEARBY : Watcher::Origin::ORIGIN_CLOUD; + origin.id = devices; + origin.store = observer_.storeId_; + observer_.watcher_->OnChange(origin, {}, {}); + } + return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } int32_t RdbGeneralStore::Watch(int32_t origin, Watcher &watcher) { - return GeneralError::E_NOT_SUPPORT; + if (origin != Watcher::Origin::ORIGIN_ALL || observer_.watcher_ != nullptr) { + return GeneralError::E_INVALID_ARGS; + } + + observer_.watcher_ = &watcher; + return GeneralError::E_OK; } int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) { - return GeneralError::E_NOT_SUPPORT; + if (origin != Watcher::Origin::ORIGIN_ALL || observer_.watcher_ != &watcher) { + return GeneralError::E_INVALID_ARGS; + } + + observer_.watcher_ = nullptr; + return GeneralError::E_OK; +} + +RdbGeneralStore::DBBriefCB RdbGeneralStore::GetDBBriefCB(DetailAsync async) +{ + if (!async) { + return [](auto &) {}; + } + return [async = std::move(async)](const std::map> &result) { + DistributedData::GenDetails details; + for (auto &[key, tables] : result) { + auto &value = details[key]; + value.progress = FINISHED; + value.progress = GeneralError::E_OK; + for (auto &table : tables) { + if (table.status != DBStatus::OK) { + value.code = GeneralError::E_ERROR; + } + } + } + async(details); + }; +} + +RdbGeneralStore::DBProcessCB RdbGeneralStore::GetDBProcessCB(DetailAsync async) +{ + if (!async) { + return [](auto &) {}; + } + + return [async = std::move(async)](const std::map &processes) { + DistributedData::GenDetails details; + for (auto &[id, process] : processes) { + auto &detail = details[id]; + detail.progress = process.process; + detail.code = process.errCode == DBStatus::OK ? GeneralError::E_OK : GeneralError::E_ERROR; + for (auto [key, value] : process.tableProcess) { + auto &table = detail.details[key]; + table.upload.total = value.upLoadInfo.total; + table.upload.success = value.upLoadInfo.successCount; + table.upload.failed = value.upLoadInfo.failCount; + table.upload.untreated = table.upload.total - table.upload.success - table.upload.failed; + table.download.total = value.downLoadInfo.total; + table.download.success = value.downLoadInfo.successCount; + table.download.failed = value.downLoadInfo.failCount; + table.download.untreated = table.download.total - table.download.success - table.download.failed; + } + } + async(details); + }; +} + +void RdbGeneralStore::ObserverProxy::OnChange(const DBChangedIF &data) +{ + if (!HasWatcher()) { + return; + } + return; +} + +void RdbGeneralStore::ObserverProxy::OnChange(DBOrigin origin, const std::string &originalId, DBChangedData &&data) +{ + using GenOrigin = Watcher::Origin; + if (!HasWatcher()) { + return; + } + GenOrigin genOrigin; + genOrigin.origin = (origin == DBOrigin::ORIGIN_LOCAL) ? GenOrigin::ORIGIN_LOCAL + : (origin == DBOrigin::ORIGIN_CLOUD) ? GenOrigin::ORIGIN_CLOUD + : GenOrigin::ORIGIN_NEARBY; + genOrigin.id.push_back(originalId); + genOrigin.store = storeId_; + Watcher::PRIFields fields; + Watcher::ChangeInfo changeInfo; + for (int i = 0; i < DistributedDB::OP_BUTT; ++i) { + auto &info = changeInfo[data.tableName][i]; + for (auto &priData : data.primaryData[i]) { + Watcher::PRIValue value; + Convert(std::move(*(priData.begin())), value); + info.push_back(std::move(value)); + } + } + if (!data.field.empty()) { + fields[std::move(data.tableName)] = std::move(*(data.field.begin())); + } + watcher_->OnChange(genOrigin, fields, std::move(changeInfo)); } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 30972e02..62c8c307 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -15,13 +15,15 @@ #ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H #define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H +#include #include +#include "metadata/store_meta_data.h" +#include "rdb_cloud.h" +#include "rdb_store.h" #include "relational_store_delegate.h" #include "relational_store_manager.h" - -#include "rdb_store.h" #include "store/general_store.h" -#include "metadata/store_meta_data.h" +#include "store/general_value.h" namespace OHOS::DistributedRdb { class RdbGeneralStore : public DistributedData::GeneralStore { public: @@ -34,12 +36,11 @@ public: using StoreMetaData = DistributedData::StoreMetaData; using Database = DistributedData::Database; using RdbStore = OHOS::NativeRdb::RdbStore; - using RdbDelegate = DistributedDB::RelationalStoreDelegate; - using RdbManager = DistributedDB::RelationalStoreManager; explicit RdbGeneralStore(const StoreMetaData &metaData); ~RdbGeneralStore(); int32_t Bind(const Database &database, BindInfo bindInfo) override; + bool IsBound() override; int32_t Execute(const std::string &table, const std::string &sql) override; int32_t BatchInsert(const std::string &table, VBuckets &&values) override; int32_t BatchUpdate(const std::string &table, const std::string &sql, VBuckets &&values) override; @@ -52,12 +53,35 @@ public: int32_t Close() override; private: + using RdbDelegate = DistributedDB::RelationalStoreDelegate; + using RdbManager = DistributedDB::RelationalStoreManager; + using SyncProcess = DistributedDB::SyncProcess; + using DBBriefCB = DistributedDB::SyncStatusCallback; + using DBProcessCB = std::function &processes)>; static constexpr uint32_t ITERATE_TIMES = 10000; + class ObserverProxy : public DistributedDB::StoreObserver { + public: + using DBChangedIF = DistributedDB::StoreChangedData; + using DBChangedData = DistributedDB::ChangedData; + using DBOrigin = DistributedDB::Origin; + void OnChange(const DistributedDB::StoreChangedData &data) override; + void OnChange(DBOrigin origin, const std::string &originalId, DBChangedData &&data) override; + bool HasWatcher() const { return watcher_ == nullptr; }; + private: + friend RdbGeneralStore; + Watcher *watcher_ = nullptr; + std::string storeId_; + }; + DBBriefCB GetDBBriefCB(DetailAsync async); + DBProcessCB GetDBProcessCB(DetailAsync async); + ObserverProxy observer_; RdbManager manager_; RdbDelegate *delegate_ = nullptr; std::shared_ptr store_; + std::shared_ptr rdbCloud_ {}; BindInfo bindInfo_; + std::atomic isBound_ = false; }; } // namespace OHOS::DistributedRdb #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H diff --git a/services/distributeddataservice/service/rdb/rdb_query.cpp b/services/distributeddataservice/service/rdb/rdb_query.cpp index fc990eb1..4830c1fb 100644 --- a/services/distributeddataservice/service/rdb/rdb_query.cpp +++ b/services/distributeddataservice/service/rdb/rdb_query.cpp @@ -20,4 +20,9 @@ bool RdbQuery::IsEqual(uint64_t tid) { return tid == TYPE_ID; } + +std::vector RdbQuery::GetTables() +{ + return {}; +} } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_query.h b/services/distributeddataservice/service/rdb/rdb_query.h index fdeed511..aea76acf 100644 --- a/services/distributeddataservice/service/rdb/rdb_query.h +++ b/services/distributeddataservice/service/rdb/rdb_query.h @@ -17,18 +17,21 @@ #define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H #include "rdb_predicates.h" #include "store/general_value.h" +#include "query.h" namespace OHOS::DistributedRdb { class RdbQuery : public DistributedData::GenQuery { public: using Predicates = NativeRdb::RdbPredicates; - static constexpr uint64_t TYPE_ID = 0; + static constexpr uint64_t TYPE_ID = 0x20000001; RdbQuery() = default; ~RdbQuery() override = default; bool IsEqual(uint64_t tid) override; + std::vector GetTables() override; - NativeRdb::RdbPredicates predicates_ {""}; + DistributedDB::Query query_; + std::string sql_; }; } // namespace OHOS::DistributedRdb #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_QUERY_H diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index cc7108e4..fe50811b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -324,7 +324,7 @@ int32_t RdbServiceImpl::SetDistributedTables(const RdbSyncerParam ¶m, const } std::pair RdbServiceImpl::DoSync(const RdbSyncerParam ¶m, const Option &option, - const RdbPredicates &pred) + const PredicatesMemo &pred) { if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); @@ -352,7 +352,7 @@ void RdbServiceImpl::OnAsyncComplete(uint32_t tokenId, uint32_t seqNum, Details } } -int32_t RdbServiceImpl::DoAsync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &pred) +int32_t RdbServiceImpl::DoAsync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &pred) { if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); @@ -448,7 +448,7 @@ int32_t RdbServiceImpl::RemoteQuery(const RdbSyncerParam& param, const std::stri return syncer->RemoteQuery(device, sql, selectionArgs, resultSet); } -int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &predicates, +int32_t RdbServiceImpl::Sync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async) { if (!option.isAsync) { diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index a217cecb..061e5489 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -50,7 +50,7 @@ public: int32_t RemoteQuery(const RdbSyncerParam& param, const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet) override; - int32_t Sync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &predicates, + int32_t Sync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async) override; int32_t Subscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, RdbStoreObserver *observer) override; @@ -96,9 +96,9 @@ private: static constexpr int32_t MAX_SYNCER_PER_PROCESS = 10; static constexpr int32_t SYNCER_TIMEOUT = 60 * 1000; // ms - std::pair DoSync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &pred); + std::pair DoSync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &pred); - int32_t DoAsync(const RdbSyncerParam ¶m, const Option &option, const RdbPredicates &pred); + int32_t DoAsync(const RdbSyncerParam ¶m, const Option &option, const PredicatesMemo &pred); Watchers GetWatchers(uint32_t tokenId, const std::string &storeName); diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 7c703fbf..f2a611a5 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -95,7 +95,7 @@ int32_t RdbServiceStub::OnRemoteDoSync(MessageParcel &data, MessageParcel &reply { RdbSyncerParam param; Option option {}; - RdbPredicates predicates; + PredicatesMemo predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables:%{public}zu", param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), predicates.tables_.size()); @@ -115,7 +115,7 @@ int32_t RdbServiceStub::OnRemoteDoAsync(MessageParcel &data, MessageParcel &repl { RdbSyncerParam param; Option option {}; - RdbPredicates predicates; + PredicatesMemo predicates; if (!ITypesUtil::Unmarshal(data, param, option, predicates)) { ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s seqNum:%{public}u table:%{public}s", param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), option.seqNum, diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 2faede55..22b17899 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -20,8 +20,10 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "checker/checker_manager.h" +#include "cloud/change_event.h" #include "crypto_manager.h" #include "device_manager_adapter.h" +#include "eventcenter/event_center.h" #include "log_print.h" #include "metadata/meta_data_manager.h" #include "rdb_query.h" @@ -29,6 +31,8 @@ #include "store/general_store.h" #include "types_export.h" #include "utils/anonymous.h" +#include "utils/constant.h" +#include "utils/converter.h" using OHOS::DistributedKv::AccountDelegate; using namespace OHOS::Security::AccessToken; using namespace OHOS::DistributedData; @@ -270,6 +274,22 @@ Details RdbSyncer::HandleSyncStatus(const std::mapGetUserByToken(token_); + storeInfo.storeName = GetStoreId(); + storeInfo.tokenId = token_; + std::shared_ptr query = nullptr; + if (!predicates.tables_.empty()) { + query = std::make_shared(); + query->query_.FromTable(predicates.tables_); + } + + auto info = ChangeEvent::EventInfo(option.mode, (option.isAsync ? 0 : WAIT_TIME), query, + [async](const GenDetails &details) { + async(HandleGenDetails(details)); + }); + auto evt = std::make_unique(std::move(storeInfo), std::move(info)); + EventCenter::GetInstance().PostEvent(std::move(evt)); } ZLOGI("delegate sync"); return RDB_OK; diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.h b/services/distributeddataservice/service/rdb/rdb_syncer.h index 9b63b0f4..cf823d74 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -18,6 +18,7 @@ #include #include +#include #include "iremote_object.h" #include "metadata/secret_key_meta_data.h" @@ -27,10 +28,12 @@ #include "rdb_types.h" #include "relational_store_delegate.h" #include "relational_store_manager.h" +#include "store/general_value.h" namespace OHOS::DistributedRdb { class RdbSyncer { public: using StoreMetaData = OHOS::DistributedData::StoreMetaData; + using GenDetails = OHOS::DistributedData::GenDetails; using SecretKeyMetaData = DistributedData::SecretKeyMetaData; using Option = DistributedRdb::RdbService::Option; RdbSyncer(const RdbSyncerParam& param, RdbStoreObserverImpl* observer); @@ -50,7 +53,7 @@ public: int32_t SetDistributedTables(const std::vector &tables, int32_t type); - int32_t DoSync(const Option &option, const RdbPredicates &predicates, const AsyncDetail &async); + int32_t DoSync(const Option &option, const PredicatesMemo &predicates, const AsyncDetail &async); int32_t RemoteQuery(const std::string& device, const std::string& sql, const std::vector& selectionArgs, sptr& resultSet); @@ -63,7 +66,7 @@ public: static bool GetPassword(const StoreMetaData &metaData, DistributedDB::CipherPassword &password); - static DistributedDB::Query MakeQuery(const RdbPredicates& predicates); + static DistributedDB::Query MakeQuery(const PredicatesMemo &predicates); private: std::string GetUserId() const; @@ -90,6 +93,7 @@ private: static std::vector NetworkIdToUUID(const std::vector& networkIds); static Details HandleSyncStatus(const std::map> &SyncStatus); + static Details HandleGenDetails(const GenDetails &details); static void EqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); static void NotEqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); static void And(const RdbPredicateOperation& operation, DistributedDB::Query& query); @@ -109,6 +113,7 @@ private: static constexpr int DECIMAL_BASE = 10; static constexpr uint64_t REMOTE_QUERY_TIME_OUT = 30 * 1000; + static constexpr int32_t WAIT_TIME = 30 * 1000; }; } // namespace OHOS::DistributedRdb #endif diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp new file mode 100644 index 00000000..fbd7c5f9 --- /dev/null +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -0,0 +1,332 @@ +/* + * 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. + */ + +#define LOG_TAG "ValueProxy" +#include "log_print.h" +#include "value_proxy.h" +namespace OHOS::DistributedRdb { +using namespace OHOS::DistributedData; +ValueProxy::Value ValueProxy::Convert(DistributedData::Value &&value) +{ + Value proxy; + DistributedData::Convert(std::move(value), proxy.value_); + return proxy; +} + +ValueProxy::Value ValueProxy::Convert(NativeRdb::ValueObject &&value) +{ + Value proxy; + DistributedData::Convert(std::move(value.value), proxy.value_); + return proxy; +} + +ValueProxy::Value ValueProxy::Convert(DistributedDB::Type &&value) +{ + Value proxy; + DistributedData::Convert(std::move(value), proxy.value_); + return proxy; +} + +ValueProxy::Values ValueProxy::Convert(DistributedData::Values &&values) +{ + Values proxy; + proxy.value_.reserve(values.size()); + for (auto &value : values) { + proxy.value_.emplace_back(Convert(std::move(value))); + } + return proxy; +} + +ValueProxy::Values ValueProxy::Convert(std::vector &&values) +{ + Values proxy; + proxy.value_.reserve(values.size()); + for (auto &value : values) { + proxy.value_.emplace_back(Convert(std::move(value))); + } + return proxy; +} + +ValueProxy::Bucket ValueProxy::Convert(DistributedData::VBucket &&bucket) +{ + ValueProxy::Bucket proxy; + for (auto &[key, value] : bucket) { + proxy.value_.insert_or_assign(key, Convert(std::move(value))); + } + return proxy; +} + +ValueProxy::Bucket ValueProxy::Convert(NativeRdb::ValuesBucket &&bucket) +{ + ValueProxy::Bucket proxy; + for (auto &[key, value] : bucket.values_) { + proxy.value_.insert_or_assign(key, Convert(std::move(value))); + } + return proxy; +} + +ValueProxy::Bucket ValueProxy::Convert(DistributedDB::VBucket &&bucket) +{ + ValueProxy::Bucket proxy; + for (auto &[key, value] : bucket) { + proxy.value_.insert_or_assign(key, Convert(std::move(value))); + } + return proxy; +} + +ValueProxy::Buckets ValueProxy::Convert(std::vector &&buckets) +{ + ValueProxy::Buckets proxy; + proxy.value_.reserve(buckets.size()); + for (auto &bucket : buckets) { + proxy.value_.emplace_back(Convert(std::move(bucket))); + } + return proxy; +} + +ValueProxy::Buckets ValueProxy::Convert(std::vector &&buckets) +{ + ValueProxy::Buckets proxy; + proxy.value_.reserve(buckets.size()); + for (auto &bucket : buckets) { + proxy.value_.emplace_back(Convert(std::move(bucket))); + } + return proxy; +} + +ValueProxy::Buckets ValueProxy::Convert(DistributedData::VBuckets &&buckets) +{ + ValueProxy::Buckets proxy; + proxy.value_.reserve(buckets.size()); + for (auto &bucket : buckets) { + proxy.value_.emplace_back(Convert(std::move(bucket))); + } + return proxy; +} + +ValueProxy::Asset::Asset(DistributedData::Asset asset) +{ + asset_ = std::move(asset); +} + +ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) +{ + asset_ = DistributedData::Asset { .version = asset.version, + .name = std::move(asset.name), + .uri = std::move(asset.uri), + .createTime = std::move(asset.createTime), + .modifyTime = std::move(asset.modifyTime), + .size = std::move(asset.size), + .hash = std::move(asset.hash) }; +} + +ValueProxy::Asset::Asset(DistributedDB::Asset asset) +{ + asset_ = DistributedData::Asset { .version = asset.version, + .name = std::move(asset.name), + .uri = std::move(asset.uri), + .createTime = std::move(asset.createTime), + .modifyTime = std::move(asset.modifyTime), + .size = std::move(asset.size), + .hash = std::move(asset.hash) }; +} + +ValueProxy::Asset &ValueProxy::Asset::operator=(const Asset &proxy) +{ + if (this == &proxy) { + return *this; + } + asset_ = proxy.asset_; + return *this; +} + +ValueProxy::Asset &ValueProxy::Asset::operator=(Asset &&proxy) noexcept +{ + if (this == &proxy) { + return *this; + } + asset_ = std::move(proxy); + return *this; +} + +ValueProxy::Asset::operator NativeRdb::AssetValue() +{ + return NativeRdb::AssetValue { .version = asset_.version, + .name = std::move(asset_.name), + .uri = std::move(asset_.uri), + .createTime = std::move(asset_.createTime), + .modifyTime = std::move(asset_.modifyTime), + .size = std::move(asset_.size), + .hash = std::move(asset_.hash) }; +} + +ValueProxy::Asset::operator DistributedData::Asset() +{ + return std::move(asset_); +} + +ValueProxy::Asset::operator DistributedDB::Asset() +{ + return DistributedDB::Asset { .version = asset_.version, + .name = std::move(asset_.name), + .uri = std::move(asset_.uri), + .modifyTime = std::move(asset_.modifyTime), + .createTime = std::move(asset_.createTime), + .size = std::move(asset_.size), + .hash = std::move(asset_.hash) }; +} + +ValueProxy::Assets::Assets(DistributedData::Assets assets) +{ + assets_.clear(); + assets_.reserve(assets.size()); + for (auto &asset : assets) { + assets_.emplace_back(std::move(asset)); + } +} + +ValueProxy::Assets::Assets(NativeRdb::ValueObject::Assets assets) +{ + assets_.clear(); + assets_.reserve(assets.size()); + for (auto &asset : assets) { + assets_.emplace_back(std::move(asset)); + } +} + +ValueProxy::Assets::Assets(DistributedDB::Assets assets) +{ + assets_.clear(); + assets_.reserve(assets.size()); + for (auto &asset : assets) { + assets_.emplace_back(std::move(asset)); + } +} + +ValueProxy::Assets &ValueProxy::Assets::operator=(const Assets &proxy) +{ + if (this == &proxy) { + return *this; + } + assets_ = proxy.assets_; + return *this; +} + +ValueProxy::Assets &ValueProxy::Assets::operator=(Assets &&proxy) noexcept +{ + if (this == &proxy) { + return *this; + } + assets_ = std::move(proxy.assets_); + return *this; +} + +ValueProxy::Assets::operator NativeRdb::ValueObject::Assets() +{ + NativeRdb::ValueObject::Assets assets; + assets.reserve(assets_.size()); + for (auto &asset : assets_) { + assets.push_back(std::move(asset)); + } + return assets; +} + +ValueProxy::Assets::operator DistributedData::Assets() +{ + DistributedData::Assets assets; + assets.reserve(assets_.size()); + for (auto &asset : assets_) { + assets.push_back(std::move(asset)); + } + return assets; +} + +ValueProxy::Assets::operator DistributedDB::Assets() +{ + DistributedDB::Assets assets; + assets.reserve(assets_.size()); + for (auto &asset : assets_) { + assets.push_back(std::move(asset)); + } + return assets; +} + +ValueProxy::Value &ValueProxy::Value::operator=(ValueProxy::Value &&value) noexcept +{ + if (this == &value) { + return *this; + } + value_ = std::move(value.value_); + return *this; +} + +ValueProxy::Value::operator NativeRdb::ValueObject() +{ + NativeRdb::ValueObject object; + DistributedData::Convert(std::move(value_), object.value); + return object; +} + +ValueProxy::Value::operator DistributedData::Value() +{ + DistributedData::Value value; + DistributedData::Convert(std::move(value_), value); + return value; +} + +ValueProxy::Value::operator DistributedDB::Type() +{ + DistributedDB::Type value; + DistributedData::Convert(std::move(value_), value); + return value; +} + +ValueProxy::Values &ValueProxy::Values::operator=(ValueProxy::Values &&values) noexcept +{ + if (this == &values) { + return *this; + } + value_ = std::move(values.value_); + return *this; +} + +ValueProxy::Bucket &ValueProxy::Bucket::operator=(Bucket &&bucket) noexcept +{ + if (this == &bucket) { + return *this; + } + value_ = std::move(bucket.value_); + return *this; +} + +ValueProxy::Bucket::operator NativeRdb::ValuesBucket() +{ + NativeRdb::ValuesBucket bucket; + for (auto &[key, value] : value_) { + bucket.values_.insert_or_assign(key, std::move(value)); + } + value_.clear(); + return bucket; +} + +ValueProxy::Buckets &ValueProxy::Buckets::operator=(Buckets &&buckets) noexcept +{ + if (this == &buckets) { + return *this; + } + value_ = std::move(buckets.value_); + return *this; +} +} // namespace OHOS::DistributedRdb \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/value_proxy.h b/services/distributeddataservice/service/rdb/value_proxy.h new file mode 100644 index 00000000..8506e268 --- /dev/null +++ b/services/distributeddataservice/service/rdb/value_proxy.h @@ -0,0 +1,181 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_VALUE_PROXY_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_VALUE_PROXY_H +#include "asset_value.h" +#include "cloud/cloud_store_types.h" +#include "store/general_value.h" +#include "value_object.h" +#include "values_bucket.h" +namespace OHOS::DistributedRdb { +class ValueProxy final { +public: + using Bytes = DistributedData::Bytes; + class Asset { + public: + Asset() = default; + Asset(Asset &&proxy) noexcept + { + *this = std::move(proxy); + }; + Asset(const Asset &proxy) + { + *this = proxy; + }; + Asset(DistributedData::Asset asset); + Asset(NativeRdb::AssetValue asset); + Asset(DistributedDB::Asset asset); + Asset &operator=(const Asset &proxy); + Asset &operator=(Asset &&proxy) noexcept; + operator NativeRdb::AssetValue(); + operator DistributedData::Asset(); + operator DistributedDB::Asset(); + + private: + DistributedData::Asset asset_; + }; + + class Assets { + public: + Assets() = default; + Assets(Assets &&proxy) noexcept + { + *this = std::move(proxy); + }; + Assets(const Assets &proxy) + { + *this = proxy; + }; + Assets(DistributedData::Assets assets); + Assets(NativeRdb::ValueObject::Assets assets); + Assets(DistributedDB::Assets assets); + Assets &operator=(const Assets &proxy); + Assets &operator=(Assets &&proxy) noexcept; + operator NativeRdb::ValueObject::Assets(); + operator DistributedData::Assets(); + operator DistributedDB::Assets(); + + private: + std::vector assets_; + }; + using Proxy = std::variant; + + class Value { + public: + Value() = default; + Value(Value &&value) noexcept + { + *this = std::move(value); + }; + Value &operator=(Value &&value) noexcept; + operator NativeRdb::ValueObject(); + operator DistributedData::Value(); + operator DistributedDB::Type(); + + private: + friend ValueProxy; + Proxy value_; + }; + class Values { + public: + Values() = default; + Values(Values &&values) noexcept + { + *this = std::move(values); + }; + Values &operator=(Values &&values) noexcept; + template + operator std::vector() + { + std::vector objects; + objects.reserve(value_.size()); + for (auto &proxy : value_) { + objects.emplace_back(std::move(proxy)); + } + value_.clear(); + return objects; + } + + private: + friend ValueProxy; + std::vector value_; + }; + class Bucket { + public: + Bucket() = default; + Bucket(Bucket &&bucket) noexcept + { + *this = std::move(bucket); + }; + Bucket &operator=(Bucket &&bucket) noexcept; + template + operator std::map() + { + std::map bucket; + for (auto &[key, value] : value_) { + bucket.insert_or_assign(key, std::move(value)); + } + value_.clear(); + return bucket; + } + operator NativeRdb::ValuesBucket(); + + private: + friend ValueProxy; + std::map value_; + }; + class Buckets { + public: + Buckets() = default; + Buckets(Buckets &&buckets) noexcept + { + *this = std::move(buckets); + }; + Buckets &operator=(Buckets &&buckets) noexcept; + template + operator std::vector() + { + std::vector buckets; + buckets.reserve(value_.size()); + for (auto &bucket : value_) { + buckets.emplace_back(std::move(bucket)); + } + value_.clear(); + return buckets; + } + + private: + friend ValueProxy; + std::vector value_; + }; + static Value Convert(DistributedData::Value &&value); + static Value Convert(NativeRdb::ValueObject &&value); + static Value Convert(DistributedDB::Type &&value); + static Values Convert(DistributedData::Values &&values); + static Values Convert(std::vector &&values); + static Bucket Convert(DistributedData::VBucket &&bucket); + static Bucket Convert(NativeRdb::ValuesBucket &&bucket); + static Bucket Convert(DistributedDB::VBucket &&bucket); + static Buckets Convert(DistributedData::VBuckets &&buckets); + static Buckets Convert(std::vector &&buckets); + static Buckets Convert(std::vector &&buckets); + +private: + ValueProxy() = delete; + ~ValueProxy() = delete; +}; +} // namespace OHOS::DistributedRdb +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_VALUE_PROXY_H diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 97d837b7..776e1993 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -67,6 +67,35 @@ ohos_unittest("CloudDataTest") { ] } +ohos_unittest("ValueProxyTest") { + module_out_path = module_output_path + sources = [ + "value_proxy_test.cpp", + ] + + include_dirs = + [ "../../../../../relational_store/interfaces/inner_api/rdb/include" ] + + configs = [ ":module_private_config" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + ] + + deps = [ + "${kv_store_distributeddb_path}:distributeddb", + "../../adapter:distributeddata_adapter", + "../../framework:distributeddatasvcfwk", + "../../service:distributeddatasvc", + "//third_party/googletest:gtest_main", + ] +} + ohos_unittest("ConfigFactoryTest") { module_out_path = module_output_path sources = [ "config_factory_test.cpp" ] @@ -183,6 +212,7 @@ group("unittest") { ":CryptoManagerTest", ":DeviceMatrixTest", ":DirectoryManagerTest", + ":ValueProxyTest", ] } ############################################################################### diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index fcde19b4..8e9fb981 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -80,7 +80,7 @@ CloudInfo CloudServerMock::GetServerInfo(int32_t userId) appInfo.version = 1; appInfo.cloudSwitch = true; - cloudInfo.apps.emplace_back(std::move(appInfo)); + cloudInfo.apps[TEST_CLOUD_BUNDLE] = std::move(appInfo); return cloudInfo; } @@ -129,6 +129,7 @@ void CloudDataTest::InitSchemaMeta() database.tables.emplace_back(table); schemaMeta_.version = 1; + schemaMeta_.bundleName = TEST_DISTRIBUTEDDATA_BUNDLE; schemaMeta_.databases.emplace_back(database); } @@ -139,7 +140,8 @@ void CloudDataTest::SetUpTestCase(void) }); auto cloudServerMock = new CloudServerMock(); - ASSERT_TRUE(CloudServer::RegisterCloudInstance(cloudServerMock)); + //ASSERT_TRUE(CloudServer::RegisterCloudInstance(cloudServerMock)); + CloudServer::RegisterCloudInstance(cloudServerMock); FeatureSystem::GetInstance().GetCreator("cloud")(); FeatureSystem::GetInstance().GetCreator("relational_store")(); } @@ -150,6 +152,7 @@ void CloudDataTest::SetUp() { InitMetaData(); InitSchemaMeta(); + MetaDataManager::GetInstance().SaveMeta(metaData_.GetKey(), metaData_); StoreMetaData storeMetaData; @@ -178,7 +181,7 @@ void CloudDataTest::TearDown() {} HWTEST_F(CloudDataTest, GetSchema, TestSize.Level0) { ZLOGI("CloudDataTest start"); - std::shared_ptr cloudServerMock = std::make_shared(); + auto cloudServerMock = std::make_shared(); auto cloudInfo = cloudServerMock->GetServerInfo( DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(OHOS::IPCSkeleton::GetCallingTokenID())); ASSERT_TRUE(MetaDataManager::GetInstance().DelMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), true)); diff --git a/services/distributeddataservice/service/test/value_proxy_test.cpp b/services/distributeddataservice/service/test/value_proxy_test.cpp new file mode 100644 index 00000000..df911512 --- /dev/null +++ b/services/distributeddataservice/service/test/value_proxy_test.cpp @@ -0,0 +1,107 @@ +/* + * 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. + */ + +#define LOG_TAG "CloudDataTest" +#include "value_proxy.h" +#include +#include "log_print.h" +namespace Test { +using namespace testing::ext; +using namespace OHOS::DistributedRdb; +class ValueProxyTest : public testing::Test { +}; + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, VBucketsNormal2GaussDB, TestSize.Level0) +{ + std::vector dbVBuckets; + OHOS::DistributedData::VBuckets extends = { + {{"#gid", {"0000000"}}, {"#flag", {true }}, {"#value", {int64_t(100)}}, {"#float", {double(100)}}}, + {{"#gid", {"0000001"}}} + }; + dbVBuckets = ValueProxy::Convert(std::move(extends)); + ASSERT_EQ(dbVBuckets.size(), 2); +} + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, VBucketsGaussDB2Normal, TestSize.Level0) +{ + std::vector dbVBuckets = { + {{"#gid", {"0000000"}}, {"#flag", {true }}, {"#value", {int64_t(100)}}, {"#float", {double(100)}}}, + {{"#gid", {"0000001"}}} + }; + OHOS::DistributedData::VBuckets extends; + extends = ValueProxy::Convert(std::move(dbVBuckets)); + ASSERT_EQ(extends.size(), 2); +} + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, VBucketsNormal2Rdb, TestSize.Level0) +{ + using RdbBucket = OHOS::NativeRdb::ValuesBucket; + std::vector rdbVBuckets; + OHOS::DistributedData::VBuckets extends = { + {{"#gid", {"0000000"}}, {"#flag", {true }}, {"#value", {int64_t(100)}}, {"#float", {double(100)}}}, + {{"#gid", {"0000001"}}} + }; + rdbVBuckets = ValueProxy::Convert(std::move(extends)); + ASSERT_EQ(rdbVBuckets.size(), 2); +} + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, VBucketsRdb2Normal, TestSize.Level0) +{ + using RdbBucket = OHOS::NativeRdb::ValuesBucket; + using RdbValue = OHOS::NativeRdb::ValueObject; + std::vector rdbVBuckets = { + RdbBucket(std::map{ + {"#gid", {"0000000"}}, + {"#flag", {true }}, + {"#value", {int64_t(100)}}, + {"#float", {double(100)}} + }), + RdbBucket(std::map{ + {"#gid", {"0000001"}} + }) + }; + OHOS::DistributedData::VBuckets extends; + extends = ValueProxy::Convert(std::move(rdbVBuckets)); + ASSERT_EQ(extends.size(), 2); +} +} -- Gitee From c7faf3e03c1229be4397fc6fe24d9e6d4ef03301 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 09:49:41 +0800 Subject: [PATCH 177/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/framework/BUILD.gn | 1 + .../framework/include/cloud/cloud_event.h | 1 - .../framework/include/utils/constant.h | 41 +++++++------------ .../framework/include/utils/ref_count.h | 3 +- .../framework/utils/constant.cpp | 10 +++++ .../service/cloud/cloud_service_impl.cpp | 19 +-------- .../service/test/BUILD.gn | 3 ++ 7 files changed, 32 insertions(+), 46 deletions(-) diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 793c97b1..b09c9c74 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -89,6 +89,7 @@ ohos_shared_library("distributeddatasvcfwk") { external_deps = [ "access_token:libaccesstoken_sdk", + "c_utils:utils", "hiviewdfx_hilog_native:libhilog", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/framework/include/cloud/cloud_event.h b/services/distributeddataservice/framework/include/cloud/cloud_event.h index ae67857f..01c2c098 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -25,7 +25,6 @@ public: enum : int32_t { FEATURE_INIT = EVT_CLOUD, GET_SCHEMA, - DATA_CHANGE, LOCAL_CHANGE, CLOUD_SYNC, CLOUD_BUTT diff --git a/services/distributeddataservice/framework/include/utils/constant.h b/services/distributeddataservice/framework/include/utils/constant.h index 7abc9282..ff0dffda 100644 --- a/services/distributeddataservice/framework/include/utils/constant.h +++ b/services/distributeddataservice/framework/include/utils/constant.h @@ -16,12 +16,13 @@ #ifndef KV_DATASERVICE_CONSTANT_H #define KV_DATASERVICE_CONSTANT_H -#include -#include #include #include #include #include +#include +#include +#include #include #include "visibility.h" @@ -41,6 +42,15 @@ public: API_EXPORT static bool NotEqual(bool first, bool second); + template + inline static constexpr bool is_pod = (std::is_standard_layout_v && std::is_trivial_v); + + template + API_EXPORT inline static std::enable_if_t && is_pod, bool> Copy(T *tag, const S *src) + { + return DCopy(reinterpret_cast(tag), sizeof(T), reinterpret_cast(src), sizeof(S)); + }; + // delete left bland in s by reference. template static void LeftTrim(T &s); @@ -53,19 +63,14 @@ public: template static void Trim(T &s); - // delete left bland in s by reference, not change raw string. - template - static T LeftTrimCopy(T s); - - // delete right bland in s by reference, not change raw string. - template - static T RightTrimCopy(T s); - // delete both left and right bland in s by reference, not change raw string. template static T TrimCopy(T s); API_EXPORT static constexpr const char *KEY_SEPARATOR = "###"; + +private: + API_EXPORT static bool DCopy(uint8_t *tag, size_t tagLen, const uint8_t *src, size_t srcLen); }; // trim from start (in place) @@ -90,22 +95,6 @@ void Constant::Trim(T &s) RightTrim(s); } -// trim from start (copying) -template -T Constant::LeftTrimCopy(T s) -{ - LeftTrim(s); - return s; -} - -// trim from end (copying) -template -T Constant::RightTrimCopy(T s) -{ - RightTrim(s); - return s; -} - // trim from both ends (copying) template T Constant::TrimCopy(T s) diff --git a/services/distributeddataservice/framework/include/utils/ref_count.h b/services/distributeddataservice/framework/include/utils/ref_count.h index f5522d85..38b71ce1 100644 --- a/services/distributeddataservice/framework/include/utils/ref_count.h +++ b/services/distributeddataservice/framework/include/utils/ref_count.h @@ -18,8 +18,9 @@ #include #include #include +#include "visibility.h" namespace OHOS::DistributedData { -class RefCount final { +class API_EXPORT RefCount final { public: RefCount(); explicit RefCount(std::function action); diff --git a/services/distributeddataservice/framework/utils/constant.cpp b/services/distributeddataservice/framework/utils/constant.cpp index 1f327be9..d05d8e9f 100644 --- a/services/distributeddataservice/framework/utils/constant.cpp +++ b/services/distributeddataservice/framework/utils/constant.cpp @@ -20,6 +20,7 @@ #include #include #include "log_print.h" +#include "securec.h" namespace OHOS { namespace DistributedData { @@ -85,5 +86,14 @@ bool Constant::IsBackground(pid_t pid) } return false; } + +bool Constant::DCopy(uint8_t *tag, size_t tagLen, const uint8_t *src, size_t srcLen) +{ + if (tagLen != srcLen || tag == nullptr || src == nullptr) { + return false; + } + auto ret = memcpy_s(tag, tagLen, src, srcLen); + return ret == EOK; +} } // namespace DistributedData } // namespace OHOS diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index c0686642..56cc1cab 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -165,23 +165,6 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str if (!cloudInfo.apps[bundleName].cloudSwitch) { return CLOUD_DISABLE_SWITCH; } - auto key = cloudInfo.GetSchemaKey(bundleName); - SchemaMeta schemaMeta; - if (!MetaDataManager::GetInstance().LoadMeta(key, schemaMeta, true)) { - ZLOGE("bundleName:%{public}s", bundleName.c_str()); - return INVALID_ARGUMENT; - } - const auto &app = cloudInfo.apps[bundleName]; - for (const auto &database : schemaMeta.databases) { - EventCenter::Defer defer; - CloudEvent::StoreInfo storeInfo; - storeInfo.bundleName = app.bundleName; - storeInfo.instanceId = app.instanceId; - storeInfo.user = cloudInfo.user; - storeInfo.storeName = database.name; - auto evt = std::make_unique(CloudEvent::DATA_CHANGE, storeInfo); - EventCenter::GetInstance().PostEvent(std::move(evt)); - } syncManager_.DoCloudSync(SyncManager::SyncInfo(cloudInfo.user, bundleName)); return SUCCESS; } @@ -378,7 +361,7 @@ SchemaMeta CloudServiceImpl::GetSchemaMeta(int32_t userId, const std::string &bu } schemaMeta = instance->GetAppSchema(userId, bundleName); if (!schemaMeta.IsValid()) { - ZLOGE("download schema from cloud failed, user:%{public}s, bundleName:%{public}s", userId, bundleName.c_str()); + ZLOGE("download schema from cloud failed, user:%{public}d, bundleName:%{public}s", userId, bundleName.c_str()); } MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); return schemaMeta; diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 776e1993..b62f9814 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -27,6 +27,7 @@ config("module_private_config") { "../crypto/include/", "../directory/include/", "../matrix/include/", + "../rdb/", "../../framework/include/", ] @@ -71,6 +72,7 @@ ohos_unittest("ValueProxyTest") { module_out_path = module_output_path sources = [ "value_proxy_test.cpp", + "../rdb/value_proxy.cpp", ] include_dirs = @@ -89,6 +91,7 @@ ohos_unittest("ValueProxyTest") { deps = [ "${kv_store_distributeddb_path}:distributeddb", + "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb:native_rdb_static", "../../adapter:distributeddata_adapter", "../../framework:distributeddatasvcfwk", "../../service:distributeddatasvc", -- Gitee From 74b621c95f5f7e812bf9c5b8eb4b72bf0945c989 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 10:51:53 +0800 Subject: [PATCH 178/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/framework/include/utils/ref_count.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/include/utils/ref_count.h b/services/distributeddataservice/framework/include/utils/ref_count.h index 38b71ce1..09fdbeb3 100644 --- a/services/distributeddataservice/framework/include/utils/ref_count.h +++ b/services/distributeddataservice/framework/include/utils/ref_count.h @@ -28,7 +28,7 @@ public: RefCount(RefCount &&other) noexcept; RefCount &operator=(const RefCount &other); RefCount &operator=(RefCount &&other) noexcept; - operator bool () const; + operator bool() const; private: std::shared_ptr ref_; -- Gitee From e6054a31dc956e6ddd74b8fbf1325d325b6f36b8 Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 8 Jun 2023 11:21:42 +0800 Subject: [PATCH 179/437] f Signed-off-by: hanlu --- .../service/data_share/common/uri_utils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.cpp b/services/distributeddataservice/service/data_share/common/uri_utils.cpp index abb53606..e5a64445 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.cpp +++ b/services/distributeddataservice/service/data_share/common/uri_utils.cpp @@ -73,11 +73,12 @@ bool URIUtils::GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32 std::string::size_type nextPos; std::string::size_type valueStartPos; while (pos != std::string::npos) { - valueStartPos = query.find_first_of('=', pos) + 1; + valueStartPos = query.find_first_of('=', pos); if (valueStartPos == std::string::npos) { ZLOGE("parse failed %{public}s", query.c_str()); return false; } + valueStartPos += 1; nextPos = query.find_first_of('&', pos); std::string value = (nextPos == std::string::npos ? query.substr(valueStartPos) : query.substr(valueStartPos, nextPos - valueStartPos)); -- Gitee From 07ae9dd33e21af5bbd07a3a014b59406a1060ea1 Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 8 Jun 2023 11:45:44 +0800 Subject: [PATCH 180/437] f Signed-off-by: hanlu --- .../service/data_share/common/uri_utils.cpp | 2 +- .../service/data_share/data/published_data.cpp | 2 +- .../service/data_share/data_share_service_impl.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.cpp b/services/distributeddataservice/service/data_share/common/uri_utils.cpp index e5a64445..c5bbe380 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.cpp +++ b/services/distributeddataservice/service/data_share/common/uri_utils.cpp @@ -86,7 +86,7 @@ bool URIUtils::GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32 if (query.compare(pos, sizeof(USER_PARAM) - 1, USER_PARAM) == 0) { user = std::stoi(value); } else if (query.compare(pos, sizeof(TOKEN_ID_PARAM) - 1, TOKEN_ID_PARAM) == 0) { - callerTokenId = std::stoi(value); + callerTokenId = std::stoul(value); } } if (nextPos == std::string::npos) { diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index e3ac79b0..881dec41 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -179,8 +179,8 @@ void PublishedData::ClearAging() } agingSize++; } - ZLOGI("aging count %{public}d", agingSize); } + ZLOGI("aging count %{public}d", agingSize); return; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 4c6f8adc..41b981b5 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -309,9 +309,9 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - result = subscribeStrategy_.Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + result = subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().EnableSubscriber( - context->uri, callerBundleName, subscriberId, context->callerTokenId); + context->uri, context->callerBundleName, subscriberId, context->callerTokenId); }); results.emplace_back(uri, result); if (result == E_OK) { @@ -337,9 +337,9 @@ std::vector DataShareServiceImpl::DisablePubSubs(const std::vec context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; results.emplace_back( - uri, subscribeStrategy_.Execute(context, [&subscriberId, &callerBundleName, &context]() -> bool { + uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { return PublishedDataSubscriberManager::GetInstance().DisableSubscriber( - context->uri, callerBundleName, subscriberId, context->callerTokenId); + context->uri, context->callerBundleName, subscriberId, context->callerTokenId); })); } return results; -- Gitee From 4a46e5b45ccb7fe7bade574eaa1d9e153b96a89f Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 11:50:59 +0800 Subject: [PATCH 181/437] update Signed-off-by: zuojiangjiang --- .../framework/cloud/sync_event.cpp | 1 - .../framework/include/cloud/sync_event.h | 3 +- .../framework/utils/constant.cpp | 4 --- .../service/cloud/cloud_service_impl.cpp | 7 ++-- .../service/cloud/sync_manager.cpp | 14 +++++--- .../service/cloud/sync_manager.h | 1 + .../gaussdb_rd/src/common/src/json_common.cpp | 4 +-- .../unittest/api/documentdb_data_test.cpp | 22 +++++++++++++ .../service/rdb/rdb_cloud.cpp | 3 +- .../service/rdb/rdb_cloud.h | 1 + .../service/rdb/rdb_general_store.cpp | 2 +- .../service/rdb/rdb_general_store.h | 5 ++- .../service/rdb/rdb_service_impl.cpp | 32 +++++++++++++------ .../service/test/cloud_data_test.cpp | 1 - .../service/test/value_proxy_test.cpp | 6 ++-- 15 files changed, 72 insertions(+), 34 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/sync_event.cpp b/services/distributeddataservice/framework/cloud/sync_event.cpp index 814b9681..7c2d3d93 100644 --- a/services/distributeddataservice/framework/cloud/sync_event.cpp +++ b/services/distributeddataservice/framework/cloud/sync_event.cpp @@ -15,7 +15,6 @@ #include "cloud/sync_event.h" -#include namespace OHOS::DistributedData { SyncEvent::EventInfo::EventInfo(int32_t mode, int32_t wait, std::shared_ptr query, GenAsync async) : mode_(mode), wait_(wait), query_(std::move(query)), asyncDetail_(std::move(async)) diff --git a/services/distributeddataservice/framework/include/cloud/sync_event.h b/services/distributeddataservice/framework/include/cloud/sync_event.h index b5b81202..351a919a 100644 --- a/services/distributeddataservice/framework/include/cloud/sync_event.h +++ b/services/distributeddataservice/framework/include/cloud/sync_event.h @@ -48,6 +48,5 @@ protected: private: EventInfo info_; }; -} - +} // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SYNC_EVENT_H diff --git a/services/distributeddataservice/framework/utils/constant.cpp b/services/distributeddataservice/framework/utils/constant.cpp index d05d8e9f..d1c0d148 100644 --- a/services/distributeddataservice/framework/utils/constant.cpp +++ b/services/distributeddataservice/framework/utils/constant.cpp @@ -15,10 +15,6 @@ #define LOG_TAG "Constant" #include "utils/constant.h" -#include -#include -#include -#include #include "log_print.h" #include "securec.h" diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 56cc1cab..c2a9ce09 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -367,7 +367,8 @@ SchemaMeta CloudServiceImpl::GetSchemaMeta(int32_t userId, const std::string &bu return schemaMeta; } -CloudInfo CloudServiceImpl::GetCloudInfo(int32_t userId) { +CloudInfo CloudServiceImpl::GetCloudInfo(int32_t userId) +{ CloudInfo cloudInfo; cloudInfo.user = userId; if (MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetKey(), cloudInfo, true)) { @@ -427,11 +428,11 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) auto &dbs = enabled ? subDbs : unsubDbs; auto it = sub.expiresTime.find(bundle); // cloud is enabled, but the subscription won't expire - if (enabled && (it != sub.expiresTime.end() && it->second >= onThreshold.count())) { + if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count()))) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. - if (!enabled && (it == sub.expiresTime.end() || it->second <= offThreshold.count())) { + if (!enabled && (it == sub.expiresTime.end() || it->second <= static_cast(offThreshold.count()))) { continue; } diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index f55515a7..9a18d2e2 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -87,7 +87,10 @@ std::shared_ptr SyncManager::SyncInfo::GenerateQuery(const std::string } class SyncQuery final : public GenQuery { public: - SyncQuery(const std::vector &tables) : tables_(tables){}; + explicit SyncQuery(const std::vector &tables) : tables_(tables) + { + } + bool IsEqual(uint64_t tid) override { return false; @@ -168,7 +171,8 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf return; } - if (!cloud.enableCloud || cloud.id != info.id_ || (!info.bundleName_.empty() && !cloud.IsOn(info.bundleName_))) { + if (!cloud.enableCloud || cloud.id != info.id_ || (!info.bundleName_.empty() && + !cloud.IsOn(info.bundleName_))) { info.SetError(E_UNOPENED); ZLOGI("cloud off bundleName:%{public}s", info.bundleName_.c_str()); return; @@ -193,7 +197,7 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf storeInfo.storeName = database.name; auto query = info.GenerateQuery(database.name, database.GetTableNames()); auto evt = std::make_unique(std::move(storeInfo), - SyncEvent::EventInfo{ info.mode_, info.wait_, std::move(query), info.async_ }); + SyncEvent::EventInfo { info.mode_, info.wait_, std::move(query), info.async_ }); EventCenter::GetInstance().PostEvent(std::move(evt)); } } @@ -271,7 +275,7 @@ std::function SyncManager::GetClientChangeHandler() uint64_t SyncManager::GenSyncId(int32_t user) { uint64_t syncId = user; - return (syncId << 32) | (++syncId_); + return (syncId << MV_BIT) | (++syncId_); } RefCount SyncManager::GenSyncRef(uint64_t syncId) @@ -284,7 +288,7 @@ RefCount SyncManager::GenSyncRef(uint64_t syncId) int32_t SyncManager::Compare(uint64_t syncId, int32_t user) { uint64_t inner = user; - return (syncId & USER_MARK) == (inner << 32); + return (syncId & USER_MARK) == (inner << MV_BIT); } void SyncManager::DoRetry(int32_t retry, SyncInfo &&info) diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index a7333898..dddedc3a 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -68,6 +68,7 @@ private: static constexpr ExecutorPool::Duration RETRY_INTERVAL = std::chrono::seconds(10); // second static constexpr int32_t RETRY_TIMES = 6; // second static constexpr uint64_t USER_MARK = 0xFFFFFFFF00000000; // high 32 bit + static constexpr int32_t MV_BIT = 32; Task GetSyncTask(int32_t retry, RefCount ref, SyncInfo &&syncInfo); void DoRetry(int32_t retry, SyncInfo &&syncInfo); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index d4cd878f..a6f4a8fc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -340,7 +340,7 @@ bool AddSpliteHitField(const JsonObject &src, const JsonObject &item, JsonFieldP return true; } - for (int32_t i = static_cast(abandonPath.size()) - 1; i > -1; i--) { + for (int32_t i = (int32_t)(abandonPath.size()) - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; @@ -382,7 +382,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie return false; } JsonFieldPath newHitPath; - for (int32_t i = static_cast(abandonPath.size()) - 1; i > -1; i--) { + for (int32_t i = (int32_t)(abandonPath.size()) - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index 25682e07..7fdb5a56 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -118,6 +118,10 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest003, TestSize.Level0) } } +HWTEST_F(DocumentDBDataTest, UpsertDataTest004, TestSize.Level0) {} + +HWTEST_F(DocumentDBDataTest, UpsertDataTest005, TestSize.Level0) {} + /** * @tc.name: UpsertDataTest006 * @tc.desc: Test upsert data with invalid flags @@ -240,6 +244,24 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest003, TestSize.Level0) } } +/** + * @tc.name: UpdateDataTest004 + * @tc.desc: Test update data with invalid filter + * @tc.type: FUNC + * @tc.require: + * @tc.author: lianhuix + */ +HWTEST_F(DocumentDBDataTest, UpdateDataTest004, TestSize.Level0) {} + +/** + * @tc.name: UpdateDataTest005 + * @tc.desc: Test update data with invalid doc + * @tc.type: FUNC + * @tc.require: + * @tc.author: lianhuix + */ +HWTEST_F(DocumentDBDataTest, UpdateDataTest005, TestSize.Level0) {} + /** * @tc.name: UpdateDataTest006 * @tc.desc: Test update data with invalid flag diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index 1724e1ba..b3dce8a7 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -81,7 +81,8 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v std::pair RdbCloud::Lock() { auto error = cloudDB_->Lock(); - return std::make_pair(ConvertStatus(static_cast(error)), cloudDB_->AliveTime() * 1000); // int64_t <-> uint32_t, s <-> ms + return std::make_pair( // int64_t <-> uint32_t, s <-> ms + ConvertStatus(static_cast(error)), cloudDB_->AliveTime() * TO_MS); } DBStatus RdbCloud::UnLock() diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.h b/services/distributeddataservice/service/rdb/rdb_cloud.h index 30e4ee59..0fac9033 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.h +++ b/services/distributeddataservice/service/rdb/rdb_cloud.h @@ -41,6 +41,7 @@ public: DBStatus ConvertStatus(DistributedData::GeneralError error); private: + static constexpr int32_t TO_MS = 1000; // s > ms std::shared_ptr cloudDB_; }; } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index bcb98824..8049f3a2 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -65,7 +65,7 @@ RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appI option.iterateTimes = ITERATE_TIMES; option.cipher = CipherType::AES_256_GCM; } - option.observer = nullptr; + option.observer = &observer_; manager_.OpenStore(meta.dataDir, meta.storeId, option, delegate_); RdbStoreConfig config(meta.dataDir); config.SetCreateNecessary(false); diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 62c8c307..127e7b52 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -66,7 +66,10 @@ private: using DBOrigin = DistributedDB::Origin; void OnChange(const DistributedDB::StoreChangedData &data) override; void OnChange(DBOrigin origin, const std::string &originalId, DBChangedData &&data) override; - bool HasWatcher() const { return watcher_ == nullptr; }; + bool HasWatcher() const + { + return watcher_ == nullptr; + } private: friend RdbGeneralStore; Watcher *watcher_ = nullptr; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index fe50811b..72db4559 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -497,18 +497,30 @@ int32_t RdbServiceImpl::Subscribe(const RdbSyncerParam ¶m, const SubscribeOp int32_t RdbServiceImpl::UnSubscribe(const RdbSyncerParam ¶m, const SubscribeOption &option, RdbStoreObserver *observer) { - auto identifier = GenIdentifier(param); - ZLOGI("%{public}s %{public}.6s", param.storeName_.c_str(), identifier.c_str()); - identifiers_.Erase(identifier); - syncAgents_.ComputeIfPresent(IPCSkeleton::GetCallingTokenID(), [](auto &key, SyncAgent &agent) { - if (agent.count_ > 0) { - agent.count_--; + switch (option.mode) { + case SubscribeMode::REMOTE: { + auto identifier = GenIdentifier(param); + ZLOGI("%{public}s %{public}.6s", param.storeName_.c_str(), identifier.c_str()); + identifiers_.Erase(identifier); + break; } - if (agent.count_ == 0) { - agent.SetWatcher(nullptr); + case SubscribeMode::CLOUD: // fallthrough + case SubscribeMode::CLOUD_DETAIL: { + syncAgents_.ComputeIfPresent(IPCSkeleton::GetCallingTokenID(), [](auto &key, SyncAgent &agent) { + if (agent.count_ > 0) { + agent.count_--; + } + if (agent.count_ == 0) { + agent.SetWatcher(nullptr); + } + return true; + }); + break; } - return true; - }); + default: + ZLOGI("mode:%{public}d", option.mode); + return RDB_ERROR; + } return RDB_OK; } diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 8e9fb981..b8500014 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -140,7 +140,6 @@ void CloudDataTest::SetUpTestCase(void) }); auto cloudServerMock = new CloudServerMock(); - //ASSERT_TRUE(CloudServer::RegisterCloudInstance(cloudServerMock)); CloudServer::RegisterCloudInstance(cloudServerMock); FeatureSystem::GetInstance().GetCreator("cloud")(); FeatureSystem::GetInstance().GetCreator("relational_store")(); diff --git a/services/distributeddataservice/service/test/value_proxy_test.cpp b/services/distributeddataservice/service/test/value_proxy_test.cpp index df911512..672b9b2a 100644 --- a/services/distributeddataservice/service/test/value_proxy_test.cpp +++ b/services/distributeddataservice/service/test/value_proxy_test.cpp @@ -14,9 +14,9 @@ */ #define LOG_TAG "CloudDataTest" -#include "value_proxy.h" #include #include "log_print.h" +#include "value_proxy.h" namespace Test { using namespace testing::ext; using namespace OHOS::DistributedRdb; @@ -90,13 +90,13 @@ HWTEST_F(ValueProxyTest, VBucketsRdb2Normal, TestSize.Level0) using RdbBucket = OHOS::NativeRdb::ValuesBucket; using RdbValue = OHOS::NativeRdb::ValueObject; std::vector rdbVBuckets = { - RdbBucket(std::map{ + RdbBucket(std::map { {"#gid", {"0000000"}}, {"#flag", {true }}, {"#value", {int64_t(100)}}, {"#float", {double(100)}} }), - RdbBucket(std::map{ + RdbBucket(std::map { {"#gid", {"0000001"}} }) }; -- Gitee From b4bd6e797741f9385de8ead1c168609d2c6fc9d6 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 11:57:45 +0800 Subject: [PATCH 182/437] update Signed-off-by: zuojiangjiang --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index a6f4a8fc..820c7438 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -340,7 +340,7 @@ bool AddSpliteHitField(const JsonObject &src, const JsonObject &item, JsonFieldP return true; } - for (int32_t i = (int32_t)(abandonPath.size()) - 1; i > -1; i--) { + for (int32_t i = (int32_t)abandonPath.size() - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; @@ -382,7 +382,7 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie return false; } JsonFieldPath newHitPath; - for (int32_t i = (int32_t)(abandonPath.size()) - 1; i > -1; i--) { + for (int32_t i = (int32_t)abandonPath.size() - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { GLOGE("Add collapse item to object failed, path not exist."); externErrCode = -E_DATA_CONFLICT; -- Gitee From fc499c959b83da7e9d431ed98e6131d402a4a30e Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 14:09:40 +0800 Subject: [PATCH 183/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/framework/utils/constant.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/utils/constant.cpp b/services/distributeddataservice/framework/utils/constant.cpp index d1c0d148..efc99c06 100644 --- a/services/distributeddataservice/framework/utils/constant.cpp +++ b/services/distributeddataservice/framework/utils/constant.cpp @@ -14,7 +14,7 @@ */ #define LOG_TAG "Constant" #include "utils/constant.h" - +#include #include "log_print.h" #include "securec.h" -- Gitee From 00de5021ad5cd65a3849d1ea9955e21eb406dcf2 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 14:23:06 +0800 Subject: [PATCH 184/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 4 ++-- .../distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index c2a9ce09..1084cce7 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -78,7 +78,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map SyncManager::GetSyncHandler() } ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), storeInfo.storeName.c_str()); - store->Sync({ "default" }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); + store->Sync( { "default" }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); }; } -- Gitee From ff10ca0aa81a9b761e814fc98334c5ae51cca87c Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 8 Jun 2023 14:32:36 +0800 Subject: [PATCH 185/437] f Signed-off-by: hanlu --- .../service/data_share/common/uri_utils.cpp | 6 +++++- .../service/data_share/common/uri_utils.h | 2 +- .../strategies/general/load_config_common_strategy.cpp | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.cpp b/services/distributeddataservice/service/data_share/common/uri_utils.cpp index c5bbe380..322a6fb8 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.cpp +++ b/services/distributeddataservice/service/data_share/common/uri_utils.cpp @@ -24,6 +24,7 @@ namespace OHOS::DataShare { constexpr const char USER_PARAM[] = "user"; constexpr const char TOKEN_ID_PARAM[] = "srcToken"; +constexpr const char DST_BUNDLE_NAME_PARAM[] = "dstBundleName"; bool URIUtils::GetInfoFromURI(const std::string &uri, UriInfo &uriInfo) { Uri uriTemp(uri); @@ -62,7 +63,8 @@ bool URIUtils::GetBundleNameFromProxyURI(const std::string &uri, std::string &bu return true; } -bool URIUtils::GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32_t &callerTokenId) +bool URIUtils::GetInfoFromProxyURI( + const std::string &uri, int32_t &user, uint32_t &callerTokenId, std::string &calledBundleName) { auto queryPos = uri.find_first_of('?'); if (queryPos == std::string::npos) { @@ -87,6 +89,8 @@ bool URIUtils::GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32 user = std::stoi(value); } else if (query.compare(pos, sizeof(TOKEN_ID_PARAM) - 1, TOKEN_ID_PARAM) == 0) { callerTokenId = std::stoul(value); + } else if (query.compare(pos, sizeof(DST_BUNDLE_NAME_PARAM) - 1, DST_BUNDLE_NAME_PARAM) == 0) { + calledBundleName = value; } } if (nextPos == std::string::npos) { diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.h b/services/distributeddataservice/service/data_share/common/uri_utils.h index f7960682..e88b21b4 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.h +++ b/services/distributeddataservice/service/data_share/common/uri_utils.h @@ -29,7 +29,7 @@ class URIUtils { public: static bool GetInfoFromURI(const std::string &uri, UriInfo &uriInfo); static bool GetBundleNameFromProxyURI(const std::string &uri, std::string &bundleName); - static bool GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32_t &callerTokenId); + static bool GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32_t &callerTokenId, std::string &calledBundleName); static bool IsDataProxyURI(const std::string &uri); static constexpr const char *DATA_SHARE_SCHEMA = "datashare:///";; static constexpr const char DATA_PROXY_SCHEMA[] = "datashareproxy://"; diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp index 70433c3e..fd1f8d93 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp @@ -31,7 +31,8 @@ bool LoadConfigCommonStrategy::operator()(std::shared_ptr context) context->currentUserId = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(context->callerTokenId); // sa, userId is in uri, caller token id is from first caller tokenId if (context->currentUserId == 0) { - URIUtils::GetInfoFromProxyURI(context->uri, context->currentUserId, context->callerTokenId); + URIUtils::GetInfoFromProxyURI( + context->uri, context->currentUserId, context->callerTokenId, context->calledBundleName); } if (context->needAutoLoadCallerBundleName && context->callerBundleName.empty()) { Security::AccessToken::HapTokenInfo tokenInfo; -- Gitee From 42fe03d3c351624f04e1bd30c62bc050e54861ca Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 14:55:53 +0800 Subject: [PATCH 186/437] update Signed-off-by: zuojiangjiang --- .../framework/include/cloud/change_event.h | 2 +- .../include/metadata/store_meta_data.h | 1 + .../framework/include/store/general_store.h | 4 ++-- .../framework/metadata/store_meta_data.cpp | 6 ++++++ .../service/cloud/cloud_service_impl.cpp | 7 +------ .../service/cloud/sync_manager.cpp | 12 ++++++------ .../service/object/object_service_impl.cpp | 6 ++++-- .../service/rdb/rdb_service_impl.cpp | 17 +++++++++-------- .../service/rdb/rdb_syncer.cpp | 8 ++++---- 9 files changed, 34 insertions(+), 29 deletions(-) diff --git a/services/distributeddataservice/framework/include/cloud/change_event.h b/services/distributeddataservice/framework/include/cloud/change_event.h index b0b4e87a..cf969698 100644 --- a/services/distributeddataservice/framework/include/cloud/change_event.h +++ b/services/distributeddataservice/framework/include/cloud/change_event.h @@ -23,7 +23,7 @@ public: ChangeEvent(StoreInfo storeInfo, EventInfo info) : SyncEvent(LOCAL_CHANGE, std::move(storeInfo), std::move(info)) { - }; + } ~ChangeEvent() override = default; }; } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/framework/include/metadata/store_meta_data.h b/services/distributeddataservice/framework/include/metadata/store_meta_data.h index bb134e35..e40965fd 100644 --- a/services/distributeddataservice/framework/include/metadata/store_meta_data.h +++ b/services/distributeddataservice/framework/include/metadata/store_meta_data.h @@ -70,6 +70,7 @@ struct API_EXPORT StoreMetaData final : public Serializable { API_EXPORT std::string GetSecretKey() const; API_EXPORT std::string GetStrategyKey() const; API_EXPORT std::string GetBackupSecretKey() const; + API_EXPORT std::string GetStoreAlias() const; API_EXPORT static std::string GetKey(const std::initializer_list &fields); API_EXPORT static std::string GetPrefix(const std::initializer_list &fields); diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index fc52bd8d..0ee2012a 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -35,8 +35,8 @@ public: NEARBY_PUSH = NEARBY_BEGIN, NEARBY_PULL, NEARBY_PULL_PUSH, - NEARBY_END = 4, - CLOUD_BEGIN = NEARBY_END, + NEARBY_END, + CLOUD_BEGIN = 4, CLOUD_TIME_FIRST = CLOUD_BEGIN, CLOUD_NATIVE_FIRST, CLOUD_ClOUD_FIRST, diff --git a/services/distributeddataservice/framework/metadata/store_meta_data.cpp b/services/distributeddataservice/framework/metadata/store_meta_data.cpp index d7867f89..09bcd61e 100644 --- a/services/distributeddataservice/framework/metadata/store_meta_data.cpp +++ b/services/distributeddataservice/framework/metadata/store_meta_data.cpp @@ -18,6 +18,7 @@ #include "metadata/secret_key_meta_data.h" #include "metadata/store_meta_data_local.h" #include "metadata/strategy_meta_data.h" +#include "utils/anonymous.h" #include "utils/constant.h" namespace OHOS { namespace DistributedData { @@ -154,6 +155,11 @@ std::string StoreMetaData::GetBackupSecretKey() const return SecretKeyMetaData::GetBackupKey({ user, "default", bundleName, storeId, std::to_string(instanceId) }); } +std::string StoreMetaData::GetStoreAlias() const +{ + return Anonymous::Change(storeId); +} + std::string StoreMetaData::GetStrategyKey() const { if (instanceId == 0) { diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 1084cce7..b8b1b20a 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -227,7 +227,6 @@ int32_t CloudServiceImpl::GetCloudInfoFromServer(CloudInfo &cloudInfo) { auto instance = CloudServer::GetInstance(); if (instance == nullptr) { - ZLOGW("cloud server unavailable"); return NOT_SUPPORT; } cloudInfo = instance->GetServerInfo(cloudInfo.user); @@ -258,7 +257,6 @@ bool CloudServiceImpl::UpdateCloudInfo(int32_t user) for (auto &[bundle, app] : cloudInfo.apps) { actions[bundle] = CLEAR_CLOUD_INFO; } - Clean(oldInfo.id, actions); } MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); @@ -291,7 +289,6 @@ int32_t CloudServiceImpl::GetAppSchema(int32_t user, const std::string &bundleNa { auto instance = CloudServer::GetInstance(); if (instance == nullptr) { - ZLOGW("cloud server unavailable"); return SERVER_UNAVAILABLE; } schemaMeta = instance->GetAppSchema(user, bundleName); @@ -356,7 +353,6 @@ SchemaMeta CloudServiceImpl::GetSchemaMeta(int32_t userId, const std::string &bu auto instance = CloudServer::GetInstance(); if (instance == nullptr) { - ZLOGE("instance is nullptr"); return schemaMeta; } schemaMeta = instance->GetAppSchema(userId, bundleName); @@ -376,7 +372,6 @@ CloudInfo CloudServiceImpl::GetCloudInfo(int32_t userId) } auto instance = CloudServer::GetInstance(); if (instance == nullptr) { - ZLOGD("no cloud server"); return cloudInfo; } @@ -395,7 +390,7 @@ void CloudServiceImpl::GetSchema(const Event &event) auto &rdbEvent = static_cast(event); auto &storeInfo = rdbEvent.GetStoreInfo(); ZLOGD("Start GetSchema, bundleName:%{public}s, storeName:%{public}s, instanceId:%{public}d", - storeInfo.bundleName.c_str(), storeInfo.storeName.c_str(), storeInfo.instanceId); + storeInfo.bundleName.c_str(), Anonymous::Change(storeInfo.storeName).c_str(), storeInfo.instanceId); GetSchemaMeta(storeInfo.user, storeInfo.bundleName, storeInfo.instanceId); } diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 7eca8c8d..883c818a 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -16,6 +16,7 @@ #include "sync_manager.h" #include "cloud/cloud_info.h" +#include "cloud/cloud_server.h" #include "cloud/schema_meta.h" #include "cloud/sync_event.h" #include "device_manager_adapter.h" @@ -23,7 +24,7 @@ #include "log_print.h" #include "metadata/meta_data_manager.h" #include "store/auto_cache.h" -#include "cloud/cloud_server.h" +#include "utils/anonymous.h" namespace OHOS::CloudData { using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; @@ -174,7 +175,6 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf if (!cloud.enableCloud || cloud.id != info.id_ || (!info.bundleName_.empty() && !cloud.IsOn(info.bundleName_))) { info.SetError(E_UNOPENED); - ZLOGI("cloud off bundleName:%{public}s", info.bundleName_.c_str()); return; } @@ -223,12 +223,12 @@ std::function SyncManager::GetSyncHandler() meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; if (!MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)) { ZLOGE("failed, no store meta bundleName:%{public}s, storeId:%{public}s", meta.bundleName.c_str(), - meta.storeId.c_str()); + meta.GetStoreAlias().c_str()); return; } auto store = AutoCache::GetInstance().GetStore(meta, {}); if (store == nullptr) { - ZLOGE("store null, storeId:%{public}s", meta.storeId.c_str()); + ZLOGE("store null, storeId:%{public}s", meta.GetStoreAlias().c_str()); return; } @@ -239,7 +239,7 @@ std::function SyncManager::GetSyncHandler() std::string schemaKey = info.GetSchemaKey(storeInfo.bundleName, storeInfo.instanceId); if (!MetaDataManager::GetInstance().LoadMeta(std::move(schemaKey), schemaMeta, true)) { ZLOGE("failed, no schema bundleName:%{public}s, storeId:%{public}s", storeInfo.bundleName.c_str(), - storeInfo.storeName.c_str()); + Anonymous::Change(storeInfo.storeName).c_str()); return; } auto dbMeta = schemaMeta.GetDataBase(storeInfo.storeName); @@ -252,7 +252,7 @@ std::function SyncManager::GetSyncHandler() store->Bind(dbMeta, std::move(cloudDB)); } ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), - storeInfo.storeName.c_str()); + Anonymous::Change(storeInfo.storeName).c_str()); store->Sync( { "default" }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); }; } diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index ccd1e57a..a058b9ae 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -112,7 +112,8 @@ int32_t ObjectServiceImpl::OnInitialize() if (!saved) { ZLOGE("Save appIdMeta failed"); } - ZLOGI("SaveMeta success appId %{public}s, storeId %{public}s", saveMeta.appId.c_str(), saveMeta.storeId.c_str()); + ZLOGI("SaveMeta success appId %{public}s, storeId %{public}s", + saveMeta.appId.c_str(), saveMeta.GetStoreAlias().c_str()); return OBJECT_SUCCESS; } @@ -235,7 +236,8 @@ int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, Dist { ZLOGI("ObjectServiceImpl::ResolveAutoLaunch start"); ZLOGI("user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), - param.appId.c_str(), param.storeId.c_str(), DistributedData::Anonymous::Change(identifier).c_str()); + param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), + DistributedData::Anonymous::Change(identifier).c_str()); std::vector metaData; auto prefix = StoreMetaData::GetPrefix({ DmAdapter::GetInstance().GetLocalDevice().uuid, param.userId }); if (!DistributedData::MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 72db4559..e9e9a370 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -85,13 +85,13 @@ RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) meta.deviceId = DmAdapter::GetInstance().GetLocalDevice().uuid; if (!MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), meta)) { ZLOGE("meta empty, bundleName:%{public}s, storeId:%{public}s", meta.bundleName.c_str(), - Anonymous::Change(meta.storeId).c_str()); + meta.GetStoreAlias().c_str()); return; } auto watchers = GetWatchers(meta.tokenId, meta.storeId); auto store = AutoCache::GetInstance().GetStore(meta, watchers); if (store == nullptr) { - ZLOGE("store null, storeId:%{public}s", Anonymous::Change(meta.storeId).c_str()); + ZLOGE("store null, storeId:%{public}s", meta.GetStoreAlias().c_str()); return; } }; @@ -116,11 +116,12 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib auto aIdentifier = DistributedDB::RelationalStoreManager::GetRelationalStoreIdentifier( entry.user, entry.appId, entry.storeId); - ZLOGI("%{public}s %{public}s %{public}s", entry.user.c_str(), entry.appId.c_str(), entry.storeId.c_str()); + ZLOGI("%{public}s %{public}s %{public}s", + entry.user.c_str(), entry.appId.c_str(), Anonymous::Change(entry.storeId).c_str()); if (aIdentifier != identifier) { continue; } - ZLOGI("find identifier %{public}s", entry.storeId.c_str()); + ZLOGI("find identifier %{public}s", Anonymous::Change(entry.storeId).c_str()); param.userId = entry.user; param.appId = entry.appId; param.storeId = entry.storeId; @@ -216,7 +217,7 @@ void RdbServiceImpl::OnDataChange(pid_t pid, uint32_t tokenId, const Distributed { DistributedDB::StoreProperty property; data.GetStoreProperty(property); - ZLOGI("%{public}d %{public}s", pid, property.storeId.c_str()); + ZLOGI("%{public}d %{public}s", pid, Anonymous::Change(property.storeId).c_str()); if (pid == 0) { auto identifier = RelationalStoreManager::GetRelationalStoreIdentifier(property.userId, property.appId, property.storeId); @@ -588,7 +589,7 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat old.area != meta.area)) { ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + meta.bundleName.c_str(), meta.GetStoreAlias().c_str(), old.storeType, meta.storeType, old.isEncrypt, meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } @@ -596,7 +597,7 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat Upgrade(param, old); ZLOGD("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + meta.bundleName.c_str(), meta.GetStoreAlias().c_str(), old.storeType, meta.storeType, old.isEncrypt, meta.isEncrypt, old.area, meta.area); MetaDataManager::GetInstance().SaveMeta(meta.GetKey(), meta); } @@ -606,7 +607,7 @@ int32_t RdbServiceImpl::CreateMetaData(const RdbSyncerParam ¶m, StoreMetaDat if (!MetaDataManager::GetInstance().SaveMeta(appIdMeta.GetKey(), appIdMeta, true)) { ZLOGE("meta bundle:%{public}s store:%{public}s type:%{public}d->%{public}d encrypt:%{public}d->%{public}d " "area:%{public}d->%{public}d", - meta.bundleName.c_str(), Anonymous::Change(meta.storeId).c_str(), old.storeType, meta.storeType, + meta.bundleName.c_str(), meta.GetStoreAlias().c_str(), old.storeType, meta.storeType, old.isEncrypt, meta.isEncrypt, old.area, meta.area); return RDB_ERROR; } diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 22b17899..4edc6ac0 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -44,13 +44,13 @@ namespace OHOS::DistributedRdb { RdbSyncer::RdbSyncer(const RdbSyncerParam& param, RdbStoreObserverImpl* observer) : param_(param), observer_(observer) { - ZLOGI("construct %{public}s", param_.storeName_.c_str()); + ZLOGI("construct %{public}s", Anonymous::Change(param_.storeName_).c_str()); } RdbSyncer::~RdbSyncer() noexcept { param_.password_.assign(param_.password_.size(), 0); - ZLOGI("destroy %{public}s", param_.storeName_.c_str()); + ZLOGI("destroy %{public}s", Anonymous::Change(param_.storeName_).c_str()); if ((manager_ != nullptr) && (delegate_ != nullptr)) { manager_->CloseStore(delegate_); } @@ -167,11 +167,11 @@ int32_t RdbSyncer::InitDBDelegate(const StoreMetaData &meta) } option.observer = observer_; std::string fileName = meta.dataDir; - ZLOGI("path=%{public}s storeId=%{public}s", fileName.c_str(), Anonymous::Change(meta.storeId).c_str()); + ZLOGI("path=%{public}s storeId=%{public}s", fileName.c_str(), meta.GetStoreAlias().c_str()); auto status = manager_->OpenStore(fileName, meta.storeId, option, delegate_); if (status != DistributedDB::DBStatus::OK) { ZLOGE("open store failed, path=%{public}s storeId=%{public}s status=%{public}d", - fileName.c_str(), Anonymous::Change(meta.storeId).c_str(), status); + fileName.c_str(), meta.GetStoreAlias().c_str(), status); return RDB_ERROR; } ZLOGI("open store success"); -- Gitee From 0cbbba591e9d7d654316427cf074cf3c5723491e Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 15:19:19 +0800 Subject: [PATCH 187/437] update Signed-off-by: zuojiangjiang --- .../service/object/object_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index a058b9ae..7158f8ef 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -236,7 +236,7 @@ int32_t ObjectServiceImpl::ResolveAutoLaunch(const std::string &identifier, Dist { ZLOGI("ObjectServiceImpl::ResolveAutoLaunch start"); ZLOGI("user:%{public}s appId:%{public}s storeId:%{public}s identifier:%{public}s", param.userId.c_str(), - param.appId.c_str(), Anonymous::Change(param.storeId).c_str(), + param.appId.c_str(), DistributedData::Anonymous::Change(param.storeId).c_str(), DistributedData::Anonymous::Change(identifier).c_str()); std::vector metaData; auto prefix = StoreMetaData::GetPrefix({ DmAdapter::GetInstance().GetLocalDevice().uuid, param.userId }); -- Gitee From f3ab889efa5da74312c462ac862760d7aa6051d5 Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 8 Jun 2023 15:42:36 +0800 Subject: [PATCH 188/437] f Signed-off-by: hanlu --- .../service/data_share/common/uri_utils.h | 3 ++- .../service/data_share/data_share_service_impl.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.h b/services/distributeddataservice/service/data_share/common/uri_utils.h index e88b21b4..4bfca5c4 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.h +++ b/services/distributeddataservice/service/data_share/common/uri_utils.h @@ -29,7 +29,8 @@ class URIUtils { public: static bool GetInfoFromURI(const std::string &uri, UriInfo &uriInfo); static bool GetBundleNameFromProxyURI(const std::string &uri, std::string &bundleName); - static bool GetInfoFromProxyURI(const std::string &uri, int32_t &user, uint32_t &callerTokenId, std::string &calledBundleName); + static bool GetInfoFromProxyURI( + const std::string &uri, int32_t &user, uint32_t &callerTokenId, std::string &calledBundleName); static bool IsDataProxyURI(const std::string &uri); static constexpr const char *DATA_SHARE_SCHEMA = "datashare:///";; static constexpr const char DATA_PROXY_SCHEMA[] = "datashareproxy://"; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 41b981b5..adc757e7 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -263,7 +263,7 @@ std::vector DataShareServiceImpl::SubscribePublishedData(const }); results.emplace_back(uri, result); if (result == E_OK) { - publishedKeys.emplace_back(key); + publishedKeys.emplace_back(context->uri, context->callerBundleName, subscriberId); } } PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, callerBundleName, observer); -- Gitee From 7955a1dc1a0f1417ca457a345f3fdd14de2ababf Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 17:15:55 +0800 Subject: [PATCH 189/437] update Signed-off-by: zuojiangjiang --- datamgr_service.gni | 2 ++ services/distributeddataservice/service/rdb/rdb_cloud.cpp | 6 ++++-- services/distributeddataservice/service/test/BUILD.gn | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/datamgr_service.gni b/datamgr_service.gni index 15f8ddfc..df29ed1d 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -17,6 +17,8 @@ kv_store_path = "//foundation/distributeddatamgr/kv_store" relational_store_path = "//foundation/distributeddatamgr/relational_store" +relational_store_inner_api_path = "${relational_store_path}/interfaces/inner_api/rdb" + kv_store_common_path = "${kv_store_path}/frameworks/common" kv_store_distributeddb_path = "${kv_store_path}/frameworks/libs/distributeddb" diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index b3dce8a7..64c95b11 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -17,6 +17,7 @@ #include "rdb_cloud.h" #include "log_print.h" #include "value_proxy.h" +#include "utils/anonymous.h" namespace OHOS::DistributedRdb { using namespace DistributedDB; @@ -55,7 +56,8 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v { auto cursor = cloudDB_->Query(tableName, ValueProxy::Convert(std::move(extend))); if (cursor == nullptr) { - ZLOGE("cursor is null, table:%{public}s, extend:%{public}zu", tableName.c_str(), extend.size()); + ZLOGE("cursor is null, table:%{public}s, extend:%{public}zu", + Anonymous::Change(tableName).c_str(), extend.size());+ return ConvertStatus(static_cast(E_ERROR)); } int32_t count = cursor->GetCount(); @@ -72,7 +74,7 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v count--; } if (cursor->IsEnd()) { - ZLOGD("query end, table:%{public}s", tableName.c_str()); + ZLOGD("query end, table:%{public}s", Anonymous::Change(tableName).c_str()); return DBStatus::QUERY_END; } return ConvertStatus(static_cast(err)); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index b62f9814..c89d8ae1 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -71,8 +71,8 @@ ohos_unittest("CloudDataTest") { ohos_unittest("ValueProxyTest") { module_out_path = module_output_path sources = [ - "value_proxy_test.cpp", "../rdb/value_proxy.cpp", + "value_proxy_test.cpp", ] include_dirs = @@ -91,7 +91,7 @@ ohos_unittest("ValueProxyTest") { deps = [ "${kv_store_distributeddb_path}:distributeddb", - "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb:native_rdb_static", + "${relational_store_inner_api_path}:native_rdb_static" "../../adapter:distributeddata_adapter", "../../framework:distributeddatasvcfwk", "../../service:distributeddatasvc", -- Gitee From a2ad048e3fb5e60d3067f90bdf6ed0cff4a82cb2 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 17:25:40 +0800 Subject: [PATCH 190/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/test/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index c89d8ae1..c28c697a 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -91,7 +91,7 @@ ohos_unittest("ValueProxyTest") { deps = [ "${kv_store_distributeddb_path}:distributeddb", - "${relational_store_inner_api_path}:native_rdb_static" + "${relational_store_inner_api_path}:native_rdb_static", "../../adapter:distributeddata_adapter", "../../framework:distributeddatasvcfwk", "../../service:distributeddatasvc", -- Gitee From c0f6b392d4379636995980c3f5888a3da430e4ad Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 17:29:22 +0800 Subject: [PATCH 191/437] update Signed-off-by: zuojiangjiang --- datamgr_service.gni | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/datamgr_service.gni b/datamgr_service.gni index df29ed1d..2537c568 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -17,7 +17,8 @@ kv_store_path = "//foundation/distributeddatamgr/kv_store" relational_store_path = "//foundation/distributeddatamgr/relational_store" -relational_store_inner_api_path = "${relational_store_path}/interfaces/inner_api/rdb" +relational_store_inner_api_path = + "${relational_store_path}/interfaces/inner_api/rdb" kv_store_common_path = "${kv_store_path}/frameworks/common" -- Gitee From 3e6046e0fe428fdb25739a30f64a619de00bdd9b Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 18:42:31 +0800 Subject: [PATCH 192/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/rdb/rdb_cloud.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index 64c95b11..e3d16735 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -57,7 +57,7 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v auto cursor = cloudDB_->Query(tableName, ValueProxy::Convert(std::move(extend))); if (cursor == nullptr) { ZLOGE("cursor is null, table:%{public}s, extend:%{public}zu", - Anonymous::Change(tableName).c_str(), extend.size());+ + Anonymous::Change(tableName).c_str(), extend.size()); return ConvertStatus(static_cast(E_ERROR)); } int32_t count = cursor->GetCount(); -- Gitee From 543ea7f8753045b51d54bc1e742054274735b73f Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 8 Jun 2023 21:36:14 +0800 Subject: [PATCH 193/437] update Signed-off-by: zuojiangjiang --- .../service/rdb/rdb_general_store.cpp | 13 +++++++++---- .../service/rdb/rdb_syncer.cpp | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 8049f3a2..bda01958 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -185,13 +185,18 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu dbQuery = rdbQuery->query_; } auto dbMode = DistributedDB::SyncMode(mode); - auto status = (mode < CLOUD_BEGIN) - ? delegate_->Sync(devices, dbMode, dbQuery, GetDBBriefCB(std::move(async)), wait) - : delegate_->Sync(devices, dbMode, dbQuery, GetDBProcessCB(std::move(async)), wait); + auto status = (mode < NEARBY_END) + ? delegate_->Sync(devices, dbMode, dbQuery, GetDBBriefCB(std::move(async)), wait) + : (mode > NEARBY_END && mode < CLOUD_END) + ? delegate_->Sync(devices, dbMode, dbQuery, GetDBProcessCB(std::move(async)), wait) + : DistributedDB::INVALID_ARGS; // mock if (observer_.HasWatcher()) { Watcher::Origin origin; - origin.origin = (mode < CLOUD_BEGIN) ? Watcher::Origin::ORIGIN_NEARBY : Watcher::Origin::ORIGIN_CLOUD; + origin.origin = (mode < NEARBY_END) ? Watcher::Origin::ORIGIN_NEARBY + : (mode > NEARBY_END && mode < CLOUD_END) + ? Watcher::Origin::ORIGIN_CLOUD + : Watcher::Origin::ORIGIN_BUTT; origin.id = devices; origin.store = observer_.storeId_; observer_.watcher_->OnChange(origin, {}, {}); diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 4edc6ac0..8cb8dd3f 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -370,7 +370,8 @@ int32_t RdbSyncer::DoSync(const Option &option, const PredicatesMemo &predicates async(HandleSyncStatus(syncStatus)); }, !option.isAsync); - } else if (option.mode < DistributedData::GeneralStore::CLOUD_END) { + } else if (option.mode < DistributedData::GeneralStore::CLOUD_END && + option.mode >= DistributedData::GeneralStore::CLOUD_BEGIN) { CloudEvent::StoreInfo storeInfo; storeInfo.bundleName = GetBundleName(); storeInfo.user = AccountDelegate::GetInstance()->GetUserByToken(token_); -- Gitee From 1be92a9cbd1d584e63078e74e2295d89df4d07e5 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 9 Jun 2023 15:27:35 +0800 Subject: [PATCH 194/437] dfx Signed-off-by: niudongyao --- .../service/data_share/BUILD.gn | 1 + .../data_share/common/template_manager.cpp | 12 +-- .../data_share/common/template_manager.h | 4 +- .../data_share/data_share_service_impl.cpp | 22 +++-- .../data_share/data_share_service_impl.h | 4 +- .../data_share/data_share_service_stub.cpp | 5 +- .../service/data_share/idata_share_service.h | 2 +- .../strategies/get_data_strategy.cpp | 4 +- .../data_share/strategies/get_data_strategy.h | 2 +- .../strategies/publish_strategy.cpp | 3 +- .../strategies/template_strategy.cpp | 91 +++++++++++++++++++ .../data_share/strategies/template_strategy.h | 38 ++++++++ 12 files changed, 167 insertions(+), 21 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/strategies/template_strategy.cpp create mode 100644 services/distributeddataservice/service/data_share/strategies/template_strategy.h diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 7acbbb7a..a917fb54 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -70,6 +70,7 @@ ohos_shared_library("data_share_service") { "strategies/publish_strategy.cpp", "strategies/query_strategy.cpp", "strategies/subscribe_strategy.cpp", + "strategies/template_strategy.cpp", "strategies/update_strategy.cpp", ] cflags = [ "-Wno-multichar" ] diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 03520d14..ebf7cd33 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -32,25 +32,25 @@ bool TemplateManager::GetTemplate( return TemplateData::Query(Id(TemplateData::GenId(uri, bundleName, subscriberId)), tpl) == E_OK; } -bool TemplateManager::AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl) +int32_t TemplateManager::AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl) { auto status = TemplateData::Add(uri, tplId.bundleName_, tplId.subscriberId_, tpl); if (!status) { ZLOGE("Add failed, %{public}d", status); - return false; + return E_ERROR; } - return true; + return E_OK; } -bool TemplateManager::DelTemplate(const std::string &uri, const TemplateId &tplId) +int32_t TemplateManager::DelTemplate(const std::string &uri, const TemplateId &tplId) { auto status = TemplateData::Delete(uri, tplId.bundleName_, tplId.subscriberId_); if (!status) { ZLOGE("Delete failed, %{public}d", status); - return false; + return E_ERROR; } SchedulerManager::GetInstance().RemoveTimer(Key(uri, tplId.subscriberId_, tplId.bundleName_)); - return true; + return E_OK; } Key::Key(const std::string &uri, const int64_t subscriberId, const std::string &bundleName) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index e2df7f6f..a91e6886 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -40,8 +40,8 @@ struct Key { class TemplateManager { public: static TemplateManager &GetInstance(); - bool AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl); - bool DelTemplate(const std::string &uri, const TemplateId &tplId); + int32_t AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl); + int32_t DelTemplate(const std::string &uri, const TemplateId &tplId); bool GetTemplate(const std::string &uri, int64_t subscriberId, const std::string &bundleName, Template &tpl); private: diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index adc757e7..2ae40028 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -110,24 +110,34 @@ std::shared_ptr DataShareServiceImpl::Query(const std::strin int32_t DataShareServiceImpl::AddTemplate(const std::string &uri, const int64_t subscriberId, const Template &tplt) { + auto context = std::make_shared(uri); TemplateId tpltId; tpltId.subscriberId_ = subscriberId; if (!GetCallerBundleName(tpltId.bundleName_)) { - ZLOGE("get bundleName error, %{public}s", tpltId.bundleName_.c_str()); + ZLOGE("get bundleName error, %{public}s", DistributedData::Anonymous::Change(uri).c_str()); return ERROR; } - return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); + return templateStrategy_.Execute(context, [&uri, &tpltId, &tplt]() -> int32_t { + return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); + }); + // return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); } int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t subscriberId) { + ZLOGI("ndy DelTemplate enter."); + auto context = std::make_shared(uri); TemplateId tpltId; tpltId.subscriberId_ = subscriberId; if (!GetCallerBundleName(tpltId.bundleName_)) { - ZLOGE("get bundleName error, %{public}s", tpltId.bundleName_.c_str()); + ZLOGE("get bundleName error, %{public}s", DistributedData::Anonymous::Change(uri).c_str()); return ERROR; } - return TemplateManager::GetInstance().DelTemplate(uri, tpltId); + + return templateStrategy_.Execute(context, [&uri, &tpltId]() -> int32_t { + return TemplateManager::GetInstance().DelTemplate(uri, tpltId); + }); + // return TemplateManager::GetInstance().DelTemplate(uri, tpltId); } bool DataShareServiceImpl::GetCallerBundleName(std::string &bundleName) @@ -173,7 +183,7 @@ std::vector DataShareServiceImpl::Publish(const Data &data, con return results; } -Data DataShareServiceImpl::GetData(const std::string &bundleNameOfProvider) +Data DataShareServiceImpl::GetData(const std::string &bundleNameOfProvider, int &errorCode) { std::string callerBundleName; if (!GetCallerBundleName(callerBundleName)) { @@ -183,7 +193,7 @@ Data DataShareServiceImpl::GetData(const std::string &bundleNameOfProvider) auto context = std::make_shared(); context->callerBundleName = callerBundleName; context->calledBundleName = bundleNameOfProvider; - return getDataStrategy_.Execute(context); + return getDataStrategy_.Execute(context, errorCode); } std::vector DataShareServiceImpl::SubscribeRdbData( diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index e1a9138e..a9bab1d9 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -28,6 +28,7 @@ #include "publish_strategy.h" #include "query_strategy.h" #include "subscribe_strategy.h" +#include "template_strategy.h" #include "update_strategy.h" #include "uri_utils.h" #include "visibility.h" @@ -45,7 +46,7 @@ public: int32_t AddTemplate(const std::string &uri, const int64_t subscriberId, const Template &tplt) override; int32_t DelTemplate(const std::string &uri, const int64_t subscriberId) override; std::vector Publish(const Data &data, const std::string &bundleNameOfProvider) override; - Data GetData(const std::string &bundleNameOfProvider) override; + Data GetData(const std::string &bundleNameOfProvider, int &errorCode) override; std::vector SubscribeRdbData(const std::vector &uris, const TemplateId &id, const sptr observer) override; std::vector UnsubscribeRdbData( @@ -85,6 +86,7 @@ private: InsertStrategy insertStrategy_; QueryStrategy queryStrategy_; UpdateStrategy updateStrategy_; + TemplateStrategy templateStrategy_; BindInfo binderInfo_; }; } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index c46905a9..959e07b0 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -164,8 +164,9 @@ int32_t DataShareServiceStub::OnRemoteGetData(MessageParcel &data, MessageParcel return -1; } ZLOGE("hanlu bundleName %{public}s", bundleName.c_str()); - auto results = GetData(bundleName); - if (!ITypesUtil::Marshal(reply, results.datas_)) { + int errorCode = E_OK; + auto results = GetData(bundleName, errorCode); + if (!ITypesUtil::Marshal(reply, results.datas_, errorCode)) { ZLOGE("ITypesUtil::Marshal(reply, results) failed"); return -1; } diff --git a/services/distributeddataservice/service/data_share/idata_share_service.h b/services/distributeddataservice/service/data_share/idata_share_service.h index a4e22949..1ae6824f 100644 --- a/services/distributeddataservice/service/data_share/idata_share_service.h +++ b/services/distributeddataservice/service/data_share/idata_share_service.h @@ -61,7 +61,7 @@ public: virtual int32_t AddTemplate(const std::string &uri, const int64_t subscriberId, const Template &tplt) = 0; virtual int32_t DelTemplate(const std::string &uri, const int64_t subscriberId) = 0; virtual std::vector Publish(const Data &data, const std::string &bundleNameOfProvider) = 0; - virtual Data GetData(const std::string &bundleNameOfProvider) = 0; + virtual Data GetData(const std::string &bundleNameOfProvider, int &errorCode) = 0; virtual std::vector SubscribeRdbData( const std::vector &uris, const TemplateId &id, const sptr observer) = 0; virtual std::vector UnsubscribeRdbData( diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp index c4962d78..1486ad21 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp @@ -23,15 +23,17 @@ #include "utils/anonymous.h" namespace OHOS::DataShare { -Data GetDataStrategy::Execute(std::shared_ptr context) +Data GetDataStrategy::Execute(std::shared_ptr context, int &errorCode) { auto &preProcess = GetStrategy(); if (preProcess.IsEmpty()) { ZLOGE("get strategy fail, maybe memory not enough"); + errorCode = E_ERROR; return Data(); } if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); + errorCode = context->errCode; return Data(); } auto result = PublishedData::Query(context->calledBundleName); diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h index 1f7a4189..076bae8d 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.h @@ -26,7 +26,7 @@ namespace OHOS::DataShare { class GetDataStrategy final { public: - Data Execute(std::shared_ptr context); + Data Execute(std::shared_ptr context, int &errorCode); private: SeqStrategy &GetStrategy(); diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index a5f059f0..ac609f32 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -32,9 +32,10 @@ int32_t PublishStrategy::Execute(std::shared_ptr context, const Publish ZLOGE("get strategy fail, maybe memory not enough"); return -1; } + if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); - return -1; + return context->errCode; } auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { diff --git a/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp new file mode 100644 index 00000000..93f7254f --- /dev/null +++ b/services/distributeddataservice/service/data_share/strategies/template_strategy.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. + */ +#define LOG_TAG "AddTemplateStrategy" + +#include "template_strategy.h" + +#include "data_proxy/load_config_from_data_proxy_node_strategy.h" +#include "datashare_errno.h" +#include "general/load_config_common_strategy.h" +#include "log_print.h" +#include "template_manager.h" +#include "utils/anonymous.h" + +namespace OHOS::DataShare { +int32_t TemplateStrategy::Execute(std::shared_ptr context, std::function process) +{ + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { + ZLOGE("get strategy fail, maybe memory not enough"); + return E_ERROR; + } + + if (!preProcess(context)) { + ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); + return context->errCode; + } + return process(); +} + +//int32_t TemplateStrategy::ExecuteAddTemplate(std::shared_ptr context, const TemplateId &tpltId, const Template &tplt) +//{ +// auto &preProcess = GetStrategy(); +// if (preProcess.IsEmpty()) { +// ZLOGE("get strategy fail, maybe memory not enough"); +// return E_ERROR; +// } +// +// if (!preProcess(context)) { +// ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); +// return context->errCode; +// } +// return TemplateManager::GetInstance().AddTemplate(context->uri, tpltId, tplt); +//} +// +//int32_t TemplateStrategy::ExecuteDelTemplate(std::shared_ptr context, const TemplateId &tpltId) +//{ +// auto &preProcess = GetStrategy(); +// if (preProcess.IsEmpty()) { +// ZLOGE("get strategy fail, maybe memory not enough"); +// return E_ERROR; +// } +// +// if (!preProcess(context)) { +// ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); +// return context->errCode; +// } +// return TemplateManager::GetInstance().DelTemplate(context->uri, tpltId); +//} + +SeqStrategy &TemplateStrategy::GetStrategy() +{ + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; + } + std::initializer_list list = { + new (std::nothrow) LoadConfigCommonStrategy(), + new (std::nothrow) LoadConfigFromDataProxyNodeStrategy() + }; + auto ret = strategies_.Init(list); + if (!ret) { + std::for_each(list.begin(), list.end(), [](Strategy *item) { + delete item; + }); + return strategies_; + } + return strategies_; +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/template_strategy.h b/services/distributeddataservice/service/data_share/strategies/template_strategy.h new file mode 100644 index 00000000..7dc4e6de --- /dev/null +++ b/services/distributeddataservice/service/data_share/strategies/template_strategy.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef LDBPROJ_TEMPLATE_STRATEGY_H +#define LDBPROJ_TEMPLATE_STRATEGY_H + +#include + +#include "data_proxy_observer.h" +#include "seq_strategy.h" + +namespace OHOS::DataShare { +class TemplateStrategy final { +public: + int32_t Execute(std::shared_ptr context, std::function process); +// int32_t ExecuteAddTemplate(std::shared_ptr context, const TemplateId &tpltId, const Template &tplt); +// +// int32_t ExecuteDelTemplate(std::shared_ptr context, const TemplateId &tpltId); + +private: + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; +}; +} // namespace OHOS::DataShare +#endif //LDBPROJ_TEMPLATE_STRATEGY_H -- Gitee From c9e7a3bfeb013934fe824b07670d19fb412f5299 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 9 Jun 2023 15:31:13 +0800 Subject: [PATCH 195/437] dfx Signed-off-by: niudongyao --- .../data_share/data_share_service_impl.cpp | 3 -- .../strategies/template_strategy.cpp | 33 +------------------ .../data_share/strategies/template_strategy.h | 3 -- 3 files changed, 1 insertion(+), 38 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 2ae40028..db5bc59d 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -120,12 +120,10 @@ int32_t DataShareServiceImpl::AddTemplate(const std::string &uri, const int64_t return templateStrategy_.Execute(context, [&uri, &tpltId, &tplt]() -> int32_t { return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); }); - // return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); } int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t subscriberId) { - ZLOGI("ndy DelTemplate enter."); auto context = std::make_shared(uri); TemplateId tpltId; tpltId.subscriberId_ = subscriberId; @@ -137,7 +135,6 @@ int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t return templateStrategy_.Execute(context, [&uri, &tpltId]() -> int32_t { return TemplateManager::GetInstance().DelTemplate(uri, tpltId); }); - // return TemplateManager::GetInstance().DelTemplate(uri, tpltId); } bool DataShareServiceImpl::GetCallerBundleName(std::string &bundleName) diff --git a/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp index 93f7254f..fd33112a 100644 --- a/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "AddTemplateStrategy" +#define LOG_TAG "TemplateStrategy" #include "template_strategy.h" @@ -20,7 +20,6 @@ #include "datashare_errno.h" #include "general/load_config_common_strategy.h" #include "log_print.h" -#include "template_manager.h" #include "utils/anonymous.h" namespace OHOS::DataShare { @@ -39,36 +38,6 @@ int32_t TemplateStrategy::Execute(std::shared_ptr context, std::functio return process(); } -//int32_t TemplateStrategy::ExecuteAddTemplate(std::shared_ptr context, const TemplateId &tpltId, const Template &tplt) -//{ -// auto &preProcess = GetStrategy(); -// if (preProcess.IsEmpty()) { -// ZLOGE("get strategy fail, maybe memory not enough"); -// return E_ERROR; -// } -// -// if (!preProcess(context)) { -// ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); -// return context->errCode; -// } -// return TemplateManager::GetInstance().AddTemplate(context->uri, tpltId, tplt); -//} -// -//int32_t TemplateStrategy::ExecuteDelTemplate(std::shared_ptr context, const TemplateId &tpltId) -//{ -// auto &preProcess = GetStrategy(); -// if (preProcess.IsEmpty()) { -// ZLOGE("get strategy fail, maybe memory not enough"); -// return E_ERROR; -// } -// -// if (!preProcess(context)) { -// ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); -// return context->errCode; -// } -// return TemplateManager::GetInstance().DelTemplate(context->uri, tpltId); -//} - SeqStrategy &TemplateStrategy::GetStrategy() { std::lock_guard lock(mutex_); diff --git a/services/distributeddataservice/service/data_share/strategies/template_strategy.h b/services/distributeddataservice/service/data_share/strategies/template_strategy.h index 7dc4e6de..ac18de03 100644 --- a/services/distributeddataservice/service/data_share/strategies/template_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/template_strategy.h @@ -25,9 +25,6 @@ namespace OHOS::DataShare { class TemplateStrategy final { public: int32_t Execute(std::shared_ptr context, std::function process); -// int32_t ExecuteAddTemplate(std::shared_ptr context, const TemplateId &tpltId, const Template &tplt); -// -// int32_t ExecuteDelTemplate(std::shared_ptr context, const TemplateId &tpltId); private: SeqStrategy &GetStrategy(); -- Gitee From 6e47af0aa1b85c653aafb1f5f81466a2bf367fd7 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 9 Jun 2023 15:34:03 +0800 Subject: [PATCH 196/437] dfx Signed-off-by: niudongyao --- .../service/data_share/data_share_service_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index a9bab1d9..493882da 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -86,7 +86,7 @@ private: InsertStrategy insertStrategy_; QueryStrategy queryStrategy_; UpdateStrategy updateStrategy_; - TemplateStrategy templateStrategy_; + TemplateStrategy templateStrategy_; BindInfo binderInfo_; }; } // namespace OHOS::DataShare -- Gitee From d0f638dbb9b6ba24e14045f21139286010b6bd76 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 9 Jun 2023 15:59:04 +0800 Subject: [PATCH 197/437] dfx Signed-off-by: niudongyao --- .../service/data_share/strategies/template_strategy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/strategies/template_strategy.h b/services/distributeddataservice/service/data_share/strategies/template_strategy.h index ac18de03..8443cd2d 100644 --- a/services/distributeddataservice/service/data_share/strategies/template_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/template_strategy.h @@ -32,4 +32,4 @@ private: SeqStrategy strategies_; }; } // namespace OHOS::DataShare -#endif //LDBPROJ_TEMPLATE_STRATEGY_H +#endif // LDBPROJ_TEMPLATE_STRATEGY_H -- Gitee From f483bffa473c068ec3e60f8ace6c6fbd71b681c3 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 9 Jun 2023 16:59:06 +0800 Subject: [PATCH 198/437] fix Signed-off-by: niudongyao --- .../service/data_share/data_share_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 959e07b0..4d39033c 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -163,7 +163,7 @@ int32_t DataShareServiceStub::OnRemoteGetData(MessageParcel &data, MessageParcel ZLOGW("read device list failed."); return -1; } - ZLOGE("hanlu bundleName %{public}s", bundleName.c_str()); + ZLOGE("bundleName is %{public}s", bundleName.c_str()); int errorCode = E_OK; auto results = GetData(bundleName, errorCode); if (!ITypesUtil::Marshal(reply, results.datas_, errorCode)) { -- Gitee From e8895218c1c73838a5e60e912121c1ee9fe93095 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 9 Jun 2023 16:59:32 +0800 Subject: [PATCH 199/437] fix Signed-off-by: niudongyao --- .../service/data_share/data_share_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 4d39033c..852b874b 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -163,7 +163,7 @@ int32_t DataShareServiceStub::OnRemoteGetData(MessageParcel &data, MessageParcel ZLOGW("read device list failed."); return -1; } - ZLOGE("bundleName is %{public}s", bundleName.c_str()); + ZLOGI("bundleName is %{public}s", bundleName.c_str()); int errorCode = E_OK; auto results = GetData(bundleName, errorCode); if (!ITypesUtil::Marshal(reply, results.datas_, errorCode)) { -- Gitee From 76f5eab07830b595a4fbb4820d4e682cb5a550c8 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Fri, 9 Jun 2023 21:32:06 +0800 Subject: [PATCH 200/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/sync_manager.cpp | 9 +++++---- .../distributeddataservice/service/cloud/sync_manager.h | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 883c818a..06efff0e 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -172,8 +172,8 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf return; } - if (!cloud.enableCloud || cloud.id != info.id_ || (!info.bundleName_.empty() && - !cloud.IsOn(info.bundleName_))) { + if (!cloud.enableCloud || (info.id_ != SyncInfo::DEFAULT_ID && cloud.id != info.id_) || + (!info.bundleName_.empty() && !cloud.IsOn(info.bundleName_))) { info.SetError(E_UNOPENED); return; } @@ -195,6 +195,7 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf storeInfo.bundleName = schema.bundleName; storeInfo.user = cloud.user; storeInfo.storeName = database.name; + storeInfo.instanceId = cloud.apps[schema.bundleName].instanceId; auto query = info.GenerateQuery(database.name, database.GetTableNames()); auto evt = std::make_unique(std::move(storeInfo), SyncEvent::EventInfo { info.mode_, info.wait_, std::move(query), info.async_ }); @@ -243,7 +244,7 @@ std::function SyncManager::GetSyncHandler() return; } auto dbMeta = schemaMeta.GetDataBase(storeInfo.storeName); - auto cloudDB = instance->ConnectCloudDB(storeInfo.tokenId, dbMeta); + auto cloudDB = instance->ConnectCloudDB(meta.tokenId, dbMeta); if (cloudDB == nullptr) { ZLOGE("failed, no cloud DB <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, dbMeta.name.c_str(), dbMeta.alias.c_str()); @@ -253,7 +254,7 @@ std::function SyncManager::GetSyncHandler() } ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), Anonymous::Change(storeInfo.storeName).c_str()); - store->Sync( { "default" }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); + store->Sync( { SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); }; } diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index dddedc3a..82b541c9 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -43,13 +43,14 @@ public: void SetQuery(std::shared_ptr query); void SetError(int32_t code); std::shared_ptr GenerateQuery(const std::string &store, const Tables &tables); + static constexpr const char *DEFAULT_ID = "default"; private: friend SyncManager; int32_t mode_ = GenStore::CLOUD_TIME_FIRST; int32_t user_ = 0; int32_t wait_ = 0; - std::string id_ = "default"; + std::string id_ = DEFAULT_ID; std::string bundleName_; std::map> tables_; GenAsync async_; -- Gitee From fb809b90404fbc0d50c09da9dc287b182d67f148 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 10 Jun 2023 16:46:42 +0800 Subject: [PATCH 201/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 2 +- .../service/data_share/common/context.h | 2 +- .../service/data_share/common/db_delegate.cpp | 13 +- .../service/data_share/common/db_delegate.h | 4 +- .../data_share/common/rdb_delegate.cpp | 5 +- .../data_share/common/scheduler_manager.cpp | 47 +++++--- .../data_share/common/scheduler_manager.h | 11 +- .../data_share/common/seq_strategy.cpp | 5 +- .../data_share/common/template_manager.cpp | 101 ++++++++-------- .../data_share/common/template_manager.h | 40 +++---- .../service/data_share/common/uri_utils.cpp | 2 +- .../data_share/data/published_data.cpp | 35 +++--- .../service/data_share/data/published_data.h | 10 +- .../service/data_share/data/template_data.cpp | 26 ++-- .../service/data_share/data/template_data.h | 16 ++- .../data_share/data_share_service_impl.cpp | 113 +++++++++--------- ...d_config_from_data_proxy_node_strategy.cpp | 2 +- ...tegy.cpp => cross_permission_strategy.cpp} | 14 +-- ...strategy.h => cross_permission_strategy.h} | 6 +- .../general/permission_strategy.cpp | 2 +- .../strategies/get_data_strategy.cpp | 2 +- .../strategies/publish_strategy.cpp | 11 +- 22 files changed, 248 insertions(+), 221 deletions(-) rename services/distributeddataservice/service/data_share/strategies/general/{white_permission_strategy.cpp => cross_permission_strategy.cpp} (69%) rename services/distributeddataservice/service/data_share/strategies/general/{white_permission_strategy.h => cross_permission_strategy.h} (81%) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index a917fb54..ef8085a0 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -58,13 +58,13 @@ ohos_shared_library("data_share_service") { "strategies/delete_strategy.cpp", "strategies/general/check_is_data_proxy_strategy.cpp", "strategies/general/check_is_single_app_strategy.cpp", + "strategies/general/cross_permission_strategy.cpp", "strategies/general/empty_strategy.cpp", "strategies/general/load_config_common_strategy.cpp", "strategies/general/load_config_data_info_strategy.cpp", "strategies/general/load_config_from_bundle_info_strategy.cpp", "strategies/general/permission_strategy.cpp", "strategies/general/process_single_app_user_cross_strategy.cpp", - "strategies/general/white_permission_strategy.cpp", "strategies/get_data_strategy.cpp", "strategies/insert_strategy.cpp", "strategies/publish_strategy.cpp", diff --git a/services/distributeddataservice/service/data_share/common/context.h b/services/distributeddataservice/service/data_share/common/context.h index 5f5cc343..59b2e9a1 100644 --- a/services/distributeddataservice/service/data_share/common/context.h +++ b/services/distributeddataservice/service/data_share/common/context.h @@ -48,7 +48,7 @@ public: int version = -1; int errCode = -1; bool isRead = false; - bool isInWhite = false; // can cross permission check, for special SA + bool isAllowCrossPer = false; // can cross permission check, for special SA bool needAutoLoadCallerBundleName = false; AccessSystemMode accessSystemMode = AccessSystemMode::UNDEFINED; OHOS::AppExecFwk::BundleInfo bundleInfo; diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index b05ca94c..a58e5714 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -16,6 +16,7 @@ #include "db_delegate.h" #include "kv_delegate.h" +#include "log_print.h" #include "rdb_delegate.h" namespace OHOS::DataShare { std::shared_ptr DBDelegate::Create(const std::string &dir, int version, bool registerFunction) @@ -37,15 +38,21 @@ std::shared_ptr KvDBDelegate::GetInstance( bool Id::Marshal(DistributedData::Serializable::json &node) const { - return SetValue(node[GET_NAME(_id)], _id); + auto ret = false; + if (_userId == INVALID_USER) { + ret = SetValue(node[GET_NAME(_id)], _id); + } else { + ret = SetValue(node[GET_NAME(_id)], _id + "_" + std::to_string(_userId)); + } + return ret; } bool Id::Unmarshal(const DistributedData::Serializable::json &node) { - return GetValue(node, GET_NAME(_id), _id); + return false; } -Id::Id(const std::string &id) : _id(id) {} +Id::Id(const std::string &id, const int32_t userId) : _id(id), _userId(userId) {} VersionData::VersionData(int version) : version(version) {} diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index b649c1a3..b33b3db5 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -44,7 +44,8 @@ public: class Id : public DistributedData::Serializable { public: - explicit Id(const std::string &id); + static constexpr int INVALID_USER = -1; + Id(const std::string &id, const int32_t userId); ~Id() = default; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; @@ -55,6 +56,7 @@ public: private: std::string _id; + int32_t _userId; }; class VersionData : public DistributedData::Serializable { diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 8dcd025d..6eb5b736 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -30,6 +30,7 @@ enum REMIND_TIMER_ARGS : int32_t { ARG_URI, ARG_SUBSCRIBER_ID, ARG_BUNDLE_NAME, + ARG_USER_ID, ARG_TIME, ARGS_SIZE }; @@ -44,8 +45,8 @@ std::string RemindTimerFunc(const std::vector &args) int version = std::strtol(args[ARG_VERSION].c_str(), nullptr, 0); Key key(args[ARG_URI], std::strtoll(args[ARG_SUBSCRIBER_ID].c_str(), nullptr, 0), args[ARG_BUNDLE_NAME]); int64_t reminderTime = std::strtoll(args[ARG_TIME].c_str(), nullptr, 0); - - SchedulerManager::GetInstance().SetTimer(dbPath, version, key, reminderTime); + int32_t userId = std::strtol(args[ARG_USER_ID].c_str(), nullptr, 0); + SchedulerManager::GetInstance().SetTimer(dbPath, userId, version, key, reminderTime); return args[ARG_TIME]; } diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index cb5c2635..c0c96fc1 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -27,7 +27,7 @@ SchedulerManager &SchedulerManager::GetInstance() return instance; } -void SchedulerManager::Execute(const std::string &uri, const std::string &rdbDir, int version) +void SchedulerManager::Execute(const std::string &uri, const int32_t userId, const std::string &rdbDir, int version) { if (!URIUtils::IsDataProxyURI(uri)) { return; @@ -39,24 +39,25 @@ void SchedulerManager::Execute(const std::string &uri, const std::string &rdbDir } std::vector keys = RdbSubscriberManager::GetInstance().GetKeysByUri(uri); for (auto const &key : keys) { - if (RdbSubscriberManager::GetInstance().GetObserverCount(key) == 0) { + if (RdbSubscriberManager::GetInstance().GetCount(key) == 0) { continue; } - ExecuteSchedulerSQL(rdbDir, version, key, delegate); + ExecuteSchedulerSQL(rdbDir, userId, version, key, delegate); } } -void SchedulerManager::Execute(const Key &key, const std::string &rdbDir, int version) +void SchedulerManager::Execute(const Key &key, const int32_t userId, const std::string &rdbDir, int version) { auto delegate = DBDelegate::Create(rdbDir, version, true); if (delegate == nullptr) { ZLOGE("malloc fail %{public}s", DistributedData::Anonymous::Change(key.uri).c_str()); return; } - ExecuteSchedulerSQL(rdbDir, version, key, delegate); + ExecuteSchedulerSQL(rdbDir, userId, version, key, delegate); } -void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Key &key, int64_t reminderTime) +void SchedulerManager::SetTimer( + const std::string &dbPath, const int32_t userId, int version, const Key &key, int64_t reminderTime) { std::lock_guard lock(mutex_); if (executor_ == nullptr) { @@ -73,12 +74,12 @@ void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Ke } // not find task in map, create new timer auto taskId = executor_->Schedule(std::chrono::seconds(reminderTime - time(nullptr)), - [key, dbPath, version, this]() { + [key, dbPath, version, userId, this]() { timerCache_.erase(key); // 1. execute schedulerSQL in next time - Execute(key, dbPath, version); + Execute(key, userId, dbPath, version); // 2. notify - RdbSubscriberManager::GetInstance().EmitByKey(key, dbPath, version); + RdbSubscriberManager::GetInstance().EmitByKey(key, userId, dbPath, version); }); if (taskId == ExecutorPool::INVALID_TASK_ID) { ZLOGE("create timer failed, over the max capacity"); @@ -89,11 +90,11 @@ void SchedulerManager::SetTimer(const std::string &dbPath, int version, const Ke timerCache_.emplace(key, taskId); } -void SchedulerManager::ExecuteSchedulerSQL(const std::string &rdbDir, int version, const Key &key, +void SchedulerManager::ExecuteSchedulerSQL(const std::string &rdbDir, const int32_t userId, int version, const Key &key, std::shared_ptr delegate) { Template tpl; - if (!TemplateManager::GetInstance().GetTemplate(key.uri, key.subscriberId, key.bundleName, tpl)) { + if (!TemplateManager::GetInstance().Get(key, userId, tpl)) { ZLOGE("template undefined, %{public}s, %{public}" PRId64 ", %{public}s", DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); return; @@ -103,7 +104,7 @@ void SchedulerManager::ExecuteSchedulerSQL(const std::string &rdbDir, int versio DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); return; } - GenRemindTimerFuncParams(rdbDir, version, key, tpl.scheduler_); + GenRemindTimerFuncParams(rdbDir, userId, version, key, tpl.scheduler_); auto resultSet = delegate->QuerySql(tpl.scheduler_); if (resultSet == nullptr) { ZLOGE("resultSet is nullptr, %{public}s, %{public}" PRId64 ", %{public}s", @@ -126,8 +127,8 @@ void SchedulerManager::ExecuteSchedulerSQL(const std::string &rdbDir, int versio } } -void SchedulerManager::GenRemindTimerFuncParams(const std::string &rdbDir, int version, const Key &key, - std::string &schedulerSQL) +void SchedulerManager::GenRemindTimerFuncParams( + const std::string &rdbDir, const int32_t userId, int version, const Key &key, std::string &schedulerSQL) { auto index = schedulerSQL.find(REMIND_TIMER_FUNC); if (index == std::string::npos) { @@ -136,7 +137,8 @@ void SchedulerManager::GenRemindTimerFuncParams(const std::string &rdbDir, int v } index += REMIND_TIMER_FUNC_LEN; std::string keyStr = "'" + rdbDir + "', " + std::to_string(version) + ", '" + key.uri + "', " + - std::to_string(key.subscriberId) + ", '" + key.bundleName + "', "; + std::to_string(key.subscriberId) + ", '" + key.bundleName + "', " + std::to_string(userId) + + ", "; schedulerSQL.insert(index, keyStr); return; } @@ -157,6 +159,21 @@ void SchedulerManager::RemoveTimer(const Key &key) } } +void SchedulerManager::ClearTimer() +{ + ZLOGI("Clear all timer"); + std::lock_guard lock(mutex_); + if (executor_ == nullptr) { + ZLOGE("executor_ is nullptr"); + return; + } + auto it = timerCache_.begin(); + while (it != timerCache_.end()) { + executor_->Remove(it->second); + it = timerCache_.erase(it); + } +} + void SchedulerManager::SetExecutorPool(std::shared_ptr executor) { executor_ = executor; diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.h b/services/distributeddataservice/service/data_share/common/scheduler_manager.h index 05a75fa3..b4ea4580 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.h +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.h @@ -26,10 +26,11 @@ namespace OHOS::DataShare { class SchedulerManager { public: static SchedulerManager &GetInstance(); - void Execute(const std::string &uri, const std::string &rdbDir, int version); - void Execute(const Key &key, const std::string &rdbDir, int version); - void SetTimer(const std::string &dbPath, int version, const Key &key, int64_t reminderTime); + void Execute(const std::string &uri, const int32_t userId, const std::string &rdbDir, int version); + void Execute(const Key &key, const int32_t userId, const std::string &rdbDir, int version); + void SetTimer(const std::string &dbPath, const int32_t userId, int version, const Key &key, int64_t reminderTime); void RemoveTimer(const Key &key); + void ClearTimer(); void SetExecutorPool(std::shared_ptr executor); private: @@ -37,9 +38,9 @@ private: static constexpr int REMIND_TIMER_FUNC_LEN = 12; SchedulerManager() = default; ~SchedulerManager() = default; - static void GenRemindTimerFuncParams(const std::string &rdbDir, int version, const Key &key, + static void GenRemindTimerFuncParams(const std::string &rdbDir, const int32_t userId, int version, const Key &key, std::string &schedulerSQL); - void ExecuteSchedulerSQL(const std::string &rdbDir, int version, const Key &key, + void ExecuteSchedulerSQL(const std::string &rdbDir, const int32_t userId, int version, const Key &key, std::shared_ptr delegate); std::mutex mutex_; diff --git a/services/distributeddataservice/service/data_share/common/seq_strategy.cpp b/services/distributeddataservice/service/data_share/common/seq_strategy.cpp index 62700398..08bb71eb 100644 --- a/services/distributeddataservice/service/data_share/common/seq_strategy.cpp +++ b/services/distributeddataservice/service/data_share/common/seq_strategy.cpp @@ -28,11 +28,12 @@ bool SeqStrategy::operator()(std::shared_ptr context) } bool SeqStrategy::Init(std::initializer_list strategies) { - for (auto &item: strategies) { + for (const auto &item: strategies) { if (item == nullptr) { - actions_.clear(); return false; } + } + for (const auto &item: strategies) { actions_.emplace_back(item); } return true; diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index ebf7cd33..03656dcd 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -26,15 +26,15 @@ #include "utils/anonymous.h" namespace OHOS::DataShare { -bool TemplateManager::GetTemplate( - const std::string &uri, const int64_t subscriberId, const std::string &bundleName, Template &tpl) +bool TemplateManager::Get(const Key &key, const int32_t userId, Template &tpl) { - return TemplateData::Query(Id(TemplateData::GenId(uri, bundleName, subscriberId)), tpl) == E_OK; + return TemplateData::Query(Id(TemplateData::GenId(key.uri, key.bundleName, key.subscriberId), userId), + tpl) == E_OK; } -int32_t TemplateManager::AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl) +int32_t TemplateManager::Add(const Key &key, const int32_t userId, const Template &tpl) { - auto status = TemplateData::Add(uri, tplId.bundleName_, tplId.subscriberId_, tpl); + auto status = TemplateData::Add(key.uri, userId, key.bundleName, key.subscriberId, tpl); if (!status) { ZLOGE("Add failed, %{public}d", status); return E_ERROR; @@ -42,14 +42,14 @@ int32_t TemplateManager::AddTemplate(const std::string &uri, const TemplateId &t return E_OK; } -int32_t TemplateManager::DelTemplate(const std::string &uri, const TemplateId &tplId) +int32_t TemplateManager::Delete(const Key &key, const int32_t userId) { - auto status = TemplateData::Delete(uri, tplId.bundleName_, tplId.subscriberId_); + auto status = TemplateData::Delete(key.uri, userId, key.bundleName, key.subscriberId); if (!status) { ZLOGE("Delete failed, %{public}d", status); return E_ERROR; } - SchedulerManager::GetInstance().RemoveTimer(Key(uri, tplId.subscriberId_, tplId.bundleName_)); + SchedulerManager::GetInstance().RemoveTimer(key); return E_OK; } @@ -143,39 +143,34 @@ void RdbSubscriberManager::OnRemoteDied(const Key &key, sptr observer, std::shared_ptr context, - std::shared_ptr executorPool) +int RdbSubscriberManager::Add(const Key &key, const sptr observer, + std::shared_ptr context, std::shared_ptr executorPool) { int result = E_OK; - Key key(uri, tplId.subscriberId_, tplId.bundleName_); - rdbCache_.Compute(key, - [&observer, &context, executorPool, this](const auto &key, std::vector &value) { + rdbCache_.Compute(key, [&observer, &context, executorPool, this](const auto &key, std::vector &value) { ZLOGI("add subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), context->callerTokenId); std::vector node; node.emplace_back(observer, context->callerTokenId); ExecutorPool::Task task = [key, node, context, this]() { LoadConfigDataInfoStrategy loadDataInfo; if (loadDataInfo(context)) { - Notify(key, node, context->calledSourceDir, context->version); + Notify(key, context->currentUserId, node, context->calledSourceDir, context->version); } }; executorPool->Execute(task); value.emplace_back(observer, context->callerTokenId); LinkToDeath(key, observer); if (GetEnableObserverCount(key) == 1) { - SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); + SchedulerManager::GetInstance().Execute( + key, context->currentUserId, context->calledSourceDir, context->version); } return true; }); return result; } -int RdbSubscriberManager::DelRdbSubscriber( - const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId) +int RdbSubscriberManager::Delete(const Key &key, const uint32_t callerTokenId) { - Key key(uri, tplId.subscriberId_, tplId.bundleName_); auto result = rdbCache_.ComputeIfPresent(key, [&callerTokenId, this](const auto &key, std::vector &value) { ZLOGI("delete subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), callerTokenId); @@ -195,10 +190,8 @@ int RdbSubscriberManager::DelRdbSubscriber( return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -int RdbSubscriberManager::DisableRdbSubscriber( - const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId) +int RdbSubscriberManager::Disable(const Key &key, const uint32_t callerTokenId) { - Key key(uri, tplId.subscriberId_, tplId.bundleName_); auto result = rdbCache_.ComputeIfPresent(key, [&callerTokenId, this](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { @@ -214,10 +207,8 @@ int RdbSubscriberManager::DisableRdbSubscriber( return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -int RdbSubscriberManager::EnableRdbSubscriber( - const std::string &uri, const TemplateId &tplId, std::shared_ptr context) +int RdbSubscriberManager::Enable(const Key &key, std::shared_ptr context) { - Key key(uri, tplId.subscriberId_, tplId.bundleName_); auto result = rdbCache_.ComputeIfPresent(key, [&context, this](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { if (it->callerTokenId == context->callerTokenId) { @@ -226,11 +217,12 @@ int RdbSubscriberManager::EnableRdbSubscriber( node.emplace_back(it->observer, context->callerTokenId); LoadConfigDataInfoStrategy loadDataInfo; if (loadDataInfo(context)) { - Notify(key, node, context->calledSourceDir, context->version); + Notify(key, context->currentUserId, node, context->calledSourceDir, context->version); } } if (GetEnableObserverCount(key) == 1) { - SchedulerManager::GetInstance().Execute(key, context->calledSourceDir, context->version); + SchedulerManager::GetInstance().Execute( + key, context->currentUserId, context->calledSourceDir, context->version); } } return true; @@ -247,7 +239,7 @@ void RdbSubscriberManager::Emit(const std::string &uri, std::shared_ptr if (key.uri != uri) { return false; } - Notify(key, val, context->calledSourceDir, context->version); + Notify(key, context->currentUserId, val, context->calledSourceDir, context->version); return false; }); } @@ -265,18 +257,18 @@ std::vector RdbSubscriberManager::GetKeysByUri(const std::string &uri) return results; } -void RdbSubscriberManager::EmitByKey(const Key &key, const std::string &rdbPath, int version) +void RdbSubscriberManager::EmitByKey(const Key &key, const int32_t userId, const std::string &rdbPath, int version) { if (!URIUtils::IsDataProxyURI(key.uri)) { return; } - rdbCache_.ComputeIfPresent(key, [&rdbPath, &version, this](const Key &key, std::vector &val) { - Notify(key, val, rdbPath, version); + rdbCache_.ComputeIfPresent(key, [&rdbPath, &version, &userId, this](const Key &key, std::vector &val) { + Notify(key, userId, val, rdbPath, version); return true; }); } -int RdbSubscriberManager::GetObserverCount(const Key &key) +int RdbSubscriberManager::GetCount(const Key &key) { auto pair = rdbCache_.Find(key); if (!pair.first) { @@ -300,11 +292,11 @@ int RdbSubscriberManager::GetEnableObserverCount(const Key &key) return count; } -int RdbSubscriberManager::Notify( - const Key &key, const std::vector &val, const std::string &rdbDir, int rdbVersion) +int RdbSubscriberManager::Notify(const Key &key, const int32_t userId, const std::vector &val, + const std::string &rdbDir, int rdbVersion) { Template tpl; - if (!TemplateManager::GetInstance().GetTemplate(key.uri, key.subscriberId, key.bundleName, tpl)) { + if (!TemplateManager::GetInstance().Get(key, userId, tpl)) { ZLOGE("template undefined, %{public}s, %{public}" PRId64 ", %{public}s", DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); return E_TEMPLATE_NOT_EXIST; @@ -333,6 +325,11 @@ int RdbSubscriberManager::Notify( return E_OK; } +void RdbSubscriberManager::Clear() +{ + rdbCache_.Clear(); +} + PublishedDataSubscriberManager &PublishedDataSubscriberManager::GetInstance() { static PublishedDataSubscriberManager manager; @@ -371,13 +368,11 @@ void PublishedDataSubscriberManager::OnRemoteDied(const PublishedDataKey &key, return !value.empty(); }); } - -int PublishedDataSubscriberManager::AddSubscriber(const std::string &key, const std::string &callerBundleName, - const int64_t subscriberId, const sptr observer, const uint32_t callerTokenId) +int PublishedDataSubscriberManager::Add( + const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId) { - PublishedDataKey publishedDataKey(key, callerBundleName, subscriberId); - publishedDataCache.Compute(publishedDataKey, - [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { + publishedDataCache.Compute(key, + [&observer, &callerTokenId](const PublishedDataKey &key, std::vector &value) { ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); LinkToDeath(key, observer); value.emplace_back(observer, callerTokenId); @@ -386,10 +381,8 @@ int PublishedDataSubscriberManager::AddSubscriber(const std::string &key, const return E_OK; } -int PublishedDataSubscriberManager::DelSubscriber(const std::string &uri, const std::string &callerBundleName, - const int64_t subscriberId, const uint32_t callerTokenId) +int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, const uint32_t callerTokenId) { - PublishedDataKey key(uri, callerBundleName, subscriberId); auto result = publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { @@ -404,10 +397,8 @@ int PublishedDataSubscriberManager::DelSubscriber(const std::string &uri, const return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -int PublishedDataSubscriberManager::DisableSubscriber(const std::string &uri, const std::string &callerBundleName, - const int64_t subscriberId, const uint32_t callerTokenId) +int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, const uint32_t callerTokenId) { - PublishedDataKey key(uri, callerBundleName, subscriberId); auto result = publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { @@ -420,10 +411,8 @@ int PublishedDataSubscriberManager::DisableSubscriber(const std::string &uri, co return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -int PublishedDataSubscriberManager::EnableSubscriber(const std::string &uri, const std::string &callerBundleName, - const int64_t subscriberId, const uint32_t callerTokenId) +int PublishedDataSubscriberManager::Enable(const PublishedDataKey &key, const uint32_t callerTokenId) { - PublishedDataKey key(uri, callerBundleName, subscriberId); auto result = publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { @@ -436,21 +425,21 @@ int PublishedDataSubscriberManager::EnableSubscriber(const std::string &uri, con return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -void PublishedDataSubscriberManager::Emit(const std::vector &keys, +void PublishedDataSubscriberManager::Emit(const std::vector &keys, const int32_t userId, const std::string &ownerBundleName, const sptr observer) { int32_t status; // key is bundleName, value is change node std::map, std::string>> publishedResult; std::map, std::vector> callbacks; - publishedDataCache.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, this]( + publishedDataCache.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, &userId, this]( const PublishedDataKey &key, std::vector &val) { for (auto &data : keys) { if (key != data || publishedResult.count(key) != 0) { continue; } status = PublishedData::Query( - Id(PublishedData::GenId(key.key, key.bundleName, key.subscriberId)), publishedResult[key]); + Id(PublishedData::GenId(key.key, key.bundleName, key.subscriberId), userId), publishedResult[key]); if (status != E_OK) { ZLOGE("query fail %{public}s %{public}s %{public}" PRId64, data.bundleName.c_str(), data.key.c_str(), data.subscriberId); @@ -493,6 +482,10 @@ void PublishedDataSubscriberManager::PutInto( } } } +void PublishedDataSubscriberManager::Clear() +{ + publishedDataCache.Clear(); +} PublishedDataKey::PublishedDataKey(const std::string &key, const std::string &bundle, const int64_t subscriberId) : key(key), bundleName(bundle), subscriberId(subscriberId) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index a91e6886..7c09f034 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -40,9 +40,9 @@ struct Key { class TemplateManager { public: static TemplateManager &GetInstance(); - int32_t AddTemplate(const std::string &uri, const TemplateId &tplId, const Template &tpl); - int32_t DelTemplate(const std::string &uri, const TemplateId &tplId); - bool GetTemplate(const std::string &uri, int64_t subscriberId, const std::string &bundleName, Template &tpl); + int32_t Add(const Key &key, const int32_t userId, const Template &tpl); + int32_t Delete(const Key &key, const int32_t userId); + bool Get(const Key &key, const int32_t userId, Template &tpl); private: TemplateManager(); @@ -52,17 +52,16 @@ private: class RdbSubscriberManager { public: static RdbSubscriberManager &GetInstance(); - int AddRdbSubscriber(const std::string &uri, const TemplateId &tplId, const sptr observer, - std::shared_ptr context, std::shared_ptr executorPool); - int DelRdbSubscriber(const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId); - int DisableRdbSubscriber( - const std::string &uri, const TemplateId &tplId, const uint32_t callerTokenId); - int EnableRdbSubscriber(const std::string &uri, const TemplateId &tplId, std::shared_ptr context); + int Add(const Key &key, const sptr observer, std::shared_ptr context, + std::shared_ptr executorPool); + int Delete(const Key &key, const uint32_t callerTokenId); + int Disable(const Key &key, const uint32_t callerTokenId); + int Enable(const Key &key, std::shared_ptr context); void Emit(const std::string &uri, std::shared_ptr context); - void EmitByKey(const Key &key, const std::string &rdbPath, int version); - int GetObserverCount(const Key &key); + void EmitByKey(const Key &key, const int32_t userId, const std::string &rdbPath, int version); + int GetCount(const Key &key); std::vector GetKeysByUri(const std::string &uri); - + void Clear(); private: struct ObserverNode { ObserverNode(const sptr &observer, uint32_t callerTokenId); @@ -93,7 +92,8 @@ private: void OnRemoteDied(const Key &key, sptr observer); RdbSubscriberManager() = default; ConcurrentMap> rdbCache_; - int Notify(const Key &key, const std::vector &val, const std::string &rdbDir, int rdbVersion); + int Notify(const Key &key, const int32_t userId, const std::vector &val, const std::string &rdbDir, + int rdbVersion); int GetEnableObserverCount(const Key &key); }; @@ -113,16 +113,14 @@ struct PublishedDataKey { class PublishedDataSubscriberManager { public: static PublishedDataSubscriberManager &GetInstance(); - int AddSubscriber(const std::string &key, const std::string &callerBundleName, const int64_t subscriberId, - const sptr observer, const uint32_t callerTokenId); - int DelSubscriber(const std::string &uri, const std::string &callerBundleName, const int64_t subscriberId, - const uint32_t callerTokenId); - int DisableSubscriber(const std::string &uri, const std::string &callerBundleName, const int64_t subscriberId, - const uint32_t callerTokenId); - int EnableSubscriber(const std::string &uri, const std::string &callerBundleName, const int64_t subscriberId, + int Add(const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId); - void Emit(const std::vector &keys, const std::string &ownerBundleName, + int Delete(const PublishedDataKey &key, const uint32_t callerTokenId); + int Disable(const PublishedDataKey &key, const uint32_t callerTokenId); + int Enable(const PublishedDataKey &key, const uint32_t callerTokenId); + void Emit(const std::vector &keys, const int32_t userId, const std::string &ownerBundleName, const sptr observer = nullptr); + void Clear(); private: struct ObserverNode { ObserverNode(const sptr &observer, uint32_t callerTokenId); diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.cpp b/services/distributeddataservice/service/data_share/common/uri_utils.cpp index 322a6fb8..84b3ec7a 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.cpp +++ b/services/distributeddataservice/service/data_share/common/uri_utils.cpp @@ -66,7 +66,7 @@ bool URIUtils::GetBundleNameFromProxyURI(const std::string &uri, std::string &bu bool URIUtils::GetInfoFromProxyURI( const std::string &uri, int32_t &user, uint32_t &callerTokenId, std::string &calledBundleName) { - auto queryPos = uri.find_first_of('?'); + auto queryPos = uri.find_last_of('?'); if (queryPos == std::string::npos) { return true; } diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 881dec41..5fee43f8 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -33,20 +33,18 @@ std::string PublishedData::GetValue() const return DistributedData::Serializable::Marshall(value); } -PublishedData::PublishedData(const std::string &key, const std::string &bundleName, int64_t subscriberId, - const std::variant, std::string> &inputValue, const int version) - : KvData(Id(GenId(key, bundleName, subscriberId))), - value(key, bundleName, subscriberId, inputValue) +PublishedData::PublishedData(const PublishedDataNode &node, const int version) + : PublishedData(node) { value.SetVersion(version); } PublishedData::PublishedData(const PublishedDataNode &node) - : KvData(Id(GenId(node.key, node.bundleName, node.subscriberId))), value(node) + : KvData(Id(GenId(node.key, node.bundleName, node.subscriberId), node.userId)), value(node) { } -std::vector PublishedData::Query(const std::string &bundleName) +std::vector PublishedData::Query(const std::string &bundleName, int32_t userId) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { @@ -54,8 +52,8 @@ std::vector PublishedData::Query(const std::string &bundleName) return std::vector(); } std::vector queryResults; - int32_t status = - delegate->GetBatch(KvDBDelegate::DATA_TABLE, "{\"bundleName\":\"" + bundleName + "\"}", "{}", queryResults); + int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, + "{\"bundleName\":\"" + bundleName + "\", \"userId\": " + std::to_string(userId) + "}", "{}", queryResults); if (status != E_OK) { ZLOGE("db GetBatch failed, %{public}s %{public}d", bundleName.c_str(), status); return std::vector(); @@ -64,7 +62,7 @@ std::vector PublishedData::Query(const std::string &bundleName) for (auto &result : queryResults) { PublishedDataNode data; if (PublishedDataNode::Unmarshall(result, data)) { - results.emplace_back(data); + results.emplace_back(data, userId); } } return results; @@ -77,6 +75,7 @@ bool PublishedDataNode::Marshal(DistributedData::Serializable::json &node) const ret = ret && SetValue(node[GET_NAME(subscriberId)], subscriberId); ret = ret && SetValue(node[GET_NAME(value)], value); ret = ret && SetValue(node[GET_NAME(timestamp)], timestamp); + ret = ret && SetValue(node[GET_NAME(userId)], userId); return ret && VersionData::Marshal(node); } @@ -91,8 +90,8 @@ bool PublishedDataNode::Unmarshal(const DistributedData::Serializable::json &nod } PublishedDataNode::PublishedDataNode(const std::string &key, const std::string &bundleName, - int64_t subscriberId, const std::variant, std::string> &value) - : VersionData(-1), key(key), bundleName(bundleName), subscriberId(subscriberId), value(std::move(value)) + int64_t subscriberId, const int32_t userId, const std::variant, std::string> &value) + : VersionData(-1), key(key), bundleName(bundleName), subscriberId(subscriberId), value(std::move(value)), userId(userId) { auto now = time(nullptr); if (now > 0) { @@ -129,15 +128,15 @@ std::string PublishedData::GenId(const std::string &key, const std::string &bund return key + "_" + std::to_string(subscriberId) + "_" + bundleName; } -void PublishedData::Delete(const std::string &bundleName) +void PublishedData::Delete(const std::string &bundleName, const int32_t userId) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { ZLOGE("db open failed"); return; } - int32_t status = - delegate->Delete(KvDBDelegate::DATA_TABLE, "{\"bundleName\":\"" + bundleName + "\"}"); + int32_t status = delegate->Delete(KvDBDelegate::DATA_TABLE, + "{\"bundleName\":\"" + bundleName + "\", \"userId\": " + std::to_string(userId) + "}"); if (status != E_OK) { ZLOGE("db Delete failed, %{public}s %{public}d", bundleName.c_str(), status); } @@ -172,15 +171,17 @@ void PublishedData::ClearAging() } if (data.timestamp < lastValidTime) { - status = delegate->Delete( - KvDBDelegate::DATA_TABLE, Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId))); + status = delegate->Delete(KvDBDelegate::DATA_TABLE, + Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId), Id::INVALID_USER)); if (status != E_OK) { ZLOGE("db Delete failed, %{public}s %{public}s", data.key.c_str(), data.bundleName.c_str()); } agingSize++; } } - ZLOGI("aging count %{public}d", agingSize); + if (agingSize > 0) { + ZLOGI("aging count %{public}d", agingSize); + } return; } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index d180670e..5f14a20f 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -24,7 +24,7 @@ class PublishedDataNode final : public VersionData { public: PublishedDataNode(); PublishedDataNode(const std::string &key, const std::string &bundleName, int64_t subscriberId, - const std::variant, std::string> &value); + const int32_t userId, const std::variant, std::string> &value); ~PublishedDataNode() = default; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; @@ -32,19 +32,19 @@ public: std::string bundleName; int64_t subscriberId; std::variant, std::string> value; + int32_t userId = Id::INVALID_USER; std::time_t timestamp = 0; }; class PublishedData final : public KvData { public: explicit PublishedData(const PublishedDataNode &node); - static std::vector Query(const std::string &bundleName); - static void Delete(const std::string &bundleName); + static std::vector Query(const std::string &bundleName, int32_t userId); + static void Delete(const std::string &bundleName, const int32_t userId); static void ClearAging(); static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); - PublishedData(const std::string &key, const std::string &bundleName, int64_t subscriberId, - const std::variant, std::string> &inputValue, const int version); + PublishedData(const PublishedDataNode &node, const int version); ~PublishedData() = default; bool HasVersion() const override; int GetVersion() const override; diff --git a/services/distributeddataservice/service/data_share/data/template_data.cpp b/services/distributeddataservice/service/data_share/data/template_data.cpp index 3805aca1..af382a22 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.cpp +++ b/services/distributeddataservice/service/data_share/data/template_data.cpp @@ -50,6 +50,7 @@ bool TemplateRootNode::Marshal(DistributedData::Serializable::json &node) const bool ret = SetValue(node[GET_NAME(uri)], uri); ret = ret && SetValue(node[GET_NAME(bundleName)], bundleName); ret = ret && SetValue(node[GET_NAME(subscriberId)], subscriberId); + ret = ret && SetValue(node[GET_NAME(userId)], userId); ret = ret && SetValue(node[GET_NAME(templat)], tpl); return ret; } @@ -59,13 +60,14 @@ bool TemplateRootNode::Unmarshal(const DistributedData::Serializable::json &node bool ret = GetValue(node, GET_NAME(uri), uri); ret = ret && GetValue(node, GET_NAME(bundleName), bundleName); ret = ret && GetValue(node, GET_NAME(subscriberId), subscriberId); + ret = ret && GetValue(node, GET_NAME(userId), userId); ret = ret && GetValue(node, GET_NAME(templat), tpl); return ret; } -TemplateRootNode::TemplateRootNode( - const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl) - : uri(uri), bundleName(bundleName), subscriberId(subscriberId), tpl(tpl) +TemplateRootNode::TemplateRootNode(const std::string &uri, const std::string &bundleName, const int64_t subscriberId, + const int32_t userId, const Template &tpl) + : uri(uri), bundleName(bundleName), subscriberId(subscriberId), userId(userId), tpl(tpl) { } @@ -80,8 +82,8 @@ std::string TemplateData::GetValue() const } TemplateData::TemplateData( - const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl) - :KvData(Id(GenId(uri, bundleName, subscriberId))), value(uri, bundleName, subscriberId, tpl) + const std::string &uri, const std::string &bundleName, int64_t subscriberId, int32_t userId, const Template &tpl) + :KvData(Id(GenId(uri, bundleName, subscriberId), userId)), value(uri, bundleName, subscriberId, userId, tpl) { } @@ -117,14 +119,15 @@ int32_t TemplateData::Query(const std::string &filter, Template &aTemplate) return E_OK; } -bool TemplateData::Delete(const std::string &bundleName) +bool TemplateData::Delete(const std::string &bundleName, const int32_t userId) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { ZLOGE("db open failed"); return false; } - auto status = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, "{\"bundleName\":\"" + bundleName + "\"}"); + auto status = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, + "{\"bundleName\":\"" + bundleName + "\", \"userId\": " + std::to_string(userId) + "}"); if (status != E_OK) { ZLOGE("db DeleteById failed, %{public}d", status); return false; @@ -133,14 +136,14 @@ bool TemplateData::Delete(const std::string &bundleName) } bool TemplateData::Add( - const std::string &uri, const std::string &bundleName, const int64_t subsciriberId, const Template &aTemplate) + const std::string &uri, const int32_t userId, const std::string &bundleName, const int64_t subsciriberId, const Template &aTemplate) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { ZLOGE("db open failed"); return false; } - TemplateData data(uri, bundleName, subsciriberId, aTemplate); + TemplateData data(uri, bundleName, subsciriberId, userId, aTemplate); auto status = delegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); if (status != E_OK) { ZLOGE("db Upsert failed, %{public}d", status); @@ -149,7 +152,8 @@ bool TemplateData::Add( return true; } -bool TemplateData::Delete(const std::string &uri, const std::string &bundleName, const int64_t subscriberId) +bool TemplateData::Delete( + const std::string &uri, const int32_t userId, const std::string &bundleName, const int64_t subscriberId) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { @@ -157,7 +161,7 @@ bool TemplateData::Delete(const std::string &uri, const std::string &bundleName, return false; } auto status = delegate->Delete(KvDBDelegate::TEMPLATE_TABLE, - static_cast(Id(TemplateData::GenId(uri, bundleName, subscriberId)))); + static_cast(Id(TemplateData::GenId(uri, bundleName, subscriberId), userId))); if (status != E_OK) { ZLOGE("db DeleteById failed, %{public}d", status); return false; diff --git a/services/distributeddataservice/service/data_share/data/template_data.h b/services/distributeddataservice/service/data_share/data/template_data.h index ba461524..f7f9e153 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.h +++ b/services/distributeddataservice/service/data_share/data/template_data.h @@ -42,7 +42,8 @@ private: struct TemplateRootNode final: public DistributedData::Serializable { TemplateRootNode() = default; - TemplateRootNode(const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl); + TemplateRootNode(const std::string &uri, const std::string &bundleName, const int64_t subscriberId, + const int32_t userId, const Template &tpl); bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; Template ToTemplate() const; @@ -50,17 +51,20 @@ private: std::string uri; std::string bundleName; int64_t subscriberId; + int32_t userId; TemplateNode tpl; }; struct TemplateData final : public KvData { - TemplateData(const std::string &uri, const std::string &bundleName, int64_t subscriberId, const Template &tpl); + TemplateData(const std::string &uri, const std::string &bundleName, int64_t subscriberId, int32_t userId, + const Template &tpl); static int32_t Query(const std::string &filter, Template &aTemplate); static std::string GenId(const std::string &uri, const std::string &bundleName, int64_t subscriberId); - static bool Delete(const std::string &bundleName); - static bool Add( - const std::string &uri, const std::string &bundleName, const int64_t subsciriberId, const Template &aTemplate); - static bool Delete(const std::string &uri, const std::string &bundleName, const int64_t subscriberId); + static bool Delete(const std::string &bundleName, const int32_t userId); + static bool Add(const std::string &uri, const int32_t userId, const std::string &bundleName, + const int64_t subsciriberId, const Template &aTemplate); + static bool Delete( + const std::string &uri, const int32_t userId, const std::string &bundleName, const int64_t subscriberId); bool HasVersion() const override; int GetVersion() const override; std::string GetValue() const override; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index db5bc59d..c47601f1 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -52,7 +52,8 @@ int32_t DataShareServiceImpl::Insert(const std::string &uri, const DataShareValu if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - SchedulerManager::GetInstance().Execute(uri, context->calledSourceDir, context->version); + SchedulerManager::GetInstance().Execute( + uri, context->currentUserId, context->calledSourceDir, context->version); } return ret; } @@ -82,7 +83,8 @@ int32_t DataShareServiceImpl::Update(const std::string &uri, const DataSharePred if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - SchedulerManager::GetInstance().Execute(uri, context->calledSourceDir, context->version); + SchedulerManager::GetInstance().Execute( + uri, context->currentUserId, context->calledSourceDir, context->version); } return ret; } @@ -95,7 +97,8 @@ int32_t DataShareServiceImpl::Delete(const std::string &uri, const DataSharePred if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - SchedulerManager::GetInstance().Execute(uri, context->calledSourceDir, context->version); + SchedulerManager::GetInstance().Execute( + uri, context->currentUserId, context->calledSourceDir, context->version); } return ret; } @@ -117,8 +120,9 @@ int32_t DataShareServiceImpl::AddTemplate(const std::string &uri, const int64_t ZLOGE("get bundleName error, %{public}s", DistributedData::Anonymous::Change(uri).c_str()); return ERROR; } - return templateStrategy_.Execute(context, [&uri, &tpltId, &tplt]() -> int32_t { - return TemplateManager::GetInstance().AddTemplate(uri, tpltId, tplt); + return templateStrategy_.Execute(context, [&uri, &tpltId, &tplt, &context]() -> int32_t { + return TemplateManager::GetInstance().Add( + Key(uri, tpltId.subscriberId_, tpltId.bundleName_), context->currentUserId, tplt); }); } @@ -132,8 +136,9 @@ int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t return ERROR; } - return templateStrategy_.Execute(context, [&uri, &tpltId]() -> int32_t { - return TemplateManager::GetInstance().DelTemplate(uri, tpltId); + return templateStrategy_.Execute(context, [&uri, &tpltId, &context]() -> int32_t { + return TemplateManager::GetInstance().Delete( + Key(uri, tpltId.subscriberId_, tpltId.bundleName_), context->currentUserId); }); } @@ -162,6 +167,7 @@ std::vector DataShareServiceImpl::Publish(const Data &data, con ZLOGE("get bundleName error, %{public}s", callerBundleName.c_str()); return results; } + int32_t userId = -1; PublishedData::ClearAging(); for (const auto &item : data.datas_) { auto context = std::make_shared(item.key_); @@ -175,8 +181,11 @@ std::vector DataShareServiceImpl::Publish(const Data &data, con continue; } publishedData.emplace_back(context->uri, callerBundleName, item.subscriberId_); + userId = context->currentUserId; + } + if (!publishedData.empty()) { + PublishedDataSubscriberManager::GetInstance().Emit(publishedData, userId, callerBundleName); } - PublishedDataSubscriberManager::GetInstance().Emit(publishedData, callerBundleName); return results; } @@ -199,11 +208,10 @@ std::vector DataShareServiceImpl::SubscribeRdbData( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back( - uri, subscribeStrategy_.Execute(context, [&id, &observer, &context, this]() -> bool { - return RdbSubscriberManager::GetInstance().AddRdbSubscriber( - context->uri, id, observer, context, binderInfo_.executors); - })); + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &observer, &context, this]() -> bool { + return RdbSubscriberManager::GetInstance().Add( + Key(context->uri, id.subscriberId_, id.bundleName_), observer, context, binderInfo_.executors); + })); } return results; } @@ -215,7 +223,8 @@ std::vector DataShareServiceImpl::UnsubscribeRdbData( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { - return RdbSubscriberManager::GetInstance().DelRdbSubscriber(context->uri, id, context->callerTokenId); + return RdbSubscriberManager::GetInstance().Delete( + Key(context->uri, id.subscriberId_, id.bundleName_), context->callerTokenId); })); } return results; @@ -228,7 +237,7 @@ std::vector DataShareServiceImpl::EnableRdbSubs( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { - return RdbSubscriberManager::GetInstance().EnableRdbSubscriber(context->uri, id, context); + return RdbSubscriberManager::GetInstance().Enable(Key(context->uri, id.subscriberId_, id.bundleName_), context); })); } return results; @@ -241,7 +250,7 @@ std::vector DataShareServiceImpl::DisableRdbSubs( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { - return RdbSubscriberManager::GetInstance().DisableRdbSubscriber(context->uri, id, context->callerTokenId); + return RdbSubscriberManager::GetInstance().Disable(Key(context->uri, id.subscriberId_, id.bundleName_), context->callerTokenId); })); } return results; @@ -258,22 +267,26 @@ std::vector DataShareServiceImpl::SubscribePublishedData(const } std::vector publishedKeys; int32_t result; + int32_t userId; for (const auto &uri : uris) { auto context = std::make_shared(uri); PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - result = subscribeStrategy_.Execute( - context, [&subscriberId, &observer, &context]() -> bool { - return PublishedDataSubscriberManager::GetInstance().AddSubscriber( - context->uri, context->callerBundleName, subscriberId, observer, context->callerTokenId); - }); + result = subscribeStrategy_.Execute(context, [&subscriberId, &observer, &context]() -> bool { + return PublishedDataSubscriberManager::GetInstance().Add( + PublishedDataKey(context->uri, context->callerBundleName, subscriberId), observer, + context->callerTokenId); + }); results.emplace_back(uri, result); if (result == E_OK) { publishedKeys.emplace_back(context->uri, context->callerBundleName, subscriberId); + userId = context->currentUserId; } } - PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, callerBundleName, observer); + if (!publishedKeys.empty()) { + PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, userId, callerBundleName, observer); + } return results; } @@ -291,11 +304,10 @@ std::vector DataShareServiceImpl::UnsubscribePublishedData(cons PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - results.emplace_back( - uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { - return PublishedDataSubscriberManager::GetInstance().DelSubscriber( - context->uri, context->callerBundleName, subscriberId, context->callerTokenId); - })); + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { + return PublishedDataSubscriberManager::GetInstance().Delete( + PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); + })); } return results; } @@ -311,21 +323,25 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect } std::vector publishedKeys; int32_t result; + int32_t userId = -1; for (const auto &uri : uris) { auto context = std::make_shared(uri); PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; result = subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { - return PublishedDataSubscriberManager::GetInstance().EnableSubscriber( - context->uri, context->callerBundleName, subscriberId, context->callerTokenId); + return PublishedDataSubscriberManager::GetInstance().Enable( + PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); }); results.emplace_back(uri, result); if (result == E_OK) { publishedKeys.emplace_back(key); + userId = context->currentUserId; } } - PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, callerBundleName); + if (!publishedKeys.empty()) { + PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, userId, callerBundleName); + } return results; } @@ -343,11 +359,10 @@ std::vector DataShareServiceImpl::DisablePubSubs(const std::vec PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - results.emplace_back( - uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { - return PublishedDataSubscriberManager::GetInstance().DisableSubscriber( - context->uri, context->callerBundleName, subscriberId, context->callerTokenId); - })); + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { + return PublishedDataSubscriberManager::GetInstance().Disable( + PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); + })); } return results; } @@ -385,27 +400,9 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) int32_t DataShareServiceImpl::OnUserChange(uint32_t code, const std::string &user, const std::string &account) { - ZLOGI("OnUserChange %{public}d %{public}s", code, user.c_str()); - if (code == static_cast(DistributedKv::AccountStatus::DEVICE_ACCOUNT_SWITCHED)) { - const std::string accountId = DistributedKv::AccountDelegate::GetInstance()->GetCurrentAccountId(); - DistributedData::StoreMetaData saveMeta; - saveMeta.appType = "default"; - saveMeta.storeId = "data_share_data_"; - saveMeta.isAutoSync = false; - saveMeta.isBackup = false; - saveMeta.isEncrypt = false; - saveMeta.bundleName = binderInfo_.selfName; - saveMeta.appId = binderInfo_.selfName; - saveMeta.user = user; - saveMeta.account = account; - saveMeta.tokenId = binderInfo_.selfTokenId; - saveMeta.securityLevel = DistributedKv::SecurityLevel::S1; - saveMeta.area = 1; - saveMeta.uid = IPCSkeleton::GetCallingUid(); - saveMeta.storeType = DATA_SHARE_SINGLE_VERSION; - saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); - KvDBDelegate::GetInstance(true, saveMeta.dataDir, binderInfo_.executors); - } + RdbSubscriberManager::GetInstance().Clear(); + PublishedDataSubscriberManager::GetInstance().Clear(); + SchedulerManager::GetInstance().ClearTimer(); return EOK; } @@ -423,9 +420,9 @@ int32_t DataShareServiceImpl::OnAppUninstall( const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) { ZLOGI("%{public}s uninstalled", bundleName.c_str()); - PublishedData::Delete(bundleName); + PublishedData::Delete(bundleName, user); PublishedData::ClearAging(); - TemplateData::Delete(bundleName); + TemplateData::Delete(bundleName, user); RdbHelper::ClearCache(); return EOK; } diff --git a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp index 85765a7a..27f2780a 100644 --- a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp @@ -64,7 +64,7 @@ bool LoadConfigFromDataProxyNodeStrategy::operator()(std::shared_ptr co ZLOGI("access private data, caller and called is same, go"); return true; } - if (context->isInWhite) { + if (context->isAllowCrossPer) { ZLOGI("access has white permission, go"); return true; } diff --git a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/cross_permission_strategy.cpp similarity index 69% rename from services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.cpp rename to services/distributeddataservice/service/data_share/strategies/general/cross_permission_strategy.cpp index 33cce533..377bec6f 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/cross_permission_strategy.cpp @@ -12,27 +12,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "WhitePermissionStrategy" +#define LOG_TAG "CrossPermissionStrategy" -#include "white_permission_strategy.h" +#include "cross_permission_strategy.h" #include "accesstoken_kit.h" #include "log_print.h" namespace OHOS::DataShare { -bool WhitePermissionStrategy::operator()(std::shared_ptr context) +bool CrossPermissionStrategy::operator()(std::shared_ptr context) { - for (const auto &permission : whitePermissions_) { + for (const auto &permission : allowCrossPermissions_) { int status = Security::AccessToken::AccessTokenKit::VerifyAccessToken(context->callerTokenId, permission); if (status == Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - context->isInWhite = true; + context->isAllowCrossPer = true; return true; } } return true; } -WhitePermissionStrategy::WhitePermissionStrategy(std::initializer_list permissions) +CrossPermissionStrategy::CrossPermissionStrategy(std::initializer_list permissions) { - whitePermissions_.insert(whitePermissions_.end(), permissions.begin(), permissions.end()); + allowCrossPermissions_.insert(allowCrossPermissions_.end(), permissions.begin(), permissions.end()); } } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h b/services/distributeddataservice/service/data_share/strategies/general/cross_permission_strategy.h similarity index 81% rename from services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h rename to services/distributeddataservice/service/data_share/strategies/general/cross_permission_strategy.h index dcc36858..53ab7da8 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/white_permission_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/general/cross_permission_strategy.h @@ -18,12 +18,12 @@ #include "strategy.h" namespace OHOS::DataShare { -class WhitePermissionStrategy final : public Strategy { +class CrossPermissionStrategy final : public Strategy { public: - explicit WhitePermissionStrategy(std::initializer_list permissions); + explicit CrossPermissionStrategy(std::initializer_list permissions); bool operator()(std::shared_ptr context) override; private: - std::vector whitePermissions_; + std::vector allowCrossPermissions_; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp index 50270a2f..92fcef98 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/permission_strategy.cpp @@ -26,7 +26,7 @@ bool PermissionStrategy::operator()(std::shared_ptr context) ZLOGE("reject permission"); return false; } - if (!context->isInWhite && !context->permission.empty()) { + if (!context->isAllowCrossPer && !context->permission.empty()) { int status = Security::AccessToken::AccessTokenKit::VerifyAccessToken(context->callerTokenId, context->permission); if (status != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp index 1486ad21..2df8047a 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp @@ -36,7 +36,7 @@ Data GetDataStrategy::Execute(std::shared_ptr context, int &errorCode) errorCode = context->errCode; return Data(); } - auto result = PublishedData::Query(context->calledBundleName); + auto result = PublishedData::Query(context->calledBundleName, context->currentUserId); Data data; for (const auto &item:result) { if (!CheckPermission(context, item.value.key)) { diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index ac609f32..af886fe8 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -17,9 +17,9 @@ #include "publish_strategy.h" #include "data_proxy/load_config_from_data_proxy_node_strategy.h" +#include "general/cross_permission_strategy.h" #include "general/load_config_common_strategy.h" #include "general/permission_strategy.h" -#include "general/white_permission_strategy.h" #include "log_print.h" #include "published_data.h" #include "utils/anonymous.h" @@ -32,7 +32,6 @@ int32_t PublishStrategy::Execute(std::shared_ptr context, const Publish ZLOGE("get strategy fail, maybe memory not enough"); return -1; } - if (!preProcess(context)) { ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); return context->errCode; @@ -42,7 +41,9 @@ int32_t PublishStrategy::Execute(std::shared_ptr context, const Publish ZLOGE("db open failed"); return -1; } - PublishedData data(context->uri, context->calledBundleName, item.subscriberId_, item.GetData(), context->version); + PublishedData data(PublishedDataNode(context->uri, context->calledBundleName, item.subscriberId_, + context->currentUserId, item.GetData()), + context->version); int32_t status = delegate->Upsert(KvDBDelegate::DATA_TABLE, data); if (status != E_OK) { ZLOGE("db Upsert failed, %{public}s %{public}s %{public}d", context->calledBundleName.c_str(), @@ -58,10 +59,10 @@ SeqStrategy &PublishStrategy::GetStrategy() if (!strategies_.IsEmpty()) { return strategies_; } - std::initializer_list whitePermissions = { "ohos.permission.WRITE_APP_PUSH_DATA" }; + std::initializer_list allowCrossPermissions = { "ohos.permission.WRITE_APP_PUSH_DATA" }; std::initializer_list list = { new (std::nothrow) LoadConfigCommonStrategy(), - new (std::nothrow) WhitePermissionStrategy(whitePermissions), + new (std::nothrow) CrossPermissionStrategy(allowCrossPermissions), new (std::nothrow) LoadConfigFromDataProxyNodeStrategy(), new (std::nothrow) PermissionStrategy() }; -- Gitee From 0f22f8c289f2e59b2b1f46ed71a8465e30e442e3 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 10 Jun 2023 16:54:57 +0800 Subject: [PATCH 202/437] f Signed-off-by: hanlu --- .../service/data_share/common/template_manager.cpp | 2 +- .../service/data_share/common/template_manager.h | 4 ++-- .../service/data_share/data_share_service_impl.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 03656dcd..f6016ec3 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -372,7 +372,7 @@ int PublishedDataSubscriberManager::Add( const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId) { publishedDataCache.Compute(key, - [&observer, &callerTokenId](const PublishedDataKey &key, std::vector &value) { + [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); LinkToDeath(key, observer); value.emplace_back(observer, callerTokenId); diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/common/template_manager.h index 7c09f034..24af1f0a 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/common/template_manager.h @@ -40,8 +40,8 @@ struct Key { class TemplateManager { public: static TemplateManager &GetInstance(); - int32_t Add(const Key &key, const int32_t userId, const Template &tpl); - int32_t Delete(const Key &key, const int32_t userId); + int32_t Add(const Key &key, const int32_t userId, const Template &tpl); + int32_t Delete(const Key &key, const int32_t userId); bool Get(const Key &key, const int32_t userId, Template &tpl); private: diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index c47601f1..1b0f1545 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -335,7 +335,7 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect }); results.emplace_back(uri, result); if (result == E_OK) { - publishedKeys.emplace_back(key); + publishedKeys.emplace_back(context->uri, context->callerBundleName, subscriberId); userId = context->currentUserId; } } -- Gitee From bfcedd2715bf4e8b0052c603a5c6eab5cce03277 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 10 Jun 2023 17:30:10 +0800 Subject: [PATCH 203/437] f Signed-off-by: hanlu --- .../service/data_share/data/template_data.cpp | 4 ++-- .../service/data_share/strategies/publish_strategy.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/template_data.cpp b/services/distributeddataservice/service/data_share/data/template_data.cpp index af382a22..4b155b84 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.cpp +++ b/services/distributeddataservice/service/data_share/data/template_data.cpp @@ -135,8 +135,8 @@ bool TemplateData::Delete(const std::string &bundleName, const int32_t userId) return true; } -bool TemplateData::Add( - const std::string &uri, const int32_t userId, const std::string &bundleName, const int64_t subsciriberId, const Template &aTemplate) +bool TemplateData::Add(const std::string &uri, const int32_t userId, const std::string &bundleName, + const int64_t subsciriberId, const Template &aTemplate) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index af886fe8..5c785f9e 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -41,9 +41,9 @@ int32_t PublishStrategy::Execute(std::shared_ptr context, const Publish ZLOGE("db open failed"); return -1; } - PublishedData data(PublishedDataNode(context->uri, context->calledBundleName, item.subscriberId_, - context->currentUserId, item.GetData()), - context->version); + PublishedDataNode node( + context->uri, context->calledBundleName, item.subscriberId_, context->currentUserId, item.GetData()); + PublishedData data(node, context->version); int32_t status = delegate->Upsert(KvDBDelegate::DATA_TABLE, data); if (status != E_OK) { ZLOGE("db Upsert failed, %{public}s %{public}s %{public}d", context->calledBundleName.c_str(), -- Gitee From 5ef984cd1418e5931c00bacc492644530d370239 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 10 Jun 2023 17:35:50 +0800 Subject: [PATCH 204/437] f Signed-off-by: hanlu --- .../service/data_share/common/db_delegate.cpp | 6 +++--- .../service/data_share/common/db_delegate.h | 2 +- .../service/data_share/common/template_manager.cpp | 4 ++-- .../service/data_share/data/published_data.cpp | 7 ++++--- .../service/data_share/data/published_data.h | 5 +++-- .../service/data_share/data_share_service_impl.cpp | 6 ++++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index a58e5714..5cf07278 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -39,10 +39,10 @@ std::shared_ptr KvDBDelegate::GetInstance( bool Id::Marshal(DistributedData::Serializable::json &node) const { auto ret = false; - if (_userId == INVALID_USER) { + if (userId == INVALID_USER) { ret = SetValue(node[GET_NAME(_id)], _id); } else { - ret = SetValue(node[GET_NAME(_id)], _id + "_" + std::to_string(_userId)); + ret = SetValue(node[GET_NAME(_id)], _id + "_" + std::to_string(userId)); } return ret; } @@ -52,7 +52,7 @@ bool Id::Unmarshal(const DistributedData::Serializable::json &node) return false; } -Id::Id(const std::string &id, const int32_t userId) : _id(id), _userId(userId) {} +Id::Id(const std::string &id, const int32_t userId) : _id(id), userId(userId) {} VersionData::VersionData(int version) : version(version) {} diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index b33b3db5..213ad276 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -56,7 +56,7 @@ public: private: std::string _id; - int32_t _userId; + int32_t userId; }; class VersionData : public DistributedData::Serializable { diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index f6016ec3..5f6f6c98 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -147,7 +147,7 @@ int RdbSubscriberManager::Add(const Key &key, const sptr std::shared_ptr context, std::shared_ptr executorPool) { int result = E_OK; - rdbCache_.Compute(key, [&observer, &context, executorPool, this](const auto &key, std::vector &value) { + rdbCache_.Compute(key, [&observer, &context, executorPool, this](const auto &key, auto &value) { ZLOGI("add subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), context->callerTokenId); std::vector node; node.emplace_back(observer, context->callerTokenId); @@ -262,7 +262,7 @@ void RdbSubscriberManager::EmitByKey(const Key &key, const int32_t userId, const if (!URIUtils::IsDataProxyURI(key.uri)) { return; } - rdbCache_.ComputeIfPresent(key, [&rdbPath, &version, &userId, this](const Key &key, std::vector &val) { + rdbCache_.ComputeIfPresent(key, [&rdbPath, &version, &userId, this](const Key &key, auto &val) { Notify(key, userId, val, rdbPath, version); return true; }); diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 5fee43f8..638edb1b 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -89,9 +89,10 @@ bool PublishedDataNode::Unmarshal(const DistributedData::Serializable::json &nod return ret && VersionData::Unmarshal(node); } -PublishedDataNode::PublishedDataNode(const std::string &key, const std::string &bundleName, - int64_t subscriberId, const int32_t userId, const std::variant, std::string> &value) - : VersionData(-1), key(key), bundleName(bundleName), subscriberId(subscriberId), value(std::move(value)), userId(userId) +PublishedDataNode::PublishedDataNode(const std::string &key, const std::string &bundleName, int64_t subscriberId, + const int32_t userId, const Data &value) + : VersionData(-1), key(key), bundleName(bundleName), subscriberId(subscriberId), value(std::move(value)), + userId(userId) { auto now = time(nullptr); if (now > 0) { diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index 5f14a20f..22042b1c 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -22,16 +22,17 @@ namespace OHOS::DataShare { class PublishedDataNode final : public VersionData { public: + using Data = std::variant, std::string>; PublishedDataNode(); PublishedDataNode(const std::string &key, const std::string &bundleName, int64_t subscriberId, - const int32_t userId, const std::variant, std::string> &value); + const int32_t userId, const Data &value); ~PublishedDataNode() = default; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; std::string key; std::string bundleName; int64_t subscriberId; - std::variant, std::string> value; + Data value; int32_t userId = Id::INVALID_USER; std::time_t timestamp = 0; }; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 1b0f1545..fa58cb8c 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -237,7 +237,8 @@ std::vector DataShareServiceImpl::EnableRdbSubs( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { - return RdbSubscriberManager::GetInstance().Enable(Key(context->uri, id.subscriberId_, id.bundleName_), context); + return RdbSubscriberManager::GetInstance().Enable( + Key(context->uri, id.subscriberId_, id.bundleName_), context); })); } return results; @@ -250,7 +251,8 @@ std::vector DataShareServiceImpl::DisableRdbSubs( for (const auto &uri : uris) { auto context = std::make_shared(uri); results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { - return RdbSubscriberManager::GetInstance().Disable(Key(context->uri, id.subscriberId_, id.bundleName_), context->callerTokenId); + return RdbSubscriberManager::GetInstance().Disable( + Key(context->uri, id.subscriberId_, id.bundleName_), context->callerTokenId); })); } return results; -- Gitee From e7d4608f9d83185ca421846aac19f6a3506a172f Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sat, 10 Jun 2023 18:27:34 +0800 Subject: [PATCH 205/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/sync_manager.h | 2 +- .../service/rdb/rdb_service_stub.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index 82b541c9..199907b5 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -43,7 +43,7 @@ public: void SetQuery(std::shared_ptr query); void SetError(int32_t code); std::shared_ptr GenerateQuery(const std::string &store, const Tables &tables); - static constexpr const char *DEFAULT_ID = "default"; + inline static constexpr const char *DEFAULT_ID = "default"; private: friend SyncManager; diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index f2a611a5..bf493d2c 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -77,13 +77,14 @@ int32_t RdbServiceStub::OnRemoteSetDistributedTables(MessageParcel &data, Messag { RdbSyncerParam param; std::vector tables; - if (!ITypesUtil::Unmarshal(data, param, tables)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables size:%{public}zu", - param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), tables.size()); + int32_t type; + if (!ITypesUtil::Unmarshal(data, param, tables, type)) { + ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s tables size:%{public}zu type:%{public}d", + param.bundleName_.c_str(), Anonymous::Change(param.storeName_).c_str(), tables.size(), type); return IPC_STUB_INVALID_DATA_ERR; } - auto status = SetDistributedTables(param, tables); + auto status = SetDistributedTables(param, tables, type); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; -- Gitee From 91e9ba678ba8d2919d3f1c05c1ec94562bac8fb2 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 10 Jun 2023 18:43:31 +0800 Subject: [PATCH 206/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 638edb1b..c7cc3ac7 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -173,7 +173,7 @@ void PublishedData::ClearAging() if (data.timestamp < lastValidTime) { status = delegate->Delete(KvDBDelegate::DATA_TABLE, - Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId), Id::INVALID_USER)); + Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId), data.userId)); if (status != E_OK) { ZLOGE("db Delete failed, %{public}s %{public}s", data.key.c_str(), data.bundleName.c_str()); } -- Gitee From 037417211d2d504012a2614596a4b67a77b6e5f2 Mon Sep 17 00:00:00 2001 From: hanlu Date: Sat, 10 Jun 2023 19:19:14 +0800 Subject: [PATCH 207/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index c7cc3ac7..79c7ef51 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -86,6 +86,7 @@ bool PublishedDataNode::Unmarshal(const DistributedData::Serializable::json &nod ret = ret && GetValue(node, GET_NAME(subscriberId), subscriberId); ret = ret && GetValue(node, GET_NAME(value), value); ret = ret && GetValue(node, GET_NAME(timestamp), timestamp); + ret = ret && GetValue(node, GET_NAME(userId), userId); return ret && VersionData::Unmarshal(node); } -- Gitee From 8c42983f5df9d335e8d7cbfd0968652639c89f64 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 11 Jun 2023 10:16:05 +0800 Subject: [PATCH 208/437] update Signed-off-by: zuojiangjiang --- .../app/src/uninstaller/uninstaller_impl.cpp | 1 - .../distributeddataservice/framework/cloud/cloud_info.cpp | 5 +++++ .../framework/include/cloud/cloud_info.h | 1 + .../service/cloud/cloud_service_impl.cpp | 8 ++++++++ .../service/cloud/cloud_service_impl.h | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index 309ee950..01c06c4c 100644 --- a/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp @@ -80,7 +80,6 @@ void UninstallEventSubscriber::OnUninstall(const std::string &bundleName, int32_ MetaDataManager::GetInstance().DelMeta(meta.GetStrategyKey()); MetaDataManager::GetInstance().DelMeta(meta.appId, true); MetaDataManager::GetInstance().DelMeta(meta.GetKeyLocal(), true); - MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); PermitDelegate::GetInstance().DelCache(meta.GetKey()); } } diff --git a/services/distributeddataservice/framework/cloud/cloud_info.cpp b/services/distributeddataservice/framework/cloud/cloud_info.cpp index 5c58d34e..7df8309f 100644 --- a/services/distributeddataservice/framework/cloud/cloud_info.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_info.cpp @@ -80,6 +80,11 @@ std::string CloudInfo::GetSchemaKey(const std::string &bundleName, int32_t insta return GetKey(SCHEMA_PREFIX, { std::to_string(user), bundleName, std::to_string(instanceId) }); } +std::string CloudInfo::GetSchemaKey(int32_t user, const std::string &bundleName, int32_t instanceId) +{ + return GetKey(SCHEMA_PREFIX, { std::to_string(user), bundleName, std::to_string(instanceId) }); +} + std::string CloudInfo::GetSchemaPrefix(const std::string &bundleName) const { if (bundleName.empty()) { diff --git a/services/distributeddataservice/framework/include/cloud/cloud_info.h b/services/distributeddataservice/framework/include/cloud/cloud_info.h index e27bae75..b88e9979 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_info.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_info.h @@ -41,6 +41,7 @@ public: std::map GetSchemaKey() const; std::string GetSchemaKey(const std::string &bundleName, int32_t instanceId = 0) const; std::string GetSchemaPrefix(const std::string &bundleName) const; + static std::string GetSchemaKey(int32_t user, const std::string &bundleName, int32_t instanceId = 0); static std::string GetSchemaKey(const StoreMetaData &meta); bool IsValid() const; bool Exist(const std::string &bundleName, int32_t instanceId = 0); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index b8b1b20a..e5d080e3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -385,6 +385,14 @@ CloudInfo CloudServiceImpl::GetCloudInfo(int32_t userId) return cloudInfo; } +int32_t CloudServiceImpl::OnAppUninstall( + const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) +{ + (void)tokenId; + MetaDataManager::GetInstance().DelMeta(Subscription::GetRelationKey(user, bundleName), true); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(user, bundleName, index), true); +} + void CloudServiceImpl::GetSchema(const Event &event) { auto &rdbEvent = static_cast(event); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 7bdbfe21..554d8301 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -37,6 +37,7 @@ public: int32_t OnInitialize() override; int32_t OnBind(const BindInfo &info) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; + int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; private: class Factory { -- Gitee From e8e0da378d8b311ef2890d682c3f431ebf01a37c Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 11 Jun 2023 10:54:49 +0800 Subject: [PATCH 209/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index e5d080e3..d4a29e00 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -391,6 +391,7 @@ int32_t CloudServiceImpl::OnAppUninstall( (void)tokenId; MetaDataManager::GetInstance().DelMeta(Subscription::GetRelationKey(user, bundleName), true); MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(user, bundleName, index), true); + return E_OK; } void CloudServiceImpl::GetSchema(const Event &event) -- Gitee From 184b81303bf5a744527cb255ad0ad4ad04a114c3 Mon Sep 17 00:00:00 2001 From: houpengtao Date: Sun, 11 Jun 2023 14:39:03 +0800 Subject: [PATCH 210/437] use shared ptr Signed-off-by: houpengtao --- .../service/data_share/common/rdb_delegate.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 8dcd025d..4c8e3236 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -159,7 +159,6 @@ std::shared_ptr RdbDelegate::QuerySql(const std:: ZLOGE("store is null"); return nullptr; } - auto result = store_->QuerySql(sql); - return std::move(result); + return store_->QuerySql(sql); } } // namespace OHOS::DataShare \ No newline at end of file -- Gitee From d47c34193fb7d31f371dbc3d6562f5726a7e8994 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 11 Jun 2023 14:41:35 +0800 Subject: [PATCH 211/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 06efff0e..897f7d2e 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -254,7 +254,7 @@ std::function SyncManager::GetSyncHandler() } ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), Anonymous::Change(storeInfo.storeName).c_str()); - store->Sync( { SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); + store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); }; } -- Gitee From fdfce714d37d7bb24a89b03e6618f3d82640b285 Mon Sep 17 00:00:00 2001 From: leiiyb Date: Sun, 11 Jun 2023 16:27:18 +0800 Subject: [PATCH 212/437] modify result Signed-off-by: leiiyb --- .../service/data_share/common/db_delegate.h | 2 +- .../service/data_share/common/rdb_delegate.cpp | 2 +- .../service/data_share/common/rdb_delegate.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index b649c1a3..b0f648f5 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -39,7 +39,7 @@ public: const DataSharePredicates &predicates, const std::vector &columns, int &errCode) = 0; virtual std::string Query( const std::string &sql, const std::vector &selectionArgs = std::vector()) = 0; - virtual std::shared_ptr QuerySql(const std::string &sql) = 0; + virtual std::shared_ptr QuerySql(const std::string &sql) = 0; }; class Id : public DistributedData::Serializable { diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp index 4c8e3236..81373b90 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.cpp @@ -153,7 +153,7 @@ std::string RdbDelegate::Query(const std::string &sql, const std::vector RdbDelegate::QuerySql(const std::string &sql) +std::shared_ptr RdbDelegate::QuerySql(const std::string &sql) { if (store_ == nullptr) { ZLOGE("store is null"); diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.h b/services/distributeddataservice/service/data_share/common/rdb_delegate.h index 39e2c119..02093dce 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.h +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.h @@ -39,7 +39,7 @@ public: std::shared_ptr Query(const std::string &tableName, const DataSharePredicates &predicates, const std::vector &columns, int &errCode) override; std::string Query(const std::string &sql, const std::vector &selectionArgs) override; - std::shared_ptr QuerySql(const std::string &sql) override; + std::shared_ptr QuerySql(const std::string &sql) override; private: static std::atomic resultSetCount; -- Gitee From 1a58debac2dd255d0a0be5f0cac92df6dd2491e1 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 11 Jun 2023 17:03:06 +0800 Subject: [PATCH 213/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/rdb/rdb_general_store.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 127e7b52..10366ca6 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -68,7 +68,7 @@ private: void OnChange(DBOrigin origin, const std::string &originalId, DBChangedData &&data) override; bool HasWatcher() const { - return watcher_ == nullptr; + return watcher_ != nullptr; } private: friend RdbGeneralStore; -- Gitee From 7efca93a985fc75e7aad0b0b9673ccca5b093d25 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sun, 11 Jun 2023 18:25:32 +0800 Subject: [PATCH 214/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/rdb/rdb_notifier_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index bd9ce05b..92aee4fa 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -60,7 +60,7 @@ int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &pr } MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option; if (Remote()->SendRequest(RDB_NOTIFIER_CMD_DATA_CHANGE, data, reply, option) != 0) { ZLOGE("send request failed"); return RDB_ERROR; -- Gitee From 8888b0466b0fedf5795955f3ace798fac16a1f2d Mon Sep 17 00:00:00 2001 From: liweifeng Date: Sun, 11 Jun 2023 21:49:33 +0800 Subject: [PATCH 215/437] =?UTF-8?q?sa=E8=B0=83=E7=94=A8=E8=BF=94=E5=9B=9Et?= =?UTF-8?q?rue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liweifeng Change-Id: I32082c4ced21b705a67958cf068e4b85a69bcc2a --- .../service/data_share/data_share_service_impl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index fa58cb8c..f55f052b 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -145,7 +145,11 @@ int32_t DataShareServiceImpl::DelTemplate(const std::string &uri, const int64_t bool DataShareServiceImpl::GetCallerBundleName(std::string &bundleName) { auto tokenId = IPCSkeleton::GetCallingTokenID(); - if (Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) != Security::AccessToken::TOKEN_HAP) { + auto type = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + if (type == Security::AccessToken::TOKEN_NATIVE) { + return true; + } + if (type != Security::AccessToken::TOKEN_HAP) { return false; } Security::AccessToken::HapTokenInfo tokenInfo; -- Gitee From 584bfe8eff8ade3a35132e9e40ff1786374f42ec Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 12 Jun 2023 14:53:21 +0800 Subject: [PATCH 216/437] fix issue of IncorrectLick Signed-off-by: mazhao --- bundle.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bundle.json b/bundle.json index 1748d179..54b1d0dc 100644 --- a/bundle.json +++ b/bundle.json @@ -87,7 +87,6 @@ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:build_module", "//foundation/distributeddatamgr/datamgr_service/conf:build_module", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share/gaussdb_rd:build_module" ], "inner_kits": [], "test": [ -- Gitee From 5804fec4aa1ceacbc2d05b8f08946004e6e89154 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Mon, 12 Jun 2023 14:58:25 +0800 Subject: [PATCH 217/437] fix:fix bug Signed-off-by: htt1997 --- .../framework/include/store/auto_cache.h | 2 ++ .../distributeddataservice/framework/store/auto_cache.cpp | 5 +++++ .../distributeddataservice/service/rdb/rdb_service_impl.cpp | 1 + services/distributeddataservice/service/rdb/rdb_syncer.cpp | 4 +++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/include/store/auto_cache.h b/services/distributeddataservice/framework/include/store/auto_cache.h index b5e91e68..e4940b91 100644 --- a/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/services/distributeddataservice/framework/include/store/auto_cache.h @@ -48,6 +48,8 @@ public: API_EXPORT void CloseStore(uint32_t tokenId, const std::string &storeId); + API_EXPORT void CloseStore(uint32_t tokenId); + API_EXPORT void CloseExcept(const std::set &users); API_EXPORT void SetObserver(uint32_t tokenId, const std::string &storeId, const Watchers &watchers); diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index ec9dea51..381c9cb7 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -94,6 +94,11 @@ void AutoCache::CloseStore(uint32_t tokenId, const std::string &storeId) }); } +void AutoCache::CloseStore(uint32_t tokenId) +{ + stores_.Erase(tokenId); +} + void AutoCache::CloseExcept(const std::set &users) { stores_.EraseIf([&users](const auto &tokenId, std::map &delegates) { diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index e9e9a370..3bf671e4 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -143,6 +143,7 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib int32_t RdbServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) { OnClientDied(pid); + AutoCache::GetInstance().CloseStore(tokenId); return E_OK; } diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index 8cb8dd3f..aef9c6ad 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -367,7 +367,9 @@ int32_t RdbSyncer::DoSync(const Option &option, const PredicatesMemo &predicates return delegate->Sync( devices, static_cast(option.mode), MakeQuery(predicates), [async](const std::map> &syncStatus) { - async(HandleSyncStatus(syncStatus)); + if (async != nullptr) { + async(HandleSyncStatus(syncStatus)); + } }, !option.isAsync); } else if (option.mode < DistributedData::GeneralStore::CLOUD_END && -- Gitee From 5618cc7b59d98e450b52e89c961d27c8eafd1ad3 Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 12 Jun 2023 15:05:17 +0800 Subject: [PATCH 218/437] fix format Signed-off-by: mazhao --- bundle.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 54b1d0dc..586e02e1 100644 --- a/bundle.json +++ b/bundle.json @@ -86,7 +86,7 @@ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:build_module", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:build_module", "//foundation/distributeddatamgr/datamgr_service/conf:build_module", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module" ], "inner_kits": [], "test": [ -- Gitee From f91ba6503d4ad4f63ef4d1c39c2af2cc0c99bfb3 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Tue, 13 Jun 2023 14:58:16 +0800 Subject: [PATCH 219/437] Override Onbind to add executors to object feature Signed-off-by: renjiecui --- .../service/object/object_service_impl.cpp | 7 +++++++ .../service/object/object_service_impl.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/services/distributeddataservice/service/object/object_service_impl.cpp b/services/distributeddataservice/service/object/object_service_impl.cpp index 7158f8ef..55464231 100644 --- a/services/distributeddataservice/service/object/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/object_service_impl.cpp @@ -279,4 +279,11 @@ int32_t ObjectServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, con ObjectServiceImpl::ObjectServiceImpl() { } + +int32_t ObjectServiceImpl::OnBind(const BindInfo &bindInfo) +{ + executors_ = bindInfo.executors; + ObjectStoreManager::GetInstance()->SetThreadPool(executors_); + return 0; +} } // namespace OHOS::DistributedObject diff --git a/services/distributeddataservice/service/object/object_service_impl.h b/services/distributeddataservice/service/object/object_service_impl.h index a7f40e51..5206481e 100644 --- a/services/distributeddataservice/service/object/object_service_impl.h +++ b/services/distributeddataservice/service/object/object_service_impl.h @@ -44,6 +44,7 @@ public: int32_t OnInitialize() override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; + int32_t OnBind(const BindInfo &bindInfo) override; private: class Factory { @@ -52,6 +53,7 @@ private: ~Factory(); }; static Factory factory_; + std::shared_ptr executors_; }; } // namespace OHOS::DistributedObject #endif -- Gitee From 1a3e03132779513382619bb02ce602fcdfee1303 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 15:14:30 +0800 Subject: [PATCH 220/437] remove the config and unused code Signed-off-by: Sven Wang --- bundle.json | 4 +- conf/BUILD.gn | 4 +- datamgr_service.gni | 2 + .../adapter/autils/BUILD.gn | 43 ---- .../adapter/autils/src/constant.cpp | 124 ------------ .../adapter/autils/src/directory_utils.cpp | 164 ---------------- .../autils/src/thread_pool/kv_store_task.cpp | 40 ---- .../src/thread_pool/kv_store_thread.cpp | 60 ------ .../autils/src/thread_pool/kv_store_thread.h | 40 ---- .../src/thread_pool/kv_store_thread_pool.cpp | 38 ---- .../thread_pool/kv_store_thread_pool_impl.cpp | 111 ----------- .../thread_pool/kv_store_thread_pool_impl.h | 53 ----- .../adapter/autils/test/BUILD.gn | 48 ----- .../unittest/kv_store_thread_pool_test.cpp | 130 ------------- .../communicator/src/softbus_adapter.h | 1 - .../adapter/include/autils/constant.h | 184 ------------------ .../adapter/include/autils/directory_utils.h | 50 ----- .../adapter/include/autils/kv_store_task.h | 39 ---- .../include/autils/kv_store_thread_pool.h | 46 ----- .../include/autils/platform_specific.h | 25 --- .../adapter/include/autils/time_utils.h | 38 ---- .../app/src/kvstore_data_service.cpp | 48 +---- .../app/src/kvstore_data_service.h | 36 ---- .../app/src/kvstore_meta_manager.cpp | 3 +- .../app/src/security/security.cpp | 3 +- .../distributeddataservice/service/BUILD.gn | 1 - .../service/kvdb/executor_factory.cpp | 46 ----- .../service/kvdb/executor_factory.h | 36 ---- 28 files changed, 11 insertions(+), 1406 deletions(-) delete mode 100755 services/distributeddataservice/adapter/autils/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/autils/src/constant.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/directory_utils.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp delete mode 100644 services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h delete mode 100755 services/distributeddataservice/adapter/autils/test/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp delete mode 100644 services/distributeddataservice/adapter/include/autils/constant.h delete mode 100644 services/distributeddataservice/adapter/include/autils/directory_utils.h delete mode 100644 services/distributeddataservice/adapter/include/autils/kv_store_task.h delete mode 100644 services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h delete mode 100644 services/distributeddataservice/adapter/include/autils/platform_specific.h delete mode 100644 services/distributeddataservice/adapter/include/autils/time_utils.h delete mode 100644 services/distributeddataservice/service/kvdb/executor_factory.cpp delete mode 100644 services/distributeddataservice/service/kvdb/executor_factory.h diff --git a/bundle.json b/bundle.json index 586e02e1..c8b8c56e 100644 --- a/bundle.json +++ b/bundle.json @@ -38,7 +38,9 @@ "name": "datamgr_service", "subsystem": "distributeddatamgr", "syscap": [], - "features": [], + "features": [ + "datamgr_service_config" + ], "adapted_system_type": [ "standard" ], diff --git a/conf/BUILD.gn b/conf/BUILD.gn index 0e9037c6..14f7ca2c 100644 --- a/conf/BUILD.gn +++ b/conf/BUILD.gn @@ -15,7 +15,9 @@ import("//build/ohos_var.gni") #/system/etc/distributeddata/conf group("build_module") { - deps = [ ":default_conf" ] + if (datamgr_service_config) { + deps = [ ":default_conf" ] + } } ohos_prebuilt_etc("default_conf") { source = "config.json" diff --git a/datamgr_service.gni b/datamgr_service.gni index 2537c568..7ef3974e 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -45,4 +45,6 @@ declare_args() { } else { os_account_part_is_enabled = false } + + datamgr_service_config = true; } diff --git a/services/distributeddataservice/adapter/autils/BUILD.gn b/services/distributeddataservice/adapter/autils/BUILD.gn deleted file mode 100755 index 48efe8f5..00000000 --- a/services/distributeddataservice/adapter/autils/BUILD.gn +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import("//build/ohos.gni") -import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") - -ohos_static_library("distributeddata_autils_static") { - sources = [ - "src/constant.cpp", - "src/directory_utils.cpp", - "src/thread_pool/kv_store_task.cpp", - "src/thread_pool/kv_store_thread.cpp", - "src/thread_pool/kv_store_thread_pool.cpp", - "src/thread_pool/kv_store_thread_pool_impl.cpp", - ] - - include_dirs = [ - "../include/autils", - "../include/log", - "../include/dfx", - "${kv_store_common_path}", - ] - - cflags_cc = [ "-fvisibility=hidden" ] - - external_deps = [ - "c_utils:utils", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", - ] - subsystem_name = "distributeddatamgr" - part_name = "datamgr_service" - defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] -} diff --git a/services/distributeddataservice/adapter/autils/src/constant.cpp b/services/distributeddataservice/adapter/autils/src/constant.cpp deleted file mode 100644 index f393d354..00000000 --- a/services/distributeddataservice/adapter/autils/src/constant.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "constant.h" -#include -#include -#include - -namespace OHOS { -namespace DistributedKv { -// the Key Prefix for Meta data of KvStore. -const std::string KvStoreMetaRow::KEY_PREFIX = "KvStoreMetaData"; - -const std::string SecretMetaRow::KEY_PREFIX = "SecretKey"; - -/* version for distributed kv data service. */ -const std::string Constant::VERSION = "1"; - -/* meta name for distributed kv data service. */ -const std::string Constant::META_DIR_NAME = "Meta"; - -/* name for distributed kv data service. */ -const std::string Constant::SERVICE_NAME = "mdds"; - -/* root path for distributed kv data service. */ -const std::string Constant::ROOT_PATH = "/data/misc_de/0"; - -/* root path for distributeddata service and system services. */ -const std::string Constant::ROOT_PATH_DE = "/data/misc_de/0"; - -/* root path for self-developed and non-self-developed app. */ -const std::string Constant::ROOT_PATH_CE = "/data/misc_ce/0"; - -// the max length for key is 1024. -const size_t Constant::MAX_KEY_LENGTH = 1024; - -// the max length for StoreId is 128. -const size_t Constant::MAX_STORE_ID_LENGTH = 128; - -// the max length for value is 4M. -const size_t Constant::MAX_VALUE_LENGTH = 4 * 1024 * 1024; - -// the max batch for putBatch is 128. -const size_t Constant::MAX_BATCH_SIZE = 128; - -// the max capacity for ipc is 800K. -const size_t Constant::MAX_IPC_CAPACITY = 800 * 1024; - -// the default mode is 0755, stands for r/w/x for user, r/x for group, r/x for others. -const mode_t Constant::DEFAULT_MODE = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - -// the mode for dir is 0755, r/w/x for user, r/-/x for group, r/-/x for others. -const mode_t Constant::DEFAULT_MODE_DIR = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - -// the mode for file is 0600, r/w/- for user, -/-/- for group, -/-/- for others. -const mode_t Constant::DEFAULT_MODE_FILE = S_IRUSR | S_IWUSR; - -// Size threshold of switching to large data is a little smaller than MAX_IPC_CAPACITY. -const int Constant::SWITCH_RAW_DATA_SIZE = 700 * 1024; - -const int Constant::MAX_OPEN_KVSTORES = 16; - -// default group id for synchronization. -const std::string Constant::DEFAULT_GROUP_ID = "default"; - -// true indicates the ownership of distributed data is DEVICE, otherwise, ACCOUNT -const bool Constant::STOREID_ONLY_FLAG = true; - -// service meta db name. -const std::string Constant::SERVICE_META_DB_NAME = "service_meta"; - -const std::string Constant::KEY_SEPARATOR = "###"; - -const std::string Constant::ROOT_KEY_GENERATED = "RootKeyGenerated"; - -std::vector KvStoreMetaRow::GetKeyFor(const std::string &key) -{ - std::string str = Constant::Concatenate({KvStoreMetaRow::KEY_PREFIX, Constant::KEY_SEPARATOR, key }); - return std::vector(str.begin(), str.end()); -} - -std::vector SecretMetaRow::GetKeyFor(const std::string &key) -{ - std::string str = Constant::Concatenate({SecretMetaRow::KEY_PREFIX, Constant::KEY_SEPARATOR, key }); - return std::vector(str.begin(), str.end()); -} - -std::string Constant::Concatenate(std::initializer_list stringList) -{ - std::string result; - size_t result_size = 0; - for (const std::string &str : stringList) { - result_size += str.size(); - } - result.reserve(result_size); - for (const std::string &str : stringList) { - result.append(str.data(), str.size()); - } - return result; -} - -std::string Constant::GetDefaultDeviceAccountId() -{ - return "0"; -} - -std::string Constant::GetDefaultHarmonyAccountName() -{ - return "default"; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/directory_utils.cpp b/services/distributeddataservice/adapter/autils/src/directory_utils.cpp deleted file mode 100644 index b1262610..00000000 --- a/services/distributeddataservice/adapter/autils/src/directory_utils.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "DirectoryUtils" - -#include "directory_utils.h" -#include -#include -#include "log_print.h" -#include "unistd.h" - -namespace OHOS { -namespace DistributedKv { -// change the mode of all files in the specified directory recursively. -bool DirectoryUtils::ChangeModeFileOnly(const std::string &path, const mode_t &mode) -{ - ZLOGI("begin."); - std::string subPath; - bool ret = true; - DIR *dir = opendir(path.c_str()); - if (dir == nullptr) { - return false; - } - - while (true) { - struct dirent *ptr = readdir(dir); - if (ptr == nullptr) { - break; - } - - // skip current directory and parent directory. - if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) { - continue; - } - - subPath = IncludeDelimiterAtPathTail(path) + std::string(ptr->d_name); - if (ptr->d_type == DT_DIR) { - ret = ChangeModeFileOnly(subPath, mode); - continue; - } - - // change the mode of file only. - if ((access(subPath.c_str(), F_OK) == 0) && (ptr->d_type == DT_REG)) { - ZLOGD("[Von-Debug]change the file[%s] to mode[%d].", subPath.c_str(), mode); - if (!ChangeMode(subPath, mode)) { - closedir(dir); - ZLOGD("[Von-Debug]change the file[%s] to mode[%d] failed.", subPath.c_str(), mode); - return false; - } - } - } - closedir(dir); - return ret; -} - -// change the mode of all subdirectories in the specified directory recursively. -bool DirectoryUtils::ChangeModeDirOnly(const std::string &path, const mode_t &mode) -{ - ZLOGI("begin."); - std::string subPath; - bool ret = true; - DIR *dir = opendir(path.c_str()); - if (dir == nullptr) { - return false; - } - - while (true) { - struct dirent *ptr = readdir(dir); - if (ptr == nullptr) { - break; - } - - // skip current directory and parent directory. - if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) { - continue; - } - - subPath = IncludeDelimiterAtPathTail(path) + std::string(ptr->d_name); - if (ptr->d_type == DT_DIR) { - ret = ChangeModeDirOnly(subPath, mode); - continue; - } - - // change the mode of directory only. - if ((access(subPath.c_str(), F_OK) == 0) && (ptr->d_type == DT_DIR)) { - ZLOGD("[Von-Debug]change the dir[%s] to mode[%d].", subPath.c_str(), mode); - if (!ChangeMode(subPath, mode)) { - closedir(dir); - ZLOGD("[Von-Debug]change the dir[%s] to mode[%d] failed.", subPath.c_str(), mode); - return false; - } - } - } - closedir(dir); - - std::string currentPath = ExcludeDelimiterAtPathTail(path); - if (access(currentPath.c_str(), F_OK) == 0) { - if (!ChangeMode(currentPath, mode)) { - return false; - } - } - return ret; -} - -// create all subdirectories in the specified directory recursively. -bool DirectoryUtils::CreateDirectory(const std::string &path) -{ - std::string::size_type index = 0; - do { - std::string subPath; - index = path.find('/', index + 1); - if (index == std::string::npos) { - subPath = path; - } else { - subPath = path.substr(0, index); - } - - if (access(subPath.c_str(), F_OK) != 0) { - if (mkdir(subPath.c_str(), (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != 0) { - return false; - } - } - } while (index != std::string::npos); - - return access(path.c_str(), F_OK) == 0; -} - -// exclude separators '/' at the end of the path. -std::string DirectoryUtils::ExcludeDelimiterAtPathTail(const std::string &path) -{ - if (path.rfind('/') != path.size() - 1) { - return path; - } - - if (!path.empty()) { - return path.substr(0, static_cast(path.size()) - 1); - } - - return path; -} - -// include separators '/' at the end of the path. -std::string DirectoryUtils::IncludeDelimiterAtPathTail(const std::string &path) -{ - if (path.rfind('/') != path.size() - 1) { - return path + "/"; - } - - return path; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp deleted file mode 100644 index b6de8ace..00000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_task.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "KvStoreTask" - -#include "kv_store_task.h" -#include "log_print.h" - -namespace OHOS { -namespace DistributedKv { -KvStoreTask::KvStoreTask(std::function lambda) -{ - task_ = std::move(lambda); - name_ = std::string(); -} - -KvStoreTask::KvStoreTask(std::function lambda, const std::string &taskName) -{ - task_ = std::move(lambda); - name_ = taskName; -} - -void KvStoreTask::operator()() -{ - task_(); -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp deleted file mode 100644 index 52efe42d..00000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "KvStoreThread" - -#include "kv_store_thread_pool_impl.h" -#include "log_print.h" -#include "pthread.h" - -namespace OHOS { -namespace DistributedKv { -KvStoreThread::KvStoreThread(KvStoreThreadPool *threadPool, const std::string &name) -{ - realThread_ = std::thread([this, threadPool, name]() { - // this makes me unconfortable: this lambda capture 'this' by reference, and right after this call this object - // is move-constructed, so when we call this in Run(), we are actually refer to the old object. we can still - // use all its non-virtual function, but all arguments and virtual-function are not available. - int32_t ret = pthread_setname_np(pthread_self(), name.c_str()); - if (ret != 0) { - ZLOGE("Failed to set thread name:%{public}s, ret:%{public}d.", name.c_str(), ret); - } - Run(threadPool); - }); -} - -void KvStoreThread::Run(KvStoreThreadPool *pool) -{ - if (pool == nullptr) { - ZLOGW("input param is null."); - return; - } - - auto impl = reinterpret_cast(pool); - while (impl->IsRunning()) { - impl->ScheduleTask()(); - } - ZLOGW("stop"); -} - -void KvStoreThread::Join() -{ - realThread_.join(); -} - -KvStoreThread::~KvStoreThread() -{} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h deleted file mode 100644 index c0c745bd..00000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef KV_STORE_THREAD_H -#define KV_STORE_THREAD_H - -#include -#include "kv_store_thread_pool.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreThread { -public: - explicit KvStoreThread(KvStoreThreadPool *threadPool, const std::string &name); - KvStoreThread(KvStoreThread &&thread) = delete; - KvStoreThread(const KvStoreThread &) = delete; - KvStoreThread &operator=(KvStoreThread &&) = delete; - KvStoreThread &operator=(const KvStoreThread &) = delete; - void Run(KvStoreThreadPool *threadPool); - void Join(); - ~KvStoreThread(); -private: - std::thread realThread_; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // KV_STORE_THREAD_H diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp deleted file mode 100644 index d8ccdc62..00000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "KvStoreThreadPool" - -#include "kv_store_thread_pool_impl.h" -#include "log_print.h" - -namespace OHOS { -namespace DistributedKv { -std::shared_ptr KvStoreThreadPool::GetPool(int poolSize, std::string poolName, bool startImmediately) -{ - std::shared_ptr poolImpl = - std::make_shared(poolSize, std::move(poolName), startImmediately); - if (poolImpl == nullptr) { - return nullptr; - } - return std::shared_ptr(std::dynamic_pointer_cast(poolImpl)); -} - -std::string KvStoreThreadPool::GetPoolName() -{ - return poolName_; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp deleted file mode 100644 index 7a8ad6b8..00000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "KvStoreThreadPoolImpl" -#include "kv_store_thread_pool_impl.h" - -#include -#include -#include - -#include "kv_store_thread.h" -#include "log_print.h" - -namespace OHOS { -namespace DistributedKv { -KvStoreThreadPoolImpl::~KvStoreThreadPoolImpl() -{ - Stop(); -} - -void KvStoreThreadPoolImpl::Start() -{ - ZLOGI("start"); - running = true; - for (int i = 0; i < threadNum; i++) { - threadList.emplace_back(this, poolName_.substr(0, MAX_THREAD_NAME_SIZE) + "_" + std::to_string(i)); - } -} - -void KvStoreThreadPoolImpl::Stop() -{ - ZLOGW("stop"); - if (!running) { - return; - } - { - std::unique_lock lock(taskListMutex); - running = false; - for (auto task = taskList.begin(); task != taskList.end(); task++) { - ZLOGI("running task in stop()"); - (*task)(); - ZLOGI("running task finish"); - } - taskList.clear(); - } - has_task.notify_all(); - for (auto thread = threadList.begin(); thread != threadList.end(); thread++) { - thread->Join(); - } -} - -bool KvStoreThreadPoolImpl::IsRunning() const -{ - return running; -} - -KvStoreThreadPoolImpl::KvStoreThreadPoolImpl(int threadNum, std::string poolName, bool startImmediately) - : taskList(), threadList(), threadNum(threadNum) -{ - this->poolName_ = poolName; - if (threadNum <= 0 || threadNum > MAX_POOL_SIZE) { - this->threadNum = DEFAULT_POOL_SIZE; - } - if (startImmediately) { - Start(); - } -} - -bool KvStoreThreadPoolImpl::AddTask(KvStoreTask &&task) -{ - ZLOGD("start"); - if (threadList.empty()) { - Start(); - } - std::unique_lock lock(taskListMutex); - if (!running) { - return false; - } - taskList.push_back(std::move(task)); - has_task.notify_one(); - return true; -} - -KvStoreTask KvStoreThreadPoolImpl::ScheduleTask() -{ - std::unique_lock lock(taskListMutex); - if (taskList.empty() && running) { - has_task.wait(lock, [&]() {return !running || !taskList.empty(); }); - } - if (taskList.empty()) { - ZLOGW("taskList empty. schedule empty task(pool stopping?)"); - return KvStoreTask([]() {;}); - } - KvStoreTask ret = std::move(taskList.front()); - taskList.pop_front(); - return ret; -} -} // namespace DistributedKv -} // namespace OHOS diff --git a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h b/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h deleted file mode 100644 index 10051ff1..00000000 --- a/services/distributeddataservice/adapter/autils/src/thread_pool/kv_store_thread_pool_impl.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef KV_STORE_THREAD_POOL_IMPL_H -#define KV_STORE_THREAD_POOL_IMPL_H - -#include -#include -#include -#include "kv_store_thread_pool.h" -#include "kv_store_thread.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreThreadPoolImpl : public KvStoreThreadPool { -public: - KvStoreThreadPoolImpl(int threadNum, std::string poolName, bool startImmediately); - KvStoreThreadPoolImpl() = delete; - KvStoreThreadPoolImpl(const KvStoreThreadPoolImpl &) = delete; - KvStoreThreadPoolImpl(KvStoreThreadPoolImpl &&) = delete; - KvStoreThreadPoolImpl& operator=(const KvStoreThreadPoolImpl &) = delete; - KvStoreThreadPoolImpl& operator=(KvStoreThreadPoolImpl &&) = delete; - bool AddTask(KvStoreTask &&task) override; - void Stop() final; - KvStoreTask ScheduleTask(); - bool IsRunning() const; - virtual ~KvStoreThreadPoolImpl(); -private: - std::mutex taskListMutex{}; - std::list taskList{}; - std::condition_variable has_task{}; - std::list threadList{}; - int threadNum; - void Start(); - bool running = false; - static constexpr int MAX_THREAD_NAME_SIZE = 11; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // KV_STORE_THREAD_POOL_IMPL_H diff --git a/services/distributeddataservice/adapter/autils/test/BUILD.gn b/services/distributeddataservice/adapter/autils/test/BUILD.gn deleted file mode 100755 index afd7c605..00000000 --- a/services/distributeddataservice/adapter/autils/test/BUILD.gn +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import("//build/test.gni") - -module_output_path = "datamgr_service/distributeddatafwk" - -############################################################################### -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "../../include/autils/", - "//foundation/distributeddatamgr/kv_store/frameworks/common", - ] - defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] -} - -ohos_unittest("KvStoreThreadPoolTest") { - module_out_path = module_output_path - - sources = [ "unittest/kv_store_thread_pool_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "../../autils:distributeddata_autils_static", - "//third_party/googletest:gtest_main", - ] -} - -group("unittest") { - testonly = true - - deps = [] - - deps += [ ":KvStoreThreadPoolTest" ] -} -############################################################################### diff --git a/services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp b/services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp deleted file mode 100644 index f9527440..00000000 --- a/services/distributeddataservice/adapter/autils/test/unittest/kv_store_thread_pool_test.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include "kv_store_thread_pool.h" - -using namespace testing::ext; -using namespace OHOS::DistributedKv; - -class KvStoreThreadPoolTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void KvStoreThreadPoolTest::SetUpTestCase(void) -{} - -void KvStoreThreadPoolTest::TearDownTestCase(void) -{} - -void KvStoreThreadPoolTest::SetUp(void) -{} - -void KvStoreThreadPoolTest::TearDown(void) -{} - -/** - * @tc.name: TestApplyTask001 - * @tc.desc: test if task can be done asynchronous. - * @tc.type: FUNC - * @tc.require: AR000CQS31 - * @tc.author: liqiao - */ -HWTEST_F(KvStoreThreadPoolTest, TestApplyTask001, TestSize.Level1) -{ - auto pool = KvStoreThreadPool::GetPool(8, "Task001", true); - int var = 0; - auto start = std::chrono::system_clock::now(); - pool->AddTask(KvStoreTask([&var](){ - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - var++; - })); - auto end = std::chrono::system_clock::now(); - std::chrono::duration returnTime = end - start; - EXPECT_LT(returnTime.count(), 0.05); - EXPECT_EQ(var, 0); - std::this_thread::sleep_for(std::chrono::milliseconds(150)); - EXPECT_EQ(var, 1); -} - -/** - * @tc.name: TestApplyTask002 - * @tc.desc: test if task can be done in different thread. - * @tc.type: FUNC - * @tc.require: AR000CQS31 - * @tc.author: liqiao - */ -HWTEST_F(KvStoreThreadPoolTest, TestApplyTask002, TestSize.Level2) -{ - auto pool = KvStoreThreadPool::GetPool(2, "Task002", false); - int var = 0; - std::mutex varMutex; - auto start = std::chrono::system_clock::now(); - KvStoreTask task([&](){ - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::lock_guard lock(varMutex); - var++; - }); - for (int i = 0; i < 8; i++) { - pool->AddTask(KvStoreTask(task)); - } - auto end = std::chrono::system_clock::now(); - std::chrono::duration returnTime = end - start; - EXPECT_LT(returnTime.count(), 0.1); - EXPECT_EQ(var, 0); - std::this_thread::sleep_for(std::chrono::milliseconds(700)); - EXPECT_EQ(var, 2); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 4); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 6); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 8); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - EXPECT_EQ(var, 8); - pool->Stop(); -} - -/** - * @tc.name: TestApplyTask003 - * @tc.desc: test whether task can be done if they are not scheduled when calling Stop(). - * @tc.type: FUNC - * @tc.require: AR000CQS31 - * @tc.author: liqiao - */ -HWTEST_F(KvStoreThreadPoolTest, TestApplyTask003, TestSize.Level1) -{ - auto pool = KvStoreThreadPool::GetPool(2, "Task003", false); - int var = 0; - std::mutex varMutex; - KvStoreTask task([&](){ - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - std::lock_guard lock(varMutex); - var++; - }); - for (int i = 0; i < 8; i++) { - pool->AddTask(KvStoreTask(task)); - } - EXPECT_EQ(var, 0); - pool->Stop(); - EXPECT_EQ(var, 8); -} diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h b/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h index 277d2d73..868d5ed1 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h +++ b/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h @@ -28,7 +28,6 @@ #include "app_data_change_listener.h" #include "app_device_change_listener.h" #include "block_data.h" -#include "platform_specific.h" #include "session.h" #include "softbus_bus_center.h" #include "softbus_client.h" diff --git a/services/distributeddataservice/adapter/include/autils/constant.h b/services/distributeddataservice/adapter/include/autils/constant.h deleted file mode 100644 index 1d974894..00000000 --- a/services/distributeddataservice/adapter/include/autils/constant.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef KV_DATASERVICE_CONSTANT_H -#define KV_DATASERVICE_CONSTANT_H - -#include -#include -#include -#include -#include -#include -#include -#include "visibility.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreMetaRow { -public: - KVSTORE_API static const std::string KEY_PREFIX; - - KVSTORE_API static std::vector GetKeyFor(const std::string &key); -}; - -class SecretMetaRow { -public: - KVSTORE_API static const std::string KEY_PREFIX; - - KVSTORE_API static std::vector GetKeyFor(const std::string &key); -}; - -class Constant { -public: - // concatenate strings and return a composition string. - KVSTORE_API static std::string Concatenate(std::initializer_list stringList); - - // delete left bland in s by reference. - template - static void LeftTrim(T &s); - - // delete right bland in s by reference. - template - static void RightTrim(T &s); - - // delete both left and right bland in s by reference. - template - static void Trim(T &s); - - // delete left bland in s by reference, not change raw string. - template - static T LeftTrimCopy(T s); - - // delete right bland in s by reference, not change raw string. - template - static T RightTrimCopy(T s); - - // delete both left and right bland in s by reference, not change raw string. - template - static T TrimCopy(T s); - - // get default device account id. - KVSTORE_API static std::string GetDefaultDeviceAccountId(); - - // get default harmony account name. - KVSTORE_API static std::string GetDefaultHarmonyAccountName(); - - // default group id for synchronization based on harmony account. - KVSTORE_API static const std::string DEFAULT_GROUP_ID; - - // Indicates whether only storeid are used as hash materials for the DistributedDB path generated. - KVSTORE_API static const bool STOREID_ONLY_FLAG; - - // version for distributed kv data service. - KVSTORE_API static const std::string VERSION; - - // meta name for distributed kv data service. - KVSTORE_API static const std::string META_DIR_NAME; - - // name for distributed kv data service. - KVSTORE_API static const std::string SERVICE_NAME; - - // root path for distributed kv data service. - KVSTORE_API static const std::string ROOT_PATH; - - // root path for distributeddata service and system services. - KVSTORE_API static const std::string ROOT_PATH_DE; - - // root path for self-developed and non-self-developed app. - KVSTORE_API static const std::string ROOT_PATH_CE; - - // the max length for key is 256. - KVSTORE_API static const size_t MAX_KEY_LENGTH; - - // the max length for value is 1M. - KVSTORE_API static const size_t MAX_VALUE_LENGTH; - - // the max length for StoreId is 64. - KVSTORE_API static const size_t MAX_STORE_ID_LENGTH; - - // the max batch for putBatch is 128. - KVSTORE_API static const size_t MAX_BATCH_SIZE; - - // the max capacity for ipc is 800KB. - KVSTORE_API static const size_t MAX_IPC_CAPACITY; - - // service meta db name. - KVSTORE_API static const std::string SERVICE_META_DB_NAME; - - KVSTORE_API static const std::string KEY_SEPARATOR; - - KVSTORE_API static const mode_t DEFAULT_MODE; - - KVSTORE_API static const mode_t DEFAULT_MODE_DIR; - - KVSTORE_API static const mode_t DEFAULT_MODE_FILE; - - KVSTORE_API static const int SWITCH_RAW_DATA_SIZE; - - KVSTORE_API static const int MAX_OPEN_KVSTORES; - - // name for process label (bus name for communication). compatible with HwDDMP - KVSTORE_API static const std::string ROOT_KEY_GENERATED; -}; - -// trim from start (in place) -template -void Constant::LeftTrim(T &s) -{ - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); })); -} - -// trim from end (in place) -template -void Constant::RightTrim(T &s) -{ - s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end()); -} - -// trim from both ends (in place) -template -void Constant::Trim(T &s) -{ - LeftTrim(s); - RightTrim(s); -} - -// trim from start (copying) -template -T Constant::LeftTrimCopy(T s) -{ - LeftTrim(s); - return s; -} - -// trim from end (copying) -template -T Constant::RightTrimCopy(T s) -{ - RightTrim(s); - return s; -} - -// trim from both ends (copying) -template -T Constant::TrimCopy(T s) -{ - Trim(s); - return s; -} -} // namespace DistributedKv -} // namespace OHOS -#endif // KV_DATASERVICE_CONSTANT_H diff --git a/services/distributeddataservice/adapter/include/autils/directory_utils.h b/services/distributeddataservice/adapter/include/autils/directory_utils.h deleted file mode 100644 index 67ba84dd..00000000 --- a/services/distributeddataservice/adapter/include/autils/directory_utils.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DIRECTORY_UTILS_H -#define DIRECTORY_UTILS_H - -#include -#include -#include "visibility.h" - -namespace OHOS { -namespace DistributedKv { -class DirectoryUtils { -public: - KVSTORE_API static bool ChangeModeFileOnly(const std::string &path, const mode_t &mode); - - KVSTORE_API static bool ChangeModeDirOnly(const std::string &path, const mode_t &mode); - - KVSTORE_API static bool CreateDirectory(const std::string &path); - -private: - DirectoryUtils() = default; - - ~DirectoryUtils() = default; - - static std::string ExcludeDelimiterAtPathTail(const std::string &path); - - static std::string IncludeDelimiterAtPathTail(const std::string &path); - - // change the mode of the specified file or directory. - static inline bool ChangeMode(const std::string &name, const mode_t &mode) - { - return (chmod(name.c_str(), mode) == 0); - } -}; -} // namespace DistributedKv -} // namespace OHOS -#endif // DIRECTORY_UTILS_H diff --git a/services/distributeddataservice/adapter/include/autils/kv_store_task.h b/services/distributeddataservice/adapter/include/autils/kv_store_task.h deleted file mode 100644 index 30891bb0..00000000 --- a/services/distributeddataservice/adapter/include/autils/kv_store_task.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef KV_STORE_TASK_H -#define KV_STORE_TASK_H - -#include -#include -#include "visibility.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreTask { -public: - KVSTORE_API ~KvStoreTask() {} - KVSTORE_API KvStoreTask(std::function lambda); - KVSTORE_API KvStoreTask(std::function lambda, const std::string &taskName); - KVSTORE_API void operator()(); - -private: - std::function task_; - std::string name_; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // TASK_H diff --git a/services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h b/services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h deleted file mode 100644 index 6b908a68..00000000 --- a/services/distributeddataservice/adapter/include/autils/kv_store_thread_pool.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef KV_STORE_THREAD_POOL_H -#define KV_STORE_THREAD_POOL_H - -#include -#include "kv_store_task.h" - -namespace OHOS { -namespace DistributedKv { -class KvStoreThreadPool { -public: - KvStoreThreadPool(KvStoreThreadPool &&) = delete; - KvStoreThreadPool(const KvStoreThreadPool &) = delete; - KvStoreThreadPool &operator=(KvStoreThreadPool &&) = delete; - KvStoreThreadPool &operator=(const KvStoreThreadPool &) = delete; - KVSTORE_API virtual ~KvStoreThreadPool() {} - - KVSTORE_API static std::shared_ptr GetPool( - int poolSize, std::string poolName, bool startImmediately = false); - KVSTORE_API virtual void Stop() = 0; - KVSTORE_API virtual bool AddTask(KvStoreTask &&task) = 0; - KVSTORE_API static constexpr int MAX_POOL_SIZE = 64; // the max thread pool size - KVSTORE_API static constexpr int DEFAULT_POOL_SIZE = 8; // the default thread pool size - std::string GetPoolName(); -protected: - KvStoreThreadPool() = default; - std::string poolName_ = ""; -}; -} // namespace DistributedKv -} // namespace OHOS - -#endif // KV_STORE_THREAD_POOL_H diff --git a/services/distributeddataservice/adapter/include/autils/platform_specific.h b/services/distributeddataservice/adapter/include/autils/platform_specific.h deleted file mode 100644 index 6634dbf4..00000000 --- a/services/distributeddataservice/adapter/include/autils/platform_specific.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PLATFORM_SPECIFIC_H -#define PLATFORM_SPECIFIC_H - -#if defined _WIN32 - #define OS_WINDOWS -#else - #define OS_OHOS -#endif - -#endif // PLATFORM_SPECIFIC_H diff --git a/services/distributeddataservice/adapter/include/autils/time_utils.h b/services/distributeddataservice/adapter/include/autils/time_utils.h deleted file mode 100644 index a67f12f7..00000000 --- a/services/distributeddataservice/adapter/include/autils/time_utils.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef TIME_UTILS_H -#define TIME_UTILS_H - -#include -#include - -namespace OHOS { -namespace DistributedKv { -constexpr int64_t SEC_TO_MICROSEC = 1000000; - -class TimeUtils final { -public: - // micro seconds since 1970 - static inline uint64_t CurrentTimeMicros() - { - struct timeval tv = { 0, 0 }; - gettimeofday(&tv, nullptr); - return (tv.tv_sec * SEC_TO_MICROSEC + tv.tv_usec); - } -}; -} // namespace DistributedKv -} // namespace OHOS -#endif diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 98e78074..5c317362 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -25,7 +25,6 @@ #include "checker/checker_manager.h" #include "communication_provider.h" #include "config_factory.h" -#include "constant.h" #include "crypto_manager.h" #include "device_manager_adapter.h" #include "device_matrix.h" @@ -312,7 +311,7 @@ void KvStoreDataService::StartService() DumpHelper::GetInstance().AddErrorInfo("StartService: Service publish failed."); } // Initialize meta db delegate manager. - KvStoreMetaManager::GetInstance().SubscribeMeta(KvStoreMetaRow::KEY_PREFIX, + KvStoreMetaManager::GetInstance().SubscribeMeta(StoreMetaData::GetKey({}), [this](const std::vector &key, const std::vector &value, CHANGE_FLAG flag) { OnStoreMetaChanged(key, value, flag); }); @@ -671,51 +670,6 @@ void KvStoreDataService::OnDeviceOnReady(const AppDistributedKv::DeviceInfo &inf }); } -bool DbMetaCallbackDelegateMgr::GetKvStoreDiskSize(const std::string &storeId, uint64_t &size) -{ - if (IsDestruct()) { - return false; - } - DistributedDB::DBStatus ret = delegate_->GetKvStoreDiskSize(storeId, size); - return (ret == DistributedDB::DBStatus::OK); -} - -void DbMetaCallbackDelegateMgr::GetKvStoreKeys(std::vector &dbStats) -{ - if (IsDestruct()) { - return; - } - DistributedDB::DBStatus dbStatusTmp; - Option option {.createIfNecessary = true, .isMemoryDb = false, .isEncryptedDb = false}; - DistributedDB::KvStoreNbDelegate *nbDelegate = nullptr; - delegate_->GetKvStore(Bootstrap::GetInstance().GetMetaDBName(), option, - [&nbDelegate, &dbStatusTmp](DistributedDB::DBStatus dbStatus, DistributedDB::KvStoreNbDelegate *delegate) { - nbDelegate = delegate; - dbStatusTmp = dbStatus; - }); - - if (dbStatusTmp != DistributedDB::DBStatus::OK) { - return; - } - DistributedDB::Key dbKey = KvStoreMetaRow::GetKeyFor(""); - std::vector entries; - nbDelegate->GetEntries(dbKey, entries); - if (entries.empty()) { - delegate_->CloseKvStore(nbDelegate); - return; - } - for (auto const &entry : entries) { - std::string key = std::string(entry.key.begin(), entry.key.end()); - std::vector out; - Split(key, Constant::KEY_SEPARATOR, out); - if (out.size() >= VECTOR_SIZE) { - StoreInfo storeInfo = {out[USER_ID], out[APP_ID], out[STORE_ID]}; - dbStats.push_back(std::move(storeInfo)); - } - } - delegate_->CloseKvStore(nbDelegate); -} - int32_t KvStoreDataService::OnUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) { features_.ForEachCopies( diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index cbb4ae01..4a16d21c 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -21,7 +21,6 @@ #include #include "account_delegate.h" -#include "constant.h" #include "dump_helper.h" #include "feature_stub_impl.h" #include "ikvstore_data_service.h" @@ -137,40 +136,5 @@ private: std::shared_ptr deviceInnerListener_; std::shared_ptr executors_; }; - -class DbMetaCallbackDelegateMgr : public DbMetaCallbackDelegate { -public: - using Option = DistributedDB::KvStoreNbDelegate::Option; - virtual ~DbMetaCallbackDelegateMgr() {} - - explicit DbMetaCallbackDelegateMgr(DistributedDB::KvStoreDelegateManager *delegate) - : delegate_(delegate) {} - bool GetKvStoreDiskSize(const std::string &storeId, uint64_t &size) override; - void GetKvStoreKeys(std::vector &dbStats) override; - bool IsDestruct() - { - return delegate_ == nullptr; - } - -private: - void Split(const std::string &str, const std::string &delimiter, std::vector &out) - { - size_t start; - size_t end = 0; - while ((start = str.find_first_not_of(delimiter, end)) != std::string::npos) { - end = str.find(delimiter, start); - if (end == std::string::npos) { - end = str.size(); - } - out.push_back(str.substr(start, end - start)); - } - } - - DistributedDB::KvStoreDelegateManager *delegate_ {}; - static const inline int USER_ID = 0; - static const inline int APP_ID = 1; - static const inline int STORE_ID = 2; - static const inline int VECTOR_SIZE = 2; -}; } #endif // KVSTORE_DATASERVICE_H diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index c281c7a2..960dcad3 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -24,7 +24,6 @@ #include "bootstrap.h" #include "communication_provider.h" #include "communication_strategy.h" -#include "constant.h" #include "crypto_manager.h" #include "device_manager_adapter.h" #include "device_matrix.h" @@ -156,7 +155,7 @@ void KvStoreMetaManager::InitMetaData() data.isEncrypt = false; data.storeType = KvStoreType::SINGLE_VERSION; data.schema = ""; - data.storeId = Constant::SERVICE_META_DB_NAME; + data.storeId = Bootstrap::GetInstance().GetMetaDBName(); data.account = accountId; data.uid = static_cast(uid); data.version = META_STORE_VERSION; diff --git a/services/distributeddataservice/app/src/security/security.cpp b/services/distributeddataservice/app/src/security/security.cpp index 0ff95061..881217ef 100644 --- a/services/distributeddataservice/app/src/security/security.cpp +++ b/services/distributeddataservice/app/src/security/security.cpp @@ -14,11 +14,10 @@ */ #include "security.h" -#include #include +#include #include #include -#include "constant.h" #include "dev_slinfo_mgr.h" #include "device_manager_adapter.h" #include "log_print.h" diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index aaab31bc..d55ad586 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -69,7 +69,6 @@ ohos_shared_library("distributeddatasvc") { "config/src/model/protocol_config.cpp", "crypto/src/crypto_manager.cpp", "kvdb/auth_delegate.cpp", - "kvdb/executor_factory.cpp", "kvdb/kvdb_exporter.cpp", "kvdb/kvdb_service_impl.cpp", "kvdb/kvdb_service_stub.cpp", diff --git a/services/distributeddataservice/service/kvdb/executor_factory.cpp b/services/distributeddataservice/service/kvdb/executor_factory.cpp deleted file mode 100644 index 4d438562..00000000 --- a/services/distributeddataservice/service/kvdb/executor_factory.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -* Copyright (c) 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 "executor_factory.h" - -namespace OHOS::DistributedData { -using namespace OHOS::DistributedKv; -ExecutorFactory &ExecutorFactory::GetInstance() -{ - static ExecutorFactory instance; - return instance; -} - -bool ExecutorFactory::Execute(KvStoreTask &&task) -{ - if (threadPool_ == nullptr) { - return false; - } - threadPool_->AddTask(std::move(task)); - return true; -} - -ExecutorFactory::ExecutorFactory() -{ - threadPool_ = KvStoreThreadPool::GetPool(POOL_SIZE, "Executor", true); -} - -ExecutorFactory::~ExecutorFactory() -{ - if (threadPool_ != nullptr) { - threadPool_->Stop(); - threadPool_ = nullptr; - } -} -} // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/service/kvdb/executor_factory.h b/services/distributeddataservice/service/kvdb/executor_factory.h deleted file mode 100644 index 42d05757..00000000 --- a/services/distributeddataservice/service/kvdb/executor_factory.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -* Copyright (c) 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 DISTRIBUTEDDATAMGR_DATAMGR_EXECUTOR_FACTORY_H -#define DISTRIBUTEDDATAMGR_DATAMGR_EXECUTOR_FACTORY_H - -#include "kv_store_thread_pool.h" -namespace OHOS::DistributedData { -using OHOS::DistributedKv::KvStoreTask; -using OHOS::DistributedKv::KvStoreThreadPool; -class ExecutorFactory { -public: - API_EXPORT static ExecutorFactory &GetInstance(); - API_EXPORT bool Execute(KvStoreTask &&task); - -private: - ExecutorFactory(); - ~ExecutorFactory(); - - static constexpr int POOL_SIZE = 4; - - std::shared_ptr threadPool_; -}; -} // namespace OHOS::DistributedData -#endif // DISTRIBUTEDDATAMGR_DATAMGR_EXECUTOR_FACTORY_H -- Gitee From 0b4ccc291b5d0e93d9489903b618550e21211c0d Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 15:18:18 +0800 Subject: [PATCH 221/437] remove the a utils Signed-off-by: Sven Wang --- services/distributeddataservice/adapter/BUILD.gn | 1 - services/distributeddataservice/adapter/dfx/BUILD.gn | 1 - services/distributeddataservice/adapter/dfx/test/BUILD.gn | 2 -- 3 files changed, 4 deletions(-) diff --git a/services/distributeddataservice/adapter/BUILD.gn b/services/distributeddataservice/adapter/BUILD.gn index caf33746..515866a6 100644 --- a/services/distributeddataservice/adapter/BUILD.gn +++ b/services/distributeddataservice/adapter/BUILD.gn @@ -45,7 +45,6 @@ ohos_shared_library("distributeddata_adapter") { configs = [ ":distributeddata_adapter_private_config" ] deps = [ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/account:distributeddata_account_static", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/autils:distributeddata_autils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/communicator:distributeddata_communicator_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/dfx:distributeddata_dfx_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/permission:distributeddata_permission_static", diff --git a/services/distributeddataservice/adapter/dfx/BUILD.gn b/services/distributeddataservice/adapter/dfx/BUILD.gn index c137b61f..c6938ff3 100644 --- a/services/distributeddataservice/adapter/dfx/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/BUILD.gn @@ -42,7 +42,6 @@ ohos_static_library("distributeddata_dfx_static") { cflags_cc = [ "-fvisibility=hidden" ] deps = [ - "../autils:distributeddata_autils_static", "//third_party/openssl:libcrypto_shared", ] external_deps = [ diff --git a/services/distributeddataservice/adapter/dfx/test/BUILD.gn b/services/distributeddataservice/adapter/dfx/test/BUILD.gn index 0c2a6050..4b4df71f 100755 --- a/services/distributeddataservice/adapter/dfx/test/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/test/BUILD.gn @@ -47,7 +47,6 @@ ohos_unittest("DistributeddataDfxMSTTest") { ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ - "../../autils:distributeddata_autils_static", "../../dfx:distributeddata_dfx_static", "//third_party/googletest:gtest_main", "//third_party/openssl:libcrypto_shared", @@ -106,7 +105,6 @@ ohos_unittest("DistributeddataDfxUTTest") { ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ - "../../autils:distributeddata_autils_static", "//third_party/googletest:gtest_main", "//third_party/openssl:libcrypto_shared", ] -- Gitee From f9350fdcb860c297de00ee8d7f78bbdb230d9d38 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 19:37:23 +0800 Subject: [PATCH 222/437] update Signed-off-by: Sven Wang --- datamgr_service.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamgr_service.gni b/datamgr_service.gni index 7ef3974e..3a7b7e96 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -46,5 +46,5 @@ declare_args() { os_account_part_is_enabled = false } - datamgr_service_config = true; + datamgr_service_config = true } -- Gitee From f2d87f58ec080652462acbf70be3c88c9c2bbb72 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Tue, 13 Jun 2023 20:05:45 +0800 Subject: [PATCH 223/437] del mock Signed-off-by: zuojiangjiang --- .../service/rdb/rdb_general_store.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index bda01958..1d24fb42 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -190,17 +190,6 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu : (mode > NEARBY_END && mode < CLOUD_END) ? delegate_->Sync(devices, dbMode, dbQuery, GetDBProcessCB(std::move(async)), wait) : DistributedDB::INVALID_ARGS; - // mock - if (observer_.HasWatcher()) { - Watcher::Origin origin; - origin.origin = (mode < NEARBY_END) ? Watcher::Origin::ORIGIN_NEARBY - : (mode > NEARBY_END && mode < CLOUD_END) - ? Watcher::Origin::ORIGIN_CLOUD - : Watcher::Origin::ORIGIN_BUTT; - origin.id = devices; - origin.store = observer_.storeId_; - observer_.watcher_->OnChange(origin, {}, {}); - } return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } -- Gitee From a6d6d831f1d1fcedac93722a73a58f49ec9ddc7f Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Tue, 13 Jun 2023 21:37:31 +0800 Subject: [PATCH 224/437] fixed the bugs Signed-off-by: Sven Wang --- conf/BUILD.gn | 1 + .../adapter/account/src/account_delegate_impl.cpp | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/conf/BUILD.gn b/conf/BUILD.gn index 14f7ca2c..330b9f2e 100644 --- a/conf/BUILD.gn +++ b/conf/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") import("//build/ohos_var.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") #/system/etc/distributeddata/conf group("build_module") { diff --git a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp index 7284cca5..875a2ca3 100644 --- a/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp +++ b/services/distributeddataservice/adapter/account/src/account_delegate_impl.cpp @@ -16,11 +16,8 @@ #define LOG_TAG "EVENT_HANDLER" #include "account_delegate_impl.h" -#include #include #include -#include -#include "constant.h" namespace OHOS { namespace DistributedKv { -- Gitee From 03d383cc92467fb3a1ff68153f72a9451b7e84f8 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 14 Jun 2023 09:30:02 +0800 Subject: [PATCH 225/437] remove a utils test Signed-off-by: Sven Wang --- services/distributeddataservice/adapter/test/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/adapter/test/BUILD.gn b/services/distributeddataservice/adapter/test/BUILD.gn index b716360d..206f581e 100755 --- a/services/distributeddataservice/adapter/test/BUILD.gn +++ b/services/distributeddataservice/adapter/test/BUILD.gn @@ -19,7 +19,6 @@ group("unittest") { deps += [ "../account/test:unittest", - "../autils/test:unittest", "../communicator/test:unittest", "../dfx/test:unittest", "../permission/test:unittest", -- Gitee From 8d5d7e514b42e802f124f417d0480c248f7f2efe Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 14 Jun 2023 10:10:28 +0800 Subject: [PATCH 226/437] fixed format bugs Signed-off-by: Sven Wang --- services/distributeddataservice/adapter/dfx/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/distributeddataservice/adapter/dfx/BUILD.gn b/services/distributeddataservice/adapter/dfx/BUILD.gn index c6938ff3..2818cae4 100644 --- a/services/distributeddataservice/adapter/dfx/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/BUILD.gn @@ -41,9 +41,7 @@ ohos_static_library("distributeddata_dfx_static") { cflags_cc = [ "-fvisibility=hidden" ] - deps = [ - "//third_party/openssl:libcrypto_shared", - ] + deps = [ "//third_party/openssl:libcrypto_shared" ] external_deps = [ "c_utils:utils", "hisysevent_native:libhisysevent", -- Gitee From 8c70f7884e9b9506f3fd87f85feeb0d80cb8361d Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 14 Jun 2023 14:00:00 +0800 Subject: [PATCH 227/437] fix:fix bug Signed-off-by: htt1997 --- .../distributeddataservice/service/rdb/rdb_service_impl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 3bf671e4..f0fa85c8 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -431,7 +431,9 @@ void RdbServiceImpl::SyncAgent::SetWatcher(std::shared_ptr watcher) { if (watcher_ != watcher) { watcher_ = watcher; - watcher_->SetNotifier(notifier_); + if (watcher_ != nullptr) { + watcher_->SetNotifier(notifier_); + } } } -- Gitee From d698371d13f43ef7399155297aa293680451ae66 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Wed, 14 Jun 2023 15:09:51 +0800 Subject: [PATCH 228/437] fix Signed-off-by: niudongyao --- .../service/data_share/common/db_delegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.h b/services/distributeddataservice/service/data_share/common/db_delegate.h index b649c1a3..ed0727e1 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.h +++ b/services/distributeddataservice/service/data_share/common/db_delegate.h @@ -30,7 +30,7 @@ namespace OHOS::DataShare { class DBDelegate { public: - static std::shared_ptr Create(const std::string &dir, int version, bool registerFunction = false); + static std::shared_ptr Create(const std::string &dir, int version, bool registerFunction = true); virtual int64_t Insert(const std::string &tableName, const DataShareValuesBucket &valuesBucket) = 0; virtual int64_t Update(const std::string &tableName, const DataSharePredicates &predicate, const DataShareValuesBucket &valuesBucket) = 0; -- Gitee From 78ad7f98a8788b6a196c19ff0f22fd0f101d0255 Mon Sep 17 00:00:00 2001 From: Sven Wang Date: Wed, 14 Jun 2023 16:04:05 +0800 Subject: [PATCH 229/437] remove time utils Signed-off-by: Sven Wang --- .../app/test/unittest/kvstore_flowctrl_manager_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp b/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp index e2e662be..506f32c1 100644 --- a/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp +++ b/services/distributeddataservice/app/test/unittest/kvstore_flowctrl_manager_test.cpp @@ -18,11 +18,11 @@ #include "flowctrl_manager/kvstore_flowctrl_manager.h" #include #include -#include "time_utils.h" - +#include using namespace testing::ext; using namespace OHOS::DistributedKv; using namespace OHOS; +using namespace std::chrono; class KvStoreFlowCtrlManagerTest : public testing::Test { public: @@ -152,11 +152,11 @@ HWTEST_F(KvStoreFlowCtrlManagerTest, KvStoreFlowCtrlManagerTest006, TestSize.Lev auto ptr = std::make_shared(OPERATION_BURST_CAPACITY, OPERATION_SUSTAINED_CAPACITY); int arr[2] = {0, 0}; uint64_t curTime = 0; - uint64_t lastTime = TimeUtils::CurrentTimeMicros(); + uint64_t lastTime = duration_cast(steady_clock::now().time_since_epoch()).count(); for (int i = 0; i < 10001; i++) { arr[ptr->IsTokenEnough()]++; while (true) { - curTime = TimeUtils::CurrentTimeMicros(); + curTime = duration_cast(steady_clock::now().time_since_epoch()).count(); if ((curTime - lastTime) > 1000) { lastTime = curTime; break; -- Gitee From e90aaff2f7b266986e0dee37242f3c3f095fb52d Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 14 Jun 2023 20:21:57 +0800 Subject: [PATCH 230/437] f Signed-off-by: hanlu --- .../service/data_share/common/kv_delegate.cpp | 4 +++- .../service/data_share/common/template_manager.cpp | 2 +- .../service/data_share/data/published_data.cpp | 2 +- .../service/data_share/data/published_data.h | 4 ++-- .../service/data_share/data/template_data.cpp | 4 ++-- .../service/data_share/data/template_data.h | 2 +- .../service/data_share/data_share_service_impl.cpp | 4 +++- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index 5a77b1ed..d0736685 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -62,7 +62,9 @@ int32_t KvDelegate::Delete(const std::string &collectionName, const std::string } } Flush(); - ZLOGI("Delete, %{public}s, count %{public}zu", collectionName.c_str(), queryResults.size()); + if (queryResults.size() > 0) { + ZLOGI("Delete, %{public}s, count %{public}zu", collectionName.c_str(), queryResults.size()); + } return E_OK; } diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/common/template_manager.cpp index 5f6f6c98..a61c4ea5 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/template_manager.cpp @@ -430,7 +430,7 @@ void PublishedDataSubscriberManager::Emit(const std::vector &k { int32_t status; // key is bundleName, value is change node - std::map, std::string>> publishedResult; + std::map publishedResult; std::map, std::vector> callbacks; publishedDataCache.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, &userId, this]( const PublishedDataKey &key, std::vector &val) { diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 79c7ef51..3cfa9be8 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -103,7 +103,7 @@ PublishedDataNode::PublishedDataNode(const std::string &key, const std::string & PublishedDataNode::PublishedDataNode() : VersionData(-1) {} -int32_t PublishedData::Query(const std::string &filter, std::variant, std::string> &publishedData) +int32_t PublishedData::Query(const std::string &filter, std::variant, std::string> &publishedData) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index 22042b1c..50a5aede 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -22,7 +22,7 @@ namespace OHOS::DataShare { class PublishedDataNode final : public VersionData { public: - using Data = std::variant, std::string>; + using Data = std::variant, std::string>; PublishedDataNode(); PublishedDataNode(const std::string &key, const std::string &bundleName, int64_t subscriberId, const int32_t userId, const Data &value); @@ -43,7 +43,7 @@ public: static std::vector Query(const std::string &bundleName, int32_t userId); static void Delete(const std::string &bundleName, const int32_t userId); static void ClearAging(); - static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); + static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); PublishedData(const PublishedDataNode &node, const int version); ~PublishedData() = default; diff --git a/services/distributeddataservice/service/data_share/data/template_data.cpp b/services/distributeddataservice/service/data_share/data/template_data.cpp index 4b155b84..4236f4d7 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.cpp +++ b/services/distributeddataservice/service/data_share/data/template_data.cpp @@ -136,14 +136,14 @@ bool TemplateData::Delete(const std::string &bundleName, const int32_t userId) } bool TemplateData::Add(const std::string &uri, const int32_t userId, const std::string &bundleName, - const int64_t subsciriberId, const Template &aTemplate) + const int64_t subscriberId, const Template &aTemplate) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { ZLOGE("db open failed"); return false; } - TemplateData data(uri, bundleName, subsciriberId, userId, aTemplate); + TemplateData data(uri, bundleName, subscriberId, userId, aTemplate); auto status = delegate->Upsert(KvDBDelegate::TEMPLATE_TABLE, data); if (status != E_OK) { ZLOGE("db Upsert failed, %{public}d", status); diff --git a/services/distributeddataservice/service/data_share/data/template_data.h b/services/distributeddataservice/service/data_share/data/template_data.h index f7f9e153..06b482b5 100644 --- a/services/distributeddataservice/service/data_share/data/template_data.h +++ b/services/distributeddataservice/service/data_share/data/template_data.h @@ -62,7 +62,7 @@ struct TemplateData final : public KvData { static std::string GenId(const std::string &uri, const std::string &bundleName, int64_t subscriberId); static bool Delete(const std::string &bundleName, const int32_t userId); static bool Add(const std::string &uri, const int32_t userId, const std::string &bundleName, - const int64_t subsciriberId, const Template &aTemplate); + const int64_t subscriberId, const Template &aTemplate); static bool Delete( const std::string &uri, const int32_t userId, const std::string &bundleName, const int64_t subscriberId); bool HasVersion() const override; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index fa58cb8c..9576aee5 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -121,8 +121,10 @@ int32_t DataShareServiceImpl::AddTemplate(const std::string &uri, const int64_t return ERROR; } return templateStrategy_.Execute(context, [&uri, &tpltId, &tplt, &context]() -> int32_t { - return TemplateManager::GetInstance().Add( + auto result = TemplateManager::GetInstance().Add( Key(uri, tpltId.subscriberId_, tpltId.bundleName_), context->currentUserId, tplt); + RdbSubscriberManager::GetInstance().Emit(context->uri, context); + return result; }); } -- Gitee From 7703e5f75257ff0c65aa5a46167bc4406629cebf Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 15 Jun 2023 15:32:47 +0800 Subject: [PATCH 231/437] f Signed-off-by: hanlu --- .../data/resultset_json_formatter.cpp | 65 ++++++++++++++++--- .../data/resultset_json_formatter.h | 1 + 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp index 931a4d54..fc354984 100644 --- a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp +++ b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp @@ -15,8 +15,8 @@ #define LOG_TAG "ResultSetJsonFormatter" #include "resultset_json_formatter.h" -#include "rdb_errno.h" #include "log_print.h" +#include "rdb_errno.h" namespace OHOS::DataShare { bool ResultSetJsonFormatter::Marshal(json &node) const @@ -28,15 +28,10 @@ bool ResultSetJsonFormatter::Marshal(json &node) const return false; } while (resultSet->GoToNextRow() == NativeRdb::E_OK) { - json result; - for (int i = 0; i < columnCount; i++) { - std::string columnName; - std::string value; - resultSet->GetColumnName(i, columnName); - resultSet->GetString(i, value); - SetValue(result[columnName], value); + if (!MarshalRow(node, columnCount)) { + ZLOGE("MarshalRow err"); + return false; } - node.push_back(result); } return true; } @@ -45,4 +40,56 @@ bool ResultSetJsonFormatter::Unmarshal(const DistributedData::Serializable::json { return false; } + +bool ResultSetJsonFormatter::MarshalRow(DistributedData::Serializable::json &node, int columnCount) const +{ + using namespace NativeRdb; + json result; + std::string columnName; + std::string value; + NativeRdb::ColumnType type; + for (int i = 0; i < columnCount; i++) { + if (resultSet->GetColumnType(i, type) != E_OK) { + ZLOGE("GetColumnType err %{public}d", i); + return false; + } + if (resultSet->GetColumnName(i, columnName) != E_OK) { + ZLOGE("GetColumnName err %{public}d", i); + return false; + } + switch (type) { + case ColumnType::TYPE_INTEGER: + int64_t value; + resultSet->GetLong(i, value); + SetValue(result[columnName], value); + break; + case ColumnType::TYPE_FLOAT: + double dValue; + resultSet->GetDouble(i, dValue); + SetValue(result[columnName], value); + break; + case ColumnType::TYPE_NULL: + result[columnName] = nullptr; + break; + case ColumnType::TYPE_STRING: { + std::string stringValue; + resultSet->GetString(i, stringValue); + SetValue(result[columnName], stringValue); + break; + } + case ColumnType::TYPE_BLOB: { + std::vector blobValue; + resultSet->GetBlob(i, blobValue); + SetValue(result[columnName], blobValue); + break; + } + default: + ZLOGE("unknow type %{public}d", type); + } + resultSet->GetString(i, value); + SetValue(result[columnName], value); + } + node.push_back(result); + return true; +} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.h b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.h index 0dfcabdf..2903aeee 100644 --- a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.h +++ b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.h @@ -29,6 +29,7 @@ public: bool Unmarshal(const json &node) override; private: + bool MarshalRow(json &node, int columnCount) const; std::shared_ptr resultSet; }; } // namespace OHOS::DataShare -- Gitee From 00897caf39c3beff0a2b5eed4f6d0a5894b64776 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 16 Jun 2023 11:41:56 +0800 Subject: [PATCH 232/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 3 +- .../data_share/common/scheduler_manager.h | 2 +- .../data/resultset_json_formatter.cpp | 6 +- .../data_share/data_share_service_impl.cpp | 4 +- .../published_data_subscriber_manager.cpp | 241 ++++++++++++++++++ .../published_data_subscriber_manager.h | 88 +++++++ .../rdb_subscriber_manager.cpp} | 229 +---------------- .../rdb_subscriber_manager.h} | 67 +---- 8 files changed, 346 insertions(+), 294 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp create mode 100644 services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h rename services/distributeddataservice/service/data_share/{common/template_manager.cpp => subscriber_managers/rdb_subscriber_manager.cpp} (56%) rename services/distributeddataservice/service/data_share/{common/template_manager.h => subscriber_managers/rdb_subscriber_manager.h} (53%) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index ef8085a0..2d8ffad4 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -44,7 +44,6 @@ ohos_shared_library("data_share_service") { "common/rdb_delegate.cpp", "common/scheduler_manager.cpp", "common/seq_strategy.cpp", - "common/template_manager.cpp", "common/uri_utils.cpp", "data/published_data.cpp", "data/resultset_json_formatter.cpp", @@ -72,6 +71,8 @@ ohos_shared_library("data_share_service") { "strategies/subscribe_strategy.cpp", "strategies/template_strategy.cpp", "strategies/update_strategy.cpp", + "subscriber_managers/published_data_subscriber_manager.cpp", + "subscriber_managers/rdb_subscriber_manager.cpp", ] cflags = [ "-Wno-multichar" ] diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.h b/services/distributeddataservice/service/data_share/common/scheduler_manager.h index b4ea4580..d133218a 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.h +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.h @@ -20,7 +20,7 @@ #include "db_delegate.h" #include "executor_pool.h" -#include "template_manager.h" +#include "subscriber_managers/rdb_subscriber_manager.h" namespace OHOS::DataShare { class SchedulerManager { diff --git a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp index fc354984..75b096a2 100644 --- a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp +++ b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp @@ -46,7 +46,6 @@ bool ResultSetJsonFormatter::MarshalRow(DistributedData::Serializable::json &nod using namespace NativeRdb; json result; std::string columnName; - std::string value; NativeRdb::ColumnType type; for (int i = 0; i < columnCount; i++) { if (resultSet->GetColumnType(i, type) != E_OK) { @@ -66,7 +65,7 @@ bool ResultSetJsonFormatter::MarshalRow(DistributedData::Serializable::json &nod case ColumnType::TYPE_FLOAT: double dValue; resultSet->GetDouble(i, dValue); - SetValue(result[columnName], value); + SetValue(result[columnName], dValue); break; case ColumnType::TYPE_NULL: result[columnName] = nullptr; @@ -85,9 +84,8 @@ bool ResultSetJsonFormatter::MarshalRow(DistributedData::Serializable::json &nod } default: ZLOGE("unknow type %{public}d", type); + return false; } - resultSet->GetString(i, value); - SetValue(result[columnName], value); } node.push_back(result); return true; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 9576aee5..d91ae2dd 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -28,7 +28,7 @@ #include "ipc_skeleton.h" #include "log_print.h" #include "scheduler_manager.h" -#include "template_manager.h" +#include "subscriber_managers/published_data_subscriber_manager.h" #include "utils/anonymous.h" #include "template_data.h" @@ -182,7 +182,7 @@ std::vector DataShareServiceImpl::Publish(const Data &data, con ZLOGE("publish error, key is %{public}s", DistributedData::Anonymous::Change(item.key_).c_str()); continue; } - publishedData.emplace_back(context->uri, callerBundleName, item.subscriberId_); + publishedData.emplace_back(context->uri, context->calledBundleName, item.subscriberId_); userId = context->currentUserId; } if (!publishedData.empty()) { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp new file mode 100644 index 00000000..37bdd915 --- /dev/null +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -0,0 +1,241 @@ +/* + * 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. + */ +#define LOG_TAG "PublishedDataSubscriberManager" + +#include "published_data_subscriber_manager.h" + +#include "general/load_config_data_info_strategy.h" +#include "log_print.h" +#include "published_data.h" +#include "uri_utils.h" +#include "utils/anonymous.h" + +namespace OHOS::DataShare { +PublishedDataSubscriberManager &PublishedDataSubscriberManager::GetInstance() +{ + static PublishedDataSubscriberManager manager; + return manager; +} + +void PublishedDataSubscriberManager::LinkToDeath( + const PublishedDataKey &key, sptr observer) +{ + sptr deathRecipient = new (std::nothrow) ObserverNodeRecipient(this, key, observer); + if (deathRecipient == nullptr) { + ZLOGE("new ObserverNodeRecipient error. uri is %{public}s", + DistributedData::Anonymous::Change(key.key).c_str()); + return; + } + auto remote = observer->AsObject(); + if (!remote->AddDeathRecipient(deathRecipient)) { + ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); + return; + } + ZLOGD("link to death success, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); +} + +void PublishedDataSubscriberManager::OnRemoteDied( + const PublishedDataKey &key, sptr observer) +{ + publishedDataCache.ComputeIfPresent(key, [&observer, this](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); ++it) { + if (it->observer->AsObject() == observer->AsObject()) { + value.erase(it); + ZLOGI("OnRemoteDied delete subscriber, uri is %{public}s", + DistributedData::Anonymous::Change(key.key).c_str()); + break; + } + } + return !value.empty(); + }); +} +int PublishedDataSubscriberManager::Add( + const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId) +{ + publishedDataCache.Compute( + key, [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { + ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); + LinkToDeath(key, observer); + value.emplace_back(observer, callerTokenId); + return true; + }); + return E_OK; +} + +int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, const uint32_t callerTokenId) +{ + auto result = + publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end();) { + if (it->callerTokenId == callerTokenId) { + it = value.erase(it); + } else { + it++; + } + } + return !value.empty(); + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, const uint32_t callerTokenId) +{ + auto result = + publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + if (it->callerTokenId == callerTokenId) { + it->enabled = false; + } + } + return true; + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +int PublishedDataSubscriberManager::Enable(const PublishedDataKey &key, const uint32_t callerTokenId) +{ + auto result = + publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + if (it->callerTokenId == callerTokenId) { + it->enabled = true; + } + } + return true; + }); + return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; +} + +void PublishedDataSubscriberManager::Emit(const std::vector &keys, const int32_t userId, + const std::string &ownerBundleName, const sptr observer) +{ + int32_t status; + // key is bundleName, value is change node + std::map publishedResult; + std::map, std::vector> callbacks; + publishedDataCache.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, &userId, this]( + const PublishedDataKey &key, std::vector &val) { + for (auto &data : keys) { + if (key != data || publishedResult.count(key) != 0) { + continue; + } + status = PublishedData::Query( + Id(PublishedData::GenId(key.key, key.bundleName, key.subscriberId), userId), publishedResult[key]); + if (status != E_OK) { + ZLOGE("query fail %{public}s %{public}s %{public}" PRId64, data.bundleName.c_str(), data.key.c_str(), + data.subscriberId); + publishedResult.erase(key); + continue; + } + PutInto(callbacks, val, key, observer); + break; + } + return false; + }); + PublishedDataChangeNode result; + for (auto &[callback, keys] : callbacks) { + result.datas_.clear(); + for (auto &key : keys) { + if (publishedResult.count(key) != 0) { + result.datas_.emplace_back(key.key, key.subscriberId, publishedResult[key]); + } + } + if (result.datas_.empty()) { + continue; + } + result.ownerBundleName_ = ownerBundleName; + callback->OnChangeFromPublishedData(result); + } +} + +void PublishedDataSubscriberManager::PutInto( + std::map, std::vector> &callbacks, + const std::vector &val, const PublishedDataKey &key, + const sptr observer) +{ + for (auto const &callback : val) { + if (callback.enabled && callback.observer != nullptr) { + // callback the observer, others do not call + if (observer != nullptr && callback.observer != observer) { + continue; + } + callbacks[callback.observer].emplace_back(key); + } + } +} +void PublishedDataSubscriberManager::Clear() +{ + publishedDataCache.Clear(); +} + +PublishedDataKey::PublishedDataKey(const std::string &key, const std::string &bundle, const int64_t subscriberId) + : key(key), bundleName(bundle), subscriberId(subscriberId) +{ + /* private published data can use key as simple uri */ + /* etc: datashareproxy://{bundleName}/meeting can use meeting replaced */ + /* if key is normal uri, bundleName is from uri */ + if (URIUtils::IsDataProxyURI(key)) { + URIUtils::GetBundleNameFromProxyURI(key, bundleName); + } +} + +bool PublishedDataKey::operator<(const PublishedDataKey &rhs) const +{ + if (key < rhs.key) { + return true; + } + if (rhs.key < key) { + return false; + } + if (bundleName < rhs.bundleName) { + return true; + } + if (rhs.bundleName < bundleName) { + return false; + } + return subscriberId < rhs.subscriberId; +} + +bool PublishedDataKey::operator>(const PublishedDataKey &rhs) const +{ + return rhs < *this; +} + +bool PublishedDataKey::operator<=(const PublishedDataKey &rhs) const +{ + return !(rhs < *this); +} + +bool PublishedDataKey::operator>=(const PublishedDataKey &rhs) const +{ + return !(*this < rhs); +} + +bool PublishedDataKey::operator==(const PublishedDataKey &rhs) const +{ + return key == rhs.key && bundleName == rhs.bundleName && subscriberId == rhs.subscriberId; +} + +bool PublishedDataKey::operator!=(const PublishedDataKey &rhs) const +{ + return !(rhs == *this); +} + +PublishedDataSubscriberManager::ObserverNode::ObserverNode( + const sptr &observer, uint32_t callerTokenId) + : observer(observer), callerTokenId(callerTokenId) +{ +} +} // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h new file mode 100644 index 00000000..d2326ac9 --- /dev/null +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -0,0 +1,88 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_PUBLISHED_DATA_SUBSCRIBER_MANAGER_H +#define DATASHARESERVICE_PUBLISHED_DATA_SUBSCRIBER_MANAGER_H + +#include +#include + +#include "concurrent_map.h" +#include "context.h" +#include "data_proxy_observer.h" +#include "datashare_template.h" +#include "executor_pool.h" +namespace OHOS::DataShare { +struct PublishedDataKey { + PublishedDataKey(const std::string &key, const std::string &bundleName, const int64_t subscriberId); + bool operator<(const PublishedDataKey &rhs) const; + bool operator>(const PublishedDataKey &rhs) const; + bool operator<=(const PublishedDataKey &rhs) const; + bool operator>=(const PublishedDataKey &rhs) const; + bool operator==(const PublishedDataKey &rhs) const; + bool operator!=(const PublishedDataKey &rhs) const; + std::string key; + std::string bundleName; + int64_t subscriberId; +}; + +class PublishedDataSubscriberManager { +public: + static PublishedDataSubscriberManager &GetInstance(); + int Add(const PublishedDataKey &key, const sptr observer, + const uint32_t callerTokenId); + int Delete(const PublishedDataKey &key, const uint32_t callerTokenId); + int Disable(const PublishedDataKey &key, const uint32_t callerTokenId); + int Enable(const PublishedDataKey &key, const uint32_t callerTokenId); + void Emit(const std::vector &keys, const int32_t userId, const std::string &ownerBundleName, + const sptr observer = nullptr); + void Clear(); + +private: + struct ObserverNode { + ObserverNode(const sptr &observer, uint32_t callerTokenId); + sptr observer; + uint32_t callerTokenId; + bool enabled = true; + }; + class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { + public: + ObserverNodeRecipient(PublishedDataSubscriberManager *owner, const PublishedDataKey &key, + sptr observer) + : owner_(owner), key_(key), observer_(observer){}; + + void OnRemoteDied(const wptr &object) override + { + if (owner_ != nullptr) { + owner_->OnRemoteDied(key_, observer_); + } + } + + private: + PublishedDataSubscriberManager *owner_; + PublishedDataKey key_; + sptr observer_; + }; + + void LinkToDeath(const PublishedDataKey &key, sptr observer); + void OnRemoteDied(const PublishedDataKey &key, sptr observer); + + PublishedDataSubscriberManager() = default; + void PutInto(std::map, std::vector> &, + const std::vector &, const PublishedDataKey &, const sptr); + ConcurrentMap> publishedDataCache; +}; +} // namespace OHOS::DataShare +#endif diff --git a/services/distributeddataservice/service/data_share/common/template_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp similarity index 56% rename from services/distributeddataservice/service/data_share/common/template_manager.cpp rename to services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index a61c4ea5..326551a0 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -12,14 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "TemplateManager" +#define LOG_TAG "RdbSubscriberManager" -#include "template_manager.h" +#include "rdb_subscriber_manager.h" #include "general/load_config_data_info_strategy.h" - #include "log_print.h" -#include "published_data.h" #include "scheduler_manager.h" #include "template_data.h" #include "uri_utils.h" @@ -28,8 +26,7 @@ namespace OHOS::DataShare { bool TemplateManager::Get(const Key &key, const int32_t userId, Template &tpl) { - return TemplateData::Query(Id(TemplateData::GenId(key.uri, key.bundleName, key.subscriberId), userId), - tpl) == E_OK; + return TemplateData::Query(Id(TemplateData::GenId(key.uri, key.bundleName, key.subscriberId), userId), tpl) == E_OK; } int32_t TemplateManager::Add(const Key &key, const int32_t userId, const Template &tpl) @@ -115,7 +112,7 @@ void RdbSubscriberManager::LinkToDeath(const Key &key, sptr deathRecipient = new (std::nothrow) ObserverNodeRecipient(this, key, observer); if (deathRecipient == nullptr) { ZLOGE("new ObserverNodeRecipient error, uri is %{public}s", - DistributedData::Anonymous::Change(key.uri).c_str()); + DistributedData::Anonymous::Change(key.uri).c_str()); return; } auto remote = observer->AsObject(); @@ -312,7 +309,7 @@ int RdbSubscriberManager::Notify(const Key &key, const int32_t userId, const std changeNode.templateId_.subscriberId_ = key.subscriberId; changeNode.templateId_.bundleName_ = key.bundleName; for (const auto &predicate : tpl.predicates_) { - std::string result = delegate->Query(predicate.selectSql_); + std::string result = delegate->Query(predicate.selectSql_); changeNode.data_.emplace_back("{\"" + predicate.key_ + "\":" + result + "}"); } @@ -330,224 +327,8 @@ void RdbSubscriberManager::Clear() rdbCache_.Clear(); } -PublishedDataSubscriberManager &PublishedDataSubscriberManager::GetInstance() -{ - static PublishedDataSubscriberManager manager; - return manager; -} - -void PublishedDataSubscriberManager::LinkToDeath(const PublishedDataKey &key, - sptr observer) -{ - sptr deathRecipient = new (std::nothrow) ObserverNodeRecipient(this, key, observer); - if (deathRecipient == nullptr) { - ZLOGE("new ObserverNodeRecipient error. uri is %{public}s", - DistributedData::Anonymous::Change(key.key).c_str()); - return; - } - auto remote = observer->AsObject(); - if (!remote->AddDeathRecipient(deathRecipient)) { - ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); - return; - } - ZLOGD("link to death success, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); -} - -void PublishedDataSubscriberManager::OnRemoteDied(const PublishedDataKey &key, - sptr observer) -{ - publishedDataCache.ComputeIfPresent(key, [&observer, this](const auto &key, std::vector &value) { - for (auto it = value.begin(); it != value.end(); ++it) { - if (it->observer->AsObject() == observer->AsObject()) { - value.erase(it); - ZLOGI("OnRemoteDied delete subscriber, uri is %{public}s", - DistributedData::Anonymous::Change(key.key).c_str()); - break; - } - } - return !value.empty(); - }); -} -int PublishedDataSubscriberManager::Add( - const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId) -{ - publishedDataCache.Compute(key, - [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { - ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); - LinkToDeath(key, observer); - value.emplace_back(observer, callerTokenId); - return true; - }); - return E_OK; -} - -int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, const uint32_t callerTokenId) -{ - auto result = - publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { - for (auto it = value.begin(); it != value.end();) { - if (it->callerTokenId == callerTokenId) { - it = value.erase(it); - } else { - it++; - } - } - return !value.empty(); - }); - return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; -} - -int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, const uint32_t callerTokenId) -{ - auto result = - publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { - for (auto it = value.begin(); it != value.end(); it++) { - if (it->callerTokenId == callerTokenId) { - it->enabled = false; - } - } - return true; - }); - return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; -} - -int PublishedDataSubscriberManager::Enable(const PublishedDataKey &key, const uint32_t callerTokenId) -{ - auto result = - publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { - for (auto it = value.begin(); it != value.end(); it++) { - if (it->callerTokenId == callerTokenId) { - it->enabled = true; - } - } - return true; - }); - return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; -} - -void PublishedDataSubscriberManager::Emit(const std::vector &keys, const int32_t userId, - const std::string &ownerBundleName, const sptr observer) -{ - int32_t status; - // key is bundleName, value is change node - std::map publishedResult; - std::map, std::vector> callbacks; - publishedDataCache.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, &userId, this]( - const PublishedDataKey &key, std::vector &val) { - for (auto &data : keys) { - if (key != data || publishedResult.count(key) != 0) { - continue; - } - status = PublishedData::Query( - Id(PublishedData::GenId(key.key, key.bundleName, key.subscriberId), userId), publishedResult[key]); - if (status != E_OK) { - ZLOGE("query fail %{public}s %{public}s %{public}" PRId64, data.bundleName.c_str(), data.key.c_str(), - data.subscriberId); - publishedResult.erase(key); - continue; - } - PutInto(callbacks, val, key, observer); - break; - } - return false; - }); - PublishedDataChangeNode result; - for (auto &[callback, keys] : callbacks) { - result.datas_.clear(); - for (auto &key : keys) { - if (publishedResult.count(key) != 0) { - result.datas_.emplace_back(key.key, key.subscriberId, publishedResult[key]); - } - } - if (result.datas_.empty()) { - continue; - } - result.ownerBundleName_ = ownerBundleName; - callback->OnChangeFromPublishedData(result); - } -} - -void PublishedDataSubscriberManager::PutInto( - std::map, std::vector> &callbacks, - const std::vector &val, const PublishedDataKey &key, - const sptr observer) -{ - for (auto const &callback : val) { - if (callback.enabled && callback.observer != nullptr) { - // callback the observer, others do not call - if (observer != nullptr && callback.observer != observer) { - continue; - } - callbacks[callback.observer].emplace_back(key); - } - } -} -void PublishedDataSubscriberManager::Clear() -{ - publishedDataCache.Clear(); -} - -PublishedDataKey::PublishedDataKey(const std::string &key, const std::string &bundle, const int64_t subscriberId) - : key(key), bundleName(bundle), subscriberId(subscriberId) -{ - /* private published data can use key as simple uri */ - /* etc: datashareproxy://{bundleName}/meeting can use meeting replaced */ - /* if key is normal uri, bundleName is from uri */ - if (URIUtils::IsDataProxyURI(key)) { - URIUtils::GetBundleNameFromProxyURI(key, bundleName); - } -} - -bool PublishedDataKey::operator<(const PublishedDataKey &rhs) const -{ - if (key < rhs.key) { - return true; - } - if (rhs.key < key) { - return false; - } - if (bundleName < rhs.bundleName) { - return true; - } - if (rhs.bundleName < bundleName) { - return false; - } - return subscriberId < rhs.subscriberId; -} - -bool PublishedDataKey::operator>(const PublishedDataKey &rhs) const -{ - return rhs < *this; -} - -bool PublishedDataKey::operator<=(const PublishedDataKey &rhs) const -{ - return !(rhs < *this); -} - -bool PublishedDataKey::operator>=(const PublishedDataKey &rhs) const -{ - return !(*this < rhs); -} - -bool PublishedDataKey::operator==(const PublishedDataKey &rhs) const -{ - return key == rhs.key && bundleName == rhs.bundleName && subscriberId == rhs.subscriberId; -} - -bool PublishedDataKey::operator!=(const PublishedDataKey &rhs) const -{ - return !(rhs == *this); -} - RdbSubscriberManager::ObserverNode::ObserverNode(const sptr &observer, uint32_t callerTokenId) : observer(observer), callerTokenId(callerTokenId) { } - -PublishedDataSubscriberManager::ObserverNode::ObserverNode( - const sptr &observer, uint32_t callerTokenId) - : observer(observer), callerTokenId(callerTokenId) -{ -} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/template_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h similarity index 53% rename from services/distributeddataservice/service/data_share/common/template_manager.h rename to services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h index 24af1f0a..ab831527 100644 --- a/services/distributeddataservice/service/data_share/common/template_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DATASHARESERVICE_TEMPLATE_MANAGER_H -#define DATASHARESERVICE_TEMPLATE_MANAGER_H +#ifndef DATASHARESERVICE_RDB_SUBSCRIBER_MANAGER_H +#define DATASHARESERVICE_RDB_SUBSCRIBER_MANAGER_H #include #include @@ -62,6 +62,7 @@ public: int GetCount(const Key &key); std::vector GetKeysByUri(const std::string &uri); void Clear(); + private: struct ObserverNode { ObserverNode(const sptr &observer, uint32_t callerTokenId); @@ -72,8 +73,8 @@ private: class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { public: - ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, - sptr observer) : owner_(owner), key_(key), observer_(observer) {}; + ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, sptr observer) + : owner_(owner), key_(key), observer_(observer){}; void OnRemoteDied(const wptr &object) override { @@ -96,63 +97,5 @@ private: int rdbVersion); int GetEnableObserverCount(const Key &key); }; - -struct PublishedDataKey { - PublishedDataKey(const std::string &key, const std::string &bundleName, const int64_t subscriberId); - bool operator<(const PublishedDataKey &rhs) const; - bool operator>(const PublishedDataKey &rhs) const; - bool operator<=(const PublishedDataKey &rhs) const; - bool operator>=(const PublishedDataKey &rhs) const; - bool operator==(const PublishedDataKey &rhs) const; - bool operator!=(const PublishedDataKey &rhs) const; - std::string key; - std::string bundleName; - int64_t subscriberId; -}; - -class PublishedDataSubscriberManager { -public: - static PublishedDataSubscriberManager &GetInstance(); - int Add(const PublishedDataKey &key, const sptr observer, - const uint32_t callerTokenId); - int Delete(const PublishedDataKey &key, const uint32_t callerTokenId); - int Disable(const PublishedDataKey &key, const uint32_t callerTokenId); - int Enable(const PublishedDataKey &key, const uint32_t callerTokenId); - void Emit(const std::vector &keys, const int32_t userId, const std::string &ownerBundleName, - const sptr observer = nullptr); - void Clear(); -private: - struct ObserverNode { - ObserverNode(const sptr &observer, uint32_t callerTokenId); - sptr observer; - uint32_t callerTokenId; - bool enabled = true; - }; - class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { - public: - ObserverNodeRecipient(PublishedDataSubscriberManager *owner, const PublishedDataKey &key, - sptr observer) : owner_(owner), key_(key), observer_(observer) {}; - - void OnRemoteDied(const wptr &object) override - { - if (owner_ != nullptr) { - owner_->OnRemoteDied(key_, observer_); - } - } - - private: - PublishedDataSubscriberManager *owner_; - PublishedDataKey key_; - sptr observer_; - }; - - void LinkToDeath(const PublishedDataKey &key, sptr observer); - void OnRemoteDied(const PublishedDataKey &key, sptr observer); - - PublishedDataSubscriberManager() = default; - void PutInto(std::map, std::vector> &, - const std::vector &, const PublishedDataKey &, const sptr); - ConcurrentMap> publishedDataCache; -}; } // namespace OHOS::DataShare #endif -- Gitee From 991df93114fb2af230cf6b0432a0f50ee7854501 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 16 Jun 2023 11:43:25 +0800 Subject: [PATCH 233/437] f Signed-off-by: hanlu --- .../framework/include/serializable/serializable.h | 1 + .../framework/serializable/serializable.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/services/distributeddataservice/framework/include/serializable/serializable.h b/services/distributeddataservice/framework/include/serializable/serializable.h index f652a684..6843d643 100644 --- a/services/distributeddataservice/framework/include/serializable/serializable.h +++ b/services/distributeddataservice/framework/include/serializable/serializable.h @@ -65,6 +65,7 @@ public: API_EXPORT static bool SetValue(json &node, const uint32_t &value); API_EXPORT static bool SetValue(json &node, const int32_t &value); API_EXPORT static bool SetValue(json &node, const int64_t &value); + API_EXPORT static bool SetValue(json &node, const double &value); API_EXPORT static bool SetValue(json &node, const uint64_t &value); // Use bool & to forbid the const T * auto convert to bool, const bool will convert to const uint32_t &value; API_EXPORT static bool SetValue(json &node, bool &value); diff --git a/services/distributeddataservice/framework/serializable/serializable.cpp b/services/distributeddataservice/framework/serializable/serializable.cpp index c1c7ca8b..68fa96db 100644 --- a/services/distributeddataservice/framework/serializable/serializable.cpp +++ b/services/distributeddataservice/framework/serializable/serializable.cpp @@ -174,6 +174,12 @@ bool Serializable::SetValue(json &node, const int64_t &value) return true; } +bool Serializable::SetValue(json &node, const double &value) +{ + node = value; + return true; +} + bool Serializable::SetValue(json &node, const uint64_t &value) { node = value; -- Gitee From 2e21af837d121f8ab8f3b0db2b0a1cb84961a7cf Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 16 Jun 2023 12:06:08 +0800 Subject: [PATCH 234/437] f Signed-off-by: hanlu --- .../service/data_share/data/resultset_json_formatter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp index 75b096a2..04e2d908 100644 --- a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp +++ b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp @@ -84,7 +84,7 @@ bool ResultSetJsonFormatter::MarshalRow(DistributedData::Serializable::json &nod } default: ZLOGE("unknow type %{public}d", type); - return false; + return false; } } node.push_back(result); -- Gitee From f983901aef01601c265432f18c4a5c3f13658d14 Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 16 Jun 2023 14:04:51 +0800 Subject: [PATCH 235/437] f Signed-off-by: hanlu --- .../subscriber_managers/published_data_subscriber_manager.h | 3 +-- .../data_share/subscriber_managers/rdb_subscriber_manager.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index d2326ac9..f4dc24e2 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -60,8 +60,7 @@ private: class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { public: ObserverNodeRecipient(PublishedDataSubscriberManager *owner, const PublishedDataKey &key, - sptr observer) - : owner_(owner), key_(key), observer_(observer){}; + sptr observer) : owner_(owner), key_(key), observer_(observer) {}; void OnRemoteDied(const wptr &object) override { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h index ab831527..3f69ed25 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h @@ -74,7 +74,7 @@ private: class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { public: ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, sptr observer) - : owner_(owner), key_(key), observer_(observer){}; + : owner_(owner), key_(key), observer_(observer) {}; void OnRemoteDied(const wptr &object) override { -- Gitee From ad58181c834259e2bb6838885e0745cd79f8545f Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Fri, 16 Jun 2023 14:19:33 +0800 Subject: [PATCH 236/437] fix UT Signed-off-by: zuojiangjiang --- .../service/test/crypto_manager_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/distributeddataservice/service/test/crypto_manager_test.cpp b/services/distributeddataservice/service/test/crypto_manager_test.cpp index a7802076..cffc4b3b 100644 --- a/services/distributeddataservice/service/test/crypto_manager_test.cpp +++ b/services/distributeddataservice/service/test/crypto_manager_test.cpp @@ -16,6 +16,7 @@ #include "crypto_manager.h" #include +#include "file_ex.h" #include "gtest/gtest.h" #include "types.h" using namespace testing::ext; @@ -37,11 +38,13 @@ static const uint32_t ENCRYPT_KEY_LENGTH = 48; std::vector CryptoManagerTest::randomKey; void CryptoManagerTest::SetUpTestCase(void) { + OHOS::SaveStringToFile("/sys/fs/selinux/enforce", 0); randomKey = Random(KEY_LENGTH); } void CryptoManagerTest::TearDownTestCase(void) { + OHOS::SaveStringToFile("/sys/fs/selinux/enforce", 1); randomKey.assign(randomKey.size(), 0); } -- Gitee From 779df0842172f0ef6ac2415d21f20214fd9b9e9b Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Fri, 16 Jun 2023 15:12:07 +0800 Subject: [PATCH 237/437] fix ut Signed-off-by: zuojiangjiang --- .../service/test/crypto_manager_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/test/crypto_manager_test.cpp b/services/distributeddataservice/service/test/crypto_manager_test.cpp index cffc4b3b..d285af1b 100644 --- a/services/distributeddataservice/service/test/crypto_manager_test.cpp +++ b/services/distributeddataservice/service/test/crypto_manager_test.cpp @@ -16,8 +16,8 @@ #include "crypto_manager.h" #include -#include "file_ex.h" #include "gtest/gtest.h" +#include "file_ex.h" #include "types.h" using namespace testing::ext; using namespace OHOS::DistributedData; @@ -38,13 +38,13 @@ static const uint32_t ENCRYPT_KEY_LENGTH = 48; std::vector CryptoManagerTest::randomKey; void CryptoManagerTest::SetUpTestCase(void) { - OHOS::SaveStringToFile("/sys/fs/selinux/enforce", 0); + OHOS::SaveStringToFile("/sys/fs/selinux/enforce", "0"); randomKey = Random(KEY_LENGTH); } void CryptoManagerTest::TearDownTestCase(void) { - OHOS::SaveStringToFile("/sys/fs/selinux/enforce", 1); + OHOS::SaveStringToFile("/sys/fs/selinux/enforce", "1"); randomKey.assign(randomKey.size(), 0); } -- Gitee From 232292f40e5b890c09581c2d9c29b30a3ed74143 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Sun, 18 Jun 2023 20:10:11 +0800 Subject: [PATCH 238/437] add asset sync Signed-off-by: wanghuajian --- .../framework/cloud/asset_loader.cpp | 6 +- .../framework/include/cloud/asset_loader.h | 5 +- .../framework/include/store/general_value.h | 18 +- .../distributeddataservice/service/BUILD.gn | 2 + .../service/cloud/cloud_service_impl.cpp | 3 + .../service/cloud/sync_manager.cpp | 8 +- .../service/rdb/rdb_asset_loader.cpp | 64 +++++++ .../service/rdb/rdb_asset_loader.h | 43 +++++ .../service/rdb/rdb_cloud_data_translate.cpp | 180 ++++++++++++++++++ .../service/rdb/rdb_cloud_data_translate.h | 51 +++++ .../service/rdb/rdb_general_store.cpp | 10 +- .../service/rdb/rdb_general_store.h | 2 + .../service/rdb/value_proxy.cpp | 32 +++- .../service/rdb/value_proxy.h | 41 +++- .../service/test/value_proxy_test.cpp | 140 ++++++++++++++ 15 files changed, 594 insertions(+), 11 deletions(-) create mode 100644 services/distributeddataservice/service/rdb/rdb_asset_loader.cpp create mode 100644 services/distributeddataservice/service/rdb/rdb_asset_loader.h create mode 100644 services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp create mode 100644 services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h diff --git a/services/distributeddataservice/framework/cloud/asset_loader.cpp b/services/distributeddataservice/framework/cloud/asset_loader.cpp index cef89e7d..70c3ee5f 100644 --- a/services/distributeddataservice/framework/cloud/asset_loader.cpp +++ b/services/distributeddataservice/framework/cloud/asset_loader.cpp @@ -15,12 +15,12 @@ #include "cloud/asset_loader.h" namespace OHOS::DistributedData { -int32_t AssetLoader::Upload(const std::vector &assets) +int32_t AssetLoader::Download(const std::string &tableName, const std::string &gid, const Value &prefix, + VBucket &assets) { return E_NOT_SUPPORT; } - -int32_t AssetLoader::Download(std::vector &assets) +int32_t AssetLoader::RemoveLocalAssets(VBucket &assets) { return E_NOT_SUPPORT; } diff --git a/services/distributeddataservice/framework/include/cloud/asset_loader.h b/services/distributeddataservice/framework/include/cloud/asset_loader.h index 0df69eb0..89f3dd21 100644 --- a/services/distributeddataservice/framework/include/cloud/asset_loader.h +++ b/services/distributeddataservice/framework/include/cloud/asset_loader.h @@ -21,8 +21,9 @@ namespace OHOS::DistributedData { class API_EXPORT AssetLoader { public: virtual ~AssetLoader() = default; - virtual int32_t Upload(const std::vector &assets); - virtual int32_t Download(std::vector &assets); + virtual int32_t Download(const std::string &tableName, const std::string &gid, const Value &prefix, + VBucket &assets); + virtual int32_t RemoveLocalAssets(VBucket &assets); }; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_ASSET_LOADER_H diff --git a/services/distributeddataservice/framework/include/store/general_value.h b/services/distributeddataservice/framework/include/store/general_value.h index 18df10a1..07da1d1f 100644 --- a/services/distributeddataservice/framework/include/store/general_value.h +++ b/services/distributeddataservice/framework/include/store/general_value.h @@ -50,9 +50,25 @@ struct GenProgressDetail { }; struct Asset { - uint32_t version; + enum Status : int32_t { + STATUS_UNKNOWN, + STATUS_NORMAL, + STATUS_INSERT, + STATUS_UPDATE, + STATUS_DELETE, + STATUS_ABNORMAL, + STATUS_DOWNLOADING, + STATUS_BUTT + }; + + static constexpr uint64_t NO_EXPIRES_TIME = 0; + uint32_t version = 0; + uint32_t status = STATUS_UNKNOWN; + uint64_t expiresTime = NO_EXPIRES_TIME; + std::string id; std::string name; std::string uri; + std::string path; std::string createTime; std::string modifyTime; std::string size; diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index d55ad586..470e5b53 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -85,7 +85,9 @@ ohos_shared_library("distributeddatasvc") { "object/object_service_impl.cpp", "object/object_service_stub.cpp", "permission/src/permit_delegate.cpp", + "rdb/rdb_asset_loader.cpp", "rdb/rdb_cloud.cpp", + "rdb/rdb_cloud_data_translate.cpp", "rdb/rdb_cursor.cpp", "rdb/rdb_general_store.cpp", "rdb/rdb_notifier_proxy.cpp", diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index d4a29e00..05a32ac8 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -27,6 +27,8 @@ #include "metadata/meta_data_manager.h" #include "store/auto_cache.h" #include "utils/anonymous.h" +#include "runtime_config.h" +#include "rdb_cloud_data_translate.h" namespace OHOS::CloudData { using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; @@ -171,6 +173,7 @@ int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::str int32_t CloudServiceImpl::OnInitialize() { + DistributedDB::RuntimeConfig::SetCloudTranslate(std::make_shared()); Execute(GetCloudTask(0, 0, { WORK_CLOUD_INFO_UPDATE, WORK_SCHEMA_UPDATE })); return E_OK; } diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 897f7d2e..04940eb2 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -250,7 +250,13 @@ std::function SyncManager::GetSyncHandler() dbMeta.name.c_str(), dbMeta.alias.c_str()); return; } - store->Bind(dbMeta, std::move(cloudDB)); + auto assetLoader = instance->ConnectAssetLoader(storeInfo.tokenId, dbMeta); + if (assetLoader == nullptr) { + ZLOGE("failed, no assetLoader <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, + dbMeta.name.c_str(), dbMeta.alias.c_str()); + return; + } + store->Bind(dbMeta, {cloudDB, assetLoader}); } ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), Anonymous::Change(storeInfo.storeName).c_str()); diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp new file mode 100644 index 00000000..45153957 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp @@ -0,0 +1,64 @@ +/* +* 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. +*/ + +#define LOG_TAG "RdbAssetLoader" +#include "rdb_asset_loader.h" + +#include "error/general_error.h" +#include "log_print.h" +#include "value_proxy.h" + +using namespace DistributedDB; +namespace OHOS::DistributedRdb { +RdbAssetLoader::RdbAssetLoader(std::shared_ptr cloudAssetLoader) + : assetLoader_(std::move(cloudAssetLoader)) +{ +} + +DBStatus RdbAssetLoader::Download(const std::string &tableName, const std::string &gid, const Type &prefix, + std::map &assets) +{ + DistributedData::VBucket downLoadAssets = ValueProxy::Convert(assets); + + auto error = assetLoader_->Download(tableName, gid, (const DistributedData::Value &)prefix, downLoadAssets); + if (error == DistributedData::GeneralError::E_OK) { + assets = ValueProxy::Convert(std::move(downLoadAssets)); + } + return ConvertStatus(static_cast(error)); +} + +DBStatus RdbAssetLoader::ConvertStatus(DistributedData::GeneralError error) +{ + switch (error) { + case DistributedData::GeneralError::E_OK: + return DBStatus::OK; + case DistributedData::GeneralError::E_BUSY: + return DBStatus::BUSY; + case DistributedData::GeneralError::E_INVALID_ARGS: + return DBStatus::INVALID_ARGS; + case DistributedData::GeneralError::E_NOT_SUPPORT: + return DBStatus::NOT_SUPPORT; + case DistributedData::GeneralError::E_ERROR: // fallthrough + case DistributedData::GeneralError::E_NOT_INIT: + case DistributedData::GeneralError::E_ALREADY_CONSUMED: + case DistributedData::GeneralError::E_ALREADY_CLOSED: + return DBStatus::CLOUD_ERROR; + default: + ZLOGE("unknown error:0x%{public}x", error); + break; + } + return DBStatus::CLOUD_ERROR; +} +} \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.h b/services/distributeddataservice/service/rdb/rdb_asset_loader.h new file mode 100644 index 00000000..72cfec58 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.h @@ -0,0 +1,43 @@ +/* +* 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. +*/ + +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H + +#include "cloud/asset_loader.h" +#include "cloud/cloud_store_types.h" +#include "cloud/iAssetLoader.h" +#include "error/general_error.h" + +namespace OHOS::DistributedRdb { +class RdbAssetLoader : public DistributedDB::IAssetLoader{ +public: + using Type = DistributedDB::Type; + using Asset = DistributedDB::Asset; + using DBStatus = DistributedDB::DBStatus; + RdbAssetLoader(std::shared_ptr cloudAssetLoader); + + ~RdbAssetLoader() = default; + + DBStatus Download(const std::string &tableName, const std::string &gid, const Type &prefix, + std::map> &assets) override; + +private: + DBStatus ConvertStatus(DistributedData::GeneralError error); + + std::shared_ptr assetLoader_; +}; +} +#endif //OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp new file mode 100644 index 00000000..66aceb8d --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -0,0 +1,180 @@ +/* +* 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 "rdb_cloud_data_translate.h" +#include "utils/endian_converter.h" +#include "value_proxy.h" + +#define UNMARSHAL_RETURN_ERR(theCall) \ + do { \ + if (!theCall) { \ + return false; \ + } \ + } while (0) + +namespace OHOS::DistributedRdb { +using Asset = DistributedDB::Asset; +using Assets = DistributedDB::Assets; +using DataAsset = NativeRdb::ValueObject::Asset; +using DataAssets = NativeRdb::ValueObject::Assets; +std::vector RdbCloudDataTranslate::AssetToBlob(const Asset &asset) +{ + std::vector rawData; + DataAsset dataAsset = ValueProxy::Asset(asset); + InnerAsset innerAsset(dataAsset); + auto data = Serializable::Marshall(innerAsset); + uint16_t size; + size = DistributedData::HostToNet((uint16_t)data.length()); + auto magicU8 = reinterpret_cast(const_cast(&ASSET_MAGIC)); + rawData.insert(rawData.end(), magicU8, magicU8 + sizeof(ASSET_MAGIC)); + rawData.insert(rawData.end(), reinterpret_cast(&size), + reinterpret_cast(&size) + sizeof(size)); + rawData.insert(rawData.end(), data.begin(), data.end()); + return rawData; +} + +std::vector RdbCloudDataTranslate::AssetsToBlob(const Assets &assets) +{ + std::vector rawData; + uint16_t num = uint16_t(assets.size()); + auto magicU8 = reinterpret_cast(const_cast(&ASSETS_MAGIC)); + rawData.insert(rawData.end(), magicU8, magicU8 + sizeof(ASSETS_MAGIC)); + rawData.insert(rawData.end(), reinterpret_cast(&num), reinterpret_cast(&num) + sizeof(num)); + for (auto &asset : assets) { + auto data = AssetToBlob(asset); + rawData.insert(rawData.end(), data.begin(), data.end()); + } + return rawData; +} + +Asset RdbCloudDataTranslate::BlobToAsset(const std::vector &blob) +{ + DataAsset asset; + if (ParserRawData(blob.data(), blob.size(), asset) == 0) { + return {}; + } + return ValueProxy::Convert(asset); +} + +Assets RdbCloudDataTranslate::BlobToAssets(std::vector &blob) +{ + DataAssets assets; + if (ParserRawData(blob.data(), blob.size(), assets) == 0) { + return {}; + } + return ValueProxy::Convert(assets); +} + +size_t RdbCloudDataTranslate::ParserRawData(const uint8_t *data, size_t length, DataAsset &asset) +{ + size_t used = 0; + uint16_t size = 0; + + if (sizeof(ASSET_MAGIC) > length - used) { + return 0; + } + std::vector alignData; + alignData.assign(data, data + sizeof(ASSET_MAGIC)); + used += sizeof(ASSET_MAGIC); + if (*(reinterpret_cast(alignData.data())) != ASSET_MAGIC) { + return 0; + } + + if (sizeof(size) > length - used) { + return 0; + } + alignData.assign(data + used, data + used + sizeof(size)); + used += sizeof(size); + size = DistributedData::NetToHost(*(reinterpret_cast(alignData.data()))); + + if (size > length - used) { + return 0; + } + auto rawData = std::string(reinterpret_cast(&data[used]), size); + InnerAsset innerAsset(asset); + if (!innerAsset.Unmarshall(rawData)) { + return 0; + } + used += size; + return used; +} + +size_t RdbCloudDataTranslate::ParserRawData(const uint8_t *data, size_t length, DataAssets &assets) +{ + size_t used = 0; + uint16_t num = 0; + + if (sizeof(ASSETS_MAGIC) > length - used) { + return 0; + } + std::vector alignData; + alignData.assign(data, data + sizeof(ASSETS_MAGIC)); + used += sizeof(ASSETS_MAGIC); + if (*(reinterpret_cast(alignData.data())) != ASSETS_MAGIC) { + return 0; + } + + if (sizeof(num) > length - used) { + return 0; + } + alignData.assign(data, data + sizeof(num)); + num = *(reinterpret_cast(alignData.data())); + used += sizeof(num); + uint16_t count = 0; + while (used < length && count < num) { + DataAsset asset; + auto dataLen = ParserRawData(&data[used], length - used, asset); + if (dataLen == 0) { + break; + } + used += dataLen; + assets.push_back(ValueProxy::Convert(asset)); + count++; + } + return used; +} + +bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializable::json &node) const +{ + SetValue(node[GET_NAME(version)], asset_.version); + SetValue(node[GET_NAME(status)], asset_.status); + SetValue(node[GET_NAME(expiresTime)], asset_.timeStamp); + SetValue(node[GET_NAME(name)], asset_.name); + SetValue(node[GET_NAME(uri)], asset_.uri); + SetValue(node[GET_NAME(path)], asset_.path); + SetValue(node[GET_NAME(createTime)], asset_.createTime); + SetValue(node[GET_NAME(modifyTime)], asset_.modifyTime); + SetValue(node[GET_NAME(size)], asset_.size); + SetValue(node[GET_NAME(hash)], asset_.hash); + SetValue(node[GET_NAME(id)], asset_.id); + return true; +} + +bool RdbCloudDataTranslate::InnerAsset::Unmarshal(const OHOS::DistributedData::Serializable::json &node) +{ + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(version), asset_.version)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(status), asset_.status)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(expiresTime), asset_.timeStamp)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(name), asset_.name)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(uri), asset_.uri)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(path), asset_.path)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(createTime), asset_.createTime)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(modifyTime), asset_.modifyTime)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(size), asset_.size)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(hash), asset_.hash)); + UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(id), asset_.id)); + return true; +} +} // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h new file mode 100644 index 00000000..3d9fb8e2 --- /dev/null +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h @@ -0,0 +1,51 @@ +/* +* 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. +*/ +#ifndef OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_DATA_TRASLATE_H +#define OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_DATA_TRASLATE_H + +#include "cloud/icloud_data_translate.h" +#include "serializable/serializable.h" +#include "value_object.h" +namespace OHOS::DistributedRdb { +class RdbCloudDataTranslate : public DistributedDB::ICloudDataTranslate { +public: + using Asset = DistributedDB::Asset; + using Assets = DistributedDB::Assets; + using DataAsset = NativeRdb::ValueObject::Asset; + using DataAssets = NativeRdb::ValueObject::Assets; + RdbCloudDataTranslate() = default; + ~RdbCloudDataTranslate() = default; + std::vector AssetToBlob(const Asset &asset) override; + std::vector AssetsToBlob(const Assets &assets) override; + Asset BlobToAsset(const std::vector &blob) override; + Assets BlobToAssets(std::vector &blob) override; + +private: + using Serializable = DistributedData::Serializable; + + static constexpr const uint32_t ASSET_MAGIC = 0x41534554; + static constexpr const uint32_t ASSETS_MAGIC = 0x41534553; + struct InnerAsset : public Serializable { + DataAsset &asset_; + explicit InnerAsset(DataAsset &asset) : asset_(asset) {} + + bool Marshal(json &node) const override; + bool Unmarshal(const json &node) override; + }; + size_t ParserRawData(const uint8_t *data, size_t length, DataAsset &asset); + size_t ParserRawData(const uint8_t *data, size_t length, DataAssets &assets); +}; +} +#endif //OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_DATA_TRASLATE_H diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 1d24fb42..9a842534 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -86,11 +86,12 @@ RdbGeneralStore::~RdbGeneralStore() bindInfo_.db_->Close(); bindInfo_.db_ = nullptr; rdbCloud_ = nullptr; + rdbLoader_ = nullptr; } int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) { - if (bindInfo.db_ == nullptr) { + if (bindInfo.db_ == nullptr || bindInfo.loader_ == nullptr) { return GeneralError::E_INVALID_ARGS; } @@ -105,6 +106,12 @@ int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) return GeneralError::E_ERROR; } delegate_->SetCloudDB(rdbCloud_); + rdbLoader_ = std::make_shared(bindInfo_.loader_); + if (rdbLoader_ == nullptr) { + ZLOGE("rdb_AssetLoader is null"); + return GeneralError::E_ERROR; + } + delegate_->SetIAssetLoader(rdbLoader_); DBSchema schema; schema.tables.resize(database.tables.size()); for (size_t i = 0; i < database.tables.size(); i++) { @@ -141,6 +148,7 @@ int32_t RdbGeneralStore::Close() bindInfo_.db_->Close(); bindInfo_.db_ = nullptr; rdbCloud_ = nullptr; + rdbLoader_ = nullptr; return 0; } diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 10366ca6..30f571c0 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -18,6 +18,7 @@ #include #include #include "metadata/store_meta_data.h" +#include "rdb_asset_loader.h" #include "rdb_cloud.h" #include "rdb_store.h" #include "relational_store_delegate.h" @@ -83,6 +84,7 @@ private: RdbDelegate *delegate_ = nullptr; std::shared_ptr store_; std::shared_ptr rdbCloud_ {}; + std::shared_ptr rdbLoader_ {}; BindInfo bindInfo_; std::atomic isBound_ = false; }; diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index fbd7c5f9..3c83e520 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -14,7 +14,6 @@ */ #define LOG_TAG "ValueProxy" -#include "log_print.h" #include "value_proxy.h" namespace OHOS::DistributedRdb { using namespace OHOS::DistributedData; @@ -124,8 +123,12 @@ ValueProxy::Asset::Asset(DistributedData::Asset asset) ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) { asset_ = DistributedData::Asset { .version = asset.version, + .status = asset.status, + .expiresTime = asset.expiresTime, + .id = std::move(asset.id), .name = std::move(asset.name), .uri = std::move(asset.uri), + .path = std::move(asset.path), .createTime = std::move(asset.createTime), .modifyTime = std::move(asset.modifyTime), .size = std::move(asset.size), @@ -135,6 +138,9 @@ ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) ValueProxy::Asset::Asset(DistributedDB::Asset asset) { asset_ = DistributedData::Asset { .version = asset.version, + .status = ConvertDBStatus(asset), + .expiresTime = DistributedData::Asset::NO_EXPIRES_TIME, + .id = std::move(asset.assetId), .name = std::move(asset.name), .uri = std::move(asset.uri), .createTime = std::move(asset.createTime), @@ -164,8 +170,12 @@ ValueProxy::Asset &ValueProxy::Asset::operator=(Asset &&proxy) noexcept ValueProxy::Asset::operator NativeRdb::AssetValue() { return NativeRdb::AssetValue { .version = asset_.version, + .status = asset_.status, + .expiresTime = asset_.expiresTime, + .id = std::move(asset_.id), .name = std::move(asset_.name), .uri = std::move(asset_.uri), + .path = std::move(asset_.path), .createTime = std::move(asset_.createTime), .modifyTime = std::move(asset_.modifyTime), .size = std::move(asset_.size), @@ -181,11 +191,29 @@ ValueProxy::Asset::operator DistributedDB::Asset() { return DistributedDB::Asset { .version = asset_.version, .name = std::move(asset_.name), + .assetId = std::move(asset_.id), + .subpath = std::move(asset_.path), .uri = std::move(asset_.uri), .modifyTime = std::move(asset_.modifyTime), .createTime = std::move(asset_.createTime), .size = std::move(asset_.size), - .hash = std::move(asset_.hash) }; + .hash = std::move(asset_.hash), + .status = asset_.status == DistributedData::Asset::STATUS_NORMAL ? DistributedDB::AssetStatus::ABNORMAL + : DistributedDB::AssetStatus::NORMAL}; +} + +uint32_t ValueProxy::Asset::ConvertDBStatus(const DistributedDB::Asset& asset) +{ + switch (asset.flag) { + case static_cast(DistributedDB::AssetOpType::INSERT): + return DistributedData::Asset::STATUS_INSERT; + case static_cast(DistributedDB::AssetOpType::UPDATE): + return DistributedData::Asset::STATUS_UPDATE; + case static_cast(DistributedDB::AssetOpType::DELETE): + return DistributedData::Asset::STATUS_DELETE; + default: + return DistributedData::Asset::STATUS_UNKNOWN; + } } ValueProxy::Assets::Assets(DistributedData::Assets assets) diff --git a/services/distributeddataservice/service/rdb/value_proxy.h b/services/distributeddataservice/service/rdb/value_proxy.h index 8506e268..75f5f441 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.h +++ b/services/distributeddataservice/service/rdb/value_proxy.h @@ -23,6 +23,23 @@ namespace OHOS::DistributedRdb { class ValueProxy final { public: + template + static inline constexpr uint32_t INDEX = DistributedData::TYPE_INDEX; + static inline constexpr uint32_t MAX = DistributedData::TYPE_MAX; + + template + struct variant_cvt_of { + static constexpr size_t value = std::is_class_v ? Traits::convertible_index_of_v + : Traits::same_index_of_v; + }; + + template + static variant_cvt_of variant_cvt_test(const T &, const std::variant &); + + template + static inline constexpr uint32_t CVT_INDEX = + decltype(variant_cvt_test(std::declval(), std::declval()))::value; + using Bytes = DistributedData::Bytes; class Asset { public: @@ -43,6 +60,7 @@ public: operator NativeRdb::AssetValue(); operator DistributedData::Asset(); operator DistributedDB::Asset(); + static uint32_t ConvertDBStatus(const DistributedDB::Asset& asset); private: DistributedData::Asset asset_; @@ -85,6 +103,16 @@ public: operator DistributedData::Value(); operator DistributedDB::Type(); + template + operator T() noexcept + { + auto val = Traits::get_if(&value_); + if (val != nullptr) { + return T(std::move(*val)); + } + return T(); + }; + private: friend ValueProxy; Proxy value_; @@ -126,7 +154,7 @@ public: { std::map bucket; for (auto &[key, value] : value_) { - bucket.insert_or_assign(key, std::move(value)); + bucket.insert_or_assign(key, std::move(static_cast(value))); } value_.clear(); return bucket; @@ -173,6 +201,17 @@ public: static Buckets Convert(std::vector &&buckets); static Buckets Convert(std::vector &&buckets); + template + static std::enable_if_t < CVT_INDEX + Convert(const std::map &values) + { + Bucket bucket; + for(auto &[key, value] : values) { + bucket.value_[key].value_ = static_cast, Proxy>>(value); + } + return bucket; + } + private: ValueProxy() = delete; ~ValueProxy() = delete; diff --git a/services/distributeddataservice/service/test/value_proxy_test.cpp b/services/distributeddataservice/service/test/value_proxy_test.cpp index 672b9b2a..51bee0c7 100644 --- a/services/distributeddataservice/service/test/value_proxy_test.cpp +++ b/services/distributeddataservice/service/test/value_proxy_test.cpp @@ -104,4 +104,144 @@ HWTEST_F(ValueProxyTest, VBucketsRdb2Normal, TestSize.Level0) extends = ValueProxy::Convert(std::move(rdbVBuckets)); ASSERT_EQ(extends.size(), 2); } + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, ConvertIntMapTest, TestSize.Level0) +{ + std::map testMap = { { "name", 1 }, { "school", 2 }, { "address", 3 } }; + auto res = ValueProxy::Convert(testMap); + auto testMap2 = std::map(res); + ASSERT_EQ(testMap2.find("name")->second, 1); + + auto errorMap = std::map(res); + ASSERT_EQ(errorMap.size(), 0); +} + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, ConvertAssetMapGaussDB2NormalTest, TestSize.Level0) +{ + DistributedDB::Asset dbAsset0{ .name = "dbname", .uri = "dburi" }; + DistributedDB::Asset dbAsset1{ .name = "dbname", .uri = "dburi" }; + std::map dbMap{ { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; + OHOS::DistributedData::VBucket transferredAsset = ValueProxy::Convert(dbMap); + ASSERT_EQ(transferredAsset.size(), 2); + auto asset = std::get(transferredAsset.find("asset0")->second); + ASSERT_EQ(asset.name, "dbname"); + + DistributedDB::Assets dbAssets{ dbAsset0, dbAsset1 }; + std::map dbAssetsMap{ {"dbAssets", dbAssets} }; + OHOS::DistributedData::VBucket transferredAssets = ValueProxy::Convert(dbAssetsMap); + ASSERT_EQ(transferredAssets.size(), 1); + auto assets = std::get(transferredAssets.find("dbAssets")->second); + ASSERT_EQ(assets.size(), 2); + auto dataAsset = assets.begin(); + ASSERT_EQ(dataAsset->name, "dbname"); +} + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, ConvertAssetMapNormal2GaussDBTest, TestSize.Level0) +{ + using NormalAsset = OHOS::DistributedData::Asset; + using NormalAssets = OHOS::DistributedData::Assets; + NormalAsset nAsset0{ .name = "name", .uri = "uri" }; + NormalAsset nAsset1{ .name = "name", .uri = "uri" }; + std::map nMap{ { "asset0", nAsset0 }, { "asset1", nAsset1 } }; + DistributedDB::VBucket transferredAsset = ValueProxy::Convert(nMap); + ASSERT_EQ(transferredAsset.size(), 2); + auto asset = std::get(transferredAsset.find("asset0")->second); + ASSERT_EQ(asset.name, "name"); + + NormalAssets nAssets{ nAsset0, nAsset1 }; + std::map nAssetsMap{ { "Assets", nAssets } }; + DistributedDB::VBucket transferredAssets = ValueProxy::Convert(nAssetsMap); + ASSERT_EQ(transferredAssets.size(), 1); + auto assets = std::get(transferredAssets.find("Assets")->second); + ASSERT_EQ(assets.size(), 2); + auto dataAsset = assets.begin(); + ASSERT_EQ(dataAsset->name, "name"); +} + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, ConvertAssetMapRdb2NormalTest, TestSize.Level0) +{ + using RdbAsset = OHOS::NativeRdb::AssetValue; + using RdbAssets = std::vector; + RdbAsset dbAsset0{ .name = "dbname", .uri = "dburi" }; + RdbAsset dbAsset1{ .name = "dbname", .uri = "dburi" }; + std::map dbMap{ { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; + OHOS::DistributedData::VBucket transferredAsset = ValueProxy::Convert(dbMap); + ASSERT_EQ(transferredAsset.size(), 2); + auto asset = std::get(transferredAsset.find("asset0")->second); + ASSERT_EQ(asset.name, "dbname"); + + RdbAssets dbAssets{ dbAsset0, dbAsset1 }; + std::map dbAssetsMap{ {"dbAssets", dbAssets} }; + OHOS::DistributedData::VBucket transferredAssets = ValueProxy::Convert(dbAssetsMap); + ASSERT_EQ(transferredAssets.size(), 1); + auto assets = std::get(transferredAssets.find("dbAssets")->second); + ASSERT_EQ(assets.size(), 2); + auto dataAsset = assets.begin(); + ASSERT_EQ(dataAsset->name, "dbname"); +} + +/** +* @tc.name: GetSchema +* @tc.desc: GetSchema from cloud when no schema in meta. +* @tc.type: FUNC +* @tc.require: +* @tc.author: ht +*/ +HWTEST_F(ValueProxyTest, ConvertAssetMapNormal2RdbTest, TestSize.Level0) +{ + using RdbAsset = OHOS::NativeRdb::AssetValue; + using RdbAssets = std::vector; + using NormalAsset = OHOS::DistributedData::Asset; + using NormalAssets = OHOS::DistributedData::Assets; + NormalAsset nAsset0{ .name = "name", .uri = "uri" }; + NormalAsset nAsset1{ .name = "name", .uri = "uri" }; + std::map nMap{ { "asset0", nAsset0 }, { "asset1", nAsset1 } }; + OHOS::NativeRdb::ValuesBucket transferredAsset = ValueProxy::Convert(nMap); + ASSERT_EQ(transferredAsset.Size(), 2); + OHOS::NativeRdb::ValueObject rdbObject; + transferredAsset.GetObject("asset0", rdbObject); + RdbAsset rdbAsset; + rdbObject.GetAsset(rdbAsset); + ASSERT_EQ(rdbAsset.name, "name"); + + NormalAssets nAssets{ nAsset0, nAsset1 }; + std::map nAssetsMap{ { "Assets", nAssets } }; + OHOS::NativeRdb::ValuesBucket transferredAssets = ValueProxy::Convert(nAssetsMap); + ASSERT_EQ(transferredAssets.Size(), 1); + OHOS::NativeRdb::ValueObject rdbObject2; + transferredAssets.GetObject("Assets", rdbObject2); + RdbAssets rdbAssets; + rdbObject2.GetAssets(rdbAssets); + ASSERT_EQ(rdbAssets.size(), 2); + auto dataAsset = rdbAssets.begin(); + ASSERT_EQ(dataAsset->name, "name"); +} } -- Gitee From db9acb08c0422a7a51e4a444fe0cb59ea6fed1f9 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Sun, 18 Jun 2023 20:34:20 +0800 Subject: [PATCH 239/437] add asset sync Signed-off-by: wanghuajian --- .../framework/cloud/asset_loader.cpp | 2 +- .../framework/include/cloud/asset_loader.h | 1 + .../service/cloud/cloud_service_impl.cpp | 4 ++-- .../service/rdb/value_proxy.cpp | 12 ++++++------ .../distributeddataservice/service/rdb/value_proxy.h | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/asset_loader.cpp b/services/distributeddataservice/framework/cloud/asset_loader.cpp index 70c3ee5f..f2551e1b 100644 --- a/services/distributeddataservice/framework/cloud/asset_loader.cpp +++ b/services/distributeddataservice/framework/cloud/asset_loader.cpp @@ -24,4 +24,4 @@ int32_t AssetLoader::RemoveLocalAssets(VBucket &assets) { return E_NOT_SUPPORT; } -} +} // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/framework/include/cloud/asset_loader.h b/services/distributeddataservice/framework/include/cloud/asset_loader.h index 89f3dd21..c2d47a63 100644 --- a/services/distributeddataservice/framework/include/cloud/asset_loader.h +++ b/services/distributeddataservice/framework/include/cloud/asset_loader.h @@ -15,6 +15,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_ASSET_LOADER_H #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_ASSET_LOADER_H #include + #include "store/general_value.h" #include "visibility.h" namespace OHOS::DistributedData { diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 05a32ac8..c4c23348 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -25,10 +25,10 @@ #include "ipc_skeleton.h" #include "log_print.h" #include "metadata/meta_data_manager.h" +#include "rdb_cloud_data_translate.h" +#include "runtime_config.h" #include "store/auto_cache.h" #include "utils/anonymous.h" -#include "runtime_config.h" -#include "rdb_cloud_data_translate.h" namespace OHOS::CloudData { using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 3c83e520..095fb3ac 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -122,7 +122,7 @@ ValueProxy::Asset::Asset(DistributedData::Asset asset) ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) { - asset_ = DistributedData::Asset { .version = asset.version, + asset_ = DistributedData::Asset{ .version = asset.version, .status = asset.status, .expiresTime = asset.expiresTime, .id = std::move(asset.id), @@ -137,7 +137,7 @@ ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) ValueProxy::Asset::Asset(DistributedDB::Asset asset) { - asset_ = DistributedData::Asset { .version = asset.version, + asset_ = DistributedData::Asset{ .version = asset.version, .status = ConvertDBStatus(asset), .expiresTime = DistributedData::Asset::NO_EXPIRES_TIME, .id = std::move(asset.assetId), @@ -169,7 +169,7 @@ ValueProxy::Asset &ValueProxy::Asset::operator=(Asset &&proxy) noexcept ValueProxy::Asset::operator NativeRdb::AssetValue() { - return NativeRdb::AssetValue { .version = asset_.version, + return NativeRdb::AssetValue{ .version = asset_.version, .status = asset_.status, .expiresTime = asset_.expiresTime, .id = std::move(asset_.id), @@ -189,7 +189,7 @@ ValueProxy::Asset::operator DistributedData::Asset() ValueProxy::Asset::operator DistributedDB::Asset() { - return DistributedDB::Asset { .version = asset_.version, + return DistributedDB::Asset{ .version = asset_.version, .name = std::move(asset_.name), .assetId = std::move(asset_.id), .subpath = std::move(asset_.path), @@ -199,10 +199,10 @@ ValueProxy::Asset::operator DistributedDB::Asset() .size = std::move(asset_.size), .hash = std::move(asset_.hash), .status = asset_.status == DistributedData::Asset::STATUS_NORMAL ? DistributedDB::AssetStatus::ABNORMAL - : DistributedDB::AssetStatus::NORMAL}; + : DistributedDB::AssetStatus::NORMAL }; } -uint32_t ValueProxy::Asset::ConvertDBStatus(const DistributedDB::Asset& asset) +uint32_t ValueProxy::Asset::ConvertDBStatus(const DistributedDB::Asset &asset) { switch (asset.flag) { case static_cast(DistributedDB::AssetOpType::INSERT): diff --git a/services/distributeddataservice/service/rdb/value_proxy.h b/services/distributeddataservice/service/rdb/value_proxy.h index 75f5f441..8fddf204 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.h +++ b/services/distributeddataservice/service/rdb/value_proxy.h @@ -60,7 +60,7 @@ public: operator NativeRdb::AssetValue(); operator DistributedData::Asset(); operator DistributedDB::Asset(); - static uint32_t ConvertDBStatus(const DistributedDB::Asset& asset); + static uint32_t ConvertDBStatus(const DistributedDB::Asset &asset); private: DistributedData::Asset asset_; @@ -206,7 +206,7 @@ public: Convert(const std::map &values) { Bucket bucket; - for(auto &[key, value] : values) { + for (auto &[key, value] : values) { bucket.value_[key].value_ = static_cast, Proxy>>(value); } return bucket; -- Gitee From 88170c27ad24b1a447a869912d5e8202dd818c23 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Sun, 18 Jun 2023 22:24:20 +0800 Subject: [PATCH 240/437] change Signed-off-by: wanghuajian --- .../framework/cloud/cloud_db.cpp | 5 ++++ .../framework/include/cloud/cloud_db.h | 2 ++ .../service/rdb/rdb_asset_loader.cpp | 2 +- .../service/rdb/rdb_asset_loader.h | 2 +- .../service/rdb/rdb_cloud.cpp | 7 +++-- .../service/rdb/rdb_cloud_data_translate.cpp | 30 +++++++------------ .../service/rdb/rdb_cloud_data_translate.h | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/cloud_db.cpp b/services/distributeddataservice/framework/cloud/cloud_db.cpp index dd149f8e..5a081255 100644 --- a/services/distributeddataservice/framework/cloud/cloud_db.cpp +++ b/services/distributeddataservice/framework/cloud/cloud_db.cpp @@ -25,6 +25,11 @@ int32_t CloudDB::BatchInsert(const std::string &table, VBuckets &&values, VBucke return E_NOT_SUPPORT; } +int32_t CloudDB::BatchUpdate(const std::string &table, VBuckets &&values, VBuckets &extends) +{ + return BatchUpdate(table, std::move(values), static_cast(extends)); +} + int32_t CloudDB::BatchUpdate(const std::string &table, VBuckets &&values, const VBuckets &extends) { return E_NOT_SUPPORT; diff --git a/services/distributeddataservice/framework/include/cloud/cloud_db.h b/services/distributeddataservice/framework/include/cloud/cloud_db.h index 4882d8d7..1b6f2462 100644 --- a/services/distributeddataservice/framework/include/cloud/cloud_db.h +++ b/services/distributeddataservice/framework/include/cloud/cloud_db.h @@ -34,6 +34,8 @@ public: virtual int32_t BatchInsert(const std::string &table, VBuckets &&values, VBuckets &extends); + virtual int32_t BatchUpdate(const std::string &table, VBuckets &&values, VBuckets &extends); + virtual int32_t BatchUpdate(const std::string &table, VBuckets &&values, const VBuckets &extends); virtual int32_t BatchDelete(const std::string &table, const VBuckets &extends); diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp index 45153957..b7d4d938 100644 --- a/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp @@ -61,4 +61,4 @@ DBStatus RdbAssetLoader::ConvertStatus(DistributedData::GeneralError error) } return DBStatus::CLOUD_ERROR; } -} \ No newline at end of file +} // namespace OHOS::DistributedRdb \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.h b/services/distributeddataservice/service/rdb/rdb_asset_loader.h index 72cfec58..e2214360 100644 --- a/services/distributeddataservice/service/rdb/rdb_asset_loader.h +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.h @@ -39,5 +39,5 @@ private: std::shared_ptr assetLoader_; }; -} +} // namespace OHOS::DistributedRdb #endif //OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index e3d16735..5880d00d 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -41,8 +41,11 @@ DBStatus RdbCloud::BatchInsert( DBStatus RdbCloud::BatchUpdate( const std::string &tableName, std::vector &&record, std::vector &extend) { - auto error = cloudDB_->BatchUpdate( - tableName, ValueProxy::Convert(std::move(record)), ValueProxy::Convert(std::move(extend))); + DistributedData::VBuckets extends = ValueProxy::Convert(std::move(extend)); + auto error = cloudDB_->BatchUpdate(tableName, ValueProxy::Convert(std::move(record)), extends); + if (error == GeneralError::E_OK) { + extend = ValueProxy::Convert(std::move(extends)); + } return ConvertStatus(static_cast(error)); } diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp index 66aceb8d..929a4714 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -17,13 +17,6 @@ #include "utils/endian_converter.h" #include "value_proxy.h" -#define UNMARSHAL_RETURN_ERR(theCall) \ - do { \ - if (!theCall) { \ - return false; \ - } \ - } while (0) - namespace OHOS::DistributedRdb { using Asset = DistributedDB::Asset; using Assets = DistributedDB::Assets; @@ -150,7 +143,7 @@ bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializa { SetValue(node[GET_NAME(version)], asset_.version); SetValue(node[GET_NAME(status)], asset_.status); - SetValue(node[GET_NAME(expiresTime)], asset_.timeStamp); + SetValue(node[GET_NAME(expiresTime)], asset_.expiresTime); SetValue(node[GET_NAME(name)], asset_.name); SetValue(node[GET_NAME(uri)], asset_.uri); SetValue(node[GET_NAME(path)], asset_.path); @@ -164,17 +157,14 @@ bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializa bool RdbCloudDataTranslate::InnerAsset::Unmarshal(const OHOS::DistributedData::Serializable::json &node) { - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(version), asset_.version)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(status), asset_.status)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(expiresTime), asset_.timeStamp)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(name), asset_.name)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(uri), asset_.uri)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(path), asset_.path)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(createTime), asset_.createTime)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(modifyTime), asset_.modifyTime)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(size), asset_.size)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(hash), asset_.hash)); - UNMARSHAL_RETURN_ERR(GetValue(node, GET_NAME(id), asset_.id)); - return true; + bool flag = false; + flag = GetValue(node, GET_NAME(version), asset_.version) && GetValue(node, GET_NAME(status), asset_.status) && + GetValue(node, GET_NAME(expiresTime), asset_.expiresTime) && GetValue(node, GET_NAME(name), asset_.name) && + GetValue(node, GET_NAME(uri), asset_.uri) && GetValue(node, GET_NAME(path), asset_.path) && + GetValue(node, GET_NAME(createTime), asset_.createTime) && + GetValue(node, GET_NAME(modifyTime), asset_.modifyTime) && GetValue(node, GET_NAME(size), asset_.size) && + GetValue(node, GET_NAME(hash), asset_.hash) && GetValue(node, GET_NAME(id), asset_.id); + + return flag; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h index 3d9fb8e2..6cf01cb8 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h @@ -47,5 +47,5 @@ private: size_t ParserRawData(const uint8_t *data, size_t length, DataAsset &asset); size_t ParserRawData(const uint8_t *data, size_t length, DataAssets &assets); }; -} +} // namespace OHOS::DistributedRdb #endif //OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_DATA_TRASLATE_H -- Gitee From 0c808d247af071749b11d300a40ca968078711fe Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Sun, 18 Jun 2023 23:50:29 +0800 Subject: [PATCH 241/437] update Signed-off-by: wanghuajian --- .../service/rdb/rdb_cloud_data_translate.cpp | 8 ++++---- .../distributeddataservice/service/rdb/value_proxy.cpp | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp index 929a4714..f280d31c 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -14,6 +14,7 @@ */ #include "rdb_cloud_data_translate.h" + #include "utils/endian_converter.h" #include "value_proxy.h" @@ -143,7 +144,7 @@ bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializa { SetValue(node[GET_NAME(version)], asset_.version); SetValue(node[GET_NAME(status)], asset_.status); - SetValue(node[GET_NAME(expiresTime)], asset_.expiresTime); + SetValue(node[GET_NAME(expiresTime)], asset_.timeStamp); SetValue(node[GET_NAME(name)], asset_.name); SetValue(node[GET_NAME(uri)], asset_.uri); SetValue(node[GET_NAME(path)], asset_.path); @@ -151,7 +152,6 @@ bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializa SetValue(node[GET_NAME(modifyTime)], asset_.modifyTime); SetValue(node[GET_NAME(size)], asset_.size); SetValue(node[GET_NAME(hash)], asset_.hash); - SetValue(node[GET_NAME(id)], asset_.id); return true; } @@ -159,11 +159,11 @@ bool RdbCloudDataTranslate::InnerAsset::Unmarshal(const OHOS::DistributedData::S { bool flag = false; flag = GetValue(node, GET_NAME(version), asset_.version) && GetValue(node, GET_NAME(status), asset_.status) && - GetValue(node, GET_NAME(expiresTime), asset_.expiresTime) && GetValue(node, GET_NAME(name), asset_.name) && + GetValue(node, GET_NAME(expiresTime), asset_.timeStamp) && GetValue(node, GET_NAME(name), asset_.name) && GetValue(node, GET_NAME(uri), asset_.uri) && GetValue(node, GET_NAME(path), asset_.path) && GetValue(node, GET_NAME(createTime), asset_.createTime) && GetValue(node, GET_NAME(modifyTime), asset_.modifyTime) && GetValue(node, GET_NAME(size), asset_.size) && - GetValue(node, GET_NAME(hash), asset_.hash) && GetValue(node, GET_NAME(id), asset_.id); + GetValue(node, GET_NAME(hash), asset_.hash); return flag; } diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 095fb3ac..72772af0 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -124,8 +124,8 @@ ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) { asset_ = DistributedData::Asset{ .version = asset.version, .status = asset.status, - .expiresTime = asset.expiresTime, - .id = std::move(asset.id), + .expiresTime = asset.timeStamp, + .id = "", .name = std::move(asset.name), .uri = std::move(asset.uri), .path = std::move(asset.path), @@ -171,8 +171,7 @@ ValueProxy::Asset::operator NativeRdb::AssetValue() { return NativeRdb::AssetValue{ .version = asset_.version, .status = asset_.status, - .expiresTime = asset_.expiresTime, - .id = std::move(asset_.id), + .timeStamp = asset_.expiresTime, .name = std::move(asset_.name), .uri = std::move(asset_.uri), .path = std::move(asset_.path), -- Gitee From 914f39de03c45b11e6fa3080e41a6fb8e11ced8b Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 01:08:19 +0800 Subject: [PATCH 242/437] update Signed-off-by: wanghuajian --- .../service/rdb/value_proxy.cpp | 53 ++++++++++++++----- .../service/rdb/value_proxy.h | 3 +- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 72772af0..b71ac7b9 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -138,7 +138,7 @@ ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) ValueProxy::Asset::Asset(DistributedDB::Asset asset) { asset_ = DistributedData::Asset{ .version = asset.version, - .status = ConvertDBStatus(asset), + .status = ConvertToDataStatus(asset), .expiresTime = DistributedData::Asset::NO_EXPIRES_TIME, .id = std::move(asset.assetId), .name = std::move(asset.name), @@ -171,7 +171,6 @@ ValueProxy::Asset::operator NativeRdb::AssetValue() { return NativeRdb::AssetValue{ .version = asset_.version, .status = asset_.status, - .timeStamp = asset_.expiresTime, .name = std::move(asset_.name), .uri = std::move(asset_.uri), .path = std::move(asset_.path), @@ -197,21 +196,47 @@ ValueProxy::Asset::operator DistributedDB::Asset() .createTime = std::move(asset_.createTime), .size = std::move(asset_.size), .hash = std::move(asset_.hash), - .status = asset_.status == DistributedData::Asset::STATUS_NORMAL ? DistributedDB::AssetStatus::ABNORMAL - : DistributedDB::AssetStatus::NORMAL }; + .flag = ConvertToDBStatus(asset_).second, + .status = ConvertToDBStatus(asset_).first }; +} + +uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asset) +{ + if (asset.status == DistributedDB::AssetStatus::DOWNLOADING) { + return DistributedData::Asset::STATUS_DOWNLOADING; + } else if (asset.status == DistributedDB::AssetStatus::ABNORMAL){ + return DistributedData::Asset::STATUS_ABNORMAL; + } else { + switch (asset.flag) { + case static_cast(DistributedDB::AssetOpType::INSERT): + return DistributedData::Asset::STATUS_INSERT; + case static_cast(DistributedDB::AssetOpType::UPDATE): + return DistributedData::Asset::STATUS_UPDATE; + case static_cast(DistributedDB::AssetOpType::DELETE): + return DistributedData::Asset::STATUS_DELETE; + default: + return DistributedData::Asset::STATUS_UNKNOWN; + } + } } -uint32_t ValueProxy::Asset::ConvertDBStatus(const DistributedDB::Asset &asset) -{ - switch (asset.flag) { - case static_cast(DistributedDB::AssetOpType::INSERT): - return DistributedData::Asset::STATUS_INSERT; - case static_cast(DistributedDB::AssetOpType::UPDATE): - return DistributedData::Asset::STATUS_UPDATE; - case static_cast(DistributedDB::AssetOpType::DELETE): - return DistributedData::Asset::STATUS_DELETE; +std::pair ValueProxy::Asset::ConvertToDBStatus(const DistributedData::Asset &asset) +{ + switch (asset.status) { + case DistributedData::Asset::STATUS_NORMAL: + return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE}; + case DistributedData::Asset::STATUS_ABNORMAL: + return {DistributedDB::AssetStatus::ABNORMAL, DistributedDB::AssetOpType::NO_CHANGE};; + case DistributedData::Asset::STATUS_INSERT: + return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::INSERT}; + case DistributedData::Asset::STATUS_UPDATE: + return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::UPDATE}; + case DistributedData::Asset::STATUS_DELETE: + return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::DELETE}; + case DistributedData::Asset::STATUS_DOWNLOADING: + return {DistributedDB::AssetStatus::DOWNLOADING, DistributedDB::AssetOpType::NO_CHANGE}; default: - return DistributedData::Asset::STATUS_UNKNOWN; + return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE}; } } diff --git a/services/distributeddataservice/service/rdb/value_proxy.h b/services/distributeddataservice/service/rdb/value_proxy.h index 8fddf204..83790b76 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.h +++ b/services/distributeddataservice/service/rdb/value_proxy.h @@ -60,7 +60,8 @@ public: operator NativeRdb::AssetValue(); operator DistributedData::Asset(); operator DistributedDB::Asset(); - static uint32_t ConvertDBStatus(const DistributedDB::Asset &asset); + static uint32_t ConvertToDataStatus(const DistributedDB::Asset &asset); + static std::pair ConvertToDBStatus(const DistributedData::Asset &asset); private: DistributedData::Asset asset_; -- Gitee From 8dd76a80539cdd01e278860e74d39c533615ef16 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 01:20:28 +0800 Subject: [PATCH 243/437] update Signed-off-by: wanghuajian --- .../service/rdb/rdb_cloud_data_translate.cpp | 44 ++++++++++--------- .../service/rdb/value_proxy.cpp | 18 ++++---- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp index f280d31c..b5797938 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -142,29 +142,33 @@ size_t RdbCloudDataTranslate::ParserRawData(const uint8_t *data, size_t length, bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializable::json &node) const { - SetValue(node[GET_NAME(version)], asset_.version); - SetValue(node[GET_NAME(status)], asset_.status); - SetValue(node[GET_NAME(expiresTime)], asset_.timeStamp); - SetValue(node[GET_NAME(name)], asset_.name); - SetValue(node[GET_NAME(uri)], asset_.uri); - SetValue(node[GET_NAME(path)], asset_.path); - SetValue(node[GET_NAME(createTime)], asset_.createTime); - SetValue(node[GET_NAME(modifyTime)], asset_.modifyTime); - SetValue(node[GET_NAME(size)], asset_.size); - SetValue(node[GET_NAME(hash)], asset_.hash); - return true; + bool ret = true; + ret = SetValue(node[GET_NAME(version)], asset_.version) && ret; + ret = SetValue(node[GET_NAME(status)], asset_.status) && ret; + ret = SetValue(node[GET_NAME(expiresTime)], asset_.timeStamp) && ret; + ret = SetValue(node[GET_NAME(name)], asset_.name) && ret; + ret = SetValue(node[GET_NAME(uri)], asset_.uri) && ret; + ret = SetValue(node[GET_NAME(path)], asset_.path) && ret; + ret = SetValue(node[GET_NAME(createTime)], asset_.createTime) && ret; + ret = SetValue(node[GET_NAME(modifyTime)], asset_.modifyTime) && ret; + ret = SetValue(node[GET_NAME(size)], asset_.size) && ret; + ret = SetValue(node[GET_NAME(hash)], asset_.hash) && ret; + return ret; } bool RdbCloudDataTranslate::InnerAsset::Unmarshal(const OHOS::DistributedData::Serializable::json &node) { - bool flag = false; - flag = GetValue(node, GET_NAME(version), asset_.version) && GetValue(node, GET_NAME(status), asset_.status) && - GetValue(node, GET_NAME(expiresTime), asset_.timeStamp) && GetValue(node, GET_NAME(name), asset_.name) && - GetValue(node, GET_NAME(uri), asset_.uri) && GetValue(node, GET_NAME(path), asset_.path) && - GetValue(node, GET_NAME(createTime), asset_.createTime) && - GetValue(node, GET_NAME(modifyTime), asset_.modifyTime) && GetValue(node, GET_NAME(size), asset_.size) && - GetValue(node, GET_NAME(hash), asset_.hash); - - return flag; + bool ret = true; + ret = GetValue(node, GET_NAME(version), asset_.version) && ret; + ret = GetValue(node, GET_NAME(status), asset_.status) && ret; + ret = GetValue(node, GET_NAME(expiresTime), asset_.timeStamp) && ret; + ret = GetValue(node, GET_NAME(name), asset_.name) && ret; + ret = GetValue(node, GET_NAME(uri), asset_.uri) && ret; + ret = GetValue(node, GET_NAME(path), asset_.path) && ret; + ret = GetValue(node, GET_NAME(createTime), asset_.createTime) && ret; + ret = GetValue(node, GET_NAME(modifyTime), asset_.modifyTime) && ret; + ret = GetValue(node, GET_NAME(size), asset_.size) && ret; + ret = GetValue(node, GET_NAME(hash), asset_.hash) && ret; + return ret; } } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index b71ac7b9..281d29fc 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -204,7 +204,7 @@ uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asse { if (asset.status == DistributedDB::AssetStatus::DOWNLOADING) { return DistributedData::Asset::STATUS_DOWNLOADING; - } else if (asset.status == DistributedDB::AssetStatus::ABNORMAL){ + } else if (asset.status == DistributedDB::AssetStatus::ABNORMAL) { return DistributedData::Asset::STATUS_ABNORMAL; } else { switch (asset.flag) { @@ -220,23 +220,23 @@ uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asse } } -std::pair ValueProxy::Asset::ConvertToDBStatus(const DistributedData::Asset &asset) +std::pair ValueProxy::Asset::ConvertToDBStatus(const DistributedData::Asset &asset) { switch (asset.status) { case DistributedData::Asset::STATUS_NORMAL: - return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE}; + return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE }; case DistributedData::Asset::STATUS_ABNORMAL: - return {DistributedDB::AssetStatus::ABNORMAL, DistributedDB::AssetOpType::NO_CHANGE};; + return { DistributedDB::AssetStatus::ABNORMAL, DistributedDB::AssetOpType::NO_CHANGE }; case DistributedData::Asset::STATUS_INSERT: - return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::INSERT}; + return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::INSERT }; case DistributedData::Asset::STATUS_UPDATE: - return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::UPDATE}; + return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::UPDATE }; case DistributedData::Asset::STATUS_DELETE: - return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::DELETE}; + return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::DELETE }; case DistributedData::Asset::STATUS_DOWNLOADING: - return {DistributedDB::AssetStatus::DOWNLOADING, DistributedDB::AssetOpType::NO_CHANGE}; + return { DistributedDB::AssetStatus::DOWNLOADING, DistributedDB::AssetOpType::NO_CHANGE }; default: - return {DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE}; + return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE }; } } -- Gitee From 6cc923a43a185bb2ce2b2b9d533081b5faab09b9 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 10:22:11 +0800 Subject: [PATCH 244/437] update Signed-off-by: wanghuajian --- .../service/rdb/rdb_cloud_data_translate.cpp | 8 +++--- .../service/rdb/value_proxy.cpp | 26 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp index b5797938..d6293bd5 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -82,7 +82,8 @@ size_t RdbCloudDataTranslate::ParserRawData(const uint8_t *data, size_t length, std::vector alignData; alignData.assign(data, data + sizeof(ASSET_MAGIC)); used += sizeof(ASSET_MAGIC); - if (*(reinterpret_cast(alignData.data())) != ASSET_MAGIC) { + auto hostMagicWord = DistributedData::NetToHost(*(reinterpret_cast(alignData.data()))); + if (hostMagicWord != ASSET_MAGIC) { return 0; } @@ -116,7 +117,8 @@ size_t RdbCloudDataTranslate::ParserRawData(const uint8_t *data, size_t length, std::vector alignData; alignData.assign(data, data + sizeof(ASSETS_MAGIC)); used += sizeof(ASSETS_MAGIC); - if (*(reinterpret_cast(alignData.data())) != ASSETS_MAGIC) { + auto hostMagicWord = DistributedData::NetToHost(*(reinterpret_cast(alignData.data()))); + if (hostMagicWord != ASSETS_MAGIC) { return 0; } @@ -124,7 +126,7 @@ size_t RdbCloudDataTranslate::ParserRawData(const uint8_t *data, size_t length, return 0; } alignData.assign(data, data + sizeof(num)); - num = *(reinterpret_cast(alignData.data())); + num = DistributedData::NetToHost(*(reinterpret_cast(alignData.data()))); used += sizeof(num); uint16_t count = 0; while (used < length && count < num) { diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 281d29fc..9280d6f3 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -206,7 +206,7 @@ uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asse return DistributedData::Asset::STATUS_DOWNLOADING; } else if (asset.status == DistributedDB::AssetStatus::ABNORMAL) { return DistributedData::Asset::STATUS_ABNORMAL; - } else { + } else if (asset.status == DistributedDB::AssetStatus::NORMAL) { switch (asset.flag) { case static_cast(DistributedDB::AssetOpType::INSERT): return DistributedData::Asset::STATUS_INSERT; @@ -215,28 +215,36 @@ uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asse case static_cast(DistributedDB::AssetOpType::DELETE): return DistributedData::Asset::STATUS_DELETE; default: - return DistributedData::Asset::STATUS_UNKNOWN; + return DistributedData::Asset::STATUS_NORMAL; } } + return DistributedData::Asset::STATUS_UNKNOWN; } std::pair ValueProxy::Asset::ConvertToDBStatus(const DistributedData::Asset &asset) { switch (asset.status) { case DistributedData::Asset::STATUS_NORMAL: - return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE }; + return { static_cast(DistributedDB::AssetStatus::NORMAL), + static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; case DistributedData::Asset::STATUS_ABNORMAL: - return { DistributedDB::AssetStatus::ABNORMAL, DistributedDB::AssetOpType::NO_CHANGE }; + return { static_cast(DistributedDB::AssetStatus::ABNORMAL), + static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; case DistributedData::Asset::STATUS_INSERT: - return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::INSERT }; + return { static_cast(DistributedDB::AssetStatus::NORMAL), + static_cast(DistributedDB::AssetOpType::INSERT) }; case DistributedData::Asset::STATUS_UPDATE: - return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::UPDATE }; + return { static_cast(DistributedDB::AssetStatus::NORMAL), + static_cast(DistributedDB::AssetOpType::UPDATE) }; case DistributedData::Asset::STATUS_DELETE: - return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::DELETE }; + return { static_cast(DistributedDB::AssetStatus::NORMAL), + static_cast(DistributedDB::AssetOpType::DELETE) }; case DistributedData::Asset::STATUS_DOWNLOADING: - return { DistributedDB::AssetStatus::DOWNLOADING, DistributedDB::AssetOpType::NO_CHANGE }; + return { static_cast(DistributedDB::AssetStatus::DOWNLOADING), + static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; default: - return { DistributedDB::AssetStatus::NORMAL, DistributedDB::AssetOpType::NO_CHANGE }; + return { static_cast(DistributedDB::AssetStatus::NORMAL), + static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; } } -- Gitee From 1faa975f64a6f4dac0d65c5ab1cd622441d55097 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 10:36:11 +0800 Subject: [PATCH 245/437] update Signed-off-by: wanghuajian --- services/distributeddataservice/service/rdb/rdb_cloud.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index 5880d00d..aeaad1f9 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -15,6 +15,8 @@ #define LOG_TAG "RdbCloud" #include "rdb_cloud.h" + +#include "cloud/schema_meta.h" #include "log_print.h" #include "value_proxy.h" #include "utils/anonymous.h" @@ -76,6 +78,9 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v err = cursor->MoveToNext(); count--; } + DistributedData::Value cursorFlag; + cursor->Get(SchemaMeta::CURSOR_FIELD, cursorFlag); + extend[SchemaMeta::CURSOR_FIELD] = ValueProxy::Convert(std::move(cursorFlag)); if (cursor->IsEnd()) { ZLOGD("query end, table:%{public}s", Anonymous::Change(tableName).c_str()); return DBStatus::QUERY_END; -- Gitee From b707688b7d66a282806d979b75082d78a2c7d8c7 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 11:05:00 +0800 Subject: [PATCH 246/437] update Signed-off-by: wanghuajian --- .../service/rdb/rdb_cloud_data_translate.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp index d6293bd5..bd8d0db7 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -31,7 +31,8 @@ std::vector RdbCloudDataTranslate::AssetToBlob(const Asset &asset) auto data = Serializable::Marshall(innerAsset); uint16_t size; size = DistributedData::HostToNet((uint16_t)data.length()); - auto magicU8 = reinterpret_cast(const_cast(&ASSET_MAGIC)); + auto leMagic = DistributedData::HostToNet(ASSET_MAGIC); + auto magicU8 = reinterpret_cast(const_cast(&leMagic)); rawData.insert(rawData.end(), magicU8, magicU8 + sizeof(ASSET_MAGIC)); rawData.insert(rawData.end(), reinterpret_cast(&size), reinterpret_cast(&size) + sizeof(size)); @@ -43,7 +44,8 @@ std::vector RdbCloudDataTranslate::AssetsToBlob(const Assets &assets) { std::vector rawData; uint16_t num = uint16_t(assets.size()); - auto magicU8 = reinterpret_cast(const_cast(&ASSETS_MAGIC)); + auto leMagic = DistributedData::HostToNet(ASSETS_MAGIC); + auto magicU8 = reinterpret_cast(const_cast(&leMagic)); rawData.insert(rawData.end(), magicU8, magicU8 + sizeof(ASSETS_MAGIC)); rawData.insert(rawData.end(), reinterpret_cast(&num), reinterpret_cast(&num) + sizeof(num)); for (auto &asset : assets) { @@ -147,7 +149,7 @@ bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializa bool ret = true; ret = SetValue(node[GET_NAME(version)], asset_.version) && ret; ret = SetValue(node[GET_NAME(status)], asset_.status) && ret; - ret = SetValue(node[GET_NAME(expiresTime)], asset_.timeStamp) && ret; + ret = SetValue(node[GET_NAME(timeStamp)], asset_.timeStamp) && ret; ret = SetValue(node[GET_NAME(name)], asset_.name) && ret; ret = SetValue(node[GET_NAME(uri)], asset_.uri) && ret; ret = SetValue(node[GET_NAME(path)], asset_.path) && ret; @@ -163,7 +165,7 @@ bool RdbCloudDataTranslate::InnerAsset::Unmarshal(const OHOS::DistributedData::S bool ret = true; ret = GetValue(node, GET_NAME(version), asset_.version) && ret; ret = GetValue(node, GET_NAME(status), asset_.status) && ret; - ret = GetValue(node, GET_NAME(expiresTime), asset_.timeStamp) && ret; + ret = GetValue(node, GET_NAME(timeStamp), asset_.timeStamp) && ret; ret = GetValue(node, GET_NAME(name), asset_.name) && ret; ret = GetValue(node, GET_NAME(uri), asset_.uri) && ret; ret = GetValue(node, GET_NAME(path), asset_.path) && ret; -- Gitee From 0459a22383ef95c3fed9877445a4ddc2ec6739aa Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 11:29:27 +0800 Subject: [PATCH 247/437] update Signed-off-by: wanghuajian --- .../service/cloud/sync_manager.cpp | 11 +++-------- .../service/rdb/rdb_asset_loader.h | 4 ++-- .../service/rdb/rdb_cloud_data_translate.cpp | 5 ++--- .../service/rdb/rdb_cloud_data_translate.h | 2 +- .../service/rdb/value_proxy.cpp | 6 +++--- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 04940eb2..10471413 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -244,15 +244,10 @@ std::function SyncManager::GetSyncHandler() return; } auto dbMeta = schemaMeta.GetDataBase(storeInfo.storeName); - auto cloudDB = instance->ConnectCloudDB(meta.tokenId, dbMeta); - if (cloudDB == nullptr) { - ZLOGE("failed, no cloud DB <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, - dbMeta.name.c_str(), dbMeta.alias.c_str()); - return; - } + auto cloudDB = instance->ConnectCloudDB(storeInfo.tokenId, dbMeta); auto assetLoader = instance->ConnectAssetLoader(storeInfo.tokenId, dbMeta); - if (assetLoader == nullptr) { - ZLOGE("failed, no assetLoader <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, + if (cloudDB == nullptr || assetLoader == nullptr) { + ZLOGE("failed, no cloud DB or no assetLoader <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, dbMeta.name.c_str(), dbMeta.alias.c_str()); return; } diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.h b/services/distributeddataservice/service/rdb/rdb_asset_loader.h index e2214360..ab5ece73 100644 --- a/services/distributeddataservice/service/rdb/rdb_asset_loader.h +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.h @@ -27,7 +27,7 @@ public: using Type = DistributedDB::Type; using Asset = DistributedDB::Asset; using DBStatus = DistributedDB::DBStatus; - RdbAssetLoader(std::shared_ptr cloudAssetLoader); + explicit RdbAssetLoader(std::shared_ptr cloudAssetLoader); ~RdbAssetLoader() = default; @@ -40,4 +40,4 @@ private: std::shared_ptr assetLoader_; }; } // namespace OHOS::DistributedRdb -#endif //OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H \ No newline at end of file +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_ASSET_LOADER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp index bd8d0db7..648f48d6 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -29,8 +29,7 @@ std::vector RdbCloudDataTranslate::AssetToBlob(const Asset &asset) DataAsset dataAsset = ValueProxy::Asset(asset); InnerAsset innerAsset(dataAsset); auto data = Serializable::Marshall(innerAsset); - uint16_t size; - size = DistributedData::HostToNet((uint16_t)data.length()); + auto size = DistributedData::HostToNet((uint16_t)data.length()); auto leMagic = DistributedData::HostToNet(ASSET_MAGIC); auto magicU8 = reinterpret_cast(const_cast(&leMagic)); rawData.insert(rawData.end(), magicU8, magicU8 + sizeof(ASSET_MAGIC)); @@ -43,7 +42,7 @@ std::vector RdbCloudDataTranslate::AssetToBlob(const Asset &asset) std::vector RdbCloudDataTranslate::AssetsToBlob(const Assets &assets) { std::vector rawData; - uint16_t num = uint16_t(assets.size()); + auto num = DistributedData::HostToNet((uint16_t)assets.size()); auto leMagic = DistributedData::HostToNet(ASSETS_MAGIC); auto magicU8 = reinterpret_cast(const_cast(&leMagic)); rawData.insert(rawData.end(), magicU8, magicU8 + sizeof(ASSETS_MAGIC)); diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h index 6cf01cb8..f4d35043 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.h @@ -48,4 +48,4 @@ private: size_t ParserRawData(const uint8_t *data, size_t length, DataAssets &assets); }; } // namespace OHOS::DistributedRdb -#endif //OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_DATA_TRASLATE_H +#endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_CLOUD_DATA_TRASLATE_H diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 9280d6f3..d79b113c 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -137,7 +137,7 @@ ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) ValueProxy::Asset::Asset(DistributedDB::Asset asset) { - asset_ = DistributedData::Asset{ .version = asset.version, + asset_ = DistributedData::Asset { .version = asset.version, .status = ConvertToDataStatus(asset), .expiresTime = DistributedData::Asset::NO_EXPIRES_TIME, .id = std::move(asset.assetId), @@ -169,7 +169,7 @@ ValueProxy::Asset &ValueProxy::Asset::operator=(Asset &&proxy) noexcept ValueProxy::Asset::operator NativeRdb::AssetValue() { - return NativeRdb::AssetValue{ .version = asset_.version, + return NativeRdb::AssetValue { .version = asset_.version, .status = asset_.status, .name = std::move(asset_.name), .uri = std::move(asset_.uri), @@ -187,7 +187,7 @@ ValueProxy::Asset::operator DistributedData::Asset() ValueProxy::Asset::operator DistributedDB::Asset() { - return DistributedDB::Asset{ .version = asset_.version, + return DistributedDB::Asset { .version = asset_.version, .name = std::move(asset_.name), .assetId = std::move(asset_.id), .subpath = std::move(asset_.path), -- Gitee From 3a91d103eec1cd6b38d9dccf272e609021942917 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 12:11:49 +0800 Subject: [PATCH 248/437] update Signed-off-by: wanghuajian --- .../service/rdb/rdb_asset_loader.h | 2 +- .../service/rdb/rdb_cloud_data_translate.cpp | 8 ++--- .../service/rdb/value_proxy.cpp | 16 +++++----- .../service/test/value_proxy_test.cpp | 30 +++++++++---------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.h b/services/distributeddataservice/service/rdb/rdb_asset_loader.h index ab5ece73..0197afbf 100644 --- a/services/distributeddataservice/service/rdb/rdb_asset_loader.h +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.h @@ -22,7 +22,7 @@ #include "error/general_error.h" namespace OHOS::DistributedRdb { -class RdbAssetLoader : public DistributedDB::IAssetLoader{ +class RdbAssetLoader : public DistributedDB::IAssetLoader { public: using Type = DistributedDB::Type; using Asset = DistributedDB::Asset; diff --git a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp index 648f48d6..9f7981f0 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud_data_translate.cpp @@ -87,14 +87,12 @@ size_t RdbCloudDataTranslate::ParserRawData(const uint8_t *data, size_t length, if (hostMagicWord != ASSET_MAGIC) { return 0; } - if (sizeof(size) > length - used) { return 0; } alignData.assign(data + used, data + used + sizeof(size)); used += sizeof(size); size = DistributedData::NetToHost(*(reinterpret_cast(alignData.data()))); - if (size > length - used) { return 0; } @@ -148,7 +146,8 @@ bool RdbCloudDataTranslate::InnerAsset::Marshal(OHOS::DistributedData::Serializa bool ret = true; ret = SetValue(node[GET_NAME(version)], asset_.version) && ret; ret = SetValue(node[GET_NAME(status)], asset_.status) && ret; - ret = SetValue(node[GET_NAME(timeStamp)], asset_.timeStamp) && ret; + ret = SetValue(node[GET_NAME(expiresTime)], asset_.expiresTime) && ret; + ret = SetValue(node[GET_NAME(id)], asset_.id) && ret; ret = SetValue(node[GET_NAME(name)], asset_.name) && ret; ret = SetValue(node[GET_NAME(uri)], asset_.uri) && ret; ret = SetValue(node[GET_NAME(path)], asset_.path) && ret; @@ -164,7 +163,8 @@ bool RdbCloudDataTranslate::InnerAsset::Unmarshal(const OHOS::DistributedData::S bool ret = true; ret = GetValue(node, GET_NAME(version), asset_.version) && ret; ret = GetValue(node, GET_NAME(status), asset_.status) && ret; - ret = GetValue(node, GET_NAME(timeStamp), asset_.timeStamp) && ret; + ret = GetValue(node, GET_NAME(expiresTime), asset_.expiresTime) && ret; + ret = GetValue(node, GET_NAME(id), asset_.id) && ret; ret = GetValue(node, GET_NAME(name), asset_.name) && ret; ret = GetValue(node, GET_NAME(uri), asset_.uri) && ret; ret = GetValue(node, GET_NAME(path), asset_.path) && ret; diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index d79b113c..7de03009 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -122,17 +122,17 @@ ValueProxy::Asset::Asset(DistributedData::Asset asset) ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) { - asset_ = DistributedData::Asset{ .version = asset.version, + asset_ = DistributedData::Asset { .version = asset.version, .status = asset.status, - .expiresTime = asset.timeStamp, - .id = "", + .expiresTime = asset.expiresTime, + .id = asset.id, .name = std::move(asset.name), .uri = std::move(asset.uri), - .path = std::move(asset.path), .createTime = std::move(asset.createTime), .modifyTime = std::move(asset.modifyTime), .size = std::move(asset.size), - .hash = std::move(asset.hash) }; + .hash = std::move(asset.hash), + .path = std::move(asset.path) }; } ValueProxy::Asset::Asset(DistributedDB::Asset asset) @@ -171,13 +171,15 @@ ValueProxy::Asset::operator NativeRdb::AssetValue() { return NativeRdb::AssetValue { .version = asset_.version, .status = asset_.status, + .expiresTime = asset_.expiresTime, + .id = std::move(asset_.id), .name = std::move(asset_.name), .uri = std::move(asset_.uri), - .path = std::move(asset_.path), .createTime = std::move(asset_.createTime), .modifyTime = std::move(asset_.modifyTime), .size = std::move(asset_.size), - .hash = std::move(asset_.hash) }; + .hash = std::move(asset_.hash), + .path = std::move(asset_.path) }; } ValueProxy::Asset::operator DistributedData::Asset() diff --git a/services/distributeddataservice/service/test/value_proxy_test.cpp b/services/distributeddataservice/service/test/value_proxy_test.cpp index 51bee0c7..814bcd5e 100644 --- a/services/distributeddataservice/service/test/value_proxy_test.cpp +++ b/services/distributeddataservice/service/test/value_proxy_test.cpp @@ -132,15 +132,15 @@ HWTEST_F(ValueProxyTest, ConvertIntMapTest, TestSize.Level0) */ HWTEST_F(ValueProxyTest, ConvertAssetMapGaussDB2NormalTest, TestSize.Level0) { - DistributedDB::Asset dbAsset0{ .name = "dbname", .uri = "dburi" }; - DistributedDB::Asset dbAsset1{ .name = "dbname", .uri = "dburi" }; + DistributedDB::Asset dbAsset0 { .name = "dbname", .uri = "dburi" }; + DistributedDB::Asset dbAsset1 { .name = "dbname", .uri = "dburi" }; std::map dbMap{ { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; OHOS::DistributedData::VBucket transferredAsset = ValueProxy::Convert(dbMap); ASSERT_EQ(transferredAsset.size(), 2); auto asset = std::get(transferredAsset.find("asset0")->second); ASSERT_EQ(asset.name, "dbname"); - DistributedDB::Assets dbAssets{ dbAsset0, dbAsset1 }; + DistributedDB::Assets dbAssets { dbAsset0, dbAsset1 }; std::map dbAssetsMap{ {"dbAssets", dbAssets} }; OHOS::DistributedData::VBucket transferredAssets = ValueProxy::Convert(dbAssetsMap); ASSERT_EQ(transferredAssets.size(), 1); @@ -161,15 +161,15 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapNormal2GaussDBTest, TestSize.Level0) { using NormalAsset = OHOS::DistributedData::Asset; using NormalAssets = OHOS::DistributedData::Assets; - NormalAsset nAsset0{ .name = "name", .uri = "uri" }; - NormalAsset nAsset1{ .name = "name", .uri = "uri" }; + NormalAsset nAsset0 { .name = "name", .uri = "uri" }; + NormalAsset nAsset1 { .name = "name", .uri = "uri" }; std::map nMap{ { "asset0", nAsset0 }, { "asset1", nAsset1 } }; DistributedDB::VBucket transferredAsset = ValueProxy::Convert(nMap); ASSERT_EQ(transferredAsset.size(), 2); auto asset = std::get(transferredAsset.find("asset0")->second); ASSERT_EQ(asset.name, "name"); - NormalAssets nAssets{ nAsset0, nAsset1 }; + NormalAssets nAssets { nAsset0, nAsset1 }; std::map nAssetsMap{ { "Assets", nAssets } }; DistributedDB::VBucket transferredAssets = ValueProxy::Convert(nAssetsMap); ASSERT_EQ(transferredAssets.size(), 1); @@ -190,15 +190,15 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapRdb2NormalTest, TestSize.Level0) { using RdbAsset = OHOS::NativeRdb::AssetValue; using RdbAssets = std::vector; - RdbAsset dbAsset0{ .name = "dbname", .uri = "dburi" }; - RdbAsset dbAsset1{ .name = "dbname", .uri = "dburi" }; + RdbAsset dbAsset0 { .name = "dbname", .uri = "dburi" }; + RdbAsset dbAsset1 { .name = "dbname", .uri = "dburi" }; std::map dbMap{ { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; OHOS::DistributedData::VBucket transferredAsset = ValueProxy::Convert(dbMap); ASSERT_EQ(transferredAsset.size(), 2); auto asset = std::get(transferredAsset.find("asset0")->second); ASSERT_EQ(asset.name, "dbname"); - RdbAssets dbAssets{ dbAsset0, dbAsset1 }; + RdbAssets dbAssets { dbAsset0, dbAsset1 }; std::map dbAssetsMap{ {"dbAssets", dbAssets} }; OHOS::DistributedData::VBucket transferredAssets = ValueProxy::Convert(dbAssetsMap); ASSERT_EQ(transferredAssets.size(), 1); @@ -221,9 +221,9 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapNormal2RdbTest, TestSize.Level0) using RdbAssets = std::vector; using NormalAsset = OHOS::DistributedData::Asset; using NormalAssets = OHOS::DistributedData::Assets; - NormalAsset nAsset0{ .name = "name", .uri = "uri" }; - NormalAsset nAsset1{ .name = "name", .uri = "uri" }; - std::map nMap{ { "asset0", nAsset0 }, { "asset1", nAsset1 } }; + NormalAsset nAsset0 { .name = "name", .uri = "uri" }; + NormalAsset nAsset1 { .name = "name", .uri = "uri" }; + std::map nMap { { "asset0", nAsset0 }, { "asset1", nAsset1 } }; OHOS::NativeRdb::ValuesBucket transferredAsset = ValueProxy::Convert(nMap); ASSERT_EQ(transferredAsset.Size(), 2); OHOS::NativeRdb::ValueObject rdbObject; @@ -232,8 +232,8 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapNormal2RdbTest, TestSize.Level0) rdbObject.GetAsset(rdbAsset); ASSERT_EQ(rdbAsset.name, "name"); - NormalAssets nAssets{ nAsset0, nAsset1 }; - std::map nAssetsMap{ { "Assets", nAssets } }; + NormalAssets nAssets { nAsset0, nAsset1 }; + std::map nAssetsMap { { "Assets", nAssets } }; OHOS::NativeRdb::ValuesBucket transferredAssets = ValueProxy::Convert(nAssetsMap); ASSERT_EQ(transferredAssets.Size(), 1); OHOS::NativeRdb::ValueObject rdbObject2; @@ -244,4 +244,4 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapNormal2RdbTest, TestSize.Level0) auto dataAsset = rdbAssets.begin(); ASSERT_EQ(dataAsset->name, "name"); } -} +} // namespace Test -- Gitee From eb85bf6db232cda6eb7fb31882d05359558d713b Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 12:25:32 +0800 Subject: [PATCH 249/437] update Signed-off-by: wanghuajian --- .../service/test/value_proxy_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/test/value_proxy_test.cpp b/services/distributeddataservice/service/test/value_proxy_test.cpp index 814bcd5e..66767e32 100644 --- a/services/distributeddataservice/service/test/value_proxy_test.cpp +++ b/services/distributeddataservice/service/test/value_proxy_test.cpp @@ -134,14 +134,14 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapGaussDB2NormalTest, TestSize.Level0) { DistributedDB::Asset dbAsset0 { .name = "dbname", .uri = "dburi" }; DistributedDB::Asset dbAsset1 { .name = "dbname", .uri = "dburi" }; - std::map dbMap{ { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; + std::map dbMap { { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; OHOS::DistributedData::VBucket transferredAsset = ValueProxy::Convert(dbMap); ASSERT_EQ(transferredAsset.size(), 2); auto asset = std::get(transferredAsset.find("asset0")->second); ASSERT_EQ(asset.name, "dbname"); DistributedDB::Assets dbAssets { dbAsset0, dbAsset1 }; - std::map dbAssetsMap{ {"dbAssets", dbAssets} }; + std::map dbAssetsMap { {"dbAssets", dbAssets} }; OHOS::DistributedData::VBucket transferredAssets = ValueProxy::Convert(dbAssetsMap); ASSERT_EQ(transferredAssets.size(), 1); auto assets = std::get(transferredAssets.find("dbAssets")->second); @@ -163,14 +163,14 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapNormal2GaussDBTest, TestSize.Level0) using NormalAssets = OHOS::DistributedData::Assets; NormalAsset nAsset0 { .name = "name", .uri = "uri" }; NormalAsset nAsset1 { .name = "name", .uri = "uri" }; - std::map nMap{ { "asset0", nAsset0 }, { "asset1", nAsset1 } }; + std::map nMap { { "asset0", nAsset0 }, { "asset1", nAsset1 } }; DistributedDB::VBucket transferredAsset = ValueProxy::Convert(nMap); ASSERT_EQ(transferredAsset.size(), 2); auto asset = std::get(transferredAsset.find("asset0")->second); ASSERT_EQ(asset.name, "name"); NormalAssets nAssets { nAsset0, nAsset1 }; - std::map nAssetsMap{ { "Assets", nAssets } }; + std::map nAssetsMap { { "Assets", nAssets } }; DistributedDB::VBucket transferredAssets = ValueProxy::Convert(nAssetsMap); ASSERT_EQ(transferredAssets.size(), 1); auto assets = std::get(transferredAssets.find("Assets")->second); @@ -192,14 +192,14 @@ HWTEST_F(ValueProxyTest, ConvertAssetMapRdb2NormalTest, TestSize.Level0) using RdbAssets = std::vector; RdbAsset dbAsset0 { .name = "dbname", .uri = "dburi" }; RdbAsset dbAsset1 { .name = "dbname", .uri = "dburi" }; - std::map dbMap{ { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; + std::map dbMap { { "asset0", dbAsset0 }, { "asset1", dbAsset1 } }; OHOS::DistributedData::VBucket transferredAsset = ValueProxy::Convert(dbMap); ASSERT_EQ(transferredAsset.size(), 2); auto asset = std::get(transferredAsset.find("asset0")->second); ASSERT_EQ(asset.name, "dbname"); RdbAssets dbAssets { dbAsset0, dbAsset1 }; - std::map dbAssetsMap{ {"dbAssets", dbAssets} }; + std::map dbAssetsMap { {"dbAssets", dbAssets} }; OHOS::DistributedData::VBucket transferredAssets = ValueProxy::Convert(dbAssetsMap); ASSERT_EQ(transferredAssets.size(), 1); auto assets = std::get(transferredAssets.find("dbAssets")->second); -- Gitee From 2b69a8d6159267544a96ea9a8a28ef40b304cf4c Mon Sep 17 00:00:00 2001 From: hanlu Date: Mon, 19 Jun 2023 15:27:59 +0800 Subject: [PATCH 250/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 2 +- .../service/data_share/data/published_data.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 3cfa9be8..a3cb46ed 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -103,7 +103,7 @@ PublishedDataNode::PublishedDataNode(const std::string &key, const std::string & PublishedDataNode::PublishedDataNode() : VersionData(-1) {} -int32_t PublishedData::Query(const std::string &filter, std::variant, std::string> &publishedData) +int32_t PublishedData::Query(const std::string &filter, PublishedDataNode::Data &publishedData) { auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index 50a5aede..aba9ee9f 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -22,7 +22,7 @@ namespace OHOS::DataShare { class PublishedDataNode final : public VersionData { public: - using Data = std::variant, std::string>; + using Data = std::variant, std::string>; PublishedDataNode(); PublishedDataNode(const std::string &key, const std::string &bundleName, int64_t subscriberId, const int32_t userId, const Data &value); @@ -43,7 +43,7 @@ public: static std::vector Query(const std::string &bundleName, int32_t userId); static void Delete(const std::string &bundleName, const int32_t userId); static void ClearAging(); - static int32_t Query(const std::string &filter, std::variant, std::string> &publishedData); + static int32_t Query(const std::string &filter, PublishedDataNode::Data &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); PublishedData(const PublishedDataNode &node, const int version); ~PublishedData() = default; -- Gitee From f738324e64494e5c5afc14b4be1823f908356897 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 15:34:46 +0800 Subject: [PATCH 251/437] update Signed-off-by: wanghuajian --- .../framework/include/store/general_value.h | 2 +- services/distributeddataservice/service/rdb/value_proxy.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/framework/include/store/general_value.h b/services/distributeddataservice/framework/include/store/general_value.h index 07da1d1f..c482b940 100644 --- a/services/distributeddataservice/framework/include/store/general_value.h +++ b/services/distributeddataservice/framework/include/store/general_value.h @@ -68,11 +68,11 @@ struct Asset { std::string id; std::string name; std::string uri; - std::string path; std::string createTime; std::string modifyTime; std::string size; std::string hash; + std::string path; }; struct GenQuery { diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 7de03009..db4ef2fe 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -146,7 +146,8 @@ ValueProxy::Asset::Asset(DistributedDB::Asset asset) .createTime = std::move(asset.createTime), .modifyTime = std::move(asset.modifyTime), .size = std::move(asset.size), - .hash = std::move(asset.hash) }; + .hash = std::move(asset.hash), + .path = std::move(asset.subpath) }; } ValueProxy::Asset &ValueProxy::Asset::operator=(const Asset &proxy) -- Gitee From 2110b25e1fe7ba4779411c661148fc328309bd03 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 15:53:51 +0800 Subject: [PATCH 252/437] update Signed-off-by: wanghuajian --- .../distributeddataservice/service/cloud/sync_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 10471413..f2da0460 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -244,8 +244,8 @@ std::function SyncManager::GetSyncHandler() return; } auto dbMeta = schemaMeta.GetDataBase(storeInfo.storeName); - auto cloudDB = instance->ConnectCloudDB(storeInfo.tokenId, dbMeta); - auto assetLoader = instance->ConnectAssetLoader(storeInfo.tokenId, dbMeta); + auto cloudDB = instance->ConnectCloudDB(meta.tokenId, dbMeta); + auto assetLoader = instance->ConnectAssetLoader(meta.tokenId, dbMeta); if (cloudDB == nullptr || assetLoader == nullptr) { ZLOGE("failed, no cloud DB or no assetLoader <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, dbMeta.name.c_str(), dbMeta.alias.c_str()); -- Gitee From ad4bddc556d7bc71ccaa659c08f18ed28ccade45 Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Mon, 19 Jun 2023 16:12:37 +0800 Subject: [PATCH 253/437] modify build config Signed-off-by: ding_dong_dong --- bundle.json | 40 ++++++++++--------- .../distributeddataservice/service/BUILD.gn | 1 - 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/bundle.json b/bundle.json index c8b8c56e..683a81f1 100644 --- a/bundle.json +++ b/bundle.json @@ -51,35 +51,39 @@ ], "deps": { "components": [ - "libuv", - "common_event_service", + "ability_base", + "ability_runtime", + "access_token", "bundle_framework", - "safwk", - "zlib", - "init", - "os_account", "common", - "samgr", + "common_event_service", + "c_utils", "dataclassification", + "data_share", + "device_auth", + "device_manager", "dsoftbus", - "jsoncpp", + "hisysevent_native", "hitrace_native", - "access_token", - "huks", - "ability_base", - "ability_runtime", "hiviewdfx_hilog_native", - "hisysevent_native", - "device_auth", + "huks", + "init", + "kv_store", "ipc", - "napi" + "napi", + "os_account", + "relational_store", + "safwk", + "samgr" ], "third_party": [ - "uv_static", + "cjson", + "openssl", "sqlite", + "libuv", "libz", "jsoncpp", - "libcrypto_shared" + "zlib" ] }, "build": { @@ -98,4 +102,4 @@ ] } } -} +} \ No newline at end of file diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index d55ad586..d532c0e9 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -107,7 +107,6 @@ ohos_shared_library("distributeddatasvc") { deps = [ "${kv_store_distributeddb_path}:distributeddb", - "${relational_store_path}/interfaces/inner_api/cloud_data:cloud_data_inner", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter:distributeddata_adapter", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/adapter/utils:distributeddata_utils_static", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:distributeddatasvcfwk", -- Gitee From 259658c9109d9b89e52dec73654fcbb03291b205 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 19 Jun 2023 19:39:32 +0800 Subject: [PATCH 254/437] schema add error filed Signed-off-by: wanghuajian --- .../distributeddataservice/framework/include/cloud/schema_meta.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/framework/include/cloud/schema_meta.h b/services/distributeddataservice/framework/include/cloud/schema_meta.h index 49c15e18..298a3393 100644 --- a/services/distributeddataservice/framework/include/cloud/schema_meta.h +++ b/services/distributeddataservice/framework/include/cloud/schema_meta.h @@ -54,6 +54,7 @@ public: static constexpr const char *CREATE_FIELD = "#_createTime"; static constexpr const char *MODIFY_FIELD = "#_modifyTime"; static constexpr const char *CURSOR_FIELD = "#_cursor"; + static constexpr const char *ERROR_FIELD = "#_error"; int32_t version = 0; std::string bundleName; std::vector databases; -- Gitee From 05e585d8fe67436dd45fda7a73befd1caaef6f76 Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 20 Jun 2023 16:03:41 +0800 Subject: [PATCH 255/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 5 +++-- .../published_data_subscriber_manager.cpp | 13 +++++++++++++ .../published_data_subscriber_manager.h | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index a3cb46ed..24baca6f 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -16,6 +16,7 @@ #include "published_data.h" #include "log_print.h" +#include "subscriber_managers/published_data_subscriber_manager.h" namespace OHOS::DataShare { bool PublishedData::HasVersion() const @@ -171,8 +172,8 @@ void PublishedData::ClearAging() ZLOGE("Unmarshall %{public}s failed", result.c_str()); continue; } - - if (data.timestamp < lastValidTime) { + if (data.timestamp < lastValidTime && PublishedDataSubscriberManager::GetInstance().GetCount(PublishedDataKey( + data.key, data.bundleName, data.subscriberId)) == 0) { status = delegate->Delete(KvDBDelegate::DATA_TABLE, Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId), data.userId)); if (status != E_OK) { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index 37bdd915..fbcb92d6 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -80,6 +80,8 @@ int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, const ui publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { + ZLOGI("delete publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), + callerTokenId); it = value.erase(it); } else { it++; @@ -175,11 +177,22 @@ void PublishedDataSubscriberManager::PutInto( } } } + void PublishedDataSubscriberManager::Clear() { publishedDataCache.Clear(); } +int PublishedDataSubscriberManager::GetCount(const PublishedDataKey &key) +{ + int count = 0; + publishedDataCache.ComputeIfPresent(key, [&count](const auto &key, std::vector &value) { + count = value.size(); + return true; + }); + return count; +} + PublishedDataKey::PublishedDataKey(const std::string &key, const std::string &bundle, const int64_t subscriberId) : key(key), bundleName(bundle), subscriberId(subscriberId) { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index f4dc24e2..4e078165 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -49,7 +49,7 @@ public: void Emit(const std::vector &keys, const int32_t userId, const std::string &ownerBundleName, const sptr observer = nullptr); void Clear(); - + int GetCount(const PublishedDataKey &key); private: struct ObserverNode { ObserverNode(const sptr &observer, uint32_t callerTokenId); -- Gitee From 3fa2221aa36ffb2d85607038cb67a7348d939f64 Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 20 Jun 2023 16:09:08 +0800 Subject: [PATCH 256/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 24baca6f..68605579 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -172,8 +172,8 @@ void PublishedData::ClearAging() ZLOGE("Unmarshall %{public}s failed", result.c_str()); continue; } - if (data.timestamp < lastValidTime && PublishedDataSubscriberManager::GetInstance().GetCount(PublishedDataKey( - data.key, data.bundleName, data.subscriberId)) == 0) { + if (data.timestamp < lastValidTime && PublishedDataSubscriberManager::GetInstance() + .GetCount(PublishedDataKey(data.key, data.bundleName, data.subscriberId)) == 0) { status = delegate->Delete(KvDBDelegate::DATA_TABLE, Id(PublishedData::GenId(data.key, data.bundleName, data.subscriberId), data.userId)); if (status != E_OK) { -- Gitee From 75e8a7746f427b88f98ddcf2260a1fd2032976c8 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 21 Jun 2023 17:22:28 +0800 Subject: [PATCH 257/437] cloud sync retry test Signed-off-by: zuojiangjiang --- .../framework/cloud/sync_event.cpp | 10 +- .../framework/include/cloud/sync_event.h | 4 +- .../service/cloud/sync_manager.cpp | 140 ++++++++++++------ .../service/cloud/sync_manager.h | 24 ++- .../service/rdb/rdb_general_store.cpp | 8 - .../service/rdb/rdb_syncer.cpp | 4 +- 6 files changed, 122 insertions(+), 68 deletions(-) diff --git a/services/distributeddataservice/framework/cloud/sync_event.cpp b/services/distributeddataservice/framework/cloud/sync_event.cpp index 7c2d3d93..f165e4f7 100644 --- a/services/distributeddataservice/framework/cloud/sync_event.cpp +++ b/services/distributeddataservice/framework/cloud/sync_event.cpp @@ -16,8 +16,8 @@ #include "cloud/sync_event.h" namespace OHOS::DistributedData { -SyncEvent::EventInfo::EventInfo(int32_t mode, int32_t wait, std::shared_ptr query, GenAsync async) - : mode_(mode), wait_(wait), query_(std::move(query)), asyncDetail_(std::move(async)) +SyncEvent::EventInfo::EventInfo(int32_t mode, int32_t wait, bool retry, std::shared_ptr query, GenAsync async) + : retry_(retry), mode_(mode), wait_(wait), query_(std::move(query)), asyncDetail_(std::move(async)) { } @@ -31,6 +31,7 @@ SyncEvent::EventInfo &SyncEvent::EventInfo::operator=(SyncEvent::EventInfo &&inf if (this == &info) { return *this; } + retry_ = info.retry_; mode_ = info.mode_; wait_ = info.wait_; query_ = std::move(info.query_); @@ -58,6 +59,11 @@ int32_t SyncEvent::GetWait() const return info_.wait_; } +bool SyncEvent::AutoRetry() const +{ + return info_.retry_; +} + std::shared_ptr SyncEvent::GetQuery() const { return info_.query_; diff --git a/services/distributeddataservice/framework/include/cloud/sync_event.h b/services/distributeddataservice/framework/include/cloud/sync_event.h index 351a919a..fb25f1a3 100644 --- a/services/distributeddataservice/framework/include/cloud/sync_event.h +++ b/services/distributeddataservice/framework/include/cloud/sync_event.h @@ -23,13 +23,14 @@ class API_EXPORT SyncEvent : public CloudEvent { public: class EventInfo { public: - API_EXPORT EventInfo(int32_t mode, int32_t wait, std::shared_ptr query, GenAsync async); + API_EXPORT EventInfo(int32_t mode, int32_t wait, bool retry, std::shared_ptr query, GenAsync async); API_EXPORT EventInfo(EventInfo &&info) noexcept; EventInfo(const EventInfo &info) = default; API_EXPORT EventInfo &operator=(EventInfo &&info) noexcept; EventInfo &operator=(const EventInfo &info) = default; private: friend SyncEvent; + bool retry_ = false; int32_t mode_ = -1; int32_t wait_ = 0; std::shared_ptr query_; @@ -39,6 +40,7 @@ public: ~SyncEvent() override = default; int32_t GetMode() const; int32_t GetWait() const; + bool AutoRetry() const; std::shared_ptr GetQuery() const; GenAsync GetAsyncDetail() const; diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index f2da0460..e3b020e2 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -28,12 +28,15 @@ namespace OHOS::CloudData { using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; +using Defer = EventCenter::Defer; +std::atomic SyncManager::genId_ = 0; SyncManager::SyncInfo::SyncInfo(int32_t user, const std::string &bundleName, const Store &store, const Tables &tables) : user_(user), bundleName_(bundleName) { if (!store.empty()) { tables_[store] = tables; } + syncId_ = SyncManager::GenerateId(user); } SyncManager::SyncInfo::SyncInfo(int32_t user, const std::string &bundleName, const Stores &stores) @@ -42,12 +45,14 @@ SyncManager::SyncInfo::SyncInfo(int32_t user, const std::string &bundleName, con for (auto &store : stores) { tables_[store] = {}; } + syncId_ = SyncManager::GenerateId(user); } SyncManager::SyncInfo::SyncInfo(int32_t user, const std::string &bundleName, const MutliStoreTables &tables) : user_(user), bundleName_(bundleName) { tables_ = tables; + syncId_ = SyncManager::GenerateId(user); } void SyncManager::SyncInfo::SetMode(int32_t mode) @@ -70,7 +75,7 @@ void SyncManager::SyncInfo::SetQuery(std::shared_ptr query) query_ = query; } -void SyncManager::SyncInfo::SetError(int32_t code) +void SyncManager::SyncInfo::SetError(int32_t code) const { if (async_) { GenDetails details; @@ -137,7 +142,7 @@ int32_t SyncManager::DoCloudSync(SyncInfo syncInfo) return E_NOT_INIT; } - actives_.Compute(GenSyncId(syncInfo.user_), [this, &syncInfo](const uint64_t &key, TaskId &taskId) mutable { + actives_.Compute(GenerateId(syncInfo.user_), [this, &syncInfo](const uint64_t &key, TaskId &taskId) mutable { taskId = executor_->Execute(GetSyncTask(0, GenSyncRef(key), std::move(syncInfo))); return true; }); @@ -163,7 +168,7 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf { retry++; return [this, retry, ref = std::move(ref), info = std::move(syncInfo)]() mutable { - EventCenter::Defer defer(GetSyncHandler(), CloudEvent::CLOUD_SYNC); + activeInfos_.Erase(info.syncId_); CloudInfo cloud; cloud.user = info.user_; if (!MetaDataManager::GetInstance().LoadMeta(cloud.GetKey(), cloud, true)) { @@ -180,11 +185,14 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf std::vector schemas; auto key = cloud.GetSchemaPrefix(info.bundleName_); + auto retryer = GetRetryer(retry, info); if (!MetaDataManager::GetInstance().LoadMeta(key, schemas, true)) { - DoRetry(retry, std::move(info)); + UpdateSchema(info); + retryer(RETRY_INTERVAL, E_RETRY_TIMEOUT); return; } + Defer defer(GetSyncHandler(std::move(retryer)), CloudEvent::CLOUD_SYNC); for (auto &schema : schemas) { if (!cloud.IsOn(schema.bundleName)) { continue; @@ -198,24 +206,18 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf storeInfo.instanceId = cloud.apps[schema.bundleName].instanceId; auto query = info.GenerateQuery(database.name, database.GetTableNames()); auto evt = std::make_unique(std::move(storeInfo), - SyncEvent::EventInfo { info.mode_, info.wait_, std::move(query), info.async_ }); + SyncEvent::EventInfo{ info.mode_, info.wait_, false, std::move(query), info.async_ }); EventCenter::GetInstance().PostEvent(std::move(evt)); } } }; } -std::function SyncManager::GetSyncHandler() +std::function SyncManager::GetSyncHandler(Retryer retryer) { - return [](const Event &event) { + return [retryer](const Event &event) { auto &evt = static_cast(event); auto &storeInfo = evt.GetStoreInfo(); - auto instance = CloudServer::GetInstance(); - if (instance == nullptr) { - ZLOGD("not support cloud sync"); - return; - } - StoreMetaData meta; meta.storeId = storeInfo.storeName; meta.bundleName = storeInfo.bundleName; @@ -227,35 +229,17 @@ std::function SyncManager::GetSyncHandler() meta.GetStoreAlias().c_str()); return; } - auto store = AutoCache::GetInstance().GetStore(meta, {}); + auto store = GetStore(meta, storeInfo.user); if (store == nullptr) { ZLOGE("store null, storeId:%{public}s", meta.GetStoreAlias().c_str()); return; } - if (!store->IsBound()) { - CloudInfo info; - info.user = storeInfo.user; - SchemaMeta schemaMeta; - std::string schemaKey = info.GetSchemaKey(storeInfo.bundleName, storeInfo.instanceId); - if (!MetaDataManager::GetInstance().LoadMeta(std::move(schemaKey), schemaMeta, true)) { - ZLOGE("failed, no schema bundleName:%{public}s, storeId:%{public}s", storeInfo.bundleName.c_str(), - Anonymous::Change(storeInfo.storeName).c_str()); - return; - } - auto dbMeta = schemaMeta.GetDataBase(storeInfo.storeName); - auto cloudDB = instance->ConnectCloudDB(meta.tokenId, dbMeta); - auto assetLoader = instance->ConnectAssetLoader(meta.tokenId, dbMeta); - if (cloudDB == nullptr || assetLoader == nullptr) { - ZLOGE("failed, no cloud DB or no assetLoader <0x%{public}x %{public}s<->%{public}s>", storeInfo.tokenId, - dbMeta.name.c_str(), dbMeta.alias.c_str()); - return; - } - store->Bind(dbMeta, {cloudDB, assetLoader}); - } ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), - Anonymous::Change(storeInfo.storeName).c_str()); - store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); + meta.GetStoreAlias().c_str()); + auto status = store->Sync( + { SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); + retryer(status == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, status); }; } @@ -269,15 +253,44 @@ std::function SyncManager::GetClientChangeHandler() syncInfo.SetWait(evt.GetWait()); syncInfo.SetAsyncDetail(evt.GetAsyncDetail()); syncInfo.SetQuery(evt.GetQuery()); - auto task = GetSyncTask(RETRY_TIMES, RefCount(), std::move(syncInfo)); + auto times = evt.AutoRetry() ? RETRY_TIMES - CLIENT_RETRY_TIMES : RETRY_TIMES; + auto task = GetSyncTask(times, RefCount(), std::move(syncInfo)); task(); }; } -uint64_t SyncManager::GenSyncId(int32_t user) +SyncManager::Retryer SyncManager::GetRetryer(int32_t retry, const SyncInfo &syncInfo) +{ + if (retry >= RETRY_TIMES) { + return [info = SyncInfo(syncInfo)](Duration, int32_t code) mutable { + if (code == E_OK) { + return true; + } + info.SetError(code); + return true; + }; + } + return [this, retry, info = SyncInfo(syncInfo)](Duration interval, int32_t code) mutable { + if (code == E_OK) { + return true; + } + + activeInfos_.ComputeIfAbsent(info.syncId_, [this, retry, interval, &info](uint64_t key) mutable { + auto syncId = GenerateId(info.user_); + actives_.Compute(syncId, [this, retry, interval, &info](const uint64_t &key, TaskId &value) mutable { + value = executor_->Schedule(interval, GetSyncTask(retry, GenSyncRef(key), std::move(info))); + return true; + }); + return syncId; + }); + return true; + }; +} + +uint64_t SyncManager::GenerateId(int32_t user) { uint64_t syncId = user; - return (syncId << MV_BIT) | (++syncId_); + return (syncId << 32) | (++genId_); } RefCount SyncManager::GenSyncRef(uint64_t syncId) @@ -293,19 +306,48 @@ int32_t SyncManager::Compare(uint64_t syncId, int32_t user) return (syncId & USER_MARK) == (inner << MV_BIT); } -void SyncManager::DoRetry(int32_t retry, SyncInfo &&info) +void SyncManager::UpdateSchema(const SyncManager::SyncInfo &syncInfo) { CloudEvent::StoreInfo storeInfo; - storeInfo.user = info.user_; - storeInfo.bundleName = info.bundleName_; + storeInfo.user = syncInfo.user_; + storeInfo.bundleName = syncInfo.bundleName_; EventCenter::GetInstance().PostEvent(std::make_unique(CloudEvent::GET_SCHEMA, storeInfo)); - if (retry > RETRY_TIMES) { - info.SetError(E_RETRY_TIMEOUT); - return; +} + +AutoCache::Store SyncManager::GetStore(const StoreMetaData &meta, int32_t user) +{ + auto instance = CloudServer::GetInstance(); + if (instance == nullptr) { + ZLOGD("not support cloud sync"); + return nullptr; } - actives_.Compute(GenSyncId(info.user_), [this, retry, &info](const uint64_t &key, TaskId &value) mutable { - value = executor_->Schedule(RETRY_INTERVAL, GetSyncTask(retry, GenSyncRef(key), std::move(info))); - return true; - }); + + auto store = AutoCache::GetInstance().GetStore(meta, {}); + if (store == nullptr) { + ZLOGE("store null, storeId:%{public}s", meta.GetStoreAlias().c_str()); + return nullptr; + } + + if (!store->IsBound()) { + CloudInfo info; + info.user = user; + SchemaMeta schemaMeta; + std::string schemaKey = info.GetSchemaKey(meta.bundleName, meta.instanceId); + if (!MetaDataManager::GetInstance().LoadMeta(std::move(schemaKey), schemaMeta, true)) { + ZLOGE("failed, no schema bundleName:%{public}s, storeId:%{public}s", meta.bundleName.c_str(), + meta.GetStoreAlias().c_str()); + return nullptr; + } + auto dbMeta = schemaMeta.GetDataBase(meta.storeId); + auto cloudDB = instance->ConnectCloudDB(meta.tokenId, dbMeta); + auto assetLoader = instance->ConnectAssetLoader(meta.tokenId, dbMeta); + if (cloudDB == nullptr || assetLoader == nullptr) { + ZLOGE("failed, no cloud DB <0x%{public}x %{public}s<->%{public}s>", meta.tokenId, + dbMeta.name.c_str(), dbMeta.alias.c_str()); + return nullptr; + } + store->Bind(dbMeta, { std::move(cloudDB), std::move(assetLoader) }); + } + return store; } } // namespace OHOS::CloudData \ No newline at end of file diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index 199907b5..e11b7dfc 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -17,6 +17,7 @@ #define OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_SYNC_MANAGER_H #include "eventcenter/event.h" #include "executor_pool.h" +#include "store/auto_cache.h" #include "store/general_store.h" #include "store/general_value.h" #include "utils/ref_count.h" @@ -41,12 +42,13 @@ public: void SetWait(int32_t wait); void SetAsyncDetail(GenAsync asyncDetail); void SetQuery(std::shared_ptr query); - void SetError(int32_t code); + void SetError(int32_t code) const; std::shared_ptr GenerateQuery(const std::string &store, const Tables &tables); inline static constexpr const char *DEFAULT_ID = "default"; private: friend SyncManager; + uint64_t syncId_ = 0; int32_t mode_ = GenStore::CLOUD_TIME_FIRST; int32_t user_ = 0; int32_t wait_ = 0; @@ -66,22 +68,32 @@ private: using Event = DistributedData::Event; using Task = ExecutorPool::Task; using TaskId = ExecutorPool::TaskId; + using AutoCache = DistributedData::AutoCache; + using Duration = ExecutorPool::Duration; + using StoreMetaData = DistributedData::StoreMetaData; + using Retryer = std::function; + static constexpr ExecutorPool::Duration RETRY_INTERVAL = std::chrono::seconds(10); // second - static constexpr int32_t RETRY_TIMES = 6; // second + static constexpr ExecutorPool::Duration LOCKED_INTERVAL = std::chrono::seconds(30); // second + static constexpr int32_t RETRY_TIMES = 6; // normal retry + static constexpr int32_t CLIENT_RETRY_TIMES = 3; // normal retry static constexpr uint64_t USER_MARK = 0xFFFFFFFF00000000; // high 32 bit static constexpr int32_t MV_BIT = 32; Task GetSyncTask(int32_t retry, RefCount ref, SyncInfo &&syncInfo); - void DoRetry(int32_t retry, SyncInfo &&syncInfo); - std::function GetSyncHandler(); + void UpdateSchema(const SyncInfo &syncInfo); + std::function GetSyncHandler(Retryer retryer); std::function GetClientChangeHandler(); - uint64_t GenSyncId(int32_t user); + Retryer GetRetryer(int32_t retry, const SyncInfo &syncInfo); + static AutoCache::Store GetStore(const StoreMetaData &meta, int32_t user); + static uint64_t GenerateId(int32_t user); RefCount GenSyncRef(uint64_t syncId); int32_t Compare(uint64_t syncId, int32_t user); - std::atomic syncId_ = 0; + static std::atomic genId_; std::shared_ptr executor_; ConcurrentMap actives_; + ConcurrentMap activeInfos_; }; } // namespace OHOS::CloudData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_CLOUD_SYNC_MANAGER_H diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 9a842534..bdd19979 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -101,16 +101,8 @@ int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) bindInfo_ = std::move(bindInfo); rdbCloud_ = std::make_shared(bindInfo_.db_); - if (rdbCloud_ == nullptr) { - ZLOGE("rdb_cloudDb is null"); - return GeneralError::E_ERROR; - } delegate_->SetCloudDB(rdbCloud_); rdbLoader_ = std::make_shared(bindInfo_.loader_); - if (rdbLoader_ == nullptr) { - ZLOGE("rdb_AssetLoader is null"); - return GeneralError::E_ERROR; - } delegate_->SetIAssetLoader(rdbLoader_); DBSchema schema; schema.tables.resize(database.tables.size()); diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index aef9c6ad..3932f3b6 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -385,8 +385,8 @@ int32_t RdbSyncer::DoSync(const Option &option, const PredicatesMemo &predicates query->query_.FromTable(predicates.tables_); } - auto info = ChangeEvent::EventInfo(option.mode, (option.isAsync ? 0 : WAIT_TIME), query, - [async](const GenDetails &details) { + auto info = ChangeEvent::EventInfo(option.mode, (option.isAsync ? 0 : WAIT_TIME), + (option.isAsync && option.seqNum == 0), query, [async](const GenDetails &details) { async(HandleGenDetails(details)); }); auto evt = std::make_unique(std::move(storeInfo), std::move(info)); -- Gitee From 0b478851e1c79475ccbb512425cd1927e3d737cd Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 21 Jun 2023 17:30:46 +0800 Subject: [PATCH 258/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index e3b020e2..be89be8c 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -290,7 +290,7 @@ SyncManager::Retryer SyncManager::GetRetryer(int32_t retry, const SyncInfo &sync uint64_t SyncManager::GenerateId(int32_t user) { uint64_t syncId = user; - return (syncId << 32) | (++genId_); + return (syncId << MV_BIT) | (++genId_); } RefCount SyncManager::GenSyncRef(uint64_t syncId) -- Gitee From 2a919d81b6fa980ecf1a4b349a61d59e3b905d58 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 21 Jun 2023 18:05:58 +0800 Subject: [PATCH 259/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index be89be8c..35c1bfd5 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -238,7 +238,7 @@ std::function SyncManager::GetSyncHandler(Retryer retryer) ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), meta.GetStoreAlias().c_str()); auto status = store->Sync( - { SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); + { SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); retryer(status == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, status); }; } -- Gitee From 565f78c9b90c4c8e5dfd47b2da573963a9b97634 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 21 Jun 2023 18:37:00 +0800 Subject: [PATCH 260/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 35c1bfd5..72085fc6 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -206,7 +206,7 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf storeInfo.instanceId = cloud.apps[schema.bundleName].instanceId; auto query = info.GenerateQuery(database.name, database.GetTableNames()); auto evt = std::make_unique(std::move(storeInfo), - SyncEvent::EventInfo{ info.mode_, info.wait_, false, std::move(query), info.async_ }); + SyncEvent::EventInfo { info.mode_, info.wait_, false, std::move(query), info.async_ }); EventCenter::GetInstance().PostEvent(std::move(evt)); } } -- Gitee From 5e850cba4f7603b7fa96e3923102146e0726174f Mon Sep 17 00:00:00 2001 From: wangkai Date: Tue, 13 Jun 2023 16:12:46 +0800 Subject: [PATCH 261/437] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkai --- .../service/cloud/cloud_service_impl.cpp | 4 ++-- .../distributeddataservice/service/cloud/sync_manager.cpp | 7 +++---- .../distributeddataservice/service/cloud/sync_manager.h | 2 +- .../service/rdb/rdb_general_store.cpp | 6 +----- .../distributeddataservice/service/rdb/rdb_general_store.h | 2 +- .../service/rdb/rdb_service_impl.cpp | 2 +- services/distributeddataservice/service/rdb/rdb_syncer.cpp | 2 +- services/distributeddataservice/service/rdb/rdb_syncer.h | 2 +- 8 files changed, 11 insertions(+), 16 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index d4a29e00..110b3d43 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -78,7 +78,7 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map SyncManager::GetClientChangeHandler() uint64_t SyncManager::GenSyncId(int32_t user) { - uint64_t syncId = user; + uint64_t syncId = static_cast(user) & 0xFFFFFFFF; return (syncId << MV_BIT) | (++syncId_); } @@ -288,7 +287,7 @@ RefCount SyncManager::GenSyncRef(uint64_t syncId) int32_t SyncManager::Compare(uint64_t syncId, int32_t user) { - uint64_t inner = user; + uint64_t inner = static_cast(user) & 0xFFFFFFFF; return (syncId & USER_MARK) == (inner << MV_BIT); } diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index 199907b5..b08fcf4a 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -72,7 +72,7 @@ private: static constexpr int32_t MV_BIT = 32; Task GetSyncTask(int32_t retry, RefCount ref, SyncInfo &&syncInfo); - void DoRetry(int32_t retry, SyncInfo &&syncInfo); + void DoRetry(int32_t retry, SyncInfo &&info); std::function GetSyncHandler(); std::function GetClientChangeHandler(); uint64_t GenSyncId(int32_t user); diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index bda01958..3000f6f5 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -100,10 +100,6 @@ int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) bindInfo_ = std::move(bindInfo); rdbCloud_ = std::make_shared(bindInfo_.db_); - if (rdbCloud_ == nullptr) { - ZLOGE("rdb_cloudDb is null"); - return GeneralError::E_ERROR; - } delegate_->SetCloudDB(rdbCloud_); DBSchema schema; schema.tables.resize(database.tables.size()); @@ -295,7 +291,7 @@ void RdbGeneralStore::ObserverProxy::OnChange(DBOrigin origin, const std::string genOrigin.store = storeId_; Watcher::PRIFields fields; Watcher::ChangeInfo changeInfo; - for (int i = 0; i < DistributedDB::OP_BUTT; ++i) { + for (uint32_t i = 0; i < DistributedDB::OP_BUTT; ++i) { auto &info = changeInfo[data.tableName][i]; for (auto &priData : data.primaryData[i]) { Watcher::PRIValue value; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 10366ca6..2d801321 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -37,7 +37,7 @@ public: using Database = DistributedData::Database; using RdbStore = OHOS::NativeRdb::RdbStore; - explicit RdbGeneralStore(const StoreMetaData &metaData); + explicit RdbGeneralStore(const StoreMetaData &meta); ~RdbGeneralStore(); int32_t Bind(const Database &database, BindInfo bindInfo) override; bool IsBound() override; diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 3bf671e4..22b6a30b 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -104,7 +104,7 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib ZLOGI("%{public}.6s", identifierHex.c_str()); std::vector entries; auto localId = DmAdapter::GetInstance().GetLocalDevice().uuid; - if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix( { localId } ), entries)) { + if (!MetaDataManager::GetInstance().LoadMeta(StoreMetaData::GetPrefix({ localId }), entries)) { ZLOGE("get meta failed"); return false; } diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index aef9c6ad..1f65915f 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -92,7 +92,7 @@ std::string RdbSyncer::GetBundleName() const std::string RdbSyncer::GetAppId() const { - return DistributedData::CheckerManager::GetInstance().GetAppId( { uid_, token_, param_.bundleName_ } ); + return DistributedData::CheckerManager::GetInstance().GetAppId({ uid_, token_, param_.bundleName_ }); } std::string RdbSyncer::GetStoreId() const diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.h b/services/distributeddataservice/service/rdb/rdb_syncer.h index cf823d74..11983e8d 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.h +++ b/services/distributeddataservice/service/rdb/rdb_syncer.h @@ -92,7 +92,7 @@ private: static std::vector GetConnectDevices(); static std::vector NetworkIdToUUID(const std::vector& networkIds); - static Details HandleSyncStatus(const std::map> &SyncStatus); + static Details HandleSyncStatus(const std::map> &syncStatus); static Details HandleGenDetails(const GenDetails &details); static void EqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); static void NotEqualTo(const RdbPredicateOperation& operation, DistributedDB::Query& query); -- Gitee From ab7cbdf20e6b55055498fddeae07342bb484c00f Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 26 Jun 2023 09:20:03 +0800 Subject: [PATCH 262/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/sync_manager.cpp | 37 +++++++++++-------- .../service/cloud/sync_manager.h | 4 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 72085fc6..6957f232 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -143,7 +143,7 @@ int32_t SyncManager::DoCloudSync(SyncInfo syncInfo) } actives_.Compute(GenerateId(syncInfo.user_), [this, &syncInfo](const uint64_t &key, TaskId &taskId) mutable { - taskId = executor_->Execute(GetSyncTask(0, GenSyncRef(key), std::move(syncInfo))); + taskId = executor_->Execute(GetSyncTask(0, true, GenSyncRef(key), std::move(syncInfo))); return true; }); @@ -164,10 +164,10 @@ int32_t SyncManager::StopCloudSync(int32_t user) return E_OK; } -ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInfo &&syncInfo) +ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount ref, SyncInfo &&syncInfo) { - retry++; - return [this, retry, ref = std::move(ref), info = std::move(syncInfo)]() mutable { + times++; + return [this, times, retry, ref = std::move(ref), info = std::move(syncInfo)]() mutable { activeInfos_.Erase(info.syncId_); CloudInfo cloud; cloud.user = info.user_; @@ -185,7 +185,7 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf std::vector schemas; auto key = cloud.GetSchemaPrefix(info.bundleName_); - auto retryer = GetRetryer(retry, info); + auto retryer = GetRetryer(times, info); if (!MetaDataManager::GetInstance().LoadMeta(key, schemas, true)) { UpdateSchema(info); retryer(RETRY_INTERVAL, E_RETRY_TIMEOUT); @@ -206,7 +206,7 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t retry, RefCount ref, SyncInf storeInfo.instanceId = cloud.apps[schema.bundleName].instanceId; auto query = info.GenerateQuery(database.name, database.GetTableNames()); auto evt = std::make_unique(std::move(storeInfo), - SyncEvent::EventInfo { info.mode_, info.wait_, false, std::move(query), info.async_ }); + SyncEvent::EventInfo { info.mode_, info.wait_, retry, std::move(query), info.async_ }); EventCenter::GetInstance().PostEvent(std::move(evt)); } } @@ -237,9 +237,14 @@ std::function SyncManager::GetSyncHandler(Retryer retryer) ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), meta.GetStoreAlias().c_str()); - auto status = store->Sync( - { SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.GetAsyncDetail(), evt.GetWait()); - retryer(status == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, status); + store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.AutoRetry() ? [retryer](const GenDetails &details) { + if (details.empty()) { + ZLOGE("retry, details empty"); + return; + } + int32_t code = details.begin()->second.code; + retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); + } : evt.GetAsyncDetail(), evt.GetWait()); }; } @@ -254,14 +259,14 @@ std::function SyncManager::GetClientChangeHandler() syncInfo.SetAsyncDetail(evt.GetAsyncDetail()); syncInfo.SetQuery(evt.GetQuery()); auto times = evt.AutoRetry() ? RETRY_TIMES - CLIENT_RETRY_TIMES : RETRY_TIMES; - auto task = GetSyncTask(times, RefCount(), std::move(syncInfo)); + auto task = GetSyncTask(times, evt.AutoRetry(), RefCount(), std::move(syncInfo)); task(); }; } -SyncManager::Retryer SyncManager::GetRetryer(int32_t retry, const SyncInfo &syncInfo) +SyncManager::Retryer SyncManager::GetRetryer(int32_t times, const SyncInfo &syncInfo) { - if (retry >= RETRY_TIMES) { + if (times >= RETRY_TIMES) { return [info = SyncInfo(syncInfo)](Duration, int32_t code) mutable { if (code == E_OK) { return true; @@ -270,15 +275,15 @@ SyncManager::Retryer SyncManager::GetRetryer(int32_t retry, const SyncInfo &sync return true; }; } - return [this, retry, info = SyncInfo(syncInfo)](Duration interval, int32_t code) mutable { + return [this, times, info = SyncInfo(syncInfo)](Duration interval, int32_t code) mutable { if (code == E_OK) { return true; } - activeInfos_.ComputeIfAbsent(info.syncId_, [this, retry, interval, &info](uint64_t key) mutable { + activeInfos_.ComputeIfAbsent(info.syncId_, [this, times, interval, &info](uint64_t key) mutable { auto syncId = GenerateId(info.user_); - actives_.Compute(syncId, [this, retry, interval, &info](const uint64_t &key, TaskId &value) mutable { - value = executor_->Schedule(interval, GetSyncTask(retry, GenSyncRef(key), std::move(info))); + actives_.Compute(syncId, [this, times, interval, &info](const uint64_t &key, TaskId &value) mutable { + value = executor_->Schedule(interval, GetSyncTask(times, true, GenSyncRef(key), std::move(info))); return true; }); return syncId; diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index e11b7dfc..3f1b4546 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -80,11 +80,11 @@ private: static constexpr uint64_t USER_MARK = 0xFFFFFFFF00000000; // high 32 bit static constexpr int32_t MV_BIT = 32; - Task GetSyncTask(int32_t retry, RefCount ref, SyncInfo &&syncInfo); + Task GetSyncTask(int32_t times, bool retry, RefCount ref, SyncInfo &&syncInfo); void UpdateSchema(const SyncInfo &syncInfo); std::function GetSyncHandler(Retryer retryer); std::function GetClientChangeHandler(); - Retryer GetRetryer(int32_t retry, const SyncInfo &syncInfo); + Retryer GetRetryer(int32_t times, const SyncInfo &syncInfo); static AutoCache::Store GetStore(const StoreMetaData &meta, int32_t user); static uint64_t GenerateId(int32_t user); RefCount GenSyncRef(uint64_t syncId); -- Gitee From ed6c811e2d14c34c144379c03d6f0da7b583d3b4 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 26 Jun 2023 09:47:14 +0800 Subject: [PATCH 263/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/sync_manager.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 8a3fd8e2..0850fec5 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -237,14 +237,16 @@ std::function SyncManager::GetSyncHandler(Retryer retryer) ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), meta.GetStoreAlias().c_str()); - store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.AutoRetry() ? [retryer](const GenDetails &details) { - if (details.empty()) { - ZLOGE("retry, details empty"); - return; + store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.AutoRetry() + ? [retryer](const GenDetails &details) { + if (details.empty()) { + ZLOGE("retry, details empty"); + return; + } + int32_t code = details.begin()->second.code; + retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); } - int32_t code = details.begin()->second.code; - retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); - } : evt.GetAsyncDetail(), evt.GetWait()); + : evt.GetAsyncDetail(), evt.GetWait()); }; } -- Gitee From 8ed60f343ac1b65f83bf6efe8b5d009f9d113476 Mon Sep 17 00:00:00 2001 From: wangkai Date: Mon, 26 Jun 2023 15:56:54 +0800 Subject: [PATCH 264/437] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkai --- .../framework/include/store/general_value.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/framework/include/store/general_value.h b/services/distributeddataservice/framework/include/store/general_value.h index 18df10a1..be79be91 100644 --- a/services/distributeddataservice/framework/include/store/general_value.h +++ b/services/distributeddataservice/framework/include/store/general_value.h @@ -32,10 +32,10 @@ enum GenProgress { }; struct GenStatistic { - int32_t total; - int32_t success; - int32_t failed; - int32_t untreated; + uint32_t total; + uint32_t success; + uint32_t failed; + uint32_t untreated; }; struct GenTableDetail { -- Gitee From fd0729dc4184a9151212e06355e96b74eafd48bf Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 26 Jun 2023 20:24:42 +0800 Subject: [PATCH 265/437] fix crash bug Signed-off-by: mazhao --- .../src/interface/src/result_set.cpp | 24 ++++---- .../unittest/api/documentdb_find_test.cpp | 56 +++++++++++++++++++ 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 6c221daa..08b51c3b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -190,19 +190,19 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat GLOGE("No node to cut"); return -E_NO_DATA; } - singlePath.emplace_back(node->GetItemField()); - size_t index = 0; - if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { - allCutPath.emplace_back(singlePath); - } - if (!node->GetChild().IsNull()) { - JsonObject nodeNew = node->GetChild(); - CheckCutNode(&nodeNew, singlePath, allCutPath); - } - if (!node->GetNext().IsNull()) { + JsonObject nodeInstance = *node; + while (!nodeInstance.IsNull()) { + singlePath.emplace_back(nodeInstance.GetItemField()); + size_t index = 0; + if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { + allCutPath.emplace_back(singlePath); + } + if (!nodeInstance.GetChild().IsNull()) { + JsonObject nodeChiled = nodeInstance.GetChild(); + CheckCutNode(&nodeChiled, singlePath, allCutPath); + } singlePath.pop_back(); - JsonObject nodeNew = node->GetNext(); - CheckCutNode(&nodeNew, singlePath, allCutPath); + nodeInstance = nodeInstance.GetNext(); } return E_OK; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index f77761d8..b54438f1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -78,6 +78,17 @@ static const char *g_document20 = "{\"_id\" : \"20\", \"name\":\"doc20\",\"ITEM\ static const char *g_document23 = "{\"_id\" : \"23\", \"name\":\"doc22\",\"ITEM\" : " "true,\"personInfo\":[{\"school\":\"b\", \"age\":15}, [{\"school\":\"doc23\"}, 10, " "{\"school\":\"doc23\"}, true, {\"school\":\"y\"}], {\"school\":\"b\"}]}"; +static const char *document0631 = R""({"_id":"city_11_com.acts.ohos.data.datasharetestclient_100", + "bundleName":"com.acts.ohos.data.datasharetestclient","key":"city","subscriberId":11, + "timestamp":1509100700,"userId":100,"value":{"type":1,"value":"xian"},"version":0})""; +static const char *document0632 = R""({"_id":"datashareproxy://com.acts.ohos.data.datasharetest/appInfo_11_com.acts.oh + os.data.datasharetest_100","bundleName":"com.acts.ohos.data.datasharetest","key":"datashareproxy://com.acts.ohos + .data.datasharetest/appInfo","subscriberId":11,"timestamp":1509100700,"userId":100, + "value":{"type":1,"value":"\"Qing\""},"version":0})""; +static const char *document0633 = + R""({"_id":"empty_11_com.acts.ohos.data.datasharetestclient_100","bundleName":"com.acts.ohos.data.datasharetestcl + ient","key":"empty","subscriberId":11,"timestamp":1509100700,"userId":100,"value":{"type":1,"value":"nobody sub"}, + "version":0})""; static std::vector g_data = { g_document1, g_document2, g_document3, g_document4, g_document5, g_document6, g_document7, g_document8, g_document9, g_document10, g_document11, g_document12, g_document13, g_document14, g_document15, g_document16, g_document17, g_document18, g_document19, g_document20, g_document23 }; @@ -1464,4 +1475,49 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest062, TestSize.Level1) Query query = { filter, projection }; EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_INVALID_ARGS); } + +HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) +{ + char *colName1 = "data_"; + GRD_DB *test_db = nullptr; + std::string path = "./dataShare.db"; + int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &test_db); + EXPECT_EQ(status, GRD_OK); + EXPECT_EQ(GRD_CreateCollection(test_db, colName1, "", 0), GRD_OK); + + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0631, 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0632, 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0633, 0), GRD_OK); + + string document1 = "{\"_id\":\"key2_11_com.acts.ohos.data.datasharetestclient_100\"\ + ,\"bundleName\":\"com.acts.ohos.data.datasharetestclient\"\ + ,\"key\":\"key2\",\"subscriberId\":11,\"timestamp\":1509100700," + "\"userId\":100,\"value\":{\"type\":0,"; + string document2 = "\"value\":["; + string document3 = "5,"; + string document4 = document3; + for (int i = 0; i < 100000; i++) { + document4 += document3; + } + document4.push_back('5'); + string document5 = "]}}"; + string document0635 = document1 + document2 + document4 + document5; + EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0635.c_str(), 0), GRD_OK); + EXPECT_EQ(status, GRD_OK); + const char *filter = "{}"; + GRD_ResultSet *resultSet = nullptr; + const char *projection = "{\"id_\":true, \"timestamp\":true, \"key\":true, \"bundleName\": true, " + "\"subscriberId\": true}"; + Query query = { filter, projection }; + EXPECT_EQ(GRD_FindDoc(test_db, colName1, query, 1, &resultSet), GRD_OK); + char *value; + while (GRD_Next(resultSet) == GRD_OK) { + EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); + printf("value is ======>%s\n", value); + GRD_FreeValue(value); + } + EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); + EXPECT_EQ(GRD_DBClose(test_db, 0), GRD_OK); + DocumentDBTestUtils::RemoveTestDbFiles(path.c_str()); +} } // namespace -- Gitee From 17b8763992dfc939041dfd52ee49d0e598a78d9c Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 26 Jun 2023 20:53:04 +0800 Subject: [PATCH 266/437] fix primary convert bug Signed-off-by: wanghuajian --- .../distributeddataservice/service/rdb/rdb_asset_loader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp index b7d4d938..a0d9f538 100644 --- a/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp @@ -31,8 +31,8 @@ DBStatus RdbAssetLoader::Download(const std::string &tableName, const std::strin std::map &assets) { DistributedData::VBucket downLoadAssets = ValueProxy::Convert(assets); - - auto error = assetLoader_->Download(tableName, gid, (const DistributedData::Value &)prefix, downLoadAssets); + DistributedDB::Type prefixTemp = prefix; + auto error = assetLoader_->Download(tableName, gid, ValueProxy::Convert(std::move(prefixTemp)), downLoadAssets); if (error == DistributedData::GeneralError::E_OK) { assets = ValueProxy::Convert(std::move(downLoadAssets)); } -- Gitee From 89164fb58f5f51283a7c1b12b886f5c1f48b5ca3 Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 26 Jun 2023 21:26:26 +0800 Subject: [PATCH 267/437] fix test format Signed-off-by: mazhao --- .../test/unittest/api/documentdb_find_test.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index b54438f1..b606e12d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -35,6 +35,7 @@ namespace { std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; constexpr const char *COLLECTION_NAME = "student"; +constexpr const char *colName1 = "data_"; const int MAX_COLLECTION_NAME = 511; const int MAX_ID_LENS = 899; @@ -1478,7 +1479,6 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest062, TestSize.Level1) HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) { - char *colName1 = "data_"; GRD_DB *test_db = nullptr; std::string path = "./dataShare.db"; int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &test_db); @@ -1489,10 +1489,9 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0632, 0), GRD_OK); EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0633, 0), GRD_OK); - string document1 = "{\"_id\":\"key2_11_com.acts.ohos.data.datasharetestclient_100\"\ - ,\"bundleName\":\"com.acts.ohos.data.datasharetestclient\"\ - ,\"key\":\"key2\",\"subscriberId\":11,\"timestamp\":1509100700," - "\"userId\":100,\"value\":{\"type\":0,"; + string document1 = "{\"_id\":\"key2_11_com.acts.ohos.data.datasharetestclient_100\",\ + \"bundleName\":\"com.acts.ohos.data.datasharetestclient\",\"key\":\"key2\",\ + \"subscriberId\":11,\"timestamp\":1509100700,""\"userId\":100,\"value\":{\"type\":0,"; string document2 = "\"value\":["; string document3 = "5,"; string document4 = document3; @@ -1513,7 +1512,6 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) char *value; while (GRD_Next(resultSet) == GRD_OK) { EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - printf("value is ======>%s\n", value); GRD_FreeValue(value); } EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); -- Gitee From 7dd52218ac0bfed822e321b9b938ad232bc2f128 Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 26 Jun 2023 21:32:21 +0800 Subject: [PATCH 268/437] fix test format Signed-off-by: mazhao --- .../test/unittest/api/documentdb_find_test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index b606e12d..e4d034ad 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -35,7 +35,7 @@ namespace { std::string g_path = "./document.db"; GRD_DB *g_db = nullptr; constexpr const char *COLLECTION_NAME = "student"; -constexpr const char *colName1 = "data_"; +constexpr const char *colName = "data_"; const int MAX_COLLECTION_NAME = 511; const int MAX_ID_LENS = 899; @@ -1483,11 +1483,11 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) std::string path = "./dataShare.db"; int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &test_db); EXPECT_EQ(status, GRD_OK); - EXPECT_EQ(GRD_CreateCollection(test_db, colName1, "", 0), GRD_OK); + EXPECT_EQ(GRD_CreateCollection(test_db, colName, "", 0), GRD_OK); - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0631, 0), GRD_OK); - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0632, 0), GRD_OK); - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0633, 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0631, 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0632, 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0633, 0), GRD_OK); string document1 = "{\"_id\":\"key2_11_com.acts.ohos.data.datasharetestclient_100\",\ \"bundleName\":\"com.acts.ohos.data.datasharetestclient\",\"key\":\"key2\",\ @@ -1501,14 +1501,14 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) document4.push_back('5'); string document5 = "]}}"; string document0635 = document1 + document2 + document4 + document5; - EXPECT_EQ(GRD_InsertDoc(test_db, colName1, document0635.c_str(), 0), GRD_OK); + EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0635.c_str(), 0), GRD_OK); EXPECT_EQ(status, GRD_OK); const char *filter = "{}"; GRD_ResultSet *resultSet = nullptr; const char *projection = "{\"id_\":true, \"timestamp\":true, \"key\":true, \"bundleName\": true, " "\"subscriberId\": true}"; Query query = { filter, projection }; - EXPECT_EQ(GRD_FindDoc(test_db, colName1, query, 1, &resultSet), GRD_OK); + EXPECT_EQ(GRD_FindDoc(test_db, colName, query, 1, &resultSet), GRD_OK); char *value; while (GRD_Next(resultSet) == GRD_OK) { EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); -- Gitee From 8af5088bd8c9875de1f271f0015dd8021bf7edf3 Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 26 Jun 2023 21:55:25 +0800 Subject: [PATCH 269/437] fix format Signed-off-by: mazhao --- .../test/unittest/api/documentdb_find_test.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index e4d034ad..654294a3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -79,17 +79,6 @@ static const char *g_document20 = "{\"_id\" : \"20\", \"name\":\"doc20\",\"ITEM\ static const char *g_document23 = "{\"_id\" : \"23\", \"name\":\"doc22\",\"ITEM\" : " "true,\"personInfo\":[{\"school\":\"b\", \"age\":15}, [{\"school\":\"doc23\"}, 10, " "{\"school\":\"doc23\"}, true, {\"school\":\"y\"}], {\"school\":\"b\"}]}"; -static const char *document0631 = R""({"_id":"city_11_com.acts.ohos.data.datasharetestclient_100", - "bundleName":"com.acts.ohos.data.datasharetestclient","key":"city","subscriberId":11, - "timestamp":1509100700,"userId":100,"value":{"type":1,"value":"xian"},"version":0})""; -static const char *document0632 = R""({"_id":"datashareproxy://com.acts.ohos.data.datasharetest/appInfo_11_com.acts.oh - os.data.datasharetest_100","bundleName":"com.acts.ohos.data.datasharetest","key":"datashareproxy://com.acts.ohos - .data.datasharetest/appInfo","subscriberId":11,"timestamp":1509100700,"userId":100, - "value":{"type":1,"value":"\"Qing\""},"version":0})""; -static const char *document0633 = - R""({"_id":"empty_11_com.acts.ohos.data.datasharetestclient_100","bundleName":"com.acts.ohos.data.datasharetestcl - ient","key":"empty","subscriberId":11,"timestamp":1509100700,"userId":100,"value":{"type":1,"value":"nobody sub"}, - "version":0})""; static std::vector g_data = { g_document1, g_document2, g_document3, g_document4, g_document5, g_document6, g_document7, g_document8, g_document9, g_document10, g_document11, g_document12, g_document13, g_document14, g_document15, g_document16, g_document17, g_document18, g_document19, g_document20, g_document23 }; @@ -1484,11 +1473,6 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest063, TestSize.Level1) int status = GRD_DBOpen(path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &test_db); EXPECT_EQ(status, GRD_OK); EXPECT_EQ(GRD_CreateCollection(test_db, colName, "", 0), GRD_OK); - - EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0631, 0), GRD_OK); - EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0632, 0), GRD_OK); - EXPECT_EQ(GRD_InsertDoc(test_db, colName, document0633, 0), GRD_OK); - string document1 = "{\"_id\":\"key2_11_com.acts.ohos.data.datasharetestclient_100\",\ \"bundleName\":\"com.acts.ohos.data.datasharetestclient\",\"key\":\"key2\",\ \"subscriberId\":11,\"timestamp\":1509100700,""\"userId\":100,\"value\":{\"type\":0,"; -- Gitee From 55167024f344ef62299355ddee83036614a07ed2 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Tue, 27 Jun 2023 10:24:37 +0800 Subject: [PATCH 270/437] fix:cursor Signed-off-by: htt1997 --- services/distributeddataservice/service/rdb/rdb_cloud.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index e3d16735..35ce54f1 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -15,6 +15,7 @@ #define LOG_TAG "RdbCloud" #include "rdb_cloud.h" +#include "cloud/schema_meta.h" #include "log_print.h" #include "value_proxy.h" #include "utils/anonymous.h" @@ -73,6 +74,9 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v err = cursor->MoveToNext(); count--; } + DistributedData::Value cursorFlag; + cursor->Get(SchemaMeta::CURSOR_FIELD, cursorFlag); + extend[SchemaMeta::CURSOR_FIELD] = ValueProxy::Convert(std::move(cursorFlag)); if (cursor->IsEnd()) { ZLOGD("query end, table:%{public}s", Anonymous::Change(tableName).c_str()); return DBStatus::QUERY_END; -- Gitee From 8c72da2d7fcaf59ea8b326f914b3c47d4b99787c Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 27 Jun 2023 20:05:53 +0800 Subject: [PATCH 271/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 1 + .../data_share/data/published_data.cpp | 36 +++++++++- .../service/data_share/data/published_data.h | 3 + .../data_share/data_share_service_impl.cpp | 22 ++++++- .../data_share/data_share_service_impl.h | 3 + .../data_share/data_share_service_stub.cpp | 11 ++++ .../data_share/data_share_service_stub.h | 4 +- .../service/data_share/idata_share_service.h | 2 + .../strategies/rdb_notify_strategy.cpp | 65 +++++++++++++++++++ .../strategies/rdb_notify_strategy.h | 34 ++++++++++ .../rdb_subscriber_manager.cpp | 4 ++ 11 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp create mode 100644 services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.h diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 2d8ffad4..9cf48c40 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -68,6 +68,7 @@ ohos_shared_library("data_share_service") { "strategies/insert_strategy.cpp", "strategies/publish_strategy.cpp", "strategies/query_strategy.cpp", + "strategies/rdb_notify_strategy.cpp", "strategies/subscribe_strategy.cpp", "strategies/template_strategy.cpp", "strategies/update_strategy.cpp", diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 68605579..df843c72 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -160,7 +160,9 @@ void PublishedData::ClearAging() return; } std::vector queryResults; - int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, "{}", "{}", queryResults); + int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, "{}", + "{\"id_\": true, \"timestamp\": true, \"key\": true, \"bundleName\": true, \"subscriberId\": true}", + queryResults); if (status != E_OK) { ZLOGE("db GetBatch failed %{public}d", status); return; @@ -187,4 +189,36 @@ void PublishedData::ClearAging() } return; } + +void PublishedData::UpdateTimestamp( + const std::string &key, const std::string &bundleName, int64_t subscriberId, const int32_t userId) +{ + auto delegate = KvDBDelegate::GetInstance(); + if (delegate == nullptr) { + ZLOGE("db open failed"); + return; + } + std::string queryResult; + int32_t status = + delegate->Get(KvDBDelegate::DATA_TABLE, Id(GenId(key, bundleName, subscriberId), userId), queryResult); + if (status != E_OK) { + ZLOGE("db Get failed, %{private}s %{public}d", queryResult.c_str(), status); + return; + } + PublishedDataNode data; + if (!PublishedDataNode::Unmarshall(queryResult, data)) { + ZLOGE("Unmarshall failed, %{private}s", queryResult.c_str()); + return; + } + auto now = time(nullptr); + if (now <= 0) { + ZLOGE("time failed"); + return; + } + data.timestamp = now; + status = delegate->Upsert(KvDBDelegate::DATA_TABLE, PublishedData(data)); + if (status == E_OK) { + ZLOGI("update timestamp %{private}s to %{public}lld", data.key.c_str(), now); + } +} } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data/published_data.h b/services/distributeddataservice/service/data_share/data/published_data.h index aba9ee9f..cff038a3 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.h +++ b/services/distributeddataservice/service/data_share/data/published_data.h @@ -42,6 +42,8 @@ public: explicit PublishedData(const PublishedDataNode &node); static std::vector Query(const std::string &bundleName, int32_t userId); static void Delete(const std::string &bundleName, const int32_t userId); + static void UpdateTimestamp( + const std::string &key, const std::string &bundleName, int64_t subscriberId, const int32_t userId); static void ClearAging(); static int32_t Query(const std::string &filter, PublishedDataNode::Data &publishedData); static std::string GenId(const std::string &key, const std::string &bundleName, int64_t subscriberId); @@ -51,6 +53,7 @@ public: int GetVersion() const override; std::string GetValue() const override; friend class GetDataStrategy; + private: PublishedDataNode value; }; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index d91ae2dd..db168740 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -308,9 +308,16 @@ std::vector DataShareServiceImpl::UnsubscribePublishedData(cons PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { - return PublishedDataSubscriberManager::GetInstance().Delete( + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context, this]() -> bool { + auto result = PublishedDataSubscriberManager::GetInstance().Delete( PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); + if (binderInfo_.executors != nullptr) { + binderInfo_.executors->Execute([context, subscriberId]() { + PublishedData::UpdateTimestamp( + context->uri, context->callerBundleName, subscriberId, context->currentUserId); + }); + } + return result; })); } return results; @@ -430,4 +437,15 @@ int32_t DataShareServiceImpl::OnAppUninstall( RdbHelper::ClearCache(); return EOK; } + +void DataShareServiceImpl::NotifyObserver(const std::string &uri) +{ + ZLOGD("%{private}s try notified", uri.c_str()); + auto context = std::make_shared(uri); + auto ret = rdbNotifyStrategy_.Execute(context); + if (ret) { + ZLOGI("%{private}s start notified", uri.c_str()); + RdbSubscriberManager::GetInstance().Emit(uri, context); + } +} } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 493882da..72d102ca 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -27,6 +27,7 @@ #include "insert_strategy.h" #include "publish_strategy.h" #include "query_strategy.h" +#include "rdb_notify_strategy.h" #include "subscribe_strategy.h" #include "template_strategy.h" #include "update_strategy.h" @@ -67,6 +68,7 @@ public: int32_t OnBind(const BindInfo &binderInfo) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; + void NotifyObserver(const std::string &uri) override; private: class Factory { @@ -87,6 +89,7 @@ private: QueryStrategy queryStrategy_; UpdateStrategy updateStrategy_; TemplateStrategy templateStrategy_; + RdbNotifyStrategy rdbNotifyStrategy_; BindInfo binderInfo_; }; } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 852b874b..99383d08 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -329,5 +329,16 @@ int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me } return -1; } + +int32_t DataShareServiceStub::OnRemoteNotifyObserver(MessageParcel &data, MessageParcel &reply) +{ + std::string uri; + if (!ITypesUtil::Unmarshal(data, uri)) { + ZLOGE("read device list failed."); + return -1; + } + NotifyObserver(uri); + return 0; +} } // namespace DataShare } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.h b/services/distributeddataservice/service/data_share/data_share_service_stub.h index d7e1dc27..17ac116a 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.h +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.h @@ -44,6 +44,7 @@ private: int32_t OnRemoteEnablePubSubs(MessageParcel& data, MessageParcel& reply); int32_t OnRemoteDisablePubSubs(MessageParcel& data, MessageParcel& reply); int32_t OnRemoteNotifyConnectDone(MessageParcel& data, MessageParcel& reply); + int32_t OnRemoteNotifyObserver(MessageParcel& data, MessageParcel& reply); using RequestHandle = int (DataShareServiceStub::*)(MessageParcel &, MessageParcel &); static constexpr RequestHandle HANDLERS[DATA_SHARE_SERVICE_CMD_MAX] = { &DataShareServiceStub::OnRemoteInsert, @@ -62,7 +63,8 @@ private: &DataShareServiceStub::OnRemoteUnsubscribePublishedData, &DataShareServiceStub::OnRemoteEnablePubSubs, &DataShareServiceStub::OnRemoteDisablePubSubs, - &DataShareServiceStub::OnRemoteNotifyConnectDone }; + &DataShareServiceStub::OnRemoteNotifyConnectDone, + &DataShareServiceStub::OnRemoteNotifyObserver }; }; } // namespace DataShare } // namespace OHOS diff --git a/services/distributeddataservice/service/data_share/idata_share_service.h b/services/distributeddataservice/service/data_share/idata_share_service.h index 1ae6824f..ce2ff44b 100644 --- a/services/distributeddataservice/service/data_share/idata_share_service.h +++ b/services/distributeddataservice/service/data_share/idata_share_service.h @@ -46,6 +46,7 @@ public: DATA_SHARE_SERVICE_CMD_ENABLE_SUBSCRIBE_PUBLISHED, DATA_SHARE_SERVICE_CMD_DISABLE_SUBSCRIBE_PUBLISHED, DATA_SHARE_SERVICE_CMD_NOTIFY, + DATA_SHARE_SERVICE_CMD_NOTIFY_OBSERVERS, DATA_SHARE_SERVICE_CMD_MAX }; @@ -79,6 +80,7 @@ public: virtual std::vector DisablePubSubs(const std::vector &uris, const int64_t subscriberId) = 0; virtual void OnConnectDone() = 0; + virtual void NotifyObserver(const std::string &uri) = 0; }; } // namespace OHOS::DataShare #endif diff --git a/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp new file mode 100644 index 00000000..2c13eb86 --- /dev/null +++ b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp @@ -0,0 +1,65 @@ +/* + * 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. + */ +#define LOG_TAG "RdbNotifyStrategy" + +#include "rdb_notify_strategy.h" + +#include "general/load_config_common_strategy.h" +#include "general/load_config_data_info_strategy.h" +#include "general/load_config_from_bundle_info_strategy.h" +#include "log_print.h" +#include "utils/anonymous.h" + +namespace OHOS::DataShare { +bool RdbNotifyStrategy::Execute(std::shared_ptr context) +{ + auto &preProcess = GetStrategy(); + if (preProcess.IsEmpty()) { + ZLOGE("get strategy fail, maybe memory not enough"); + return false; + } + if (!preProcess(context)) { + ZLOGE("pre process fail, uri: %{public}s", DistributedData::Anonymous::Change(context->uri).c_str()); + return false; + } + if (context->callerBundleName != context->calledBundleName) { + ZLOGE("not your data, cannot notify, callerBundleName: %{public}s, calledBundleName: %{public}s", + context->callerBundleName.c_str(), context->calledBundleName.c_str()); + return false; + } + return true; +} + +SeqStrategy &RdbNotifyStrategy::GetStrategy() +{ + std::lock_guard lock(mutex_); + if (!strategies_.IsEmpty()) { + return strategies_; + } + std::initializer_list list = { + new (std::nothrow)LoadConfigCommonStrategy(), + new (std::nothrow)LoadConfigFromBundleInfoStrategy(), + new (std::nothrow)LoadConfigDataInfoStrategy() + }; + auto ret = strategies_.Init(list); + if (!ret) { + std::for_each(list.begin(), list.end(), [](Strategy *item) { + delete item; + }); + return strategies_; + } + return strategies_; +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.h b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.h new file mode 100644 index 00000000..d6678ccd --- /dev/null +++ b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.h @@ -0,0 +1,34 @@ +/* + * 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. + */ +#ifndef DATASHARESERVICE_RDB_NOTIFY_STRAGETY_H +#define DATASHARESERVICE_RDB_NOTIFY_STRAGETY_H + +#include + +#include "datashare_values_bucket.h" +#include "seq_strategy.h" + +namespace OHOS::DataShare { +class RdbNotifyStrategy final { +public: + bool Execute(std::shared_ptr context); + +private: + SeqStrategy &GetStrategy(); + std::mutex mutex_; + SeqStrategy strategies_; +}; +} // namespace OHOS::DataShare +#endif diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index 326551a0..a3110b9e 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -232,6 +232,10 @@ void RdbSubscriberManager::Emit(const std::string &uri, std::shared_ptr if (!URIUtils::IsDataProxyURI(uri)) { return; } + if (context->calledSourceDir.empty()) { + LoadConfigDataInfoStrategy loadDataInfo; + loadDataInfo(context); + } rdbCache_.ForEach([&uri, &context, this](const Key &key, std::vector &val) { if (key.uri != uri) { return false; -- Gitee From 6931baa088cdaf8cbdc910690be8978fd1f354ed Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 27 Jun 2023 21:10:55 +0800 Subject: [PATCH 272/437] f Signed-off-by: hanlu --- .../service/data_share/data_share_service_impl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index db168740..9896dafa 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -442,6 +442,10 @@ void DataShareServiceImpl::NotifyObserver(const std::string &uri) { ZLOGD("%{private}s try notified", uri.c_str()); auto context = std::make_shared(uri); + if (!GetCallerBundleName(context->callerBundleName)) { + ZLOGE("get bundleName error, %{private}s", uri.c_str()); + return; + } auto ret = rdbNotifyStrategy_.Execute(context); if (ret) { ZLOGI("%{private}s start notified", uri.c_str()); -- Gitee From 9efbebaf734a29d25ef6f77fe54e372337f8a6ed Mon Sep 17 00:00:00 2001 From: Jeremyzzz Date: Tue, 27 Jun 2023 21:18:38 +0800 Subject: [PATCH 273/437] fix bug Signed-off-by: Jeremyzzz --- .../src/oh_adapter/src/json_object.cpp | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 7ac3a08c..22cb53bc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -152,17 +152,23 @@ int JsonObject::GetDeep(cJSON *cjson) int JsonObject::CheckNumber(cJSON *item, int &errCode) { - if (item != NULL && cJSON_IsNumber(item)) { - double value = cJSON_GetNumberValue(item); - if (value > __DBL_MAX__ || value < -__DBL_MAX__) { - errCode = -E_INVALID_ARGS; + std::queue cjsonQueue; + cjsonQueue.push(item); + while (!cjsonQueue.empty()) { + cJSON *node = cjsonQueue.front(); + cjsonQueue.pop(); + if (node != NULL && cJSON_IsNumber(node)) { + double value = cJSON_GetNumberValue(node); + if (value > __DBL_MAX__ || value < -__DBL_MAX__) { + errCode = -E_INVALID_ARGS; + } + } + if (node->child != nullptr) { + cjsonQueue.push(node->child); + } + if (node->next != nullptr) { + cjsonQueue.push(node->next); } - } - if (item->child != nullptr) { - return CheckNumber(item->child, errCode); - } - if (item->next != nullptr) { - return CheckNumber(item->next, errCode); } return E_OK; } -- Gitee From e69a25c210b69149a225d1fb7ae74e8fce3b2f73 Mon Sep 17 00:00:00 2001 From: hanlu Date: Tue, 27 Jun 2023 22:00:53 +0800 Subject: [PATCH 274/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index df843c72..471225c8 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -34,8 +34,7 @@ std::string PublishedData::GetValue() const return DistributedData::Serializable::Marshall(value); } -PublishedData::PublishedData(const PublishedDataNode &node, const int version) - : PublishedData(node) +PublishedData::PublishedData(const PublishedDataNode &node, const int version) : PublishedData(node) { value.SetVersion(version); } @@ -85,10 +84,13 @@ bool PublishedDataNode::Unmarshal(const DistributedData::Serializable::json &nod bool ret = GetValue(node, GET_NAME(key), key); ret = ret && GetValue(node, GET_NAME(bundleName), bundleName); ret = ret && GetValue(node, GET_NAME(subscriberId), subscriberId); - ret = ret && GetValue(node, GET_NAME(value), value); + if (ret) { + GetValue(node, GET_NAME(value), value); + VersionData::Unmarshal(node); + } ret = ret && GetValue(node, GET_NAME(timestamp), timestamp); ret = ret && GetValue(node, GET_NAME(userId), userId); - return ret && VersionData::Unmarshal(node); + return ret; } PublishedDataNode::PublishedDataNode(const std::string &key, const std::string &bundleName, int64_t subscriberId, @@ -161,7 +163,8 @@ void PublishedData::ClearAging() } std::vector queryResults; int32_t status = delegate->GetBatch(KvDBDelegate::DATA_TABLE, "{}", - "{\"id_\": true, \"timestamp\": true, \"key\": true, \"bundleName\": true, \"subscriberId\": true}", + "{\"id_\": true, \"timestamp\": true, \"key\": true, \"bundleName\": true, \"subscriberId\": true, " + "\"userId\": true}", queryResults); if (status != E_OK) { ZLOGE("db GetBatch failed %{public}d", status); -- Gitee From cb31d569cf4bd17107fe0dd76c96df57dfdf5e7d Mon Sep 17 00:00:00 2001 From: Jeremyzzz Date: Wed, 28 Jun 2023 00:54:43 +0800 Subject: [PATCH 275/437] add head Signed-off-by: Jeremyzzz --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 22cb53bc..10afef3a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -14,9 +14,9 @@ */ #include "json_object.h" - #include #include +#include #include "doc_errno.h" #include "log_print.h" -- Gitee From 456e93eebb1f8dee70339c53ff961287494102a0 Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Sun, 25 Jun 2023 17:49:17 +0800 Subject: [PATCH 276/437] modify udmf build config Signed-off-by: ding_dong_dong --- BUILD.gn | 1 + bundle.json | 6 +- datamgr_service.gni | 4 + .../service/test/fuzztest/BUILD.gn | 21 ++ .../test/fuzztest/udmfservice_fuzzer/BUILD.gn | 68 ++++ .../fuzztest/udmfservice_fuzzer/corpus/init | 16 + .../fuzztest/udmfservice_fuzzer/project.xml | 25 ++ .../udmfservice_fuzzer/udmfservice_fuzzer.cpp | 54 +++ .../udmfservice_fuzzer/udmfservice_fuzzer.h | 21 ++ .../service/udmf/BUILD.gn | 74 ++++ .../service/udmf/data_manager.cpp | 341 ++++++++++++++++++ .../service/udmf/data_manager.h | 54 +++ .../udmf/lifecycle/clean_after_get.cpp | 21 ++ .../service/udmf/lifecycle/clean_after_get.h | 26 ++ .../udmf/lifecycle/clean_on_startup.cpp | 30 ++ .../service/udmf/lifecycle/clean_on_startup.h | 28 ++ .../udmf/lifecycle/clean_on_timeout.cpp | 30 ++ .../service/udmf/lifecycle/clean_on_timeout.h | 28 ++ .../udmf/lifecycle/lifecycle_manager.cpp | 92 +++++ .../udmf/lifecycle/lifecycle_manager.h | 47 +++ .../udmf/lifecycle/lifecycle_policy.cpp | 101 ++++++ .../service/udmf/lifecycle/lifecycle_policy.h | 44 +++ .../udmf/permission/checker_manager.cpp | 58 +++ .../service/udmf/permission/checker_manager.h | 51 +++ .../service/udmf/permission/data_checker.cpp | 46 +++ .../service/udmf/permission/data_checker.h | 35 ++ .../permission/uri_permission_manager.cpp | 46 +++ .../udmf/permission/uri_permission_manager.h | 33 ++ .../udmf/preprocess/preprocess_utils.cpp | 96 +++++ .../udmf/preprocess/preprocess_utils.h | 38 ++ .../service/udmf/same_process_ipc_guard.h | 43 +++ .../service/udmf/store/runtime_store.cpp | 313 ++++++++++++++++ .../service/udmf/store/runtime_store.h | 59 +++ .../service/udmf/store/store.h | 62 ++++ .../service/udmf/store/store_cache.cpp | 76 ++++ .../service/udmf/store/store_cache.h | 45 +++ .../service/udmf/udmf_service_impl.cpp | 108 ++++++ .../service/udmf/udmf_service_impl.h | 56 +++ .../service/udmf/udmf_service_stub.cpp | 269 ++++++++++++++ .../service/udmf/udmf_service_stub.h | 60 +++ 40 files changed, 2624 insertions(+), 2 deletions(-) create mode 100644 services/distributeddataservice/service/test/fuzztest/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.h create mode 100755 services/distributeddataservice/service/udmf/BUILD.gn create mode 100755 services/distributeddataservice/service/udmf/data_manager.cpp create mode 100755 services/distributeddataservice/service/udmf/data_manager.h create mode 100644 services/distributeddataservice/service/udmf/lifecycle/clean_after_get.cpp create mode 100644 services/distributeddataservice/service/udmf/lifecycle/clean_after_get.h create mode 100644 services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.cpp create mode 100644 services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.h create mode 100644 services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.cpp create mode 100644 services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.h create mode 100644 services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp create mode 100644 services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.h create mode 100644 services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp create mode 100644 services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h create mode 100755 services/distributeddataservice/service/udmf/permission/checker_manager.cpp create mode 100755 services/distributeddataservice/service/udmf/permission/checker_manager.h create mode 100755 services/distributeddataservice/service/udmf/permission/data_checker.cpp create mode 100755 services/distributeddataservice/service/udmf/permission/data_checker.h create mode 100755 services/distributeddataservice/service/udmf/permission/uri_permission_manager.cpp create mode 100755 services/distributeddataservice/service/udmf/permission/uri_permission_manager.h create mode 100755 services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp create mode 100644 services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h create mode 100644 services/distributeddataservice/service/udmf/same_process_ipc_guard.h create mode 100755 services/distributeddataservice/service/udmf/store/runtime_store.cpp create mode 100755 services/distributeddataservice/service/udmf/store/runtime_store.h create mode 100755 services/distributeddataservice/service/udmf/store/store.h create mode 100755 services/distributeddataservice/service/udmf/store/store_cache.cpp create mode 100755 services/distributeddataservice/service/udmf/store/store_cache.h create mode 100755 services/distributeddataservice/service/udmf/udmf_service_impl.cpp create mode 100755 services/distributeddataservice/service/udmf/udmf_service_impl.h create mode 100755 services/distributeddataservice/service/udmf/udmf_service_stub.cpp create mode 100755 services/distributeddataservice/service/udmf/udmf_service_stub.h diff --git a/BUILD.gn b/BUILD.gn index f2510207..609c8f50 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,6 +29,7 @@ group("fuzztest") { testonly = true deps = [] deps += [ + "services/distributeddataservice/service/test/fuzztest:fuzztest", "test/fuzztest/autolaunch_fuzzer:fuzztest", "test/fuzztest/kvstoredisksize_fuzzer:fuzztest", ] diff --git a/bundle.json b/bundle.json index 683a81f1..71456bba 100644 --- a/bundle.json +++ b/bundle.json @@ -74,7 +74,8 @@ "os_account", "relational_store", "safwk", - "samgr" + "samgr", + "udmf" ], "third_party": [ "cjson", @@ -92,7 +93,8 @@ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:build_module", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:build_module", "//foundation/distributeddatamgr/datamgr_service/conf:build_module", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module" + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module", + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/udmf:build_module" ], "inner_kits": [], "test": [ diff --git a/datamgr_service.gni b/datamgr_service.gni index 3a7b7e96..5e1d91c6 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -32,6 +32,10 @@ ipc_core_path = "//foundation/communication/ipc/interfaces/innerkits/ipc_core" device_manager_path = "//foundation/distributedhardware/device_manager" +data_service_path = "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice" + +udmf_path = "//foundation/distributeddatamgr/udmf" + declare_args() { datamgr_service_power = true if (!defined(global_parts_info.power_manager_native_powermgr_client) || diff --git a/services/distributeddataservice/service/test/fuzztest/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/BUILD.gn new file mode 100644 index 00000000..6152b951 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/BUILD.gn @@ -0,0 +1,21 @@ +# 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. + +import("//build/ohos.gni") + +######################################################################################### +group("fuzztest") { + testonly = true + + deps = [ "udmfservice_fuzzer:fuzztest" ] +} diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn new file mode 100644 index 00000000..30a81399 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("UdmfServiceFuzzTest") { + module_out_path = "datamgr_service/service" + + include_dirs = [ + "${udmf_path}/framework/common", + "${udmf_path}/interfaces/innerkits/common", + "${udmf_path}/interfaces/innerkits/data", + "${data_service_path}/framework/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + "${kv_store_path}/frameworks/common", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservice_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "udmfservice_fuzzer.cpp" ] + + deps = [ "${data_service_path}/service/udmf:udmf_server" ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp new file mode 100644 index 00000000..010f5bda --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "udmfservice_fuzzer.h" + +#include +#include + +#include "udmf_service_impl.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; + +bool OnRemoteRequestFuzz(const uint8_t* data, size_t size) +{ + uint32_t code = static_cast(*data); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + std::shared_ptr udmfServiceStub = std::make_shared(); + udmfServiceStub->OnRemoteRequest(code, request, reply); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.h new file mode 100644 index 00000000..d86d273e --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef UDMF_SERVICE_FUZZER_H +#define UDMF_SERVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservice_fuzzer" + +#endif // UDMF_SERVICE_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn new file mode 100755 index 00000000..64077d45 --- /dev/null +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -0,0 +1,74 @@ +# Copyright (c) 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. +import("//build/ohos.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +group("build_module") { + deps = [ ":udmf_server" ] +} + +config("module_public_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${udmf_path}/framework/common", + "${udmf_path}/interfaces/innerkits/common", + "${udmf_path}/interfaces/innerkits/data", + "${data_service_path}/framework/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + "${kv_store_path}/frameworks/common", + ] +} + +ohos_shared_library("udmf_server") { + sources = [ + "data_manager.cpp", + "lifecycle/clean_after_get.cpp", + "lifecycle/clean_on_startup.cpp", + "lifecycle/clean_on_timeout.cpp", + "lifecycle/lifecycle_manager.cpp", + "lifecycle/lifecycle_policy.cpp", + "permission/checker_manager.cpp", + "permission/data_checker.cpp", + "permission/uri_permission_manager.cpp", + "preprocess/preprocess_utils.cpp", + "store/runtime_store.cpp", + "store/store_cache.cpp", + "udmf_service_impl.cpp", + "udmf_service_stub.cpp", + ] + + configs = [ ":module_public_config" ] + + deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "udmf:udmf_client", + ] + + subsystem_name = "distributeddatamgr" + + part_name = "datamgr_service" +} diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp new file mode 100755 index 00000000..7b4bc0a3 --- /dev/null +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -0,0 +1,341 @@ +/* + * 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. + */ +#define LOG_TAG "DataManager" + +#include "data_manager.h" + +#include "checker_manager.h" +#include "file.h" +#include "lifecycle/lifecycle_manager.h" +#include "log_print.h" +#include "preprocess_utils.h" +#include "uri_permission_manager.h" + +namespace OHOS { +namespace UDMF { +const std::string MSDP_PROCESS_NAME = "msdp_sa"; +const std::string DATA_PREFIX = "udmf://"; +DataManager::DataManager() +{ + authorizationMap_[UD_INTENTION_MAP.at(UD_INTENTION_DRAG)] = MSDP_PROCESS_NAME; + CheckerManager::GetInstance().LoadCheckers(); +} + +DataManager::~DataManager() +{ +} + +DataManager &DataManager::GetInstance() +{ + static DataManager instance; + return instance; +} + +int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key) +{ + if (unifiedData.IsEmpty()) { + ZLOGE("Invalid parameters, have no record"); + return E_INVALID_PARAMETERS; + } + + if (!UnifiedDataUtils::IsValidIntention(option.intention)) { + ZLOGE("Invalid parameters intention: %{public}d.", option.intention); + return E_INVALID_PARAMETERS; + } + + // imput runtime info before put it into store and save one privilege + if (PreProcessUtils::RuntimeDataImputation(unifiedData, option) != E_OK) { + ZLOGE("Imputation failed"); + return E_UNKNOWN; + } + for (auto &record : unifiedData.GetRecords()) { + std::string uid = PreProcessUtils::IdGenerator(); + record->SetUid(uid); + } + + std::string intention = unifiedData.GetRuntime()->key.intention; + auto store = storeCache_.GetStore(intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + + if (!UnifiedDataUtils::IsPersist(intention) && store->Clear() != E_OK) { + ZLOGE("Clear store failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + + if (store->Put(unifiedData) != E_OK) { + ZLOGE("Put unified data failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + key = unifiedData.GetRuntime()->key.GetUnifiedKey(); + ZLOGD("Put unified data successful, key: %{public}s.", key.c_str()); + return E_OK; +} + +int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unifiedData) +{ + UnifiedKey key(query.key); + if (!key.IsValid()) { + ZLOGE("Unified key: %{public}s is invalid.", query.key.c_str()); + return E_INVALID_PARAMETERS; + } + auto store = storeCache_.GetStore(key.intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + int32_t res = store->Get(query.key, unifiedData); + if (res != E_OK) { + ZLOGE("Get data from store failed, intention: %{public}s.", key.intention.c_str()); + return res; + } + if (unifiedData.IsEmpty()) { + return E_OK; + } + std::shared_ptr runtime = unifiedData.GetRuntime(); + CheckerManager::CheckInfo info; + info.tokenId = query.tokenId; + if (!CheckerManager::GetInstance().IsValid(runtime->privileges, info)) { + return E_NO_PERMISSION; + } + std::string bundleName; + if (!PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName)) { + return E_ERROR; + } + if (runtime->createPackage != bundleName) { + auto records = unifiedData.GetRecords(); + for (auto record : records) { + auto type = record->GetType(); + std::string uri = ""; + if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO + || type == UDType::FOLDER) { + auto file = static_cast(record.get()); + uri = file->GetUri(); + } + if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { + return E_NO_PERMISSION; + } + } + } + if (LifeCycleManager::GetInstance().DeleteOnGet(key) != E_OK) { + ZLOGE("Remove data failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} + +int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector &unifiedDataSet) +{ + std::vector dataSet; + std::shared_ptr store; + auto status = QueryDataCommon(query, dataSet, store); + if (status != E_OK) { + ZLOGE("QueryDataCommon failed."); + return status; + } + if (dataSet.empty()) { + ZLOGW("DataSet has no data, key: %{public}s, intention: %{public}d.", query.key.c_str(), query.intention); + return E_OK; + } + for (const auto &data : dataSet) { + unifiedDataSet.push_back(data); + } + return E_OK; +} + +int32_t DataManager::UpdateData(const QueryOption &query, UnifiedData &unifiedData) +{ + UnifiedKey key(query.key); + if (!key.IsValid()) { + ZLOGE("Unified key: %{public}s is invalid.", query.key.c_str()); + return E_INVALID_PARAMETERS; + } + if (unifiedData.IsEmpty()) { + ZLOGE("Invalid parameters, unified data has no record."); + return E_INVALID_PARAMETERS; + } + auto store = storeCache_.GetStore(key.intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + + UnifiedData data; + int32_t res = store->Get(query.key, data); + if (res != E_OK) { + ZLOGE("Get data from store failed, intention: %{public}s.", key.intention.c_str()); + return res; + } + if (data.IsEmpty()) { + ZLOGE("Invalid parameter, unified data has no record; intention: %{public}s.", key.intention.c_str()); + return E_INVALID_PARAMETERS; + } + std::shared_ptr runtime = data.GetRuntime(); + runtime->lastModifiedTime = PreProcessUtils::GetTimeStamp(); + unifiedData.SetRuntime(*runtime); + for (auto &record : unifiedData.GetRecords()) { + record->SetUid(PreProcessUtils::IdGenerator()); + } + if (store->Update(unifiedData) != E_OK) { + ZLOGE("Update unified data failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} +int32_t DataManager::DeleteData(const QueryOption &query, std::vector &unifiedDataSet) +{ + std::vector dataSet; + std::shared_ptr store; + auto status = QueryDataCommon(query, dataSet, store); + if (status != E_OK) { + ZLOGE("QueryDataCommon failed."); + return status; + } + if (dataSet.empty()) { + ZLOGW("DataSet has no data, key: %{public}s, intention: %{public}d.", query.key.c_str(), query.intention); + return E_OK; + } + std::shared_ptr runtime; + std::vector deleteKeys; + for (const auto &data : dataSet) { + runtime = data.GetRuntime(); + unifiedDataSet.push_back(data); + deleteKeys.push_back(runtime->key.key); + } + if (store->DeleteBatch(deleteKeys) != E_OK) { + ZLOGE("Remove data failed."); + return E_DB_ERROR; + } + return E_OK; +} + +int32_t DataManager::GetSummary(const QueryOption &query, Summary &summary) +{ + UnifiedKey key(query.key); + if (!key.IsValid()) { + ZLOGE("Unified key: %{public}s is invalid.", query.key.c_str()); + return E_INVALID_PARAMETERS; + } + + auto store = storeCache_.GetStore(key.intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + + if (store->GetSummary(query.key, summary) != E_OK) { + ZLOGE("Store get summary failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} + +int32_t DataManager::AddPrivilege(const QueryOption &query, const Privilege &privilege) +{ + UnifiedKey key(query.key); + if (!key.IsValid()) { + ZLOGE("Unified key: %{public}s is invalid.", query.key.c_str()); + return E_INVALID_PARAMETERS; + } + + std::string processName; + if (!PreProcessUtils::GetNativeProcessNameByToken(query.tokenId, processName)) { + return E_UNKNOWN; + } + + if (processName != authorizationMap_[key.intention]) { + ZLOGE("Process: %{public}s have no permission", processName.c_str()); + return E_NO_PERMISSION; + } + + auto store = storeCache_.GetStore(key.intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + + UnifiedData data; + int32_t res = store->Get(query.key, data); + if (res != E_OK) { + ZLOGE("Get data from store failed, intention: %{public}s.", key.intention.c_str()); + return res; + } + + if (data.IsEmpty()) { + ZLOGE("Invalid parameters, unified data has no record, intention: %{public}s.", key.intention.c_str()); + return E_INVALID_PARAMETERS; + } + + data.GetRuntime()->privileges.emplace_back(privilege); + if (store->Update(data) != E_OK) { + ZLOGE("Update unified data failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} + +int32_t DataManager::Sync(const QueryOption &query, const std::vector &devices) +{ + UnifiedKey key(query.key); + if (!key.IsValid()) { + ZLOGE("Unified key: %{public}s is invalid.", query.key.c_str()); + return E_INVALID_PARAMETERS; + } + + auto store = storeCache_.GetStore(key.intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + + if (store->Sync(devices) != E_OK) { + ZLOGE("Store sync failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} + +int32_t DataManager::QueryDataCommon( + const QueryOption &query, std::vector &dataSet, std::shared_ptr &store) +{ + auto find = UD_INTENTION_MAP.find(query.intention); + std::string intention = find == UD_INTENTION_MAP.end() ? intention : find->second; + if (!UnifiedDataUtils::IsValidOptions(query.key, intention)) { + ZLOGE("Unified key: %{public}s and intention: %{public}s is invalid.", query.key.c_str(), intention.c_str()); + return E_INVALID_PARAMETERS; + } + std::string dataPrefix = DATA_PREFIX + intention; + UnifiedKey key(query.key); + key.IsValid(); + if (intention.empty()) { + dataPrefix = key.key; + intention = key.intention; + } + ZLOGD("dataPrefix = %{public}s, intention: %{public}s.", dataPrefix.c_str(), intention.c_str()); + store = storeCache_.GetStore(intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + if (store->GetBatchData(dataPrefix, dataSet) != E_OK) { + ZLOGE("Get dataSet failed, dataPrefix: %{public}s.", dataPrefix.c_str()); + return E_DB_ERROR; + } + return E_OK; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/data_manager.h b/services/distributeddataservice/service/udmf/data_manager.h new file mode 100755 index 00000000..608d608c --- /dev/null +++ b/services/distributeddataservice/service/udmf/data_manager.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#ifndef UDMF_DATA_MANAGER_H +#define UDMF_DATA_MANAGER_H + +#include +#include +#include +#include + +#include "error_code.h" +#include "store_cache.h" +#include "unified_data.h" +#include "unified_types.h" + +namespace OHOS { +namespace UDMF { +class DataManager { +public: + virtual ~DataManager(); + + static DataManager &GetInstance(); + + int32_t SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key); + int32_t RetrieveData(const QueryOption &query, UnifiedData &unifiedData); + int32_t RetrieveBatchData(const QueryOption &query, std::vector &unifiedDataSet); + int32_t UpdateData(const QueryOption &query, UnifiedData &unifiedData); + int32_t DeleteData(const QueryOption &query, std::vector &unifiedDataSet); + int32_t GetSummary(const QueryOption &query, Summary &summary); + int32_t AddPrivilege(const QueryOption &query, const Privilege &privilege); + int32_t Sync(const QueryOption &query, const std::vector &devices); + +private: + DataManager(); + int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); + StoreCache storeCache_; + std::map authorizationMap_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_DATA_MANAGER_H diff --git a/services/distributeddataservice/service/udmf/lifecycle/clean_after_get.cpp b/services/distributeddataservice/service/udmf/lifecycle/clean_after_get.cpp new file mode 100644 index 00000000..54fc5545 --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/clean_after_get.cpp @@ -0,0 +1,21 @@ +/* + * 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 "clean_after_get.h" + +namespace OHOS { +namespace UDMF { +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/lifecycle/clean_after_get.h b/services/distributeddataservice/service/udmf/lifecycle/clean_after_get.h new file mode 100644 index 00000000..1e94b5fb --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/clean_after_get.h @@ -0,0 +1,26 @@ +/* + * 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. + */ +#ifndef UDMF_CLEAN_AFTER_GET_H +#define UDMF_CLEAN_AFTER_GET_H +#include "lifecycle_policy.h" + +namespace OHOS { +namespace UDMF { +class CleanAfterGet : public LifeCyclePolicy { +public: +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_CLEAN_AFTER_GET_H diff --git a/services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.cpp b/services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.cpp new file mode 100644 index 00000000..eef045ff --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.cpp @@ -0,0 +1,30 @@ +/* + * 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 "clean_on_startup.h" + +namespace OHOS { +namespace UDMF { +Status CleanOnStartup::DeleteOnTimeout(const std::string &intention) +{ + return E_OK; +} + +Status CleanOnStartup::DeleteOnGet(const UnifiedKey &key) +{ + return E_OK; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.h b/services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.h new file mode 100644 index 00000000..b269743a --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/clean_on_startup.h @@ -0,0 +1,28 @@ +/* + * 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. + */ +#ifndef UDMF_CLEAN_ON_STARTUP_H +#define UDMF_CLEAN_ON_STARTUP_H +#include "lifecycle_policy.h" + +namespace OHOS { +namespace UDMF { +class CleanOnStartup : public LifeCyclePolicy { +public: + Status DeleteOnTimeout(const std::string &intention) override; + Status DeleteOnGet(const UnifiedKey &key) override; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_CLEAN_ON_STARTUP_H diff --git a/services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.cpp b/services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.cpp new file mode 100644 index 00000000..6b36eadf --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.cpp @@ -0,0 +1,30 @@ +/* + * 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 "clean_on_timeout.h" + +namespace OHOS { +namespace UDMF { +Status CleanOnTimeout::DeleteOnStart(const std::string &intention) +{ + return LifeCyclePolicy::DeleteOnTimeout(intention); +} + +Status CleanOnTimeout::DeleteOnGet(const UnifiedKey &key) +{ + return E_OK; +} +} // namespace UDMF +} // namespace OHOS diff --git a/services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.h b/services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.h new file mode 100644 index 00000000..d86be258 --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/clean_on_timeout.h @@ -0,0 +1,28 @@ +/* + * 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. + */ +#ifndef UDMF_CLEAN_ON_TIMEOUT_H +#define UDMF_CLEAN_ON_TIMEOUT_H +#include "lifecycle_policy.h" + +namespace OHOS { +namespace UDMF { +class CleanOnTimeout : public LifeCyclePolicy { +public: + Status DeleteOnStart(const std::string &intention) override; + Status DeleteOnGet(const UnifiedKey &key) override; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_CLEAN_ON_TIMEOUT_H diff --git a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp new file mode 100644 index 00000000..c285644f --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.cpp @@ -0,0 +1,92 @@ +/* + * 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. + */ +#define LOG_TAG "LifeCycleManager" + +#include "lifecycle_manager.h" + +#include +#include + +#include "log_print.h" + +namespace OHOS { +namespace UDMF { +std::shared_ptr LifeCycleManager::executorPool_ = std::make_shared(2, 1); + +std::unordered_map> LifeCycleManager::intentionPolicyMap_ = { + { UD_INTENTION_MAP.at(UD_INTENTION_DRAG), std::make_shared() }, +}; + +LifeCycleManager &LifeCycleManager::GetInstance() +{ + static LifeCycleManager instance; + return instance; +} + +Status LifeCycleManager::DeleteOnGet(const UnifiedKey &key) +{ + auto findPolicy = intentionPolicyMap_.find(key.intention); + if (findPolicy == intentionPolicyMap_.end()) { + ZLOGE("Invalid intention, intention: %{public}s.", key.intention.c_str()); + return E_INVALID_PARAMETERS; + } + auto policy = findPolicy->second; + return policy->DeleteOnGet(key); +} + +Status LifeCycleManager::DeleteOnStart() +{ + Status status = E_OK; + std::shared_ptr LifeCyclePolicy; + for (const auto &intentionPolicyPair : intentionPolicyMap_) { + LifeCyclePolicy = GetPolicy(intentionPolicyPair.first); + status = status == E_OK ? LifeCyclePolicy->DeleteOnStart(intentionPolicyPair.first) : status; + } + return status; +} + +Status LifeCycleManager::DeleteOnSchedule() +{ + ExecutorPool::TaskId taskId = + executorPool_->Schedule(&LifeCycleManager::DeleteOnTimeout, LifeCyclePolicy::INTERVAL); + if (taskId == ExecutorPool::INVALID_TASK_ID) { + ZLOGE("ExecutorPool Schedule failed."); + return E_ERROR; + } + ZLOGI("ScheduleTask start, TaskId: %{public}" PRIu64 ".", taskId); + return E_OK; +} + +std::shared_ptr LifeCycleManager::GetPolicy(const std::string &intention) +{ + auto findPolicy = intentionPolicyMap_.find(intention); + if (findPolicy == intentionPolicyMap_.end()) { + return nullptr; + } + return findPolicy->second; +} + +Status LifeCycleManager::DeleteOnTimeout() +{ + Status status = E_OK; + std::shared_ptr LifeCyclePolicy; + for (const auto &intentionPolicyPair : intentionPolicyMap_) { + LifeCyclePolicy = LifeCycleManager::GetInstance().GetPolicy(intentionPolicyPair.first); + status = status == E_OK ? LifeCyclePolicy->DeleteOnTimeout(intentionPolicyPair.first) : status; + } + return status; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.h b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.h new file mode 100644 index 00000000..e73032d9 --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_manager.h @@ -0,0 +1,47 @@ +/* + * 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. + */ +#ifndef UDMF_LIFECYCLE_MANAGER_H +#define UDMF_LIFECYCLE_MANAGER_H + +#include +#include +#include +#include +#include + +#include "clean_after_get.h" +#include "clean_on_startup.h" +#include "clean_on_timeout.h" +#include "executor_pool.h" +#include "lifecycle_policy.h" + +namespace OHOS { +namespace UDMF { +class LifeCycleManager { +public: + static LifeCycleManager &GetInstance(); + Status DeleteOnGet(const UnifiedKey &key); + Status DeleteOnStart(); + Status DeleteOnSchedule(); + +private: + static std::shared_ptr executorPool_; + static std::unordered_map> intentionPolicyMap_; + static std::shared_ptr GetPolicy(const std::string &intention); + static Status DeleteOnTimeout(); +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_LIFECYCLE_MANAGER_H diff --git a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp new file mode 100644 index 00000000..7e790fb9 --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.cpp @@ -0,0 +1,101 @@ +/* + * 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. + */ +#define LOG_TAG "LifeCyclePolicy" + +#include "lifecycle_policy.h" + +#include + +#include "log_print.h" +#include "preprocess/preprocess_utils.h" + +namespace OHOS { +namespace UDMF { +using namespace std::chrono; +const LifeCyclePolicy::Duration LifeCyclePolicy::INTERVAL = milliseconds(60 * 60 * 1000); +const std::string LifeCyclePolicy::DATA_PREFIX = "udmf://"; + +Status LifeCyclePolicy::DeleteOnGet(const UnifiedKey &key) +{ + auto store = storeCache_.GetStore(key.intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + if (store->Delete(key.key) != E_OK) { + ZLOGE("Remove data failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} + +Status LifeCyclePolicy::DeleteOnStart(const std::string &intention) +{ + auto store = storeCache_.GetStore(intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + if (store->Clear() != E_OK) { + ZLOGE("Remove data failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} + +Status LifeCyclePolicy::DeleteOnTimeout(const std::string &intention) +{ + auto store = storeCache_.GetStore(intention); + if (store == nullptr) { + ZLOGE("Get store failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + std::vector timeoutKeys; + auto status = GetTimeoutKeys(store, INTERVAL, timeoutKeys); + if (status != E_OK) { + ZLOGE("Get timeout keys failed."); + return E_DB_ERROR; + } + if (store->DeleteBatch(timeoutKeys) != E_OK) { + ZLOGE("Remove data failed, intention: %{public}s.", intention.c_str()); + return E_DB_ERROR; + } + return E_OK; +} + +Status LifeCyclePolicy::GetTimeoutKeys( + const std::shared_ptr &store, Duration interval, std::vector &timeoutKeys) +{ + std::vector datas; + auto status = store->GetBatchData(DATA_PREFIX, datas); + if (status != E_OK) { + ZLOGE("Get data failed."); + return E_DB_ERROR; + } + if (datas.empty()) { + ZLOGD("entries is empty."); + return E_OK; + } + auto curTime = PreProcessUtils::GetTimeStamp(); + for (const auto &data : datas) { + if (curTime > data.GetRuntime()->createTime + duration_cast(interval).count() + || curTime < data.GetRuntime()->createTime) { + timeoutKeys.push_back(data.GetRuntime()->key.key); + } + } + return E_OK; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h new file mode 100644 index 00000000..45f8e63a --- /dev/null +++ b/services/distributeddataservice/service/udmf/lifecycle/lifecycle_policy.h @@ -0,0 +1,44 @@ +/* + * 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. + */ +#ifndef UDMF_LIFECYCLE_POLICY_H +#define UDMF_LIFECYCLE_POLICY_H + +#include +#include + +#include "store_cache.h" +#include "unified_key.h" + +namespace OHOS { +namespace UDMF { +class LifeCyclePolicy { +public: + using Duration = std::chrono::steady_clock::duration; + static const Duration INTERVAL; + virtual ~LifeCyclePolicy() = default; + virtual Status DeleteOnGet(const UnifiedKey &key); + virtual Status DeleteOnStart(const std::string &intention); + virtual Status DeleteOnTimeout(const std::string &intention); + virtual Status GetTimeoutKeys( + const std::shared_ptr &store, Duration interval, std::vector &timeoutKeys); + +private: + static const std::string DATA_PREFIX; + StoreCache storeCache_; +}; +} // namespace UDMF +} // namespace OHOS + +#endif // UDMF_LIFECYCLE_POLICY_H \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/permission/checker_manager.cpp b/services/distributeddataservice/service/udmf/permission/checker_manager.cpp new file mode 100755 index 00000000..1e925398 --- /dev/null +++ b/services/distributeddataservice/service/udmf/permission/checker_manager.cpp @@ -0,0 +1,58 @@ +/* + * 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 "checker_manager.h" + +namespace OHOS { +namespace UDMF { +const std::string DATA_CHECKER = "DataChecker"; +CheckerManager &CheckerManager::GetInstance() +{ + static CheckerManager instance; + return instance; +} + +void CheckerManager::RegisterChecker(const std::string &checker, std::function getter) +{ + getters_.ComputeIfAbsent(checker, [&getter](const auto &) { + return move(getter); + }); +} + +void CheckerManager::LoadCheckers() +{ + getters_.ForEach([this] (const auto &key, const auto &val) { + if (this->checkers_.find(key) != this->checkers_.end()) { + return false; + } + auto *checker = val(); + if (checker == nullptr) { + return false; + } + this->checkers_[key] = checker; + return false; + }); +} + +bool CheckerManager::IsValid(const std::vector &privileges, const CheckInfo &info) +{ + auto it = checkers_.find(DATA_CHECKER); + if (it == checkers_.end()) { + return true; + } + return it->second->IsValid(privileges, info); +} +} // namespace UDMF +} // namespace OHOS diff --git a/services/distributeddataservice/service/udmf/permission/checker_manager.h b/services/distributeddataservice/service/udmf/permission/checker_manager.h new file mode 100755 index 00000000..3145fd0c --- /dev/null +++ b/services/distributeddataservice/service/udmf/permission/checker_manager.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef UDMF_CHECKER_MANAGER_H +#define UDMF_CHECKER_MANAGER_H + +#include + +#include "concurrent_map.h" +#include "unified_types.h" + +namespace OHOS { +namespace UDMF { +class CheckerManager { +public: + struct CheckInfo { + uint32_t tokenId; + }; + + class Checker { + public: + virtual bool IsValid(const std::vector &privileges, const CheckInfo &info) = 0; + protected: + ~Checker() = default; + }; + + static CheckerManager &GetInstance(); + + void RegisterChecker(const std::string &checker, std::function getter); + void LoadCheckers(); + bool IsValid(const std::vector &privileges, const CheckInfo &info); + +private: + std::map checkers_; + ConcurrentMap> getters_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_CHECKER_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/permission/data_checker.cpp b/services/distributeddataservice/service/udmf/permission/data_checker.cpp new file mode 100755 index 00000000..ac0588f9 --- /dev/null +++ b/services/distributeddataservice/service/udmf/permission/data_checker.cpp @@ -0,0 +1,46 @@ +/* + * 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. + */ +#define LOG_TAG "DataChecker" + +#include "data_checker.h" + +#include "utils/anonymous.h" +#include "log_print.h" + +namespace OHOS { +namespace UDMF { +__attribute__((used)) DataChecker DataChecker::instance_; +DataChecker::DataChecker() noexcept +{ + CheckerManager::GetInstance().RegisterChecker( + "DataChecker", [this]() -> auto { return this; }); +} + +DataChecker::~DataChecker() +{ +} + +bool DataChecker::IsValid(const std::vector &privileges, const CheckerManager::CheckInfo &info) +{ + for (const auto &privilege : privileges) { + if (privilege.tokenId == info.tokenId) { + return true; + } + } + ZLOGE("Invalid parameters, %{public}s", DistributedData::Anonymous::Change(std::to_string(info.tokenId)).c_str()); + return false; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/permission/data_checker.h b/services/distributeddataservice/service/udmf/permission/data_checker.h new file mode 100755 index 00000000..5aec008f --- /dev/null +++ b/services/distributeddataservice/service/udmf/permission/data_checker.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef UDMF_DATA_CHECKER_H +#define UDMF_DATA_CHECKER_H + +#include "checker_manager.h" + +namespace OHOS { +namespace UDMF { +class DataChecker : public CheckerManager::Checker { +public: + DataChecker() noexcept; + ~DataChecker(); + + bool IsValid(const std::vector &privileges, const CheckerManager::CheckInfo &info) override; + +private: + static DataChecker instance_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_DATA_CHECKER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/permission/uri_permission_manager.cpp b/services/distributeddataservice/service/udmf/permission/uri_permission_manager.cpp new file mode 100755 index 00000000..d5771ce6 --- /dev/null +++ b/services/distributeddataservice/service/udmf/permission/uri_permission_manager.cpp @@ -0,0 +1,46 @@ +/* + * 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. + */ +#define LOG_TAG "UriPermissionManager" + +#include "uri_permission_manager.h" + +#include "want.h" +#include "uri.h" +#include "uri_permission_manager_client.h" + +#include "log_print.h" + +namespace OHOS { +namespace UDMF { +UriPermissionManager &UriPermissionManager::GetInstance() +{ + static UriPermissionManager instance; + return instance; +} + +Status UriPermissionManager::GrantUriPermission(const std::string &path, const std::string &bundleName) +{ + Uri uri(path); + int autoRemove = 1; + auto status = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission( + uri, AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, bundleName, autoRemove); + if (status != ERR_OK) { + ZLOGE("GrantUriPermission failed, %{public}d", status); + return E_ERROR; + } + return E_OK; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/permission/uri_permission_manager.h b/services/distributeddataservice/service/udmf/permission/uri_permission_manager.h new file mode 100755 index 00000000..db32e311 --- /dev/null +++ b/services/distributeddataservice/service/udmf/permission/uri_permission_manager.h @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#ifndef UDMF_URI_PERMISSION_MANAGER_H +#define UDMF_URI_PERMISSION_MANAGER_H + +#include +#include + +#include "error_code.h" + +namespace OHOS { +namespace UDMF { +class UriPermissionManager { +public: + static UriPermissionManager &GetInstance(); + Status GrantUriPermission(const std::string &path, const std::string &bundleName); +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_URI_PERMISSION_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp new file mode 100755 index 00000000..130ffa20 --- /dev/null +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -0,0 +1,96 @@ +/* + * 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 "preprocess_utils.h" + +#include + +#include "error_code.h" +#include "accesstoken_kit.h" +#include "bundlemgr/bundle_mgr_client_impl.h" +#include "ipc_skeleton.h" + +namespace OHOS { +namespace UDMF { +static constexpr int ID_LEN = 32; +const char SPECIAL = '^'; +int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &option) +{ + auto it = UD_INTENTION_MAP.find(option.intention); + if (it == UD_INTENTION_MAP.end()) { + return E_UNKNOWN; + } + std::string bundleName; + GetHapBundleNameByToken(option.tokenId, bundleName); + std::string intention = it->second; + UnifiedKey key(intention, bundleName, IdGenerator()); + Privilege privilege; + privilege.tokenId = option.tokenId; + Runtime runtime; + runtime.key = key; + runtime.privileges.emplace_back(privilege); + runtime.createTime = GetTimeStamp(); + runtime.sourcePackage = bundleName; + runtime.createPackage = bundleName; + data.SetRuntime(runtime); + return E_OK; +} + +std::string PreProcessUtils::IdGenerator() +{ + std::random_device randomDevice; + int minimum = 48; + int maximum = 121; + std::uniform_int_distribution distribution(minimum, maximum); + std::stringstream idStr; + for (int32_t i = 0; i < ID_LEN; i++) { + auto asc = distribution(randomDevice); + asc = asc >= SPECIAL ? asc + 1 : asc; + idStr << static_cast(asc); + } + return idStr.str(); +} + +time_t PreProcessUtils::GetTimeStamp() +{ + std::chrono::time_point tp = + std::chrono::time_point_cast(std::chrono::system_clock::now()); + time_t timestamp = tp.time_since_epoch().count(); + return timestamp; +} + +bool PreProcessUtils::GetHapBundleNameByToken(int tokenId, std::string &bundleName) +{ + Security::AccessToken::HapTokenInfo hapInfo; + if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) + != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { + return false; + } + bundleName = hapInfo.bundleName; + return true; +} + +bool PreProcessUtils::GetNativeProcessNameByToken(int tokenId, std::string &processName) +{ + Security::AccessToken::NativeTokenInfo nativeInfo; + if (Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, nativeInfo) + != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { + return false; + } + processName = nativeInfo.processName; + return true; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h new file mode 100644 index 00000000..175027ea --- /dev/null +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -0,0 +1,38 @@ +/* + * 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. + */ +#ifndef UDMF_PREPROCESS_UTILS_H +#define UDMF_PREPROCESS_UTILS_H + +#include +#include +#include +#include + +#include "unified_data.h" +#include "unified_meta.h" + +namespace OHOS { +namespace UDMF { +class PreProcessUtils { +public: + static int32_t RuntimeDataImputation(UnifiedData &data, CustomOption &option); + static std::string IdGenerator(); + static time_t GetTimeStamp(); + static bool GetHapBundleNameByToken(int tokenId, std::string &bundleName); + static bool GetNativeProcessNameByToken(int tokenId, std::string &processName); +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_PREPROCESS_UTILS_H \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/same_process_ipc_guard.h b/services/distributeddataservice/service/udmf/same_process_ipc_guard.h new file mode 100644 index 00000000..02ecb47e --- /dev/null +++ b/services/distributeddataservice/service/udmf/same_process_ipc_guard.h @@ -0,0 +1,43 @@ +/* +* 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. +*/ + +#ifndef UDMF_SAMEPROCESSIPCGUARD_H +#define UDMF_SAMEPROCESSIPCGUARD_H + +#include + +#include "ipc_skeleton.h" + +namespace OHOS { +namespace UDMF { +class SameProcessIpcGuard { +public: + SameProcessIpcGuard() + { + identity = IPCSkeleton::ResetCallingIdentity(); + } + + ~SameProcessIpcGuard() + { + IPCSkeleton::SetCallingIdentity(identity); + } + +private: + std::string identity; +}; +} // namespace UDMF +} // namespace OHOS + +#endif // UDMF_SAMEPROCESSIPCGUARD_H \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp new file mode 100755 index 00000000..c5248de1 --- /dev/null +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -0,0 +1,313 @@ +/* + * 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. + */ +#define LOG_TAG "RuntimeStore" + +#include "runtime_store.h" + +#include +#include + +#include "log_print.h" +#include "same_process_ipc_guard.h" +#include "tlv_util.h" + +namespace OHOS { +namespace UDMF { +using namespace DistributedKv; +const AppId RuntimeStore::APP_ID = { "distributeddata" }; +const std::string RuntimeStore::DATA_PREFIX = "udmf://"; +const std::string RuntimeStore::BASE_DIR = "/data/service/el1/public/database/distributeddata"; + +RuntimeStore::RuntimeStore(const std::string &storeId) : storeId_({ storeId }) +{ + updateTime(); + ZLOGI("Construct runtimeStore: %{public}s.", storeId_.storeId.c_str()); +} + +RuntimeStore::~RuntimeStore() +{ + ZLOGI("Destruct runtimeStore: %{public}s.", storeId_.storeId.c_str()); + Close(); +} + +Status RuntimeStore::Put(const UnifiedData &unifiedData) +{ + updateTime(); + std::vector entries; + std::string unifiedKey = unifiedData.GetRuntime()->key.GetUnifiedKey(); + // add unified record + for (const auto &record : unifiedData.GetRecords()) { + if (record == nullptr) { + ZLOGE("record is nullptr."); + return E_INVALID_PARAMETERS; + } + + std::vector recordBytes; + auto recordTlv = TLVObject(recordBytes); + if (!TLVUtil::Writing(record, recordTlv)) { + ZLOGI("Marshall unified record failed."); + return E_WRITE_PARCEL_ERROR; + } + + Entry entry = { Key(unifiedKey + "/" + record->GetUid()), Value(recordBytes) }; + entries.push_back(entry); + } + // add runtime info + std::vector runtimeBytes; + auto runtimeTlv = TLVObject(runtimeBytes); + if (!TLVUtil::Writing(*unifiedData.GetRuntime(), runtimeTlv)) { + ZLOGI("Marshall runtime info failed."); + return E_WRITE_PARCEL_ERROR; + } + Entry entry = { Key(unifiedKey), Value(runtimeBytes) }; + entries.push_back(entry); + auto status = PutEntries(entries); + return status; +} + +Status RuntimeStore::Get(const std::string &key, UnifiedData &unifiedData) +{ + updateTime(); + std::vector entries; + if (GetEntries(key, entries) != E_OK) { + ZLOGI("GetEntries failed, dataPrefix: %{public}s.", key.c_str()); + return E_DB_ERROR; + } + if (entries.empty()) { + ZLOGD("entries is empty."); + return E_OK; + } + return UnMarshalEntries(key, entries, unifiedData); +} + +Status RuntimeStore::GetSummary(const std::string &key, Summary &summary) +{ + updateTime(); + UnifiedData unifiedData; + if (Get(key, unifiedData) != E_OK) { + ZLOGE("Get unified data failed."); + return E_DB_ERROR; + } + + for (const auto &record : unifiedData.GetRecords()) { + int64_t recordSize = record->GetSize(); + auto it = summary.summary.find(UD_TYPE_MAP.at(record->GetType())); + if (it == summary.summary.end()) { + summary.summary[UD_TYPE_MAP.at(record->GetType())] = recordSize; + } else { + summary.summary[UD_TYPE_MAP.at(record->GetType())] += recordSize; + } + summary.totalSize += recordSize; + } + return E_OK; +} + +Status RuntimeStore::Update(const UnifiedData &unifiedData) +{ + updateTime(); + std::string key = unifiedData.GetRuntime()->key.key; + if (Delete(key) != E_OK) { + ZLOGE("Delete unified data failed."); + return E_DB_ERROR; + } + if (Put(unifiedData) != E_OK) { + ZLOGE("Put unified data failed."); + return E_DB_ERROR; + } + return E_OK; +} + +Status RuntimeStore::Delete(const std::string &key) +{ + updateTime(); + std::vector entries; + if (GetEntries(key, entries) != E_OK) { + ZLOGE("GetEntries failed, dataPrefix: %{public}s.", key.c_str()); + return E_DB_ERROR; + } + if (entries.empty()) { + ZLOGD("entries is empty."); + return E_OK; + } + std::vector keys; + for (const auto &entry : entries) { + keys.push_back(entry.key); + } + return DeleteEntries(keys); +} + +Status RuntimeStore::DeleteBatch(const std::vector &unifiedKeys) +{ + updateTime(); + ZLOGD("called!"); + if (unifiedKeys.empty()) { + ZLOGD("No need to delete!"); + return E_OK; + } + for (const std::string &unifiedKey : unifiedKeys) { + if (Delete(unifiedKey) != E_OK) { + ZLOGE("Delete failed, key: %{public}s.", unifiedKey.c_str()); + return E_DB_ERROR; + } + } + return E_OK; +} + +Status RuntimeStore::Sync(const std::vector &devices) +{ + updateTime(); + SameProcessIpcGuard ipcGuard; + DistributedKv::Status status = kvStore_->Sync(devices, SyncMode::PULL); + if (status != DistributedKv::Status::SUCCESS) { + ZLOGE("Sync kvStore failed, status: %{public}d.", status); + return E_DB_ERROR; + } + return E_OK; +} + +Status RuntimeStore::Clear() +{ + updateTime(); + return Delete(DATA_PREFIX); +} + +Status RuntimeStore::GetBatchData(const std::string &dataPrefix, std::vector &unifiedDataSet) +{ + updateTime(); + std::vector entries; + auto status = GetEntries(dataPrefix, entries); + if (status != E_OK) { + ZLOGE("GetEntries failed, dataPrefix: %{public}s.", dataPrefix.c_str()); + return E_DB_ERROR; + } + if (entries.empty()) { + ZLOGD("entries is empty."); + return E_OK; + } + std::vector keySet; + for (const auto &entry : entries) { + std::string keyStr = entry.key.ToString(); + if (std::count(keyStr.begin(), keyStr.end(), '/') == SLASH_COUNT_IN_KEY) { + keySet.emplace_back(keyStr); + } + } + + for (const std::string &key : keySet) { + UnifiedData data; + if (UnMarshalEntries(key, entries, data) != E_OK) { + return E_READ_PARCEL_ERROR; + } + unifiedDataSet.emplace_back(data); + } + return E_OK; +} + +void RuntimeStore::Close() +{ + dataManager_.CloseKvStore(APP_ID, storeId_); +} + +bool RuntimeStore::Init() +{ + Options options; + options.autoSync = false; + options.createIfMissing = true; + options.rebuild = true; + options.backup = false; + options.securityLevel = SecurityLevel::S1; + options.baseDir = BASE_DIR; + options.area = Area::EL1; + options.kvStoreType = KvStoreType::SINGLE_VERSION; + SameProcessIpcGuard ipcGuard; + DistributedKv::Status status = dataManager_.GetSingleKvStore(options, APP_ID, storeId_, kvStore_); + if (status != DistributedKv::Status::SUCCESS) { + ZLOGE("GetKvStore: %{public}s failed, status: %{public}d.", storeId_.storeId.c_str(), status); + return false; + } + return true; +} + +Status RuntimeStore::GetEntries(const std::string &dataPrefix, std::vector &entries) +{ + DataQuery query; + query.KeyPrefix(dataPrefix); + query.OrderByWriteTime(true); + auto status = kvStore_->GetEntries(query, entries); + if (status != DistributedKv::Status::SUCCESS) { + ZLOGE("KvStore getEntries failed, status: %{public}d.", static_cast(status)); + return E_DB_ERROR; + } + return E_OK; +} + +Status RuntimeStore::PutEntries(const std::vector &entries) +{ + size_t size = entries.size(); + DistributedKv::Status status; + for (size_t index = 0; index < size; index += MAX_BATCH_SIZE) { + std::vector batchEntries( + entries.begin() + index, entries.begin() + std::min(index + MAX_BATCH_SIZE, size)); + status = kvStore_->PutBatch(batchEntries); + if (status != DistributedKv::Status::SUCCESS) { + ZLOGE("KvStore putBatch failed, status: %{public}d.", status); + return E_DB_ERROR; + } + } + return E_OK; +} + +Status RuntimeStore::DeleteEntries(const std::vector &keys) +{ + size_t size = keys.size(); + DistributedKv::Status status; + for (size_t index = 0; index < size; index += MAX_BATCH_SIZE) { + std::vector batchKeys(keys.begin() + index, keys.begin() + std::min(index + MAX_BATCH_SIZE, size)); + status = kvStore_->DeleteBatch(batchKeys); + if (status != DistributedKv::Status::SUCCESS) { + ZLOGE("KvStore deleteBatch failed, status: %{public}d.", status); + return E_DB_ERROR; + } + } + return E_OK; +} + +Status RuntimeStore::UnMarshalEntries(const std::string &key, std::vector &entries, UnifiedData &unifiedData) +{ + for (const auto &entry : entries) { + std::string keyStr = entry.key.ToString(); + if (keyStr == key) { + Runtime runtime; + auto runtimeTlv = TLVObject(const_cast &>(entry.value.Data())); + if (!TLVUtil::Reading(runtime, runtimeTlv)) { + ZLOGE("Unmarshall runtime info failed."); + return E_READ_PARCEL_ERROR; + } + unifiedData.SetRuntime(runtime); + break; + } + if (keyStr.find(key) == 0) { + std::shared_ptr record; + auto recordTlv = TLVObject(const_cast &>(entry.value.Data())); + if (!TLVUtil::Reading(record, recordTlv)) { + ZLOGE("Unmarshall unified record failed."); + return E_READ_PARCEL_ERROR; + } + unifiedData.AddRecord(record); + } + } + return E_OK; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.h b/services/distributeddataservice/service/udmf/store/runtime_store.h new file mode 100755 index 00000000..d819e64c --- /dev/null +++ b/services/distributeddataservice/service/udmf/store/runtime_store.h @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#ifndef UDMF_RUNTIMESTORE_H +#define UDMF_RUNTIMESTORE_H + +#include "distributed_kv_data_manager.h" +#include "single_kvstore.h" + +#include "store.h" + +namespace OHOS { +namespace UDMF { +class RuntimeStore final : public Store { +public: + explicit RuntimeStore(const std::string &storeId); + ~RuntimeStore(); + Status Put(const UnifiedData &unifiedData) override; + Status Get(const std::string &key, UnifiedData &unifiedData) override; + Status GetSummary(const std::string &key, Summary &summary) override; + Status Update(const UnifiedData &unifiedData) override; + Status Delete(const std::string &key) override; + Status DeleteBatch(const std::vector &unifiedKeys) override; + Status Sync(const std::vector &devices) override; + Status Clear() override; + Status GetBatchData(const std::string &dataPrefix, std::vector &unifiedDataSet) override; + void Close() override; + bool Init() override; + +private: + static const DistributedKv::AppId APP_ID; + static const std::string DATA_PREFIX; + static const std::string BASE_DIR; + static constexpr std::int32_t SLASH_COUNT_IN_KEY = 4; + static constexpr std::int32_t MAX_BATCH_SIZE = 128; + DistributedKv::DistributedKvDataManager dataManager_; + std::shared_ptr kvStore_; + DistributedKv::StoreId storeId_; + Status GetEntries(const std::string &dataPrefix, std::vector &entries); + Status PutEntries(const std::vector &entries); + Status DeleteEntries(const std::vector &keys); + Status UnMarshalEntries( + const std::string &key, std::vector &entries, UnifiedData &unifiedData); +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_RUNTIMESTORE_H diff --git a/services/distributeddataservice/service/udmf/store/store.h b/services/distributeddataservice/service/udmf/store/store.h new file mode 100755 index 00000000..6996d849 --- /dev/null +++ b/services/distributeddataservice/service/udmf/store/store.h @@ -0,0 +1,62 @@ +/* + * 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. + */ + +#ifndef UDMF_STORE_H +#define UDMF_STORE_H + +#include +#include + +#include "error_code.h" +#include "unified_data.h" +#include "unified_key.h" +#include "unified_types.h" + +namespace OHOS { +namespace UDMF { +class Store { +public: + using Time = std::chrono::steady_clock::time_point; + virtual Status Put(const UnifiedData &unifiedData) = 0; + virtual Status Get(const std::string &key, UnifiedData &unifiedData) = 0; + virtual Status GetSummary(const std::string &key, Summary &summary) = 0; + virtual Status Update(const UnifiedData &unifiedData) = 0; + virtual Status Delete(const std::string &key) = 0; + virtual Status DeleteBatch(const std::vector &unifiedKeys) = 0; + virtual Status Sync(const std::vector &devices) = 0; + virtual Status Clear() = 0; + virtual bool Init() = 0; + virtual void Close() = 0; + virtual Status GetBatchData(const std::string &dataPrefix, std::vector &unifiedDataSet) = 0; + + bool operator<(const Time &time) const + { + std::shared_lock lock(timeMutex_); + return time_ < time; + } + + void updateTime() + { + std::unique_lock lock(timeMutex_); + time_ = std::chrono::steady_clock::now() + std::chrono::minutes(INTERVAL); + } +private: + static constexpr int64_t INTERVAL = 1; // 1 min + mutable Time time_; + mutable std::shared_mutex timeMutex_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_STORE_H diff --git a/services/distributeddataservice/service/udmf/store/store_cache.cpp b/services/distributeddataservice/service/udmf/store/store_cache.cpp new file mode 100755 index 00000000..7f53f27c --- /dev/null +++ b/services/distributeddataservice/service/udmf/store/store_cache.cpp @@ -0,0 +1,76 @@ +/* + * 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. + */ +#define LOG_TAG "StoreCache" + +#include "store_cache.h" +#include + +#include "log_print.h" +#include "runtime_store.h" +#include "unified_meta.h" + +namespace OHOS { +namespace UDMF { +std::shared_ptr StoreCache::executorPool_ = std::make_shared(2, 1); + +std::shared_ptr StoreCache::GetStore(std::string intention) +{ + std::shared_ptr store; + stores_.Compute(intention, [&store](const auto &intention, std::shared_ptr &storePtr) -> bool { + if (storePtr != nullptr) { + store = storePtr; + return true; + } + + if (intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG) + || intention == UD_INTENTION_MAP.at(UD_INTENTION_DATA_HUB)) { + storePtr = std::make_shared(intention); + if (!storePtr->Init()) { + ZLOGE("Init runtime store failed."); + return false; + } + store = storePtr; + return true; + } + return false; + }); + + std::unique_lock lock(taskMutex_); + if (taskId_ == ExecutorPool::INVALID_TASK_ID) { + taskId_ = executorPool_->Schedule(std::chrono::minutes(INTERVAL), std::bind(&StoreCache::GarbageCollect, this)); + } + return store; +} + +void StoreCache::GarbageCollect() +{ + auto current = std::chrono::steady_clock::now(); + stores_.EraseIf([¤t](auto &key, std::shared_ptr &storePtr) { + if (*storePtr < current) { + ZLOGD("GarbageCollect, stores:%{public}s time limit, will be close.", key.c_str()); + return true; + } + return false; + }); + std::unique_lock lock(taskMutex_); + if (!stores_.Empty()) { + ZLOGE("GarbageCollect, stores size:%{public}zu", stores_.Size()); + taskId_ = executorPool_->Schedule(std::chrono::minutes(INTERVAL), std::bind(&StoreCache::GarbageCollect, this)); + } else { + taskId_ = ExecutorPool::INVALID_TASK_ID; + } +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/store/store_cache.h b/services/distributeddataservice/service/udmf/store/store_cache.h new file mode 100755 index 00000000..59807f74 --- /dev/null +++ b/services/distributeddataservice/service/udmf/store/store_cache.h @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#ifndef UDMF_STORE_CACHE_H +#define UDMF_STORE_CACHE_H + +#include +#include + +#include "concurrent_map.h" +#include "executor_pool.h" +#include "store.h" +#include "unified_meta.h" + +namespace OHOS { +namespace UDMF { +class StoreCache { +public: + std::shared_ptr GetStore(std::string intention); + +private: + void GarbageCollect(); + + ConcurrentMap> stores_; + std::mutex taskMutex_; + ExecutorPool::TaskId taskId_ = ExecutorPool::INVALID_TASK_ID; + + static constexpr int64_t INTERVAL = 1; // 1 min + static std::shared_ptr executorPool_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_STORE_CACHE_H diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp new file mode 100755 index 00000000..dcbf8b47 --- /dev/null +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 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. + */ +#define LOG_TAG "UdmfServiceImpl" + +#include "udmf_service_impl.h" + +#include "iservice_registry.h" + +#include "data_manager.h" +#include "lifecycle/lifecycle_manager.h" +#include "log_print.h" +#include "preprocess_utils.h" + +namespace OHOS { +namespace UDMF { +using FeatureSystem = DistributedData::FeatureSystem; +__attribute__((used)) UdmfServiceImpl::Factory UdmfServiceImpl::factory_; +UdmfServiceImpl::Factory::Factory() +{ + ZLOGI("Register udmf creator!"); + FeatureSystem::GetInstance().RegisterCreator("udmf", [this]() { + if (product_ == nullptr) { + product_ = std::make_shared(); + } + return product_; + }); +} + +UdmfServiceImpl::Factory::~Factory() +{ + product_ = nullptr; +} + +int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) +{ + ZLOGD("start"); + return DataManager::GetInstance().SaveData(option, unifiedData, key); +} + +int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedData) +{ + ZLOGD("start"); + return DataManager::GetInstance().RetrieveData(query, unifiedData); +} + +int32_t UdmfServiceImpl::GetBatchData(const QueryOption &query, std::vector &unifiedDataSet) +{ + ZLOGD("start"); + return DataManager::GetInstance().RetrieveBatchData(query, unifiedDataSet); +} + +int32_t UdmfServiceImpl::UpdateData(const QueryOption &query, UnifiedData &unifiedData) +{ + ZLOGD("start"); + return DataManager::GetInstance().UpdateData(query, unifiedData); +} + +int32_t UdmfServiceImpl::DeleteData(const QueryOption &query, std::vector &unifiedDataSet) +{ + ZLOGD("start"); + return DataManager::GetInstance().DeleteData(query, unifiedDataSet); +} + +int32_t UdmfServiceImpl::GetSummary(const QueryOption &query, Summary &summary) +{ + ZLOGD("start"); + return DataManager::GetInstance().GetSummary(query, summary); +} + +int32_t UdmfServiceImpl::AddPrivilege(const QueryOption &query, Privilege &privilege) +{ + ZLOGD("start"); + return DataManager::GetInstance().AddPrivilege(query, privilege); +} + +int32_t UdmfServiceImpl::Sync(const QueryOption &query, const std::vector &devices) +{ + ZLOGD("start"); + return DataManager::GetInstance().Sync(query, devices); +} + +int32_t UdmfServiceImpl::OnInitialize() +{ + ZLOGD("start"); + Status status = LifeCycleManager::GetInstance().DeleteOnStart(); + if (status != E_OK) { + ZLOGE("DeleteOnStart execute failed, status: %{public}d", status); + } + status = LifeCycleManager::GetInstance().DeleteOnSchedule(); + if (status != E_OK) { + ZLOGE("ScheduleTask start failed, status: %{public}d", status); + } + return DistributedData::FeatureSystem::STUB_SUCCESS; +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.h b/services/distributeddataservice/service/udmf/udmf_service_impl.h new file mode 100755 index 00000000..30b9dafd --- /dev/null +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 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 UDMF_SERVICE_IMPL_H +#define UDMF_SERVICE_IMPL_H + +#include + +#include "udmf_service_stub.h" + +namespace OHOS { +namespace UDMF { +/* + * UDMF server implementation + */ +class UdmfServiceImpl final : public UdmfServiceStub { +public: + UdmfServiceImpl() = default; + ~UdmfServiceImpl() = default; + + int32_t SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) override; + int32_t GetData(const QueryOption &query, UnifiedData &unifiedData) override; + int32_t GetBatchData(const QueryOption &query, std::vector &unifiedDataSet) override; + int32_t UpdateData(const QueryOption &query, UnifiedData &unifiedData) override; + int32_t DeleteData(const QueryOption &query, std::vector &unifiedDataSet) override; + int32_t GetSummary(const QueryOption &query, Summary &summary) override; + int32_t AddPrivilege(const QueryOption &query, Privilege &privilege) override; + int32_t Sync(const QueryOption &query, const std::vector &devices) override; + int32_t OnInitialize() override; + +private: + class Factory { + public: + Factory(); + ~Factory(); + + private: + std::shared_ptr product_; + }; + static Factory factory_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_SERVICE_IMPL_H diff --git a/services/distributeddataservice/service/udmf/udmf_service_stub.cpp b/services/distributeddataservice/service/udmf/udmf_service_stub.cpp new file mode 100755 index 00000000..febb3a3d --- /dev/null +++ b/services/distributeddataservice/service/udmf/udmf_service_stub.cpp @@ -0,0 +1,269 @@ +/* + * 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. + */ +#define LOG_TAG "UdmfServiceStub" + +#include "udmf_service_stub.h" + +#include + +#include "accesstoken_kit.h" +#include "ipc_skeleton.h" +#include "log_print.h" +#include "udmf_types_util.h" +#include "unified_data.h" +#include "unified_meta.h" + +namespace OHOS { +namespace UDMF { +UdmfServiceStub::UdmfServiceStub() +{ + memberFuncMap_[static_cast(SET_DATA)] = &UdmfServiceStub::OnSetData; + memberFuncMap_[static_cast(GET_DATA)] = &UdmfServiceStub::OnGetData; + memberFuncMap_[static_cast(GET_BATCH_DATA)] = &UdmfServiceStub::OnGetBatchData; + memberFuncMap_[static_cast(UPDATE_DATA)] = &UdmfServiceStub::OnUpdateData; + memberFuncMap_[static_cast(DELETE_DATA)] = &UdmfServiceStub::OnDeleteData; + memberFuncMap_[static_cast(GET_SUMMARY)] = &UdmfServiceStub::OnGetSummary; + memberFuncMap_[static_cast(ADD_PRIVILEGE)] = &UdmfServiceStub::OnAddPrivilege; + memberFuncMap_[static_cast(SYNC)] = &UdmfServiceStub::OnSync; +} + +UdmfServiceStub::~UdmfServiceStub() +{ + memberFuncMap_.clear(); +} + +int UdmfServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start##code = %{public}u", code); + std::u16string myDescripter = UdmfServiceStub::GetDescriptor(); + std::u16string remoteDescripter = data.ReadInterfaceToken(); + if (myDescripter != remoteDescripter) { + ZLOGE("end##descriptor checked fail"); + return -1; + } + if (CODE_HEAD > code || code >= CODE_BUTT) { + return -1; + } + auto itFunc = memberFuncMap_.find(code); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data, reply); + } + } + ZLOGI("end##ret = -1"); + return -1; +} + +int32_t UdmfServiceStub::OnSetData(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + CustomOption customOption; + UnifiedData unifiedData; + if (!ITypesUtil::Unmarshal(data, customOption, unifiedData)) { + ZLOGE("Unmarshal customOption or unifiedData failed!"); + return E_READ_PARCEL_ERROR; + } + if (unifiedData.IsEmpty()) { + ZLOGE("Empty data without any record!"); + return E_INVALID_PARAMETERS; + } + if (unifiedData.GetSize() > UdmfService::MAX_DATA_SIZE) { + ZLOGE("Exceeded data limit!"); + return E_INVALID_PARAMETERS; + } + for (const auto &record : unifiedData.GetRecords()) { + if (record == nullptr) { + ZLOGE("record is nullptr!"); + return E_INVALID_PARAMETERS; + } + if (record->GetSize() > UdmfService::MAX_RECORD_SIZE) { + ZLOGE("Exceeded record limit!"); + return E_INVALID_PARAMETERS; + } + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + customOption.tokenId = token; + std::string key; + int32_t status = SetData(customOption, unifiedData, key); + if (!ITypesUtil::Marshal(reply, status, key)) { + ZLOGE("Marshal status or key failed, status: %{public}d, key: %{public}s", status, key.c_str()); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +int32_t UdmfServiceStub::OnGetData(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + QueryOption query; + if (!ITypesUtil::Unmarshal(data, query)) { + ZLOGE("Unmarshal queryOption failed!"); + return E_READ_PARCEL_ERROR; + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + query.tokenId = token; + UnifiedData unifiedData; + int32_t status = GetData(query, unifiedData); + if (!ITypesUtil::Marshal(reply, status, unifiedData)) { + ZLOGE("Marshal status or unifiedData failed, status: %{public}d", status); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +int32_t UdmfServiceStub::OnGetBatchData(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + QueryOption query; + if (!ITypesUtil::Unmarshal(data, query)) { + ZLOGE("Unmarshal queryOption failed!"); + return E_READ_PARCEL_ERROR; + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + query.tokenId = token; + std::vector unifiedDataSet; + int32_t status = GetBatchData(query, unifiedDataSet); + if (!ITypesUtil::Marshal(reply, status, unifiedDataSet)) { + ZLOGE("Marshal status or unifiedDataSet failed, status: %{public}d", status); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +int32_t UdmfServiceStub::OnUpdateData(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + QueryOption query; + UnifiedData unifiedData; + if (!ITypesUtil::Unmarshal(data, query, unifiedData)) { + ZLOGE("Unmarshal queryOption or unifiedData failed!"); + return E_READ_PARCEL_ERROR; + } + if (unifiedData.IsEmpty()) { + ZLOGE("Empty data without any record!"); + return E_INVALID_PARAMETERS; + } + if (unifiedData.GetSize() > UdmfService::MAX_DATA_SIZE) { + ZLOGE("Exceeded data limit!"); + return E_INVALID_PARAMETERS; + } + for (const auto &record : unifiedData.GetRecords()) { + if (record->GetSize() > UdmfService::MAX_RECORD_SIZE) { + ZLOGE("Exceeded record limit!"); + return E_INVALID_PARAMETERS; + } + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + query.tokenId = token; + int32_t status = UpdateData(query, unifiedData); + if (!ITypesUtil::Marshal(reply, status)) { + ZLOGE("Marshal status failed, status: %{public}d", status); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +int32_t UdmfServiceStub::OnDeleteData(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + QueryOption query; + if (!ITypesUtil::Unmarshal(data, query)) { + ZLOGE("Unmarshal queryOption failed!"); + return E_READ_PARCEL_ERROR; + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + query.tokenId = token; + std::vector unifiedDataSet; + int32_t status = DeleteData(query, unifiedDataSet); + if (!ITypesUtil::Marshal(reply, status, unifiedDataSet)) { + ZLOGE("Marshal status or unifiedDataSet failed, status: %{public}d", status); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +int32_t UdmfServiceStub::OnGetSummary(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + QueryOption query; + if (!ITypesUtil::Unmarshal(data, query)) { + ZLOGE("Unmarshal query failed"); + return E_READ_PARCEL_ERROR; + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + query.tokenId = token; + Summary summary; + int32_t status = GetSummary(query, summary); + if (!ITypesUtil::Marshal(reply, status, summary)) { + ZLOGE("Marshal summary failed, key: %{public}s", query.key.c_str()); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +int32_t UdmfServiceStub::OnAddPrivilege(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + QueryOption query; + Privilege privilege; + if (!ITypesUtil::Unmarshal(data, query, privilege)) { + ZLOGE("Unmarshal query and privilege failed"); + return E_READ_PARCEL_ERROR; + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + query.tokenId = token; + int32_t status = AddPrivilege(query, privilege); + if (!ITypesUtil::Marshal(reply, status)) { + ZLOGE("Marshal status failed, key: %{public}s", query.key.c_str()); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +int32_t UdmfServiceStub::OnSync(MessageParcel &data, MessageParcel &reply) +{ + ZLOGI("start"); + QueryOption query; + std::vector devices; + if (!ITypesUtil::Unmarshal(data, query, devices)) { + ZLOGE("Unmarshal query and devices failed"); + return E_READ_PARCEL_ERROR; + } + uint32_t token = static_cast(IPCSkeleton::GetCallingTokenID()); + query.tokenId = token; + int32_t status = Sync(query, devices); + if (!ITypesUtil::Marshal(reply, status)) { + ZLOGE("Marshal status failed, key: %{public}s", query.key.c_str()); + return E_WRITE_PARCEL_ERROR; + } + return E_OK; +} + +/* + * Check whether the caller has the permission to access data. + */ +bool UdmfServiceStub::VerifyPermission(const std::string &permission) +{ +#ifdef UDMF_PERMISSION_ENABLED + uint32_t tokenId = IPCSkeleton::GetCallingTokenID(); + int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, permission); + return result == Security::AccessToken::TypePermissionState::PERMISSION_GRANTED; +#else + return true; +#endif // UDMF_PERMISSION_ENABLED +} +} // namespace UDMF +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_stub.h b/services/distributeddataservice/service/udmf/udmf_service_stub.h new file mode 100755 index 00000000..9684d2ec --- /dev/null +++ b/services/distributeddataservice/service/udmf/udmf_service_stub.h @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#ifndef UDMF_SERVICE_STUB_H +#define UDMF_SERVICE_STUB_H + +#include +#include + +#include "feature/feature_system.h" +#include "message_parcel.h" + +#include "error_code.h" +#include "udmf_service.h" + +namespace OHOS { +namespace UDMF { +/* + * UDMF server stub + */ +class UdmfServiceStub : public UdmfService, public DistributedData::FeatureSystem::Feature { +public: + UdmfServiceStub(); + virtual ~UdmfServiceStub() override; + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override; + +private: + int32_t OnSetData(MessageParcel &data, MessageParcel &reply); + int32_t OnGetData(MessageParcel &data, MessageParcel &reply); + int32_t OnGetBatchData(MessageParcel &data, MessageParcel &reply); + int32_t OnUpdateData(MessageParcel &data, MessageParcel &reply); + int32_t OnDeleteData(MessageParcel &data, MessageParcel &reply); + int32_t OnGetSummary(MessageParcel &data, MessageParcel &reply); + int32_t OnAddPrivilege(MessageParcel &data, MessageParcel &reply); + int32_t OnSync(MessageParcel &data, MessageParcel &reply); + + bool VerifyPermission(const std::string &permission); + + const std::string READ_PERMISSION = "ohos.permission.READ_UDMF_DATA"; + const std::string WRITE_PERMISSION = "ohos.permission.WRITE_UDMF_DATA"; + const std::string SYNC_PERMISSION = "ohos.permission.SYNC_UDMF_DATA"; + + using UdmfServiceFunc = int32_t (UdmfServiceStub::*)(MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_; +}; +} // namespace UDMF +} // namespace OHOS +#endif // UDMF_SERVICE_STUB_H -- Gitee From 2d1b1c79734e03651d973213a9c6c15e859e3b18 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 28 Jun 2023 10:17:22 +0800 Subject: [PATCH 277/437] f Signed-off-by: hanlu --- .../service/data_share/data_share_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 9896dafa..05db01a0 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -314,7 +314,7 @@ std::vector DataShareServiceImpl::UnsubscribePublishedData(cons if (binderInfo_.executors != nullptr) { binderInfo_.executors->Execute([context, subscriberId]() { PublishedData::UpdateTimestamp( - context->uri, context->callerBundleName, subscriberId, context->currentUserId); + context->uri, context->calledBundleName, subscriberId, context->currentUserId); }); } return result; -- Gitee From a3f43d4aa57bf6a548698f443a614621e778c710 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 28 Jun 2023 10:26:19 +0800 Subject: [PATCH 278/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/sync_manager.cpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 0850fec5..8580741d 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -237,16 +237,24 @@ std::function SyncManager::GetSyncHandler(Retryer retryer) ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), meta.GetStoreAlias().c_str()); - store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.AutoRetry() - ? [retryer](const GenDetails &details) { - if (details.empty()) { - ZLOGE("retry, details empty"); - return; - } - int32_t code = details.begin()->second.code; - retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); - } - : evt.GetAsyncDetail(), evt.GetWait()); + auto status = store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.AutoRetry() + ? [retryer](const GenDetails &details) { + if (details.empty()) { + ZLOGE("retry, details empty"); + return; + } + int32_t code = details.begin()->second.code; + retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); + } + : evt.GetAsyncDetail(), evt.GetWait()); + GenAsync async = evt.GetAsyncDetail(); + if (status != E_OK && async) { + GenDetails details; + auto &detail = details[SyncInfo::DEFAULT_ID]; + detail.progress = SYNC_FINISH; + detail.code = status; + async(std::move(details)); + } }; } -- Gitee From 809366a1d1a36ac1e68b2df13f539afb10b4b98d Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 28 Jun 2023 10:30:20 +0800 Subject: [PATCH 279/437] f Signed-off-by: hanlu --- .../service/data_share/data/published_data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 471225c8..416b27c9 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -221,7 +221,7 @@ void PublishedData::UpdateTimestamp( data.timestamp = now; status = delegate->Upsert(KvDBDelegate::DATA_TABLE, PublishedData(data)); if (status == E_OK) { - ZLOGI("update timestamp %{private}s to %{public}lld", data.key.c_str(), now); + ZLOGI("update timestamp %{private}s", data.key.c_str()); } } } // namespace OHOS::DataShare \ No newline at end of file -- Gitee From 2e6cf3ef087846852f2cb5140a2b573c2936a2f9 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 28 Jun 2023 10:54:48 +0800 Subject: [PATCH 280/437] upadte Signed-off-by: zuojiangjiang --- .../service/cloud/sync_manager.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 8580741d..0ca92183 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -238,15 +238,15 @@ std::function SyncManager::GetSyncHandler(Retryer retryer) ZLOGD("database:<%{public}d:%{public}s:%{public}s> sync start", storeInfo.user, storeInfo.bundleName.c_str(), meta.GetStoreAlias().c_str()); auto status = store->Sync({ SyncInfo::DEFAULT_ID }, evt.GetMode(), *(evt.GetQuery()), evt.AutoRetry() - ? [retryer](const GenDetails &details) { - if (details.empty()) { - ZLOGE("retry, details empty"); - return; - } - int32_t code = details.begin()->second.code; - retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); - } - : evt.GetAsyncDetail(), evt.GetWait()); + ? [retryer](const GenDetails &details) { + if (details.empty()) { + ZLOGE("retry, details empty"); + return; + } + int32_t code = details.begin()->second.code; + retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); + } + : evt.GetAsyncDetail(), evt.GetWait()); GenAsync async = evt.GetAsyncDetail(); if (status != E_OK && async) { GenDetails details; -- Gitee From aac1ef5579e08639882dd18ad52a6ba5d4f0661d Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 28 Jun 2023 11:21:35 +0800 Subject: [PATCH 281/437] f Signed-off-by: hanlu --- .../service/data_share/common/kv_delegate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp index d0736685..9e36164a 100644 --- a/services/distributeddataservice/service/data_share/common/kv_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/kv_delegate.cpp @@ -138,9 +138,9 @@ int32_t KvDelegate::Get(const std::string &collectionName, const Id &id, std::st std::string filter = DistributedData::Serializable::Marshall(id); if (Get(collectionName, filter, "{}", value) != E_OK) { ZLOGE("Get failed, %{public}s %{public}s", collectionName.c_str(), filter.c_str()); - return false; + return E_ERROR; } - return true; + return E_OK; } bool KvDelegate::GetVersion(const std::string &collectionName, const std::string &filter, int &version) -- Gitee From 521278c84754d6aef3a1491154d6e8e539b16204 Mon Sep 17 00:00:00 2001 From: mazhao Date: Wed, 28 Jun 2023 11:37:23 +0800 Subject: [PATCH 282/437] delete empty assertions Signed-off-by: mazhao --- .../test/unittest/api/documentdb_data_test.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index 7fdb5a56..b1364de3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -244,24 +244,6 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest003, TestSize.Level0) } } -/** - * @tc.name: UpdateDataTest004 - * @tc.desc: Test update data with invalid filter - * @tc.type: FUNC - * @tc.require: - * @tc.author: lianhuix - */ -HWTEST_F(DocumentDBDataTest, UpdateDataTest004, TestSize.Level0) {} - -/** - * @tc.name: UpdateDataTest005 - * @tc.desc: Test update data with invalid doc - * @tc.type: FUNC - * @tc.require: - * @tc.author: lianhuix - */ -HWTEST_F(DocumentDBDataTest, UpdateDataTest005, TestSize.Level0) {} - /** * @tc.name: UpdateDataTest006 * @tc.desc: Test update data with invalid flag -- Gitee From 325b2b164b3375a8d64c98ee281262eb44c00567 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 28 Jun 2023 14:53:42 +0800 Subject: [PATCH 283/437] f Signed-off-by: hanlu --- .../data_share/data_share_service_impl.cpp | 39 ++++++++++++++----- .../strategies/subscribe_strategy.cpp | 2 +- .../strategies/subscribe_strategy.h | 2 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 05db01a0..01492376 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -210,7 +210,7 @@ std::vector DataShareServiceImpl::SubscribeRdbData( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &observer, &context, this]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &observer, &context, this]() { return RdbSubscriberManager::GetInstance().Add( Key(context->uri, id.subscriberId_, id.bundleName_), observer, context, binderInfo_.executors); })); @@ -224,7 +224,7 @@ std::vector DataShareServiceImpl::UnsubscribeRdbData( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() { return RdbSubscriberManager::GetInstance().Delete( Key(context->uri, id.subscriberId_, id.bundleName_), context->callerTokenId); })); @@ -238,7 +238,7 @@ std::vector DataShareServiceImpl::EnableRdbSubs( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() { return RdbSubscriberManager::GetInstance().Enable( Key(context->uri, id.subscriberId_, id.bundleName_), context); })); @@ -252,7 +252,7 @@ std::vector DataShareServiceImpl::DisableRdbSubs( std::vector results; for (const auto &uri : uris) { auto context = std::make_shared(uri); - results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&id, &context]() { return RdbSubscriberManager::GetInstance().Disable( Key(context->uri, id.subscriberId_, id.bundleName_), context->callerTokenId); })); @@ -277,7 +277,7 @@ std::vector DataShareServiceImpl::SubscribePublishedData(const PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - result = subscribeStrategy_.Execute(context, [&subscriberId, &observer, &context]() -> bool { + result = subscribeStrategy_.Execute(context, [&subscriberId, &observer, &context]() { return PublishedDataSubscriberManager::GetInstance().Add( PublishedDataKey(context->uri, context->callerBundleName, subscriberId), observer, context->callerTokenId); @@ -285,6 +285,12 @@ std::vector DataShareServiceImpl::SubscribePublishedData(const results.emplace_back(uri, result); if (result == E_OK) { publishedKeys.emplace_back(context->uri, context->callerBundleName, subscriberId); + if (binderInfo_.executors != nullptr) { + binderInfo_.executors->Execute([context, subscriberId]() { + PublishedData::UpdateTimestamp( + context->uri, context->calledBundleName, subscriberId, context->currentUserId); + }); + } userId = context->currentUserId; } } @@ -308,10 +314,10 @@ std::vector DataShareServiceImpl::UnsubscribePublishedData(cons PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context, this]() -> bool { + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context, this]() { auto result = PublishedDataSubscriberManager::GetInstance().Delete( PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); - if (binderInfo_.executors != nullptr) { + if (result == E_OK && binderInfo_.executors != nullptr) { binderInfo_.executors->Execute([context, subscriberId]() { PublishedData::UpdateTimestamp( context->uri, context->calledBundleName, subscriberId, context->currentUserId); @@ -340,10 +346,16 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - result = subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { + result = subscribeStrategy_.Execute(context, [&subscriberId, &context]() { return PublishedDataSubscriberManager::GetInstance().Enable( PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); }); + if (result == E_OK && binderInfo_.executors != nullptr) { + binderInfo_.executors->Execute([context, subscriberId]() { + PublishedData::UpdateTimestamp( + context->uri, context->calledBundleName, subscriberId, context->currentUserId); + }); + } results.emplace_back(uri, result); if (result == E_OK) { publishedKeys.emplace_back(context->uri, context->callerBundleName, subscriberId); @@ -370,9 +382,16 @@ std::vector DataShareServiceImpl::DisablePubSubs(const std::vec PublishedDataKey key(uri, callerBundleName, subscriberId); context->callerBundleName = callerBundleName; context->calledBundleName = key.bundleName; - results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context]() -> bool { - return PublishedDataSubscriberManager::GetInstance().Disable( + results.emplace_back(uri, subscribeStrategy_.Execute(context, [&subscriberId, &context, this]() { + auto result = PublishedDataSubscriberManager::GetInstance().Disable( PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); + if (result == E_OK && binderInfo_.executors != nullptr) { + binderInfo_.executors->Execute([context, subscriberId]() { + PublishedData::UpdateTimestamp( + context->uri, context->calledBundleName, subscriberId, context->currentUserId); + }); + } + return result; })); } return results; diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp index 067c8cda..4b7314c8 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp @@ -24,7 +24,7 @@ #include "utils/anonymous.h" namespace OHOS::DataShare { -int32_t SubscribeStrategy::Execute(std::shared_ptr context, std::function process) +int32_t SubscribeStrategy::Execute(std::shared_ptr context, std::function process) { auto &preProcess = GetStrategy(); if (preProcess.IsEmpty()) { diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h index 7395b90f..3456b66c 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.h @@ -23,7 +23,7 @@ namespace OHOS::DataShare { class SubscribeStrategy final { public: - int32_t Execute(std::shared_ptr context, std::function process); + int32_t Execute(std::shared_ptr context, std::function process); private: SeqStrategy &GetStrategy(); -- Gitee From 02aff37f149bda3749ea9091e832a2954d726a06 Mon Sep 17 00:00:00 2001 From: mazhao Date: Wed, 28 Jun 2023 15:36:57 +0800 Subject: [PATCH 284/437] Remediate parts Signed-off-by: mazhao --- .../service/data_share/gaussdb_rd/BUILD.gn | 6 +++--- .../data_share/gaussdb_rd/test/unittest/BUILD.gn | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn index 47128f8c..a66602e0 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn @@ -82,9 +82,9 @@ ohos_shared_library("gaussdb_rd") { external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn index b4cc59a3..75835174 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn @@ -81,9 +81,9 @@ ohos_source_set("src_file") { deps += [ "//third_party/cJSON:cjson" ] external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" @@ -115,9 +115,9 @@ template("gaussdb_rd_unittest") { ] external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] } } -- Gitee From 7d8b673b2499edf0d95ad75752e20af4afa4cc8a Mon Sep 17 00:00:00 2001 From: wellinleo Date: Wed, 28 Jun 2023 17:18:16 +0800 Subject: [PATCH 285/437] dxf modifty Signed-off-by: wellinleo --- bundle.json | 6 +++--- services/distributeddataservice/adapter/BUILD.gn | 8 ++++---- .../distributeddataservice/adapter/account/BUILD.gn | 2 +- .../adapter/account/test/BUILD.gn | 2 +- .../adapter/broadcaster/BUILD.gn | 2 +- .../adapter/communicator/BUILD.gn | 2 +- .../adapter/communicator/test/BUILD.gn | 4 ++-- services/distributeddataservice/adapter/dfx/BUILD.gn | 8 ++++---- .../distributeddataservice/adapter/dfx/test/BUILD.gn | 12 ++++++------ .../adapter/permission/BUILD.gn | 2 +- .../adapter/permission/test/BUILD.gn | 2 +- .../distributeddataservice/adapter/utils/BUILD.gn | 2 +- services/distributeddataservice/app/BUILD.gn | 8 ++++---- .../distributeddataservice/app/src/checker/BUILD.gn | 2 +- .../app/src/uninstaller/BUILD.gn | 2 +- services/distributeddataservice/app/test/BUILD.gn | 12 ++++++------ services/distributeddataservice/framework/BUILD.gn | 2 +- .../distributeddataservice/framework/test/BUILD.gn | 6 +++--- services/distributeddataservice/service/BUILD.gn | 2 +- .../service/data_share/BUILD.gn | 2 +- .../service/data_share/gaussdb_rd/BUILD.gn | 6 +++--- .../data_share/gaussdb_rd/test/unittest/BUILD.gn | 12 ++++++------ .../distributeddataservice/service/test/BUILD.gn | 12 ++++++------ .../test/fuzztest/schemaquery_fuzzer/BUILD.gn | 2 +- test/fuzztest/autolaunch_fuzzer/BUILD.gn | 2 +- test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn | 2 +- 26 files changed, 62 insertions(+), 62 deletions(-) diff --git a/bundle.json b/bundle.json index 683a81f1..4a4a1270 100644 --- a/bundle.json +++ b/bundle.json @@ -63,9 +63,9 @@ "device_auth", "device_manager", "dsoftbus", - "hisysevent_native", - "hitrace_native", - "hiviewdfx_hilog_native", + "hisysevent", + "hitrace", + "hilog", "huks", "init", "kv_store", diff --git a/services/distributeddataservice/adapter/BUILD.gn b/services/distributeddataservice/adapter/BUILD.gn index 515866a6..998c7164 100644 --- a/services/distributeddataservice/adapter/BUILD.gn +++ b/services/distributeddataservice/adapter/BUILD.gn @@ -52,10 +52,10 @@ ohos_shared_library("distributeddata_adapter") { external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hitrace_native:libhitracechain", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "hilog:libhilog", ] public_configs = [ ":distributeddata_adapter_public_config" ] diff --git a/services/distributeddataservice/adapter/account/BUILD.gn b/services/distributeddataservice/adapter/account/BUILD.gn index d2a449b8..e9428651 100755 --- a/services/distributeddataservice/adapter/account/BUILD.gn +++ b/services/distributeddataservice/adapter/account/BUILD.gn @@ -42,7 +42,7 @@ ohos_static_library("distributeddata_account_static") { "ability_base:want", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", ] if (os_account_part_is_enabled) { diff --git a/services/distributeddataservice/adapter/account/test/BUILD.gn b/services/distributeddataservice/adapter/account/test/BUILD.gn index fa8c3d6e..34a2846e 100755 --- a/services/distributeddataservice/adapter/account/test/BUILD.gn +++ b/services/distributeddataservice/adapter/account/test/BUILD.gn @@ -38,7 +38,7 @@ ohos_unittest("AccountDelegateTest") { "ability_base:want", "bundle_framework:appexecfwk_base", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] diff --git a/services/distributeddataservice/adapter/broadcaster/BUILD.gn b/services/distributeddataservice/adapter/broadcaster/BUILD.gn index fe0fc348..550fb44e 100755 --- a/services/distributeddataservice/adapter/broadcaster/BUILD.gn +++ b/services/distributeddataservice/adapter/broadcaster/BUILD.gn @@ -36,7 +36,7 @@ ohos_static_library("distributeddata_broadcaster_static") { "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/adapter/communicator/BUILD.gn b/services/distributeddataservice/adapter/communicator/BUILD.gn index be70a5dd..451b8de6 100755 --- a/services/distributeddataservice/adapter/communicator/BUILD.gn +++ b/services/distributeddataservice/adapter/communicator/BUILD.gn @@ -58,7 +58,7 @@ ohos_static_library("distributeddata_communicator_static") { "c_utils:utils", "device_manager:devicemanagersdk", "dsoftbus:softbus_client", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/adapter/communicator/test/BUILD.gn b/services/distributeddataservice/adapter/communicator/test/BUILD.gn index a3fa43ac..b3dbad12 100755 --- a/services/distributeddataservice/adapter/communicator/test/BUILD.gn +++ b/services/distributeddataservice/adapter/communicator/test/BUILD.gn @@ -30,7 +30,7 @@ ohos_unittest("CommunicationProviderTest") { ] external_deps = [ "dsoftbus:softbus_client", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] deps = [ @@ -55,7 +55,7 @@ ohos_unittest("DeviceManagerAdapterTest") { ] external_deps = [ "dsoftbus:softbus_client", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] deps = [ diff --git a/services/distributeddataservice/adapter/dfx/BUILD.gn b/services/distributeddataservice/adapter/dfx/BUILD.gn index 2818cae4..f64e5809 100644 --- a/services/distributeddataservice/adapter/dfx/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/BUILD.gn @@ -44,10 +44,10 @@ ohos_static_library("distributeddata_dfx_static") { deps = [ "//third_party/openssl:libcrypto_shared" ] external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hitrace_native:libhitracechain", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" part_name = "datamgr_service" diff --git a/services/distributeddataservice/adapter/dfx/test/BUILD.gn b/services/distributeddataservice/adapter/dfx/test/BUILD.gn index 4b4df71f..1189d178 100755 --- a/services/distributeddataservice/adapter/dfx/test/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/test/BUILD.gn @@ -41,9 +41,9 @@ ohos_unittest("DistributeddataDfxMSTTest") { external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ @@ -99,9 +99,9 @@ ohos_unittest("DistributeddataDfxUTTest") { external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ diff --git a/services/distributeddataservice/adapter/permission/BUILD.gn b/services/distributeddataservice/adapter/permission/BUILD.gn index 48e77927..2c478746 100644 --- a/services/distributeddataservice/adapter/permission/BUILD.gn +++ b/services/distributeddataservice/adapter/permission/BUILD.gn @@ -35,7 +35,7 @@ ohos_static_library("distributeddata_permission_static") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" part_name = "datamgr_service" diff --git a/services/distributeddataservice/adapter/permission/test/BUILD.gn b/services/distributeddataservice/adapter/permission/test/BUILD.gn index a19f4c30..509f49b3 100644 --- a/services/distributeddataservice/adapter/permission/test/BUILD.gn +++ b/services/distributeddataservice/adapter/permission/test/BUILD.gn @@ -42,7 +42,7 @@ ohos_unittest("PermissionValidatorTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ "hilog:libhilog" ] defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] } diff --git a/services/distributeddataservice/adapter/utils/BUILD.gn b/services/distributeddataservice/adapter/utils/BUILD.gn index b57d430b..e3f085cf 100755 --- a/services/distributeddataservice/adapter/utils/BUILD.gn +++ b/services/distributeddataservice/adapter/utils/BUILD.gn @@ -35,7 +35,7 @@ ohos_static_library("distributeddata_utils_static") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", ] subsystem_name = "distributeddatamgr" part_name = "datamgr_service" diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 5df04bdd..14cda7f3 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -118,10 +118,10 @@ ohos_shared_library("distributeddataservice") { "bundle_framework:appexecfwk_core", "c_utils:utils", "dataclassification:data_transit_mgr", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hitrace_native:libhitracechain", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", "safwk:system_ability_fwk", diff --git a/services/distributeddataservice/app/src/checker/BUILD.gn b/services/distributeddataservice/app/src/checker/BUILD.gn index 1f59492c..0cb0a4f8 100644 --- a/services/distributeddataservice/app/src/checker/BUILD.gn +++ b/services/distributeddataservice/app/src/checker/BUILD.gn @@ -40,7 +40,7 @@ ohos_static_library("distributeddata_checker_static") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/services/distributeddataservice/app/src/uninstaller/BUILD.gn b/services/distributeddataservice/app/src/uninstaller/BUILD.gn index 04daeef7..d59a8144 100755 --- a/services/distributeddataservice/app/src/uninstaller/BUILD.gn +++ b/services/distributeddataservice/app/src/uninstaller/BUILD.gn @@ -49,7 +49,7 @@ ohos_static_library("distributeddata_uninstaller_static") { "ability_base:want", "common_event_service:cesfwk_innerkits", "dataclassification:data_transit_mgr", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 3ce6b41d..3518e2f5 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -87,10 +87,10 @@ ohos_unittest("KvStoreDataServiceTest") { "c_utils:utils", "dataclassification:data_transit_mgr", "device_auth:deviceauth_sdk", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hitrace_native:libhitracechain", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", @@ -138,7 +138,7 @@ ohos_unittest("SessionManagerTest") { "c_utils:utils", "dataclassification:data_transit_mgr", "device_auth:deviceauth_sdk", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", @@ -177,7 +177,7 @@ ohos_unittest("KvStoreFlowCtrlManagerTest") { "c_utils:utils", "dataclassification:data_transit_mgr", "device_auth:deviceauth_sdk", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index b09c9c74..b13f8c45 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -90,7 +90,7 @@ ohos_shared_library("distributeddatasvcfwk") { external_deps = [ "access_token:libaccesstoken_sdk", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index 1e2ccfa5..ba131185 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -37,7 +37,7 @@ ohos_unittest("CheckerManagerTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] @@ -60,7 +60,7 @@ ohos_unittest("EventCenterTest") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] @@ -83,7 +83,7 @@ ohos_unittest("SerializableTest") { "ability_base:base", "ability_base:want", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 4fbe91e3..6e8f2eba 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -124,7 +124,7 @@ ohos_shared_library("distributeddatasvc") { "c_utils:utils", "device_auth:deviceauth_sdk", "device_manager:devicemanagersdk", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 2d8ffad4..5abf23e6 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -99,7 +99,7 @@ ohos_shared_library("data_share_service") { "c_utils:utils", "data_share:datashare_common", "device_manager:devicemanagersdk", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", "relational_store:native_rdb", "relational_store:rdb_bms_adapter", diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn index 47128f8c..a66602e0 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn @@ -82,9 +82,9 @@ ohos_shared_library("gaussdb_rd") { external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn index b4cc59a3..75835174 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn @@ -81,9 +81,9 @@ ohos_source_set("src_file") { deps += [ "//third_party/cJSON:cjson" ] external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" @@ -115,9 +115,9 @@ template("gaussdb_rd_unittest") { ] external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hilog:libhilog", ] } } diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index c28c697a..79e3ba53 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("CloudDataTest") { "ability_base:base", "ability_base:want", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", ] @@ -84,7 +84,7 @@ ohos_unittest("ValueProxyTest") { "ability_base:base", "ability_base:want", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", ] @@ -109,7 +109,7 @@ ohos_unittest("ConfigFactoryTest") { "ability_base:base", "ability_base:want", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", "ipc:ipc_core", ] @@ -135,7 +135,7 @@ ohos_unittest("DirectoryManagerTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", "ipc:ipc_core", ] @@ -160,7 +160,7 @@ ohos_unittest("CryptoManagerTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", "ipc:ipc_core", ] @@ -189,7 +189,7 @@ ohos_unittest("DeviceMatrixTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", "ipc:ipc_core", ] diff --git a/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn b/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn index d2236940..7c7d5246 100644 --- a/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn +++ b/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn @@ -69,7 +69,7 @@ ohos_fuzztest("SchemaQueryFuzzTest") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", "ipc:ipc_core", ] } diff --git a/test/fuzztest/autolaunch_fuzzer/BUILD.gn b/test/fuzztest/autolaunch_fuzzer/BUILD.gn index fb3e4402..a9919927 100644 --- a/test/fuzztest/autolaunch_fuzzer/BUILD.gn +++ b/test/fuzztest/autolaunch_fuzzer/BUILD.gn @@ -89,7 +89,7 @@ ohos_fuzztest("AutoLaunchFuzzTest") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", ] } diff --git a/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn b/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn index 9ee8840f..56d0e5cc 100644 --- a/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn +++ b/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn @@ -90,7 +90,7 @@ ohos_fuzztest("KvStoreDiskSizeFuzzTest") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hiviewdfx_hilog:libhilog", ] } -- Gitee From db22a3e711497414de0dbeff2c551f8b18feff14 Mon Sep 17 00:00:00 2001 From: wellinleo Date: Wed, 28 Jun 2023 17:30:53 +0800 Subject: [PATCH 286/437] update Signed-off-by: wellinleo --- .../service/data_share/gaussdb_rd/BUILD.gn | 6 +++--- .../data_share/gaussdb_rd/test/unittest/BUILD.gn | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn index a66602e0..47128f8c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn @@ -82,9 +82,9 @@ ohos_shared_library("gaussdb_rd") { external_deps = [ "c_utils:utils", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", - "hilog:libhilog", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn index 75835174..b4cc59a3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn @@ -81,9 +81,9 @@ ohos_source_set("src_file") { deps += [ "//third_party/cJSON:cjson" ] external_deps = [ "c_utils:utils", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", - "hilog:libhilog", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", ] subsystem_name = "distributeddatamgr" @@ -115,9 +115,9 @@ template("gaussdb_rd_unittest") { ] external_deps = [ "c_utils:utils", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", - "hilog:libhilog", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", ] } } -- Gitee From b757b4f74629d50facce3493dc20c68caf59feb0 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 28 Jun 2023 20:22:47 +0800 Subject: [PATCH 287/437] fix:dataType Signed-off-by: htt1997 --- .../framework/include/store/general_watcher.h | 6 ++++++ services/distributeddataservice/service/rdb/rdb_cloud.cpp | 4 ---- .../service/rdb/rdb_general_store.cpp | 2 ++ services/distributeddataservice/service/rdb/rdb_watcher.cpp | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/framework/include/store/general_watcher.h b/services/distributeddataservice/framework/include/store/general_watcher.h index 4583aa9d..db0cde87 100644 --- a/services/distributeddataservice/framework/include/store/general_watcher.h +++ b/services/distributeddataservice/framework/include/store/general_watcher.h @@ -29,7 +29,13 @@ public: ORIGIN_ALL, ORIGIN_BUTT, }; + enum DataType : int32_t { + BASIC_DATA, + ASSET_DATA, + TYPE_BUTT, + }; int32_t origin = ORIGIN_BUTT; + int32_t dataType = BASIC_DATA; // origin is ORIGIN_LOCAL, the id is empty // origin is ORIGIN_NEARBY, the id is networkId; // origin is ORIGIN_CLOUD, the id is the cloud account id diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index 35ce54f1..e3d16735 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -15,7 +15,6 @@ #define LOG_TAG "RdbCloud" #include "rdb_cloud.h" -#include "cloud/schema_meta.h" #include "log_print.h" #include "value_proxy.h" #include "utils/anonymous.h" @@ -74,9 +73,6 @@ DBStatus RdbCloud::Query(const std::string &tableName, DBVBucket &extend, std::v err = cursor->MoveToNext(); count--; } - DistributedData::Value cursorFlag; - cursor->Get(SchemaMeta::CURSOR_FIELD, cursorFlag); - extend[SchemaMeta::CURSOR_FIELD] = ValueProxy::Convert(std::move(cursorFlag)); if (cursor->IsEnd()) { ZLOGD("query end, table:%{public}s", Anonymous::Change(tableName).c_str()); return DBStatus::QUERY_END; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 1d24fb42..ec47b7af 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -280,6 +280,8 @@ void RdbGeneralStore::ObserverProxy::OnChange(DBOrigin origin, const std::string genOrigin.origin = (origin == DBOrigin::ORIGIN_LOCAL) ? GenOrigin::ORIGIN_LOCAL : (origin == DBOrigin::ORIGIN_CLOUD) ? GenOrigin::ORIGIN_CLOUD : GenOrigin::ORIGIN_NEARBY; + genOrigin.dataType = (data.type == TYPE_INDEX || data.type == TYPE_INDEX) ? GenOrigin::ASSET_DATA + : GenOrigin::BASIC_DATA; genOrigin.id.push_back(originalId); genOrigin.store = storeId_; Watcher::PRIFields fields; diff --git a/services/distributeddataservice/service/rdb/rdb_watcher.cpp b/services/distributeddataservice/service/rdb/rdb_watcher.cpp index c929a769..a0d4d0ed 100644 --- a/services/distributeddataservice/service/rdb/rdb_watcher.cpp +++ b/services/distributeddataservice/service/rdb/rdb_watcher.cpp @@ -35,6 +35,7 @@ int32_t RdbWatcher::OnChange(const Origin &origin, const PRIFields &primaryField } DistributedRdb::Origin rdbOrigin; rdbOrigin.origin = origin.origin; + rdbOrigin.dataType = origin.dataType; rdbOrigin.id = origin.id; rdbOrigin.store = origin.store; notifier->OnChange(rdbOrigin, primaryFields, std::move(values)); -- Gitee From c9c6e257baa4dbdf39fc2d184e08c6c2d785a196 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Wed, 28 Jun 2023 20:33:18 +0800 Subject: [PATCH 288/437] fix status convert Signed-off-by: wanghuajian --- services/distributeddataservice/service/rdb/value_proxy.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index db4ef2fe..7affb81e 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -234,13 +234,13 @@ std::pair ValueProxy::Asset::ConvertToDBStatus(const Distrib return { static_cast(DistributedDB::AssetStatus::ABNORMAL), static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; case DistributedData::Asset::STATUS_INSERT: - return { static_cast(DistributedDB::AssetStatus::NORMAL), + return { static_cast(DistributedDB::AssetStatus::INSERT), static_cast(DistributedDB::AssetOpType::INSERT) }; case DistributedData::Asset::STATUS_UPDATE: - return { static_cast(DistributedDB::AssetStatus::NORMAL), + return { static_cast(DistributedDB::AssetStatus::UPDATE), static_cast(DistributedDB::AssetOpType::UPDATE) }; case DistributedData::Asset::STATUS_DELETE: - return { static_cast(DistributedDB::AssetStatus::NORMAL), + return { static_cast(DistributedDB::AssetStatus::DELETE), static_cast(DistributedDB::AssetOpType::DELETE) }; case DistributedData::Asset::STATUS_DOWNLOADING: return { static_cast(DistributedDB::AssetStatus::DOWNLOADING), -- Gitee From bcdc6feccd87ab2e3cbadd59568be216ac4c992e Mon Sep 17 00:00:00 2001 From: wellinleo Date: Wed, 28 Jun 2023 20:56:28 +0800 Subject: [PATCH 289/437] modify Signed-off-by: wellinleo --- services/distributeddataservice/adapter/BUILD.gn | 2 +- services/distributeddataservice/adapter/dfx/BUILD.gn | 2 +- services/distributeddataservice/adapter/dfx/test/BUILD.gn | 4 ++-- services/distributeddataservice/app/BUILD.gn | 2 +- services/distributeddataservice/app/test/BUILD.gn | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/adapter/BUILD.gn b/services/distributeddataservice/adapter/BUILD.gn index 998c7164..7c5cebe1 100644 --- a/services/distributeddataservice/adapter/BUILD.gn +++ b/services/distributeddataservice/adapter/BUILD.gn @@ -52,10 +52,10 @@ ohos_shared_library("distributeddata_adapter") { external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "hitrace:libhitracechain", - "hilog:libhilog", ] public_configs = [ ":distributeddata_adapter_public_config" ] diff --git a/services/distributeddataservice/adapter/dfx/BUILD.gn b/services/distributeddataservice/adapter/dfx/BUILD.gn index f64e5809..9d23ea69 100644 --- a/services/distributeddataservice/adapter/dfx/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/BUILD.gn @@ -44,10 +44,10 @@ ohos_static_library("distributeddata_dfx_static") { deps = [ "//third_party/openssl:libcrypto_shared" ] external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "hitrace:libhitracechain", - "hilog:libhilog", ] subsystem_name = "distributeddatamgr" part_name = "datamgr_service" diff --git a/services/distributeddataservice/adapter/dfx/test/BUILD.gn b/services/distributeddataservice/adapter/dfx/test/BUILD.gn index 1189d178..fe26d017 100755 --- a/services/distributeddataservice/adapter/dfx/test/BUILD.gn +++ b/services/distributeddataservice/adapter/dfx/test/BUILD.gn @@ -41,9 +41,9 @@ ohos_unittest("DistributeddataDfxMSTTest") { external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "hilog:libhilog", ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ @@ -99,9 +99,9 @@ ohos_unittest("DistributeddataDfxUTTest") { external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "hilog:libhilog", ] ldflags = [ "-Wl,--exclude-libs,ALL" ] deps = [ diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 14cda7f3..607c6732 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -118,10 +118,10 @@ ohos_shared_library("distributeddataservice") { "bundle_framework:appexecfwk_core", "c_utils:utils", "dataclassification:data_transit_mgr", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "hitrace:libhitracechain", - "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", "safwk:system_ability_fwk", diff --git a/services/distributeddataservice/app/test/BUILD.gn b/services/distributeddataservice/app/test/BUILD.gn index 3518e2f5..f471e188 100644 --- a/services/distributeddataservice/app/test/BUILD.gn +++ b/services/distributeddataservice/app/test/BUILD.gn @@ -87,10 +87,10 @@ ohos_unittest("KvStoreDataServiceTest") { "c_utils:utils", "dataclassification:data_transit_mgr", "device_auth:deviceauth_sdk", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "hitrace:libhitracechain", - "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", -- Gitee From 093b4eef63935bf1fc815ad634973dc62bc9a264 Mon Sep 17 00:00:00 2001 From: wellinleo Date: Wed, 28 Jun 2023 21:05:35 +0800 Subject: [PATCH 290/437] update Signed-off-by: wellinleo --- .../distributeddataservice/service/test/BUILD.gn | 12 ++++++------ .../test/fuzztest/schemaquery_fuzzer/BUILD.gn | 2 +- test/fuzztest/autolaunch_fuzzer/BUILD.gn | 2 +- test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 79e3ba53..a951e052 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -54,7 +54,7 @@ ohos_unittest("CloudDataTest") { "ability_base:base", "ability_base:want", "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", ] @@ -84,7 +84,7 @@ ohos_unittest("ValueProxyTest") { "ability_base:base", "ability_base:want", "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", ] @@ -109,7 +109,7 @@ ohos_unittest("ConfigFactoryTest") { "ability_base:base", "ability_base:want", "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] @@ -135,7 +135,7 @@ ohos_unittest("DirectoryManagerTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] @@ -160,7 +160,7 @@ ohos_unittest("CryptoManagerTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] @@ -189,7 +189,7 @@ ohos_unittest("DeviceMatrixTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] diff --git a/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn b/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn index 7c7d5246..2cc4e277 100644 --- a/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn +++ b/services/distributeddataservice/test/fuzztest/schemaquery_fuzzer/BUILD.gn @@ -69,7 +69,7 @@ ohos_fuzztest("SchemaQueryFuzzTest") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", "ipc:ipc_core", ] } diff --git a/test/fuzztest/autolaunch_fuzzer/BUILD.gn b/test/fuzztest/autolaunch_fuzzer/BUILD.gn index a9919927..92344ab4 100644 --- a/test/fuzztest/autolaunch_fuzzer/BUILD.gn +++ b/test/fuzztest/autolaunch_fuzzer/BUILD.gn @@ -89,7 +89,7 @@ ohos_fuzztest("AutoLaunchFuzzTest") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", ] } diff --git a/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn b/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn index 56d0e5cc..d6de3de8 100644 --- a/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn +++ b/test/fuzztest/kvstoredisksize_fuzzer/BUILD.gn @@ -90,7 +90,7 @@ ohos_fuzztest("KvStoreDiskSizeFuzzTest") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", ] } -- Gitee From 48ac3d95429e9378334a9f30b87d6d6caff8eed2 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 28 Jun 2023 21:19:13 +0800 Subject: [PATCH 291/437] fix:dataType Signed-off-by: htt1997 --- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index ec47b7af..8304927e 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -280,8 +280,7 @@ void RdbGeneralStore::ObserverProxy::OnChange(DBOrigin origin, const std::string genOrigin.origin = (origin == DBOrigin::ORIGIN_LOCAL) ? GenOrigin::ORIGIN_LOCAL : (origin == DBOrigin::ORIGIN_CLOUD) ? GenOrigin::ORIGIN_CLOUD : GenOrigin::ORIGIN_NEARBY; - genOrigin.dataType = (data.type == TYPE_INDEX || data.type == TYPE_INDEX) ? GenOrigin::ASSET_DATA - : GenOrigin::BASIC_DATA; + genOrigin.dataType = data.type == DistributedDB::ASSET ? GenOrigin::ASSET_DATA : GenOrigin::BASIC_DATA; genOrigin.id.push_back(originalId); genOrigin.store = storeId_; Watcher::PRIFields fields; -- Gitee From c11e00da9c137482a1defdaa16d9cd014f518d8f Mon Sep 17 00:00:00 2001 From: wellinleo Date: Thu, 29 Jun 2023 09:13:15 +0800 Subject: [PATCH 292/437] update Signed-off-by: wellinleo --- services/distributeddataservice/adapter/utils/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/adapter/utils/BUILD.gn b/services/distributeddataservice/adapter/utils/BUILD.gn index e3f085cf..6442a139 100755 --- a/services/distributeddataservice/adapter/utils/BUILD.gn +++ b/services/distributeddataservice/adapter/utils/BUILD.gn @@ -35,7 +35,7 @@ ohos_static_library("distributeddata_utils_static") { external_deps = [ "c_utils:utils", - "hiviewdfx_hilog:libhilog", + "hilog:libhilog", ] subsystem_name = "distributeddatamgr" part_name = "datamgr_service" -- Gitee From fec47c62a97d5597fbf78d72b9608eb99f7c3acf Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 29 Jun 2023 10:53:12 +0800 Subject: [PATCH 293/437] fix:change close time Signed-off-by: htt1997 --- .../service/rdb/rdb_service_impl.cpp | 13 ++++++++++++- .../service/rdb/rdb_service_impl.h | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index f0fa85c8..3135c20f 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -143,7 +143,6 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib int32_t RdbServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) { OnClientDied(pid); - AutoCache::GetInstance().CloseStore(tokenId); return E_OK; } @@ -653,4 +652,16 @@ int32_t RdbServiceImpl::OnBind(const BindInfo &bindInfo) executors_ = bindInfo.executors; return 0; } + +int32_t RdbServiceImpl::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) +{ + AutoCache::GetInstance().CloseStore(tokenId); + return E_OK; +} + +int32_t RdbServiceImpl::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) +{ + AutoCache::GetInstance().CloseStore(tokenId); + return E_OK; +} } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 061e5489..29d87b0e 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -66,6 +66,10 @@ public: int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; + int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; + + int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; + int32_t GetSchema(const RdbSyncerParam ¶m) override; int32_t OnBind(const BindInfo &bindInfo) override; -- Gitee From d7dc7cd28d3f68344ac8db0a05aaeb651733e3eb Mon Sep 17 00:00:00 2001 From: wellinleo Date: Thu, 29 Jun 2023 11:24:43 +0800 Subject: [PATCH 294/437] update Signed-off-by: wellinleo --- .../service/test/fuzztest/udmfservice_fuzzer/BUILD.gn | 2 +- services/distributeddataservice/service/udmf/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn index 30a81399..4c7e0b1e 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn @@ -52,7 +52,7 @@ ohos_fuzztest("UdmfServiceFuzzTest") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", "udmf:udmf_client", diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index 64077d45..cfb32b79 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -62,7 +62,7 @@ ohos_shared_library("udmf_server") { "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_core", "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", "udmf:udmf_client", -- Gitee From 03366f59c3d48f8917af2299798532ce89ed998e Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Thu, 29 Jun 2023 10:32:10 +0800 Subject: [PATCH 295/437] modify ipc code Signed-off-by: ding_dong_dong --- .../service/kvdb/kvdb_service_stub.cpp | 9 ++++-- .../service/kvdb/kvdb_service_stub.h | 3 +- .../test/fuzztest/udmfservice_fuzzer/BUILD.gn | 5 ++- .../service/udmf/udmf_service_stub.cpp | 32 +++---------------- .../service/udmf/udmf_service_stub.h | 16 +++++++--- 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp index 8894c4ad..1da51ce4 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp @@ -23,7 +23,8 @@ #include "utils/anonymous.h" namespace OHOS::DistributedKv { using namespace OHOS::DistributedData; -const KVDBServiceStub::Handler KVDBServiceStub::HANDLERS[TRANS_BUTT] = { +const KVDBServiceStub::Handler + KVDBServiceStub::HANDLERS[static_cast(KVDBServiceInterfaceCode::TRANS_BUTT)] = { &KVDBServiceStub::OnGetStoreIds, &KVDBServiceStub::OnBeforeCreate, &KVDBServiceStub::OnAfterCreate, @@ -53,8 +54,10 @@ int KVDBServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message return -1; } - if (TRANS_HEAD > code || code >= TRANS_BUTT || HANDLERS[code] == nullptr) { - ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); + if (static_cast(KVDBServiceInterfaceCode::TRANS_HEAD) > code || + code >= static_cast(KVDBServiceInterfaceCode::TRANS_BUTT) || HANDLERS[code] == nullptr) { + ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, + static_cast(KVDBServiceInterfaceCode::TRANS_BUTT)); return -1; } diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_stub.h b/services/distributeddataservice/service/kvdb/kvdb_service_stub.h index ab0bacc4..00b1763d 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_stub.h +++ b/services/distributeddataservice/service/kvdb/kvdb_service_stub.h @@ -15,6 +15,7 @@ #ifndef OHOS_DISTRIBUTED_DATA_SERVICE_KVDB_SERVICE_STUB_H #define OHOS_DISTRIBUTED_DATA_SERVICE_KVDB_SERVICE_STUB_H +#include "distributeddata_kvdb_ipc_interface_code.h" #include "iremote_stub.h" #include "kvdb_service.h" #include "feature/feature_system.h" @@ -43,7 +44,7 @@ private: int32_t OnSubscribe(const AppId &appId, const StoreId &storeId, MessageParcel &data, MessageParcel &reply); int32_t OnUnsubscribe(const AppId &appId, const StoreId &storeId, MessageParcel &data, MessageParcel &reply); int32_t OnGetBackupPassword(const AppId &appId, const StoreId &storeId, MessageParcel &data, MessageParcel &reply); - static const Handler HANDLERS[TRANS_BUTT]; + static const Handler HANDLERS[static_cast(KVDBServiceInterfaceCode::TRANS_BUTT)]; }; } // namespace OHOS::DistributedKv #endif // OHOS_DISTRIBUTED_DATA_SERVICE_KVDB_SERVICE_STUB_H diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn index 30a81399..92b49df7 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn @@ -44,7 +44,10 @@ ohos_fuzztest("UdmfServiceFuzzTest") { sources = [ "udmfservice_fuzzer.cpp" ] - deps = [ "${data_service_path}/service/udmf:udmf_server" ] + deps = [ + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/udmf:udmf_server", + ] external_deps = [ "ability_base:zuri", diff --git a/services/distributeddataservice/service/udmf/udmf_service_stub.cpp b/services/distributeddataservice/service/udmf/udmf_service_stub.cpp index febb3a3d..ca92a0fb 100755 --- a/services/distributeddataservice/service/udmf/udmf_service_stub.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_stub.cpp @@ -27,23 +27,8 @@ namespace OHOS { namespace UDMF { -UdmfServiceStub::UdmfServiceStub() -{ - memberFuncMap_[static_cast(SET_DATA)] = &UdmfServiceStub::OnSetData; - memberFuncMap_[static_cast(GET_DATA)] = &UdmfServiceStub::OnGetData; - memberFuncMap_[static_cast(GET_BATCH_DATA)] = &UdmfServiceStub::OnGetBatchData; - memberFuncMap_[static_cast(UPDATE_DATA)] = &UdmfServiceStub::OnUpdateData; - memberFuncMap_[static_cast(DELETE_DATA)] = &UdmfServiceStub::OnDeleteData; - memberFuncMap_[static_cast(GET_SUMMARY)] = &UdmfServiceStub::OnGetSummary; - memberFuncMap_[static_cast(ADD_PRIVILEGE)] = &UdmfServiceStub::OnAddPrivilege; - memberFuncMap_[static_cast(SYNC)] = &UdmfServiceStub::OnSync; -} - -UdmfServiceStub::~UdmfServiceStub() -{ - memberFuncMap_.clear(); -} - +constexpr UdmfServiceStub::Handler + UdmfServiceStub::HANDLERS[static_cast(UdmfServiceInterfaceCode::CODE_BUTT)]; int UdmfServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) { ZLOGI("start##code = %{public}u", code); @@ -53,18 +38,11 @@ int UdmfServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message ZLOGE("end##descriptor checked fail"); return -1; } - if (CODE_HEAD > code || code >= CODE_BUTT) { + if (static_cast(UdmfServiceInterfaceCode::CODE_HEAD) > code || + code >= static_cast(UdmfServiceInterfaceCode::CODE_BUTT)) { return -1; } - auto itFunc = memberFuncMap_.find(code); - if (itFunc != memberFuncMap_.end()) { - auto memberFunc = itFunc->second; - if (memberFunc != nullptr) { - return (this->*memberFunc)(data, reply); - } - } - ZLOGI("end##ret = -1"); - return -1; + return (this->*HANDLERS[code])(data, reply); } int32_t UdmfServiceStub::OnSetData(MessageParcel &data, MessageParcel &reply) diff --git a/services/distributeddataservice/service/udmf/udmf_service_stub.h b/services/distributeddataservice/service/udmf/udmf_service_stub.h index 9684d2ec..d3a73999 100755 --- a/services/distributeddataservice/service/udmf/udmf_service_stub.h +++ b/services/distributeddataservice/service/udmf/udmf_service_stub.h @@ -22,6 +22,7 @@ #include "feature/feature_system.h" #include "message_parcel.h" +#include "distributeddata_udmf_ipc_interface_code.h" #include "error_code.h" #include "udmf_service.h" @@ -32,8 +33,6 @@ namespace UDMF { */ class UdmfServiceStub : public UdmfService, public DistributedData::FeatureSystem::Feature { public: - UdmfServiceStub(); - virtual ~UdmfServiceStub() override; int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override; private: @@ -52,8 +51,17 @@ private: const std::string WRITE_PERMISSION = "ohos.permission.WRITE_UDMF_DATA"; const std::string SYNC_PERMISSION = "ohos.permission.SYNC_UDMF_DATA"; - using UdmfServiceFunc = int32_t (UdmfServiceStub::*)(MessageParcel &data, MessageParcel &reply); - std::map memberFuncMap_; + using Handler = int32_t (UdmfServiceStub::*)(MessageParcel &data, MessageParcel &reply); + static constexpr Handler HANDLERS[static_cast(UdmfServiceInterfaceCode::CODE_BUTT)] = { + &UdmfServiceStub::OnSetData, + &UdmfServiceStub::OnGetData, + &UdmfServiceStub::OnGetBatchData, + &UdmfServiceStub::OnUpdateData, + &UdmfServiceStub::OnDeleteData, + &UdmfServiceStub::OnGetSummary, + &UdmfServiceStub::OnAddPrivilege, + &UdmfServiceStub::OnSync + }; }; } // namespace UDMF } // namespace OHOS -- Gitee From 12e75ffd236e491062f5d3ac09ea1fb4e9c136e7 Mon Sep 17 00:00:00 2001 From: leiiyb Date: Thu, 29 Jun 2023 10:48:02 +0800 Subject: [PATCH 296/437] Anonymize the database path Signed-off-by: leiiyb --- services/distributeddataservice/service/rdb/rdb_syncer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_syncer.cpp b/services/distributeddataservice/service/rdb/rdb_syncer.cpp index a6442cf1..9fbd7642 100644 --- a/services/distributeddataservice/service/rdb/rdb_syncer.cpp +++ b/services/distributeddataservice/service/rdb/rdb_syncer.cpp @@ -167,11 +167,11 @@ int32_t RdbSyncer::InitDBDelegate(const StoreMetaData &meta) } option.observer = observer_; std::string fileName = meta.dataDir; - ZLOGI("path=%{public}s storeId=%{public}s", fileName.c_str(), meta.GetStoreAlias().c_str()); + ZLOGI("path=%{public}s storeId=%{public}s", Anonymous::Change(fileName).c_str(), meta.GetStoreAlias().c_str()); auto status = manager_->OpenStore(fileName, meta.storeId, option, delegate_); if (status != DistributedDB::DBStatus::OK) { ZLOGE("open store failed, path=%{public}s storeId=%{public}s status=%{public}d", - fileName.c_str(), meta.GetStoreAlias().c_str(), status); + Anonymous::Change(fileName).c_str(), meta.GetStoreAlias().c_str(), status); return RDB_ERROR; } ZLOGI("open store success"); -- Gitee From c8663bcf87c8180cd4f9c514c772a603bdc96084 Mon Sep 17 00:00:00 2001 From: mazhao Date: Thu, 29 Jun 2023 14:44:05 +0800 Subject: [PATCH 297/437] Optimized for checking format codes Signed-off-by: mazhao --- .../src/executor/document/check_common.cpp | 50 ++++++++++++------- .../src/executor/document/check_common.h | 2 +- .../src/interface/src/document_store.cpp | 15 +----- .../src/oh_adapter/include/json_object.h | 4 +- .../src/oh_adapter/src/json_object.cpp | 24 ++++++--- .../documentdb_json_common_test.cpp | 19 ------- 6 files changed, 56 insertions(+), 58 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp index 01513f9f..52891fe1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp @@ -155,34 +155,50 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) return E_OK; } -int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector> &path) +int SplitFieldName(const std::string &fieldName, std::vector &allFieldsName) { - if (updataObj.GetDeep() > JSON_DEEP_MAX) { - GLOGE("projectionObj's json deep is deeper than JSON_DEEP_MAX"); - return -E_INVALID_ARGS; - } - for (size_t i = 0; i < path.size(); i++) { - if (path[i].empty()) { - return -E_INVALID_JSON_FORMAT; + std::string tempParseName; + std::string priFieldName = fieldName; + for (size_t j = 0; j < priFieldName.size(); j++) { + if (priFieldName[j] != '.') { + tempParseName += priFieldName[j]; } - for (size_t j = 0; j < path[i].size(); j++) { - if (path[i][j].empty()) { + if (priFieldName[j] == '.' || j == priFieldName.size() - 1) { + if ((j > 0 && priFieldName[j] == '.' && priFieldName[j - 1] == '.') || + (priFieldName[j] == '.' && j == priFieldName.size() - 1)) { return -E_INVALID_ARGS; } - for (auto oneChar : path[i][j]) { + allFieldsName.emplace_back(tempParseName); + tempParseName.clear(); + } + } + return E_OK; +} + +int CheckCommon::CheckUpdata(JsonObject &updataObj) +{ + JsonObject jsonTemp = updataObj.GetChild(); + size_t maxDeep = 0; + while (!jsonTemp.IsNull()) { + std::vector allFieldsName; + int errCode = SplitFieldName(jsonTemp.GetItemField(), allFieldsName); + if (errCode != E_OK) { + return errCode; + } + for (auto fieldName : allFieldsName) { + for (auto oneChar : fieldName) { if (!((isalpha(oneChar)) || (isdigit(oneChar)) || (oneChar == '_'))) { + GLOGE("updata fieldName is illegal"); return -E_INVALID_ARGS; } } } - if (!path[i].empty() && !path[i][0].empty() && isdigit(path[i][0][0])) { - return -E_INVALID_ARGS; - } - } - for (const auto &singlePath : path) { - if (singlePath.size() > JSON_DEEP_MAX) { + maxDeep = std::max(allFieldsName.size() + jsonTemp.GetDeep(), maxDeep); + if (maxDeep > JSON_DEEP_MAX) { + GLOGE("document's json deep is deeper than JSON_DEEP_MAX"); return -E_INVALID_ARGS; } + jsonTemp = jsonTemp.GetNext(); } bool isIdExist = true; CheckIdFormat(updataObj, isIdExist); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h index 2985bd67..e9ae1180 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h @@ -32,7 +32,7 @@ public: static int CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector> &filterPath); static int CheckIdFormat(JsonObject &filterJson, bool &isIdExisit); static int CheckDocument(JsonObject &documentObj); - static int CheckUpdata(JsonObject &updataObj, std::vector> &path); + static int CheckUpdata(JsonObject &updata); static int CheckProjection(JsonObject &projectionObj, std::vector> &path); }; using Key = std::vector; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index 1b50f92a..caa230c1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -157,13 +157,7 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } if (update != "{}") { - std::vector> allPath; - allPath = JsonCommon::ParsePath(updateObj, errCode); - if (errCode != E_OK) { - GLOGE("updateObj ParsePath failed"); - return errCode; - } - errCode = CheckCommon::CheckUpdata(updateObj, allPath); + errCode = CheckCommon::CheckUpdata(updateObj); if (errCode != E_OK) { GLOGE("Updata format is illegal"); return errCode; @@ -343,12 +337,7 @@ int UpsertDocumentFormatCheck(const std::string &document, JsonObject &documentO { int errCode = E_OK; if (document != "{}") { - std::vector> allPath; - allPath = JsonCommon::ParsePath(documentObj, errCode); - if (errCode != E_OK) { - return errCode; - } - errCode = CheckCommon::CheckUpdata(documentObj, allPath); + errCode = CheckCommon::CheckUpdata(documentObj); if (errCode != E_OK) { GLOGE("UpsertDocument document format is illegal"); return errCode; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h index afd0489d..9680c82c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h @@ -106,8 +106,8 @@ public: private: JsonObject(); int Init(const std::string &str, bool isFilter = false); - int CheckJsonRepeatField(cJSON *object); - int CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType); + int CheckJsonRepeatField(cJSON *object, bool isFirstFloor); + int CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType, bool isFirstFloor); int GetDeep(cJSON *cjson); int CheckNumber(cJSON *cjson, int &errCode); cJSON *cjson_ = nullptr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 10afef3a..5f5bcc06 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -195,7 +195,8 @@ int JsonObject::Init(const std::string &str, bool isFilter) return -E_INVALID_ARGS; } if (!isFilter) { - ret = CheckJsonRepeatField(cjson_); + bool isFirstFloor = true; + ret = CheckJsonRepeatField(cjson_, isFirstFloor); if (ret != E_OK) { return ret; } @@ -203,7 +204,7 @@ int JsonObject::Init(const std::string &str, bool isFilter) return E_OK; } -int JsonObject::CheckJsonRepeatField(cJSON *object) +int JsonObject::CheckJsonRepeatField(cJSON *object, bool isFirstFloor) { if (object == nullptr) { return -E_INVALID_ARGS; @@ -216,7 +217,7 @@ int JsonObject::CheckJsonRepeatField(cJSON *object) std::set fieldSet; cJSON *subObj = object->child; while (subObj != nullptr) { - ret = CheckSubObj(fieldSet, subObj, type); + ret = CheckSubObj(fieldSet, subObj, type, isFirstFloor); if (ret != E_OK) { break; } @@ -225,7 +226,7 @@ int JsonObject::CheckJsonRepeatField(cJSON *object) return ret; } -int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType) +int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType, bool isFirstFloor) { if (subObj == nullptr) { return -E_INVALID_ARGS; @@ -233,9 +234,20 @@ int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int std::string fieldName; if (subObj->string != nullptr) { fieldName = subObj->string; + if (!isFirstFloor) { + for (auto oneChar : fieldName) { + if (!((isalpha(oneChar)) || (isdigit(oneChar)) || (oneChar == '_'))) { + return -E_INVALID_ARGS; + } + } + } + if (!fieldName.empty() && isdigit(fieldName[0])) { + return -E_INVALID_ARGS; + } } + isFirstFloor = false; if (parentType == cJSON_Array) { - return CheckJsonRepeatField(subObj); + return CheckJsonRepeatField(subObj, isFirstFloor); } if (fieldName.empty()) { return -E_INVALID_JSON_FORMAT; @@ -245,7 +257,7 @@ int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int } else { return -E_INVALID_JSON_FORMAT; } - return CheckJsonRepeatField(subObj); + return CheckJsonRepeatField(subObj, isFirstFloor); } std::string JsonObject::Print() const diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp index bec7c70a..3e92ba17 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -147,25 +147,6 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); } -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest006, TestSize.Level0) -{ - std::string document = R""({"name":{"first":"Tno", "last":"moray"}})""; - std::string updateDoc = R""({"name":{"midle.AA":"GG"}})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add, false), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({ "name", "midle.AA" }, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); -} - HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest007, TestSize.Level0) { std::string document = R""({"name":{"first":["XX", "CC"], "last":"moray"}})""; -- Gitee From c7f204308702761a2ea1e7b95cbb6a0dd2a053d2 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 30 Jun 2023 11:00:07 +0800 Subject: [PATCH 298/437] test Signed-off-by: niudongyao --- .idea/.gitignore | 8 ++++++++ .idea/deployment.xml | 14 ++++++++++++++ ...distributeddatamgr_datamgr_service_warn_fix.iml | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ .../service/data_share/data_share_service_impl.cpp | 6 ++++++ .../service/data_share/data_share_service_impl.h | 1 + 7 files changed, 51 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/deployment.xml create mode 100644 .idea/distributeddatamgr_datamgr_service_warn_fix.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..73f69e09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 00000000..88d7df4d --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/distributeddatamgr_datamgr_service_warn_fix.iml b/.idea/distributeddatamgr_datamgr_service_warn_fix.iml new file mode 100644 index 00000000..bc2cd874 --- /dev/null +++ b/.idea/distributeddatamgr_datamgr_service_warn_fix.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..c106ae70 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 568c1046..3fe12182 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -461,6 +461,12 @@ int32_t DataShareServiceImpl::OnAppUninstall( return EOK; } +int32_t DataShareServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) +{ + ZLOGI("ObjectServiceImpl::OnAppExit uid=%{public}d, pid=%{public}d, tokenId=%{public}d, bundleName=%{public}s", + uid, pid, tokenId, bundleName.c_str()); +} + void DataShareServiceImpl::NotifyObserver(const std::string &uri) { ZLOGD("%{private}s try notified", uri.c_str()); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 72d102ca..7978baed 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -68,6 +68,7 @@ public: int32_t OnBind(const BindInfo &binderInfo) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; + int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; void NotifyObserver(const std::string &uri) override; private: -- Gitee From 4904a1d0963e9bf77d9fbf3d262915cc288304fb Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 30 Jun 2023 11:00:22 +0800 Subject: [PATCH 299/437] test Signed-off-by: niudongyao --- .idea/.gitignore | 8 -------- .idea/deployment.xml | 14 -------------- ...distributeddatamgr_datamgr_service_warn_fix.iml | 8 -------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 5 files changed, 44 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/deployment.xml delete mode 100644 .idea/distributeddatamgr_datamgr_service_warn_fix.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e09..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/deployment.xml b/.idea/deployment.xml deleted file mode 100644 index 88d7df4d..00000000 --- a/.idea/deployment.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/distributeddatamgr_datamgr_service_warn_fix.iml b/.idea/distributeddatamgr_datamgr_service_warn_fix.iml deleted file mode 100644 index bc2cd874..00000000 --- a/.idea/distributeddatamgr_datamgr_service_warn_fix.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index c106ae70..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file -- Gitee From 74e2b1b3c930fa908886d67fb60b62565a0458c2 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Fri, 30 Jun 2023 11:39:21 +0800 Subject: [PATCH 300/437] codestyle fix Signed-off-by: genglingxia --- .../service/udmf/store/runtime_store.cpp | 20 +++++++++---------- .../service/udmf/store/store.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index c5248de1..05ad7c40 100755 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -32,7 +32,7 @@ const std::string RuntimeStore::BASE_DIR = "/data/service/el1/public/database/di RuntimeStore::RuntimeStore(const std::string &storeId) : storeId_({ storeId }) { - updateTime(); + UpdateTime(); ZLOGI("Construct runtimeStore: %{public}s.", storeId_.storeId.c_str()); } @@ -44,7 +44,7 @@ RuntimeStore::~RuntimeStore() Status RuntimeStore::Put(const UnifiedData &unifiedData) { - updateTime(); + UpdateTime(); std::vector entries; std::string unifiedKey = unifiedData.GetRuntime()->key.GetUnifiedKey(); // add unified record @@ -79,7 +79,7 @@ Status RuntimeStore::Put(const UnifiedData &unifiedData) Status RuntimeStore::Get(const std::string &key, UnifiedData &unifiedData) { - updateTime(); + UpdateTime(); std::vector entries; if (GetEntries(key, entries) != E_OK) { ZLOGI("GetEntries failed, dataPrefix: %{public}s.", key.c_str()); @@ -94,7 +94,7 @@ Status RuntimeStore::Get(const std::string &key, UnifiedData &unifiedData) Status RuntimeStore::GetSummary(const std::string &key, Summary &summary) { - updateTime(); + UpdateTime(); UnifiedData unifiedData; if (Get(key, unifiedData) != E_OK) { ZLOGE("Get unified data failed."); @@ -116,7 +116,7 @@ Status RuntimeStore::GetSummary(const std::string &key, Summary &summary) Status RuntimeStore::Update(const UnifiedData &unifiedData) { - updateTime(); + UpdateTime(); std::string key = unifiedData.GetRuntime()->key.key; if (Delete(key) != E_OK) { ZLOGE("Delete unified data failed."); @@ -131,7 +131,7 @@ Status RuntimeStore::Update(const UnifiedData &unifiedData) Status RuntimeStore::Delete(const std::string &key) { - updateTime(); + UpdateTime(); std::vector entries; if (GetEntries(key, entries) != E_OK) { ZLOGE("GetEntries failed, dataPrefix: %{public}s.", key.c_str()); @@ -150,7 +150,7 @@ Status RuntimeStore::Delete(const std::string &key) Status RuntimeStore::DeleteBatch(const std::vector &unifiedKeys) { - updateTime(); + UpdateTime(); ZLOGD("called!"); if (unifiedKeys.empty()) { ZLOGD("No need to delete!"); @@ -167,7 +167,7 @@ Status RuntimeStore::DeleteBatch(const std::vector &unifiedKeys) Status RuntimeStore::Sync(const std::vector &devices) { - updateTime(); + UpdateTime(); SameProcessIpcGuard ipcGuard; DistributedKv::Status status = kvStore_->Sync(devices, SyncMode::PULL); if (status != DistributedKv::Status::SUCCESS) { @@ -179,13 +179,13 @@ Status RuntimeStore::Sync(const std::vector &devices) Status RuntimeStore::Clear() { - updateTime(); + UpdateTime(); return Delete(DATA_PREFIX); } Status RuntimeStore::GetBatchData(const std::string &dataPrefix, std::vector &unifiedDataSet) { - updateTime(); + UpdateTime(); std::vector entries; auto status = GetEntries(dataPrefix, entries); if (status != E_OK) { diff --git a/services/distributeddataservice/service/udmf/store/store.h b/services/distributeddataservice/service/udmf/store/store.h index 6996d849..519a79b7 100755 --- a/services/distributeddataservice/service/udmf/store/store.h +++ b/services/distributeddataservice/service/udmf/store/store.h @@ -47,7 +47,7 @@ public: return time_ < time; } - void updateTime() + void UpdateTime() { std::unique_lock lock(timeMutex_); time_ = std::chrono::steady_clock::now() + std::chrono::minutes(INTERVAL); -- Gitee From 2e8bac59296a02225e7ea0bdb4951c69cbdb8ae2 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 30 Jun 2023 11:43:06 +0800 Subject: [PATCH 301/437] test Signed-off-by: niudongyao --- .idea/workspace.xml | 60 +++++++++++++++++++ .../data_share/data_share_service_impl.cpp | 1 + 2 files changed, 61 insertions(+) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..58df6bd9 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1688093771186 + + + + + + + + + \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 3fe12182..b3e34324 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -465,6 +465,7 @@ int32_t DataShareServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, { ZLOGI("ObjectServiceImpl::OnAppExit uid=%{public}d, pid=%{public}d, tokenId=%{public}d, bundleName=%{public}s", uid, pid, tokenId, bundleName.c_str()); + return EOK; } void DataShareServiceImpl::NotifyObserver(const std::string &uri) -- Gitee From d522979710d02630c73e23e5cd620a176cce31bc Mon Sep 17 00:00:00 2001 From: genglingxia Date: Thu, 29 Jun 2023 21:12:06 +0800 Subject: [PATCH 302/437] drag cross device 0629 Signed-off-by: genglingxia --- bundle.json | 3 +- datamgr_service.gni | 2 + .../distributeddataservice/service/BUILD.gn | 1 + .../service/udmf/BUILD.gn | 7 +++- .../service/udmf/data_manager.cpp | 38 ++++++++++++++++--- .../service/udmf/data_manager.h | 1 + .../udmf/preprocess/preprocess_utils.cpp | 26 ++++++++++++- .../udmf/preprocess/preprocess_utils.h | 2 + 8 files changed, 72 insertions(+), 8 deletions(-) diff --git a/bundle.json b/bundle.json index 71456bba..59a52531 100644 --- a/bundle.json +++ b/bundle.json @@ -75,7 +75,8 @@ "relational_store", "safwk", "samgr", - "udmf" + "udmf", + "app_file_service" ], "third_party": [ "cjson", diff --git a/datamgr_service.gni b/datamgr_service.gni index 5e1d91c6..9d22d3e6 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -32,6 +32,8 @@ ipc_core_path = "//foundation/communication/ipc/interfaces/innerkits/ipc_core" device_manager_path = "//foundation/distributedhardware/device_manager" +file_service_path = "//foundation/filemanagement/app_file_service" + data_service_path = "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice" udmf_path = "//foundation/distributeddatamgr/udmf" diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 4fbe91e3..c6a237e6 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -128,6 +128,7 @@ ohos_shared_library("distributeddatasvc") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", + "app_file_service:remote_file_share_native", "relational_store:native_rdb", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index 64077d45..6ca9f218 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -31,6 +31,7 @@ config("module_public_config") { "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", "${kv_store_path}/frameworks/common", + "${file_service_path}/interfaces/innerkits/remote_file_share/native", ] } @@ -54,12 +55,16 @@ ohos_shared_library("udmf_server") { configs = [ ":module_public_config" ] - deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] + deps = [ "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/adapter:distributeddata_adapter", + + ] external_deps = [ "ability_base:zuri", "ability_runtime:uri_permission_mgr", "access_token:libaccesstoken_sdk", + "app_file_service:remote_file_share_native", "bundle_framework:appexecfwk_core", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 7b4bc0a3..7d02621a 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -22,6 +22,7 @@ #include "log_print.h" #include "preprocess_utils.h" #include "uri_permission_manager.h" +#include "remote_file_share.h" namespace OHOS { namespace UDMF { @@ -43,6 +44,14 @@ DataManager &DataManager::GetInstance() return instance; } +bool DataManager::IsFileType(UDType udType){ + if (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO + || udType == UDType::FOLDER) { + return true; + } + return false; +} + int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key) { if (unifiedData.IsEmpty()) { @@ -60,11 +69,24 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st ZLOGE("Imputation failed"); return E_UNKNOWN; } - for (auto &record : unifiedData.GetRecords()) { - std::string uid = PreProcessUtils::IdGenerator(); - record->SetUid(uid); + int32_t userId = PreProcessUtils::GetHapUidByToken(option.tokenId); + for (const auto &record : unifiedData.GetRecords()) + { + auto type = record->GetType(); + if (IsFileType(type)) { + auto file = static_cast(record.get()); + std::string remoteUri = AppFileService::GetDfsUriFromLocal(file->GetUri(), userId); + if(remoteUri.empty()) { + ZLOGW("Get remoteUri failed, uri: %{public}s, remoteUri: %{public}s.", file->GetUri().c_str(), remoteUri.c_str()); + return E_UNKNOWN; + } + file->SetRemoteUri(remoteUri); + } + + record->SetUid(PreProcessUtils::GetInstance().IdGenerator()); } + std::string intention = unifiedData.GetRuntime()->key.intention; auto store = storeCache_.GetStore(intention); if (store == nullptr) { @@ -121,10 +143,16 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified for (auto record : records) { auto type = record->GetType(); std::string uri = ""; - if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO - || type == UDType::FOLDER) { + if (IsFileType(type)) { auto file = static_cast(record.get()); uri = file->GetUri(); + + std::string localDeviceId=PreProcessUtils::GetLocalDeviceId(); + ZLOGE("DataManager::RetrieveData, localDeviceId=%{public}s, remoteDeviceId=%{public}s,uri=%{public}s,remoteUri=%{public}s.", localDeviceId.c_str(), (runtime->deviceId).c_str(),file->GetUri().c_str(),file->GetRemoteUri().c_str()); + if (localDeviceId != runtime->deviceId) { + uri = file->GetRemoteUri(); + file->SetUri(uri); // cross dev, need dis path. + } } if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { return E_NO_PERMISSION; diff --git a/services/distributeddataservice/service/udmf/data_manager.h b/services/distributeddataservice/service/udmf/data_manager.h index 608d608c..1e1718c5 100755 --- a/services/distributeddataservice/service/udmf/data_manager.h +++ b/services/distributeddataservice/service/udmf/data_manager.h @@ -45,6 +45,7 @@ public: private: DataManager(); + bool IsFileType(UDType udType); int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); StoreCache storeCache_; std::map authorizationMap_; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp index 130ffa20..2e299617 100755 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -16,11 +16,12 @@ #include "preprocess_utils.h" #include - +#include "log_print.h" #include "error_code.h" #include "accesstoken_kit.h" #include "bundlemgr/bundle_mgr_client_impl.h" #include "ipc_skeleton.h" +#include "device_manager_adapter.h" namespace OHOS { namespace UDMF { @@ -44,10 +45,23 @@ int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption & runtime.createTime = GetTimeStamp(); runtime.sourcePackage = bundleName; runtime.createPackage = bundleName; + runtime.deviceId = GetLocalDeviceId(); data.SetRuntime(runtime); return E_OK; } +std::string PreProcessUtils::GetLocalDeviceId() +{ + auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice(); + + std::string encryptedUuid; + encryptedUuid = DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); + + ZLOGI("[LocalDevice] uuid:%{public}s, encryptedUuid:%{public}s, name:%{public}s, type:%{public}d", + info.uuid.c_str(), encryptedUuid.c_str(), info.deviceName.c_str(), info.deviceType); // if log uuid, need tb be anonymous; + return encryptedUuid; +} + std::string PreProcessUtils::IdGenerator() { std::random_device randomDevice; @@ -71,6 +85,16 @@ time_t PreProcessUtils::GetTimeStamp() return timestamp; } +int32_t PreProcessUtils::GetHapUidByToken(uint32_t tokenId) const +{ + HapTokenInfo tokenInfo; + auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo); + if (result != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { + ZLOGE("token:0x%{public}x, result:%{public}d", tokenId, result); + return -1; + } + return tokenInfo.userID; +} bool PreProcessUtils::GetHapBundleNameByToken(int tokenId, std::string &bundleName) { Security::AccessToken::HapTokenInfo hapInfo; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 175027ea..15c18cb3 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -30,8 +30,10 @@ public: static int32_t RuntimeDataImputation(UnifiedData &data, CustomOption &option); static std::string IdGenerator(); static time_t GetTimeStamp(); + static int32_t GetHapUidByToken(uint32_t tokenId); static bool GetHapBundleNameByToken(int tokenId, std::string &bundleName); static bool GetNativeProcessNameByToken(int tokenId, std::string &processName); + static std::string GetLocalDeviceId(); // uuid }; } // namespace UDMF } // namespace OHOS -- Gitee From 9e09915d111e42e187db864cecf5b8f32695a89e Mon Sep 17 00:00:00 2001 From: hanlu Date: Fri, 30 Jun 2023 15:34:50 +0800 Subject: [PATCH 303/437] f Signed-off-by: hanlu --- .../data_proxy/load_config_from_data_proxy_node_strategy.cpp | 3 ++- .../strategies/general/load_config_common_strategy.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp index 27f2780a..f8595c73 100644 --- a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp @@ -64,7 +64,8 @@ bool LoadConfigFromDataProxyNodeStrategy::operator()(std::shared_ptr co ZLOGI("access private data, caller and called is same, go"); return true; } - if (context->isAllowCrossPer) { + // cross permission can only cross uri like weather,can not cross like datashareproxy://weather + if (context->isAllowCrossPer && !URIUtils::IsDataProxyURI(context->uri)) { ZLOGI("access has white permission, go"); return true; } diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp index fd1f8d93..859bc436 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp @@ -33,6 +33,7 @@ bool LoadConfigCommonStrategy::operator()(std::shared_ptr context) if (context->currentUserId == 0) { URIUtils::GetInfoFromProxyURI( context->uri, context->currentUserId, context->callerTokenId, context->calledBundleName); + FormatUri(context->uri); } if (context->needAutoLoadCallerBundleName && context->callerBundleName.empty()) { Security::AccessToken::HapTokenInfo tokenInfo; @@ -43,13 +44,12 @@ bool LoadConfigCommonStrategy::operator()(std::shared_ptr context) } context->callerBundleName = tokenInfo.bundleName; } - FormatUri(context->uri); return true; } void LoadConfigCommonStrategy::FormatUri(std::string &uri) { - auto pos = uri.find('?'); + auto pos = uri.find_last_of('?'); if (pos == std::string::npos) { return; } -- Gitee From eedefe2aad318900c854fb5ed1dc9a5a3006e336 Mon Sep 17 00:00:00 2001 From: mazhao Date: Fri, 30 Jun 2023 15:41:18 +0800 Subject: [PATCH 304/437] delete useless log Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 5f5bcc06..86357c71 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -675,7 +675,6 @@ int JsonObject::DeleteItemOnTarget(const JsonFieldPath &path) cJSON *nodeFather = MoveToPath(cjson_, patherPath, caseSensitive_); if (nodeFather == nullptr) { - GLOGE("Delete item failed, json field path not found."); return -E_JSON_PATH_NOT_EXISTS; } @@ -708,7 +707,6 @@ int JsonObject::DeleteItemDeeplyOnTarget(const JsonFieldPath &path) cJSON *nodeFather = MoveToPath(cjson_, patherPath, caseSensitive_); if (nodeFather == nullptr) { - GLOGE("Delete item failed, json field path not found."); return -E_JSON_PATH_NOT_EXISTS; } -- Gitee From 7054f24fbc8b3db1680d13eb13462a66827b645b Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Fri, 30 Jun 2023 10:22:21 +0800 Subject: [PATCH 305/437] modify ipcamera build config Signed-off-by: ding_dong_dong --- bundle.json | 3 ++- datamgr_service.gni | 2 ++ .../distributeddataservice/service/test/fuzztest/BUILD.gn | 6 +++++- services/distributeddataservice/service/udmf/BUILD.gn | 5 ++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bundle.json b/bundle.json index ee085912..28674e17 100644 --- a/bundle.json +++ b/bundle.json @@ -39,7 +39,8 @@ "subsystem": "distributeddatamgr", "syscap": [], "features": [ - "datamgr_service_config" + "datamgr_service_config", + "datamgr_service_udmf" ], "adapted_system_type": [ "standard" diff --git a/datamgr_service.gni b/datamgr_service.gni index 5e1d91c6..708ee20e 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -51,4 +51,6 @@ declare_args() { } datamgr_service_config = true + + datamgr_service_udmf = false } diff --git a/services/distributeddataservice/service/test/fuzztest/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/BUILD.gn index 6152b951..133f732d 100644 --- a/services/distributeddataservice/service/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/BUILD.gn @@ -12,10 +12,14 @@ # limitations under the License. import("//build/ohos.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") ######################################################################################### group("fuzztest") { testonly = true - deps = [ "udmfservice_fuzzer:fuzztest" ] + deps = [] + if (datamgr_service_udmf) { + deps += [ "udmfservice_fuzzer:fuzztest" ] + } } diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index cfb32b79..4713e40d 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -14,7 +14,10 @@ import("//build/ohos.gni") import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") group("build_module") { - deps = [ ":udmf_server" ] + deps = [] + if (datamgr_service_udmf) { + deps += [ ":udmf_server" ] + } } config("module_public_config") { -- Gitee From 90147aa06ae705876e820a24fbf7ad94c7f6637d Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Fri, 30 Jun 2023 18:16:30 +0800 Subject: [PATCH 306/437] fix flag convert Signed-off-by: wanghuajian --- services/distributeddataservice/service/rdb/value_proxy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 7affb81e..249259ca 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -125,7 +125,7 @@ ValueProxy::Asset::Asset(NativeRdb::AssetValue asset) asset_ = DistributedData::Asset { .version = asset.version, .status = asset.status, .expiresTime = asset.expiresTime, - .id = asset.id, + .id = std::move(asset.id), .name = std::move(asset.name), .uri = std::move(asset.uri), .createTime = std::move(asset.createTime), @@ -209,7 +209,7 @@ uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asse return DistributedData::Asset::STATUS_DOWNLOADING; } else if (asset.status == DistributedDB::AssetStatus::ABNORMAL) { return DistributedData::Asset::STATUS_ABNORMAL; - } else if (asset.status == DistributedDB::AssetStatus::NORMAL) { + } else { switch (asset.flag) { case static_cast(DistributedDB::AssetOpType::INSERT): return DistributedData::Asset::STATUS_INSERT; -- Gitee From e751ff4290a647a3a207287cbb24ba2a9b65727b Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Fri, 30 Jun 2023 19:44:25 +0800 Subject: [PATCH 307/437] =?UTF-8?q?=E5=BE=AE=E7=A7=92=E7=BB=9F=E4=B8=80ms?= =?UTF-8?q?=20Signed-off-by:=20zuojiangjiang=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/cloud/cloud_service_impl.cpp | 4 ++-- .../distributeddataservice/service/cloud/cloud_service_impl.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 547ed074..1806d194 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -435,11 +435,11 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) auto &dbs = enabled ? subDbs : unsubDbs; auto it = sub.expiresTime.find(bundle); // cloud is enabled, but the subscription won't expire - if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count()))) { + if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count() / TO_MS))) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. - if (!enabled && (it == sub.expiresTime.end() || it->second <= static_cast(offThreshold.count()))) { + if (!enabled && (it == sub.expiresTime.end() || it->second <= static_cast(offThreshold.count() / TO_MS))) { continue; } diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 554d8301..2b1311f9 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -66,6 +66,7 @@ private: static constexpr int32_t RETRY_TIMES = 10; static constexpr int32_t RETRY_INTERVAL = 30; static constexpr int32_t EXPIRE_INTERVAL = 7 * 24; // 7 day + static constexpr int32_t TO_MS = 1000; bool UpdateCloudInfo(int32_t user); bool UpdateSchema(int32_t user); -- Gitee From f527aae06f8c58dd9d64e98e540d762342a27eaf Mon Sep 17 00:00:00 2001 From: ylq121 Date: Fri, 30 Jun 2023 22:09:45 +0800 Subject: [PATCH 308/437] xiugai Signed-off-by: ylq121 --- .../framework/include/store/general_store.h | 8 ++ .../service/cloud/cloud_service_impl.cpp | 75 ++++++++++++++++--- .../service/cloud/cloud_service_impl.h | 1 + .../service/cloud/sync_manager.cpp | 13 ++-- .../service/cloud/sync_manager.h | 6 +- .../service/rdb/rdb_general_store.cpp | 16 ++++ .../service/rdb/rdb_general_store.h | 1 + 7 files changed, 100 insertions(+), 20 deletions(-) diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 0ee2012a..f41fc9d9 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -43,6 +43,12 @@ public: CLOUD_END, MODE_BUTT = CLOUD_END, }; + enum CleanMode { + NEARBY_DATA, + CLOUD_DATA, + CLOUD_INFO, + LOCAL_DATA, + }; struct BindInfo { BindInfo(std::shared_ptr db = nullptr, std::shared_ptr loader = nullptr) @@ -72,6 +78,8 @@ public: virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) = 0; + virtual int32_t Clean(const std::vector &device, int32_t mode) = 0; + virtual int32_t Watch(int32_t origin, Watcher &watcher) = 0; virtual int32_t Unwatch(int32_t origin, Watcher &watcher) = 0; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 547ed074..f0b72926 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -16,7 +16,7 @@ #define LOG_TAG "CloudServiceImpl" #include "cloud_service_impl.h" - +#include "accesstoken_kit.h" #include "account/account_delegate.h" #include "checker/checker_manager.h" #include "cloud/cloud_server.h" @@ -29,10 +29,12 @@ #include "runtime_config.h" #include "store/auto_cache.h" #include "utils/anonymous.h" +#include "sync_manager.h" namespace OHOS::CloudData { using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using Account = OHOS::DistributedKv::AccountDelegate; +using AccessTokenKit = Security::AccessToken::AccessTokenKit; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; const CloudServiceImpl::Work CloudServiceImpl::HANDLERS[WORK_BUTT] = { &CloudServiceImpl::DoSubscribe, @@ -122,14 +124,8 @@ int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::stri return SUCCESS; } -int32_t CloudServiceImpl::Clean(const std::string &id, const std::map &actions) +int32_t CloudServiceImpl::DoClean(CloudInfo &cloudInfo, const std::map &actions) { - CloudInfo cloudInfo; - auto tokenId = IPCSkeleton::GetCallingTokenID(); - cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); - if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS) { - return ERROR; - } syncManager_.StopCloudSync(cloudInfo.user); auto keys = cloudInfo.GetSchemaKey(); for (const auto &[bundle, action] : actions) { @@ -137,13 +133,61 @@ int32_t CloudServiceImpl::Clean(const std::string &id, const std::mapClean({}, action); + if (status != E_OK) { + ZLOGD("remove device data status:%{public}d, storeId:%{public}s", status, meta.GetStoreAlias().c_str()); + return ERROR; + } } } return SUCCESS; } +int32_t CloudServiceImpl::Clean(const std::string &id, const std::map &actions) +{ + CloudInfo cloudInfo; + auto tokenId = IPCSkeleton::GetCallingTokenID(); + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); + if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS) { + return ERROR; + } + if (id != cloudInfo.id) { + ZLOGE("different id, [server] id:%{public}s, [meta] id:%{public}s", Anonymous::Change(cloudInfo.id).c_str(), + Anonymous::Change(id).c_str()); + } + auto status = DoClean(cloudInfo, actions); + return status; +} + int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::string &bundleName) { CloudInfo cloudInfo; @@ -254,14 +298,21 @@ bool CloudServiceImpl::UpdateCloudInfo(int32_t user) return true; } if (oldInfo.id != cloudInfo.id) { - ZLOGE("different id, [server] id:%{public}s, [meta] id:%{public}s", - Anonymous::Change(cloudInfo.id).c_str(), Anonymous::Change(oldInfo.id).c_str()); + ZLOGE("different id, [server] id:%{public}s, [meta] id:%{public}s", Anonymous::Change(cloudInfo.id).c_str(), + Anonymous::Change(oldInfo.id).c_str()); std::map actions; for (auto &[bundle, app] : cloudInfo.apps) { actions[bundle] = CLEAR_CLOUD_INFO; } + DoClean(oldInfo, actions); + } + if (cloudInfo.enableCloud) { + for (auto &[bundle, app] : cloudInfo.apps) { + if (app.cloudSwitch == true && oldInfo.apps[bundle].cloudSwitch == false) { + syncManager_.DoCloudSync({ cloudInfo.user, bundle }); + } + } } - MetaDataManager::GetInstance().SaveMeta(cloudInfo.GetKey(), cloudInfo, true); return true; } diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 554d8301..31599142 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -80,6 +80,7 @@ private: ExecutorPool::Task GenTask(int32_t retry, int32_t user, AsyncWork work); void Execute(Tasks tasks); bool DoSubscribe(int32_t user); + int32_t DoClean(CloudInfo &cloudInfo, const std::map &actions); std::shared_ptr executor_; SyncManager syncManager_; static const Work HANDLERS[WORK_BUTT]; diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 0ca92183..8bc0025d 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -329,7 +329,7 @@ void SyncManager::UpdateSchema(const SyncManager::SyncInfo &syncInfo) EventCenter::GetInstance().PostEvent(std::make_unique(CloudEvent::GET_SCHEMA, storeInfo)); } -AutoCache::Store SyncManager::GetStore(const StoreMetaData &meta, int32_t user) +AutoCache::Store SyncManager::GetStore(const StoreMetaData &meta, int32_t user, bool mustBind) { auto instance = CloudServer::GetInstance(); if (instance == nullptr) { @@ -356,12 +356,15 @@ AutoCache::Store SyncManager::GetStore(const StoreMetaData &meta, int32_t user) auto dbMeta = schemaMeta.GetDataBase(meta.storeId); auto cloudDB = instance->ConnectCloudDB(meta.tokenId, dbMeta); auto assetLoader = instance->ConnectAssetLoader(meta.tokenId, dbMeta); - if (cloudDB == nullptr || assetLoader == nullptr) { - ZLOGE("failed, no cloud DB <0x%{public}x %{public}s<->%{public}s>", meta.tokenId, - dbMeta.name.c_str(), dbMeta.alias.c_str()); + if (mustBind && (cloudDB == nullptr || assetLoader == nullptr)) { + ZLOGE("failed, no cloud DB <0x%{public}x %{public}s<->%{public}s>", meta.tokenId, dbMeta.name.c_str(), + dbMeta.alias.c_str()); return nullptr; } - store->Bind(dbMeta, { std::move(cloudDB), std::move(assetLoader) }); + + if (cloudDB != nullptr || assetLoader != nullptr) { + store->Bind(dbMeta, { std::move(cloudDB), std::move(assetLoader) }); + } } return store; } diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index 3f1b4546..f0b8fd60 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -29,6 +29,8 @@ public: using GenStore = DistributedData::GeneralStore; using GenQuery = DistributedData::GenQuery; using RefCount = DistributedData::RefCount; + using AutoCache = DistributedData::AutoCache; + using StoreMetaData = DistributedData::StoreMetaData; class SyncInfo final { public: using Store = std::string; @@ -44,6 +46,7 @@ public: void SetQuery(std::shared_ptr query); void SetError(int32_t code) const; std::shared_ptr GenerateQuery(const std::string &store, const Tables &tables); + static AutoCache::Store GetStore(const StoreMetaData &meta, int32_t user, bool mustBind = false); inline static constexpr const char *DEFAULT_ID = "default"; private: @@ -68,9 +71,7 @@ private: using Event = DistributedData::Event; using Task = ExecutorPool::Task; using TaskId = ExecutorPool::TaskId; - using AutoCache = DistributedData::AutoCache; using Duration = ExecutorPool::Duration; - using StoreMetaData = DistributedData::StoreMetaData; using Retryer = std::function; static constexpr ExecutorPool::Duration RETRY_INTERVAL = std::chrono::seconds(10); // second @@ -85,7 +86,6 @@ private: std::function GetSyncHandler(Retryer retryer); std::function GetClientChangeHandler(); Retryer GetRetryer(int32_t times, const SyncInfo &syncInfo); - static AutoCache::Store GetStore(const StoreMetaData &meta, int32_t user); static uint64_t GenerateId(int32_t user); RefCount GenSyncRef(uint64_t syncId); int32_t Compare(uint64_t syncId, int32_t user); diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index daa4be49..dfe18696 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -35,6 +35,7 @@ using namespace NativeRdb; using DBField = DistributedDB::Field; using DBTable = DistributedDB::TableSchema; using DBSchema = DistributedDB::DataBaseSchema; +using ClearMode = DistributedDB::ClearMode; class RdbOpenCallbackImpl : public RdbOpenCallback { public: int OnCreate(RdbStore &rdbStore) override @@ -193,6 +194,21 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } +int32_t RdbGeneralStore::Clean(const std::vector &device, int32_t mode) +{ + if (mode < 0 || mode > 1) { + return GeneralError::E_INVALID_ARGS; + } + int32_t dbMode; + if (mode == CLOUD_INFO) { + dbMode = CleanMode::CLOUD_INFO; + } else { + dbMode = CleanMode::CLOUD_DATA; + } + auto status = delegate_->RemoveDeviceData(device, static_cast(dbMode)); + return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; +} + int32_t RdbGeneralStore::Watch(int32_t origin, Watcher &watcher) { if (origin != Watcher::Origin::ORIGIN_ALL || observer_.watcher_ != nullptr) { diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 2a27c83a..4e408600 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -49,6 +49,7 @@ public: std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, GenQuery &query) override; int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) override; + int32_t Clean(const std::vector &device, int32_t mode) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; int32_t Close() override; -- Gitee From 00826a238fae866d40ffe21d7b3cf533474129aa Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sat, 1 Jul 2023 09:09:36 +0800 Subject: [PATCH 309/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 1806d194..4a55e73e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -435,11 +435,13 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) auto &dbs = enabled ? subDbs : unsubDbs; auto it = sub.expiresTime.find(bundle); // cloud is enabled, but the subscription won't expire - if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count() / TO_MS))) { + if (enabled && (it != sub.expiresTime.end() && + it->second >= static_cast(onThreshold.count() / TO_MS))) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. - if (!enabled && (it == sub.expiresTime.end() || it->second <= static_cast(offThreshold.count() / TO_MS))) { + if (!enabled && (it == sub.expiresTime.end() || + it->second <= static_cast(offThreshold.count() / TO_MS))) { continue; } -- Gitee From 27fab5edb49e7acfc238c5bb7fab7287d2cbd66a Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Fri, 30 Jun 2023 18:30:24 +0800 Subject: [PATCH 310/437] modify bundle.json build config Signed-off-by: ding_dong_dong --- bundle.json | 9 +++------ .../distributeddataservice/adapter/broadcaster/BUILD.gn | 1 - .../distributeddataservice/app/src/uninstaller/BUILD.gn | 4 +--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/bundle.json b/bundle.json index ee085912..0e5b563a 100644 --- a/bundle.json +++ b/bundle.json @@ -55,7 +55,6 @@ "ability_runtime", "access_token", "bundle_framework", - "common", "common_event_service", "c_utils", "dataclassification", @@ -63,11 +62,10 @@ "device_auth", "device_manager", "dsoftbus", + "hilog", "hisysevent", "hitrace", - "hilog", "huks", - "init", "kv_store", "ipc", "napi", @@ -79,11 +77,10 @@ ], "third_party": [ "cjson", + "jsoncpp", + "libuv", "openssl", "sqlite", - "libuv", - "libz", - "jsoncpp", "zlib" ] }, diff --git a/services/distributeddataservice/adapter/broadcaster/BUILD.gn b/services/distributeddataservice/adapter/broadcaster/BUILD.gn index 550fb44e..472bef0c 100755 --- a/services/distributeddataservice/adapter/broadcaster/BUILD.gn +++ b/services/distributeddataservice/adapter/broadcaster/BUILD.gn @@ -30,7 +30,6 @@ ohos_static_library("distributeddata_broadcaster_static") { cflags_cc = [ "-fvisibility=hidden" ] external_deps = [ - # "ces:libcommonevent", "ability_base:base", "ability_base:want", "bundle_framework:appexecfwk_base", diff --git a/services/distributeddataservice/app/src/uninstaller/BUILD.gn b/services/distributeddataservice/app/src/uninstaller/BUILD.gn index d59a8144..54196c83 100755 --- a/services/distributeddataservice/app/src/uninstaller/BUILD.gn +++ b/services/distributeddataservice/app/src/uninstaller/BUILD.gn @@ -42,11 +42,9 @@ ohos_static_library("distributeddata_uninstaller_static") { ] external_deps = [ + "ability_base:want", "bundle_framework:appexecfwk_base", "c_utils:utils", - - # "ces:libcommonevent", - "ability_base:want", "common_event_service:cesfwk_innerkits", "dataclassification:data_transit_mgr", "hilog:libhilog", -- Gitee From fc2006f87a535a07d47a32147e9e6814b8fbd944 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 1 Jul 2023 10:39:43 +0800 Subject: [PATCH 311/437] xiugai Signed-off-by: ylq121 --- .../framework/include/store/general_store.h | 2 +- .../service/rdb/rdb_general_store.cpp | 10 +++++++++- .../service/rdb/rdb_general_store.h | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index f41fc9d9..1fd399c4 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -78,7 +78,7 @@ public: virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) = 0; - virtual int32_t Clean(const std::vector &device, int32_t mode) = 0; + virtual int32_t Clean(const std::vector &devices, int32_t mode) = 0; virtual int32_t Watch(int32_t origin, Watcher &watcher) = 0; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index dfe18696..c841117b 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -36,6 +36,7 @@ using DBField = DistributedDB::Field; using DBTable = DistributedDB::TableSchema; using DBSchema = DistributedDB::DataBaseSchema; using ClearMode = DistributedDB::ClearMode; +using DBStatus = DistributedDB::DBStatus; class RdbOpenCallbackImpl : public RdbOpenCallback { public: int OnCreate(RdbStore &rdbStore) override @@ -205,7 +206,14 @@ int32_t RdbGeneralStore::Clean(const std::vector &device, int32_t m } else { dbMode = CleanMode::CLOUD_DATA; } - auto status = delegate_->RemoveDeviceData(device, static_cast(dbMode)); + DBStatus status; + if (devices.size() == 0) { + status = delegate_->RemoveDeviceData("", static_cast(dbMode)); + return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; + } + for (auto device : devices) { + status = delegate_->RemoveDeviceData("", static_cast(dbMode)); + } return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 4e408600..053f9bc7 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -49,7 +49,7 @@ public: std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, GenQuery &query) override; int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) override; - int32_t Clean(const std::vector &device, int32_t mode) override; + int32_t Clean(const std::vector &devices, int32_t mode) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; int32_t Close() override; -- Gitee From 8f80938bbf24a030b07ba4b1b81e01365255783d Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 1 Jul 2023 11:00:01 +0800 Subject: [PATCH 312/437] xiugai2 Signed-off-by: ylq121 --- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index c841117b..0ee00a7c 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -14,7 +14,7 @@ */ #define LOG_TAG "RdbGeneralStore" #include "rdb_general_store.h" - +#include "cloud_service.h" #include "cloud/asset_loader.h" #include "cloud/cloud_db.h" #include "cloud/schema_meta.h" @@ -32,6 +32,7 @@ namespace OHOS::DistributedRdb { using namespace DistributedData; using namespace DistributedDB; using namespace NativeRdb; +using namespace CloudData; using DBField = DistributedDB::Field; using DBTable = DistributedDB::TableSchema; using DBSchema = DistributedDB::DataBaseSchema; @@ -201,7 +202,7 @@ int32_t RdbGeneralStore::Clean(const std::vector &device, int32_t m return GeneralError::E_INVALID_ARGS; } int32_t dbMode; - if (mode == CLOUD_INFO) { + if (mode == CloudService::CLEAR_CLOUD_INFO) { dbMode = CleanMode::CLOUD_INFO; } else { dbMode = CleanMode::CLOUD_DATA; -- Gitee From 7a480a2028994a712a8ea09a9c6d1f9fac55c69f Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sat, 1 Jul 2023 11:32:04 +0800 Subject: [PATCH 313/437] update .h Signed-off-by: wangdengze --- .../service/object/object_callback_proxy.cpp | 16 ++++++++++++---- .../service/rdb/rdb_notifier_proxy.cpp | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/object/object_callback_proxy.cpp b/services/distributeddataservice/service/object/object_callback_proxy.cpp index 0eb7942b..17989ec0 100644 --- a/services/distributeddataservice/service/object/object_callback_proxy.cpp +++ b/services/distributeddataservice/service/object/object_callback_proxy.cpp @@ -55,7 +55,9 @@ void ObjectSaveCallbackProxy::Completed(const std::map &re return; } MessageOption mo { MessageOption::TF_SYNC }; - int error = Remote()->SendRequest(COMPLETED, data, reply, mo); + int error = Remote()->SendRequest( + static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), + data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } @@ -74,7 +76,9 @@ void ObjectRevokeSaveCallbackProxy::Completed(int32_t status) return; } MessageOption mo { MessageOption::TF_SYNC }; - int error = Remote()->SendRequest(COMPLETED, data, reply, mo); + int error = Remote()->SendRequest( + static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), + data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } @@ -93,7 +97,9 @@ void ObjectRetrieveCallbackProxy::Completed(const std::mapSendRequest(COMPLETED, data, reply, mo); + int error = Remote()->SendRequest( + static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED, + data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } @@ -112,7 +118,9 @@ void ObjectChangeCallbackProxy::Completed(const std::mapSendRequest(COMPLETED, data, reply, mo); + int error = Remote()->SendRequest( + static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED, + data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index 92aee4fa..6041f4ad 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -40,7 +40,9 @@ int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, Details &&result) MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); - if (Remote()->SendRequest(RDB_NOTIFIER_CMD_SYNC_COMPLETE, data, reply, option) != 0) { + if (Remote()->SendRequest( + static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_SYNC_COMPLETE, + data, reply, option) != 0) { ZLOGE("send request failed"); return RDB_ERROR; } @@ -61,7 +63,9 @@ int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &pr MessageParcel reply; MessageOption option; - if (Remote()->SendRequest(RDB_NOTIFIER_CMD_DATA_CHANGE, data, reply, option) != 0) { + if (Remote()->SendRequest( + static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_DATA_CHANGE, + data, reply, option) != 0) { ZLOGE("send request failed"); return RDB_ERROR; } -- Gitee From 9e6496e799244eb6379e8ba16e14124fabdb4aff Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 1 Jul 2023 11:35:30 +0800 Subject: [PATCH 314/437] xiugai3 Signed-off-by: ylq121 --- .../service/cloud/cloud_service_impl.cpp | 4 ++-- .../distributeddataservice/service/cloud/sync_manager.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index f0b72926..98c6d24e 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -153,9 +153,9 @@ int32_t CloudServiceImpl::DoClean(CloudInfo &cloudInfo, const std::map%{public}s>", meta.tokenId, dbMeta.name.c_str(), dbMeta.alias.c_str()); - return nullptr; + return store; } if (cloudDB != nullptr || assetLoader != nullptr) { -- Gitee From 05a6cd47e4065cbb0ba440b70a034b5823c80ecd Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sat, 1 Jul 2023 05:12:49 +0000 Subject: [PATCH 315/437] update services/distributeddataservice/service/object/object_callback_proxy.cpp. Signed-off-by: wangdengze --- .../service/object/object_callback_proxy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/object/object_callback_proxy.cpp b/services/distributeddataservice/service/object/object_callback_proxy.cpp index 17989ec0..95415af7 100644 --- a/services/distributeddataservice/service/object/object_callback_proxy.cpp +++ b/services/distributeddataservice/service/object/object_callback_proxy.cpp @@ -98,7 +98,7 @@ void ObjectRetrieveCallbackProxy::Completed(const std::mapSendRequest( - static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED, + static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); @@ -119,7 +119,7 @@ void ObjectChangeCallbackProxy::Completed(const std::mapSendRequest( - static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED, + static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); -- Gitee From 36c2d4c710c18df77e8131268ca43991de7dbc16 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sat, 1 Jul 2023 05:13:39 +0000 Subject: [PATCH 316/437] update services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp. Signed-off-by: wangdengze --- .../distributeddataservice/service/rdb/rdb_notifier_proxy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index 6041f4ad..50564dbb 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -41,7 +41,7 @@ int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, Details &&result) MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); if (Remote()->SendRequest( - static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_SYNC_COMPLETE, + static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_SYNC_COMPLETE), data, reply, option) != 0) { ZLOGE("send request failed"); return RDB_ERROR; @@ -64,7 +64,7 @@ int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &pr MessageParcel reply; MessageOption option; if (Remote()->SendRequest( - static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_DATA_CHANGE, + static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_DATA_CHANGE), data, reply, option) != 0) { ZLOGE("send request failed"); return RDB_ERROR; -- Gitee From 98687f800a4c2c4da2426f84ca153b1cad0b83be Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 1 Jul 2023 14:27:10 +0800 Subject: [PATCH 317/437] xiugai Signed-off-by: ylq121 --- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 0ee00a7c..96f9fb25 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -196,7 +196,7 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } -int32_t RdbGeneralStore::Clean(const std::vector &device, int32_t mode) +int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t mode) { if (mode < 0 || mode > 1) { return GeneralError::E_INVALID_ARGS; -- Gitee From ab0238cbf4e2996b762451c7d606fd49c671ec84 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 1 Jul 2023 15:27:20 +0800 Subject: [PATCH 318/437] xiugai Signed-off-by: ylq121 --- .../service/cloud/cloud_service_impl.cpp | 4 ++-- services/distributeddataservice/service/cloud/sync_manager.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 98c6d24e..f35101ef 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -153,9 +153,9 @@ int32_t CloudServiceImpl::DoClean(CloudInfo &cloudInfo, const std::map query); void SetError(int32_t code) const; std::shared_ptr GenerateQuery(const std::string &store, const Tables &tables); - static AutoCache::Store GetStore(const StoreMetaData &meta, int32_t user, bool mustBind = false); inline static constexpr const char *DEFAULT_ID = "default"; private: -- Gitee From 096bf3d9ba6b3f8b45695c762edc7bc333340633 Mon Sep 17 00:00:00 2001 From: mazhao Date: Sat, 1 Jul 2023 15:39:56 +0800 Subject: [PATCH 319/437] Optimize the clipping function Signed-off-by: mazhao --- .../gaussdb_rd/src/interface/src/projection_tree.cpp | 6 +++--- .../data_share/gaussdb_rd/src/interface/src/result_set.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp index 5c37b84b..4ab699c3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -58,11 +58,11 @@ bool ProjectionTree::SearchTree(std::vector &singlePath, size_t &in { ProjectionNode *node = &node_; for (size_t i = 0; i < singlePath.size(); i++) { - if (node->isDeepest) { - index = i; - } if (node->sonNode[singlePath[i]] != nullptr) { node = node->sonNode[singlePath[i]]; + if (node->isDeepest) { + index = i + 1; + } } else { return false; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 08b51c3b..7c6ea6e1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -194,10 +194,12 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat while (!nodeInstance.IsNull()) { singlePath.emplace_back(nodeInstance.GetItemField()); size_t index = 0; - if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { + if ((nodeInstance.GetType() == JsonObject::Type::JSON_ARRAY && + context_->projectionTree.SearchTree(singlePath, index) && index == 0) || + (!context_->projectionTree.SearchTree(singlePath, index) && index == 0)) { allCutPath.emplace_back(singlePath); } - if (!nodeInstance.GetChild().IsNull()) { + if (nodeInstance.GetType() != JsonObject::Type::JSON_ARRAY && !nodeInstance.GetChild().IsNull()) { JsonObject nodeChiled = nodeInstance.GetChild(); CheckCutNode(&nodeChiled, singlePath, allCutPath); } @@ -206,6 +208,7 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat } return E_OK; } + int ResultSet::CutJsonBranch(std::string &jsonData) { int errCode; -- Gitee From b06908430df145d16e8a290520064afd376dac72 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 1 Jul 2023 15:50:21 +0800 Subject: [PATCH 320/437] xiugai Signed-off-by: ylq121 --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index f35101ef..d94e68c3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -136,7 +136,6 @@ int32_t CloudServiceImpl::DoClean(CloudInfo &cloudInfo, const std::map Date: Sat, 1 Jul 2023 17:46:15 +0800 Subject: [PATCH 321/437] fix code check Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/interface/src/result_set.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 7c6ea6e1..225a8bc8 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -194,9 +194,9 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat while (!nodeInstance.IsNull()) { singlePath.emplace_back(nodeInstance.GetItemField()); size_t index = 0; - if ((nodeInstance.GetType() == JsonObject::Type::JSON_ARRAY && - context_->projectionTree.SearchTree(singlePath, index) && index == 0) || - (!context_->projectionTree.SearchTree(singlePath, index) && index == 0)) { + bool isMatch = context_->projectionTree.SearchTree(singlePath, index); + if ((nodeInstance.GetType() == JsonObject::Type::JSON_ARRAY && isMatch && index == 0) || + (!isMatch && index == 0)) { allCutPath.emplace_back(singlePath); } if (nodeInstance.GetType() != JsonObject::Type::JSON_ARRAY && !nodeInstance.GetChild().IsNull()) { -- Gitee From 188af85c4384174d02b4e5a73a94ca6645f1d2a5 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sat, 1 Jul 2023 18:06:05 +0800 Subject: [PATCH 322/437] xiugai Signed-off-by: ylq121 --- .../framework/include/store/general_store.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 1fd399c4..a66ef179 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -44,7 +44,7 @@ public: MODE_BUTT = CLOUD_END, }; enum CleanMode { - NEARBY_DATA, + NEARBY_DATA = 0, CLOUD_DATA, CLOUD_INFO, LOCAL_DATA, -- Gitee From 2beda53744efd4c4095c00cffbde43a0e25cc848 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sat, 1 Jul 2023 22:30:38 +0800 Subject: [PATCH 323/437] getmodifytime Signed-off-by: zuojiangjiang --- .../framework/include/store/general_watcher.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/framework/include/store/general_watcher.h b/services/distributeddataservice/framework/include/store/general_watcher.h index db0cde87..bcf226d6 100644 --- a/services/distributeddataservice/framework/include/store/general_watcher.h +++ b/services/distributeddataservice/framework/include/store/general_watcher.h @@ -49,7 +49,7 @@ public: OP_BUTT, }; // PK primary key - using PRIValue = std::variant; + using PRIValue = std::variant; using PRIFields = std::map; using ChangeInfo = std::map[OP_BUTT]>; virtual ~GeneralWatcher() = default; -- Gitee From 50541bb53f7fdd5300a5e0c4dc8a5235b1c61133 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sun, 2 Jul 2023 14:42:44 +0800 Subject: [PATCH 324/437] xiugai Signed-off-by: ylq121 --- .../service/cloud/cloud_service_impl.cpp | 22 ++++++++----------- .../service/cloud/sync_manager.cpp | 2 +- .../service/cloud/sync_manager.h | 2 +- .../service/rdb/rdb_general_store.cpp | 18 ++++++++++----- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index d94e68c3..c2e06d12 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -134,9 +134,11 @@ int32_t CloudServiceImpl::DoClean(CloudInfo &cloudInfo, const std::mapClean({}, action); if (status != E_OK) { - ZLOGD("remove device data status:%{public}d, storeId:%{public}s", status, meta.GetStoreAlias().c_str()); - return ERROR; + ZLOGE("remove device data status:%{public}d, storeId:%{public}s", status, meta.GetStoreAlias().c_str()); + continue; } } } @@ -177,14 +173,14 @@ int32_t CloudServiceImpl::Clean(const std::string &id, const std::mapGetUserByToken(tokenId); if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS) { + ZLOGE("get cloud meta failed user:%{public}d", static_cast(cloudInfo.user)); return ERROR; } if (id != cloudInfo.id) { ZLOGE("different id, [server] id:%{public}s, [meta] id:%{public}s", Anonymous::Change(cloudInfo.id).c_str(), Anonymous::Change(id).c_str()); } - auto status = DoClean(cloudInfo, actions); - return status; + return DoClean(cloudInfo, actions); } int32_t CloudServiceImpl::NotifyDataChange(const std::string &id, const std::string &bundleName) @@ -307,7 +303,7 @@ bool CloudServiceImpl::UpdateCloudInfo(int32_t user) } if (cloudInfo.enableCloud) { for (auto &[bundle, app] : cloudInfo.apps) { - if (app.cloudSwitch == true && oldInfo.apps[bundle].cloudSwitch == false) { + if (app.cloudSwitch && !oldInfo.apps[bundle].cloudSwitch) { syncManager_.DoCloudSync({ cloudInfo.user, bundle }); } } diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index ee6723a5..8bc0025d 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -359,7 +359,7 @@ AutoCache::Store SyncManager::GetStore(const StoreMetaData &meta, int32_t user, if (mustBind && (cloudDB == nullptr || assetLoader == nullptr)) { ZLOGE("failed, no cloud DB <0x%{public}x %{public}s<->%{public}s>", meta.tokenId, dbMeta.name.c_str(), dbMeta.alias.c_str()); - return store; + return nullptr; } if (cloudDB != nullptr || assetLoader != nullptr) { diff --git a/services/distributeddataservice/service/cloud/sync_manager.h b/services/distributeddataservice/service/cloud/sync_manager.h index 3a085d6f..5f19611d 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.h +++ b/services/distributeddataservice/service/cloud/sync_manager.h @@ -31,7 +31,7 @@ public: using RefCount = DistributedData::RefCount; using AutoCache = DistributedData::AutoCache; using StoreMetaData = DistributedData::StoreMetaData; - static AutoCache::Store GetStore(const StoreMetaData &meta, int32_t user, bool mustBind = false); + static AutoCache::Store GetStore(const StoreMetaData &meta, int32_t user, bool mustBind = true); class SyncInfo final { public: using Store = std::string; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 96f9fb25..5468a8e3 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -198,14 +198,20 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t mode) { - if (mode < 0 || mode > 1) { + if (mode < CloudService::CLEAR_CLOUD_INFO || mode > CloudService::CLEAR_CLOUD_BUTT) { return GeneralError::E_INVALID_ARGS; } int32_t dbMode; - if (mode == CloudService::CLEAR_CLOUD_INFO) { - dbMode = CleanMode::CLOUD_INFO; - } else { - dbMode = CleanMode::CLOUD_DATA; + switch (mode) { + case CloudService::CLEAR_CLOUD_INFO: + dbMode = CleanMode::CLOUD_INFO; + break; + case CloudService::CLEAR_CLOUD_DATA_AND_INFO: + dbMode = CleanMode::CLOUD_DATA; + break; + default: + dbMode = CleanMode::LOCAL_DATA; + break; } DBStatus status; if (devices.size() == 0) { @@ -213,7 +219,7 @@ int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } for (auto device : devices) { - status = delegate_->RemoveDeviceData("", static_cast(dbMode)); + status = delegate_->RemoveDeviceData(device, static_cast(dbMode)); } return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } -- Gitee From b4d7f9d33efaf6652e6e187075ffd7e34a3eba06 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sun, 2 Jul 2023 15:09:05 +0800 Subject: [PATCH 325/437] xiugai Signed-off-by: ylq121 --- .../framework/include/store/general_store.h | 2 +- .../service/cloud/cloud_service_impl.cpp | 6 +++-- .../service/rdb/rdb_general_store.cpp | 22 ++++++++++--------- .../service/rdb/rdb_general_store.h | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index a66ef179..0da33a6e 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -78,7 +78,7 @@ public: virtual int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) = 0; - virtual int32_t Clean(const std::vector &devices, int32_t mode) = 0; + virtual int32_t Clean(const std::vector &devices, int32_t mode, const std::string &tableName) = 0; virtual int32_t Watch(int32_t origin, Watcher &watcher) = 0; diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index c2e06d12..b8f5e1a3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -157,9 +157,11 @@ int32_t CloudServiceImpl::DoClean(CloudInfo &cloudInfo, const std::mapClean({}, action); + auto status = store->Clean({}, action, ""); if (status != E_OK) { - ZLOGE("remove device data status:%{public}d, storeId:%{public}s", status, meta.GetStoreAlias().c_str()); + ZLOGW("remove device data status:%{public}d, user:%{pubilc}d, bundleName:%{public}s, " + "storeId:%{public}s", + status, static_cast(cloudInfo.user), meta.bundleName.c_str(), meta.GetStoreAlias().c_str()); continue; } } diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 5468a8e3..b7e833ef 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -198,29 +198,31 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t mode) { - if (mode < CloudService::CLEAR_CLOUD_INFO || mode > CloudService::CLEAR_CLOUD_BUTT) { + if (mode < 0 || mode > CloudService::CLEAR_CLOUD_BUTT) { return GeneralError::E_INVALID_ARGS; } int32_t dbMode; + DBStatus status; switch (mode) { case CloudService::CLEAR_CLOUD_INFO: dbMode = CleanMode::CLOUD_INFO; + status = delegate_->RemoveDeviceData("", static_cast(dbMode)); break; case CloudService::CLEAR_CLOUD_DATA_AND_INFO: dbMode = CleanMode::CLOUD_DATA; + status = delegate_->RemoveDeviceData("", static_cast(dbMode)); break; default: - dbMode = CleanMode::LOCAL_DATA; + if (devices.empty()) { + delegate_->RemoveDeviceData(); + break; + } + + for (auto device : devices) { + status = delegate_->RemoveDeviceData(device, tableName); + } break; } - DBStatus status; - if (devices.size() == 0) { - status = delegate_->RemoveDeviceData("", static_cast(dbMode)); - return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; - } - for (auto device : devices) { - status = delegate_->RemoveDeviceData(device, static_cast(dbMode)); - } return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 053f9bc7..3213be87 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -49,7 +49,7 @@ public: std::shared_ptr Query(const std::string &table, const std::string &sql, Values &&args) override; std::shared_ptr Query(const std::string &table, GenQuery &query) override; int32_t Sync(const Devices &devices, int32_t mode, GenQuery &query, DetailAsync async, int32_t wait) override; - int32_t Clean(const std::vector &devices, int32_t mode) override; + int32_t Clean(const std::vector &devices, int32_t mode, const std::string &tableName) override; int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; int32_t Close() override; -- Gitee From a2ce3d5f49d3625d848fc9a0cf8cdf8fc336e106 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sun, 2 Jul 2023 16:00:39 +0800 Subject: [PATCH 326/437] xiugai Signed-off-by: ylq121 --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index b8f5e1a3..9473ca20 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -137,7 +137,6 @@ int32_t CloudServiceImpl::DoClean(CloudInfo &cloudInfo, const std::map Date: Sun, 2 Jul 2023 16:05:51 +0800 Subject: [PATCH 327/437] xiugai Signed-off-by: ylq121 --- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index b7e833ef..951cc4fe 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -196,7 +196,7 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu return status == DistributedDB::OK ? GeneralError::E_OK : GeneralError::E_ERROR; } -int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t mode) +int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t mode, const std::string &tableName) { if (mode < 0 || mode > CloudService::CLEAR_CLOUD_BUTT) { return GeneralError::E_INVALID_ARGS; -- Gitee From 3b9a42ac678a71943df2c0c3e87f65e7060c3aa9 Mon Sep 17 00:00:00 2001 From: ylq121 Date: Sun, 2 Jul 2023 16:42:01 +0800 Subject: [PATCH 328/437] xiugai Signed-off-by: ylq121 --- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 951cc4fe..88a5e0eb 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -214,7 +214,7 @@ int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t break; default: if (devices.empty()) { - delegate_->RemoveDeviceData(); + status = delegate_->RemoveDeviceData(); break; } -- Gitee From f147c6986bf60a364d110619c38cec5b7c2442c0 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sun, 2 Jul 2023 13:33:06 +0000 Subject: [PATCH 329/437] update services/distributeddataservice/service/object/object_callback_proxy.cpp. Signed-off-by: wangdengze --- .../service/object/object_callback_proxy.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/services/distributeddataservice/service/object/object_callback_proxy.cpp b/services/distributeddataservice/service/object/object_callback_proxy.cpp index 95415af7..0eb7942b 100644 --- a/services/distributeddataservice/service/object/object_callback_proxy.cpp +++ b/services/distributeddataservice/service/object/object_callback_proxy.cpp @@ -55,9 +55,7 @@ void ObjectSaveCallbackProxy::Completed(const std::map &re return; } MessageOption mo { MessageOption::TF_SYNC }; - int error = Remote()->SendRequest( - static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), - data, reply, mo); + int error = Remote()->SendRequest(COMPLETED, data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } @@ -76,9 +74,7 @@ void ObjectRevokeSaveCallbackProxy::Completed(int32_t status) return; } MessageOption mo { MessageOption::TF_SYNC }; - int error = Remote()->SendRequest( - static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), - data, reply, mo); + int error = Remote()->SendRequest(COMPLETED, data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } @@ -97,9 +93,7 @@ void ObjectRetrieveCallbackProxy::Completed(const std::mapSendRequest( - static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), - data, reply, mo); + int error = Remote()->SendRequest(COMPLETED, data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } @@ -118,9 +112,7 @@ void ObjectChangeCallbackProxy::Completed(const std::mapSendRequest( - static_cast(OHOS::DistributedObject::ObjectStore::ObjectStoreInterfaceCode::COMPLETED), - data, reply, mo); + int error = Remote()->SendRequest(COMPLETED, data, reply, mo); if (error != 0) { ZLOGW("SendRequest failed, error %d", error); } -- Gitee From a2e412a86fb44691a9487d33d6d6f2553869fc52 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sun, 2 Jul 2023 13:34:28 +0000 Subject: [PATCH 330/437] update services/distributeddataservice/service/object/object_service_stub.cpp. Signed-off-by: wangdengze --- .../service/object/object_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/object/object_service_stub.cpp b/services/distributeddataservice/service/object/object_service_stub.cpp index 9a5281bf..33ec84c2 100644 --- a/services/distributeddataservice/service/object/object_service_stub.cpp +++ b/services/distributeddataservice/service/object/object_service_stub.cpp @@ -150,7 +150,7 @@ int ObjectServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa if (!CheckInterfaceToken(data)) { return -1; } - if (code >= 0 && code < OBJECTSTORE_SERVICE_CMD_MAX) { + if (code >= 0 && code < ObjectCode::OBJECTSTORE_SERVICE_CMD_MAX) { return (this->*HANDLERS[code])(data, reply); } return -1; -- Gitee From 0cd9cd7a92cee61670ce49af8ac52082859a65db Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sun, 2 Jul 2023 13:37:25 +0000 Subject: [PATCH 331/437] update services/distributeddataservice/service/object/object_service_stub.h. Signed-off-by: wangdengze --- .../service/object/object_service_stub.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/object/object_service_stub.h b/services/distributeddataservice/service/object/object_service_stub.h index c3e319fa..886136ba 100644 --- a/services/distributeddataservice/service/object/object_service_stub.h +++ b/services/distributeddataservice/service/object/object_service_stub.h @@ -20,6 +20,8 @@ #include "iobject_service.h" #include "feature/feature_system.h" namespace OHOS::DistributedObject { +using ObjectCode = ObjectService::ObjectServiceInterfaceCode; + class ObjectServiceStub : public ObjectService, public DistributedData::FeatureSystem::Feature { public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) override; @@ -33,7 +35,7 @@ private: int32_t OnUnsubscribeRequest(MessageParcel &data, MessageParcel &reply); using RequestHandle = int (ObjectServiceStub::*)(MessageParcel &, MessageParcel &); - static constexpr RequestHandle HANDLERS[OBJECTSTORE_SERVICE_CMD_MAX] = { + static constexpr RequestHandle HANDLERS[static_cast(ObjectCode::OBJECTSTORE_SERVICE_CMD_MAX)] = { &ObjectServiceStub::ObjectStoreSaveOnRemote, &ObjectServiceStub::ObjectStoreRevokeSaveOnRemote, &ObjectServiceStub::ObjectStoreRetrieveOnRemote, -- Gitee From 51564c5c1b223b4d0b2a6a5efdfe2ac8e253078d Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sun, 2 Jul 2023 13:38:49 +0000 Subject: [PATCH 332/437] update services/distributeddataservice/service/object/object_service_stub.cpp. Signed-off-by: wangdengze --- .../service/object/object_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/object/object_service_stub.cpp b/services/distributeddataservice/service/object/object_service_stub.cpp index 33ec84c2..a97dd72d 100644 --- a/services/distributeddataservice/service/object/object_service_stub.cpp +++ b/services/distributeddataservice/service/object/object_service_stub.cpp @@ -150,7 +150,7 @@ int ObjectServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa if (!CheckInterfaceToken(data)) { return -1; } - if (code >= 0 && code < ObjectCode::OBJECTSTORE_SERVICE_CMD_MAX) { + if (code >= 0 && code < static_cast(ObjectCode::OBJECTSTORE_SERVICE_CMD_MAX)) { return (this->*HANDLERS[code])(data, reply); } return -1; -- Gitee From f93c7f130ff55a1082ebbdbdaa2bad81972e7c8e Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sun, 2 Jul 2023 13:42:36 +0000 Subject: [PATCH 333/437] update services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp. Signed-off-by: wangdengze --- .../service/rdb/rdb_notifier_proxy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index 50564dbb..f77575fe 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -17,6 +17,8 @@ #include "itypes_util.h" #include "log_print.h" namespace OHOS::DistributedRdb { +using NotifierIFCode = relationalStore::IRdbNotifierInterfaceCode; + RdbNotifierProxy::RdbNotifierProxy(const sptr &object) : IRemoteProxy(object) { ZLOGI("construct"); @@ -41,8 +43,7 @@ int32_t RdbNotifierProxy::OnComplete(uint32_t seqNum, Details &&result) MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); if (Remote()->SendRequest( - static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_SYNC_COMPLETE), - data, reply, option) != 0) { + static_cast(NotifierIFCode::RDB_NOTIFIER_CMD_SYNC_COMPLETE), data, reply, option) != 0) { ZLOGE("send request failed"); return RDB_ERROR; } @@ -64,8 +65,7 @@ int32_t RdbNotifierProxy::OnChange(const Origin &origin, const PrimaryFields &pr MessageParcel reply; MessageOption option; if (Remote()->SendRequest( - static_cast(OHOS::DistributedRdb::RelStore::RelStoreInterfaceCode::RDB_NOTIFIER_CMD_DATA_CHANGE), - data, reply, option) != 0) { + static_cast(NotifierIFCode::RDB_NOTIFIER_CMD_DATA_CHANGE), data, reply, option) != 0) { ZLOGE("send request failed"); return RDB_ERROR; } -- Gitee From d0c5175c5ff1ecaa0dc8019e6bbe467555a8b459 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sun, 2 Jul 2023 14:12:59 +0000 Subject: [PATCH 334/437] update services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp. Signed-off-by: wangdengze --- .../distributeddataservice/service/rdb/rdb_notifier_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp index f77575fe..1d9d7401 100644 --- a/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp +++ b/services/distributeddataservice/service/rdb/rdb_notifier_proxy.cpp @@ -17,7 +17,7 @@ #include "itypes_util.h" #include "log_print.h" namespace OHOS::DistributedRdb { -using NotifierIFCode = relationalStore::IRdbNotifierInterfaceCode; +using NotifierIFCode = RelationalStore::IRdbNotifierInterfaceCode; RdbNotifierProxy::RdbNotifierProxy(const sptr &object) : IRemoteProxy(object) { -- Gitee From b1caaea44312b683e16ff0861099b9238f21c244 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sun, 2 Jul 2023 15:30:13 +0000 Subject: [PATCH 335/437] update services/distributeddataservice/service/object/object_service_stub.h. Signed-off-by: wangdengze --- .../distributeddataservice/service/object/object_service_stub.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/object/object_service_stub.h b/services/distributeddataservice/service/object/object_service_stub.h index 886136ba..6acd6c75 100644 --- a/services/distributeddataservice/service/object/object_service_stub.h +++ b/services/distributeddataservice/service/object/object_service_stub.h @@ -20,7 +20,7 @@ #include "iobject_service.h" #include "feature/feature_system.h" namespace OHOS::DistributedObject { -using ObjectCode = ObjectService::ObjectServiceInterfaceCode; +using ObjectCode = ObjectStoreService::ObjectServiceInterfaceCode; class ObjectServiceStub : public ObjectService, public DistributedData::FeatureSystem::Feature { public: -- Gitee From b62ee3c9ccff20d526fe43832beb70e045fa5c76 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Mon, 3 Jul 2023 11:06:17 +0800 Subject: [PATCH 336/437] delete gs flag convert Signed-off-by: wanghuajian --- .../service/rdb/value_proxy.cpp | 26 +++++++------------ .../service/rdb/value_proxy.h | 2 +- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 249259ca..23bac1a7 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -199,8 +199,7 @@ ValueProxy::Asset::operator DistributedDB::Asset() .createTime = std::move(asset_.createTime), .size = std::move(asset_.size), .hash = std::move(asset_.hash), - .flag = ConvertToDBStatus(asset_).second, - .status = ConvertToDBStatus(asset_).first }; + .status = ConvertToDBStatus(asset_) }; } uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asset) @@ -224,30 +223,23 @@ uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asse return DistributedData::Asset::STATUS_UNKNOWN; } -std::pair ValueProxy::Asset::ConvertToDBStatus(const DistributedData::Asset &asset) +uint32_t ValueProxy::Asset::ConvertToDBStatus(const DistributedData::Asset &asset) { switch (asset.status) { case DistributedData::Asset::STATUS_NORMAL: - return { static_cast(DistributedDB::AssetStatus::NORMAL), - static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; + return static_cast(DistributedDB::AssetStatus::NORMAL); case DistributedData::Asset::STATUS_ABNORMAL: - return { static_cast(DistributedDB::AssetStatus::ABNORMAL), - static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; + return static_cast(DistributedDB::AssetStatus::ABNORMAL); case DistributedData::Asset::STATUS_INSERT: - return { static_cast(DistributedDB::AssetStatus::INSERT), - static_cast(DistributedDB::AssetOpType::INSERT) }; + return static_cast(DistributedDB::AssetStatus::INSERT); case DistributedData::Asset::STATUS_UPDATE: - return { static_cast(DistributedDB::AssetStatus::UPDATE), - static_cast(DistributedDB::AssetOpType::UPDATE) }; + return static_cast(DistributedDB::AssetStatus::UPDATE); case DistributedData::Asset::STATUS_DELETE: - return { static_cast(DistributedDB::AssetStatus::DELETE), - static_cast(DistributedDB::AssetOpType::DELETE) }; + return static_cast(DistributedDB::AssetStatus::DELETE); case DistributedData::Asset::STATUS_DOWNLOADING: - return { static_cast(DistributedDB::AssetStatus::DOWNLOADING), - static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; + return static_cast(DistributedDB::AssetStatus::DOWNLOADING); default: - return { static_cast(DistributedDB::AssetStatus::NORMAL), - static_cast(DistributedDB::AssetOpType::NO_CHANGE) }; + return static_cast(DistributedDB::AssetStatus::NORMAL); } } diff --git a/services/distributeddataservice/service/rdb/value_proxy.h b/services/distributeddataservice/service/rdb/value_proxy.h index 83790b76..3c351ee5 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.h +++ b/services/distributeddataservice/service/rdb/value_proxy.h @@ -61,7 +61,7 @@ public: operator DistributedData::Asset(); operator DistributedDB::Asset(); static uint32_t ConvertToDataStatus(const DistributedDB::Asset &asset); - static std::pair ConvertToDBStatus(const DistributedData::Asset &asset); + static uint32_t ConvertToDBStatus(const DistributedData::Asset &asset); private: DistributedData::Asset asset_; -- Gitee From d461779c043e4d6456662affccaade3f2e29b592 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 03:42:17 +0000 Subject: [PATCH 337/437] update services/distributeddataservice/service/cloud/cloud_service_stub.cpp. Signed-off-by: wangdengze --- .../distributeddataservice/service/cloud/cloud_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index 34a65dc1..ff4155d3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -44,7 +44,7 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, if (TRANS_HEAD > code || code >= TRANS_BUTT || HANDLERS[code] == nullptr) { ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); - return -1; + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) { -- Gitee From 6617bc220447fe4c6ee9000e44e5801748120446 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 3 Jul 2023 11:42:48 +0800 Subject: [PATCH 338/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 9 +++++---- .../service/cloud/cloud_service_impl.h | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 4a55e73e..8315bfdc 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -426,8 +426,9 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) ZLOGD("begin cloud:%{public}d user:%{public}d apps:%{public}zu", cloudInfo.enableCloud, sub.userId, cloudInfo.apps.size()); - auto onThreshold = (std::chrono::system_clock::now() + std::chrono::hours(EXPIRE_INTERVAL)).time_since_epoch(); - auto offThreshold = std::chrono::system_clock::now().time_since_epoch(); + auto onThreshold = std::chrono::duration_cast( + (system_clock::now() + hours(EXPIRE_INTERVAL)).time_since_epoch()); + auto offThreshold = std::chrono::duration_cast(system_clock::now().time_since_epoch()); std::map> subDbs; std::map> unsubDbs; for (auto &[bundle, app] : cloudInfo.apps) { @@ -436,12 +437,12 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) auto it = sub.expiresTime.find(bundle); // cloud is enabled, but the subscription won't expire if (enabled && (it != sub.expiresTime.end() && - it->second >= static_cast(onThreshold.count() / TO_MS))) { + it->second >= static_cast(onThreshold.count())) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. if (!enabled && (it == sub.expiresTime.end() || - it->second <= static_cast(offThreshold.count() / TO_MS))) { + it->second <= static_cast(offThreshold.count()))) { continue; } diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 2b1311f9..554d8301 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -66,7 +66,6 @@ private: static constexpr int32_t RETRY_TIMES = 10; static constexpr int32_t RETRY_INTERVAL = 30; static constexpr int32_t EXPIRE_INTERVAL = 7 * 24; // 7 day - static constexpr int32_t TO_MS = 1000; bool UpdateCloudInfo(int32_t user); bool UpdateSchema(int32_t user); -- Gitee From e699c14a1a71303430d4eaee43ddfc8a7dd89c9d Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 03:43:07 +0000 Subject: [PATCH 339/437] update services/distributeddataservice/service/data_share/data_share_service_stub.cpp. Signed-off-by: wangdengze --- .../service/data_share/data_share_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 99383d08..362f3d58 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -327,7 +327,7 @@ int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me if (code < DATA_SHARE_SERVICE_CMD_MAX) { return (this->*HANDLERS[code])(data, reply); } - return -1; + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } int32_t DataShareServiceStub::OnRemoteNotifyObserver(MessageParcel &data, MessageParcel &reply) -- Gitee From 8b189305782be0de0844c242eebe98453f0e476e Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 03:43:56 +0000 Subject: [PATCH 340/437] update services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp. Signed-off-by: wangdengze --- .../distributeddataservice/service/kvdb/kvdb_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp index 1da51ce4..1fb08ee9 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp @@ -58,7 +58,7 @@ int KVDBServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message code >= static_cast(KVDBServiceInterfaceCode::TRANS_BUTT) || HANDLERS[code] == nullptr) { ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, static_cast(KVDBServiceInterfaceCode::TRANS_BUTT)); - return -1; + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } AppId appId; -- Gitee From 19f33aad0046e16038d998896f0f2453ba22c20b Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 03:44:43 +0000 Subject: [PATCH 341/437] update services/distributeddataservice/service/object/object_service_stub.cpp. Signed-off-by: wangdengze --- .../service/object/object_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/object/object_service_stub.cpp b/services/distributeddataservice/service/object/object_service_stub.cpp index a97dd72d..9a57eb6a 100644 --- a/services/distributeddataservice/service/object/object_service_stub.cpp +++ b/services/distributeddataservice/service/object/object_service_stub.cpp @@ -153,6 +153,6 @@ int ObjectServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa if (code >= 0 && code < static_cast(ObjectCode::OBJECTSTORE_SERVICE_CMD_MAX)) { return (this->*HANDLERS[code])(data, reply); } - return -1; + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } // namespace OHOS::DistributedRdb -- Gitee From 2e41f42966750c8ded046c22c2122f40b11de5e0 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 3 Jul 2023 11:45:11 +0800 Subject: [PATCH 342/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 8315bfdc..ea4bc71c 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -436,13 +436,11 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) auto &dbs = enabled ? subDbs : unsubDbs; auto it = sub.expiresTime.find(bundle); // cloud is enabled, but the subscription won't expire - if (enabled && (it != sub.expiresTime.end() && - it->second >= static_cast(onThreshold.count())) { + if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count())) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. - if (!enabled && (it == sub.expiresTime.end() || - it->second <= static_cast(offThreshold.count()))) { + if (!enabled && (it == sub.expiresTime.end() || it->second <= static_cast(offThreshold.count()))) { continue; } -- Gitee From 24cd479773c09d7eb0825cce44e9c48b242a3ed3 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 3 Jul 2023 11:46:19 +0800 Subject: [PATCH 343/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index ea4bc71c..138003d0 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -436,7 +436,7 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) auto &dbs = enabled ? subDbs : unsubDbs; auto it = sub.expiresTime.find(bundle); // cloud is enabled, but the subscription won't expire - if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count())) { + if (enabled && (it != sub.expiresTime.end() && it->second >= static_cast(onThreshold.count()))) { continue; } // cloud is disabled, we don't care the subscription which was expired or didn't subscribe. -- Gitee From 73c70deb8acffca75ff5f2ee6110e581e69138aa Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 03:47:06 +0000 Subject: [PATCH 344/437] update services/distributeddataservice/service/rdb/rdb_service_stub.cpp. Signed-off-by: wangdengze --- .../distributeddataservice/service/rdb/rdb_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index bf493d2c..8e602e5c 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -207,7 +207,7 @@ int RdbServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageP if (!CheckInterfaceToken(data)) { return RDB_ERROR; } - if (code >= 0 && code < RDB_SERVICE_CMD_MAX) { + if (code >= 0 && code < static_cast(RdbServiceCode::RDB_SERVICE_CMD_MAX)) { return (this->*HANDLERS[code])(data, reply); } return RDB_ERROR; -- Gitee From 706952bad6957bdfd5109dcaf23abd0a3fd10049 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 03:47:53 +0000 Subject: [PATCH 345/437] update services/distributeddataservice/service/rdb/rdb_service_stub.h. Signed-off-by: wangdengze --- .../service/rdb/rdb_service_stub.h | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_service_stub.h b/services/distributeddataservice/service/rdb/rdb_service_stub.h index b67c3e5b..fbd2173a 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_stub.h +++ b/services/distributeddataservice/service/rdb/rdb_service_stub.h @@ -22,6 +22,8 @@ #include "feature/feature_system.h" namespace OHOS::DistributedRdb { +using RdbServiceCode = OHOS::DistributedRdb::RelationalStore::RdbServiceInterfaceCode; + class RdbServiceStub : public RdbService, public DistributedData::FeatureSystem::Feature { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedRdb.IRdbService"); @@ -49,16 +51,18 @@ private: int32_t OnRemoteDoRemoteQuery(MessageParcel& data, MessageParcel& reply); using RequestHandle = int (RdbServiceStub::*)(MessageParcel &, MessageParcel &); - static constexpr RequestHandle HANDLERS[RDB_SERVICE_CMD_MAX] = { - [RDB_SERVICE_CMD_OBTAIN_TABLE] = &RdbServiceStub::OnRemoteObtainDistributedTableName, - [RDB_SERVICE_CMD_INIT_NOTIFIER] = &RdbServiceStub::OnRemoteInitNotifier, - [RDB_SERVICE_CMD_SET_DIST_TABLE] = &RdbServiceStub::OnRemoteSetDistributedTables, - [RDB_SERVICE_CMD_SYNC] = &RdbServiceStub::OnRemoteDoSync, - [RDB_SERVICE_CMD_ASYNC] = &RdbServiceStub::OnRemoteDoAsync, - [RDB_SERVICE_CMD_SUBSCRIBE] = &RdbServiceStub::OnRemoteDoSubscribe, - [RDB_SERVICE_CMD_UNSUBSCRIBE] = &RdbServiceStub::OnRemoteDoUnSubscribe, - [RDB_SERVICE_CMD_REMOTE_QUERY] = &RdbServiceStub::OnRemoteDoRemoteQuery, - [RDB_SERVICE_CMD_GET_SCHEMA] = &RdbServiceStub::OnGetSchema + static constexpr RequestHandle HANDLERS[static_cast(RdbServiceCode::RDB_SERVICE_CMD_MAX)] = { + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_OBTAIN_TABLE)] = + &RdbServiceStub::OnRemoteObtainDistributedTableName, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_INIT_NOTIFIER)] = &RdbServiceStub::OnRemoteInitNotifier, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_SET_DIST_TABLE)] = + &RdbServiceStub::OnRemoteSetDistributedTables, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_SYNC)] = &RdbServiceStub::OnRemoteDoSync, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_ASYNC)] = &RdbServiceStub::OnRemoteDoAsync, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_SUBSCRIBE)] = &RdbServiceStub::OnRemoteDoSubscribe, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_UNSUBSCRIBE)] = &RdbServiceStub::OnRemoteDoUnSubscribe, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_REMOTE_QUERY)] = &RdbServiceStub::OnRemoteDoRemoteQuery, + [static_cast(RdbServiceCode::RDB_SERVICE_CMD_GET_SCHEMA)] = &RdbServiceStub::OnGetSchema }; }; } // namespace OHOS::DistributedRdb -- Gitee From 517c3da25f43cd48d1bcfadd78616312e7370484 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 05:09:17 +0000 Subject: [PATCH 346/437] update services/distributeddataservice/service/cloud/cloud_service_stub.cpp. Signed-off-by: wangdengze --- .../distributeddataservice/service/cloud/cloud_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp index ff4155d3..34a65dc1 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_stub.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_stub.cpp @@ -44,7 +44,7 @@ int CloudServiceStub::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data, if (TRANS_HEAD > code || code >= TRANS_BUTT || HANDLERS[code] == nullptr) { ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, TRANS_BUTT); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return -1; } if (!TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) { -- Gitee From 5f74116ce6c33c5de1f20a03a8d2cd1574eaf467 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 05:12:13 +0000 Subject: [PATCH 347/437] update services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp. Signed-off-by: wangdengze --- .../distributeddataservice/service/kvdb/kvdb_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp index 1fb08ee9..1da51ce4 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_stub.cpp @@ -58,7 +58,7 @@ int KVDBServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message code >= static_cast(KVDBServiceInterfaceCode::TRANS_BUTT) || HANDLERS[code] == nullptr) { ZLOGE("not support code:%{public}u, BUTT:%{public}d", code, static_cast(KVDBServiceInterfaceCode::TRANS_BUTT)); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return -1; } AppId appId; -- Gitee From cba0621b20916efd0df01c239f26418dace18fb5 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 05:14:34 +0000 Subject: [PATCH 348/437] update services/distributeddataservice/service/object/object_service_stub.cpp. Signed-off-by: wangdengze --- .../service/object/object_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/object/object_service_stub.cpp b/services/distributeddataservice/service/object/object_service_stub.cpp index 9a57eb6a..a97dd72d 100644 --- a/services/distributeddataservice/service/object/object_service_stub.cpp +++ b/services/distributeddataservice/service/object/object_service_stub.cpp @@ -153,6 +153,6 @@ int ObjectServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa if (code >= 0 && code < static_cast(ObjectCode::OBJECTSTORE_SERVICE_CMD_MAX)) { return (this->*HANDLERS[code])(data, reply); } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return -1; } } // namespace OHOS::DistributedRdb -- Gitee From 2ebee45992ed3751f33f40cc7ce982a38e4e5a26 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 3 Jul 2023 05:59:48 +0000 Subject: [PATCH 349/437] update services/distributeddataservice/service/data_share/data_share_service_stub.cpp. Signed-off-by: wangdengze --- .../service/data_share/data_share_service_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index 362f3d58..99383d08 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -327,7 +327,7 @@ int DataShareServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me if (code < DATA_SHARE_SERVICE_CMD_MAX) { return (this->*HANDLERS[code])(data, reply); } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return -1; } int32_t DataShareServiceStub::OnRemoteNotifyObserver(MessageParcel &data, MessageParcel &reply) -- Gitee From d70a721519d1b817c9c77da51ca3469816a9aa54 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 3 Jul 2023 14:00:48 +0800 Subject: [PATCH 350/437] update Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 138003d0..af0f9613 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -427,8 +427,9 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) ZLOGD("begin cloud:%{public}d user:%{public}d apps:%{public}zu", cloudInfo.enableCloud, sub.userId, cloudInfo.apps.size()); auto onThreshold = std::chrono::duration_cast( - (system_clock::now() + hours(EXPIRE_INTERVAL)).time_since_epoch()); - auto offThreshold = std::chrono::duration_cast(system_clock::now().time_since_epoch()); + (std::chrono::system_clock::now() + hours(EXPIRE_INTERVAL)).time_since_epoch()); + auto offThreshold = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()); std::map> subDbs; std::map> unsubDbs; for (auto &[bundle, app] : cloudInfo.apps) { -- Gitee From fb52272d07fe76d9466bb75c07a482241e557615 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 3 Jul 2023 14:21:19 +0800 Subject: [PATCH 351/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/cloud_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index af0f9613..88d7ff51 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -427,7 +427,7 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) ZLOGD("begin cloud:%{public}d user:%{public}d apps:%{public}zu", cloudInfo.enableCloud, sub.userId, cloudInfo.apps.size()); auto onThreshold = std::chrono::duration_cast( - (std::chrono::system_clock::now() + hours(EXPIRE_INTERVAL)).time_since_epoch()); + (std::chrono::system_clock::now() + std::chrono::hours(EXPIRE_INTERVAL)).time_since_epoch()); auto offThreshold = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()); std::map> subDbs; -- Gitee From e6138e1e86d365475fa06a16d77016fc66b83c98 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 3 Jul 2023 15:21:28 +0800 Subject: [PATCH 352/437] udpate Signed-off-by: zuojiangjiang --- .../service/cloud/cloud_service_impl.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 88d7ff51..e7c92bb2 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -31,6 +31,7 @@ #include "utils/anonymous.h" namespace OHOS::CloudData { using namespace DistributedData; +using namespace std::chrono; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using Account = OHOS::DistributedKv::AccountDelegate; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; @@ -426,10 +427,8 @@ bool CloudServiceImpl::DoSubscribe(int32_t user) ZLOGD("begin cloud:%{public}d user:%{public}d apps:%{public}zu", cloudInfo.enableCloud, sub.userId, cloudInfo.apps.size()); - auto onThreshold = std::chrono::duration_cast( - (std::chrono::system_clock::now() + std::chrono::hours(EXPIRE_INTERVAL)).time_since_epoch()); - auto offThreshold = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()); + auto onThreshold = duration_cast((system_clock::now() + hours(EXPIRE_INTERVAL)).time_since_epoch()); + auto offThreshold = duration_cast(system_clock::now().time_since_epoch()); std::map> subDbs; std::map> unsubDbs; for (auto &[bundle, app] : cloudInfo.apps) { -- Gitee From d560fd4bc2af2a6b5c28207007779ce6b78bfd7e Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 3 Jul 2023 17:04:38 +0800 Subject: [PATCH 353/437] fix Build.gn format Signed-off-by: mazhao --- .../service/data_share/gaussdb_rd/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn old mode 100644 new mode 100755 index a66602e0..293099f3 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn @@ -82,9 +82,9 @@ ohos_shared_library("gaussdb_rd") { external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "hilog:libhilog", ] subsystem_name = "distributeddatamgr" -- Gitee From 04eb16a0be7bf61a597d89afc3d05dd79cfd65e0 Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 3 Jul 2023 17:21:25 +0800 Subject: [PATCH 354/437] fix format Signed-off-by: mazhao --- .../service/data_share/gaussdb_rd/test/unittest/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn index 75835174..81eb4698 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn @@ -81,9 +81,9 @@ ohos_source_set("src_file") { deps += [ "//third_party/cJSON:cjson" ] external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "hilog:libhilog", ] subsystem_name = "distributeddatamgr" @@ -115,9 +115,9 @@ template("gaussdb_rd_unittest") { ] external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "hilog:libhilog", ] } } -- Gitee From 2dd5b4de56316eea1205265ec2c0114c3886f9fd Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Mon, 3 Jul 2023 20:39:55 +0800 Subject: [PATCH 355/437] modify ipcamera build config Signed-off-by: ding_dong_dong --- bundle.json | 3 +-- services/distributeddataservice/service/BUILD.gn | 4 ++++ services/distributeddataservice/service/udmf/BUILD.gn | 7 ------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bundle.json b/bundle.json index c79e1be9..3b5839ad 100644 --- a/bundle.json +++ b/bundle.json @@ -91,8 +91,7 @@ "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/framework:build_module", "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service:build_module", "//foundation/distributeddatamgr/datamgr_service/conf:build_module", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module", - "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/udmf:build_module" + "//foundation/distributeddatamgr/datamgr_service/services/distributeddataservice/service/data_share:build_module" ], "inner_kits": [], "test": [ diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 6e8f2eba..42b0e4b6 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -16,6 +16,10 @@ import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") group("build_module") { deps = [ ":distributeddatasvc" ] + + if (datamgr_service_udmf) { + deps += [ "${data_service_path}/service/udmf:udmf_server" ] + } } config("module_public_config") { visibility = [ ":*" ] diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index 4713e40d..9997263e 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -13,13 +13,6 @@ import("//build/ohos.gni") import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") -group("build_module") { - deps = [] - if (datamgr_service_udmf) { - deps += [ ":udmf_server" ] - } -} - config("module_public_config") { visibility = [ ":*" ] -- Gitee From daf104c38cedc09b0a744d3a1b44fb1dfe7de62f Mon Sep 17 00:00:00 2001 From: lyj_love_code Date: Mon, 3 Jul 2023 19:50:40 +0800 Subject: [PATCH 356/437] feat: change the component name of hilog/hisysevent/hitrace Signed-off-by: lyj_love_code --- .../service/data_share/gaussdb_rd/BUILD.gn | 6 +++--- .../data_share/gaussdb_rd/test/unittest/BUILD.gn | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn index 47128f8c..293099f3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/BUILD.gn @@ -82,9 +82,9 @@ ohos_shared_library("gaussdb_rd") { external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn index b4cc59a3..81eb4698 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/BUILD.gn @@ -81,9 +81,9 @@ ohos_source_set("src_file") { deps += [ "//third_party/cJSON:cjson" ] external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", ] subsystem_name = "distributeddatamgr" @@ -115,9 +115,9 @@ template("gaussdb_rd_unittest") { ] external_deps = [ "c_utils:utils", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", ] } } -- Gitee From ff0f9c9c668ee718b974d629e45152a1497f86a5 Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Mon, 3 Jul 2023 20:19:42 +0800 Subject: [PATCH 357/437] add fuzz test Signed-off-by: ding_dong_dong --- BUILD.gn | 2 + datamgr_service.gni | 2 + .../communicator/test/fuzztest/BUILD.gn | 21 +++ .../fuzztest/softbusadapter_fuzzer/BUILD.gn | 68 ++++++++++ .../softbusadapter_fuzzer/corpus/init | 16 +++ .../softbusadapter_fuzzer/project.xml | 25 ++++ .../softbusadapter_fuzzer.cpp | 47 +++++++ .../softbusadapter_fuzzer.h | 21 +++ .../adapter/test/BUILD.gn | 6 + .../app/test/fuzztest/BUILD.gn | 21 +++ .../fuzztest/dataservicestub_fuzzer/BUILD.gn | 116 ++++++++++++++++ .../dataservicestub_fuzzer/corpus/init | 16 +++ .../dataservicestub_fuzzer.cpp | 57 ++++++++ .../dataservicestub_fuzzer.h | 21 +++ .../dataservicestub_fuzzer/project.xml | 25 ++++ .../service/test/fuzztest/BUILD.gn | 9 +- .../fuzztest/cloudservicestub_fuzzer/BUILD.gn | 113 ++++++++++++++++ .../cloudservicestub_fuzzer.cpp | 56 ++++++++ .../cloudservicestub_fuzzer.h | 21 +++ .../cloudservicestub_fuzzer/corpus/init | 16 +++ .../cloudservicestub_fuzzer/project.xml | 25 ++++ .../datashareservicestub_fuzzer/BUILD.gn | 124 ++++++++++++++++++ .../datashareservicestub_fuzzer/corpus/init | 16 +++ .../datashareservicestub_fuzzer.cpp | 56 ++++++++ .../datashareservicestub_fuzzer.h | 21 +++ .../datashareservicestub_fuzzer/project.xml | 25 ++++ .../fuzztest/kvdbservicestub_fuzzer/BUILD.gn | 110 ++++++++++++++++ .../kvdbservicestub_fuzzer/corpus/init | 16 +++ .../kvdbservicestub_fuzzer.cpp | 56 ++++++++ .../kvdbservicestub_fuzzer.h | 21 +++ .../kvdbservicestub_fuzzer/project.xml | 25 ++++ .../objectservicestub_fuzzer/BUILD.gn | 110 ++++++++++++++++ .../objectservicestub_fuzzer/corpus/init | 16 +++ .../objectservicestub_fuzzer.cpp | 56 ++++++++ .../objectservicestub_fuzzer.h | 21 +++ .../objectservicestub_fuzzer/project.xml | 25 ++++ .../fuzztest/rdbresultsetstub_fuzzer/BUILD.gn | 123 +++++++++++++++++ .../rdbresultsetstub_fuzzer/corpus/init | 16 +++ .../rdbresultsetstub_fuzzer/project.xml | 25 ++++ .../rdbresultsetstub_fuzzer.cpp | 58 ++++++++ .../rdbresultsetstub_fuzzer.h | 21 +++ .../fuzztest/rdbservicestub_fuzzer/BUILD.gn | 111 ++++++++++++++++ .../rdbservicestub_fuzzer/corpus/init | 16 +++ .../rdbservicestub_fuzzer/project.xml | 25 ++++ .../rdbservicestub_fuzzer.cpp | 56 ++++++++ .../rdbservicestub_fuzzer.h | 21 +++ 46 files changed, 1873 insertions(+), 1 deletion(-) create mode 100644 services/distributeddataservice/adapter/communicator/test/fuzztest/BUILD.gn create mode 100644 services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/corpus/init create mode 100644 services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/project.xml create mode 100644 services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp create mode 100644 services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h create mode 100644 services/distributeddataservice/app/test/fuzztest/BUILD.gn create mode 100644 services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/corpus/init create mode 100644 services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.cpp create mode 100644 services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.h create mode 100644 services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.h create mode 100644 services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.h create mode 100644 services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.h create mode 100644 services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.h create mode 100644 services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.h create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.h diff --git a/BUILD.gn b/BUILD.gn index 609c8f50..e759bcf1 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,6 +29,8 @@ group("fuzztest") { testonly = true deps = [] deps += [ + "services/distributeddataservice/adapter/test:fuzztest", + "services/distributeddataservice/app/test/fuzztest:fuzztest", "services/distributeddataservice/service/test/fuzztest:fuzztest", "test/fuzztest/autolaunch_fuzzer:fuzztest", "test/fuzztest/kvstoredisksize_fuzzer:fuzztest", diff --git a/datamgr_service.gni b/datamgr_service.gni index 708ee20e..ac2f5ccb 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -36,6 +36,8 @@ data_service_path = "//foundation/distributeddatamgr/datamgr_service/services/di udmf_path = "//foundation/distributeddatamgr/udmf" +dataobject_path = "//foundation/distributeddatamgr/data_object" + declare_args() { datamgr_service_power = true if (!defined(global_parts_info.power_manager_native_powermgr_client) || diff --git a/services/distributeddataservice/adapter/communicator/test/fuzztest/BUILD.gn b/services/distributeddataservice/adapter/communicator/test/fuzztest/BUILD.gn new file mode 100644 index 00000000..dacf421d --- /dev/null +++ b/services/distributeddataservice/adapter/communicator/test/fuzztest/BUILD.gn @@ -0,0 +1,21 @@ +# 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. + +import("//build/ohos.gni") + +######################################################################################### +group("fuzztest") { + testonly = true + + deps = [ "softbusadapter_fuzzer:fuzztest" ] +} diff --git a/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/BUILD.gn b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/BUILD.gn new file mode 100644 index 00000000..25df6bdb --- /dev/null +++ b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SoftBusAdapterFuzzTest") { + module_out_path = "datamgr_service/adapter" + + include_dirs = [ + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/adapter/include/dfx", + "${data_service_path}/adapter/include/log", + "${data_service_path}/adapter/include/autils", + "${data_service_path}/adapter/include/utils", + "${data_service_path}/adapter/communicator/src", + "${dsoftbus_core_path}", + "${kv_store_common_path}", + "${kv_store_distributeddb_path}/interfaces/include", + "${kv_store_distributeddb_path}/include", + "${kv_store_distributeddb_path}/interfaces/include/relational", + "${kv_store_path}/interfaces/innerkits/distributeddata/include", + ] + + fuzz_config_file = "${data_service_path}/adapter/communicator/test/fuzztest/softbusadapter_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "softbusadapter_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/communicator:distributeddata_communicator_static", + "${data_service_path}/adapter/dfx:distributeddata_dfx_static", + "${data_service_path}/adapter/utils:distributeddata_utils_static", + ] + + external_deps = [ + "c_utils:utils", + "device_manager:devicemanagersdk", + "dsoftbus:softbus_client", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":SoftBusAdapterFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/corpus/init b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/project.xml b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp new file mode 100644 index 00000000..cc972106 --- /dev/null +++ b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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 "softbusadapter_fuzzer.h" + +#include +#include + +#include "softbus_adapter_standard.cpp" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::AppDistributedKv; + +namespace OHOS { +bool OnBytesReceivedFuzz(const uint8_t *data, size_t size) +{ + int connId = static_cast(*data); + unsigned int dataLen = static_cast(size); + AppDataListenerWrap::OnBytesReceived(connId, data, dataLen); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnBytesReceivedFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h new file mode 100644 index 00000000..d77e3037 --- /dev/null +++ b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef SOFTBUSADAPTER_FUZZER_H +#define SOFTBUSADAPTER_FUZZER_H + +#define FUZZ_PROJECT_NAME "softbusadapter_fuzzer" + +#endif // SOFTBUSADAPTER_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/adapter/test/BUILD.gn b/services/distributeddataservice/adapter/test/BUILD.gn index 206f581e..f85ada83 100755 --- a/services/distributeddataservice/adapter/test/BUILD.gn +++ b/services/distributeddataservice/adapter/test/BUILD.gn @@ -24,3 +24,9 @@ group("unittest") { "../permission/test:unittest", ] } + +group("fuzztest") { + testonly = true + + deps = [ "../communicator/test/fuzztest:fuzztest" ] +} diff --git a/services/distributeddataservice/app/test/fuzztest/BUILD.gn b/services/distributeddataservice/app/test/fuzztest/BUILD.gn new file mode 100644 index 00000000..d7c29a7a --- /dev/null +++ b/services/distributeddataservice/app/test/fuzztest/BUILD.gn @@ -0,0 +1,21 @@ +# 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. + +import("//build/ohos.gni") + +######################################################################################### +group("fuzztest") { + testonly = true + + deps = [ "dataservicestub_fuzzer:fuzztest" ] +} diff --git a/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn new file mode 100644 index 00000000..3e594bee --- /dev/null +++ b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/BUILD.gn @@ -0,0 +1,116 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DataServiceStubFuzzTest") { + module_out_path = "datamgr_service/app" + + include_dirs = [ + "${kv_store_common_path}", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${data_service_path}/service/bootstrap/include", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/directory/include", + "${data_service_path}/service/permission/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/app/src", + "${data_service_path}/app/src/backup_rule/include", + "${data_service_path}/app/src/checker", + "${data_service_path}/app/src/flowctrl_manager", + "${data_service_path}/app/src/security", + "${data_service_path}/app/src/session_manager", + "${data_service_path}/app/src/uninstaller", + "${data_service_path}/framework/include", + "${data_service_path}/service/backup/include", + "${data_service_path}/service/kvdb", + "${data_service_path}/adapter/include/account", + "${data_service_path}/adapter/include/permission", + "${data_service_path}/adapter/include/uninstaller", + "${data_service_path}/adapter/include/broadcaster", + "${data_service_path}/adapter/include/utils", + "${data_service_path}/adapter/include/dfx", + "${data_service_path}/adapter/include", + "${device_manager_path}/interfaces/inner_kits/native_cpp/include", + "${distributedfilejs_path}/interfaces/kits/js/src/mod_securitylabel", + "//third_party/json/single_include", + ] + + fuzz_config_file = + "${data_service_path}/app/test/fuzztest/dataservicestub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/app/src/dump_helper.cpp", + "${data_service_path}/app/src/feature_stub_impl.cpp", + "${data_service_path}/app/src/kvstore_account_observer.cpp", + "${data_service_path}/app/src/kvstore_data_service.cpp", + "${data_service_path}/app/src/kvstore_device_listener.cpp", + "${data_service_path}/app/src/kvstore_meta_manager.cpp", + "${data_service_path}/app/src/security/security.cpp", + "${data_service_path}/app/src/security/sensitive.cpp", + "${data_service_path}/app/src/session_manager/route_head_handler_impl.cpp", + "${data_service_path}/app/src/session_manager/session_manager.cpp", + "${data_service_path}/app/src/session_manager/upgrade_manager.cpp", + "${data_service_path}/app/src/task_manager.cpp", + "dataservicestub_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/adapter/broadcaster:distributeddata_broadcaster_static", + "${data_service_path}/adapter/utils:distributeddata_utils_static", + "${data_service_path}/app/src/checker:distributeddata_checker_static", + "${data_service_path}/app/src/flowctrl_manager:distributeddata_flowctrl_static", + "${data_service_path}/app/src/uninstaller:distributeddata_uninstaller_static", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service:distributeddatasvc", + "${kv_store_distributeddb_path}:distributeddb", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "dataclassification:data_transit_mgr", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DataServiceStubFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/corpus/init b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.cpp b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.cpp new file mode 100644 index 00000000..e5164c94 --- /dev/null +++ b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * 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 "dataservicestub_fuzzer.h" + +#include +#include + +#include "kvstore_data_service.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DistributedKv; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.DistributedKv.IKvStoreDataService"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 10; + +bool OnRemoteRequestFuzz(const uint8_t *data, size_t size) +{ + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + MessageOption option; + std::shared_ptr kvStoreDataServiceStub = std::make_shared(); + kvStoreDataServiceStub->OnRemoteRequest(code, request, reply, option); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.h b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.h new file mode 100644 index 00000000..02e3b8df --- /dev/null +++ b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/dataservicestub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DATAMGR_SERVICE_DATA_SERVICE_STUB_FUZZER_H +#define DATAMGR_SERVICE_DATA_SERVICE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "dataservicestub_fuzzer" + +#endif // DATAMGR_SERVICE_DATA_SERVICE_STUB_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/project.xml b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/app/test/fuzztest/dataservicestub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/BUILD.gn index 133f732d..59ad2cd8 100644 --- a/services/distributeddataservice/service/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/BUILD.gn @@ -18,7 +18,14 @@ import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") group("fuzztest") { testonly = true - deps = [] + deps = [ + "cloudservicestub_fuzzer:fuzztest", + "datashareservicestub_fuzzer:fuzztest", + "kvdbservicestub_fuzzer:fuzztest", + "objectservicestub_fuzzer:fuzztest", + "rdbresultsetstub_fuzzer:fuzztest", + "rdbservicestub_fuzzer:fuzztest", + ] if (datamgr_service_udmf) { deps += [ "udmfservice_fuzzer:fuzztest" ] } diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn new file mode 100644 index 00000000..d39a5b82 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn @@ -0,0 +1,113 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("CloudServiceStubFuzzTest") { + module_out_path = "datamgr_service/service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/backup/include", + "${data_service_path}/service/bootstrap/include", + "${data_service_path}/service/cloud", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/object", + "${data_service_path}/service/permission/include", + "${data_service_path}/service/rdb", + "${kv_store_common_path}", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", + "${kv_store_distributeddb_path}", + "${kv_store_distributeddb_path}/include/", + "${kv_store_distributeddb_path}/interfaces/include/", + "${kv_store_distributeddb_path}/interfaces/include/relational", + "${dataobject_path}/frameworks/innerkitsimpl/include", + "${relational_store_path}/interfaces/inner_api/cloud_data/include", + "${relational_store_path}/interfaces/inner_api/rdb/include", + "//third_party/json/single_include", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/cloudservicestub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/cloud/cloud_service_impl.cpp", + "${data_service_path}/service/cloud/cloud_service_stub.cpp", + "${data_service_path}/service/cloud/sync_manager.cpp", + "${data_service_path}/service/rdb/rdb_asset_loader.cpp", + "${data_service_path}/service/rdb/rdb_cloud.cpp", + "${data_service_path}/service/rdb/rdb_cloud_data_translate.cpp", + "${data_service_path}/service/rdb/rdb_cursor.cpp", + "${data_service_path}/service/rdb/rdb_general_store.cpp", + "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", + "${data_service_path}/service/rdb/rdb_query.cpp", + "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", + "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", + "${data_service_path}/service/rdb/rdb_service_impl.cpp", + "${data_service_path}/service/rdb/rdb_service_stub.cpp", + "${data_service_path}/service/rdb/rdb_store_observer_impl.cpp", + "${data_service_path}/service/rdb/rdb_syncer.cpp", + "${data_service_path}/service/rdb/rdb_watcher.cpp", + "${data_service_path}/service/rdb/value_proxy.cpp", + "cloudservicestub_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/adapter/utils:distributeddata_utils_static", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service:distributeddatasvc", + "${kv_store_distributeddb_path}:distributeddb", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "device_manager:devicemanagersdk", + "hilog:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":CloudServiceStubFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp new file mode 100644 index 00000000..1dada5ad --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "cloudservicestub_fuzzer.h" + +#include +#include + +#include "cloud_service_impl.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::CloudData; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.CloudData.CloudServer"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 4; + +bool OnRemoteRequestFuzz(const uint8_t *data, size_t size) +{ + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + std::shared_ptr cloudServiceStub = std::make_shared(); + cloudServiceStub->OnRemoteRequest(code, request, reply); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.h new file mode 100644 index 00000000..c007ebba --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DATAMGR_SERVICE_CLOUD_SERVICE_STUB_FUZZER_H +#define DATAMGR_SERVICE_CLOUD_SERVICE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "cloudservicestub_fuzzer" + +#endif // DATAMGR_SERVICE_CLOUD_SERVICE_STUB_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn new file mode 100644 index 00000000..e2cbf7fe --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -0,0 +1,124 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DataShareServiceStubFuzzTest") { + module_out_path = "datamgr_service/service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/data_share/common", + "${data_service_path}/service/data_share/data", + "${data_service_path}/service/data_share/strategies", + "${data_service_path}/service/data_share/subscriber_managers", + "${data_service_path}/service/data_share", + "${datashare_path}/frameworks/native/common/include", + "${datashare_path}/interfaces/inner_api/common/include", + "${datashare_path}/interfaces/inner_api/consumer/include", + "//third_party/json/single_include", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/datashareservicestub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/data_share/common/app_connect_manager.cpp", + "${data_service_path}/service/data_share/common/bundle_mgr_proxy.cpp", + "${data_service_path}/service/data_share/common/db_delegate.cpp", + "${data_service_path}/service/data_share/common/div_strategy.cpp", + "${data_service_path}/service/data_share/common/extension_connect_adaptor.cpp", + "${data_service_path}/service/data_share/common/kv_delegate.cpp", + "${data_service_path}/service/data_share/common/rdb_delegate.cpp", + "${data_service_path}/service/data_share/common/scheduler_manager.cpp", + "${data_service_path}/service/data_share/common/seq_strategy.cpp", + "${data_service_path}/service/data_share/common/uri_utils.cpp", + "${data_service_path}/service/data_share/data/published_data.cpp", + "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", + "${data_service_path}/service/data_share/data/template_data.cpp", + "${data_service_path}/service/data_share/data_share_obs_proxy.cpp", + "${data_service_path}/service/data_share/data_share_service_impl.cpp", + "${data_service_path}/service/data_share/data_share_service_stub.cpp", + "${data_service_path}/service/data_share/data_share_types_util.cpp", + "${data_service_path}/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp", + "${data_service_path}/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/delete_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/check_is_data_proxy_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/check_is_single_app_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/cross_permission_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/empty_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_common_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_data_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_from_bundle_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/permission_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/process_single_app_user_cross_strategy.cpp", + "${data_service_path}/service/data_share/strategies/get_data_strategy.cpp", + "${data_service_path}/service/data_share/strategies/insert_strategy.cpp", + "${data_service_path}/service/data_share/strategies/publish_strategy.cpp", + "${data_service_path}/service/data_share/strategies/query_strategy.cpp", + "${data_service_path}/service/data_share/strategies/rdb_notify_strategy.cpp", + "${data_service_path}/service/data_share/strategies/subscribe_strategy.cpp", + "${data_service_path}/service/data_share/strategies/template_strategy.cpp", + "${data_service_path}/service/data_share/strategies/update_strategy.cpp", + "${data_service_path}/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp", + "${data_service_path}/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp", + "datashareservicestub_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/data_share:data_share_service", + "${data_service_path}/service/data_share/gaussdb_rd:gaussdb_rd", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_common", + "device_manager:devicemanagersdk", + "hilog:libhilog", + "ipc:ipc_core", + "relational_store:native_rdb", + "relational_store:rdb_bms_adapter", + "relational_store:rdb_data_share_adapter", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DataShareServiceStubFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.cpp new file mode 100644 index 00000000..7fb0269f --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "datashareservicestub_fuzzer.h" + +#include +#include + +#include "data_share_service_impl.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DataShare; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.DataShare.IDataShare"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 16; + +bool OnRemoteRequestFuzz(const uint8_t *data, size_t size) +{ + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + std::shared_ptr dataShareServiceStub = std::make_shared(); + dataShareServiceStub->OnRemoteRequest(code, request, reply); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.h new file mode 100644 index 00000000..28399e52 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/datashareservicestub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB_FUZZER_H +#define DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "datashareservicestub_fuzzer" + +#endif // DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn new file mode 100644 index 00000000..8998072c --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/BUILD.gn @@ -0,0 +1,110 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("KvdbServiceStubFuzzTest") { + module_out_path = "datamgr_service/service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/backup/include", + "${data_service_path}/service/bootstrap/include", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/permission/include", + "${kv_store_common_path}", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", + "${kv_store_distributeddb_path}", + "${kv_store_distributeddb_path}/include/", + "${kv_store_distributeddb_path}/interfaces/include/", + "${kv_store_distributeddb_path}/interfaces/include/relational", + "//third_party/json/single_include", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/kvdbservicestub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/backup/src/backup_manager.cpp", + "${data_service_path}/service/bootstrap/src/bootstrap.cpp", + "${data_service_path}/service/config/src/config_factory.cpp", + "${data_service_path}/service/config/src/model/backup_config.cpp", + "${data_service_path}/service/config/src/model/checker_config.cpp", + "${data_service_path}/service/config/src/model/component_config.cpp", + "${data_service_path}/service/config/src/model/directory_config.cpp", + "${data_service_path}/service/config/src/model/global_config.cpp", + "${data_service_path}/service/config/src/model/network_config.cpp", + "${data_service_path}/service/config/src/model/protocol_config.cpp", + "${data_service_path}/service/crypto/src/crypto_manager.cpp", + "${data_service_path}/service/kvdb/auth_delegate.cpp", + "${data_service_path}/service/kvdb/kvdb_exporter.cpp", + "${data_service_path}/service/kvdb/kvdb_service_impl.cpp", + "${data_service_path}/service/kvdb/kvdb_service_stub.cpp", + "${data_service_path}/service/kvdb/kvstore_sync_manager.cpp", + "${data_service_path}/service/kvdb/query_helper.cpp", + "${data_service_path}/service/kvdb/store_cache.cpp", + "${data_service_path}/service/kvdb/upgrade.cpp", + "${data_service_path}/service/kvdb/user_delegate.cpp", + "${data_service_path}/service/matrix/src/device_matrix.cpp", + "${data_service_path}/service/matrix/src/matrix_event.cpp", + "${data_service_path}/service/permission/src/permit_delegate.cpp", + "kvdbservicestub_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/adapter/utils:distributeddata_utils_static", + "${data_service_path}/framework:distributeddatasvcfwk", + "${kv_store_distributeddb_path}:distributeddb", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "device_manager:devicemanagersdk", + "hilog:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":KvdbServiceStubFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.cpp new file mode 100644 index 00000000..b01aa999 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "kvdbservicestub_fuzzer.h" + +#include +#include + +#include "kvdb_service_impl.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DistributedKv; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.DistributedKv.KVFeature"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 16; + +bool OnRemoteRequestFuzz(const uint8_t *data, size_t size) +{ + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + std::shared_ptr kvdbServiceStub = std::make_shared(); + kvdbServiceStub->OnRemoteRequest(code, request, reply); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.h new file mode 100644 index 00000000..9fba238a --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/kvdbservicestub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DATAMGR_SERVICE_KVDB_SERVICE_STUB_FUZZER_H +#define DATAMGR_SERVICE_KVDB_SERVICE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "kvdbservicestub_fuzzer" + +#endif // DATAMGR_SERVICE_KVDB_SERVICE_STUB_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/kvdbservicestub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn new file mode 100644 index 00000000..2db37d6e --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn @@ -0,0 +1,110 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ObjectServiceStubFuzzTest") { + module_out_path = "datamgr_service/service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/backup/include", + "${data_service_path}/service/bootstrap/include", + "${data_service_path}/service/cloud", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/data_share", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/object", + "${data_service_path}/service/permission/include", + "${data_service_path}/service/rdb", + "${kv_store_common_path}", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", + "${kv_store_distributeddb_path}", + "${kv_store_distributeddb_path}/include/", + "${kv_store_distributeddb_path}/interfaces/include/", + "${kv_store_distributeddb_path}/interfaces/include/relational", + "${dataobject_path}/frameworks/innerkitsimpl/include", + "//third_party/json/single_include", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/objectservicestub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/bootstrap/src/bootstrap.cpp", + "${data_service_path}/service/config/src/config_factory.cpp", + "${data_service_path}/service/config/src/model/backup_config.cpp", + "${data_service_path}/service/config/src/model/checker_config.cpp", + "${data_service_path}/service/config/src/model/component_config.cpp", + "${data_service_path}/service/config/src/model/directory_config.cpp", + "${data_service_path}/service/config/src/model/global_config.cpp", + "${data_service_path}/service/config/src/model/network_config.cpp", + "${data_service_path}/service/config/src/model/protocol_config.cpp", + "${data_service_path}/service/crypto/src/crypto_manager.cpp", + "${data_service_path}/service/matrix/src/device_matrix.cpp", + "${data_service_path}/service/matrix/src/matrix_event.cpp", + "${data_service_path}/service/object/object_callback_proxy.cpp", + "${data_service_path}/service/object/object_data_listener.cpp", + "${data_service_path}/service/object/object_manager.cpp", + "${data_service_path}/service/object/object_service_impl.cpp", + "${data_service_path}/service/object/object_service_stub.cpp", + "${data_service_path}/service/permission/src/permit_delegate.cpp", + "objectservicestub_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/adapter/utils:distributeddata_utils_static", + "${data_service_path}/framework:distributeddatasvcfwk", + "${kv_store_distributeddb_path}:distributeddb", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "device_manager:devicemanagersdk", + "hilog:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":ObjectServiceStubFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.cpp new file mode 100644 index 00000000..410f53b1 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "objectservicestub_fuzzer.h" + +#include +#include + +#include "object_service_impl.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DistributedObject; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.DistributedObject.IObjectService"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 4; + +bool OnRemoteRequestFuzz(const uint8_t *data, size_t size) +{ + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + std::shared_ptr objectServiceStub = std::make_shared(); + objectServiceStub->OnRemoteRequest(code, request, reply); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.h new file mode 100644 index 00000000..019e06f5 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/objectservicestub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DATAMGR_SERVICE_OBJECT_SERVICE_STUB_FUZZER_H +#define DATAMGR_SERVICE_OBJECT_SERVICE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "objectservicestub_fuzzer" + +#endif // DATAMGR_SERVICE_OBJECT_SERVICE_STUB_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn new file mode 100644 index 00000000..494fd1c0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn @@ -0,0 +1,123 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("RdbResultSetStubFuzzTest") { + module_out_path = "datamgr_service/service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/backup/include", + "${data_service_path}/service/bootstrap/include", + "${data_service_path}/service/cloud", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/data_share", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/object", + "${data_service_path}/service/permission/include", + "${data_service_path}/service/rdb", + "${kv_store_common_path}", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", + "${kv_store_distributeddb_path}", + "${kv_store_distributeddb_path}/include/", + "${kv_store_distributeddb_path}/interfaces/include/", + "${kv_store_distributeddb_path}/interfaces/include/relational", + "${dataobject_path}/frameworks/innerkitsimpl/include", + "${relational_store_path}/interfaces/inner_api/cloud_data/include", + "${relational_store_path}/interfaces/inner_api/rdb/include", + "//third_party/json/single_include", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/rdbresultsetstub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/bootstrap/src/bootstrap.cpp", + "${data_service_path}/service/config/src/config_factory.cpp", + "${data_service_path}/service/config/src/model/backup_config.cpp", + "${data_service_path}/service/config/src/model/checker_config.cpp", + "${data_service_path}/service/config/src/model/component_config.cpp", + "${data_service_path}/service/config/src/model/directory_config.cpp", + "${data_service_path}/service/config/src/model/global_config.cpp", + "${data_service_path}/service/config/src/model/network_config.cpp", + "${data_service_path}/service/config/src/model/protocol_config.cpp", + "${data_service_path}/service/crypto/src/crypto_manager.cpp", + "${data_service_path}/service/matrix/src/device_matrix.cpp", + "${data_service_path}/service/matrix/src/matrix_event.cpp", + "${data_service_path}/service/permission/src/permit_delegate.cpp", + "${data_service_path}/service/rdb/rdb_asset_loader.cpp", + "${data_service_path}/service/rdb/rdb_cloud.cpp", + "${data_service_path}/service/rdb/rdb_cloud_data_translate.cpp", + "${data_service_path}/service/rdb/rdb_cursor.cpp", + "${data_service_path}/service/rdb/rdb_general_store.cpp", + "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", + "${data_service_path}/service/rdb/rdb_query.cpp", + "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", + "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", + "${data_service_path}/service/rdb/rdb_service_impl.cpp", + "${data_service_path}/service/rdb/rdb_service_stub.cpp", + "${data_service_path}/service/rdb/rdb_store_observer_impl.cpp", + "${data_service_path}/service/rdb/rdb_syncer.cpp", + "${data_service_path}/service/rdb/rdb_watcher.cpp", + "${data_service_path}/service/rdb/value_proxy.cpp", + "rdbresultsetstub_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/adapter/utils:distributeddata_utils_static", + "${data_service_path}/framework:distributeddatasvcfwk", + "${kv_store_distributeddb_path}:distributeddb", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "device_manager:devicemanagersdk", + "hilog:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":RdbResultSetStubFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.cpp new file mode 100644 index 00000000..a1542122 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 "rdbresultsetstub_fuzzer.h" + +#include +#include + +#include "rdb_result_set_impl.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DistributedRdb; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS::NativeRdb.IResultSet"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 24; + +bool OnRemoteRequestFuzz(const uint8_t *data, size_t size) +{ + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + MessageOption option; + std::shared_ptr dbResultSet; + std::shared_ptr rdbResultSetStub = std::make_shared(dbResultSet); + rdbResultSetStub->OnRemoteRequest(code, request, reply, option); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.h new file mode 100644 index 00000000..b8f8cc37 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/rdbresultsetstub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DATAMGR_SERVICE_RDB_RESULT_SET_STUB_FUZZER_H +#define DATAMGR_SERVICE_RDB_RESULT_SET_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "rdbresultsetstub_fuzzer" + +#endif // DATAMGR_SERVICE_RDB_RESULT_SET_STUB_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn new file mode 100644 index 00000000..9fef0947 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/BUILD.gn @@ -0,0 +1,111 @@ +# 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. +##############################hydra-fuzz######################################## +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("RdbServiceStubFuzzTest") { + module_out_path = "datamgr_service/service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/backup/include", + "${data_service_path}/service/bootstrap/include", + "${data_service_path}/service/cloud", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/data_share", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/object", + "${data_service_path}/service/permission/include", + "${data_service_path}/service/rdb", + "${kv_store_common_path}", + "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", + "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", + "${kv_store_distributeddb_path}", + "${kv_store_distributeddb_path}/include/", + "${kv_store_distributeddb_path}/interfaces/include/", + "${kv_store_distributeddb_path}/interfaces/include/relational", + "${dataobject_path}/frameworks/innerkitsimpl/include", + "${relational_store_path}/interfaces/inner_api/cloud_data/include", + "${relational_store_path}/interfaces/inner_api/rdb/include", + "//third_party/json/single_include", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/rdbservicestub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/rdb/rdb_asset_loader.cpp", + "${data_service_path}/service/rdb/rdb_cloud.cpp", + "${data_service_path}/service/rdb/rdb_cloud_data_translate.cpp", + "${data_service_path}/service/rdb/rdb_cursor.cpp", + "${data_service_path}/service/rdb/rdb_general_store.cpp", + "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", + "${data_service_path}/service/rdb/rdb_query.cpp", + "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", + "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", + "${data_service_path}/service/rdb/rdb_service_impl.cpp", + "${data_service_path}/service/rdb/rdb_service_stub.cpp", + "${data_service_path}/service/rdb/rdb_store_observer_impl.cpp", + "${data_service_path}/service/rdb/rdb_syncer.cpp", + "${data_service_path}/service/rdb/rdb_watcher.cpp", + "${data_service_path}/service/rdb/value_proxy.cpp", + "rdbservicestub_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/adapter/utils:distributeddata_utils_static", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service:distributeddatasvc", + "${kv_store_distributeddb_path}:distributeddb", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "device_manager:devicemanagersdk", + "hilog:libhilog", + "huks:libhukssdk", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":RdbServiceStubFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/corpus/init new file mode 100644 index 00000000..2b595da0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/project.xml new file mode 100644 index 00000000..3fdba3e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.cpp new file mode 100644 index 00000000..aa7737e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "rdbservicestub_fuzzer.h" + +#include +#include + +#include "rdb_service_impl.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DistributedRdb; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.DistributedRdb.IRdbService"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 10; + +bool OnRemoteRequestFuzz(const uint8_t *data, size_t size) +{ + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(data, size); + request.RewindRead(0); + MessageParcel reply; + std::shared_ptr rdbServiceStub = std::make_shared(); + rdbServiceStub->OnRemoteRequest(code, request, reply); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return 0; + } + + OHOS::OnRemoteRequestFuzz(data, size); + + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.h new file mode 100644 index 00000000..582118e9 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/rdbservicestub_fuzzer/rdbservicestub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef DATAMGR_SERVICE_RDB_SERVICE_STUB_FUZZER_H +#define DATAMGR_SERVICE_RDB_SERVICE_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "rdbservicestub_fuzzer" + +#endif // DATAMGR_SERVICE_RDB_SERVICE_STUB_FUZZER_HH \ No newline at end of file -- Gitee From 55042eddee9a71ce28b83e10e739aa3f81d23e20 Mon Sep 17 00:00:00 2001 From: wanghuajian Date: Tue, 4 Jul 2023 11:45:33 +0800 Subject: [PATCH 358/437] fix delete status error when downloading asset Signed-off-by: wanghuajian --- services/distributeddataservice/service/rdb/value_proxy.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/distributeddataservice/service/rdb/value_proxy.cpp b/services/distributeddataservice/service/rdb/value_proxy.cpp index 23bac1a7..f87ef75b 100644 --- a/services/distributeddataservice/service/rdb/value_proxy.cpp +++ b/services/distributeddataservice/service/rdb/value_proxy.cpp @@ -205,6 +205,9 @@ ValueProxy::Asset::operator DistributedDB::Asset() uint32_t ValueProxy::Asset::ConvertToDataStatus(const DistributedDB::Asset &asset) { if (asset.status == DistributedDB::AssetStatus::DOWNLOADING) { + if (asset.flag == static_cast(DistributedDB::AssetOpType::DELETE)) { + return DistributedData::Asset::STATUS_DELETE; + } return DistributedData::Asset::STATUS_DOWNLOADING; } else if (asset.status == DistributedDB::AssetStatus::ABNORMAL) { return DistributedData::Asset::STATUS_ABNORMAL; -- Gitee From f8c1a28d5d8f34c1f82d6a9576bdb2f210add004 Mon Sep 17 00:00:00 2001 From: mazhao Date: Tue, 4 Jul 2023 15:04:24 +0800 Subject: [PATCH 359/437] fix alarm Signed-off-by: mazhao --- .../src/oh_adapter/src/json_object.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 86357c71..2a2a288f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -14,6 +14,7 @@ */ #include "json_object.h" + #include #include #include @@ -226,6 +227,16 @@ int JsonObject::CheckJsonRepeatField(cJSON *object, bool isFirstFloor) return ret; } +bool IsFieldNameLegal(const std::string &fieldName) +{ + for (auto oneChar : fieldName) { + if (!((isalpha(oneChar)) || (isdigit(oneChar)) || (oneChar == '_'))) { + return false; + } + } + return true; +} + int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType, bool isFirstFloor) { if (subObj == nullptr) { @@ -235,10 +246,8 @@ int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int if (subObj->string != nullptr) { fieldName = subObj->string; if (!isFirstFloor) { - for (auto oneChar : fieldName) { - if (!((isalpha(oneChar)) || (isdigit(oneChar)) || (oneChar == '_'))) { - return -E_INVALID_ARGS; - } + if (!IsFieldNameLegal(fieldName)) { + return -E_INVALID_ARGS; } } if (!fieldName.empty() && isdigit(fieldName[0])) { -- Gitee From 49dfb62d341992a2c1fb358c4e91d6a98419a14a Mon Sep 17 00:00:00 2001 From: genglingxia Date: Tue, 4 Jul 2023 21:29:27 +0800 Subject: [PATCH 360/437] fix drag cross dev codereview Signed-off-by: genglingxia --- services/distributeddataservice/service/udmf/BUILD.gn | 2 ++ .../distributeddataservice/service/udmf/data_manager.cpp | 7 ++++--- .../service/udmf/preprocess/preprocess_utils.cpp | 9 ++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index 6ca9f218..8bdf216f 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -32,6 +32,8 @@ config("module_public_config") { "${data_service_path}/service/udmf", "${kv_store_path}/frameworks/common", "${file_service_path}/interfaces/innerkits/remote_file_share/native", + "${device_manager_path}/interfaces/inner_kits/native_cpp/include", + "${data_service_path}/adapter/include/communicator" ] } diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 7d02621a..62bad77c 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -75,15 +75,16 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st auto type = record->GetType(); if (IsFileType(type)) { auto file = static_cast(record.get()); - std::string remoteUri = AppFileService::GetDfsUriFromLocal(file->GetUri(), userId); - if(remoteUri.empty()) { + std::string remoteUri = AppFileService::ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId); + if(remoteUri.empty() || remoteUri == "error") { ZLOGW("Get remoteUri failed, uri: %{public}s, remoteUri: %{public}s.", file->GetUri().c_str(), remoteUri.c_str()); return E_UNKNOWN; } + file->SetRemoteUri(remoteUri); } - record->SetUid(PreProcessUtils::GetInstance().IdGenerator()); + record->SetUid(PreProcessUtils::IdGenerator()); } diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp index 2e299617..d02b20ad 100755 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -16,7 +16,6 @@ #include "preprocess_utils.h" #include -#include "log_print.h" #include "error_code.h" #include "accesstoken_kit.h" #include "bundlemgr/bundle_mgr_client_impl.h" @@ -56,9 +55,6 @@ std::string PreProcessUtils::GetLocalDeviceId() std::string encryptedUuid; encryptedUuid = DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); - - ZLOGI("[LocalDevice] uuid:%{public}s, encryptedUuid:%{public}s, name:%{public}s, type:%{public}d", - info.uuid.c_str(), encryptedUuid.c_str(), info.deviceName.c_str(), info.deviceType); // if log uuid, need tb be anonymous; return encryptedUuid; } @@ -85,12 +81,11 @@ time_t PreProcessUtils::GetTimeStamp() return timestamp; } -int32_t PreProcessUtils::GetHapUidByToken(uint32_t tokenId) const +int32_t PreProcessUtils::GetHapUidByToken(uint32_t tokenId) { - HapTokenInfo tokenInfo; + Security::AccessToken::HapTokenInfo tokenInfo; auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo); if (result != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { - ZLOGE("token:0x%{public}x, result:%{public}d", tokenId, result); return -1; } return tokenInfo.userID; -- Gitee From 17c8f475b49560b50d54f76585df628f020de6e9 Mon Sep 17 00:00:00 2001 From: dboy190 Date: Wed, 5 Jul 2023 10:04:50 +0800 Subject: [PATCH 361/437] support p2p dev Signed-off-by: dboy190 --- .../communicator/src/app_pipe_handler.cpp | 6 +++--- .../communicator/src/app_pipe_handler.h | 4 ++-- .../adapter/communicator/src/app_pipe_mgr.cpp | 12 ++++++------ .../adapter/communicator/src/app_pipe_mgr.h | 4 ++-- .../src/communication_provider_impl.cpp | 6 +++--- .../src/communication_provider_impl.h | 4 ++-- .../src/process_communicator_impl.cpp | 5 +++-- .../communicator/src/softbus_adapter.h | 4 ++-- .../src/softbus_adapter_standard.cpp | 19 ++++++++++++++----- .../communicator/src/softbus_client.cpp | 7 ++++--- .../adapter/communicator/src/softbus_client.h | 6 +++++- .../include/communicator/commu_types.h | 15 +++++++++++++++ .../communicator/communication_provider.h | 4 ++-- .../communicator/process_communicator_impl.h | 2 +- 14 files changed, 64 insertions(+), 34 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.cpp b/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.cpp index 5a02eb33..c29f60aa 100644 --- a/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.cpp +++ b/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.cpp @@ -43,10 +43,10 @@ AppPipeHandler::AppPipeHandler(const PipeInfo &pipeInfo) softbusAdapter_ = SoftBusAdapter::GetInstance(); } -Status AppPipeHandler::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size, - const MessageInfo &info) +Status AppPipeHandler::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info) { - return softbusAdapter_->SendData(pipeInfo, deviceId, ptr, size, info); + return softbusAdapter_->SendData(pipeInfo, deviceId, dataInfo, totalLength, info); } Status AppPipeHandler::StartWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) diff --git a/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.h b/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.h index 5fe49b7e..2a2508c5 100644 --- a/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.h +++ b/services/distributeddataservice/adapter/communicator/src/app_pipe_handler.h @@ -42,8 +42,8 @@ public: // stop DataChangeListener to watch data change; Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo); // Send data to other device, function will be called back after sent to notify send result. - Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size, - const MessageInfo &info); + Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info); bool IsSameStartedOnPeer(const struct PipeInfo &pipeInfo, const struct DeviceId &peer); void SetMessageTransFlag(const PipeInfo &pipeInfo, bool flag); diff --git a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp index d6580c8b..240777a3 100644 --- a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp +++ b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp @@ -58,15 +58,15 @@ Status AppPipeMgr::StopWatchDataChange(const AppDataChangeListener *observer, co } // Send data to other device, function will be called back after sent to notify send result. -Status AppPipeMgr::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size, - const MessageInfo &info) +Status AppPipeMgr::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info) { - if (size > DataBuffer::MAX_TRANSFER_SIZE || size <= 0 || ptr == nullptr || + if (dataInfo.length > DataBuffer::MAX_TRANSFER_SIZE || dataInfo.length == 0 || dataInfo.data == nullptr || pipeInfo.pipeId.empty() || deviceId.deviceId.empty()) { - ZLOGW("Input is invalid, maxSize:%d, current size:%d", DataBuffer::MAX_TRANSFER_SIZE, size); + ZLOGW("Input is invalid, maxSize:%d, current size:%u", DataBuffer::MAX_TRANSFER_SIZE, dataInfo.length); return Status::ERROR; } - ZLOGD("pipeInfo:%s ,size:%d", pipeInfo.pipeId.c_str(), size); + ZLOGD("pipeInfo:%s ,size:%u", pipeInfo.pipeId.c_str(), dataInfo.length); std::shared_ptr appPipeHandler; { std::lock_guard lock(dataBusMapMutex_); @@ -77,7 +77,7 @@ Status AppPipeMgr::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, } appPipeHandler = it->second; } - return appPipeHandler->SendData(pipeInfo, deviceId, ptr, size, info); + return appPipeHandler->SendData(pipeInfo, deviceId, dataInfo, totalLength, info); } // start server diff --git a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.h b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.h index c942cd46..222248c5 100644 --- a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.h +++ b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.h @@ -36,8 +36,8 @@ public: Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo); // Send data to other device, function will be called back after sent to notify send result. - Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size, - const MessageInfo &info); + Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info); // start server Status Start(const PipeInfo &pipeInfo); // stop server diff --git a/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.cpp b/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.cpp index 75b71e64..ee654fcc 100644 --- a/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.cpp +++ b/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.cpp @@ -48,10 +48,10 @@ Status CommunicationProviderImpl::StopWatchDataChange(const AppDataChangeListene return appPipeMgr_.StopWatchDataChange(observer, pipeInfo); } -Status CommunicationProviderImpl::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, - int size, const MessageInfo &info) +Status CommunicationProviderImpl::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info) { - return appPipeMgr_.SendData(pipeInfo, deviceId, ptr, size, info); + return appPipeMgr_.SendData(pipeInfo, deviceId, dataInfo, totalLength, info); } Status CommunicationProviderImpl::Start(const PipeInfo &pipeInfo) diff --git a/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h b/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h index 469a7101..7838d988 100644 --- a/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h +++ b/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h @@ -36,8 +36,8 @@ public: Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) override; // Send data to other device, function will be called back after sent to notify send result. - Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size, - const MessageInfo &info) override; + Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &DataInfo, + uint32_t totalLength, const MessageInfo &info) override; // start 1 server to listen data from other devices; Status Start(const PipeInfo &pipeInfo) override; diff --git a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp index c93a2a97..5b0b3eaa 100644 --- a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp +++ b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp @@ -110,12 +110,13 @@ DBStatus ProcessCommunicatorImpl::RegOnDataReceive(const OnDataReceive &callback return DBStatus::OK; } -DBStatus ProcessCommunicatorImpl::SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length) +DBStatus ProcessCommunicatorImpl::SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, uint32_t totalLength) { PipeInfo pi = {thisProcessLabel_, ""}; + const DataInfo dataInfo = { const_cast(data), length}; DeviceId destination; destination.deviceId = dstDevInfo.identifier; - Status errCode = CommunicationProvider::GetInstance().SendData(pi, destination, data, static_cast(length)); + Status errCode = CommunicationProvider::GetInstance().SendData(pi, destination, dataInfo, totalLength); if (errCode != Status::SUCCESS) { ZLOGE("commProvider_ SendData Fail."); return DBStatus::DB_ERROR; diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h b/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h index 868d5ed1..2cd755e0 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h +++ b/services/distributeddataservice/adapter/communicator/src/softbus_adapter.h @@ -46,8 +46,8 @@ public: Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo); // Send data to other device, function will be called back after sent to notify send result. - Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *data, int size, - const MessageInfo &info); + Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info); bool IsSameStartedOnPeer(const struct PipeInfo &pipeInfo, const struct DeviceId &peer); diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp index d7c2d786..9f795a78 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp @@ -38,6 +38,7 @@ enum SoftBusAdapterErrorCode : int32_t { PEER_SESSION_NAME_INVALID, PEER_DEVICE_ID_INVALID, SESSION_SIDE_INVALID, + ROUTE_TYPE_INVALID, }; constexpr int32_t SESSION_NAME_SIZE_MAX = 65; constexpr int32_t DEVICE_ID_SIZE_MAX = 65; @@ -52,6 +53,7 @@ struct ConnDetailsInfo { char peerName[SESSION_NAME_SIZE_MAX] = ""; std::string peerDevUuid; int32_t side = -1; + int32_t routeType = -1; }; class AppDataListenerWrap { public: @@ -160,8 +162,8 @@ Status SoftBusAdapter::StopWatchDataChange(__attribute__((unused)) const AppData return Status::ERROR; } -Status SoftBusAdapter::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *data, int size, - const MessageInfo &info) +Status SoftBusAdapter::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info) { std::shared_ptr conn; { @@ -176,7 +178,7 @@ Status SoftBusAdapter::SendData(const PipeInfo &pipeInfo, const DeviceId &device } if (conn != nullptr) { - return conn->Send(data, size); + return conn->Send(dataInfo, totalLength); } return Status::ERROR; @@ -359,6 +361,13 @@ int AppDataListenerWrap::GetConnDetailsInfo(int connId, ConnDetailsInfo &connInf return SESSION_SIDE_INVALID; } + int32_t routeType = RouteType::INVALID_ROUTE_TYPE; + ret = GetSessionOption(connId, SESSION_OPTION_LINK_TYPE, &routeType, sizeof(routeType)); + if (ret != SOFTBUS_OK) { + return ROUTE_TYPE_INVALID; + } + connInfo.routeType = routeType; + return SOFTBUS_OK; } @@ -379,8 +388,8 @@ int AppDataListenerWrap::OnConnectOpened(int connId, int result) } ZLOGD("[OnConnectOpened] conn id:%{public}d, my name:%{public}s, peer name:%{public}s, " - "peer devId:%{public}s, side:%{public}d", connId, connInfo.myName, connInfo.peerName, - KvStoreUtils::ToBeAnonymous(connInfo.peerDevUuid).c_str(), connInfo.side); + "peer devId:%{public}s, side:%{public}d, routeType:%{public}d", connId, connInfo.myName, connInfo.peerName, + KvStoreUtils::ToBeAnonymous(connInfo.peerDevUuid).c_str(), connInfo.side, connInfo.routeType); return 0; } diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp index fe9601d6..dedaa0ff 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp @@ -51,6 +51,7 @@ void SoftBusClient::RestoreDefaultValue() { connId_ = INVALID_CONNECT_ID; status_ = ConnectStatus::DISCONNECT; + routeType_ = RouteType::INVALID_ROUTE_TYPE; strategy_ = Strategy::DEFAULT; mtu_ = DEFAULT_MTU_SIZE; } @@ -61,7 +62,7 @@ uint32_t SoftBusClient::GetMtuSize() const return mtu_; } -Status SoftBusClient::Send(const uint8_t *data, int size) +Status SoftBusClient::Send(const DataInfo &dataInfo, uint32_t totalLength) { std::lock_guard lock(mutex_); auto result = OpenConnect(); @@ -69,8 +70,8 @@ Status SoftBusClient::Send(const uint8_t *data, int size) return result; } - ZLOGD("send data connId:%{public}d, data size:%{public}d.", connId_, size); - int32_t ret = SendBytes(connId_, data, size); + ZLOGD("send data connId:%{public}d, data size:%{public}u.", connId_, dataInfo.length); + int32_t ret = SendBytes(connId_, dataInfo.data, dataInfo.length); if (ret != SOFTBUS_OK) { ZLOGE("send data to connId%{public}d failed, ret:%{public}d.", connId_, ret); return Status::ERROR; diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.h b/services/distributeddataservice/adapter/communicator/src/softbus_client.h index 4a434606..9b8edd9a 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.h +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.h @@ -19,6 +19,7 @@ #include #include +#include "commu_types.h" #include "communication_strategy.h" #include "session.h" #include "softbus_bus_center.h" @@ -30,7 +31,7 @@ public: ~SoftBusClient(); using Strategy = CommunicationStrategy::Strategy; - Status Send(const uint8_t *data, int size); + Status Send(const DataInfo &dataInfo, uint32_t totalLength); bool operator==(int32_t connId) const; bool operator==(const std::string &deviceId) const; uint32_t GetMtuSize() const; @@ -50,7 +51,10 @@ private: static constexpr int32_t INVALID_CONNECT_ID = -1; static constexpr uint32_t WAIT_MAX_TIME = 10; static constexpr uint32_t DEFAULT_MTU_SIZE = 4096u; + static constexpr uint32_t P2P_SIZE_THRESHOLD = 0x10000u; // 64KB + static constexpr float SWITCH_DELAY_FACTOR = 0.6f; // 64KB int32_t connId_ = INVALID_CONNECT_ID; + int32_t routeType_ = RouteType::INVALID_ROUTE_TYPE; Strategy strategy_ = Strategy::DEFAULT; ConnectStatus status_ = ConnectStatus::DISCONNECT; std::mutex mutex_; diff --git a/services/distributeddataservice/adapter/include/communicator/commu_types.h b/services/distributeddataservice/adapter/include/communicator/commu_types.h index ca822697..bcd72794 100644 --- a/services/distributeddataservice/adapter/include/communicator/commu_types.h +++ b/services/distributeddataservice/adapter/include/communicator/commu_types.h @@ -35,6 +35,21 @@ enum DeviceType { OTHERS, }; +enum RouteType : int32_t { + INVALID_ROUTE_TYPE = -1, + ROUTE_TYPE_ALL = 0, + WIFI_STA = 1, + WIFI_P2P = 2, + BT_BR = 3, + BT_BLE = 4, + BUTT = 5, +}; + +struct DataInfo { + uint8_t *data; + uint32_t length; +}; + struct API_EXPORT PipeInfo { std::string pipeId; std::string userId; diff --git a/services/distributeddataservice/adapter/include/communicator/communication_provider.h b/services/distributeddataservice/adapter/include/communicator/communication_provider.h index 0418b0c3..b0295285 100644 --- a/services/distributeddataservice/adapter/include/communicator/communication_provider.h +++ b/services/distributeddataservice/adapter/include/communicator/communication_provider.h @@ -45,8 +45,8 @@ public: virtual Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) = 0; // Send data to other device, function will be called back after sent to notify send result - virtual Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const uint8_t *ptr, int size, - const MessageInfo &info = { MessageType::DEFAULT }) = 0; + virtual Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, + uint32_t totalLength, const MessageInfo &info = { MessageType::DEFAULT }) = 0; // start one server to listen data from other devices; virtual Status Start(const PipeInfo &pipeInfo) = 0; diff --git a/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h b/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h index 26146c6f..17219b11 100644 --- a/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h +++ b/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h @@ -45,7 +45,7 @@ public: DBStatus RegOnDeviceChange(const OnDeviceChange &callback) override; DBStatus RegOnDataReceive(const OnDataReceive &callback) override; - DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length) override; + DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, uint32_t totalLength) override; uint32_t GetMtuSize() override; uint32_t GetMtuSize(const DeviceInfos &devInfo) override; DeviceInfos GetLocalDeviceInfos() override; -- Gitee From 495675d663e8a84e0dfdf5da9fee9ef0a5645c4f Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Wed, 5 Jul 2023 10:32:39 +0800 Subject: [PATCH 362/437] del unused code Signed-off-by: zuojiangjiang --- .../service/rdb/rdb_general_store.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 88a5e0eb..ed0034b3 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -70,14 +70,6 @@ RdbGeneralStore::RdbGeneralStore(const StoreMetaData &meta) : manager_(meta.appI } option.observer = &observer_; manager_.OpenStore(meta.dataDir, meta.storeId, option, delegate_); - RdbStoreConfig config(meta.dataDir); - config.SetCreateNecessary(false); - RdbOpenCallbackImpl callback; - int32_t errCode = NativeRdb::E_OK; - store_ = RdbHelper::GetRdbStore(config, -1, callback, errCode); - if (errCode != NativeRdb::E_OK) { - ZLOGE("GetRdbStore failed, errCode is %{public}d, storeId is %{public}s", errCode, meta.storeId.c_str()); - } } RdbGeneralStore::~RdbGeneralStore() -- Gitee From e8d63d204eb648c3cc2bda05d353930ce8674596 Mon Sep 17 00:00:00 2001 From: mazhao Date: Wed, 5 Jul 2023 11:18:58 +0800 Subject: [PATCH 363/437] fix alarm Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/executor/document/check_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h index e9ae1180..d43aa552 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.h @@ -32,7 +32,7 @@ public: static int CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector> &filterPath); static int CheckIdFormat(JsonObject &filterJson, bool &isIdExisit); static int CheckDocument(JsonObject &documentObj); - static int CheckUpdata(JsonObject &updata); + static int CheckUpdata(JsonObject &updataObj); static int CheckProjection(JsonObject &projectionObj, std::vector> &path); }; using Key = std::vector; -- Gitee From d6e557deff39e9ffe016e43acf9cd38a2bd63457 Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 5 Jul 2023 15:16:16 +0800 Subject: [PATCH 364/437] fix bug Signed-off-by: htt1997 --- .../framework/include/store/general_store.h | 4 ++ .../framework/store/auto_cache.cpp | 7 ++- .../service/kvdb/user_delegate.cpp | 7 +-- .../service/rdb/rdb_general_store.cpp | 62 ++++++++++++++++--- .../service/rdb/rdb_general_store.h | 5 ++ .../service/rdb/rdb_service_impl.cpp | 13 +--- .../service/rdb/rdb_service_impl.h | 4 -- 7 files changed, 72 insertions(+), 30 deletions(-) diff --git a/services/distributeddataservice/framework/include/store/general_store.h b/services/distributeddataservice/framework/include/store/general_store.h index 0da33a6e..f28df99d 100644 --- a/services/distributeddataservice/framework/include/store/general_store.h +++ b/services/distributeddataservice/framework/include/store/general_store.h @@ -85,6 +85,10 @@ public: virtual int32_t Unwatch(int32_t origin, Watcher &watcher) = 0; virtual int32_t Close() = 0; + + virtual int32_t AddRef() = 0; + + virtual int32_t Release() = 0; }; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_STORE_GENERAL_STORE_H diff --git a/services/distributeddataservice/framework/store/auto_cache.cpp b/services/distributeddataservice/framework/store/auto_cache.cpp index 381c9cb7..8b443036 100644 --- a/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/services/distributeddataservice/framework/store/auto_cache.cpp @@ -161,6 +161,7 @@ AutoCache::Delegate::~Delegate() if (store_ != nullptr) { store_->Unwatch(Origin::ORIGIN_ALL, *this); store_->Close(); + store_->Release(); store_ = nullptr; } } @@ -168,7 +169,11 @@ AutoCache::Delegate::~Delegate() AutoCache::Delegate::operator Store() { time_ = std::chrono::steady_clock::now() + std::chrono::minutes(INTERVAL); - return Store(store_, [](GeneralStore *) {}); + if (store_ != nullptr) { + store_->AddRef(); + return Store(store_, [](GeneralStore *store) { store->Release(); }); + } + return nullptr; } bool AutoCache::Delegate::operator<(const AutoCache::Time &time) const diff --git a/services/distributeddataservice/service/kvdb/user_delegate.cpp b/services/distributeddataservice/service/kvdb/user_delegate.cpp index 2cd03d0f..1d245bf9 100644 --- a/services/distributeddataservice/service/kvdb/user_delegate.cpp +++ b/services/distributeddataservice/service/kvdb/user_delegate.cpp @@ -26,12 +26,7 @@ namespace OHOS::DistributedData { using namespace OHOS::DistributedKv; std::string GetLocalDeviceId() { - static std::string deviceId; - if (deviceId.empty()) { - deviceId = DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid; - } - - return deviceId; + return DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid; } std::vector UserDelegate::GetLocalUserStatus() diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 88a5e0eb..222e6c2b 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -27,6 +27,7 @@ #include "rdb_query.h" #include "rdb_syncer.h" #include "relational_store_manager.h" +#include "utils/anonymous.h" #include "value_proxy.h" namespace OHOS::DistributedRdb { using namespace DistributedData; @@ -104,9 +105,7 @@ int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) bindInfo_ = std::move(bindInfo); rdbCloud_ = std::make_shared(bindInfo_.db_); - delegate_->SetCloudDB(rdbCloud_); rdbLoader_ = std::make_shared(bindInfo_.loader_); - delegate_->SetIAssetLoader(rdbLoader_); DBSchema schema; schema.tables.resize(database.tables.size()); for (size_t i = 0; i < database.tables.size(); i++) { @@ -122,6 +121,13 @@ int32_t RdbGeneralStore::Bind(const Database &database, BindInfo bindInfo) dbTable.fields.push_back(std::move(dbField)); } } + std::unique_lock lock(rwMutex_); + if (delegate_ == nullptr) { + ZLOGE("database:%{public}s already closed!", Anonymous::Change(database.name).c_str()); + return GeneralError::E_ALREADY_CLOSED; + } + delegate_->SetCloudDB(rdbCloud_); + delegate_->SetIAssetLoader(rdbLoader_); delegate_->SetCloudDbSchema(std::move(schema)); return GeneralError::E_OK; } @@ -133,17 +139,18 @@ bool RdbGeneralStore::IsBound() int32_t RdbGeneralStore::Close() { - auto status = manager_.CloseStore(delegate_); - if (status != DBStatus::OK) { - return status; - } - delegate_ = nullptr; store_ = nullptr; bindInfo_.loader_ = nullptr; bindInfo_.db_->Close(); bindInfo_.db_ = nullptr; rdbCloud_ = nullptr; rdbLoader_ = nullptr; + std::unique_lock lock(rwMutex_); + auto status = manager_.CloseStore(delegate_); + if (status != DBStatus::OK) { + return status; + } + delegate_ = nullptr; return 0; } @@ -188,6 +195,13 @@ int32_t RdbGeneralStore::Sync(const Devices &devices, int32_t mode, GenQuery &qu dbQuery = rdbQuery->query_; } auto dbMode = DistributedDB::SyncMode(mode); + std::shared_lock lock(rwMutex_); + if (delegate_ == nullptr) { + ZLOGE("store already closed! devices count:%{public}zu, the 1st:%{public}s, mode:%{public}d, " + "wait:%{public}d", + devices.size(), devices.empty() ? "null" : Anonymous::Change(*devices.begin()).c_str(), mode, wait); + return GeneralError::E_ALREADY_CLOSED; + } auto status = (mode < NEARBY_END) ? delegate_->Sync(devices, dbMode, dbQuery, GetDBBriefCB(std::move(async)), wait) : (mode > NEARBY_END && mode < CLOUD_END) @@ -203,6 +217,14 @@ int32_t RdbGeneralStore::Clean(const std::vector &devices, int32_t } int32_t dbMode; DBStatus status; + std::shared_lock lock(rwMutex_); + if (delegate_ == nullptr) { + ZLOGE("store already closed! devices count:%{public}zu, the 1st:%{public}s, mode:%{public}d, " + "tableName:%{public}s", + devices.size(), devices.empty() ? "null" : Anonymous::Change(*devices.begin()).c_str(), mode, + Anonymous::Change(tableName).c_str()); + return GeneralError::E_ALREADY_CLOSED; + } switch (mode) { case CloudService::CLEAR_CLOUD_INFO: dbMode = CleanMode::CLOUD_INFO; @@ -295,6 +317,32 @@ RdbGeneralStore::DBProcessCB RdbGeneralStore::GetDBProcessCB(DetailAsync async) }; } +int32_t RdbGeneralStore::Release() +{ + auto ref = 1; + { + std::lock_guard lock(mutex_); + if (ref_ == 0) { + return 0; + } + ref = --ref_; + } + ZLOGD("ref:%{public}d", ref); + if (ref == 0) { + delete this; + } + return ref; +} + +int32_t RdbGeneralStore::AddRef() +{ + std::lock_guard lock(mutex_); + if (ref_ == 0) { + return 0; + } + return ++ref_; +} + void RdbGeneralStore::ObserverProxy::OnChange(const DBChangedIF &data) { if (!HasWatcher()) { diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 3213be87..01db30b3 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -53,6 +53,8 @@ public: int32_t Watch(int32_t origin, Watcher &watcher) override; int32_t Unwatch(int32_t origin, Watcher &watcher) override; int32_t Close() override; + int32_t AddRef() override; + int32_t Release() override; private: using RdbDelegate = DistributedDB::RelationalStoreDelegate; @@ -88,6 +90,9 @@ private: std::shared_ptr rdbLoader_ {}; BindInfo bindInfo_; std::atomic isBound_ = false; + std::mutex mutex_; + int32_t ref_ = 1; + mutable std::shared_mutex rwMutex_; }; } // namespace OHOS::DistributedRdb #endif // OHOS_DISTRIBUTED_DATA_DATAMGR_SERVICE_RDB_GENERAL_STORE_H diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 6134d454..491d38e3 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -143,6 +143,7 @@ int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, Distrib int32_t RdbServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) { OnClientDied(pid); + AutoCache::GetInstance().CloseStore(tokenId); return E_OK; } @@ -652,16 +653,4 @@ int32_t RdbServiceImpl::OnBind(const BindInfo &bindInfo) executors_ = bindInfo.executors; return 0; } - -int32_t RdbServiceImpl::OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) -{ - AutoCache::GetInstance().CloseStore(tokenId); - return E_OK; -} - -int32_t RdbServiceImpl::OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) -{ - AutoCache::GetInstance().CloseStore(tokenId); - return E_OK; -} } // namespace OHOS::DistributedRdb diff --git a/services/distributeddataservice/service/rdb/rdb_service_impl.h b/services/distributeddataservice/service/rdb/rdb_service_impl.h index 29d87b0e..061e5489 100644 --- a/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -66,10 +66,6 @@ public: int32_t OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) override; - int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; - - int32_t OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; - int32_t GetSchema(const RdbSyncerParam ¶m) override; int32_t OnBind(const BindInfo &bindInfo) override; -- Gitee From 0b35e50d4e4eb172a11f0e15d42f585c6a1f714e Mon Sep 17 00:00:00 2001 From: htt1997 Date: Wed, 5 Jul 2023 16:48:07 +0800 Subject: [PATCH 365/437] fix:lock timing in close Signed-off-by: htt1997 --- .../service/rdb/rdb_general_store.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 222e6c2b..990dccf7 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -139,18 +139,21 @@ bool RdbGeneralStore::IsBound() int32_t RdbGeneralStore::Close() { - store_ = nullptr; - bindInfo_.loader_ = nullptr; - bindInfo_.db_->Close(); - bindInfo_.db_ = nullptr; - rdbCloud_ = nullptr; - rdbLoader_ = nullptr; std::unique_lock lock(rwMutex_); + if (delegate_ == nullptr) { + return 0; + } auto status = manager_.CloseStore(delegate_); if (status != DBStatus::OK) { return status; } delegate_ = nullptr; + store_ = nullptr; + bindInfo_.loader_ = nullptr; + bindInfo_.db_->Close(); + bindInfo_.db_ = nullptr; + rdbCloud_ = nullptr; + rdbLoader_ = nullptr; return 0; } -- Gitee From cbf79842e5c438d91acbabe59ea3e953e0221047 Mon Sep 17 00:00:00 2001 From: mazhao Date: Wed, 5 Jul 2023 17:08:24 +0800 Subject: [PATCH 366/437] fix alarm Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 2a2a288f..973f115b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -155,10 +155,10 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) { std::queue cjsonQueue; cjsonQueue.push(item); - while (!cjsonQueue.empty()) { + while (!cjsonQueue.empty()) { // node is not null all the time cJSON *node = cjsonQueue.front(); cjsonQueue.pop(); - if (node != NULL && cJSON_IsNumber(node)) { + if (cJSON_IsNumber(node)) { double value = cJSON_GetNumberValue(node); if (value > __DBL_MAX__ || value < -__DBL_MAX__) { errCode = -E_INVALID_ARGS; -- Gitee From a8116fabab77c101809ea9a496c67d7a020c8598 Mon Sep 17 00:00:00 2001 From: mazhao Date: Wed, 5 Jul 2023 17:31:13 +0800 Subject: [PATCH 367/437] fix alarm Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 973f115b..f72ad01c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -155,7 +155,7 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) { std::queue cjsonQueue; cjsonQueue.push(item); - while (!cjsonQueue.empty()) { // node is not null all the time + while (!cjsonQueue.empty()) { //node is not null all the time cJSON *node = cjsonQueue.front(); cjsonQueue.pop(); if (cJSON_IsNumber(node)) { -- Gitee From bb85850d900efbd29317b70f72c7e974b0ed6fc4 Mon Sep 17 00:00:00 2001 From: mazhao Date: Wed, 5 Jul 2023 17:37:27 +0800 Subject: [PATCH 368/437] fix alarm Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index f72ad01c..33bab7ce 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -155,7 +155,7 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) { std::queue cjsonQueue; cjsonQueue.push(item); - while (!cjsonQueue.empty()) { //node is not null all the time + while (!cjsonQueue.empty()) { cJSON *node = cjsonQueue.front(); cjsonQueue.pop(); if (cJSON_IsNumber(node)) { -- Gitee From 27427e8dbc7ac013bba928da4b8e184f87004522 Mon Sep 17 00:00:00 2001 From: mazhao Date: Wed, 5 Jul 2023 17:38:11 +0800 Subject: [PATCH 369/437] fix alarm Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 33bab7ce..7236e024 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -158,7 +158,7 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) while (!cjsonQueue.empty()) { cJSON *node = cjsonQueue.front(); cjsonQueue.pop(); - if (cJSON_IsNumber(node)) { + if (cJSON_IsNumber(node)) { // node is not null all the time double value = cJSON_GetNumberValue(node); if (value > __DBL_MAX__ || value < -__DBL_MAX__) { errCode = -E_INVALID_ARGS; -- Gitee From bb98d6e28338317f1d7dbc966631eacbf08d0dd4 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Thu, 6 Jul 2023 09:57:56 +0800 Subject: [PATCH 370/437] add OnAppExit Signed-off-by: niudongyao --- .idea/workspace.xml | 7 ++- .../data_share/data_share_service_impl.cpp | 4 +- .../published_data_subscriber_manager.cpp | 48 ++++++----------- .../published_data_subscriber_manager.h | 21 +------- .../rdb_subscriber_manager.cpp | 52 +++++++------------ .../rdb_subscriber_manager.h | 21 +------- 6 files changed, 44 insertions(+), 109 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 58df6bd9..fd11f428 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,7 +7,12 @@ + + + + + diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index b3e34324..af1500da 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -463,8 +463,10 @@ int32_t DataShareServiceImpl::OnAppUninstall( int32_t DataShareServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) { - ZLOGI("ObjectServiceImpl::OnAppExit uid=%{public}d, pid=%{public}d, tokenId=%{public}d, bundleName=%{public}s", + ZLOGI("AppExit uid=%{public}d, pid=%{public}d, tokenId=%{public}d, bundleName=%{public}s", uid, pid, tokenId, bundleName.c_str()); + RdbSubscriberManager::GetInstance().Delete(tokenId); + PublishedDataSubscriberManager::GetInstance().Delete(tokenId); return EOK; } diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index fbcb92d6..3f6eec09 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -29,45 +29,12 @@ PublishedDataSubscriberManager &PublishedDataSubscriberManager::GetInstance() return manager; } -void PublishedDataSubscriberManager::LinkToDeath( - const PublishedDataKey &key, sptr observer) -{ - sptr deathRecipient = new (std::nothrow) ObserverNodeRecipient(this, key, observer); - if (deathRecipient == nullptr) { - ZLOGE("new ObserverNodeRecipient error. uri is %{public}s", - DistributedData::Anonymous::Change(key.key).c_str()); - return; - } - auto remote = observer->AsObject(); - if (!remote->AddDeathRecipient(deathRecipient)) { - ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); - return; - } - ZLOGD("link to death success, uri is %{public}s", DistributedData::Anonymous::Change(key.key).c_str()); -} - -void PublishedDataSubscriberManager::OnRemoteDied( - const PublishedDataKey &key, sptr observer) -{ - publishedDataCache.ComputeIfPresent(key, [&observer, this](const auto &key, std::vector &value) { - for (auto it = value.begin(); it != value.end(); ++it) { - if (it->observer->AsObject() == observer->AsObject()) { - value.erase(it); - ZLOGI("OnRemoteDied delete subscriber, uri is %{public}s", - DistributedData::Anonymous::Change(key.key).c_str()); - break; - } - } - return !value.empty(); - }); -} int PublishedDataSubscriberManager::Add( const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId) { publishedDataCache.Compute( key, [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); - LinkToDeath(key, observer); value.emplace_back(observer, callerTokenId); return true; }); @@ -92,6 +59,21 @@ int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, const ui return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } +void PublishedDataSubscriberManager::Delete(const uint32_t callerTokenId) +{ + publishedDataCache.EraseIf([&callerTokenId](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end();) { + if (it->callerTokenId == callerTokenId) { + ZLOGI("erase start, uri is %{private}s, tokenId is %{public}d", key.key.c_str(), callerTokenId); + it = value.erase(it); + } else { + it++; + } + } + return value.empty(); + }); +} + int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, const uint32_t callerTokenId) { auto result = diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index 4e078165..06c1a30d 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -44,6 +44,7 @@ public: int Add(const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId); int Delete(const PublishedDataKey &key, const uint32_t callerTokenId); + void Delete(const uint32_t callerTokenId); int Disable(const PublishedDataKey &key, const uint32_t callerTokenId); int Enable(const PublishedDataKey &key, const uint32_t callerTokenId); void Emit(const std::vector &keys, const int32_t userId, const std::string &ownerBundleName, @@ -57,26 +58,6 @@ private: uint32_t callerTokenId; bool enabled = true; }; - class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { - public: - ObserverNodeRecipient(PublishedDataSubscriberManager *owner, const PublishedDataKey &key, - sptr observer) : owner_(owner), key_(key), observer_(observer) {}; - - void OnRemoteDied(const wptr &object) override - { - if (owner_ != nullptr) { - owner_->OnRemoteDied(key_, observer_); - } - } - - private: - PublishedDataSubscriberManager *owner_; - PublishedDataKey key_; - sptr observer_; - }; - - void LinkToDeath(const PublishedDataKey &key, sptr observer); - void OnRemoteDied(const PublishedDataKey &key, sptr observer); PublishedDataSubscriberManager() = default; void PutInto(std::map, std::vector> &, diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index a3110b9e..ad2583f4 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -107,39 +107,6 @@ RdbSubscriberManager &RdbSubscriberManager::GetInstance() return manager; } -void RdbSubscriberManager::LinkToDeath(const Key &key, sptr observer) -{ - sptr deathRecipient = new (std::nothrow) ObserverNodeRecipient(this, key, observer); - if (deathRecipient == nullptr) { - ZLOGE("new ObserverNodeRecipient error, uri is %{public}s", - DistributedData::Anonymous::Change(key.uri).c_str()); - return; - } - auto remote = observer->AsObject(); - if (!remote->AddDeathRecipient(deathRecipient)) { - ZLOGE("add death recipient failed, uri is %{public}s", DistributedData::Anonymous::Change(key.uri).c_str()); - return; - } - ZLOGD("link to death success, uri is %{public}s", DistributedData::Anonymous::Change(key.uri).c_str()); -} - -void RdbSubscriberManager::OnRemoteDied(const Key &key, sptr observer) -{ - rdbCache_.ComputeIfPresent(key, [&observer, this](const auto &key, std::vector &value) { - for (auto it = value.begin(); it != value.end(); ++it) { - if (it->observer->AsObject() == observer->AsObject()) { - value.erase(it); - ZLOGI("OnRemoteDied delete subscriber, uri is %{public}s", - DistributedData::Anonymous::Change(key.uri).c_str()); - break; - } - } - if (GetEnableObserverCount(key) == 0) { - SchedulerManager::GetInstance().RemoveTimer(key); - } - return !value.empty(); - }); -} int RdbSubscriberManager::Add(const Key &key, const sptr observer, std::shared_ptr context, std::shared_ptr executorPool) { @@ -156,7 +123,6 @@ int RdbSubscriberManager::Add(const Key &key, const sptr }; executorPool->Execute(task); value.emplace_back(observer, context->callerTokenId); - LinkToDeath(key, observer); if (GetEnableObserverCount(key) == 1) { SchedulerManager::GetInstance().Execute( key, context->currentUserId, context->calledSourceDir, context->version); @@ -187,6 +153,24 @@ int RdbSubscriberManager::Delete(const Key &key, const uint32_t callerTokenId) return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } +void RdbSubscriberManager::Delete(const uint32_t callerTokenId) +{ + rdbCache_.EraseIf([&callerTokenId, this](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end();) { + if (it->callerTokenId == callerTokenId) { + ZLOGI("erase start, uri is %{private}s, tokenId %{public}d", key.uri.c_str(), callerTokenId); + it = value.erase(it); + } else { + it++; + } + } + if (GetEnableObserverCount(key) == 0) { + SchedulerManager::GetInstance().RemoveTimer(key); + } + return value.empty(); + }); +} + int RdbSubscriberManager::Disable(const Key &key, const uint32_t callerTokenId) { auto result = diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h index 3f69ed25..bcc7d0ec 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h @@ -55,6 +55,7 @@ public: int Add(const Key &key, const sptr observer, std::shared_ptr context, std::shared_ptr executorPool); int Delete(const Key &key, const uint32_t callerTokenId); + void Delete(const uint32_t callerTokenId); int Disable(const Key &key, const uint32_t callerTokenId); int Enable(const Key &key, std::shared_ptr context); void Emit(const std::string &uri, std::shared_ptr context); @@ -71,26 +72,6 @@ private: bool enabled = true; }; - class ObserverNodeRecipient : public IRemoteObject::DeathRecipient { - public: - ObserverNodeRecipient(RdbSubscriberManager *owner, const Key &key, sptr observer) - : owner_(owner), key_(key), observer_(observer) {}; - - void OnRemoteDied(const wptr &object) override - { - if (owner_ != nullptr) { - owner_->OnRemoteDied(key_, observer_); - } - } - - private: - RdbSubscriberManager *owner_; - Key key_; - sptr observer_; - }; - - void LinkToDeath(const Key &key, sptr observer); - void OnRemoteDied(const Key &key, sptr observer); RdbSubscriberManager() = default; ConcurrentMap> rdbCache_; int Notify(const Key &key, const int32_t userId, const std::vector &val, const std::string &rdbDir, -- Gitee From 7979e822b2137c84dd23c7edd4e2f3eb244ebf2d Mon Sep 17 00:00:00 2001 From: niudongyao Date: Thu, 6 Jul 2023 09:58:53 +0800 Subject: [PATCH 371/437] add OnAppExit Signed-off-by: niudongyao --- .idea/workspace.xml | 65 --------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index fd11f428..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1688093771186 - - - - - - - - - \ No newline at end of file -- Gitee From c24a44cf7af419ae02559d47d8adedaa79776709 Mon Sep 17 00:00:00 2001 From: mazhao Date: Thu, 6 Jul 2023 10:48:45 +0800 Subject: [PATCH 372/437] fix alarm Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 7236e024..a462e971 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -158,6 +158,10 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) while (!cjsonQueue.empty()) { cJSON *node = cjsonQueue.front(); cjsonQueue.pop(); + if (node == nullptr) { + errCode = -E_INVALID_ARGS; + break; + } if (cJSON_IsNumber(node)) { // node is not null all the time double value = cJSON_GetNumberValue(node); if (value > __DBL_MAX__ || value < -__DBL_MAX__) { -- Gitee From ba62d9e4fbc71602497adc8c6aafcfc7a8b54b7e Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Thu, 6 Jul 2023 14:48:09 +0800 Subject: [PATCH 373/437] modify bundle.json Signed-off-by: ding_dong_dong --- bundle.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 3b5839ad..326a05ab 100644 --- a/bundle.json +++ b/bundle.json @@ -77,7 +77,7 @@ "udmf" ], "third_party": [ - "cjson", + "cJSON", "jsoncpp", "libuv", "openssl", -- Gitee From e348552c589ddaae19df2db24080e7aa5154f4e3 Mon Sep 17 00:00:00 2001 From: dboy190 Date: Thu, 6 Jul 2023 16:19:47 +0800 Subject: [PATCH 374/437] support p2p dev update Signed-off-by: dboy190 --- .../communicator/src/softbus_client.cpp | 94 ++++++++++++++++--- .../adapter/communicator/src/softbus_client.h | 10 +- 2 files changed, 85 insertions(+), 19 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp index dedaa0ff..872379be 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp @@ -65,7 +65,7 @@ uint32_t SoftBusClient::GetMtuSize() const Status SoftBusClient::Send(const DataInfo &dataInfo, uint32_t totalLength) { std::lock_guard lock(mutex_); - auto result = OpenConnect(); + auto result = OpenConnect(totalLength); if (result != Status::SUCCESS) { return result; } @@ -80,30 +80,81 @@ Status SoftBusClient::Send(const DataInfo &dataInfo, uint32_t totalLength) return Status::SUCCESS; } -Status SoftBusClient::OpenConnect() +Status SoftBusClient::OpenConnect(uint32_t totalLength) { + strategy_ = CommunicationStrategy::GetInstance().GetStrategy(device_.deviceId); if (status_ == ConnectStatus::CONNECT_OK) { - return Status::SUCCESS; + auto result = SwitchChannel(totalLength); + if (result != Status::SUCCESS) { + status_ = ConnectStatus::DISCONNECT; + } + return result; } - auto result = Open(); + auto result = CreateChannel(totalLength); if (result != Status::SUCCESS) { return result; } status_ = ConnectStatus::CONNECT_OK; - UpdateMtuSize(); return Status::SUCCESS; } -Status SoftBusClient::Open() +Status SoftBusClient::SwitchChannel(uint32_t totalLength) +{ + if (strategy_ == Strategy::BUTT) { + return Status::NETWORK_ERROR; + } + + if (strategy_ == Strategy::ON_LINE_SELECT_CHANNEL) { + return Status::SUCCESS; + } + + if (routeType_ == RouteType::WIFI_STA) { + return Status::SUCCESS; + } + + if (routeType_ == RouteType::BT_BLE || routeType_ == RouteType::BT_BR) { + if (totalLength < P2P_SIZE_THRESHOLD) { + return Status::SUCCESS; + } + + RestoreDefaultValue(); + return Open(GetSessionAttribute(true)); + } + + if (routeType_ == RouteType::WIFI_P2P) { + if (totalLength > P2P_SIZE_THRESHOLD * SWITCH_DELAY_FACTOR) { + return Status::SUCCESS; + } + + CloseSession(connId_); + RestoreDefaultValue(); + return Open(GetSessionAttribute(false)); + } +} + +Status SoftBusClient::CreateChannel(uint32_t totalLength) +{ + if (strategy_ == Strategy::BUTT) { + return Status::NETWORK_ERROR; + } + + if (strategy_ == Strategy::ON_LINE_SELECT_CHANNEL) { + return Open(GetSessionAttribute(true)); + } + + if (totalLength < P2P_SIZE_THRESHOLD) { + return Open(GetSessionAttribute(false)); + } + return Open(GetSessionAttribute(true)); +} + +Status SoftBusClient::Open(SessionAttribute attr) { - Strategy strategy = CommunicationStrategy::GetInstance().GetStrategy(device_.deviceId); - SessionAttribute attr = { 0 }; - InitSessionAttribute(strategy, attr); int id = OpenSession(pipe_.pipeId.c_str(), pipe_.pipeId.c_str(), DmAdapter::GetInstance().ToNetworkID(device_.deviceId).c_str(), "GROUP_ID", &attr); - ZLOGI("open %{public}s,session:%{public}s,connId:%{public}d,linkNum:%{public}d,strategy:%{public}d", - KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), id, attr.linkTypeNum, strategy); + ZLOGI("open %{public}s,session:%{public}s,connId:%{public}d,linkNum:%{public}d", + KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), id, attr.linkTypeNum); if (id < 0) { ZLOGW("Open %{public}s, type:%{public}d failed, connId:%{public}d", pipe_.pipeId.c_str(), attr.dataType, id); @@ -111,22 +162,34 @@ Status SoftBusClient::Open() } connId_ = id; - strategy_ = strategy; int state = getConnStatus_(connId_); ZLOGI("waited for notification, state:%{public}d connId:%{public}d", state, id); if (state != SOFTBUS_OK) { ZLOGE("open callback result error"); return Status::NETWORK_ERROR; } + + int32_t routeType = RouteType::INVALID_ROUTE_TYPE; + auto ret = GetSessionOption(connId_, SESSION_OPTION_LINK_TYPE, &routeType, sizeof(routeType)); + if (ret != SOFTBUS_OK) { + ZLOGE("get routeType failed, session:%{public}s, connId:%{public}d", pipe_.pipeId.c_str(), connId_); + return Status::NETWORK_ERROR; + } + routeType_ = routeType; + + UpdateMtuSize(); + ZLOGI("open %{public}s, session:%{public}s success, connId:%{public}d, routeType:%{public}d", + KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), connId_, routeType_); return Status::SUCCESS; } -void SoftBusClient::InitSessionAttribute(Strategy strategy, SessionAttribute &attr) +SessionAttribute SoftBusClient::GetSessionAttribute(bool isP2P) { + SessionAttribute attr; attr.dataType = TYPE_BYTES; // If the dataType is BYTES, the default strategy is wifi_5G > wifi_2.4G > BR, without P2P; - if (strategy == Strategy::DEFAULT) { - return; + if (!isP2P) { + return attr; } int index = 0; @@ -135,6 +198,7 @@ void SoftBusClient::InitSessionAttribute(Strategy strategy, SessionAttribute &at attr.linkType[index++] = LINK_TYPE_WIFI_P2P; attr.linkType[index++] = LINK_TYPE_BR; attr.linkTypeNum = index; + return attr; } void SoftBusClient::UpdateMtuSize() diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.h b/services/distributeddataservice/adapter/communicator/src/softbus_client.h index 9b8edd9a..a99d9b1c 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.h +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.h @@ -42,9 +42,11 @@ private: DISCONNECT, }; - Status OpenConnect(); - Status Open(); - void InitSessionAttribute(Strategy strategy, SessionAttribute &attr); + Status OpenConnect(uint32_t totalLength); + Status SwitchChannel(uint32_t totalLength); + Status CreateChannel(uint32_t totalLength); + Status Open(SessionAttribute attr); + SessionAttribute GetSessionAttribute(bool isP2P); void RestoreDefaultValue(); void UpdateMtuSize(); @@ -52,7 +54,7 @@ private: static constexpr uint32_t WAIT_MAX_TIME = 10; static constexpr uint32_t DEFAULT_MTU_SIZE = 4096u; static constexpr uint32_t P2P_SIZE_THRESHOLD = 0x10000u; // 64KB - static constexpr float SWITCH_DELAY_FACTOR = 0.6f; // 64KB + static constexpr float SWITCH_DELAY_FACTOR = 0.6f; int32_t connId_ = INVALID_CONNECT_ID; int32_t routeType_ = RouteType::INVALID_ROUTE_TYPE; Strategy strategy_ = Strategy::DEFAULT; -- Gitee From 73b64053cb62aadb850fec8aa54a05394a8f7955 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Thu, 6 Jul 2023 15:05:28 +0800 Subject: [PATCH 375/437] add networkManager Signed-off-by: renjiecui --- services/distributeddataservice/app/BUILD.gn | 3 + .../app/src/feature_stub_impl.cpp | 14 +++ .../app/src/feature_stub_impl.h | 2 + .../app/src/kvstore_data_service.cpp | 20 +++++ .../app/src/kvstore_data_service.h | 4 + .../src/network_manager/network_manager.cpp | 86 +++++++++++++++++++ .../app/src/network_manager/network_manager.h | 53 ++++++++++++ .../framework/feature/feature_system.cpp | 10 +++ .../include/feature/feature_system.h | 2 + .../service/cloud/cloud_service_impl.cpp | 53 ++++++++++++ .../service/cloud/cloud_service_impl.h | 2 + 11 files changed, 249 insertions(+) create mode 100644 services/distributeddataservice/app/src/network_manager/network_manager.cpp create mode 100644 services/distributeddataservice/app/src/network_manager/network_manager.h diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index 607c6732..e9f65131 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -59,6 +59,7 @@ config("module_private_config") { "../adapter/include/utils", "../adapter/include/dfx", "../adapter/include", + "src/network_manager", # for ipc_core interfaces. "include", @@ -81,6 +82,7 @@ ohos_shared_library("distributeddataservice") { "src/kvstore_data_service.cpp", "src/kvstore_device_listener.cpp", "src/kvstore_meta_manager.cpp", + "src/network_manager/network_manager.cpp", "src/security/security.cpp", "src/security/sensitive.cpp", "src/session_manager/route_head_handler_impl.cpp", @@ -124,6 +126,7 @@ ohos_shared_library("distributeddataservice") { "hitrace:libhitracechain", "ipc:ipc_core", "kv_store:distributeddata_inner", + "netmanager_base:net_conn_manager_if", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index f1f52b91..e3d3d205 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -108,4 +108,18 @@ int32_t FeatureStubImpl::OnReady(const std::string &device) } return featureImpl_->OnReady(device); } +int32_t FeatureStubImpl::OnNetworkOnline() +{ + if (featureImpl_ == nullptr) { + return -1; + } + return featureImpl_->OnNetworkOnline(); +} +int32_t FeatureStubImpl::OnNetworkOffline() +{ + if (featureImpl_ == nullptr) { + return -1; + } + return featureImpl_->OnNetworkOffline(); +} } diff --git a/services/distributeddataservice/app/src/feature_stub_impl.h b/services/distributeddataservice/app/src/feature_stub_impl.h index b00646bc..e3e3a905 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/services/distributeddataservice/app/src/feature_stub_impl.h @@ -39,6 +39,8 @@ public: int32_t Online(const std::string &device); int32_t Offline(const std::string &device); int32_t OnReady(const std::string &device); + int32_t OnNetworkOnline(); + int32_t OnNetworkOffline(); private: std::shared_ptr featureImpl_; }; diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 5c317362..5933b685 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -36,6 +36,7 @@ #include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" #include "metadata/secret_key_meta_data.h" +#include "network_manager/network_manager.h" #include "permission_validator.h" #include "permit_delegate.h" #include "process_communicator_impl.h" @@ -286,6 +287,7 @@ void KvStoreDataService::OnAddSystemAbility(int32_t systemAbilityId, const std:: } AccountDelegate::GetInstance()->SubscribeAccountEvent(); Uninstaller::GetInstance().Init(this, executors_); + NetWorkManager::GetInstance().RegOnNetworkChange(this); } void KvStoreDataService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) @@ -689,4 +691,22 @@ int32_t KvStoreDataService::OnUpdate(const std::string &bundleName, int32_t user }); return 0; } + +int32_t KvStoreDataService::OnNetworkOnline() +{ + features_.ForEachCopies([](const auto &, sptr &value) { + value->OnNetworkOnline(); + return false; + }); + return 0; +} + +int32_t KvStoreDataService::OnNetworkOffline() +{ + features_.ForEachCopies([](const auto &, sptr &value) { + value->OnNetworkOffline(); + return false; + }); + return 0; +} } // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 4a16d21c..c668ae10 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -77,6 +77,10 @@ public: int32_t OnUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); + int32_t OnNetworkOnline(); + + int32_t OnNetworkOffline(); + private: void NotifyAccountEvent(const AccountEventInfo &eventInfo); class KvStoreClientDeathObserverImpl { diff --git a/services/distributeddataservice/app/src/network_manager/network_manager.cpp b/services/distributeddataservice/app/src/network_manager/network_manager.cpp new file mode 100644 index 00000000..3f863d53 --- /dev/null +++ b/services/distributeddataservice/app/src/network_manager/network_manager.cpp @@ -0,0 +1,86 @@ +/* + * 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. + */ +#define LOG_TAG "NetWorkManager" +#include "network_manager.h" + +#include "i_net_conn_callback.h" +#include "log_print.h" +#include "net_conn_client.h" + +using namespace OHOS::NetManagerStandard; +namespace OHOS::DistributedKv { +bool NetWorkManager::RegOnNetworkChange(KvStoreDataService *kvStoreDataService) +{ + sptr observer = new (std::nothrow) NetConnCallbackObserver(kvStoreDataService); + if (observer == nullptr) { + ZLOGE("new operator error.observer is nullptr"); + return false; + } + int nRet = DelayedSingleton::GetInstance()->RegisterNetConnCallback(observer); + if (nRet != NETMANAGER_SUCCESS) { + ZLOGE("RegisterNetConnCallback failed, ret = %{public}d", nRet); + return false; + } + return true; +} + +NetWorkManager &NetWorkManager::GetInstance() +{ + static NetWorkManager instance; + return instance; +} + +NetWorkManager::NetWorkManager() = default; + +NetWorkManager::~NetWorkManager() = default; + +int32_t NetWorkManager::NetConnCallbackObserver::NetAvailable(sptr &netHandle) +{ + ZLOGI("OnNetworkAvailable"); + return kvStoreDataService_->OnNetworkOnline(); +} + +int32_t NetWorkManager::NetConnCallbackObserver::NetUnavailable() +{ + ZLOGI("OnNetworkUnavailable"); + return kvStoreDataService_->OnNetworkOffline(); +} + +int32_t NetWorkManager::NetConnCallbackObserver::NetCapabilitiesChange(sptr &netHandle, + const sptr &netAllCap) +{ + ZLOGI("OnNetCapabilitiesChange"); + return SUCCESS; +} + +int32_t NetWorkManager::NetConnCallbackObserver::NetConnectionPropertiesChange(sptr &netHandle, + const sptr &info) +{ + ZLOGI("OnNetConnectionPropertiesChange"); + return SUCCESS; +} + +int32_t NetWorkManager::NetConnCallbackObserver::NetLost(sptr &netHandle) +{ + ZLOGI("OnNetLost"); + return SUCCESS; +} + +int32_t NetWorkManager::NetConnCallbackObserver::NetBlockStatusChange(sptr &netHandle, bool blocked) +{ + ZLOGI("OnNetBlockStatusChange"); + return SUCCESS; +} +} // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/network_manager/network_manager.h b/services/distributeddataservice/app/src/network_manager/network_manager.h new file mode 100644 index 00000000..d55968c1 --- /dev/null +++ b/services/distributeddataservice/app/src/network_manager/network_manager.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifndef OHOS_NETWORK_MANAGER_H +#define OHOS_NETWORK_MANAGER_H + +#include "net_all_capabilities.h" +#include "net_conn_callback_stub.h" +#include "net_handle.h" +#include "kvstore_data_service.h" +namespace OHOS::DistributedKv { +using namespace NetManagerStandard; +class NetWorkManager { +public: + bool RegOnNetworkChange(KvStoreDataService *kvStoreDataService); + static NetWorkManager &GetInstance(); + + class NetConnCallbackObserver : public NetConnCallbackStub { + public: + explicit NetConnCallbackObserver(KvStoreDataService *kvStoreDataService) + : kvStoreDataService_(kvStoreDataService) + { + } + ~NetConnCallbackObserver() override = default; + int32_t NetAvailable(sptr &netHandle) override; + int32_t NetCapabilitiesChange(sptr &netHandle, const sptr &netAllCap) override; + int32_t NetConnectionPropertiesChange(sptr &netHandle, const sptr &info) override; + int32_t NetLost(sptr &netHandle) override; + int32_t NetUnavailable() override; + int32_t NetBlockStatusChange(sptr &netHandle, bool blocked) override; + + private: + KvStoreDataService *kvStoreDataService_; + }; + +private: + NetWorkManager(); + ~NetWorkManager(); +}; +} // namespace OHOS::DistributedKv +#endif // OHOS_NETWORK_MANAGER_H diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index 74907ec8..26b4f4e9 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -106,5 +106,15 @@ int32_t FeatureSystem::Feature::OnBind(const FeatureSystem::Feature::BindInfo &b { return E_OK; } + +int32_t FeatureSystem::Feature::OnNetworkOnline() +{ + return E_OK; +} + +int32_t FeatureSystem::Feature::OnNetworkOffline() +{ + return E_OK; +} } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index d549cc6d..66a1e6b0 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -53,6 +53,8 @@ public: virtual int32_t Online(const std::string &device); virtual int32_t Offline(const std::string &device); virtual int32_t OnReady(const std::string &device); + virtual int32_t OnNetworkOnline(); + virtual int32_t OnNetworkOffline(); }; using Creator = std::function()>; static FeatureSystem &GetInstance(); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 844f2ed3..8929c7a0 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -239,6 +239,59 @@ int32_t CloudServiceImpl::OnUserChange(uint32_t code, const std::string &user, c return E_OK; } +int32_t CloudServiceImpl::OnNetworkOnline() +{ + ZLOGI("OnNetworkOnline"); + + std::vector users; + Account::GetInstance()->QueryUsers(users); + if (users.empty()) { + return SUCCESS; + } + auto it = users.begin(); + while (it != users.end()) { + CloudInfo cloudInfo; + cloudInfo.user = *it; + if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS && GetCloudInfoFromServer(cloudInfo) != SUCCESS) { + it++; + continue; + } + if (!cloudInfo.enableCloud) { + it++; + continue; + } + syncManager_.DoCloudSync( { *it } ); + it++; + } + return SUCCESS; +} + +int32_t CloudServiceImpl::OnNetworkOffline() +{ + ZLOGI("OnNetworkOffline"); + std::vector users; + Account::GetInstance()->QueryUsers(users); + if (users.empty()) { + return SUCCESS; + } + auto it = users.begin(); + while (it != users.end()) { + CloudInfo cloudInfo; + cloudInfo.user = *it; + if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS && GetCloudInfoFromServer(cloudInfo) != SUCCESS) { + it++; + continue; + } + if (!cloudInfo.enableCloud) { + it++; + continue; + } + syncManager_.StopCloudSync(*it); + it++; + } + return SUCCESS; +} + int32_t CloudServiceImpl::GetCloudInfo(uint32_t tokenId, const std::string &id, CloudInfo &cloudInfo) { cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(tokenId); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 31599142..7dcedfd4 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -38,6 +38,8 @@ public: int32_t OnBind(const BindInfo &info) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; + int32_t OnNetworkOnline() override; + int32_t OnNetworkOffline() override; private: class Factory { -- Gitee From 48319b57358b9bfe6cdd1778d23e9910db6624ad Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 6 Jul 2023 22:04:00 +0800 Subject: [PATCH 376/437] add progress code Signed-off-by: zuojiangjiang --- .../framework/include/error/general_error.h | 6 ++++- .../service/cloud/sync_manager.cpp | 6 ++--- .../service/rdb/rdb_asset_loader.cpp | 26 ++----------------- .../service/rdb/rdb_cloud.cpp | 21 +++++++-------- .../service/rdb/rdb_cloud.h | 2 +- .../service/rdb/rdb_general_store.cpp | 24 +++++++++++++++-- .../service/rdb/rdb_general_store.h | 2 ++ 7 files changed, 44 insertions(+), 43 deletions(-) diff --git a/services/distributeddataservice/framework/include/error/general_error.h b/services/distributeddataservice/framework/include/error/general_error.h index 56fc4a8f..79a4433a 100644 --- a/services/distributeddataservice/framework/include/error/general_error.h +++ b/services/distributeddataservice/framework/include/error/general_error.h @@ -19,6 +19,11 @@ namespace OHOS::DistributedData { enum GeneralError : int32_t { E_OK = 0, E_ERROR, + E_NETWORK_ERROR, + E_CLOUD_DISABLED, + E_LOCKED_BY_OTHERS, + E_RECODE_LIMIT_EXCEEDED, + E_NO_SPACE_FOR_ASSET, E_BUSY, E_INVALID_ARGS, E_NOT_INIT, @@ -27,7 +32,6 @@ enum GeneralError : int32_t { E_ALREADY_CLOSED, E_UNOPENED, E_RETRY_TIMEOUT, - E_ALREADY_LOCKED, E_BUTT, }; } diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 8bc0025d..feb63889 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -172,14 +172,14 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount CloudInfo cloud; cloud.user = info.user_; if (!MetaDataManager::GetInstance().LoadMeta(cloud.GetKey(), cloud, true)) { - info.SetError(E_NOT_INIT); + info.SetError(E_CLOUD_DISABLED); ZLOGE("no cloud info for user:%{public}d", info.user_); return; } if (!cloud.enableCloud || (info.id_ != SyncInfo::DEFAULT_ID && cloud.id != info.id_) || (!info.bundleName_.empty() && !cloud.IsOn(info.bundleName_))) { - info.SetError(E_UNOPENED); + info.SetError(E_CLOUD_DISABLED); return; } @@ -244,7 +244,7 @@ std::function SyncManager::GetSyncHandler(Retryer retryer) return; } int32_t code = details.begin()->second.code; - retryer(code == E_ALREADY_LOCKED ? LOCKED_INTERVAL : RETRY_INTERVAL, code); + retryer(code == E_LOCKED_BY_OTHERS ? LOCKED_INTERVAL : RETRY_INTERVAL, code); } : evt.GetAsyncDetail(), evt.GetWait()); GenAsync async = evt.GetAsyncDetail(); diff --git a/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp index a0d9f538..5612e8a9 100644 --- a/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp +++ b/services/distributeddataservice/service/rdb/rdb_asset_loader.cpp @@ -18,6 +18,7 @@ #include "error/general_error.h" #include "log_print.h" +#include "rdb_cloud.h" #include "value_proxy.h" using namespace DistributedDB; @@ -36,29 +37,6 @@ DBStatus RdbAssetLoader::Download(const std::string &tableName, const std::strin if (error == DistributedData::GeneralError::E_OK) { assets = ValueProxy::Convert(std::move(downLoadAssets)); } - return ConvertStatus(static_cast(error)); -} - -DBStatus RdbAssetLoader::ConvertStatus(DistributedData::GeneralError error) -{ - switch (error) { - case DistributedData::GeneralError::E_OK: - return DBStatus::OK; - case DistributedData::GeneralError::E_BUSY: - return DBStatus::BUSY; - case DistributedData::GeneralError::E_INVALID_ARGS: - return DBStatus::INVALID_ARGS; - case DistributedData::GeneralError::E_NOT_SUPPORT: - return DBStatus::NOT_SUPPORT; - case DistributedData::GeneralError::E_ERROR: // fallthrough - case DistributedData::GeneralError::E_NOT_INIT: - case DistributedData::GeneralError::E_ALREADY_CONSUMED: - case DistributedData::GeneralError::E_ALREADY_CLOSED: - return DBStatus::CLOUD_ERROR; - default: - ZLOGE("unknown error:0x%{public}x", error); - break; - } - return DBStatus::CLOUD_ERROR; + return RdbCloud::ConvertStatus(static_cast(error)); } } // namespace OHOS::DistributedRdb \ No newline at end of file diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index aeaad1f9..1df3b1f8 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -118,19 +118,16 @@ DBStatus RdbCloud::ConvertStatus(DistributedData::GeneralError error) switch (error) { case GeneralError::E_OK: return DBStatus::OK; - case GeneralError::E_BUSY: - return DBStatus::BUSY; - case GeneralError::E_INVALID_ARGS: - return DBStatus::INVALID_ARGS; - case GeneralError::E_NOT_SUPPORT: - return DBStatus::NOT_SUPPORT; - case GeneralError::E_ERROR: // fallthrough - case GeneralError::E_NOT_INIT: - case GeneralError::E_ALREADY_CONSUMED: - case GeneralError::E_ALREADY_CLOSED: - return DBStatus::CLOUD_ERROR; + case GeneralError::E_NETWORK_ERROR: + return DBStatus::CLOUD_NETWORK_ERROR; + case GeneralError::E_LOCKED_BY_OTHERS: + return DBStatus::CLOUD_LOCK_ERROR; + case GeneralError::E_RECODE_LIMIT_EXCEEDED: + return DBStatus::CLOUD_FULL_RECORDS; + case GeneralError::E_NO_SPACE_FOR_ASSET: + return DBStatus::CLOUD_SYNC_UNSET; // for test default: - ZLOGE("unknown error:0x%{public}x", error); + ZLOGI("error:0x%{public}x", error); break; } return DBStatus::CLOUD_ERROR; diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.h b/services/distributeddataservice/service/rdb/rdb_cloud.h index 0fac9033..161286ea 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.h +++ b/services/distributeddataservice/service/rdb/rdb_cloud.h @@ -38,7 +38,7 @@ public: DBStatus UnLock() override; DBStatus HeartBeat() override; DBStatus Close() override; - DBStatus ConvertStatus(DistributedData::GeneralError error); + static DBStatus ConvertStatus(DistributedData::GeneralError error); private: static constexpr int32_t TO_MS = 1000; // s > ms diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 6343a76e..90fdea28 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -273,7 +273,7 @@ RdbGeneralStore::DBBriefCB RdbGeneralStore::GetDBBriefCB(DetailAsync async) for (auto &[key, tables] : result) { auto &value = details[key]; value.progress = FINISHED; - value.progress = GeneralError::E_OK; + value.code = GeneralError::E_OK; for (auto &table : tables) { if (table.status != DBStatus::OK) { value.code = GeneralError::E_ERROR; @@ -295,7 +295,7 @@ RdbGeneralStore::DBProcessCB RdbGeneralStore::GetDBProcessCB(DetailAsync async) for (auto &[id, process] : processes) { auto &detail = details[id]; detail.progress = process.process; - detail.code = process.errCode == DBStatus::OK ? GeneralError::E_OK : GeneralError::E_ERROR; + detail.code = ConvertStatus(process.errCode); for (auto [key, value] : process.tableProcess) { auto &table = detail.details[key]; table.upload.total = value.upLoadInfo.total; @@ -338,6 +338,26 @@ int32_t RdbGeneralStore::AddRef() return ++ref_; } +RdbGeneralStore::GenErr RdbGeneralStore::ConvertStatus(DistributedDB::DBStatus status) +{ + switch (status) { + case DBStatus::OK: + return GenErr::E_OK; + case DBStatus::CLOUD_NETWORK_ERROR: + return GenErr::E_NETWORK_ERROR; + case DBStatus::CLOUD_LOCK_ERROR: + return GenErr::E_LOCKED_BY_OTHERS; + case DBStatus::CLOUD_FULL_RECORDS: + return GenErr::E_RECODE_LIMIT_EXCEEDED; + case DBStatus::CLOUD_SYNC_UNSET: // for test + return GenErr::E_NO_SPACE_FOR_ASSET; + default: + ZLOGI("status:0x%{public}x", status); + break; + } + return GenErr::E_ERROR; +} + void RdbGeneralStore::ObserverProxy::OnChange(const DBChangedIF &data) { if (!HasWatcher()) { diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 01db30b3..7c1c10bb 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -36,6 +36,7 @@ public: using Values = DistributedData::Values; using StoreMetaData = DistributedData::StoreMetaData; using Database = DistributedData::Database; + using GenErr = DistributedData::GeneralError; using RdbStore = OHOS::NativeRdb::RdbStore; explicit RdbGeneralStore(const StoreMetaData &meta); @@ -55,6 +56,7 @@ public: int32_t Close() override; int32_t AddRef() override; int32_t Release() override; + static GenErr ConvertStatus(DistributedDB::DBStatus status); private: using RdbDelegate = DistributedDB::RelationalStoreDelegate; -- Gitee From d35b305ad9e2dfb1ed2434cb5448b9813e4ec1ad Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 6 Jul 2023 22:06:59 +0800 Subject: [PATCH 377/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/rdb/rdb_general_store.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.h b/services/distributeddataservice/service/rdb/rdb_general_store.h index 7c1c10bb..128198f2 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -56,7 +56,7 @@ public: int32_t Close() override; int32_t AddRef() override; int32_t Release() override; - static GenErr ConvertStatus(DistributedDB::DBStatus status); + static GenErr ConvertStatus(DistributedDB::DBStatus status); private: using RdbDelegate = DistributedDB::RelationalStoreDelegate; -- Gitee From e1fe3738a3c291a3d482ec78a5173a1e9cdb5afc Mon Sep 17 00:00:00 2001 From: mazhao Date: Fri, 7 Jul 2023 09:12:58 +0800 Subject: [PATCH 378/437] fix alarm Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/include/json_object.h | 2 +- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h index 9680c82c..b6a1e8f5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h @@ -109,7 +109,7 @@ private: int CheckJsonRepeatField(cJSON *object, bool isFirstFloor); int CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType, bool isFirstFloor); int GetDeep(cJSON *cjson); - int CheckNumber(cJSON *cjson, int &errCode); + void CheckNumber(cJSON *cjson, int &errCode); cJSON *cjson_ = nullptr; int jsonDeep_ = 0; bool isOwner_ = false; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index a462e971..2f990589 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -151,7 +151,7 @@ int JsonObject::GetDeep(cJSON *cjson) return depth; } -int JsonObject::CheckNumber(cJSON *item, int &errCode) +void JsonObject::CheckNumber(cJSON *item, int &errCode) { std::queue cjsonQueue; cjsonQueue.push(item); @@ -175,7 +175,6 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) cjsonQueue.push(node->next); } } - return E_OK; } int JsonObject::Init(const std::string &str, bool isFilter) -- Gitee From d44e80900d7058ddaf632007f3fbaf52c299aa2c Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 7 Jul 2023 11:32:42 +0800 Subject: [PATCH 379/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 60 +++++++++++++++++++ .../published_data_subscriber_manager.cpp | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..6d625d84 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1688093771186 + + + + + + + + + \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index 3f6eec09..86d193eb 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -169,7 +169,7 @@ int PublishedDataSubscriberManager::GetCount(const PublishedDataKey &key) { int count = 0; publishedDataCache.ComputeIfPresent(key, [&count](const auto &key, std::vector &value) { - count = value.size(); + count = static_cast(value.size()); return true; }); return count; -- Gitee From 8bd5574d38597423cfb2474f293614ab04730412 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 7 Jul 2023 11:32:55 +0800 Subject: [PATCH 380/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 60 --------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 6d625d84..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1688093771186 - - - - - - - - - \ No newline at end of file -- Gitee From 44e381e289e43b145c113864d490b8a36ef2d86a Mon Sep 17 00:00:00 2001 From: genglingxia Date: Fri, 7 Jul 2023 18:48:55 +0800 Subject: [PATCH 381/437] drag_cross_dev interface adapt Signed-off-by: genglingxia --- services/distributeddataservice/service/udmf/BUILD.gn | 2 +- .../service/udmf/data_manager.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index 8bdf216f..ca34d007 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -31,7 +31,7 @@ config("module_public_config") { "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", "${kv_store_path}/frameworks/common", - "${file_service_path}/interfaces/innerkits/remote_file_share/native", + "${file_service_path}/interfaces/innerkits/native/remote_file_share/include", "${device_manager_path}/interfaces/inner_kits/native_cpp/include", "${data_service_path}/adapter/include/communicator" ] diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 62bad77c..280f5749 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -75,13 +75,14 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st auto type = record->GetType(); if (IsFileType(type)) { auto file = static_cast(record.get()); - std::string remoteUri = AppFileService::ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId); - if(remoteUri.empty() || remoteUri == "error") { - ZLOGW("Get remoteUri failed, uri: %{public}s, remoteUri: %{public}s.", file->GetUri().c_str(), remoteUri.c_str()); - return E_UNKNOWN; + struct AppFileService::ModuleRemoteFileShare::HmdfsUriInfo dfsUriInfo; + int ret = AppFileService::ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); + if(ret != 0 || dfsUriInfo.uriStr.empty()) { + ZLOGW("Get remoteUri failed, ret = %{public}d, uri: %{public}s, userId: %{public}d.", ret, file->GetUri().c_str(), userId); + return E_DFS_URI; } - file->SetRemoteUri(remoteUri); + file->SetRemoteUri(dfsUriInfo.uriStr); } record->SetUid(PreProcessUtils::IdGenerator()); -- Gitee From b2e56d14fb99be2e96fecfe3c2bc4cbc99d33c12 Mon Sep 17 00:00:00 2001 From: dboy190 Date: Sat, 8 Jul 2023 10:53:25 +0800 Subject: [PATCH 382/437] support p2p dev fix ut Signed-off-by: dboy190 --- .../test/unittest/communication_provider_impl_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/adapter/communicator/test/unittest/communication_provider_impl_test.cpp b/services/distributeddataservice/adapter/communicator/test/unittest/communication_provider_impl_test.cpp index 137f105c..0000371d 100644 --- a/services/distributeddataservice/adapter/communicator/test/unittest/communication_provider_impl_test.cpp +++ b/services/distributeddataservice/adapter/communicator/test/unittest/communication_provider_impl_test.cpp @@ -132,7 +132,8 @@ HWTEST_F(CommunicationProviderImplTest, CommunicationProvider005, TestSize.Level std::string content = "Helloworlds"; const uint8_t *t = reinterpret_cast(content.c_str()); DeviceId di17 = {"127.0.0.2"}; - Status status = CommunicationProvider::GetInstance().SendData(id17, di17, t, content.length()); + DataInfo data = { const_cast(t), static_cast(content.length())}; + Status status = CommunicationProvider::GetInstance().SendData(id17, di17, data, 0); EXPECT_NE(status, Status::SUCCESS); CommunicationProvider::GetInstance().StopWatchDataChange(dataListener17, id17); CommunicationProvider::GetInstance().Stop(id17); -- Gitee From c9e72b194b47a22db6d11e6fc17fae47c16cc814 Mon Sep 17 00:00:00 2001 From: dboy190 Date: Sat, 8 Jul 2023 11:21:08 +0800 Subject: [PATCH 383/437] support p2p dev fix compile problem Signed-off-by: dboy190 --- .../adapter/communicator/src/softbus_client.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp index 872379be..4f9f41be 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp @@ -131,6 +131,8 @@ Status SoftBusClient::SwitchChannel(uint32_t totalLength) RestoreDefaultValue(); return Open(GetSessionAttribute(false)); } + + return Status::NETWORK_ERROR; } Status SoftBusClient::CreateChannel(uint32_t totalLength) -- Gitee From e8da609d1a9cc2fe7d9c02127d90c95a6b1049fb Mon Sep 17 00:00:00 2001 From: renjiecui Date: Sat, 8 Jul 2023 15:21:19 +0800 Subject: [PATCH 384/437] remove networkmanger Signed-off-by: renjiecui --- .../adapter/communicator/BUILD.gn | 2 + .../src/device_manager_adapter.cpp | 122 +++++++++++++++++- .../include/communicator/commu_types.h | 2 + .../communicator/device_manager_adapter.h | 5 + services/distributeddataservice/app/BUILD.gn | 3 - .../app/src/feature_stub_impl.cpp | 2 + .../app/src/kvstore_data_service.cpp | 1 - .../app/src/kvstore_device_listener.cpp | 21 ++- .../src/network_manager/network_manager.cpp | 86 ------------ .../app/src/network_manager/network_manager.h | 53 -------- 10 files changed, 144 insertions(+), 153 deletions(-) delete mode 100644 services/distributeddataservice/app/src/network_manager/network_manager.cpp delete mode 100644 services/distributeddataservice/app/src/network_manager/network_manager.h diff --git a/services/distributeddataservice/adapter/communicator/BUILD.gn b/services/distributeddataservice/adapter/communicator/BUILD.gn index 451b8de6..ce3266a4 100755 --- a/services/distributeddataservice/adapter/communicator/BUILD.gn +++ b/services/distributeddataservice/adapter/communicator/BUILD.gn @@ -59,6 +59,8 @@ ohos_static_library("distributeddata_communicator_static") { "device_manager:devicemanagersdk", "dsoftbus:softbus_client", "hilog:libhilog", + "ipc:ipc_core", + "netmanager_base:net_conn_manager_if", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 2ea67eb8..99d9fc21 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -15,16 +15,23 @@ #define LOG_TAG "DeviceManagerAdapter" #include "device_manager_adapter.h" + #include -#include "log_print.h" + #include "kvstore_utils.h" +#include "log_print.h" +#include "net_conn_callback_stub.h" +#include "net_conn_client.h" +#include "net_handle.h" namespace OHOS::DistributedData { using namespace OHOS::DistributedHardware; using namespace OHOS::AppDistributedKv; +using namespace OHOS::NetManagerStandard; using KvStoreUtils = OHOS::DistributedKv::KvStoreUtils; constexpr int32_t DM_OK = 0; constexpr const char *PKG_NAME = "ohos.distributeddata.service"; +DmDeviceInfo DeviceManagerAdapter::cloudDmInfo = { "cloudDeviceId", "cloudDeviceName", 0, "cloudNetworkId", 0 }; class DataMgrDmStateCall final : public DistributedHardware::DeviceStateCallback { public: explicit DataMgrDmStateCall(DeviceManagerAdapter &dmAdapter) : dmAdapter_(dmAdapter) {} @@ -74,6 +81,63 @@ void DataMgrDmInitCall::OnRemoteDied() dmAdapter_.Init(executors_); } +class NetConnCallbackObserver : public NetConnCallbackStub { +public: + explicit NetConnCallbackObserver(DeviceManagerAdapter &dmAdapter) : dmAdapter_(dmAdapter) {} + ~NetConnCallbackObserver() override = default; + int32_t NetAvailable(sptr &netHandle) override; + int32_t NetCapabilitiesChange(sptr &netHandle, const sptr &netAllCap) override; + int32_t NetConnectionPropertiesChange(sptr &netHandle, const sptr &info) override; + int32_t NetLost(sptr &netHandle) override; + int32_t NetUnavailable() override; + int32_t NetBlockStatusChange(sptr &netHandle, bool blocked) override; + +private: + DeviceManagerAdapter &dmAdapter_; +}; + +int32_t NetConnCallbackObserver::NetAvailable(sptr &netHandle) +{ + ZLOGI("OnNetworkAvailable"); + dmAdapter_.Online(DeviceManagerAdapter::cloudDmInfo); + dmAdapter_.isNetAvailable_ = true; + return DistributedKv::SUCCESS; +} + +int32_t NetConnCallbackObserver::NetUnavailable() +{ + ZLOGI("OnNetworkUnavailable"); + dmAdapter_.Offline(DeviceManagerAdapter::cloudDmInfo); + dmAdapter_.isNetAvailable_ = false; + return DistributedKv::SUCCESS; +} + +int32_t NetConnCallbackObserver::NetCapabilitiesChange(sptr &netHandle, + const sptr &netAllCap) +{ + ZLOGI("OnNetCapabilitiesChange"); + return DistributedKv::SUCCESS; +} + +int32_t NetConnCallbackObserver::NetConnectionPropertiesChange(sptr &netHandle, + const sptr &info) +{ + ZLOGI("OnNetConnectionPropertiesChange"); + return DistributedKv::SUCCESS; +} + +int32_t NetConnCallbackObserver::NetLost(sptr &netHandle) +{ + ZLOGI("OnNetLost"); + return DistributedKv::SUCCESS; +} + +int32_t NetConnCallbackObserver::NetBlockStatusChange(sptr &netHandle, bool blocked) +{ + ZLOGI("OnNetBlockStatusChange"); + return DistributedKv::SUCCESS; +} + DeviceManagerAdapter::DeviceManagerAdapter() { ZLOGI("construct"); @@ -107,11 +171,12 @@ std::function DeviceManagerAdapter::RegDevCallback() auto dmInitCall = std::make_shared(*this, executors_); auto resultInit = devManager.InitDeviceManager(PKG_NAME, dmInitCall); auto resultState = devManager.RegisterDevStateCallback(PKG_NAME, "", dmStateCall); - if (resultInit == DM_OK && resultState == DM_OK) { + auto resultNet = RegOnNetworkChange(); + if (resultInit == DM_OK && resultState == DM_OK && resultNet) { return; } constexpr int32_t INTERVAL = 500; - executors_->Schedule(RegDevCallback(), std::chrono::milliseconds(INTERVAL)); + executors_->Schedule(std::chrono::milliseconds(INTERVAL), RegDevCallback()); }; } @@ -154,6 +219,17 @@ void DeviceManagerAdapter::Online(const DmDeviceInfo &info) KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_ONLINE); auto observers = GetObservers(); + + if (dvInfo.deviceName == DeviceManagerAdapter::cloudDmInfo.deviceName) { + for (const auto &item : observers) { // network available + if (item == nullptr) { + continue; + } + item->OnDeviceChanged(dvInfo, DeviceChangeType::DEVICE_NET_AVAILABLE); + } + return; + } + for (const auto &item : observers) { // notify db if (item == nullptr) { continue; @@ -232,6 +308,16 @@ void DeviceManagerAdapter::Offline(const DmDeviceInfo &info) return; } syncTask_.Erase(dvInfo.uuid); + if (dvInfo.deviceName == DeviceManagerAdapter::cloudDmInfo.deviceName) { + auto observers = GetObservers(); + for (const auto &item : observers) { // network unavailable + if (item == nullptr) { + continue; + } + item->OnDeviceChanged(dvInfo, DeviceChangeType::DEVICE_NET_UNAVAILABLE); + } + return; + } ZLOGI("[offline] uuid:%{public}s, name:%{public}s, type:%{public}d", KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_OFFLINE); @@ -404,6 +490,9 @@ std::string DeviceManagerAdapter::GetUuidByNetworkId(const std::string &networkI if (networkId.empty()) { return ""; } + if (networkId == DeviceManagerAdapter::cloudDmInfo.networkId) { + return "netUuid"; + } DeviceInfo dvInfo; if (deviceInfos_.Get(networkId, dvInfo)) { return dvInfo.uuid; @@ -422,6 +511,9 @@ std::string DeviceManagerAdapter::GetUdidByNetworkId(const std::string &networkI if (networkId.empty()) { return ""; } + if (networkId == DeviceManagerAdapter::cloudDmInfo.networkId) { + return "netUdid"; + } DeviceInfo dvInfo; if (deviceInfos_.Get(networkId, dvInfo)) { return dvInfo.udid; @@ -451,7 +543,7 @@ std::vector DeviceManagerAdapter::ToUUID(const std::vector DeviceManagerAdapter::ToUUID(std::vector de std::vector uuids; for (auto &device : devices) { if (device.uuid.empty()) { - continue ; + continue; } uuids.push_back(std::move(device.uuid)); } @@ -488,4 +580,24 @@ std::string DeviceManagerAdapter::CalcClientUuid(const std::string &appId, const } return encryptedUuid; } + +bool DeviceManagerAdapter::RegOnNetworkChange() +{ + sptr observer = new (std::nothrow) NetConnCallbackObserver(*this); + if (observer == nullptr) { + ZLOGE("new operator error.observer is nullptr"); + return false; + } + int nRet = DelayedSingleton::GetInstance()->RegisterNetConnCallback(observer); + if (nRet != NETMANAGER_SUCCESS) { + ZLOGE("RegisterNetConnCallback failed, ret = %{public}d", nRet); + return false; + } + return true; +} + +bool DeviceManagerAdapter::IsNetworkAvailable() +{ + return isNetAvailable_; +} } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/adapter/include/communicator/commu_types.h b/services/distributeddataservice/adapter/include/communicator/commu_types.h index ca822697..95eed1f1 100644 --- a/services/distributeddataservice/adapter/include/communicator/commu_types.h +++ b/services/distributeddataservice/adapter/include/communicator/commu_types.h @@ -57,6 +57,8 @@ enum class API_EXPORT DeviceChangeType { DEVICE_OFFLINE = 0, DEVICE_ONLINE = 1, DEVICE_ONREADY = 2, + DEVICE_NET_AVAILABLE = 3, + DEVICE_NET_UNAVAILABLE = 4, }; enum class API_EXPORT DeviceStatus { diff --git a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h index 9cb05a88..d7d43688 100644 --- a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h +++ b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h @@ -54,12 +54,15 @@ public: static std::vector ToUUID(std::vector devices); std::string ToNetworkID(const std::string &id); void NotifyReadyEvent(const std::string &uuid); + bool IsNetworkAvailable(); friend class DataMgrDmStateCall; + friend class NetConnCallbackObserver; private: DeviceManagerAdapter(); ~DeviceManagerAdapter(); std::function RegDevCallback(); + bool RegOnNetworkChange(); bool GetDeviceInfo(const DmDeviceInfo &dmInfo, DeviceInfo &dvInfo); void SaveDeviceInfo(const DeviceInfo &deviceInfo, const AppDistributedKv::DeviceChangeType &type); void UpdateDeviceInfo(); @@ -73,12 +76,14 @@ private: std::mutex devInfoMutex_ {}; DeviceInfo localInfo_ {}; + static DmDeviceInfo cloudDmInfo; ConcurrentMap observers_ {}; LRUBucket deviceInfos_ {64}; static constexpr size_t TIME_TASK_CAPACITY = 50; static constexpr int32_t SYNC_TIMEOUT = 10 * 1000; // ms ConcurrentMap syncTask_ {}; std::shared_ptr executors_; + bool isNetAvailable_ = false; }; } // namespace DistributedData } // namespace OHOS diff --git a/services/distributeddataservice/app/BUILD.gn b/services/distributeddataservice/app/BUILD.gn index e9f65131..607c6732 100644 --- a/services/distributeddataservice/app/BUILD.gn +++ b/services/distributeddataservice/app/BUILD.gn @@ -59,7 +59,6 @@ config("module_private_config") { "../adapter/include/utils", "../adapter/include/dfx", "../adapter/include", - "src/network_manager", # for ipc_core interfaces. "include", @@ -82,7 +81,6 @@ ohos_shared_library("distributeddataservice") { "src/kvstore_data_service.cpp", "src/kvstore_device_listener.cpp", "src/kvstore_meta_manager.cpp", - "src/network_manager/network_manager.cpp", "src/security/security.cpp", "src/security/sensitive.cpp", "src/session_manager/route_head_handler_impl.cpp", @@ -126,7 +124,6 @@ ohos_shared_library("distributeddataservice") { "hitrace:libhitracechain", "ipc:ipc_core", "kv_store:distributeddata_inner", - "netmanager_base:net_conn_manager_if", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index e3d3d205..b613c0bb 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -108,6 +108,7 @@ int32_t FeatureStubImpl::OnReady(const std::string &device) } return featureImpl_->OnReady(device); } + int32_t FeatureStubImpl::OnNetworkOnline() { if (featureImpl_ == nullptr) { @@ -115,6 +116,7 @@ int32_t FeatureStubImpl::OnNetworkOnline() } return featureImpl_->OnNetworkOnline(); } + int32_t FeatureStubImpl::OnNetworkOffline() { if (featureImpl_ == nullptr) { diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 5933b685..96c96a59 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -287,7 +287,6 @@ void KvStoreDataService::OnAddSystemAbility(int32_t systemAbilityId, const std:: } AccountDelegate::GetInstance()->SubscribeAccountEvent(); Uninstaller::GetInstance().Init(this, executors_); - NetWorkManager::GetInstance().RegOnNetworkChange(this); } void KvStoreDataService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) diff --git a/services/distributeddataservice/app/src/kvstore_device_listener.cpp b/services/distributeddataservice/app/src/kvstore_device_listener.cpp index 4d155a17..488891da 100644 --- a/services/distributeddataservice/app/src/kvstore_device_listener.cpp +++ b/services/distributeddataservice/app/src/kvstore_device_listener.cpp @@ -23,11 +23,22 @@ namespace OHOS::DistributedKv { void KvStoreDeviceListener::OnDeviceChanged( const AppDistributedKv::DeviceInfo &info, const AppDistributedKv::DeviceChangeType &type) const { - if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONLINE) { - kvStoreDataService_.SetCompatibleIdentify(info); - kvStoreDataService_.OnDeviceOnline(info); - } else if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONREADY) { - kvStoreDataService_.OnDeviceOnReady(info); + switch (type) { + case AppDistributedKv::DeviceChangeType::DEVICE_ONLINE: + kvStoreDataService_.SetCompatibleIdentify(info); + kvStoreDataService_.OnDeviceOnline(info); + break; + case AppDistributedKv::DeviceChangeType::DEVICE_ONREADY: + kvStoreDataService_.OnDeviceOnReady(info); + break; + case AppDistributedKv::DeviceChangeType::DEVICE_NET_AVAILABLE: + kvStoreDataService_.OnNetworkOnline(); + break; + case AppDistributedKv::DeviceChangeType::DEVICE_NET_UNAVAILABLE: + kvStoreDataService_.OnNetworkOffline(); + break; + default: + break; } ZLOGI("device is %{public}d", type); } diff --git a/services/distributeddataservice/app/src/network_manager/network_manager.cpp b/services/distributeddataservice/app/src/network_manager/network_manager.cpp deleted file mode 100644 index 3f863d53..00000000 --- a/services/distributeddataservice/app/src/network_manager/network_manager.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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. - */ -#define LOG_TAG "NetWorkManager" -#include "network_manager.h" - -#include "i_net_conn_callback.h" -#include "log_print.h" -#include "net_conn_client.h" - -using namespace OHOS::NetManagerStandard; -namespace OHOS::DistributedKv { -bool NetWorkManager::RegOnNetworkChange(KvStoreDataService *kvStoreDataService) -{ - sptr observer = new (std::nothrow) NetConnCallbackObserver(kvStoreDataService); - if (observer == nullptr) { - ZLOGE("new operator error.observer is nullptr"); - return false; - } - int nRet = DelayedSingleton::GetInstance()->RegisterNetConnCallback(observer); - if (nRet != NETMANAGER_SUCCESS) { - ZLOGE("RegisterNetConnCallback failed, ret = %{public}d", nRet); - return false; - } - return true; -} - -NetWorkManager &NetWorkManager::GetInstance() -{ - static NetWorkManager instance; - return instance; -} - -NetWorkManager::NetWorkManager() = default; - -NetWorkManager::~NetWorkManager() = default; - -int32_t NetWorkManager::NetConnCallbackObserver::NetAvailable(sptr &netHandle) -{ - ZLOGI("OnNetworkAvailable"); - return kvStoreDataService_->OnNetworkOnline(); -} - -int32_t NetWorkManager::NetConnCallbackObserver::NetUnavailable() -{ - ZLOGI("OnNetworkUnavailable"); - return kvStoreDataService_->OnNetworkOffline(); -} - -int32_t NetWorkManager::NetConnCallbackObserver::NetCapabilitiesChange(sptr &netHandle, - const sptr &netAllCap) -{ - ZLOGI("OnNetCapabilitiesChange"); - return SUCCESS; -} - -int32_t NetWorkManager::NetConnCallbackObserver::NetConnectionPropertiesChange(sptr &netHandle, - const sptr &info) -{ - ZLOGI("OnNetConnectionPropertiesChange"); - return SUCCESS; -} - -int32_t NetWorkManager::NetConnCallbackObserver::NetLost(sptr &netHandle) -{ - ZLOGI("OnNetLost"); - return SUCCESS; -} - -int32_t NetWorkManager::NetConnCallbackObserver::NetBlockStatusChange(sptr &netHandle, bool blocked) -{ - ZLOGI("OnNetBlockStatusChange"); - return SUCCESS; -} -} // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/network_manager/network_manager.h b/services/distributeddataservice/app/src/network_manager/network_manager.h deleted file mode 100644 index d55968c1..00000000 --- a/services/distributeddataservice/app/src/network_manager/network_manager.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - */ - -#ifndef OHOS_NETWORK_MANAGER_H -#define OHOS_NETWORK_MANAGER_H - -#include "net_all_capabilities.h" -#include "net_conn_callback_stub.h" -#include "net_handle.h" -#include "kvstore_data_service.h" -namespace OHOS::DistributedKv { -using namespace NetManagerStandard; -class NetWorkManager { -public: - bool RegOnNetworkChange(KvStoreDataService *kvStoreDataService); - static NetWorkManager &GetInstance(); - - class NetConnCallbackObserver : public NetConnCallbackStub { - public: - explicit NetConnCallbackObserver(KvStoreDataService *kvStoreDataService) - : kvStoreDataService_(kvStoreDataService) - { - } - ~NetConnCallbackObserver() override = default; - int32_t NetAvailable(sptr &netHandle) override; - int32_t NetCapabilitiesChange(sptr &netHandle, const sptr &netAllCap) override; - int32_t NetConnectionPropertiesChange(sptr &netHandle, const sptr &info) override; - int32_t NetLost(sptr &netHandle) override; - int32_t NetUnavailable() override; - int32_t NetBlockStatusChange(sptr &netHandle, bool blocked) override; - - private: - KvStoreDataService *kvStoreDataService_; - }; - -private: - NetWorkManager(); - ~NetWorkManager(); -}; -} // namespace OHOS::DistributedKv -#endif // OHOS_NETWORK_MANAGER_H -- Gitee From 7557b958866124c9a0b187ee4d86247a56becd0e Mon Sep 17 00:00:00 2001 From: renjiecui Date: Sat, 8 Jul 2023 16:07:12 +0800 Subject: [PATCH 385/437] modify online Signed-off-by: renjiecui --- .../adapter/communicator/src/process_communicator_impl.cpp | 3 ++- .../distributeddataservice/app/src/kvstore_data_service.cpp | 1 - services/distributeddataservice/app/src/security/security.cpp | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp index c93a2a97..2e950e09 100644 --- a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp +++ b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp @@ -195,7 +195,8 @@ void ProcessCommunicatorImpl::OnMessage(const DeviceInfo &info, const uint8_t *p void ProcessCommunicatorImpl::OnDeviceChanged(const DeviceInfo &info, const DeviceChangeType &type) const { - if (type == DeviceChangeType::DEVICE_ONREADY) { + if (type == DeviceChangeType::DEVICE_ONREADY || type == DeviceChangeType::DEVICE_NET_AVAILABLE || + type == DeviceChangeType::DEVICE_NET_UNAVAILABLE) { return; } std::lock_guard onDeviceChangeLockGuard(onDeviceChangeMutex_); diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 96c96a59..932b2380 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -36,7 +36,6 @@ #include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" #include "metadata/secret_key_meta_data.h" -#include "network_manager/network_manager.h" #include "permission_validator.h" #include "permit_delegate.h" #include "process_communicator_impl.h" diff --git a/services/distributeddataservice/app/src/security/security.cpp b/services/distributeddataservice/app/src/security/security.cpp index 881217ef..3359f6f9 100644 --- a/services/distributeddataservice/app/src/security/security.cpp +++ b/services/distributeddataservice/app/src/security/security.cpp @@ -141,6 +141,10 @@ void Security::OnDeviceChanged(const AppDistributedKv::DeviceInfo &info, return; } + if (type == AppDistributedKv::DeviceChangeType::DEVICE_NET_AVAILABLE || + type == AppDistributedKv::DeviceChangeType::DEVICE_NET_UNAVAILABLE) { + return; + } bool isOnline = type == AppDistributedKv::DeviceChangeType::DEVICE_ONLINE; if (isOnline) { (void)GetSensitiveByUuid(info.uuid); -- Gitee From cb7b60892f3169ed7f6ce11be82ddc2525845300 Mon Sep 17 00:00:00 2001 From: dboy190 Date: Sat, 8 Jul 2023 16:52:34 +0800 Subject: [PATCH 386/437] fix compile problem Signed-off-by: dboy190 --- .../adapter/communicator/src/process_communicator_impl.cpp | 6 ++++++ .../include/communicator/process_communicator_impl.h | 1 + 2 files changed, 7 insertions(+) diff --git a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp index 5b0b3eaa..8ba2863f 100644 --- a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp +++ b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp @@ -110,6 +110,12 @@ DBStatus ProcessCommunicatorImpl::RegOnDataReceive(const OnDataReceive &callback return DBStatus::OK; } +DBStatus ProcessCommunicatorImpl::SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length) +{ + uint32_t totalLength = 0; + return SendData(dstDevInfo, data, length, totalLength); +} + DBStatus ProcessCommunicatorImpl::SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, uint32_t totalLength) { PipeInfo pi = {thisProcessLabel_, ""}; diff --git a/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h b/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h index 17219b11..fbe08349 100644 --- a/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h +++ b/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h @@ -45,6 +45,7 @@ public: DBStatus RegOnDeviceChange(const OnDeviceChange &callback) override; DBStatus RegOnDataReceive(const OnDataReceive &callback) override; + DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length) override; DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, uint32_t totalLength) override; uint32_t GetMtuSize() override; uint32_t GetMtuSize(const DeviceInfos &devInfo) override; -- Gitee From a75cb6711be3fd3ba098f25fe250c827f0032185 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Sat, 8 Jul 2023 17:01:32 +0800 Subject: [PATCH 387/437] udpate Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/sync_manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index feb63889..082d1f4c 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -191,6 +191,10 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount retryer(RETRY_INTERVAL, E_RETRY_TIMEOUT); return; } + if (!DmAdapter::GetInstance().IsNetworkAvailable()) { + retryer(RETRY_INTERVAL, E_NETWORK_ERROR); + return; + } Defer defer(GetSyncHandler(std::move(retryer)), CloudEvent::CLOUD_SYNC); for (auto &schema : schemas) { -- Gitee From 70867cd6b9d4437120b280870f86bf848e06fc4f Mon Sep 17 00:00:00 2001 From: niudongyao Date: Mon, 10 Jul 2023 10:36:49 +0800 Subject: [PATCH 388/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 61 +++++++++++++++++++ .../published_data_subscriber_manager.cpp | 35 +++++------ .../published_data_subscriber_manager.h | 14 ++--- 3 files changed, 86 insertions(+), 24 deletions(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..16353b05 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1688093771186 + + + + + + + + + \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index 86d193eb..30c14ce5 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -30,24 +30,24 @@ PublishedDataSubscriberManager &PublishedDataSubscriberManager::GetInstance() } int PublishedDataSubscriberManager::Add( - const PublishedDataKey &key, const sptr observer, const uint32_t callerTokenId) + const PublishedDataKey &key, const sptr observer, uint32_t callerTokenId) { - publishedDataCache.Compute( + publishedDataCache_.Compute( key, [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { - ZLOGI("add publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), callerTokenId); + ZLOGI("add publish subscriber, uri %{public}s tokenId %{public}d", key.key.c_str(), callerTokenId); value.emplace_back(observer, callerTokenId); return true; }); return E_OK; } -int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, const uint32_t callerTokenId) +int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, uint32_t callerTokenId) { auto result = - publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + publishedDataCache_.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { - ZLOGI("delete publish subscriber, uri %{private}s tokenId %{public}d", key.key.c_str(), + ZLOGI("delete publish subscriber, uri %{public}s tokenId %{public}d", key.key.c_str(), callerTokenId); it = value.erase(it); } else { @@ -59,12 +59,13 @@ int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, const ui return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -void PublishedDataSubscriberManager::Delete(const uint32_t callerTokenId) +void PublishedDataSubscriberManager::Delete(uint32_t callerTokenId) { - publishedDataCache.EraseIf([&callerTokenId](const auto &key, std::vector &value) { + publishedDataCache_.EraseIf([&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { - ZLOGI("erase start, uri is %{private}s, tokenId is %{public}d", key.key.c_str(), callerTokenId); + ZLOGI("erase start, uri is %{public}s, tokenId is %{public}d", + DistributedData::Anonymous::Change(key.key).c_str(), callerTokenId); it = value.erase(it); } else { it++; @@ -74,10 +75,10 @@ void PublishedDataSubscriberManager::Delete(const uint32_t callerTokenId) }); } -int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, const uint32_t callerTokenId) +int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, uint32_t callerTokenId) { auto result = - publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + publishedDataCache_.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { if (it->callerTokenId == callerTokenId) { it->enabled = false; @@ -88,10 +89,10 @@ int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, const u return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -int PublishedDataSubscriberManager::Enable(const PublishedDataKey &key, const uint32_t callerTokenId) +int PublishedDataSubscriberManager::Enable(const PublishedDataKey &key, uint32_t callerTokenId) { auto result = - publishedDataCache.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { + publishedDataCache_.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { if (it->callerTokenId == callerTokenId) { it->enabled = true; @@ -102,14 +103,14 @@ int PublishedDataSubscriberManager::Enable(const PublishedDataKey &key, const ui return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -void PublishedDataSubscriberManager::Emit(const std::vector &keys, const int32_t userId, +void PublishedDataSubscriberManager::Emit(const std::vector &keys, int32_t userId, const std::string &ownerBundleName, const sptr observer) { int32_t status; // key is bundleName, value is change node std::map publishedResult; std::map, std::vector> callbacks; - publishedDataCache.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, &userId, this]( + publishedDataCache_.ForEach([&keys, &status, &observer, &publishedResult, &callbacks, &userId, this]( const PublishedDataKey &key, std::vector &val) { for (auto &data : keys) { if (key != data || publishedResult.count(key) != 0) { @@ -162,13 +163,13 @@ void PublishedDataSubscriberManager::PutInto( void PublishedDataSubscriberManager::Clear() { - publishedDataCache.Clear(); + publishedDataCache_.Clear(); } int PublishedDataSubscriberManager::GetCount(const PublishedDataKey &key) { int count = 0; - publishedDataCache.ComputeIfPresent(key, [&count](const auto &key, std::vector &value) { + publishedDataCache_.ComputeIfPresent(key, [&count](const auto &key, std::vector &value) { count = static_cast(value.size()); return true; }); diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index 06c1a30d..8b6ba531 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -26,7 +26,7 @@ #include "executor_pool.h" namespace OHOS::DataShare { struct PublishedDataKey { - PublishedDataKey(const std::string &key, const std::string &bundleName, const int64_t subscriberId); + PublishedDataKey(const std::string &key, const std::string &bundleName, int64_t subscriberId); bool operator<(const PublishedDataKey &rhs) const; bool operator>(const PublishedDataKey &rhs) const; bool operator<=(const PublishedDataKey &rhs) const; @@ -42,12 +42,12 @@ class PublishedDataSubscriberManager { public: static PublishedDataSubscriberManager &GetInstance(); int Add(const PublishedDataKey &key, const sptr observer, - const uint32_t callerTokenId); - int Delete(const PublishedDataKey &key, const uint32_t callerTokenId); + uint32_t callerTokenId); + int Delete(const PublishedDataKey &key, uint32_t callerTokenId); void Delete(const uint32_t callerTokenId); - int Disable(const PublishedDataKey &key, const uint32_t callerTokenId); - int Enable(const PublishedDataKey &key, const uint32_t callerTokenId); - void Emit(const std::vector &keys, const int32_t userId, const std::string &ownerBundleName, + int Disable(const PublishedDataKey &key, uint32_t callerTokenId); + int Enable(const PublishedDataKey &key, uint32_t callerTokenId); + void Emit(const std::vector &keys, int32_t userId, const std::string &ownerBundleName, const sptr observer = nullptr); void Clear(); int GetCount(const PublishedDataKey &key); @@ -62,7 +62,7 @@ private: PublishedDataSubscriberManager() = default; void PutInto(std::map, std::vector> &, const std::vector &, const PublishedDataKey &, const sptr); - ConcurrentMap> publishedDataCache; + ConcurrentMap> publishedDataCache_; }; } // namespace OHOS::DataShare #endif -- Gitee From eae9584972ae3d01056e3c54050dc436772749c7 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Mon, 10 Jul 2023 10:37:02 +0800 Subject: [PATCH 389/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 61 --------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 16353b05..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1688093771186 - - - - - - - - - \ No newline at end of file -- Gitee From cf459f06da0d27a36300c48b3b8b55fa8be875ef Mon Sep 17 00:00:00 2001 From: niudongyao Date: Mon, 10 Jul 2023 10:40:12 +0800 Subject: [PATCH 390/437] fix Signed-off-by: niudongyao --- .../published_data_subscriber_manager.cpp | 7 ++++--- .../published_data_subscriber_manager.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index 30c14ce5..c1c70ae4 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -34,7 +34,8 @@ int PublishedDataSubscriberManager::Add( { publishedDataCache_.Compute( key, [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { - ZLOGI("add publish subscriber, uri %{public}s tokenId %{public}d", key.key.c_str(), callerTokenId); + ZLOGI("add publish subscriber, uri %{public}s tokenId %{public}d", + DistributedData::Anonymous::Change(key.key).c_str(), callerTokenId); value.emplace_back(observer, callerTokenId); return true; }); @@ -47,8 +48,8 @@ int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, uint32_t publishedDataCache_.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { - ZLOGI("delete publish subscriber, uri %{public}s tokenId %{public}d", key.key.c_str(), - callerTokenId); + ZLOGI("delete publish subscriber, uri %{public}s tokenId %{public}d", + DistributedData::Anonymous::Change(key.key).c_str(), callerTokenId); it = value.erase(it); } else { it++; diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index 8b6ba531..6a21c820 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -44,7 +44,7 @@ public: int Add(const PublishedDataKey &key, const sptr observer, uint32_t callerTokenId); int Delete(const PublishedDataKey &key, uint32_t callerTokenId); - void Delete(const uint32_t callerTokenId); + void Delete(uint32_t callerTokenId); int Disable(const PublishedDataKey &key, uint32_t callerTokenId); int Enable(const PublishedDataKey &key, uint32_t callerTokenId); void Emit(const std::vector &keys, int32_t userId, const std::string &ownerBundleName, -- Gitee From bd04be907a779acf9b27c83f2d6d0f8c3a167d51 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Mon, 10 Jul 2023 10:58:18 +0800 Subject: [PATCH 391/437] fix Signed-off-by: niudongyao --- .../rdb_subscriber_manager.cpp | 24 ++++++++++--------- .../rdb_subscriber_manager.h | 18 +++++++------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index ad2583f4..4bc41c77 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -24,12 +24,12 @@ #include "utils/anonymous.h" namespace OHOS::DataShare { -bool TemplateManager::Get(const Key &key, const int32_t userId, Template &tpl) +bool TemplateManager::Get(const Key &key, int32_t userId, Template &tpl) { return TemplateData::Query(Id(TemplateData::GenId(key.uri, key.bundleName, key.subscriberId), userId), tpl) == E_OK; } -int32_t TemplateManager::Add(const Key &key, const int32_t userId, const Template &tpl) +int32_t TemplateManager::Add(const Key &key, int32_t userId, const Template &tpl) { auto status = TemplateData::Add(key.uri, userId, key.bundleName, key.subscriberId, tpl); if (!status) { @@ -39,7 +39,7 @@ int32_t TemplateManager::Add(const Key &key, const int32_t userId, const Templat return E_OK; } -int32_t TemplateManager::Delete(const Key &key, const int32_t userId) +int32_t TemplateManager::Delete(const Key &key, int32_t userId) { auto status = TemplateData::Delete(key.uri, userId, key.bundleName, key.subscriberId); if (!status) { @@ -50,7 +50,7 @@ int32_t TemplateManager::Delete(const Key &key, const int32_t userId) return E_OK; } -Key::Key(const std::string &uri, const int64_t subscriberId, const std::string &bundleName) +Key::Key(const std::string &uri, int64_t subscriberId, const std::string &bundleName) : uri(uri), subscriberId(subscriberId), bundleName(bundleName) { } @@ -132,11 +132,12 @@ int RdbSubscriberManager::Add(const Key &key, const sptr return result; } -int RdbSubscriberManager::Delete(const Key &key, const uint32_t callerTokenId) +int RdbSubscriberManager::Delete(const Key &key, uint32_t callerTokenId) { auto result = rdbCache_.ComputeIfPresent(key, [&callerTokenId, this](const auto &key, std::vector &value) { - ZLOGI("delete subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), callerTokenId); + ZLOGI("delete subscriber, uri %{public}s tokenId %{public}d", + DistributedData::Anonymous::Change(key.uri).c_str(), callerTokenId); for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { ZLOGI("erase start"); @@ -153,12 +154,13 @@ int RdbSubscriberManager::Delete(const Key &key, const uint32_t callerTokenId) return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; } -void RdbSubscriberManager::Delete(const uint32_t callerTokenId) +void RdbSubscriberManager::Delete(uint32_t callerTokenId) { rdbCache_.EraseIf([&callerTokenId, this](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { - ZLOGI("erase start, uri is %{private}s, tokenId %{public}d", key.uri.c_str(), callerTokenId); + ZLOGI("erase start, uri is %{public}s, tokenId %{public}d", + DistributedData::Anonymous::Change(key.uri).c_str(), callerTokenId); it = value.erase(it); } else { it++; @@ -171,7 +173,7 @@ void RdbSubscriberManager::Delete(const uint32_t callerTokenId) }); } -int RdbSubscriberManager::Disable(const Key &key, const uint32_t callerTokenId) +int RdbSubscriberManager::Disable(const Key &key, uint32_t callerTokenId) { auto result = rdbCache_.ComputeIfPresent(key, [&callerTokenId, this](const auto &key, std::vector &value) { @@ -242,7 +244,7 @@ std::vector RdbSubscriberManager::GetKeysByUri(const std::string &uri) return results; } -void RdbSubscriberManager::EmitByKey(const Key &key, const int32_t userId, const std::string &rdbPath, int version) +void RdbSubscriberManager::EmitByKey(const Key &key, int32_t userId, const std::string &rdbPath, int version) { if (!URIUtils::IsDataProxyURI(key.uri)) { return; @@ -277,7 +279,7 @@ int RdbSubscriberManager::GetEnableObserverCount(const Key &key) return count; } -int RdbSubscriberManager::Notify(const Key &key, const int32_t userId, const std::vector &val, +int RdbSubscriberManager::Notify(const Key &key, int32_t userId, const std::vector &val, const std::string &rdbDir, int rdbVersion) { Template tpl; diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h index bcc7d0ec..d388c5af 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h @@ -26,7 +26,7 @@ #include "executor_pool.h" namespace OHOS::DataShare { struct Key { - Key(const std::string &uri, const int64_t subscriberId, const std::string &bundleName); + Key(const std::string &uri, int64_t subscriberId, const std::string &bundleName); bool operator==(const Key &rhs) const; bool operator!=(const Key &rhs) const; bool operator<(const Key &rhs) const; @@ -40,9 +40,9 @@ struct Key { class TemplateManager { public: static TemplateManager &GetInstance(); - int32_t Add(const Key &key, const int32_t userId, const Template &tpl); - int32_t Delete(const Key &key, const int32_t userId); - bool Get(const Key &key, const int32_t userId, Template &tpl); + int32_t Add(const Key &key, int32_t userId, const Template &tpl); + int32_t Delete(const Key &key, int32_t userId); + bool Get(const Key &key, int32_t userId, Template &tpl); private: TemplateManager(); @@ -54,12 +54,12 @@ public: static RdbSubscriberManager &GetInstance(); int Add(const Key &key, const sptr observer, std::shared_ptr context, std::shared_ptr executorPool); - int Delete(const Key &key, const uint32_t callerTokenId); - void Delete(const uint32_t callerTokenId); - int Disable(const Key &key, const uint32_t callerTokenId); + int Delete(const Key &key, uint32_t callerTokenId); + void Delete(uint32_t callerTokenId); + int Disable(const Key &key, uint32_t callerTokenId); int Enable(const Key &key, std::shared_ptr context); void Emit(const std::string &uri, std::shared_ptr context); - void EmitByKey(const Key &key, const int32_t userId, const std::string &rdbPath, int version); + void EmitByKey(const Key &key, int32_t userId, const std::string &rdbPath, int version); int GetCount(const Key &key); std::vector GetKeysByUri(const std::string &uri); void Clear(); @@ -74,7 +74,7 @@ private: RdbSubscriberManager() = default; ConcurrentMap> rdbCache_; - int Notify(const Key &key, const int32_t userId, const std::vector &val, const std::string &rdbDir, + int Notify(const Key &key, int32_t userId, const std::vector &val, const std::string &rdbDir, int rdbVersion); int GetEnableObserverCount(const Key &key); }; -- Gitee From f77e1f3b293be773ba457bd9e5cc061fd620e56f Mon Sep 17 00:00:00 2001 From: niudongyao Date: Mon, 10 Jul 2023 14:06:18 +0800 Subject: [PATCH 392/437] fix Signed-off-by: niudongyao --- .../service/data_share/data_share_service_impl.cpp | 2 +- .../published_data_subscriber_manager.cpp | 6 +++--- .../subscriber_managers/rdb_subscriber_manager.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index af1500da..f084a0fe 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -463,7 +463,7 @@ int32_t DataShareServiceImpl::OnAppUninstall( int32_t DataShareServiceImpl::OnAppExit(pid_t uid, pid_t pid, uint32_t tokenId, const std::string &bundleName) { - ZLOGI("AppExit uid=%{public}d, pid=%{public}d, tokenId=%{public}d, bundleName=%{public}s", + ZLOGI("AppExit uid=%{public}d, pid=%{public}d, tokenId=0x%{public}x, bundleName=%{public}s", uid, pid, tokenId, bundleName.c_str()); RdbSubscriberManager::GetInstance().Delete(tokenId); PublishedDataSubscriberManager::GetInstance().Delete(tokenId); diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index c1c70ae4..4972ae45 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -34,7 +34,7 @@ int PublishedDataSubscriberManager::Add( { publishedDataCache_.Compute( key, [&observer, &callerTokenId, this](const PublishedDataKey &key, std::vector &value) { - ZLOGI("add publish subscriber, uri %{public}s tokenId %{public}d", + ZLOGI("add publish subscriber, uri %{public}s tokenId 0x%{public}x", DistributedData::Anonymous::Change(key.key).c_str(), callerTokenId); value.emplace_back(observer, callerTokenId); return true; @@ -48,7 +48,7 @@ int PublishedDataSubscriberManager::Delete(const PublishedDataKey &key, uint32_t publishedDataCache_.ComputeIfPresent(key, [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { - ZLOGI("delete publish subscriber, uri %{public}s tokenId %{public}d", + ZLOGI("delete publish subscriber, uri %{public}s tokenId 0x%{public}x", DistributedData::Anonymous::Change(key.key).c_str(), callerTokenId); it = value.erase(it); } else { @@ -65,7 +65,7 @@ void PublishedDataSubscriberManager::Delete(uint32_t callerTokenId) publishedDataCache_.EraseIf([&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { - ZLOGI("erase start, uri is %{public}s, tokenId is %{public}d", + ZLOGI("erase start, uri is %{public}s, tokenId is 0x%{public}x", DistributedData::Anonymous::Change(key.key).c_str(), callerTokenId); it = value.erase(it); } else { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index 4bc41c77..cb8a9059 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -112,7 +112,7 @@ int RdbSubscriberManager::Add(const Key &key, const sptr { int result = E_OK; rdbCache_.Compute(key, [&observer, &context, executorPool, this](const auto &key, auto &value) { - ZLOGI("add subscriber, uri %{private}s tokenId %{public}d", key.uri.c_str(), context->callerTokenId); + ZLOGI("add subscriber, uri %{private}s tokenId 0x%{public}x", key.uri.c_str(), context->callerTokenId); std::vector node; node.emplace_back(observer, context->callerTokenId); ExecutorPool::Task task = [key, node, context, this]() { @@ -136,7 +136,7 @@ int RdbSubscriberManager::Delete(const Key &key, uint32_t callerTokenId) { auto result = rdbCache_.ComputeIfPresent(key, [&callerTokenId, this](const auto &key, std::vector &value) { - ZLOGI("delete subscriber, uri %{public}s tokenId %{public}d", + ZLOGI("delete subscriber, uri %{public}s tokenId 0x%{public}x", DistributedData::Anonymous::Change(key.uri).c_str(), callerTokenId); for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { @@ -159,7 +159,7 @@ void RdbSubscriberManager::Delete(uint32_t callerTokenId) rdbCache_.EraseIf([&callerTokenId, this](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end();) { if (it->callerTokenId == callerTokenId) { - ZLOGI("erase start, uri is %{public}s, tokenId %{public}d", + ZLOGI("erase start, uri is %{public}s, tokenId 0x%{public}x", DistributedData::Anonymous::Change(key.uri).c_str(), callerTokenId); it = value.erase(it); } else { -- Gitee From 19475e607d6f69a94d00aca3e2f33dd4e67c9ed5 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Sat, 8 Jul 2023 17:30:05 +0800 Subject: [PATCH 393/437] delete onnetworkonline Signed-off-by: renjiecui --- .../src/device_manager_adapter.cpp | 23 +------------------ .../src/process_communicator_impl.cpp | 3 +-- .../include/communicator/commu_types.h | 2 -- .../app/src/feature_stub_impl.cpp | 16 ------------- .../app/src/feature_stub_impl.h | 2 -- .../app/src/kvstore_data_service.cpp | 18 --------------- .../app/src/kvstore_data_service.h | 4 ---- .../app/src/kvstore_device_listener.cpp | 21 ++++------------- .../app/src/security/security.cpp | 4 ---- .../framework/feature/feature_system.cpp | 10 -------- .../include/feature/feature_system.h | 2 -- .../service/cloud/cloud_service_impl.cpp | 18 ++++++++++----- .../service/cloud/cloud_service_impl.h | 4 ++-- 13 files changed, 21 insertions(+), 106 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 99d9fc21..b7af5973 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -219,17 +219,6 @@ void DeviceManagerAdapter::Online(const DmDeviceInfo &info) KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_ONLINE); auto observers = GetObservers(); - - if (dvInfo.deviceName == DeviceManagerAdapter::cloudDmInfo.deviceName) { - for (const auto &item : observers) { // network available - if (item == nullptr) { - continue; - } - item->OnDeviceChanged(dvInfo, DeviceChangeType::DEVICE_NET_AVAILABLE); - } - return; - } - for (const auto &item : observers) { // notify db if (item == nullptr) { continue; @@ -308,16 +297,6 @@ void DeviceManagerAdapter::Offline(const DmDeviceInfo &info) return; } syncTask_.Erase(dvInfo.uuid); - if (dvInfo.deviceName == DeviceManagerAdapter::cloudDmInfo.deviceName) { - auto observers = GetObservers(); - for (const auto &item : observers) { // network unavailable - if (item == nullptr) { - continue; - } - item->OnDeviceChanged(dvInfo, DeviceChangeType::DEVICE_NET_UNAVAILABLE); - } - return; - } ZLOGI("[offline] uuid:%{public}s, name:%{public}s, type:%{public}d", KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_OFFLINE); @@ -588,7 +567,7 @@ bool DeviceManagerAdapter::RegOnNetworkChange() ZLOGE("new operator error.observer is nullptr"); return false; } - int nRet = DelayedSingleton::GetInstance()->RegisterNetConnCallback(observer); + int nRet = NetConnClient::GetInstance().RegisterNetConnCallback(observer); if (nRet != NETMANAGER_SUCCESS) { ZLOGE("RegisterNetConnCallback failed, ret = %{public}d", nRet); return false; diff --git a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp index 2e950e09..c93a2a97 100644 --- a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp +++ b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp @@ -195,8 +195,7 @@ void ProcessCommunicatorImpl::OnMessage(const DeviceInfo &info, const uint8_t *p void ProcessCommunicatorImpl::OnDeviceChanged(const DeviceInfo &info, const DeviceChangeType &type) const { - if (type == DeviceChangeType::DEVICE_ONREADY || type == DeviceChangeType::DEVICE_NET_AVAILABLE || - type == DeviceChangeType::DEVICE_NET_UNAVAILABLE) { + if (type == DeviceChangeType::DEVICE_ONREADY) { return; } std::lock_guard onDeviceChangeLockGuard(onDeviceChangeMutex_); diff --git a/services/distributeddataservice/adapter/include/communicator/commu_types.h b/services/distributeddataservice/adapter/include/communicator/commu_types.h index 95eed1f1..ca822697 100644 --- a/services/distributeddataservice/adapter/include/communicator/commu_types.h +++ b/services/distributeddataservice/adapter/include/communicator/commu_types.h @@ -57,8 +57,6 @@ enum class API_EXPORT DeviceChangeType { DEVICE_OFFLINE = 0, DEVICE_ONLINE = 1, DEVICE_ONREADY = 2, - DEVICE_NET_AVAILABLE = 3, - DEVICE_NET_UNAVAILABLE = 4, }; enum class API_EXPORT DeviceStatus { diff --git a/services/distributeddataservice/app/src/feature_stub_impl.cpp b/services/distributeddataservice/app/src/feature_stub_impl.cpp index b613c0bb..f1f52b91 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/services/distributeddataservice/app/src/feature_stub_impl.cpp @@ -108,20 +108,4 @@ int32_t FeatureStubImpl::OnReady(const std::string &device) } return featureImpl_->OnReady(device); } - -int32_t FeatureStubImpl::OnNetworkOnline() -{ - if (featureImpl_ == nullptr) { - return -1; - } - return featureImpl_->OnNetworkOnline(); -} - -int32_t FeatureStubImpl::OnNetworkOffline() -{ - if (featureImpl_ == nullptr) { - return -1; - } - return featureImpl_->OnNetworkOffline(); -} } diff --git a/services/distributeddataservice/app/src/feature_stub_impl.h b/services/distributeddataservice/app/src/feature_stub_impl.h index e3e3a905..b00646bc 100644 --- a/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/services/distributeddataservice/app/src/feature_stub_impl.h @@ -39,8 +39,6 @@ public: int32_t Online(const std::string &device); int32_t Offline(const std::string &device); int32_t OnReady(const std::string &device); - int32_t OnNetworkOnline(); - int32_t OnNetworkOffline(); private: std::shared_ptr featureImpl_; }; diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 932b2380..5c317362 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -689,22 +689,4 @@ int32_t KvStoreDataService::OnUpdate(const std::string &bundleName, int32_t user }); return 0; } - -int32_t KvStoreDataService::OnNetworkOnline() -{ - features_.ForEachCopies([](const auto &, sptr &value) { - value->OnNetworkOnline(); - return false; - }); - return 0; -} - -int32_t KvStoreDataService::OnNetworkOffline() -{ - features_.ForEachCopies([](const auto &, sptr &value) { - value->OnNetworkOffline(); - return false; - }); - return 0; -} } // namespace OHOS::DistributedKv diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index c668ae10..4a16d21c 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -77,10 +77,6 @@ public: int32_t OnUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); - int32_t OnNetworkOnline(); - - int32_t OnNetworkOffline(); - private: void NotifyAccountEvent(const AccountEventInfo &eventInfo); class KvStoreClientDeathObserverImpl { diff --git a/services/distributeddataservice/app/src/kvstore_device_listener.cpp b/services/distributeddataservice/app/src/kvstore_device_listener.cpp index 488891da..4d155a17 100644 --- a/services/distributeddataservice/app/src/kvstore_device_listener.cpp +++ b/services/distributeddataservice/app/src/kvstore_device_listener.cpp @@ -23,22 +23,11 @@ namespace OHOS::DistributedKv { void KvStoreDeviceListener::OnDeviceChanged( const AppDistributedKv::DeviceInfo &info, const AppDistributedKv::DeviceChangeType &type) const { - switch (type) { - case AppDistributedKv::DeviceChangeType::DEVICE_ONLINE: - kvStoreDataService_.SetCompatibleIdentify(info); - kvStoreDataService_.OnDeviceOnline(info); - break; - case AppDistributedKv::DeviceChangeType::DEVICE_ONREADY: - kvStoreDataService_.OnDeviceOnReady(info); - break; - case AppDistributedKv::DeviceChangeType::DEVICE_NET_AVAILABLE: - kvStoreDataService_.OnNetworkOnline(); - break; - case AppDistributedKv::DeviceChangeType::DEVICE_NET_UNAVAILABLE: - kvStoreDataService_.OnNetworkOffline(); - break; - default: - break; + if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONLINE) { + kvStoreDataService_.SetCompatibleIdentify(info); + kvStoreDataService_.OnDeviceOnline(info); + } else if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONREADY) { + kvStoreDataService_.OnDeviceOnReady(info); } ZLOGI("device is %{public}d", type); } diff --git a/services/distributeddataservice/app/src/security/security.cpp b/services/distributeddataservice/app/src/security/security.cpp index 3359f6f9..881217ef 100644 --- a/services/distributeddataservice/app/src/security/security.cpp +++ b/services/distributeddataservice/app/src/security/security.cpp @@ -141,10 +141,6 @@ void Security::OnDeviceChanged(const AppDistributedKv::DeviceInfo &info, return; } - if (type == AppDistributedKv::DeviceChangeType::DEVICE_NET_AVAILABLE || - type == AppDistributedKv::DeviceChangeType::DEVICE_NET_UNAVAILABLE) { - return; - } bool isOnline = type == AppDistributedKv::DeviceChangeType::DEVICE_ONLINE; if (isOnline) { (void)GetSensitiveByUuid(info.uuid); diff --git a/services/distributeddataservice/framework/feature/feature_system.cpp b/services/distributeddataservice/framework/feature/feature_system.cpp index 26b4f4e9..74907ec8 100644 --- a/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/services/distributeddataservice/framework/feature/feature_system.cpp @@ -106,15 +106,5 @@ int32_t FeatureSystem::Feature::OnBind(const FeatureSystem::Feature::BindInfo &b { return E_OK; } - -int32_t FeatureSystem::Feature::OnNetworkOnline() -{ - return E_OK; -} - -int32_t FeatureSystem::Feature::OnNetworkOffline() -{ - return E_OK; -} } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/feature/feature_system.h b/services/distributeddataservice/framework/include/feature/feature_system.h index 66a1e6b0..d549cc6d 100644 --- a/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/services/distributeddataservice/framework/include/feature/feature_system.h @@ -53,8 +53,6 @@ public: virtual int32_t Online(const std::string &device); virtual int32_t Offline(const std::string &device); virtual int32_t OnReady(const std::string &device); - virtual int32_t OnNetworkOnline(); - virtual int32_t OnNetworkOffline(); }; using Creator = std::function()>; static FeatureSystem &GetInstance(); diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 8929c7a0..1e3992bc 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -36,6 +36,7 @@ using namespace std::chrono; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using Account = OHOS::DistributedKv::AccountDelegate; using AccessTokenKit = Security::AccessToken::AccessTokenKit; +const std::string NET_UUID = "netUuid"; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; const CloudServiceImpl::Work CloudServiceImpl::HANDLERS[WORK_BUTT] = { &CloudServiceImpl::DoSubscribe, @@ -239,10 +240,12 @@ int32_t CloudServiceImpl::OnUserChange(uint32_t code, const std::string &user, c return E_OK; } -int32_t CloudServiceImpl::OnNetworkOnline() +int32_t CloudServiceImpl::Online(const std::string &device) { - ZLOGI("OnNetworkOnline"); - + if (device != NET_UUID) { + ZLOGI("Not network online"); + return SUCCESS; + } std::vector users; Account::GetInstance()->QueryUsers(users); if (users.empty()) { @@ -260,15 +263,18 @@ int32_t CloudServiceImpl::OnNetworkOnline() it++; continue; } - syncManager_.DoCloudSync( { *it } ); + syncManager_.DoCloudSync({ *it }); it++; } return SUCCESS; } -int32_t CloudServiceImpl::OnNetworkOffline() +int32_t CloudServiceImpl::Offline(const std::string &device) { - ZLOGI("OnNetworkOffline"); + if (device != NET_UUID) { + ZLOGI("Not network offline"); + return SUCCESS; + } std::vector users; Account::GetInstance()->QueryUsers(users); if (users.empty()) { diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.h b/services/distributeddataservice/service/cloud/cloud_service_impl.h index 7dcedfd4..93803ab3 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.h @@ -38,8 +38,8 @@ public: int32_t OnBind(const BindInfo &info) override; int32_t OnUserChange(uint32_t code, const std::string &user, const std::string &account) override; int32_t OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId) override; - int32_t OnNetworkOnline() override; - int32_t OnNetworkOffline() override; + int32_t Online(const std::string &device) override; + int32_t Offline(const std::string &device) override; private: class Factory { -- Gitee From f744b99c468a059e96c7edaa50be31d07029f43d Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 10 Jul 2023 15:34:08 +0800 Subject: [PATCH 394/437] update Signed-off-by: zuojiangjiang --- services/distributeddataservice/service/rdb/rdb_cloud.cpp | 2 +- .../distributeddataservice/service/rdb/rdb_general_store.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/rdb/rdb_cloud.cpp b/services/distributeddataservice/service/rdb/rdb_cloud.cpp index 1df3b1f8..e41b7664 100644 --- a/services/distributeddataservice/service/rdb/rdb_cloud.cpp +++ b/services/distributeddataservice/service/rdb/rdb_cloud.cpp @@ -125,7 +125,7 @@ DBStatus RdbCloud::ConvertStatus(DistributedData::GeneralError error) case GeneralError::E_RECODE_LIMIT_EXCEEDED: return DBStatus::CLOUD_FULL_RECORDS; case GeneralError::E_NO_SPACE_FOR_ASSET: - return DBStatus::CLOUD_SYNC_UNSET; // for test + return DBStatus::CLOUD_ASSET_SPACE_INSUFFICIENT; default: ZLOGI("error:0x%{public}x", error); break; diff --git a/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 90fdea28..31944ad9 100644 --- a/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -349,7 +349,7 @@ RdbGeneralStore::GenErr RdbGeneralStore::ConvertStatus(DistributedDB::DBStatus s return GenErr::E_LOCKED_BY_OTHERS; case DBStatus::CLOUD_FULL_RECORDS: return GenErr::E_RECODE_LIMIT_EXCEEDED; - case DBStatus::CLOUD_SYNC_UNSET: // for test + case DBStatus::CLOUD_ASSET_SPACE_INSUFFICIENT: return GenErr::E_NO_SPACE_FOR_ASSET; default: ZLOGI("status:0x%{public}x", status); -- Gitee From a93568abcef45e877d316486c08a0b9928737e09 Mon Sep 17 00:00:00 2001 From: dboy190 Date: Mon, 10 Jul 2023 16:03:46 +0800 Subject: [PATCH 395/437] fix test problem Signed-off-by: dboy190 --- .../adapter/communicator/src/softbus_client.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp index 4f9f41be..72d40403 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp @@ -88,6 +88,8 @@ Status SoftBusClient::OpenConnect(uint32_t totalLength) if (result != Status::SUCCESS) { status_ = ConnectStatus::DISCONNECT; } + + status_ = ConnectStatus::CONNECT_OK; return result; } @@ -118,6 +120,8 @@ Status SoftBusClient::SwitchChannel(uint32_t totalLength) return Status::SUCCESS; } + ZLOGD("switch %{public}s,session:%{public}s,connId:%{public}d,routeType:%{public}d to wifi or p2p.", + KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), connId_, routeType_); RestoreDefaultValue(); return Open(GetSessionAttribute(true)); } @@ -127,6 +131,8 @@ Status SoftBusClient::SwitchChannel(uint32_t totalLength) return Status::SUCCESS; } + ZLOGD("switch %{public}s,session:%{public}s,connId:%{public}d,routeType:%{public}d to ble or br.", + KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), connId_, routeType_); CloseSession(connId_); RestoreDefaultValue(); return Open(GetSessionAttribute(false)); @@ -155,8 +161,8 @@ Status SoftBusClient::Open(SessionAttribute attr) { int id = OpenSession(pipe_.pipeId.c_str(), pipe_.pipeId.c_str(), DmAdapter::GetInstance().ToNetworkID(device_.deviceId).c_str(), "GROUP_ID", &attr); - ZLOGI("open %{public}s,session:%{public}s,connId:%{public}d,linkNum:%{public}d", - KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), id, attr.linkTypeNum); + ZLOGI("open %{public}s,session:%{public}s,connId:%{public}d,linkNum:%{public}d,strategy:%{public}d", + KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), id, attr.linkTypeNum, strategy_); if (id < 0) { ZLOGW("Open %{public}s, type:%{public}d failed, connId:%{public}d", pipe_.pipeId.c_str(), attr.dataType, id); -- Gitee From 52e5250145755020fb3646cc5377c9cdc2d0fafa Mon Sep 17 00:00:00 2001 From: dboy190 Date: Mon, 10 Jul 2023 16:53:39 +0800 Subject: [PATCH 396/437] fix test problem and add log Signed-off-by: dboy190 --- .../adapter/communicator/src/app_pipe_mgr.cpp | 2 +- .../adapter/communicator/src/softbus_client.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp index 240777a3..a2ac4894 100644 --- a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp +++ b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp @@ -66,7 +66,7 @@ Status AppPipeMgr::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, ZLOGW("Input is invalid, maxSize:%d, current size:%u", DataBuffer::MAX_TRANSFER_SIZE, dataInfo.length); return Status::ERROR; } - ZLOGD("pipeInfo:%s ,size:%u", pipeInfo.pipeId.c_str(), dataInfo.length); + ZLOGD("pipeInfo:%s ,size:%u, total length:%u", pipeInfo.pipeId.c_str(), dataInfo.length, totalLength); std::shared_ptr appPipeHandler; { std::lock_guard lock(dataBusMapMutex_); diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp index 72d40403..63ad56fa 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp @@ -70,7 +70,8 @@ Status SoftBusClient::Send(const DataInfo &dataInfo, uint32_t totalLength) return result; } - ZLOGD("send data connId:%{public}d, data size:%{public}u.", connId_, dataInfo.length); + ZLOGD("send data connId:%{public}d, data size:%{public}u, total length:%{public}u.", + connId_, dataInfo.length, totalLength); int32_t ret = SendBytes(connId_, dataInfo.data, dataInfo.length); if (ret != SOFTBUS_OK) { ZLOGE("send data to connId%{public}d failed, ret:%{public}d.", connId_, ret); -- Gitee From d98210870ce8896e33e105278034c7135581314c Mon Sep 17 00:00:00 2001 From: dboy190 Date: Mon, 10 Jul 2023 16:57:07 +0800 Subject: [PATCH 397/437] fix switch problem Signed-off-by: dboy190 --- .../adapter/communicator/src/softbus_client.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp index 63ad56fa..ecba7a53 100644 --- a/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_client.cpp @@ -123,6 +123,7 @@ Status SoftBusClient::SwitchChannel(uint32_t totalLength) ZLOGD("switch %{public}s,session:%{public}s,connId:%{public}d,routeType:%{public}d to wifi or p2p.", KvStoreUtils::ToBeAnonymous(device_.deviceId).c_str(), pipe_.pipeId.c_str(), connId_, routeType_); + CloseSession(connId_); RestoreDefaultValue(); return Open(GetSessionAttribute(true)); } -- Gitee From 7d8e9a78af788e07afba37b09a6fe113d2f122e8 Mon Sep 17 00:00:00 2001 From: dboy190 Date: Mon, 10 Jul 2023 17:13:49 +0800 Subject: [PATCH 398/437] fix codecheck Signed-off-by: dboy190 --- .../adapter/communicator/src/process_communicator_impl.cpp | 3 ++- .../adapter/include/communicator/process_communicator_impl.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp index 8ba2863f..4b435d1e 100644 --- a/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp +++ b/services/distributeddataservice/adapter/communicator/src/process_communicator_impl.cpp @@ -116,7 +116,8 @@ DBStatus ProcessCommunicatorImpl::SendData(const DeviceInfos &dstDevInfo, const return SendData(dstDevInfo, data, length, totalLength); } -DBStatus ProcessCommunicatorImpl::SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, uint32_t totalLength) +DBStatus ProcessCommunicatorImpl::SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, + uint32_t totalLength) { PipeInfo pi = {thisProcessLabel_, ""}; const DataInfo dataInfo = { const_cast(data), length}; diff --git a/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h b/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h index fbe08349..259f775e 100644 --- a/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h +++ b/services/distributeddataservice/adapter/include/communicator/process_communicator_impl.h @@ -46,7 +46,8 @@ public: DBStatus RegOnDataReceive(const OnDataReceive &callback) override; DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length) override; - DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, uint32_t totalLength) override; + DBStatus SendData(const DeviceInfos &dstDevInfo, const uint8_t *data, uint32_t length, + uint32_t totalLength) override; uint32_t GetMtuSize() override; uint32_t GetMtuSize(const DeviceInfos &devInfo) override; DeviceInfos GetLocalDeviceInfos() override; -- Gitee From 36fbcccd7c3531f6c0ddec326d5a4e0b7fe4858a Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Mon, 10 Jul 2023 21:46:28 +0800 Subject: [PATCH 399/437] fix online bug Signed-off-by: zuojiangjiang --- .../service/matrix/src/device_matrix.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/matrix/src/device_matrix.cpp b/services/distributeddataservice/service/matrix/src/device_matrix.cpp index a1ee0235..44679550 100644 --- a/services/distributeddataservice/service/matrix/src/device_matrix.cpp +++ b/services/distributeddataservice/service/matrix/src/device_matrix.cpp @@ -83,9 +83,7 @@ void DeviceMatrix::Online(const std::string &device) offLines_.erase(it); } onLines_.insert_or_assign(device, mask); - if (mask.bitset != 0) { - EventCenter::GetInstance().PostEvent(std::make_unique(MATRIX_ONLINE, device, mask.bitset)); - } + EventCenter::GetInstance().PostEvent(std::make_unique(MATRIX_ONLINE, device, mask.bitset)); } void DeviceMatrix::Offline(const std::string &device) -- Gitee From 5feef0bcda4b966038414dff857059237d5c2d68 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Mon, 10 Jul 2023 22:13:10 +0800 Subject: [PATCH 400/437] =?UTF-8?q?=E8=B7=A8=E8=AE=BE=E5=A4=87=E6=99=AE?= =?UTF-8?q?=E9=80=9Auri=E6=8B=96=E6=8B=BD=20=E6=A3=80=E8=A7=86=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9=20Signed-off-by:=20genglingxia=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../distributeddataservice/service/BUILD.gn | 1 - .../service/udmf/BUILD.gn | 10 ++-- .../service/udmf/data_manager.cpp | 55 ++++++++++--------- .../service/udmf/data_manager.h | 2 + .../udmf/preprocess/preprocess_utils.cpp | 12 ++-- 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index c6a237e6..4fbe91e3 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -128,7 +128,6 @@ ohos_shared_library("distributeddatasvc") { "huks:libhukssdk", "ipc:ipc_core", "kv_store:distributeddata_inner", - "app_file_service:remote_file_share_native", "relational_store:native_rdb", ] subsystem_name = "distributeddatamgr" diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index ca34d007..2b812cf3 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -33,7 +33,7 @@ config("module_public_config") { "${kv_store_path}/frameworks/common", "${file_service_path}/interfaces/innerkits/native/remote_file_share/include", "${device_manager_path}/interfaces/inner_kits/native_cpp/include", - "${data_service_path}/adapter/include/communicator" + "${data_service_path}/adapter/include/communicator", ] } @@ -57,10 +57,10 @@ ohos_shared_library("udmf_server") { configs = [ ":module_public_config" ] - deps = [ "${data_service_path}/framework:distributeddatasvcfwk", - "${data_service_path}/adapter:distributeddata_adapter", - - ] + deps = [ + "${data_service_path}/adapter:distributeddata_adapter", + "${data_service_path}/framework:distributeddatasvcfwk", + ] external_deps = [ "ability_base:zuri", diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 280f5749..744a8b4f 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -26,6 +26,8 @@ namespace OHOS { namespace UDMF { +using namespace OHOS::AppFileService; + const std::string MSDP_PROCESS_NAME = "msdp_sa"; const std::string DATA_PREFIX = "udmf://"; DataManager::DataManager() @@ -44,7 +46,8 @@ DataManager &DataManager::GetInstance() return instance; } -bool DataManager::IsFileType(UDType udType){ +bool DataManager::IsFileType(UDType udType) +{ if (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO || udType == UDType::FOLDER) { return true; @@ -70,25 +73,23 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st return E_UNKNOWN; } int32_t userId = PreProcessUtils::GetHapUidByToken(option.tokenId); - for (const auto &record : unifiedData.GetRecords()) - { + for (const auto &record : unifiedData.GetRecords()) { auto type = record->GetType(); if (IsFileType(type)) { auto file = static_cast(record.get()); - struct AppFileService::ModuleRemoteFileShare::HmdfsUriInfo dfsUriInfo; - int ret = AppFileService::ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); - if(ret != 0 || dfsUriInfo.uriStr.empty()) { - ZLOGW("Get remoteUri failed, ret = %{public}d, uri: %{public}s, userId: %{public}d.", ret, file->GetUri().c_str(), userId); - return E_DFS_URI; - } - - file->SetRemoteUri(dfsUriInfo.uriStr); + struct ModuleRemoteFileShare::HmdfsUriInfo dfsUriInfo; + int ret = ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); + if (ret != 0 || dfsUriInfo.uriStr.empty()) { + ZLOGE("Get remoteUri failed, ret = %{public}d, uri: %{public}s, userId: %{public}d.", + ret, file->GetUri().c_str(), userId); + return E_FS_ERROR; + } + file->SetRemoteUri(dfsUriInfo.uriStr); } record->SetUid(PreProcessUtils::IdGenerator()); } - std::string intention = unifiedData.GetRuntime()->key.intention; auto store = storeCache_.GetStore(intention); if (store == nullptr) { @@ -141,21 +142,10 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified return E_ERROR; } if (runtime->createPackage != bundleName) { + std::string localDeviceId = PreProcessUtils::GetLocalDeviceId(); auto records = unifiedData.GetRecords(); for (auto record : records) { - auto type = record->GetType(); - std::string uri = ""; - if (IsFileType(type)) { - auto file = static_cast(record.get()); - uri = file->GetUri(); - - std::string localDeviceId=PreProcessUtils::GetLocalDeviceId(); - ZLOGE("DataManager::RetrieveData, localDeviceId=%{public}s, remoteDeviceId=%{public}s,uri=%{public}s,remoteUri=%{public}s.", localDeviceId.c_str(), (runtime->deviceId).c_str(),file->GetUri().c_str(),file->GetRemoteUri().c_str()); - if (localDeviceId != runtime->deviceId) { - uri = file->GetRemoteUri(); - file->SetUri(uri); // cross dev, need dis path. - } - } + std::string uri = ConvertUri(record, localDeviceId, runtime->deviceId); if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { return E_NO_PERMISSION; } @@ -167,6 +157,21 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified } return E_OK; } +std::string DataManager::ConvertUri(std::shared_ptr record, std::string localDevId, + std::string remoteDevId) +{ + std::string uri = ""; + auto type = record->GetType(); + if (IsFileType(type)) { + auto file = static_cast(record.get()); + uri = file->GetUri(); + if (localDevId != remoteDevId) { + uri = file->GetRemoteUri(); + file->SetUri(uri); // cross dev, need dis path. + } + } + return uri; +} int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector &unifiedDataSet) { diff --git a/services/distributeddataservice/service/udmf/data_manager.h b/services/distributeddataservice/service/udmf/data_manager.h index 1e1718c5..04b5c1fb 100755 --- a/services/distributeddataservice/service/udmf/data_manager.h +++ b/services/distributeddataservice/service/udmf/data_manager.h @@ -47,6 +47,8 @@ private: DataManager(); bool IsFileType(UDType udType); int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); + std::string ConvertUri(std::shared_ptr record, std::string localDevId, std::string remoteDevId); + StoreCache storeCache_; std::map authorizationMap_; }; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp index d02b20ad..f20ba1d6 100755 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#define LOG_TAG "preprocess_utils" + #include "preprocess_utils.h" #include @@ -21,6 +23,7 @@ #include "bundlemgr/bundle_mgr_client_impl.h" #include "ipc_skeleton.h" #include "device_manager_adapter.h" +#include "log_print.h" namespace OHOS { namespace UDMF { @@ -52,10 +55,7 @@ int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption & std::string PreProcessUtils::GetLocalDeviceId() { auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice(); - - std::string encryptedUuid; - encryptedUuid = DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); - return encryptedUuid; + return DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); } std::string PreProcessUtils::IdGenerator() @@ -86,10 +86,12 @@ int32_t PreProcessUtils::GetHapUidByToken(uint32_t tokenId) Security::AccessToken::HapTokenInfo tokenInfo; auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo); if (result != Security::AccessToken::AccessTokenKitRet::RET_SUCCESS) { - return -1; + ZLOGE("GetHapUidByToken failed, result = %{public}d.", result); + return E_ERROR; } return tokenInfo.userID; } + bool PreProcessUtils::GetHapBundleNameByToken(int tokenId, std::string &bundleName) { Security::AccessToken::HapTokenInfo hapInfo; -- Gitee From 24649ca7c7536ed3f2bd27927820c922c65a0bca Mon Sep 17 00:00:00 2001 From: ding_dong_dong Date: Tue, 11 Jul 2023 11:27:44 +0800 Subject: [PATCH 401/437] modify asan build Signed-off-by: ding_dong_dong --- .../objectservicestub_fuzzer/BUILD.gn | 10 +---- .../fuzztest/rdbresultsetstub_fuzzer/BUILD.gn | 37 ------------------- .../udmfservice_fuzzer/udmfservice_fuzzer.cpp | 4 +- 3 files changed, 4 insertions(+), 47 deletions(-) diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn index 2db37d6e..cd27ac04 100644 --- a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn @@ -25,15 +25,9 @@ ohos_fuzztest("ObjectServiceStubFuzzTest") { "${data_service_path}/framework/include", "${data_service_path}/service/backup/include", "${data_service_path}/service/bootstrap/include", - "${data_service_path}/service/cloud", "${data_service_path}/service/config/include", "${data_service_path}/service/crypto/include", - "${data_service_path}/service/data_share", - "${data_service_path}/service/kvdb", - "${data_service_path}/service/matrix/include", "${data_service_path}/service/object", - "${data_service_path}/service/permission/include", - "${data_service_path}/service/rdb", "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", "${kv_store_path}/frameworks/innerkitsimpl/kvdb/include", @@ -56,6 +50,7 @@ ohos_fuzztest("ObjectServiceStubFuzzTest") { ] sources = [ + "${data_service_path}/service/backup/src/backup_manager.cpp", "${data_service_path}/service/bootstrap/src/bootstrap.cpp", "${data_service_path}/service/config/src/config_factory.cpp", "${data_service_path}/service/config/src/model/backup_config.cpp", @@ -66,14 +61,11 @@ ohos_fuzztest("ObjectServiceStubFuzzTest") { "${data_service_path}/service/config/src/model/network_config.cpp", "${data_service_path}/service/config/src/model/protocol_config.cpp", "${data_service_path}/service/crypto/src/crypto_manager.cpp", - "${data_service_path}/service/matrix/src/device_matrix.cpp", - "${data_service_path}/service/matrix/src/matrix_event.cpp", "${data_service_path}/service/object/object_callback_proxy.cpp", "${data_service_path}/service/object/object_data_listener.cpp", "${data_service_path}/service/object/object_manager.cpp", "${data_service_path}/service/object/object_service_impl.cpp", "${data_service_path}/service/object/object_service_stub.cpp", - "${data_service_path}/service/permission/src/permit_delegate.cpp", "objectservicestub_fuzzer.cpp", ] diff --git a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn index 494fd1c0..ef1263e8 100644 --- a/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/rdbresultsetstub_fuzzer/BUILD.gn @@ -23,16 +23,6 @@ ohos_fuzztest("RdbResultSetStubFuzzTest") { "${data_service_path}/adapter/include", "${data_service_path}/app/src", "${data_service_path}/framework/include", - "${data_service_path}/service/backup/include", - "${data_service_path}/service/bootstrap/include", - "${data_service_path}/service/cloud", - "${data_service_path}/service/config/include", - "${data_service_path}/service/crypto/include", - "${data_service_path}/service/data_share", - "${data_service_path}/service/kvdb", - "${data_service_path}/service/matrix/include", - "${data_service_path}/service/object", - "${data_service_path}/service/permission/include", "${data_service_path}/service/rdb", "${kv_store_common_path}", "${kv_store_path}/frameworks/innerkitsimpl/distributeddatafwk/include", @@ -41,7 +31,6 @@ ohos_fuzztest("RdbResultSetStubFuzzTest") { "${kv_store_distributeddb_path}/include/", "${kv_store_distributeddb_path}/interfaces/include/", "${kv_store_distributeddb_path}/interfaces/include/relational", - "${dataobject_path}/frameworks/innerkitsimpl/include", "${relational_store_path}/interfaces/inner_api/cloud_data/include", "${relational_store_path}/interfaces/inner_api/rdb/include", "//third_party/json/single_include", @@ -58,34 +47,8 @@ ohos_fuzztest("RdbResultSetStubFuzzTest") { ] sources = [ - "${data_service_path}/service/bootstrap/src/bootstrap.cpp", - "${data_service_path}/service/config/src/config_factory.cpp", - "${data_service_path}/service/config/src/model/backup_config.cpp", - "${data_service_path}/service/config/src/model/checker_config.cpp", - "${data_service_path}/service/config/src/model/component_config.cpp", - "${data_service_path}/service/config/src/model/directory_config.cpp", - "${data_service_path}/service/config/src/model/global_config.cpp", - "${data_service_path}/service/config/src/model/network_config.cpp", - "${data_service_path}/service/config/src/model/protocol_config.cpp", - "${data_service_path}/service/crypto/src/crypto_manager.cpp", - "${data_service_path}/service/matrix/src/device_matrix.cpp", - "${data_service_path}/service/matrix/src/matrix_event.cpp", - "${data_service_path}/service/permission/src/permit_delegate.cpp", - "${data_service_path}/service/rdb/rdb_asset_loader.cpp", - "${data_service_path}/service/rdb/rdb_cloud.cpp", - "${data_service_path}/service/rdb/rdb_cloud_data_translate.cpp", - "${data_service_path}/service/rdb/rdb_cursor.cpp", - "${data_service_path}/service/rdb/rdb_general_store.cpp", - "${data_service_path}/service/rdb/rdb_notifier_proxy.cpp", - "${data_service_path}/service/rdb/rdb_query.cpp", "${data_service_path}/service/rdb/rdb_result_set_impl.cpp", "${data_service_path}/service/rdb/rdb_result_set_stub.cpp", - "${data_service_path}/service/rdb/rdb_service_impl.cpp", - "${data_service_path}/service/rdb/rdb_service_stub.cpp", - "${data_service_path}/service/rdb/rdb_store_observer_impl.cpp", - "${data_service_path}/service/rdb/rdb_syncer.cpp", - "${data_service_path}/service/rdb/rdb_watcher.cpp", - "${data_service_path}/service/rdb/value_proxy.cpp", "rdbresultsetstub_fuzzer.cpp", ] diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp index 010f5bda..dda466ec 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp +++ b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp @@ -26,10 +26,12 @@ using namespace OHOS::UDMF; namespace OHOS { const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +const uint32_t CODE_MIN = 0; +const uint32_t CODE_MAX = 10; bool OnRemoteRequestFuzz(const uint8_t* data, size_t size) { - uint32_t code = static_cast(*data); + uint32_t code = static_cast(*data) % (CODE_MAX - CODE_MIN + 1) + CODE_MIN; MessageParcel request; request.WriteInterfaceToken(INTERFACE_TOKEN); request.WriteBuffer(data, size); -- Gitee From 20c6cbd73f28787cdc0943e168e59345914b1c55 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Tue, 11 Jul 2023 11:23:36 +0800 Subject: [PATCH 402/437] =?UTF-8?q?drag=5Fcross=5Fdev=20=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: genglingxia --- .../service/udmf/data_manager.cpp | 19 +++++++------------ .../service/udmf/data_manager.h | 4 ++-- .../udmf/preprocess/preprocess_utils.h | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 744a8b4f..ec92b385 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -48,11 +48,8 @@ DataManager &DataManager::GetInstance() bool DataManager::IsFileType(UDType udType) { - if (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO - || udType == UDType::FOLDER) { - return true; - } - return false; + return (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO + || udType == UDType::FOLDER); } int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key) @@ -80,8 +77,7 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st struct ModuleRemoteFileShare::HmdfsUriInfo dfsUriInfo; int ret = ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); if (ret != 0 || dfsUriInfo.uriStr.empty()) { - ZLOGE("Get remoteUri failed, ret = %{public}d, uri: %{public}s, userId: %{public}d.", - ret, file->GetUri().c_str(), userId); + ZLOGE("Get remoteUri failed, ret = %{public}d, userId: %{public}d.", ret, userId); return E_FS_ERROR; } file->SetRemoteUri(dfsUriInfo.uriStr); @@ -157,12 +153,11 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified } return E_OK; } -std::string DataManager::ConvertUri(std::shared_ptr record, std::string localDevId, - std::string remoteDevId) +std::string DataManager::ConvertUri(std::shared_ptr record, const std::string &localDevId, + const std::string &remoteDevId) { - std::string uri = ""; - auto type = record->GetType(); - if (IsFileType(type)) { + std::string uri; + if (record != nullptr && IsFileType(record->GetType())) { auto file = static_cast(record.get()); uri = file->GetUri(); if (localDevId != remoteDevId) { diff --git a/services/distributeddataservice/service/udmf/data_manager.h b/services/distributeddataservice/service/udmf/data_manager.h index 04b5c1fb..4f0c0293 100755 --- a/services/distributeddataservice/service/udmf/data_manager.h +++ b/services/distributeddataservice/service/udmf/data_manager.h @@ -47,8 +47,8 @@ private: DataManager(); bool IsFileType(UDType udType); int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); - std::string ConvertUri(std::shared_ptr record, std::string localDevId, std::string remoteDevId); - + std::string ConvertUri(std::shared_ptr record, const std::string &localDevId, + const std::string &remoteDevId); StoreCache storeCache_; std::map authorizationMap_; }; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 15c18cb3..52759057 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -30,7 +30,7 @@ public: static int32_t RuntimeDataImputation(UnifiedData &data, CustomOption &option); static std::string IdGenerator(); static time_t GetTimeStamp(); - static int32_t GetHapUidByToken(uint32_t tokenId); + static int32_t GetHapUidByToken(uint32_t tokenId); static bool GetHapBundleNameByToken(int tokenId, std::string &bundleName); static bool GetNativeProcessNameByToken(int tokenId, std::string &processName); static std::string GetLocalDeviceId(); // uuid -- Gitee From fe3bc6687846e8c39d73514c251919ba4f0e6b64 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Tue, 11 Jul 2023 14:12:49 +0800 Subject: [PATCH 403/437] update Signed-off-by: zuojiangjiang --- .../app/src/kvstore_meta_manager.cpp | 28 +++++++++++-------- .../framework/include/utils/ref_count.h | 2 +- .../service/kvdb/kvdb_service_impl.cpp | 2 +- .../service/matrix/include/device_matrix.h | 3 +- .../service/matrix/include/matrix_event.h | 4 +++ .../service/matrix/src/device_matrix.cpp | 8 ++++-- .../service/matrix/src/matrix_event.cpp | 10 +++++++ 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index 960dcad3..95a972ff 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -37,6 +37,7 @@ #include "utils/anonymous.h" #include "utils/block_integer.h" #include "utils/crypto.h" +#include "utils/ref_count.h" namespace OHOS { namespace DistributedKv { @@ -107,27 +108,28 @@ void KvStoreMetaManager::InitBroadcast() void KvStoreMetaManager::InitDeviceOnline() { ZLOGI("observer matrix online event."); + using DBStatuses = std::map; EventCenter::GetInstance().Subscribe(DeviceMatrix::MATRIX_ONLINE, [this](const Event &event) { - const MatrixEvent &matrixEvent = static_cast(event); + auto &matrixEvent = static_cast(event); auto mask = matrixEvent.GetMask(); auto deviceId = matrixEvent.GetDeviceId(); auto store = GetMetaKvStore(); + auto onComplete = [deviceId, mask, refCount = matrixEvent.StealRefCount()](const DBStatuses &) mutable { + ZLOGD("matrix 0x%{public}08x device:%{public}s online", mask, Anonymous::Change(deviceId).c_str()); + auto finEvent = std::make_unique(DeviceMatrix::MATRIX_META_FINISHED, deviceId, mask); + finEvent->SetRefCount(std::move(refCount)); + DeviceMatrix::GetInstance().OnExchanged(deviceId, DeviceMatrix::META_STORE_MASK); + EventCenter::GetInstance().PostEvent(std::move(finEvent)); + }; if (((mask & DeviceMatrix::META_STORE_MASK) != 0) && store != nullptr) { - auto onComplete = [deviceId, mask](const std::map &) { - ZLOGI("online sync complete"); - auto event = std::make_unique(DeviceMatrix::MATRIX_META_FINISHED, deviceId, mask); - DeviceMatrix::GetInstance().OnExchanged(deviceId, DeviceMatrix::META_STORE_MASK); - EventCenter::GetInstance().PostEvent(std::move(event)); - }; auto status = store->Sync({ deviceId }, DistributedDB::SyncMode::SYNC_MODE_PUSH_PULL, onComplete); if (status == OK) { return; } - ZLOGW("meta db sync error %{public}d.", status); + ZLOGW("meta online sync error 0x%{public}08x device:%{public}s %{public}d", mask, + Anonymous::Change(deviceId).c_str(), status); } - - auto finEvent = std::make_unique(DeviceMatrix::MATRIX_META_FINISHED, deviceId, mask); - EventCenter::GetInstance().PostEvent(std::move(finEvent)); + onComplete({}); }); } @@ -365,7 +367,9 @@ void KvStoreMetaManager::MetaDeviceChangeListenerImpl::OnDeviceChanged(const App DeviceMatrix::GetInstance().Offline(info.uuid); break; case AppDistributedKv::DeviceChangeType::DEVICE_ONLINE: - DeviceMatrix::GetInstance().Online(info.uuid); + DeviceMatrix::GetInstance().Online(info.uuid, RefCount([deviceId = info.uuid]() { + DmAdapter::GetInstance().NotifyReadyEvent(deviceId); + })); break; default: ZLOGI("flag:%{public}d", type); diff --git a/services/distributeddataservice/framework/include/utils/ref_count.h b/services/distributeddataservice/framework/include/utils/ref_count.h index 09fdbeb3..eb868790 100644 --- a/services/distributeddataservice/framework/include/utils/ref_count.h +++ b/services/distributeddataservice/framework/include/utils/ref_count.h @@ -23,7 +23,7 @@ namespace OHOS::DistributedData { class API_EXPORT RefCount final { public: RefCount(); - explicit RefCount(std::function action); + RefCount(std::function action); RefCount(const RefCount &other); RefCount(RefCount &&other) noexcept; RefCount &operator=(const RefCount &other); diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index db17f3ca..40a4709a 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -70,7 +70,7 @@ KVDBServiceImpl::KVDBServiceImpl() EventCenter::GetInstance().Subscribe(DeviceMatrix::MATRIX_META_FINISHED, [this](const Event &event) { auto &matrixEvent = static_cast(event); auto deviceId = matrixEvent.GetDeviceId(); - RefCount refCount([deviceId] { DMAdapter::GetInstance().NotifyReadyEvent(deviceId); }); + auto refCount = matrixEvent.StealRefCount(); std::vector metaData; auto prefix = StoreMetaData::GetPrefix({ DMAdapter::GetInstance().GetLocalDevice().uuid }); if (!MetaDataManager::GetInstance().LoadMeta(prefix, metaData)) { diff --git a/services/distributeddataservice/service/matrix/include/device_matrix.h b/services/distributeddataservice/service/matrix/include/device_matrix.h index c04223aa..4298f3b6 100644 --- a/services/distributeddataservice/service/matrix/include/device_matrix.h +++ b/services/distributeddataservice/service/matrix/include/device_matrix.h @@ -20,6 +20,7 @@ #include "lru_bucket.h" #include "metadata/matrix_meta_data.h" #include "metadata/store_meta_data.h" +#include "utils/ref_count.h" #include "visibility.h" namespace OHOS::DistributedData { class API_EXPORT DeviceMatrix { @@ -34,7 +35,7 @@ public: }; static DeviceMatrix &GetInstance(); bool Initialize(uint32_t token, std::string storeId); - void Online(const std::string &device); + void Online(const std::string &device, RefCount refCount = {}); void Offline(const std::string &device); uint16_t OnBroadcast(const std::string &device, uint16_t code); void OnChanged(uint16_t code); diff --git a/services/distributeddataservice/service/matrix/include/matrix_event.h b/services/distributeddataservice/service/matrix/include/matrix_event.h index e6e9b471..e44f8205 100644 --- a/services/distributeddataservice/service/matrix/include/matrix_event.h +++ b/services/distributeddataservice/service/matrix/include/matrix_event.h @@ -18,6 +18,7 @@ #include #include "eventcenter/event.h" +#include "utils/ref_count.h" #include "visibility.h" namespace OHOS::DistributedData { class API_EXPORT MatrixEvent : public Event { @@ -26,11 +27,14 @@ public: ~MatrixEvent() = default; uint16_t GetMask() const; std::string GetDeviceId() const; + void SetRefCount(RefCount refCount); + RefCount StealRefCount() const; bool Equals(const Event &event) const override; private: uint16_t mask_; std::string deviceId_; + mutable RefCount refCount_; }; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICE_MATRIX_MATRIX_EVENT_H diff --git a/services/distributeddataservice/service/matrix/src/device_matrix.cpp b/services/distributeddataservice/service/matrix/src/device_matrix.cpp index 44679550..d4db69a1 100644 --- a/services/distributeddataservice/service/matrix/src/device_matrix.cpp +++ b/services/distributeddataservice/service/matrix/src/device_matrix.cpp @@ -72,7 +72,7 @@ bool DeviceMatrix::Initialize(uint32_t token, std::string storeId) return MetaDataManager::GetInstance().SaveMeta(newMeta.GetKey(), newMeta); } -void DeviceMatrix::Online(const std::string &device) +void DeviceMatrix::Online(const std::string &device, RefCount refCount) { Mask mask; EventCenter::Defer defer; @@ -83,7 +83,11 @@ void DeviceMatrix::Online(const std::string &device) offLines_.erase(it); } onLines_.insert_or_assign(device, mask); - EventCenter::GetInstance().PostEvent(std::make_unique(MATRIX_ONLINE, device, mask.bitset)); + if (mask.bitset != 0) { + auto evt = std::make_unique(MATRIX_ONLINE, device, mask.bitset); + evt->SetRefCount(std::move(refCount)); + EventCenter::GetInstance().PostEvent(std::move(evt)); + } } void DeviceMatrix::Offline(const std::string &device) diff --git a/services/distributeddataservice/service/matrix/src/matrix_event.cpp b/services/distributeddataservice/service/matrix/src/matrix_event.cpp index b61a0caf..d7ce1c13 100644 --- a/services/distributeddataservice/service/matrix/src/matrix_event.cpp +++ b/services/distributeddataservice/service/matrix/src/matrix_event.cpp @@ -34,4 +34,14 @@ bool MatrixEvent::Equals(const Event &event) const auto &evt = static_cast(event); return (deviceId_ == evt.deviceId_) && (mask_ == evt.mask_); } + +void MatrixEvent::SetRefCount(RefCount refCount) +{ + refCount_ = std::move(refCount); +} + +RefCount MatrixEvent::StealRefCount() const +{ + return std::move(refCount_); +} } // namespace OHOS::DistributedData \ No newline at end of file -- Gitee From 50ae5e95738c813d6798e168be13665c814194b1 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Tue, 11 Jul 2023 16:07:50 +0800 Subject: [PATCH 404/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/service/cloud/sync_manager.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 082d1f4c..feb63889 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -191,10 +191,6 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount retryer(RETRY_INTERVAL, E_RETRY_TIMEOUT); return; } - if (!DmAdapter::GetInstance().IsNetworkAvailable()) { - retryer(RETRY_INTERVAL, E_NETWORK_ERROR); - return; - } Defer defer(GetSyncHandler(std::move(retryer)), CloudEvent::CLOUD_SYNC); for (auto &schema : schemas) { -- Gitee From 2189b9fe16e7379cb279765d4ad9128f94227669 Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Tue, 11 Jul 2023 16:26:37 +0800 Subject: [PATCH 405/437] update Signed-off-by: zuojiangjiang --- .../distributeddataservice/app/src/kvstore_meta_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index 95a972ff..98d02fb5 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -129,7 +129,7 @@ void KvStoreMetaManager::InitDeviceOnline() ZLOGW("meta online sync error 0x%{public}08x device:%{public}s %{public}d", mask, Anonymous::Change(deviceId).c_str(), status); } - onComplete({}); + onComplete({ }); }); } @@ -397,6 +397,7 @@ size_t KvStoreMetaManager::GetSyncDataSize(const std::string &deviceId) return metaDelegate->GetSyncDataSize(deviceId); } + void KvStoreMetaManager::BindExecutor(std::shared_ptr executors) { executors_ = executors; -- Gitee From e61443fce06fb0c3090051960c5dae020b2f85cc Mon Sep 17 00:00:00 2001 From: anqi Date: Tue, 11 Jul 2023 20:44:29 +0800 Subject: [PATCH 406/437] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UDMF=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA=E4=BA=8B=E4=BB=B6=E6=89=93=E7=82=B9=20Signed-off-by:?= =?UTF-8?q?=20anqi=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hisysevent.yaml | 9 ++++ .../src/behaviour/behaviour_reporter_impl.cpp | 8 +++- .../src/behaviour/behaviour_reporter_impl.h | 1 + .../adapter/dfx/src/dfx_code_constant.h | 1 + .../adapter/dfx/src/hiview_adapter.cpp | 23 +++++++++ .../adapter/dfx/src/hiview_adapter.h | 1 + .../adapter/include/dfx/behaviour_reporter.h | 1 + .../adapter/include/dfx/dfx_types.h | 9 ++++ .../adapter/include/dfx/reporter.h | 2 +- .../service/udmf/BUILD.gn | 14 +++--- .../service/udmf/data_manager.cpp | 5 +- .../udmf/preprocess/preprocess_utils.cpp | 48 +++++++++++++++---- .../udmf/preprocess/preprocess_utils.h | 3 +- .../service/udmf/udmf_service_impl.cpp | 43 ++++++++++++++++- 14 files changed, 146 insertions(+), 22 deletions(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index 44a9a785..daba8439 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -100,6 +100,15 @@ DATABASE_BEHAVIOUR: STORE_ID: {type: STRING, desc: store id } BEHAVIOUR_INFO: {type: STRING, desc: behaviour type and behaviour resulte } +UDMF_DATA_BEHAVIOR: + __BASE: {type: BEHAVIOR, level: MINOR, desc: The event is behaviour record } + APP_ID: {type: STRING, desc: app id } + CHANNEL: {type: STRING, desc: channel name } + DATA_SIZE: {type: INT64, desc: data size } + DATA_TYPE: {type: STRING, desc: data type } + OPERATION: {type: STRING, desc: data operation } + RESULT: {type: STRING, desc: data operation result } + OPEN_DATABASE_FAILED: __BASE: {type: FAULT, level: CRITICAL, desc: The database open failed} APP_ID: {type: STRING, desc: app id } diff --git a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp index 9e3b4619..cee6b854 100644 --- a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp +++ b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "behaviour_reporter_impl.h" namespace OHOS { @@ -22,6 +21,13 @@ ReportStatus BehaviourReporterImpl::Report(const BehaviourMsg &msg) HiViewAdapter::ReportBehaviour(DfxCodeConstant::DATABASE_BEHAVIOUR, msg, executors_); return ReportStatus::SUCCESS; } + +ReportStatus BehaviourReporterImpl::UDMFReport(const UDMFBehaviourMsg &msg) +{ + HiViewAdapter::ReportUDMFBehaviour(DfxCodeConstant::UDMF_DATA_BEHAVIOR, msg, executors_); + return ReportStatus::SUCCESS; +} + void BehaviourReporterImpl::SetThreadPool(std::shared_ptr executors) { executors_ = executors; diff --git a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h index 7ac010b1..72d9ef3c 100644 --- a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h +++ b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h @@ -25,6 +25,7 @@ class BehaviourReporterImpl : public BehaviourReporter { public: virtual ~BehaviourReporterImpl() {} ReportStatus Report(const struct BehaviourMsg &msg) override; + ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) override; void SetThreadPool(std::shared_ptr executors); private: diff --git a/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h b/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h index a78caaaf..cc2cba1d 100644 --- a/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h +++ b/services/distributeddataservice/adapter/dfx/src/dfx_code_constant.h @@ -32,5 +32,6 @@ public: static inline const int DATABASE_CORRUPTED_FAILED = 950001113; static inline const int DATABASE_REKEY_FAILED = 950001114; static inline const int DATABASE_BEHAVIOUR = 950001115; + static inline const int UDMF_DATA_BEHAVIOR = 950001116; }; #endif // DISTRIBUTEDDATAMGR_DFX_CODE_CONSTANT_H diff --git a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp index 9ac6fef2..c98b3b36 100644 --- a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp +++ b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp @@ -47,6 +47,11 @@ constexpr const char *TAG = "TAG"; constexpr const char *POWERSTATS = "PowerStats"; // behaviour key constexpr const char *BEHAVIOUR_INFO = "BEHAVIOUR_INFO"; +constexpr const char *CHANNEL = "CHANNEL"; +constexpr const char *DATA_SIZE = "DATA_SIZE"; +constexpr const char *DATA_TYPE = "DATA_TYPE"; +constexpr const char *OPERATION = "OPERATION"; +constexpr const char *RESULT = "RESULT"; const std::map EVENT_COVERT_TABLE = { { DfxCodeConstant::SERVICE_FAULT, "SERVICE_FAULT" }, @@ -63,6 +68,7 @@ const std::map EVENT_COVERT_TABLE = { { DfxCodeConstant::DATABASE_CORRUPTED_FAILED, "DATABASE_CORRUPTED_FAILED" }, { DfxCodeConstant::DATABASE_REKEY_FAILED, "DATABASE_REKEY_FAILED" }, { DfxCodeConstant::DATABASE_BEHAVIOUR, "DATABASE_BEHAVIOUR" }, + { DfxCodeConstant::UDMF_DATA_BEHAVIOR, "UDMF_DATA_BEHAVIOR" }, }; } using OHOS::HiviewDFX::HiSysEvent; @@ -298,6 +304,23 @@ void HiViewAdapter::ReportApiPerformanceStatistic(int dfxCode, const ApiPerforma StartTimerThread(executors); } +void HiViewAdapter::ReportUDMFBehaviour( + int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr executors) +{ + ExecutorPool::Task task([dfxCode, msg]() { + HiSysEventWrite(HiSysEvent::Domain::DISTRIBUTED_DATAMGR, + CoverEventID(dfxCode), + HiSysEvent::EventType::BEHAVIOR, + APP_ID, msg.appId, + CHANNEL, msg.channel, + DATA_SIZE, msg.dataSize, + DATA_TYPE, msg.dataType, + OPERATION, msg.operation, + RESULT, msg.result); + }); + executors->Execute(std::move(task)); +} + void HiViewAdapter::InvokeApiPerformance() { std::string message; diff --git a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h index 21de2703..7bfbc6c0 100644 --- a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h +++ b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h @@ -46,6 +46,7 @@ public: static void ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat, std::shared_ptr executors); static void ReportBehaviour(int dfxCode, const BehaviourMsg &msg, std::shared_ptr executors); + static void ReportUDMFBehaviour(int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr executors); static void StartTimerThread(std::shared_ptr executors); private: diff --git a/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h b/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h index 57b1f32c..4a9c9062 100644 --- a/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h +++ b/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h @@ -23,6 +23,7 @@ namespace DistributedDataDfx { class BehaviourReporter { public: KVSTORE_API virtual ReportStatus Report(const BehaviourMsg &msg) = 0; + KVSTORE_API virtual ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) = 0; KVSTORE_API virtual ~BehaviourReporter() {} }; } // namespace DistributedDataDfx diff --git a/services/distributeddataservice/adapter/include/dfx/dfx_types.h b/services/distributeddataservice/adapter/include/dfx/dfx_types.h index e8ab47b4..8068abbe 100644 --- a/services/distributeddataservice/adapter/include/dfx/dfx_types.h +++ b/services/distributeddataservice/adapter/include/dfx/dfx_types.h @@ -131,6 +131,15 @@ struct BehaviourMsg { std::string extensionInfo; }; +struct UDMFBehaviourMsg { + std::string appId; + std::string channel; + int64_t dataSize; + std::string dataType; + std::string operation; + std::string result; +}; + struct VisitStat { std::string appId; std::string interfaceName; diff --git a/services/distributeddataservice/adapter/include/dfx/reporter.h b/services/distributeddataservice/adapter/include/dfx/reporter.h index c2537b57..de60c0e8 100644 --- a/services/distributeddataservice/adapter/include/dfx/reporter.h +++ b/services/distributeddataservice/adapter/include/dfx/reporter.h @@ -43,7 +43,7 @@ public: void SetThreadPool(std::shared_ptr executors) { executors_ = executors; - if (executors == nullptr) { + if (executors != nullptr) { ServiceFault(); RuntimeFault(); DatabaseFault(); diff --git a/services/distributeddataservice/service/udmf/BUILD.gn b/services/distributeddataservice/service/udmf/BUILD.gn index cc209315..4e33af71 100755 --- a/services/distributeddataservice/service/udmf/BUILD.gn +++ b/services/distributeddataservice/service/udmf/BUILD.gn @@ -17,19 +17,21 @@ config("module_public_config") { visibility = [ ":*" ] include_dirs = [ - "${udmf_path}/framework/common", - "${udmf_path}/interfaces/innerkits/common", - "${udmf_path}/interfaces/innerkits/data", "${data_service_path}/framework/include", + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/adapter/include/dfx", "${data_service_path}/service/udmf/lifecycle", "${data_service_path}/service/udmf/permission", "${data_service_path}/service/udmf/preprocess", "${data_service_path}/service/udmf/store", "${data_service_path}/service/udmf", - "${kv_store_path}/frameworks/common", - "${file_service_path}/interfaces/innerkits/native/remote_file_share/include", "${device_manager_path}/interfaces/inner_kits/native_cpp/include", - "${data_service_path}/adapter/include/communicator", + "${file_service_path}/interfaces/innerkits/native/remote_file_share/include", + "${kv_store_path}/interfaces/innerkits/distributeddata/include", + "${kv_store_common_path}", + "${udmf_path}/framework/common", + "${udmf_path}/interfaces/innerkits/common", + "${udmf_path}/interfaces/innerkits/data", ] } diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index ec92b385..8641ed43 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -17,6 +17,7 @@ #include "data_manager.h" #include "checker_manager.h" +#include "dfx_types.h" #include "file.h" #include "lifecycle/lifecycle_manager.h" #include "log_print.h" @@ -151,6 +152,7 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified ZLOGE("Remove data failed, intention: %{public}s.", key.intention.c_str()); return E_DB_ERROR; } + PreProcessUtils::SetRemoteData(unifiedData); return E_OK; } std::string DataManager::ConvertUri(std::shared_ptr record, const std::string &localDevId, @@ -181,7 +183,8 @@ int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector -#include "error_code.h" + #include "accesstoken_kit.h" #include "bundlemgr/bundle_mgr_client_impl.h" -#include "ipc_skeleton.h" #include "device_manager_adapter.h" +#include "error_code.h" +#include "file.h" +#include "ipc_skeleton.h" #include "log_print.h" namespace OHOS { namespace UDMF { static constexpr int ID_LEN = 32; const char SPECIAL = '^'; +using namespace Security::AccessToken; int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &option) { auto it = UD_INTENTION_MAP.find(option.intention); @@ -52,12 +54,6 @@ int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption & return E_OK; } -std::string PreProcessUtils::GetLocalDeviceId() -{ - auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice(); - return DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); -} - std::string PreProcessUtils::IdGenerator() { std::random_device randomDevice; @@ -113,5 +109,37 @@ bool PreProcessUtils::GetNativeProcessNameByToken(int tokenId, std::string &proc processName = nativeInfo.processName; return true; } + +std::string PreProcessUtils::GetLocalDeviceId() +{ + auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice(); + std::string encryptedUuid = DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid); + return encryptedUuid; +} + +void PreProcessUtils::SetRemoteData(UnifiedData &data) +{ + if (data.IsEmpty()) { + ZLOGD("invalid data."); + return; + } + std::shared_ptr runtime = data.GetRuntime(); + if (runtime->deviceId == PreProcessUtils::GetLocalDeviceId()) { + ZLOGD("not remote data."); + return; + } + ZLOGD("is remote data."); + auto records = data.GetRecords(); + for (auto record : records) { + auto type = record->GetType(); + if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO + || type == UDType::FOLDER) { + auto file = static_cast(record.get()); + UDDetails details = file->GetDetails(); + details.insert({"isRemote", "true"}); + file->SetDetails(details); + } + } +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 52759057..76272973 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -33,7 +33,8 @@ public: static int32_t GetHapUidByToken(uint32_t tokenId); static bool GetHapBundleNameByToken(int tokenId, std::string &bundleName); static bool GetNativeProcessNameByToken(int tokenId, std::string &processName); - static std::string GetLocalDeviceId(); // uuid + static std::string GetLocalDeviceId(); + static void SetRemoteData(UnifiedData &data); }; } // namespace UDMF } // namespace OHOS diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index dcbf8b47..b1744347 100755 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -22,10 +22,13 @@ #include "lifecycle/lifecycle_manager.h" #include "log_print.h" #include "preprocess_utils.h" +#include "reporter.h" namespace OHOS { namespace UDMF { using FeatureSystem = DistributedData::FeatureSystem; +using UDMFBehaviourMsg = OHOS::DistributedDataDfx::UDMFBehaviourMsg; +using Reporter = OHOS::DistributedDataDfx::Reporter; __attribute__((used)) UdmfServiceImpl::Factory UdmfServiceImpl::factory_; UdmfServiceImpl::Factory::Factory() { @@ -46,13 +49,49 @@ UdmfServiceImpl::Factory::~Factory() int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) { ZLOGD("start"); - return DataManager::GetInstance().SaveData(option, unifiedData, key); + int32_t res = E_OK; + UDMFBehaviourMsg msg; + auto find = UD_INTENTION_MAP.find(option.intention); + msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second; + msg.operation = "insert"; + std::string bundleName; + if (!PreProcessUtils::GetHapBundleNameByToken(option.tokenId, bundleName)) { + msg.appId = "unknown"; + res = E_ERROR; + } else { + msg.appId = bundleName; + res = DataManager::GetInstance().SaveData(option, unifiedData, key); + } + msg.result = ERROR_MAP.find(res)->second; + std::vector types = unifiedData.GetUDTypes(); + msg.dataType = unifiedData.GetTypes(); + msg.dataSize = unifiedData.GetSize(); + Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); + return res; } int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedData) { ZLOGD("start"); - return DataManager::GetInstance().RetrieveData(query, unifiedData); + int32_t res = E_OK; + UDMFBehaviourMsg msg; + auto find = UD_INTENTION_MAP.find(query.intention); + msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second; + msg.operation = "insert"; + std::string bundleName; + if (!PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName)) { + msg.appId = "unknown"; + res = E_ERROR; + } else { + msg.appId = bundleName; + res = DataManager::GetInstance().RetrieveData(query, unifiedData); + } + msg.result = ERROR_MAP.find(res)->second; + std::vector types = unifiedData.GetUDTypes(); + msg.dataType = unifiedData.GetTypes(); + msg.dataSize = unifiedData.GetSize(); + Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); + return res; } int32_t UdmfServiceImpl::GetBatchData(const QueryOption &query, std::vector &unifiedDataSet) -- Gitee From 03df028c2cb47ce1f05b3e7e1550d97630b4b8ae Mon Sep 17 00:00:00 2001 From: genglingxia Date: Tue, 11 Jul 2023 23:12:36 +0800 Subject: [PATCH 407/437] =?UTF-8?q?=E6=B7=BB=E5=8A=A0dfs=5Fshare=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: genglingxia --- services/distributeddataservice/app/distributed_data.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/app/distributed_data.cfg b/services/distributeddataservice/app/distributed_data.cfg index 45046b10..fbc1350a 100644 --- a/services/distributeddataservice/app/distributed_data.cfg +++ b/services/distributeddataservice/app/distributed_data.cfg @@ -17,7 +17,7 @@ "name" : "distributeddata", "path" : ["/system/bin/sa_main","/system/profile/distributeddata.json"], "uid" : "ddms", - "gid" : ["system","shell","readproc","ddms"], + "gid" : ["system","shell","readproc","ddms","dfs_share"], "writepid":[ "/dev/cpuset/foreground/tasks", "/dev/stune/foreground/tasks", -- Gitee From 0f9058bf3b9c54b4ddd2162aeb0f11a8e62837b4 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 01:31:08 +0800 Subject: [PATCH 408/437] f Signed-off-by: hanlu --- .../distributeddataservice/service/BUILD.gn | 1 - .../service/data_share/BUILD.gn | 4 +- .../service/data_share/common/callback_impl.h | 1 - .../common/extension_connect_adaptor.cpp | 7 +- .../data_share/common/extension_mgr_proxy.cpp | 102 ++++++++++++++++++ .../data_share/common/extension_mgr_proxy.h | 57 ++++++++++ .../data_share/common/scheduler_manager.cpp | 35 +++--- .../data/resultset_json_formatter.cpp | 1 + .../data_share/data_share_service_impl.cpp | 6 -- .../strategies/rdb_notify_strategy.cpp | 2 +- .../rdb_subscriber_manager.cpp | 11 +- .../rdb_subscriber_manager.h | 1 - 12 files changed, 189 insertions(+), 39 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp create mode 100644 services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index 42b0e4b6..e467c8c7 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -121,7 +121,6 @@ ohos_shared_library("distributeddatasvc") { external_deps = [ "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_manager", "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 8cb08cb8..d2245f76 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -35,11 +35,11 @@ group("build_module") { } ohos_shared_library("data_share_service") { sources = [ - "common/app_connect_manager.cpp", "common/bundle_mgr_proxy.cpp", "common/db_delegate.cpp", "common/div_strategy.cpp", "common/extension_connect_adaptor.cpp", + "common/extension_mgr_proxy.cpp", "common/kv_delegate.cpp", "common/rdb_delegate.cpp", "common/scheduler_manager.cpp", @@ -91,7 +91,7 @@ ohos_shared_library("data_share_service") { external_deps = [ "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", diff --git a/services/distributeddataservice/service/data_share/common/callback_impl.h b/services/distributeddataservice/service/data_share/common/callback_impl.h index 2eb22014..451f375f 100644 --- a/services/distributeddataservice/service/data_share/common/callback_impl.h +++ b/services/distributeddataservice/service/data_share/common/callback_impl.h @@ -16,7 +16,6 @@ #define DATASHARESERVICE_CALLBACK_IMPL_H #include "ability_connect_callback_stub.h" -#include "ability_manager_client.h" #include "block_data.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index 44725a69..a0deba23 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -20,6 +20,7 @@ #include "app_connect_manager.h" #include "callback_impl.h" +#include "extension_mgr_proxy.h" #include "log_print.h" namespace OHOS::DataShare { @@ -37,8 +38,6 @@ ExtensionConnectAdaptor::ExtensionConnectAdaptor() : data_(1) {} bool ExtensionConnectAdaptor::DoConnect(std::shared_ptr context) { - AAFwk::Want want; - want.SetUri(context->uri); data_.Clear(); callback_ = new (std::nothrow) CallbackImpl(data_); if (callback_ == nullptr) { @@ -46,7 +45,7 @@ bool ExtensionConnectAdaptor::DoConnect(std::shared_ptr context) return false; } ZLOGI("Start connect %{public}s", context->uri.c_str()); - ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, callback_, nullptr); + ErrCode ret = ExtensionMgrProxy::GetInstance()->Connect(context->uri, callback_->AsObject(), nullptr); if (ret != ERR_OK) { ZLOGE("connect ability failed, ret = %{public}d", ret); return false; @@ -80,7 +79,7 @@ void ExtensionConnectAdaptor::Disconnect() } data_.Clear(); ZLOGI("Start disconnect"); - AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(callback_); + ExtensionMgrProxy::GetInstance()->DisConnect(callback_->AsObject()); if (!data_.GetValue()) { ZLOGI("disconnect ability ended successfully"); } diff --git a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp new file mode 100644 index 00000000..8b3454b4 --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp @@ -0,0 +1,102 @@ +/* + * 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. + */ + +#define LOG_TAG "AppConnectManager" +#include "extension_mgr_proxy.h" + +#include "app_connect_manager.h" +#include "extension_ability_info.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "log_print.h" +#include "system_ability_definition.h" +#include "want.h" +namespace OHOS::DataShare { +void ExtensionMgrProxy::OnProxyDied() +{ + std::lock_guard lock(mutex_); + if (sa_ != nullptr) { + sa_->RemoveDeathRecipient(deathRecipient_); + } + deathRecipient_ = nullptr; + proxy_ = nullptr; +} + +ExtensionMgrProxy::~ExtensionMgrProxy() +{ + std::lock_guard lock(mutex_); + if (sa_ != nullptr) { + sa_->RemoveDeathRecipient(deathRecipient_); + } +} + +std::shared_ptr ExtensionMgrProxy::GetInstance() +{ + static std::shared_ptr proxy(new ExtensionMgrProxy()); + return proxy; +} + +bool ExtensionMgrProxy::Connect( + const std::string &uri, const sptr &connect, const sptr &callerToken) +{ + AAFwk::Want want; + want.SetUri(uri); + std::lock_guard lock(mutex_); + if (ConnectSA()) { + return proxy_->ConnectAbilityCommon(want, connect, callerToken, AppExecFwk::ExtensionAbilityType::DATASHARE); + } + return false; +} + +bool ExtensionMgrProxy::ConnectSA() +{ + if (proxy_ != nullptr) { + return true; + } + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + ZLOGE("Failed to get system ability mgr."); + return false; + } + + sa_ = systemAbilityManager->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + if (sa_ == nullptr) { + ZLOGE("Failed to GetSystemAbility."); + return false; + } + deathRecipient_ = new (std::nothrow) ExtensionMgrProxy::ServiceDeathRecipient(weak_from_this()); + if (deathRecipient_ == nullptr) { + ZLOGE("deathRecipient alloc failed."); + return false; + } + sa_->AddDeathRecipient(deathRecipient_); + proxy_ = new (std::nothrow)Proxy(sa_); + if (proxy_ == nullptr) { + ZLOGE("proxy_ null, new failed"); + return false; + } + return true; +} + +bool ExtensionMgrProxy::DisConnect(sptr connect) +{ + std::lock_guard lock(mutex_); + if (ConnectSA()) { + return proxy_->DisconnectAbility(connect); + } + return false; +} +} // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h new file mode 100644 index 00000000..96d3a41b --- /dev/null +++ b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#ifndef DATASHARESERVICE_EXTENSION_PROXY_H +#define DATASHARESERVICE_EXTENSION_PROXY_H + +#include +#include + +#include "extension_manager_proxy.h" +namespace OHOS::DataShare { +class ExtensionMgrProxy final : public std::enable_shared_from_this { +public: + ~ExtensionMgrProxy(); + static std::shared_ptr GetInstance(); + bool Connect(const std::string &uri, const sptr &connect, const sptr &callerToken); + bool DisConnect(sptr connect); +private: + using Proxy = AAFwk::ExtensionManagerProxy; + ExtensionMgrProxy() = default; + class ServiceDeathRecipient : public IRemoteObject::DeathRecipient { + public: + explicit ServiceDeathRecipient(std::weak_ptr owner) : owner_(owner) + { + } + void OnRemoteDied(const wptr &object) override + { + auto owner = owner_.lock(); + if (owner != nullptr) { + owner->OnProxyDied(); + } + } + + private: + std::weak_ptr owner_; + }; + void OnProxyDied(); + bool ConnectSA(); + std::mutex mutex_; + sptr sa_; + sptr proxy_; + sptr deathRecipient_; +}; +} // namespace OHOS::DataShare +#endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index c0c96fc1..67628ee4 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -39,9 +39,6 @@ void SchedulerManager::Execute(const std::string &uri, const int32_t userId, con } std::vector keys = RdbSubscriberManager::GetInstance().GetKeysByUri(uri); for (auto const &key : keys) { - if (RdbSubscriberManager::GetInstance().GetCount(key) == 0) { - continue; - } ExecuteSchedulerSQL(rdbDir, userId, version, key, delegate); } } @@ -64,23 +61,33 @@ void SchedulerManager::SetTimer( ZLOGE("executor_ is nullptr"); return; } + // reminder time must is in future + auto now = time(nullptr); + if (reminderTime <= now) { + ZLOGE("reminderTime is not in future, %{public}" PRId64 "%{public}" PRId64 , reminderTime, now); + return; + } + auto duration = std::chrono::seconds(reminderTime - now); + ZLOGI("reminderTime will notify in %{public}" PRId64 " seconds", reminderTime - now); auto it = timerCache_.find(key); if (it != timerCache_.end()) { // has current timer, reset time - ZLOGD("has current taskId, uri is %{public}s, subscriberId is %{public}" PRId64 ", bundleName is %{public}s", - DistributedData::Anonymous::Change(key.uri).c_str(), key.subscriberId, key.bundleName.c_str()); - executor_->Reset(it->second, std::chrono::seconds(reminderTime - time(nullptr))); + ZLOGD("has current taskId, uri is %{private}s, subscriberId is %{public}" PRId64 ", bundleName is %{public}s", + key.uri.c_str(), key.subscriberId, key.bundleName.c_str()); + executor_->Reset(it->second, duration); return; } // not find task in map, create new timer - auto taskId = executor_->Schedule(std::chrono::seconds(reminderTime - time(nullptr)), - [key, dbPath, version, userId, this]() { - timerCache_.erase(key); - // 1. execute schedulerSQL in next time - Execute(key, userId, dbPath, version); - // 2. notify - RdbSubscriberManager::GetInstance().EmitByKey(key, userId, dbPath, version); - }); + auto taskId = executor_->Schedule(duration, [key, dbPath, version, userId, this]() { + ZLOGI("schedule notify start, uri is %{private}s, subscriberId is %{public}" PRId64 ", bundleName is " + "%{public}s", + key.uri.c_str(), key.subscriberId, key.bundleName.c_str()); + timerCache_.erase(key); + // 1. execute schedulerSQL in next time + Execute(key, userId, dbPath, version); + // 2. notify + RdbSubscriberManager::GetInstance().EmitByKey(key, userId, dbPath, version); + }); if (taskId == ExecutorPool::INVALID_TASK_ID) { ZLOGE("create timer failed, over the max capacity"); return; diff --git a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp index 04e2d908..5bdfa4a7 100644 --- a/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp +++ b/services/distributeddataservice/service/data_share/data/resultset_json_formatter.cpp @@ -21,6 +21,7 @@ namespace OHOS::DataShare { bool ResultSetJsonFormatter::Marshal(json &node) const { + node = json::array(); int columnCount = 0; auto result = resultSet->GetColumnCount(columnCount); if (result != NativeRdb::E_OK) { diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index f084a0fe..cb7b14f7 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -52,8 +52,6 @@ int32_t DataShareServiceImpl::Insert(const std::string &uri, const DataShareValu if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - SchedulerManager::GetInstance().Execute( - uri, context->currentUserId, context->calledSourceDir, context->version); } return ret; } @@ -83,8 +81,6 @@ int32_t DataShareServiceImpl::Update(const std::string &uri, const DataSharePred if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - SchedulerManager::GetInstance().Execute( - uri, context->currentUserId, context->calledSourceDir, context->version); } return ret; } @@ -97,8 +93,6 @@ int32_t DataShareServiceImpl::Delete(const std::string &uri, const DataSharePred if (ret) { NotifyChange(uri); RdbSubscriberManager::GetInstance().Emit(uri, context); - SchedulerManager::GetInstance().Execute( - uri, context->currentUserId, context->calledSourceDir, context->version); } return ret; } diff --git a/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp index 2c13eb86..ab3c95d8 100644 --- a/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp @@ -35,7 +35,7 @@ bool RdbNotifyStrategy::Execute(std::shared_ptr context) return false; } if (context->callerBundleName != context->calledBundleName) { - ZLOGE("not your data, cannot notify, callerBundleName: %{public}s, calledBundleName: %{public}s", + ZLOGD("not your data, cannot notify, callerBundleName: %{public}s, calledBundleName: %{public}s", context->callerBundleName.c_str(), context->calledBundleName.c_str()); return false; } diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index cb8a9059..59c274ea 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -229,6 +229,8 @@ void RdbSubscriberManager::Emit(const std::string &uri, std::shared_ptr Notify(key, context->currentUserId, val, context->calledSourceDir, context->version); return false; }); + SchedulerManager::GetInstance().Execute( + uri, context->currentUserId, context->calledSourceDir, context->version); } std::vector RdbSubscriberManager::GetKeysByUri(const std::string &uri) @@ -255,15 +257,6 @@ void RdbSubscriberManager::EmitByKey(const Key &key, int32_t userId, const std:: }); } -int RdbSubscriberManager::GetCount(const Key &key) -{ - auto pair = rdbCache_.Find(key); - if (!pair.first) { - return 0; - } - return pair.second.size(); -} - int RdbSubscriberManager::GetEnableObserverCount(const Key &key) { auto pair = rdbCache_.Find(key); diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h index d388c5af..32f8471e 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h @@ -60,7 +60,6 @@ public: int Enable(const Key &key, std::shared_ptr context); void Emit(const std::string &uri, std::shared_ptr context); void EmitByKey(const Key &key, int32_t userId, const std::string &rdbPath, int version); - int GetCount(const Key &key); std::vector GetKeysByUri(const std::string &uri); void Clear(); -- Gitee From 6521ac9499a707cbf8fe2532c0a20f209059b41a Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 01:35:52 +0800 Subject: [PATCH 409/437] f Signed-off-by: hanlu --- services/distributeddataservice/service/data_share/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index d2245f76..cbc645f4 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -35,6 +35,7 @@ group("build_module") { } ohos_shared_library("data_share_service") { sources = [ + "common/app_connect_manager.cpp", "common/bundle_mgr_proxy.cpp", "common/db_delegate.cpp", "common/div_strategy.cpp", -- Gitee From 6e2981002c72d91bdd7cd5d8e38d2c0d0b5e567a Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 02:00:09 +0800 Subject: [PATCH 410/437] f Signed-off-by: hanlu --- .../service/data_share/common/scheduler_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index 67628ee4..e63f070a 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -64,7 +64,7 @@ void SchedulerManager::SetTimer( // reminder time must is in future auto now = time(nullptr); if (reminderTime <= now) { - ZLOGE("reminderTime is not in future, %{public}" PRId64 "%{public}" PRId64 , reminderTime, now); + ZLOGE("reminderTime is not in future, %{public}" PRId64 "%{public}" PRId64, reminderTime, now); return; } auto duration = std::chrono::seconds(reminderTime - now); -- Gitee From aca8471d1ed0ec4668778f07c546feca2e1cddad Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 02:17:12 +0800 Subject: [PATCH 411/437] f Signed-off-by: hanlu --- .../service/data_share/common/extension_mgr_proxy.cpp | 2 +- .../service/data_share/common/extension_mgr_proxy.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp index 8b3454b4..9ee1a361 100644 --- a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp @@ -44,7 +44,7 @@ ExtensionMgrProxy::~ExtensionMgrProxy() std::shared_ptr ExtensionMgrProxy::GetInstance() { - static std::shared_ptr proxy(new ExtensionMgrProxy()); + std::shared_ptr proxy = std::make_shared(); return proxy; } diff --git a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h index 96d3a41b..d107cde6 100644 --- a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h +++ b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.h @@ -23,13 +23,14 @@ namespace OHOS::DataShare { class ExtensionMgrProxy final : public std::enable_shared_from_this { public: + // do not use + ExtensionMgrProxy() = default; ~ExtensionMgrProxy(); static std::shared_ptr GetInstance(); bool Connect(const std::string &uri, const sptr &connect, const sptr &callerToken); bool DisConnect(sptr connect); private: using Proxy = AAFwk::ExtensionManagerProxy; - ExtensionMgrProxy() = default; class ServiceDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit ServiceDeathRecipient(std::weak_ptr owner) : owner_(owner) -- Gitee From a2943fa0648b303ae2ff874c33c4570f3ab2e4ab Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 02:19:01 +0800 Subject: [PATCH 412/437] f Signed-off-by: hanlu --- services/distributeddataservice/service/data_share/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index cbc645f4..35f0aa35 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -92,8 +92,8 @@ ohos_shared_library("data_share_service") { external_deps = [ "ability_base:want", "ability_base:zuri", - "ability_runtime:extension_manager", "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", -- Gitee From 969f96752d237343f2cc2d24eabd06cafd00fdf0 Mon Sep 17 00:00:00 2001 From: wangkai Date: Tue, 11 Jul 2023 19:19:23 +0800 Subject: [PATCH 413/437] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=8E=92=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkai --- services/distributeddataservice/app/src/security/security.cpp | 4 ++-- .../framework/test/serializable_test.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/app/src/security/security.cpp b/services/distributeddataservice/app/src/security/security.cpp index 881217ef..61c84b14 100644 --- a/services/distributeddataservice/app/src/security/security.cpp +++ b/services/distributeddataservice/app/src/security/security.cpp @@ -161,8 +161,8 @@ Sensitive Security::GetSensitiveByUuid(const std::string &uuid) const auto it = devicesUdid_.Find(uuid); if (!it.first) { executors_->Execute([this, uuid]() { - auto it = devicesUdid_.Find(uuid); - if (it.first) { + auto iter = devicesUdid_.Find(uuid); + if (iter.first) { return; } auto udid = DistributedData::DeviceManagerAdapter::GetInstance().ToUDID(uuid); diff --git a/services/distributeddataservice/framework/test/serializable_test.cpp b/services/distributeddataservice/framework/test/serializable_test.cpp index 697b33b5..3729a6e4 100644 --- a/services/distributeddataservice/framework/test/serializable_test.cpp +++ b/services/distributeddataservice/framework/test/serializable_test.cpp @@ -198,6 +198,7 @@ HWTEST_F(SerializableTest, GetMapInStruct, TestSize.Level2) ~TestMeta() { delete index; + index = nullptr; } bool Marshal(json &node) const { -- Gitee From 082dbf3b47225f58a0a69fb89ef9b476d1a9261a Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 19:54:15 +0800 Subject: [PATCH 414/437] f Signed-off-by: hanlu --- services/distributeddataservice/service/BUILD.gn | 3 --- .../data_share/subscriber_managers/rdb_subscriber_manager.cpp | 3 +++ .../service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/BUILD.gn b/services/distributeddataservice/service/BUILD.gn index e467c8c7..ff073e3e 100644 --- a/services/distributeddataservice/service/BUILD.gn +++ b/services/distributeddataservice/service/BUILD.gn @@ -119,9 +119,6 @@ ohos_shared_library("distributeddatasvc") { ] external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "c_utils:utils", diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index 59c274ea..9acd29a0 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -293,6 +293,9 @@ int RdbSubscriberManager::Notify(const Key &key, int32_t userId, const std::vect changeNode.templateId_.bundleName_ = key.bundleName; for (const auto &predicate : tpl.predicates_) { std::string result = delegate->Query(predicate.selectSql_); + if (result.empty()) { + continue; + } changeNode.data_.emplace_back("{\"" + predicate.key_ + "\":" + result + "}"); } diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index e2cbf7fe..0c3106cf 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -97,7 +97,7 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { external_deps = [ "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_manager", + "ability_runtime:extension_manager", "ability_runtime:dataobs_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", -- Gitee From a1927bb2b056907340219e8336598f1241464824 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 20:00:07 +0800 Subject: [PATCH 415/437] f Signed-off-by: hanlu --- .../service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index 0c3106cf..e65270f6 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -97,8 +97,8 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { external_deps = [ "ability_base:want", "ability_base:zuri", - "ability_runtime:extension_manager", "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", -- Gitee From 6ff024ba536b9fe5624a99f6f1d6320ca91d5144 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Wed, 12 Jul 2023 17:50:33 +0800 Subject: [PATCH 416/437] udmf tdd fix and drag intention check Signed-off-by: genglingxia --- .../service/udmf/data_manager.cpp | 52 +++++------------ .../service/udmf/data_manager.h | 3 - .../udmf/preprocess/preprocess_utils.cpp | 56 ++++++++++++++++++- .../udmf/preprocess/preprocess_utils.h | 5 ++ 4 files changed, 71 insertions(+), 45 deletions(-) diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 8641ed43..37838d42 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -23,12 +23,9 @@ #include "log_print.h" #include "preprocess_utils.h" #include "uri_permission_manager.h" -#include "remote_file_share.h" namespace OHOS { namespace UDMF { -using namespace OHOS::AppFileService; - const std::string MSDP_PROCESS_NAME = "msdp_sa"; const std::string DATA_PREFIX = "udmf://"; DataManager::DataManager() @@ -47,12 +44,6 @@ DataManager &DataManager::GetInstance() return instance; } -bool DataManager::IsFileType(UDType udType) -{ - return (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO - || udType == UDType::FOLDER); -} - int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key) { if (unifiedData.IsEmpty()) { @@ -70,24 +61,19 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st ZLOGE("Imputation failed"); return E_UNKNOWN; } - int32_t userId = PreProcessUtils::GetHapUidByToken(option.tokenId); - for (const auto &record : unifiedData.GetRecords()) { - auto type = record->GetType(); - if (IsFileType(type)) { - auto file = static_cast(record.get()); - struct ModuleRemoteFileShare::HmdfsUriInfo dfsUriInfo; - int ret = ModuleRemoteFileShare::RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); - if (ret != 0 || dfsUriInfo.uriStr.empty()) { - ZLOGE("Get remoteUri failed, ret = %{public}d, userId: %{public}d.", ret, userId); - return E_FS_ERROR; - } - file->SetRemoteUri(dfsUriInfo.uriStr); + + std::string intention = unifiedData.GetRuntime()->key.intention; + if (intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { + int32_t ret = PreProcessUtils::SetDargRemoteUri(option.tokenId, unifiedData); + if (ret != E_OK) { + return ret; } + } + for (const auto &record : unifiedData.GetRecords()) { record->SetUid(PreProcessUtils::IdGenerator()); } - std::string intention = unifiedData.GetRuntime()->key.intention; auto store = storeCache_.GetStore(intention); if (store == nullptr) { ZLOGE("Get store failed, intention: %{public}s.", intention.c_str()); @@ -142,9 +128,11 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified std::string localDeviceId = PreProcessUtils::GetLocalDeviceId(); auto records = unifiedData.GetRecords(); for (auto record : records) { - std::string uri = ConvertUri(record, localDeviceId, runtime->deviceId); - if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { - return E_NO_PERMISSION; + if (key.intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { + std::string uri = PreProcessUtils::ConvertUri(record, localDeviceId, runtime->deviceId); + if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { + return E_NO_PERMISSION; + } } } } @@ -155,20 +143,6 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified PreProcessUtils::SetRemoteData(unifiedData); return E_OK; } -std::string DataManager::ConvertUri(std::shared_ptr record, const std::string &localDevId, - const std::string &remoteDevId) -{ - std::string uri; - if (record != nullptr && IsFileType(record->GetType())) { - auto file = static_cast(record.get()); - uri = file->GetUri(); - if (localDevId != remoteDevId) { - uri = file->GetRemoteUri(); - file->SetUri(uri); // cross dev, need dis path. - } - } - return uri; -} int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector &unifiedDataSet) { diff --git a/services/distributeddataservice/service/udmf/data_manager.h b/services/distributeddataservice/service/udmf/data_manager.h index 4f0c0293..608d608c 100755 --- a/services/distributeddataservice/service/udmf/data_manager.h +++ b/services/distributeddataservice/service/udmf/data_manager.h @@ -45,10 +45,7 @@ public: private: DataManager(); - bool IsFileType(UDType udType); int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); - std::string ConvertUri(std::shared_ptr record, const std::string &localDevId, - const std::string &remoteDevId); StoreCache storeCache_; std::map authorizationMap_; }; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp index 712a85d9..3b62cbf7 100755 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -25,12 +25,15 @@ #include "file.h" #include "ipc_skeleton.h" #include "log_print.h" - +#include "remote_file_share.h" +#include "uri.h" namespace OHOS { namespace UDMF { static constexpr int ID_LEN = 32; const char SPECIAL = '^'; using namespace Security::AccessToken; +using namespace OHOS::AppFileService::ModuleRemoteFileShare; + int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &option) { auto it = UD_INTENTION_MAP.find(option.intention); @@ -132,8 +135,7 @@ void PreProcessUtils::SetRemoteData(UnifiedData &data) auto records = data.GetRecords(); for (auto record : records) { auto type = record->GetType(); - if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO - || type == UDType::FOLDER) { + if (IsFileType(type)) { auto file = static_cast(record.get()); UDDetails details = file->GetDetails(); details.insert({"isRemote", "true"}); @@ -141,5 +143,53 @@ void PreProcessUtils::SetRemoteData(UnifiedData &data) } } } + +bool PreProcessUtils::IsFileType(UDType udType) +{ + return (udType == UDType::FILE || udType == UDType::IMAGE || udType == UDType::VIDEO || udType == UDType::AUDIO + || udType == UDType::FOLDER); +} + +int32_t PreProcessUtils::SetDargRemoteUri(uint32_t tokenId, UnifiedData &data) +{ + int32_t userId = GetHapUidByToken(tokenId); + std::string bundleName = data.GetRuntime()->createPackage; + for (const auto &record : data.GetRecords()) { + if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) { + auto file = static_cast(record.get()); + if (!(file->GetUri()).empty() && IsHapOwnPath(file->GetUri(), bundleName)) { + struct HmdfsUriInfo dfsUriInfo; + int ret = RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); + if (ret != 0 || dfsUriInfo.uriStr.empty()) { + ZLOGE("Get remoteUri failed, ret = %{public}d, userId: %{public}d.", ret, userId); + return E_FS_ERROR; + } + file->SetRemoteUri(dfsUriInfo.uriStr); + } + } + } + return E_OK; +} + +bool PreProcessUtils::IsHapOwnPath(const std::string &path, const std::string &bundleName) +{ + Uri uri(path); + return (uri.GetAuthority() == bundleName); +} + +std::string PreProcessUtils::ConvertUri(std::shared_ptr record, const std::string &localDevId, + const std::string &remoteDevId) +{ + std::string uri; + if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) { + auto file = static_cast(record.get()); + uri = file->GetUri(); + if (localDevId != remoteDevId) { + uri = file->GetRemoteUri(); + file->SetUri(uri); // cross dev, need dis path. + } + } + return uri; +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 76272973..e0308af4 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -35,6 +35,11 @@ public: static bool GetNativeProcessNameByToken(int tokenId, std::string &processName); static std::string GetLocalDeviceId(); static void SetRemoteData(UnifiedData &data); + static bool IsFileType(UDType udType); + static int32_t SetDargRemoteUri(uint32_t tokenId, UnifiedData &data); + static std::string ConvertUri(std::shared_ptr record, const std::string &localDevId, + const std::string &remoteDevId); + static bool IsHapOwnPath(const std::string &uri, const std::string &bundleName); }; } // namespace UDMF } // namespace OHOS -- Gitee From dca192c9eb9a9a529aa59589972e55800b00934e Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 12 Jul 2023 22:20:48 +0800 Subject: [PATCH 417/437] f Signed-off-by: hanlu --- .../service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index e65270f6..fc781eb6 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { "${data_service_path}/service/data_share/common/db_delegate.cpp", "${data_service_path}/service/data_share/common/div_strategy.cpp", "${data_service_path}/service/data_share/common/extension_connect_adaptor.cpp", + "${data_service_path}/service/data_share/common/extension_mgr_proxy.cpp", "${data_service_path}/service/data_share/common/kv_delegate.cpp", "${data_service_path}/service/data_share/common/rdb_delegate.cpp", "${data_service_path}/service/data_share/common/scheduler_manager.cpp", -- Gitee From 3abd74a1d44fba6c9d6e9e5c57f5a843826f072a Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 13 Jul 2023 04:08:46 +0800 Subject: [PATCH 418/437] f Signed-off-by: hanlu --- .../service/data_share/common/extension_mgr_proxy.cpp | 2 +- .../service/data_share/common/scheduler_manager.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp index 9ee1a361..e6081f85 100644 --- a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp @@ -44,7 +44,7 @@ ExtensionMgrProxy::~ExtensionMgrProxy() std::shared_ptr ExtensionMgrProxy::GetInstance() { - std::shared_ptr proxy = std::make_shared(); + static std::shared_ptr proxy = std::make_shared(); return proxy; } diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index e63f070a..694771d7 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -80,8 +80,7 @@ void SchedulerManager::SetTimer( // not find task in map, create new timer auto taskId = executor_->Schedule(duration, [key, dbPath, version, userId, this]() { ZLOGI("schedule notify start, uri is %{private}s, subscriberId is %{public}" PRId64 ", bundleName is " - "%{public}s", - key.uri.c_str(), key.subscriberId, key.bundleName.c_str()); + "%{public}s", key.uri.c_str(), key.subscriberId, key.bundleName.c_str()); timerCache_.erase(key); // 1. execute schedulerSQL in next time Execute(key, userId, dbPath, version); -- Gitee From 66a7615c622bcae8bf174ef03e886f50107622ec Mon Sep 17 00:00:00 2001 From: zuojiangjiang Date: Thu, 13 Jul 2023 10:16:17 +0800 Subject: [PATCH 419/437] update Signed-off-by: zuojiangjiang --- .../adapter/communicator/src/device_manager_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 2ea67eb8..132f5708 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -153,6 +153,7 @@ void DeviceManagerAdapter::Online(const DmDeviceInfo &info) ZLOGI("[online] uuid:%{public}s, name:%{public}s, type:%{public}d", KvStoreUtils::ToBeAnonymous(dvInfo.uuid).c_str(), dvInfo.deviceName.c_str(), dvInfo.deviceType); SaveDeviceInfo(dvInfo, DeviceChangeType::DEVICE_ONLINE); + syncTask_.Insert(dvInfo.uuid, dvInfo.uuid); auto observers = GetObservers(); for (const auto &item : observers) { // notify db if (item == nullptr) { @@ -176,7 +177,6 @@ void DeviceManagerAdapter::Online(const DmDeviceInfo &info) [this, dvInfo]() { TimeOut(dvInfo.uuid); }); - syncTask_.Insert(dvInfo.uuid, dvInfo.uuid); for (const auto &item : observers) { // set compatible identify, sync service meta if (item == nullptr) { continue; -- Gitee From 6f667db5da607869262dd6104de5c12c425dbe32 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Thu, 13 Jul 2023 13:09:22 +0800 Subject: [PATCH 420/437] =?UTF-8?q?=E5=90=8C=E5=BA=94=E7=94=A8=E8=B7=A8?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=9C=BA=E6=99=AFuri=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E4=BF=AE=E5=A4=8D0713?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: genglingxia --- .../service/udmf/data_manager.cpp | 38 ++++++++++++++----- .../service/udmf/data_manager.h | 1 + .../udmf/preprocess/preprocess_utils.cpp | 15 +++----- .../udmf/preprocess/preprocess_utils.h | 3 +- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 37838d42..16461f3f 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -120,27 +120,45 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified if (!CheckerManager::GetInstance().IsValid(runtime->privileges, info)) { return E_NO_PERMISSION; } + + if (key.intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { + if (DragUriProcessing(query, unifiedData) != E_OK) { + return E_NO_PERMISSION; + } + } + + if (LifeCycleManager::GetInstance().DeleteOnGet(key) != E_OK) { + ZLOGE("Remove data failed, intention: %{public}s.", key.intention.c_str()); + return E_DB_ERROR; + } + PreProcessUtils::SetRemoteData(unifiedData); + return E_OK; +} + +int32_t DataManager::DragUriProcessing(const QueryOption &query, UnifiedData &unifiedData) +{ + std::string localDeviceId = PreProcessUtils::GetLocalDeviceId(); + if (localDeviceId != unifiedData.GetRuntime()->deviceId) { + PreProcessUtils::ConvertUri(unifiedData.GetRecords()); + } + std::string bundleName; if (!PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName)) { return E_ERROR; } - if (runtime->createPackage != bundleName) { - std::string localDeviceId = PreProcessUtils::GetLocalDeviceId(); + if (unifiedData.GetRuntime()->createPackage != bundleName) { auto records = unifiedData.GetRecords(); for (auto record : records) { - if (key.intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { - std::string uri = PreProcessUtils::ConvertUri(record, localDeviceId, runtime->deviceId); - if (!uri.empty() && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { + if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) { + auto file = static_cast(record.get()); + std::string uri = file->GetUri(); + if (!uri.empty() + && (UriPermissionManager::GetInstance().GrantUriPermission(uri, bundleName) != E_OK)) { return E_NO_PERMISSION; } } } } - if (LifeCycleManager::GetInstance().DeleteOnGet(key) != E_OK) { - ZLOGE("Remove data failed, intention: %{public}s.", key.intention.c_str()); - return E_DB_ERROR; - } - PreProcessUtils::SetRemoteData(unifiedData); return E_OK; } diff --git a/services/distributeddataservice/service/udmf/data_manager.h b/services/distributeddataservice/service/udmf/data_manager.h index 608d608c..7edbb43d 100755 --- a/services/distributeddataservice/service/udmf/data_manager.h +++ b/services/distributeddataservice/service/udmf/data_manager.h @@ -46,6 +46,7 @@ public: private: DataManager(); int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); + int32_t DragUriProcessing(const QueryOption &query, UnifiedData &unifiedData); StoreCache storeCache_; std::map authorizationMap_; }; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp index 3b62cbf7..36d25e67 100755 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -127,7 +127,7 @@ void PreProcessUtils::SetRemoteData(UnifiedData &data) return; } std::shared_ptr runtime = data.GetRuntime(); - if (runtime->deviceId == PreProcessUtils::GetLocalDeviceId()) { + if (runtime->deviceId == GetLocalDeviceId()) { ZLOGD("not remote data."); return; } @@ -155,7 +155,7 @@ int32_t PreProcessUtils::SetDargRemoteUri(uint32_t tokenId, UnifiedData &data) int32_t userId = GetHapUidByToken(tokenId); std::string bundleName = data.GetRuntime()->createPackage; for (const auto &record : data.GetRecords()) { - if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) { + if (record != nullptr && IsFileType(record->GetType())) { auto file = static_cast(record.get()); if (!(file->GetUri()).empty() && IsHapOwnPath(file->GetUri(), bundleName)) { struct HmdfsUriInfo dfsUriInfo; @@ -177,19 +177,16 @@ bool PreProcessUtils::IsHapOwnPath(const std::string &path, const std::string &b return (uri.GetAuthority() == bundleName); } -std::string PreProcessUtils::ConvertUri(std::shared_ptr record, const std::string &localDevId, - const std::string &remoteDevId) +void PreProcessUtils::ConvertUri(std::vector> records) { std::string uri; - if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) { - auto file = static_cast(record.get()); - uri = file->GetUri(); - if (localDevId != remoteDevId) { + for (auto record : records) { + if (record != nullptr && IsFileType(record->GetType())) { + auto file = static_cast(record.get()); uri = file->GetRemoteUri(); file->SetUri(uri); // cross dev, need dis path. } } - return uri; } } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index e0308af4..63d5803f 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -37,8 +37,7 @@ public: static void SetRemoteData(UnifiedData &data); static bool IsFileType(UDType udType); static int32_t SetDargRemoteUri(uint32_t tokenId, UnifiedData &data); - static std::string ConvertUri(std::shared_ptr record, const std::string &localDevId, - const std::string &remoteDevId); + static void ConvertUri(std::vector> records); static bool IsHapOwnPath(const std::string &uri, const std::string &bundleName); }; } // namespace UDMF -- Gitee From 8e5e261f4e887059a3555b6f0dfc1fcbaed62111 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Thu, 13 Jul 2023 16:47:27 +0800 Subject: [PATCH 421/437] add network status check Signed-off-by: renjiecui --- .../distributeddataservice/service/cloud/sync_manager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 8bc0025d..3e7e3c32 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -192,6 +192,11 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount return; } + if (!DmAdapter::GetInstance().IsNetworkAvailable()) { + retryer(RETRY_INTERVAL, E_NETWORK_ERROR); + return; + } + Defer defer(GetSyncHandler(std::move(retryer)), CloudEvent::CLOUD_SYNC); for (auto &schema : schemas) { if (!cloud.IsOn(schema.bundleName)) { -- Gitee From 7afa12ef71641f88ea6fcd7e6978cc9391946d91 Mon Sep 17 00:00:00 2001 From: wangkai Date: Thu, 13 Jul 2023 14:34:18 +0800 Subject: [PATCH 422/437] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangkai --- .../adapter/communicator/src/app_pipe_mgr.cpp | 2 +- .../communicator/src/communication_provider_impl.h | 2 +- .../adapter/communicator/src/data_buffer.cpp | 8 -------- .../adapter/communicator/src/data_buffer.h | 10 +++++----- .../service/udmf/udmf_service_impl.cpp | 2 -- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp index a2ac4894..f3794147 100644 --- a/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp +++ b/services/distributeddataservice/adapter/communicator/src/app_pipe_mgr.cpp @@ -63,7 +63,7 @@ Status AppPipeMgr::SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, { if (dataInfo.length > DataBuffer::MAX_TRANSFER_SIZE || dataInfo.length == 0 || dataInfo.data == nullptr || pipeInfo.pipeId.empty() || deviceId.deviceId.empty()) { - ZLOGW("Input is invalid, maxSize:%d, current size:%u", DataBuffer::MAX_TRANSFER_SIZE, dataInfo.length); + ZLOGW("Input is invalid, maxSize:%u, current size:%u", DataBuffer::MAX_TRANSFER_SIZE, dataInfo.length); return Status::ERROR; } ZLOGD("pipeInfo:%s ,size:%u, total length:%u", pipeInfo.pipeId.c_str(), dataInfo.length, totalLength); diff --git a/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h b/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h index 7838d988..edac68dc 100644 --- a/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h +++ b/services/distributeddataservice/adapter/communicator/src/communication_provider_impl.h @@ -36,7 +36,7 @@ public: Status StopWatchDataChange(const AppDataChangeListener *observer, const PipeInfo &pipeInfo) override; // Send data to other device, function will be called back after sent to notify send result. - Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &DataInfo, + Status SendData(const PipeInfo &pipeInfo, const DeviceId &deviceId, const DataInfo &dataInfo, uint32_t totalLength, const MessageInfo &info) override; // start 1 server to listen data from other devices; diff --git a/services/distributeddataservice/adapter/communicator/src/data_buffer.cpp b/services/distributeddataservice/adapter/communicator/src/data_buffer.cpp index 84d2f95a..49dd5459 100644 --- a/services/distributeddataservice/adapter/communicator/src/data_buffer.cpp +++ b/services/distributeddataservice/adapter/communicator/src/data_buffer.cpp @@ -19,14 +19,6 @@ namespace OHOS { namespace AppDistributedKv { int DataBuffer::sequence_ = 0; -const size_t DataBuffer::MAX_DATA_LEN = 1024 * 1024 * 5; - -const int DataBuffer::MAX_TRANSFER_SIZE = 1024 * 1024 * 5 - DataBuffer::HEADER_LEN; - -const uint32_t DataBuffer::VERSION = 0; - -const uint32_t DataBuffer::TYPE = 0; - DataBuffer::DataBuffer() : buf_(nullptr), size_(0), used_(0) {} diff --git a/services/distributeddataservice/adapter/communicator/src/data_buffer.h b/services/distributeddataservice/adapter/communicator/src/data_buffer.h index 1a7627c1..e56d8915 100644 --- a/services/distributeddataservice/adapter/communicator/src/data_buffer.h +++ b/services/distributeddataservice/adapter/communicator/src/data_buffer.h @@ -45,17 +45,17 @@ public: size_t GetBufUsed() const; // header length - static const int HEADER_LEN = sizeof(HeaderInfo); + static const uint32_t HEADER_LEN = sizeof(HeaderInfo); // max size for transferring data using pipe is 5M - static const size_t MAX_DATA_LEN; + static constexpr size_t MAX_DATA_LEN = 1024 * 1024 * 5; // 5M; max size for transfer using pipe (12 is header length, rest is data wait for transferring) - static const int MAX_TRANSFER_SIZE; + static constexpr uint32_t MAX_TRANSFER_SIZE = 1024 * 1024 * 5 - HEADER_LEN; - static const uint32_t VERSION; + static constexpr uint32_t VERSION = 0; - static const uint32_t TYPE; + static constexpr uint32_t TYPE = 0; private: char *buf_; diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index b1744347..09c3cd8b 100755 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -63,7 +63,6 @@ int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, res = DataManager::GetInstance().SaveData(option, unifiedData, key); } msg.result = ERROR_MAP.find(res)->second; - std::vector types = unifiedData.GetUDTypes(); msg.dataType = unifiedData.GetTypes(); msg.dataSize = unifiedData.GetSize(); Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); @@ -87,7 +86,6 @@ int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedD res = DataManager::GetInstance().RetrieveData(query, unifiedData); } msg.result = ERROR_MAP.find(res)->second; - std::vector types = unifiedData.GetUDTypes(); msg.dataType = unifiedData.GetTypes(); msg.dataSize = unifiedData.GetSize(); Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); -- Gitee From f2c16337bba115ea601b9453810b7b11aef1dca5 Mon Sep 17 00:00:00 2001 From: genglingxia Date: Thu, 13 Jul 2023 16:13:13 +0800 Subject: [PATCH 423/437] =?UTF-8?q?drag=20fix=20=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: genglingxia --- .../service/udmf/data_manager.cpp | 19 ++++++--- .../service/udmf/data_manager.h | 2 +- .../udmf/preprocess/preprocess_utils.cpp | 41 +++++++------------ .../udmf/preprocess/preprocess_utils.h | 4 +- 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/services/distributeddataservice/service/udmf/data_manager.cpp b/services/distributeddataservice/service/udmf/data_manager.cpp index 16461f3f..b9efa7f7 100755 --- a/services/distributeddataservice/service/udmf/data_manager.cpp +++ b/services/distributeddataservice/service/udmf/data_manager.cpp @@ -64,7 +64,7 @@ int32_t DataManager::SaveData(CustomOption &option, UnifiedData &unifiedData, st std::string intention = unifiedData.GetRuntime()->key.intention; if (intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { - int32_t ret = PreProcessUtils::SetDargRemoteUri(option.tokenId, unifiedData); + int32_t ret = PreProcessUtils::SetRemoteUri(option.tokenId, unifiedData); if (ret != E_OK) { return ret; } @@ -122,7 +122,9 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified } if (key.intention == UD_INTENTION_MAP.at(UD_INTENTION_DRAG)) { - if (DragUriProcessing(query, unifiedData) != E_OK) { + int32_t ret = ProcessingUri(query, unifiedData); + if (ret != E_OK) { + ZLOGE("DragUriProcessing failed. ret=%{public}d", ret); return E_NO_PERMISSION; } } @@ -135,11 +137,19 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified return E_OK; } -int32_t DataManager::DragUriProcessing(const QueryOption &query, UnifiedData &unifiedData) +int32_t DataManager::ProcessingUri(const QueryOption &query, UnifiedData &unifiedData) { std::string localDeviceId = PreProcessUtils::GetLocalDeviceId(); + auto records = unifiedData.GetRecords(); if (localDeviceId != unifiedData.GetRuntime()->deviceId) { - PreProcessUtils::ConvertUri(unifiedData.GetRecords()); + std::string uri; + for (auto record : records) { + if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) { + auto file = static_cast(record.get()); + uri = file->GetRemoteUri(); + file->SetUri(uri); // cross dev, need dis path. + } + } } std::string bundleName; @@ -147,7 +157,6 @@ int32_t DataManager::DragUriProcessing(const QueryOption &query, UnifiedData &un return E_ERROR; } if (unifiedData.GetRuntime()->createPackage != bundleName) { - auto records = unifiedData.GetRecords(); for (auto record : records) { if (record != nullptr && PreProcessUtils::IsFileType(record->GetType())) { auto file = static_cast(record.get()); diff --git a/services/distributeddataservice/service/udmf/data_manager.h b/services/distributeddataservice/service/udmf/data_manager.h index 7edbb43d..69abcefb 100755 --- a/services/distributeddataservice/service/udmf/data_manager.h +++ b/services/distributeddataservice/service/udmf/data_manager.h @@ -46,7 +46,7 @@ public: private: DataManager(); int32_t QueryDataCommon(const QueryOption &query, std::vector &dataSet, std::shared_ptr &store); - int32_t DragUriProcessing(const QueryOption &query, UnifiedData &unifiedData); + int32_t ProcessingUri(const QueryOption &query, UnifiedData &unifiedData); StoreCache storeCache_; std::map authorizationMap_; }; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp index 36d25e67..0e95ffd2 100755 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.cpp @@ -150,43 +150,30 @@ bool PreProcessUtils::IsFileType(UDType udType) || udType == UDType::FOLDER); } -int32_t PreProcessUtils::SetDargRemoteUri(uint32_t tokenId, UnifiedData &data) +int32_t PreProcessUtils::SetRemoteUri(uint32_t tokenId, UnifiedData &data) { int32_t userId = GetHapUidByToken(tokenId); std::string bundleName = data.GetRuntime()->createPackage; for (const auto &record : data.GetRecords()) { if (record != nullptr && IsFileType(record->GetType())) { auto file = static_cast(record.get()); - if (!(file->GetUri()).empty() && IsHapOwnPath(file->GetUri(), bundleName)) { - struct HmdfsUriInfo dfsUriInfo; - int ret = RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); - if (ret != 0 || dfsUriInfo.uriStr.empty()) { - ZLOGE("Get remoteUri failed, ret = %{public}d, userId: %{public}d.", ret, userId); - return E_FS_ERROR; - } - file->SetRemoteUri(dfsUriInfo.uriStr); + if (file->GetUri().empty()) { + continue; } + Uri uri(file->GetUri()); + if (uri.GetAuthority().empty()) { + continue; + } + struct HmdfsUriInfo dfsUriInfo; + int ret = RemoteFileShare::GetDfsUriFromLocal(file->GetUri(), userId, dfsUriInfo); + if (ret != 0 || dfsUriInfo.uriStr.empty()) { + ZLOGE("Get remoteUri failed, ret = %{public}d, userId: %{public}d.", ret, userId); + return E_FS_ERROR; + } + file->SetRemoteUri(dfsUriInfo.uriStr); } } return E_OK; } - -bool PreProcessUtils::IsHapOwnPath(const std::string &path, const std::string &bundleName) -{ - Uri uri(path); - return (uri.GetAuthority() == bundleName); -} - -void PreProcessUtils::ConvertUri(std::vector> records) -{ - std::string uri; - for (auto record : records) { - if (record != nullptr && IsFileType(record->GetType())) { - auto file = static_cast(record.get()); - uri = file->GetRemoteUri(); - file->SetUri(uri); // cross dev, need dis path. - } - } -} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 63d5803f..14892ff7 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -36,8 +36,8 @@ public: static std::string GetLocalDeviceId(); static void SetRemoteData(UnifiedData &data); static bool IsFileType(UDType udType); - static int32_t SetDargRemoteUri(uint32_t tokenId, UnifiedData &data); - static void ConvertUri(std::vector> records); + static int32_t SetRemoteUri(uint32_t tokenId, UnifiedData &data); + static void ConvertUri(std::vector> &records); static bool IsHapOwnPath(const std::string &uri, const std::string &bundleName); }; } // namespace UDMF -- Gitee From a630854151b38121bdde9f4e8533db120254ad61 Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 13 Jul 2023 20:04:00 +0800 Subject: [PATCH 424/437] f Signed-off-by: hanlu --- .../service/data_share/BUILD.gn | 1 + .../data_share/common/scheduler_manager.cpp | 9 +++++ .../data_share/common/scheduler_manager.h | 1 + .../data_share/data_share_service_impl.cpp | 37 ++++++++++++++++++- .../data_share/data_share_service_impl.h | 12 +++++- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 8cb08cb8..d2107b3d 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -98,6 +98,7 @@ ohos_shared_library("data_share_service") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "common_event_service:cesfwk_innerkits", "data_share:datashare_common", "device_manager:devicemanagersdk", "hilog:libhilog", diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index c0c96fc1..a0fa073c 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -178,5 +178,14 @@ void SchedulerManager::SetExecutorPool(std::shared_ptr executor) { executor_ = executor; } + +void SchedulerManager::ReExecuteAll() +{ + std::lock_guard lock(mutex_); + for (auto &item : timerCache_) { + // restart in 200ms + executor_->Reset(item.second, std::chrono::milliseconds(200)); + } +} } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.h b/services/distributeddataservice/service/data_share/common/scheduler_manager.h index d133218a..939da970 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.h +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.h @@ -28,6 +28,7 @@ public: static SchedulerManager &GetInstance(); void Execute(const std::string &uri, const int32_t userId, const std::string &rdbDir, int version); void Execute(const Key &key, const int32_t userId, const std::string &rdbDir, int version); + void ReExecuteAll(); void SetTimer(const std::string &dbPath, const int32_t userId, int version, const Key &key, int64_t reminderTime); void RemoveTimer(const Key &key); void ClearTimer(); diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index f084a0fe..3f5af981 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -20,6 +20,8 @@ #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "app_connect_manager.h" +#include "common_event_manager.h" +#include "common_event_support.h" #include "dataobs_mgr_client.h" #include "datashare_errno.h" #include "datashare_template.h" @@ -27,10 +29,11 @@ #include "hap_token_info.h" #include "ipc_skeleton.h" #include "log_print.h" +#include "matching_skills.h" #include "scheduler_manager.h" #include "subscriber_managers/published_data_subscriber_manager.h" -#include "utils/anonymous.h" #include "template_data.h" +#include "utils/anonymous.h" namespace OHOS::DataShare { using FeatureSystem = DistributedData::FeatureSystem; @@ -429,6 +432,7 @@ int32_t DataShareServiceImpl::OnBind(const BindInfo &binderInfo) saveMeta.dataDir = DistributedData::DirectoryManager::GetInstance().GetStorePath(saveMeta); KvDBDelegate::GetInstance(false, saveMeta.dataDir, binderInfo.executors); SchedulerManager::GetInstance().SetExecutorPool(binderInfo.executors); + SubscribeTimeChanged(); return EOK; } @@ -484,4 +488,35 @@ void DataShareServiceImpl::NotifyObserver(const std::string &uri) RdbSubscriberManager::GetInstance().Emit(uri, context); } } +bool DataShareServiceImpl::SubscribeTimeChanged() +{ + ZLOGD("start"); + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON); + timerReceiver_ = std::make_shared(subscribeInfo); + auto result = EventFwk::CommonEventManager::SubscribeCommonEvent(timerReceiver_); + if (!result) { + ZLOGE("SubscribeCommonEvent err"); + } + return result; +} + +void DataShareServiceImpl::TimerReceiver::OnReceiveEvent(const EventFwk::CommonEventData &eventData) +{ + AAFwk::Want want = eventData.GetWant(); + std::string action = want.GetAction(); + ZLOGI("action:%{public}s.", action.c_str()); + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_TIME_CHANGED + || action == EventFwk::CommonEventSupport::COMMON_EVENT_TIMEZONE_CHANGED) { + SchedulerManager::GetInstance().ReExecuteAll(); + } +} + +DataShareServiceImpl::TimerReceiver::TimerReceiver(const EventFwk::CommonEventSubscribeInfo &subscriberInfo) + : CommonEventSubscriber(subscriberInfo) +{ +} } // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 7978baed..46d7ca1f 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -18,6 +18,8 @@ #include +#include "common_event_subscribe_info.h" +#include "common_event_subscriber.h" #include "data_proxy_observer.h" #include "data_share_service_stub.h" #include "datashare_template.h" @@ -77,7 +79,14 @@ private: Factory(); ~Factory(); }; - + class TimerReceiver : public EventFwk::CommonEventSubscriber { + public: + TimerReceiver() = default; + TimerReceiver(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); + virtual ~TimerReceiver() = default; + virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; + }; + bool SubscribeTimeChanged(); bool NotifyChange(const std::string &uri); bool GetCallerBundleName(std::string &bundleName); static Factory factory_; @@ -92,6 +101,7 @@ private: TemplateStrategy templateStrategy_; RdbNotifyStrategy rdbNotifyStrategy_; BindInfo binderInfo_; + std::shared_ptr timerReceiver_ = nullptr; }; } // namespace OHOS::DataShare #endif -- Gitee From 211ece126f06ab000da9dd8756e634b36aef94ef Mon Sep 17 00:00:00 2001 From: hanlu Date: Thu, 13 Jul 2023 22:00:06 +0800 Subject: [PATCH 425/437] f Signed-off-by: hanlu --- .../service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index e2cbf7fe..e821b361 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -104,6 +104,7 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "common_event_service:cesfwk_innerkits", "data_share:datashare_common", "device_manager:devicemanagersdk", "hilog:libhilog", -- Gitee From 7ada16bf37f220445ad964d69f4df49800b49036 Mon Sep 17 00:00:00 2001 From: anqi Date: Fri, 14 Jul 2023 10:37:54 +0800 Subject: [PATCH 426/437] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E7=82=B9?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20Signed-off-by:=20anqi=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dfx/src/behaviour/behaviour_reporter_impl.cpp | 4 ++-- .../dfx/src/behaviour/behaviour_reporter_impl.h | 2 +- .../adapter/dfx/src/hiview_adapter.cpp | 8 ++++++-- .../adapter/dfx/src/hiview_adapter.h | 2 +- .../adapter/include/dfx/behaviour_reporter.h | 2 +- .../adapter/include/dfx/dfx_types.h | 2 +- .../service/udmf/preprocess/preprocess_utils.h | 2 -- .../service/udmf/udmf_service_impl.cpp | 12 +++++++----- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp index cee6b854..7632db6c 100644 --- a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp +++ b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.cpp @@ -22,9 +22,9 @@ ReportStatus BehaviourReporterImpl::Report(const BehaviourMsg &msg) return ReportStatus::SUCCESS; } -ReportStatus BehaviourReporterImpl::UDMFReport(const UDMFBehaviourMsg &msg) +ReportStatus BehaviourReporterImpl::UDMFReport(const UdmfBehaviourMsg &msg) { - HiViewAdapter::ReportUDMFBehaviour(DfxCodeConstant::UDMF_DATA_BEHAVIOR, msg, executors_); + HiViewAdapter::ReportUdmfBehaviour(DfxCodeConstant::UDMF_DATA_BEHAVIOR, msg, executors_); return ReportStatus::SUCCESS; } diff --git a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h index 72d9ef3c..5fff69e4 100644 --- a/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h +++ b/services/distributeddataservice/adapter/dfx/src/behaviour/behaviour_reporter_impl.h @@ -25,7 +25,7 @@ class BehaviourReporterImpl : public BehaviourReporter { public: virtual ~BehaviourReporterImpl() {} ReportStatus Report(const struct BehaviourMsg &msg) override; - ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) override; + ReportStatus UDMFReport(const UdmfBehaviourMsg &msg) override; void SetThreadPool(std::shared_ptr executors); private: diff --git a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp index c98b3b36..47aa3016 100644 --- a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp +++ b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.cpp @@ -304,9 +304,13 @@ void HiViewAdapter::ReportApiPerformanceStatistic(int dfxCode, const ApiPerforma StartTimerThread(executors); } -void HiViewAdapter::ReportUDMFBehaviour( - int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr executors) +void HiViewAdapter::ReportUdmfBehaviour( + int dfxCode, const UdmfBehaviourMsg &msg, std::shared_ptr executors) { + if (executors == nullptr) { + ZLOGI("report udmf behavior failed"); + return; + } ExecutorPool::Task task([dfxCode, msg]() { HiSysEventWrite(HiSysEvent::Domain::DISTRIBUTED_DATAMGR, CoverEventID(dfxCode), diff --git a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h index 7bfbc6c0..cb03b82c 100644 --- a/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h +++ b/services/distributeddataservice/adapter/dfx/src/hiview_adapter.h @@ -46,7 +46,7 @@ public: static void ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat, std::shared_ptr executors); static void ReportBehaviour(int dfxCode, const BehaviourMsg &msg, std::shared_ptr executors); - static void ReportUDMFBehaviour(int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr executors); + static void ReportUdmfBehaviour(int dfxCode, const UdmfBehaviourMsg &msg, std::shared_ptr executors); static void StartTimerThread(std::shared_ptr executors); private: diff --git a/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h b/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h index 4a9c9062..82431c96 100644 --- a/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h +++ b/services/distributeddataservice/adapter/include/dfx/behaviour_reporter.h @@ -23,7 +23,7 @@ namespace DistributedDataDfx { class BehaviourReporter { public: KVSTORE_API virtual ReportStatus Report(const BehaviourMsg &msg) = 0; - KVSTORE_API virtual ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) = 0; + KVSTORE_API virtual ReportStatus UDMFReport(const UdmfBehaviourMsg &msg) = 0; KVSTORE_API virtual ~BehaviourReporter() {} }; } // namespace DistributedDataDfx diff --git a/services/distributeddataservice/adapter/include/dfx/dfx_types.h b/services/distributeddataservice/adapter/include/dfx/dfx_types.h index 8068abbe..cbc0117d 100644 --- a/services/distributeddataservice/adapter/include/dfx/dfx_types.h +++ b/services/distributeddataservice/adapter/include/dfx/dfx_types.h @@ -131,7 +131,7 @@ struct BehaviourMsg { std::string extensionInfo; }; -struct UDMFBehaviourMsg { +struct UdmfBehaviourMsg { std::string appId; std::string channel; int64_t dataSize; diff --git a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h index 14892ff7..129b42c1 100644 --- a/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h +++ b/services/distributeddataservice/service/udmf/preprocess/preprocess_utils.h @@ -37,8 +37,6 @@ public: static void SetRemoteData(UnifiedData &data); static bool IsFileType(UDType udType); static int32_t SetRemoteUri(uint32_t tokenId, UnifiedData &data); - static void ConvertUri(std::vector> &records); - static bool IsHapOwnPath(const std::string &uri, const std::string &bundleName); }; } // namespace UDMF } // namespace OHOS diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index 09c3cd8b..b343283b 100755 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -27,7 +27,7 @@ namespace OHOS { namespace UDMF { using FeatureSystem = DistributedData::FeatureSystem; -using UDMFBehaviourMsg = OHOS::DistributedDataDfx::UDMFBehaviourMsg; +using UdmfBehaviourMsg = OHOS::DistributedDataDfx::UdmfBehaviourMsg; using Reporter = OHOS::DistributedDataDfx::Reporter; __attribute__((used)) UdmfServiceImpl::Factory UdmfServiceImpl::factory_; UdmfServiceImpl::Factory::Factory() @@ -50,7 +50,7 @@ int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, { ZLOGD("start"); int32_t res = E_OK; - UDMFBehaviourMsg msg; + UdmfBehaviourMsg msg; auto find = UD_INTENTION_MAP.find(option.intention); msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second; msg.operation = "insert"; @@ -62,7 +62,8 @@ int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, msg.appId = bundleName; res = DataManager::GetInstance().SaveData(option, unifiedData, key); } - msg.result = ERROR_MAP.find(res)->second; + auto errFind = ERROR_MAP.find(res); + msg.result = errFind == ERROR_MAP.end() ? "E_ERROR" : errFind->second; msg.dataType = unifiedData.GetTypes(); msg.dataSize = unifiedData.GetSize(); Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); @@ -73,7 +74,7 @@ int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedD { ZLOGD("start"); int32_t res = E_OK; - UDMFBehaviourMsg msg; + UdmfBehaviourMsg msg; auto find = UD_INTENTION_MAP.find(query.intention); msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second; msg.operation = "insert"; @@ -85,7 +86,8 @@ int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedD msg.appId = bundleName; res = DataManager::GetInstance().RetrieveData(query, unifiedData); } - msg.result = ERROR_MAP.find(res)->second; + auto errFind = ERROR_MAP.find(res); + msg.result = errFind == ERROR_MAP.end() ? "E_ERROR" : errFind->second; msg.dataType = unifiedData.GetTypes(); msg.dataSize = unifiedData.GetSize(); Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg); -- Gitee From 08682491b90546c69e8de5f8b2d2f27b537b3ee9 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 14 Jul 2023 14:48:15 +0800 Subject: [PATCH 427/437] fix Signed-off-by: niudongyao --- .../data_share/data_share_service_impl.cpp | 8 +++- .../published_data_subscriber_manager.cpp | 41 +++++++++++++++++++ .../published_data_subscriber_manager.h | 6 +++ .../rdb_subscriber_manager.cpp | 29 ++++++++----- .../rdb_subscriber_manager.h | 1 + 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index cb7b14f7..cf203381 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -185,6 +185,7 @@ std::vector DataShareServiceImpl::Publish(const Data &data, con } if (!publishedData.empty()) { PublishedDataSubscriberManager::GetInstance().Emit(publishedData, userId, callerBundleName); + PublishedDataSubscriberManager::GetInstance().SetObserversNotifiedOnEnabled(publishedData); } return results; } @@ -356,12 +357,17 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect } results.emplace_back(uri, result); if (result == E_OK) { - publishedKeys.emplace_back(context->uri, context->callerBundleName, subscriberId); + PublishedDataKey pKey(context->uri, context->callerBundleName, subscriberId); + // ��ȥ����key��ѯ���ж�����tokenid��ͬ���Ƿ�boolֵΪtrue + if (PublishedDataSubscriberManager::GetInstance().IsNotifyOnEnabled(pKey, context->callerTokenId)) { + publishedKeys.emplace_back(pKey); + } userId = context->currentUserId; } } if (!publishedKeys.empty()) { PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, userId, callerBundleName); + PublishedDataSubscriberManager::GetInstance().SetObserversNotNotifiedOnEnabled(publishedKeys); } return results; } diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index 4972ae45..acddf608 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -83,6 +83,7 @@ int PublishedDataSubscriberManager::Disable(const PublishedDataKey &key, uint32_ for (auto it = value.begin(); it != value.end(); it++) { if (it->callerTokenId == callerTokenId) { it->enabled = false; + it->isNotifyOnEnabled = false; } } return true; @@ -177,6 +178,46 @@ int PublishedDataSubscriberManager::GetCount(const PublishedDataKey &key) return count; } +bool PublishedDataSubscriberManager::IsNotifyOnEnabled(const PublishedDataKey &key, uint32_t callerTokenId) +{ + auto pair = publishedDataCache_.Find(key); + if (!pair.first) { + return false; + } + for (const auto &value : pair.second) { + if (value.callerTokenId == callerTokenId && value.isNotifyOnEnabled) { + return true; + } + } + return false; +} + +void PublishedDataSubscriberManager::SetObserversNotifiedOnEnabled(const std::vector &keys) +{ + for (const auto &pkey : keys) { + publishedDataCache_.ComputeIfPresent(pkey, [](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + if (!it->enabled) { + it->isNotifyOnEnabled = true; + } + } + return true; + }); + } +} + +void PublishedDataSubscriberManager::SetObserversNotNotifiedOnEnabled(const std::vector &keys) +{ + for (const auto &pkey : keys) { + publishedDataCache_.ComputeIfPresent(pkey, [](const auto &key, std::vector &value) { + for (auto it = value.begin(); it != value.end(); it++) { + it->isNotifyOnEnabled = false; + } + return true; + }); + } +} + PublishedDataKey::PublishedDataKey(const std::string &key, const std::string &bundle, const int64_t subscriberId) : key(key), bundleName(bundle), subscriberId(subscriberId) { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index 6a21c820..34963b0f 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -51,12 +51,18 @@ public: const sptr observer = nullptr); void Clear(); int GetCount(const PublishedDataKey &key); + + bool IsNotifyOnEnabled(const PublishedDataKey &key, uint32_t callerTokenId); + void SetObserversNotNotifiedOnEnabled(const std::vector &keys); + void SetObserversNotifiedOnEnabled(const std::vector &keys); + private: struct ObserverNode { ObserverNode(const sptr &observer, uint32_t callerTokenId); sptr observer; uint32_t callerTokenId; bool enabled = true; + bool isNotifyOnEnabled = false; }; PublishedDataSubscriberManager() = default; diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index 9acd29a0..2bb23216 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -180,11 +180,9 @@ int RdbSubscriberManager::Disable(const Key &key, uint32_t callerTokenId) for (auto it = value.begin(); it != value.end(); it++) { if (it->callerTokenId == callerTokenId) { it->enabled = false; + it->isNotifyOnEnabled = false; } } - if (GetEnableObserverCount(key) == 0) { - SchedulerManager::GetInstance().RemoveTimer(key); - } return true; }); return result ? E_OK : E_SUBSCRIBER_NOT_EXIST; @@ -197,16 +195,15 @@ int RdbSubscriberManager::Enable(const Key &key, std::shared_ptr contex if (it->callerTokenId == context->callerTokenId) { it->enabled = true; std::vector node; - node.emplace_back(it->observer, context->callerTokenId); - LoadConfigDataInfoStrategy loadDataInfo; - if (loadDataInfo(context)) { - Notify(key, context->currentUserId, node, context->calledSourceDir, context->version); + if (it->isNotifyOnEnabled) { + node.emplace_back(it->observer, context->callerTokenId); + LoadConfigDataInfoStrategy loadDataInfo; + if (loadDataInfo(context)) { + Notify(key, context->currentUserId, node, context->calledSourceDir, context->version); + } + it->isNotifyOnEnabled = false; } } - if (GetEnableObserverCount(key) == 1) { - SchedulerManager::GetInstance().Execute( - key, context->currentUserId, context->calledSourceDir, context->version); - } } return true; }); @@ -227,6 +224,11 @@ void RdbSubscriberManager::Emit(const std::string &uri, std::shared_ptr return false; } Notify(key, context->currentUserId, val, context->calledSourceDir, context->version); + for (auto &node : val) { + if (!node.enabled) { + node.isNotifyOnEnabled = true; + } + } return false; }); SchedulerManager::GetInstance().Execute( @@ -253,6 +255,11 @@ void RdbSubscriberManager::EmitByKey(const Key &key, int32_t userId, const std:: } rdbCache_.ComputeIfPresent(key, [&rdbPath, &version, &userId, this](const Key &key, auto &val) { Notify(key, userId, val, rdbPath, version); + for (auto &node : val) { + if (!node.enabled) { + node.isNotifyOnEnabled = true; + } + } return true; }); } diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h index 32f8471e..1cab6fe6 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h @@ -69,6 +69,7 @@ private: sptr observer; uint32_t callerTokenId; bool enabled = true; + bool isNotifyOnEnabled = false; }; RdbSubscriberManager() = default; -- Gitee From 43251f7b383dbad4c19b7b1ca70f1a83cf6a5574 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 14 Jul 2023 14:49:14 +0800 Subject: [PATCH 428/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 62 +++++++++++++++++++ .../data_share/data_share_service_impl.cpp | 1 - 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..d02956a4 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1688093771186 + + + + + + + + + \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index cf203381..1168adce 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -358,7 +358,6 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect results.emplace_back(uri, result); if (result == E_OK) { PublishedDataKey pKey(context->uri, context->callerBundleName, subscriberId); - // ��ȥ����key��ѯ���ж�����tokenid��ͬ���Ƿ�boolֵΪtrue if (PublishedDataSubscriberManager::GetInstance().IsNotifyOnEnabled(pKey, context->callerTokenId)) { publishedKeys.emplace_back(pKey); } -- Gitee From e7cb5f909be7e651b805e9d3650f6e2b8f153fc8 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 14 Jul 2023 14:49:25 +0800 Subject: [PATCH 429/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 62 --------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index d02956a4..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1688093771186 - - - - - - - - - \ No newline at end of file -- Gitee From fb2746aaa592ebf7563b19980c3c0efb8d500855 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 14 Jul 2023 15:05:01 +0800 Subject: [PATCH 430/437] fix Signed-off-by: niudongyao --- .../rdb_subscriber_manager.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index 2bb23216..336224b7 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -192,17 +192,18 @@ int RdbSubscriberManager::Enable(const Key &key, std::shared_ptr contex { auto result = rdbCache_.ComputeIfPresent(key, [&context, this](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { - if (it->callerTokenId == context->callerTokenId) { - it->enabled = true; + if (it->callerTokenId != context->callerTokenId) { + continue; + } + it->enabled = true; + if (it->isNotifyOnEnabled) { std::vector node; - if (it->isNotifyOnEnabled) { - node.emplace_back(it->observer, context->callerTokenId); - LoadConfigDataInfoStrategy loadDataInfo; - if (loadDataInfo(context)) { - Notify(key, context->currentUserId, node, context->calledSourceDir, context->version); - } - it->isNotifyOnEnabled = false; + node.emplace_back(it->observer, context->callerTokenId); + LoadConfigDataInfoStrategy loadDataInfo; + if (loadDataInfo(context)) { + Notify(key, context->currentUserId, node, context->calledSourceDir, context->version); } + it->isNotifyOnEnabled = false; } } return true; -- Gitee From 80e1a0a6729faa364ffa7f47bd5178d0b4945a29 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 14 Jul 2023 15:55:12 +0800 Subject: [PATCH 431/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 62 +++++++++++++++++++ .../data_share/data_share_service_impl.cpp | 4 +- .../published_data_subscriber_manager.cpp | 10 ++- .../published_data_subscriber_manager.h | 2 +- 4 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..9c240cc9 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1688093771186 + + + + + + + + + \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 1168adce..c5abe852 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -340,6 +340,7 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect std::vector publishedKeys; int32_t result; int32_t userId = -1; + uint32_t callerTokenId = 0; for (const auto &uri : uris) { auto context = std::make_shared(uri); PublishedDataKey key(uri, callerBundleName, subscriberId); @@ -349,6 +350,7 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect return PublishedDataSubscriberManager::GetInstance().Enable( PublishedDataKey(context->uri, context->callerBundleName, subscriberId), context->callerTokenId); }); + callerTokenId = context->callerTokenId; if (result == E_OK && binderInfo_.executors != nullptr) { binderInfo_.executors->Execute([context, subscriberId]() { PublishedData::UpdateTimestamp( @@ -366,7 +368,7 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect } if (!publishedKeys.empty()) { PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, userId, callerBundleName); - PublishedDataSubscriberManager::GetInstance().SetObserversNotNotifiedOnEnabled(publishedKeys); + PublishedDataSubscriberManager::GetInstance().SetObserversNotNotifiedOnEnabled(publishedKeys, callerTokenId); } return results; } diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index acddf608..96be5de0 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -206,12 +206,16 @@ void PublishedDataSubscriberManager::SetObserversNotifiedOnEnabled(const std::ve } } -void PublishedDataSubscriberManager::SetObserversNotNotifiedOnEnabled(const std::vector &keys) +void PublishedDataSubscriberManager::SetObserversNotNotifiedOnEnabled(const std::vector &keys, + uint32_t callerTokenId) { for (const auto &pkey : keys) { - publishedDataCache_.ComputeIfPresent(pkey, [](const auto &key, std::vector &value) { + publishedDataCache_.ComputeIfPresent(pkey, + [&callerTokenId](const auto &key, std::vector &value) { for (auto it = value.begin(); it != value.end(); it++) { - it->isNotifyOnEnabled = false; + if (it->callerTokenId == callerTokenId) { + it->isNotifyOnEnabled = false; + } } return true; }); diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index 34963b0f..2fe17023 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -53,7 +53,7 @@ public: int GetCount(const PublishedDataKey &key); bool IsNotifyOnEnabled(const PublishedDataKey &key, uint32_t callerTokenId); - void SetObserversNotNotifiedOnEnabled(const std::vector &keys); + void SetObserversNotNotifiedOnEnabled(const std::vector &keys, uint32_t callerTokenId); void SetObserversNotifiedOnEnabled(const std::vector &keys); private: -- Gitee From cc74d5997ad0511655619fd53d4117ee90739934 Mon Sep 17 00:00:00 2001 From: niudongyao Date: Fri, 14 Jul 2023 15:55:17 +0800 Subject: [PATCH 432/437] fix Signed-off-by: niudongyao --- .idea/workspace.xml | 62 --------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 .idea/workspace.xml diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 9c240cc9..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1688093771186 - - - - - - - - - \ No newline at end of file -- Gitee From 4f112cea363d6681cf3f621613907d4cce9be2fd Mon Sep 17 00:00:00 2001 From: renjiecui Date: Fri, 14 Jul 2023 09:16:53 +0800 Subject: [PATCH 433/437] modify bundle.json Signed-off-by: renjiecui --- bundle.json | 1 + .../adapter/communicator/src/device_manager_adapter.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 3b5839ad..deb3ae21 100644 --- a/bundle.json +++ b/bundle.json @@ -70,6 +70,7 @@ "kv_store", "ipc", "napi", + "netmanager_base", "os_account", "relational_store", "safwk", diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index b7af5973..21a2cdd1 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -107,7 +107,6 @@ int32_t NetConnCallbackObserver::NetAvailable(sptr & int32_t NetConnCallbackObserver::NetLost(sptr &netHandle) { ZLOGI("OnNetLost"); + dmAdapter_.isNetAvailable_ = false; + dmAdapter_.Offline(DeviceManagerAdapter::cloudDmInfo); return DistributedKv::SUCCESS; } -- Gitee From b3f9933fd82a9551030e9ed4423e614b9a234797 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Fri, 14 Jul 2023 17:31:34 +0800 Subject: [PATCH 434/437] add ondeviceoffline Signed-off-by: renjiecui --- .../app/src/kvstore_data_service.cpp | 11 +++++++++++ .../app/src/kvstore_data_service.h | 2 ++ .../app/src/kvstore_device_listener.cpp | 2 ++ 3 files changed, 15 insertions(+) diff --git a/services/distributeddataservice/app/src/kvstore_data_service.cpp b/services/distributeddataservice/app/src/kvstore_data_service.cpp index 5c317362..df12f123 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/services/distributeddataservice/app/src/kvstore_data_service.cpp @@ -659,6 +659,17 @@ void KvStoreDataService::OnDeviceOnline(const AppDistributedKv::DeviceInfo &info }); } +void KvStoreDataService::OnDeviceOffline(const AppDistributedKv::DeviceInfo &info) +{ + if (info.uuid.empty()) { + return; + } + features_.ForEachCopies([&info](const auto &key, sptr &value) { + value->Offline(info.uuid); + return false; + }); +} + void KvStoreDataService::OnDeviceOnReady(const AppDistributedKv::DeviceInfo &info) { if (info.uuid.empty()) { diff --git a/services/distributeddataservice/app/src/kvstore_data_service.h b/services/distributeddataservice/app/src/kvstore_data_service.h index 4a16d21c..12f949b2 100644 --- a/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/services/distributeddataservice/app/src/kvstore_data_service.h @@ -71,6 +71,8 @@ public: void OnDeviceOnline(const AppDistributedKv::DeviceInfo &info); + void OnDeviceOffline(const AppDistributedKv::DeviceInfo &info); + void OnDeviceOnReady(const AppDistributedKv::DeviceInfo &info); int32_t OnUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); diff --git a/services/distributeddataservice/app/src/kvstore_device_listener.cpp b/services/distributeddataservice/app/src/kvstore_device_listener.cpp index 4d155a17..be0e9a79 100644 --- a/services/distributeddataservice/app/src/kvstore_device_listener.cpp +++ b/services/distributeddataservice/app/src/kvstore_device_listener.cpp @@ -26,6 +26,8 @@ void KvStoreDeviceListener::OnDeviceChanged( if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONLINE) { kvStoreDataService_.SetCompatibleIdentify(info); kvStoreDataService_.OnDeviceOnline(info); + } else if (type == AppDistributedKv::DeviceChangeType::DEVICE_OFFLINE) { + kvStoreDataService_.OnDeviceOffline(info); } else if (type == AppDistributedKv::DeviceChangeType::DEVICE_ONREADY) { kvStoreDataService_.OnDeviceOnReady(info); } -- Gitee From 26b1016e0e0f2f2dcdfcb92f1adddb04ab141c77 Mon Sep 17 00:00:00 2001 From: renjiecui Date: Fri, 14 Jul 2023 18:01:11 +0800 Subject: [PATCH 435/437] modify construct cloudDmInfo Signed-off-by: renjiecui --- .../adapter/communicator/src/device_manager_adapter.cpp | 2 +- .../adapter/include/communicator/device_manager_adapter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index 21a2cdd1..ef2fb38d 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -31,7 +31,6 @@ using namespace OHOS::NetManagerStandard; using KvStoreUtils = OHOS::DistributedKv::KvStoreUtils; constexpr int32_t DM_OK = 0; constexpr const char *PKG_NAME = "ohos.distributeddata.service"; -DmDeviceInfo DeviceManagerAdapter::cloudDmInfo = { "cloudDeviceId", "cloudDeviceName", 0, "cloudNetworkId", 0 }; class DataMgrDmStateCall final : public DistributedHardware::DeviceStateCallback { public: explicit DataMgrDmStateCall(DeviceManagerAdapter &dmAdapter) : dmAdapter_(dmAdapter) {} @@ -140,6 +139,7 @@ int32_t NetConnCallbackObserver::NetBlockStatusChange(sptr &netHandle } DeviceManagerAdapter::DeviceManagerAdapter() + : cloudDmInfo({ "cloudDeviceId", "cloudDeviceName", 0, "cloudNetworkId", 0 }) { ZLOGI("construct"); } diff --git a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h index d7d43688..71b04416 100644 --- a/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h +++ b/services/distributeddataservice/adapter/include/communicator/device_manager_adapter.h @@ -76,7 +76,7 @@ private: std::mutex devInfoMutex_ {}; DeviceInfo localInfo_ {}; - static DmDeviceInfo cloudDmInfo; + const DmDeviceInfo cloudDmInfo; ConcurrentMap observers_ {}; LRUBucket deviceInfos_ {64}; static constexpr size_t TIME_TASK_CAPACITY = 50; -- Gitee From 0d49e05998e6916f13a2cd208a1aa6fac9da96fd Mon Sep 17 00:00:00 2001 From: renjiecui Date: Fri, 14 Jul 2023 18:32:39 +0800 Subject: [PATCH 436/437] modify code Signed-off-by: renjiecui --- .../src/device_manager_adapter.cpp | 4 +-- .../service/cloud/cloud_service_impl.cpp | 32 ++----------------- .../service/cloud/sync_manager.cpp | 10 +++--- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp index ef2fb38d..83a07de3 100644 --- a/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp +++ b/services/distributeddataservice/adapter/communicator/src/device_manager_adapter.cpp @@ -98,7 +98,7 @@ private: int32_t NetConnCallbackObserver::NetAvailable(sptr &netHandle) { ZLOGI("OnNetworkAvailable"); - dmAdapter_.Online(DeviceManagerAdapter::cloudDmInfo); + dmAdapter_.Online(dmAdapter_.cloudDmInfo); dmAdapter_.isNetAvailable_ = true; return DistributedKv::SUCCESS; } @@ -128,7 +128,7 @@ int32_t NetConnCallbackObserver::NetLost(sptr &netHandle) { ZLOGI("OnNetLost"); dmAdapter_.isNetAvailable_ = false; - dmAdapter_.Offline(DeviceManagerAdapter::cloudDmInfo); + dmAdapter_.Offline(dmAdapter_.cloudDmInfo); return DistributedKv::SUCCESS; } diff --git a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 1e3992bc..3d2567db 100644 --- a/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -36,7 +36,7 @@ using namespace std::chrono; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using Account = OHOS::DistributedKv::AccountDelegate; using AccessTokenKit = Security::AccessToken::AccessTokenKit; -const std::string NET_UUID = "netUuid"; +constexpr std::string_view NET_UUID = "netUuid"; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; const CloudServiceImpl::Work CloudServiceImpl::HANDLERS[WORK_BUTT] = { &CloudServiceImpl::DoSubscribe, @@ -252,20 +252,7 @@ int32_t CloudServiceImpl::Online(const std::string &device) return SUCCESS; } auto it = users.begin(); - while (it != users.end()) { - CloudInfo cloudInfo; - cloudInfo.user = *it; - if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS && GetCloudInfoFromServer(cloudInfo) != SUCCESS) { - it++; - continue; - } - if (!cloudInfo.enableCloud) { - it++; - continue; - } - syncManager_.DoCloudSync({ *it }); - it++; - } + syncManager_.DoCloudSync({ *it }); return SUCCESS; } @@ -281,20 +268,7 @@ int32_t CloudServiceImpl::Offline(const std::string &device) return SUCCESS; } auto it = users.begin(); - while (it != users.end()) { - CloudInfo cloudInfo; - cloudInfo.user = *it; - if (GetCloudInfoFromMeta(cloudInfo) != SUCCESS && GetCloudInfoFromServer(cloudInfo) != SUCCESS) { - it++; - continue; - } - if (!cloudInfo.enableCloud) { - it++; - continue; - } - syncManager_.StopCloudSync(*it); - it++; - } + syncManager_.StopCloudSync(*it); return SUCCESS; } diff --git a/services/distributeddataservice/service/cloud/sync_manager.cpp b/services/distributeddataservice/service/cloud/sync_manager.cpp index 3e7e3c32..742918b5 100644 --- a/services/distributeddataservice/service/cloud/sync_manager.cpp +++ b/services/distributeddataservice/service/cloud/sync_manager.cpp @@ -183,6 +183,11 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount return; } + if (!DmAdapter::GetInstance().IsNetworkAvailable()) { + info.SetError(E_NETWORK_ERROR); + return; + } + std::vector schemas; auto key = cloud.GetSchemaPrefix(info.bundleName_); auto retryer = GetRetryer(times, info); @@ -192,11 +197,6 @@ ExecutorPool::Task SyncManager::GetSyncTask(int32_t times, bool retry, RefCount return; } - if (!DmAdapter::GetInstance().IsNetworkAvailable()) { - retryer(RETRY_INTERVAL, E_NETWORK_ERROR); - return; - } - Defer defer(GetSyncHandler(std::move(retryer)), CloudEvent::CLOUD_SYNC); for (auto &schema : schemas) { if (!cloud.IsOn(schema.bundleName)) { -- Gitee From 443b3ded34e06deaa2ddda4dfd0829e58e3299df Mon Sep 17 00:00:00 2001 From: niudongyao Date: Sat, 15 Jul 2023 10:20:18 +0800 Subject: [PATCH 437/437] fix Signed-off-by: niudongyao --- .../data_share/data_share_service_impl.cpp | 1 - .../published_data_subscriber_manager.cpp | 16 -------------- .../published_data_subscriber_manager.h | 1 - .../rdb_subscriber_manager.cpp | 22 +++++++++---------- .../rdb_subscriber_manager.h | 1 + 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index c5abe852..338a461e 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -368,7 +368,6 @@ std::vector DataShareServiceImpl::EnablePubSubs(const std::vect } if (!publishedKeys.empty()) { PublishedDataSubscriberManager::GetInstance().Emit(publishedKeys, userId, callerBundleName); - PublishedDataSubscriberManager::GetInstance().SetObserversNotNotifiedOnEnabled(publishedKeys, callerTokenId); } return results; } diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index 96be5de0..0f057ed0 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -206,22 +206,6 @@ void PublishedDataSubscriberManager::SetObserversNotifiedOnEnabled(const std::ve } } -void PublishedDataSubscriberManager::SetObserversNotNotifiedOnEnabled(const std::vector &keys, - uint32_t callerTokenId) -{ - for (const auto &pkey : keys) { - publishedDataCache_.ComputeIfPresent(pkey, - [&callerTokenId](const auto &key, std::vector &value) { - for (auto it = value.begin(); it != value.end(); it++) { - if (it->callerTokenId == callerTokenId) { - it->isNotifyOnEnabled = false; - } - } - return true; - }); - } -} - PublishedDataKey::PublishedDataKey(const std::string &key, const std::string &bundle, const int64_t subscriberId) : key(key), bundleName(bundle), subscriberId(subscriberId) { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h index 2fe17023..2cef1f7c 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.h @@ -53,7 +53,6 @@ public: int GetCount(const PublishedDataKey &key); bool IsNotifyOnEnabled(const PublishedDataKey &key, uint32_t callerTokenId); - void SetObserversNotNotifiedOnEnabled(const std::vector &keys, uint32_t callerTokenId); void SetObserversNotifiedOnEnabled(const std::vector &keys); private: diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index 336224b7..6abb2225 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -203,7 +203,6 @@ int RdbSubscriberManager::Enable(const Key &key, std::shared_ptr contex if (loadDataInfo(context)) { Notify(key, context->currentUserId, node, context->calledSourceDir, context->version); } - it->isNotifyOnEnabled = false; } } return true; @@ -225,17 +224,22 @@ void RdbSubscriberManager::Emit(const std::string &uri, std::shared_ptr return false; } Notify(key, context->currentUserId, val, context->calledSourceDir, context->version); - for (auto &node : val) { - if (!node.enabled) { - node.isNotifyOnEnabled = true; - } - } + SetObserverNotifyOnEnabled(val); return false; }); SchedulerManager::GetInstance().Execute( uri, context->currentUserId, context->calledSourceDir, context->version); } +void RdbSubscriberManager::SetObserverNotifyOnEnabled(std::vector &nodes) +{ + for (auto &node : nodes) { + if (!node.enabled) { + node.isNotifyOnEnabled = true; + } + } +} + std::vector RdbSubscriberManager::GetKeysByUri(const std::string &uri) { std::vector results; @@ -256,11 +260,7 @@ void RdbSubscriberManager::EmitByKey(const Key &key, int32_t userId, const std:: } rdbCache_.ComputeIfPresent(key, [&rdbPath, &version, &userId, this](const Key &key, auto &val) { Notify(key, userId, val, rdbPath, version); - for (auto &node : val) { - if (!node.enabled) { - node.isNotifyOnEnabled = true; - } - } + SetObserverNotifyOnEnabled(val); return true; }); } diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h index 1cab6fe6..a0636dd0 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.h @@ -77,6 +77,7 @@ private: int Notify(const Key &key, int32_t userId, const std::vector &val, const std::string &rdbDir, int rdbVersion); int GetEnableObserverCount(const Key &key); + void SetObserverNotifyOnEnabled(std::vector &nodes); }; } // namespace OHOS::DataShare #endif -- Gitee