From f72167eb43edbed994a52354728aaa3706942fdf Mon Sep 17 00:00:00 2001 From: htt1997 Date: Thu, 11 May 2023 16:42:40 +0800 Subject: [PATCH] update Signed-off-by: htt1997 --- .../src/account_delegate_default_impl.cpp | 2 +- .../src/account_delegate_normal_impl.cpp | 2 +- .../framework/include/store/auto_cache.h | 2 +- .../framework/store/auto_cache.cpp | 2 +- .../service/cloud/cloud_service_impl.cpp | 6 +++- .../service/cloud/cloud_syncer.cpp | 28 ----------------- .../service/cloud/cloud_syncer.h | 30 ------------------- .../service/rdb/rdb_service_impl.cpp | 5 ++-- .../service/test/BUILD.gn | 1 + .../service/test/cloud_data_test.cpp | 22 +++++++++----- mock/src/mock_ipc.cpp | 9 ++++++ .../frameworks/js/napi/cloud_data/BUILD.gn | 28 +++++++++-------- .../native/rdb/src/rdb_store_impl.cpp | 19 +++++------- 13 files changed, 59 insertions(+), 97 deletions(-) delete mode 100644 datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.cpp delete mode 100644 datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.h diff --git a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.cpp b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.cpp index 70c3a4b6..5aa2f4d2 100644 --- a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.cpp +++ b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_default_impl.cpp @@ -23,7 +23,7 @@ namespace { constexpr const char *DEFAULT_OHOS_ACCOUNT_UID = ""; // default UID } -AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateDefaultImpl::GetBaseInstance; +//AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateDefaultImpl::GetBaseInstance; AccountDelegate *AccountDelegateDefaultImpl::GetBaseInstance() { static AccountDelegateDefaultImpl accountDelegate; diff --git a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp index 940fd4c2..152b38ad 100644 --- a/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp +++ b/datamgr_service/services/distributeddataservice/adapter/account/src/account_delegate_normal_impl.cpp @@ -32,7 +32,7 @@ using namespace OHOS::EventFwk; using namespace OHOS::AAFwk; using namespace OHOS::DistributedData; using namespace Security::AccessToken; -// AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateNormalImpl::GetBaseInstance; + AccountDelegate::BaseInstance AccountDelegate::getInstance_ = AccountDelegateNormalImpl::GetBaseInstance; AccountDelegate *AccountDelegateNormalImpl::GetBaseInstance() { static AccountDelegateNormalImpl accountDelegate; diff --git a/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h b/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h index 3522dfb5..11c3a117 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp b/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp index bb22477f..37aff132 100644 --- a/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp index 083c86b9..97f694e2 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/datamgr_service/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" @@ -76,6 +75,10 @@ CloudServiceImpl::CloudServiceImpl() 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) { @@ -90,6 +93,7 @@ CloudServiceImpl::CloudServiceImpl() if (cloudDB != nullptr) { store->Bind(cloudDB); } + executor_->Execute(GetCloudTask(RETRY_TIMES)); // do sync } return; diff --git a/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.cpp b/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.cpp deleted file mode 100644 index f920c5ec..00000000 --- a/datamgr_service/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/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.h b/datamgr_service/services/distributeddataservice/service/cloud/cloud_syncer.h deleted file mode 100644 index c9dd7971..00000000 --- a/datamgr_service/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/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index 0a05e19d..71a73d97 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -478,7 +478,7 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) auto storeMeta = GetStoreMetaData(param); StoreMetaData oldMeta; - bool isCreated = MetaDataManager::GetInstance().LoadMeta(storeMeta.GetKey(), oldMeta, true); + bool isCreated = MetaDataManager::GetInstance().LoadMeta(storeMeta.GetKey(), oldMeta); if (isCreated && (oldMeta.storeType != storeMeta.storeType || Constant::NotEqual(oldMeta.isEncrypt, storeMeta.isEncrypt) || oldMeta.area != storeMeta.area)) { @@ -488,8 +488,7 @@ int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) oldMeta.isEncrypt, storeMeta.isEncrypt, oldMeta.area, storeMeta.area); return RDB_ERROR; } - auto saved = MetaDataManager::GetInstance().SaveMeta(storeMeta.GetKey(), storeMeta, true); - if (!saved) { + if (!MetaDataManager::GetInstance().SaveMeta(storeMeta.GetKey(), storeMeta)) { return RDB_ERROR; } CloudEvent::StoreInfo storeInfo { IPCSkeleton::GetCallingTokenID(), param.bundleName_, param.storeName_, diff --git a/datamgr_service/services/distributeddataservice/service/test/BUILD.gn b/datamgr_service/services/distributeddataservice/service/test/BUILD.gn index 0c5173a0..cb562215 100644 --- a/datamgr_service/services/distributeddataservice/service/test/BUILD.gn +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp index 62dc043e..031ea345 100644 --- a/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -27,14 +27,16 @@ #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"; - class CloudDataTest : public testing::Test { public: static void SetUpTestCase(void); @@ -45,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_; @@ -114,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; @@ -134,6 +135,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() {} @@ -145,14 +147,15 @@ 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; storeMetaData.isAutoSync = true; - storeMetaData.storeType = 1; + 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); } @@ -169,14 +172,17 @@ 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( MetaDataManager::GetInstance().LoadMeta(cloudInfo.GetSchemaKey(TEST_CLOUD_BUNDLE), storeMetaData, true)); } +} // namespace DistributedDataTest +} // namespace OHOS diff --git a/mock/src/mock_ipc.cpp b/mock/src/mock_ipc.cpp index 5c8f16aa..18d285ca 100644 --- a/mock/src/mock_ipc.cpp +++ b/mock/src/mock_ipc.cpp @@ -120,6 +120,15 @@ uint32_t IPCSkeleton::GetCallingTokenID() params.aplStr = "distributed_test"; return GetAccessTokenId(¶ms); } + +uint64_t IPCSkeleton::GetSelfTokenID() +{ + NativeTokenInfoParams params{0}; + params.processName = "distributed_test"; + params.aplStr = "distributed_test"; + return GetAccessTokenId(¶ms); +} + MessageOption::MessageOption(int flags, int waitTime) {} void MessageOption::SetFlags(int flags) {} int MessageOption::GetFlags() const { return 0; } diff --git a/relational_store/frameworks/js/napi/cloud_data/BUILD.gn b/relational_store/frameworks/js/napi/cloud_data/BUILD.gn index 9aaddce9..2d309564 100644 --- a/relational_store/frameworks/js/napi/cloud_data/BUILD.gn +++ b/relational_store/frameworks/js/napi/cloud_data/BUILD.gn @@ -11,14 +11,22 @@ # See the License for the specific language governing permissions and # limitations under the License. import("//build/ohos.gni") +import("//build/ohos/ace/ace.gni") import("//foundation/distributeddatamgr/relational_store/relational_store.gni") +ohos_copy("relational_store_declaration") { + sources = [ "./api" ] + outputs = [ target_out_dir + "/$target_name/" ] + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" +} + config("cloud_data_config") { visibility = [ ":*" ] include_dirs = [ - "../../../../../kv_store/frameworks/common", "${cloud_data_native_path}/include", + "${kvstore_path}/common", "${relational_store_innerapi_path}/rdb/include", "${relational_store_innerapi_path}/cloud_data/include", "include", @@ -30,22 +38,17 @@ config("cloud_data_config") { ] } -base_sources = [ - "${cloud_data_native_path}/src/cloud_manager.cpp", - "${cloud_data_native_path}/src/cloud_service_proxy.cpp", -] - ohos_shared_library("cloud_data") { - part_name = "relational_store" - sources = base_sources - configs = [ ":cloud_data_config" ] deps = [] ldflags = [ "-Wl,--exclude-libs,ALL" ] cflags_cc = [ "-fvisibility=hidden" ] - sources += [] + sources = [ + "${cloud_data_native_path}/src/cloud_manager.cpp", + "${cloud_data_native_path}/src/cloud_service_proxy.cpp", + ] public_deps = [ "${relational_store_innerapi_path}/appdatafwk:native_appdatafwk" ] @@ -58,6 +61,7 @@ ohos_shared_library("cloud_data") { "samgr:samgr_proxy", ] - innerapi_tags = [ "platformsdk" ] subsystem_name = "distributeddatamgr" -} \ No newline at end of file + part_name = "relational_store" + relative_install_dir = "module/data" +} diff --git a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp index 8a5b3aa5..01273a65 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -90,26 +90,23 @@ int RdbStoreImpl::InnerOpen(const RdbStoreConfig &config) syncerParam_.password_ = {}; std::shared_ptr service = nullptr; - errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); + errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); if (errCode != E_OK) { LOG_ERROR("RdbStoreImpl::InnerOpen get service failed, err is %{public}d.", errCode); return E_OK; } - - errCode = service->GetSchema(syncerParam_); - if (errCode != E_OK) { - LOG_ERROR("RdbStoreImpl::InnerOpen GetSchema failed, err is %{public}d.", errCode); - return E_OK; - } - - // open uri share if (!config.GetUri().empty()) { errCode = service->CreateRDBTable(syncerParam_, config.GetWritePermission(), config.GetReadPermission()); if (errCode != E_OK) { LOG_ERROR("RdbStoreImpl::InnerOpen service CreateRDBTable failed"); - return E_OK; + } else { + isShared_ = true; } - isShared_ = true; + } + + errCode = service->GetSchema(syncerParam_); + if (errCode != E_OK) { + LOG_ERROR("RdbStoreImpl::InnerOpen GetSchema failed, err is %{public}d.", errCode); } #endif return E_OK; -- Gitee