1 /*
2  * Copyright (c) 2022 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 "ability_running_info.h"
17 
18 namespace OHOS {
19 namespace AAFwk {
ReadFromParcel(Parcel & parcel)20 bool AbilityRunningInfo::ReadFromParcel(Parcel &parcel)
21 {
22     std::unique_ptr<AppExecFwk::ElementName> abilityInfo(parcel.ReadParcelable<AppExecFwk::ElementName>());
23     if (abilityInfo == nullptr) {
24         return false;
25     }
26     ability = *abilityInfo;
27     pid = parcel.ReadInt32();
28     uid = parcel.ReadInt32();
29     processName = Str16ToStr8(parcel.ReadString16());
30     startTime = parcel.ReadInt64();
31     abilityState = parcel.ReadInt32();
32     appCloneIndex = parcel.ReadInt32();
33     return true;
34 }
35 
Unmarshalling(Parcel & parcel)36 AbilityRunningInfo *AbilityRunningInfo::Unmarshalling(Parcel &parcel)
37 {
38     AbilityRunningInfo *info = new (std::nothrow) AbilityRunningInfo();
39     if (info == nullptr) {
40         return nullptr;
41     }
42 
43     if (!info->ReadFromParcel(parcel)) {
44         delete info;
45         info = nullptr;
46     }
47     return info;
48 }
49 
Marshalling(Parcel & parcel) const50 bool AbilityRunningInfo::Marshalling(Parcel &parcel) const
51 {
52     if (!parcel.WriteParcelable(&ability)) {
53         return false;
54     }
55     if (!parcel.WriteInt32(pid)) {
56         return false;
57     }
58     if (!parcel.WriteInt32(uid)) {
59         return false;
60     }
61     if (!parcel.WriteString16(Str8ToStr16(processName))) {
62         return false;
63     }
64     if (!parcel.WriteInt64(startTime)) {
65         return false;
66     }
67     if (!parcel.WriteInt32(abilityState)) {
68         return false;
69     }
70     if (!parcel.WriteInt32(appCloneIndex)) {
71         return false;
72     }
73     return true;
74 }
75 }  // namespace AAFwk
76 }  // namespace OHOS
77