• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "modal_callback_service.h"
17 
18 #include "callback_manager.h"
19 #include "iam_logger.h"
20 #include "iam_ptr.h"
21 #include "iam_common_defines.h"
22 
23 #define LOG_TAG "USER_AUTH_SDK"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
ModalCallbackService(const std::shared_ptr<UserAuthModalClientCallback> & impl)28 ModalCallbackService::ModalCallbackService(const std::shared_ptr<UserAuthModalClientCallback> &impl)
29     : modalCallback_(impl),
30     iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuthWidget"))
31 {
32     IAM_LOGI("set modal callback");
33     CallbackManager::CallbackAction action = [impl]() {
34         if (impl != nullptr) {
35             IAM_LOGI("user auth service death, auth widget callback return default result to caller");
36             uint64_t contextId = 0;
37             std::string cmdData = "";
38             impl->SendCommand(contextId, cmdData);
39         }
40     };
41     CallbackManager::GetInstance().AddCallback(reinterpret_cast<uintptr_t>(this), action);
42 }
43 
~ModalCallbackService()44 ModalCallbackService::~ModalCallbackService()
45 {
46     IAM_LOGI("~ModalCallbackService clean");
47     iamHitraceHelper_= nullptr;
48     CallbackManager::GetInstance().RemoveCallback(reinterpret_cast<uintptr_t>(this));
49 }
50 
SendCommand(uint64_t contextId,const std::string & cmdData)51 int32_t ModalCallbackService::SendCommand(uint64_t contextId, const std::string &cmdData)
52 {
53     IAM_LOGI("SendCommand start");
54     if (modalCallback_ == nullptr) {
55         IAM_LOGE("modal callback is nullptr");
56         return GENERAL_ERROR;
57     }
58     modalCallback_->SendCommand(contextId, cmdData);
59     iamHitraceHelper_ = nullptr;
60     return SUCCESS;
61 }
62 
CallbackEnter(uint32_t code)63 int32_t ModalCallbackService::CallbackEnter([[maybe_unused]] uint32_t code)
64 {
65     IAM_LOGI("start, code:%{public}u", code);
66     return SUCCESS;
67 }
68 
CallbackExit(uint32_t code,int32_t result)69 int32_t ModalCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
70 {
71     IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result);
72     return SUCCESS;
73 }
74 } // namespace UserAuth
75 } // namespace UserIam
76 } // namespace OHOS