• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ability_state_data.h"
17 
18 #include "hilog_tag_wrapper.h"
19 
20 namespace OHOS {
21 namespace AppExecFwk {
Marshalling(Parcel & parcel) const22 bool AbilityStateData::Marshalling(Parcel &parcel) const
23 {
24     if (!parcel.WriteString(moduleName)) {
25         return false;
26     }
27     if (!parcel.WriteString(bundleName)) {
28         return false;
29     }
30     if (!parcel.WriteString(abilityName)) {
31         return false;
32     }
33     if (!parcel.WriteInt32(abilityState)) {
34         return false;
35     }
36     if (!parcel.WriteInt32(pid)) {
37         return false;
38     }
39     if (!parcel.WriteInt32(uid)) {
40         return false;
41     }
42     if (token == nullptr) {
43         if (!parcel.WriteBool(false)) {
44             return false;
45         }
46     } else {
47         if (!parcel.WriteBool(true)) {
48             return false;
49         }
50         if (!parcel.WriteRemoteObject(token)) {
51             return false;
52         }
53     }
54     if (!MarshallingOne(parcel)) {
55         return false;
56     }
57     return true;
58 }
59 
MarshallingOne(Parcel & parcel) const60 bool AbilityStateData::MarshallingOne(Parcel &parcel) const
61 {
62     if (!parcel.WriteInt32(abilityType)) {
63         return false;
64     }
65     if (!parcel.WriteBool(isFocused)) {
66         return false;
67     }
68     if (!parcel.WriteString(callerBundleName)) {
69         return false;
70     }
71     if (!parcel.WriteString(callerAbilityName)) {
72         return false;
73     }
74     if (!parcel.WriteBool(isAtomicService) || !parcel.WriteInt32(abilityRecordId)) {
75         return false;
76     }
77     if (!parcel.WriteInt32(appCloneIndex)) {
78         return false;
79     }
80     if (!parcel.WriteInt32(extensionAbilityType)) {
81         return false;
82     }
83     if (!parcel.WriteInt32(processType)) {
84         return false;
85     }
86     if (!parcel.WriteInt32(callerUid)) {
87         return false;
88     }
89     if (!parcel.WriteBool(isInnerNotify)) {
90         return false;
91     }
92     return true;
93 }
94 
ReadFromParcel(Parcel & parcel)95 bool AbilityStateData::ReadFromParcel(Parcel &parcel)
96 {
97     moduleName = parcel.ReadString();
98 
99     bundleName = parcel.ReadString();
100 
101     abilityName = parcel.ReadString();
102 
103     abilityState = parcel.ReadInt32();
104 
105     pid = parcel.ReadInt32();
106 
107     uid = parcel.ReadInt32();
108 
109     if (parcel.ReadBool()) {
110         token = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
111     }
112 
113     abilityType = parcel.ReadInt32();
114 
115     isFocused = parcel.ReadBool();
116 
117     callerBundleName = parcel.ReadString();
118 
119     callerAbilityName = parcel.ReadString();
120     isAtomicService = parcel.ReadBool();
121     abilityRecordId = parcel.ReadInt32();
122     appCloneIndex = parcel.ReadInt32();
123     extensionAbilityType = parcel.ReadInt32();
124     processType = parcel.ReadInt32();
125     callerUid = parcel.ReadInt32();
126     isInnerNotify = parcel.ReadBool();
127     return true;
128 }
129 
Unmarshalling(Parcel & parcel)130 AbilityStateData *AbilityStateData::Unmarshalling(Parcel &parcel)
131 {
132     AbilityStateData *abilityStateData = new (std::nothrow) AbilityStateData();
133     if (abilityStateData && !abilityStateData->ReadFromParcel(parcel)) {
134         TAG_LOGW(AAFwkTag::APPMGR, "ReadFromParcel failed");
135         delete abilityStateData;
136         abilityStateData = nullptr;
137     }
138     return abilityStateData;
139 }
140 }  // namespace AppExecFwk
141 }  // namespace OHOS
142