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 "process_data.h"
17 
18 namespace OHOS {
19 namespace Security {
20 namespace AccessToken {
Marshalling(Parcel & parcel) const21 bool ProcessData::Marshalling(Parcel &parcel) const
22 {
23     return (parcel.WriteString(bundleName) && parcel.WriteInt32(pid) &&
24         parcel.WriteInt32(uid) && parcel.WriteInt32(hostPid) && parcel.WriteInt32(gpuPid) &&
25         parcel.WriteInt32(static_cast<int32_t>(state)) && parcel.WriteBool(isContinuousTask) &&
26         parcel.WriteBool(isKeepAlive) && parcel.WriteBool(isFocused) && parcel.WriteInt32(requestProcCode) &&
27         parcel.WriteInt32(processChangeReason) && parcel.WriteString(processName) &&
28         parcel.WriteInt32(static_cast<int32_t>(processType)) && parcel.WriteInt32(extensionType)
29         && parcel.WriteInt32(renderUid) && parcel.WriteUint32(accessTokenId) &&
30         parcel.WriteBool(isTestMode) && parcel.WriteInt32(exitReason) && parcel.WriteString(exitMsg) &&
31         parcel.WriteInt32(childUid) && parcel.WriteBool(isPreload) && parcel.WriteBool(isPreloadModule));
32 }
33 
ReadFromParcel(Parcel & parcel)34 bool ProcessData::ReadFromParcel(Parcel &parcel)
35 {
36     bundleName = parcel.ReadString();
37     pid = parcel.ReadInt32();
38     uid = parcel.ReadInt32();
39     hostPid = parcel.ReadInt32();
40     gpuPid = parcel.ReadInt32();
41     state = static_cast<AppProcessState>(parcel.ReadInt32());
42     isContinuousTask = parcel.ReadBool();
43     isKeepAlive = parcel.ReadBool();
44     isFocused = parcel.ReadBool();
45     requestProcCode = parcel.ReadInt32();
46     processChangeReason = parcel.ReadInt32();
47     processName = parcel.ReadString();
48     processType = static_cast<ProcessType>(parcel.ReadInt32());
49     extensionType = parcel.ReadInt32();
50     renderUid = parcel.ReadInt32();
51     accessTokenId = parcel.ReadUint32();
52     isTestMode = parcel.ReadBool();
53     exitReason = parcel.ReadInt32();
54     exitMsg = parcel.ReadString();
55     childUid = parcel.ReadInt32();
56     isPreload = parcel.ReadBool();
57     isPreloadModule = parcel.ReadBool();
58     return true;
59 }
60 
Unmarshalling(Parcel & parcel)61 ProcessData *ProcessData::Unmarshalling(Parcel &parcel)
62 {
63     ProcessData *processData = new (std::nothrow) ProcessData();
64     if (processData && !processData->ReadFromParcel(parcel)) {
65         delete processData;
66         processData = nullptr;
67     }
68     return processData;
69 }
70 }  // namespace AccessToken
71 }  // namespace Security
72 }  // namespace OHOS
73