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 #include "start_hce_info_parcelable.h" 16 #include "loghelper.h" 17 #include "nfc_sdk_common.h" 18 namespace OHOS { 19 namespace NFC { 20 namespace KITS { StartHceInfoParcelable(const std::vector<std::string> & aids,const ElementName & element)21StartHceInfoParcelable::StartHceInfoParcelable(const std::vector<std::string> &aids, const ElementName &element) 22 { 23 aids_ = std::move(aids); 24 aidsCount_ = aids.size(); 25 element_.SetBundleName(element.GetBundleName()); 26 element_.SetAbilityName(element.GetAbilityName()); 27 element_.SetDeviceID(element.GetDeviceID()); 28 element_.SetModuleName(element.GetModuleName()); 29 } StartHceInfoParcelable(Parcel & parcel)30StartHceInfoParcelable::StartHceInfoParcelable(Parcel &parcel) 31 { 32 parcel.ReadUint32(aidsCount_); 33 if (aidsCount_ > MAX_AID_LIST_NUM_PER_APP) { 34 ErrorLog("invalid length"); 35 return; 36 } 37 38 for (uint32_t i = 0; i < aidsCount_; i++) { 39 std::string aid; 40 parcel.ReadString(aid); 41 aids_.push_back(aid); 42 } 43 44 element_.ReadFromParcel(parcel); 45 } StartHceInfoParcelable()46StartHceInfoParcelable::StartHceInfoParcelable() 47 { 48 } ~StartHceInfoParcelable()49StartHceInfoParcelable::~StartHceInfoParcelable() 50 { 51 aids_.clear(); 52 element_.SetBundleName(""); 53 element_.SetAbilityName(""); 54 element_.SetDeviceID(""); 55 element_.SetModuleName(""); 56 } Marshalling(Parcel & parcel) const57bool StartHceInfoParcelable::Marshalling(Parcel &parcel) const 58 { 59 if (aids_.size() > MAX_AID_LIST_NUM_PER_APP) { 60 ErrorLog("invalid length"); 61 return false; 62 } 63 if (!parcel.WriteUint32(aids_.size())) { 64 ErrorLog("write size failed"); 65 return false; 66 } 67 for (uint32_t i = 0; i < aids_.size(); i++) { 68 if (!parcel.WriteString(aids_[i])) { 69 ErrorLog("write aid failed"); 70 return false; 71 } 72 } 73 if (!element_.Marshalling(parcel)) { 74 ErrorLog("write element failed"); 75 return false; 76 } 77 return true; 78 } SetAids(const std::vector<std::string> & aids)79void StartHceInfoParcelable::SetAids(const std::vector<std::string> &aids) 80 { 81 aids_ = std::move(aids); 82 aidsCount_ = aids.size(); 83 } SetElement(const ElementName & element)84void StartHceInfoParcelable::SetElement(const ElementName &element) 85 { 86 element_.SetBundleName(element.GetBundleName()); 87 element_.SetAbilityName(element.GetAbilityName()); 88 element_.SetDeviceID(element.GetDeviceID()); 89 element_.SetModuleName(element.GetModuleName()); 90 } GetAids()91std::vector<std::string> StartHceInfoParcelable::GetAids() 92 { 93 return aids_; 94 } GetElement()95ElementName StartHceInfoParcelable::GetElement() 96 { 97 return element_; 98 } 99 } // namespace KITS 100 } // namespace NFC 101 } // namespace OHOS