• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "widget_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 {
WidgetCallbackService(const std::shared_ptr<IUserAuthWidgetCallback> & impl)28 WidgetCallbackService::WidgetCallbackService(const std::shared_ptr<IUserAuthWidgetCallback> &impl)
29     : widgetCallback_(impl),
30     iamHitraceHelper_(Common::MakeShared<UserIam::UserAuth::IamHitraceHelper>("UserAuthWidget"))
31 {
32     CallbackManager::CallbackAction action = [impl]() {
33         if (impl != nullptr) {
34             IAM_LOGI("user auth service death, auth widget callback return default result to caller");
35             std::string command = "";
36             impl->SendCommand(command);
37         }
38     };
39     CallbackManager::GetInstance().AddCallback(reinterpret_cast<uintptr_t>(this), action);
40 }
41 
~WidgetCallbackService()42 WidgetCallbackService::~WidgetCallbackService()
43 {
44     CallbackManager::GetInstance().RemoveCallback(reinterpret_cast<uintptr_t>(this));
45 }
46 
SendCommand(const std::string & cmdData)47 int32_t WidgetCallbackService::SendCommand(const std::string &cmdData)
48 {
49     IAM_LOGD("start");
50     if (widgetCallback_ == nullptr) {
51         IAM_LOGE("both widget callback is nullptr");
52         return GENERAL_ERROR;
53     }
54     widgetCallback_->SendCommand(cmdData);
55     iamHitraceHelper_= nullptr;
56     return SUCCESS;
57 }
58 
CallbackEnter(uint32_t code)59 int32_t WidgetCallbackService::CallbackEnter([[maybe_unused]] uint32_t code)
60 {
61     IAM_LOGI("start, code:%{public}u", code);
62     return SUCCESS;
63 }
64 
CallbackExit(uint32_t code,int32_t result)65 int32_t WidgetCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
66 {
67     IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result);
68     return SUCCESS;
69 }
70 } // namespace UserAuth
71 } // namespace UserIam
72 } // namespace OHOS