• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
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_LOGI("code = %{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 UserAuthInterfaceCode::USER_AUTH_ON_RESULT:
39             return OnResultStub(data, reply);
40         case UserAuthInterfaceCode::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     IAM_LOGI("start");
50     int32_t result;
51     std::vector<uint8_t> buffer;
52 
53     if (!data.ReadInt32(result)) {
54         IAM_LOGE("failed to read result");
55         return READ_PARCEL_ERROR;
56     }
57     if (!data.ReadUInt8Vector(&buffer)) {
58         IAM_LOGE("failed to read buffer");
59         return READ_PARCEL_ERROR;
60     }
61 
62     Attributes extraInfo(buffer);
63     OnResult(result, extraInfo);
64     return SUCCESS;
65 }
66 
OnAcquireInfoStub(MessageParcel & data,MessageParcel & reply)67 int32_t UserAuthCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply)
68 {
69     IAM_LOGI("start");
70     int32_t module;
71     int32_t acquireInfo;
72     std::vector<uint8_t> buffer;
73 
74     if (!data.ReadInt32(module)) {
75         IAM_LOGE("failed to read module");
76         return READ_PARCEL_ERROR;
77     }
78     if (!data.ReadInt32(acquireInfo)) {
79         IAM_LOGE("failed to read acquireInfo");
80         return READ_PARCEL_ERROR;
81     }
82     if (!data.ReadUInt8Vector(&buffer)) {
83         IAM_LOGE("failed to read buffer");
84         return READ_PARCEL_ERROR;
85     }
86 
87     Attributes extraInfo(buffer);
88     OnAcquireInfo(module, acquireInfo, extraInfo);
89     return SUCCESS;
90 }
91 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)92 int32_t GetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
93     MessageOption &option)
94 {
95     IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags());
96     if (GetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
97         IAM_LOGE("descriptor is not matched");
98         return GENERAL_ERROR;
99     }
100 
101     if (code == UserAuthInterfaceCode::USER_AUTH_GET_EX_PROP) {
102         return OnGetExecutorPropertyResultStub(data, reply);
103     }
104     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
105 }
106 
OnGetExecutorPropertyResultStub(MessageParcel & data,MessageParcel & reply)107 int32_t GetExecutorPropertyCallbackStub::OnGetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply)
108 {
109     IAM_LOGI("start");
110     int32_t result;
111     std::vector<uint8_t> buffer;
112 
113     if (!data.ReadInt32(result)) {
114         IAM_LOGE("failed to read result");
115         return READ_PARCEL_ERROR;
116     }
117     if (!data.ReadUInt8Vector(&buffer)) {
118         IAM_LOGE("failed to read buffer");
119         return READ_PARCEL_ERROR;
120     }
121 
122     Attributes attr(buffer);
123     OnGetExecutorPropertyResult(result, attr);
124     return SUCCESS;
125 }
126 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)127 int32_t SetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
128     MessageOption &option)
129 {
130     IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags());
131     if (SetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) {
132         IAM_LOGE("descriptor is not matched");
133         return GENERAL_ERROR;
134     }
135 
136     if (code == UserAuthInterfaceCode::USER_AUTH_SET_EX_PROP) {
137         return OnSetExecutorPropertyResultStub(data, reply);
138     }
139     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
140 }
141 
OnSetExecutorPropertyResultStub(MessageParcel & data,MessageParcel & reply)142 int32_t SetExecutorPropertyCallbackStub::OnSetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply)
143 {
144     IAM_LOGI("start");
145     int32_t result;
146 
147     if (!data.ReadInt32(result)) {
148         IAM_LOGE("failed to read result");
149         return READ_PARCEL_ERROR;
150     }
151     OnSetExecutorPropertyResult(result);
152     return SUCCESS;
153 }
154 } // namespace UserAuth
155 } // namespace UserIam
156 } // namespace OHOS