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_proxy.h"
17
18 #include "iam_logger.h"
19 #include "iam_common_defines.h"
20 #include "user_auth_interface.h"
21
22 #define LOG_TAG "USER_AUTH_SA"
23
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
SendCommand(uint64_t contextId,const std::string & cmdData)27 void ModalCallbackProxy::SendCommand(uint64_t contextId, const std::string &cmdData)
28 {
29 IAM_LOGI("start");
30
31 MessageParcel data;
32 MessageParcel reply;
33
34 if (!data.WriteInterfaceToken(ModalCallbackProxy::GetDescriptor())) {
35 IAM_LOGE("write descriptor failed");
36 return;
37 }
38 if (!data.WriteUint64(contextId)) {
39 IAM_LOGE("write context id failed");
40 return;
41 }
42 if (!data.WriteString(cmdData)) {
43 IAM_LOGE("write cmd data failed");
44 return;
45 }
46
47 bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_AUTH_MODAL_SEND_COMMAND, data, reply);
48 if (!ret) {
49 IAM_LOGE("send request failed");
50 }
51 }
52
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)53 bool ModalCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
54 {
55 IAM_LOGI("start code = %{public}u", code);
56 sptr<IRemoteObject> remote = Remote();
57 if (remote == nullptr) {
58 IAM_LOGE("get remote failed");
59 return false;
60 }
61 MessageOption option(MessageOption::TF_ASYNC);
62 int32_t result = remote->SendRequest(code, data, reply, option);
63 if (result != OHOS::NO_ERROR) {
64 IAM_LOGE("send request failed, result = %{public}d", result);
65 return false;
66 }
67 IAM_LOGI("end");
68 return true;
69 }
70 } // namespace UserAuth
71 } // namespace UserIam
72 } // namespace OHOS