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_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(const std::string & cmdData)27 void WidgetCallbackProxy::SendCommand(const std::string &cmdData)
28 {
29     IAM_LOGI("start");
30 
31     MessageParcel data;
32     MessageParcel reply;
33 
34     if (!data.WriteInterfaceToken(WidgetCallbackProxy::GetDescriptor())) {
35         IAM_LOGE("write descriptor failed");
36         return;
37     }
38     if (!data.WriteString(cmdData)) {
39         IAM_LOGE("write cmd data failed");
40         return;
41     }
42     bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND, data, reply);
43     if (!ret) {
44         IAM_LOGE("send request failed");
45     }
46 }
47 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)48 bool WidgetCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
49 {
50     IAM_LOGI("start code = %{public}u", code);
51     sptr<IRemoteObject> remote = Remote();
52     if (remote == nullptr) {
53         IAM_LOGE("get remote failed");
54         return false;
55     }
56     MessageOption option(MessageOption::TF_SYNC);
57     int32_t result = remote->SendRequest(code, data, reply, option);
58     if (result != OHOS::NO_ERROR) {
59         IAM_LOGE("send request failed, result = %{public}d", result);
60         return false;
61     }
62     IAM_LOGI("end");
63     return true;
64 }
65 } // namespace UserAuth
66 } // namespace UserIam
67 } // namespace OHOS