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 std::unique_ptr<CallerInfo> callerInfo(parcel.ReadParcelable<CallerInfo>()); 30 if (callerInfo == nullptr) { 31 return false; 32 } 33 caller = *callerInfo; 34 AbilityStartSetting *pSetting = parcel.ReadParcelable<AbilityStartSetting>(); 35 if (pSetting != nullptr) { 36 setting = std::shared_ptr<AbilityStartSetting>(pSetting); 37 } else { 38 setting = nullptr; 39 } 40 std::unique_ptr<LaunchParam> launchInfo(parcel.ReadParcelable<LaunchParam>()); 41 if (launchInfo == nullptr) { 42 return false; 43 } 44 launchParam = *launchInfo; 45 sceneFlag = parcel.ReadUint32(); 46 return true; 47 } 48 Unmarshalling(Parcel & parcel)49LifeCycleStateInfo *LifeCycleStateInfo::Unmarshalling(Parcel &parcel) 50 { 51 LifeCycleStateInfo *info = new (std::nothrow) LifeCycleStateInfo(); 52 if (info == nullptr) { 53 return nullptr; 54 } 55 56 if (!info->ReadFromParcel(parcel)) { 57 delete info; 58 info = nullptr; 59 } 60 return info; 61 } 62 Marshalling(Parcel & parcel) const63bool LifeCycleStateInfo::Marshalling(Parcel &parcel) const 64 { 65 // write isNewWant 66 if (!parcel.WriteBool(isNewWant)) { 67 return false; 68 } 69 // write state 70 if (!parcel.WriteInt32(static_cast<int32_t>(state))) { 71 return false; 72 } 73 // write missionId 74 if (!parcel.WriteInt32(missionId)) { 75 return false; 76 } 77 // write caller 78 if (!parcel.WriteParcelable(&caller)) { 79 return false; 80 } 81 // write setting 82 if (!parcel.WriteParcelable(setting.get())) { 83 return false; 84 } 85 // write launch param 86 if (!parcel.WriteParcelable(&launchParam)) { 87 return false; 88 } 89 if (!parcel.WriteUint32(sceneFlag)) { 90 return false; 91 } 92 return true; 93 } 94 } // namespace AAFwk 95 } // namespace OHOS 96