1 /* 2 * Copyright (c) 2021 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 "mission_snapshot.h" 17 18 namespace OHOS { 19 namespace AAFwk { ReadFromParcel(Parcel & parcel)20bool MissionSnapshot::ReadFromParcel(Parcel &parcel) 21 { 22 #ifdef SUPPORT_SCREEN 23 std::unique_ptr<AppExecFwk::ElementName> ability(parcel.ReadParcelable<AppExecFwk::ElementName>()); 24 if (ability == nullptr) { 25 return false; 26 } 27 topAbility = *ability; 28 std::shared_ptr<Media::PixelMap> pixelMap(parcel.ReadParcelable<Media::PixelMap>()); 29 if (pixelMap == nullptr) { 30 return false; 31 } 32 snapshot = pixelMap; 33 #endif 34 return true; 35 } 36 Unmarshalling(Parcel & parcel)37MissionSnapshot *MissionSnapshot::Unmarshalling(Parcel &parcel) 38 { 39 MissionSnapshot *info = new (std::nothrow) MissionSnapshot(); 40 if (info == nullptr) { 41 return nullptr; 42 } 43 44 if (!info->ReadFromParcel(parcel)) { 45 delete info; 46 info = nullptr; 47 } 48 return info; 49 } 50 Marshalling(Parcel & parcel) const51bool MissionSnapshot::Marshalling(Parcel &parcel) const 52 { 53 if (!parcel.WriteParcelable(&topAbility)) { 54 return false; 55 } 56 #ifdef SUPPORT_SCREEN 57 if (!parcel.WriteParcelable(snapshot.get())) { 58 return false; 59 } 60 #endif 61 return true; 62 } 63 } // namespace AAFwk 64 } // namespace OHOS 65