!1130 新增三态WiFi半开状态监听

Merge pull request !1130 from liuhongjie/master
This commit is contained in:
openharmony_ci 2024-10-18 12:16:43 +00:00 committed by Gitee
commit 18fdc72192
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 43 additions and 18 deletions

View File

@ -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);

View File

@ -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<WifiStateListener>(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<WifiStateListener>(subscribeInfo);
if (!EventFwk::CommonEventManager::SubscribeCommonEvent(wifiStateListener)) {
HILOGE("SubscribeCommonEvent wifiSemiStateListener failed!");
}
}
void DistributedSchedService::InitDeviceCfg()
{
HILOGI("called");

View File

@ -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);
}