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 "ui_extension/ui_extension_host_info.h" 17 #include "hilog_tag_wrapper.h" 18 19 namespace OHOS { 20 namespace AbilityRuntime { ReadFromParcel(Parcel & parcel)21bool UIExtensionHostInfo::ReadFromParcel(Parcel &parcel) 22 { 23 std::unique_ptr<AppExecFwk::ElementName> abilityInfo(parcel.ReadParcelable<AppExecFwk::ElementName>()); 24 if (abilityInfo == nullptr) { 25 TAG_LOGE(AAFwkTag::ABILITYMGR, "read hostInfo failed"); 26 return false; 27 } 28 29 elementName_ = *abilityInfo; 30 sessionName = parcel.ReadString(); 31 return true; 32 } 33 Unmarshalling(Parcel & parcel)34UIExtensionHostInfo *UIExtensionHostInfo::Unmarshalling(Parcel &parcel) 35 { 36 UIExtensionHostInfo *hostInfo = new (std::nothrow) UIExtensionHostInfo(); 37 if (hostInfo == nullptr) { 38 TAG_LOGE(AAFwkTag::ABILITYMGR, "create hostInfo failed"); 39 return nullptr; 40 } 41 42 if (!hostInfo->ReadFromParcel(parcel)) { 43 delete hostInfo; 44 hostInfo = nullptr; 45 } 46 47 return hostInfo; 48 } 49 Marshalling(Parcel & parcel) const50bool UIExtensionHostInfo::Marshalling(Parcel &parcel) const 51 { 52 if (!parcel.WriteParcelable(&elementName_)) { 53 TAG_LOGE(AAFwkTag::ABILITYMGR, "write elementName failed"); 54 return false; 55 } 56 57 if (!parcel.WriteString(sessionName)) { 58 TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionName failed"); 59 return false; 60 } 61 62 return true; 63 } 64 } // namespace AbilityRuntime 65 } // namespace OHOS 66