1 /*
2 * Copyright (c) 2022 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 "user_auth_callback_stub.h"
17
18 #include <cinttypes>
19
20 #include "iam_logger.h"
21 #include "user_auth_interface.h"
22
23 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SDK
24
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int32_t UserAuthCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
29 MessageOption &option)
30 {
31 IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
32 if (UserAuthCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
33 IAM_LOGE("descriptor is not matched");
34 return GENERAL_ERROR;
35 }
36
37 switch (code) {
38 case UserAuthInterface::USER_AUTH_ON_RESULT:
39 return OnResultStub(data, reply);
40 case UserAuthInterface::USER_AUTH_ACQUIRE_INFO:
41 return OnAcquireInfoStub(data, reply);
42 default:
43 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
44 }
45 }
46
OnResultStub(MessageParcel & data,MessageParcel & reply)47 int32_t UserAuthCallbackStub::OnResultStub(MessageParcel &data, MessageParcel &reply)
48 {
49 int32_t result;
50 std::vector<uint8_t> buffer;
51
52 if (!data.ReadInt32(result)) {
53 IAM_LOGE("failed to read result");
54 return READ_PARCEL_ERROR;
55 }
56 if (!data.ReadUInt8Vector(&buffer)) {
57 IAM_LOGE("failed to read buffer");
58 return READ_PARCEL_ERROR;
59 }
60
61 Attributes extraInfo(buffer);
62 OnResult(result, extraInfo);
63 return SUCCESS;
64 }
65
OnAcquireInfoStub(MessageParcel & data,MessageParcel & reply)66 int32_t UserAuthCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply)
67 {
68 int32_t module;
69 int32_t acquireInfo;
70 std::vector<uint8_t> buffer;
71
72 if (!data.ReadInt32(module)) {
73 IAM_LOGE("failed to read module");
74 return READ_PARCEL_ERROR;
75 }
76 if (!data.ReadInt32(acquireInfo)) {
77 IAM_LOGE("failed to read acquireInfo");
78 return READ_PARCEL_ERROR;
79 }
80 if (!data.ReadUInt8Vector(&buffer)) {
81 IAM_LOGE("failed to read buffer");
82 return READ_PARCEL_ERROR;
83 }
84
85 Attributes extraInfo(buffer);
86 OnAcquireInfo(module, acquireInfo, extraInfo);
87 return SUCCESS;
88 }
89
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)90 int32_t GetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
91 MessageOption &option)
92 {
93 IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
94 if (GetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
95 IAM_LOGE("descriptor is not matched");
96 return GENERAL_ERROR;
97 }
98
99 if (code == UserAuthInterface::USER_AUTH_GET_EX_PROP) {
100 return OnGetExecutorPropertyResultStub(data, reply);
101 }
102 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
103 }
104
OnGetExecutorPropertyResultStub(MessageParcel & data,MessageParcel & reply)105 int32_t GetExecutorPropertyCallbackStub::OnGetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply)
106 {
107 int32_t result;
108 std::vector<uint8_t> buffer;
109
110 if (!data.ReadInt32(result)) {
111 IAM_LOGE("failed to read result");
112 return READ_PARCEL_ERROR;
113 }
114 if (!data.ReadUInt8Vector(&buffer)) {
115 IAM_LOGE("failed to read buffer");
116 return READ_PARCEL_ERROR;
117 }
118
119 Attributes attr(buffer);
120 OnGetExecutorPropertyResult(result, attr);
121 return SUCCESS;
122 }
123
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)124 int32_t SetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
125 MessageOption &option)
126 {
127 IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
128 if (SetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
129 IAM_LOGE("descriptor is not matched");
130 return GENERAL_ERROR;
131 }
132
133 if (code == UserAuthInterface::USER_AUTH_SET_EX_PROP) {
134 return OnSetExecutorPropertyResultStub(data, reply);
135 }
136 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
137 }
138
OnSetExecutorPropertyResultStub(MessageParcel & data,MessageParcel & reply)139 int32_t SetExecutorPropertyCallbackStub::OnSetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply)
140 {
141 int32_t result;
142
143 if (!data.ReadInt32(result)) {
144 IAM_LOGE("failed to read result");
145 return READ_PARCEL_ERROR;
146 }
147 OnSetExecutorPropertyResult(result);
148 return SUCCESS;
149 }
150 } // namespace UserAuth
151 } // namespace UserIam
152 } // namespace OHOS