1/*
2 * Copyright (c) 2021-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 "launch_param.h"
17
18#include "hilog_tag_wrapper.h"
19#include "string_ex.h"
20
21namespace OHOS {
22namespace AAFwk {
23bool LaunchParam::ReadFromParcel(Parcel &parcel)
24{
25    int32_t reason = 0;
26    if (!parcel.ReadInt32(reason)) {
27        return false;
28    }
29    launchReason = static_cast<LaunchReason>(reason);
30
31    if (!parcel.ReadInt32(reason)) {
32        return false;
33    }
34    lastExitReason = static_cast<LastExitReason>(reason);
35
36    lastExitMessage = Str16ToStr8(parcel.ReadString16());
37    return true;
38}
39
40LaunchParam *LaunchParam::Unmarshalling(Parcel &parcel)
41{
42    LaunchParam *param = new (std::nothrow) LaunchParam();
43    if (param == nullptr) {
44        return nullptr;
45    }
46
47    if (!param->ReadFromParcel(parcel)) {
48        delete param;
49        param = nullptr;
50    }
51    return param;
52}
53
54bool LaunchParam::Marshalling(Parcel &parcel) const
55{
56    // write launchReason
57    if (!parcel.WriteInt32(static_cast<int32_t>(launchReason))) {
58        return false;
59    }
60    // write lastExitReason
61    if (!parcel.WriteInt32(static_cast<int32_t>(lastExitReason))) {
62        return false;
63    }
64    if (!parcel.WriteString16(Str8ToStr16(lastExitMessage))) {
65        TAG_LOGE(AAFwkTag::ABILITYMGR, "write lastExitMessage failed");
66        return false;
67    }
68    return true;
69}
70}  // namespace AAFwk
71}  // namespace OHOS
72