1 /* 2 * Copyright (c) 2021-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 "screen_group_info.h" 17 18 namespace OHOS::Rosen { Marshalling(Parcel & parcel) const19bool ScreenGroupInfo::Marshalling(Parcel &parcel) const 20 { 21 bool res = ScreenInfo::Marshalling(parcel) && parcel.WriteUint32((uint32_t)combination_) && 22 parcel.WriteUInt64Vector(children_); 23 if (!res) { 24 return false; 25 } 26 size_t size = position_.size(); 27 if (!parcel.WriteUint32(size)) { 28 return false; 29 } 30 if (size > MAX_SCREEN_GROUP_INFO_SIZE) { 31 return false; 32 } 33 for (size_t i = 0; i < size; i++) { 34 if (!parcel.WriteInt32(position_[i].posX_) || !parcel.WriteInt32(position_[i].posY_)) { 35 return false; 36 } 37 } 38 return true; 39 } 40 Unmarshalling(Parcel & parcel)41ScreenGroupInfo* ScreenGroupInfo::Unmarshalling(Parcel &parcel) 42 { 43 ScreenGroupInfo* screenGroupInfo = new(std::nothrow) ScreenGroupInfo(); 44 if (screenGroupInfo == nullptr) { 45 return screenGroupInfo; 46 } 47 bool res = screenGroupInfo->InnerUnmarshalling(parcel); 48 if (res) { 49 return screenGroupInfo; 50 } 51 delete screenGroupInfo; 52 return nullptr; 53 } 54 InnerUnmarshalling(Parcel & parcel)55bool ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel) 56 { 57 uint32_t combination; 58 if (!ScreenInfo::InnerUnmarshalling(parcel) || !parcel.ReadUint32(combination) || 59 !parcel.ReadUInt64Vector(&children_)) { 60 return false; 61 } 62 combination_ = (ScreenCombination) combination; 63 uint32_t size; 64 if (!parcel.ReadUint32(size)) { 65 return false; 66 } 67 if (size > MAX_SCREEN_GROUP_INFO_SIZE) { 68 return false; 69 } 70 for (size_t i = 0; i < size; i++) { 71 Point point; 72 if (parcel.ReadInt32(point.posX_) && parcel.ReadInt32(point.posY_)) { 73 position_.push_back(point); 74 } else { 75 return false; 76 } 77 } 78 return true; 79 } 80 } // namespace OHOS::Rosen