• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_WIFI_EVENT_SUBSCRIBER_MANAGER_H
17 #define OHOS_WIFI_EVENT_SUBSCRIBER_MANAGER_H
18 
19 #ifndef OHOS_ARCH_LITE
20 #include <mutex>
21 #include <functional>
22 #include "wifi_errcode.h"
23 #include "wifi_internal_msg.h"
24 #include "wifi_system_ability_listerner.h"
25 #include "common_event_manager.h"
26 #include "wifi_event_handler.h"
27 
28 namespace OHOS {
29 namespace Wifi {
30 #ifdef HAS_POWERMGR_PART
31 const std::string COMMON_EVENT_POWER_MANAGER_STATE_CHANGED = "usual.event.POWER_MANAGER_STATE_CHANGED";
32 #endif
33 #ifdef SUPPORT_ClOUD_WIFI_ASSET
34 inline const std::string COMMON_EVENT_ASSETCLOUD_MANAGER_STATE_CHANGED = "usual.event.ASSET_SYNC_DATA_CHANGED_SA";
35 const int ASSETID = 6226;
36 #endif
37 const int CAST_ENGINE_SA_ID = 65546;
38 const int SHARE_SERVICE_ID = 2902;
39 const int MOUSE_CROSS_SERVICE_ID = 65569;
40 class CesEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
41 public:
42     explicit CesEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo);
43     virtual ~CesEventSubscriber();
44     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override;
45     void OnReceiveStandbyEvent(const OHOS::EventFwk::CommonEventData &eventData);
46     void OnReceiveScreenEvent(const OHOS::EventFwk::CommonEventData &eventData);
47     void OnReceiveAirplaneEvent(const OHOS::EventFwk::CommonEventData &eventData);
48     void OnReceiveBatteryEvent(const OHOS::EventFwk::CommonEventData &eventData);
49     void OnReceiveAppEvent(const OHOS::EventFwk::CommonEventData &eventData);
50     void OnReceiveThermalEvent(const OHOS::EventFwk::CommonEventData &eventData);
51     void OnReceiveNotificationEvent(const OHOS::EventFwk::CommonEventData &eventData);
52     void OnReceiveUserUnlockedEvent(const OHOS::EventFwk::CommonEventData &eventData);
53 private:
54     bool lastSleepState = false;
55 };
56 
57 class NotificationEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
58 public:
59     explicit NotificationEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo);
60     virtual ~NotificationEventSubscriber();
61     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override;
62     void OnReceiveWlanKeepConnected(const OHOS::EventFwk::CommonEventData &eventData);
63 };
64 
65 #ifdef HAS_POWERMGR_PART
66 class PowermgrEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
67 public:
68     explicit PowermgrEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo);
69     virtual ~PowermgrEventSubscriber();
70     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override;
71 };
72 #endif
73 #ifdef SUPPORT_ClOUD_WIFI_ASSET
74 class AssetEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
75 public:
76     explicit AssetEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo);
77     virtual ~AssetEventSubscriber();
78     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override;
79 };
80 #endif
81 
82 class NetworkStateChangeSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
83 public:
84     explicit NetworkStateChangeSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo);
85     ~NetworkStateChangeSubscriber() = default;
86     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override;
87 };
88 
89 class WifiScanEventChangeSubscriber : public OHOS::EventFwk::CommonEventSubscriber {
90 public:
91     explicit WifiScanEventChangeSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo);
92     ~WifiScanEventChangeSubscriber() = default;
93     void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override;
94 };
95 
96 class WifiEventSubscriberManager : public WifiSystemAbilityListener {
97 public:
98     WifiEventSubscriberManager();
99     virtual ~WifiEventSubscriberManager();
100 
101     void OnSystemAbilityChanged(int systemAbilityId, bool add) override;
102     void GetAirplaneModeByDatashare();
103     void GetWifiAllowSemiActiveByDatashare();
104     bool GetLocationModeByDatashare();
105     void DealLocationModeChangeEvent();
106     void DealCloneDataChangeEvent();
107     void CheckAndStartStaByDatashare();
108     bool IsMdmForbidden(void);
109 
110 private:
111     void DelayedAccessDataShare();
112     void InitSubscribeListener();
113     bool IsDataMgrServiceActive();
114     void HandleAppMgrServiceChange(bool add);
115     void HandleCommNetConnManagerSysChange(int systemAbilityId, bool add);
116     void HandleCommonEventServiceChange(int systemAbilityId, bool add);
117 #ifdef HAS_MOVEMENT_PART
118     void HandleHasMovementPartChange(int systemAbilityId, bool add);
119 #endif
120     void HandleDistributedKvDataServiceChange(bool add);
121     void HandleCastServiceChange(bool add);
122     void HandleShareServiceChange(bool add);
123     void HandleMouseCrossServiceChange(bool add);
124     int GetLastStaStateByDatashare();
125     void GetCloneDataByDatashare(std::string &cloneData);
126     void SetCloneDataByDatashare(const std::string &cloneData);
127     void RegisterCloneEvent();
128     void UnRegisterCloneEvent();
129     void RegisterCesEvent();
130 #ifdef HAS_POWERMGR_PART
131     void RegisterPowermgrEvent();
132     void UnRegisterPowermgrEvent();
133     std::shared_ptr<PowermgrEventSubscriber> wifiPowermgrEventSubsciber_ = nullptr;
134     std::mutex powermgrEventMutex;
135 #endif
136     void UnRegisterCesEvent();
137     void RegisterLocationEvent();
138     void UnRegisterLocationEvent();
139     void RegisterNotificationEvent();
140     void UnRegisterNotificationEvent();
141     void GetMdmProp();
142     void GetChipProp();
143     void RegisterMdmPropListener();
144     static void MdmPropChangeEvt(const char *key, const char *value, void *context);
145 #ifdef HAS_MOVEMENT_PART
146     void RegisterMovementCallBack();
147     void UnRegisterMovementCallBack();
148 #endif
149 #ifdef FEATURE_P2P_SUPPORT
150     void HandleP2pBusinessChange(int systemAbilityId, bool add);
151 #endif
152 #ifdef SUPPORT_ClOUD_WIFI_ASSET
153     void RegisterAssetEvent();
154     void UnRegisterAssetEvent();
155 #endif
156     void RegisterNetworkStateChangeEvent();
157     void UnRegisterNetworkStateChangeEvent();
158     void RegisterWifiScanChangeEvent();
159     void UnRegisterWifiScanChangeEvent();
160 private:
161     std::mutex cloneEventMutex;
162     uint32_t cesTimerId{0};
163     uint32_t notificationTimerId{0};
164     uint32_t accessDatashareTimerId{0};
165     uint32_t networkStateChangeTimerId{0};
166     uint32_t wifiScanChangeTimerId{0};
167     std::mutex cesEventMutex;
168     std::mutex notificationEventMutex;
169     std::mutex networkStateChangeEventMutex;
170     std::mutex wifiScanChangeEventMutex;
171     bool isCesEventSubscribered = false;
172     std::shared_ptr<CesEventSubscriber> cesEventSubscriber_ = nullptr;
173     std::shared_ptr<NotificationEventSubscriber> wifiNotificationSubsciber_ = nullptr;
174     std::shared_ptr<NetworkStateChangeSubscriber> networkStateChangeSubsciber_ = nullptr;
175     std::shared_ptr<WifiScanEventChangeSubscriber> wifiScanEventChangeSubscriber_ = nullptr;
176 #ifdef HAS_MOVEMENT_PART
177     std::mutex deviceMovementEventMutex;
178 #endif
179     static bool mIsMdmForbidden;
180     bool islocationModeObservered = false;
181     std::mutex locationEventMutex;
182     std::unique_ptr<WifiEventHandler> mWifiEventSubsThread = nullptr;
183 #ifdef SUPPORT_ClOUD_WIFI_ASSET
184     std::shared_ptr<AssetEventSubscriber> wifiAssetrEventSubsciber_ = nullptr;
185     std::mutex AssetEventMutex;
186     uint32_t assetMgrId{0};
187 #endif
188 };
189 
190 }  // namespace Wifi
191 }  // namespace OHOS
192 #endif
193 #endif // OHOS_WIFI_EVENT_SUBSCRIBER_MANAGER_H
194