1 /*
2 * Copyright (c) 2021-2023 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_detection_callback_stub.h"
16
17 #include "net_mgr_log_wrapper.h"
18
19 namespace OHOS {
20 namespace NetManagerStandard {
NetDetectionCallbackStub()21 NetDetectionCallbackStub::NetDetectionCallbackStub()
22 {
23 memberFuncMap_[static_cast<uint32_t>(DetectionCallback::NET_DETECTION_RESULT)] =
24 &NetDetectionCallbackStub::OnNetDetectionResult;
25 }
26
~NetDetectionCallbackStub()27 NetDetectionCallbackStub::~NetDetectionCallbackStub() {}
28
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t NetDetectionCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
30 MessageOption &option)
31 {
32 NETMGR_LOG_D("Stub call start, code:[%{public}d]", code);
33 std::u16string myDescripter = NetDetectionCallbackStub::GetDescriptor();
34 std::u16string remoteDescripter = data.ReadInterfaceToken();
35 if (myDescripter != remoteDescripter) {
36 NETMGR_LOG_E("Descriptor checked failed");
37 return 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 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 }
50
OnNetDetectionResult(MessageParcel & data,MessageParcel & reply)51 int32_t NetDetectionCallbackStub::OnNetDetectionResult(MessageParcel &data, MessageParcel &reply)
52 {
53 if (!data.ContainFileDescriptors()) {
54 NETMGR_LOG_E("Execute ContainFileDescriptors failed");
55 }
56 std::string urlRedirect;
57 if (!data.ReadString(urlRedirect)) {
58 return NETMANAGER_ERR_READ_DATA_FAIL;
59 }
60
61 int32_t netDetectionResult = 0;
62 if (!data.ReadInt32(netDetectionResult)) {
63 return NETMANAGER_ERR_READ_DATA_FAIL;
64 }
65
66 int32_t ret = OnNetDetectionResultChanged(static_cast<NetDetectionResultCode>(netDetectionResult), urlRedirect);
67 if (!reply.WriteInt32(ret)) {
68 NETMGR_LOG_E("Write parcel failed");
69 return ret;
70 }
71
72 return NETMANAGER_SUCCESS;
73 }
74 } // namespace NetManagerStandard
75 } // namespace OHOS
76