• 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 "co_auth_client_impl.h"
17 
18 #include "system_ability_definition.h"
19 
20 #include "executor_callback_service.h"
21 #include "iam_logger.h"
22 #include "ipc_client_utils.h"
23 
24 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SDK
25 
26 namespace OHOS {
27 namespace UserIam {
28 namespace UserAuth {
Register(const ExecutorInfo & info,const std::shared_ptr<ExecutorRegisterCallback> & callback)29 void CoAuthClientImpl::Register(const ExecutorInfo &info, const std::shared_ptr<ExecutorRegisterCallback> &callback)
30 {
31     if (!callback) {
32         IAM_LOGE("callback is nullptr");
33         return;
34     }
35 
36     auto proxy = GetProxy();
37     if (!proxy) {
38         return;
39     }
40 
41     CoAuthInterface::ExecutorRegisterInfo regInfo;
42     regInfo.authType = info.authType;
43     regInfo.executorRole = info.executorRole;
44     regInfo.executorSensorHint = info.executorSensorHint;
45     regInfo.executorMatcher = info.executorMatcher;
46     regInfo.esl = info.esl;
47     regInfo.publicKey = info.publicKey;
48 
49     sptr<ExecutorCallbackInterface> wrapper = new (std::nothrow) ExecutorCallbackService(callback);
50     if (wrapper == nullptr) {
51         IAM_LOGE("failed to create wrapper");
52         return;
53     }
54     proxy->ExecutorRegister(regInfo, wrapper);
55 }
56 
Unregister(const ExecutorInfo & info)57 void CoAuthClientImpl::Unregister(const ExecutorInfo &info)
58 {
59 }
60 
GetProxy()61 sptr<CoAuthInterface> CoAuthClientImpl::GetProxy()
62 {
63     auto obj = IpcClientUtils::GetRemoteObject(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR);
64     if (!obj) {
65         IAM_LOGE("failed to get service");
66         return nullptr;
67     }
68 
69     return iface_cast<CoAuthInterface>(obj);
70 }
71 
GetInstance()72 CoAuthClient &CoAuthClient::GetInstance()
73 {
74     static CoAuthClientImpl impl;
75     return impl;
76 }
77 } // namespace UserAuth
78 } // namespace UserIam
79 } // namespace OHOS