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 16 #ifndef NETWORKSLICEMANAGER_H 17 #define NETWORKSLICEMANAGER_H 18 19 #include <cstdint> 20 #include <string> 21 #include <vector> 22 #include "event_handler.h" 23 #include "nrunsolicitedmsgparser.h" 24 #include "singleton.h" 25 #include "networkslicemsgcenter.h" 26 #include "networkslice_service_base.h" 27 #include "networkslicecommconfig.h" 28 #include "broadcast_proxy.h" 29 namespace OHOS { 30 namespace NetManagerStandard { 31 32 const int32_t INVALID_FOREGROUND_UID = -1; 33 class NetworkSliceManager : public NetworkSliceServiceBase { 34 DECLARE_DELAYED_SINGLETON(NetworkSliceManager); 35 public: 36 std::vector<ForbiddenRouteDescriptor> mNormalForbiddenRules; 37 bool mIsIpParaReportEnable = false; 38 bool mApnStartflag = true; 39 void OnInit() override;; 40 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 41 void ProcessEventEx(const AppExecFwk::InnerEvent::Pointer& event); 42 void InitUePolicy(); 43 void HandleForegroundAppChanged(const std::shared_ptr<AppExecFwk::AppStateData>& msg); 44 void HandleUrspChanged(const std::shared_ptr<std::map<std::string, std::string>>& msg); 45 void HandleSimStateChanged(); 46 void HandleUrspFromUnsolData(const std::shared_ptr<std::vector<uint8_t>>& buffer); 47 void HandleIpRpt(const std::shared_ptr<std::vector<uint8_t>>& msg); 48 void HandleAllowedNssaiFromUnsolData(const std::shared_ptr<std::vector<uint8_t>>& msg); 49 void HandleEhplmnFromUnsolData(const std::shared_ptr<std::vector<uint8_t>>& msg); 50 void SendUrspUpdateMsg(); 51 void GetRouteSelectionDescriptorByAppDescriptor(const std::shared_ptr<GetSlicePara>& getSlicePara); 52 bool isMeetNetworkSliceConditions(); 53 void NotifySlicePara(const std::shared_ptr<GetSlicePara>& getSlicePara); 54 bool GetAppDescriptor(std::map<std::string, std::string>& data, AppDescriptor& appDescriptor); 55 void SetAppId(AppDescriptor& appDescriptor, const std::vector<std::string>& values, const std::string& appId); 56 void FillRouteSelectionDescriptor(std::map<std::string, std::string>& ret, 57 SelectedRouteDescriptor routeRule); 58 bool isSaState(); 59 bool hasAvailableUrspRule(); 60 bool isNrSlicesSupported(); 61 bool isDefaultDataOnMainCard(); 62 bool isWifiConnected(); 63 bool isScreenOn(); 64 bool isAirPlaneModeOn(); 65 bool isInVpnMode(); 66 void SetSaState(bool isSaState); 67 bool isRouteRuleInForbiddenList(const SelectedRouteDescriptor& routeRule); 68 void HandleIpv4Rpt(int& startIndex, const std::vector<uint8_t>& buffer, 69 std::map<std::string, std::string>& bundle, AppDescriptor& appDescriptor); 70 void HandleIpv6Rpt(int& startIndex, const std::vector<uint8_t>& buffer, 71 std::map<std::string, std::string>& bundle, AppDescriptor& appDescriptor); 72 void DumpAppDescriptor(AppDescriptor appDescriptor); 73 void DumpSelectedRouteDescriptor(SelectedRouteDescriptor routeRule); 74 void IpParaReportControl(); 75 void BindProcessToNetworkByFullPara(std::shared_ptr<std::map<std::string, std::string>> msg); 76 bool GetUidRoutePara(AddRoutePara& addRoutePara, std::map<std::string, std::string>& data); 77 bool GetRoutePara(AddRoutePara& addRoutePara, std::map<std::string, std::string>& data); 78 void GetRouteParaEx(AddRoutePara& addRoutePara, std::map<std::string, std::string>& data); 79 bool CalculateParaLen(AddRoutePara& addRoutePara); 80 bool FillRoutePara(std::vector<uint8_t>& buffer, AddRoutePara addRoutePara); 81 void DeleteNetworkBindByFullPara(std::shared_ptr<std::map<std::string, std::string>> msg); 82 void FillDeletePara(short len, int type, std::vector<int> precedenceArray, std::vector<int> uidArrays, 83 std::map<std::string, std::string> data); 84 std::vector<int> GetUidArray(std::string uids); 85 std::vector<int> GetPrecedenceArray(std::string precedences); 86 void CloseTcpSocketsForUid(int uid); 87 void SendIpPara(AppDescriptor appDescriptor, std::map<std::string, std::string> bundle); 88 void onUrspAvailableStateChanged(); 89 void ProcessNetworkParaForbiddenTimeOut(); 90 void StartNetworkParaForbiddenTimer(int64_t timeMillies); 91 void HandleNetworkActivateResult(std::shared_ptr<std::map<std::string, std::any>> data); 92 int32_t BindUidProcessToNetworkForDns(int netid, int uid); 93 bool isCanRequestNetwork(); 94 void HandleAirModeChanged(int32_t mode); 95 void HandleWifiConnChanged(int32_t state); 96 void HandleVpnModeChanged(bool mode); 97 bool isMobileDataClose(); 98 void HandleScreenOn(); 99 void HandleScreenOff(); 100 int32_t GetForeGroundAppUid(); 101 void GetRouteSelectionDescriptorByDNN(const std::string dnn, std::string& snssai, uint8_t& sscmode); 102 private: 103 int32_t foregroundApp_uid = INVALID_FOREGROUND_UID; 104 bool mIsUrspFirstReported = false; 105 bool airModeOn_ { false }; 106 bool wifiConn_ { false }; 107 bool vpnMode_ { false }; 108 bool screenOn_ { false }; 109 bool isSaState_ { false }; 110 }; 111 112 extern std::shared_ptr<NrUnsolicitedMsgParser> sNrUnsolicitedMsgParser_; 113 extern std::shared_ptr<UrspConfig> sUrspConfig_; 114 115 116 } // namespace NetManagerStandard 117 } // namespace OHOS 118 119 #endif // NETWORKSLICEMANAGER_H 120