• 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_client.h"
17 
18 #include <cstdint>
19 #include <mutex>
20 
21 #include "if_system_ability_manager.h"
22 #include "iremote_broker.h"
23 #include "iremote_object.h"
24 #include "iservice_registry.h"
25 #include "refbase.h"
26 #include "system_ability_definition.h"
27 
28 #include "iam_logger.h"
29 
30 #include "face_auth_defines.h"
31 #include "iface_auth.h"
32 
33 #define LOG_LABEL UserIam::Common::LABEL_FACE_AUTH_SDK
34 
35 namespace OHOS {
36 namespace UserIam {
37 namespace FaceAuth {
SetBufferProducer(sptr<IBufferProducer> & producer)38 int32_t FaceAuthClient::SetBufferProducer(sptr<IBufferProducer> &producer)
39 {
40     IAM_LOGI("start");
41     sptr<IFaceAuth> proxy = GetFaceAuthProxy();
42     if (proxy == nullptr) {
43         IAM_LOGE("get faceAuthProxy fail");
44         return FACE_AUTH_ERROR;
45     }
46     return proxy->SetBufferProducer(producer);
47 }
48 
OnRemoteDied(const wptr<IRemoteObject> & remote)49 void FaceAuthClient::OnRemoteDied(const wptr<IRemoteObject> &remote)
50 {
51     IAM_LOGI("start");
52     std::lock_guard<std::mutex> lock(mutex_);
53     if ((faceAuthProxy_ != nullptr) && (faceAuthProxy_->AsObject() != nullptr)) {
54         faceAuthProxy_->AsObject()->RemoveDeathRecipient(this);
55     }
56     faceAuthProxy_ = nullptr;
57     return;
58 }
59 
GetFaceAuthProxy()60 sptr<IFaceAuth> FaceAuthClient::GetFaceAuthProxy()
61 {
62     IAM_LOGI("start");
63     std::lock_guard<std::mutex> lock(mutex_);
64     if (faceAuthProxy_ != nullptr) {
65         return faceAuthProxy_;
66     }
67 
68     sptr<ISystemAbilityManager> systemAbilityManager =
69         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
70     if (systemAbilityManager == nullptr) {
71         IAM_LOGE("failed to get systemAbilityManager.");
72         return nullptr;
73     }
74 
75     sptr<IRemoteObject> remoteObject = systemAbilityManager->CheckSystemAbility(SUBSYS_USERIAM_SYS_ABILITY_FACEAUTH);
76     if (remoteObject == nullptr) {
77         IAM_LOGE("failed to get remoteObject.");
78         return nullptr;
79     }
80 
81     faceAuthProxy_ = iface_cast<IFaceAuth>(remoteObject);
82     if ((faceAuthProxy_ == nullptr) || (faceAuthProxy_->AsObject() == nullptr)) {
83         IAM_LOGE("failed to get faceAuthProxy_");
84         return nullptr;
85     }
86 
87     faceAuthProxy_->AsObject()->AddDeathRecipient(this);
88     return faceAuthProxy_;
89 }
90 } // namespace FaceAuth
91 } // namespace UserIam
92 } // namespace OHOS
93