Debian Codegraph @

core/java/android/app/WindowConfiguration.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2017 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.app;
18
19 import static android.app.ActivityThread.isSystem;
20 import static android.app.WindowConfigurationProto.ACTIVITY_TYPE;
21 import static android.app.WindowConfigurationProto.APP_BOUNDS;
22 import static android.app.WindowConfigurationProto.BOUNDS;
23 import static android.app.WindowConfigurationProto.MAX_BOUNDS;
24 import static android.app.WindowConfigurationProto.WINDOWING_MODE;
25 import static android.view.Surface.rotationToString;
26
27 import android.annotation.IntDef;
28 import android.annotation.NonNull;
29 import android.annotation.Nullable;
30 import android.annotation.TestApi;
31 import android.compat.annotation.UnsupportedAppUsage;
32 import android.content.res.Configuration;
33 import android.graphics.Rect;
34 import android.os.Parcel;
35 import android.os.Parcelable;
36 import android.util.proto.ProtoInputStream;
37 import android.util.proto.ProtoOutputStream;
38 import android.util.proto.WireTypeMismatchException;
39 import android.view.DisplayInfo;
40 import android.view.Surface;
41 import android.view.WindowManager;
42
43 import java.io.IOException;
44 import java.util.Objects;
45
46 /**
47 * Class that contains windowing configuration/state for other objects that contain windows directly
48 * or indirectly. E.g. Activities, Task, Displays, ...
49 * The test class is {@link com.android.server.wm.WindowConfigurationTests} which must be kept
50 * up-to-date and ran anytime changes are made to this class.
51 * @hide
52 */
53 @TestApi
54 public class WindowConfiguration implements Parcelable, Comparable<WindowConfiguration> {
55 /**
56 * bounds that can differ from app bounds, which may include things such as insets.
57 *
58 * TODO: Investigate combining with {@link #mAppBounds}. Can the latter be a product of the
59 * former?
60 */
61 private final Rect mBounds = new Rect();
62
63 /**
64 * {@link android.graphics.Rect} defining app bounds. The dimensions override usages of
65 * {@link DisplayInfo#appHeight} and {@link DisplayInfo#appWidth} and mirrors these values at
66 * the display level. Lower levels can override these values to provide custom bounds to enforce
67 * features such as a max aspect ratio.
68 */
69 private Rect mAppBounds;
70
71 /**
72 * The maximum {@link Rect} bounds that an app can expect. It is used to report value of
73 * {@link WindowManager#getMaximumWindowMetrics()}.
74 */
75 private final Rect mMaxBounds = new Rect();
76
77 /**
78 * The rotation of this window's apparent display. This can differ from mRotation in some
79 * situations (like letterbox).
80 */
81 @Surface.Rotation
82 private int mDisplayRotation = ROTATION_UNDEFINED;
83
84 /**
85 * The current rotation of this window container relative to the default
86 * orientation of the display it is on (regardless of how deep in the hierarchy
87 * it is). It is used by the configuration hierarchy to apply rotation-dependent
88 * policy during bounds calculation.
89 */
90 private int mRotation = ROTATION_UNDEFINED;
91
92 /** Rotation is not defined, use the parent containers rotation. */
93 public static final int ROTATION_UNDEFINED = -1;
94
95 /** The current windowing mode of the configuration. */
96 private @WindowingMode int mWindowingMode;
97
98 /** The display windowing mode of the configuration */
99 private @WindowingMode int mDisplayWindowingMode;
100
101 /** Windowing mode is currently not defined. */
102 public static final int WINDOWING_MODE_UNDEFINED = 0;
103 /** Occupies the full area of the screen or the parent container. */
104 public static final int WINDOWING_MODE_FULLSCREEN = 1;
105 /** Always on-top (always visible). of other siblings in its parent container. */
106 public static final int WINDOWING_MODE_PINNED = 2;
107 /** Can be freely resized within its parent container. */
108 // TODO: Remove once freeform is migrated to wm-shell.
109 public static final int WINDOWING_MODE_FREEFORM = 5;
110 /** Generic multi-window with no presentation attribution from the window manager. */
111 public static final int WINDOWING_MODE_MULTI_WINDOW = 6;
112
113 /** @hide */
114 @IntDef(prefix = { "WINDOWING_MODE_" }, value = {
115 WINDOWING_MODE_UNDEFINED,
116 WINDOWING_MODE_FULLSCREEN,
117 WINDOWING_MODE_MULTI_WINDOW,
118 WINDOWING_MODE_PINNED,
119 WINDOWING_MODE_FREEFORM,
120 })
121 public @interface WindowingMode {}
122
123 /** The current activity type of the configuration. */
124 private @ActivityType int mActivityType;
125
126 /** Activity type is currently not defined. */
127 public static final int ACTIVITY_TYPE_UNDEFINED = 0;
128 /** Standard activity type. Nothing special about the activity... */
129 public static final int ACTIVITY_TYPE_STANDARD = 1;
130 /** Home/Launcher activity type. */
131 public static final int ACTIVITY_TYPE_HOME = 2;
132 /** Recents/Overview activity type. There is only one activity with this type in the system. */
133 public static final int ACTIVITY_TYPE_RECENTS = 3;
134 /** Assistant activity type. */
135 public static final int ACTIVITY_TYPE_ASSISTANT = 4;
136 /** Dream activity type. */
137 public static final int ACTIVITY_TYPE_DREAM = 5;
138
139 /** @hide */
140 @IntDef(prefix = { "ACTIVITY_TYPE_" }, value = {
141 ACTIVITY_TYPE_UNDEFINED,
142 ACTIVITY_TYPE_STANDARD,
143 ACTIVITY_TYPE_HOME,
144 ACTIVITY_TYPE_RECENTS,
145 ACTIVITY_TYPE_ASSISTANT,
146 ACTIVITY_TYPE_DREAM,
147 })
148 public @interface ActivityType {}
149
150 /** The current always on top status of the configuration. */
151 private @AlwaysOnTop int mAlwaysOnTop;
152
153 /** Always on top is currently not defined. */
154 private static final int ALWAYS_ON_TOP_UNDEFINED = 0;
155 /** Always on top is currently on for this configuration. */
156 private static final int ALWAYS_ON_TOP_ON = 1;
157 /** Always on top is currently off for this configuration. */
158 private static final int ALWAYS_ON_TOP_OFF = 2;
159
160 /** @hide */
161 @IntDef(prefix = { "ALWAYS_ON_TOP_" }, value = {
162 ALWAYS_ON_TOP_UNDEFINED,
163 ALWAYS_ON_TOP_ON,
164 ALWAYS_ON_TOP_OFF,
165 })
166 private @interface AlwaysOnTop {}
167
168 /** Bit that indicates that the {@link #mBounds} changed.
169 * @hide */
170 public static final int WINDOW_CONFIG_BOUNDS = 1 << 0;
171 /** Bit that indicates that the {@link #mAppBounds} changed.
172 * @hide */
173 public static final int WINDOW_CONFIG_APP_BOUNDS = 1 << 1;
174 /** Bit that indicates that the {@link #mMaxBounds} changed.
175 * @hide */
176 public static final int WINDOW_CONFIG_MAX_BOUNDS = 1 << 2;
177 /** Bit that indicates that the {@link #mWindowingMode} changed.
178 * @hide */
179 public static final int WINDOW_CONFIG_WINDOWING_MODE = 1 << 3;
180 /** Bit that indicates that the {@link #mActivityType} changed.
181 * @hide */
182 public static final int WINDOW_CONFIG_ACTIVITY_TYPE = 1 << 4;
183 /** Bit that indicates that the {@link #mAlwaysOnTop} changed.
184 * @hide */
185 public static final int WINDOW_CONFIG_ALWAYS_ON_TOP = 1 << 5;
186 /** Bit that indicates that the {@link #mRotation} changed.
187 * @hide */
188 public static final int WINDOW_CONFIG_ROTATION = 1 << 6;
189 /** Bit that indicates that the {@link #mDisplayWindowingMode} changed.
190 * @hide */
191 public static final int WINDOW_CONFIG_DISPLAY_WINDOWING_MODE = 1 << 7;
192 /** Bit that indicates that the apparent-display changed.
193 * @hide */
194 public static final int WINDOW_CONFIG_DISPLAY_ROTATION = 1 << 8;
195
196 /** @hide */
197 @IntDef(flag = true, prefix = { "WINDOW_CONFIG_" }, value = {
198 WINDOW_CONFIG_BOUNDS,
199 WINDOW_CONFIG_APP_BOUNDS,
200 WINDOW_CONFIG_MAX_BOUNDS,
201 WINDOW_CONFIG_WINDOWING_MODE,
202 WINDOW_CONFIG_ACTIVITY_TYPE,
203 WINDOW_CONFIG_ALWAYS_ON_TOP,
204 WINDOW_CONFIG_ROTATION,
205 WINDOW_CONFIG_DISPLAY_WINDOWING_MODE,
206 WINDOW_CONFIG_DISPLAY_ROTATION,
207 })
208 public @interface WindowConfig {}
209
210 @UnsupportedAppUsage
211 public WindowConfiguration() {
212 unset();
213 }
214
215 /** @hide */
216 public WindowConfiguration(WindowConfiguration configuration) {
217 setTo(configuration);
218 }
219
220 private WindowConfiguration(Parcel in) {
221 readFromParcel(in);
222 }
223
224 @Override
225 public void writeToParcel(Parcel dest, int flags) {
226 mBounds.writeToParcel(dest, flags);
227 dest.writeTypedObject(mAppBounds, flags);
228 mMaxBounds.writeToParcel(dest, flags);
229 dest.writeInt(mWindowingMode);
230 dest.writeInt(mActivityType);
231 dest.writeInt(mAlwaysOnTop);
232 dest.writeInt(mRotation);
233 dest.writeInt(mDisplayWindowingMode);
234 dest.writeInt(mDisplayRotation);
235 }
236
237 /** @hide */
238 public void readFromParcel(@NonNull Parcel source) {
239 mBounds.readFromParcel(source);
240 mAppBounds = source.readTypedObject(Rect.CREATOR);
241 mMaxBounds.readFromParcel(source);
242 mWindowingMode = source.readInt();
243 mActivityType = source.readInt();
244 mAlwaysOnTop = source.readInt();
245 mRotation = source.readInt();
246 mDisplayWindowingMode = source.readInt();
247 mDisplayRotation = source.readInt();
248 }
249
250 @Override
251 public int describeContents() {
252 return 0;
253 }
254
255 /** @hide */
256 public static final @android.annotation.NonNull Creator<WindowConfiguration> CREATOR = new Creator<WindowConfiguration>() {
257 @Override
258 public WindowConfiguration createFromParcel(Parcel in) {
259 return new WindowConfiguration(in);
260 }
261
262 @Override
263 public WindowConfiguration[] newArray(int size) {
264 return new WindowConfiguration[size];
265 }
266 };
267
268 /**
269 * Sets the bounds to the provided {@link Rect}.
270 * @param rect the new bounds value.
271 */
272 public void setBounds(Rect rect) {
273 if (rect == null) {
274 mBounds.setEmpty();
275 return;
276 }
277
278 mBounds.set(rect);
279 }
280
281 /**
282 * Set {@link #mAppBounds} to the input Rect.
283 * @param rect The rect value to set {@link #mAppBounds} to.
284 * @see #getAppBounds()
285 */
286 public void setAppBounds(Rect rect) {
287 if (rect == null) {
288 mAppBounds = null;
289 return;
290 }
291
292 setAppBounds(rect.left, rect.top, rect.right, rect.bottom);
293 }
294
295 /**
296 * Sets the maximum bounds to the provided {@link Rect}.
297 * @param rect the new bounds value.
298 * @see #getMaxBounds()
299 */
300 public void setMaxBounds(@Nullable Rect rect) {
301 if (rect == null) {
302 mMaxBounds.setEmpty();
303 return;
304 }
305 mMaxBounds.set(rect);
306 }
307
308 /**
309 * @see #setMaxBounds(Rect)
310 * @hide
311 */
312 public void setMaxBounds(int left, int top, int right, int bottom) {
313 mMaxBounds.set(left, top, right, bottom);
314 }
315
316 /**
317 * Sets the apparent display cutout.
318 * @hide
319 */
320 public void setDisplayRotation(@Surface.Rotation int rotation) {
321 mDisplayRotation = rotation;
322 }
323
324 /**
325 * Sets whether this window should be always on top.
326 * @param alwaysOnTop {@code true} to set window always on top, otherwise {@code false}
327 * @hide
328 */
329 public void setAlwaysOnTop(boolean alwaysOnTop) {
330 mAlwaysOnTop = alwaysOnTop ? ALWAYS_ON_TOP_ON : ALWAYS_ON_TOP_OFF;
331 }
332
333 /**
334 * Unsets always-on-top to undefined.
335 * @hide
336 */
337 public void unsetAlwaysOnTop() {
338 mAlwaysOnTop = ALWAYS_ON_TOP_UNDEFINED;
339 }
340
341 private void setAlwaysOnTop(@AlwaysOnTop int alwaysOnTop) {
342 mAlwaysOnTop = alwaysOnTop;
343 }
344
345 /**
346 * @see #setAppBounds(Rect)
347 * @see #getAppBounds()
348 * @hide
349 */
350 public void setAppBounds(int left, int top, int right, int bottom) {
351 if (mAppBounds == null) {
352 mAppBounds = new Rect();
353 }
354
355 mAppBounds.set(left, top, right, bottom);
356 }
357
358 /** @see #setAppBounds(Rect) */
359 public Rect getAppBounds() {
360 return mAppBounds;
361 }
362
363 /** @see #setBounds(Rect) */
364 public Rect getBounds() {
365 return mBounds;
366 }
367
368 /** @see #setMaxBounds(Rect) */
369 @NonNull
370 public Rect getMaxBounds() {
371 return mMaxBounds;
372 }
373
374 /**
375 * @see #setDisplayRotation
376 * @hide
377 */
378 public @Surface.Rotation int getDisplayRotation() {
379 return mDisplayRotation;
380 }
381
382 public int getRotation() {
383 return mRotation;
384 }
385
386 public void setRotation(int rotation) {
387 mRotation = rotation;
388 }
389
390 public void setWindowingMode(@WindowingMode int windowingMode) {
391 mWindowingMode = windowingMode;
392 }
393
394 @WindowingMode
395 public int getWindowingMode() {
396 return mWindowingMode;
397 }
398
399 /** @hide */
400 public void setDisplayWindowingMode(@WindowingMode int windowingMode) {
401 mDisplayWindowingMode = windowingMode;
402 }
403
404 /** @hide */
405 @WindowingMode
406 public int getDisplayWindowingMode() {
407 return mDisplayWindowingMode;
408 }
409
410 public void setActivityType(@ActivityType int activityType) {
411 if (mActivityType == activityType) {
412 return;
413 }
414
415 // Error check within system server that we are not changing activity type which can be
416 // dangerous. It is okay for things to change in the application process as it doesn't
417 // affect how other things is the system is managed.
418 if (isSystem()
419 && mActivityType != ACTIVITY_TYPE_UNDEFINED
420 && activityType != ACTIVITY_TYPE_UNDEFINED) {
421 throw new IllegalStateException("Can't change activity type once set: " + this
422 + " activityType=" + activityTypeToString(activityType));
423 }
424 mActivityType = activityType;
425 }
426
427 @ActivityType
428 public int getActivityType() {
429 return mActivityType;
430 }
431
432 public void setTo(WindowConfiguration other) {
433 setBounds(other.mBounds);
434 setAppBounds(other.mAppBounds);
435 setMaxBounds(other.mMaxBounds);
436 setDisplayRotation(other.mDisplayRotation);
437 setWindowingMode(other.mWindowingMode);
438 setActivityType(other.mActivityType);
439 setAlwaysOnTop(other.mAlwaysOnTop);
440 setRotation(other.mRotation);
441 setDisplayWindowingMode(other.mDisplayWindowingMode);
442 }
443
444 /** Set this object to completely undefined.
445 * @hide */
446 public void unset() {
447 setToDefaults();
448 }
449
450 /** @hide */
451 public void setToDefaults() {
452 setAppBounds(null);
453 setBounds(null);
454 setMaxBounds(null);
455 setDisplayRotation(ROTATION_UNDEFINED);
456 setWindowingMode(WINDOWING_MODE_UNDEFINED);
457 setActivityType(ACTIVITY_TYPE_UNDEFINED);
458 setAlwaysOnTop(ALWAYS_ON_TOP_UNDEFINED);
459 setRotation(ROTATION_UNDEFINED);
460 setDisplayWindowingMode(WINDOWING_MODE_UNDEFINED);
461 }
462
463 /** @hide */
464 public void scale(float scale) {
465 mBounds.scale(scale);
466 mMaxBounds.scale(scale);
467 if (mAppBounds != null) {
468 mAppBounds.scale(scale);
469 }
470 }
471
472 /**
473 * Copies the fields from delta into this Configuration object, keeping
474 * track of which ones have changed. Any undefined fields in {@code delta}
475 * are ignored and not copied in to the current Configuration.
476 *
477 * @return a bit mask of the changed fields, as per {@link #diff}
478 * @hide
479 */
480 public @WindowConfig int updateFrom(@NonNull WindowConfiguration delta) {
481 int changed = 0;
482 // Only allow override if bounds is not empty
483 if (!delta.mBounds.isEmpty() && !delta.mBounds.equals(mBounds)) {
484 changed |= WINDOW_CONFIG_BOUNDS;
485 setBounds(delta.mBounds);
486 }
487 if (delta.mAppBounds != null && !delta.mAppBounds.equals(mAppBounds)) {
488 changed |= WINDOW_CONFIG_APP_BOUNDS;
489 setAppBounds(delta.mAppBounds);
490 }
491 if (!delta.mMaxBounds.isEmpty() && !delta.mMaxBounds.equals(mMaxBounds)) {
492 changed |= WINDOW_CONFIG_MAX_BOUNDS;
493 setMaxBounds(delta.mMaxBounds);
494 }
495 if (delta.mWindowingMode != WINDOWING_MODE_UNDEFINED
496 && mWindowingMode != delta.mWindowingMode) {
497 changed |= WINDOW_CONFIG_WINDOWING_MODE;
498 setWindowingMode(delta.mWindowingMode);
499 }
500 if (delta.mActivityType != ACTIVITY_TYPE_UNDEFINED
501 && mActivityType != delta.mActivityType) {
502 changed |= WINDOW_CONFIG_ACTIVITY_TYPE;
503 setActivityType(delta.mActivityType);
504 }
505 if (delta.mAlwaysOnTop != ALWAYS_ON_TOP_UNDEFINED
506 && mAlwaysOnTop != delta.mAlwaysOnTop) {
507 changed |= WINDOW_CONFIG_ALWAYS_ON_TOP;
508 setAlwaysOnTop(delta.mAlwaysOnTop);
509 }
510 if (delta.mRotation != ROTATION_UNDEFINED && delta.mRotation != mRotation) {
511 changed |= WINDOW_CONFIG_ROTATION;
512 setRotation(delta.mRotation);
513 }
514 if (delta.mDisplayWindowingMode != WINDOWING_MODE_UNDEFINED
515 && mDisplayWindowingMode != delta.mDisplayWindowingMode) {
516 changed |= WINDOW_CONFIG_DISPLAY_WINDOWING_MODE;
517 setDisplayWindowingMode(delta.mDisplayWindowingMode);
518 }
519 if (delta.mDisplayRotation != ROTATION_UNDEFINED
520 && delta.mDisplayRotation != mDisplayRotation) {
521 changed |= WINDOW_CONFIG_DISPLAY_ROTATION;
522 setDisplayRotation(delta.mDisplayRotation);
523 }
524 return changed;
525 }
526
527 /**
528 * Copies the fields specified by mask from delta into this Configuration object.
529 * @hide
530 */
531 public void setTo(@NonNull WindowConfiguration delta, @WindowConfig int mask) {
532 if ((mask & WINDOW_CONFIG_BOUNDS) != 0) {
533 setBounds(delta.mBounds);
534 }
535 if ((mask & WINDOW_CONFIG_APP_BOUNDS) != 0) {
536 setAppBounds(delta.mAppBounds);
537 }
538 if ((mask & WINDOW_CONFIG_MAX_BOUNDS) != 0) {
539 setMaxBounds(delta.mMaxBounds);
540 }
541 if ((mask & WINDOW_CONFIG_WINDOWING_MODE) != 0) {
542 setWindowingMode(delta.mWindowingMode);
543 }
544 if ((mask & WINDOW_CONFIG_ACTIVITY_TYPE) != 0) {
545 setActivityType(delta.mActivityType);
546 }
547 if ((mask & WINDOW_CONFIG_ALWAYS_ON_TOP) != 0) {
548 setAlwaysOnTop(delta.mAlwaysOnTop);
549 }
550 if ((mask & WINDOW_CONFIG_ROTATION) != 0) {
551 setRotation(delta.mRotation);
552 }
553 if ((mask & WINDOW_CONFIG_DISPLAY_WINDOWING_MODE) != 0) {
554 setDisplayWindowingMode(delta.mDisplayWindowingMode);
555 }
556 if ((mask & WINDOW_CONFIG_DISPLAY_ROTATION) != 0) {
557 setDisplayRotation(delta.mDisplayRotation);
558 }
559 }
560
561 /**
562 * Return a bit mask of the differences between this Configuration object and the given one.
563 * Does not change the values of either. Any undefined fields in <var>other</var> are ignored.
564 * @param other The configuration to diff against.
565 * @param compareUndefined If undefined values should be compared.
566 * @return Returns a bit mask indicating which configuration
567 * values has changed, containing any combination of {@link WindowConfig} flags.
568 *
569 * @see Configuration#diff(Configuration)
570 * @hide
571 */
572 public @WindowConfig long diff(WindowConfiguration other, boolean compareUndefined) {
573 long changes = 0;
574
575 if (!mBounds.equals(other.mBounds)) {
576 changes |= WINDOW_CONFIG_BOUNDS;
577 }
578
579 // Make sure that one of the values is not null and that they are not equal.
580 if ((compareUndefined || other.mAppBounds != null)
581 && mAppBounds != other.mAppBounds
582 && (mAppBounds == null || !mAppBounds.equals(other.mAppBounds))) {
583 changes |= WINDOW_CONFIG_APP_BOUNDS;
584 }
585
586 if (!mMaxBounds.equals(other.mMaxBounds)) {
587 changes |= WINDOW_CONFIG_MAX_BOUNDS;
588 }
589
590 if ((compareUndefined || other.mWindowingMode != WINDOWING_MODE_UNDEFINED)
591 && mWindowingMode != other.mWindowingMode) {
592 changes |= WINDOW_CONFIG_WINDOWING_MODE;
593 }
594
595 if ((compareUndefined || other.mActivityType != ACTIVITY_TYPE_UNDEFINED)
596 && mActivityType != other.mActivityType) {
597 changes |= WINDOW_CONFIG_ACTIVITY_TYPE;
598 }
599
600 if ((compareUndefined || other.mAlwaysOnTop != ALWAYS_ON_TOP_UNDEFINED)
601 && mAlwaysOnTop != other.mAlwaysOnTop) {
602 changes |= WINDOW_CONFIG_ALWAYS_ON_TOP;
603 }
604
605 if ((compareUndefined || other.mRotation != ROTATION_UNDEFINED)
606 && mRotation != other.mRotation) {
607 changes |= WINDOW_CONFIG_ROTATION;
608 }
609
610 if ((compareUndefined || other.mDisplayWindowingMode != WINDOWING_MODE_UNDEFINED)
611 && mDisplayWindowingMode != other.mDisplayWindowingMode) {
612 changes |= WINDOW_CONFIG_DISPLAY_WINDOWING_MODE;
613 }
614
615 if ((compareUndefined || other.mDisplayRotation != ROTATION_UNDEFINED)
616 && mDisplayRotation != other.mDisplayRotation) {
617 changes |= WINDOW_CONFIG_DISPLAY_ROTATION;
618 }
619
620 return changes;
621 }
622
623 @Override
624 public int compareTo(WindowConfiguration that) {
625 int n = 0;
626 if (mAppBounds == null && that.mAppBounds != null) {
627 return 1;
628 } else if (mAppBounds != null && that.mAppBounds == null) {
629 return -1;
630 } else if (mAppBounds != null && that.mAppBounds != null) {
631 n = mAppBounds.left - that.mAppBounds.left;
632 if (n != 0) return n;
633 n = mAppBounds.top - that.mAppBounds.top;
634 if (n != 0) return n;
635 n = mAppBounds.right - that.mAppBounds.right;
636 if (n != 0) return n;
637 n = mAppBounds.bottom - that.mAppBounds.bottom;
638 if (n != 0) return n;
639 }
640
641 n = mMaxBounds.left - that.mMaxBounds.left;
642 if (n != 0) return n;
643 n = mMaxBounds.top - that.mMaxBounds.top;
644 if (n != 0) return n;
645 n = mMaxBounds.right - that.mMaxBounds.right;
646 if (n != 0) return n;
647 n = mMaxBounds.bottom - that.mMaxBounds.bottom;
648 if (n != 0) return n;
649
650 n = mBounds.left - that.mBounds.left;
651 if (n != 0) return n;
652 n = mBounds.top - that.mBounds.top;
653 if (n != 0) return n;
654 n = mBounds.right - that.mBounds.right;
655 if (n != 0) return n;
656 n = mBounds.bottom - that.mBounds.bottom;
657 if (n != 0) return n;
658
659 n = mWindowingMode - that.mWindowingMode;
660 if (n != 0) return n;
661 n = mActivityType - that.mActivityType;
662 if (n != 0) return n;
663 n = mAlwaysOnTop - that.mAlwaysOnTop;
664 if (n != 0) return n;
665 n = mRotation - that.mRotation;
666 if (n != 0) return n;
667
668 n = mDisplayWindowingMode - that.mDisplayWindowingMode;
669 if (n != 0) return n;
670 n = mDisplayRotation - that.mDisplayRotation;
671 if (n != 0) return n;
672
673 // if (n != 0) return n;
674 return n;
675 }
676
677 /** @hide */
678 @Override
679 public boolean equals(@Nullable Object that) {
680 if (that == null) return false;
681 if (that == this) return true;
682 if (!(that instanceof WindowConfiguration)) {
683 return false;
684 }
685 return this.compareTo((WindowConfiguration) that) == 0;
686 }
687
688 /** @hide */
689 @Override
690 public int hashCode() {
691 int result = 0;
692 result = 31 * result + Objects.hashCode(mAppBounds);
693 result = 31 * result + Objects.hashCode(mBounds);
694 result = 31 * result + Objects.hashCode(mMaxBounds);
695 result = 31 * result + mWindowingMode;
696 result = 31 * result + mActivityType;
697 result = 31 * result + mAlwaysOnTop;
698 result = 31 * result + mRotation;
699 result = 31 * result + mDisplayWindowingMode;
700 result = 31 * result + mDisplayRotation;
701 return result;
702 }
703
704 /** @hide */
705 @Override
706 public String toString() {
707 return "{ mBounds=" + mBounds
708 + " mAppBounds=" + mAppBounds
709 + " mMaxBounds=" + mMaxBounds
710 + " mDisplayRotation=" + (mRotation == ROTATION_UNDEFINED
711 ? "undefined" : rotationToString(mDisplayRotation))
712 + " mWindowingMode=" + windowingModeToString(mWindowingMode)
713 + " mDisplayWindowingMode=" + windowingModeToString(mDisplayWindowingMode)
714 + " mActivityType=" + activityTypeToString(mActivityType)
715 + " mAlwaysOnTop=" + alwaysOnTopToString(mAlwaysOnTop)
716 + " mRotation=" + (mRotation == ROTATION_UNDEFINED
717 ? "undefined" : rotationToString(mRotation))
718 + "}";
719 }
720
721 /**
722 * Write to a protocol buffer output stream.
723 * Protocol buffer message definition at {@link android.app.WindowConfigurationProto}
724 *
725 * @param protoOutputStream Stream to write the WindowConfiguration object to.
726 * @param fieldId Field Id of the WindowConfiguration as defined in the parent message
727 * @hide
728 */
729 public void dumpDebug(ProtoOutputStream protoOutputStream, long fieldId) {
730 final long token = protoOutputStream.start(fieldId);
731 if (mAppBounds != null) {
732 mAppBounds.dumpDebug(protoOutputStream, APP_BOUNDS);
733 }
734 protoOutputStream.write(WINDOWING_MODE, mWindowingMode);
735 protoOutputStream.write(ACTIVITY_TYPE, mActivityType);
736 mBounds.dumpDebug(protoOutputStream, BOUNDS);
737 mMaxBounds.dumpDebug(protoOutputStream, MAX_BOUNDS);
738 protoOutputStream.end(token);
739 }
740
741 /**
742 * Read from a protocol buffer input stream.
743 * Protocol buffer message definition at {@link android.app.WindowConfigurationProto}
744 *
745 * @param proto Stream to read the WindowConfiguration object from.
746 * @param fieldId Field Id of the WindowConfiguration as defined in the parent message
747 * @hide
748 */
749 public void readFromProto(ProtoInputStream proto, long fieldId)
750 throws IOException, WireTypeMismatchException {
751 final long token = proto.start(fieldId);
752 try {
753 while (proto.nextField() != ProtoInputStream.NO_MORE_FIELDS) {
754 switch (proto.getFieldNumber()) {
755 case (int) APP_BOUNDS:
756 mAppBounds = new Rect();
757 mAppBounds.readFromProto(proto, APP_BOUNDS);
758 break;
759 case (int) BOUNDS:
760 mBounds.readFromProto(proto, BOUNDS);
761 break;
762 case (int) MAX_BOUNDS:
763 mMaxBounds.readFromProto(proto, MAX_BOUNDS);
764 break;
765 case (int) WINDOWING_MODE:
766 mWindowingMode = proto.readInt(WINDOWING_MODE);
767 break;
768 case (int) ACTIVITY_TYPE:
769 mActivityType = proto.readInt(ACTIVITY_TYPE);
770 break;
771 }
772 }
773 } finally {
774 // Let caller handle any exceptions
775 proto.end(token);
776 }
777 }
778
779 /**
780 * Returns true if the activities associated with this window configuration display a shadow
781 * around their border.
782 * @hide
783 */
784 public boolean hasWindowShadow() {
785 return mWindowingMode != WINDOWING_MODE_MULTI_WINDOW && tasksAreFloating();
786 }
787
788 /**
789 * Returns true if the activities associated with this window configuration display a decor
790 * view.
791 * @hide
792 */
793 public boolean hasWindowDecorCaption() {
794 return mActivityType == ACTIVITY_TYPE_STANDARD && (mWindowingMode == WINDOWING_MODE_FREEFORM
795 || mDisplayWindowingMode == WINDOWING_MODE_FREEFORM);
796 }
797
798 /**
799 * Returns true if the tasks associated with this window configuration can be resized
800 * independently of their parent container.
801 * @hide
802 */
803 public boolean canResizeTask() {
804 return mWindowingMode == WINDOWING_MODE_FREEFORM
805 || mWindowingMode == WINDOWING_MODE_MULTI_WINDOW;
806 }
807
808 /** Returns true if the task bounds should persist across power cycles.
809 * @hide */
810 public boolean persistTaskBounds() {
811 return mWindowingMode == WINDOWING_MODE_FREEFORM;
812 }
813
814 /**
815 * Returns true if the tasks associated with this window configuration are floating.
816 * Floating tasks are laid out differently as they are allowed to extend past the display bounds
817 * without overscan insets.
818 * @hide
819 */
820 public boolean tasksAreFloating() {
821 return isFloating(mWindowingMode);
822 }
823
824 /** Returns true if the windowingMode represents a floating window. */
825 public static boolean isFloating(@WindowingMode int windowingMode) {
826 return windowingMode == WINDOWING_MODE_FREEFORM || windowingMode == WINDOWING_MODE_PINNED;
827 }
828
829 /**
830 * Returns {@code true} if the windowingMode represents a window in multi-window mode.
831 * I.e. sharing the screen with another activity.
832 * @hide
833 */
834 public static boolean inMultiWindowMode(int windowingMode) {
835 return windowingMode != WINDOWING_MODE_FULLSCREEN
836 && windowingMode != WINDOWING_MODE_UNDEFINED;
837 }
838
839 /**
840 * Returns true if the windows associated with this window configuration can receive input keys.
841 * @hide
842 */
843 public boolean canReceiveKeys() {
844 return mWindowingMode != WINDOWING_MODE_PINNED;
845 }
846
847 /**
848 * Returns true if the container associated with this window configuration is always-on-top of
849 * its siblings.
850 * @hide
851 */
852 public boolean isAlwaysOnTop() {
853 if (mWindowingMode == WINDOWING_MODE_PINNED) return true;
854 if (mActivityType == ACTIVITY_TYPE_DREAM) return true;
855 if (mAlwaysOnTop != ALWAYS_ON_TOP_ON) return false;
856 return mWindowingMode == WINDOWING_MODE_FREEFORM
857 || mWindowingMode == WINDOWING_MODE_MULTI_WINDOW;
858 }
859
860 /**
861 * Returns true if any visible windows belonging to apps with this window configuration should
862 * be kept on screen when the app is killed due to something like the low memory killer.
863 * @hide
864 */
865 public boolean keepVisibleDeadAppWindowOnScreen() {
866 return mWindowingMode != WINDOWING_MODE_PINNED;
867 }
868
869 /**
870 * Returns true if the backdrop on the client side should match the frame of the window.
871 * Returns false, if the backdrop should be fullscreen.
872 * @hide
873 */
874 public boolean useWindowFrameForBackdrop() {
875 return mWindowingMode == WINDOWING_MODE_FREEFORM || mWindowingMode == WINDOWING_MODE_PINNED;
876 }
877
878 /**
879 * Returns true if windows in this container should be given move animations by default.
880 * @hide
881 */
882 public boolean hasMovementAnimations() {
883 return mWindowingMode != WINDOWING_MODE_PINNED;
884 }
885
886 /**
887 * Returns true if this container can be put in {@link #WINDOWING_MODE_MULTI_WINDOW}
888 * windowing mode based on its current state.
889 * @hide
890 */
891 public boolean supportSplitScreenWindowingMode() {
892 return supportSplitScreenWindowingMode(mActivityType);
893 }
894
895 /** @hide */
896 public static boolean supportSplitScreenWindowingMode(int activityType) {
897 return activityType != ACTIVITY_TYPE_ASSISTANT && activityType != ACTIVITY_TYPE_DREAM;
898 }
899
900 /** @hide */
901 public static String windowingModeToString(@WindowingMode int windowingMode) {
902 switch (windowingMode) {
903 case WINDOWING_MODE_UNDEFINED: return "undefined";
904 case WINDOWING_MODE_FULLSCREEN: return "fullscreen";
905 case WINDOWING_MODE_MULTI_WINDOW: return "multi-window";
906 case WINDOWING_MODE_PINNED: return "pinned";
907 case WINDOWING_MODE_FREEFORM: return "freeform";
908 }
909 return String.valueOf(windowingMode);
910 }
911
912 /** @hide */
913 public static String activityTypeToString(@ActivityType int applicationType) {
914 switch (applicationType) {
915 case ACTIVITY_TYPE_UNDEFINED: return "undefined";
916 case ACTIVITY_TYPE_STANDARD: return "standard";
917 case ACTIVITY_TYPE_HOME: return "home";
918 case ACTIVITY_TYPE_RECENTS: return "recents";
919 case ACTIVITY_TYPE_ASSISTANT: return "assistant";
920 case ACTIVITY_TYPE_DREAM: return "dream";
921 }
922 return String.valueOf(applicationType);
923 }
924
925 /** @hide */
926 public static String alwaysOnTopToString(@AlwaysOnTop int alwaysOnTop) {
927 switch (alwaysOnTop) {
928 case ALWAYS_ON_TOP_UNDEFINED: return "undefined";
929 case ALWAYS_ON_TOP_ON: return "on";
930 case ALWAYS_ON_TOP_OFF: return "off";
931 }
932 return String.valueOf(alwaysOnTop);
933 }
934 }