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 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pid);
27 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
28 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, exitSubReason);
29 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rss);
30 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pss);
31 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, processState);
32 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timestamp);
33 processName = Str16ToStr8(parcel.ReadString16());
34 exitMsg = Str16ToStr8(parcel.ReadString16());
35 return true;
36 }
37
Unmarshalling(Parcel & parcel)38 LastExitDetailInfo *LastExitDetailInfo::Unmarshalling(Parcel &parcel)
39 {
40 LastExitDetailInfo *data = new (std::nothrow) LastExitDetailInfo();
41 if (data == nullptr) {
42 TAG_LOGE(AAFwkTag::ABILITYMGR, "null data");
43 return nullptr;
44 }
45
46 if (!data->ReadFromParcel(parcel)) {
47 TAG_LOGE(AAFwkTag::ABILITYMGR, "read failed");
48 delete data;
49 data = nullptr;
50 }
51 return data;
52 }
53
Marshalling(Parcel & parcel) const54 bool LastExitDetailInfo::Marshalling(Parcel &parcel) const
55 {
56 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pid);
57 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
58 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, exitSubReason);
59 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, rss);
60 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pss);
61 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, processState);
62 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timestamp);
63 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(processName));
64 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(exitMsg));
65 return true;
66 }
67 } // namespace AAFwk
68 } // namespace OHOS
69