1 /*
2  * Copyright (c) 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 #include "netfirewall_callback_proxy.h"
16 #include "netnative_log_wrapper.h"
17 #include "netsys_ipc_interface_code.h"
18 
19 namespace OHOS {
20 namespace NetsysNative {
NetFirewallCallbackProxy(const sptr<IRemoteObject> & impl)21 NetFirewallCallbackProxy::NetFirewallCallbackProxy(const sptr<IRemoteObject> &impl)
22     : IRemoteProxy<INetFirewallCallback>(impl)
23 {}
24 
OnIntercept(sptr<NetManagerStandard::InterceptRecord> & record)25 int32_t NetFirewallCallbackProxy::OnIntercept(sptr<NetManagerStandard::InterceptRecord> &record)
26 {
27     NETNATIVE_LOGI("Proxy OnIntercept");
28     MessageParcel data;
29     if (!data.WriteInterfaceToken(NetFirewallCallbackProxy::GetDescriptor())) {
30         NETNATIVE_LOGE("WriteInterfaceToken failed");
31         return ERR_NULL_OBJECT;
32     }
33     if (!record->Marshalling(data)) {
34         return ERR_NONE;
35     }
36     sptr<IRemoteObject> remote = Remote();
37     if (remote == nullptr) {
38         NETNATIVE_LOGE("Remote is null");
39         return ERR_NULL_OBJECT;
40     }
41     MessageParcel reply;
42     MessageOption option;
43     int32_t ret = remote->SendRequest(static_cast<uint32_t>(NetFirewallfaceCode::ON_INTERCEPT), data, reply, option);
44     if (ret != ERR_NONE) {
45         NETNATIVE_LOGE("Proxy SendRequest failed, ret code:[%{public}d]", ret);
46     }
47     return ret;
48 }
49 } // namespace NetsysNative
50 } // namespace OHOS
51