Debian Codegraph @

core/java/android/window/WindowContainerTransaction.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.window;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.TestApi;
22 import android.app.PendingIntent;
23 import android.app.WindowConfiguration;
24 import android.content.Intent;
25 import android.content.pm.ActivityInfo;
26 import android.content.pm.ShortcutInfo;
27 import android.content.res.Configuration;
28 import android.graphics.Rect;
29 import android.os.Bundle;
30 import android.os.IBinder;
31 import android.os.Parcel;
32 import android.os.Parcelable;
33 import android.util.ArrayMap;
34 import android.view.InsetsState;
35 import android.view.SurfaceControl;
36
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Objects;
42
43 /**
44 * Represents a collection of operations on some WindowContainers that should be applied all at
45 * once.
46 *
47 * @hide
48 */
49 @TestApi
50 public final class WindowContainerTransaction implements Parcelable {
51 private final ArrayMap<IBinder, Change> mChanges = new ArrayMap<>();
52
53 // Flat list because re-order operations are order-dependent
54 private final ArrayList<HierarchyOp> mHierarchyOps = new ArrayList<>();
55
56 @Nullable
57 private IBinder mErrorCallbackToken;
58
59 @Nullable
60 private ITaskFragmentOrganizer mTaskFragmentOrganizer;
61
62 public WindowContainerTransaction() {}
63
64 private WindowContainerTransaction(Parcel in) {
65 in.readMap(mChanges, null /* loader */);
66 in.readTypedList(mHierarchyOps, HierarchyOp.CREATOR);
67 mErrorCallbackToken = in.readStrongBinder();
68 mTaskFragmentOrganizer = ITaskFragmentOrganizer.Stub.asInterface(in.readStrongBinder());
69 }
70
71 private Change getOrCreateChange(IBinder token) {
72 Change out = mChanges.get(token);
73 if (out == null) {
74 out = new Change();
75 mChanges.put(token, out);
76 }
77 return out;
78 }
79
80 /**
81 * Resize a container.
82 */
83 @NonNull
84 public WindowContainerTransaction setBounds(
85 @NonNull WindowContainerToken container,@NonNull Rect bounds) {
86 Change chg = getOrCreateChange(container.asBinder());
87 chg.mConfiguration.windowConfiguration.setBounds(bounds);
88 chg.mConfigSetMask |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
89 chg.mWindowSetMask |= WindowConfiguration.WINDOW_CONFIG_BOUNDS;
90 return this;
91 }
92
93 /**
94 * Resize a container's app bounds. This is the bounds used to report appWidth/Height to an
95 * app's DisplayInfo. It is derived by subtracting the overlapping portion of the navbar from
96 * the full bounds.
97 */
98 @NonNull
99 public WindowContainerTransaction setAppBounds(
100 @NonNull WindowContainerToken container,@NonNull Rect appBounds) {
101 Change chg = getOrCreateChange(container.asBinder());
102 chg.mConfiguration.windowConfiguration.setAppBounds(appBounds);
103 chg.mConfigSetMask |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
104 chg.mWindowSetMask |= WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS;
105 return this;
106 }
107
108 /**
109 * Resize a container's configuration size. The configuration size is what gets reported to the
110 * app via screenWidth/HeightDp and influences which resources get loaded. This size is
111 * derived by subtracting the overlapping portions of both the statusbar and the navbar from
112 * the full bounds.
113 */
114 @NonNull
115 public WindowContainerTransaction setScreenSizeDp(
116 @NonNull WindowContainerToken container, int w, int h) {
117 Change chg = getOrCreateChange(container.asBinder());
118 chg.mConfiguration.screenWidthDp = w;
119 chg.mConfiguration.screenHeightDp = h;
120 chg.mConfigSetMask |= ActivityInfo.CONFIG_SCREEN_SIZE;
121 return this;
122 }
123
124 /**
125 * Notify {@link com.android.server.wm.PinnedTaskController} that the picture-in-picture task
126 * has finished the enter animation with the given bounds.
127 */
128 @NonNull
129 public WindowContainerTransaction scheduleFinishEnterPip(
130 @NonNull WindowContainerToken container,@NonNull Rect bounds) {
131 Change chg = getOrCreateChange(container.asBinder());
132 chg.mPinnedBounds = new Rect(bounds);
133 chg.mChangeMask |= Change.CHANGE_PIP_CALLBACK;
134
135 return this;
136 }
137
138 /**
139 * Send a SurfaceControl transaction to the server, which the server will apply in sync with
140 * the next bounds change. As this uses deferred transaction and not BLAST it is only
141 * able to sync with a single window, and the first visible window in this hierarchy of type
142 * BASE_APPLICATION to resize will be used. If there are bound changes included in this
143 * WindowContainer transaction (from setBounds or scheduleFinishEnterPip), the SurfaceControl
144 * transaction will be synced with those bounds. If there are no changes, then
145 * the SurfaceControl transaction will be synced with the next bounds change. This means
146 * that you can call this, apply the WindowContainer transaction, and then later call
147 * dismissPip() to achieve synchronization.
148 */
149 @NonNull
150 public WindowContainerTransaction setBoundsChangeTransaction(
151 @NonNull WindowContainerToken container,@NonNull SurfaceControl.Transaction t) {
152 Change chg = getOrCreateChange(container.asBinder());
153 chg.mBoundsChangeTransaction = t;
154 chg.mChangeMask |= Change.CHANGE_BOUNDS_TRANSACTION;
155 return this;
156 }
157
158 /**
159 * Like {@link #setBoundsChangeTransaction} but instead queues up a setPosition/WindowCrop
160 * on a container's surface control. This is useful when a boundsChangeTransaction needs to be
161 * queued up on a Task that won't be organized until the end of this window-container
162 * transaction.
163 *
164 * This requires that, at the end of this transaction, `task` will be organized; otherwise
165 * the server will throw an IllegalArgumentException.
166 *
167 * WARNING: Use this carefully. Whatever is set here should match the expected bounds after
168 * the transaction completes since it will likely be replaced by it. This call is
169 * intended to pre-emptively set bounds on a surface in sync with a buffer when
170 * otherwise the new bounds and the new buffer would update on different frames.
171 *
172 * TODO(b/134365562): remove once TaskOrg drives full-screen or BLAST is enabled.
173 *
174 * @hide
175 */
176 @NonNull
177 public WindowContainerTransaction setBoundsChangeTransaction(
178 @NonNull WindowContainerToken task, @NonNull Rect surfaceBounds) {
179 Change chg = getOrCreateChange(task.asBinder());
180 if (chg.mBoundsChangeSurfaceBounds == null) {
181 chg.mBoundsChangeSurfaceBounds = new Rect();
182 }
183 chg.mBoundsChangeSurfaceBounds.set(surfaceBounds);
184 chg.mChangeMask |= Change.CHANGE_BOUNDS_TRANSACTION_RECT;
185 return this;
186 }
187
188 /**
189 * Set the windowing mode of children of a given root task, without changing
190 * the windowing mode of the Task itself. This can be used during transitions
191 * for example to make the activity render it's fullscreen configuration
192 * while the Task is still in PIP, so you can complete the animation.
193 *
194 * TODO(b/134365562): Can be removed once TaskOrg drives full-screen
195 */
196 @NonNull
197 public WindowContainerTransaction setActivityWindowingMode(
198 @NonNull WindowContainerToken container, int windowingMode) {
199 Change chg = getOrCreateChange(container.asBinder());
200 chg.mActivityWindowingMode = windowingMode;
201 return this;
202 }
203
204 /**
205 * Sets the windowing mode of the given container.
206 */
207 @NonNull
208 public WindowContainerTransaction setWindowingMode(
209 @NonNull WindowContainerToken container, int windowingMode) {
210 Change chg = getOrCreateChange(container.asBinder());
211 chg.mWindowingMode = windowingMode;
212 return this;
213 }
214
215 /**
216 * Sets whether a container or any of its children can be focusable. When {@code false}, no
217 * child can be focused; however, when {@code true}, it is still possible for children to be
218 * non-focusable due to WM policy.
219 */
220 @NonNull
221 public WindowContainerTransaction setFocusable(
222 @NonNull WindowContainerToken container, boolean focusable) {
223 Change chg = getOrCreateChange(container.asBinder());
224 chg.mFocusable = focusable;
225 chg.mChangeMask |= Change.CHANGE_FOCUSABLE;
226 return this;
227 }
228
229 /**
230 * Sets whether a container or its children should be hidden. When {@code false}, the existing
231 * visibility of the container applies, but when {@code true} the container will be forced
232 * to be hidden.
233 */
234 @NonNull
235 public WindowContainerTransaction setHidden(
236 @NonNull WindowContainerToken container, boolean hidden) {
237 Change chg = getOrCreateChange(container.asBinder());
238 chg.mHidden = hidden;
239 chg.mChangeMask |= Change.CHANGE_HIDDEN;
240 return this;
241 }
242
243 /**
244 * Set the smallestScreenWidth of a container.
245 */
246 @NonNull
247 public WindowContainerTransaction setSmallestScreenWidthDp(
248 @NonNull WindowContainerToken container, int widthDp) {
249 Change cfg = getOrCreateChange(container.asBinder());
250 cfg.mConfiguration.smallestScreenWidthDp = widthDp;
251 cfg.mConfigSetMask |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
252 return this;
253 }
254
255 /**
256 * Sets whether a container should ignore the orientation request from apps and windows below
257 * it. It currently only applies to {@link com.android.server.wm.DisplayArea}. When
258 * {@code false}, it may rotate based on the orientation request; When {@code true}, it can
259 * never specify orientation, but shows the fixed-orientation apps below it in the letterbox.
260 * @hide
261 */
262 @NonNull
263 public WindowContainerTransaction setIgnoreOrientationRequest(
264 @NonNull WindowContainerToken container, boolean ignoreOrientationRequest) {
265 Change chg = getOrCreateChange(container.asBinder());
266 chg.mIgnoreOrientationRequest = ignoreOrientationRequest;
267 chg.mChangeMask |= Change.CHANGE_IGNORE_ORIENTATION_REQUEST;
268 return this;
269 }
270
271 /**
272 * Sets whether a task should be translucent. When {@code false}, the existing translucent of
273 * the task applies, but when {@code true} the task will be forced to be translucent.
274 * @hide
275 */
276 @NonNull
277 public WindowContainerTransaction setForceTranslucent(
278 @NonNull WindowContainerToken container, boolean forceTranslucent) {
279 Change chg = getOrCreateChange(container.asBinder());
280 chg.mForceTranslucent = forceTranslucent;
281 chg.mChangeMask |= Change.CHANGE_FORCE_TRANSLUCENT;
282 return this;
283 }
284
285 /**
286 * Used in conjunction with a shell-transition call (usually finishTransition). This is
287 * basically a message to the transition system that a particular task should NOT go into
288 * PIP even though it normally would. This is to deal with some edge-case situations where
289 * Recents will "commit" the transition to go home, but then not actually go-home.
290 * @hide
291 */
292 @NonNull
293 public WindowContainerTransaction setDoNotPip(@NonNull WindowContainerToken container) {
294 Change chg = getOrCreateChange(container.asBinder());
295 chg.mChangeMask |= Change.CHANGE_FORCE_NO_PIP;
296 return this;
297 }
298
299 /**
300 * Reparents a container into another one. The effect of a {@code null} parent can vary. For
301 * example, reparenting a stack to {@code null} will reparent it to its display.
302 *
303 * @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
304 * the bottom.
305 */
306 @NonNull
307 public WindowContainerTransaction reparent(@NonNull WindowContainerToken child,
308 @Nullable WindowContainerToken parent, boolean onTop) {
309 mHierarchyOps.add(HierarchyOp.createForReparent(child.asBinder(),
310 parent == null ? null : parent.asBinder(),
311 onTop));
312 return this;
313 }
314
315 /**
316 * Reorders a container within its parent.
317 *
318 * @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
319 * the bottom.
320 */
321 @NonNull
322 public WindowContainerTransaction reorder(@NonNull WindowContainerToken child, boolean onTop) {
323 mHierarchyOps.add(HierarchyOp.createForReorder(child.asBinder(), onTop));
324 return this;
325 }
326
327 /**
328 * Reparent's all children tasks or the top task of {@param currentParent} in the specified
329 * {@param windowingMode} and {@param activityType} to {@param newParent} in their current
330 * z-order.
331 *
332 * @param currentParent of the tasks to perform the operation no.
333 * {@code null} will perform the operation on the display.
334 * @param newParent for the tasks. {@code null} will perform the operation on the display.
335 * @param windowingModes of the tasks to reparent.
336 * @param activityTypes of the tasks to reparent.
337 * @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
338 * the bottom.
339 * @param reparentTopOnly When {@code true}, only reparent the top task which fit windowingModes
340 * and activityTypes.
341 * @hide
342 */
343 @NonNull
344 public WindowContainerTransaction reparentTasks(@Nullable WindowContainerToken currentParent,
345 @Nullable WindowContainerToken newParent, @Nullable int[] windowingModes,
346 @Nullable int[] activityTypes, boolean onTop, boolean reparentTopOnly) {
347 mHierarchyOps.add(HierarchyOp.createForChildrenTasksReparent(
348 currentParent != null ? currentParent.asBinder() : null,
349 newParent != null ? newParent.asBinder() : null,
350 windowingModes,
351 activityTypes,
352 onTop,
353 reparentTopOnly));
354 return this;
355 }
356
357 /**
358 * Reparent's all children tasks of {@param currentParent} in the specified
359 * {@param windowingMode} and {@param activityType} to {@param newParent} in their current
360 * z-order.
361 *
362 * @param currentParent of the tasks to perform the operation no.
363 * {@code null} will perform the operation on the display.
364 * @param newParent for the tasks. {@code null} will perform the operation on the display.
365 * @param windowingModes of the tasks to reparent. {@code null} ignore this attribute when
366 * perform the operation.
367 * @param activityTypes of the tasks to reparent. {@code null} ignore this attribute when
368 * perform the operation.
369 * @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
370 * the bottom.
371 */
372 @NonNull
373 public WindowContainerTransaction reparentTasks(@Nullable WindowContainerToken currentParent,
374 @Nullable WindowContainerToken newParent, @Nullable int[] windowingModes,
375 @Nullable int[] activityTypes, boolean onTop) {
376 return reparentTasks(currentParent, newParent, windowingModes, activityTypes, onTop,
377 false /* reparentTopOnly */);
378 }
379
380 /**
381 * Sets whether a container should be the launch root for the specified windowing mode and
382 * activity type. This currently only applies to Task containers created by organizer.
383 */
384 @NonNull
385 public WindowContainerTransaction setLaunchRoot(@NonNull WindowContainerToken container,
386 @Nullable int[] windowingModes, @Nullable int[] activityTypes) {
387 mHierarchyOps.add(HierarchyOp.createForSetLaunchRoot(
388 container.asBinder(),
389 windowingModes,
390 activityTypes));
391 return this;
392 }
393
394 /**
395 * Sets to containers adjacent to each other. Containers below two visible adjacent roots will
396 * be made invisible. This currently only applies to TaskFragment containers created by
397 * organizer.
398 * @param root1 the first root.
399 * @param root2 the second root.
400 */
401 @NonNull
402 public WindowContainerTransaction setAdjacentRoots(
403 @NonNull WindowContainerToken root1, @NonNull WindowContainerToken root2) {
404 mHierarchyOps.add(HierarchyOp.createForAdjacentRoots(
405 root1.asBinder(),
406 root2.asBinder()));
407 return this;
408 }
409
410 /**
411 * This is temp function for compatible with old cts tests suite and it equal to
412 * {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken).
413 * @deprecated should use {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken)}
414 */
415 @Deprecated
416 @NonNull
417 public WindowContainerTransaction setAdjacentRoots(
418 @NonNull WindowContainerToken root1, @NonNull WindowContainerToken root2,
419 boolean moveTogether) {
420 return setAdjacentRoots(root1, root2);
421 }
422
423 /**
424 * Sets the container as launch adjacent flag root. Task starting with
425 * {@link FLAG_ACTIVITY_LAUNCH_ADJACENT} will be launching to.
426 */
427 @NonNull
428 public WindowContainerTransaction setLaunchAdjacentFlagRoot(
429 @NonNull WindowContainerToken container) {
430 mHierarchyOps.add(HierarchyOp.createForSetLaunchAdjacentFlagRoot(container.asBinder(),
431 false /* clearRoot */));
432 return this;
433 }
434
435 /**
436 * Clears launch adjacent flag root for the display area of passing container.
437 */
438 @NonNull
439 public WindowContainerTransaction clearLaunchAdjacentFlagRoot(
440 @NonNull WindowContainerToken container) {
441 mHierarchyOps.add(HierarchyOp.createForSetLaunchAdjacentFlagRoot(container.asBinder(),
442 true /* clearRoot */));
443 return this;
444 }
445
446 /**
447 * Starts a task by id. The task is expected to already exist (eg. as a recent task).
448 * @param taskId Id of task to start.
449 * @param options bundle containing ActivityOptions for the task's top activity.
450 * @hide
451 */
452 @NonNull
453 public WindowContainerTransaction startTask(int taskId, @Nullable Bundle options) {
454 mHierarchyOps.add(HierarchyOp.createForTaskLaunch(taskId, options));
455 return this;
456 }
457
458 /**
459 * Finds and removes a task and its children using its container token. The task is removed
460 * from recents.
461 * @param containerToken ContainerToken of Task to be removed
462 */
463 @NonNull
464 public WindowContainerTransaction removeTask(@NonNull WindowContainerToken containerToken) {
465 mHierarchyOps.add(HierarchyOp.createForRemoveTask(containerToken.asBinder()));
466 return this;
467 }
468
469 /**
470 * Sets whether a container is being drag-resized.
471 * When {@code true}, the client will reuse a single (larger) surface size to avoid
472 * continuous allocations on every size change.
473 *
474 * @param container WindowContainerToken of the task that changed its drag resizing state
475 * @hide
476 */
477 @NonNull
478 public WindowContainerTransaction setDragResizing(@NonNull WindowContainerToken container,
479 boolean dragResizing) {
480 final Change change = getOrCreateChange(container.asBinder());
481 change.mChangeMask |= Change.CHANGE_DRAG_RESIZING;
482 change.mDragResizing = dragResizing;
483 return this;
484 }
485
486 /**
487 * Sends a pending intent in sync.
488 * @param sender The PendingIntent sender.
489 * @param intent The fillIn intent to patch over the sender's base intent.
490 * @param options bundle containing ActivityOptions for the task's top activity.
491 * @hide
492 */
493 @NonNull
494 public WindowContainerTransaction sendPendingIntent(PendingIntent sender, Intent intent,
495 @Nullable Bundle options) {
496 mHierarchyOps.add(new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_PENDING_INTENT)
497 .setLaunchOptions(options)
498 .setPendingIntent(sender)
499 .setActivityIntent(intent)
500 .build());
501 return this;
502 }
503
504 /**
505 * Starts activity(s) from a shortcut.
506 * @param callingPackage The package launching the shortcut.
507 * @param shortcutInfo Information about the shortcut to start
508 * @param options bundle containing ActivityOptions for the task's top activity.
509 * @hide
510 */
511 @NonNull
512 public WindowContainerTransaction startShortcut(@NonNull String callingPackage,
513 @NonNull ShortcutInfo shortcutInfo, @Nullable Bundle options) {
514 mHierarchyOps.add(HierarchyOp.createForStartShortcut(
515 callingPackage, shortcutInfo, options));
516 return this;
517 }
518
519 /**
520 * Creates a new TaskFragment with the given options.
521 * @param taskFragmentOptions the options used to create the TaskFragment.
522 */
523 @NonNull
524 public WindowContainerTransaction createTaskFragment(
525 @NonNull TaskFragmentCreationParams taskFragmentOptions) {
526 final HierarchyOp hierarchyOp =
527 new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT)
528 .setTaskFragmentCreationOptions(taskFragmentOptions)
529 .build();
530 mHierarchyOps.add(hierarchyOp);
531 return this;
532 }
533
534 /**
535 * Deletes an existing TaskFragment. Any remaining activities below it will be destroyed.
536 * @param taskFragment the TaskFragment to be removed.
537 */
538 @NonNull
539 public WindowContainerTransaction deleteTaskFragment(
540 @NonNull WindowContainerToken taskFragment) {
541 final HierarchyOp hierarchyOp =
542 new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT)
543 .setContainer(taskFragment.asBinder())
544 .build();
545 mHierarchyOps.add(hierarchyOp);
546 return this;
547 }
548
549 /**
550 * Starts an activity in the TaskFragment.
551 * @param fragmentToken client assigned unique token to create TaskFragment with specified in
552 * {@link TaskFragmentCreationParams#getFragmentToken()}.
553 * @param callerToken the activity token that initialized the activity launch.
554 * @param activityIntent intent to start the activity.
555 * @param activityOptions ActivityOptions to start the activity with.
556 * @see android.content.Context#startActivity(Intent, Bundle).
557 */
558 @NonNull
559 public WindowContainerTransaction startActivityInTaskFragment(
560 @NonNull IBinder fragmentToken, @NonNull IBinder callerToken,
561 @NonNull Intent activityIntent, @Nullable Bundle activityOptions) {
562 final HierarchyOp hierarchyOp =
563 new HierarchyOp.Builder(
564 HierarchyOp.HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT)
565 .setContainer(fragmentToken)
566 .setReparentContainer(callerToken)
567 .setActivityIntent(activityIntent)
568 .setLaunchOptions(activityOptions)
569 .build();
570 mHierarchyOps.add(hierarchyOp);
571 return this;
572 }
573
574 /**
575 * Moves an activity into the TaskFragment.
576 * @param fragmentToken client assigned unique token to create TaskFragment with specified in
577 * {@link TaskFragmentCreationParams#getFragmentToken()}.
578 * @param activityToken activity to be reparented.
579 */
580 @NonNull
581 public WindowContainerTransaction reparentActivityToTaskFragment(
582 @NonNull IBinder fragmentToken, @NonNull IBinder activityToken) {
583 final HierarchyOp hierarchyOp =
584 new HierarchyOp.Builder(
585 HierarchyOp.HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT)
586 .setReparentContainer(fragmentToken)
587 .setContainer(activityToken)
588 .build();
589 mHierarchyOps.add(hierarchyOp);
590 return this;
591 }
592
593 /**
594 * Reparents all children of one TaskFragment to another.
595 * @param oldParent children of this TaskFragment will be reparented.
596 * @param newParent the new parent TaskFragment to move the children to. If {@code null}, the
597 * children will be moved to the leaf Task.
598 */
599 @NonNull
600 public WindowContainerTransaction reparentChildren(
601 @NonNull WindowContainerToken oldParent,
602 @Nullable WindowContainerToken newParent) {
603 final HierarchyOp hierarchyOp =
604 new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_REPARENT_CHILDREN)
605 .setContainer(oldParent.asBinder())
606 .setReparentContainer(newParent != null ? newParent.asBinder() : null)
607 .build();
608 mHierarchyOps.add(hierarchyOp);
609 return this;
610 }
611
612 /**
613 * Sets to TaskFragments adjacent to each other. Containers below two visible adjacent
614 * TaskFragments will be made invisible. This is similar to
615 * {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken)}, but can be used with
616 * fragmentTokens when that TaskFragments haven't been created (but will be created in the same
617 * {@link WindowContainerTransaction}).
618 * To reset it, pass {@code null} for {@code fragmentToken2}.
619 * @param fragmentToken1 client assigned unique token to create TaskFragment with specified
620 * in {@link TaskFragmentCreationParams#getFragmentToken()}.
621 * @param fragmentToken2 client assigned unique token to create TaskFragment with specified
622 * in {@link TaskFragmentCreationParams#getFragmentToken()}. If it is
623 * {@code null}, the transaction will reset the adjacent TaskFragment.
624 */
625 @NonNull
626 public WindowContainerTransaction setAdjacentTaskFragments(
627 @NonNull IBinder fragmentToken1, @Nullable IBinder fragmentToken2,
628 @Nullable TaskFragmentAdjacentParams params) {
629 final HierarchyOp hierarchyOp =
630 new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS)
631 .setContainer(fragmentToken1)
632 .setReparentContainer(fragmentToken2)
633 .setLaunchOptions(params != null ? params.toBundle() : null)
634 .build();
635 mHierarchyOps.add(hierarchyOp);
636 return this;
637 }
638
639 /**
640 * If `container` was brought to front as a transient-launch (eg. recents), this will reorder
641 * the container back to where it was prior to the transient-launch. This way if a transient
642 * launch is "aborted", the z-ordering of containers in WM should be restored to before the
643 * launch.
644 * @hide
645 */
646 @NonNull
647 public WindowContainerTransaction restoreTransientOrder(
648 @NonNull WindowContainerToken container) {
649 final HierarchyOp hierarchyOp =
650 new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER)
651 .setContainer(container.asBinder())
652 .build();
653 mHierarchyOps.add(hierarchyOp);
654 return this;
655 }
656
657 /**
658 * Adds a given {@code Rect} as a rect insets provider on the {@code receiverWindowContainer}.
659 * This will trigger a change of insets for all the children in the subtree of
660 * {@code receiverWindowContainer}.
661 *
662 * @param receiverWindowContainer the window container which the insets provider need to be
663 * added to
664 * @param insetsProviderFrame the frame that will be added as Insets provider
665 * @param insetsTypes types of insets the rect provides
666 * @hide
667 */
668 @NonNull
669 public WindowContainerTransaction addRectInsetsProvider(
670 @NonNull WindowContainerToken receiverWindowContainer,
671 @NonNull Rect insetsProviderFrame,
672 @InsetsState.InternalInsetsType int[] insetsTypes) {
673 final HierarchyOp hierarchyOp =
674 new HierarchyOp.Builder(
675 HierarchyOp.HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER)
676 .setContainer(receiverWindowContainer.asBinder())
677 .setInsetsProviderFrame(insetsProviderFrame)
678 .setInsetsTypes(insetsTypes)
679 .build();
680 mHierarchyOps.add(hierarchyOp);
681 return this;
682 }
683
684 /**
685 * Removes the insets provider for the given types from the
686 * {@code receiverWindowContainer}. This will trigger a change of insets for all the children
687 * in the subtree of {@code receiverWindowContainer}.
688 *
689 * @param receiverWindowContainer the window container which the insets-override-provider has
690 * to be removed from
691 * @param insetsTypes types of insets that have to be removed
692 * @hide
693 */
694 @NonNull
695 public WindowContainerTransaction removeInsetsProvider(
696 @NonNull WindowContainerToken receiverWindowContainer,
697 @InsetsState.InternalInsetsType int[] insetsTypes) {
698 final HierarchyOp hierarchyOp =
699 new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER)
700 .setContainer(receiverWindowContainer.asBinder())
701 .setInsetsTypes(insetsTypes)
702 .build();
703 mHierarchyOps.add(hierarchyOp);
704 return this;
705 }
706
707 /**
708 * Requests focus on the top running Activity in the given TaskFragment. This will only take
709 * effect if there is no focus, or if the current focus is in the same Task as the requested
710 * TaskFragment.
711 * @param fragmentToken client assigned unique token to create TaskFragment with specified in
712 * {@link TaskFragmentCreationParams#getFragmentToken()}.
713 */
714 @NonNull
715 public WindowContainerTransaction requestFocusOnTaskFragment(@NonNull IBinder fragmentToken) {
716 final HierarchyOp hierarchyOp =
717 new HierarchyOp.Builder(
718 HierarchyOp.HIERARCHY_OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT)
719 .setContainer(fragmentToken)
720 .build();
721 mHierarchyOps.add(hierarchyOp);
722 return this;
723 }
724
725 /**
726 * Finishes the Activity.
727 * Comparing to directly calling {@link android.app.Activity#finish()}, calling this can make
728 * sure the finishing happens in the same transaction with other operations.
729 * @param activityToken activity to be finished.
730 */
731 @NonNull
732 public WindowContainerTransaction finishActivity(@NonNull IBinder activityToken) {
733 final HierarchyOp hierarchyOp =
734 new HierarchyOp.Builder(
735 HierarchyOp.HIERARCHY_OP_TYPE_FINISH_ACTIVITY)
736 .setContainer(activityToken)
737 .build();
738 mHierarchyOps.add(hierarchyOp);
739 return this;
740 }
741
742 /**
743 * Sets the TaskFragment {@code container} to have a companion TaskFragment {@code companion}.
744 * This indicates that the organizer will remove the TaskFragment when the companion
745 * TaskFragment is removed.
746 *
747 * @param container the TaskFragment container
748 * @param companion the companion TaskFragment. If it is {@code null}, the transaction will
749 * reset the companion TaskFragment.
750 * @hide
751 */
752 @NonNull
753 public WindowContainerTransaction setCompanionTaskFragment(@NonNull IBinder container,
754 @Nullable IBinder companion) {
755 final HierarchyOp hierarchyOp =
756 new HierarchyOp.Builder(
757 HierarchyOp.HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT)
758 .setContainer(container)
759 .setReparentContainer(companion)
760 .build();
761 mHierarchyOps.add(hierarchyOp);
762 return this;
763 }
764
765 /**
766 * Sets the {@link TaskFragmentOperation} to apply to the given TaskFragment.
767 *
768 * @param fragmentToken client assigned unique token to create TaskFragment with specified in
769 * {@link TaskFragmentCreationParams#getFragmentToken()}.
770 * @param taskFragmentOperation the {@link TaskFragmentOperation} to apply to the given
771 * TaskFramgent.
772 * @hide
773 */
774 @NonNull
775 public WindowContainerTransaction setTaskFragmentOperation(@NonNull IBinder fragmentToken,
776 @NonNull TaskFragmentOperation taskFragmentOperation) {
777 Objects.requireNonNull(fragmentToken);
778 Objects.requireNonNull(taskFragmentOperation);
779 final HierarchyOp hierarchyOp =
780 new HierarchyOp.Builder(
781 HierarchyOp.HIERARCHY_OP_TYPE_SET_TASK_FRAGMENT_OPERATION)
782 .setContainer(fragmentToken)
783 .setTaskFragmentOperation(taskFragmentOperation)
784 .build();
785 mHierarchyOps.add(hierarchyOp);
786 return this;
787 }
788
789 /**
790 * Sets/removes the always on top flag for this {@code windowContainer}. See
791 * {@link com.android.server.wm.ConfigurationContainer#setAlwaysOnTop(boolean)}.
792 * Please note that this method is only intended to be used for a
793 * {@link com.android.server.wm.DisplayArea}.
794 *
795 * <p>
796 * Setting always on top to {@code True} will also make the {@code windowContainer} to move
797 * to the top.
798 * </p>
799 * <p>
800 * Setting always on top to {@code False} will make this {@code windowContainer} to move
801 * below the other always on top sibling containers.
802 * </p>
803 *
804 * @param windowContainer the container which the flag need to be updated for.
805 * @param alwaysOnTop denotes whether or not always on top flag should be set.
806 * @hide
807 */
808 @NonNull
809 public WindowContainerTransaction setAlwaysOnTop(
810 @NonNull WindowContainerToken windowContainer,
811 boolean alwaysOnTop) {
812 final HierarchyOp hierarchyOp =
813 new HierarchyOp.Builder(
814 HierarchyOp.HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP)
815 .setContainer(windowContainer.asBinder())
816 .setAlwaysOnTop(alwaysOnTop)
817 .build();
818 mHierarchyOps.add(hierarchyOp);
819 return this;
820 }
821
822 /**
823 * When this {@link WindowContainerTransaction} failed to finish on the server side, it will
824 * trigger callback with this {@param errorCallbackToken}.
825 * @param errorCallbackToken client provided token that will be passed back as parameter in
826 * the callback if there is an error on the server side.
827 * @see ITaskFragmentOrganizer#onTaskFragmentError
828 */
829 @NonNull
830 public WindowContainerTransaction setErrorCallbackToken(@NonNull IBinder errorCallbackToken) {
831 if (mErrorCallbackToken != null) {
832 throw new IllegalStateException("Can't set multiple error token for one transaction.");
833 }
834 mErrorCallbackToken = errorCallbackToken;
835 return this;
836 }
837
838 /**
839 * Sets the {@link TaskFragmentOrganizer} that applies this {@link WindowContainerTransaction}.
840 * When this is set, the server side will not check for the permission of
841 * {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}, but will ensure this WCT only
842 * contains operations that are allowed for this organizer, such as modifying TaskFragments that
843 * are organized by this organizer.
844 * @hide
845 */
846 @NonNull
847 public WindowContainerTransaction setTaskFragmentOrganizer(
848 @NonNull ITaskFragmentOrganizer organizer) {
849 mTaskFragmentOrganizer = organizer;
850 return this;
851 }
852
853 /**
854 * Sets/removes the reparent leaf task flag for this {@code windowContainer}.
855 * When this is set, the server side will try to reparent the leaf task to task display area
856 * if there is an existing activity in history during the activity launch. This operation only
857 * support on the organized root task.
858 * @hide
859 */
860 @NonNull
861 public WindowContainerTransaction setReparentLeafTaskIfRelaunch(
862 @NonNull WindowContainerToken windowContainer, boolean reparentLeafTaskIfRelaunch) {
863 final HierarchyOp hierarchyOp =
864 new HierarchyOp.Builder(
865 HierarchyOp.HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH)
866 .setContainer(windowContainer.asBinder())
867 .setReparentLeafTaskIfRelaunch(reparentLeafTaskIfRelaunch)
868 .build();
869 mHierarchyOps.add(hierarchyOp);
870 return this;
871 }
872
873 /**
874 * Merges another WCT into this one.
875 * @param transfer When true, this will transfer everything from other potentially leaving
876 * other in an unusable state. When false, other is left alone, but
877 * SurfaceFlinger Transactions will not be merged.
878 * @hide
879 */
880 public void merge(WindowContainerTransaction other, boolean transfer) {
881 for (int i = 0, n = other.mChanges.size(); i < n; ++i) {
882 final IBinder key = other.mChanges.keyAt(i);
883 Change existing = mChanges.get(key);
884 if (existing == null) {
885 existing = new Change();
886 mChanges.put(key, existing);
887 }
888 existing.merge(other.mChanges.valueAt(i), transfer);
889 }
890 for (int i = 0, n = other.mHierarchyOps.size(); i < n; ++i) {
891 mHierarchyOps.add(transfer ? other.mHierarchyOps.get(i)
892 : new HierarchyOp(other.mHierarchyOps.get(i)));
893 }
894 if (mErrorCallbackToken != null && other.mErrorCallbackToken != null && mErrorCallbackToken
895 != other.mErrorCallbackToken) {
896 throw new IllegalArgumentException("Can't merge two WCTs with different error token");
897 }
898 final IBinder taskFragmentOrganizerAsBinder = mTaskFragmentOrganizer != null
899 ? mTaskFragmentOrganizer.asBinder()
900 : null;
901 final IBinder otherTaskFragmentOrganizerAsBinder = other.mTaskFragmentOrganizer != null
902 ? other.mTaskFragmentOrganizer.asBinder()
903 : null;
904 if (!Objects.equals(taskFragmentOrganizerAsBinder, otherTaskFragmentOrganizerAsBinder)) {
905 throw new IllegalArgumentException(
906 "Can't merge two WCTs from different TaskFragmentOrganizers");
907 }
908 mErrorCallbackToken = mErrorCallbackToken != null
909 ? mErrorCallbackToken
910 : other.mErrorCallbackToken;
911 }
912
913 /** @hide */
914 public boolean isEmpty() {
915 return mChanges.isEmpty() && mHierarchyOps.isEmpty();
916 }
917
918 /** @hide */
919 public Map<IBinder, Change> getChanges() {
920 return mChanges;
921 }
922
923 /** @hide */
924 public List<HierarchyOp> getHierarchyOps() {
925 return mHierarchyOps;
926 }
927
928 /** @hide */
929 @Nullable
930 public IBinder getErrorCallbackToken() {
931 return mErrorCallbackToken;
932 }
933
934 /** @hide */
935 @Nullable
936 public ITaskFragmentOrganizer getTaskFragmentOrganizer() {
937 return mTaskFragmentOrganizer;
938 }
939
940 @Override
941 @NonNull
942 public String toString() {
943 return "WindowContainerTransaction {"
944 + " changes = " + mChanges
945 + " hops = " + mHierarchyOps
946 + " errorCallbackToken=" + mErrorCallbackToken
947 + " taskFragmentOrganizer=" + mTaskFragmentOrganizer
948 + " }";
949 }
950
951 @Override
952 public void writeToParcel(@NonNull Parcel dest, int flags) {
953 dest.writeMap(mChanges);
954 dest.writeTypedList(mHierarchyOps);
955 dest.writeStrongBinder(mErrorCallbackToken);
956 dest.writeStrongInterface(mTaskFragmentOrganizer);
957 }
958
959 @Override
960 public int describeContents() {
961 return 0;
962 }
963
964 @NonNull
965 public static final Creator<WindowContainerTransaction> CREATOR =
966 new Creator<WindowContainerTransaction>() {
967 @Override
968 public WindowContainerTransaction createFromParcel(Parcel in) {
969 return new WindowContainerTransaction(in);
970 }
971
972 @Override
973 public WindowContainerTransaction[] newArray(int size) {
974 return new WindowContainerTransaction[size];
975 }
976 };
977
978 /**
979 * Holds changes on a single WindowContainer including Configuration changes.
980 * @hide
981 */
982 public static class Change implements Parcelable {
983 public static final int CHANGE_FOCUSABLE = 1;
984 public static final int CHANGE_BOUNDS_TRANSACTION = 1 << 1;
985 public static final int CHANGE_PIP_CALLBACK = 1 << 2;
986 public static final int CHANGE_HIDDEN = 1 << 3;
987 public static final int CHANGE_BOUNDS_TRANSACTION_RECT = 1 << 4;
988 public static final int CHANGE_IGNORE_ORIENTATION_REQUEST = 1 << 5;
989 public static final int CHANGE_FORCE_NO_PIP = 1 << 6;
990 public static final int CHANGE_FORCE_TRANSLUCENT = 1 << 7;
991 public static final int CHANGE_DRAG_RESIZING = 1 << 8;
992
993 private final Configuration mConfiguration = new Configuration();
994 private boolean mFocusable = true;
995 private boolean mHidden = false;
996 private boolean mIgnoreOrientationRequest = false;
997 private boolean mForceTranslucent = false;
998 private boolean mDragResizing = false;
999
1000 private int mChangeMask = 0;
1001 private @ActivityInfo.Config int mConfigSetMask = 0;
1002 private @WindowConfiguration.WindowConfig int mWindowSetMask = 0;
1003
1004 private Rect mPinnedBounds = null;
1005 private SurfaceControl.Transaction mBoundsChangeTransaction = null;
1006 private Rect mBoundsChangeSurfaceBounds = null;
1007
1008 private int mActivityWindowingMode = -1;
1009 private int mWindowingMode = -1;
1010
1011 public Change() {}
1012
1013 protected Change(Parcel in) {
1014 mConfiguration.readFromParcel(in);
1015 mFocusable = in.readBoolean();
1016 mHidden = in.readBoolean();
1017 mIgnoreOrientationRequest = in.readBoolean();
1018 mForceTranslucent = in.readBoolean();
1019 mDragResizing = in.readBoolean();
1020 mChangeMask = in.readInt();
1021 mConfigSetMask = in.readInt();
1022 mWindowSetMask = in.readInt();
1023 if ((mChangeMask & Change.CHANGE_PIP_CALLBACK) != 0) {
1024 mPinnedBounds = new Rect();
1025 mPinnedBounds.readFromParcel(in);
1026 }
1027 if ((mChangeMask & Change.CHANGE_BOUNDS_TRANSACTION) != 0) {
1028 mBoundsChangeTransaction =
1029 SurfaceControl.Transaction.CREATOR.createFromParcel(in);
1030 }
1031 if ((mChangeMask & Change.CHANGE_BOUNDS_TRANSACTION_RECT) != 0) {
1032 mBoundsChangeSurfaceBounds = new Rect();
1033 mBoundsChangeSurfaceBounds.readFromParcel(in);
1034 }
1035
1036 mWindowingMode = in.readInt();
1037 mActivityWindowingMode = in.readInt();
1038 }
1039
1040 /**
1041 * @param transfer When true, this will transfer other into this leaving other in an
1042 * undefined state. Use this if you don't intend to use other. When false,
1043 * SurfaceFlinger Transactions will not merge.
1044 */
1045 public void merge(Change other, boolean transfer) {
1046 mConfiguration.setTo(other.mConfiguration, other.mConfigSetMask, other.mWindowSetMask);
1047 mConfigSetMask |= other.mConfigSetMask;
1048 mWindowSetMask |= other.mWindowSetMask;
1049 if ((other.mChangeMask & CHANGE_FOCUSABLE) != 0) {
1050 mFocusable = other.mFocusable;
1051 }
1052 if (transfer && (other.mChangeMask & CHANGE_BOUNDS_TRANSACTION) != 0) {
1053 mBoundsChangeTransaction = other.mBoundsChangeTransaction;
1054 other.mBoundsChangeTransaction = null;
1055 }
1056 if ((other.mChangeMask & CHANGE_PIP_CALLBACK) != 0) {
1057 mPinnedBounds = transfer ? other.mPinnedBounds : new Rect(other.mPinnedBounds);
1058 }
1059 if ((other.mChangeMask & CHANGE_HIDDEN) != 0) {
1060 mHidden = other.mHidden;
1061 }
1062 if ((other.mChangeMask & CHANGE_IGNORE_ORIENTATION_REQUEST) != 0) {
1063 mIgnoreOrientationRequest = other.mIgnoreOrientationRequest;
1064 }
1065 if ((other.mChangeMask & CHANGE_FORCE_TRANSLUCENT) != 0) {
1066 mForceTranslucent = other.mForceTranslucent;
1067 }
1068 if ((other.mChangeMask & CHANGE_DRAG_RESIZING) != 0) {
1069 mDragResizing = other.mDragResizing;
1070 }
1071 mChangeMask |= other.mChangeMask;
1072 if (other.mActivityWindowingMode >= 0) {
1073 mActivityWindowingMode = other.mActivityWindowingMode;
1074 }
1075 if (other.mWindowingMode >= 0) {
1076 mWindowingMode = other.mWindowingMode;
1077 }
1078 if (other.mBoundsChangeSurfaceBounds != null) {
1079 mBoundsChangeSurfaceBounds = transfer ? other.mBoundsChangeSurfaceBounds
1080 : new Rect(other.mBoundsChangeSurfaceBounds);
1081 }
1082 }
1083
1084 public int getWindowingMode() {
1085 return mWindowingMode;
1086 }
1087
1088 public int getActivityWindowingMode() {
1089 return mActivityWindowingMode;
1090 }
1091
1092 public Configuration getConfiguration() {
1093 return mConfiguration;
1094 }
1095
1096 /** Gets the requested focusable state */
1097 public boolean getFocusable() {
1098 if ((mChangeMask & CHANGE_FOCUSABLE) == 0) {
1099 throw new RuntimeException("Focusable not set. check CHANGE_FOCUSABLE first");
1100 }
1101 return mFocusable;
1102 }
1103
1104 /** Gets the requested hidden state */
1105 public boolean getHidden() {
1106 if ((mChangeMask & CHANGE_HIDDEN) == 0) {
1107 throw new RuntimeException("Hidden not set. check CHANGE_HIDDEN first");
1108 }
1109 return mHidden;
1110 }
1111
1112 /** Gets the requested state of whether to ignore orientation request. */
1113 public boolean getIgnoreOrientationRequest() {
1114 if ((mChangeMask & CHANGE_IGNORE_ORIENTATION_REQUEST) == 0) {
1115 throw new RuntimeException("IgnoreOrientationRequest not set. "
1116 + "Check CHANGE_IGNORE_ORIENTATION_REQUEST first");
1117 }
1118 return mIgnoreOrientationRequest;
1119 }
1120
1121 /** Gets the requested force translucent state. */
1122 public boolean getForceTranslucent() {
1123 if ((mChangeMask & CHANGE_FORCE_TRANSLUCENT) == 0) {
1124 throw new RuntimeException("Force translucent not set. "
1125 + "Check CHANGE_FORCE_TRANSLUCENT first");
1126 }
1127 return mForceTranslucent;
1128 }
1129
1130 /** Gets the requested drag resizing state. */
1131 public boolean getDragResizing() {
1132 if ((mChangeMask & CHANGE_DRAG_RESIZING) == 0) {
1133 throw new RuntimeException("Drag resizing not set. "
1134 + "Check CHANGE_DRAG_RESIZING first");
1135 }
1136 return mDragResizing;
1137 }
1138
1139 public int getChangeMask() {
1140 return mChangeMask;
1141 }
1142
1143 @ActivityInfo.Config
1144 public int getConfigSetMask() {
1145 return mConfigSetMask;
1146 }
1147
1148 @WindowConfiguration.WindowConfig
1149 public int getWindowSetMask() {
1150 return mWindowSetMask;
1151 }
1152
1153 /**
1154 * Returns the bounds to be used for scheduling the enter pip callback
1155 * or null if no callback is to be scheduled.
1156 */
1157 public Rect getEnterPipBounds() {
1158 return mPinnedBounds;
1159 }
1160
1161 public SurfaceControl.Transaction getBoundsChangeTransaction() {
1162 return mBoundsChangeTransaction;
1163 }
1164
1165 public Rect getBoundsChangeSurfaceBounds() {
1166 return mBoundsChangeSurfaceBounds;
1167 }
1168
1169 @Override
1170 public String toString() {
1171 final boolean changesBounds =
1172 (mConfigSetMask & ActivityInfo.CONFIG_WINDOW_CONFIGURATION) != 0
1173 && ((mWindowSetMask & WindowConfiguration.WINDOW_CONFIG_BOUNDS)
1174 != 0);
1175 final boolean changesAppBounds =
1176 (mConfigSetMask & ActivityInfo.CONFIG_WINDOW_CONFIGURATION) != 0
1177 && ((mWindowSetMask & WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS)
1178 != 0);
1179 final boolean changesSs = (mConfigSetMask & ActivityInfo.CONFIG_SCREEN_SIZE) != 0;
1180 final boolean changesSss =
1181 (mConfigSetMask & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0;
1182 StringBuilder sb = new StringBuilder();
1183 sb.append('{');
1184 if (changesBounds) {
1185 sb.append("bounds:" + mConfiguration.windowConfiguration.getBounds() + ",");
1186 }
1187 if (changesAppBounds) {
1188 sb.append("appbounds:" + mConfiguration.windowConfiguration.getAppBounds() + ",");
1189 }
1190 if (changesSss) {
1191 sb.append("ssw:" + mConfiguration.smallestScreenWidthDp + ",");
1192 }
1193 if (changesSs) {
1194 sb.append("sw/h:" + mConfiguration.screenWidthDp + "x"
1195 + mConfiguration.screenHeightDp + ",");
1196 }
1197 if ((mChangeMask & CHANGE_FOCUSABLE) != 0) {
1198 sb.append("focusable:" + mFocusable + ",");
1199 }
1200 if ((mChangeMask & CHANGE_DRAG_RESIZING) != 0) {
1201 sb.append("dragResizing:" + mDragResizing + ",");
1202 }
1203 if (mBoundsChangeTransaction != null) {
1204 sb.append("hasBoundsTransaction,");
1205 }
1206 if ((mChangeMask & CHANGE_IGNORE_ORIENTATION_REQUEST) != 0) {
1207 sb.append("ignoreOrientationRequest:" + mIgnoreOrientationRequest + ",");
1208 }
1209 sb.append("}");
1210 return sb.toString();
1211 }
1212
1213 @Override
1214 public void writeToParcel(Parcel dest, int flags) {
1215 mConfiguration.writeToParcel(dest, flags);
1216 dest.writeBoolean(mFocusable);
1217 dest.writeBoolean(mHidden);
1218 dest.writeBoolean(mIgnoreOrientationRequest);
1219 dest.writeBoolean(mForceTranslucent);
1220 dest.writeBoolean(mDragResizing);
1221 dest.writeInt(mChangeMask);
1222 dest.writeInt(mConfigSetMask);
1223 dest.writeInt(mWindowSetMask);
1224
1225 if (mPinnedBounds != null) {
1226 mPinnedBounds.writeToParcel(dest, flags);
1227 }
1228 if (mBoundsChangeTransaction != null) {
1229 mBoundsChangeTransaction.writeToParcel(dest, flags);
1230 }
1231 if (mBoundsChangeSurfaceBounds != null) {
1232 mBoundsChangeSurfaceBounds.writeToParcel(dest, flags);
1233 }
1234
1235 dest.writeInt(mWindowingMode);
1236 dest.writeInt(mActivityWindowingMode);
1237 }
1238
1239 @Override
1240 public int describeContents() {
1241 return 0;
1242 }
1243
1244 public static final Creator<Change> CREATOR = new Creator<Change>() {
1245 @Override
1246 public Change createFromParcel(Parcel in) {
1247 return new Change(in);
1248 }
1249
1250 @Override
1251 public Change[] newArray(int size) {
1252 return new Change[size];
1253 }
1254 };
1255 }
1256
1257 /**
1258 * Holds information about a reparent/reorder operation in the hierarchy. This is separate from
1259 * Changes because they must be executed in the same order that they are added.
1260 * @hide
1261 */
1262 public static final class HierarchyOp implements Parcelable {
1263 public static final int HIERARCHY_OP_TYPE_REPARENT = 0;
1264 public static final int HIERARCHY_OP_TYPE_REORDER = 1;
1265 public static final int HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT = 2;
1266 public static final int HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT = 3;
1267 public static final int HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS = 4;
1268 public static final int HIERARCHY_OP_TYPE_LAUNCH_TASK = 5;
1269 public static final int HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT = 6;
1270 public static final int HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT = 7;
1271 public static final int HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT = 8;
1272 public static final int HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT = 9;
1273 public static final int HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT = 10;
1274 public static final int HIERARCHY_OP_TYPE_REPARENT_CHILDREN = 11;
1275 public static final int HIERARCHY_OP_TYPE_PENDING_INTENT = 12;
1276 public static final int HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS = 13;
1277 public static final int HIERARCHY_OP_TYPE_START_SHORTCUT = 14;
1278 public static final int HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER = 15;
1279 public static final int HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER = 16;
1280 public static final int HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER = 17;
1281 public static final int HIERARCHY_OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT = 18;
1282 public static final int HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP = 19;
1283 public static final int HIERARCHY_OP_TYPE_REMOVE_TASK = 20;
1284 public static final int HIERARCHY_OP_TYPE_FINISH_ACTIVITY = 21;
1285 public static final int HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT = 22;
1286 public static final int HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH = 23;
1287 public static final int HIERARCHY_OP_TYPE_SET_TASK_FRAGMENT_OPERATION = 24;
1288
1289 // The following key(s) are for use with mLaunchOptions:
1290 // When launching a task (eg. from recents), this is the taskId to be launched.
1291 public static final String LAUNCH_KEY_TASK_ID = "android:transaction.hop.taskId";
1292
1293 // When starting from a shortcut, this contains the calling package.
1294 public static final String LAUNCH_KEY_SHORTCUT_CALLING_PACKAGE =
1295 "android:transaction.hop.shortcut_calling_package";
1296
1297 private final int mType;
1298
1299 // Container we are performing the operation on.
1300 @Nullable
1301 private IBinder mContainer;
1302
1303 // If this is same as mContainer, then only change position, don't reparent.
1304 @Nullable
1305 private IBinder mReparent;
1306
1307 private @InsetsState.InternalInsetsType int[] mInsetsTypes;
1308
1309 private Rect mInsetsProviderFrame;
1310
1311 // Moves/reparents to top of parent when {@code true}, otherwise moves/reparents to bottom.
1312 private boolean mToTop;
1313
1314 private boolean mReparentTopOnly;
1315
1316 @Nullable
1317 private int[] mWindowingModes;
1318
1319 @Nullable
1320 private int[] mActivityTypes;
1321
1322 @Nullable
1323 private Bundle mLaunchOptions;
1324
1325 @Nullable
1326 private Intent mActivityIntent;
1327
1328 /** Used as options for {@link #createTaskFragment}. */
1329 @Nullable
1330 private TaskFragmentCreationParams mTaskFragmentCreationOptions;
1331
1332 /** Used as options for {@link #setTaskFragmentOperation}. */
1333 @Nullable
1334 private TaskFragmentOperation mTaskFragmentOperation;
1335
1336 @Nullable
1337 private PendingIntent mPendingIntent;
1338
1339 @Nullable
1340 private ShortcutInfo mShortcutInfo;
1341
1342 private boolean mAlwaysOnTop;
1343
1344 private boolean mReparentLeafTaskIfRelaunch;
1345
1346 public static HierarchyOp createForReparent(
1347 @NonNull IBinder container, @Nullable IBinder reparent, boolean toTop) {
1348 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REPARENT)
1349 .setContainer(container)
1350 .setReparentContainer(reparent)
1351 .setToTop(toTop)
1352 .build();
1353 }
1354
1355 public static HierarchyOp createForReorder(@NonNull IBinder container, boolean toTop) {
1356 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REORDER)
1357 .setContainer(container)
1358 .setReparentContainer(container)
1359 .setToTop(toTop)
1360 .build();
1361 }
1362
1363 public static HierarchyOp createForChildrenTasksReparent(IBinder currentParent,
1364 IBinder newParent, int[] windowingModes, int[] activityTypes, boolean onTop,
1365 boolean reparentTopOnly) {
1366 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT)
1367 .setContainer(currentParent)
1368 .setReparentContainer(newParent)
1369 .setWindowingModes(windowingModes)
1370 .setActivityTypes(activityTypes)
1371 .setToTop(onTop)
1372 .setReparentTopOnly(reparentTopOnly)
1373 .build();
1374 }
1375
1376 public static HierarchyOp createForSetLaunchRoot(IBinder container,
1377 int[] windowingModes, int[] activityTypes) {
1378 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT)
1379 .setContainer(container)
1380 .setWindowingModes(windowingModes)
1381 .setActivityTypes(activityTypes)
1382 .build();
1383 }
1384
1385 /** Create a hierarchy op for setting adjacent root tasks. */
1386 public static HierarchyOp createForAdjacentRoots(IBinder root1, IBinder root2) {
1387 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS)
1388 .setContainer(root1)
1389 .setReparentContainer(root2)
1390 .build();
1391 }
1392
1393 /** Create a hierarchy op for launching a task. */
1394 public static HierarchyOp createForTaskLaunch(int taskId, @Nullable Bundle options) {
1395 final Bundle fullOptions = options == null ? new Bundle() : options;
1396 fullOptions.putInt(LAUNCH_KEY_TASK_ID, taskId);
1397 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_LAUNCH_TASK)
1398 .setToTop(true)
1399 .setLaunchOptions(fullOptions)
1400 .build();
1401 }
1402
1403 /** Create a hierarchy op for starting a shortcut. */
1404 public static HierarchyOp createForStartShortcut(@NonNull String callingPackage,
1405 @NonNull ShortcutInfo shortcutInfo, @Nullable Bundle options) {
1406 final Bundle fullOptions = options == null ? new Bundle() : options;
1407 fullOptions.putString(LAUNCH_KEY_SHORTCUT_CALLING_PACKAGE, callingPackage);
1408 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_START_SHORTCUT)
1409 .setShortcutInfo(shortcutInfo)
1410 .setLaunchOptions(fullOptions)
1411 .build();
1412 }
1413
1414 /** Create a hierarchy op for setting launch adjacent flag root. */
1415 public static HierarchyOp createForSetLaunchAdjacentFlagRoot(IBinder container,
1416 boolean clearRoot) {
1417 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT)
1418 .setContainer(container)
1419 .setToTop(clearRoot)
1420 .build();
1421 }
1422
1423 /** create a hierarchy op for deleting a task **/
1424 public static HierarchyOp createForRemoveTask(@NonNull IBinder container) {
1425 return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REMOVE_TASK)
1426 .setContainer(container)
1427 .build();
1428 }
1429
1430 /** Only creates through {@link Builder}. */
1431 private HierarchyOp(int type) {
1432 mType = type;
1433 }
1434
1435 public HierarchyOp(@NonNull HierarchyOp copy) {
1436 mType = copy.mType;
1437 mContainer = copy.mContainer;
1438 mReparent = copy.mReparent;
1439 mInsetsTypes = copy.mInsetsTypes;
1440 mInsetsProviderFrame = copy.mInsetsProviderFrame;
1441 mToTop = copy.mToTop;
1442 mReparentTopOnly = copy.mReparentTopOnly;
1443 mWindowingModes = copy.mWindowingModes;
1444 mActivityTypes = copy.mActivityTypes;
1445 mLaunchOptions = copy.mLaunchOptions;
1446 mActivityIntent = copy.mActivityIntent;
1447 mTaskFragmentCreationOptions = copy.mTaskFragmentCreationOptions;
1448 mTaskFragmentOperation = copy.mTaskFragmentOperation;
1449 mPendingIntent = copy.mPendingIntent;
1450 mShortcutInfo = copy.mShortcutInfo;
1451 mAlwaysOnTop = copy.mAlwaysOnTop;
1452 mReparentLeafTaskIfRelaunch = copy.mReparentLeafTaskIfRelaunch;
1453 }
1454
1455 protected HierarchyOp(Parcel in) {
1456 mType = in.readInt();
1457 mContainer = in.readStrongBinder();
1458 mReparent = in.readStrongBinder();
1459 mInsetsTypes = in.createIntArray();
1460 if (in.readInt() != 0) {
1461 mInsetsProviderFrame = Rect.CREATOR.createFromParcel(in);
1462 } else {
1463 mInsetsProviderFrame = null;
1464 }
1465 mToTop = in.readBoolean();
1466 mReparentTopOnly = in.readBoolean();
1467 mWindowingModes = in.createIntArray();
1468 mActivityTypes = in.createIntArray();
1469 mLaunchOptions = in.readBundle();
1470 mActivityIntent = in.readTypedObject(Intent.CREATOR);
1471 mTaskFragmentCreationOptions = in.readTypedObject(TaskFragmentCreationParams.CREATOR);
1472 mTaskFragmentOperation = in.readTypedObject(TaskFragmentOperation.CREATOR);
1473 mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
1474 mShortcutInfo = in.readTypedObject(ShortcutInfo.CREATOR);
1475 mAlwaysOnTop = in.readBoolean();
1476 mReparentLeafTaskIfRelaunch = in.readBoolean();
1477 }
1478
1479 public int getType() {
1480 return mType;
1481 }
1482
1483 public boolean isReparent() {
1484 return mType == HIERARCHY_OP_TYPE_REPARENT;
1485 }
1486
1487 @Nullable
1488 public IBinder getNewParent() {
1489 return mReparent;
1490 }
1491
1492 @Nullable
1493 public @InsetsState.InternalInsetsType int[] getInsetsTypes() {
1494 return mInsetsTypes;
1495 }
1496
1497 public Rect getInsetsProviderFrame() {
1498 return mInsetsProviderFrame;
1499 }
1500
1501 @NonNull
1502 public IBinder getContainer() {
1503 return mContainer;
1504 }
1505
1506 @NonNull
1507 public IBinder getAdjacentRoot() {
1508 return mReparent;
1509 }
1510
1511 @NonNull
1512 public IBinder getCompanionContainer() {
1513 return mReparent;
1514 }
1515
1516 @NonNull
1517 public IBinder getCallingActivity() {
1518 return mReparent;
1519 }
1520
1521 public boolean getToTop() {
1522 return mToTop;
1523 }
1524
1525 public boolean getReparentTopOnly() {
1526 return mReparentTopOnly;
1527 }
1528
1529 public int[] getWindowingModes() {
1530 return mWindowingModes;
1531 }
1532
1533 public int[] getActivityTypes() {
1534 return mActivityTypes;
1535 }
1536
1537 @Nullable
1538 public Bundle getLaunchOptions() {
1539 return mLaunchOptions;
1540 }
1541
1542 @Nullable
1543 public Intent getActivityIntent() {
1544 return mActivityIntent;
1545 }
1546
1547 public boolean isAlwaysOnTop() {
1548 return mAlwaysOnTop;
1549 }
1550
1551 public boolean isReparentLeafTaskIfRelaunch() {
1552 return mReparentLeafTaskIfRelaunch;
1553 }
1554
1555 @Nullable
1556 public TaskFragmentCreationParams getTaskFragmentCreationOptions() {
1557 return mTaskFragmentCreationOptions;
1558 }
1559
1560 @Nullable
1561 public TaskFragmentOperation getTaskFragmentOperation() {
1562 return mTaskFragmentOperation;
1563 }
1564
1565 @Nullable
1566 public PendingIntent getPendingIntent() {
1567 return mPendingIntent;
1568 }
1569
1570 @Nullable
1571 public ShortcutInfo getShortcutInfo() {
1572 return mShortcutInfo;
1573 }
1574
1575 @Override
1576 public String toString() {
1577 switch (mType) {
1578 case HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT:
1579 return "{ChildrenTasksReparent: from=" + mContainer + " to=" + mReparent
1580 + " mToTop=" + mToTop + " mReparentTopOnly=" + mReparentTopOnly
1581 + " mWindowingMode=" + Arrays.toString(mWindowingModes)
1582 + " mActivityType=" + Arrays.toString(mActivityTypes) + "}";
1583 case HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT:
1584 return "{SetLaunchRoot: container=" + mContainer
1585 + " mWindowingMode=" + Arrays.toString(mWindowingModes)
1586 + " mActivityType=" + Arrays.toString(mActivityTypes) + "}";
1587 case HIERARCHY_OP_TYPE_REPARENT:
1588 return "{reparent: " + mContainer + " to " + (mToTop ? "top of " : "bottom of ")
1589 + mReparent + "}";
1590 case HIERARCHY_OP_TYPE_REORDER:
1591 return "{reorder: " + mContainer + " to " + (mToTop ? "top" : "bottom") + "}";
1592 case HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS:
1593 return "{SetAdjacentRoot: container=" + mContainer
1594 + " adjacentRoot=" + mReparent + "}";
1595 case HIERARCHY_OP_TYPE_LAUNCH_TASK:
1596 return "{LaunchTask: " + mLaunchOptions + "}";
1597 case HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT:
1598 return "{SetAdjacentFlagRoot: container=" + mContainer + " clearRoot=" + mToTop
1599 + "}";
1600 case HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT:
1601 return "{CreateTaskFragment: options=" + mTaskFragmentCreationOptions + "}";
1602 case HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT:
1603 return "{DeleteTaskFragment: taskFragment=" + mContainer + "}";
1604 case HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT:
1605 return "{StartActivityInTaskFragment: fragmentToken=" + mContainer + " intent="
1606 + mActivityIntent + " options=" + mLaunchOptions + "}";
1607 case HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT:
1608 return "{ReparentActivityToTaskFragment: fragmentToken=" + mReparent
1609 + " activity=" + mContainer + "}";
1610 case HIERARCHY_OP_TYPE_REPARENT_CHILDREN:
1611 return "{ReparentChildren: oldParent=" + mContainer + " newParent=" + mReparent
1612 + "}";
1613 case HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS:
1614 return "{SetAdjacentTaskFragments: container=" + mContainer
1615 + " adjacentContainer=" + mReparent + "}";
1616 case HIERARCHY_OP_TYPE_START_SHORTCUT:
1617 return "{StartShortcut: options=" + mLaunchOptions + " info=" + mShortcutInfo
1618 + "}";
1619 case HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER:
1620 return "{addRectInsetsProvider: container=" + mContainer
1621 + " insetsProvidingFrame=" + mInsetsProviderFrame
1622 + " insetsType=" + Arrays.toString(mInsetsTypes) + "}";
1623 case HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER:
1624 return "{removeLocalInsetsProvider: container=" + mContainer
1625 + " insetsType=" + Arrays.toString(mInsetsTypes) + "}";
1626 case HIERARCHY_OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT:
1627 return "{requestFocusOnTaskFragment: container=" + mContainer + "}";
1628 case HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP:
1629 return "{setAlwaysOnTop: container=" + mContainer
1630 + " alwaysOnTop=" + mAlwaysOnTop + "}";
1631 case HIERARCHY_OP_TYPE_REMOVE_TASK:
1632 return "{RemoveTask: task=" + mContainer + "}";
1633 case HIERARCHY_OP_TYPE_FINISH_ACTIVITY:
1634 return "{finishActivity: activity=" + mContainer + "}";
1635 case HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT:
1636 return "{setCompanionTaskFragment: container = " + mContainer + " companion = "
1637 + mReparent + "}";
1638 case HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH:
1639 return "{setReparentLeafTaskIfRelaunch: container= " + mContainer
1640 + " reparentLeafTaskIfRelaunch= " + mReparentLeafTaskIfRelaunch + "}";
1641 case HIERARCHY_OP_TYPE_SET_TASK_FRAGMENT_OPERATION:
1642 return "{setTaskFragmentOperation: fragmentToken= " + mContainer
1643 + " operation= " + mTaskFragmentOperation + "}";
1644 default:
1645 return "{mType=" + mType + " container=" + mContainer + " reparent=" + mReparent
1646 + " mToTop=" + mToTop
1647 + " mWindowingMode=" + Arrays.toString(mWindowingModes)
1648 + " mActivityType=" + Arrays.toString(mActivityTypes) + "}";
1649 }
1650 }
1651
1652 @Override
1653 public void writeToParcel(Parcel dest, int flags) {
1654 dest.writeInt(mType);
1655 dest.writeStrongBinder(mContainer);
1656 dest.writeStrongBinder(mReparent);
1657 dest.writeIntArray(mInsetsTypes);
1658 if (mInsetsProviderFrame != null) {
1659 dest.writeInt(1);
1660 mInsetsProviderFrame.writeToParcel(dest, 0);
1661 } else {
1662 dest.writeInt(0);
1663 }
1664 dest.writeBoolean(mToTop);
1665 dest.writeBoolean(mReparentTopOnly);
1666 dest.writeIntArray(mWindowingModes);
1667 dest.writeIntArray(mActivityTypes);
1668 dest.writeBundle(mLaunchOptions);
1669 dest.writeTypedObject(mActivityIntent, flags);
1670 dest.writeTypedObject(mTaskFragmentCreationOptions, flags);
1671 dest.writeTypedObject(mTaskFragmentOperation, flags);
1672 dest.writeTypedObject(mPendingIntent, flags);
1673 dest.writeTypedObject(mShortcutInfo, flags);
1674 dest.writeBoolean(mAlwaysOnTop);
1675 dest.writeBoolean(mReparentLeafTaskIfRelaunch);
1676 }
1677
1678 @Override
1679 public int describeContents() {
1680 return 0;
1681 }
1682
1683 public static final Creator<HierarchyOp> CREATOR = new Creator<HierarchyOp>() {
1684 @Override
1685 public HierarchyOp createFromParcel(Parcel in) {
1686 return new HierarchyOp(in);
1687 }
1688
1689 @Override
1690 public HierarchyOp[] newArray(int size) {
1691 return new HierarchyOp[size];
1692 }
1693 };
1694
1695 private static class Builder {
1696
1697 private final int mType;
1698
1699 @Nullable
1700 private IBinder mContainer;
1701
1702 @Nullable
1703 private IBinder mReparent;
1704
1705 private int[] mInsetsTypes;
1706
1707 private Rect mInsetsProviderFrame;
1708
1709 private boolean mToTop;
1710
1711 private boolean mReparentTopOnly;
1712
1713 @Nullable
1714 private int[] mWindowingModes;
1715
1716 @Nullable
1717 private int[] mActivityTypes;
1718
1719 @Nullable
1720 private Bundle mLaunchOptions;
1721
1722 @Nullable
1723 private Intent mActivityIntent;
1724
1725 @Nullable
1726 private TaskFragmentCreationParams mTaskFragmentCreationOptions;
1727
1728 @Nullable
1729 private TaskFragmentOperation mTaskFragmentOperation;
1730
1731 @Nullable
1732 private PendingIntent mPendingIntent;
1733
1734 @Nullable
1735 private ShortcutInfo mShortcutInfo;
1736
1737 private boolean mAlwaysOnTop;
1738
1739 private boolean mReparentLeafTaskIfRelaunch;
1740
1741 Builder(int type) {
1742 mType = type;
1743 }
1744
1745 Builder setContainer(@Nullable IBinder container) {
1746 mContainer = container;
1747 return this;
1748 }
1749
1750 Builder setReparentContainer(@Nullable IBinder reparentContainer) {
1751 mReparent = reparentContainer;
1752 return this;
1753 }
1754
1755 Builder setInsetsTypes(int[] insetsTypes) {
1756 mInsetsTypes = insetsTypes;
1757 return this;
1758 }
1759
1760 Builder setInsetsProviderFrame(Rect insetsProviderFrame) {
1761 mInsetsProviderFrame = insetsProviderFrame;
1762 return this;
1763 }
1764
1765 Builder setToTop(boolean toTop) {
1766 mToTop = toTop;
1767 return this;
1768 }
1769
1770 Builder setReparentTopOnly(boolean reparentTopOnly) {
1771 mReparentTopOnly = reparentTopOnly;
1772 return this;
1773 }
1774
1775 Builder setWindowingModes(@Nullable int[] windowingModes) {
1776 mWindowingModes = windowingModes;
1777 return this;
1778 }
1779
1780 Builder setActivityTypes(@Nullable int[] activityTypes) {
1781 mActivityTypes = activityTypes;
1782 return this;
1783 }
1784
1785 Builder setLaunchOptions(@Nullable Bundle launchOptions) {
1786 mLaunchOptions = launchOptions;
1787 return this;
1788 }
1789
1790 Builder setActivityIntent(@Nullable Intent activityIntent) {
1791 mActivityIntent = activityIntent;
1792 return this;
1793 }
1794
1795 Builder setPendingIntent(@Nullable PendingIntent sender) {
1796 mPendingIntent = sender;
1797 return this;
1798 }
1799
1800 Builder setAlwaysOnTop(boolean alwaysOnTop) {
1801 mAlwaysOnTop = alwaysOnTop;
1802 return this;
1803 }
1804
1805 Builder setTaskFragmentCreationOptions(
1806 @Nullable TaskFragmentCreationParams taskFragmentCreationOptions) {
1807 mTaskFragmentCreationOptions = taskFragmentCreationOptions;
1808 return this;
1809 }
1810
1811 Builder setTaskFragmentOperation(
1812 @Nullable TaskFragmentOperation taskFragmentOperation) {
1813 mTaskFragmentOperation = taskFragmentOperation;
1814 return this;
1815 }
1816
1817 Builder setReparentLeafTaskIfRelaunch(boolean reparentLeafTaskIfRelaunch) {
1818 mReparentLeafTaskIfRelaunch = reparentLeafTaskIfRelaunch;
1819 return this;
1820 }
1821
1822 Builder setShortcutInfo(@Nullable ShortcutInfo shortcutInfo) {
1823 mShortcutInfo = shortcutInfo;
1824 return this;
1825 }
1826
1827 HierarchyOp build() {
1828 final HierarchyOp hierarchyOp = new HierarchyOp(mType);
1829 hierarchyOp.mContainer = mContainer;
1830 hierarchyOp.mReparent = mReparent;
1831 hierarchyOp.mWindowingModes = mWindowingModes != null
1832 ? Arrays.copyOf(mWindowingModes, mWindowingModes.length)
1833 : null;
1834 hierarchyOp.mActivityTypes = mActivityTypes != null
1835 ? Arrays.copyOf(mActivityTypes, mActivityTypes.length)
1836 : null;
1837 hierarchyOp.mInsetsTypes = mInsetsTypes;
1838 hierarchyOp.mInsetsProviderFrame = mInsetsProviderFrame;
1839 hierarchyOp.mToTop = mToTop;
1840 hierarchyOp.mReparentTopOnly = mReparentTopOnly;
1841 hierarchyOp.mLaunchOptions = mLaunchOptions;
1842 hierarchyOp.mActivityIntent = mActivityIntent;
1843 hierarchyOp.mPendingIntent = mPendingIntent;
1844 hierarchyOp.mAlwaysOnTop = mAlwaysOnTop;
1845 hierarchyOp.mTaskFragmentCreationOptions = mTaskFragmentCreationOptions;
1846 hierarchyOp.mTaskFragmentOperation = mTaskFragmentOperation;
1847 hierarchyOp.mShortcutInfo = mShortcutInfo;
1848 hierarchyOp.mReparentLeafTaskIfRelaunch = mReparentLeafTaskIfRelaunch;
1849
1850 return hierarchyOp;
1851 }
1852 }
1853 }
1854
1855 /**
1856 * Helper class for building an options Bundle that can be used to set adjacent rules of
1857 * TaskFragments.
1858 */
1859 public static class TaskFragmentAdjacentParams {
1860 private static final String DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL =
1861 "android:transaction.adjacent.option.delay_primary_removal";
1862 private static final String DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL =
1863 "android:transaction.adjacent.option.delay_secondary_removal";
1864
1865 private boolean mDelayPrimaryLastActivityRemoval;
1866 private boolean mDelaySecondaryLastActivityRemoval;
1867
1868 public TaskFragmentAdjacentParams() {
1869 }
1870
1871 public TaskFragmentAdjacentParams(@NonNull Bundle bundle) {
1872 mDelayPrimaryLastActivityRemoval = bundle.getBoolean(
1873 DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL);
1874 mDelaySecondaryLastActivityRemoval = bundle.getBoolean(
1875 DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL);
1876 }
1877
1878 /** @see #shouldDelayPrimaryLastActivityRemoval() */
1879 public void setShouldDelayPrimaryLastActivityRemoval(boolean delay) {
1880 mDelayPrimaryLastActivityRemoval = delay;
1881 }
1882
1883 /** @see #shouldDelaySecondaryLastActivityRemoval() */
1884 public void setShouldDelaySecondaryLastActivityRemoval(boolean delay) {
1885 mDelaySecondaryLastActivityRemoval = delay;
1886 }
1887
1888 /**
1889 * Whether to delay the last activity of the primary adjacent TaskFragment being immediately
1890 * removed while finishing.
1891 * <p>
1892 * It is usually set to {@code true} to give organizer an opportunity to perform other
1893 * actions or animations. An example is to finish together with the adjacent TaskFragment.
1894 * </p>
1895 */
1896 public boolean shouldDelayPrimaryLastActivityRemoval() {
1897 return mDelayPrimaryLastActivityRemoval;
1898 }
1899
1900 /**
1901 * Similar to {@link #shouldDelayPrimaryLastActivityRemoval()}, but for the secondary
1902 * TaskFragment.
1903 */
1904 public boolean shouldDelaySecondaryLastActivityRemoval() {
1905 return mDelaySecondaryLastActivityRemoval;
1906 }
1907
1908 Bundle toBundle() {
1909 final Bundle b = new Bundle();
1910 b.putBoolean(DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL, mDelayPrimaryLastActivityRemoval);
1911 b.putBoolean(DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL, mDelaySecondaryLastActivityRemoval);
1912 return b;
1913 }
1914 }
1915 }