1 /*
2  * Copyright (c) 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 "string_ex.h"
17 #include "report_data.h"
18 #include "xcollie_utils.h"
19 
20 namespace OHOS {
21 namespace HiviewDFX {
WriteContent(Parcel & parcel) const22 bool ReportData::WriteContent(Parcel &parcel) const
23 {
24     if (!parcel.WriteBool(forceExit)) {
25         XCOLLIE_LOGE("ForceExit [%{public}s] write bool failed.", forceExit ? "true" : "false");
26         return false;
27     }
28 
29     if (!parcel.WriteUint32(state)) {
30         XCOLLIE_LOGE("State [%{public}u] write uint32 failed.", state);
31         return false;
32     }
33 
34     if (!parcel.WriteInt32(eventId)) {
35         XCOLLIE_LOGE("EventId [%{public}u] write int32 failed.", eventId);
36         return false;
37     }
38 
39     if (!parcel.WriteInt32(tid)) {
40         XCOLLIE_LOGE("Tid [%{public}u] write int32 failed.", tid);
41         return false;
42     }
43 
44     if (token == nullptr) {
45         if (!parcel.WriteBool(false)) {
46             XCOLLIE_LOGE("Token falge [false] write bool failed.");
47             return false;
48         }
49     } else {
50         if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
51             XCOLLIE_LOGE("Token falge [true] write bool failed.");
52             return false;
53         }
54     }
55     return true;
56 }
57 
Marshalling(Parcel & parcel) const58 bool ReportData::Marshalling(Parcel &parcel) const
59 {
60     if (!parcel.WriteString(errorObject.name)) {
61         XCOLLIE_LOGE("Name [%{public}s] write string failed.", errorObject.name.c_str());
62         return false;
63     }
64 
65     if (!parcel.WriteString(errorObject.message)) {
66         XCOLLIE_LOGE("Message [%{public}s] write string failed.", errorObject.message.c_str());
67         return false;
68     }
69 
70     if (!parcel.WriteString(errorObject.stack)) {
71         XCOLLIE_LOGE("Stack [%{public}s] write string failed.", errorObject.stack.c_str());
72         return false;
73     }
74 
75     if (!parcel.WriteInt32(static_cast<int32_t>(faultType))) {
76         XCOLLIE_LOGE("FaultType [%{public}d] write int32 failed.", static_cast<int32_t>(faultType));
77         return false;
78     }
79 
80     if (!parcel.WriteString(timeoutMarkers)) {
81         XCOLLIE_LOGE("TimeoutMarkers [%{public}s] write string failed.", timeoutMarkers.c_str());
82         return false;
83     }
84 
85     if (!parcel.WriteBool(waitSaveState)) {
86         XCOLLIE_LOGE("WaitSaveState [%{public}s] write bool failed.", waitSaveState ? "true" : "false");
87         return false;
88     }
89 
90     if (!parcel.WriteBool(notifyApp)) {
91         XCOLLIE_LOGE("NotifyApp [%{public}s] write bool failed.", notifyApp ? "true" : "false");
92         return false;
93     }
94 
95     return WriteContent(parcel);
96 }
97 } // end of HiviewDFX
98 } // end of OHOS
99