1 /* 2 * Copyright (c) 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 "mem_mgr_process_state_info.h" 17 #include "memmgr_log.h" 18 19 namespace OHOS { 20 namespace Memory { 21 namespace { 22 const std::string TAG = "MemMgrProcessStateInfo"; 23 } 24 Marshalling(Parcel & parcel) const25bool MemMgrProcessStateInfo::Marshalling(Parcel &parcel) const 26 { 27 return parcel.WriteInt32(callerPid_) && parcel.WriteInt32(callerUid_) && 28 parcel.WriteInt32(pid_) && parcel.WriteInt32(uid_) && 29 parcel.WriteUint32(static_cast<uint32_t>(reason_)); 30 } 31 Unmarshalling(Parcel & parcel)32MemMgrProcessStateInfo* MemMgrProcessStateInfo::Unmarshalling(Parcel &parcel) 33 { 34 auto memMgrProcessStateInfo = new (std::nothrow) MemMgrProcessStateInfo(); 35 if (memMgrProcessStateInfo == nullptr) { 36 HILOGE("process state info is nullptr."); 37 return nullptr; 38 } 39 uint32_t reason = static_cast<uint32_t>(ProcPriorityUpdateReason::UNKNOWN); 40 bool res = parcel.ReadInt32(memMgrProcessStateInfo->callerPid_) && 41 parcel.ReadInt32(memMgrProcessStateInfo->callerUid_) && 42 parcel.ReadInt32(memMgrProcessStateInfo->pid_) && 43 parcel.ReadInt32(memMgrProcessStateInfo->uid_) && 44 parcel.ReadUint32(reason); 45 if (!res) { 46 delete memMgrProcessStateInfo; 47 return nullptr; 48 } 49 switch (reason) { 50 case static_cast<uint32_t>(ProcPriorityUpdateReason::START_ABILITY): 51 memMgrProcessStateInfo->reason_ = static_cast<ProcPriorityUpdateReason>(reason); 52 break; 53 default: 54 break; 55 } 56 return memMgrProcessStateInfo; 57 } 58 } 59 } 60 61