1 /*
2  * Copyright (c) 2023-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 "child_process_info.h"
17 
18 #include "hilog_tag_wrapper.h"
19 #include "nlohmann/json.hpp"
20 #include "parcel_macro_base.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)25 bool ChildProcessInfo::ReadFromParcel(Parcel &parcel)
26 {
27     int32_t pidData;
28     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pidData);
29     pid = static_cast<int32_t>(pidData);
30 
31     int32_t hostPidData;
32     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hostPidData);
33     hostPid = static_cast<int32_t>(hostPidData);
34 
35     int32_t uidData;
36     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uidData);
37     uid = static_cast<int32_t>(uidData);
38 
39     int32_t hostUidData;
40     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hostUidData);
41     hostUid = static_cast<int32_t>(hostUidData);
42 
43     int32_t userIdData;
44     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, userIdData);
45     userId = static_cast<int32_t>(userIdData);
46 
47     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childProcessType);
48 
49     bundleName = Str16ToStr8(parcel.ReadString16());
50     processName = Str16ToStr8(parcel.ReadString16());
51     srcEntry = Str16ToStr8(parcel.ReadString16());
52     entryFunc = Str16ToStr8(parcel.ReadString16());
53     entryParams = Str16ToStr8(parcel.ReadString16());
54     jitEnabled = parcel.ReadBool();
55     isDebugApp = parcel.ReadBool();
56     isStartWithDebug = parcel.ReadBool();
57     isStartWithNative = parcel.ReadBool();
58 
59     return true;
60 }
61 
Unmarshalling(Parcel & parcel)62 ChildProcessInfo *ChildProcessInfo::Unmarshalling(Parcel &parcel)
63 {
64     ChildProcessInfo *info = new (std::nothrow) ChildProcessInfo();
65     if (info && !info->ReadFromParcel(parcel)) {
66         TAG_LOGW(AAFwkTag::APPMGR, "read from parcel failed");
67         delete info;
68         info = nullptr;
69     }
70     return info;
71 }
72 
Marshalling(Parcel & parcel) const73 bool ChildProcessInfo::Marshalling(Parcel &parcel) const
74 {
75     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pid));
76     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(hostPid));
77     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(uid));
78     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(hostUid));
79     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(userId));
80     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(childProcessType));
81     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
82     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName));
83     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcEntry));
84     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entryFunc));
85     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entryParams));
86     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, jitEnabled);
87     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDebugApp);
88     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isStartWithDebug);
89     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isStartWithNative);
90     return true;
91 }
92 }  // namespace AppExecFwk
93 }  // namespace OHOS
94