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 "native_token_info_for_sync_parcel.h" 17 #include "refbase.h" 18 #include "native_token_info_parcel.h" 19 #include "parcel_utils.h" 20 #include "permission_state_full.h" 21 #include "permission_state_full_parcel.h" 22 23 namespace OHOS { 24 namespace Security { 25 namespace AccessToken { Marshalling(Parcel & out) const26bool NativeTokenInfoForSyncParcel::Marshalling(Parcel& out) const 27 { 28 NativeTokenInfoParcel baseInfoParcel; 29 baseInfoParcel.nativeTokenInfoParams = this->nativeTokenInfoForSyncParams.baseInfo; 30 RETURN_IF_FALSE(out.WriteParcelable(&baseInfoParcel)); 31 32 const std::vector<PermissionStateFull>& permStateList = this->nativeTokenInfoForSyncParams.permStateList; 33 uint32_t permStateListSize = permStateList.size(); 34 RETURN_IF_FALSE(permStateListSize <= MAX_PERMLIST_SIZE); 35 RETURN_IF_FALSE(out.WriteUint32(permStateListSize)); 36 for (uint32_t i = 0; i < permStateListSize; i++) { 37 PermissionStateFullParcel permStateParcel; 38 permStateParcel.permStatFull = permStateList[i]; 39 RETURN_IF_FALSE(out.WriteParcelable(&permStateParcel)); 40 } 41 42 return true; 43 } 44 Unmarshalling(Parcel & in)45NativeTokenInfoForSyncParcel* NativeTokenInfoForSyncParcel::Unmarshalling(Parcel& in) 46 { 47 auto* nativeTokenInfoForSyncParcel = new (std::nothrow) NativeTokenInfoForSyncParcel(); 48 if (nativeTokenInfoForSyncParcel == nullptr) { 49 return nullptr; 50 } 51 52 sptr<NativeTokenInfoParcel> baseInfoParcel = in.ReadParcelable<NativeTokenInfoParcel>(); 53 RELEASE_IF_FALSE(baseInfoParcel != nullptr, nativeTokenInfoForSyncParcel); 54 nativeTokenInfoForSyncParcel->nativeTokenInfoForSyncParams.baseInfo = baseInfoParcel->nativeTokenInfoParams; 55 56 uint32_t permStateListSize; 57 RELEASE_IF_FALSE(in.ReadUint32(permStateListSize), nativeTokenInfoForSyncParcel); 58 RELEASE_IF_FALSE(permStateListSize <= MAX_PERMLIST_SIZE, nativeTokenInfoForSyncParcel); 59 for (uint32_t i = 0; i < permStateListSize; i++) { 60 sptr<PermissionStateFullParcel> permissionStateParcel = in.ReadParcelable<PermissionStateFullParcel>(); 61 RELEASE_IF_FALSE(permissionStateParcel != nullptr, nativeTokenInfoForSyncParcel); 62 nativeTokenInfoForSyncParcel->nativeTokenInfoForSyncParams.permStateList.emplace_back( 63 permissionStateParcel->permStatFull); 64 } 65 return nativeTokenInfoForSyncParcel; 66 } 67 } // namespace AccessToken 68 } // namespace Security 69 } // namespace OHOS 70