• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 "fault_data.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 #include "hilog_tag_wrapper.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)24 bool FaultData::ReadFromParcel(Parcel &parcel)
25 {
26     std::string strValue;
27     if (!parcel.ReadString(strValue)) {
28         TAG_LOGE(AAFwkTag::APPMGR, "Name read string failed.");
29         return false;
30     }
31     errorObject.name = strValue;
32 
33     if (!parcel.ReadString(strValue)) {
34         TAG_LOGE(AAFwkTag::APPMGR, "Message read string failed.");
35         return false;
36     }
37     errorObject.message = strValue;
38 
39     if (!parcel.ReadString(strValue)) {
40         TAG_LOGE(AAFwkTag::APPMGR, "Stack read string failed.");
41         return false;
42     }
43     errorObject.stack = strValue;
44 
45     int type = 0;
46     if (!parcel.ReadInt32(type)) {
47         TAG_LOGE(AAFwkTag::APPMGR, "FaultType read int32 failed.");
48         return false;
49     }
50     faultType = static_cast<FaultDataType>(type);
51 
52     if (!parcel.ReadString(strValue)) {
53         TAG_LOGE(AAFwkTag::APPMGR, "TimeoutMarkers read string failed.");
54         return false;
55     }
56     timeoutMarkers = strValue;
57 
58     waitSaveState = parcel.ReadBool();
59     notifyApp = parcel.ReadBool();
60     forceExit = parcel.ReadBool();
61     state = parcel.ReadUint32();
62     eventId = parcel.ReadInt32();
63     tid = parcel.ReadInt32();
64     stuckTimeout = parcel.ReadUint32();
65     if (parcel.ReadBool()) {
66         token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
67     }
68     return true;
69 }
70 
Unmarshalling(Parcel & parcel)71 FaultData *FaultData::Unmarshalling(Parcel &parcel)
72 {
73     FaultData *info = new FaultData();
74     if (!info->ReadFromParcel(parcel)) {
75         delete info;
76         info = nullptr;
77     }
78     return info;
79 }
80 
WriteContent(Parcel & parcel) const81 bool FaultData::WriteContent(Parcel &parcel) const
82 {
83     if (!parcel.WriteUint32(stuckTimeout)) {
84         TAG_LOGE(AAFwkTag::APPMGR, "stuckTimeout [%{public}u] write uint32 failed.", stuckTimeout);
85         return false;
86     }
87 
88     if (token == nullptr) {
89         if (!parcel.WriteBool(false)) {
90             TAG_LOGE(AAFwkTag::APPMGR, "Token falge [false] write bool failed.");
91             return false;
92         }
93     } else {
94         if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
95             TAG_LOGE(AAFwkTag::APPMGR, "Token falge [true] write bool failed.");
96             return false;
97         }
98     }
99     return true;
100 }
101 
Marshalling(Parcel & parcel) const102 bool FaultData::Marshalling(Parcel &parcel) const
103 {
104     if (!parcel.WriteString(errorObject.name)) {
105         TAG_LOGE(AAFwkTag::APPMGR, "Name [%{public}s] write string failed.", errorObject.name.c_str());
106         return false;
107     }
108 
109     if (!parcel.WriteString(errorObject.message)) {
110         TAG_LOGE(AAFwkTag::APPMGR, "Message [%{public}s] write string failed.", errorObject.message.c_str());
111         return false;
112     }
113 
114     if (!parcel.WriteString(errorObject.stack)) {
115         TAG_LOGE(AAFwkTag::APPMGR, "Stack [%{public}s] write string failed.", errorObject.stack.c_str());
116         return false;
117     }
118 
119     if (!parcel.WriteInt32(static_cast<int32_t>(faultType))) {
120         TAG_LOGE(AAFwkTag::APPMGR, "FaultType [%{public}d] write int32 failed.", static_cast<int32_t>(faultType));
121         return false;
122     }
123 
124     if (!parcel.WriteString(timeoutMarkers)) {
125         TAG_LOGE(AAFwkTag::APPMGR, "TimeoutMarkers [%{public}s] write string failed.", timeoutMarkers.c_str());
126         return false;
127     }
128 
129     if (!parcel.WriteBool(waitSaveState)) {
130         TAG_LOGE(AAFwkTag::APPMGR, "WaitSaveState [%{public}s] write bool failed.", waitSaveState ? "true" : "false");
131         return false;
132     }
133 
134     if (!parcel.WriteBool(notifyApp)) {
135         TAG_LOGE(AAFwkTag::APPMGR, "NotifyApp [%{public}s] write bool failed.", notifyApp ? "true" : "false");
136         return false;
137     }
138 
139     if (!parcel.WriteBool(forceExit)) {
140         TAG_LOGE(AAFwkTag::APPMGR, "ForceExit [%{public}s] write bool failed.", forceExit ? "true" : "false");
141         return false;
142     }
143 
144     if (!parcel.WriteUint32(state)) {
145         TAG_LOGE(AAFwkTag::APPMGR, "State [%{public}u] write uint32 failed.", state);
146         return false;
147     }
148 
149     if (!parcel.WriteInt32(eventId)) {
150         TAG_LOGE(AAFwkTag::APPMGR, "EventId [%{public}u] write int32 failed.", eventId);
151         return false;
152     }
153 
154     if (!parcel.WriteInt32(tid)) {
155         TAG_LOGE(AAFwkTag::APPMGR, "Tid [%{public}u] write int32 failed.", tid);
156         return false;
157     }
158 
159     return WriteContent(parcel);
160 }
161 
ReadFromParcel(Parcel & parcel)162 bool AppFaultDataBySA::ReadFromParcel(Parcel &parcel)
163 {
164     std::string strValue;
165     if (!parcel.ReadString(strValue)) {
166         TAG_LOGE(AAFwkTag::APPMGR, "Name read string failed.");
167         return false;
168     }
169     errorObject.name = strValue;
170 
171     if (!parcel.ReadString(strValue)) {
172         TAG_LOGE(AAFwkTag::APPMGR, "Message read string failed.");
173         return false;
174     }
175     errorObject.message = strValue;
176 
177     if (!parcel.ReadString(strValue)) {
178         TAG_LOGE(AAFwkTag::APPMGR, "Stack read string failed.");
179         return false;
180     }
181     errorObject.stack = strValue;
182 
183     int type = 0;
184     if (!parcel.ReadInt32(type)) {
185         TAG_LOGE(AAFwkTag::APPMGR, "Type read int32 failed.");
186         return false;
187     }
188     faultType = static_cast<FaultDataType>(type);
189 
190     if (!parcel.ReadInt32(pid)) {
191         TAG_LOGE(AAFwkTag::APPMGR, "Pid read int32 failed.");
192         return false;
193     }
194 
195     if (!parcel.ReadString(strValue)) {
196         TAG_LOGE(AAFwkTag::APPMGR, "TimeoutMarkers read string failed.");
197         return false;
198     }
199     timeoutMarkers = strValue;
200 
201     waitSaveState = parcel.ReadBool();
202     notifyApp = parcel.ReadBool();
203     forceExit = parcel.ReadBool();
204     state = parcel.ReadUint32();
205     eventId = parcel.ReadInt32();
206     if (parcel.ReadBool()) {
207         token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
208     }
209     return true;
210 }
211 
Unmarshalling(Parcel & parcel)212 AppFaultDataBySA *AppFaultDataBySA::Unmarshalling(Parcel &parcel)
213 {
214     AppFaultDataBySA *info = new AppFaultDataBySA();
215     if (!info->ReadFromParcel(parcel)) {
216         delete info;
217         info = nullptr;
218     }
219     return info;
220 }
221 
Marshalling(Parcel & parcel) const222 bool AppFaultDataBySA::Marshalling(Parcel &parcel) const
223 {
224     if (!parcel.WriteString(errorObject.name)) {
225         TAG_LOGE(AAFwkTag::APPMGR, "Name [%{public}s] write string failed.", errorObject.name.c_str());
226         return false;
227     }
228 
229     if (!parcel.WriteString(errorObject.message)) {
230         TAG_LOGE(AAFwkTag::APPMGR, "Message [%{public}s] write string failed.", errorObject.message.c_str());
231         return false;
232     }
233 
234     if (!parcel.WriteString(errorObject.stack)) {
235         TAG_LOGE(AAFwkTag::APPMGR, "Stack [%{public}s] write string failed.", errorObject.stack.c_str());
236         return false;
237     }
238 
239     if (!parcel.WriteInt32(static_cast<int32_t>(faultType))) {
240         TAG_LOGE(AAFwkTag::APPMGR, "FaultType [%{public}d] write int32 failed.", static_cast<int32_t>(faultType));
241         return false;
242     }
243 
244     if (!parcel.WriteInt32(pid)) {
245         TAG_LOGE(AAFwkTag::APPMGR, "Pid [%{public}d] write int32 failed.", static_cast<int32_t>(pid));
246         return false;
247     }
248 
249     if (!parcel.WriteString(timeoutMarkers)) {
250         TAG_LOGE(AAFwkTag::APPMGR, "TimeoutMarkers [%{public}s] write string failed.", timeoutMarkers.c_str());
251         return false;
252     }
253 
254     if (!parcel.WriteBool(waitSaveState)) {
255         TAG_LOGE(AAFwkTag::APPMGR, "WaitSaveState [%{public}s] write bool failed.", waitSaveState ? "true" : "false");
256         return false;
257     }
258 
259     if (!parcel.WriteBool(notifyApp)) {
260         TAG_LOGE(AAFwkTag::APPMGR, "NotifyApp [%{public}s] write bool failed.", notifyApp ? "true" : "false");
261         return false;
262     }
263 
264     if (!parcel.WriteBool(forceExit)) {
265         TAG_LOGE(AAFwkTag::APPMGR, "ForceExit [%{public}s] write bool failed.", forceExit ? "true" : "false");
266         return false;
267     }
268 
269     if (!parcel.WriteUint32(state)) {
270         TAG_LOGE(AAFwkTag::APPMGR, "State [%{public}u] write uint32 failed.", state);
271         return false;
272     }
273 
274     if (!parcel.WriteInt32(eventId)) {
275         TAG_LOGE(AAFwkTag::APPMGR, "EventId [%{public}u] write int32 failed.", eventId);
276         return false;
277     }
278 
279     if (token == nullptr) {
280         if (!parcel.WriteBool(false)) {
281             TAG_LOGE(AAFwkTag::APPMGR, "Token falge [false] write bool failed.");
282             return false;
283         }
284     } else {
285         if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
286             TAG_LOGE(AAFwkTag::APPMGR, "Token falge [true] write bool failed.");
287             return false;
288         }
289     }
290     return true;
291 }
292 }  // namespace AppExecFwk
293 }  // namespace OHOS