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)); 36 } 37 ReadFromParcel(Parcel & parcel)38bool ProcessData::ReadFromParcel(Parcel &parcel) 39 { 40 bundleName = parcel.ReadString(); 41 pid = parcel.ReadInt32(); 42 uid = parcel.ReadInt32(); 43 hostPid = parcel.ReadInt32(); 44 gpuPid = parcel.ReadInt32(); 45 state = static_cast<AppProcessState>(parcel.ReadInt32()); 46 isContinuousTask = parcel.ReadBool(); 47 isKeepAlive = parcel.ReadBool(); 48 isFocused = parcel.ReadBool(); 49 requestProcCode = parcel.ReadInt32(); 50 processChangeReason = parcel.ReadInt32(); 51 processName = parcel.ReadString(); 52 processType = static_cast<ProcessType>(parcel.ReadInt32()); 53 extensionType = static_cast<ExtensionAbilityType>(parcel.ReadInt32()); 54 renderUid = parcel.ReadInt32(); 55 accessTokenId = parcel.ReadUint32(); 56 isTestMode = parcel.ReadBool(); 57 exitReason = parcel.ReadInt32(); 58 exitMsg = Str16ToStr8(parcel.ReadString16()); 59 childUid = parcel.ReadInt32(); 60 isPreload = parcel.ReadBool(); 61 isPreloadModule = parcel.ReadBool(); 62 callerPid = parcel.ReadInt32(); 63 callerUid = parcel.ReadInt32(); 64 return true; 65 } 66 Unmarshalling(Parcel & parcel)67ProcessData *ProcessData::Unmarshalling(Parcel &parcel) 68 { 69 ProcessData *processData = new (std::nothrow) ProcessData(); 70 if (processData && !processData->ReadFromParcel(parcel)) { 71 TAG_LOGW(AAFwkTag::APPMGR, "processData failed, because ReadFromParcel failed"); 72 delete processData; 73 processData = nullptr; 74 } 75 return processData; 76 } 77 } // namespace AppExecFwk 78 } // namespace OHOS 79