1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#include "sender_info.h" 17eace7efcSopenharmony_ci 18eace7efcSopenharmony_ci#include "hilog_tag_wrapper.h" 19eace7efcSopenharmony_ci 20eace7efcSopenharmony_cinamespace OHOS { 21eace7efcSopenharmony_cinamespace AAFwk { 22eace7efcSopenharmony_cibool SenderInfo::ReadFromParcel(Parcel &parcel) 23eace7efcSopenharmony_ci{ 24eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); 25eace7efcSopenharmony_ci 26eace7efcSopenharmony_ci code = parcel.ReadInt32(); 27eace7efcSopenharmony_ci std::unique_ptr<Want> wantResquest(parcel.ReadParcelable<Want>()); 28eace7efcSopenharmony_ci if (wantResquest == nullptr) { 29eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null wantResquest"); 30eace7efcSopenharmony_ci return false; 31eace7efcSopenharmony_ci } 32eace7efcSopenharmony_ci want = *wantResquest; 33eace7efcSopenharmony_ci resolvedType = Str16ToStr8(parcel.ReadString16()); 34eace7efcSopenharmony_ci 35eace7efcSopenharmony_ci if (parcel.ReadBool()) { 36eace7efcSopenharmony_ci sptr<IRemoteObject> finishedReceiverResquest = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 37eace7efcSopenharmony_ci if (finishedReceiverResquest == nullptr) { 38eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote object"); 39eace7efcSopenharmony_ci return false; 40eace7efcSopenharmony_ci } 41eace7efcSopenharmony_ci finishedReceiver = iface_cast<IWantReceiver>(finishedReceiverResquest); 42eace7efcSopenharmony_ci if (!finishedReceiver) { 43eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null receiver"); 44eace7efcSopenharmony_ci return false; 45eace7efcSopenharmony_ci } 46eace7efcSopenharmony_ci } 47eace7efcSopenharmony_ci requiredPermission = Str16ToStr8(parcel.ReadString16()); 48eace7efcSopenharmony_ci if (parcel.ReadBool()) { 49eace7efcSopenharmony_ci startOptions = parcel.ReadParcelable<StartOptions>(); 50eace7efcSopenharmony_ci } 51eace7efcSopenharmony_ci return true; 52eace7efcSopenharmony_ci} 53eace7efcSopenharmony_ci 54eace7efcSopenharmony_ciSenderInfo *SenderInfo::Unmarshalling(Parcel &parcel) 55eace7efcSopenharmony_ci{ 56eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); 57eace7efcSopenharmony_ci 58eace7efcSopenharmony_ci SenderInfo *info = new (std::nothrow) SenderInfo(); 59eace7efcSopenharmony_ci if (info == nullptr) { 60eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null senderInfo"); 61eace7efcSopenharmony_ci return nullptr; 62eace7efcSopenharmony_ci } 63eace7efcSopenharmony_ci 64eace7efcSopenharmony_ci if (!info->ReadFromParcel(parcel)) { 65eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "ReadFromParcel failed"); 66eace7efcSopenharmony_ci delete info; 67eace7efcSopenharmony_ci info = nullptr; 68eace7efcSopenharmony_ci } 69eace7efcSopenharmony_ci return info; 70eace7efcSopenharmony_ci} 71eace7efcSopenharmony_ci 72eace7efcSopenharmony_cibool SenderInfo::Marshalling(Parcel &parcel) const 73eace7efcSopenharmony_ci{ 74eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); 75eace7efcSopenharmony_ci 76eace7efcSopenharmony_ci if (!parcel.WriteInt32(code)) { 77eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write code failed"); 78eace7efcSopenharmony_ci return false; 79eace7efcSopenharmony_ci } 80eace7efcSopenharmony_ci if (!parcel.WriteParcelable(&want)) { 81eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed"); 82eace7efcSopenharmony_ci return false; 83eace7efcSopenharmony_ci } 84eace7efcSopenharmony_ci if (!parcel.WriteString16(Str8ToStr16(resolvedType))) { 85eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write resolvedType failed"); 86eace7efcSopenharmony_ci return false; 87eace7efcSopenharmony_ci } 88eace7efcSopenharmony_ci if (!parcel.WriteBool(finishedReceiver != nullptr)) { 89eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag failed"); 90eace7efcSopenharmony_ci return false; 91eace7efcSopenharmony_ci } 92eace7efcSopenharmony_ci if (finishedReceiver) { 93eace7efcSopenharmony_ci if (finishedReceiver->AsObject() == nullptr) { 94eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "null object"); 95eace7efcSopenharmony_ci return false; 96eace7efcSopenharmony_ci } 97eace7efcSopenharmony_ci if (!(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(finishedReceiver->AsObject())) { 98eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write receiver failed"); 99eace7efcSopenharmony_ci return false; 100eace7efcSopenharmony_ci } 101eace7efcSopenharmony_ci } 102eace7efcSopenharmony_ci if (!parcel.WriteString16(Str8ToStr16(requiredPermission))) { 103eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write requiredPermission failed"); 104eace7efcSopenharmony_ci return false; 105eace7efcSopenharmony_ci } 106eace7efcSopenharmony_ci if (!parcel.WriteBool(startOptions != nullptr)) { 107eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag failed"); 108eace7efcSopenharmony_ci return false; 109eace7efcSopenharmony_ci } 110eace7efcSopenharmony_ci if (startOptions) { 111eace7efcSopenharmony_ci if (!parcel.WriteParcelable(startOptions)) { 112eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::ABILITYMGR, "write startOptions failed"); 113eace7efcSopenharmony_ci return false; 114eace7efcSopenharmony_ci } 115eace7efcSopenharmony_ci } 116eace7efcSopenharmony_ci return true; 117eace7efcSopenharmony_ci} 118eace7efcSopenharmony_ci} // namespace AAFwk 119eace7efcSopenharmony_ci} // namespace OHOS 120