• 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 "hdi_wrapper.h"
17 
18 #include <mutex>
19 
20 #include "iam_ptr.h"
21 #include "iproxy_broker.h"
22 
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
GetHdi()26 sptr<IUserAuthInterface> HdiWrapper::GetHdi()
27 {
28     static sptr<IUserAuthInterface> hdi = nullptr;
29     static std::mutex mutex;
30 
31     std::lock_guard<std::mutex> lock(mutex);
32     if (hdi != nullptr) {
33         auto remoteObject = HDI::hdi_objcast<IUserAuthInterface>(hdi);
34         if (remoteObject != nullptr && !remoteObject->IsObjectDead()) {
35             return hdi;
36         }
37     }
38 
39     hdi = IUserAuthInterface::Get();
40     return hdi;
41 }
42 
GetHdiInstance()43 std::shared_ptr<IUserAuthInterface> HdiWrapper::GetHdiInstance()
44 {
45     auto hdi = GetHdi();
46     if (!hdi) {
47         return nullptr;
48     }
49     return Common::SptrToStdSharedPtr<IUserAuthInterface>(hdi);
50 }
51 
GetHdiRemoteObjInstance()52 sptr<IRemoteObject> HdiWrapper::GetHdiRemoteObjInstance()
53 {
54     auto hdi = GetHdi();
55     if (!hdi) {
56         return sptr<IRemoteObject>(nullptr);
57     }
58     return HDI::hdi_objcast<IUserAuthInterface>(hdi);
59 }
60 } // namespace UserAuth
61 } // namespace UserIam
62 } // namespace OHOS
63