• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "account_iam_client_callback_proxy.h"
17 
18 #include "account_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace AccountSA {
SendRequestFunc(const sptr<IRemoteObject> & remote,uint32_t code,MessageParcel & data,MessageParcel & reply)22 static ErrCode SendRequestFunc(
23     const sptr<IRemoteObject> &remote, uint32_t code, MessageParcel &data, MessageParcel &reply)
24 {
25     if (remote == nullptr) {
26         ACCOUNT_LOGE("remote is nullptr, code = %{public}d", code);
27         return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
28     }
29     MessageOption option(MessageOption::TF_SYNC);
30     int32_t result = remote->SendRequest(code, data, reply, option);
31     if (result != ERR_OK) {
32         ACCOUNT_LOGE("failed to SendRequest, code = %{public}d, result = %{public}d", code, result);
33         return ERR_ACCOUNT_IAM_KIT_SEND_REQUEST;
34     }
35     return ERR_OK;
36 }
37 
OnResultFunc(const sptr<IRemoteObject> & remote,uint32_t code,std::u16string descriptor,int32_t result,const Attributes & extraInfo)38 static void OnResultFunc(const sptr<IRemoteObject> &remote, uint32_t code, std::u16string descriptor,
39     int32_t result, const Attributes &extraInfo)
40 {
41     MessageParcel data;
42     MessageParcel reply;
43     if (!data.WriteInterfaceToken(descriptor)) {
44         ACCOUNT_LOGE("write descriptor fail");
45         return;
46     }
47     if (!data.WriteInt32(result)) {
48         ACCOUNT_LOGE("write result fail");
49         return;
50     }
51     auto buffer = extraInfo.Serialize();
52     if (!data.WriteUInt8Vector(buffer)) {
53         ACCOUNT_LOGE("write buffer fail");
54         return;
55     }
56     SendRequestFunc(remote, code, data, reply);
57 }
58 
IDMCallbackProxy(const sptr<IRemoteObject> & object)59 IDMCallbackProxy::IDMCallbackProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IIDMCallback>(object)
60 {}
61 
OnAcquireInfo(int32_t module,uint32_t acquireInfo,const Attributes & extraInfo)62 void IDMCallbackProxy::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)
63 {
64     MessageParcel data;
65     MessageParcel reply;
66     if (!data.WriteInterfaceToken(GetDescriptor())) {
67         ACCOUNT_LOGE("write descriptor fail");
68         return;
69     }
70     if (!data.WriteInt32(module)) {
71         ACCOUNT_LOGE("write module fail");
72         return;
73     }
74     if (!data.WriteUint32(acquireInfo)) {
75         ACCOUNT_LOGE("write acquireInfo fail");
76         return;
77     }
78     auto buffer = extraInfo.Serialize();
79     if (!data.WriteUInt8Vector(buffer)) {
80         ACCOUNT_LOGE("write buffer fail");
81         return;
82     }
83     uint32_t code = static_cast<uint32_t>(IIDMCallback::Message::ON_ACQUIRE_INFO);
84     SendRequestFunc(Remote(), code, data, reply);
85 }
86 
OnResult(int32_t result,const Attributes & extraInfo)87 void IDMCallbackProxy::OnResult(int32_t result, const Attributes &extraInfo)
88 {
89     uint32_t code = static_cast<uint32_t>(IIDMCallback::Message::ON_RESULT);
90     OnResultFunc(Remote(), code, GetDescriptor(), result, extraInfo);
91 }
92 
GetCredInfoCallbackProxy(const sptr<IRemoteObject> & object)93 GetCredInfoCallbackProxy::GetCredInfoCallbackProxy(const sptr<IRemoteObject> &object)
94     : IRemoteProxy<IGetCredInfoCallback>(object)
95 {}
96 
OnCredentialInfo(const std::vector<CredentialInfo> & infoList)97 void GetCredInfoCallbackProxy::OnCredentialInfo(const std::vector<CredentialInfo> &infoList)
98 {
99     MessageParcel data;
100     MessageParcel reply;
101     if (!data.WriteInterfaceToken(GetDescriptor())) {
102         ACCOUNT_LOGE("write descriptor fail");
103         return;
104     }
105     if (!data.WriteUint32(infoList.size())) {
106         ACCOUNT_LOGE("write info size fail");
107         return;
108     }
109     for (const auto &info : infoList) {
110         if (!data.WriteUint64(info.credentialId)) {
111             ACCOUNT_LOGE("write credentialId fail");
112             return;
113         }
114         if (!data.WriteInt32(info.authType)) {
115             ACCOUNT_LOGE("write authType fail");
116             return;
117         }
118         PinSubType pinType = info.pinType.value_or(PinSubType::PIN_MAX);
119         if (!data.WriteInt32(pinType)) {
120             ACCOUNT_LOGE("write authSubType fail");
121             return;
122         }
123         if (!data.WriteUint64(info.templateId)) {
124             ACCOUNT_LOGE("write templateId fail");
125             return;
126         }
127     }
128     uint32_t code = static_cast<uint32_t>(IGetCredInfoCallback::Message::ON_CREDENTIAL_INFO);
129     SendRequestFunc(Remote(), code, data, reply);
130 }
131 
GetSetPropCallbackProxy(const sptr<IRemoteObject> & object)132 GetSetPropCallbackProxy::GetSetPropCallbackProxy(const sptr<IRemoteObject> &object)
133     : IRemoteProxy<IGetSetPropCallback>(object)
134 {}
135 
OnResult(int32_t result,const Attributes & extraInfo)136 void GetSetPropCallbackProxy::OnResult(int32_t result, const Attributes &extraInfo)
137 {
138     uint32_t code = static_cast<uint32_t>(IGetSetPropCallback::Message::ON_RESULT);
139     OnResultFunc(Remote(), code, GetDescriptor(), result, extraInfo);
140 }
141 }  // namespace AccountSA
142 }  // namespace OHOS
143