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 "remote_iam_callback.h"
17
18 #include "iam_check.h"
19 #include "iam_ptr.h"
20 #include "remote_connect_manager.h"
21 #include "remote_msg_util.h"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
RemoteIamCallback(std::string & connectionName)26 RemoteIamCallback::RemoteIamCallback(std::string &connectionName) : connectionName_(connectionName)
27 {
28 endPointName_ = REMOTE_CALLBACK_ENDPOINT_NAME;
29 }
30
~RemoteIamCallback()31 RemoteIamCallback::~RemoteIamCallback()
32 {
33 }
34
OnResult(int32_t result,const Attributes & extraInfo)35 void RemoteIamCallback::OnResult(int32_t result, const Attributes &extraInfo)
36 {
37 IAM_LOGI("result: %{public}d", result);
38
39 std::shared_ptr<Attributes> request = Common::MakeShared<Attributes>(extraInfo.Serialize());
40 IF_FALSE_LOGE_AND_RETURN(request != nullptr);
41
42 bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_RESULT);
43 IF_FALSE_LOGE_AND_RETURN(setMsgTypeRet);
44
45 bool setResultRet = request->SetInt32Value(Attributes::ATTR_RESULT, result);
46 IF_FALSE_LOGE_AND_RETURN(setResultRet);
47
48 MsgCallback msgCallback = [](const std::shared_ptr<Attributes> &) { IAM_LOGI("message sent"); };
49
50 ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_,
51 REMOTE_AUTH_INVOKER_CONTEXT_ENDPOINT_NAME, request, msgCallback);
52 IF_FALSE_LOGE_AND_RETURN(sendMsgRet == ResultCode::SUCCESS);
53
54 IAM_LOGI("success");
55 }
56
OnAcquireInfo(int32_t module,int32_t acquireInfo,const Attributes & extraInfo)57 void RemoteIamCallback::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo)
58 {
59 IAM_LOGI("module: %{public}d, acquireInfo: %{public}d", module, acquireInfo);
60
61 std::shared_ptr<Attributes> request = Common::MakeShared<Attributes>(extraInfo.Serialize());
62 IF_FALSE_LOGE_AND_RETURN(request != nullptr);
63
64 bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_TIP);
65 IF_FALSE_LOGE_AND_RETURN(setMsgTypeRet);
66
67 bool setModuleRet = request->SetInt32Value(Attributes::ATTR_DEST_ROLE, module);
68 IF_FALSE_LOGE_AND_RETURN(setModuleRet);
69
70 bool setAcquireInfoRet = request->SetInt32Value(Attributes::ATTR_TIP_INFO, acquireInfo);
71 IF_FALSE_LOGE_AND_RETURN(setAcquireInfoRet);
72
73 MsgCallback msgCallback = [](const std::shared_ptr<Attributes> &) { IAM_LOGI("message sent"); };
74
75 ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_,
76 REMOTE_AUTH_INVOKER_CONTEXT_ENDPOINT_NAME, request, msgCallback);
77 IF_FALSE_LOGE_AND_RETURN(sendMsgRet == ResultCode::SUCCESS);
78
79 IAM_LOGI("success");
80 }
81
AsObject()82 sptr<IRemoteObject> RemoteIamCallback::AsObject()
83 {
84 return nullptr;
85 }
86 } // namespace UserAuth
87 } // namespace UserIam
88 } // namespace OHOS