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 "domain_has_domain_info_callback.h"
17 #include "account_log_wrapper.h"
18 #include "domain_account_common.h"
19 #include "parcel.h"
20
21 namespace OHOS {
22 namespace AccountSA {
DomainHasDomainInfoCallback(const sptr<IDomainAccountCallback> & callback,const std::string & domain,const std::string & accountName)23 DomainHasDomainInfoCallback::DomainHasDomainInfoCallback(
24 const sptr<IDomainAccountCallback> &callback, const std::string &domain, const std::string &accountName)
25 : innerCallback_(callback), domain_(domain), accountName_(accountName)
26 {}
27
OnResult(const int32_t errCode,Parcel & parcel)28 void DomainHasDomainInfoCallback::OnResult(const int32_t errCode, Parcel &parcel)
29 {
30 if (innerCallback_ == nullptr) {
31 ACCOUNT_LOGE("innerPlugin_ is nullptr");
32 return;
33 }
34 Parcel parcelResult;
35 if (errCode != ERR_OK) {
36 parcelResult.WriteBool(false);
37 return innerCallback_->OnResult(errCode, parcelResult);
38 }
39 std::shared_ptr<AAFwk::WantParams> parameters(AAFwk::WantParams::Unmarshalling(parcel));
40 if (parameters == nullptr) {
41 ACCOUNT_LOGE("parameters unmarshalling error");
42 parcelResult.WriteBool(false);
43 return innerCallback_->OnResult(ERR_ACCOUNT_COMMON_INSUFFICIENT_MEMORY_ERROR, parcelResult);
44 }
45 DomainAccountInfo info;
46 info.accountName_ = parameters->GetStringParam("accountName");
47 info.domain_ = parameters->GetStringParam("domain");
48 info.accountId_ = parameters->GetStringParam("accountId");
49 if ((info.domain_ != domain_) || (info.accountName_ != accountName_)) {
50 parcelResult.WriteBool(false);
51 return innerCallback_->OnResult(errCode, parcelResult);
52 }
53 parcelResult.WriteBool(true);
54 return innerCallback_->OnResult(errCode, parcelResult);
55 }
56 } // namespace AccountSA
57 } // namespace OHOS