• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.WriteInt32(tid)) {
25         XCOLLIE_LOGE("Tid [%{public}u] write int32 failed.", tid);
26         return false;
27     }
28 
29     if (!parcel.WriteUint32(stuckTimeout)) {
30         XCOLLIE_LOGE("StuckTimeout [%{public}u] write uint32 failed.", stuckTimeout);
31         return false;
32     }
33 
34     if (token == nullptr) {
35         if (!parcel.WriteBool(false)) {
36             XCOLLIE_LOGE("Token falge [false] write bool failed.");
37             return false;
38         }
39     } else {
40         if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
41             XCOLLIE_LOGE("Token falge [true] write bool failed.");
42             return false;
43         }
44     }
45 
46     if (!parcel.WriteString(freezeInfo)) {
47         XCOLLIE_LOGE("FreezeInfo [%{public}s] write string failed.", freezeInfo.c_str());
48         return false;
49     }
50 
51     if (!parcel.WriteString(appRunningUniqueId)) {
52         XCOLLIE_LOGE("AppRunningUniqueId [%{public}s] write string failed.", appRunningUniqueId.c_str());
53         return false;
54     }
55 
56     if (!parcel.WriteString(procStatm)) {
57         XCOLLIE_LOGE("ProcStatm [%{public}s] write string failed.", procStatm.c_str());
58         return false;
59     }
60     return true;
61 }
62 
Marshalling(Parcel & parcel) const63 bool ReportData::Marshalling(Parcel &parcel) const
64 {
65     if (!parcel.WriteString(errorObject.name)) {
66         XCOLLIE_LOGE("Name [%{public}s] write string failed.", errorObject.name.c_str());
67         return false;
68     }
69 
70     if (!parcel.WriteString(errorObject.message)) {
71         XCOLLIE_LOGE("Message [%{public}s] write string failed.", errorObject.message.c_str());
72         return false;
73     }
74 
75     if (!parcel.WriteString(errorObject.stack)) {
76         XCOLLIE_LOGE("Stack [%{public}s] write string failed.", errorObject.stack.c_str());
77         return false;
78     }
79 
80     if (!parcel.WriteInt32(static_cast<int32_t>(faultType))) {
81         XCOLLIE_LOGE("FaultType [%{public}d] write int32 failed.", static_cast<int32_t>(faultType));
82         return false;
83     }
84 
85     if (!parcel.WriteString(timeoutMarkers)) {
86         XCOLLIE_LOGE("TimeoutMarkers [%{public}s] write string failed.", timeoutMarkers.c_str());
87         return false;
88     }
89 
90     if (!parcel.WriteBool(waitSaveState)) {
91         XCOLLIE_LOGE("WaitSaveState [%{public}s] write bool failed.", waitSaveState ? "true" : "false");
92         return false;
93     }
94 
95     if (!parcel.WriteBool(notifyApp)) {
96         XCOLLIE_LOGE("NotifyApp [%{public}s] write bool failed.", notifyApp ? "true" : "false");
97         return false;
98     }
99 
100     if (!parcel.WriteBool(forceExit)) {
101         XCOLLIE_LOGE("ForceExit [%{public}s] write bool failed.", forceExit ? "true" : "false");
102         return false;
103     }
104 
105     if (!parcel.WriteBool(needKillProcess)) {
106         XCOLLIE_LOGE("needKillProcess [%{public}s] write bool failed.", needKillProcess ? "true" : "false");
107         return false;
108     }
109 
110     if (!parcel.WriteUint32(state)) {
111         XCOLLIE_LOGE("State [%{public}u] write uint32 failed.", state);
112         return false;
113     }
114 
115     if (!parcel.WriteInt32(eventId)) {
116         XCOLLIE_LOGE("EventId [%{public}u] write int32 failed.", eventId);
117         return false;
118     }
119 
120     return WriteContent(parcel);
121 }
122 } // end of HiviewDFX
123 } // end of OHOS
124