diff --git a/datamgr_service.gni b/datamgr_service.gni index da3e7a494d5e4474f2f5e30387cab6d3a8465cfd..d54e7572e24f9971f637a779fad486a3aaf122bd 100644 --- a/datamgr_service.gni +++ b/datamgr_service.gni @@ -64,5 +64,7 @@ declare_args() { datamgr_service_object = true + datamgr_service_object_asset = true + datamgr_service_data_share = true } diff --git a/services/distributeddataservice/service/object/BUILD.gn b/services/distributeddataservice/service/object/BUILD.gn index 29056fe07bb32af5805190b0fc8ad429f53572cd..464f969b700a56f731004ceb7ae81c2078682ef5 100644 --- a/services/distributeddataservice/service/object/BUILD.gn +++ b/services/distributeddataservice/service/object/BUILD.gn @@ -34,7 +34,7 @@ ohos_source_set("distributeddata_object") { } sources = [ - "src/object_asset_loader.cpp", + "src/object_asset_delegate.cpp", "src/object_asset_machine.cpp", "src/object_callback_proxy.cpp", "src/object_data_listener.cpp", @@ -74,14 +74,24 @@ ohos_source_set("distributeddata_object") { external_deps = [ "access_token:libtokenid_sdk", "data_object:data_object_inner", - "dfs_service:cloudsync_asset_kit_inner", - "dfs_service:distributed_file_daemon_kit_inner", + "device_manager:devicemanagersdk", "dmsfwk:distributed_sdk", + "hilog:libhilog", "hisysevent:libhisysevent", "kv_store:datamgr_common", "kv_store:distributeddb", ] + if (datamgr_service_object_asset) { + sources += [ "src/object_asset_delegate_normal_impl.cpp" ] + external_deps += [ + "dfs_service:cloudsync_asset_kit_inner", + "dfs_service:distributed_file_daemon_kit_inner", + ] + } else { + sources += [ "src/object_asset_delegate_default_impl.cpp" ] + } + subsystem_name = "distributeddatamgr" part_name = "datamgr_service" } diff --git a/services/distributeddataservice/service/object/include/object_asset_delegate.h b/services/distributeddataservice/service/object/include/object_asset_delegate.h new file mode 100644 index 0000000000000000000000000000000000000000..5e34ad066e17c600828a9c054412ace4ef10ec5c --- /dev/null +++ b/services/distributeddataservice/service/object/include/object_asset_delegate.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_H +#define DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_H + +#include "executor_pool.h" +#include "store/general_value.h" + +namespace OHOS { +namespace DistributedObject { +using TransferFunc = std::function; +class ObjectAssetDelegate { +public: + static bool RegisterInstance(ObjectAssetDelegate *instance); + static ObjectAssetDelegate *GetInstance(); + virtual bool RegisterAssetsListener(); + virtual bool UnRegisterAssetsListener(); + virtual bool SetThreadPool(std::shared_ptr executors); + virtual int32_t PushAsset(const std::string &sessionId, const std::string &dstNetworkId, + const std::string &srcBundleName, const std::string &dstBundleName, const std::vector &uris); + virtual void TransferAssetsAsync(const int32_t userId, const std::string &bundleName, const std::string &deviceId, + const std::vector &assets, const TransferFunc &callback); + +private: + static ObjectAssetDelegate *instance_; +}; +} // namespace DistributedObject +} // namespace OHOS +#endif // DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_H diff --git a/services/distributeddataservice/service/object/include/object_asset_delegate_default_impl.h b/services/distributeddataservice/service/object/include/object_asset_delegate_default_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..02b1b80ef60b63dd69708100c69bad7a8ad7c152 --- /dev/null +++ b/services/distributeddataservice/service/object/include/object_asset_delegate_default_impl.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_DEFAULT_IMPL_H +#define DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_DEFAULT_IMPL_H + +#include "object_asset_delegate.h" + +namespace OHOS { +namespace DistributedObject { +class ObjectAssetDelegateDefaultImpl final : public ObjectAssetDelegate { +public: + static bool Init(); + bool RegisterAssetsListener() override; + bool UnRegisterAssetsListener() override; + bool SetThreadPool(std::shared_ptr executors) override; + int32_t PushAsset(const std::string &sessionId, const std::string &dstNetworkId, const std::string &srcBundleName, + const std::string &dstBundleName, const std::vector &uris) override; + void TransferAssetsAsync(const int32_t userId, const std::string &bundleName, const std::string &deviceId, + const std::vector &assets, const TransferFunc &callback) override; +}; +} // namespace DistributedObject +} // namespace OHOS +#endif // DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_DEFAULT_IMPL_H diff --git a/services/distributeddataservice/service/object/include/object_asset_loader.h b/services/distributeddataservice/service/object/include/object_asset_delegate_normal_impl.h similarity index 47% rename from services/distributeddataservice/service/object/include/object_asset_loader.h rename to services/distributeddataservice/service/object/include/object_asset_delegate_normal_impl.h index 44d3f8ab0f8d155c60d0697234b2d525408906eb..6407226693477a47d0ee351c41b55e5425c9f444 100644 --- a/services/distributeddataservice/service/object/include/object_asset_loader.h +++ b/services/distributeddataservice/service/object/include/object_asset_delegate_normal_impl.h @@ -12,52 +12,63 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef DISTRIBUTEDDATAMGR_OBJECT_ASSET_LOADER_H -#define DISTRIBUTEDDATAMGR_OBJECT_ASSET_LOADER_H +#ifndef DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_NORMAL_IMPL_H +#define DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_NORMAL_IMPL_H + +#include "object_asset_delegate.h" -#include -#include "executor_pool.h" -#include "object_types.h" -#include "store/general_value.h" -#include "concurrent_map.h" #include + +#include "asset/asset_recv_callback_stub.h" #include "asset/asset_send_callback_stub.h" +#include "concurrent_map.h" +#include "object_types.h" +#include "store/general_value.h" + namespace OHOS { namespace DistributedObject { using AssetObj = Storage::DistributedFile::AssetObj; -using TransferFunc = std::function; struct TransferTask { TransferTask() = default; std::unordered_set downloadAssets; TransferFunc callback; }; +class ObjectAssetsRecvListener : public Storage::DistributedFile::AssetRecvCallbackStub { +public: + ObjectAssetsRecvListener() = default; + ~ObjectAssetsRecvListener() = default; + int32_t OnStart(const std::string &srcNetworkId, const std::string &dstNetworkId, const std::string &sessionId, + const std::string &dstBundleName) override; + int32_t OnFinished(const std::string &srcNetworkId, const sptr &assetObj, int32_t result) override; +}; + class ObjectAssetsSendListener : public Storage::DistributedFile::AssetSendCallbackStub { public: - ObjectAssetsSendListener() =default; + ObjectAssetsSendListener() = default; ~ObjectAssetsSendListener() = default; int32_t OnSendResult(const sptr &assetObj, int32_t result) override; }; -class ObjectAssetLoader { +class ObjectAssetDelegateNormalImpl final : public ObjectAssetDelegate { public: - static ObjectAssetLoader *GetInstance(); - void SetThreadPool(std::shared_ptr executors); - bool Transfer(const int32_t userId, const std::string& bundleName, const std::string& deviceId, - const DistributedData::Asset& asset); - void TransferAssetsAsync(const int32_t userId, const std::string& bundleName, const std::string& deviceId, - const std::vector& assets, const TransferFunc& callback); - int32_t PushAsset(int32_t userId, const sptr &assetObj, - const sptr &sendCallback); + static bool Init(); + bool SetThreadPool(std::shared_ptr executors) override; + void TransferAssetsAsync(const int32_t userId, const std::string &bundleName, const std::string &deviceId, + const std::vector &assets, const TransferFunc &callback) override; + int32_t PushAsset(const std::string &sessionId, const std::string &dstNetworkId, const std::string &srcBundleName, + const std::string &dstBundleName, const std::vector &uris) override; + bool RegisterAssetsListener() override; + bool UnRegisterAssetsListener() override; + private: - ObjectAssetLoader() = default; - ~ObjectAssetLoader() = default; - ObjectAssetLoader(const ObjectAssetLoader &) = delete; - ObjectAssetLoader &operator=(const ObjectAssetLoader &) = delete; - void FinishTask(const std::string& uri, bool result); - bool IsDownloading(const DistributedData::Asset& asset); - bool IsDownloaded(const DistributedData::Asset& asset); - void UpdateDownloaded(const DistributedData::Asset& asset); + bool Transfer(const int32_t userId, const std::string &bundleName, const std::string &deviceId, + const DistributedData::Asset &asset); + void FinishTask(const std::string &uri, bool result); + bool IsDownloading(const DistributedData::Asset &asset); + bool IsDownloaded(const DistributedData::Asset &asset); + void UpdateDownloaded(const DistributedData::Asset &asset); + int32_t GetCurrentUser(); static constexpr int WAIT_TIME = 60; static constexpr int LAST_DOWNLOAD_ASSET_SIZE = 200; std::shared_ptr executors_; @@ -67,7 +78,9 @@ private: ConcurrentMap tasks_; ConcurrentMap downloaded_; ConcurrentMap downloading_; + sptr assetsRecvListener_ = nullptr; + sptr assetsSendListener_ = nullptr; }; } // namespace DistributedObject } // namespace OHOS -#endif // DISTRIBUTEDDATAMGR_OBJECT_ASSET_LOADER_H \ No newline at end of file +#endif // DISTRIBUTEDDATAMGR_OBJECT_ASSET_DELEGATE_NORMAL_IMPL_H diff --git a/services/distributeddataservice/service/object/include/object_data_listener.h b/services/distributeddataservice/service/object/include/object_data_listener.h index 3c1bfdea0dee7cf4dfb4303b42b3b5f2684d64a6..a50bc390f905fc7856c33915c4210bdb30ed3826 100644 --- a/services/distributeddataservice/service/object/include/object_data_listener.h +++ b/services/distributeddataservice/service/object/include/object_data_listener.h @@ -17,10 +17,9 @@ #define DISTRIBUTEDDATAMGR_OBJECT_DATA_LISTENER_H #include "kv_store_observer.h" -#include "asset/asset_recv_callback_stub.h" + namespace OHOS { namespace DistributedObject { -using AssetObj = Storage::DistributedFile::AssetObj; class ObjectDataListener : public DistributedDB::KvStoreObserver { public: ObjectDataListener(); @@ -28,17 +27,6 @@ public: // Database change callback void OnChange(const DistributedDB::KvStoreChangedData &data) override; }; - -class ObjectAssetsRecvListener : public Storage::DistributedFile::AssetRecvCallbackStub { -public: - ObjectAssetsRecvListener() =default; - ~ObjectAssetsRecvListener() =default; - int32_t OnStart(const std::string &srcNetworkId, - const std::string &dstNetworkId, const std::string &sessionId, - const std::string &dstBundleName) override; - int32_t OnFinished(const std::string &srcNetworkId, - const sptr &assetObj, int32_t result) override; -}; } // namespace DistributedObject } // namespace OHOS #endif // DISTRIBUTEDDATAMGR_OBJECT_DATA_LISTENER_H diff --git a/services/distributeddataservice/service/object/include/object_manager.h b/services/distributeddataservice/service/object/include/object_manager.h index 2f4f6302c177cd23197b245ffd2e8a056d3cfdc5..d0dbef2363f0be218f2769ca79f8d4c563228fe1 100644 --- a/services/distributeddataservice/service/object/include/object_manager.h +++ b/services/distributeddataservice/service/object/include/object_manager.h @@ -21,7 +21,6 @@ #include "device_manager_adapter.h" #include "kv_store_delegate_manager.h" #include "kvstore_sync_callback.h" -#include "object_asset_loader.h" #include "object_callback.h" #include "object_callback_proxy.h" #include "object_common.h" @@ -171,7 +170,6 @@ private: static bool IsAssetKey(const std::string& key); static bool IsAssetComplete(const ObjectRecord& result, const std::string& assetPrefix); Assets GetAssetsFromDBRecords(const ObjectRecord& result); - bool RegisterAssetsLister(); void ComputeStatus(const std::string& objectKey, const SaveInfo& saveInfo, const std::map& data); void NotifyDataChanged(const std::map& data, const SaveInfo& saveInfo); @@ -206,8 +204,6 @@ private: DistributedDB::KvStoreDelegateManager *kvStoreDelegateManager_ = nullptr; DistributedDB::KvStoreNbDelegate *delegate_ = nullptr; ObjectDataListener *objectDataListener_ = nullptr; - sptr objectAssetsRecvListener_ = nullptr; - sptr objectAssetsSendListener_ = nullptr; uint32_t syncCount_ = 0; std::string userId_; std::atomic isSyncing_ = false; diff --git a/services/distributeddataservice/service/object/src/object_asset_delegate.cpp b/services/distributeddataservice/service/object/src/object_asset_delegate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..785a21c43321246b5f247dffb70dba2a81a9f0a8 --- /dev/null +++ b/services/distributeddataservice/service/object/src/object_asset_delegate.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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 "object_asset_delegate.h" + +namespace OHOS { +namespace DistributedObject { +ObjectAssetDelegate *ObjectAssetDelegate::instance_ = nullptr; +bool ObjectAssetDelegate::RegisterInstance(ObjectAssetDelegate *instance) +{ + if (instance_ != nullptr) { + return false; + } + instance_ = instance; + return true; +} + +ObjectAssetDelegate *ObjectAssetDelegate::GetInstance() +{ + return instance_; +} +} // namespace DistributedObject +} // namespace OHOS diff --git a/services/distributeddataservice/service/object/src/object_asset_delegate_default_impl.cpp b/services/distributeddataservice/service/object/src/object_asset_delegate_default_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41c35ead992b8894a026e3743fd3823ebfb6c760 --- /dev/null +++ b/services/distributeddataservice/service/object/src/object_asset_delegate_default_impl.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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 "object_asset_delegate_default_impl.h" + +#include + +namespace OHOS { +namespace DistributedObject { +__attribute__((used)) static bool g_isInit = ObjectAssetDelegateDefaultImpl::Init(); +bool ObjectAssetDelegateDefaultImpl::Init() +{ + static ObjectAssetDelegateDefaultImpl defaultObjectAssetDelegate; + static std::once_flag onceFlag; + std::call_once(onceFlag, [&]() { ObjectAssetDelegate::RegisterInstance(&defaultObjectAssetDelegate); }); + return true; +} + +bool ObjectAssetDelegateDefaultImpl::SetThreadPool(std::shared_ptr executors) +{ + return false; +} + +void ObjectAssetDelegateDefaultImpl::TransferAssetsAsync(const int32_t userId, const std::string &bundleName, + const std::string &deviceId, const std::vector &assets, const TransferFunc &callback) +{ + callback(false); +} + +int32_t ObjectAssetDelegateDefaultImpl::PushAsset(const std::string &sessionId, const std::string &dstNetworkId, + const std::string &srcBundleName, const std::string &dstBundleName, const std::vector &uris) +{ + return -1; +} + +bool ObjectAssetDelegateDefaultImpl::RegisterAssetsListener() +{ + return false; +} + +bool ObjectAssetDelegateDefaultImpl::UnRegisterAssetsListener() +{ + return false; +} +} // namespace DistributedObject +} // namespace OHOS diff --git a/services/distributeddataservice/service/object/src/object_asset_loader.cpp b/services/distributeddataservice/service/object/src/object_asset_delegate_normal_impl.cpp similarity index 60% rename from services/distributeddataservice/service/object/src/object_asset_loader.cpp rename to services/distributeddataservice/service/object/src/object_asset_delegate_normal_impl.cpp index c3d582e6aef6ae46beef39d1bc06ae2c34d3794c..fe6f35c5b57b83a238a3ad3ef39670c4e9195ce6 100644 --- a/services/distributeddataservice/service/object/src/object_asset_loader.cpp +++ b/services/distributeddataservice/service/object/src/object_asset_delegate_normal_impl.cpp @@ -12,31 +12,67 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "ObjectAssetLoader" -#include "object_asset_loader.h" +#define LOG_TAG "ObjectAssetDelegateNormalImpl" + +#include "object_asset_delegate_normal_impl.h" + +#include "account/account_delegate.h" #include "block_data.h" #include "cloud_sync_asset_manager.h" +#include "distributed_file_daemon_manager.h" #include "log_print.h" #include "object_common.h" -#include "utils/anonymous.h" +#include "object_manager.h" #include "object_radar_reporter.h" -#include "distributed_file_daemon_manager.h" +#include "utils/anonymous.h" + namespace OHOS::DistributedObject { +using DistributedFileDaemonManager = Storage::DistributedFile::DistributedFileDaemonManager; using namespace OHOS::FileManagement::CloudSync; -ObjectAssetLoader *ObjectAssetLoader::GetInstance() +__attribute__((used)) static bool g_isInit = ObjectAssetDelegateNormalImpl::Init(); +bool ObjectAssetDelegateNormalImpl::Init() +{ + static ObjectAssetDelegateNormalImpl normalObjectAssetDelegate; + static std::once_flag onceFlag; + std::call_once(onceFlag, [&]() { ObjectAssetDelegate::RegisterInstance(&normalObjectAssetDelegate); }); + return true; +} + +int32_t ObjectAssetsRecvListener::OnStart(const std::string &srcNetworkId, const std::string &dstNetworkId, + const std::string &sessionId, const std::string &dstBundleName) { - static ObjectAssetLoader *loader = new ObjectAssetLoader(); - return loader; + auto objectKey = dstBundleName + sessionId; + ZLOGI("OnStart, objectKey:%{public}s", objectKey.c_str()); + ObjectStoreManager::GetInstance()->NotifyAssetsStart(objectKey, srcNetworkId); + return OBJECT_SUCCESS; } -void ObjectAssetLoader::SetThreadPool(std::shared_ptr executors) +int32_t ObjectAssetsRecvListener::OnFinished(const std::string &srcNetworkId, const sptr &assetObj, + int32_t result) +{ + if (assetObj == nullptr) { + ZLOGE("OnFinished error! status:%{public}d, srcNetworkId:%{public}s", result, + DistributedData::Anonymous::Change(srcNetworkId).c_str()); + ObjectStore::RadarReporter::ReportStageError(std::string(__FUNCTION__), ObjectStore::DATA_RESTORE, + ObjectStore::ASSETS_RECV, ObjectStore::RADAR_FAILED, result); + return result; + } + auto objectKey = assetObj->dstBundleName_+assetObj->sessionId_; + ZLOGI("OnFinished, status:%{public}d objectKey:%{public}s, asset size:%{public}zu", result, objectKey.c_str(), + assetObj->uris_.size()); + ObjectStoreManager::GetInstance()->NotifyAssetsReady(objectKey, assetObj->dstBundleName_, srcNetworkId); + return OBJECT_SUCCESS; +} + +bool ObjectAssetDelegateNormalImpl::SetThreadPool(std::shared_ptr executors) { executors_ = executors; + return true; } -bool ObjectAssetLoader::Transfer(const int32_t userId, const std::string& bundleName, const std::string& deviceId, - const DistributedData::Asset& asset) +bool ObjectAssetDelegateNormalImpl::Transfer(const int32_t userId, const std::string &bundleName, + const std::string &deviceId, const DistributedData::Asset &asset) { AssetInfo assetInfo; assetInfo.uri = asset.uri; @@ -64,8 +100,8 @@ bool ObjectAssetLoader::Transfer(const int32_t userId, const std::string& bundle return true; } -void ObjectAssetLoader::TransferAssetsAsync(const int32_t userId, const std::string& bundleName, - const std::string& deviceId, const std::vector& assets, const TransferFunc& callback) +void ObjectAssetDelegateNormalImpl::TransferAssetsAsync(const int32_t userId, const std::string &bundleName, + const std::string &deviceId, const std::vector &assets, const TransferFunc &callback) { if (executors_ == nullptr) { ZLOGE("executors is null, bundleName: %{public}s, deviceId: %{public}s, userId: %{public}d", @@ -115,7 +151,7 @@ void ObjectAssetLoader::TransferAssetsAsync(const int32_t userId, const std::str }); } -void ObjectAssetLoader::FinishTask(const std::string& uri, bool result) +void ObjectAssetDelegateNormalImpl::FinishTask(const std::string& uri, bool result) { std::vector finishedTasks; tasks_.ForEach([&uri, &finishedTasks, result](auto& seq, auto& task) { @@ -131,7 +167,7 @@ void ObjectAssetLoader::FinishTask(const std::string& uri, bool result) } } -void ObjectAssetLoader::UpdateDownloaded(const DistributedData::Asset& asset) +void ObjectAssetDelegateNormalImpl::UpdateDownloaded(const DistributedData::Asset& asset) { downloaded_.ComputeIfAbsent(asset.uri, [asset](const std::string& key) { return asset.hash; @@ -144,7 +180,7 @@ void ObjectAssetLoader::UpdateDownloaded(const DistributedData::Asset& asset) } } -bool ObjectAssetLoader::IsDownloading(const DistributedData::Asset& asset) +bool ObjectAssetDelegateNormalImpl::IsDownloading(const DistributedData::Asset& asset) { auto [success, hash] = downloading_.Find(asset.uri); if (success && hash == asset.hash) { @@ -154,7 +190,7 @@ bool ObjectAssetLoader::IsDownloading(const DistributedData::Asset& asset) return false; } -bool ObjectAssetLoader::IsDownloaded(const DistributedData::Asset& asset) +bool ObjectAssetDelegateNormalImpl::IsDownloaded(const DistributedData::Asset& asset) { auto [success, hash] = downloaded_.Find(asset.uri); if (success && hash == asset.hash) { @@ -164,15 +200,24 @@ bool ObjectAssetLoader::IsDownloaded(const DistributedData::Asset& asset) return false; } -int32_t ObjectAssetLoader::PushAsset(int32_t userId, const sptr &assetObj, - const sptr &sendCallback) +int32_t ObjectAssetDelegateNormalImpl::PushAsset(const std::string &sessionId, const std::string &dstNetworkId, + const std::string &srcBundleName, const std::string &dstBundleName, const std::vector &uris) { ObjectStore::RadarReporter::ReportStage(std::string(__FUNCTION__), ObjectStore::SAVE, ObjectStore::PUSH_ASSETS, ObjectStore::IDLE); ZLOGI("PushAsset start, asset size:%{public}zu, bundleName:%{public}s, sessionId:%{public}s", - assetObj->uris_.size(), assetObj->dstBundleName_.c_str(), assetObj->sessionId_.c_str()); - auto status = Storage::DistributedFile::DistributedFileDaemonManager::GetInstance().PushAsset(userId, assetObj, - sendCallback); + uris.size(), dstBundleName.c_str(), sessionId.c_str()); + sptr assetObj = new AssetObj(); + assetObj->dstBundleName_ = dstBundleName; + assetObj->srcBundleName_ = srcBundleName; + assetObj->dstNetworkId_ = dstNetworkId; + assetObj->sessionId_ = sessionId; + assetObj->uris_ = uris; + if (assetsSendListener_ == nullptr) { + assetsSendListener_ = new ObjectAssetsSendListener(); + } + auto status = + DistributedFileDaemonManager::GetInstance().PushAsset(GetCurrentUser(), assetObj, assetsSendListener_); if (status != OBJECT_SUCCESS) { ZLOGE("PushAsset err status: %{public}d, asset size:%{public}zu, bundleName:%{public}s, sessionId:%{public}s", status, assetObj->uris_.size(), assetObj->dstBundleName_.c_str(), assetObj->sessionId_.c_str()); @@ -200,4 +245,41 @@ int32_t ObjectAssetsSendListener::OnSendResult(const sptr &assetObj, i } return result; } -} // namespace OHOS::DistributedObject \ No newline at end of file + +int32_t ObjectAssetDelegateNormalImpl::GetCurrentUser() +{ + std::vector users; + AccountDelegate::GetInstance()->QueryUsers(users); + if (!users.empty()) { + return users[0]; + } + return 0; +} + +bool ObjectAssetDelegateNormalImpl::RegisterAssetsListener() +{ + if (assetsRecvListener_ == nullptr) { + assetsRecvListener_ = new ObjectAssetsRecvListener(); + } + auto status = DistributedFileDaemonManager::GetInstance().RegisterAssetCallback(assetsRecvListener_); + if (status != 0) { + ZLOGE("Register asset callback err=%{public}d", status); + return false; + } + return true; +} + +bool ObjectAssetDelegateNormalImpl::UnRegisterAssetsListener() +{ + if (assetsRecvListener_ != nullptr) { + auto status = DistributedFileDaemonManager::GetInstance().UnRegisterAssetCallback(assetsRecvListener_); + if (status != 0) { + ZLOGE("UnRegister asset callback err=%{public}d", status); + return false; + } + delete assetsRecvListener_; + assetsRecvListener_ = nullptr; + } + return true; +} +} // namespace OHOS::DistributedObject diff --git a/services/distributeddataservice/service/object/src/object_asset_machine.cpp b/services/distributeddataservice/service/object/src/object_asset_machine.cpp index 6d1d11fb71cf86609a5b6c0df42cf0befe6ed635..7996c22897586c96ce47c459bb363ecd06914fee 100644 --- a/services/distributeddataservice/service/object/src/object_asset_machine.cpp +++ b/services/distributeddataservice/service/object/src/object_asset_machine.cpp @@ -24,7 +24,7 @@ #include "eventcenter/event_center.h" #include "log_print.h" #include "metadata/meta_data_manager.h" -#include "object_asset_loader.h" +#include "object_asset_delegate.h" #include "snapshot/bind_event.h" #include "store/auto_cache.h" #include "utils/anonymous.h" @@ -164,7 +164,7 @@ static int32_t DoTransfer(int32_t eventId, ChangedAssetInfo& changedAsset, Asset changedAsset.deviceId = newAsset.first; changedAsset.asset = newAsset.second; std::vector assets{ changedAsset.asset }; - ObjectAssetLoader::GetInstance()->TransferAssetsAsync(changedAsset.storeInfo.user, + ObjectAssetDelegate::GetInstance()->TransferAssetsAsync(changedAsset.storeInfo.user, changedAsset.storeInfo.bundleName, changedAsset.deviceId, assets, [&changedAsset](bool success) { if (success) { auto status = UpdateStore(changedAsset); diff --git a/services/distributeddataservice/service/object/src/object_data_listener.cpp b/services/distributeddataservice/service/object/src/object_data_listener.cpp index e7a7a5d0abcd44de8af8b2ac9b582c17ab887a3b..91910124ec9fd0adaf60861ff9c4ef3076cf9a04 100644 --- a/services/distributeddataservice/service/object/src/object_data_listener.cpp +++ b/services/distributeddataservice/service/object/src/object_data_listener.cpp @@ -13,13 +13,10 @@ * limitations under the License. */ -#define LOG_TAG "ObjectDataListener" - #include "object_data_listener.h" -#include "log_print.h" + #include "object_manager.h" -#include "object_radar_reporter.h" -#include "utils/anonymous.h" + namespace OHOS { namespace DistributedObject { ObjectDataListener::ObjectDataListener() @@ -45,31 +42,5 @@ void ObjectDataListener::OnChange(const DistributedDB::KvStoreChangedData &data) } DistributedObject::ObjectStoreManager::GetInstance()->NotifyChange(changedData); } - -int32_t ObjectAssetsRecvListener::OnStart(const std::string &srcNetworkId, const std::string &dstNetworkId, - const std::string &sessionId, const std::string &dstBundleName) -{ - auto objectKey = dstBundleName + sessionId; - ZLOGI("OnStart, objectKey:%{public}s", objectKey.c_str()); - ObjectStoreManager::GetInstance()->NotifyAssetsStart(objectKey, srcNetworkId); - return OBJECT_SUCCESS; -} - -int32_t ObjectAssetsRecvListener::OnFinished(const std::string &srcNetworkId, const sptr &assetObj, - int32_t result) -{ - if (assetObj == nullptr) { - ZLOGE("OnFinished error! status:%{public}d, srcNetworkId:%{public}s", result, - DistributedData::Anonymous::Change(srcNetworkId).c_str()); - ObjectStore::RadarReporter::ReportStageError(std::string(__FUNCTION__), ObjectStore::DATA_RESTORE, - ObjectStore::ASSETS_RECV, ObjectStore::RADAR_FAILED, result); - return result; - } - auto objectKey = assetObj->dstBundleName_+assetObj->sessionId_; - ZLOGI("OnFinished, status:%{public}d objectKey:%{public}s, asset size:%{public}zu", result, objectKey.c_str(), - assetObj->uris_.size()); - ObjectStoreManager::GetInstance()->NotifyAssetsReady(objectKey, assetObj->dstBundleName_, srcNetworkId); - return OBJECT_SUCCESS; -} } // namespace DistributedObject } // namespace OHOS diff --git a/services/distributeddataservice/service/object/src/object_manager.cpp b/services/distributeddataservice/service/object/src/object_manager.cpp index 63f90ce8c639e03f23d78002b16974c85db391d3..711668d9b77ca81fc6d581cf9b066d2e8746a733 100644 --- a/services/distributeddataservice/service/object/src/object_manager.cpp +++ b/services/distributeddataservice/service/object/src/object_manager.cpp @@ -25,11 +25,11 @@ #include "common/bytes.h" #include "common/string_utils.h" #include "datetime_ex.h" -#include "distributed_file_daemon_manager.h" #include "kvstore_utils.h" #include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" +#include "object_asset_delegate.h" #include "object_dms_handler.h" #include "object_radar_reporter.h" #include "utils/anonymous.h" @@ -39,26 +39,19 @@ namespace DistributedObject { using namespace OHOS::DistributedKv; using namespace Security::AccessToken; using StoreMetaData = OHOS::DistributedData::StoreMetaData; -using Account = OHOS::DistributedData::AccountDelegate; using AccessTokenKit = Security::AccessToken::AccessTokenKit; using ValueProxy = OHOS::DistributedData::ValueProxy; -using DistributedFileDaemonManager = Storage::DistributedFile::DistributedFileDaemonManager; constexpr const char *SAVE_INFO = "p_###SAVEINFO###"; ObjectStoreManager::ObjectStoreManager() { ZLOGI("ObjectStoreManager construct"); - RegisterAssetsLister(); + ObjectAssetDelegate::GetInstance()->RegisterAssetsListener(); } ObjectStoreManager::~ObjectStoreManager() { ZLOGI("ObjectStoreManager destroy"); - if (objectAssetsRecvListener_ != nullptr) { - auto status = DistributedFileDaemonManager::GetInstance().UnRegisterAssetCallback(objectAssetsRecvListener_); - if (status != DistributedDB::DBStatus::OK) { - ZLOGE("UnRegister assetsRecvListener err %{public}d", status); - } - } + ObjectAssetDelegate::GetInstance()->UnRegisterAssetsListener(); } DistributedDB::KvStoreNbDelegate *ObjectStoreManager::OpenObjectKvStore() @@ -91,22 +84,6 @@ DistributedDB::KvStoreNbDelegate *ObjectStoreManager::OpenObjectKvStore() return store; } -bool ObjectStoreManager::RegisterAssetsLister() -{ - if (objectAssetsSendListener_ == nullptr) { - objectAssetsSendListener_ = new ObjectAssetsSendListener(); - } - if (objectAssetsRecvListener_ == nullptr) { - objectAssetsRecvListener_ = new ObjectAssetsRecvListener(); - } - auto status = DistributedFileDaemonManager::GetInstance().RegisterAssetCallback(objectAssetsRecvListener_); - if (status != DistributedDB::DBStatus::OK) { - ZLOGE("Register assetsRecvListener err %{public}d", status); - return false; - } - return true; -} - void ObjectStoreManager::ProcessSyncCallback(const std::map &results, const std::string &appId, const std::string &sessionId, const std::string &deviceId) { @@ -182,19 +159,12 @@ int32_t ObjectStoreManager::PushAssets(const std::string &srcBundleName, const s if (assets.empty() || data.find(ObjectStore::FIELDS_PREFIX + ObjectStore::DEVICEID_KEY) == data.end()) { return OBJECT_SUCCESS; } - sptr assetObj = new AssetObj(); - assetObj->dstBundleName_ = dstBundleName; - assetObj->srcBundleName_ = srcBundleName; - assetObj->dstNetworkId_ = deviceId; - assetObj->sessionId_ = sessionId; + std::vector uris; for (const auto& asset : assets) { - assetObj->uris_.push_back(asset.uri); - } - if (objectAssetsSendListener_ == nullptr) { - objectAssetsSendListener_ = new ObjectAssetsSendListener(); + uris.push_back(std::move(asset.uri)); } - int userId = std::atoi(GetCurrentUser().c_str()); - auto status = ObjectAssetLoader::GetInstance()->PushAsset(userId, assetObj, objectAssetsSendListener_); + auto status = + ObjectAssetDelegate::GetInstance()->PushAsset(sessionId, deviceId, srcBundleName, dstBundleName, uris); return status; } @@ -520,7 +490,7 @@ void ObjectStoreManager::PullAssets(const std::map& d for (const auto& [objectId, assets] : changedAssets) { std::string networkId = DmAdaper::GetInstance().ToNetworkID(saveInfo.sourceDeviceId); auto block = std::make_shared>>(WAIT_TIME, std::tuple{ true, true }); - ObjectAssetLoader::GetInstance()->TransferAssetsAsync(std::stoi(GetCurrentUser()), + ObjectAssetDelegate::GetInstance()->TransferAssetsAsync(std::stoi(GetCurrentUser()), saveInfo.bundleName, networkId, assets, [this, block](bool success) { block->SetValue({ false, success }); }); @@ -1221,7 +1191,7 @@ int32_t ObjectStoreManager::OnAssetChanged(const uint32_t tokenId, const std::st } auto block = std::make_shared>>(WAIT_TIME, std::tuple{ true, true }); - ObjectAssetLoader::GetInstance()->TransferAssetsAsync(userId, appId, deviceId, { dataAsset }, [block](bool ret) { + ObjectAssetDelegate::GetInstance()->TransferAssetsAsync(userId, appId, deviceId, { dataAsset }, [block](bool ret) { block->SetValue({ false, ret }); }); auto [timeout, success] = block->GetValue(); diff --git a/services/distributeddataservice/service/object/src/object_service_impl.cpp b/services/distributeddataservice/service/object/src/object_service_impl.cpp index fdb08505e7ad12410d938f5807446a5666d7d9fc..7c3e1e7f7b4c8d2cafff95da953129f0615b00b1 100644 --- a/services/distributeddataservice/service/object/src/object_service_impl.cpp +++ b/services/distributeddataservice/service/object/src/object_service_impl.cpp @@ -17,8 +17,6 @@ #include "object_service_impl.h" -#include - #include "accesstoken_kit.h" #include "account/account_delegate.h" #include "bootstrap.h" @@ -27,16 +25,17 @@ #include "directory/directory_manager.h" #include "dump/dump_manager.h" #include "eventcenter/event_center.h" +#include "ipc_skeleton.h" #include "log_print.h" #include "metadata/appid_meta_data.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" -#include "object_asset_loader.h" +#include "object_asset_delegate.h" #include "object_dms_handler.h" +#include "object_radar_reporter.h" #include "snapshot/bind_event.h" #include "store/auto_cache.h" #include "utils/anonymous.h" -#include "object_radar_reporter.h" namespace OHOS::DistributedObject { using DmAdapter = OHOS::DistributedData::DeviceManagerAdapter; @@ -398,7 +397,7 @@ int32_t ObjectServiceImpl::OnBind(const BindInfo &bindInfo) { executors_ = bindInfo.executors; ObjectStoreManager::GetInstance()->SetThreadPool(executors_); - ObjectAssetLoader::GetInstance()->SetThreadPool(executors_); + ObjectAssetDelegate::GetInstance()->SetThreadPool(executors_); return 0; } } // namespace OHOS::DistributedObject diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index 4cf45945b514efed754ff5ead3f5fe4062f08a87..8e50684ce712f2d13ca215e2f80eef348f4c99a4 100755 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -713,25 +713,85 @@ ohos_unittest("RdbServiceImplTest") { ] } -ohos_unittest("ObjectAssetLoaderTest") { +config("object_private_config") { + visibility = [ ":*" ] + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/adapter/include/utils", + "${data_service_path}/framework/include", + "${data_service_path}/service/bootstrap/include/", + "${data_service_path}/service/common/", + "${data_service_path}/service/object/include", + ] + + cflags = [ "-Werror" ] + + defines = [ + "TEST_ON_DEVICE", + "OPENSSL_SUPPRESS_DEPRECATED", + ] +} + +ohos_unittest("ObjectAssetDelegateNormalImplTest") { + module_out_path = module_output_path + sources = [ + "../object/src/object_asset_delegate.cpp", + "../object/src/object_asset_delegate_normal_impl.cpp", + "../object/src/object_callback_proxy.cpp", + "../object/src/object_manager.cpp", + "object_asset_delegate_normal_impl_test.cpp", + ] + + configs = [ ":object_private_config" ] + + deps = [ + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service:distributeddatasvc", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/common:distributeddata_common", + ] + + external_deps = [ + "access_token:libtokenid_sdk", + "c_utils:utils", + "data_object:data_object_inner", + "dfs_service:cloudsync_asset_kit_inner", + "dfs_service:distributed_file_daemon_kit_inner", + "dmsfwk:distributed_sdk", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:datamgr_common", + "kv_store:distributeddb", + ] + + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + ] +} + +ohos_unittest("ObjectAssetDelegateTest") { module_out_path = module_output_path sources = [ - "../object/src/object_asset_loader.cpp", + "../object/src/object_asset_delegate.cpp", + "../object/src/object_asset_delegate_default_impl.cpp", "../object/src/object_asset_machine.cpp", "../object/src/object_snapshot.cpp", - "object_asset_loader_test.cpp", + "object_asset_delegate_test.cpp", ] include_dirs = [ - "${dataobject_path}/frameworks/innerkitsimpl/include/common", - "${dataobject_path}/interfaces/innerkits", - "${relational_store_path}/interfaces/inner_api/common_type/include", + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/service/object/include", ] - configs = [ ":module_private_config" ] - external_deps = [ "c_utils:utils", + "data_object:distributeddataobject_impl", "dfs_service:cloudsync_asset_kit_inner", "dfs_service:distributed_file_daemon_kit_inner", "hilog:libhilog", @@ -739,12 +799,13 @@ ohos_unittest("ObjectAssetLoaderTest") { "ipc:ipc_core", "json:nlohmann_json_static", "kv_store:distributeddata_inner", + "relational_store:native_rdb", ] deps = [ + "${data_service_path}/adapter/communicator:distributeddata_communicator", "${data_service_path}/framework:distributeddatasvcfwk", "${data_service_path}/service:distributeddatasvc", - "//third_party/googletest:gtest_main", ] cflags = [ @@ -756,7 +817,8 @@ ohos_unittest("ObjectAssetLoaderTest") { ohos_unittest("ObjectAssetMachineTest") { module_out_path = module_output_path sources = [ - "../object/src/object_asset_loader.cpp", + "../object/src/object_asset_delegate.cpp", + "../object/src/object_asset_delegate_default_impl.cpp", "../object/src/object_asset_machine.cpp", "object_asset_machine_test.cpp", ] @@ -828,7 +890,8 @@ ohos_unittest("ObjectManagerTest") { sources = [ "${data_service_path}/service/common/common_types_utils.cpp", "${data_service_path}/service/common/value_proxy.cpp", - "../object/src/object_asset_loader.cpp", + "../object/src/object_asset_delegate.cpp", + "../object/src/object_asset_delegate_default_impl.cpp", "../object/src/object_asset_machine.cpp", "../object/src/object_callback_proxy.cpp", "../object/src/object_data_listener.cpp", @@ -887,7 +950,8 @@ ohos_unittest("ObjectManagerTest") { ohos_unittest("ObjectSnapshotTest") { module_out_path = module_output_path sources = [ - "../object/src/object_asset_loader.cpp", + "../object/src/object_asset_delegate.cpp", + "../object/src/object_asset_delegate_default_impl.cpp", "../object/src/object_asset_machine.cpp", "../object/src/object_snapshot.cpp", "object_snapshot_test.cpp", @@ -1975,12 +2039,15 @@ group("unittest") { if (datamgr_service_object) { deps += [ - ":ObjectAssetLoaderTest", + ":ObjectAssetDelegateTest", ":ObjectAssetMachineTest", ":ObjectDmsHandlerTest", ":ObjectManagerTest", ":ObjectSnapshotTest", ] + if (datamgr_service_object_asset) { + deps += [ ":ObjectAssetDelegateNormalImplTest" ] + } } if (datamgr_service_rdb) { diff --git a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn index 336b0dbfc3561fdf79595a75894079899c6f2b08..7bda944bc0d8dfba25d26123562aafc524bc0893 100755 --- a/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/objectservicestub_fuzzer/BUILD.gn @@ -74,7 +74,8 @@ ohos_fuzztest("ObjectServiceStubFuzzTest") { "${data_service_path}/service/config/src/model/protocol_config.cpp", "${data_service_path}/service/config/src/model/thread_config.cpp", "${data_service_path}/service/crypto/src/crypto_manager.cpp", - "${data_service_path}/service/object/src/object_asset_loader.cpp", + "${data_service_path}/service/object/src/object_asset_delegate.cpp", + "${data_service_path}/service/object/src/object_asset_delegate_default_impl.cpp", "${data_service_path}/service/object/src/object_asset_machine.cpp", "${data_service_path}/service/object/src/object_callback_proxy.cpp", "${data_service_path}/service/object/src/object_data_listener.cpp", diff --git a/services/distributeddataservice/service/test/object_asset_delegate_normal_impl_test.cpp b/services/distributeddataservice/service/test/object_asset_delegate_normal_impl_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12d8a6fb72e4b3acd9ef08e14557bff989727446 --- /dev/null +++ b/services/distributeddataservice/service/test/object_asset_delegate_normal_impl_test.cpp @@ -0,0 +1,337 @@ +/* + * Copyright (c) 2025 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 "object_asset_delegate_normal_impl.h" + +#include + +#include "object_common.h" + +using namespace testing::ext; +using namespace OHOS::DistributedData; +using namespace OHOS::DistributedObject; +namespace OHOS::Test { +static ObjectAssetDelegateNormalImpl instance_; +class ObjectAssetDelegateNormalImplTest : public testing::Test { +public: + void SetUp(); + void TearDown(); +}; + +void ObjectAssetDelegateNormalImplTest::SetUp() {} +void ObjectAssetDelegateNormalImplTest::TearDown() {} + +/** +* @tc.name: Init001 +* @tc.desc: Init test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, Init001, TestSize.Level0) +{ + auto res = instance_.Init(); + EXPECT_TRUE(res); +} + +/** +* @tc.name: TransferAssetsAsync001 +* @tc.desc: TransferAssetsAsync test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, TransferAssetsAsync001, TestSize.Level0) +{ + Asset asset{ + .name = "assetName", + .uri = "assetUri", + .createTime = "assetCreateTime", + .modifyTime = "assetModifyTime", + .size = "assetSize", + .path = "assetPath", + .status = 0 + }; + std::vector assets{ asset }; + bool status = false; + std::function transferCallback = [&status](bool success) { + if (success) { + status = success; + } + }; + instance_.TransferAssetsAsync(0, "bundleName", "deviceId", assets, transferCallback); + ASSERT_EQ(instance_.executors_, nullptr); + EXPECT_FALSE(status); +} + +/** +* @tc.name: SetThreadPool001 +* @tc.desc: SetThreadPool test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, SetThreadPool001, TestSize.Level0) +{ + ASSERT_EQ(instance_.executors_, nullptr); + auto executors = std::make_shared(2, 1); + auto res = instance_.SetThreadPool(executors); + EXPECT_TRUE(res); + ASSERT_NE(instance_.executors_, nullptr); +} + +/** +* @tc.name: TransferAssetsAsync002 +* @tc.desc: TransferAssetsAsync test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, TransferAssetsAsync002, TestSize.Level0) +{ + Asset asset{ + .name = "assetName", + .uri = "assetUri", + .createTime = "assetCreateTime", + .modifyTime = "assetModifyTime", + .size = "assetSize", + .path = "assetPath", + .status = 0 + }; + std::vector assets{ asset }; + bool status = false; + std::function transferCallback = [&status](bool success) { + if (success) { + status = success; + } + }; + instance_.TransferAssetsAsync(0, "bundleName", "deviceId", assets, transferCallback); + EXPECT_FALSE(status); +} + +/** +* @tc.name: PushAsset001 +* @tc.desc: PushAsset test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, PushAsset001, TestSize.Level0) +{ + instance_.assetsSendListener_ = nullptr; + auto res = instance_.PushAsset("sessionId", "deviceId", "srcBundleName", "dstBundleName", {"uri"}); + EXPECT_NE(res, 0); + + + ASSERT_NE(instance_.assetsSendListener_, nullptr); + res = instance_.PushAsset("sessionId", "deviceId", "srcBundleName", "dstBundleName", {"uri"}); + EXPECT_NE(res, 0); +} + +/** +* @tc.name: RegisterAssetsListener001 +* @tc.desc: RegisterAssetsListener test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, RegisterAssetsListener001, TestSize.Level0) +{ + instance_.assetsRecvListener_ = nullptr; + auto res = instance_.RegisterAssetsListener(); + // E_BROKEN_IPC + EXPECT_FALSE(res); + ASSERT_NE(instance_.assetsRecvListener_, nullptr); + // assetsRecvListener_ not null + res = instance_.RegisterAssetsListener(); + EXPECT_FALSE(res); +} + +/** +* @tc.name: UnRegisterAssetsListener001 +* @tc.desc: UnRegisterAssetsListener test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, UnRegisterAssetsListener001, TestSize.Level0) +{ + ASSERT_NE(instance_.assetsRecvListener_, nullptr); + auto res = instance_.UnRegisterAssetsListener(); + // E_BROKEN_IPC + EXPECT_TRUE(res); + ASSERT_NE(instance_.assetsRecvListener_, nullptr); + // assetsRecvListener_ null + instance_.assetsRecvListener_ = nullptr; + res = instance_.UnRegisterAssetsListener(); + EXPECT_TRUE(res); +} + +/** +* @tc.name: FinishTask001 +* @tc.desc: FinishTask test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, FinishTask001, TestSize.Level0) +{ + ObjectAssetDelegateNormalImpl instance; + bool status = false; + uint32_t seq = 10; + TransferTask task; + std::string uri1 = "uri1"; + std::string uri2 = "uri2"; + task.downloadAssets.insert(uri1); + task.downloadAssets.insert(uri2); + task.callback = [&status](bool result) { + status = result; + }; + instance.tasks_.Insert(seq, task); + EXPECT_EQ(instance.tasks_.Size(), 1); + instance.FinishTask(uri1, true); + EXPECT_FALSE(status); + instance.FinishTask(uri2, true); + EXPECT_TRUE(status); + EXPECT_TRUE(instance.tasks_.Empty()); +} + +/** +* @tc.name: IsDownloading001 +* @tc.desc: IsDownloading test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, IsDownloading001, TestSize.Level0) +{ + Asset asset{ + .name = "name1", + .uri = "uri1", + .createTime = "createTime1", + .modifyTime = "modifyTime1", + .size = "size1", + .path = "path1", + .status = 0, + .hash = "hash1" + }; + instance_.downloading_.Clear(); + instance_.downloaded_.Insert("uri1", "hash1"); + auto ret = instance_.IsDownloading(asset); + EXPECT_TRUE(ret); + asset.uri = "uri2"; + ret = instance_.IsDownloading(asset); + EXPECT_FALSE(ret); + asset.uri = "uri1"; + asset.hash = "hash2"; + ret = instance_.IsDownloading(asset); + EXPECT_FALSE(ret); + instance_.downloading_.Clear(); +} + +/** +* @tc.name: IsDownloaded001 +* @tc.desc: IsDownloaded test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, IsDownloaded001, TestSize.Level0) +{ + Asset asset{ + .name = "name1", + .uri = "uri1", + .createTime = "createTime1", + .modifyTime = "modifyTime1", + .size = "size1", + .path = "path1", + .status = 0, + .hash = "hash1" + }; + instance_.downloaded_.Clear(); + instance_.downloaded_.Insert("uri1", "hash1"); + auto ret = instance_.IsDownloaded(asset); + EXPECT_TRUE(ret); + asset.uri = "uri2"; + ret = instance_.IsDownloaded(asset); + EXPECT_FALSE(ret); + asset.uri = "uri1"; + asset.hash = "hash2"; + ret = instance_.IsDownloaded(asset); + EXPECT_FALSE(ret); + instance_.downloaded_.Clear(); +} + +/** +* @tc.name: UpdateDownloaded001 +* @tc.desc: UpdateDownloaded test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, UpdateDownloaded001, TestSize.Level0) +{ + Asset asset{ + .name = "name0", + .uri = "uri0", + .createTime = "createTime0", + .modifyTime = "modifyTime0", + .size = "size0", + .path = "path0", + .status = 0, + .hash = "hash0" + }; + instance_.downloaded_.Clear(); + instance_.UpdateDownloaded(asset); + EXPECT_TRUE(instance_.assetQueue_.back() == asset.uri); + EXPECT_EQ(instance_.assetQueue_.size(), 1); + instance_.downloaded_.Clear(); + instance_.assetQueue_.pop(); + for (int num = 1; num <= instance_.LAST_DOWNLOAD_ASSET_SIZE; ++num) { + asset.uri = "uri" + std::to_string(num); + instance_.UpdateDownloaded(asset); + EXPECT_TRUE(instance_.assetQueue_.back() == asset.uri); + EXPECT_EQ(instance_.assetQueue_.size(), num); + } + asset.uri = "uri0"; + instance_.UpdateDownloaded(asset); + EXPECT_TRUE(instance_.assetQueue_.back() == asset.uri); + EXPECT_EQ(instance_.assetQueue_.size(), instance_.LAST_DOWNLOAD_ASSET_SIZE); +} + +/** +* @tc.name: OnFinished001 +* @tc.desc: OnFinished test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, OnFinished001, TestSize.Level1) +{ + std::string srcNetworkId = "srcNetworkId"; + sptr assetObj = nullptr; + int32_t result = 100; + ObjectAssetsRecvListener listener; + int32_t ret = listener.OnFinished(srcNetworkId, assetObj, result); + EXPECT_NE(ret, DistributedObject::OBJECT_SUCCESS); + + sptr assetObj_1 = new AssetObj(); + assetObj_1->dstBundleName_ = "bundleName"; + assetObj_1->srcBundleName_ = "bundleName"; + assetObj_1->dstNetworkId_ = "1"; + assetObj_1->sessionId_ = "123"; + ret = listener.OnFinished(srcNetworkId, assetObj_1, result); + EXPECT_EQ(ret, DistributedObject::OBJECT_SUCCESS); +} + +/** +* @tc.name: OnSendResult001 +* @tc.desc: OnSendResult test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateNormalImplTest, OnSendResult001, TestSize.Level1) +{ + sptr assetObj = new AssetObj(); + int32_t result = 100; + ObjectAssetsSendListener listener; + int32_t ret = listener.OnSendResult(assetObj, result); + EXPECT_EQ(ret, result); + + sptr assetObj_1 = new AssetObj(); + ret = listener.OnSendResult(assetObj_1, result); + EXPECT_EQ(ret, result); + + // OBJECT_SUCCESS + result = 0; + ret = listener.OnSendResult(assetObj_1, result); + EXPECT_EQ(ret, DistributedObject::OBJECT_SUCCESS); +} +} // namespace OHOS::Test diff --git a/services/distributeddataservice/service/test/object_asset_delegate_test.cpp b/services/distributeddataservice/service/test/object_asset_delegate_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e04789ee3663fa05432cc650291de51429fed3c --- /dev/null +++ b/services/distributeddataservice/service/test/object_asset_delegate_test.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2025 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 "object_asset_delegate.h" +#include "object_asset_delegate_default_impl.h" + +#include + +using namespace testing::ext; +using namespace OHOS::DistributedData; +using namespace OHOS::DistributedObject; +namespace OHOS::Test { +class ObjectAssetDelegateTest : public testing::Test { +public: + void SetUp(); + void TearDown(); +}; + +void ObjectAssetDelegateTest::SetUp() {} + +void ObjectAssetDelegateTest::TearDown() {} + +/** +* @tc.name: RegisterInstance001 +* @tc.desc: RegisterInstance test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateTest, RegisterInstance001, TestSize.Level0) +{ + static ObjectAssetDelegateDefaultImpl defaultObjectAssetDelegate; + static std::once_flag onceFlag; + std::call_once(onceFlag, [&]() { ObjectAssetDelegate::RegisterInstance(&defaultObjectAssetDelegate); }); + auto instance = ObjectAssetDelegate::GetInstance(); + EXPECT_NE(instance, nullptr); +} + +/** +* @tc.name: GetInstance001 +* @tc.desc: GetInstance test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateTest, GetInstance001, TestSize.Level0) +{ + auto instance = ObjectAssetDelegate::GetInstance(); + EXPECT_NE(instance, nullptr); +} + +/** +* @tc.name: RegisterAssetsListener001 +* @tc.desc: RegisterAssetsListener test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateTest, RegisterAssetsListener001, TestSize.Level0) +{ + auto res = ObjectAssetDelegate::GetInstance()->RegisterAssetsListener(); + EXPECT_FALSE(res); +} + +/** +* @tc.name: UnRegisterAssetsListener001 +* @tc.desc: UnRegisterAssetsListener test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateTest, UnRegisterAssetsListener001, TestSize.Level0) +{ + auto res = ObjectAssetDelegate::GetInstance()->UnRegisterAssetsListener(); + EXPECT_FALSE(res); +} + +/** +* @tc.name: SetThreadPool001 +* @tc.desc: SetThreadPool test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateTest, SetThreadPool001, TestSize.Level0) +{ + auto executors = std::make_shared(2, 1); + auto res = ObjectAssetDelegate::GetInstance()->SetThreadPool(executors); + EXPECT_FALSE(res); +} + +/** +* @tc.name: PushAsset001 +* @tc.desc: PushAsset test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateTest, PushAsset001, TestSize.Level0) +{ + auto res = ObjectAssetDelegate::GetInstance()->PushAsset("sessionId ", "dstNetworkId ", "srcBundleName ", + "dstBundleName ", { "uris" }); + EXPECT_EQ(res, -1); +} + +/** +* @tc.name: TransferAssetsAsync001 +* @tc.desc: TransferAssetsAsync test. +* @tc.type: FUNC +*/ +HWTEST_F(ObjectAssetDelegateTest, TransferAssetsAsync001, TestSize.Level0) +{ + Asset asset{ + .name = "assetName", + .uri = "assetUri", + .createTime = "assetCreateTime", + .modifyTime = "assetModifyTime", + .size = "assetSize", + .path = "assetPath", + .status = 0 + }; + std::vector assets{ asset }; + bool status = false; + std::function transferCallback = [&status](bool success) { + if (success) { + status = success; + } + }; + ObjectAssetDelegate::GetInstance()->TransferAssetsAsync(0, "bundleName", "deviceId", assets, transferCallback); + EXPECT_FALSE(status); +} +} // namespace OHOS::Test diff --git a/services/distributeddataservice/service/test/object_asset_loader_test.cpp b/services/distributeddataservice/service/test/object_asset_loader_test.cpp deleted file mode 100644 index c25e185cb9cac8f8cc2000f0d1c71384dde44027..0000000000000000000000000000000000000000 --- a/services/distributeddataservice/service/test/object_asset_loader_test.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "ObjectAssetLoaderTest" - -#include "object_asset_loader.h" - -#include - -#include "executor_pool.h" -#include "object_common.h" -#include "snapshot/machine_status.h" - -using namespace testing::ext; -using namespace OHOS::DistributedObject; -using namespace OHOS::DistributedData; -namespace OHOS::Test { - -class ObjectAssetLoaderTest : public testing::Test { -public: - void SetUp(); - void TearDown(); - -protected: - Asset asset_; - std::string uri_; - int32_t userId_ = 1; - std::string bundleName_ = "test_bundleName_1"; - std::string deviceId_ = "test_deviceId__1"; -}; - -void ObjectAssetLoaderTest::SetUp() -{ - uri_ = "file:://com.example.hmos.notepad/data/storage/el2/distributedfiles/dir/asset1.jpg"; - Asset asset{ - .name = "test_name", - .uri = uri_, - .modifyTime = "modifyTime", - .size = "size", - .hash = "modifyTime_size", - }; - asset_ = asset; -} - -void ObjectAssetLoaderTest::TearDown() {} - -/** -* @tc.name: UploadTest001 -* @tc.desc: Transfer test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, UploadTest001, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - auto result = assetLoader->Transfer(userId_, bundleName_, deviceId_, asset_); - ASSERT_EQ(result, false); -} - -/** -* @tc.name: TransferAssetsAsync001 -* @tc.desc: TransferAssetsAsync test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, TransferAssetsAsync001, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - std::function lambdaFunc = [](bool success) { - if (success) {} - }; - std::vector assets{ asset_ }; - ASSERT_EQ(assetLoader->executors_, nullptr); - assetLoader->TransferAssetsAsync(userId_, bundleName_, deviceId_, assets, lambdaFunc); -} - -/** -* @tc.name: TransferAssetsAsync002 -* @tc.desc: TransferAssetsAsync test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, TransferAssetsAsync002, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - std::function lambdaFunc = [](bool success) { - if (success) {} - }; - std::vector assets{ asset_ }; - std::shared_ptr executors = std::make_shared(5, 3); - ASSERT_NE(executors, nullptr); - assetLoader->SetThreadPool(executors); - ASSERT_NE(assetLoader->executors_, nullptr); - assetLoader->TransferAssetsAsync(userId_, bundleName_, deviceId_, assets, lambdaFunc); -} - -/** -* @tc.name: FinishTask001 -* @tc.desc: FinishTask test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, FinishTask001, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - ASSERT_NE(assetLoader, nullptr); - TransferTask task; - task.downloadAssets.insert(uri_); - assetLoader->FinishTask(asset_.uri, true); - ASSERT_TRUE(assetLoader->tasks_.Empty()); - assetLoader->FinishTask(asset_.uri, false); - ASSERT_TRUE(assetLoader->tasks_.Empty()); -} - -/** -* @tc.name: IsDownloading001 -* @tc.desc: IsDownloading test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, IsDownloading001, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - assetLoader->downloading_.InsertOrAssign(asset_.uri, asset_.hash); - auto result = assetLoader->IsDownloading(asset_); - ASSERT_EQ(result, true); - assetLoader->downloading_.Erase(asset_.uri); - result = assetLoader->IsDownloading(asset_); - ASSERT_EQ(result, false); -} - -/** -* @tc.name: IsDownloaded001 -* @tc.desc: IsDownloaded test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, IsDownloaded001, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - auto result = assetLoader->IsDownloaded(asset_); - ASSERT_EQ(result, false); - assetLoader->downloaded_.Insert(asset_.uri, "modifyTime_size"); - result = assetLoader->IsDownloaded(asset_); - ASSERT_EQ(result, true); -} - -/** -* @tc.name: UpdateDownloaded001 -* @tc.desc: UpdateDownloaded test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, UpdateDownloaded001, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - ASSERT_NE(assetLoader, nullptr); - while (!assetLoader->assetQueue_.empty()) { - assetLoader->assetQueue_.pop(); - } - assetLoader->UpdateDownloaded(asset_); - auto [success, hash] = assetLoader->downloaded_.Find(asset_.uri); - ASSERT_TRUE(success); - EXPECT_EQ(hash, asset_.hash); -} - -/** -* @tc.name: UpdateDownloaded002 -* @tc.desc: UpdateDownloaded test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectAssetLoaderTest, UpdateDownloaded002, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - ASSERT_NE(assetLoader, nullptr); - while (!assetLoader->assetQueue_.empty()) { - assetLoader->assetQueue_.pop(); - } - for (int i = 0; i <= assetLoader->LAST_DOWNLOAD_ASSET_SIZE; i++) { - assetLoader->assetQueue_.push(asset_.uri); - } - assetLoader->UpdateDownloaded(asset_); - EXPECT_NE(assetLoader->assetQueue_.size(), ObjectAssetLoader::LAST_DOWNLOAD_ASSET_SIZE); - EXPECT_EQ(assetLoader->assetQueue_.size(), ObjectAssetLoader::LAST_DOWNLOAD_ASSET_SIZE + 1); - auto [success, hash] = assetLoader->downloaded_.Find(asset_.uri); - EXPECT_EQ(success, false); - EXPECT_EQ(hash, ""); -} - -/** -* @tc.name: PushAsset001 -* @tc.desc: PushAsset test. -* @tc.type: FUNC -*/ -HWTEST_F(ObjectAssetLoaderTest, PushAsset001, TestSize.Level0) -{ - auto assetLoader = ObjectAssetLoader::GetInstance(); - ASSERT_NE(assetLoader, nullptr); - sptr assetObj = new AssetObj(); - assetObj->dstBundleName_ = bundleName_; - assetObj->srcBundleName_ = bundleName_; - assetObj->dstNetworkId_ = "1"; - assetObj->sessionId_ = "123"; - - sptr sendCallback = new ObjectAssetsSendListener(); - ASSERT_NE(sendCallback, nullptr); - int32_t ret = assetLoader->PushAsset(userId_, assetObj, sendCallback); - EXPECT_NE(ret, DistributedObject::OBJECT_SUCCESS); -} - -/** -* @tc.name: OnSendResult001 -* @tc.desc: OnSendResult test. -* @tc.type: FUNC -*/ -HWTEST_F(ObjectAssetLoaderTest, OnSendResult001, TestSize.Level1) -{ - sptr assetObj = nullptr; - - int32_t result = -1; - sptr sendCallback = new ObjectAssetsSendListener(); - int32_t ret = sendCallback->OnSendResult(assetObj, result); - EXPECT_EQ(ret, result); - - assetObj = new AssetObj(); - assetObj->dstBundleName_ = bundleName_; - assetObj->srcBundleName_ = bundleName_; - assetObj->dstNetworkId_ = "1"; - assetObj->sessionId_ = "123"; - - ret = sendCallback->OnSendResult(assetObj, result); - EXPECT_EQ(ret, result); - - result = 0; - ret = sendCallback->OnSendResult(assetObj, result); - EXPECT_EQ(ret, result); -} -} // namespace OHOS::Test diff --git a/services/distributeddataservice/service/test/object_asset_machine_test.cpp b/services/distributeddataservice/service/test/object_asset_machine_test.cpp index 1f09e90d6afe091208bac6780879060afa580b36..35a6b8781417ef8b356f684bd78e693ac468d894 100644 --- a/services/distributeddataservice/service/test/object_asset_machine_test.cpp +++ b/services/distributeddataservice/service/test/object_asset_machine_test.cpp @@ -20,7 +20,7 @@ #include #include "executor_pool.h" -#include "object_asset_loader.h" +#include "object_asset_delegate.h" #include "snapshot/machine_status.h" using namespace testing::ext; @@ -78,7 +78,7 @@ void ObjectAssetMachineTest::SetUp() if (machine == nullptr) { machine = std::make_shared(); auto executors = std::make_shared(2, 1); - ObjectAssetLoader::GetInstance()->SetThreadPool(executors); + ObjectAssetDelegate::GetInstance()->SetThreadPool(executors); } } @@ -198,7 +198,7 @@ HWTEST_F(ObjectAssetMachineTest, StatusUpload001, TestSize.Level0) ASSERT_EQ(changedAssets_[uri_].status, STATUS_STABLE); // dotransfer machine->DFAPostEvent(REMOTE_CHANGED, changedAssets_[uri_], asset, changedAsset); - ASSERT_EQ(changedAssets_[uri_].status, STATUS_TRANSFERRING); + ASSERT_EQ(changedAssets_[uri_].status, STATUS_STABLE); } /** @@ -244,7 +244,7 @@ HWTEST_F(ObjectAssetMachineTest, StatusUpload002, TestSize.Level0) ASSERT_EQ(changedAssetInfo.asset.hash, asset.hash); machine->DFAPostEvent(UPLOAD_FINISHED, changedAssetInfo, asset); - ASSERT_EQ(changedAssetInfo.status, STATUS_TRANSFERRING); + ASSERT_EQ(changedAssetInfo.status, STATUS_STABLE); } /** diff --git a/services/distributeddataservice/service/test/object_manager_test.cpp b/services/distributeddataservice/service/test/object_manager_test.cpp index 835dca5b618de16032826ec1644ba2ec994ca94e..68e4658550fff4abb72a3f099323d97fd88cdfeb 100644 --- a/services/distributeddataservice/service/test/object_manager_test.cpp +++ b/services/distributeddataservice/service/test/object_manager_test.cpp @@ -841,26 +841,6 @@ HWTEST_F(ObjectManagerTest, GetAssetsFromDBRecords002, TestSize.Level0) EXPECT_EQ(assets[0].hash, "(string)test_(string)test"); } -/** -* @tc.name: RegisterAssetsLister001 -* @tc.desc: RegisterAssetsLister test. -* @tc.type: FUNC -* @tc.require: -* @tc.author: wangbin -*/ -HWTEST_F(ObjectManagerTest, RegisterAssetsLister001, TestSize.Level0) -{ - auto manager = ObjectStoreManager::GetInstance(); - manager->objectAssetsSendListener_ = nullptr; - manager->objectAssetsRecvListener_ = nullptr; - auto result = manager->RegisterAssetsLister(); - ASSERT_EQ(result, true); - manager->objectAssetsSendListener_ = new ObjectAssetsSendListener(); - manager->objectAssetsRecvListener_ = new ObjectAssetsRecvListener();; - result = manager->RegisterAssetsLister(); - ASSERT_EQ(result, true); -} - /** * @tc.name: PushAssets001 * @tc.desc: PushAssets test. @@ -906,14 +886,8 @@ HWTEST_F(ObjectManagerTest, PushAssets002, TestSize.Level0) data.insert({assetPrefix + ObjectStore::SIZE_SUFFIX, value}); data.insert({fieldsPrefix + deviceIdKey, value}); - manager->objectAssetsSendListener_ = nullptr; int32_t ret = manager->PushAssets(appId_, appId_, sessionId_, data, deviceId_); EXPECT_NE(ret, DistributedObject::OBJECT_SUCCESS); - - manager->objectAssetsSendListener_ = new ObjectAssetsSendListener(); - ASSERT_NE(manager->objectAssetsSendListener_, nullptr); - ret = manager->PushAssets(appId_, appId_, sessionId_, data, deviceId_); - EXPECT_NE(ret, DistributedObject::OBJECT_SUCCESS); } /** @@ -965,29 +939,6 @@ HWTEST_F(ObjectManagerTest, BindAsset001, TestSize.Level0) ASSERT_EQ(result, DistributedObject::OBJECT_DBSTATUS_ERROR); } -/** -* @tc.name: OnFinished001 -* @tc.desc: OnFinished test. -* @tc.type: FUNC -*/ -HWTEST_F(ObjectManagerTest, OnFinished001, TestSize.Level1) -{ - std::string srcNetworkId = "srcNetworkId"; - sptr assetObj = nullptr; - int32_t result = 100; - ObjectAssetsRecvListener listener; - int32_t ret = listener.OnFinished(srcNetworkId, assetObj, result); - EXPECT_NE(ret, DistributedObject::OBJECT_SUCCESS); - - sptr assetObj_1 = new AssetObj(); - assetObj_1->dstBundleName_ = bundleName_; - assetObj_1->srcBundleName_ = bundleName_; - assetObj_1->dstNetworkId_ = "1"; - assetObj_1->sessionId_ = "123"; - ret = listener.OnFinished(srcNetworkId, assetObj_1, result); - EXPECT_EQ(ret, DistributedObject::OBJECT_SUCCESS); -} - /** * @tc.name: GetObjectData001 * @tc.desc: GetObjectData test.