From 40bb8e4df0920e0e507ddd1850558396434b6ca5 Mon Sep 17 00:00:00 2001 From: liuhongjie Date: Fri, 18 Oct 2024 19:31:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=89=E6=80=81WiFi?= =?UTF-8?q?=E5=8D=8A=E5=BC=80=E7=8A=B6=E6=80=81=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuhongjie --- .../include/distributed_sched_service.h | 2 + .../src/distributed_sched_service.cpp | 46 +++++++++++++------ .../src/mission/wifi_state_listener.cpp | 13 ++++-- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/services/dtbschedmgr/include/distributed_sched_service.h b/services/dtbschedmgr/include/distributed_sched_service.h index 26138d31..14ef75f3 100644 --- a/services/dtbschedmgr/include/distributed_sched_service.h +++ b/services/dtbschedmgr/include/distributed_sched_service.h @@ -230,6 +230,7 @@ private: DistributedSchedService(); bool Init(); void InitDataShareManager(); + void InitMissionManager(); void InitCommonEventListener(); int32_t GetCallerInfo(const std::string &localDeviceId, int32_t callerUid, uint32_t accessToken, CallerInfo &callerInfo); @@ -293,6 +294,7 @@ private: void SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId); void RemoveConnectAbilityInfo(const std::string& deviceId); void InitWifiStateListener(); + void InitWifiSemiStateListener(); void NotifyContinuateEventResult(int32_t resultCode, const EventNotify& event); void InitDeviceCfg(); void NotifyCollaborateEventResult(int32_t resultCode, const EventNotify& event); diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp index f0d778c9..7200a393 100644 --- a/services/dtbschedmgr/src/distributed_sched_service.cpp +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -115,6 +115,7 @@ const std::string DMS_CONTINUE_SESSION_ID = "ohos.dms.continueSessionId"; const std::string DMS_PERSISTENT_ID = "ohos.dms.persistentId"; const std::string PKG_NAME = "DBinderBus_Dms_" + std::to_string(getprocpid()); const std::string BOOT_COMPLETED_EVENT = "usual.event.BOOT_COMPLETED"; +const std::string COMMON_EVENT_WIFI_SEMI_STATE = "usual.event.wifi.SEMI_STATE"; constexpr int32_t DEFAULT_DMS_MISSION_ID = -1; constexpr int32_t DEFAULT_DMS_CONNECT_TOKEN = -1; constexpr int32_t BIND_CONNECT_RETRY_TIMES = 3; @@ -140,6 +141,7 @@ constexpr int32_t DMSDURATION_SRCTODSTRPCTIME = 5; constexpr int32_t DMSDURATION_STARTABILITY = 6; constexpr int32_t HID_HAP = 10000; /* first hap user */ constexpr int32_t WINDOW_MANAGER_SERVICE_ID = 4606; +constexpr int32_t SEMI_WIFI_ID = 1010; DataShareManager &dataShareManager = DataShareManager::GetInstance(); } @@ -286,18 +288,8 @@ bool DistributedSchedService::Init() HILOGW("DtbschedmgrDeviceInfoStorage init failed."); } InitDataShareManager(); + InitMissionManager(); -#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER - if (!AddSystemAbilityListener(WINDOW_MANAGER_SERVICE_ID)) { - HILOGE("Add System Ability Listener failed!"); - } - DistributedSchedMissionManager::GetInstance().Init(); - DistributedSchedMissionManager::GetInstance().InitDataStorage(); - InitCommonEventListener(); - InitWifiStateListener(); - DMSContinueSendMgr::GetInstance().Init(); - DMSContinueRecvMgr::GetInstance().Init(); -#endif DistributedSchedAdapter::GetInstance().Init(); if (SwitchStatusDependency::GetInstance().IsContinueSwitchOn()) { DSchedContinueManager::GetInstance().Init(); @@ -313,6 +305,22 @@ bool DistributedSchedService::Init() return true; } +void DistributedSchedService::InitMissionManager() +{ +#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER + if (!AddSystemAbilityListener(WINDOW_MANAGER_SERVICE_ID)) { + HILOGE("Add System Ability Listener failed!"); + } + DistributedSchedMissionManager::GetInstance().Init(); + DistributedSchedMissionManager::GetInstance().InitDataStorage(); + InitCommonEventListener(); + InitWifiStateListener(); + InitWifiSemiStateListener(); + DMSContinueSendMgr::GetInstance().Init(); + DMSContinueRecvMgr::GetInstance().Init(); +#endif +} + void DistributedSchedService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { HILOGI("OnAddSystemAbility systemAbilityId:%{public}d added!", systemAbilityId); @@ -383,12 +391,24 @@ void DistributedSchedService::InitWifiStateListener() EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); auto wifiStateListener = std::make_shared(subscribeInfo); wifiStateListener->InitWifiState(); - bool ret = EventFwk::CommonEventManager::SubscribeCommonEvent(wifiStateListener); - if (!ret) { + if (!EventFwk::CommonEventManager::SubscribeCommonEvent(wifiStateListener)) { HILOGE("SubscribeCommonEvent wifiStateListener failed!"); } } +void DistributedSchedService::InitWifiSemiStateListener() +{ + HILOGI("InitWifiSemiStateListener called"); + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(COMMON_EVENT_WIFI_SEMI_STATE); + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPublisherUid(SEMI_WIFI_ID); + auto wifiStateListener = std::make_shared(subscribeInfo); + if (!EventFwk::CommonEventManager::SubscribeCommonEvent(wifiStateListener)) { + HILOGE("SubscribeCommonEvent wifiSemiStateListener failed!"); + } +} + void DistributedSchedService::InitDeviceCfg() { HILOGI("called"); diff --git a/services/dtbschedmgr/src/mission/wifi_state_listener.cpp b/services/dtbschedmgr/src/mission/wifi_state_listener.cpp index f6bdf67e..f3e24da7 100644 --- a/services/dtbschedmgr/src/mission/wifi_state_listener.cpp +++ b/services/dtbschedmgr/src/mission/wifi_state_listener.cpp @@ -30,19 +30,21 @@ const std::string TAG = "WifiStateListener"; void WifiStateListener::OnReceiveEvent(const EventFwk::CommonEventData &data) { + HILOGI("receive event code = %{public}d", data.GetCode()); switch (data.GetCode()) { case int32_t(OHOS::Wifi::WifiState::DISABLED): { HILOGI("on wifi disabled"); - if (CheckWifiStateIsActived()) { - WifiStateAdapter::GetInstance().UpdateWifiState(true); - HILOGI("WifiState is STATE_SEMIACTIVE"); - return; - } WifiStateAdapter::GetInstance().UpdateWifiState(false); DMSContinueRecvMgr::GetInstance().OnContinueSwitchOff(); break; } + case int32_t(Wifi::WifiDetailState::STATE_SEMI_ACTIVE): { + HILOGI("on wifi SEMI_ACTIVE"); + WifiStateAdapter::GetInstance().UpdateWifiState(true); + break; + } + case int32_t(OHOS::Wifi::WifiState::ENABLED): { HILOGI("on wifi enabled"); WifiStateAdapter::GetInstance().UpdateWifiState(true); @@ -70,6 +72,7 @@ bool WifiStateListener::CheckWifiStateIsActived() return false; } + HILOGI("get wifi detail state is %{public}d", wifiDetailState); return (wifiDetailState == Wifi::WifiDetailState::STATE_SEMI_ACTIVE) || (wifiDetailState == Wifi::WifiDetailState::STATE_ACTIVATED); }