• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "net_conn_callback.h"
16 #include "net_manager_constants.h"
17 #include "networkslicecommconfig.h"
18 #include "networksliceutil.h"
19 #include "hwnetworkslicemanager.h"
20 
21 namespace OHOS {
22 namespace NetManagerStandard {
NetAvailable(sptr<NetHandle> & netHandle)23 int32_t NetConnCallback::NetAvailable(sptr<NetHandle> &netHandle)
24 {
25     int32_t netId = netHandle->GetNetId();
26     netId_ = netId;
27     NETMGR_EXT_LOG_I("netconn callback, netAvailable, netId: %{public}d", netId);
28     DelayedSingleton<HwNetworkSliceManager>::GetInstance()->OnNetworkAvailable(mNetCap_, netId);
29     std::shared_ptr<NetworkSliceInfo> info =
30         DelayedSingleton<HwNetworkSliceManager>::GetInstance()->GetNetworkSliceInfoByParaNetCap(mNetCap_);
31     if (info != nullptr) {
32         info->setNetId(netId);
33     }
34     return NetManagerStandard::NETMANAGER_SUCCESS;
35 }
36 
NetLost(sptr<NetHandle> & netHandle)37 int32_t NetConnCallback::NetLost(sptr<NetHandle> &netHandle)
38 {
39     int32_t netId = netHandle->GetNetId();
40     netId_ = 0;
41     NETMGR_EXT_LOG_I("netconn callback, NetLost, netId: %{public}d", netId);
42     DelayedSingleton<HwNetworkSliceManager>::GetInstance()->OnNetworkLost(mNetCap_, netId);
43     return NetManagerStandard::NETMANAGER_SUCCESS;
44 }
45 
NetUnavailable()46 int32_t NetConnCallback::NetUnavailable()
47 {
48     NETMGR_EXT_LOG_E("netconn callback, NetUnavailable");
49     DelayedSingleton<HwNetworkSliceManager>::GetInstance()->OnNetworkUnavailable(mNetCap_);
50     return NetManagerStandard::NETMANAGER_SUCCESS;
51 }
52 
SetNetCap(NetCap netCap)53 void NetConnCallback::SetNetCap(NetCap netCap)
54 {
55     mNetCap_ = netCap;
56 }
57 
GetNetCap()58 NetCap NetConnCallback::GetNetCap()
59 {
60     return mNetCap_;
61 }
62 
CacheRequestUid(int32_t uid)63 void NetConnCallback::CacheRequestUid(int32_t uid)
64 {
65     mRequestUids_.insert(uid);
66 }
67 
RemoveRequestUid(int32_t uid)68 void NetConnCallback::RemoveRequestUid(int32_t uid)
69 {
70     mRequestUids_.erase(uid);
71 }
72 
GetRequestUids()73 std::set<int32_t> NetConnCallback::GetRequestUids()
74 {
75     return mRequestUids_;
76 }
77 
SetUid(int32_t uid)78 void NetConnCallback::SetUid(int32_t uid)
79 {
80     mUid_ = uid;
81 }
82 
GetUid()83 int32_t NetConnCallback::GetUid()
84 {
85     return mUid_;
86 }
87 
GetNetId()88 int32_t NetConnCallback::GetNetId()
89 {
90     return netId_;
91 }
92 }
93 }
94