• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "face_auth_stub.h"
17 
18 #include <cstdint>
19 #include <functional>
20 #include <map>
21 #include <string>
22 #include <utility>
23 
24 #include "buffer_client_producer.h"
25 #include "ibuffer_producer.h"
26 #include "ipc_object_stub.h"
27 #include "iremote_broker.h"
28 #include "message_parcel.h"
29 #include "refbase.h"
30 
31 #include "iam_check.h"
32 #include "iam_logger.h"
33 #include "iam_para2str.h"
34 
35 #include "face_auth_defines.h"
36 #include "iface_auth.h"
37 
38 #define LOG_LABEL UserIam::Common::LABEL_FACE_AUTH_SDK
39 
40 namespace OHOS {
41 namespace UserIam {
42 namespace FaceAuth {
43 using namespace OHOS::UserIam;
FaceAuthStub()44 FaceAuthStub::FaceAuthStub()
45 {
46     IAM_LOGI("start");
47     RegisterKeyToHandle();
48 }
49 
RegisterKeyToHandle()50 void FaceAuthStub::RegisterKeyToHandle()
51 {
52     keyToHandle_[FACE_AUTH_SET_BUFFER_PRODUCER] = &FaceAuthStub::FaceAuthSetBufferProducer;
53 }
54 
FaceAuthSetBufferProducer(MessageParcel & data,MessageParcel & reply)55 int32_t FaceAuthStub::FaceAuthSetBufferProducer(MessageParcel &data, MessageParcel &reply)
56 {
57     sptr<IBufferProducer> buffer = nullptr;
58     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
59     IAM_LOGI("read remote object %{public}s", Common::GetPointerNullStateString(remoteObj).c_str());
60     buffer = iface_cast<BufferClientProducer>(remoteObj);
61     int32_t ret = SetBufferProducer(buffer);
62     IAM_LOGI("SetBufferProducer ret %{public}d", ret);
63     if (!reply.WriteInt32(ret)) {
64         IAM_LOGE("failed to WriteInt32(ret)");
65         return FACE_AUTH_ERROR;
66     }
67     return FACE_AUTH_SUCCESS;
68 }
69 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)70 int32_t FaceAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
71 {
72     IAM_LOGI("start");
73     if (data.ReadInterfaceToken() != FaceAuthStub::GetDescriptor()) {
74         IAM_LOGE("descriptor is not matched");
75         return FACE_AUTH_ERROR;
76     }
77     auto itFunc = keyToHandle_.find(code);
78     if (itFunc == keyToHandle_.end()) {
79         IAM_LOGE("key not match, send to IPCObjectStub on default");
80         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
81     }
82     auto requestFunc = itFunc->second;
83     IF_FALSE_LOGE_AND_RETURN_VAL(requestFunc != nullptr, FACE_AUTH_ERROR);
84     return (this->*requestFunc)(data, reply);
85 }
86 } // namespace FaceAuth
87 } // namespace UserIam
88 } // namespace OHOS