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 "user_access_ctrl_callback_proxy.h"
17
18 #include "iam_logger.h"
19 #include "user_access_ctrl_callback_interface.h"
20
21 #define LOG_TAG "USER_ACCESS_CTRL_SDK"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
OnVerifyTokenResult(int32_t result,const Attributes & attributes)26 void VerifyTokenCallbackProxy::OnVerifyTokenResult(int32_t result, const Attributes &attributes)
27 {
28 IAM_LOGI("start, result: %{public}d", result);
29
30 MessageParcel data;
31 MessageParcel reply;
32
33 if (!data.WriteInterfaceToken(VerifyTokenCallbackProxy::GetDescriptor())) {
34 IAM_LOGE("failed to write descriptor");
35 return;
36 }
37 if (!data.WriteInt32(result)) {
38 IAM_LOGE("write result failed");
39 return;
40 }
41 auto buffer = attributes.Serialize();
42 if (!data.WriteUInt8Vector(buffer)) {
43 IAM_LOGE("write buffer failed");
44 return;
45 }
46
47 bool ret = SendRequest(UserAccessCtrlCallbackInterfaceCode::ON_VERIFY_TOKEN_RESULT, data, reply);
48 if (!ret) {
49 IAM_LOGE("failed to send request");
50 }
51 }
52
53
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)54 bool VerifyTokenCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
55 {
56 IAM_LOGI("start code = %{public}u", code);
57 sptr<IRemoteObject> remote = Remote();
58 if (remote == nullptr) {
59 IAM_LOGE("failed to get remote");
60 return false;
61 }
62 MessageOption option(MessageOption::TF_ASYNC);
63 int32_t result = remote->SendRequest(code, data, reply, option);
64 if (result != SUCCESS) {
65 IAM_LOGE("failed to send request result = %{public}d", result);
66 return false;
67 }
68
69 IAM_LOGI("end");
70 return true;
71 }
72 } // namespace UserAuth
73 } // namespace UserIam
74 } // namespace OHOS
75