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 #include "netsys_traffic_callback_proxy.h"
16 #include "netnative_log_wrapper.h"
17 #include "netsys_ipc_interface_code.h"
18
19 namespace OHOS {
20 namespace NetsysNative {
NetsysTrafficCallbackProxy(const sptr<IRemoteObject> & impl)21 NetsysTrafficCallbackProxy::NetsysTrafficCallbackProxy(const sptr<IRemoteObject> &impl)
22 : IRemoteProxy<INetsysTrafficCallback>(impl)
23 {}
24
OnExceedTrafficLimits(int8_t & flag)25 int32_t NetsysTrafficCallbackProxy::OnExceedTrafficLimits(int8_t &flag)
26 {
27 NETNATIVE_LOGI("Proxy OnExceedTrafficLimits");
28 MessageParcel data;
29 if (!data.WriteInterfaceToken(NetsysTrafficCallbackProxy::GetDescriptor())) {
30 NETNATIVE_LOGE("WriteInterfaceToken failed");
31 return ERR_NULL_OBJECT;
32 }
33 if (!data.WriteInt8(flag)) {
34 NETNATIVE_LOGE("Write flag failed");
35 return ERR_NULL_OBJECT;
36 }
37 sptr<IRemoteObject> remote = Remote();
38 if (remote == nullptr) {
39 NETNATIVE_LOGE("Remote is null");
40 return ERR_NULL_OBJECT;
41 }
42 MessageParcel reply;
43 MessageOption option;
44 int32_t ret = remote->SendRequest(
45 static_cast<uint32_t>(NetsysTrafficfaceCode::NETSYS_TRAFFIC_STATUS_CHANGED), data, reply, option);
46 if (ret != ERR_NONE) {
47 NETNATIVE_LOGE("Proxy SendRequest failed, ret code:[%{public}d]", ret);
48 }
49 return ret;
50 }
51 } // namespace NetsysNative
52 } // namespace OHOS
53