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 "app_state_data.h" 17 18 #include "hilog_wrapper.h" 19 20 namespace OHOS { 21 namespace AppExecFwk { Marshalling(Parcel & parcel) const22bool AppStateData::Marshalling(Parcel &parcel) const 23 { 24 return (parcel.WriteString(bundleName) && parcel.WriteInt32(uid) && parcel.WriteInt32(state) 25 && parcel.WriteInt32(pid) && parcel.WriteInt32(accessTokenId) && parcel.WriteBool(isFocused)); 26 } 27 ReadFromParcel(Parcel & parcel)28bool AppStateData::ReadFromParcel(Parcel &parcel) 29 { 30 bundleName = parcel.ReadString(); 31 uid = parcel.ReadInt32(); 32 state = parcel.ReadInt32(); 33 pid = parcel.ReadInt32(); 34 accessTokenId = parcel.ReadInt32(); 35 isFocused = parcel.ReadBool(); 36 37 return true; 38 } 39 Unmarshalling(Parcel & parcel)40AppStateData *AppStateData::Unmarshalling(Parcel &parcel) 41 { 42 AppStateData *appStateData = new (std::nothrow) AppStateData(); 43 if (appStateData && !appStateData->ReadFromParcel(parcel)) { 44 HILOG_WARN("appStateData failed, because ReadFromParcel failed"); 45 delete appStateData; 46 appStateData = nullptr; 47 } 48 return appStateData; 49 } 50 } // namespace AppExecFwk 51 } // namespace OHOS 52