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 } 43 lastExitDetailInfo = *detailInfo; 44 45 return true; 46 } 47 Unmarshalling(Parcel & parcel)48LaunchParam *LaunchParam::Unmarshalling(Parcel &parcel) 49 { 50 LaunchParam *param = new (std::nothrow) LaunchParam(); 51 if (param == nullptr) { 52 return nullptr; 53 } 54 55 if (!param->ReadFromParcel(parcel)) { 56 delete param; 57 param = nullptr; 58 } 59 return param; 60 } 61 Marshalling(Parcel & parcel) const62bool LaunchParam::Marshalling(Parcel &parcel) const 63 { 64 // write launchReason 65 if (!parcel.WriteInt32(static_cast<int32_t>(launchReason))) { 66 return false; 67 } 68 if (!parcel.WriteString16(Str8ToStr16(launchReasonMessage))) { 69 TAG_LOGE(AAFwkTag::ABILITYMGR, "write launchReasonMessage failed"); 70 return false; 71 } 72 // write lastExitReason 73 if (!parcel.WriteInt32(static_cast<int32_t>(lastExitReason))) { 74 return false; 75 } 76 if (!parcel.WriteString16(Str8ToStr16(lastExitMessage))) { 77 TAG_LOGE(AAFwkTag::ABILITYMGR, "write lastExitMessage failed"); 78 return false; 79 } 80 // write lastExitDetailInfo 81 if (!parcel.WriteParcelable(&lastExitDetailInfo)) { 82 TAG_LOGE(AAFwkTag::ABILITYMGR, "write lastExitDetailInfo failed"); 83 return false; 84 } 85 return true; 86 } 87 } // namespace AAFwk 88 } // namespace OHOS 89