1 /* 2 * Copyright (c) 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 "param.h" 17 18 namespace OHOS::AbilityRuntime { Marshalling(Parcel & parcel) const19bool LoadParam::Marshalling(Parcel &parcel) const 20 { 21 if (!parcel.WriteInt32(abilityRecordId)) { 22 return false; 23 } 24 if (!parcel.WriteBool(isShellCall)) { 25 return false; 26 } 27 if (!parcel.WriteString(instanceKey)) { 28 return false; 29 } 30 if (token == nullptr) { 31 if (!parcel.WriteBool(false)) { 32 return false; 33 } 34 } else { 35 if (!parcel.WriteBool(true)) { 36 return false; 37 } 38 if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) { 39 return false; 40 } 41 } 42 if (preToken == nullptr) { 43 if (!parcel.WriteBool(false)) { 44 return false; 45 } 46 } else { 47 if (!parcel.WriteBool(true)) { 48 return false; 49 } 50 if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(preToken)) { 51 return false; 52 } 53 } 54 if (!parcel.WriteBool(isKeepAlive)) { 55 return false; 56 } 57 if (!parcel.WriteUint32(extensionProcessMode)) { 58 return false; 59 } 60 if (!parcel.WriteParcelable(&extensionLoadParam)) { 61 return false; 62 } 63 return true; 64 } 65 ReadFromParcel(Parcel & parcel)66bool LoadParam::ReadFromParcel(Parcel &parcel) 67 { 68 abilityRecordId = parcel.ReadInt32(); 69 isShellCall = parcel.ReadBool(); 70 instanceKey = parcel.ReadString(); 71 if (parcel.ReadBool()) { 72 token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 73 if (token == nullptr) { 74 return false; 75 } 76 } 77 if (parcel.ReadBool()) { 78 preToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 79 if (preToken == nullptr) { 80 return false; 81 } 82 } 83 isKeepAlive = parcel.ReadBool(); 84 extensionProcessMode = parcel.ReadUint32(); 85 std::unique_ptr<ExtensionLoadParam> extensionParamRead(parcel.ReadParcelable<ExtensionLoadParam>()); 86 if (!extensionParamRead) { 87 return false; 88 } 89 extensionLoadParam = *extensionParamRead; 90 return true; 91 } 92 Unmarshalling(Parcel & parcel)93LoadParam *LoadParam::Unmarshalling(Parcel &parcel) 94 { 95 LoadParam *loadParam = new (std::nothrow) LoadParam(); 96 if (loadParam && !loadParam->ReadFromParcel(parcel)) { 97 delete loadParam; 98 loadParam = nullptr; 99 } 100 return loadParam; 101 } 102 }