1 /*
2 * Copyright (c) 2023-2025 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 "session_info.h"
17
18 #include "ability_base_log_wrapper.h"
19 #include "ability_start_setting.h"
20 #include "js_window_animation_utils.h"
21 #include "process_options.h"
22 #include "start_window_option.h"
23 #include "wm_animation_common.h"
24
25 namespace OHOS {
26 namespace AAFwk {
27 constexpr int MAX_SUPPOPRT_WINDOW_MODES_SIZE = 10;
28
Marshalling(Parcel & parcel) const29 bool SessionInfo::Marshalling(Parcel& parcel) const
30 {
31 if (!DoMarshallingOne(parcel)) {
32 return false;
33 }
34
35 if (!DoMarshallingTwo(parcel)) {
36 return false;
37 }
38
39 if (!DoMarshallingThree(parcel)) {
40 return false;
41 }
42
43 if (!DoMarshallingFour(parcel)) {
44 return false;
45 }
46
47 if (!DoMarshallingFive(parcel)) {
48 return false;
49 }
50
51 return DoMarshallingSix(parcel);
52 }
53
DoMarshallingOne(Parcel & parcel) const54 bool SessionInfo::DoMarshallingOne(Parcel& parcel) const
55 {
56 if (sessionToken) {
57 if (!parcel.WriteBool(true) ||
58 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(sessionToken)) {
59 ABILITYBASE_LOGE("Write session token failed");
60 return false;
61 }
62 } else {
63 if (!parcel.WriteBool(false)) {
64 return false;
65 }
66 }
67
68 if (callerSession) {
69 if (!parcel.WriteBool(true) ||
70 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(callerSession)) {
71 ABILITYBASE_LOGE("Write caller session failed");
72 return false;
73 }
74 } else {
75 if (!parcel.WriteBool(false)) {
76 return false;
77 }
78 }
79
80 if (callerToken) {
81 if (!parcel.WriteBool(true) ||
82 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(callerToken)) {
83 ABILITYBASE_LOGE("Write caller token failed");
84 return false;
85 }
86 } else {
87 if (!parcel.WriteBool(false)) {
88 return false;
89 }
90 }
91
92 if (parentToken) {
93 if (!parcel.WriteBool(true) ||
94 !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(parentToken)) {
95 ABILITYBASE_LOGE("Write parent token failed");
96 return false;
97 }
98 } else {
99 if (!parcel.WriteBool(false)) {
100 return false;
101 }
102 }
103 return true;
104 }
105
DoMarshallingTwo(Parcel & parcel) const106 bool SessionInfo::DoMarshallingTwo(Parcel& parcel) const
107 {
108 if (!parcel.WriteString(identityToken)) {
109 ABILITYBASE_LOGE("Write identityToken failed");
110 return false;
111 }
112
113 if (!parcel.WriteUint32(parentWindowType)) {
114 ABILITYBASE_LOGE("Write parent window type failed.");
115 return false;
116 }
117
118 if (!parcel.WriteBool(hideStartWindow)) {
119 ABILITYBASE_LOGE("Write hideStartWindow failed.");
120 return false;
121 }
122
123 if (!parcel.WriteBool(shouldSkipKillInStartup)) {
124 ABILITYBASE_LOGE("Write shouldSkipKillInStartup failed.");
125 return false;
126 }
127
128 return true;
129 }
130
DoMarshallingThree(Parcel & parcel) const131 bool SessionInfo::DoMarshallingThree(Parcel& parcel) const
132 {
133 if (!parcel.WriteInt32(persistentId)) {
134 ABILITYBASE_LOGE("Write persistent id failed");
135 return false;
136 }
137
138 if (!parcel.WriteUint32(hostWindowId)) {
139 ABILITYBASE_LOGE("Write host window id failed");
140 return false;
141 }
142
143 if (!parcel.WriteUint32(realHostWindowId)) {
144 ABILITYBASE_LOGE("Write real host window id failed.");
145 return false;
146 }
147
148 if (!parcel.WriteUint32(static_cast<uint32_t>(state))) {
149 ABILITYBASE_LOGE("Write state failed");
150 return false;
151 }
152
153 if (!parcel.WriteInt32(resultCode)) {
154 ABILITYBASE_LOGE("Write resultCode failed");
155 return false;
156 }
157
158 if (!parcel.WriteInt32(requestCode)) {
159 ABILITYBASE_LOGE("Write requestCode failed");
160 return false;
161 }
162
163 if (!parcel.WriteString(errorReason)) {
164 ABILITYBASE_LOGE("Write errorReason failed");
165 return false;
166 }
167
168 if (!parcel.WriteInt32(errorCode)) {
169 ABILITYBASE_LOGE("Write errorCode failed");
170 return false;
171 }
172
173 if (!parcel.WriteInt64(uiAbilityId)) {
174 ABILITYBASE_LOGE("Write uiAbilityId failed");
175 return false;
176 }
177
178 if (!parcel.WriteParcelable(startSetting.get())) {
179 ABILITYBASE_LOGE("Write startSetting failed");
180 return false;
181 }
182
183 if (!parcel.WriteParcelable(processOptions.get())) {
184 ABILITYBASE_LOGE("Write processOptions failed");
185 return false;
186 }
187 return true;
188 }
189
DoMarshallingFour(Parcel & parcel) const190 bool SessionInfo::DoMarshallingFour(Parcel& parcel) const
191 {
192 if (!parcel.WriteBool(isNewWant)) {
193 ABILITYBASE_LOGE("Write isNewWant failed");
194 return false;
195 }
196
197 if (!parcel.WriteBool(isClearSession)) {
198 ABILITYBASE_LOGE("Write isClearSession failed");
199 return false;
200 }
201
202 if (!parcel.WriteUint32(callingTokenId)) {
203 ABILITYBASE_LOGE("Write callingTokenId failed");
204 return false;
205 }
206
207 if (!parcel.WriteBool(reuse)) {
208 ABILITYBASE_LOGE("Write reuse failed");
209 return false;
210 }
211
212 if (!parcel.WriteBool(canStartAbilityFromBackground)) {
213 ABILITYBASE_LOGE("Write canStartAbilityFromBackground failed.");
214 return false;
215 }
216
217 if (!parcel.WriteInt32(collaboratorType)) {
218 ABILITYBASE_LOGE("Write collaboratorType failed");
219 return false;
220 }
221
222 if (!parcel.WriteString(sessionName)) {
223 ABILITYBASE_LOGE("Write sessionName failed");
224 return false;
225 }
226
227 if (!parcel.WriteUint64(uiExtensionComponentId)) {
228 ABILITYBASE_LOGE("Write uiExtensionComponentId failed");
229 return false;
230 }
231
232 if (!parcel.WriteBool(isAsyncModalBinding)) {
233 ABILITYBASE_LOGE("Write isAsyncModalBinding failed");
234 return false;
235 }
236
237 if (!parcel.WriteUint32(static_cast<uint32_t>(uiExtensionUsage))) {
238 ABILITYBASE_LOGE("Write uiExtensionUsage failed");
239 return false;
240 }
241
242 if (!parcel.WriteBool(isAtomicService)) {
243 ABILITYBASE_LOGE("Write isAtomicService failed");
244 return false;
245 }
246
247 return true;
248 }
249
DoMarshallingFive(Parcel & parcel) const250 bool SessionInfo::DoMarshallingFive(Parcel& parcel) const
251 {
252 if (!parcel.WriteBool(isBackTransition)) {
253 ABILITYBASE_LOGE("Write isBackTransition failed.");
254 return false;
255 }
256
257 if (!parcel.WriteBool(isSkipErms)) {
258 ABILITYBASE_LOGE("Write isSkipErms failed.");
259 return false;
260 }
261
262 if (!parcel.WriteUint64(displayId)) {
263 ABILITYBASE_LOGE("Write displayId failed.");
264 return false;
265 }
266
267 if (!parcel.WriteFloat(density)) {
268 ABILITYBASE_LOGE("Write density failed.");
269 return false;
270 }
271
272 if (!parcel.WriteInt32(orientation)) {
273 ABILITYBASE_LOGE("Write orientation failed.");
274 return false;
275 }
276
277 if (!parcel.WriteBool(needClearInNotShowRecent)) {
278 ABILITYBASE_LOGE("Write needClearInNotShowRecent failed");
279 return false;
280 }
281
282 if (!parcel.WriteString(instanceKey)) {
283 ABILITYBASE_LOGE("Write instanceKey failed");
284 return false;
285 }
286
287 if (!parcel.WriteBool(isFromIcon)) {
288 ABILITYBASE_LOGE("Write isFromIcon failed");
289 return false;
290 }
291
292 if (!parcel.WriteInt32(requestId)) {
293 ABILITYBASE_LOGE("Write requestId failed");
294 return false;
295 }
296 return true;
297 }
298
DoMarshallingSix(Parcel & parcel) const299 bool SessionInfo::DoMarshallingSix(Parcel& parcel) const
300 {
301 if (!parcel.WriteInt32(isDensityFollowHost)) {
302 ABILITYBASE_LOGE("Write isDensityFollowHost failed");
303 return false;
304 }
305
306 if (!parcel.WriteString(specifiedFlag)) {
307 ABILITYBASE_LOGE("Write specifiedFlag failed");
308 return false;
309 }
310
311 if (!parcel.WriteBool(reuseDelegatorWindow)) {
312 ABILITYBASE_LOGE("Write reuseDelegatorWindow failed");
313 return false;
314 }
315
316 if (!parcel.WriteInt32(scenarios)) {
317 ABILITYBASE_LOGE("Write scenarios failed");
318 return false;
319 }
320
321 if (!parcel.WriteParcelable(windowCreateParams.get())) {
322 ABILITYBASE_LOGE("Write windowCreateParams failed");
323 return false;
324 }
325
326 // other params need place before want
327 if (!parcel.WriteParcelable(&want)) {
328 ABILITYBASE_LOGE("Write want failed");
329 return false;
330 }
331
332 if (!parcel.WriteParcelable(startWindowOption.get())) {
333 ABILITYBASE_LOGE("Write startWindowOption failed");
334 return false;
335 }
336
337 parcel.WriteInt32(supportWindowModes.size());
338 for (auto windowMode : supportWindowModes) {
339 parcel.WriteInt32(static_cast<int32_t>(windowMode));
340 }
341 return true;
342 }
343
Unmarshalling(Parcel & parcel)344 SessionInfo* SessionInfo::Unmarshalling(Parcel& parcel)
345 {
346 SessionInfo* info = new (std::nothrow) SessionInfo();
347 if (info == nullptr) {
348 ABILITYBASE_LOGE("new SessionInfo failed");
349 return nullptr;
350 }
351 if (parcel.ReadBool()) {
352 info->sessionToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
353 }
354
355 if (parcel.ReadBool()) {
356 info->callerSession = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
357 }
358
359 if (parcel.ReadBool()) {
360 info->callerToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
361 }
362
363 if (parcel.ReadBool()) {
364 info->parentToken = (static_cast<MessageParcel*>(&parcel))->ReadRemoteObject();
365 }
366 ReadParcelOne(info, parcel);
367 ReadParcelTwo(info, parcel);
368 return info;
369 }
370
ReadParcelOne(SessionInfo * info,Parcel & parcel)371 SessionInfo* SessionInfo::ReadParcelOne(SessionInfo* info, Parcel& parcel)
372 {
373 info->identityToken = parcel.ReadString();
374 info->parentWindowType = parcel.ReadUint32();
375 info->hideStartWindow = parcel.ReadBool();
376 info->shouldSkipKillInStartup = parcel.ReadBool();
377 info->persistentId = parcel.ReadInt32();
378 info->hostWindowId = parcel.ReadUint32();
379 info->realHostWindowId = parcel.ReadInt32();
380 info->state = static_cast<CallToState>(parcel.ReadUint32());
381 info->resultCode = parcel.ReadInt32();
382 info->requestCode = parcel.ReadInt32();
383 info->errorReason = parcel.ReadString();
384 info->errorCode = parcel.ReadInt32();
385 info->uiAbilityId = parcel.ReadInt64();
386 info->startSetting.reset(parcel.ReadParcelable<AbilityStartSetting>());
387 info->processOptions.reset(parcel.ReadParcelable<ProcessOptions>());
388 info->isNewWant = parcel.ReadBool();
389 info->isClearSession = parcel.ReadBool();
390 info->callingTokenId = parcel.ReadUint32();
391 info->reuse = parcel.ReadBool();
392 info->canStartAbilityFromBackground = parcel.ReadBool();
393 info->collaboratorType = parcel.ReadInt32();
394 info->sessionName = parcel.ReadString();
395 info->uiExtensionComponentId = parcel.ReadUint64();
396 info->isAsyncModalBinding = parcel.ReadBool();
397 info->uiExtensionUsage = static_cast<UIExtensionUsage>(parcel.ReadUint32());
398 info->isAtomicService = parcel.ReadBool();
399 info->isBackTransition = parcel.ReadBool();
400 info->isSkipErms = parcel.ReadBool();
401 info->displayId = parcel.ReadUint64();
402 info->density = parcel.ReadFloat();
403 info->orientation = parcel.ReadInt32();
404 info->needClearInNotShowRecent = parcel.ReadBool();
405 info->instanceKey = parcel.ReadString();
406 info->isFromIcon = parcel.ReadBool();
407 info->requestId = parcel.ReadInt32();
408 info->isDensityFollowHost = parcel.ReadBool();
409 info->specifiedFlag = parcel.ReadString();
410 info->reuseDelegatorWindow = parcel.ReadBool();
411 info->scenarios = parcel.ReadInt32();
412 info->windowCreateParams.reset(parcel.ReadParcelable<Rosen::WindowCreateParams>());
413
414 std::unique_ptr<Want> want(parcel.ReadParcelable<Want>());
415 if (want != nullptr) {
416 info->want = *want;
417 }
418 return info;
419 }
420
ReadParcelTwo(SessionInfo * info,Parcel & parcel)421 SessionInfo* SessionInfo::ReadParcelTwo(SessionInfo* info, Parcel& parcel)
422 {
423 info->startWindowOption.reset(parcel.ReadParcelable<StartWindowOption>());
424 auto size = parcel.ReadInt32();
425 if (size <= MAX_SUPPOPRT_WINDOW_MODES_SIZE) {
426 for (int i = 0; i < size; i++) {
427 info->supportWindowModes.emplace_back(AppExecFwk::SupportWindowMode(parcel.ReadInt32()));
428 }
429 }
430 return info;
431 }
432 } // namespace AAFwk
433 } // namespace OHOS
434