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 "ability_state_data.h" 17 18 #include "hilog_tag_wrapper.h" 19 20 namespace OHOS { 21 namespace AppExecFwk { Marshalling(Parcel & parcel) const22bool AbilityStateData::Marshalling(Parcel &parcel) const 23 { 24 if (!parcel.WriteString(moduleName)) { 25 return false; 26 } 27 if (!parcel.WriteString(bundleName)) { 28 return false; 29 } 30 if (!parcel.WriteString(abilityName)) { 31 return false; 32 } 33 if (!parcel.WriteInt32(abilityState)) { 34 return false; 35 } 36 if (!parcel.WriteInt32(pid)) { 37 return false; 38 } 39 if (!parcel.WriteInt32(uid)) { 40 return false; 41 } 42 if (token == nullptr) { 43 if (!parcel.WriteBool(false)) { 44 return false; 45 } 46 } else { 47 if (!parcel.WriteBool(true)) { 48 return false; 49 } 50 if (!parcel.WriteRemoteObject(token)) { 51 return false; 52 } 53 } 54 if (!MarshallingOne(parcel)) { 55 return false; 56 } 57 return true; 58 } 59 MarshallingOne(Parcel & parcel) const60bool AbilityStateData::MarshallingOne(Parcel &parcel) const 61 { 62 if (!parcel.WriteInt32(abilityType)) { 63 return false; 64 } 65 if (!parcel.WriteBool(isFocused)) { 66 return false; 67 } 68 if (!parcel.WriteString(callerBundleName)) { 69 return false; 70 } 71 if (!parcel.WriteString(callerAbilityName)) { 72 return false; 73 } 74 if (!parcel.WriteBool(isAtomicService) || !parcel.WriteInt32(abilityRecordId)) { 75 return false; 76 } 77 if (!parcel.WriteInt32(appCloneIndex)) { 78 return false; 79 } 80 return true; 81 } 82 ReadFromParcel(Parcel & parcel)83bool AbilityStateData::ReadFromParcel(Parcel &parcel) 84 { 85 moduleName = parcel.ReadString(); 86 87 bundleName = parcel.ReadString(); 88 89 abilityName = parcel.ReadString(); 90 91 abilityState = parcel.ReadInt32(); 92 93 pid = parcel.ReadInt32(); 94 95 uid = parcel.ReadInt32(); 96 97 if (parcel.ReadBool()) { 98 token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 99 } 100 101 abilityType = parcel.ReadInt32(); 102 103 isFocused = parcel.ReadBool(); 104 105 callerBundleName = parcel.ReadString(); 106 107 callerAbilityName = parcel.ReadString(); 108 isAtomicService = parcel.ReadBool(); 109 abilityRecordId = parcel.ReadInt32(); 110 appCloneIndex = parcel.ReadInt32(); 111 return true; 112 } 113 Unmarshalling(Parcel & parcel)114AbilityStateData *AbilityStateData::Unmarshalling(Parcel &parcel) 115 { 116 AbilityStateData *abilityStateData = new (std::nothrow) AbilityStateData(); 117 if (abilityStateData && !abilityStateData->ReadFromParcel(parcel)) { 118 TAG_LOGW(AAFwkTag::APPMGR, "ReadFromParcel failed"); 119 delete abilityStateData; 120 abilityStateData = nullptr; 121 } 122 return abilityStateData; 123 } 124 } // namespace AppExecFwk 125 } // namespace OHOS 126