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 "render_process_info.h"
17
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20
21 #include "hilog_tag_wrapper.h"
22 #include "parcel_macro_base.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)26 bool RenderProcessInfo::ReadFromParcel(Parcel &parcel)
27 {
28 bundleName_ = Str16ToStr8(parcel.ReadString16());
29 processName_ = Str16ToStr8(parcel.ReadString16());
30 int32_t pidData;
31 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pidData);
32 pid_ = static_cast<int32_t>(pidData);
33 int32_t uidData;
34 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uidData);
35 uid_ = static_cast<int32_t>(uidData);
36 int32_t hostUidData;
37 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hostUidData);
38 hostUid_ = static_cast<int32_t>(hostUidData);
39 int32_t hostPidData;
40 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hostPidData);
41 hostPid_ = static_cast<int32_t>(hostPidData);
42 int32_t stateData;
43 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, stateData);
44 state_ = static_cast<int32_t>(stateData);
45 return true;
46 }
47
Unmarshalling(Parcel & parcel)48 RenderProcessInfo *RenderProcessInfo::Unmarshalling(Parcel &parcel)
49 {
50 RenderProcessInfo *info = new (std::nothrow) RenderProcessInfo();
51 if (info && !info->ReadFromParcel(parcel)) {
52 TAG_LOGW(AAFwkTag::APPMGR, "read from parcel failed");
53 delete info;
54 info = nullptr;
55 }
56 return info;
57 }
58
Marshalling(Parcel & parcel) const59 bool RenderProcessInfo::Marshalling(Parcel &parcel) const
60 {
61 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName_));
62 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName_));
63 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pid_));
64 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(uid_));
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(hostUid_));
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(hostPid_));
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(state_));
68 return true;
69 }
70 } // namespace AppExecFwk
71 } // namespace OHOS
72