1 /* 2 * Copyright (c) 2021-2022 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_wrapper.h" 19 20 namespace OHOS { 21 namespace AppExecFwk { Marshalling(Parcel & parcel) const22bool AbilityStateData::Marshalling(Parcel &parcel) const 23 { 24 return (parcel.WriteString(moduleName) && parcel.WriteString(bundleName) && 25 parcel.WriteString(abilityName) && parcel.WriteInt32(abilityState) && 26 parcel.WriteInt32(pid) && parcel.WriteInt32(uid) && 27 (static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token) && 28 parcel.WriteInt32(abilityType) && parcel.WriteBool(isFocused)); 29 } 30 ReadFromParcel(Parcel & parcel)31bool AbilityStateData::ReadFromParcel(Parcel &parcel) 32 { 33 moduleName = parcel.ReadString(); 34 35 bundleName = parcel.ReadString(); 36 37 abilityName = parcel.ReadString(); 38 39 abilityState = parcel.ReadInt32(); 40 41 pid = parcel.ReadInt32(); 42 43 uid = parcel.ReadInt32(); 44 45 token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject(); 46 47 abilityType = parcel.ReadInt32(); 48 49 isFocused = parcel.ReadBool(); 50 return true; 51 } 52 Unmarshalling(Parcel & parcel)53AbilityStateData *AbilityStateData::Unmarshalling(Parcel &parcel) 54 { 55 AbilityStateData *abilityStateData = new (std::nothrow) AbilityStateData(); 56 if (abilityStateData && !abilityStateData->ReadFromParcel(parcel)) { 57 HILOG_WARN("AbilityStateData failed, because ReadFromParcel failed"); 58 delete abilityStateData; 59 abilityStateData = nullptr; 60 } 61 return abilityStateData; 62 } 63 } // namespace AppExecFwk 64 } // namespace OHOS 65