1 /* 2 * Copyright (c) 2025-2026 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 #ifndef BROADCAST_PROXY_H 16 #define BROADCAST_PROXY_H 17 18 #pragma once 19 #include <memory> 20 #include "system_ability_status_change_stub.h" 21 #include "application_state_observer_stub.h" 22 #include "common_event_subscriber.h" 23 #include "common_event_manager.h" 24 #include "common_event_support.h" 25 #include "singleton.h" 26 #include "networkvpn_client.h" 27 #include "ffrt.h" 28 #include "networksliceutil.h" 29 #include "app_mgr_interface.h" 30 #include "app_mgr_proxy.h" 31 #include "dns_result_callback.h" 32 33 namespace OHOS { 34 namespace NetManagerStandard { 35 const int32_t SUB_NUM = 3; 36 enum class CallStatus { 37 CALL_STATUS_UNKNOWN = -1, 38 CALL_STATUS_ACTIVE = 0, 39 CALL_STATUS_HOLDING = 1, 40 CALL_STATUS_DIALING = 2, 41 CALL_STATUS_ALERTING = 3, 42 CALL_STATUS_INCOMING = 4, 43 CALL_STATUS_WAITING = 5, 44 CALL_STATUS_DISCONNECTED = 6, 45 CALL_STATUS_DISCONNECTING = 7, 46 CALL_STATUS_IDLE = 8 47 }; 48 49 struct CellState { 50 int32_t slotId; 51 int32_t dataState; 52 int32_t networkType; 53 }; 54 55 const int32_t SLOT_0 = 0; 56 const int32_t SLOT_1 = 1; 57 58 struct SimState { 59 int32_t slotId; 60 int32_t simStatus; 61 }; 62 63 struct NetworkStandard { 64 int32_t slotId; 65 std::string networkState; 66 }; 67 68 class broadcast_proxy : public std::enable_shared_from_this<broadcast_proxy> { 69 public: 70 broadcast_proxy(); 71 virtual ~broadcast_proxy(); 72 73 private: 74 void Subscribe(); 75 void UnSubscribe(); 76 using BroadcastFunc = void (broadcast_proxy::*)(const EventFwk::CommonEventData& data); 77 void SubscribeCommonEvent(); 78 void UnSubscribeCommonEvent(); 79 void SubscribeApplicationState(); 80 void UnSubscribeApplicationState(); 81 void InitBroadCastHandleMap(); 82 void HandleSystemEvent(const EventFwk::CommonEventData& eventData); 83 void HandleScreenOnEvent(const EventFwk::CommonEventData& eventData); 84 void HandleScreenOffEvent(const EventFwk::CommonEventData& eventData); 85 void HandleWifiConnEvent(const EventFwk::CommonEventData& eventData); 86 void HandleSimStateEvent(const EventFwk::CommonEventData& eventData); 87 void HandleAirPlaneModeEvent(const EventFwk::CommonEventData& eventData); 88 void HandleNetWorkStateChanged(const EventFwk::CommonEventData &eventData); 89 void HandleConnectivityChanged(const EventFwk::CommonEventData &eventData); 90 private: 91 class BroadcastEventSubscriber : public EventFwk::CommonEventSubscriber { 92 public: BroadcastEventSubscriber(const EventFwk::CommonEventSubscribeInfo & info)93 BroadcastEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info) 94 : EventFwk::CommonEventSubscriber(info), 95 broadcastFfrtQueue_(std::make_shared<ffrt::queue>("BoosterNetBroadCast")) {} 96 ~BroadcastEventSubscriber() = default; 97 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 98 private: 99 std::shared_ptr<ffrt::queue> broadcastFfrtQueue_ = nullptr; 100 }; 101 102 class AppAwareObserver : public AppExecFwk::ApplicationStateObserverStub { 103 public: 104 AppAwareObserver() = default; 105 ~AppAwareObserver() = default; 106 107 void OnForegroundApplicationChanged(const AppExecFwk::AppStateData& appStateData) override; 108 private: 109 AppExecFwk::AppStateData lastAppStateData; 110 }; 111 class VpnEventObserver : public NetManagerStandard::VpnSetUpEventCallback { 112 public: 113 VpnEventObserver() = default; 114 ~VpnEventObserver() = default; 115 int32_t OnVpnStateChanged(bool isConnected) override; 116 }; 117 118 class SystemAbilityListener : public SystemAbilityStatusChangeStub { 119 public: 120 SystemAbilityListener() = default; 121 ~SystemAbilityListener() = default; 122 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 123 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 124 private: 125 void RegisterVpnEventCallback(); 126 void RegisterDnsResultCallback(); 127 128 private: 129 sptr<VpnEventObserver> vpnEventObserver_ = nullptr; 130 sptr<DnsResultCallback> dnsResultCallback_ = nullptr; 131 }; 132 133 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 134 std::map<std::string, BroadcastFunc> systemEventHandleMap_; 135 std::shared_ptr<BroadcastEventSubscriber> subscriber_ = nullptr; 136 sptr<AppAwareObserver> appAwareObserver_ = nullptr; 137 int32_t WifiConnected = 4; 138 int32_t WifiDisconnected = 6; 139 }; 140 } // namespace NetManagerStandard 141 } // namespace OHOS 142 143 #endif // BROADCAST_PROXY_H 144