From 134f10f640f7c587f21984c490ebd614e38449a4 Mon Sep 17 00:00:00 2001 From: chenshuo Date: Fri, 12 Jul 2024 11:09:38 +0800 Subject: [PATCH] =?UTF-8?q?DP=E6=A3=80=E8=A7=86=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenshuo --- .../src/authority/trust_group_manager.cpp | 4 +++ .../contentsensor/content_sensor_manager.cpp | 4 +-- .../device_profile_storage_manager.cpp | 29 +++++++++++++++---- .../core/src/dbstorage/sync_coordinator.cpp | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/old/services/core/src/authority/trust_group_manager.cpp b/old/services/core/src/authority/trust_group_manager.cpp index 14058ba9..31c920f4 100644 --- a/old/services/core/src/authority/trust_group_manager.cpp +++ b/old/services/core/src/authority/trust_group_manager.cpp @@ -78,6 +78,10 @@ bool TrustGroupManager::InitHichainService() void TrustGroupManager::InitDataChangeListener() { dataChangeListener_.onDeviceUnBound = OnDeviceUnBoundAdapter; + if (hichainGmInstance_ == nullptr) { + HILOGE("hichainGmInstance_ is nullptr"); + return; + } if (hichainGmInstance_->regDataChangeListener(AUTH_APPID.c_str(), &dataChangeListener_) != 0) { HILOGE("auth RegDataChangeListener failed"); } diff --git a/old/services/core/src/contentsensor/content_sensor_manager.cpp b/old/services/core/src/contentsensor/content_sensor_manager.cpp index 86e13eb3..6792235b 100644 --- a/old/services/core/src/contentsensor/content_sensor_manager.cpp +++ b/old/services/core/src/contentsensor/content_sensor_manager.cpp @@ -52,13 +52,13 @@ bool ContentSensorManager::Collect() HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_CONTENT_SENSOR_TRACE); for (auto& task : taskList) { ServiceCharacteristicProfile profileData; - if (!task->ConvertToProfileData(profileData)) { + if (task == nullptr || !task->ConvertToProfileData(profileData)) { continue; } task->DoCollect(profileData); } }; - if (!csCollectorHandler_->PostTask(csTask)) { + if (csCollectorHandler_ == nullptr || !csCollectorHandler_->PostTask(csTask)) { HILOGE("post task failed"); return false; } diff --git a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp b/old/services/core/src/dbstorage/device_profile_storage_manager.cpp index 56a2cd1a..6138571c 100644 --- a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp +++ b/old/services/core/src/dbstorage/device_profile_storage_manager.cpp @@ -256,7 +256,10 @@ void DeviceProfileStorageManager::SetServiceType(const std::string& udid, } return; } - + if (onlineSyncTbl_ == nullptr) { + HILOGE("onlineSyncTbl is nullptr"); + return; + } std::string value; std::string key = GenerateKey(udid, SERVICES, KeyType::SERVICE_LIST); int32_t result = onlineSyncTbl_->GetDeviceProfile(key, value); @@ -329,7 +332,7 @@ int32_t DeviceProfileStorageManager::DeleteDeviceProfile(const std::string& serv int32_t DeviceProfileStorageManager::RemoveUnBoundDeviceProfile(const std::string& udid) { - if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { + if (onlineSyncTbl_ == nullptr || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { HILOGE("kvstore init failed"); return ERR_DP_INIT_DB_FAILED; } @@ -354,7 +357,7 @@ int32_t DeviceProfileStorageManager::RemoveUnBoundDeviceProfile(const std::strin int32_t DeviceProfileStorageManager::RemoveRemoteDeviceProfile() { - if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { + if (onlineSyncTbl_ == nullptr || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { HILOGE("kvstore init failed"); return ERR_DP_INIT_DB_FAILED; } @@ -477,7 +480,9 @@ bool DeviceProfileStorageManager::CheckSyncOption(const SyncOptions& syncOptions DpDeviceManager::GetInstance().GetDeviceList(onlineDevices); std::list onlineDeviceIds; for (const auto& onlineDevice : onlineDevices) { - onlineDeviceIds.emplace_back(onlineDevice->GetNetworkId()); + if (onlineDevice != nullptr) { + onlineDeviceIds.emplace_back(onlineDevice->GetNetworkId()); + } } // check whether deviceId is online @@ -509,6 +514,10 @@ void DeviceProfileStorageManager::FlushProfileItems() { std::string services; std::string servicesKey = GenerateKey(localUdid_, SERVICES, KeyType::SERVICE_LIST); + if (onlineSyncTbl_ == nullptr) { + HILOGE("onlineSyncTbl is nullptr"); + return; + } int32_t errCode = onlineSyncTbl_->GetDeviceProfile(servicesKey, services); std::unique_lock autoLock(serviceLock_); if (errCode == ERR_OK) { @@ -543,11 +552,11 @@ void DeviceProfileStorageManager::RegisterCallbacks() { HILOGI("called"); int32_t errCode = ERR_OK; - if (kvStoreObserver_ != nullptr) { + if (onlineSyncTbl_ != nullptr && kvStoreObserver_ != nullptr) { errCode = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_); HILOGI("SubscribeKvStore errCode = %{public}d", errCode); } - if (kvStoreSyncCallback_ != nullptr) { + if (onlineSyncTbl_ != nullptr && kvStoreSyncCallback_ != nullptr) { errCode = onlineSyncTbl_->RegisterSyncCallback(kvStoreSyncCallback_); HILOGI("RegisterSyncCallback errCode = %{public}d", errCode); } @@ -573,6 +582,10 @@ int32_t DeviceProfileStorageManager::UnSubscribeKvStore(const std::shared_ptr autoLock(callbackLock_); kvStoreObserver_ = nullptr; + if (onlineSyncTbl_ == nullptr) { + HILOGE("onlineSyncTbl is nullptr"); + return ERR_DP_INVALID_PARAMS; + } return onlineSyncTbl_->UnSubscribeKvStore(observer); } @@ -590,6 +603,10 @@ int32_t DeviceProfileStorageManager::UnRegisterSyncCallback() { std::lock_guard autoLock(callbackLock_); kvStoreSyncCallback_ = nullptr; + if (onlineSyncTbl_ == nullptr) { + HILOGE("onlineSyncTbl is nullptr"); + return ERR_DP_INVALID_PARAMS; + } return onlineSyncTbl_->UnRegisterSyncCallback(); } diff --git a/old/services/core/src/dbstorage/sync_coordinator.cpp b/old/services/core/src/dbstorage/sync_coordinator.cpp index dc9059df..5fe340d2 100644 --- a/old/services/core/src/dbstorage/sync_coordinator.cpp +++ b/old/services/core/src/dbstorage/sync_coordinator.cpp @@ -70,7 +70,7 @@ bool SyncCoordinator::IsOnlineSync() bool SyncCoordinator::DispatchSyncTask(const SyncTask& syncTask, int64_t delayTime) { - if (!syncHandler_->PostTask(syncTask, delayTime)) { + if (syncHandler_ == nullptr || !syncHandler_->PostTask(syncTask, delayTime)) { HILOGE("post task failed"); isOnSync_ = false; return false; -- Gitee