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