1 /*
2 * Copyright (c) 2023 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_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 return true;
40 }
41
Unmarshalling(Parcel & parcel)42 RenderProcessInfo *RenderProcessInfo::Unmarshalling(Parcel &parcel)
43 {
44 RenderProcessInfo *info = new (std::nothrow) RenderProcessInfo();
45 if (info && !info->ReadFromParcel(parcel)) {
46 HILOG_WARN("read from parcel failed");
47 delete info;
48 info = nullptr;
49 }
50 return info;
51 }
52
Marshalling(Parcel & parcel) const53 bool RenderProcessInfo::Marshalling(Parcel &parcel) const
54 {
55 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName_));
56 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName_));
57 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(pid_));
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(uid_));
59 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(hostUid_));
60 return true;
61 }
62 } // namespace AppExecFwk
63 } // namespace OHOS
64