diff --git a/old/services/core/src/authority/trust_group_manager.cpp b/old/services/core/src/authority/trust_group_manager.cpp index 14058ba9b22e3119a460cb0fb81c8326292d9dbd..31c920f44fa8f953dffb778bb62dd435638c281f 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 86e13eb3dd7b2506400255be819f2cc243858f54..6792235b367d4ee1606bf28ec95264f0ab7a6c7d 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 56a2cd1ac83bd0528b8d8767a253fb1213ff6ab0..6138571c13a0cb922bd521678e10160aa4d59770 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 dc9059df23b46efe8a5a8111e2c46624df2e1c3e..5fe340d26d6581aa605894e82e1714b4c021cd90 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;