diff --git a/datamgr_service/datamgr_service.gni b/datamgr_service/datamgr_service.gni index d1abd9afc053bc647945c6168a748edab1c67005..6ec402a19d78db68d0e97b6f7d131cf7793fb8c7 100644 --- a/datamgr_service/datamgr_service.gni +++ b/datamgr_service/datamgr_service.gni @@ -11,6 +11,21 @@ # See the License for the specific language governing permissions and # limitations under the License. +distributedfilejs_path = "//foundation/distributeddatamgr/distributedfile" + +kv_store_path = "//foundation/distributeddatamgr/kv_store" + +kv_store_common_path = "${kv_store_path}/frameworks/common" + +kv_store_distributeddb_path = "${kv_store_path}/frameworks/libs/distributeddb" + +dsoftbus_core_path = "//foundation/communication/dsoftbus/core/common/include" + +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/datamgr_service/services/distributeddataservice/app/src/feature_stub_impl.cpp b/datamgr_service/services/distributeddataservice/app/src/feature_stub_impl.cpp index 16876215e3e16455c655ebb5a28ea7c812c3f354..cbca54b07d9e129ab8dc8ddfd24d0ac0a466687b 100644 --- a/datamgr_service/services/distributeddataservice/app/src/feature_stub_impl.cpp +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/app/src/feature_stub_impl.h b/datamgr_service/services/distributeddataservice/app/src/feature_stub_impl.h index 6fc9c824b5960dd27f1001c66aee93ae0285e4bd..b00646bc0493d9ccf4d3f5464be2f975bea78458 100644 --- a/datamgr_service/services/distributeddataservice/app/src/feature_stub_impl.h +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.cpp b/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.cpp index ee5ef9e7b90aebcd78d88e1f1d143ab652da1c31..2e190156e753c652d128c972beab0587bc02f36d 100644 --- a/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.cpp +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.h b/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.h index fae1dbac481000ad378d095995a224e78cf46253..60aac3527556724b9411b49374563669d23072f7 100644 --- a/datamgr_service/services/distributeddataservice/app/src/kvstore_data_service.h +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp b/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp index 81072e469f43c694d6a6ddfd9457c4d238e79833..65ff559f27c4d4da25a64445808c7c3ff5511914 100644 --- a/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.cpp +++ b/datamgr_service/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:%s, user:%d, appIndex:%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,8 +87,11 @@ 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_REPLACED); CommonEventSubscribeInfo info(matchingSkills); - auto callback = [kvStoreDataService](const std::string &bundleName, int32_t userId, int32_t appIndex) { + + 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()); std::string prefix = StoreMetaData::GetPrefix({ DeviceManagerAdapter::GetInstance().GetLocalDevice().uuid, std::to_string(userId), "default", bundleName }); @@ -102,11 +108,33 @@ Status UninstallerImpl::Init(KvStoreDataService *kvStoreDataService, std::shared 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()); } } }; - auto subscriber = std::make_shared(info, callback); + + auto replacedCallback = [kvStoreDataService](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:%s, stordId:%s", bundleName.c_str(), meta.storeId.c_str()); + MetaDataManager::GetInstance().DelMeta(CloudInfo::GetSchemaKey(meta), true); + } + } + }; + + subscriber->RegisterCallback(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, removedCallback); + subscriber->RegisterCallback(OHOS::AppExecFwk::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED, removedCallback); + subscriber->RegisterCallback(CommonEventSupport::COMMON_EVENT_PACKAGE_REPLACED, replacedCallback); + subscriber_ = subscriber; executors_ = executors; executors_->Execute(GetTask()); diff --git a/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h b/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h index 50ec5fe33d53a09470fb5217b4bee88a1c70c9ef..07a026c83b21bbb5bae48013ab0489217e708356 100644 --- a/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h +++ b/datamgr_service/services/distributeddataservice/app/src/uninstaller/uninstaller_impl.h @@ -25,8 +25,8 @@ using UninstallEventCallback = std::function callbacks_; + }; class UninstallerImpl : public Uninstaller { public: diff --git a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_event.cpp b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_event.cpp index 0212fcc73edc89a35441af7eb30264369c2ea78e..11f43a392842af44ce70bcd7c2643dd231e7384b 100644 --- a/datamgr_service/services/distributeddataservice/framework/cloud/cloud_event.cpp +++ b/datamgr_service/services/distributeddataservice/framework/cloud/cloud_event.cpp @@ -16,15 +16,8 @@ #include "cloud/cloud_event.h" namespace OHOS::DistributedData { -CloudEvent::CloudEvent(int32_t evtId, uint32_t tokenId, const std::string &storeName, const std::string &bundleName, - const std::string &featureName, const std::string &schemaKey) - : Event(evtId), featureName_(featureName), tokenId_(tokenId), storeName_(storeName), bundleName_(bundleName), - schemaKey_(schemaKey) -{ -} -CloudEvent::CloudEvent(int32_t evtId, const CloudEvent &cloudEvent) - : Event(evtId), featureName_(cloudEvent.GetFeatureName()), tokenId_(cloudEvent.GetTokenId()), - storeName_(cloudEvent.GetStoreName()), bundleName_(cloudEvent.GetBundleName()) +CloudEvent::CloudEvent(int32_t evtId, CloudEvent::StoreInfo storeInfo, const std::string &featureName) + : Event(evtId), featureName_(featureName), storeInfo_(storeInfo) { } @@ -33,33 +26,8 @@ std::string CloudEvent::GetFeatureName() const return featureName_; } -void CloudEvent::SetSchemaKey(std::string schemaKey) -{ - schemaKey_ = schemaKey; -} - -std::string CloudEvent::GetSchemaKey() const -{ - return schemaKey_; -} - -std::string CloudEvent::GetBundleName() const -{ - return bundleName_; -} - -std::string CloudEvent::GetStoreName() const -{ - return storeName_; -} - -bool CloudEvent::Equals(const Event &event) const -{ - return false; -} - -uint32_t CloudEvent::GetTokenId() const +CloudEvent::StoreInfo CloudEvent::GetStoreInfo() const { - return tokenId_; + return storeInfo_; } } \ No newline at end of file diff --git a/datamgr_service/services/distributeddataservice/framework/feature/feature_system.cpp b/datamgr_service/services/distributeddataservice/framework/feature/feature_system.cpp index 6bfd3d23bc4499e55ff9ef411d7973ab9a3d27ff..49b69e8c0ec31c8b6731bc20700223a8f5edda60 100644 --- a/datamgr_service/services/distributeddataservice/framework/feature/feature_system.cpp +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_event.h b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_event.h index d39a83480b375d9cde2c59616c28023f2daa0701..e6cff13aa5498253250c83019e292b1d6924296f 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_event.h +++ b/datamgr_service/services/distributeddataservice/framework/include/cloud/cloud_event.h @@ -28,26 +28,22 @@ public: NEED_CREATE, CLOUD_BUTT }; - CloudEvent(int32_t evtId, uint32_t tokenId = 0, const std::string &storeName = "", - const std::string &bundleName = "", const std::string &featureName = "relational_store", - const std::string &schemaKey = ""); - CloudEvent(int32_t evtId, const CloudEvent &cloudEvent); + + struct StoreInfo { + uint32_t tokenId = 0; + std::string bundleName; + std::string storeName; + int32_t instanceId = 0; + }; + + CloudEvent(int32_t evtId, StoreInfo storeInfo, const std::string &featureName = "relational_store"); ~CloudEvent() = default; std::string GetFeatureName() const; - void SetSchemaKey(std::string bundleName); - std::string GetSchemaKey() const; - std::string GetBundleName() const; - std::string GetStoreName() const; - uint32_t GetTokenId() const; - bool Equals(const DistributedData::Event &event) const override; + StoreInfo GetStoreInfo() const; private: std::string featureName_; - uint32_t tokenId_; - std::string storeName_; - std::string bundleName_; - std::string schemaKey_; - + StoreInfo storeInfo_; }; } // namespace OHOS::DistributedData #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_CLOUD_EVENT_H diff --git a/datamgr_service/services/distributeddataservice/framework/include/feature/feature_system.h b/datamgr_service/services/distributeddataservice/framework/include/feature/feature_system.h index 8aa732cfd9e78e12367d24cbc0d1665cbed560b7..6bb345308c60e9b3529ab9f59e5ceb0b9b2cfebb 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/feature/feature_system.h +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h b/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h index 0dd4e15d6089f78ba53bf28ce32465323cea3749..3522dfb5dd1d2016a061b1b551c7c20a2c0ade35 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/store/auto_cache.h +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h b/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h index 56cdcf87abe2841a12b64b9172b339118f62babe..097f8d9a781842b620aee193a5ada94f049ab4ca 100644 --- a/datamgr_service/services/distributeddataservice/framework/include/store/general_store.h +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp b/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp index 11dedf24da3a4d7272da9978644b0997f1caa13c..bb22477f5c16e014432ea7ccad92e67a0851370f 100644 --- a/datamgr_service/services/distributeddataservice/framework/store/auto_cache.cpp +++ b/datamgr_service/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/datamgr_service/services/distributeddataservice/service/BUILD.gn b/datamgr_service/services/distributeddataservice/service/BUILD.gn index 1a7ecb5859d0abe2436b853857d4ca26d5becfee..81b76328ee39be1bc223703998e15d94ba5591ba 100644 --- a/datamgr_service/services/distributeddataservice/service/BUILD.gn +++ b/datamgr_service/services/distributeddataservice/service/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") group("build_module") { deps = [ ":distributeddatasvc" ] @@ -21,6 +22,7 @@ config("module_public_config") { include_dirs = [ "backup/include", "bootstrap/include", + "cloud", "config/include", "crypto/include", "data_share", @@ -53,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", ] sources = [ "backup/src/backup_manager.cpp", @@ -119,6 +121,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 = [ @@ -138,6 +141,7 @@ 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", 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 4ad57d2bcd6cdea9c925e7ea1b492f7bd3281c66..083c86b9794885135a08c7a1c51c9a8aaa9c4d8d 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.cpp @@ -37,7 +37,7 @@ using namespace DistributedData; using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; using Account = OHOS::DistributedKv::AccountDelegate; __attribute__((used)) CloudServiceImpl::Factory CloudServiceImpl::factory_; -CloudServiceImpl::Factory::Factory() +CloudServiceImpl::Factory::Factory() noexcept { FeatureSystem::GetInstance().RegisterCreator( CloudServiceImpl::SERVICE_NAME, @@ -57,7 +57,7 @@ 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.GetTokenId()); + cloudInfo.user = DistributedKv::AccountDelegate::GetInstance()->GetUserByToken(rdbEvent.GetStoreInfo().tokenId); if (GetServerInfo(cloudInfo) != SUCCESS) { ZLOGE("failed, user:%{public}d", cloudInfo.user); return; @@ -69,39 +69,35 @@ 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.GetTokenId()); - 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.GetBundleName()); - if (!MetaDataManager::GetInstance().LoadMeta(schemaKey, schemaMeta, true)) { - schemaMeta = instance->GetAppSchema(cloudInfo.user, rdbEvent.GetBundleName()); - MetaDataManager::GetInstance().SaveMeta(schemaKey, schemaMeta, true); - auto finishedEvent = std::make_unique(CloudEvent::NEED_CREATE, rdbEvent); - finishedEvent->SetSchemaKey(schemaKey); - EventCenter::GetInstance().PostEvent(move(finishedEvent)); - } - for (auto &database : schemaMeta.databases) { - if (database.name != rdbEvent.GetStoreName() /* ||TODO:不需要同步*/) { + if (database.name != rdbEvent.GetStoreInfo().storeName /* || don't need sync */) { continue; } - auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetTokenId(), database); - //TODO:同步 + auto cloudDB = instance->ConnectCloudDB(rdbEvent.GetStoreInfo().tokenId, database); + if (cloudDB != nullptr) { + store->Bind(cloudDB); + } + // do sync } + return; }); } int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map &switches) { - std::lock_guard lg(mutex_); CloudInfo cloudInfo; cloudInfo.id = id; if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { @@ -126,7 +122,6 @@ int32_t CloudServiceImpl::EnableCloud(const std::string &id, const std::map lg(mutex_); CloudInfo cloudInfo; cloudInfo.id = id; if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { @@ -141,7 +136,6 @@ int32_t CloudServiceImpl::DisableCloud(const std::string &id) int32_t CloudServiceImpl::ChangeAppSwitch(const std::string &id, const std::string &bundleName, int32_t appSwitch) { - std::lock_guard lg(mutex_); CloudInfo cloudInfo; cloudInfo.id = id; if (GetCloudInfo(cloudInfo) != SUCCESS && GetServerInfo(cloudInfo) != SUCCESS) { @@ -304,4 +298,38 @@ ExecutorPool::Task CloudServiceImpl::GetCloudTask(int32_t retry) executor_->Schedule(std::chrono::seconds(RETRY_INTERVAL), GetCloudTask(retry + 1)); }; } + +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/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h b/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h index 1d1c359283780a03d6ff1e9786735cdf7fb1ebdb..4556914084c62ade2fbb9bab13bce72fbd7129a4 100644 --- a/datamgr_service/services/distributeddataservice/service/cloud/cloud_service_impl.h +++ b/datamgr_service/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; @@ -37,7 +38,7 @@ public: private: class Factory { public: - Factory(); + Factory() noexcept; ~Factory(); private: std::shared_ptr product_; @@ -52,14 +53,15 @@ 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); std::string GetAppId(const std::string &bundleName); ExecutorPool::Task GetCloudTask(int32_t retry); bool CheckAccess(const std::string &bundleName); - std::mutex mutex_; - ConcurrentMap cloudInfos_; std::shared_ptr executor_; }; } // namespace OHOS::DistributedData diff --git a/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 086b280796189c0dcaa35cdadaed7d2fd726c2fb..1d252ce8c0b4837b82d094bae91c6f97387d506a 100644 --- a/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -46,7 +46,7 @@ using namespace OHOS::Security::AccessToken; using system_clock = std::chrono::system_clock; using DMAdapter = DistributedData::DeviceManagerAdapter; __attribute__((used)) KVDBServiceImpl::Factory KVDBServiceImpl::factory_; -KVDBServiceImpl::Factory::Factory() +KVDBServiceImpl::Factory::Factory() noexcept { FeatureSystem::GetInstance().RegisterCreator("kv_store", [this]() { if (product_ == nullptr) { diff --git a/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.h b/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.h index b1c3e5fd07d5bc8a27e90b74533842cd1d0a64b6..5267a0bd9ba9d1216dc563bd7488927b0a2f2e72 100644 --- a/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/kvdb/kvdb_service_impl.h @@ -84,7 +84,7 @@ private: }; class Factory { public: - Factory(); + Factory() noexcept; ~Factory(); private: std::shared_ptr product_; diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp index 2d4445172b40bc67feeda88602b30e13dad78c46..f69051cabade5c507f450aa3ba33605431bf3d96 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.cpp @@ -167,4 +167,10 @@ int32_t RdbGeneralStore::Unwatch(int32_t origin, Watcher &watcher) { return GeneralError::E_NOT_SUPPORT; } + +int32_t RdbGeneralStore::SetSchema(const SchemaMeta &schemaMeta) +{ + //SetSchema + return GeneralError::E_OK; +} } // namespace OHOS::DistributedRdb diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.h index f328986a961edaab34f39dbe87528d983df2891b..a77e7e33bc6d4568e0a1d07838309e19a440ed80 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_general_store.h @@ -32,13 +32,15 @@ public: using Value = DistributedData::Value; using Values = DistributedData::Values; using StoreMetaData = DistributedData::StoreMetaData; - using CloudDB = DistributedData::CloudDB; + using SchemaMeta = DistributedData::SchemaMeta; + 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); + 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; 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/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp index c4cb096805b3ad75db36f6dcc632cc5859be6771..0a05e19d6f19133a07e72e921afd821e4f4dbae4 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.cpp @@ -53,7 +53,7 @@ RdbServiceImpl::Factory::Factory() FeatureSystem::GetInstance().RegisterCreator(RdbServiceImpl::SERVICE_NAME, []() { return std::make_shared(); }); - AutoCache::GetInstance().RegCreator(RDB_DEVICE_COLLABORATION, [](const StoreMetaData &metaData) -> GeneralStore * { + AutoCache::GetInstance().RegCreator(RDB_DEVICE_COLLABORATION, [](const StoreMetaData &metaData) -> GeneralStore* { return new RdbGeneralStore(metaData); }); } @@ -88,16 +88,6 @@ RdbServiceImpl::RdbServiceImpl() : autoLaunchObserver_(this) [this](const std::string& identifier, DistributedDB::AutoLaunchParam ¶m) { return ResolveAutoLaunch(identifier, param); }); - - EventCenter::GetInstance().Subscribe(CloudEvent::NEED_CREATE, [this](const Event &event) { - auto &cloudEvent = static_cast(event); - if (cloudEvent.GetFeatureName() != "relation_store") { - return; - } - DistributedData::SchemaMeta schemaMeta; - MetaDataManager::GetInstance().LoadMeta(cloudEvent.GetSchemaKey(), schemaMeta); - //CreateDatabase(schemaMeta)TODO:根据schema创建表和trigger - }); } int32_t RdbServiceImpl::ResolveAutoLaunch(const std::string &identifier, DistributedDB::AutoLaunchParam ¶m) @@ -179,9 +169,9 @@ std::string RdbServiceImpl::ObtainDistributedTableName(const std::string &device return DistributedDB::RelationalStoreManager::GetDistributedTableName(uuid, table); } -int32_t RdbServiceImpl::InitNotifier(const std::string &bundleName, const sptr ¬ifier) +int32_t RdbServiceImpl::InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) { - if (!CheckAccess(bundleName, "")) { + if (!CheckAccess(param.bundleName_, "")) { ZLOGE("permission error"); return RDB_ERROR; } @@ -375,7 +365,7 @@ std::string RdbServiceImpl::GenIdentifier(const RdbSyncerParam ¶m) pid_t uid = IPCSkeleton::GetCallingUid(); uint32_t token = IPCSkeleton::GetCallingTokenID(); auto storeId = RdbSyncer::RemoveSuffix(param.storeName_); - CheckerManager::StoreInfo storeInfo{ uid, token, param.bundleName_, storeId }; + CheckerManager::StoreInfo storeInfo { uid, token, param.bundleName_, storeId }; auto userId = AccountDelegate::GetInstance()->GetUserByToken(token); std::string appId = CheckerManager::GetInstance().GetAppId(storeInfo); std::string identifier = RelationalStoreManager::GetRelationalStoreIdentifier( @@ -473,25 +463,84 @@ int32_t RdbServiceImpl::DestroyRDBTable(const RdbSyncerParam ¶m) int32_t RdbServiceImpl::OnInitialize() { - auto initEvt = std::make_unique(CloudEvent::FEATURE_INIT, CloudEvent(IPCSkeleton::GetCallingTokenID())); + 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 std::string &bundleName, const std::string &storeName) +int32_t RdbServiceImpl::GetSchema(const RdbSyncerParam ¶m) { - if (!CheckAccess(bundleName, storeName)) { + if (!CheckAccess(param.bundleName_, param.storeName_)) { ZLOGE("permission error"); return RDB_ERROR; } - auto event = std::make_unique(CloudEvent::GET_SCHEMA, IPCSkeleton::GetCallingTokenID(), - storeName, bundleName); - EventCenter::GetInstance().PostEvent(std::move(event)); + + 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 }; + 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; +} + int32_t RdbServiceImpl::OnExecutor(std::shared_ptr executors) { executors_ = std::move(executors); - return E_OK; + return RDB_OK; } } // namespace OHOS::DistributedRdb diff --git a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h index aa2d7615d5b4db8ab5470d9e82664ef2ad391fcb..89fcac3c94a4e13a617e831cbf972385cdae0e23 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_impl.h @@ -40,7 +40,7 @@ public: /* IPC interface */ std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; - int32_t InitNotifier(const std::string& bundleName, const sptr ¬ifier) override; + int32_t InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) override; int32_t SetDistributedTables(const RdbSyncerParam& param, const std::vector& tables) override; @@ -59,7 +59,7 @@ public: int32_t OnInitialize() override; - int32_t GetSchema(const std::string &bundleName, const std::string &storeName) override; + int32_t GetSchema(const RdbSyncerParam ¶m) override; protected: int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, @@ -83,6 +83,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/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp index 85e3719edcef38ee95bcd6735904a84fb99c8491..39fd62d4eaacea188f684bbf7afbd7c11b03a34b 100644 --- a/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp +++ b/datamgr_service/services/distributeddataservice/service/rdb/rdb_service_stub.cpp @@ -40,14 +40,15 @@ int32_t RdbServiceStub::OnRemoteObtainDistributedTableName(MessageParcel &data, return RDB_OK; } -int32_t RdbServiceStub::OnGetSchema(MessageParcel &data, MessageParcel &reply) { - std::string bundleName; - std::string storeName; - if (!ITypesUtil::Unmarshal(data, bundleName, storeName)) { - ZLOGE("Unmarshal bundleName_:%{public}s storeName_:%{public}s", bundleName.c_str(), storeName.c_str()); +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()); return IPC_STUB_INVALID_DATA_ERR; } - auto status = GetSchema(bundleName, storeName); + auto status = GetSchema(param); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; @@ -57,14 +58,14 @@ int32_t RdbServiceStub::OnGetSchema(MessageParcel &data, MessageParcel &reply) { int32_t RdbServiceStub::OnRemoteInitNotifier(MessageParcel &data, MessageParcel &reply) { - std::string bundleName; + RdbSyncerParam param; sptr notifier; - if (!ITypesUtil::Unmarshal(data, bundleName, notifier) || bundleName.empty() || notifier == nullptr) { - ZLOGE("Unmarshal bundleName:%{public}s notifier is nullptr:%{public}d", bundleName.c_str(), + 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(bundleName, notifier); + auto status = InitNotifier(param, notifier); if (!ITypesUtil::Marshal(reply, status)) { ZLOGE("Marshal status:0x%{public}x", status); return IPC_STUB_WRITE_PARCEL_ERR; diff --git a/datamgr_service/services/distributeddataservice/service/test/BUILD.gn b/datamgr_service/services/distributeddataservice/service/test/BUILD.gn index 70ad6fddbf99bd05d4b6dbd047e361a6af889c04..0c5173a09ccd333fe8535d53ca462d8233bbf70f 100644 --- a/datamgr_service/services/distributeddataservice/service/test/BUILD.gn +++ b/datamgr_service/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 = [ + "${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" ] @@ -146,6 +175,7 @@ group("unittest") { deps = [] deps += [ + ":CloudDataTest", ":ConfigFactoryTest", ":CryptoManagerTest", ":DeviceMatrixTest", diff --git a/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..62dc043e671eb6537f30834c0f4944e3238ef277 --- /dev/null +++ b/datamgr_service/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -0,0 +1,182 @@ +/* +* 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 "CloudDataTest" +#include +#include "log_print.h" +#include "ipc_skeleton.h" +#include "account/account_delegate.h" +#include "cloud/cloud_event.h" +#include "cloud/cloud_server.h" +#include "communicator/device_manager_adapter.h" +#include "device_matrix.h" +#include "eventcenter/event_center.h" +#include "feature/feature_system.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" +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 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; + 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; +}; + +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_BUNDLE; + 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_STORE; + database.alias = "test_cloud_database_alias"; + database.tables.emplace_back(table); + + SchemaMeta schemaMeta; + schemaMeta.version = 1; + schemaMeta.databases.emplace_back(database); + + return schemaMeta; +} + +std::shared_ptr CloudDataTest::dbStoreMock_ = std::make_shared(); + +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_.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 = -1; + storeMetaData.bundleName = TEST_CLOUD_BUNDLE; + storeMetaData.storeId = TEST_CLOUD_STORE; + storeMetaData.instanceId = 0; + 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() {} + +/** +* @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"); + 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 }; + 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/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.cpp b/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.cpp index 87639965c2b44870b3de0d12a3528b3a020bf1a4..e4f0f3b2438cbe1cf7ebd21cb783a41c0e35e882 100644 --- a/datamgr_service/services/distributeddataservice/service/test/mock/db_store_mock.cpp +++ b/datamgr_service/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; }); @@ -273,9 +273,9 @@ 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, {}); + 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); } diff --git a/mock/src/mock_notification.cpp b/mock/src/mock_notification.cpp index 0de94585646fa0a226c135953f88caa2a79c0a3b..d6f1beb87bb013e0baf20c763b56a18597b82d9e 100644 --- a/mock/src/mock_notification.cpp +++ b/mock/src/mock_notification.cpp @@ -192,6 +192,7 @@ const std::string CommonEventSupport::COMMON_EVENT_USER_REMOVED = "COMMON_EVENT_ const std::string CommonEventSupport::COMMON_EVENT_HWID_TOKEN_INVALID = "COMMON_EVENT_HWID_TOKEN_INVALID"; const std::string CommonEventSupport::COMMON_EVENT_HWID_LOGOUT = "COMMON_EVENT_HWID_LOGOUT"; const std::string CommonEventSupport::COMMON_EVENT_HWID_LOGIN = "COMMON_EVENT_HWID_LOGIN"; +const std::string CommonEventSupport::COMMON_EVENT_PACKAGE_REPLACED = "COMMON_EVENT_PACKAGE_REPLACED"; const std::string CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED = "COMMON_EVENT_PACKAGE_REMOVED"; const std::string CommonEventSupport::COMMON_EVENT_USER_SWITCHED = "COMMON_EVENT_USER_SWITCHED"; const std::string CommonEventSupport::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED = "COMMON_EVENT_SANDBOX_PACKAGE_REMOVED"; diff --git a/relational_store/bundle.json b/relational_store/bundle.json index 6b9df4d3c0078159d716b8b9c91076a088350a56..58e7097754e8f435cc16c23d28f1cf15840a4364 100644 --- a/relational_store/bundle.json +++ b/relational_store/bundle.json @@ -71,7 +71,7 @@ "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/dataability:native_dataability", "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb_data_share_adapter:rdb_data_share_adapter", "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb:native_rdb", - "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/cloud_data:cloud_data", + "//foundation/distributeddatamgr/relational_store/frameworks/js/napi/cloud_data:cloud_data", "//foundation/distributeddatamgr/relational_store/frameworks/js/napi/dataability:dataability", "//foundation/distributeddatamgr/relational_store/frameworks/js/napi/rdb:rdb", "//foundation/distributeddatamgr/relational_store/frameworks/js/napi/rdb:napi_rdb", @@ -137,16 +137,6 @@ ], "header_base": "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/rdb_data_ability_adapter/include" } - }, - { - "name": "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/cloud_data:cloud_data", - "header": { - "header_files": [ - "cloud_manager.h", - "cloud_service.h" - ], - "header_base": "//foundation/distributeddatamgr/relational_store/interfaces/inner_api/cloud_data/include" - } } ], "test": [ diff --git a/relational_store/frameworks/js/napi/cloud_data/BUILD.gn b/relational_store/frameworks/js/napi/cloud_data/BUILD.gn index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9aaddce9f11085cbf632ba3bb4bb710833c61928 100644 --- a/relational_store/frameworks/js/napi/cloud_data/BUILD.gn +++ b/relational_store/frameworks/js/napi/cloud_data/BUILD.gn @@ -0,0 +1,63 @@ +# 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("//foundation/distributeddatamgr/relational_store/relational_store.gni") + +config("cloud_data_config") { + visibility = [ ":*" ] + + include_dirs = [ + "../../../../../kv_store/frameworks/common", + "${cloud_data_native_path}/include", + "${relational_store_innerapi_path}/rdb/include", + "${relational_store_innerapi_path}/cloud_data/include", + "include", + ] + + defines = [ + "RELATIONAL_STORE", + "SQLITE_HAS_CODEC", + ] +} + +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 += [] + + public_deps = + [ "${relational_store_innerapi_path}/appdatafwk:native_appdatafwk" ] + + external_deps = [ + "c_utils:utils", + "hilog_native:libhilog", + "hitrace_native:hitrace_meter", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "distributeddatamgr" +} \ No newline at end of file diff --git a/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h b/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h index 7dec3bf806788cc32dbe148eb8f9380126c01794..b94c8032fe87478c6f5a92d0fbd0f8fb6981f24d 100644 --- a/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h +++ b/relational_store/frameworks/native/cloud_data/include/cloud_service_proxy.h @@ -21,7 +21,7 @@ #include "iremote_proxy.h" namespace OHOS::CloudData { -class CloudServiceProxy: public IRemoteProxy { +class CloudServiceProxy : public IRemoteProxy { public: explicit CloudServiceProxy(const sptr& object); virtual ~CloudServiceProxy() = default; diff --git a/relational_store/frameworks/native/rdb/include/rdb_manager_impl.h b/relational_store/frameworks/native/rdb/include/rdb_manager_impl.h index 22150516fcfb14105494405197585946659afc78..61b84c295000e440580df1edde8c6194e60025ef 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_manager_impl.h +++ b/relational_store/frameworks/native/rdb/include/rdb_manager_impl.h @@ -38,7 +38,7 @@ public: static RdbManagerImpl &GetInstance(); - int GetRdbService(const std::string& bundleName, std::shared_ptr &service); + int GetRdbService(const RdbSyncerParam ¶m, std::shared_ptr &service); void OnRemoteDied(); diff --git a/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h b/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h index 7dcab25edda032a5b90b5497dd80235a91e899be..6c7bc59d1e5061ea1c95f3a7ac1e622512e21730 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h +++ b/relational_store/frameworks/native/rdb/include/rdb_service_proxy.h @@ -33,8 +33,8 @@ public: std::string ObtainDistributedTableName(const std::string& device, const std::string& table) override; - int32_t InitNotifier(const std::string& bundleName); - int32_t InitNotifier(const std::string& bundleName, const sptr ¬ifier) override; + int32_t InitNotifier(const RdbSyncerParam ¶m); + int32_t InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) override; int32_t SetDistributedTables(const RdbSyncerParam& param, const std::vector& tables) override; @@ -57,8 +57,7 @@ public: void ImportObservers(ObserverMap& observers); /*CLoudData*/ - int32_t GetSchema(const std::string &bundleName, const std::string &storeName) override; - + int32_t GetSchema(const RdbSyncerParam ¶m) override; protected: int32_t DoSync(const RdbSyncerParam& param, const SyncOption& option, const RdbPredicates& predicates, SyncResult& result) override; diff --git a/relational_store/frameworks/native/rdb/include/rdb_types_util.h b/relational_store/frameworks/native/rdb/include/rdb_types_util.h index cb1be91c47980532e796fee39d3936238588cbe2..019b9ce416de9588ff3ba2e116983431c38e649f 100644 --- a/relational_store/frameworks/native/rdb/include/rdb_types_util.h +++ b/relational_store/frameworks/native/rdb/include/rdb_types_util.h @@ -23,7 +23,6 @@ namespace OHOS::ITypesUtil { using SyncerParam = DistributedRdb::RdbSyncerParam; using SyncOption = DistributedRdb::SyncOption; -using CloudParam = DistributedRdb::CloudParam; using RdbPredicates = DistributedRdb::RdbPredicates; using RdbOperation = DistributedRdb::RdbPredicateOperation; using ValueObject = NativeRdb::ValueObject; @@ -36,10 +35,6 @@ API_EXPORT bool Unmarshalling(SyncerParam &output, MessageParcel &data); template<> API_EXPORT bool Marshalling(const SyncOption &input, MessageParcel &data); template<> -API_EXPORT bool Marshalling(const CloudParam &input, MessageParcel &data); -template<> -API_EXPORT bool Unmarshalling(CloudParam &output, MessageParcel &data); -template<> API_EXPORT bool Unmarshalling(SyncOption &output, MessageParcel &data); template<> API_EXPORT bool Marshalling(const RdbPredicates &input, MessageParcel &data); diff --git a/relational_store/frameworks/native/rdb/src/rdb_manager_impl.cpp b/relational_store/frameworks/native/rdb/src/rdb_manager_impl.cpp index 0e38609fbdb466a0dc4adbe514ad31391ffaf639..d7321f9253f99b8aa73840622cb7f8a2def9171c 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_manager_impl.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_manager_impl.cpp @@ -80,7 +80,7 @@ RdbManagerImpl& RdbManagerImpl::GetInstance() return manager; } -int RdbManagerImpl::GetRdbService(const std::string& bundleName, std::shared_ptr &service) +int RdbManagerImpl::GetRdbService(const RdbSyncerParam ¶m, std::shared_ptr &service) { std::lock_guard lock(mutex_); if (rdbService_ != nullptr) { @@ -101,7 +101,7 @@ int RdbManagerImpl::GetRdbService(const std::string& bundleName, std::shared_ptr return E_NOT_SUPPORTED; } sptr serviceProxy = iface_cast(remote); - if (serviceProxy->InitNotifier(bundleName) != RDB_OK) { + if (serviceProxy->InitNotifier(param) != RDB_OK) { ZLOGE("init notifier failed"); return E_ERROR; } @@ -111,7 +111,7 @@ int RdbManagerImpl::GetRdbService(const std::string& bundleName, std::shared_ptr if (rdbService_ == nullptr) { return E_ERROR; } - bundleName_ = bundleName; + bundleName_ = param.bundleName_; service = rdbService_; return E_OK; } @@ -131,7 +131,7 @@ void RdbManagerImpl::OnRemoteDied() RdbSyncerParam param; param.bundleName_ = bundleName_; std::shared_ptr service = nullptr; - int errCode = GetRdbService(bundleName_, service); + int errCode = GetRdbService(param, service); if (errCode != E_OK) { return; } diff --git a/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp b/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp index 42bfe9a94f18ebfae50d0e5d4e9ea38e42905603..fa87c474e0b2cc045f10be994dd4d1d08e47873f 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_service_proxy.cpp @@ -83,19 +83,22 @@ std::string RdbServiceProxy::ObtainDistributedTableName(const std::string &devic return reply.ReadString(); } -int32_t RdbServiceProxy::InitNotifier(const std::string &bundleName) +int32_t RdbServiceProxy::InitNotifier(const RdbSyncerParam ¶m) { - notifier_ = new (std::nothrow) - RdbNotifierStub([this](uint32_t seqNum, const SyncResult &result) { OnSyncComplete(seqNum, result); }, - [this](const std::string &storeName, const std::vector &devices) { - OnDataChange(storeName, devices); - }); + notifier_ = new (std::nothrow) RdbNotifierStub( + [this] (uint32_t seqNum, const SyncResult& result) { + OnSyncComplete(seqNum, result); + }, + [this] (const std::string& storeName, const std::vector& devices) { + OnDataChange(storeName, devices); + } + ); if (notifier_ == nullptr) { ZLOGE("create notifier failed"); return RDB_ERROR; } - if (InitNotifier(bundleName, notifier_->AsObject().GetRefPtr()) != RDB_OK) { + if (InitNotifier(param, notifier_->AsObject().GetRefPtr()) != RDB_OK) { notifier_ = nullptr; return RDB_ERROR; } @@ -104,12 +107,12 @@ int32_t RdbServiceProxy::InitNotifier(const std::string &bundleName) return RDB_OK; } -int32_t RdbServiceProxy::InitNotifier(const std::string& bundleName, const sptr ¬ifier) +int32_t RdbServiceProxy::InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) { MessageParcel reply; - int32_t status = IPC_SEND(RDB_SERVICE_CMD_INIT_NOTIFIER, reply, bundleName, notifier); + int32_t status = IPC_SEND(RDB_SERVICE_CMD_INIT_NOTIFIER, reply, param, notifier); if (status != RDB_OK) { - ZLOGE("status:%{public}d, bundleName:%{public}s", status, bundleName.c_str()); + ZLOGE("status:%{public}d, bundleName:%{public}s", status, param.bundleName_.c_str()); } return status; } @@ -339,13 +342,13 @@ int32_t RdbServiceProxy::DestroyRDBTable(const RdbSyncerParam ¶m) return status; } -int32_t RdbServiceProxy::GetSchema(const std::string &bundleName, const std::string &storeName) +int32_t RdbServiceProxy::GetSchema(const RdbSyncerParam ¶m) { MessageParcel reply; - int32_t status = IPC_SEND(RDB_SERVICE_CMD_GET_SCHEMA, reply, bundleName, storeName); + int32_t status = IPC_SEND(RDB_SERVICE_CMD_GET_SCHEMA, reply, param); if (status != RDB_OK) { - ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", status, bundleName.c_str(), - storeName.c_str()); + ZLOGE("status:%{public}d, bundleName:%{public}s, storeName:%{public}s", status, param.bundleName_.c_str(), + param.storeName_.c_str()); } return status; } 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 2c63d00c95feed5729bfa7bd503d6497aad30683..8a5b3aa578cb1dc9c8aea5bc2148336b032d965f 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_store_impl.cpp @@ -90,13 +90,13 @@ int RdbStoreImpl::InnerOpen(const RdbStoreConfig &config) syncerParam_.password_ = {}; std::shared_ptr service = nullptr; - errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(config.GetBundleName(), 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(config.GetBundleName(), config.GetName()); + errCode = service->GetSchema(syncerParam_); if (errCode != E_OK) { LOG_ERROR("RdbStoreImpl::InnerOpen GetSchema failed, err is %{public}d.", errCode); return E_OK; @@ -127,7 +127,7 @@ RdbStoreImpl::~RdbStoreImpl() #if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM) if (isShared_) { std::shared_ptr service = nullptr; - int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_.bundleName_, service); + int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); if (errCode != E_OK) { LOG_ERROR("RdbStoreImpl::~RdbStoreImpl get service failed"); return; @@ -432,7 +432,7 @@ std::shared_ptr RdbStoreImpl::RemoteQuery(const std::string &device, std::vector selectionArgs = predicates.GetWhereArgs(); std::string sql = SqliteSqlBuilder::BuildQueryString(predicates, columns); std::shared_ptr service = nullptr; - errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_.bundleName_, service); + errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); if (errCode != E_OK) { LOG_ERROR("RdbStoreImpl::RemoteQuery get service failed"); return nullptr; @@ -1139,7 +1139,7 @@ int RdbStoreImpl::SetDistributedTables(const std::vector &tables) } std::shared_ptr service = nullptr; - int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_.bundleName_, service); + int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); if (errCode != E_OK) { return errCode; } @@ -1185,7 +1185,7 @@ int RdbStoreImpl::Sync(const SyncOption &option, const AbsRdbPredicates &predica { DISTRIBUTED_DATA_HITRACE(std::string(__FUNCTION__)); std::shared_ptr service = nullptr; - int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_.bundleName_, service); + int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); if (errCode != E_OK) { LOG_ERROR("GetRdbService is failed, err is %{public}d.", errCode); return errCode; @@ -1201,7 +1201,7 @@ int RdbStoreImpl::Sync(const SyncOption &option, const AbsRdbPredicates &predica int RdbStoreImpl::Subscribe(const SubscribeOption &option, RdbStoreObserver *observer) { std::shared_ptr service = nullptr; - int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_.bundleName_, service); + int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); if (errCode != E_OK) { return errCode; } @@ -1212,7 +1212,7 @@ int RdbStoreImpl::UnSubscribe(const SubscribeOption &option, RdbStoreObserver *o { LOG_INFO("enter"); std::shared_ptr service = nullptr; - int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_.bundleName_, service); + int errCode = DistributedRdb::RdbManagerImpl::GetInstance().GetRdbService(syncerParam_, service); if (errCode != E_OK) { return errCode; } diff --git a/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp b/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp index 08d639607e53d4f3ea943d25ee2f9937406036cb..444ba037956af7a223bee4851ea976dd2e895204 100644 --- a/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp +++ b/relational_store/frameworks/native/rdb/src/rdb_types_util.cpp @@ -28,17 +28,6 @@ bool Unmarshalling(SyncerParam &output, MessageParcel &data) output.level_, output.type_, output.isAutoSync_, output.isEncrypt_, output.password_); } -template<> -bool Marshalling(const CloudParam &input, MessageParcel &data) -{ - return ITypesUtil::Marshal(data, input.bundleName, input.storeName); -} -template<> -bool Unmarshalling(CloudParam &output, MessageParcel &data) -{ - return ITypesUtil::Unmarshal(data, output.bundleName, output.storeName); -} - template<> bool Marshalling(const SyncOption &input, MessageParcel &data) { diff --git a/relational_store/interfaces/inner_api/cloud_data/BUILD.gn b/relational_store/interfaces/inner_api/cloud_data/BUILD.gn index 8c07306ecb6c3e61eb48c2802400e0bec4877b8f..2a9adf45c71167a2cff9ea4a3ee8be08357a2d87 100644 --- a/relational_store/interfaces/inner_api/cloud_data/BUILD.gn +++ b/relational_store/interfaces/inner_api/cloud_data/BUILD.gn @@ -13,8 +13,10 @@ import("//build/ohos.gni") import("//foundation/distributeddatamgr/relational_store/relational_store.gni") config("cloud_public_config") { - visibility = [ "//foundation/distributeddatamgr/datamgr_service:*" ] - visibility = [ "//foundation/distributeddatamgr/relational_store:*" ] + visibility = [ + "../../../../datamgr_service/*", + "../../../../relational_store/*" + ] include_dirs = [ "include", diff --git a/relational_store/interfaces/inner_api/rdb/include/rdb_service.h b/relational_store/interfaces/inner_api/rdb/include/rdb_service.h index 9cef9274d502823d79245eb847220df5f03bcfa9..fc8f6ed33cf6cf6f69a2517a2a1eeb5e739dce6e 100644 --- a/relational_store/interfaces/inner_api/rdb/include/rdb_service.h +++ b/relational_store/interfaces/inner_api/rdb/include/rdb_service.h @@ -55,14 +55,15 @@ public: virtual int32_t RemoteQuery(const RdbSyncerParam ¶m, const std::string &device, const std::string &sql, const std::vector &selectionArgs, sptr &resultSet) = 0; + virtual int32_t CreateRDBTable(const RdbSyncerParam ¶m, const std::string &writePermission, const std::string &readPermission) = 0; virtual int32_t DestroyRDBTable(const RdbSyncerParam ¶m) = 0; - virtual int32_t InitNotifier(const std::string& bundleName, const sptr ¬ifier) = 0; + virtual int32_t InitNotifier(const RdbSyncerParam ¶m, const sptr notifier) = 0; - virtual int32_t GetSchema(const std::string &bundleName, const std::string &storeName) = 0; + virtual int32_t GetSchema(const RdbSyncerParam ¶m) = 0; static constexpr const char *SERVICE_NAME = "relational_store"; protected: diff --git a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h index 291c648436fb3e20570a20531fabf5c4ddcf4e82..ed0d372f80ffefc4b76f7981122d4220007fc16e 100644 --- a/relational_store/interfaces/inner_api/rdb/include/rdb_types.h +++ b/relational_store/interfaces/inner_api/rdb/include/rdb_types.h @@ -48,13 +48,6 @@ struct RdbSyncerParam { }; }; -struct CloudParam { - std::string bundleName; - std::string storeName; - std::string cloudId; -// int32_t schemaVerion; -}; - enum SyncMode { PUSH, PULL, diff --git a/relational_store/relational_store.gni b/relational_store/relational_store.gni index 442ce6d8aa61e3b9a5d9188144ea65757d2cc201..0b286407aa0a428d9133a195745d13b31991fb06 100644 --- a/relational_store/relational_store.gni +++ b/relational_store/relational_store.gni @@ -27,4 +27,5 @@ relational_store_native_path = "${relational_store_base_path}/frameworks/native" relational_store_innerapi_path = "${relational_store_base_path}/interfaces/inner_api" -cloud_data_native_path = "${relational_store_base_path}/frameworks/native/cloud_data" \ No newline at end of file +cloud_data_native_path = + "${relational_store_base_path}/frameworks/native/cloud_data"