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 "refbase.h" 18 #include "parcel_utils.h" 19 #include "permission_used_record_parcel.h" 20 21 namespace OHOS { 22 namespace Security { 23 namespace AccessToken { Marshalling(Parcel & out) const24 bool BundleUsedRecordParcel::Marshalling(Parcel& out) const 25 { 26 RETURN_IF_FALSE(out.WriteUint32(this->bundleRecord.tokenId)); 27 RETURN_IF_FALSE(out.WriteBool(this->bundleRecord.isRemote)); 28 RETURN_IF_FALSE(out.WriteString(this->bundleRecord.deviceId)); 29 RETURN_IF_FALSE(out.WriteString(this->bundleRecord.bundleName)); 30 31 RETURN_IF_FALSE(out.WriteUint32(this->bundleRecord.permissionRecords.size())); 32 for (const auto& permRecord : this->bundleRecord.permissionRecords) { 33 PermissionUsedRecordParcel permRecordParcel; 34 permRecordParcel.permissionRecord = permRecord; 35 out.WriteParcelable(&permRecordParcel); 36 } 37 return true; 38 } 39 Unmarshalling(Parcel & in)40 BundleUsedRecordParcel* BundleUsedRecordParcel::Unmarshalling(Parcel& in) 41 { 42 auto* bundleRecordParcel = new (std::nothrow) BundleUsedRecordParcel(); 43 if (bundleRecordParcel == nullptr) { 44 return nullptr; 45 } 46 47 RELEASE_IF_FALSE(in.ReadUint32(bundleRecordParcel->bundleRecord.tokenId), bundleRecordParcel); 48 RELEASE_IF_FALSE(in.ReadBool(bundleRecordParcel->bundleRecord.isRemote), bundleRecordParcel); 49 RELEASE_IF_FALSE(in.ReadString(bundleRecordParcel->bundleRecord.deviceId), bundleRecordParcel); 50 RELEASE_IF_FALSE(in.ReadString(bundleRecordParcel->bundleRecord.bundleName), bundleRecordParcel); 51 52 uint32_t permRecordSize = 0; 53 RELEASE_IF_FALSE(in.ReadUint32(permRecordSize), bundleRecordParcel); 54 RELEASE_IF_FALSE(permRecordSize <= MAX_RECORD_SIZE, bundleRecordParcel); 55 for (uint32_t i = 0; i < permRecordSize; i++) { 56 sptr<PermissionUsedRecordParcel> permRecord = in.ReadParcelable<PermissionUsedRecordParcel>(); 57 RELEASE_IF_FALSE(permRecord != nullptr, bundleRecordParcel); 58 bundleRecordParcel->bundleRecord.permissionRecords.emplace_back(permRecord->permissionRecord); 59 } 60 return bundleRecordParcel; 61 } 62 } // namespace AccessToken 63 } // namespace Security 64 } // namespace OHOS 65