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 "lifecycle_state_info.h" 17 18 namespace OHOS { 19 namespace AAFwk { ReadFromParcel(Parcel & parcel)20bool LifeCycleStateInfo::ReadFromParcel(Parcel &parcel) 21 { 22 isNewWant = parcel.ReadBool(); 23 int32_t stateData = parcel.ReadInt32(); 24 state = static_cast<AbilityLifeCycleState>(stateData); 25 missionId = parcel.ReadInt32(); 26 std::unique_ptr<CallerInfo> callerInfo(parcel.ReadParcelable<CallerInfo>()); 27 if (callerInfo == nullptr) { 28 return false; 29 } 30 caller = *callerInfo; 31 setting = std::shared_ptr<AbilityStartSetting>(parcel.ReadParcelable<AbilityStartSetting>()); 32 std::unique_ptr<LaunchParam> launchInfo(parcel.ReadParcelable<LaunchParam>()); 33 if (launchInfo == nullptr) { 34 return false; 35 } 36 launchParam = *launchInfo; 37 sceneFlag = parcel.ReadUint32(); 38 return true; 39 } 40 Unmarshalling(Parcel & parcel)41LifeCycleStateInfo *LifeCycleStateInfo::Unmarshalling(Parcel &parcel) 42 { 43 LifeCycleStateInfo *info = new (std::nothrow) LifeCycleStateInfo(); 44 if (info == nullptr) { 45 return nullptr; 46 } 47 48 if (!info->ReadFromParcel(parcel)) { 49 delete info; 50 info = nullptr; 51 } 52 return info; 53 } 54 Marshalling(Parcel & parcel) const55bool LifeCycleStateInfo::Marshalling(Parcel &parcel) const 56 { 57 // write isNewWant 58 if (!parcel.WriteBool(isNewWant)) { 59 return false; 60 } 61 // write state 62 if (!parcel.WriteInt32(static_cast<int32_t>(state))) { 63 return false; 64 } 65 // write missionId 66 if (!parcel.WriteInt32(missionId)) { 67 return false; 68 } 69 // write caller 70 if (!parcel.WriteParcelable(&caller)) { 71 return false; 72 } 73 // write setting 74 if (!parcel.WriteParcelable(setting.get())) { 75 return false; 76 } 77 // write launch param 78 if (!parcel.WriteParcelable(&launchParam)) { 79 return false; 80 } 81 if (!parcel.WriteUint32(sceneFlag)) { 82 return false; 83 } 84 return true; 85 } 86 } // namespace AAFwk 87 } // namespace OHOS 88