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 "distributed_device_profile_log.h"
17 #include "ipc_utils.h"
18 #include "message_parcel.h"
19 #include "pincode_invalid_callback_stub.h"
20
21 namespace OHOS {
22 namespace DistributedDeviceProfile {
23 namespace {
24 const std::string TAG = "PinCodeInvalidCallbackStub";
25 }
26
PinCodeInvalidCallbackStub()27 PinCodeInvalidCallbackStub::PinCodeInvalidCallbackStub()
28 {
29 HILOGI("constructor!");
30 }
31
~PinCodeInvalidCallbackStub()32 PinCodeInvalidCallbackStub::~PinCodeInvalidCallbackStub()
33 {
34 HILOGI("destruct!");
35 }
36
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)37 int32_t PinCodeInvalidCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
38 MessageParcel& reply, MessageOption& option)
39 {
40 HILOGI("Code = %{public}u", code);
41 std::u16string descriptor = PinCodeInvalidCallbackStub::GetDescriptor();
42 std::u16string remoteDescriptor = data.ReadInterfaceToken();
43 if (descriptor != remoteDescriptor) {
44 HILOGE("Check descriptor failed");
45 return DP_INTERFACE_CHECK_FAILED;
46 }
47 if (code != static_cast<uint32_t>(DPInterfaceCode::ON_PINCODE_INVALID)) {
48 HILOGW("Unknown request code, code = %{public}u", code);
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51 return OnPincodeInvalidInner(data, reply);
52 }
53
OnPincodeInvalidInner(MessageParcel & data,MessageParcel & reply)54 int32_t PinCodeInvalidCallbackStub::OnPincodeInvalidInner(MessageParcel& data, MessageParcel& reply)
55 {
56 HILOGI("called");
57 LocalServiceInfo localServiceInfo;
58 if (!localServiceInfo.UnMarshalling(data)) {
59 HILOGE("read parcel fail!");
60 return DP_READ_PARCEL_FAIL;
61 }
62 int32_t ret = OnPincodeInvalid(localServiceInfo);
63 if (!reply.WriteInt32(ret)) {
64 HILOGE("Write reply failed");
65 return ERR_FLATTEN_OBJECT;
66 }
67 return DP_SUCCESS;
68 }
69 } // namespace DistributedDeviceProfile
70 } // namespace OHOS
71