• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "lifecycle_state_info.h"
17 
18 #include "nlohmann/json.hpp"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
ReadFromParcel(Parcel & parcel)23 bool LifeCycleStateInfo::ReadFromParcel(Parcel &parcel)
24 {
25     isNewWant = parcel.ReadBool();
26     int32_t stateData = parcel.ReadInt32();
27     state = static_cast<AbilityLifeCycleState>(stateData);
28     missionId = parcel.ReadInt32();
29     std::unique_ptr<CallerInfo> callerInfo(parcel.ReadParcelable<CallerInfo>());
30     if (callerInfo == nullptr) {
31         return false;
32     }
33     caller = *callerInfo;
34     setting = std::shared_ptr<AbilityStartSetting>(parcel.ReadParcelable<AbilityStartSetting>());
35     std::unique_ptr<LaunchParam> launchInfo(parcel.ReadParcelable<LaunchParam>());
36     if (launchInfo == nullptr) {
37         return false;
38     }
39     launchParam = *launchInfo;
40     sceneFlag = parcel.ReadUint32();
41     return true;
42 }
43 
Unmarshalling(Parcel & parcel)44 LifeCycleStateInfo *LifeCycleStateInfo::Unmarshalling(Parcel &parcel)
45 {
46     LifeCycleStateInfo *info = new (std::nothrow) LifeCycleStateInfo();
47     if (info == nullptr) {
48         return nullptr;
49     }
50 
51     if (!info->ReadFromParcel(parcel)) {
52         delete info;
53         info = nullptr;
54     }
55     return info;
56 }
57 
Marshalling(Parcel & parcel) const58 bool LifeCycleStateInfo::Marshalling(Parcel &parcel) const
59 {
60     // write isNewWant
61     if (!parcel.WriteBool(isNewWant)) {
62         return false;
63     }
64     // write state
65     if (!parcel.WriteInt32(static_cast<int32_t>(state))) {
66         return false;
67     }
68     // write missionId
69     if (!parcel.WriteInt32(missionId)) {
70         return false;
71     }
72     // write caller
73     if (!parcel.WriteParcelable(&caller)) {
74         return false;
75     }
76     // write setting
77     if (!parcel.WriteParcelable(setting.get())) {
78         return false;
79     }
80     // write launch param
81     if (!parcel.WriteParcelable(&launchParam)) {
82         return false;
83     }
84     if (!parcel.WriteUint32(sceneFlag)) {
85         return false;
86     }
87     return true;
88 }
89 }  // namespace AAFwk
90 }  // namespace OHOS
91