From 53645f71b549f95b48c80da8ae458ef59abf65d0 Mon Sep 17 00:00:00 2001 From: yanghui Date: Thu, 19 Dec 2024 03:55:31 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=A4null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanghui --- .../wifi_sub_manage/wifi_event_subscriber_manager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp index bc27fe69b..4cfa2c408 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp @@ -344,10 +344,14 @@ void WifiEventSubscriberManager::DealLocationModeChangeEvent() { if (GetLocationModeByDatashare()) { WIFI_LOGI("DealLocationModeChangeEvent open"); - WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(1); + if(WifiManager::GetInstance().GetWifiTogglerManager()){ + WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(1); + } } else { WIFI_LOGI("DealLocationModeChangeEvent close"); - WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(0); + if(WifiManager::GetInstance().GetWifiTogglerManager()){ + WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(0); + } } } -- Gitee From d72ac944f585e19f8528553649904f83c00619d1 Mon Sep 17 00:00:00 2001 From: yanghui Date: Wed, 25 Dec 2024 04:26:55 +0000 Subject: [PATCH 2/4] =?UTF-8?q?null=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanghui --- .../wifi_manage/wifi_manager.cpp | 1 + .../wifi_event_subscriber_manager.cpp | 88 ++++++++++++++----- .../wifi_event_subscriber_manager.h | 14 ++- 3 files changed, 82 insertions(+), 21 deletions(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp index 4da71e5f9..16ca07ba0 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp @@ -102,6 +102,7 @@ int WifiManager::Init() return -1; } mInitStatus = INIT_OK; + wifiEventSubscriberManager->Init(); if (!std::filesystem::exists(WIFI_CONFIG_FILE_PATH) && !std::filesystem::exists(DUAL_WIFI_CONFIG_FILE_PATH) && !std::filesystem::exists(DUAL_SOFTAP_CONFIG_FILE_PATH)) { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp index 4cfa2c408..ab5de4eaf 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp @@ -77,9 +77,7 @@ const std::map CES_REQUEST_MAP = { {OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_DEVICE_IDLE_MODE_CHANGED, & CesEventSubscriber::OnReceiveStandbyEvent}, {OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED, & - CesEventSubscriber::OnReceiveUserUnlockedEvent}, - {OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY, & - CesEventSubscriber::OnReceiveDataShareReadyEvent} + CesEventSubscriber::OnReceiveUserUnlockedEvent} }; WifiEventSubscriberManager::WifiEventSubscriberManager() @@ -115,6 +113,14 @@ WifiEventSubscriberManager::~WifiEventSubscriberManager() UnRegisterSettingsEnterEvent(); } +void WifiEventSubscriberManager::Init() +{ + WIFI_LOGI("Init WifiEventSubscriberManager"); + // Subscribe and register operation after wifiManager init completed. + SubscribeSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); // subscribe data management service done + RegisterDataShareReadyEvent() +} + void WifiEventSubscriberManager::RegisterCesEvent() { std::unique_lock lock(cesEventMutex); @@ -344,14 +350,10 @@ void WifiEventSubscriberManager::DealLocationModeChangeEvent() { if (GetLocationModeByDatashare()) { WIFI_LOGI("DealLocationModeChangeEvent open"); - if(WifiManager::GetInstance().GetWifiTogglerManager()){ - WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(1); - } + WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(1); } else { WIFI_LOGI("DealLocationModeChangeEvent close"); - if(WifiManager::GetInstance().GetWifiTogglerManager()){ - WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(0); - } + WifiManager::GetInstance().GetWifiTogglerManager()->ScanOnlyToggled(0); } } @@ -406,7 +408,6 @@ void WifiEventSubscriberManager::InitSubscribeListener() #ifdef HAS_MOVEMENT_PART SubscribeSystemAbility(MSDP_MOVEMENT_SERVICE_ID); #endif - SubscribeSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); // subscribe data management service done SubscribeSystemAbility(SOFTBUS_SERVER_SA_ID); SubscribeSystemAbility(CAST_ENGINE_SA_ID); SubscribeSystemAbility(MIRACAST_SERVICE_SA_ID); @@ -725,16 +726,6 @@ void CesEventSubscriber::OnReceiveStandbyEvent(const OHOS::EventFwk::CommonEvent } } -void CesEventSubscriber::OnReceiveDataShareReadyEvent(const OHOS::EventFwk::CommonEventData &eventData) -{ - const auto &action = eventData.GetWant().GetAction(); - WIFI_LOGI("OnReceiveDataShareReadyEvent action[%{public}s]", action.c_str()); - if (WifiManager::GetInstance().GetWifiEventSubscriberManager()) { - WifiManager::GetInstance().GetWifiEventSubscriberManager()->AccessDataShare(); - WifiManager::GetInstance().GetWifiEventSubscriberManager()->RegisterLocationEvent(); - } -} - void WifiEventSubscriberManager::RegisterNotificationEvent() { std::unique_lock lock(notificationEventMutex); @@ -1158,6 +1149,63 @@ void SettingsEnterSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &ev } } +void WifiEventSubscriberManager::RegisterDataShareReadyEvent() +{ + WIFI_LOGI("RegisterDataShareReadyEvent enter"); + std::unique_lock lock(dataShareReadySubscriber_); + if (dataShareReadyTimerId_ != 0) { + WifiTimer::GetInstance()->UnRegister(dataShareReadyTimerId_); + } + if (dataShareReadySubscriber_) { + return; + } + OHOS::EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY); + OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + dataShareReadySubscriber_ = std::make_shared(subscriberInfo); + if (!EventFwk::CommonEventManager::SubscribeCommonEvent(dataShareReadySubscriber_)) { + WIFI_LOGE("RegisterDataShareReadyEvent failed"); + dataShareReadySubscriber_ = nullptr; + WifiTimer::TimerCallback timeoutCallBack = [this]() { this->RegisterDataShareReadyEvent(); }; + WifiTimer::GetInstance()->Register(timeoutCallBack, dataShareReadyTimerId_, TIMEOUT_EVENT_SUBSCRIBER, false); + WIFI_LOGI("RegisterDataShareReadyEvent retry, dataShareReadyTimerId_ = %{public}u", dataShareReadyTimerId_); + } else { + WIFI_LOGI("RegisterDataShareReadyEvent success"); + } +} + +void WifiEventSubscriberManager::UnRegisterDataShareReadyEvent() +{ + std::unique_lock lock(dataShareReadySubscriber_); + if (dataShareReadyTimerId_ != 0) { + WifiTimer::GetInstance()->UnRegister(dataShareReadyTimerId_); + } + if (!dataShareReadySubscriber_) { + return; + } + if (!EventFwk::CommonEventManager::UnSubscribeCommonEvent(dataShareReadySubscriber_)) { + WIFI_LOGE("UnRegisterDataShareReadyEvent failed"); + } + dataShareReadySubscriber_ = nullptr; + WIFI_LOGI("UnRegisterDataShareReadyEvent finished"); +} + +DataShareReadySubscriber::DataShareReadySubscriber( + const EventFwk::CommonEventSubscribeInfo &subscriberInfo) : CommonEventSubscriber(subscriberInfo) +{ + WIFI_LOGI("DataShareReadySubscriber enter"); +} + +void DataShareReadySubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData) +{ + const auto &action = eventData.GetWant().GetAction(); + WIFI_LOGI("DataShareReadySubscriber OnReceiveEvent: %{public}s", action.c_str()); + if (action == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY) { + WifiManager::GetInstance().GetWifiEventSubscriberManager()->AccessDataShare(); + WifiManager::GetInstance().GetWifiEventSubscriberManager()->RegisterLocationEvent(); + } +} + } // namespace Wifi } // namespace OHOS #endif diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.h index 59ef7d598..c08a20905 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.h @@ -50,7 +50,6 @@ public: void OnReceiveThermalEvent(const OHOS::EventFwk::CommonEventData &eventData); void OnReceiveNotificationEvent(const OHOS::EventFwk::CommonEventData &eventData); void OnReceiveUserUnlockedEvent(const OHOS::EventFwk::CommonEventData &eventData); - void OnReceiveDataShareReadyEvent(const OHOS::EventFwk::CommonEventData &eventData); private: bool lastSleepState = false; }; @@ -101,11 +100,19 @@ public: void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override; }; +class DataShareReadySubscriber : public OHOS::EventFwk::CommonEventSubscriber { +public: + explicit DataShareReadySubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo); + ~DataShareReadySubscriber() = default; + void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override; +}; + class WifiEventSubscriberManager : public WifiSystemAbilityListener { public: WifiEventSubscriberManager(); virtual ~WifiEventSubscriberManager(); + void Init(); void OnSystemAbilityChanged(int systemAbilityId, bool add) override; void GetAirplaneModeByDatashare(); void GetWifiAllowSemiActiveByDatashare(); @@ -159,6 +166,8 @@ private: void UnRegisterWifiScanChangeEvent(); void RegisterSettingsEnterEvent(); void UnRegisterSettingsEnterEvent(); + void RegisterDataShareReadyEvent(); + void UnRegisterDataShareReadyEvent(); private: uint32_t cesTimerId{0}; @@ -166,17 +175,20 @@ private: uint32_t networkStateChangeTimerId{0}; uint32_t wifiScanChangeTimerId{0}; uint32_t settingsTimerId{0}; + uint32_t dataShareReadyTimerId_{0}; std::mutex cesEventMutex; std::mutex notificationEventMutex; std::mutex networkStateChangeEventMutex; std::mutex wifiScanChangeEventMutex; std::mutex settingsEnterEventMutex; + std::mutex dataShareReadyEventMutex_; bool isCesEventSubscribered = false; std::shared_ptr cesEventSubscriber_ = nullptr; std::shared_ptr wifiNotificationSubsciber_ = nullptr; std::shared_ptr networkStateChangeSubsciber_ = nullptr; std::shared_ptr wifiScanEventChangeSubscriber_ = nullptr; std::shared_ptr settingsEnterSubscriber_ = nullptr; + std::shared_ptr dataShareReadySubscriber_ = nullptr; #ifdef HAS_MOVEMENT_PART std::mutex deviceMovementEventMutex; #endif -- Gitee From 3e46c8b62b41a0ad41a4df0abf5ad9d27a721664 Mon Sep 17 00:00:00 2001 From: yanghui Date: Wed, 25 Dec 2024 06:05:11 +0000 Subject: [PATCH 3/4] =?UTF-8?q?null=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanghui --- .../wifi_sub_manage/wifi_event_subscriber_manager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp index ab5de4eaf..3255fe6b5 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp @@ -111,14 +111,15 @@ WifiEventSubscriberManager::~WifiEventSubscriberManager() UnRegisterNetworkStateChangeEvent(); UnRegisterWifiScanChangeEvent(); UnRegisterSettingsEnterEvent(); + UnRegisterDataShareReadyEvent(); } void WifiEventSubscriberManager::Init() { - WIFI_LOGI("Init WifiEventSubscriberManager"); + WIFI_LOGI("WifiEventSubscriberManager Init"); // Subscribe and register operation after wifiManager init completed. SubscribeSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); // subscribe data management service done - RegisterDataShareReadyEvent() + RegisterDataShareReadyEvent(); } void WifiEventSubscriberManager::RegisterCesEvent() @@ -1152,7 +1153,7 @@ void SettingsEnterSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &ev void WifiEventSubscriberManager::RegisterDataShareReadyEvent() { WIFI_LOGI("RegisterDataShareReadyEvent enter"); - std::unique_lock lock(dataShareReadySubscriber_); + std::unique_lock lock(dataShareReadyEventMutex_); if (dataShareReadyTimerId_ != 0) { WifiTimer::GetInstance()->UnRegister(dataShareReadyTimerId_); } @@ -1176,7 +1177,7 @@ void WifiEventSubscriberManager::RegisterDataShareReadyEvent() void WifiEventSubscriberManager::UnRegisterDataShareReadyEvent() { - std::unique_lock lock(dataShareReadySubscriber_); + std::unique_lock lock(dataShareReadyEventMutex_); if (dataShareReadyTimerId_ != 0) { WifiTimer::GetInstance()->UnRegister(dataShareReadyTimerId_); } -- Gitee From ace27f252cc4b93b51b8710e87ed1ccb6115e6cf Mon Sep 17 00:00:00 2001 From: yanghui Date: Wed, 25 Dec 2024 07:36:06 +0000 Subject: [PATCH 4/4] =?UTF-8?q?null=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanghui --- .../wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp index 16ca07ba0..df18ddcec 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp @@ -102,8 +102,10 @@ int WifiManager::Init() return -1; } mInitStatus = INIT_OK; - wifiEventSubscriberManager->Init(); +#ifndef OHOS_ARCH_LITE + wifiEventSubscriberManager->Init(); +#endif if (!std::filesystem::exists(WIFI_CONFIG_FILE_PATH) && !std::filesystem::exists(DUAL_WIFI_CONFIG_FILE_PATH) && !std::filesystem::exists(DUAL_SOFTAP_CONFIG_FILE_PATH)) { if (IsStartUpWifiEnableSupport()) { -- Gitee