1 /* 2 * Copyright (c) 2021-2024 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 NET_CONN_SERVICE_H 17 #define NET_CONN_SERVICE_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <list> 22 #include <memory> 23 #include <mutex> 24 #include <string> 25 #include <vector> 26 #include <thread> 27 #include <condition_variable> 28 29 #include "singleton.h" 30 #include "system_ability.h" 31 32 #include "http_proxy.h" 33 #include "net_activate.h" 34 #include "net_conn_constants.h" 35 #include "net_conn_event_handler.h" 36 #include "net_conn_service_iface.h" 37 #include "net_conn_service_stub.h" 38 #include "net_supplier.h" 39 #include "netsys_controller_callback.h" 40 #include "network.h" 41 #include "dns_result_call_back.h" 42 #include "net_factoryreset_callback.h" 43 #include "common_event_data.h" 44 #include "common_event_manager.h" 45 #include "common_event_subscriber.h" 46 #include "common_event_support.h" 47 #include "os_account_manager.h" 48 49 namespace OHOS { 50 namespace NetManagerStandard { 51 using EventReceiver = std::function<void(const EventFwk::CommonEventData&)>; 52 namespace { 53 const int32_t PRIMARY_USER_ID = 100; 54 } 55 class NetConnService : public SystemAbility, 56 public INetActivateCallback, 57 public NetConnServiceStub, 58 public std::enable_shared_from_this<NetConnService> { 59 DECLARE_SYSTEM_ABILITY(NetConnService) 60 61 NetConnService(); 62 virtual ~NetConnService(); 63 using NET_SUPPLIER_MAP = std::map<uint32_t, sptr<NetSupplier>>; 64 using NET_NETWORK_MAP = std::map<int32_t, std::shared_ptr<Network>>; 65 using NET_ACTIVATE_MAP = std::map<uint32_t, std::shared_ptr<NetActivate>>; 66 using NET_UIDREQUEST_MAP = std::map<uint32_t, uint32_t>; 67 68 public: 69 class NetConnListener : public EventFwk::CommonEventSubscriber { 70 public: 71 NetConnListener(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, EventReceiver receiver); 72 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 73 74 private: 75 EventReceiver eventReceiver_; 76 }; GetInstance()77 static std::shared_ptr<NetConnService> &GetInstance() 78 { 79 static std::shared_ptr<NetConnService> instance = std::make_shared<NetConnService>(); 80 return instance; 81 } 82 void OnStart() override; 83 void OnStop() override; 84 /** 85 * The interface in NetConnService can be called when the system is ready 86 * 87 * @return Returns 0, the system is ready, otherwise the system is not ready 88 */ 89 int32_t SystemReady() override; 90 91 /** 92 * Disallow or allow a app to create AF_INET or AF_INET6 socket 93 * 94 * @param uid App's uid which need to be disallowed ot allowed to create AF_INET or AF_INET6 socket 95 * @param allow 0 means disallow, 1 means allow 96 * @return return 0 if OK, return error number if not OK 97 */ 98 int32_t SetInternetPermission(uint32_t uid, uint8_t allow) override; 99 100 /** 101 * The interface is register the network 102 * 103 * @param bearerType Bearer Network Type 104 * @param ident Unique identification of mobile phone card 105 * @param netCaps Network capabilities registered by the network supplier 106 * @param supplierId out param, return supplier id 107 * 108 * @return function result 109 */ 110 int32_t RegisterNetSupplier(NetBearType bearerType, const std::string &ident, const std::set<NetCap> &netCaps, 111 uint32_t &supplierId) override; 112 113 /** 114 * The interface is unregister the network 115 * 116 * @param supplierId The id of the network supplier 117 * 118 * @return Returns 0, unregister the network successfully, otherwise it will fail 119 */ 120 int32_t UnregisterNetSupplier(uint32_t supplierId) override; 121 122 /** 123 * Register supplier callback 124 * 125 * @param supplierId The id of the network supplier 126 * @param callback INetSupplierCallback callback interface 127 * 128 * @return Returns 0, unregister the network successfully, otherwise it will fail 129 */ 130 int32_t RegisterNetSupplierCallback(uint32_t supplierId, const sptr<INetSupplierCallback> &callback) override; 131 132 /** 133 * Register net connection callback 134 * 135 * @param netSpecifier specifier information 136 * @param callback The callback of INetConnCallback interface 137 * 138 * @return Returns 0, successfully register net connection callback, otherwise it will failed 139 */ 140 int32_t RegisterNetConnCallback(const sptr<INetConnCallback> callback) override; 141 142 /** 143 * Register net connection callback by NetSpecifier 144 * 145 * @param netSpecifier specifier information 146 * @param callback The callback of INetConnCallback interface 147 * @param timeoutMS net connection time out 148 * 149 * @return Returns 0, successfully register net connection callback, otherwise it will failed 150 */ 151 int32_t RegisterNetConnCallback(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> callback, 152 const uint32_t &timeoutMS) override; 153 154 /** 155 * Request net connection callback by NetSpecifier 156 * 157 * @param netSpecifier specifier information 158 * @param callback The callback of INetConnCallback interface 159 * @param timeoutMS net connection time out 160 * 161 * @return Returns 0, successfully register net connection callback, otherwise it will failed 162 */ 163 int32_t RequestNetConnection(const sptr<NetSpecifier> netSpecifier, const sptr<INetConnCallback> callback, 164 const uint32_t timeoutMS) override; 165 /** 166 * Unregister net connection callback 167 * 168 * @return Returns 0, successfully unregister net connection callback, otherwise it will fail 169 */ 170 int32_t UnregisterNetConnCallback(const sptr<INetConnCallback> &callback) override; 171 172 int32_t UpdateNetStateForTest(const sptr<NetSpecifier> &netSpecifier, int32_t netState) override; 173 /** 174 * The interface is update network connection status information 175 * 176 * @param supplierId The id of the network supplier 177 * @param netSupplierInfo network connection status information 178 * 179 * @return Returns 0, successfully update the network connection status information, otherwise it will fail 180 */ 181 int32_t UpdateNetSupplierInfo(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo) override; 182 183 /** 184 * The interface is update network link attribute information 185 * 186 * @param supplierId The id of the network supplier 187 * @param netLinkInfo network link attribute information 188 * 189 * @return Returns 0, successfully update the network link attribute information, otherwise it will fail 190 */ 191 int32_t UpdateNetLinkInfo(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo) override; 192 193 /** 194 * The interface names which NetBearType is equal than bearerType 195 * 196 * @param bearerType Network bearer type 197 * @param ifaceNames save the obtained ifaceNames 198 * @return Returns 0, successfully get the network link attribute iface name, otherwise it will fail 199 */ 200 int32_t GetIfaceNames(NetBearType bearerType, std::list<std::string> &ifaceNames) override; 201 202 /** 203 * The interface is get the iface name for network 204 * 205 * @param bearerType Network bearer type 206 * @param ident Unique identification of mobile phone card 207 * @param ifaceName save the obtained ifaceName 208 * @return Returns 0, successfully get the network link attribute iface name, otherwise it will fail 209 */ 210 int32_t GetIfaceNameByType(NetBearType bearerType, const std::string &ident, std::string &ifaceName) override; 211 212 /** 213 * The interface is to get all iface and ident maps 214 * 215 * @param bearerType the type of network 216 * @param ifaceNameIdentMaps the map of ifaceName and ident 217 * @return Returns 0 success. Otherwise fail. 218 * @permission ohos.permission.CONNECTIVITY_INTERNAL 219 * @systemapi Hide this for inner system use. 220 */ 221 int32_t GetIfaceNameIdentMaps(NetBearType bearerType, 222 SafeMap<std::string, std::string> &ifaceNameIdentMaps) override; 223 224 /** 225 * register network detection return result method 226 * 227 * @param netId Network ID 228 * @param callback The callback of INetDetectionCallback interface 229 * @return int32_t Returns 0, unregister the network successfully, otherwise it will fail 230 */ 231 int32_t RegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback) override; 232 233 /** 234 * unregister network detection return result method 235 * 236 * @param netId Network ID 237 * @param callback The callback of INetDetectionCallback interface 238 * @return int32_t Returns 0, unregister the network successfully, otherwise it will fail 239 */ 240 int32_t UnRegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback) override; 241 242 /** 243 * The interface of network detection called by the application 244 * 245 * @param netId network ID 246 * @return int32_t Whether the network probe is successful 247 */ 248 int32_t NetDetection(int32_t netId) override; 249 int32_t GetDefaultNet(int32_t &netId) override; 250 int32_t HasDefaultNet(bool &flag) override; 251 int32_t GetAddressesByName(const std::string &host, int32_t netId, std::vector<INetAddr> &addrList) override; 252 int32_t GetAddressByName(const std::string &host, int32_t netId, INetAddr &addr) override; 253 int32_t GetSpecificNet(NetBearType bearerType, std::list<int32_t> &netIdList) override; 254 int32_t GetAllNets(std::list<int32_t> &netIdList) override; 255 int32_t GetSpecificUidNet(int32_t uid, int32_t &netId) override; 256 int32_t GetConnectionProperties(int32_t netId, NetLinkInfo &info) override; 257 int32_t GetNetCapabilities(int32_t netId, NetAllCapabilities &netAllCap) override; 258 int32_t BindSocket(int32_t socketFd, int32_t netId) override; 259 void HandleDetectionResult(uint32_t supplierId, NetDetectionStatus netState); 260 int32_t RestrictBackgroundChanged(bool isRestrictBackground); 261 /** 262 * Set airplane mode 263 * 264 * @param state airplane state 265 * @return Returns 0, successfully set airplane mode, otherwise it will fail 266 */ 267 int32_t SetAirplaneMode(bool state) override; 268 /** 269 * Dump 270 * 271 * @param fd file description 272 * @param args unused 273 * @return Returns 0, successfully get dump info, otherwise it will fail 274 */ 275 int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override; 276 /** 277 * Is default network metered 278 * 279 * @param save the metered state 280 * @return Returns 0, Successfully get whether the default network is metered, otherwise it will fail 281 */ 282 int32_t IsDefaultNetMetered(bool &isMetered) override; 283 284 /** 285 * Set http proxy server 286 * 287 * @param httpProxy the http proxy server 288 * @return NETMANAGER_SUCCESS if OK, NET_CONN_ERR_HTTP_PROXY_INVALID if httpProxy is null string 289 */ 290 int32_t SetGlobalHttpProxy(const HttpProxy &httpProxy) override; 291 292 /** 293 * Get http proxy server 294 * 295 * @param httpProxy output param, the http proxy server 296 * @return NETMANAGER_SUCCESS if OK, NET_CONN_ERR_NO_HTTP_PROXY if httpProxy is null string 297 */ 298 int32_t GetGlobalHttpProxy(HttpProxy &httpProxy) override; 299 300 /** 301 * Obtains the default proxy settings. 302 * 303 * <p>If a global proxy is set, the global proxy parameters are returned. 304 * If the process is bound to a network using {@link setAppNet}, 305 * the {@link Network} proxy settings are returned. 306 * In other cases, the default proxy settings of network are returned. 307 * 308 * @param bindNetId App bound network ID 309 * @param httpProxy output param, the http proxy server 310 * @return Returns NETMANAGER_SUCCESS even if HttpProxy is empty 311 */ 312 int32_t GetDefaultHttpProxy(int32_t bindNetId, HttpProxy &httpProxy) override; 313 314 /** 315 * Get net id by identifier 316 * 317 * @param ident Net identifier 318 * @param netIdList output param, the net id list 319 * @return NETMANAGER_SUCCESS if OK, ERR_NO_NET_IDENT if ident is null string 320 */ 321 int32_t GetNetIdByIdentifier(const std::string &ident, std::list<int32_t> &netIdList) override; 322 323 /** 324 * Activate network timeout 325 * 326 * @param reqId Net request id 327 */ 328 void OnNetActivateTimeOut(uint32_t reqId) override; 329 330 /** 331 * The interface of network detection called when DNS health check failed 332 * 333 * @param netId network ID 334 * @return int32_t Whether the network probe is successful 335 */ 336 int32_t NetDetectionForDnsHealth(int32_t netId, bool dnsHealthSuccess); 337 338 int32_t SetAppNet(int32_t netId) override; 339 int32_t RegisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback) override; 340 int32_t GetNetInterfaceConfiguration(const std::string &iface, NetInterfaceConfiguration &config) override; 341 int32_t AddNetworkRoute(int32_t netId, const std::string &ifName, 342 const std::string &destination, const std::string &nextHop) override; 343 int32_t RemoveNetworkRoute(int32_t netId, const std::string &ifName, 344 const std::string &destination, const std::string &nextHop) override; 345 int32_t AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr, 346 int32_t prefixLength) override; 347 int32_t DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr, 348 int32_t prefixLength) override; 349 int32_t AddStaticArp(const std::string &ipAddr, const std::string &macAddr, 350 const std::string &ifName) override; 351 int32_t DelStaticArp(const std::string &ipAddr, const std::string &macAddr, 352 const std::string &ifName) override; 353 int32_t RegisterSlotType(uint32_t supplierId, int32_t type) override; 354 int32_t GetSlotType(std::string &type) override; 355 int32_t FactoryResetNetwork() override; 356 int32_t RegisterNetFactoryResetCallback(const sptr<INetFactoryResetCallback> &callback) override; 357 int32_t IsPreferCellularUrl(const std::string& url, bool& preferCellular) override; 358 int32_t RegisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback) override; 359 int32_t UnregisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback) override; 360 bool IsAddrInOtherNetwork(const std::string &ifaceName, int32_t netId, const INetAddr &netAddr); 361 bool IsIfaceNameInUse(const std::string &ifaceName, int32_t netId); 362 int32_t UpdateSupplierScore(NetBearType bearerType, uint32_t detectionStatus, uint32_t& supplierId) override; 363 std::string GetNetCapabilitiesAsString(const uint32_t supplierId); 364 int32_t EnableVnicNetwork(const sptr<NetLinkInfo> &netLinkInfo, const std::set<int32_t> &uids) override; 365 int32_t DisableVnicNetwork() override; 366 int32_t SetPacUrl(const std::string &pacUrl) override; 367 int32_t GetPacUrl(std::string &pacUrl) override; 368 369 private: 370 class NetInterfaceStateCallback : public NetsysControllerCallback { 371 public: 372 NetInterfaceStateCallback() = default; 373 ~NetInterfaceStateCallback() = default; 374 int32_t OnInterfaceAddressUpdated(const std::string &addr, const std::string &ifName, int flags, 375 int scope) override; 376 int32_t OnInterfaceAddressRemoved(const std::string &addr, const std::string &ifName, int flags, 377 int scope) override; 378 int32_t OnInterfaceAdded(const std::string &iface) override; 379 int32_t OnInterfaceRemoved(const std::string &iface) override; 380 int32_t OnInterfaceChanged(const std::string &iface, bool up) override; 381 int32_t OnInterfaceLinkStateChanged(const std::string &iface, bool up) override; 382 int32_t OnRouteChanged(bool updated, const std::string &route, const std::string &gateway, 383 const std::string &ifName) override; 384 int32_t OnDhcpSuccess(NetsysControllerCallback::DhcpResult &dhcpResult) override; 385 int32_t OnBandwidthReachedLimit(const std::string &limitName, const std::string &iface) override; 386 387 int32_t RegisterInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback); 388 389 private: 390 std::mutex mutex_; 391 std::vector<sptr<INetInterfaceStateCallback>> ifaceStateCallbacks_; 392 }; 393 394 protected: 395 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 396 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 397 398 private: 399 enum RegisterType { 400 INVALIDTYPE, 401 REGISTER, 402 REQUEST, 403 }; 404 405 enum UserIdType { 406 ACTIVE, 407 LOCAL, 408 SPECIFY, 409 }; 410 bool Init(); 411 void GetHttpUrlFromConfig(std::string &httpUrl); 412 std::list<sptr<NetSupplier>> GetNetSupplierFromList(NetBearType bearerType, const std::string &ident = ""); 413 sptr<NetSupplier> GetNetSupplierFromList(NetBearType bearerType, const std::string &ident, 414 const std::set<NetCap> &netCaps); 415 int32_t ActivateNetwork(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> &callback, 416 const uint32_t &timeoutMS, const int32_t registerType = REGISTER, 417 const uint32_t callingUid = 0); 418 void CallbackForSupplier(sptr<NetSupplier> &supplier, CallbackType type); 419 void CallbackForAvailable(sptr<NetSupplier> &supplier, const sptr<INetConnCallback> &callback); 420 uint32_t FindBestNetworkForRequest(sptr<NetSupplier> &supplier, std::shared_ptr<NetActivate> &netActivateNetwork); 421 uint32_t FindInternalNetworkForRequest(std::shared_ptr<NetActivate> &netActivateNetwork, 422 sptr<NetSupplier> &supplier); 423 void SendRequestToAllNetwork(std::shared_ptr<NetActivate> request, const uint32_t callingUid = 0); 424 void SendBestScoreAllNetwork(uint32_t reqId, int32_t bestScore, uint32_t supplierId); 425 void SendAllRequestToNetwork(sptr<NetSupplier> supplier); 426 void FindBestNetworkForAllRequest(); 427 void MakeDefaultNetWork(sptr<NetSupplier> &oldService, sptr<NetSupplier> &newService); 428 void NotFindBestSupplier(uint32_t reqId, const std::shared_ptr<NetActivate> &active, 429 const sptr<NetSupplier> &supplier, const sptr<INetConnCallback> &callback); 430 void CreateDefaultRequest(); 431 int32_t RegUnRegNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback, bool isReg); 432 int32_t GenerateNetId(); 433 int32_t GenerateInternalNetId(); 434 bool FindSameCallback(const sptr<INetConnCallback> &callback, uint32_t &reqId); 435 bool FindSameCallback(const sptr<INetConnCallback> &callback, uint32_t &reqId, RegisterType ®isterType); 436 void GetDumpMessage(std::string &message); 437 sptr<NetSupplier> FindNetSupplier(uint32_t supplierId); 438 int32_t RegisterNetSupplierAsync(NetBearType bearerType, const std::string &ident, const std::set<NetCap> &netCaps, 439 uint32_t &supplierId); 440 int32_t UnregisterNetSupplierAsync(uint32_t supplierId); 441 int32_t RegisterNetSupplierCallbackAsync(uint32_t supplierId, const sptr<INetSupplierCallback> &callback); 442 int32_t RegisterNetConnCallbackAsync(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> &callback, 443 const uint32_t &timeoutMS, const uint32_t callingUid); 444 int32_t RequestNetConnectionAsync(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> &callback, 445 const uint32_t &timeoutMS, const uint32_t callingUid); 446 int32_t UnregisterNetConnCallbackAsync(const sptr<INetConnCallback> &callback, const uint32_t callingUid); 447 int32_t RegUnRegNetDetectionCallbackAsync(int32_t netId, const sptr<INetDetectionCallback> &callback, bool isReg); 448 int32_t UpdateNetStateForTestAsync(const sptr<NetSpecifier> &netSpecifier, int32_t netState); 449 int32_t UpdateNetSupplierInfoAsync(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo); 450 int32_t UpdateNetLinkInfoAsync(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo); 451 int32_t NetDetectionAsync(int32_t netId); 452 int32_t RestrictBackgroundChangedAsync(bool restrictBackground); 453 int32_t UpdateSupplierScoreAsync(NetBearType bearerType, uint32_t detectionStatus, uint32_t& supplierId); 454 void SendHttpProxyChangeBroadcast(const HttpProxy &httpProxy); 455 void RequestAllNetworkExceptDefault(); 456 void LoadGlobalHttpProxy(UserIdType userIdType, HttpProxy &httpProxy); 457 void UpdateGlobalHttpProxy(const HttpProxy &httpProxy); 458 int32_t SetGlobalHttpProxyOld(HttpProxy httpProxy, int32_t activeUserId); 459 int32_t SetGlobalHttpProxyInner(const HttpProxy &httpProxy); 460 void ActiveHttpProxy(); 461 void CreateActiveHttpProxyThread(); 462 void DecreaseNetConnCallbackCntForUid(const uint32_t callingUid, 463 const RegisterType registerType = REGISTER); 464 int32_t IncreaseNetConnCallbackCntForUid(const uint32_t callingUid, 465 const RegisterType registerType = REGISTER); 466 467 void OnNetSysRestart(); 468 469 bool IsSupplierMatchRequestAndNetwork(sptr<NetSupplier> ns); 470 std::vector<std::string> GetPreferredUrl(); 471 bool IsValidDecValue(const std::string &inputValue); 472 473 int32_t GetDelayNotifyTime(); 474 int32_t NetDetectionForDnsHealthSync(int32_t netId, bool dnsHealthSuccess); 475 std::vector<sptr<NetSupplier>> FindSupplierWithInternetByBearerType(NetBearType bearerType); 476 int32_t GetLocalUserId(int32_t &userId); 477 int32_t GetActiveUserId(int32_t &userId); 478 bool IsValidUserId(int32_t userId); 479 int32_t GetValidUserIdFromProxy(const HttpProxy &httpProxy); IsPrimaryUserId(const int32_t userId)480 inline bool IsPrimaryUserId(const int32_t userId) 481 { 482 return userId == PRIMARY_USER_ID; 483 } 484 uint32_t FindSupplierToReduceScore(std::vector<sptr<NetSupplier>>& suppliers, uint32_t& supplierId); 485 int32_t EnableVnicNetworkAsync(const sptr<NetLinkInfo> &netLinkInfo, const std::set<int32_t> &uids); 486 int32_t DisableVnicNetworkAsync(); 487 488 // for NET_CAPABILITY_INTERNAL_DEFAULT 489 bool IsInRequestNetUids(int32_t uid); 490 private: 491 enum ServiceRunningState { 492 STATE_STOPPED = 0, 493 STATE_RUNNING, 494 }; 495 496 bool registerToService_; 497 ServiceRunningState state_; 498 sptr<NetSpecifier> defaultNetSpecifier_ = nullptr; 499 std::shared_ptr<NetActivate> defaultNetActivate_ = nullptr; 500 sptr<NetSupplier> defaultNetSupplier_ = nullptr; 501 NET_SUPPLIER_MAP netSuppliers_; 502 NET_ACTIVATE_MAP netActivates_; 503 NET_UIDREQUEST_MAP netUidRequest_; 504 NET_UIDREQUEST_MAP internalDefaultUidRequest_; 505 NET_NETWORK_MAP networks_; 506 std::atomic<bool> vnicCreated = false; 507 sptr<NetConnServiceIface> serviceIface_ = nullptr; 508 std::atomic<int32_t> netIdLastValue_ = MIN_NET_ID - 1; 509 std::atomic<int32_t> internalNetIdLastValue_ = MIN_INTERNAL_NET_ID; 510 std::atomic<bool> isDataShareReady_ = false; 511 std::mutex globalHttpProxyMutex_; 512 SafeMap<int32_t, HttpProxy> globalHttpProxyCache_; 513 std::recursive_mutex netManagerMutex_; 514 std::shared_ptr<AppExecFwk::EventRunner> netConnEventRunner_ = nullptr; 515 std::shared_ptr<NetConnEventHandler> netConnEventHandler_ = nullptr; 516 sptr<NetInterfaceStateCallback> interfaceStateCallback_ = nullptr; 517 sptr<NetDnsResultCallback> dnsResultCallback_ = nullptr; 518 sptr<NetFactoryResetCallback> netFactoryResetCallback_ = nullptr; 519 std::mutex httpProxyThreadNeedRunMutex_; 520 std::atomic_bool httpProxyThreadNeedRun_ = false; 521 std::condition_variable httpProxyThreadCv_; 522 std::mutex httpProxyThreadMutex_; 523 static constexpr const uint32_t HTTP_PROXY_ACTIVE_PERIOD_S = 120; 524 std::map<int32_t, sptr<IPreAirplaneCallback>> preAirplaneCallbacks_; 525 std::mutex preAirplaneCbsMutex_; 526 std::shared_ptr<NetConnListener> subscriber_ = nullptr; 527 528 bool hasSARemoved_ = false; 529 static constexpr int32_t INVALID_USER_ID = -1; 530 static constexpr int32_t ROOT_USER_ID = 0; 531 int32_t currentUserId_ = INVALID_USER_ID; 532 std::mutex currentUserIdMutex_; 533 534 private: 535 class ConnCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 536 public: ConnCallbackDeathRecipient(NetConnService & client)537 explicit ConnCallbackDeathRecipient(NetConnService &client) : client_(client) {} 538 ~ConnCallbackDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)539 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 540 { 541 client_.OnRemoteDied(remote); 542 } 543 544 private: 545 NetConnService &client_; 546 }; 547 class NetSupplierCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 548 public: NetSupplierCallbackDeathRecipient(NetConnService & client)549 explicit NetSupplierCallbackDeathRecipient(NetConnService &client) : client_(client) {} 550 ~NetSupplierCallbackDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)551 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 552 { 553 client_.OnNetSupplierRemoteDied(remote); 554 } 555 556 private: 557 NetConnService &client_; 558 }; 559 560 void OnRemoteDied(const wptr<IRemoteObject> &remoteObject); 561 void OnNetSupplierRemoteDied(const wptr<IRemoteObject> &remoteObject); 562 void AddClientDeathRecipient(const sptr<INetConnCallback> &callback); 563 void AddNetSupplierDeathRecipient(const sptr<INetSupplierCallback> &callback); 564 void RemoveNetSupplierDeathRecipient(const sptr<INetSupplierCallback> &callback); 565 void RemoveClientDeathRecipient(const sptr<INetConnCallback> &callback); 566 void RemoveALLClientDeathRecipient(); 567 void OnReceiveEvent(const EventFwk::CommonEventData &data); 568 void SubscribeCommonEvent(const std::string &eventName, EventReceiver receiver); 569 std::mutex remoteMutex_; 570 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 571 sptr<IRemoteObject::DeathRecipient> netSuplierDeathRecipient_ = nullptr; 572 std::vector<sptr<INetConnCallback>> remoteCallback_; 573 bool CheckIfSettingsDataReady(); 574 std::mutex dataShareMutexWait; 575 std::condition_variable dataShareWait; 576 }; 577 } // namespace NetManagerStandard 578 } // namespace OHOS 579 #endif // NET_CONN_SERVICE_H 580