• 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 "netsys_traffic_callback_stub.h"
17 #include "net_manager_constants.h"
18 #include "netnative_log_wrapper.h"
19 #include "netsys_ipc_interface_code.h"
20 
21 namespace OHOS {
22 namespace NetsysNative {
NetsysTrafficCallbackStub()23 NetsysTrafficCallbackStub::NetsysTrafficCallbackStub()
24 {
25     memberFuncMap_[static_cast<uint32_t>(NetsysTrafficfaceCode::NETSYS_TRAFFIC_STATUS_CHANGED)] =
26         &NetsysTrafficCallbackStub::CmdOnExceedTrafficLimits;
27 }
28 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t NetsysTrafficCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
30     MessageOption &option)
31 {
32     NETNATIVE_LOGI("Stub call start, code:[%{public}d]", code);
33     std::u16string myDescriptor = NetsysTrafficCallbackStub::GetDescriptor();
34     std::u16string remoteDescriptor = data.ReadInterfaceToken();
35     if (myDescriptor != remoteDescriptor) {
36         NETNATIVE_LOGE("Descriptor checked failed");
37         return NetManagerStandard::NETMANAGER_ERR_DESCRIPTOR_MISMATCH;
38     }
39 
40     auto itFunc = memberFuncMap_.find(code);
41     if (itFunc != memberFuncMap_.end()) {
42         auto requestFunc = itFunc->second;
43         if (requestFunc != nullptr) {
44             return (this->*requestFunc)(data, reply);
45         }
46     }
47 
48     NETNATIVE_LOGI("Stub default case, need check");
49     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51 
CmdOnExceedTrafficLimits(MessageParcel & data,MessageParcel & reply)52 int32_t NetsysTrafficCallbackStub::CmdOnExceedTrafficLimits(MessageParcel &data, MessageParcel &reply)
53 {
54     int8_t flag = 0;
55     if (!data.ReadInt8(flag)) {
56         NETNATIVE_LOGE("CmdOnExceedTrafficLimits read flag failed");
57         return NetManagerStandard::NETMANAGER_ERR_READ_DATA_FAIL;
58     }
59     int32_t result = OnExceedTrafficLimits(flag);
60     if (!reply.WriteInt32(result)) {
61         return NetManagerStandard::NETMANAGER_ERR_WRITE_REPLY_FAIL;
62     }
63     return NetManagerStandard::NETMANAGER_SUCCESS;
64 }
65 
OnExceedTrafficLimits(int8_t & flag)66 int32_t NetsysTrafficCallbackStub::OnExceedTrafficLimits(int8_t &flag)
67 {
68     return NetManagerStandard::NETMANAGER_SUCCESS;
69 }
70 } // namespace NetsysNative
71 } // namespace OHOS
72