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 "face_auth_proxy.h"
17 
18 #include <cstdint>
19 
20 #include "ibuffer_producer.h"
21 #include "ipc_types.h"
22 #include "iremote_object.h"
23 #include "iremote_proxy.h"
24 #include "message_option.h"
25 #include "message_parcel.h"
26 #include "refbase.h"
27 
28 #include "iam_logger.h"
29 
30 #include "face_auth_defines.h"
31 #include "iface_auth.h"
32 
33 #define LOG_TAG "FACE_AUTH_SDK"
34 
35 namespace OHOS {
36 namespace UserIam {
37 namespace FaceAuth {
FaceAuthProxy(const sptr<IRemoteObject> & object)38 FaceAuthProxy::FaceAuthProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IFaceAuth>(object)
39 {
40 }
41 
SetBufferProducer(sptr<IBufferProducer> & producer)42 int32_t FaceAuthProxy::SetBufferProducer(sptr<IBufferProducer> &producer)
43 {
44     MessageParcel data;
45     MessageParcel reply;
46     if (!data.WriteInterfaceToken(FaceAuthProxy::GetDescriptor())) {
47         IAM_LOGE("write descriptor failed");
48         return FACE_AUTH_ERROR;
49     }
50     if (producer != nullptr) {
51         if (!data.WriteRemoteObject(producer->AsObject())) {
52             IAM_LOGE("failed to WriteRemoteObject(producer).");
53             return FACE_AUTH_ERROR;
54         }
55     }
56     bool ret = SendRequest(IFaceAuthInterfaceCode::FACE_AUTH_SET_BUFFER_PRODUCER, data, reply);
57     if (!ret) {
58         IAM_LOGE("failed to send request.");
59         return FACE_AUTH_ERROR;
60     }
61     int32_t result = reply.ReadInt32();
62     IAM_LOGI("result = %{public}d", result);
63     return result;
64 }
65 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)66 bool FaceAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
67 {
68     IAM_LOGI("start");
69     sptr<IRemoteObject> remote = Remote();
70     if (remote == nullptr) {
71         IAM_LOGE("failed to get remote.");
72         return false;
73     }
74     MessageOption option(MessageOption::TF_SYNC);
75     int32_t result = remote->SendRequest(code, data, reply, option);
76     if (result != OHOS::NO_ERROR) {
77         IAM_LOGE("failed to SendRequest.result = %{public}d", result);
78         return false;
79     }
80     return true;
81 }
82 } // namespace FaceAuth
83 } // namespace UserIam
84 } // namespace OHOS