• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "net_conn_callback_proxy_wrapper.h"
17 
18 namespace OHOS {
19 namespace NetManagerStandard {
NetConnCallbackProxyWrapper(const sptr<INetConnCallback> & callback)20 NetConnCallbackProxyWrapper::NetConnCallbackProxyWrapper(const sptr<INetConnCallback> &callback)
21     : netConnCallback_(callback) {}
22 
~NetConnCallbackProxyWrapper()23 NetConnCallbackProxyWrapper::~NetConnCallbackProxyWrapper() {}
24 
NetAvailable(sptr<NetHandle> & netHandle)25 int32_t NetConnCallbackProxyWrapper::NetAvailable(sptr<NetHandle> &netHandle)
26 {
27     if (IsAllowCallback(CALL_TYPE_AVAILABLE)) {
28         return netConnCallback_->NetAvailable(netHandle);
29     }
30     return NETMANAGER_SUCCESS;
31 }
32 
NetCapabilitiesChange(sptr<NetHandle> & netHandle,const sptr<NetAllCapabilities> & netAllCap)33 int32_t NetConnCallbackProxyWrapper::NetCapabilitiesChange(
34     sptr<NetHandle> &netHandle, const sptr<NetAllCapabilities> &netAllCap)
35 {
36     if (IsAllowCallback(CALL_TYPE_UPDATE_CAP)) {
37         return netConnCallback_->NetCapabilitiesChange(netHandle, netAllCap);
38     }
39     return NETMANAGER_SUCCESS;
40 }
41 
NetConnectionPropertiesChange(sptr<NetHandle> & netHandle,const sptr<NetLinkInfo> & info)42 int32_t NetConnCallbackProxyWrapper::NetConnectionPropertiesChange
43     (sptr<NetHandle> &netHandle, const sptr<NetLinkInfo> &info)
44 {
45     if (IsAllowCallback(CALL_TYPE_UPDATE_LINK)) {
46         return netConnCallback_->NetConnectionPropertiesChange(netHandle, info);
47     }
48     return NETMANAGER_SUCCESS;
49 }
50 
NetLost(sptr<NetHandle> & netHandle)51 int32_t NetConnCallbackProxyWrapper::NetLost(sptr<NetHandle> &netHandle)
52 {
53     if (IsAllowCallback(CALL_TYPE_LOST)) {
54         return netConnCallback_->NetLost(netHandle);
55     }
56     return NETMANAGER_SUCCESS;
57 }
58 
NetUnavailable()59 int32_t NetConnCallbackProxyWrapper::NetUnavailable()
60 {
61     if (IsAllowCallback(CALL_TYPE_UNAVAILABLE)) {
62         return netConnCallback_->NetUnavailable();
63     }
64     return NETMANAGER_SUCCESS;
65 }
66 
NetBlockStatusChange(sptr<NetHandle> & netHandle,bool blocked)67 int32_t NetConnCallbackProxyWrapper::NetBlockStatusChange(sptr<NetHandle> &netHandle, bool blocked)
68 {
69     if (IsAllowCallback(CALL_TYPE_BLOCK_STATUS)) {
70         return netConnCallback_->NetBlockStatusChange(netHandle, blocked);
71     }
72     return NETMANAGER_SUCCESS;
73 }
74 
AsObject()75 sptr<IRemoteObject> NetConnCallbackProxyWrapper::AsObject()
76 {
77     if (netConnCallback_ == nullptr) {
78         return nullptr;
79     }
80     return netConnCallback_->AsObject();
81 }
82 
SetNetActivate(std::shared_ptr<NetActivate> netActivate)83 void NetConnCallbackProxyWrapper::SetNetActivate(std::shared_ptr<NetActivate> netActivate)
84 {
85     netActivate_ = netActivate;
86 }
87 
IsAllowCallback(CallbackType callback)88 bool NetConnCallbackProxyWrapper::IsAllowCallback(CallbackType callback)
89 {
90     if (netConnCallback_ == nullptr) {
91         return false;
92     }
93     auto netActivate = netActivate_.lock();
94     if (netActivate) {
95         bool isAllow = netActivate->IsAllowCallback(callback);
96         if (!isAllow) {
97             return false;
98         }
99     }
100     return true;
101 }
102 
103 } // namespace NetManagerStandard
104 } // namespace OHOS
105