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 "process_data.h" 17 18 #include "hilog_tag_wrapper.h" 19 #include "parcel_macro_base.h" 20 #include "string_ex.h" 21 22 namespace OHOS { 23 namespace AppExecFwk { Marshalling(Parcel & parcel) const24bool ProcessData::Marshalling(Parcel &parcel) const 25 { 26 return (parcel.WriteString(bundleName) && parcel.WriteInt32(pid) && 27 parcel.WriteInt32(uid) && parcel.WriteInt32(hostPid) && parcel.WriteInt32(gpuPid) && 28 parcel.WriteInt32(static_cast<int32_t>(state)) && parcel.WriteBool(isContinuousTask) && 29 parcel.WriteBool(isKeepAlive) && parcel.WriteBool(isFocused) && parcel.WriteInt32(requestProcCode) && 30 parcel.WriteInt32(processChangeReason) && parcel.WriteString(processName) && 31 parcel.WriteInt32(static_cast<int32_t>(processType)) && parcel.WriteInt32(static_cast<int32_t>(extensionType)) 32 && parcel.WriteInt32(renderUid) && parcel.WriteUint32(accessTokenId) && 33 parcel.WriteBool(isTestMode) && parcel.WriteInt32(exitReason) && parcel.WriteString16(Str8ToStr16(exitMsg)) && 34 parcel.WriteInt32(childUid) && parcel.WriteBool(isPreload) && parcel.WriteBool(isPreloadModule) && 35 parcel.WriteInt32(callerPid) && parcel.WriteInt32(callerUid) && parcel.WriteString(killReason) && 36 parcel.WriteBool(isFromWindowFocusChanged)); 37 } 38 ReadFromParcel(Parcel & parcel)39bool ProcessData::ReadFromParcel(Parcel &parcel) 40 { 41 bundleName = parcel.ReadString(); 42 pid = parcel.ReadInt32(); 43 uid = parcel.ReadInt32(); 44 hostPid = parcel.ReadInt32(); 45 gpuPid = parcel.ReadInt32(); 46 state = static_cast<AppProcessState>(parcel.ReadInt32()); 47 isContinuousTask = parcel.ReadBool(); 48 isKeepAlive = parcel.ReadBool(); 49 isFocused = parcel.ReadBool(); 50 requestProcCode = parcel.ReadInt32(); 51 processChangeReason = parcel.ReadInt32(); 52 processName = parcel.ReadString(); 53 processType = static_cast<ProcessType>(parcel.ReadInt32()); 54 extensionType = static_cast<ExtensionAbilityType>(parcel.ReadInt32()); 55 renderUid = parcel.ReadInt32(); 56 accessTokenId = parcel.ReadUint32(); 57 isTestMode = parcel.ReadBool(); 58 exitReason = parcel.ReadInt32(); 59 exitMsg = Str16ToStr8(parcel.ReadString16()); 60 childUid = parcel.ReadInt32(); 61 isPreload = parcel.ReadBool(); 62 isPreloadModule = parcel.ReadBool(); 63 callerPid = parcel.ReadInt32(); 64 callerUid = parcel.ReadInt32(); 65 killReason = parcel.ReadString(); 66 isFromWindowFocusChanged = parcel.ReadBool(); 67 return true; 68 } 69 Unmarshalling(Parcel & parcel)70ProcessData *ProcessData::Unmarshalling(Parcel &parcel) 71 { 72 ProcessData *processData = new (std::nothrow) ProcessData(); 73 if (processData && !processData->ReadFromParcel(parcel)) { 74 TAG_LOGW(AAFwkTag::APPMGR, "processData failed, because ReadFromParcel failed"); 75 delete processData; 76 processData = nullptr; 77 } 78 return processData; 79 } 80 } // namespace AppExecFwk 81 } // namespace OHOS 82