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 "bundle_used_record_parcel.h" 17 #include "parcel_utils.h" 18 #include "permission_used_result_parcel.h" 19 #include "refbase.h" 20 21 namespace OHOS { 22 namespace Security { 23 namespace AccessToken { Marshalling(Parcel & out) const24 bool PermissionUsedResultParcel::Marshalling(Parcel& out) const 25 { 26 RETURN_IF_FALSE(out.WriteInt64(this->result.beginTimeMillis)); 27 RETURN_IF_FALSE(out.WriteInt64(this->result.endTimeMillis)); 28 29 RETURN_IF_FALSE(out.WriteUint32(this->result.bundleRecords.size())); 30 for (const auto& bundRecord : this->result.bundleRecords) { 31 BundleUsedRecordParcel bundleParcel; 32 bundleParcel.bundleRecord = bundRecord; 33 out.WriteParcelable(&bundleParcel); 34 } 35 return true; 36 } 37 Unmarshalling(Parcel & in)38 PermissionUsedResultParcel* PermissionUsedResultParcel::Unmarshalling(Parcel& in) 39 { 40 auto* resultParcel = new (std::nothrow) PermissionUsedResultParcel(); 41 if (resultParcel == nullptr) { 42 return nullptr; 43 } 44 45 RELEASE_IF_FALSE(in.ReadInt64(resultParcel->result.beginTimeMillis), resultParcel); 46 RELEASE_IF_FALSE(in.ReadInt64(resultParcel->result.endTimeMillis), resultParcel); 47 48 uint32_t bundResponseSize = 0; 49 RELEASE_IF_FALSE(in.ReadUint32(bundResponseSize), resultParcel); 50 RELEASE_IF_FALSE(bundResponseSize <= MAX_RECORD_SIZE, resultParcel); 51 for (uint32_t i = 0; i < bundResponseSize; i++) { 52 sptr<BundleUsedRecordParcel> bunRecordParcel = in.ReadParcelable<BundleUsedRecordParcel>(); 53 RELEASE_IF_FALSE(bunRecordParcel != nullptr, resultParcel); 54 resultParcel->result.bundleRecords.emplace_back(bunRecordParcel->bundleRecord); 55 } 56 return resultParcel; 57 } 58 } // namespace AccessToken 59 } // namespace Security 60 } // namespace OHOS 61