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