1 /*
2 * Copyright (c) 2023-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 "ecological_rule/ability_ecological_rule_mgr_service_param.h"
17
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace EcologicalRuleMgrService {
22
Unmarshalling(Parcel & in)23 AbilityExperienceRule *AbilityExperienceRule::Unmarshalling(Parcel &in)
24 {
25 auto *rule = new (std::nothrow) AbilityExperienceRule();
26 if (rule == nullptr) {
27 return nullptr;
28 }
29
30 if (!in.ReadInt32(rule->resultCode)) {
31 delete rule;
32 return nullptr;
33 }
34
35 if (!in.ReadString(rule->sceneCode)) {
36 delete rule;
37 return nullptr;
38 }
39
40 rule->replaceWant = in.ReadParcelable<Want>();
41
42 if (!in.ReadBool(rule->isBackSkuExempt)) {
43 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read isBackSkuExempt failed");
44 rule->isBackSkuExempt = true;
45 }
46
47 if (!in.ReadInt32(rule->embedResultCode)) {
48 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read embedResultCode failed");
49 rule->embedResultCode = 1;
50 }
51
52 return rule;
53 }
54
Marshalling(Parcel & parcel) const55 bool AbilityExperienceRule::Marshalling(Parcel &parcel) const
56 {
57 if (!parcel.WriteInt32(resultCode)) {
58 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write resultCode failed");
59 return false;
60 }
61
62 if (!parcel.WriteString(sceneCode)) {
63 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write sceneCode failed");
64 return false;
65 }
66 if (!parcel.WriteParcelable(replaceWant)) {
67 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write replaceWant failed");
68 return false;
69 }
70
71 if (!parcel.WriteBool(isBackSkuExempt)) {
72 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write isBackSkuExempt failed");
73 }
74
75 if (!parcel.WriteInt32(embedResultCode)) {
76 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write embedResultCode failed");
77 }
78
79 return true;
80 }
81
ReadFromParcel(Parcel & parcel)82 bool AbilityCallerInfo::ReadFromParcel(Parcel &parcel)
83 {
84 TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "read from parcel");
85 return true;
86 }
87
Unmarshalling(Parcel & in)88 AbilityCallerInfo *AbilityCallerInfo::Unmarshalling(Parcel &in)
89 {
90 auto *info = new (std::nothrow) AbilityCallerInfo();
91 if (info == nullptr) {
92 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "info null");
93 return nullptr;
94 }
95
96 info->packageName = in.ReadString();
97 TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "read packageName result: %{public}s", info->packageName.c_str());
98
99 if (!in.ReadInt32(info->uid)) {
100 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read uid failed");
101 delete info;
102 return nullptr;
103 }
104
105 if (!in.ReadInt32(info->pid)) {
106 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read pid failed");
107 delete info;
108 return nullptr;
109 }
110
111 if (!in.ReadInt32(info->callerAppType)) {
112 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read callerAppType failed");
113 delete info;
114 return nullptr;
115 }
116
117 if (!in.ReadInt32(info->targetAppType)) {
118 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read targetAppType failed");
119 delete info;
120 return nullptr;
121 }
122
123 if (!in.ReadInt32(info->callerModelType)) {
124 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read callerModelType failed");
125 delete info;
126 return nullptr;
127 }
128
129 info->targetAppDistType = in.ReadString();
130 info->targetLinkFeature = in.ReadString();
131
132 if (!in.ReadInt32(info->targetLinkType)) {
133 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read targetLinkType failed");
134 delete info;
135 return nullptr;
136 }
137
138 info->callerAbilityType = static_cast<AppExecFwk::AbilityType>(in.ReadInt32());
139
140 info->embedded = in.ReadInt32();
141 info->callerAppProvisionType = in.ReadString();
142 info->targetAppProvisionType = in.ReadString();
143 info->callerExtensionAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(in.ReadInt32());
144 info->targetAbilityType = static_cast<AppExecFwk::AbilityType>(in.ReadInt32());
145 info->targetExtensionAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(in.ReadInt32());
146 return info;
147 }
148
Marshalling(Parcel & parcel) const149 bool AbilityCallerInfo::Marshalling(Parcel &parcel) const
150 {
151 if (!DoMarshallingOne(parcel)) {
152 return false;
153 }
154
155 if (!DoMarshallingTwo(parcel)) {
156 return false;
157 }
158
159 return true;
160 }
161
DoMarshallingOne(Parcel & parcel) const162 bool AbilityCallerInfo::DoMarshallingOne(Parcel &parcel) const
163 {
164 if (!parcel.WriteString(packageName)) {
165 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write packageName failed");
166 return false;
167 }
168
169 if (!parcel.WriteInt32(uid)) {
170 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write uid failed");
171 return false;
172 }
173
174 if (!parcel.WriteInt32(pid)) {
175 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write pid failed");
176 return false;
177 }
178
179 if (!parcel.WriteInt32(callerAppType)) {
180 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerAppType failed");
181 return false;
182 }
183
184 if (!parcel.WriteInt32(targetAppType)) {
185 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetAppType failed");
186 return false;
187 }
188
189 if (!parcel.WriteInt32(callerModelType)) {
190 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerModelType failed");
191 return false;
192 }
193
194 if (!parcel.WriteString(targetAppDistType)) {
195 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetAppDistType failed");
196 return false;
197 }
198
199 if (!parcel.WriteString(targetLinkFeature)) {
200 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetLinkFeature failed");
201 return false;
202 }
203
204 if (!parcel.WriteInt32(targetLinkType)) {
205 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetLinkType failed");
206 return false;
207 }
208
209 if (!parcel.WriteInt32(static_cast<int32_t>(callerAbilityType))) {
210 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerAbilityType failed");
211 return false;
212 }
213
214 return true;
215 }
216
DoMarshallingTwo(Parcel & parcel) const217 bool AbilityCallerInfo::DoMarshallingTwo(Parcel &parcel) const
218 {
219 if (!parcel.WriteInt32(embedded)) {
220 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write embedded failed");
221 return false;
222 }
223
224 if (!parcel.WriteString(callerAppProvisionType)) {
225 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerAppProvisionType failed");
226 return false;
227 }
228
229 if (!parcel.WriteString(targetAppProvisionType)) {
230 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetAppProvisionType failed");
231 return false;
232 }
233
234 if (!parcel.WriteInt32(static_cast<int32_t>(callerExtensionAbilityType))) {
235 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerExtensionAbilityType failed");
236 return false;
237 }
238
239 if (!parcel.WriteInt32(static_cast<int32_t>(targetAbilityType))) {
240 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetAbilityType failed");
241 return false;
242 }
243
244 if (!parcel.WriteInt32(static_cast<int32_t>(targetExtensionAbilityType))) {
245 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetExtensionAbilityType failed");
246 return false;
247 }
248
249 if (!parcel.WriteInt32(userId)) {
250 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write userId failed");
251 return false;
252 }
253
254 if (!parcel.WriteInt32(targetApplicationReservedFlag)) {
255 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetApplicationReservedFlag failed");
256 return false;
257 }
258
259 if (!parcel.WriteBool(isAsCaller)) {
260 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write isAsCaller failed");
261 return false;
262 }
263
264 if (!parcel.WriteString(targetBundleName)) {
265 TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetBundleName failed");
266 return false;
267 }
268
269 return true;
270 }
271
ToString() const272 std::string AbilityCallerInfo::ToString() const
273 {
274 std::string str = "CallerInfo{packageName:" + packageName + ",uid:" + std::to_string(uid) +
275 ",pid:" + std::to_string(pid) + ",callerAppType:" + std::to_string(callerAppType) +
276 ",targetAppType:" + std::to_string(targetAppType) + ",callerModelType:" + std::to_string(callerModelType) +
277 ",targetAppDistType:" + targetAppDistType + ",targetLinkFeature:" + targetLinkFeature + ",targetLinkType:" +
278 std::to_string(targetLinkType) + ",callerAbilityType:" +
279 std::to_string(static_cast<int32_t>(callerAbilityType)) + ",callerExtensionAbilityType:" +
280 std::to_string(static_cast<int32_t>(callerExtensionAbilityType)) + ",embedded:" +
281 std::to_string(embedded) + ",callerAppProvisionType:" + callerAppProvisionType + ",targetAppProvisionType:" +
282 targetAppProvisionType + ",targetAbilityType:" +
283 std::to_string(static_cast<int32_t>(targetAbilityType)) + ",targetExtensionAbilityType:" +
284 std::to_string(static_cast<int32_t>(targetExtensionAbilityType)) + ",isAsCaller:" +
285 std::to_string(static_cast<int32_t>(isAsCaller)) + "}";
286 return str;
287 }
288 } // namespace EcologicalRuleMgrService
289 } // namespace OHOS
290