diff --git a/conf/config.json b/conf/config.json index 8226a69be..d369e3707 100644 --- a/conf/config.json +++ b/conf/config.json @@ -37,13 +37,7 @@ } ], "distrusts": [], - "switches": [ - { - "bundleName": "distributed_device_profile_service", - "appId": "distributed_device_profile_service", - "checker": "SystemChecker" - } - ] + "switches": [] }, "networks": { "chains": [ diff --git a/services/distributeddataservice/adapter/communicator/src/communicator_context.cpp b/services/distributeddataservice/adapter/communicator/src/communicator_context.cpp index cace1d847..691b0aed2 100644 --- a/services/distributeddataservice/adapter/communicator/src/communicator_context.cpp +++ b/services/distributeddataservice/adapter/communicator/src/communicator_context.cpp @@ -44,9 +44,10 @@ Status CommunicatorContext::RegSessionListener(const DevChangeListener *observer ZLOGE("observer is nullptr"); return Status::INVALID_ARGUMENT; } - if (!observers_.Insert(observer, observer)) { - ZLOGE("insert observer fail"); - return Status::ERROR; + std::lock_guard lock(mutex_); + auto it = std::find(observers_.begin(), observers_.end(), observer); + if (it == observers_.end()) { + observers_.emplace_back(observer); } return Status::SUCCESS; } @@ -63,9 +64,10 @@ Status CommunicatorContext::UnRegSessionListener(const DevChangeListener *observ ZLOGE("observer is nullptr"); return Status::INVALID_ARGUMENT; } - if (!observers_.Erase(observer)) { - ZLOGE("erase observer fail"); - return Status::ERROR; + std::lock_guard lock(mutex_); + auto it = std::find(observers_.begin(), observers_.end(), observer); + if (it != observers_.end()) { + observers_.erase(it); } return Status::SUCCESS; } @@ -77,19 +79,17 @@ void CommunicatorContext::NotifySessionReady(const std::string &deviceId) return; } devices_.Insert(deviceId, deviceId); - std::vector observers; - observers_.ForEach([&observers](const auto &key, auto &value) { - observers.emplace_back(value); - return false; - }); - ZLOGI("Notify session begin, deviceId:%{public}s, observer count:%{public}zu", - KvUtils::ToBeAnonymous(deviceId).c_str(), observers.size()); DeviceInfo devInfo; devInfo.uuid = deviceId; - for (const auto &observer : observers) { - if (observer != nullptr) { - observer->OnSessionReady(devInfo); + { + std::lock_guard lock(mutex_); + for (const auto &observer : observers_) { + if (observer != nullptr) { + observer->OnSessionReady(devInfo); + } } + ZLOGI("Notify session begin, deviceId:%{public}s, observer count:%{public}zu", + KvUtils::ToBeAnonymous(deviceId).c_str(), observers_.size()); } std::lock_guard sessionLockGard(sessionMutex_); if (closeListener_) { diff --git a/services/distributeddataservice/adapter/include/communicator/communicator_context.h b/services/distributeddataservice/adapter/include/communicator/communicator_context.h index 1b234bddb..a77a2db3a 100644 --- a/services/distributeddataservice/adapter/include/communicator/communicator_context.h +++ b/services/distributeddataservice/adapter/include/communicator/communicator_context.h @@ -52,7 +52,8 @@ private: mutable std::mutex sessionMutex_; OnCloseAble closeListener_; std::shared_ptr executors_; - ConcurrentMap observers_ {}; + std::mutex mutex_; + std::vector observers_; ConcurrentMap devices_ {}; }; } // namespace OHOS::DistributedData diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index ed210074d..003660d6e 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -150,7 +150,7 @@ void KvStoreMetaManager::InitDeviceOnline() EventCenter::GetInstance().PostEvent(std::move(finEvent)); }; auto store = GetMetaKvStore(); - uint16_t mask = data.dynamic & 0x000F; + uint16_t mask = data.dynamic & DEFAULT_MASK; if (((mask & DeviceMatrix::META_STORE_MASK) != 0) && store != nullptr) { auto status = store->Sync({ deviceId }, DistributedDB::SyncMode::SYNC_MODE_PUSH_PULL, onComplete); if (status == OK) { diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.h b/services/distributeddataservice/app/src/kvstore_meta_manager.h index a59f4b143..a2355edd1 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.h +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.h @@ -36,6 +36,7 @@ enum class CHANGE_FLAG { class KvStoreMetaManager { public: static constexpr uint32_t META_STORE_VERSION = 0x03000001; + static constexpr uint16_t DEFAULT_MASK = 0x000F; using ChangeObserver = std::function &, const std::vector &, CHANGE_FLAG)>; class MetaDeviceChangeListenerImpl : public AppDistributedKv::AppDeviceChangeListener {