• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
17 #include <vector>
18 #include "account_log_wrapper.h"
19 #include "domain_account_common.h"
20 #include "parcel.h"
21 
22 namespace OHOS {
23 namespace AccountSA {
24 
DomainAccountInfo()25 DomainAccountInfo::DomainAccountInfo() : domain_(""), accountName_(""), accountId_("")
26 {}
27 
DomainAccountInfo(const std::string & domain,const std::string & domainAccountName)28 DomainAccountInfo::DomainAccountInfo(const std::string &domain, const std::string &domainAccountName)
29     : domain_(domain), accountName_(domainAccountName)
30 {}
31 
DomainAccountInfo(const std::string & domain,const std::string & domainAccountName,const std::string & accountId)32 DomainAccountInfo::DomainAccountInfo(
33     const std::string &domain, const std::string &domainAccountName, const std::string &accountId)
34     : domain_(domain), accountName_(domainAccountName), accountId_(accountId)
35 {}
36 
Clear()37 void DomainAccountInfo::Clear()
38 {
39     domain_.clear();
40     accountName_.clear();
41     accountId_.clear();
42 }
43 
ReadFromParcel(Parcel & parcel)44 bool DomainAccountInfo::ReadFromParcel(Parcel &parcel)
45 {
46     if (!parcel.ReadString(accountName_)) {
47         ACCOUNT_LOGE("failed to read domain account name");
48         return false;
49     }
50     if (!parcel.ReadString(domain_)) {
51         ACCOUNT_LOGE("failed to read domain");
52         return false;
53     }
54     if (!parcel.ReadString(accountId_)) {
55         ACCOUNT_LOGE("failed to read domain accountId");
56         return false;
57     }
58     return true;
59 }
60 
Marshalling(Parcel & parcel) const61 bool DomainAccountInfo::Marshalling(Parcel &parcel) const
62 {
63     if (!parcel.WriteString(accountName_)) {
64         ACCOUNT_LOGE("failed to read write account name");
65         return false;
66     }
67     if (!parcel.WriteString(domain_)) {
68         ACCOUNT_LOGE("failed to write domain");
69         return false;
70     }
71     if (!parcel.WriteString(accountId_)) {
72         ACCOUNT_LOGE("failed to read write accountId");
73         return false;
74     }
75     return true;
76 }
77 
Unmarshalling(Parcel & parcel)78 DomainAccountInfo *DomainAccountInfo::Unmarshalling(Parcel &parcel)
79 {
80     DomainAccountInfo *domainAccountInfo = new (std::nothrow) DomainAccountInfo();
81     if (domainAccountInfo == nullptr) {
82         return nullptr;
83     }
84 
85     if (!domainAccountInfo->ReadFromParcel(parcel)) {
86         ACCOUNT_LOGE("failed to read from parcel");
87         delete domainAccountInfo;
88         domainAccountInfo = nullptr;
89     }
90 
91     return domainAccountInfo;
92 }
93 
GetAccessTokenOptions(const int32_t & callingUid,const AAFwk::WantParams & getTokenParams)94 GetAccessTokenOptions::GetAccessTokenOptions(const int32_t &callingUid, const AAFwk::WantParams &getTokenParams)
95     : callingUid_(callingUid), getTokenParams_(getTokenParams)
96 {}
97 
GetAccessTokenOptions()98 GetAccessTokenOptions::GetAccessTokenOptions()
99 {}
100 
ReadFromParcel(Parcel & parcel)101 bool GetAccessTokenOptions::ReadFromParcel(Parcel &parcel)
102 {
103     if (!parcel.ReadInt32(callingUid_)) {
104         ACCOUNT_LOGE("failed to read callingUid");
105         return false;
106     }
107     auto param = parcel.ReadParcelable<AAFwk::WantParams>();
108     if (param == nullptr) {
109         ACCOUNT_LOGE("failed to read wantParams");
110         return false;
111     }
112     getTokenParams_ = (*param);
113     delete param;
114     return true;
115 }
116 
Marshalling(Parcel & parcel) const117 bool GetAccessTokenOptions::Marshalling(Parcel &parcel) const
118 {
119     if (!parcel.WriteInt32(callingUid_)) {
120         ACCOUNT_LOGE("failed to read write callingUid");
121         return false;
122     }
123     if (!parcel.WriteParcelable(&getTokenParams_)) {
124         ACCOUNT_LOGE("failed to write getTokenParams");
125         return false;
126     }
127     return true;
128 }
129 
Unmarshalling(Parcel & parcel)130 GetAccessTokenOptions *GetAccessTokenOptions::Unmarshalling(Parcel &parcel)
131 {
132     GetAccessTokenOptions *getAccessTokenOptions = new (std::nothrow) GetAccessTokenOptions();
133     if (getAccessTokenOptions == nullptr) {
134         return nullptr;
135     }
136 
137     if (!getAccessTokenOptions->ReadFromParcel(parcel)) {
138         ACCOUNT_LOGE("failed to read from parcel");
139         delete getAccessTokenOptions;
140         getAccessTokenOptions = nullptr;
141     }
142 
143     return getAccessTokenOptions;
144 }
145 
ReadFromParcel(Parcel & parcel)146 bool GetDomainAccountInfoOptions::ReadFromParcel(Parcel &parcel)
147 {
148     std::shared_ptr<DomainAccountInfo> infoPtr(parcel.ReadParcelable<DomainAccountInfo>());
149     if (infoPtr == nullptr) {
150         ACCOUNT_LOGE("failed to read authStatusInfo");
151         return false;
152     }
153     accountInfo = *infoPtr;
154     if (!parcel.ReadInt32(callingUid)) {
155         ACCOUNT_LOGE("failed to read callingUid");
156         return false;
157     }
158     return true;
159 }
160 
Marshalling(Parcel & parcel) const161 bool GetDomainAccountInfoOptions::Marshalling(Parcel &parcel) const
162 {
163     if (!parcel.WriteParcelable(&accountInfo)) {
164         ACCOUNT_LOGE("failed to write authStatusInfo");
165         return false;
166     }
167     if (!parcel.WriteInt32(callingUid)) {
168         ACCOUNT_LOGE("failed to read write callingUid");
169         return false;
170     }
171     return true;
172 }
173 
Unmarshalling(Parcel & parcel)174 GetDomainAccountInfoOptions *GetDomainAccountInfoOptions::Unmarshalling(Parcel &parcel)
175 {
176     GetDomainAccountInfoOptions *getAccountInfoOptions = new (std::nothrow) GetDomainAccountInfoOptions();
177     if (getAccountInfoOptions == nullptr) {
178         return nullptr;
179     }
180 
181     if (!getAccountInfoOptions->ReadFromParcel(parcel)) {
182         ACCOUNT_LOGE("failed to read from parcel");
183         delete getAccountInfoOptions;
184         getAccountInfoOptions = nullptr;
185     }
186 
187     return getAccountInfoOptions;
188 }
189 
ReadFromParcel(Parcel & parcel)190 bool AuthStatusInfo::ReadFromParcel(Parcel &parcel)
191 {
192     if (!parcel.ReadInt32(remainingTimes)) {
193         ACCOUNT_LOGE("failed to read remainingTimes");
194         return false;
195     }
196     if (!parcel.ReadInt32(freezingTime)) {
197         ACCOUNT_LOGE("failed to read freezingTime");
198         return false;
199     }
200     return true;
201 }
202 
Marshalling(Parcel & parcel) const203 bool AuthStatusInfo::Marshalling(Parcel &parcel) const
204 {
205     if (!parcel.WriteInt32(remainingTimes)) {
206         ACCOUNT_LOGE("failed to read write remainingTimes");
207         return false;
208     }
209     if (!parcel.WriteInt32(freezingTime)) {
210         ACCOUNT_LOGE("failed to write freezingTime");
211         return false;
212     }
213     return true;
214 }
215 
Unmarshalling(Parcel & parcel)216 AuthStatusInfo *AuthStatusInfo::Unmarshalling(Parcel &parcel)
217 {
218     AuthStatusInfo *info = new (std::nothrow) AuthStatusInfo();
219     if (info == nullptr) {
220         ACCOUNT_LOGE("failed to create AuthStatusInfo");
221         return nullptr;
222     }
223     if (!info->ReadFromParcel(parcel)) {
224         ACCOUNT_LOGE("failed to read from parcel");
225         delete info;
226         info = nullptr;
227     }
228     return info;
229 }
230 
ReadFromParcel(Parcel & parcel)231 bool DomainAuthResult::ReadFromParcel(Parcel &parcel)
232 {
233     if (!parcel.ReadUInt8Vector(&token)) {
234         ACCOUNT_LOGE("failed to read remainingTimes");
235         return false;
236     }
237     std::shared_ptr<AuthStatusInfo> infoPtr(parcel.ReadParcelable<AuthStatusInfo>());
238     if (infoPtr == nullptr) {
239         ACCOUNT_LOGE("failed to read authStatusInfo");
240         return false;
241     }
242     authStatusInfo = *infoPtr;
243     return true;
244 }
245 
Marshalling(Parcel & parcel) const246 bool DomainAuthResult::Marshalling(Parcel &parcel) const
247 {
248     if (!parcel.WriteUInt8Vector(token)) {
249         ACCOUNT_LOGE("failed to read write token");
250         return false;
251     }
252     if (!parcel.WriteParcelable(&authStatusInfo)) {
253         ACCOUNT_LOGE("failed to write authStatusInfo");
254         return false;
255     }
256     return true;
257 }
258 
Unmarshalling(Parcel & parcel)259 DomainAuthResult *DomainAuthResult::Unmarshalling(Parcel &parcel)
260 {
261     DomainAuthResult *result = new (std::nothrow) DomainAuthResult();
262     if (result == nullptr) {
263         ACCOUNT_LOGE("failed to create DomainAuthResult");
264         return nullptr;
265     }
266     if (!result->ReadFromParcel(parcel)) {
267         ACCOUNT_LOGE("failed to read from parcel");
268         delete result;
269         result = nullptr;
270     }
271     return result;
272 }
273 }  // namespace AccountSA
274 }  // namespace OHOS