diff --git a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h index 8ce850102bca057d79c079cb94e693f9140d97e3..36e9df94f0da1aaa2848c19531b13a462dae3fc9 100644 --- a/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h +++ b/frameworks/libs/distributeddb/interfaces/include/kv_store_nb_delegate.h @@ -45,7 +45,7 @@ public: std::string schema = ""; bool createDirByStoreIdOnly = false; SecurityOption secOption; // Add data security level parameter - std::weak_ptr observer; + std::shared_ptr observer; Key key; // The key that needs to be subscribed on obsever, empty means full subscription unsigned int mode = 0; // obsever mode int conflictType = 0; @@ -137,10 +137,10 @@ public: // synced data changes from remote devices, // local changes of local kv store. DB_API virtual DBStatus RegisterObserver(const Key &key, unsigned int mode, - const std::weak_ptr &observer) = 0; + std::shared_ptr observer) = 0; // UnRegister the registered observer. - DB_API virtual DBStatus UnRegisterObserver(const std::weak_ptr &observer) = 0; + DB_API virtual DBStatus UnRegisterObserver(std::shared_ptr observer) = 0; // Remove the device data synced from remote. DB_API virtual DBStatus RemoveDeviceData(const std::string &device) = 0; diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp index 34eb25b6e8493aa1532234837e805e85e9a946c5..c092868d9a269de93d29ab8e060717ceaf077284 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp @@ -128,8 +128,8 @@ bool CheckObserverConflictParam(const KvStoreNbDelegate::Option &option) LOGE("Invalid conflict type, conflict type is [%d]", option.conflictType); return false; } - if ((option.observer.lock() != nullptr && !ParamCheckUtils::CheckObserver(option.key, option.mode)) || - (option.observer.lock() == nullptr && (!option.key.empty() || option.mode != 0))) { + if ((option.observer != nullptr && !ParamCheckUtils::CheckObserver(option.key, option.mode)) || + (option.observer == nullptr && (!option.key.empty() || option.mode != 0))) { LOGE("Invalid observer param, observer mode is [%u]", option.mode); return false; } @@ -236,7 +236,7 @@ DBStatus KvStoreDelegateManager::SetObserverNotifier( KvStoreNbDelegate *kvStore, const KvStoreNbDelegate::Option &option) { DBStatus status; - if (option.observer.lock() != nullptr) { + if (option.observer != nullptr) { status = kvStore->RegisterObserver(option.key, option.mode, option.observer); if (status != OK) { LOGE("[KvStoreMgr] RegisterObserver failed."); diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp index aa2c806a6e638f74f7f1b64e5ae67feed1850ce8..f5b5b6ce2d2a9c1811b95681c100b2cfde54c2ab 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.cpp @@ -371,12 +371,12 @@ DBStatus KvStoreNbDelegateImpl::DeleteLocalBatch(const std::vector &keys) } DBStatus KvStoreNbDelegateImpl::RegisterObserver(const Key &key, unsigned int mode, - const std::weak_ptr &observer) + std::shared_ptr observer) { if (key.size() > DBConstant::MAX_KEY_SIZE) { return INVALID_ARGS; } - if (observer.lock() == nullptr) { + if (observer == nullptr) { LOGE("[KvStoreNbDelegate][RegisterObserver] Observer is null"); return INVALID_ARGS; } @@ -393,7 +393,7 @@ DBStatus KvStoreNbDelegateImpl::RegisterObserver(const Key &key, unsigned int mo } DBStatus KvStoreNbDelegateImpl::CheckDeviceObserver(const Key &key, unsigned int mode, - const std::weak_ptr &observer) + const std::shared_ptr &observer) { if (!ParamCheckUtils::CheckObserver(key, mode)) { LOGE("[KvStoreNbDelegate][CheckDeviceObserver] Register nb observer by illegal mode or key size!"); @@ -413,7 +413,7 @@ DBStatus KvStoreNbDelegateImpl::CheckDeviceObserver(const Key &key, unsigned int } DBStatus KvStoreNbDelegateImpl::RegisterDeviceObserver(const Key &key, unsigned int mode, - const std::weak_ptr &observer) + const std::shared_ptr &observer) { if (conn_->IsTransactionStarted()) { LOGE("[KvStoreNbDelegate][RegisterDeviceObserver] Transaction unfinished"); @@ -428,12 +428,13 @@ DBStatus KvStoreNbDelegateImpl::RegisterDeviceObserver(const Key &key, unsigned int errCode = E_OK; auto storeId = storeId_; + std::weak_ptr wkPtr = observer; KvDBObserverHandle *observerHandle = conn_->RegisterObserver( mode, key, - [observer, storeId](const KvDBCommitNotifyData ¬ifyData) { + [wkPtr, storeId](const KvDBCommitNotifyData ¬ifyData) { KvStoreChangedDataImpl data(¬ifyData); LOGD("[KvStoreNbDelegate][RegisterDeviceObserver] Trigger on change"); - if (auto observerPtr = observer.lock()) { + if (auto observerPtr = wkPtr.lock()) { observerPtr->OnChange(data); } else { LOGW("[KvStoreNbDelegate][RegisterDeviceObserver] observer released"); @@ -452,7 +453,7 @@ DBStatus KvStoreNbDelegateImpl::RegisterDeviceObserver(const Key &key, unsigned return OK; } -DBStatus KvStoreNbDelegateImpl::CheckCloudObserver(const std::weak_ptr &observer) +DBStatus KvStoreNbDelegateImpl::CheckCloudObserver(const std::shared_ptr &observer) { if (cloudObserverMap_.size() >= DBConstant::MAX_OBSERVER_COUNT) { LOGE("[KvStoreNbDelegate][CheckCloudObserver] The number of kv cloud observers over limit, storeId[%.3s]", @@ -467,7 +468,7 @@ DBStatus KvStoreNbDelegateImpl::CheckCloudObserver(const std::weak_ptr &observer) + const std::shared_ptr &observer) { std::lock_guard lockGuard(observerMapLock_); DBStatus status = CheckCloudObserver(observer); @@ -477,11 +478,12 @@ DBStatus KvStoreNbDelegateImpl::RegisterCloudObserver(const Key &key, unsigned i } auto storeId = storeId_; - ObserverAction action = [observer, storeId]( + std::weak_ptr wkPtr = observer; + ObserverAction action = [wkPtr, storeId]( const std::string &device, ChangedData &&changedData, bool isChangedData) { if (isChangedData) { LOGD("[KvStoreNbDelegate][RegisterCloudObserver] Trigger on change"); - if (auto observerPtr = observer.lock()) { + if (auto observerPtr = wkPtr.lock()) { observerPtr->OnChange(Origin::ORIGIN_CLOUD, device, std::move(changedData)); } else { LOGW("[KvStoreNbDelegate][RegisterCloudObserver] observer released"); @@ -498,9 +500,9 @@ DBStatus KvStoreNbDelegateImpl::RegisterCloudObserver(const Key &key, unsigned i return OK; } -DBStatus KvStoreNbDelegateImpl::UnRegisterObserver(const std::weak_ptr &observer) +DBStatus KvStoreNbDelegateImpl::UnRegisterObserver(std::shared_ptr observer) { - if (observer.lock() == nullptr) { + if (observer == nullptr) { return INVALID_ARGS; } @@ -517,7 +519,7 @@ DBStatus KvStoreNbDelegateImpl::UnRegisterObserver(const std::weak_ptr &observer) +DBStatus KvStoreNbDelegateImpl::UnRegisterDeviceObserver(const std::shared_ptr &observer) { std::lock_guard lockGuard(observerMapLock_); auto iter = observerMap_.find(observer); @@ -536,7 +538,7 @@ DBStatus KvStoreNbDelegateImpl::UnRegisterDeviceObserver(const std::weak_ptr &observer) +DBStatus KvStoreNbDelegateImpl::UnRegisterCloudObserver(const std::shared_ptr &observer) { std::lock_guard lockGuard(observerMapLock_); auto iter = cloudObserverMap_.find(observer); diff --git a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h index ef8c4ac91ed6b02b316a037102984d0da748dbf6..b7857fc221af30f1734f3086c1a776c6fd6802eb 100644 --- a/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h +++ b/frameworks/libs/distributeddb/interfaces/src/kv_store_nb_delegate_impl.h @@ -74,9 +74,9 @@ public: // Observer interfaces DBStatus RegisterObserver(const Key &key, unsigned int mode, - const std::weak_ptr &observer) override; + std::shared_ptr observer) override; - DBStatus UnRegisterObserver(const std::weak_ptr &observer) override; + DBStatus UnRegisterObserver(std::shared_ptr observer) override; DBStatus RemoveDeviceData(const std::string &device) override; @@ -219,17 +219,18 @@ private: void OnDeviceSyncProcess(const std::map &processMap, const DeviceSyncProcessCallback &onProcess) const; - DBStatus RegisterDeviceObserver(const Key &key, unsigned int mode, const std::weak_ptr &observer); + DBStatus RegisterDeviceObserver(const Key &key, unsigned int mode, + const std::shared_ptr &observer); - DBStatus RegisterCloudObserver(const Key &key, unsigned int mode, const std::weak_ptr &observer); + DBStatus RegisterCloudObserver(const Key &key, unsigned int mode, const std::shared_ptr &observer); - DBStatus UnRegisterDeviceObserver(const std::weak_ptr &observer); + DBStatus UnRegisterDeviceObserver(const std::shared_ptr &observer); - DBStatus UnRegisterCloudObserver(const std::weak_ptr &observer); + DBStatus UnRegisterCloudObserver(const std::shared_ptr &observer); - DBStatus CheckDeviceObserver(const Key &key, unsigned int mode, const std::weak_ptr &observer); + DBStatus CheckDeviceObserver(const Key &key, unsigned int mode, const std::shared_ptr &observer); - DBStatus CheckCloudObserver(const std::weak_ptr &observer); + DBStatus CheckCloudObserver(const std::shared_ptr &observer); IKvDBConnection *conn_; std::string storeId_; diff --git a/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h b/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h index c01dd6635087008cecc060f067435a95791f9100..a432cbd91e07648a921884cc09aeb98636a3139d 100644 --- a/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h +++ b/frameworks/libs/distributeddb/storage/include/ikvdb_connection.h @@ -153,10 +153,10 @@ public: virtual int32_t GetTaskCount() = 0; - virtual int RegisterObserverAction(const std::weak_ptr &observer, + virtual int RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action) = 0; - virtual int UnRegisterObserverAction(const std::weak_ptr &observer) = 0; + virtual int UnRegisterObserverAction(const std::shared_ptr &observer) = 0; virtual void SetGenCloudVersionCallback(const GenerateCloudVersionCallback &callback) = 0; diff --git a/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.cpp b/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.cpp index 55fe52529627a008fe23cd8520357dc8433a896d..66600bafee5f5ac8b8402b338cffa9ddf044dac7 100644 --- a/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.cpp @@ -410,13 +410,13 @@ int32_t GenericKvDBConnection::GetTaskCount() return 0; } -int GenericKvDBConnection::RegisterObserverAction([[gnu::unused]] const std::weak_ptr &observer, +int GenericKvDBConnection::RegisterObserverAction([[gnu::unused]] const std::shared_ptr &observer, [[gnu::unused]] const ObserverAction &action) { return E_OK; } -int GenericKvDBConnection::UnRegisterObserverAction([[gnu::unused]] const std::weak_ptr &observer) +int GenericKvDBConnection::UnRegisterObserverAction([[gnu::unused]] const std::shared_ptr &observer) { return E_OK; } diff --git a/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.h b/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.h index 78c22a581f48fc5f95fc4ef71361908bf8b34205..6f12c5922b263ddce4522707559cedd8048e81f3 100644 --- a/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.h +++ b/frameworks/libs/distributeddb/storage/src/kv/generic_kvdb_connection.h @@ -95,9 +95,9 @@ public: int32_t GetTaskCount() override; - int RegisterObserverAction(const std::weak_ptr &observer, const ObserverAction &action) override; + int RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action) override; - int UnRegisterObserverAction(const std::weak_ptr &observer) override; + int UnRegisterObserverAction(const std::shared_ptr &observer) override; void SetGenCloudVersionCallback(const GenerateCloudVersionCallback &callback) override; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp index 3ff139f46e29ffcf4218d27426cdfdbc2dd36fc4..6a5dada1e67929f9a0a8c27f3287d9fa166172a8 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.cpp @@ -515,14 +515,14 @@ std::pair SqliteCloudKvStore::GetTr return {db, transactionHandle_}; } -void SqliteCloudKvStore::RegisterObserverAction(const std::weak_ptr &observer, +void SqliteCloudKvStore::RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action) { std::lock_guard autoLock(observerMapMutex_); cloudObserverMap_[observer] = action; } -void SqliteCloudKvStore::UnRegisterObserverAction(const std::weak_ptr &observer) +void SqliteCloudKvStore::UnRegisterObserverAction(const std::shared_ptr &observer) { std::lock_guard autoLock(observerMapMutex_); cloudObserverMap_.erase(observer); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h index 562f2ab0fb446429dd0f8eb7b94d412b9739a06f..9accc25fb2736071a3e2e401fc9ca059a500fce9 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_store.h @@ -91,9 +91,9 @@ public: int SetCloudDbSchema(const std::map &schema); - void RegisterObserverAction(const std::weak_ptr &observer, const ObserverAction &action); + void RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action); - void UnRegisterObserverAction(const std::weak_ptr &observer); + void UnRegisterObserverAction(const std::shared_ptr &observer); int GetCloudVersion(const std::string &device, std::map &versionMap); diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h index b774558ee88bebcb471ebeb26a12ffec5163fca1..e13ca3294965840ca180ae5279940bac5231eab4 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store.h @@ -221,9 +221,9 @@ public: int SetCloudDbSchema(const std::map &schema); - int RegisterObserverAction(const std::weak_ptr &observer, const ObserverAction &action); + int RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action); - int UnRegisterObserverAction(const std::weak_ptr &observer); + int UnRegisterObserverAction(const std::shared_ptr &observer); void SetReceiveDataInterceptor(const DataInterceptor &interceptor) override; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp index 8f640988381d41a46dcacf6add3097d29ec2d17c..2e79c639d728e2ae8abcddde0e9790252fa79402 100755 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.cpp @@ -1933,7 +1933,7 @@ int SQLiteSingleVerNaturalStoreConnection::SetCloudDbSchema(const std::map &observer, +int SQLiteSingleVerNaturalStoreConnection::RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action) { auto naturalStore = GetDB(); @@ -1944,7 +1944,7 @@ int SQLiteSingleVerNaturalStoreConnection::RegisterObserverAction(const std::wea return naturalStore->RegisterObserverAction(observer, action); } -int SQLiteSingleVerNaturalStoreConnection::UnRegisterObserverAction(const std::weak_ptr &observer) +int SQLiteSingleVerNaturalStoreConnection::UnRegisterObserverAction(const std::shared_ptr &observer) { auto naturalStore = GetDB(); if (naturalStore == nullptr) { diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h index db654dbd49a00bfb85c6562266fdc65053a2956c..4dc0a5457c9f6762180a817bf2f219768c4f54db 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_connection.h @@ -106,9 +106,9 @@ public: int UpdateKey(const UpdateKeyCallback &callback) override; - int RegisterObserverAction(const std::weak_ptr &observer, const ObserverAction &action) override; + int RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action) override; - int UnRegisterObserverAction(const std::weak_ptr &observer) override; + int UnRegisterObserverAction(const std::shared_ptr &observer) override; int RemoveDeviceData(const std::string &device, ClearMode mode) override; diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_extend.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_extend.cpp index 14ff900e17c1aab797cfa33959c789e5dc3c4b78..7c39ca31e9c634575cbd5bb455961465ac655484 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_extend.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_single_ver_natural_store_extend.cpp @@ -641,7 +641,7 @@ TimeOffset SQLiteSingleVerNaturalStore::GetLocalTimeOffsetForCloud() return GetLocalTimeOffset(); } -int SQLiteSingleVerNaturalStore::RegisterObserverAction(const std::weak_ptr &observer, +int SQLiteSingleVerNaturalStore::RegisterObserverAction(const std::shared_ptr &observer, const ObserverAction &action) { #ifdef USE_DISTRIBUTEDDB_CLOUD @@ -654,7 +654,7 @@ int SQLiteSingleVerNaturalStore::RegisterObserverAction(const std::weak_ptr &observer) +int SQLiteSingleVerNaturalStore::UnRegisterObserverAction(const std::shared_ptr &observer) { #ifdef USE_DISTRIBUTEDDB_CLOUD std::lock_guard autoLock(cloudStoreMutex_); diff --git a/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/kvdelegatemanager_fuzzer.cpp b/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/kvdelegatemanager_fuzzer.cpp index 3726117ca2b9a31096c1d93dfae294c17c902fde..62d3b8a441d70e5e920323f27211f937b7c8deca 100644 --- a/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/kvdelegatemanager_fuzzer.cpp +++ b/frameworks/libs/distributeddb/test/fuzztest/kvdelegatemanager_fuzzer/kvdelegatemanager_fuzzer.cpp @@ -75,6 +75,90 @@ void CallbackFuzz(FuzzedDataProvider &fdp, std::string storeId) KvStoreDelegateManager::NotifyUserChanged(); } +<<<<<<< HEAD +======= +void SetStoreStatusNotifierV2Fuzz(FuzzedDataProvider &fdp) +{ + StoreStatusNotifierParam param; + param.userId = fdp.ConsumeRandomLengthString(); + param.appId = fdp.ConsumeRandomLengthString(); + param.storeId = fdp.ConsumeRandomLengthString(); + param.subUserId = fdp.ConsumeRandomLengthString(); + param.deviceId = fdp.ConsumeRandomLengthString(); + bool isCheckOk = false; + auto databaseStatusNotifyCallbackV2 = [&](const StoreStatusNotifierParam ¬ifierParam, + bool onLineStatus) -> void { + if (param.userId == notifierParam.userId && param.appId == notifierParam.appId && + param.storeId == notifierParam.storeId && param.deviceId == notifierParam.deviceId && + onLineStatus == true) { + isCheckOk = true; + } + }; + g_mgr.SetStoreStatusNotifier(databaseStatusNotifyCallbackV2); +} + +CipherPassword GetPassWord(FuzzedDataProvider &fdp) +{ + CipherPassword passwd; + size_t size = fdp.ConsumeIntegralInRange(0, PASSWDLEN); + uint8_t *val = static_cast(new uint8_t[size]); + fdp.ConsumeData(val, size); + passwd.SetValue(val, size); + delete[] static_cast(val); + val = nullptr; + return passwd; +} + +void SetAutoLaunchFuzz(FuzzedDataProvider &fdp) +{ + int securityLabel = fdp.ConsumeIntegralInRange(SecurityLabel::INVALID_SEC_LABEL, SecurityLabel::S4); + int securityFlag = fdp.ConsumeIntegralInRange(SecurityFlag::INVALID_SEC_FLAG, SecurityFlag::SECE); + AutoLaunchOption option = { + .createIfNecessary = fdp.ConsumeBool(), + .isEncryptedDb = fdp.ConsumeBool(), + .cipher = static_cast(fdp.ConsumeIntegralInRange(MIN_CIPHER_TYPE, MAX_CIPHER_TYPE)), + .passwd = GetPassWord(fdp), + .schema = fdp.ConsumeRandomLengthString(), + .createDirByStoreIdOnly = fdp.ConsumeBool(), + .dataDir = fdp.ConsumeRandomLengthString(), + .conflictType = fdp.ConsumeIntegral(), + .notifier = nullptr, + .secOption = {static_cast(securityLabel), static_cast(securityFlag)}, + .isNeedIntegrityCheck = fdp.ConsumeBool(), + .isNeedRmCorruptedDb = fdp.ConsumeBool(), + .isNeedCompressOnSync = fdp.ConsumeBool(), + .compressionRate = fdp.ConsumeIntegralInRange(MIN_COUNT, MAX_COMPRESSION_RATE), + .isAutoSync = fdp.ConsumeBool(), + .storeObserver = nullptr, + .syncDualTupleMode = fdp.ConsumeBool(), + .iterateTimes = fdp.ConsumeIntegral(), + .conflictResolvePolicy = fdp.ConsumeIntegralInRange(MIN_POLICY, MAX_POLICY), + .tableMode = static_cast(fdp.ConsumeIntegralInRange(MIN_MODE, MAX_MODE)), + }; + std::string appId = fdp.ConsumeRandomLengthString(); + std::string userId = fdp.ConsumeRandomLengthString(); + std::string storeId = fdp.ConsumeRandomLengthString(); + const AutoLaunchParam encryptedParam = { + .userId = fdp.ConsumeRandomLengthString(), + .appId = fdp.ConsumeRandomLengthString(), + .storeId = fdp.ConsumeRandomLengthString(), + .option = option, + .notifier = nullptr, + .path = fdp.ConsumeRandomLengthString(), + .subUser = fdp.ConsumeRandomLengthString(), + }; + std::string id = g_mgr.GetKvStoreIdentifier(userId, appId, storeId); + const AutoLaunchRequestCallback callback = [&](const std::string &identifier, AutoLaunchParam ¶m) { + if (id != identifier) { + return false; + } + param = encryptedParam; + return true; + }; + g_mgr.SetAutoLaunchRequestCallback(callback); +} + +>>>>>>> 078f60bcc (observer入参类型调整为智能指针,检视) void CombineTest(FuzzedDataProvider &fdp) { LOGD("Begin KvDelegateManagerFuzzer"); diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h index 03eaf49aab4a7cf7ec35bdadbedf2ba604ff1483..cb78b530b9af61a8302948abd17acc06c55e4900 100644 --- a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/include/distributeddb_nb_test_tools.h @@ -47,7 +47,7 @@ struct Option { #endif // endif of RELEASE_MODE_V2 #ifdef RELEASE_MODE_V3 DistributedDB::SecurityOption secOption; - std::weak_ptr observer; + std::shared_ptr observer; DistributedDB::Key key; unsigned int mode = 0; int conflictType = 0; @@ -67,7 +67,7 @@ struct Option { #ifdef RELEASE_MODE_V3 Option(bool createIfNecessary, bool isMemoryDb, bool isEncryptedDb, const DistributedDB::CipherType &cipher, const std::vector &passwd, const DistributedDB::SecurityOption &secOption, - const std::weak_ptr &observer, + std::shared_ptr observer, const DistributedDB::KvStoreNbConflictNotifier ¬ifier) : createIfNecessary(createIfNecessary), isMemoryDb(isMemoryDb), isEncryptedDb(isEncryptedDb), cipher(cipher), passwd(passwd), secOption(secOption), observer(observer), notifier(notifier) @@ -233,10 +233,10 @@ public: static DistributedDB::DBStatus RegisterObserver(DistributedDB::KvStoreNbDelegate &kvStoreNbDelegate, const DistributedDB::Key &key, unsigned int mode, - const std::weak_ptr &observer); + std::shared_ptr observer); static DistributedDB::DBStatus UnRegisterObserver(DistributedDB::KvStoreNbDelegate &kvStoreNbDelegate, - const std::weak_ptr &observer); + std::shared_ptr observer); static bool CloseNbAndRelease(DistributedDB::KvStoreDelegateManager *&manager, DistributedDB::KvStoreNbDelegate *&delegate); static bool ModifyDatabaseFile(const std::string &fileDir); diff --git a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_nb_test_tools.cpp b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_nb_test_tools.cpp index e252902fc366d8d0ec6a02b1cfb2d8218fa8c98e..c38db02870fbb7a762a2cdd5e95db71f82daee7e 100644 --- a/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_nb_test_tools.cpp +++ b/frameworks/libs/distributeddb/test/moduletest/common/distributeddb/src/distributeddb_nb_test_tools.cpp @@ -443,13 +443,13 @@ DistributedDB::DBStatus DistributedDBNbTestTools::DeleteLocalBatch(DistributedDB } DistributedDB::DBStatus DistributedDBNbTestTools::RegisterObserver(DistributedDB::KvStoreNbDelegate &kvStoreNbDelegate, - const DistributedDB::Key &key, unsigned int mode, const std::weak_ptr &observer) + const DistributedDB::Key &key, unsigned int mode, std::shared_ptr observer) { return kvStoreNbDelegate.RegisterObserver(key, mode, observer); } DistributedDB::DBStatus DistributedDBNbTestTools::UnRegisterObserver( - DistributedDB::KvStoreNbDelegate &kvStoreNbDelegate, const std::weak_ptr &observer) + DistributedDB::KvStoreNbDelegate &kvStoreNbDelegate, std::shared_ptr observer) { return kvStoreNbDelegate.UnRegisterObserver(observer); } diff --git a/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_observer_test.cpp b/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_observer_test.cpp index 5aee191f9c258aac00be8d0426941156dc4216e0..d4e9424af7243fe8bd7d012e622433d43296f1bf 100644 --- a/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_observer_test.cpp +++ b/frameworks/libs/distributeddb/test/moduletest/src/distributeddb_nb_observer_test.cpp @@ -1058,7 +1058,7 @@ HWTEST_F(DistributeddbNbObserverTest, Pressure004, TestSize.Level1) * @tc.steps: step1. UnRegister nullpter. * @tc.expected: step1. it will be failed to unregister nullptr and return INVALID_ARGS. */ - std::weak_ptr observer; + std::shared_ptr observer; DBStatus status = g_nbObserverDelegate->UnRegisterObserver(observer); EXPECT_EQ(status, INVALID_ARGS); diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_single_version_result_set_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_single_version_result_set_test.cpp index 5aecebb72d27a2e6c825a81c54b680c2b73264ec..5faec617ece177e091c5051ad4960a93af43ab24 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_single_version_result_set_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_single_version_result_set_test.cpp @@ -563,7 +563,7 @@ HWTEST_F(DistributedDBInterfacesSingleVersionResultSetTest, SingleVerNaturalStor std::map versionMap; EXPECT_EQ(storeObj.GetCloudVersion("", versionMap), -E_INTERNAL_ERROR); #endif - std::weak_ptr observer; + std::shared_ptr observer; EXPECT_EQ(storeObj.UnRegisterObserverAction(observer), -E_INTERNAL_ERROR); ObserverAction action; EXPECT_EQ(storeObj.RegisterObserverAction(observer, action), -E_INTERNAL_ERROR);