• 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 "exit_reason.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 {
ExitReason(const Reason reason,const std::string & exitMsg)24 ExitReason::ExitReason(const Reason reason, const std::string &exitMsg)
25 {
26     this->reason = reason;
27     this->exitMsg = exitMsg;
28 }
29 
ExitReason(const Reason & reason,int32_t subReason,const std::string & exitMsg)30 ExitReason::ExitReason(const Reason &reason, int32_t subReason, const std::string &exitMsg)
31 {
32     this->reason = reason;
33     this->subReason = subReason;
34     this->exitMsg = exitMsg;
35 }
36 
ReadFromParcel(Parcel & parcel)37 bool ExitReason::ReadFromParcel(Parcel &parcel)
38 {
39     int32_t reasonData;
40     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reasonData);
41     reason = static_cast<Reason>(reasonData);
42     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reasonData);
43     subReason = reasonData;
44     exitMsg = Str16ToStr8(parcel.ReadString16());
45     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, shouldKillForeground);
46     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, shouldSkipKillInStartup);
47     return true;
48 }
49 
Unmarshalling(Parcel & parcel)50 ExitReason *ExitReason::Unmarshalling(Parcel &parcel)
51 {
52     ExitReason *data = new (std::nothrow) ExitReason();
53     if (!data) {
54         TAG_LOGE(AAFwkTag::ABILITYMGR, "null data");
55         return nullptr;
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 ExitReason::Marshalling(Parcel &parcel) const
66 {
67     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(reason));
68     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, subReason);
69     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(exitMsg));
70     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, shouldKillForeground);
71     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, shouldSkipKillInStartup);
72     return true;
73 }
74 }  // namespace AppExecFwk
75 }  // namespace OHOS
76