1 /* 2 * Copyright (c) 2021-2024 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 "launch_param.h" 17 18 #include "hilog_tag_wrapper.h" 19 #include "string_ex.h" 20 21 namespace OHOS { 22 namespace AAFwk { ReadFromParcel(Parcel & parcel)23bool LaunchParam::ReadFromParcel(Parcel &parcel) 24 { 25 int32_t reason = 0; 26 if (!parcel.ReadInt32(reason)) { 27 return false; 28 } 29 launchReason = static_cast<LaunchReason>(reason); 30 launchReasonMessage = Str16ToStr8(parcel.ReadString16()); 31 32 if (!parcel.ReadInt32(reason)) { 33 return false; 34 } 35 lastExitReason = static_cast<LastExitReason>(reason); 36 37 lastExitMessage = Str16ToStr8(parcel.ReadString16()); 38 39 std::unique_ptr<LastExitDetailInfo> detailInfo(parcel.ReadParcelable<LastExitDetailInfo>()); 40 if (detailInfo == nullptr) { 41 TAG_LOGW(AAFwkTag::ABILITYMGR, "detailInfo null"); 42 return false; 43 } 44 lastExitDetailInfo = *detailInfo; 45 46 return true; 47 } 48 Unmarshalling(Parcel & parcel)49LaunchParam *LaunchParam::Unmarshalling(Parcel &parcel) 50 { 51 LaunchParam *param = new (std::nothrow) LaunchParam(); 52 if (param == nullptr) { 53 return nullptr; 54 } 55 56 if (!param->ReadFromParcel(parcel)) { 57 delete param; 58 param = nullptr; 59 } 60 return param; 61 } 62 Marshalling(Parcel & parcel) const63bool LaunchParam::Marshalling(Parcel &parcel) const 64 { 65 // write launchReason 66 if (!parcel.WriteInt32(static_cast<int32_t>(launchReason))) { 67 return false; 68 } 69 if (!parcel.WriteString16(Str8ToStr16(launchReasonMessage))) { 70 TAG_LOGE(AAFwkTag::ABILITYMGR, "write launchReasonMessage failed"); 71 return false; 72 } 73 // write lastExitReason 74 if (!parcel.WriteInt32(static_cast<int32_t>(lastExitReason))) { 75 return false; 76 } 77 if (!parcel.WriteString16(Str8ToStr16(lastExitMessage))) { 78 TAG_LOGE(AAFwkTag::ABILITYMGR, "write lastExitMessage failed"); 79 return false; 80 } 81 // write lastExitDetailInfo 82 if (!parcel.WriteParcelable(&lastExitDetailInfo)) { 83 TAG_LOGE(AAFwkTag::ABILITYMGR, "write lastExitDetailInfo failed"); 84 return false; 85 } 86 return true; 87 } 88 } // namespace AAFwk 89 } // namespace OHOS 90