• 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_callback_stub.h"
17 
18 #include "account_error_no.h"
19 #include "account_log_wrapper.h"
20 #include "ipc_skeleton.h"
21 
22 namespace OHOS {
23 namespace AccountSA {
24 const std::map<uint32_t, IDMCallbackStub::MessageProcFunction> IDMCallbackStub::messageProcMap_ = {
25     {
26         static_cast<uint32_t>(IIDMCallback::Message::ON_ACQUIRE_INFO),
27         &IDMCallbackStub::ProcOnAcquireInfo
28     },
29     {
30         static_cast<uint32_t>(IIDMCallback::Message::ON_RESULT),
31         &IDMCallbackStub::ProcOnResult
32     }
33 };
34 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int IDMCallbackStub::OnRemoteRequest(
36     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
39         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingPid());
40     if (data.ReadInterfaceToken() != GetDescriptor()) {
41         ACCOUNT_LOGE("check IDMCallbackStub descriptor failed! code %{public}u.", code);
42         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
43     }
44     const auto &itFunc = messageProcMap_.find(code);
45     if (itFunc != messageProcMap_.end()) {
46         return (this->*(itFunc->second))(data, reply);
47     }
48     ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
49     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51 
ProcOnAcquireInfo(MessageParcel & data,MessageParcel & reply)52 ErrCode IDMCallbackStub::ProcOnAcquireInfo(MessageParcel &data, MessageParcel &reply)
53 {
54     int32_t module;
55     int32_t acquireInfo;
56     std::vector<uint8_t> buffer;
57     if (!data.ReadInt32(module)) {
58         ACCOUNT_LOGE("failed to read module");
59         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
60     }
61     if (!data.ReadInt32(acquireInfo)) {
62         ACCOUNT_LOGE("failed to read acquireInfo");
63         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
64     }
65     if (!data.ReadUInt8Vector(&buffer)) {
66         ACCOUNT_LOGE("failed to read buffer");
67         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
68     }
69     Attributes extraInfo(buffer);
70     OnAcquireInfo(module, acquireInfo, extraInfo);
71     return ERR_OK;
72 }
73 
ProcOnResult(MessageParcel & data,MessageParcel & reply)74 ErrCode IDMCallbackStub::ProcOnResult(MessageParcel &data, MessageParcel &reply)
75 {
76     int32_t result;
77     if (!data.ReadInt32(result)) {
78         ACCOUNT_LOGE("failed to read result for IDMCallback OnResult");
79         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
80     }
81     std::vector<uint8_t> buffer;
82     if (!data.ReadUInt8Vector(&buffer)) {
83         ACCOUNT_LOGE("failed to read result for IDMCallback OnResult");
84         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
85     }
86     Attributes extraInfo(buffer);
87     OnResult(result, extraInfo);
88     return ERR_OK;
89 }
90 
91 const std::map<uint32_t, GetCredInfoCallbackStub::MessageProcFunction>
92     GetCredInfoCallbackStub::messageProcMap_ = {
93     {
94         static_cast<uint32_t>(IGetCredInfoCallback::Message::ON_CREDENTIAL_INFO),
95         &GetCredInfoCallbackStub::ProcOnCredentialInfo
96     }
97 };
98 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)99 int GetCredInfoCallbackStub::OnRemoteRequest(
100     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
101 {
102     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
103         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingPid());
104     if (data.ReadInterfaceToken() != GetDescriptor()) {
105         ACCOUNT_LOGE("check GetCredInfoCallbackStub descriptor failed! code %{public}u.", code);
106         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
107     }
108     const auto &itFunc = messageProcMap_.find(code);
109     if (itFunc != messageProcMap_.end()) {
110         return (this->*(itFunc->second))(data, reply);
111     }
112     ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
113     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
114 }
115 
ProcOnCredentialInfo(MessageParcel & data,MessageParcel & reply)116 ErrCode GetCredInfoCallbackStub::ProcOnCredentialInfo(MessageParcel &data, MessageParcel &reply)
117 {
118     uint32_t vectorSize = 0;
119     std::vector<CredentialInfo> infoList;
120     if (!data.ReadUint32(vectorSize)) {
121         ACCOUNT_LOGE("read size fail");
122         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
123     }
124     for (uint32_t i = 0; i < vectorSize; ++i) {
125         CredentialInfo info;
126         int32_t authType = 0;
127         int32_t pinType = 0;
128         if (!data.ReadUint64(info.credentialId)) {
129             ACCOUNT_LOGE("failed to read credentialId");
130             return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
131         }
132         if (!data.ReadInt32(authType)) {
133             ACCOUNT_LOGE("failed to read authType");
134             return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
135         }
136         if (!data.ReadInt32(pinType)) {
137             ACCOUNT_LOGE("failed to read pinSubType");
138             return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
139         }
140         if (!data.ReadUint64(info.templateId)) {
141             ACCOUNT_LOGE("failed to read templateId");
142             return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
143         }
144         info.authType = static_cast<AuthType>(authType);
145         info.pinType = static_cast<PinSubType>(pinType);
146         infoList.push_back(info);
147     }
148     OnCredentialInfo(infoList);
149     return ERR_OK;
150 }
151 
152 const std::map<uint32_t, GetSetPropCallbackStub::MessageProcFunction> GetSetPropCallbackStub::messageProcMap_ = {
153     {
154         static_cast<uint32_t>(IGetSetPropCallback::Message::ON_RESULT),
155         &GetSetPropCallbackStub::ProcOnResult
156     }
157 };
158 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)159 int GetSetPropCallbackStub::OnRemoteRequest(
160     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
161 {
162     ACCOUNT_LOGD("Received stub message: %{public}d, callingUid: %{public}d, callingPid: %{public}d",
163         code, IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingPid());
164     if (data.ReadInterfaceToken() != GetDescriptor()) {
165         ACCOUNT_LOGE("check GetSetPropCallbackStub descriptor failed! code %{public}u.", code);
166         return ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR;
167     }
168     const auto &itFunc = messageProcMap_.find(code);
169     if (itFunc != messageProcMap_.end()) {
170         return (this->*(itFunc->second))(data, reply);
171     }
172     ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
173     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
174 }
175 
ProcOnResult(MessageParcel & data,MessageParcel & reply)176 ErrCode GetSetPropCallbackStub::ProcOnResult(MessageParcel &data, MessageParcel &reply)
177 {
178     int32_t result;
179     if (!data.ReadInt32(result)) {
180         ACCOUNT_LOGE("failed to read result for GetSetPropCallback OnResult");
181         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
182     }
183     std::vector<uint8_t> buffer;
184     if (!data.ReadUInt8Vector(&buffer)) {
185         ACCOUNT_LOGE("failed to read result for GetSetPropCallback OnResult");
186         return ERR_ACCOUNT_IAM_KIT_READ_PARCEL_FAIL;
187     }
188     Attributes extraInfo(buffer);
189     OnResult(result, extraInfo);
190     return ERR_OK;
191 }
192 }  // namespace AccountSA
193 }  // namespace OHOS
194