1 /*
2 * Copyright (c) 2025 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 "last_exit_detail_info.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 AAFwk {
ReadFromParcel(Parcel & parcel)24 bool LastExitDetailInfo::ReadFromParcel(Parcel &parcel)
25 {
26 int32_t pidData;
27 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pidData);
28 pid = pidData;
29 int32_t uidData;
30 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uidData);
31 uid = uidData;
32 int32_t exitSubReasonData;
33 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, exitSubReasonData);
34 exitSubReason = exitSubReasonData;
35 int32_t rssData;
36 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rssData);
37 rss = rssData;
38 int32_t pssData;
39 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pssData);
40 pss = pssData;
41 int64_t timeStampData;
42 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timeStampData);
43 timestamp = timeStampData;
44 processName = Str16ToStr8(parcel.ReadString16());
45 exitMsg = Str16ToStr8(parcel.ReadString16());
46 return true;
47 }
48
Unmarshalling(Parcel & parcel)49 LastExitDetailInfo *LastExitDetailInfo::Unmarshalling(Parcel &parcel)
50 {
51 LastExitDetailInfo *data = new (std::nothrow) LastExitDetailInfo();
52 if (data == nullptr) {
53 TAG_LOGE(AAFwkTag::ABILITYMGR, "null data");
54 return nullptr;
55 }
56
57 if (!data->ReadFromParcel(parcel)) {
58 TAG_LOGE(AAFwkTag::ABILITYMGR, "read failed");
59 delete data;
60 data = nullptr;
61 }
62 return data;
63 }
64
Marshalling(Parcel & parcel) const65 bool LastExitDetailInfo::Marshalling(Parcel &parcel) const
66 {
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pid);
68 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
69 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, exitSubReason);
70 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rss);
71 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pss);
72 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timestamp);
73 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName));
74 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(exitMsg));
75 return true;
76 }
77 } // namespace AAFwk
78 } // namespace OHOS
79