1 /*
2  * Copyright (C) 2006 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.view;
18 
19 import static android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
20 import static android.Manifest.permission.HIDE_OVERLAY_WINDOWS;
21 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
22 import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
23 import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
24 
25 import android.annotation.ColorInt;
26 import android.annotation.DrawableRes;
27 import android.annotation.FlaggedApi;
28 import android.annotation.FloatRange;
29 import android.annotation.IdRes;
30 import android.annotation.LayoutRes;
31 import android.annotation.NonNull;
32 import android.annotation.Nullable;
33 import android.annotation.RequiresPermission;
34 import android.annotation.StyleRes;
35 import android.annotation.SystemApi;
36 import android.annotation.TestApi;
37 import android.annotation.UiContext;
38 import android.app.WindowConfiguration;
39 import android.compat.annotation.UnsupportedAppUsage;
40 import android.content.Context;
41 import android.content.pm.ActivityInfo;
42 import android.content.res.Configuration;
43 import android.content.res.Resources;
44 import android.content.res.TypedArray;
45 import android.graphics.Insets;
46 import android.graphics.PixelFormat;
47 import android.graphics.Rect;
48 import android.graphics.drawable.Drawable;
49 import android.media.session.MediaController;
50 import android.net.Uri;
51 import android.os.Build;
52 import android.os.Bundle;
53 import android.os.Handler;
54 import android.os.IBinder;
55 import android.transition.Scene;
56 import android.transition.Transition;
57 import android.transition.TransitionManager;
58 import android.util.Pair;
59 import android.view.View.OnApplyWindowInsetsListener;
60 import android.view.accessibility.AccessibilityEvent;
61 import android.window.OnBackInvokedDispatcher;
62 
63 import java.util.Collections;
64 import java.util.List;
65 
66 /**
67  * Abstract base class for a top-level window look and behavior policy.  An
68  * instance of this class should be used as the top-level view added to the
69  * window manager. It provides standard UI policies such as a background, title
70  * area, default key processing, etc.
71  *
72  * <p>The framework will instantiate an implementation of this class on behalf of the application.
73  */
74 public abstract class Window {
75     /** Flag for the "options panel" feature.  This is enabled by default. */
76     public static final int FEATURE_OPTIONS_PANEL = 0;
77     /** Flag for the "no title" feature, turning off the title at the top
78      *  of the screen. */
79     public static final int FEATURE_NO_TITLE = 1;
80 
81     /**
82      * Flag for the progress indicator feature.
83      *
84      * @deprecated No longer supported starting in API 21.
85      */
86     @Deprecated
87     public static final int FEATURE_PROGRESS = 2;
88 
89     /** Flag for having an icon on the left side of the title bar */
90     public static final int FEATURE_LEFT_ICON = 3;
91     /** Flag for having an icon on the right side of the title bar */
92     public static final int FEATURE_RIGHT_ICON = 4;
93 
94     /**
95      * Flag for indeterminate progress.
96      *
97      * @deprecated No longer supported starting in API 21.
98      */
99     @Deprecated
100     public static final int FEATURE_INDETERMINATE_PROGRESS = 5;
101 
102     /** Flag for the context menu.  This is enabled by default. */
103     public static final int FEATURE_CONTEXT_MENU = 6;
104     /** Flag for custom title. You cannot combine this feature with other title features. */
105     public static final int FEATURE_CUSTOM_TITLE = 7;
106     /**
107      * Flag for enabling the Action Bar.
108      * This is enabled by default for some devices. The Action Bar
109      * replaces the title bar and provides an alternate location
110      * for an on-screen menu button on some devices.
111      */
112     public static final int FEATURE_ACTION_BAR = 8;
113     /**
114      * Flag for requesting an Action Bar that overlays window content.
115      * Normally an Action Bar will sit in the space above window content, but if this
116      * feature is requested along with {@link #FEATURE_ACTION_BAR} it will be layered over
117      * the window content itself. This is useful if you would like your app to have more control
118      * over how the Action Bar is displayed, such as letting application content scroll beneath
119      * an Action Bar with a transparent background or otherwise displaying a transparent/translucent
120      * Action Bar over application content.
121      *
122      * <p>This mode is especially useful with {@link View#SYSTEM_UI_FLAG_FULLSCREEN
123      * View.SYSTEM_UI_FLAG_FULLSCREEN}, which allows you to seamlessly hide the
124      * action bar in conjunction with other screen decorations.
125      *
126      * <p>As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, when an
127      * ActionBar is in this mode it will adjust the insets provided to
128      * {@link View#fitSystemWindows(android.graphics.Rect) View.fitSystemWindows(Rect)}
129      * to include the content covered by the action bar, so you can do layout within
130      * that space.
131      */
132     public static final int FEATURE_ACTION_BAR_OVERLAY = 9;
133     /**
134      * Flag for specifying the behavior of action modes when an Action Bar is not present.
135      * If overlay is enabled, the action mode UI will be allowed to cover existing window content.
136      */
137     public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
138     /**
139      * Flag for requesting a decoration-free window that is dismissed by swiping from the left.
140      *
141      * @deprecated Swipe-to-dismiss isn't functional anymore.
142      */
143     @Deprecated
144     public static final int FEATURE_SWIPE_TO_DISMISS = 11;
145     /**
146      * Flag for requesting that window content changes should be animated using a
147      * TransitionManager.
148      *
149      * <p>The TransitionManager is set using
150      * {@link #setTransitionManager(android.transition.TransitionManager)}. If none is set,
151      * a default TransitionManager will be used.</p>
152      *
153      * @see #setContentView
154      */
155     public static final int FEATURE_CONTENT_TRANSITIONS = 12;
156 
157     /**
158      * Enables Activities to run Activity Transitions either through sending or receiving
159      * ActivityOptions bundle created with
160      * {@link android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,
161      * android.util.Pair[])} or {@link android.app.ActivityOptions#makeSceneTransitionAnimation(
162      * android.app.Activity, View, String)}.
163      */
164     public static final int FEATURE_ACTIVITY_TRANSITIONS = 13;
165 
166     /**
167      * Max value used as a feature ID
168      * @hide
169      */
170     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
171     public static final int FEATURE_MAX = FEATURE_ACTIVITY_TRANSITIONS;
172 
173     /**
174      * Flag for setting the progress bar's visibility to VISIBLE.
175      *
176      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
177      *             supported starting in API 21.
178      */
179     @Deprecated
180     public static final int PROGRESS_VISIBILITY_ON = -1;
181 
182     /**
183      * Flag for setting the progress bar's visibility to GONE.
184      *
185      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
186      *             supported starting in API 21.
187      */
188     @Deprecated
189     public static final int PROGRESS_VISIBILITY_OFF = -2;
190 
191     /**
192      * Flag for setting the progress bar's indeterminate mode on.
193      *
194      * @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
195      *             are no longer supported starting in API 21.
196      */
197     @Deprecated
198     public static final int PROGRESS_INDETERMINATE_ON = -3;
199 
200     /**
201      * Flag for setting the progress bar's indeterminate mode off.
202      *
203      * @deprecated {@link #FEATURE_INDETERMINATE_PROGRESS} and related methods
204      *             are no longer supported starting in API 21.
205      */
206     @Deprecated
207     public static final int PROGRESS_INDETERMINATE_OFF = -4;
208 
209     /**
210      * Starting value for the (primary) progress.
211      *
212      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
213      *             supported starting in API 21.
214      */
215     @Deprecated
216     public static final int PROGRESS_START = 0;
217 
218     /**
219      * Ending value for the (primary) progress.
220      *
221      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
222      *             supported starting in API 21.
223      */
224     @Deprecated
225     public static final int PROGRESS_END = 10000;
226 
227     /**
228      * Lowest possible value for the secondary progress.
229      *
230      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
231      *             supported starting in API 21.
232      */
233     @Deprecated
234     public static final int PROGRESS_SECONDARY_START = 20000;
235 
236     /**
237      * Highest possible value for the secondary progress.
238      *
239      * @deprecated {@link #FEATURE_PROGRESS} and related methods are no longer
240      *             supported starting in API 21.
241      */
242     @Deprecated
243     public static final int PROGRESS_SECONDARY_END = 30000;
244 
245     /**
246      * The transitionName for the status bar background View when a custom background is used.
247      * @see android.view.Window#setStatusBarColor(int)
248      */
249     public static final String STATUS_BAR_BACKGROUND_TRANSITION_NAME = "android:status:background";
250 
251     /**
252      * The transitionName for the navigation bar background View when a custom background is used.
253      * @see android.view.Window#setNavigationBarColor(int)
254      */
255     public static final String NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME =
256             "android:navigation:background";
257 
258     /**
259      * The default features enabled.
260      * @deprecated use {@link #getDefaultFeatures(android.content.Context)} instead.
261      */
262     @Deprecated
263     @SuppressWarnings({"PointlessBitwiseExpression"})
264     protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
265             (1 << FEATURE_CONTEXT_MENU);
266 
267     /**
268      * The ID that the main layout in the XML layout file should have.
269      */
270     public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
271 
272     /**
273      * Flag for letting the theme drive the color of the window caption controls. Use with
274      * {@link #setDecorCaptionShade(int)}. This is the default value.
275      */
276     public static final int DECOR_CAPTION_SHADE_AUTO = 0;
277     /**
278      * Flag for setting light-color controls on the window caption. Use with
279      * {@link #setDecorCaptionShade(int)}.
280      */
281     public static final int DECOR_CAPTION_SHADE_LIGHT = 1;
282     /**
283      * Flag for setting dark-color controls on the window caption. Use with
284      * {@link #setDecorCaptionShade(int)}.
285      */
286     public static final int DECOR_CAPTION_SHADE_DARK = 2;
287 
288     @UnsupportedAppUsage
289     @UiContext
290     private final Context mContext;
291 
292     @UnsupportedAppUsage
293     private TypedArray mWindowStyle;
294     @UnsupportedAppUsage
295     private Callback mCallback;
296     private OnWindowDismissedCallback mOnWindowDismissedCallback;
297     private OnWindowSwipeDismissedCallback mOnWindowSwipeDismissedCallback;
298     private WindowControllerCallback mWindowControllerCallback;
299     @WindowInsetsController.Appearance
300     private int mSystemBarAppearance;
301     private DecorCallback mDecorCallback;
302     private OnRestrictedCaptionAreaChangedListener mOnRestrictedCaptionAreaChangedListener;
303     private Rect mRestrictedCaptionAreaRect;
304     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
305     private WindowManager mWindowManager;
306     @UnsupportedAppUsage
307     private IBinder mAppToken;
308     @UnsupportedAppUsage
309     private String mAppName;
310     @UnsupportedAppUsage
311     private boolean mHardwareAccelerated;
312     private Window mContainer;
313     private Window mActiveChild;
314     private boolean mIsActive = false;
315     private boolean mHasChildren = false;
316     private boolean mCloseOnTouchOutside = false;
317     private boolean mSetCloseOnTouchOutside = false;
318     private int mForcedWindowFlags = 0;
319 
320     @UnsupportedAppUsage
321     private int mFeatures;
322     @UnsupportedAppUsage
323     private int mLocalFeatures;
324 
325     private boolean mHaveWindowFormat = false;
326     private boolean mHaveDimAmount = false;
327     private int mDefaultWindowFormat = PixelFormat.OPAQUE;
328 
329     private boolean mHasSoftInputMode = false;
330 
331     @UnsupportedAppUsage
332     private boolean mDestroyed;
333 
334     private boolean mOverlayWithDecorCaptionEnabled = true;
335     private boolean mCloseOnSwipeEnabled = false;
336 
337     /**
338      * To check if toolkitSetFrameRateReadOnly flag is enabled
339      *
340      * @hide
341      */
342     protected static boolean sToolkitSetFrameRateReadOnlyFlagValue =
343                 android.view.flags.Flags.toolkitSetFrameRateReadOnly();
344 
345     // The current window attributes.
346     @UnsupportedAppUsage
347     private final WindowManager.LayoutParams mWindowAttributes =
348         new WindowManager.LayoutParams();
349 
350     /**
351      * API from a Window back to its caller.  This allows the client to
352      * intercept key dispatching, panels and menus, etc.
353      */
354     public interface Callback {
355         /**
356          * Called to process key events.  At the very least your
357          * implementation must call
358          * {@link android.view.Window#superDispatchKeyEvent} to do the
359          * standard key processing.
360          *
361          * @param event The key event.
362          *
363          * @return boolean Return true if this event was consumed.
364          */
dispatchKeyEvent(KeyEvent event)365         public boolean dispatchKeyEvent(KeyEvent event);
366 
367         /**
368          * Called to process a key shortcut event.
369          * At the very least your implementation must call
370          * {@link android.view.Window#superDispatchKeyShortcutEvent} to do the
371          * standard key shortcut processing.
372          *
373          * @param event The key shortcut event.
374          * @return True if this event was consumed.
375          */
dispatchKeyShortcutEvent(KeyEvent event)376         public boolean dispatchKeyShortcutEvent(KeyEvent event);
377 
378         /**
379          * Called to process touch screen events.  At the very least your
380          * implementation must call
381          * {@link android.view.Window#superDispatchTouchEvent} to do the
382          * standard touch screen processing.
383          *
384          * @param event The touch screen event.
385          *
386          * @return boolean Return true if this event was consumed.
387          */
dispatchTouchEvent(MotionEvent event)388         public boolean dispatchTouchEvent(MotionEvent event);
389 
390         /**
391          * Called to process trackball events.  At the very least your
392          * implementation must call
393          * {@link android.view.Window#superDispatchTrackballEvent} to do the
394          * standard trackball processing.
395          *
396          * @param event The trackball event.
397          *
398          * @return boolean Return true if this event was consumed.
399          */
dispatchTrackballEvent(MotionEvent event)400         public boolean dispatchTrackballEvent(MotionEvent event);
401 
402         /**
403          * Called to process generic motion events.  At the very least your
404          * implementation must call
405          * {@link android.view.Window#superDispatchGenericMotionEvent} to do the
406          * standard processing.
407          *
408          * @param event The generic motion event.
409          *
410          * @return boolean Return true if this event was consumed.
411          */
dispatchGenericMotionEvent(MotionEvent event)412         public boolean dispatchGenericMotionEvent(MotionEvent event);
413 
414         /**
415          * Called to process population of {@link AccessibilityEvent}s.
416          *
417          * @param event The event.
418          *
419          * @return boolean Return true if event population was completed.
420          */
dispatchPopulateAccessibilityEvent(AccessibilityEvent event)421         public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event);
422 
423         /**
424          * Instantiate the view to display in the panel for 'featureId'.
425          * You can return null, in which case the default content (typically
426          * a menu) will be created for you.
427          *
428          * @param featureId Which panel is being created.
429          *
430          * @return view The top-level view to place in the panel.
431          *
432          * @see #onPreparePanel
433          */
434         @Nullable
onCreatePanelView(int featureId)435         public View onCreatePanelView(int featureId);
436 
437         /**
438          * Initialize the contents of the menu for panel 'featureId'.  This is
439          * called if onCreatePanelView() returns null, giving you a standard
440          * menu in which you can place your items.  It is only called once for
441          * the panel, the first time it is shown.
442          *
443          * <p>You can safely hold on to <var>menu</var> (and any items created
444          * from it), making modifications to it as desired, until the next
445          * time onCreatePanelMenu() is called for this feature.
446          *
447          * @param featureId The panel being created.
448          * @param menu The menu inside the panel.
449          *
450          * @return boolean You must return true for the panel to be displayed;
451          *         if you return false it will not be shown.
452          */
onCreatePanelMenu(int featureId, @NonNull Menu menu)453         boolean onCreatePanelMenu(int featureId, @NonNull Menu menu);
454 
455         /**
456          * Prepare a panel to be displayed.  This is called right before the
457          * panel window is shown, every time it is shown.
458          *
459          * @param featureId The panel that is being displayed.
460          * @param view The View that was returned by onCreatePanelView().
461          * @param menu If onCreatePanelView() returned null, this is the Menu
462          *             being displayed in the panel.
463          *
464          * @return boolean You must return true for the panel to be displayed;
465          *         if you return false it will not be shown.
466          *
467          * @see #onCreatePanelView
468          */
onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu)469         boolean onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu);
470 
471         /**
472          * Called when a panel's menu is opened by the user. This may also be
473          * called when the menu is changing from one type to another (for
474          * example, from the icon menu to the expanded menu).
475          *
476          * @param featureId The panel that the menu is in.
477          * @param menu The menu that is opened.
478          * @return Return true to allow the menu to open, or false to prevent
479          *         the menu from opening.
480          */
onMenuOpened(int featureId, @NonNull Menu menu)481         boolean onMenuOpened(int featureId, @NonNull Menu menu);
482 
483         /**
484          * Called when a panel's menu item has been selected by the user.
485          *
486          * @param featureId The panel that the menu is in.
487          * @param item The menu item that was selected.
488          *
489          * @return boolean Return true to finish processing of selection, or
490          *         false to perform the normal menu handling (calling its
491          *         Runnable or sending a Message to its target Handler).
492          */
onMenuItemSelected(int featureId, @NonNull MenuItem item)493         boolean onMenuItemSelected(int featureId, @NonNull MenuItem item);
494 
495         /**
496          * This is called whenever the current window attributes change.
497          *
498          */
onWindowAttributesChanged(WindowManager.LayoutParams attrs)499         public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
500 
501         /**
502          * This hook is called whenever the content view of the screen changes
503          * (due to a call to
504          * {@link Window#setContentView(View, android.view.ViewGroup.LayoutParams)
505          * Window.setContentView} or
506          * {@link Window#addContentView(View, android.view.ViewGroup.LayoutParams)
507          * Window.addContentView}).
508          */
onContentChanged()509         public void onContentChanged();
510 
511         /**
512          * This hook is called whenever the window focus changes.  See
513          * {@link View#onWindowFocusChanged(boolean)
514          * View.onWindowFocusChangedNotLocked(boolean)} for more information.
515          *
516          * @param hasFocus Whether the window now has focus.
517          */
onWindowFocusChanged(boolean hasFocus)518         public void onWindowFocusChanged(boolean hasFocus);
519 
520         /**
521          * Called when the window has been attached to the window manager.
522          * See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
523          * for more information.
524          */
onAttachedToWindow()525         public void onAttachedToWindow();
526 
527         /**
528          * Called when the window has been detached from the window manager.
529          * See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
530          * for more information.
531          */
onDetachedFromWindow()532         public void onDetachedFromWindow();
533 
534         /**
535          * Called when a panel is being closed.  If another logical subsequent
536          * panel is being opened (and this panel is being closed to make room for the subsequent
537          * panel), this method will NOT be called.
538          *
539          * @param featureId The panel that is being displayed.
540          * @param menu If onCreatePanelView() returned null, this is the Menu
541          *            being displayed in the panel.
542          */
onPanelClosed(int featureId, @NonNull Menu menu)543         void onPanelClosed(int featureId, @NonNull Menu menu);
544 
545         /**
546          * Called when the user signals the desire to start a search.
547          *
548          * @return true if search launched, false if activity refuses (blocks)
549          *
550          * @see android.app.Activity#onSearchRequested()
551          */
onSearchRequested()552         public boolean onSearchRequested();
553 
554         /**
555          * Called when the user signals the desire to start a search.
556          *
557          * @param searchEvent A {@link SearchEvent} describing the signal to
558          *                   start a search.
559          * @return true if search launched, false if activity refuses (blocks)
560          */
onSearchRequested(SearchEvent searchEvent)561         public boolean onSearchRequested(SearchEvent searchEvent);
562 
563         /**
564          * Called when an action mode is being started for this window. Gives the
565          * callback an opportunity to handle the action mode in its own unique and
566          * beautiful way. If this method returns null the system can choose a way
567          * to present the mode or choose not to start the mode at all. This is equivalent
568          * to {@link #onWindowStartingActionMode(android.view.ActionMode.Callback, int)}
569          * with type {@link ActionMode#TYPE_PRIMARY}.
570          *
571          * @param callback Callback to control the lifecycle of this action mode
572          * @return The ActionMode that was started, or null if the system should present it
573          */
574         @Nullable
onWindowStartingActionMode(ActionMode.Callback callback)575         public ActionMode onWindowStartingActionMode(ActionMode.Callback callback);
576 
577         /**
578          * Called when an action mode is being started for this window. Gives the
579          * callback an opportunity to handle the action mode in its own unique and
580          * beautiful way. If this method returns null the system can choose a way
581          * to present the mode or choose not to start the mode at all.
582          *
583          * @param callback Callback to control the lifecycle of this action mode
584          * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}.
585          * @return The ActionMode that was started, or null if the system should present it
586          */
587         @Nullable
onWindowStartingActionMode(ActionMode.Callback callback, int type)588         public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type);
589 
590         /**
591          * Called when an action mode has been started. The appropriate mode callback
592          * method will have already been invoked.
593          *
594          * @param mode The new mode that has just been started.
595          */
onActionModeStarted(ActionMode mode)596         public void onActionModeStarted(ActionMode mode);
597 
598         /**
599          * Called when an action mode has been finished. The appropriate mode callback
600          * method will have already been invoked.
601          *
602          * @param mode The mode that was just finished.
603          */
onActionModeFinished(ActionMode mode)604         public void onActionModeFinished(ActionMode mode);
605 
606         /**
607          * Called when Keyboard Shortcuts are requested for the current window.
608          *
609          * @param data The data list to populate with shortcuts.
610          * @param menu The current menu, which may be null.
611          * @param deviceId The id for the connected device the shortcuts should be provided for.
612          */
onProvideKeyboardShortcuts( List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId)613         default public void onProvideKeyboardShortcuts(
614                 List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId) { };
615 
616         /**
617          * Called when pointer capture is enabled or disabled for the current window.
618          *
619          * @param hasCapture True if the window has pointer capture.
620          */
onPointerCaptureChanged(boolean hasCapture)621         default public void onPointerCaptureChanged(boolean hasCapture) { };
622     }
623 
624     /** @hide */
625     public interface OnWindowDismissedCallback {
626         /**
627          * Called when a window is dismissed. This informs the callback that the
628          * window is gone, and it should finish itself.
629          * @param finishTask True if the task should also be finished.
630          * @param suppressWindowTransition True if the resulting exit and enter window transition
631          * animations should be suppressed.
632          */
onWindowDismissed(boolean finishTask, boolean suppressWindowTransition)633         void onWindowDismissed(boolean finishTask, boolean suppressWindowTransition);
634     }
635 
636     /** @hide */
637     public interface OnWindowSwipeDismissedCallback {
638         /**
639          * Called when a window is swipe dismissed. This informs the callback that the
640          * window is gone, and it should finish itself.
641          * @param finishTask True if the task should also be finished.
642          * @param suppressWindowTransition True if the resulting exit and enter window transition
643          * animations should be suppressed.
644          */
onWindowSwipeDismissed()645         void onWindowSwipeDismissed();
646     }
647 
648     /** @hide */
649     public interface WindowControllerCallback {
650         /**
651          * Moves the activity between {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing
652          * mode and {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}.
653          */
toggleFreeformWindowingMode()654         void toggleFreeformWindowingMode();
655 
656         /**
657          * Puts the activity in picture-in-picture mode if the activity supports.
658          * @see android.R.attr#supportsPictureInPicture
659          */
enterPictureInPictureModeIfPossible()660         void enterPictureInPictureModeIfPossible();
661 
662         /** Returns whether the window belongs to the task root. */
isTaskRoot()663         boolean isTaskRoot();
664 
665         /**
666          * Update the status bar color to a forced one.
667          */
updateStatusBarColor(int color)668         void updateStatusBarColor(int color);
669 
670         /**
671          * Update the status bar appearance.
672          */
673 
updateSystemBarsAppearance(int appearance)674         void updateSystemBarsAppearance(int appearance);
675 
676         /**
677          * Update the navigation bar color to a forced one.
678          */
updateNavigationBarColor(int color)679         void updateNavigationBarColor(int color);
680     }
681 
682     /** @hide */
683     public interface DecorCallback {
684         /**
685          * Called from
686          * {@link com.android.internal.policy.DecorView#onSystemBarAppearanceChanged(int)}.
687          *
688          * @param appearance The newly applied appearance.
689          */
onSystemBarAppearanceChanged(@indowInsetsController.Appearance int appearance)690         void onSystemBarAppearanceChanged(@WindowInsetsController.Appearance int appearance);
691 
692         /**
693          * Called from
694          * {@link com.android.internal.policy.DecorView#updateColorViews(WindowInsets, boolean)}
695          * when {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackground} is
696          * being updated.
697          *
698          * @param drawLegacyNavigationBarBackground the new value that is being set to
699          *        {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackground}.
700          * @return The value to be set to
701          *   {@link com.android.internal.policy.DecorView#mDrawLegacyNavigationBarBackgroundHandled}
702          *         on behalf of the {@link com.android.internal.policy.DecorView}.
703          *         {@code true} to tell that the Window can render the legacy navigation bar
704          *         background on behalf of the {@link com.android.internal.policy.DecorView}.
705          *         {@code false} to let {@link com.android.internal.policy.DecorView} handle it.
706          */
onDrawLegacyNavigationBarBackgroundChanged( boolean drawLegacyNavigationBarBackground)707         boolean onDrawLegacyNavigationBarBackgroundChanged(
708                 boolean drawLegacyNavigationBarBackground);
709     }
710 
711     /**
712      * Callback for clients that want to be aware of where caption draws content.
713      */
714     public interface OnRestrictedCaptionAreaChangedListener {
715         /**
716          * Called when the area where caption draws content changes.
717          *
718          * @param rect The area where caption content is positioned, relative to the top view.
719          */
onRestrictedCaptionAreaChanged(Rect rect)720         void onRestrictedCaptionAreaChanged(Rect rect);
721     }
722 
723     /**
724      * Callback for clients that want frame timing information for each
725      * frame rendered by the Window.
726      */
727     public interface OnFrameMetricsAvailableListener {
728         /**
729          * Called when information is available for the previously rendered frame.
730          *
731          * Reports can be dropped if this callback takes too
732          * long to execute, as the report producer cannot wait for the consumer to
733          * complete.
734          *
735          * It is highly recommended that clients copy the passed in FrameMetrics
736          * via {@link FrameMetrics#FrameMetrics(FrameMetrics)} within this method and defer
737          * additional computation or storage to another thread to avoid unnecessarily
738          * dropping reports.
739          *
740          * @param window The {@link Window} on which the frame was displayed.
741          * @param frameMetrics the available metrics. This object is reused on every call
742          * and thus <strong>this reference is not valid outside the scope of this method</strong>.
743          * @param dropCountSinceLastInvocation the number of reports dropped since the last time
744          * this callback was invoked.
745          */
onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics, int dropCountSinceLastInvocation)746         void onFrameMetricsAvailable(Window window, FrameMetrics frameMetrics,
747                 int dropCountSinceLastInvocation);
748     }
749 
750     /**
751      * Listener for applying window insets on the content of a window. Used only by the framework to
752      * fit content according to legacy SystemUI flags.
753      *
754      * @hide
755      */
756     public interface OnContentApplyWindowInsetsListener {
757 
758         /**
759          * Called when the window needs to apply insets on the container of its content view which
760          * are set by calling {@link #setContentView}. The method should determine what insets to
761          * apply on the container of the root level content view and what should be dispatched to
762          * the content view's
763          * {@link View#setOnApplyWindowInsetsListener(OnApplyWindowInsetsListener)} through the view
764          * hierarchy.
765          *
766          * @param view The view for which to apply insets. Must not be directly modified.
767          * @param insets The root level insets that are about to be dispatched
768          * @return A pair, with the first element containing the insets to apply as margin to the
769          * root-level content views, and the second element determining what should be
770          * dispatched to the content view.
771          */
772         @NonNull
onContentApplyWindowInsets(@onNull View view, @NonNull WindowInsets insets)773         Pair<Insets, WindowInsets> onContentApplyWindowInsets(@NonNull View view,
774                 @NonNull WindowInsets insets);
775     }
776 
777 
Window(@iContext Context context)778     public Window(@UiContext Context context) {
779         mContext = context;
780         mFeatures = mLocalFeatures = getDefaultFeatures(context);
781     }
782 
783     /**
784      * Return the Context this window policy is running in, for retrieving
785      * resources and other information.
786      *
787      * @return Context The Context that was supplied to the constructor.
788      */
789     @UiContext
getContext()790     public final Context getContext() {
791         return mContext;
792     }
793 
794     /**
795      * Return the {@link android.R.styleable#Window} attributes from this
796      * window's theme.
797      */
getWindowStyle()798     public final TypedArray getWindowStyle() {
799         synchronized (this) {
800             if (mWindowStyle == null) {
801                 mWindowStyle = mContext.obtainStyledAttributes(
802                         com.android.internal.R.styleable.Window);
803             }
804             return mWindowStyle;
805         }
806     }
807 
808     /**
809      * Set the container for this window.  If not set, the DecorWindow
810      * operates as a top-level window; otherwise, it negotiates with the
811      * container to display itself appropriately.
812      *
813      * @param container The desired containing Window.
814      */
setContainer(Window container)815     public void setContainer(Window container) {
816         mContainer = container;
817         if (container != null) {
818             // Embedded screens never have a title.
819             mFeatures |= 1<<FEATURE_NO_TITLE;
820             mLocalFeatures |= 1<<FEATURE_NO_TITLE;
821             container.mHasChildren = true;
822         }
823     }
824 
825     /**
826      * Return the container for this Window.
827      *
828      * @return Window The containing window, or null if this is a
829      *         top-level window.
830      */
getContainer()831     public final Window getContainer() {
832         return mContainer;
833     }
834 
hasChildren()835     public final boolean hasChildren() {
836         return mHasChildren;
837     }
838 
839     /** @hide */
destroy()840     public final void destroy() {
841         mDestroyed = true;
842         onDestroy();
843     }
844 
845     /** @hide */
onDestroy()846     protected void onDestroy() {
847     }
848 
849     /** @hide */
850     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
isDestroyed()851     public final boolean isDestroyed() {
852         return mDestroyed;
853     }
854 
855     /**
856      * Set the window manager for use by this Window to, for example,
857      * display panels.  This is <em>not</em> used for displaying the
858      * Window itself -- that must be done by the client.
859      *
860      * @param wm The window manager for adding new windows.
861      */
setWindowManager(WindowManager wm, IBinder appToken, String appName)862     public void setWindowManager(WindowManager wm, IBinder appToken, String appName) {
863         setWindowManager(wm, appToken, appName, false);
864     }
865 
866     /**
867      * Set the window manager for use by this Window to, for example,
868      * display panels.  This is <em>not</em> used for displaying the
869      * Window itself -- that must be done by the client.
870      *
871      * @param wm The window manager for adding new windows.
872      */
setWindowManager(WindowManager wm, IBinder appToken, String appName, boolean hardwareAccelerated)873     public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
874             boolean hardwareAccelerated) {
875         mAppToken = appToken;
876         mAppName = appName;
877         mHardwareAccelerated = hardwareAccelerated;
878         if (wm == null) {
879             wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
880         }
881         mWindowManager = ((WindowManagerImpl)wm).createLocalWindowManager(this);
882     }
883 
adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp)884     void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
885         CharSequence curTitle = wp.getTitle();
886         if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
887                 wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
888             if (wp.token == null) {
889                 View decor = peekDecorView();
890                 if (decor != null) {
891                     wp.token = decor.getWindowToken();
892                 }
893             }
894             if (curTitle == null || curTitle.length() == 0) {
895                 final StringBuilder title = new StringBuilder(32);
896                 if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
897                     title.append("Media");
898                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
899                     title.append("MediaOvr");
900                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
901                     title.append("Panel");
902                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
903                     title.append("SubPanel");
904                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL) {
905                     title.append("AboveSubPanel");
906                 } else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
907                     title.append("AtchDlg");
908                 } else {
909                     title.append(wp.type);
910                 }
911                 if (mAppName != null) {
912                     title.append(":").append(mAppName);
913                 }
914                 wp.setTitle(title);
915             }
916         } else if (wp.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW &&
917                 wp.type <= WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
918             // We don't set the app token to this system window because the life cycles should be
919             // independent. If an app creates a system window and then the app goes to the stopped
920             // state, the system window should not be affected (can still show and receive input
921             // events).
922             if (curTitle == null || curTitle.length() == 0) {
923                 final StringBuilder title = new StringBuilder(32);
924                 title.append("Sys").append(wp.type);
925                 if (mAppName != null) {
926                     title.append(":").append(mAppName);
927                 }
928                 wp.setTitle(title);
929             }
930         } else {
931             if (wp.token == null) {
932                 wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
933             }
934             if ((curTitle == null || curTitle.length() == 0)
935                     && mAppName != null) {
936                 wp.setTitle(mAppName);
937             }
938         }
939         if (wp.packageName == null) {
940             wp.packageName = mContext.getPackageName();
941         }
942         if (mHardwareAccelerated ||
943                 (mWindowAttributes.flags & FLAG_HARDWARE_ACCELERATED) != 0) {
944             wp.flags |= FLAG_HARDWARE_ACCELERATED;
945         }
946     }
947 
948     /**
949      * Return the window manager allowing this Window to display its own
950      * windows.
951      *
952      * @return WindowManager The ViewManager.
953      */
getWindowManager()954     public WindowManager getWindowManager() {
955         return mWindowManager;
956     }
957 
958     /**
959      * Set the Callback interface for this window, used to intercept key
960      * events and other dynamic operations in the window.
961      *
962      * @param callback The desired Callback interface.
963      */
setCallback(Callback callback)964     public void setCallback(Callback callback) {
965         mCallback = callback;
966     }
967 
968     /**
969      * Return the current Callback interface for this window.
970      */
getCallback()971     public final Callback getCallback() {
972         return mCallback;
973     }
974 
975     /**
976      * Set an observer to collect frame stats for each frame rendered in this window.
977      *
978      * Must be in hardware rendering mode.
979      */
addOnFrameMetricsAvailableListener( @onNull OnFrameMetricsAvailableListener listener, Handler handler)980     public final void addOnFrameMetricsAvailableListener(
981             @NonNull OnFrameMetricsAvailableListener listener,
982             Handler handler) {
983         final View decorView = getDecorView();
984         if (decorView == null) {
985             throw new IllegalStateException("can't observe a Window without an attached view");
986         }
987 
988         if (listener == null) {
989             throw new NullPointerException("listener cannot be null");
990         }
991 
992         decorView.addFrameMetricsListener(this, listener, handler);
993     }
994 
995     /**
996      * Remove observer and stop listening to frame stats for this window.
997      */
removeOnFrameMetricsAvailableListener(OnFrameMetricsAvailableListener listener)998     public final void removeOnFrameMetricsAvailableListener(OnFrameMetricsAvailableListener listener) {
999         final View decorView = getDecorView();
1000         if (decorView != null) {
1001             getDecorView().removeFrameMetricsListener(listener);
1002         }
1003     }
1004 
1005     /** @hide */
setOnWindowDismissedCallback(OnWindowDismissedCallback dcb)1006     public final void setOnWindowDismissedCallback(OnWindowDismissedCallback dcb) {
1007         mOnWindowDismissedCallback = dcb;
1008     }
1009 
1010     /** @hide */
dispatchOnWindowDismissed( boolean finishTask, boolean suppressWindowTransition)1011     public final void dispatchOnWindowDismissed(
1012             boolean finishTask, boolean suppressWindowTransition) {
1013         if (mOnWindowDismissedCallback != null) {
1014             mOnWindowDismissedCallback.onWindowDismissed(finishTask, suppressWindowTransition);
1015         }
1016     }
1017 
1018     /** @hide */
setOnWindowSwipeDismissedCallback(OnWindowSwipeDismissedCallback sdcb)1019     public final void setOnWindowSwipeDismissedCallback(OnWindowSwipeDismissedCallback sdcb) {
1020         mOnWindowSwipeDismissedCallback = sdcb;
1021     }
1022 
1023     /** @hide */
dispatchOnWindowSwipeDismissed()1024     public final void dispatchOnWindowSwipeDismissed() {
1025         if (mOnWindowSwipeDismissedCallback != null) {
1026             mOnWindowSwipeDismissedCallback.onWindowSwipeDismissed();
1027         }
1028     }
1029 
1030     /** @hide */
setWindowControllerCallback(WindowControllerCallback wccb)1031     public final void setWindowControllerCallback(WindowControllerCallback wccb) {
1032         mWindowControllerCallback = wccb;
1033     }
1034 
1035     /** @hide */
getWindowControllerCallback()1036     public final WindowControllerCallback getWindowControllerCallback() {
1037         return mWindowControllerCallback;
1038     }
1039 
1040     /** @hide */
setDecorCallback(DecorCallback decorCallback)1041     public final void setDecorCallback(DecorCallback decorCallback) {
1042         mDecorCallback = decorCallback;
1043     }
1044 
1045     /** @hide */
setSystemBarAppearance(@indowInsetsController.Appearance int appearance)1046     public final void setSystemBarAppearance(@WindowInsetsController.Appearance int appearance) {
1047         mSystemBarAppearance = appearance;
1048     }
1049 
1050     /** @hide */
1051     @WindowInsetsController.Appearance
getSystemBarAppearance()1052     public final int getSystemBarAppearance() {
1053         return mSystemBarAppearance;
1054     }
1055 
1056     /** @hide */
dispatchOnSystemBarAppearanceChanged( @indowInsetsController.Appearance int appearance)1057     public final void dispatchOnSystemBarAppearanceChanged(
1058             @WindowInsetsController.Appearance int appearance) {
1059         setSystemBarAppearance(appearance);
1060         if (mDecorCallback != null) {
1061             mDecorCallback.onSystemBarAppearanceChanged(appearance);
1062         }
1063         if (mWindowControllerCallback != null) {
1064             mWindowControllerCallback.updateSystemBarsAppearance(appearance);
1065         }
1066     }
1067 
1068     /** @hide */
onDrawLegacyNavigationBarBackgroundChanged( boolean drawLegacyNavigationBarBackground)1069     public final boolean onDrawLegacyNavigationBarBackgroundChanged(
1070             boolean drawLegacyNavigationBarBackground) {
1071         if (mDecorCallback == null) {
1072             return false;
1073         }
1074         return mDecorCallback.onDrawLegacyNavigationBarBackgroundChanged(
1075                 drawLegacyNavigationBarBackground);
1076     }
1077 
1078     /**
1079      * Set a callback for changes of area where caption will draw its content.
1080      *
1081      * @param listener Callback that will be called when the area changes.
1082      */
setRestrictedCaptionAreaListener(OnRestrictedCaptionAreaChangedListener listener)1083     public final void setRestrictedCaptionAreaListener(OnRestrictedCaptionAreaChangedListener listener) {
1084         mOnRestrictedCaptionAreaChangedListener = listener;
1085         mRestrictedCaptionAreaRect = listener != null ? new Rect() : null;
1086     }
1087 
1088     /**
1089      * Prevent non-system overlay windows from being drawn on top of this window.
1090      *
1091      * @param hide whether non-system overlay windows should be hidden.
1092      */
1093     @RequiresPermission(HIDE_OVERLAY_WINDOWS)
setHideOverlayWindows(boolean hide)1094     public final void setHideOverlayWindows(boolean hide) {
1095         // This permission check is here to throw early and let the developer know that they need
1096         // to hold HIDE_OVERLAY_WINDOWS for the flag to have any effect. The WM verifies that the
1097         // owner of the window has the permission before applying the flag, but this is done
1098         // asynchronously.
1099         if (mContext.checkSelfPermission(HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != PERMISSION_GRANTED
1100                 && mContext.checkSelfPermission(HIDE_OVERLAY_WINDOWS) != PERMISSION_GRANTED) {
1101             throw new SecurityException(
1102                     "Permission denial: setHideOverlayWindows: HIDE_OVERLAY_WINDOWS");
1103         }
1104         setPrivateFlags(hide ? SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS : 0,
1105                 SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
1106     }
1107 
1108     /**
1109      * Take ownership of this window's surface.  The window's view hierarchy
1110      * will no longer draw into the surface, though it will otherwise continue
1111      * to operate (such as for receiving input events).  The given SurfaceHolder
1112      * callback will be used to tell you about state changes to the surface.
1113      */
takeSurface(SurfaceHolder.Callback2 callback)1114     public abstract void takeSurface(SurfaceHolder.Callback2 callback);
1115 
1116     /**
1117      * Take ownership of this window's InputQueue.  The window will no
1118      * longer read and dispatch input events from the queue; it is your
1119      * responsibility to do so.
1120      */
takeInputQueue(InputQueue.Callback callback)1121     public abstract void takeInputQueue(InputQueue.Callback callback);
1122 
1123     /**
1124      * Return whether this window is being displayed with a floating style
1125      * (based on the {@link android.R.attr#windowIsFloating} attribute in
1126      * the style/theme).
1127      *
1128      * @return Returns true if the window is configured to be displayed floating
1129      * on top of whatever is behind it.
1130      */
isFloating()1131     public abstract boolean isFloating();
1132 
1133     /**
1134      * Set the width and height layout parameters of the window.  The default
1135      * for both of these is MATCH_PARENT; you can change them to WRAP_CONTENT
1136      * or an absolute value to make a window that is not full-screen.
1137      *
1138      * @param width The desired layout width of the window.
1139      * @param height The desired layout height of the window.
1140      *
1141      * @see ViewGroup.LayoutParams#height
1142      * @see ViewGroup.LayoutParams#width
1143      */
setLayout(int width, int height)1144     public void setLayout(int width, int height) {
1145         final WindowManager.LayoutParams attrs = getAttributes();
1146         attrs.width = width;
1147         attrs.height = height;
1148         dispatchWindowAttributesChanged(attrs);
1149     }
1150 
1151     /**
1152      * Set the gravity of the window, as per the Gravity constants.  This
1153      * controls how the window manager is positioned in the overall window; it
1154      * is only useful when using WRAP_CONTENT for the layout width or height.
1155      *
1156      * @param gravity The desired gravity constant.
1157      *
1158      * @see Gravity
1159      * @see #setLayout
1160      */
setGravity(int gravity)1161     public void setGravity(int gravity)
1162     {
1163         final WindowManager.LayoutParams attrs = getAttributes();
1164         attrs.gravity = gravity;
1165         dispatchWindowAttributesChanged(attrs);
1166     }
1167 
1168     /**
1169      * Set the type of the window, as per the WindowManager.LayoutParams
1170      * types.
1171      *
1172      * @param type The new window type (see WindowManager.LayoutParams).
1173      */
setType(int type)1174     public void setType(int type) {
1175         final WindowManager.LayoutParams attrs = getAttributes();
1176         attrs.type = type;
1177         dispatchWindowAttributesChanged(attrs);
1178     }
1179 
1180     /**
1181      * Set the format of window, as per the PixelFormat types.  This overrides
1182      * the default format that is selected by the Window based on its
1183      * window decorations.
1184      *
1185      * @param format The new window format (see PixelFormat).  Use
1186      *               PixelFormat.UNKNOWN to allow the Window to select
1187      *               the format.
1188      *
1189      * @see PixelFormat
1190      */
setFormat(int format)1191     public void setFormat(int format) {
1192         final WindowManager.LayoutParams attrs = getAttributes();
1193         if (format != PixelFormat.UNKNOWN) {
1194             attrs.format = format;
1195             mHaveWindowFormat = true;
1196         } else {
1197             attrs.format = mDefaultWindowFormat;
1198             mHaveWindowFormat = false;
1199         }
1200         dispatchWindowAttributesChanged(attrs);
1201     }
1202 
1203     /**
1204      * Specify custom animations to use for the window, as per
1205      * {@link WindowManager.LayoutParams#windowAnimations
1206      * WindowManager.LayoutParams.windowAnimations}.  Providing anything besides
1207      * 0 here will override the animations the window would
1208      * normally retrieve from its theme.
1209      */
setWindowAnimations(@tyleRes int resId)1210     public void setWindowAnimations(@StyleRes int resId) {
1211         final WindowManager.LayoutParams attrs = getAttributes();
1212         attrs.windowAnimations = resId;
1213         dispatchWindowAttributesChanged(attrs);
1214     }
1215 
1216     /**
1217      * Specify an explicit soft input mode to use for the window, as per
1218      * {@link WindowManager.LayoutParams#softInputMode
1219      * WindowManager.LayoutParams.softInputMode}.  Providing anything besides
1220      * "unspecified" here will override the input mode the window would
1221      * normally retrieve from its theme.
1222      */
setSoftInputMode(int mode)1223     public void setSoftInputMode(int mode) {
1224         final WindowManager.LayoutParams attrs = getAttributes();
1225         if (mode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
1226             attrs.softInputMode = mode;
1227             mHasSoftInputMode = true;
1228         } else {
1229             mHasSoftInputMode = false;
1230         }
1231         dispatchWindowAttributesChanged(attrs);
1232     }
1233 
1234     /**
1235      * Convenience function to set the flag bits as specified in flags, as
1236      * per {@link #setFlags}.
1237      * @param flags The flag bits to be set.
1238      * @see #setFlags
1239      * @see #clearFlags
1240      */
addFlags(int flags)1241     public void addFlags(int flags) {
1242         setFlags(flags, flags);
1243     }
1244 
1245     /**
1246      * Add private flag bits.
1247      *
1248      * <p>Refer to the individual flags for the permissions needed.
1249      *
1250      * @param flags The flag bits to add.
1251      *
1252      * @hide
1253      */
1254     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
addPrivateFlags(int flags)1255     public void addPrivateFlags(int flags) {
1256         setPrivateFlags(flags, flags);
1257     }
1258 
1259     /**
1260      * Add system flag bits.
1261      *
1262      * <p>Refer to the individual flags for the permissions needed.
1263      *
1264      * <p>Note: Only for updateable system components (aka. mainline modules)
1265      *
1266      * @param flags The flag bits to add.
1267      *
1268      * @hide
1269      */
1270     @SystemApi
addSystemFlags(@indowManager.LayoutParams.SystemFlags int flags)1271     public void addSystemFlags(@WindowManager.LayoutParams.SystemFlags int flags) {
1272         addPrivateFlags(flags);
1273     }
1274 
1275     /**
1276      * Convenience function to clear the flag bits as specified in flags, as
1277      * per {@link #setFlags}.
1278      * @param flags The flag bits to be cleared.
1279      * @see #setFlags
1280      * @see #addFlags
1281      */
clearFlags(int flags)1282     public void clearFlags(int flags) {
1283         setFlags(0, flags);
1284     }
1285 
1286     /**
1287      * Set the flags of the window, as per the
1288      * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
1289      * flags.
1290      *
1291      * <p>Note that some flags must be set before the window decoration is
1292      * created (by the first call to
1293      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
1294      * {@link #getDecorView()}:
1295      * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
1296      * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
1297      * will be set for you based on the {@link android.R.attr#windowIsFloating}
1298      * attribute.
1299      *
1300      * @param flags The new window flags (see WindowManager.LayoutParams).
1301      * @param mask Which of the window flag bits to modify.
1302      * @see #addFlags
1303      * @see #clearFlags
1304      */
setFlags(int flags, int mask)1305     public void setFlags(int flags, int mask) {
1306         final WindowManager.LayoutParams attrs = getAttributes();
1307         attrs.flags = (attrs.flags&~mask) | (flags&mask);
1308         mForcedWindowFlags |= mask;
1309         dispatchWindowAttributesChanged(attrs);
1310     }
1311 
setPrivateFlags(int flags, int mask)1312     private void setPrivateFlags(int flags, int mask) {
1313         final WindowManager.LayoutParams attrs = getAttributes();
1314         attrs.privateFlags = (attrs.privateFlags & ~mask) | (flags & mask);
1315         dispatchWindowAttributesChanged(attrs);
1316     }
1317 
1318     /**
1319      * {@hide}
1320      */
dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs)1321     protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) {
1322         if (mCallback != null) {
1323             mCallback.onWindowAttributesChanged(attrs);
1324         }
1325     }
1326 
1327     /**
1328      * <p>Sets the requested color mode of the window. The requested the color mode might
1329      * override the window's pixel {@link WindowManager.LayoutParams#format format}.</p>
1330      *
1331      * <p>The requested color mode must be one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
1332      * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or {@link ActivityInfo#COLOR_MODE_HDR}.</p>
1333      *
1334      * <p>The requested color mode is not guaranteed to be honored. Please refer to
1335      * {@link #getColorMode()} for more information.</p>
1336      *
1337      * @see #getColorMode()
1338      * @see Display#isWideColorGamut()
1339      * @see Configuration#isScreenWideColorGamut()
1340      */
setColorMode(@ctivityInfo.ColorMode int colorMode)1341     public void setColorMode(@ActivityInfo.ColorMode int colorMode) {
1342         final WindowManager.LayoutParams attrs = getAttributes();
1343         attrs.setColorMode(colorMode);
1344         dispatchWindowAttributesChanged(attrs);
1345     }
1346 
1347     /**
1348      * <p>Sets the desired about of HDR headroom to be used when rendering as a ratio of
1349      * targetHdrPeakBrightnessInNits / targetSdrWhitePointInNits. Only applies when
1350      * {@link #setColorMode(int)} is {@link ActivityInfo#COLOR_MODE_HDR}</p>
1351      *
1352      * <p>By default the system will choose an amount of HDR headroom that is appropriate
1353      * for the underlying device capabilities & bit-depth of the panel. However, for some types
1354      * of content this can end up being more headroom than necessary or desired. An example
1355      * would be a messaging app or gallery thumbnail view where some amount of HDR pop is desired
1356      * without overly influencing the perceived brightness of the majority SDR content. This can
1357      * also be used to animate in/out of an HDR range for smoother transitions.</p>
1358      *
1359      * <p>Note: The actual amount of HDR headroom that will be given is subject to a variety
1360      * of factors such as ambient conditions, display capabilities, or bit-depth limitations.
1361      * See {@link Display#getHdrSdrRatio()} for more information as well as how to query the
1362      * current value.</p>
1363      *
1364      * @param desiredHeadroom The amount of HDR headroom that is desired. Must be >= 1.0 (no HDR)
1365      *                        and <= 10,000.0. Passing 0.0 will reset to the default, automatically
1366      *                        chosen value.
1367      * @see #getDesiredHdrHeadroom()
1368      * @see Display#getHdrSdrRatio()
1369      */
1370     @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_LIMITED_HDR)
setDesiredHdrHeadroom( @loatRangefrom = 0.0f, to = 10000.0) float desiredHeadroom)1371     public void setDesiredHdrHeadroom(
1372             @FloatRange(from = 0.0f, to = 10000.0) float desiredHeadroom) {
1373         final WindowManager.LayoutParams attrs = getAttributes();
1374         attrs.setDesiredHdrHeadroom(desiredHeadroom);
1375         dispatchWindowAttributesChanged(attrs);
1376     }
1377 
1378     /**
1379      * Get the desired amount of HDR headroom as set by {@link #setDesiredHdrHeadroom(float)}
1380      * @return The amount of HDR headroom set, or 0 for automatic/default behavior.
1381      * @see #setDesiredHdrHeadroom(float)
1382      */
1383     @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_LIMITED_HDR)
getDesiredHdrHeadroom()1384     public float getDesiredHdrHeadroom() {
1385         return getAttributes().getDesiredHdrHeadroom();
1386     }
1387 
1388     /**
1389      * Sets whether the frame rate touch boost is enabled for this Window.
1390      * When enabled, the frame rate will be boosted when a user touches the Window.
1391      *
1392      * @param enabled whether the frame rate touch boost is enabled.
1393      * @see #getFrameRateBoostOnTouchEnabled()
1394      * @see WindowManager.LayoutParams#setFrameRateBoostOnTouchEnabled(boolean)
1395      */
1396     @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
setFrameRateBoostOnTouchEnabled(boolean enabled)1397     public void setFrameRateBoostOnTouchEnabled(boolean enabled) {
1398         if (sToolkitSetFrameRateReadOnlyFlagValue) {
1399             final WindowManager.LayoutParams attrs = getAttributes();
1400             attrs.setFrameRateBoostOnTouchEnabled(enabled);
1401             dispatchWindowAttributesChanged(attrs);
1402         }
1403     }
1404 
1405     /**
1406      * Get whether frame rate touch boost is enabled
1407      * {@link #setFrameRateBoostOnTouchEnabled(boolean)}
1408      *
1409      * @return whether the frame rate touch boost is enabled.
1410      * @see #setFrameRateBoostOnTouchEnabled(boolean)
1411      * @see WindowManager.LayoutParams#getFrameRateBoostOnTouchEnabled()
1412      */
1413     @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
getFrameRateBoostOnTouchEnabled()1414     public boolean getFrameRateBoostOnTouchEnabled() {
1415         if (sToolkitSetFrameRateReadOnlyFlagValue) {
1416             return getAttributes().getFrameRateBoostOnTouchEnabled();
1417         }
1418         return true;
1419     }
1420 
1421     /**
1422      * Set whether frameratepowersavingsbalance is enabled for this Window.
1423      * This allows device to adjust refresh rate
1424      * as needed and can be useful for power saving.
1425      *
1426      * @param enabled whether the frameratepowersavingsbalance is enabled.
1427      * @see #isFrameRatePowerSavingsBalanced()
1428      * @see WindowManager.LayoutParams#setFrameRatePowerSavingsBalanced(boolean)
1429      */
1430     @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
setFrameRatePowerSavingsBalanced(boolean enabled)1431     public void setFrameRatePowerSavingsBalanced(boolean enabled) {
1432         if (sToolkitSetFrameRateReadOnlyFlagValue) {
1433             final WindowManager.LayoutParams attrs = getAttributes();
1434             attrs.setFrameRatePowerSavingsBalanced(enabled);
1435             dispatchWindowAttributesChanged(attrs);
1436         }
1437     }
1438 
1439     /**
1440      * Get whether frameratepowersavingsbalance is enabled for this Window.
1441      * This allows device to adjust refresh rate
1442      * as needed and can be useful for power saving.
1443      * {@link #setFrameRateBoostOnTouchEnabled(boolean)}
1444      *
1445      * @return whether the frameratepowersavingsbalance is enabled.
1446      * @see #setFrameRatePowerSavingsBalanced(boolean)
1447      * @see WindowManager.LayoutParams#isFrameRatePowerSavingsBalanced()
1448      */
1449     @FlaggedApi(android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY)
isFrameRatePowerSavingsBalanced()1450     public boolean isFrameRatePowerSavingsBalanced() {
1451         if (sToolkitSetFrameRateReadOnlyFlagValue) {
1452             return getAttributes().isFrameRatePowerSavingsBalanced();
1453         }
1454         return false;
1455     }
1456 
1457     /**
1458      * If {@code isPreferred} is true, this method requests that the connected display does minimal
1459      * post processing when this window is visible on the screen. Otherwise, it requests that the
1460      * display switches back to standard image processing.
1461      *
1462      * <p> By default, the display does not do minimal post processing and if this is desired, this
1463      * method should not be used. It should be used with {@code isPreferred=true} when low
1464      * latency has a higher priority than image enhancement processing (e.g. for games or video
1465      * conferencing). The display will automatically go back into standard image processing mode
1466      * when no window requesting minimal posst processing is visible on screen anymore.
1467      * {@code setPreferMinimalPostProcessing(false)} can be used if
1468      * {@code setPreferMinimalPostProcessing(true)} was previously called for this window and
1469      * minimal post processing is no longer required.
1470      *
1471      * <p>If the Display sink is connected via HDMI, the device will begin to send infoframes with
1472      * Auto Low Latency Mode enabled and Game Content Type. This will switch the connected display
1473      * to a minimal image processing mode (if available), which reduces latency, improving the user
1474      * experience for gaming or video conferencing applications. For more information, see HDMI 2.1
1475      * specification.
1476      *
1477      * <p>If the Display sink has an internal connection or uses some other protocol than HDMI,
1478      * effects may be similar but implementation-defined.
1479      *
1480      * <p>The ability to switch to a mode with minimal post proessing may be disabled by a user
1481      * setting in the system settings menu. In that case, this method does nothing.
1482      *
1483      * @see android.content.pm.ActivityInfo#FLAG_PREFER_MINIMAL_POST_PROCESSING
1484      * @see android.view.Display#isMinimalPostProcessingSupported
1485      * @see android.view.WindowManager.LayoutParams#preferMinimalPostProcessing
1486      *
1487      * @param isPreferred Indicates whether minimal post processing is preferred for this window
1488      *                    ({@code isPreferred=true}) or not ({@code isPreferred=false}).
1489      */
setPreferMinimalPostProcessing(boolean isPreferred)1490     public void setPreferMinimalPostProcessing(boolean isPreferred) {
1491         mWindowAttributes.preferMinimalPostProcessing = isPreferred;
1492         dispatchWindowAttributesChanged(mWindowAttributes);
1493     }
1494 
1495     /**
1496      * Returns the requested color mode of the window, one of
1497      * {@link ActivityInfo#COLOR_MODE_DEFAULT}, {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT}
1498      * or {@link ActivityInfo#COLOR_MODE_HDR}. If {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT}
1499      * was requested it is possible the window will not be put in wide color gamut mode depending
1500      * on device and display support for that mode. Use {@link #isWideColorGamut} to determine
1501      * if the window is currently in wide color gamut mode.
1502      *
1503      * @see #setColorMode(int)
1504      * @see Display#isWideColorGamut()
1505      * @see Configuration#isScreenWideColorGamut()
1506      */
1507     @ActivityInfo.ColorMode
getColorMode()1508     public int getColorMode() {
1509         return getAttributes().getColorMode();
1510     }
1511 
1512     /**
1513      * Returns true if this window's color mode is {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT},
1514      * the display has a wide color gamut and this device supports wide color gamut rendering.
1515      *
1516      * @see Display#isWideColorGamut()
1517      * @see Configuration#isScreenWideColorGamut()
1518      */
isWideColorGamut()1519     public boolean isWideColorGamut() {
1520         return getColorMode() == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT
1521                 && getContext().getResources().getConfiguration().isScreenWideColorGamut();
1522     }
1523 
1524     /**
1525      * Set the amount of dim behind the window when using
1526      * {@link WindowManager.LayoutParams#FLAG_DIM_BEHIND}.  This overrides
1527      * the default dim amount of that is selected by the Window based on
1528      * its theme.
1529      *
1530      * @param amount The new dim amount, from 0 for no dim to 1 for full dim.
1531      */
setDimAmount(float amount)1532     public void setDimAmount(float amount) {
1533         final WindowManager.LayoutParams attrs = getAttributes();
1534         attrs.dimAmount = amount;
1535         mHaveDimAmount = true;
1536         dispatchWindowAttributesChanged(attrs);
1537     }
1538 
1539     /**
1540      * Sets whether the decor view should fit root-level content views for {@link WindowInsets}.
1541      * <p>
1542      * If set to {@code true}, the framework will inspect the now deprecated
1543      * {@link View#SYSTEM_UI_LAYOUT_FLAGS} as well the
1544      * {@link WindowManager.LayoutParams#SOFT_INPUT_ADJUST_RESIZE} flag and fits content according
1545      * to these flags.
1546      *
1547      * <p>
1548      * If set to {@code false}, the framework will not fit the content view to the insets and will
1549      * just pass through the {@link WindowInsets} to the content view.
1550      *
1551      * <p>
1552      * If the app targets
1553      * {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM VANILLA_ICE_CREAM} or above,
1554      * the behavior will be like setting this to {@code false}, and cannot be changed.
1555      *
1556      * @param decorFitsSystemWindows Whether the decor view should fit root-level content views for
1557      *                               insets.
1558      * @deprecated Make space in the container views to prevent the critical elements from getting
1559      *             obscured by {@link WindowInsets.Type#systemBars()} or
1560      *             {@link WindowInsets.Type#displayCutout()} instead.
1561      */
setDecorFitsSystemWindows(boolean decorFitsSystemWindows)1562     public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) {
1563     }
1564 
1565     /** @hide */
decorFitsSystemWindows()1566     public boolean decorFitsSystemWindows() {
1567         return false;
1568     }
1569 
1570     /**
1571      * Specify custom window attributes.  <strong>PLEASE NOTE:</strong> the
1572      * layout params you give here should generally be from values previously
1573      * retrieved with {@link #getAttributes()}; you probably do not want to
1574      * blindly create and apply your own, since this will blow away any values
1575      * set by the framework that you are not interested in.
1576      *
1577      * @param a The new window attributes, which will completely override any
1578      *          current values.
1579      */
setAttributes(WindowManager.LayoutParams a)1580     public void setAttributes(WindowManager.LayoutParams a) {
1581         mWindowAttributes.copyFrom(a);
1582         dispatchWindowAttributesChanged(mWindowAttributes);
1583     }
1584 
1585     /**
1586      * Retrieve the current window attributes associated with this panel.
1587      *
1588      * @return WindowManager.LayoutParams Either the existing window
1589      *         attributes object, or a freshly created one if there is none.
1590      */
getAttributes()1591     public final WindowManager.LayoutParams getAttributes() {
1592         return mWindowAttributes;
1593     }
1594 
1595     /**
1596      * Return the window flags that have been explicitly set by the client,
1597      * so will not be modified by {@link #getDecorView}.
1598      */
getForcedWindowFlags()1599     protected final int getForcedWindowFlags() {
1600         return mForcedWindowFlags;
1601     }
1602 
1603     /**
1604      * Has the app specified their own soft input mode?
1605      */
hasSoftInputMode()1606     protected final boolean hasSoftInputMode() {
1607         return mHasSoftInputMode;
1608     }
1609 
1610     /** @hide */
1611     @UnsupportedAppUsage
setCloseOnTouchOutside(boolean close)1612     public void setCloseOnTouchOutside(boolean close) {
1613         mCloseOnTouchOutside = close;
1614         mSetCloseOnTouchOutside = true;
1615     }
1616 
1617     /** @hide */
1618     @UnsupportedAppUsage
setCloseOnTouchOutsideIfNotSet(boolean close)1619     public void setCloseOnTouchOutsideIfNotSet(boolean close) {
1620         if (!mSetCloseOnTouchOutside) {
1621             mCloseOnTouchOutside = close;
1622             mSetCloseOnTouchOutside = true;
1623         }
1624     }
1625 
1626     /** @hide */
shouldCloseOnTouchOutside()1627     public boolean shouldCloseOnTouchOutside() {
1628         return mCloseOnTouchOutside;
1629     }
1630 
1631     /** @hide */
1632     @SuppressWarnings("HiddenAbstractMethod")
1633     @UnsupportedAppUsage
alwaysReadCloseOnTouchAttr()1634     public abstract void alwaysReadCloseOnTouchAttr();
1635 
1636     /** @hide */
1637     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
shouldCloseOnTouch(Context context, MotionEvent event)1638     public boolean shouldCloseOnTouch(Context context, MotionEvent event) {
1639         final boolean isOutside =
1640                 event.getAction() == MotionEvent.ACTION_UP && isOutOfBounds(context, event)
1641                 || event.getAction() == MotionEvent.ACTION_OUTSIDE;
1642         if (mCloseOnTouchOutside && peekDecorView() != null && isOutside) {
1643             return true;
1644         }
1645         return false;
1646     }
1647 
1648     /* Sets the Sustained Performance requirement for the calling window.
1649      * @param enable disables or enables the mode.
1650      */
setSustainedPerformanceMode(boolean enable)1651     public void setSustainedPerformanceMode(boolean enable) {
1652         setPrivateFlags(enable
1653                 ? WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE : 0,
1654                 WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE);
1655     }
1656 
isOutOfBounds(Context context, MotionEvent event)1657     private boolean isOutOfBounds(Context context, MotionEvent event) {
1658         final int x = (int) event.getX();
1659         final int y = (int) event.getY();
1660         final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
1661         final View decorView = getDecorView();
1662         return (x < -slop) || (y < -slop)
1663                 || (x > (decorView.getWidth()+slop))
1664                 || (y > (decorView.getHeight()+slop));
1665     }
1666 
1667     /**
1668      * Enable extended screen features.  This must be called before
1669      * setContentView().  May be called as many times as desired as long as it
1670      * is before setContentView().  If not called, no extended features
1671      * will be available.  You can not turn off a feature once it is requested.
1672      * You canot use other title features with {@link #FEATURE_CUSTOM_TITLE}.
1673      *
1674      * @param featureId The desired features, defined as constants by Window.
1675      * @return The features that are now set.
1676      */
requestFeature(int featureId)1677     public boolean requestFeature(int featureId) {
1678         final int flag = 1<<featureId;
1679         mFeatures |= flag;
1680         mLocalFeatures |= mContainer != null ? (flag&~mContainer.mFeatures) : flag;
1681         return (mFeatures&flag) != 0;
1682     }
1683 
1684     /**
1685      * @hide Used internally to help resolve conflicting features.
1686      */
removeFeature(int featureId)1687     protected void removeFeature(int featureId) {
1688         final int flag = 1<<featureId;
1689         mFeatures &= ~flag;
1690         mLocalFeatures &= ~(mContainer != null ? (flag&~mContainer.mFeatures) : flag);
1691     }
1692 
makeActive()1693     public final void makeActive() {
1694         if (mContainer != null) {
1695             if (mContainer.mActiveChild != null) {
1696                 mContainer.mActiveChild.mIsActive = false;
1697             }
1698             mContainer.mActiveChild = this;
1699         }
1700         mIsActive = true;
1701         onActive();
1702     }
1703 
isActive()1704     public final boolean isActive()
1705     {
1706         return mIsActive;
1707     }
1708 
1709     /**
1710      * Finds a view that was identified by the {@code android:id} XML attribute
1711      * that was processed in {@link android.app.Activity#onCreate}.
1712      * <p>
1713      * This will implicitly call {@link #getDecorView} with all of the associated side-effects.
1714      * <p>
1715      * <strong>Note:</strong> In most cases -- depending on compiler support --
1716      * the resulting view is automatically cast to the target class type. If
1717      * the target class type is unconstrained, an explicit cast may be
1718      * necessary.
1719      *
1720      * @param id the ID to search for
1721      * @return a view with given ID if found, or {@code null} otherwise
1722      * @see View#findViewById(int)
1723      * @see Window#requireViewById(int)
1724      */
1725     @Nullable
findViewById(@dRes int id)1726     public <T extends View> T findViewById(@IdRes int id) {
1727         return getDecorView().findViewById(id);
1728     }
1729     /**
1730      * Finds a view that was identified by the {@code android:id} XML attribute
1731      * that was processed in {@link android.app.Activity#onCreate}, or throws an
1732      * IllegalArgumentException if the ID is invalid, or there is no matching view in the hierarchy.
1733      * <p>
1734      * <strong>Note:</strong> In most cases -- depending on compiler support --
1735      * the resulting view is automatically cast to the target class type. If
1736      * the target class type is unconstrained, an explicit cast may be
1737      * necessary.
1738      *
1739      * @param id the ID to search for
1740      * @return a view with given ID
1741      * @see View#requireViewById(int)
1742      * @see Window#findViewById(int)
1743      */
1744     @NonNull
requireViewById(@dRes int id)1745     public final <T extends View> T requireViewById(@IdRes int id) {
1746         T view = findViewById(id);
1747         if (view == null) {
1748             throw new IllegalArgumentException("ID does not reference a View inside this Window");
1749         }
1750         return view;
1751     }
1752 
1753     /**
1754      * Convenience for
1755      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1756      * to set the screen content from a layout resource.  The resource will be
1757      * inflated, adding all top-level views to the screen.
1758      *
1759      * @param layoutResID Resource ID to be inflated.
1760      * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
1761      */
setContentView(@ayoutRes int layoutResID)1762     public abstract void setContentView(@LayoutRes int layoutResID);
1763 
1764     /**
1765      * Convenience for
1766      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1767      * set the screen content to an explicit view.  This view is placed
1768      * directly into the screen's view hierarchy.  It can itself be a complex
1769      * view hierarhcy.
1770      *
1771      * @param view The desired content to display.
1772      * @see #setContentView(View, android.view.ViewGroup.LayoutParams)
1773      */
setContentView(View view)1774     public abstract void setContentView(View view);
1775 
1776     /**
1777      * Set the screen content to an explicit view.  This view is placed
1778      * directly into the screen's view hierarchy.  It can itself be a complex
1779      * view hierarchy.
1780      *
1781      * <p>Note that calling this function "locks in" various characteristics
1782      * of the window that can not, from this point forward, be changed: the
1783      * features that have been requested with {@link #requestFeature(int)},
1784      * and certain window flags as described in {@link #setFlags(int, int)}.</p>
1785      *
1786      * <p>If {@link #FEATURE_CONTENT_TRANSITIONS} is set, the window's
1787      * TransitionManager will be used to animate content from the current
1788      * content View to view.</p>
1789      *
1790      * @param view The desired content to display.
1791      * @param params Layout parameters for the view.
1792      * @see #getTransitionManager()
1793      * @see #setTransitionManager(android.transition.TransitionManager)
1794      */
setContentView(View view, ViewGroup.LayoutParams params)1795     public abstract void setContentView(View view, ViewGroup.LayoutParams params);
1796 
1797     /**
1798      * Variation on
1799      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
1800      * to add an additional content view to the screen.  Added after any existing
1801      * ones in the screen -- existing views are NOT removed.
1802      *
1803      * @param view The desired content to display.
1804      * @param params Layout parameters for the view.
1805      */
addContentView(View view, ViewGroup.LayoutParams params)1806     public abstract void addContentView(View view, ViewGroup.LayoutParams params);
1807 
1808     /**
1809      * Remove the view that was used as the screen content.
1810      *
1811      * @hide
1812      */
1813     @SuppressWarnings("HiddenAbstractMethod")
clearContentView()1814     public abstract void clearContentView();
1815 
1816     /**
1817      * Return the view in this Window that currently has focus, or null if
1818      * there are none.  Note that this does not look in any containing
1819      * Window.
1820      *
1821      * @return View The current View with focus or null.
1822      */
1823     @Nullable
getCurrentFocus()1824     public abstract View getCurrentFocus();
1825 
1826     /**
1827      * Quick access to the {@link LayoutInflater} instance that this Window
1828      * retrieved from its Context.
1829      *
1830      * @return LayoutInflater The shared LayoutInflater.
1831      */
1832     @NonNull
getLayoutInflater()1833     public abstract LayoutInflater getLayoutInflater();
1834 
setTitle(CharSequence title)1835     public abstract void setTitle(CharSequence title);
1836 
1837     @Deprecated
setTitleColor(@olorInt int textColor)1838     public abstract void setTitleColor(@ColorInt int textColor);
1839 
openPanel(int featureId, KeyEvent event)1840     public abstract void openPanel(int featureId, KeyEvent event);
1841 
closePanel(int featureId)1842     public abstract void closePanel(int featureId);
1843 
togglePanel(int featureId, KeyEvent event)1844     public abstract void togglePanel(int featureId, KeyEvent event);
1845 
invalidatePanelMenu(int featureId)1846     public abstract void invalidatePanelMenu(int featureId);
1847 
performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags)1848     public abstract boolean performPanelShortcut(int featureId,
1849                                                  int keyCode,
1850                                                  KeyEvent event,
1851                                                  int flags);
performPanelIdentifierAction(int featureId, int id, int flags)1852     public abstract boolean performPanelIdentifierAction(int featureId,
1853                                                  int id,
1854                                                  int flags);
1855 
closeAllPanels()1856     public abstract void closeAllPanels();
1857 
performContextMenuIdentifierAction(int id, int flags)1858     public abstract boolean performContextMenuIdentifierAction(int id, int flags);
1859 
1860     /**
1861      * Should be called when the configuration is changed.
1862      *
1863      * @param newConfig The new configuration.
1864      */
onConfigurationChanged(Configuration newConfig)1865     public abstract void onConfigurationChanged(Configuration newConfig);
1866 
1867     /**
1868      * Sets the window elevation.
1869      * <p>
1870      * Changes to this property take effect immediately and will cause the
1871      * window surface to be recreated. This is an expensive operation and as a
1872      * result, this property should not be animated.
1873      *
1874      * @param elevation The window elevation.
1875      * @see View#setElevation(float)
1876      * @see android.R.styleable#Window_windowElevation
1877      */
setElevation(float elevation)1878     public void setElevation(float elevation) {}
1879 
1880     /**
1881      * Gets the window elevation.
1882      *
1883      * @hide
1884      */
getElevation()1885     public float getElevation() {
1886         return 0.0f;
1887     }
1888 
1889     /**
1890      * Sets whether window content should be clipped to the outline of the
1891      * window background.
1892      *
1893      * @param clipToOutline Whether window content should be clipped to the
1894      *                      outline of the window background.
1895      * @see View#setClipToOutline(boolean)
1896      * @see android.R.styleable#Window_windowClipToOutline
1897      */
setClipToOutline(boolean clipToOutline)1898     public void setClipToOutline(boolean clipToOutline) {}
1899 
1900     /**
1901      * Change the background of this window to a Drawable resource. Setting the
1902      * background to null will make the window be opaque. To make the window
1903      * transparent, you can use an empty drawable (for instance a ColorDrawable
1904      * with the color 0 or the system drawable android:drawable/empty.)
1905      *
1906      * @param resId The resource identifier of a drawable resource which will
1907      *              be installed as the new background.
1908      */
setBackgroundDrawableResource(@rawableRes int resId)1909     public void setBackgroundDrawableResource(@DrawableRes int resId) {
1910         setBackgroundDrawable(mContext.getDrawable(resId));
1911     }
1912 
1913     /**
1914      * Change the background of this window to a custom Drawable. Setting the
1915      * background to null will make the window be opaque. To make the window
1916      * transparent, you can use an empty drawable (for instance a ColorDrawable
1917      * with the color 0 or the system drawable android:drawable/empty.)
1918      *
1919      * @param drawable The new Drawable to use for this window's background.
1920      */
setBackgroundDrawable(Drawable drawable)1921     public abstract void setBackgroundDrawable(Drawable drawable);
1922 
1923     /**
1924      * <p>
1925      * Blurs the screen behind the window within the bounds of the window.
1926      * </p><p>
1927      * The density of the blur is set by the blur radius. The radius defines the size
1928      * of the neighbouring area, from which pixels will be averaged to form the final
1929      * color for each pixel. The operation approximates a Gaussian blur.
1930      * A radius of 0 means no blur. The higher the radius, the denser the blur.
1931      * </p><p>
1932      * The window background drawable is drawn on top of the blurred region. The blur
1933      * region bounds and rounded corners will mimic those of the background drawable.
1934      * </p><p>
1935      * For the blur region to be visible, the window has to be translucent
1936      * (see {@link android.R.attr#windowIsTranslucent}) and floating
1937      * (see {@link android.R.attr#windowIsFloating}).
1938      * </p><p>
1939      * Note the difference with {@link WindowManager.LayoutParams#setBlurBehindRadius},
1940      * which blurs the whole screen behind the window. Background blur blurs the screen behind
1941      * only within the bounds of the window.
1942      * </p><p>
1943      * Some devices might not support cross-window blur due to GPU limitations. It can also be
1944      * disabled at runtime, e.g. during battery saving mode, when multimedia tunneling is used or
1945      * when minimal post processing is requested. In such situations, no blur will be computed or
1946      * drawn, resulting in a transparent window background. To avoid this, the app might want to
1947      * change its theme to one that does not use blurs. To listen for cross-window blur
1948      * enabled/disabled events, use {@link WindowManager#addCrossWindowBlurEnabledListener}.
1949      * </p>
1950      *
1951      * @param blurRadius The blur radius to use for window background blur in pixels
1952      *
1953      * @see android.R.styleable#Window_windowBackgroundBlurRadius
1954      * @see WindowManager.LayoutParams#setBlurBehindRadius
1955      * @see WindowManager#addCrossWindowBlurEnabledListener
1956      */
setBackgroundBlurRadius(int blurRadius)1957     public void setBackgroundBlurRadius(int blurRadius) {}
1958 
1959     /**
1960      * Set the value for a drawable feature of this window, from a resource
1961      * identifier.  You must have called requestFeature(featureId) before
1962      * calling this function.
1963      *
1964      * @see android.content.res.Resources#getDrawable(int)
1965      *
1966      * @param featureId The desired drawable feature to change, defined as a
1967      * constant by Window.
1968      * @param resId Resource identifier of the desired image.
1969      */
setFeatureDrawableResource(int featureId, @DrawableRes int resId)1970     public abstract void setFeatureDrawableResource(int featureId, @DrawableRes int resId);
1971 
1972     /**
1973      * Set the value for a drawable feature of this window, from a URI. You
1974      * must have called requestFeature(featureId) before calling this
1975      * function.
1976      *
1977      * <p>The only URI currently supported is "content:", specifying an image
1978      * in a content provider.
1979      *
1980      * @see android.widget.ImageView#setImageURI
1981      *
1982      * @param featureId The desired drawable feature to change. Features are
1983      * constants defined by Window.
1984      * @param uri The desired URI.
1985      */
setFeatureDrawableUri(int featureId, Uri uri)1986     public abstract void setFeatureDrawableUri(int featureId, Uri uri);
1987 
1988     /**
1989      * Set an explicit Drawable value for feature of this window. You must
1990      * have called requestFeature(featureId) before calling this function.
1991      *
1992      * @param featureId The desired drawable feature to change. Features are
1993      *                  constants defined by Window.
1994      * @param drawable A Drawable object to display.
1995      */
setFeatureDrawable(int featureId, Drawable drawable)1996     public abstract void setFeatureDrawable(int featureId, Drawable drawable);
1997 
1998     /**
1999      * Set a custom alpha value for the given drawable feature, controlling how
2000      * much the background is visible through it.
2001      *
2002      * @param featureId The desired drawable feature to change. Features are
2003      *                  constants defined by Window.
2004      * @param alpha The alpha amount, 0 is completely transparent and 255 is
2005      *              completely opaque.
2006      */
setFeatureDrawableAlpha(int featureId, int alpha)2007     public abstract void setFeatureDrawableAlpha(int featureId, int alpha);
2008 
2009     /**
2010      * Set the integer value for a feature. The range of the value depends on
2011      * the feature being set. For {@link #FEATURE_PROGRESS}, it should go from
2012      * 0 to 10000. At 10000 the progress is complete and the indicator hidden.
2013      *
2014      * @param featureId The desired feature to change. Features are constants
2015      *                  defined by Window.
2016      * @param value The value for the feature. The interpretation of this
2017      *              value is feature-specific.
2018      */
setFeatureInt(int featureId, int value)2019     public abstract void setFeatureInt(int featureId, int value);
2020 
2021     /**
2022      * Request that key events come to this activity. Use this if your
2023      * activity has no views with focus, but the activity still wants
2024      * a chance to process key events.
2025      */
takeKeyEvents(boolean get)2026     public abstract void takeKeyEvents(boolean get);
2027 
2028     /**
2029      * Used by custom windows, such as Dialog, to pass the key press event
2030      * further down the view hierarchy. Application developers should
2031      * not need to implement or call this.
2032      *
2033      */
superDispatchKeyEvent(KeyEvent event)2034     public abstract boolean superDispatchKeyEvent(KeyEvent event);
2035 
2036     /**
2037      * Used by custom windows, such as Dialog, to pass the key shortcut press event
2038      * further down the view hierarchy. Application developers should
2039      * not need to implement or call this.
2040      *
2041      */
superDispatchKeyShortcutEvent(KeyEvent event)2042     public abstract boolean superDispatchKeyShortcutEvent(KeyEvent event);
2043 
2044     /**
2045      * Used by custom windows, such as Dialog, to pass the touch screen event
2046      * further down the view hierarchy. Application developers should
2047      * not need to implement or call this.
2048      *
2049      */
superDispatchTouchEvent(MotionEvent event)2050     public abstract boolean superDispatchTouchEvent(MotionEvent event);
2051 
2052     /**
2053      * Used by custom windows, such as Dialog, to pass the trackball event
2054      * further down the view hierarchy. Application developers should
2055      * not need to implement or call this.
2056      *
2057      */
superDispatchTrackballEvent(MotionEvent event)2058     public abstract boolean superDispatchTrackballEvent(MotionEvent event);
2059 
2060     /**
2061      * Used by custom windows, such as Dialog, to pass the generic motion event
2062      * further down the view hierarchy. Application developers should
2063      * not need to implement or call this.
2064      *
2065      */
superDispatchGenericMotionEvent(MotionEvent event)2066     public abstract boolean superDispatchGenericMotionEvent(MotionEvent event);
2067 
2068     /**
2069      * Retrieve the top-level window decor view (containing the standard
2070      * window frame/decorations and the client's content inside of that), which
2071      * can be added as a window to the window manager.
2072      *
2073      * <p><em>Note that calling this function for the first time "locks in"
2074      * various window characteristics as described in
2075      * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}.</em></p>
2076      *
2077      * @return Returns the top-level window decor view.
2078      */
getDecorView()2079     public abstract @NonNull View getDecorView();
2080 
2081     /**
2082      * @return the status bar background view or null.
2083      * @hide
2084      */
2085     @TestApi
getStatusBarBackgroundView()2086     public @Nullable View getStatusBarBackgroundView() {
2087         return null;
2088     }
2089 
2090     /**
2091      * @return the navigation bar background view or null.
2092      * @hide
2093      */
2094     @TestApi
getNavigationBarBackgroundView()2095     public @Nullable View getNavigationBarBackgroundView() {
2096         return null;
2097     }
2098 
2099     /**
2100      * Retrieve the current decor view, but only if it has already been created;
2101      * otherwise returns null.
2102      *
2103      * @return Returns the top-level window decor or null.
2104      * @see #getDecorView
2105      */
peekDecorView()2106     public abstract View peekDecorView();
2107 
saveHierarchyState()2108     public abstract Bundle saveHierarchyState();
2109 
restoreHierarchyState(Bundle savedInstanceState)2110     public abstract void restoreHierarchyState(Bundle savedInstanceState);
2111 
onActive()2112     protected abstract void onActive();
2113 
2114     /**
2115      * Return the feature bits that are enabled.  This is the set of features
2116      * that were given to requestFeature(), and are being handled by this
2117      * Window itself or its container.  That is, it is the set of
2118      * requested features that you can actually use.
2119      *
2120      * <p>To do: add a public version of this API that allows you to check for
2121      * features by their feature ID.
2122      *
2123      * @return int The feature bits.
2124      */
getFeatures()2125     protected final int getFeatures()
2126     {
2127         return mFeatures;
2128     }
2129 
2130     /**
2131      * Return the feature bits set by default on a window.
2132      * @param context The context used to access resources
2133      */
getDefaultFeatures(Context context)2134     public static int getDefaultFeatures(Context context) {
2135         int features = 0;
2136 
2137         final Resources res = context.getResources();
2138         if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureOptionsPanel)) {
2139             features |= 1 << FEATURE_OPTIONS_PANEL;
2140         }
2141 
2142         if (res.getBoolean(com.android.internal.R.bool.config_defaultWindowFeatureContextMenu)) {
2143             features |= 1 << FEATURE_CONTEXT_MENU;
2144         }
2145 
2146         return features;
2147     }
2148 
2149     /**
2150      * Query for the availability of a certain feature.
2151      *
2152      * @param feature The feature ID to check
2153      * @return true if the feature is enabled, false otherwise.
2154      */
hasFeature(int feature)2155     public boolean hasFeature(int feature) {
2156         return (getFeatures() & (1 << feature)) != 0;
2157     }
2158 
2159     /**
2160      * Return the feature bits that are being implemented by this Window.
2161      * This is the set of features that were given to requestFeature(), and are
2162      * being handled by only this Window itself, not by its containers.
2163      *
2164      * @return int The feature bits.
2165      */
getLocalFeatures()2166     protected final int getLocalFeatures()
2167     {
2168         return mLocalFeatures;
2169     }
2170 
2171     /**
2172      * Set the default format of window, as per the PixelFormat types.  This
2173      * is the format that will be used unless the client specifies in explicit
2174      * format with setFormat();
2175      *
2176      * @param format The new window format (see PixelFormat).
2177      *
2178      * @see #setFormat
2179      * @see PixelFormat
2180      */
setDefaultWindowFormat(int format)2181     protected void setDefaultWindowFormat(int format) {
2182         mDefaultWindowFormat = format;
2183         if (!mHaveWindowFormat) {
2184             final WindowManager.LayoutParams attrs = getAttributes();
2185             attrs.format = format;
2186             dispatchWindowAttributesChanged(attrs);
2187         }
2188     }
2189 
2190     /** @hide */
haveDimAmount()2191     protected boolean haveDimAmount() {
2192         return mHaveDimAmount;
2193     }
2194 
setChildDrawable(int featureId, Drawable drawable)2195     public abstract void setChildDrawable(int featureId, Drawable drawable);
2196 
setChildInt(int featureId, int value)2197     public abstract void setChildInt(int featureId, int value);
2198 
2199     /**
2200      * Is a keypress one of the defined shortcut keys for this window.
2201      * @param keyCode the key code from {@link android.view.KeyEvent} to check.
2202      * @param event the {@link android.view.KeyEvent} to use to help check.
2203      */
isShortcutKey(int keyCode, KeyEvent event)2204     public abstract boolean isShortcutKey(int keyCode, KeyEvent event);
2205 
2206     /**
2207      * @see android.app.Activity#setVolumeControlStream(int)
2208      */
setVolumeControlStream(int streamType)2209     public abstract void setVolumeControlStream(int streamType);
2210 
2211     /**
2212      * @see android.app.Activity#getVolumeControlStream()
2213      */
getVolumeControlStream()2214     public abstract int getVolumeControlStream();
2215 
2216     /**
2217      * Sets a {@link MediaController} to send media keys and volume changes to.
2218      * If set, this should be preferred for all media keys and volume requests
2219      * sent to this window.
2220      *
2221      * @param controller The controller for the session which should receive
2222      *            media keys and volume changes.
2223      * @see android.app.Activity#setMediaController(android.media.session.MediaController)
2224      */
setMediaController(MediaController controller)2225     public void setMediaController(MediaController controller) {
2226     }
2227 
2228     /**
2229      * Gets the {@link MediaController} that was previously set.
2230      *
2231      * @return The controller which should receive events.
2232      * @see #setMediaController(android.media.session.MediaController)
2233      * @see android.app.Activity#getMediaController()
2234      */
getMediaController()2235     public MediaController getMediaController() {
2236         return null;
2237     }
2238 
2239     /**
2240      * Set extra options that will influence the UI for this window.
2241      * @param uiOptions Flags specifying extra options for this window.
2242      */
setUiOptions(int uiOptions)2243     public void setUiOptions(int uiOptions) { }
2244 
2245     /**
2246      * Set extra options that will influence the UI for this window.
2247      * Only the bits filtered by mask will be modified.
2248      * @param uiOptions Flags specifying extra options for this window.
2249      * @param mask Flags specifying which options should be modified. Others will remain unchanged.
2250      */
setUiOptions(int uiOptions, int mask)2251     public void setUiOptions(int uiOptions, int mask) { }
2252 
2253     /**
2254      * Set the primary icon for this window.
2255      *
2256      * @param resId resource ID of a drawable to set
2257      */
setIcon(@rawableRes int resId)2258     public void setIcon(@DrawableRes int resId) { }
2259 
2260     /**
2261      * Set the default icon for this window.
2262      * This will be overridden by any other icon set operation which could come from the
2263      * theme or another explicit set.
2264      *
2265      * @hide
2266      */
setDefaultIcon(@rawableRes int resId)2267     public void setDefaultIcon(@DrawableRes int resId) { }
2268 
2269     /**
2270      * Set the logo for this window. A logo is often shown in place of an
2271      * {@link #setIcon(int) icon} but is generally wider and communicates window title information
2272      * as well.
2273      *
2274      * @param resId resource ID of a drawable to set
2275      */
setLogo(@rawableRes int resId)2276     public void setLogo(@DrawableRes int resId) { }
2277 
2278     /**
2279      * Set the default logo for this window.
2280      * This will be overridden by any other logo set operation which could come from the
2281      * theme or another explicit set.
2282      *
2283      * @hide
2284      */
setDefaultLogo(@rawableRes int resId)2285     public void setDefaultLogo(@DrawableRes int resId) { }
2286 
2287     /**
2288      * Set focus locally. The window should have the
2289      * {@link WindowManager.LayoutParams#FLAG_LOCAL_FOCUS_MODE} flag set already.
2290      * @param hasFocus Whether this window has focus or not.
2291      * @param inTouchMode Whether this window is in touch mode or not.
2292      */
setLocalFocus(boolean hasFocus, boolean inTouchMode)2293     public void setLocalFocus(boolean hasFocus, boolean inTouchMode) { }
2294 
2295     /**
2296      * Inject an event to window locally.
2297      * @param event A key or touch event to inject to this window.
2298      */
injectInputEvent(InputEvent event)2299     public void injectInputEvent(InputEvent event) { }
2300 
2301     /**
2302      * Retrieve the {@link TransitionManager} responsible for  for default transitions
2303      * in this window. Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
2304      *
2305      * <p>This method will return non-null after content has been initialized (e.g. by using
2306      * {@link #setContentView}) if {@link #FEATURE_CONTENT_TRANSITIONS} has been granted.</p>
2307      *
2308      * @return This window's content TransitionManager or null if none is set.
2309      * @attr ref android.R.styleable#Window_windowContentTransitionManager
2310      */
getTransitionManager()2311     public TransitionManager getTransitionManager() {
2312         return null;
2313     }
2314 
2315     /**
2316      * Set the {@link TransitionManager} to use for default transitions in this window.
2317      * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
2318      *
2319      * @param tm The TransitionManager to use for scene changes.
2320      * @attr ref android.R.styleable#Window_windowContentTransitionManager
2321      */
setTransitionManager(TransitionManager tm)2322     public void setTransitionManager(TransitionManager tm) {
2323         throw new UnsupportedOperationException();
2324     }
2325 
2326     /**
2327      * Retrieve the {@link Scene} representing this window's current content.
2328      * Requires {@link #FEATURE_CONTENT_TRANSITIONS}.
2329      *
2330      * <p>This method will return null if the current content is not represented by a Scene.</p>
2331      *
2332      * @return Current Scene being shown or null
2333      */
getContentScene()2334     public Scene getContentScene() {
2335         return null;
2336     }
2337 
2338     /**
2339      * Sets the Transition that will be used to move Views into the initial scene. The entering
2340      * Views will be those that are regular Views or ViewGroups that have
2341      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2342      * {@link android.transition.Visibility} as entering is governed by changing visibility from
2343      * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
2344      * entering Views will remain unaffected.
2345      *
2346      * @param transition The Transition to use to move Views into the initial Scene.
2347      * @attr ref android.R.styleable#Window_windowEnterTransition
2348      */
setEnterTransition(Transition transition)2349     public void setEnterTransition(Transition transition) {}
2350 
2351     /**
2352      * Sets the Transition that will be used to move Views out of the scene when the Window is
2353      * preparing to close, for example after a call to
2354      * {@link android.app.Activity#finishAfterTransition()}. The exiting
2355      * Views will be those that are regular Views or ViewGroups that have
2356      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2357      * {@link android.transition.Visibility} as entering is governed by changing visibility from
2358      * {@link View#VISIBLE} to {@link View#INVISIBLE}. If <code>transition</code> is null,
2359      * entering Views will remain unaffected. If nothing is set, the default will be to
2360      * use the same value as set in {@link #setEnterTransition(android.transition.Transition)}.
2361      *
2362      * @param transition The Transition to use to move Views out of the Scene when the Window
2363      *                   is preparing to close.
2364      * @attr ref android.R.styleable#Window_windowReturnTransition
2365      */
setReturnTransition(Transition transition)2366     public void setReturnTransition(Transition transition) {}
2367 
2368     /**
2369      * Sets the Transition that will be used to move Views out of the scene when starting a
2370      * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
2371      * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2372      * {@link android.transition.Visibility} as exiting is governed by changing visibility
2373      * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
2374      * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2375      *
2376      * @param transition The Transition to use to move Views out of the scene when calling a
2377      *                   new Activity.
2378      * @attr ref android.R.styleable#Window_windowExitTransition
2379      */
setExitTransition(Transition transition)2380     public void setExitTransition(Transition transition) {}
2381 
2382     /**
2383      * Sets the Transition that will be used to move Views in to the scene when returning from
2384      * a previously-started Activity. The entering Views will be those that are regular Views
2385      * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
2386      * will extend {@link android.transition.Visibility} as exiting is governed by changing
2387      * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null,
2388      * the views will remain unaffected. If nothing is set, the default will be to use the same
2389      * transition as {@link #setExitTransition(android.transition.Transition)}.
2390      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2391      *
2392      * @param transition The Transition to use to move Views into the scene when reentering from a
2393      *                   previously-started Activity.
2394      * @attr ref android.R.styleable#Window_windowReenterTransition
2395      */
setReenterTransition(Transition transition)2396     public void setReenterTransition(Transition transition) {}
2397 
2398     /**
2399      * Returns the transition used to move Views into the initial scene. The entering
2400      * Views will be those that are regular Views or ViewGroups that have
2401      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2402      * {@link android.transition.Visibility} as entering is governed by changing visibility from
2403      * {@link View#INVISIBLE} to {@link View#VISIBLE}. If <code>transition</code> is null,
2404      * entering Views will remain unaffected.  Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2405      *
2406      * @return the Transition to use to move Views into the initial Scene.
2407      * @attr ref android.R.styleable#Window_windowEnterTransition
2408      */
getEnterTransition()2409     public Transition getEnterTransition() { return null; }
2410 
2411     /**
2412      * Returns the Transition that will be used to move Views out of the scene when the Window is
2413      * preparing to close, for example after a call to
2414      * {@link android.app.Activity#finishAfterTransition()}. The exiting
2415      * Views will be those that are regular Views or ViewGroups that have
2416      * {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2417      * {@link android.transition.Visibility} as entering is governed by changing visibility from
2418      * {@link View#VISIBLE} to {@link View#INVISIBLE}.
2419      *
2420      * @return The Transition to use to move Views out of the Scene when the Window
2421      *         is preparing to close.
2422      * @attr ref android.R.styleable#Window_windowReturnTransition
2423      */
getReturnTransition()2424     public Transition getReturnTransition() { return null; }
2425 
2426     /**
2427      * Returns the Transition that will be used to move Views out of the scene when starting a
2428      * new Activity. The exiting Views will be those that are regular Views or ViewGroups that
2429      * have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions will extend
2430      * {@link android.transition.Visibility} as exiting is governed by changing visibility
2431      * from {@link View#VISIBLE} to {@link View#INVISIBLE}. If transition is null, the views will
2432      * remain unaffected. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2433      *
2434      * @return the Transition to use to move Views out of the scene when calling a
2435      * new Activity.
2436      * @attr ref android.R.styleable#Window_windowExitTransition
2437      */
getExitTransition()2438     public Transition getExitTransition() { return null; }
2439 
2440     /**
2441      * Returns the Transition that will be used to move Views in to the scene when returning from
2442      * a previously-started Activity. The entering Views will be those that are regular Views
2443      * or ViewGroups that have {@link ViewGroup#isTransitionGroup} return true. Typical Transitions
2444      * will extend {@link android.transition.Visibility} as exiting is governed by changing
2445      * visibility from {@link View#VISIBLE} to {@link View#INVISIBLE}.
2446      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2447      *
2448      * @return The Transition to use to move Views into the scene when reentering from a
2449      *         previously-started Activity.
2450      * @attr ref android.R.styleable#Window_windowReenterTransition
2451      */
getReenterTransition()2452     public Transition getReenterTransition() { return null; }
2453 
2454     /**
2455      * Sets the Transition that will be used for shared elements transferred into the content
2456      * Scene. Typical Transitions will affect size and location, such as
2457      * {@link android.transition.ChangeBounds}. A null
2458      * value will cause transferred shared elements to blink to the final position.
2459      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2460      *
2461      * @param transition The Transition to use for shared elements transferred into the content
2462      *                   Scene.
2463      * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
2464      */
setSharedElementEnterTransition(Transition transition)2465     public void setSharedElementEnterTransition(Transition transition) {}
2466 
2467     /**
2468      * Sets the Transition that will be used for shared elements transferred back to a
2469      * calling Activity. Typical Transitions will affect size and location, such as
2470      * {@link android.transition.ChangeBounds}. A null
2471      * value will cause transferred shared elements to blink to the final position.
2472      * If no value is set, the default will be to use the same value as
2473      * {@link #setSharedElementEnterTransition(android.transition.Transition)}.
2474      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2475      *
2476      * @param transition The Transition to use for shared elements transferred out of the content
2477      *                   Scene.
2478      * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
2479      */
setSharedElementReturnTransition(Transition transition)2480     public void setSharedElementReturnTransition(Transition transition) {}
2481 
2482     /**
2483      * Returns the Transition that will be used for shared elements transferred into the content
2484      * Scene. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2485      *
2486      * @return Transition to use for sharend elements transferred into the content Scene.
2487      * @attr ref android.R.styleable#Window_windowSharedElementEnterTransition
2488      */
getSharedElementEnterTransition()2489     public Transition getSharedElementEnterTransition() { return null; }
2490 
2491     /**
2492      * Returns the Transition that will be used for shared elements transferred back to a
2493      * calling Activity. Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2494      *
2495      * @return Transition to use for sharend elements transferred into the content Scene.
2496      * @attr ref android.R.styleable#Window_windowSharedElementReturnTransition
2497      */
getSharedElementReturnTransition()2498     public Transition getSharedElementReturnTransition() { return null; }
2499 
2500     /**
2501      * Sets the Transition that will be used for shared elements after starting a new Activity
2502      * before the shared elements are transferred to the called Activity. If the shared elements
2503      * must animate during the exit transition, this Transition should be used. Upon completion,
2504      * the shared elements may be transferred to the started Activity.
2505      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2506      *
2507      * @param transition The Transition to use for shared elements in the launching Window
2508      *                   prior to transferring to the launched Activity's Window.
2509      * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
2510      */
setSharedElementExitTransition(Transition transition)2511     public void setSharedElementExitTransition(Transition transition) {}
2512 
2513     /**
2514      * Sets the Transition that will be used for shared elements reentering from a started
2515      * Activity after it has returned the shared element to it start location. If no value
2516      * is set, this will default to
2517      * {@link #setSharedElementExitTransition(android.transition.Transition)}.
2518      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2519      *
2520      * @param transition The Transition to use for shared elements in the launching Window
2521      *                   after the shared element has returned to the Window.
2522      * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
2523      */
setSharedElementReenterTransition(Transition transition)2524     public void setSharedElementReenterTransition(Transition transition) {}
2525 
2526     /**
2527      * Returns the Transition to use for shared elements in the launching Window prior
2528      * to transferring to the launched Activity's Window.
2529      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2530      *
2531      * @return the Transition to use for shared elements in the launching Window prior
2532      * to transferring to the launched Activity's Window.
2533      * @attr ref android.R.styleable#Window_windowSharedElementExitTransition
2534      */
getSharedElementExitTransition()2535     public Transition getSharedElementExitTransition() { return null; }
2536 
2537     /**
2538      * Returns the Transition that will be used for shared elements reentering from a started
2539      * Activity after it has returned the shared element to it start location.
2540      * Requires {@link #FEATURE_ACTIVITY_TRANSITIONS}.
2541      *
2542      * @return the Transition that will be used for shared elements reentering from a started
2543      * Activity after it has returned the shared element to it start location.
2544      * @attr ref android.R.styleable#Window_windowSharedElementReenterTransition
2545      */
getSharedElementReenterTransition()2546     public Transition getSharedElementReenterTransition() { return null; }
2547 
2548     /**
2549      * Controls how the transition set in
2550      * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
2551      * transition of the calling Activity. When true, the transition will start as soon as possible.
2552      * When false, the transition will wait until the remote exiting transition completes before
2553      * starting. The default value is true.
2554      *
2555      * @param allow true to start the enter transition when possible or false to
2556      *              wait until the exiting transition completes.
2557      * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
2558      */
setAllowEnterTransitionOverlap(boolean allow)2559     public void setAllowEnterTransitionOverlap(boolean allow) {}
2560 
2561     /**
2562      * Returns how the transition set in
2563      * {@link #setEnterTransition(android.transition.Transition)} overlaps with the exit
2564      * transition of the calling Activity. When true, the transition will start as soon as possible.
2565      * When false, the transition will wait until the remote exiting transition completes before
2566      * starting. The default value is true.
2567      *
2568      * @return true when the enter transition should start as soon as possible or false to
2569      * when it should wait until the exiting transition completes.
2570      * @attr ref android.R.styleable#Window_windowAllowEnterTransitionOverlap
2571      */
getAllowEnterTransitionOverlap()2572     public boolean getAllowEnterTransitionOverlap() { return true; }
2573 
2574     /**
2575      * Controls how the transition set in
2576      * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
2577      * transition of the called Activity when reentering after if finishes. When true,
2578      * the transition will start as soon as possible. When false, the transition will wait
2579      * until the called Activity's exiting transition completes before starting.
2580      * The default value is true.
2581      *
2582      * @param allow true to start the transition when possible or false to wait until the
2583      *              called Activity's exiting transition completes.
2584      * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
2585      */
setAllowReturnTransitionOverlap(boolean allow)2586     public void setAllowReturnTransitionOverlap(boolean allow) {}
2587 
2588     /**
2589      * Returns how the transition set in
2590      * {@link #setExitTransition(android.transition.Transition)} overlaps with the exit
2591      * transition of the called Activity when reentering after if finishes. When true,
2592      * the transition will start as soon as possible. When false, the transition will wait
2593      * until the called Activity's exiting transition completes before starting.
2594      * The default value is true.
2595      *
2596      * @return true when the transition should start when possible or false when it should wait
2597      * until the called Activity's exiting transition completes.
2598      * @attr ref android.R.styleable#Window_windowAllowReturnTransitionOverlap
2599      */
getAllowReturnTransitionOverlap()2600     public boolean getAllowReturnTransitionOverlap() { return true; }
2601 
2602     /**
2603      * Returns the duration, in milliseconds, of the window background fade
2604      * when transitioning into or away from an Activity when called with an Activity Transition.
2605      * <p>When executing the enter transition, the background starts transparent
2606      * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
2607      * 300 milliseconds.</p>
2608      *
2609      * @return The duration of the window background fade to opaque during enter transition.
2610      * @see #getEnterTransition()
2611      * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
2612      */
getTransitionBackgroundFadeDuration()2613     public long getTransitionBackgroundFadeDuration() { return 0; }
2614 
2615     /**
2616      * Sets the duration, in milliseconds, of the window background fade
2617      * when transitioning into or away from an Activity when called with an Activity Transition.
2618      * <p>When executing the enter transition, the background starts transparent
2619      * and fades in. This requires {@link #FEATURE_ACTIVITY_TRANSITIONS}. The default is
2620      * 300 milliseconds.</p>
2621      *
2622      * @param fadeDurationMillis The duration of the window background fade to or from opaque
2623      *                           during enter transition.
2624      * @see #setEnterTransition(android.transition.Transition)
2625      * @attr ref android.R.styleable#Window_windowTransitionBackgroundFadeDuration
2626      */
setTransitionBackgroundFadeDuration(long fadeDurationMillis)2627     public void setTransitionBackgroundFadeDuration(long fadeDurationMillis) { }
2628 
2629     /**
2630      * Returns <code>true</code> when shared elements should use an Overlay during
2631      * shared element transitions or <code>false</code> when they should animate as
2632      * part of the normal View hierarchy. The default value is true.
2633      *
2634      * @return <code>true</code> when shared elements should use an Overlay during
2635      * shared element transitions or <code>false</code> when they should animate as
2636      * part of the normal View hierarchy.
2637      * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
2638      */
getSharedElementsUseOverlay()2639     public boolean getSharedElementsUseOverlay() { return true; }
2640 
2641     /**
2642      * Sets whether or not shared elements should use an Overlay during shared element transitions.
2643      * The default value is true.
2644      *
2645      * @param sharedElementsUseOverlay <code>true</code> indicates that shared elements should
2646      *                                 be transitioned with an Overlay or <code>false</code>
2647      *                                 to transition within the normal View hierarchy.
2648      * @attr ref android.R.styleable#Window_windowSharedElementsUseOverlay
2649      */
setSharedElementsUseOverlay(boolean sharedElementsUseOverlay)2650     public void setSharedElementsUseOverlay(boolean sharedElementsUseOverlay) { }
2651 
2652     /**
2653      * @return the color of the status bar.
2654      * @deprecated This is no longer needed since the setter is deprecated.
2655      */
2656     @Deprecated
2657     @ColorInt
getStatusBarColor()2658     public abstract int getStatusBarColor();
2659 
2660     /**
2661      * Sets the color of the status bar to {@code color}.
2662      *
2663      * For this to take effect,
2664      * the window must be drawing the system bar backgrounds with
2665      * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
2666      * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS} must not be set.
2667      *
2668      * If {@code color} is not opaque, consider setting
2669      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
2670      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.
2671      * <p>
2672      * The transitionName for the view background will be "android:status:background".
2673      *
2674      * <p>
2675      * If the color is transparent and the window enforces the status bar contrast, the system
2676      * will determine whether a scrim is necessary and draw one on behalf of the app to ensure
2677      * that the status bar has enough contrast with the contents of this app, and set an appropriate
2678      * effective bar background accordingly.
2679      *
2680      * <p>
2681      * If the app targets
2682      * {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM VANILLA_ICE_CREAM} or above,
2683      * the color will be transparent and cannot be changed.
2684      *
2685      * @see #setNavigationBarContrastEnforced
2686      * @deprecated Draw proper background behind {@link WindowInsets.Type#statusBars()}} instead.
2687      */
2688     @Deprecated
setStatusBarColor(@olorInt int color)2689     public abstract void setStatusBarColor(@ColorInt int color);
2690 
2691     /**
2692      * @return the color of the navigation bar.
2693      * @deprecated This is no longer needed since the setter is deprecated.
2694      */
2695     @Deprecated
2696     @ColorInt
getNavigationBarColor()2697     public abstract int getNavigationBarColor();
2698 
2699     /**
2700      * Sets the color of the navigation bar to {@param color}.
2701      *
2702      * For this to take effect,
2703      * the window must be drawing the system bar backgrounds with
2704      * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
2705      * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
2706      *
2707      * If {@param color} is not opaque, consider setting
2708      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
2709      * {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.
2710      * <p>
2711      * The transitionName for the view background will be "android:navigation:background".
2712      *
2713      * <p>
2714      * If the color is transparent and the window enforces the navigation bar contrast, the system
2715      * will determine whether a scrim is necessary and draw one on behalf of the app to ensure that
2716      * the navigation bar has enough contrast with the contents of this app, and set an appropriate
2717      * effective bar background accordingly.
2718      *
2719      * <p>
2720      * If the app targets
2721      * {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM VANILLA_ICE_CREAM} or above,
2722      * the color will be transparent and cannot be changed.
2723      *
2724      * @attr ref android.R.styleable#Window_navigationBarColor
2725      * @see #setNavigationBarContrastEnforced
2726      * @deprecated Draw proper background behind {@link WindowInsets.Type#navigationBars()} or
2727      *             {@link WindowInsets.Type#tappableElement()} instead.
2728      */
2729     @Deprecated
setNavigationBarColor(@olorInt int color)2730     public abstract void setNavigationBarColor(@ColorInt int color);
2731 
2732     /**
2733      * Shows a thin line of the specified color between the navigation bar and the app
2734      * content.
2735      * <p>
2736      * For this to take effect,
2737      * the window must be drawing the system bar backgrounds with
2738      * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and
2739      * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION} must not be set.
2740      *
2741      * <p>
2742      * If the app targets
2743      * {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM VANILLA_ICE_CREAM} or above,
2744      * the color will be transparent and cannot be changed.
2745      *
2746      * @param dividerColor The color of the thin line.
2747      * @attr ref android.R.styleable#Window_navigationBarDividerColor
2748      * @deprecated Draw proper background behind {@link WindowInsets.Type#navigationBars()} or
2749      *             {@link WindowInsets.Type#tappableElement()} instead.
2750      */
2751     @Deprecated
setNavigationBarDividerColor(@olorInt int dividerColor)2752     public void setNavigationBarDividerColor(@ColorInt int dividerColor) {
2753     }
2754 
2755     /**
2756      * Retrieves the color of the navigation bar divider.
2757      *
2758      * @return The color of the navigation bar divider color.
2759      * @see #setNavigationBarColor(int)
2760      * @attr ref android.R.styleable#Window_navigationBarDividerColor
2761      * @deprecated This is no longer needed since the setter is deprecated.
2762      */
2763     @Deprecated
getNavigationBarDividerColor()2764     public @ColorInt int getNavigationBarDividerColor() {
2765         return 0;
2766     }
2767 
2768     /**
2769      * Sets whether the system should ensure that the status bar has enough
2770      * contrast when a fully transparent background is requested.
2771      *
2772      * <p>If set to this value, the system will determine whether a scrim is necessary
2773      * to ensure that the status bar has enough contrast with the contents of
2774      * this app, and set an appropriate effective bar background color accordingly.
2775      *
2776      * <p>When the status bar color has a non-zero alpha value, the value of this
2777      * property has no effect.
2778      *
2779      * @see android.R.attr#enforceStatusBarContrast
2780      * @see #isStatusBarContrastEnforced
2781      * @see #setStatusBarColor
2782      * @deprecated Draw proper background behind {@link WindowInsets.Type#statusBars()}} instead.
2783      */
2784     @Deprecated
setStatusBarContrastEnforced(boolean ensureContrast)2785     public void setStatusBarContrastEnforced(boolean ensureContrast) {
2786     }
2787 
2788     /**
2789      * Returns whether the system is ensuring that the status bar has enough contrast when a
2790      * fully transparent background is requested.
2791      *
2792      * <p>When the status bar color has a non-zero alpha value, the value of this
2793      * property has no effect.
2794      *
2795      * @return true, if the system is ensuring contrast, false otherwise.
2796      * @see android.R.attr#enforceStatusBarContrast
2797      * @see #setStatusBarContrastEnforced
2798      * @see #setStatusBarColor
2799      * @deprecated This is not needed since the setter is deprecated.
2800      */
2801     @Deprecated
isStatusBarContrastEnforced()2802     public boolean isStatusBarContrastEnforced() {
2803         return false;
2804     }
2805 
2806     /**
2807      * Sets whether the system should ensure that the navigation bar has enough
2808      * contrast when a fully transparent background is requested.
2809      *
2810      * <p>If set to this value, the system will determine whether a scrim is necessary
2811      * to ensure that the navigation bar has enough contrast with the contents of
2812      * this app, and set an appropriate effective bar background color accordingly.
2813      *
2814      * <p>When the navigation bar color has a non-zero alpha value, the value of this
2815      * property has no effect.
2816      *
2817      * @see android.R.attr#enforceNavigationBarContrast
2818      * @see #isNavigationBarContrastEnforced
2819      * @see #setNavigationBarColor
2820      */
setNavigationBarContrastEnforced(boolean enforceContrast)2821     public void setNavigationBarContrastEnforced(boolean enforceContrast) {
2822     }
2823 
2824     /**
2825      * Returns whether the system is ensuring that the navigation bar has enough contrast when a
2826      * fully transparent background is requested.
2827      *
2828      * <p>When the navigation bar color has a non-zero alpha value, the value of this
2829      * property has no effect.
2830      *
2831      * @return true, if the system is ensuring contrast, false otherwise.
2832      * @see android.R.attr#enforceNavigationBarContrast
2833      * @see #setNavigationBarContrastEnforced
2834      * @see #setNavigationBarColor
2835      */
isNavigationBarContrastEnforced()2836     public boolean isNavigationBarContrastEnforced() {
2837         return false;
2838     }
2839 
2840     /**
2841      * Sets a list of areas within this window's coordinate space where the system should not
2842      * intercept touch or other pointing device gestures.
2843      *
2844      * <p>This method should be used by apps that make use of
2845      * {@link #takeSurface(SurfaceHolder.Callback2)} and do not have a view hierarchy available.
2846      * Apps that do have a view hierarchy should use
2847      * {@link View#setSystemGestureExclusionRects(List)} instead. This method does not modify or
2848      * replace the gesture exclusion rects populated by individual views in this window's view
2849      * hierarchy using {@link View#setSystemGestureExclusionRects(List)}.</p>
2850      *
2851      * <p>Use this to tell the system which specific sub-areas of a view need to receive gesture
2852      * input in order to function correctly in the presence of global system gestures that may
2853      * conflict. For example, if the system wishes to capture swipe-in-from-screen-edge gestures
2854      * to provide system-level navigation functionality, a view such as a navigation drawer
2855      * container can mark the left (or starting) edge of itself as requiring gesture capture
2856      * priority using this API. The system may then choose to relax its own gesture recognition
2857      * to allow the app to consume the user's gesture. It is not necessary for an app to register
2858      * exclusion rects for broadly spanning regions such as the entirety of a
2859      * <code>ScrollView</code> or for simple press and release click targets such as
2860      * <code>Button</code>. Mark an exclusion rect when interacting with a view requires
2861      * a precision touch gesture in a small area in either the X or Y dimension, such as
2862      * an edge swipe or dragging a <code>SeekBar</code> thumb.</p>
2863      *
2864      * <p>Do not modify the provided list after this method is called.</p>
2865      *
2866      * @param rects A list of precision gesture regions that this window needs to function correctly
2867      */
2868     @SuppressWarnings("unused")
setSystemGestureExclusionRects(@onNull List<Rect> rects)2869     public void setSystemGestureExclusionRects(@NonNull List<Rect> rects) {
2870         throw new UnsupportedOperationException("window does not support gesture exclusion rects");
2871     }
2872 
2873     /**
2874      * Retrieve the list of areas within this window's coordinate space where the system should not
2875      * intercept touch or other pointing device gestures. This is the list as set by
2876      * {@link #setSystemGestureExclusionRects(List)} or an empty list if
2877      * {@link #setSystemGestureExclusionRects(List)} has not been called. It does not include
2878      * exclusion rects set by this window's view hierarchy.
2879      *
2880      * @return a list of system gesture exclusion rects specific to this window
2881      */
2882     @NonNull
getSystemGestureExclusionRects()2883     public List<Rect> getSystemGestureExclusionRects() {
2884         return Collections.emptyList();
2885     }
2886 
2887     /**
2888      * System request to begin scroll capture.
2889      *
2890      * @param listener to receive the response
2891      * @hide
2892      */
requestScrollCapture(IScrollCaptureResponseListener listener)2893     public void requestScrollCapture(IScrollCaptureResponseListener listener) {
2894     }
2895 
2896     /**
2897      * Used to provide scroll capture support for an arbitrary window. This registeres the given
2898      * callback with the root view of the window.
2899      *
2900      * @param callback the callback to add
2901      */
registerScrollCaptureCallback(@onNull ScrollCaptureCallback callback)2902     public void registerScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) {
2903     }
2904 
2905     /**
2906      * Unregisters a {@link ScrollCaptureCallback} previously registered with this window.
2907      *
2908      * @param callback the callback to remove
2909      */
unregisterScrollCaptureCallback(@onNull ScrollCaptureCallback callback)2910     public void unregisterScrollCaptureCallback(@NonNull ScrollCaptureCallback callback) {
2911     }
2912 
2913     /** @hide */
setTheme(int resId)2914     public void setTheme(int resId) {
2915     }
2916 
2917     /**
2918      * Whether the caption should be displayed directly on the content rather than push the content
2919      * down. This affects only freeform windows since they display the caption.
2920      * @hide
2921      */
setOverlayWithDecorCaptionEnabled(boolean enabled)2922     public void setOverlayWithDecorCaptionEnabled(boolean enabled) {
2923         mOverlayWithDecorCaptionEnabled = enabled;
2924     }
2925 
2926     /** @hide */
isOverlayWithDecorCaptionEnabled()2927     public boolean isOverlayWithDecorCaptionEnabled() {
2928         return mOverlayWithDecorCaptionEnabled;
2929     }
2930 
2931     /** @hide */
notifyRestrictedCaptionAreaCallback(int left, int top, int right, int bottom)2932     public void notifyRestrictedCaptionAreaCallback(int left, int top, int right, int bottom) {
2933         if (mOnRestrictedCaptionAreaChangedListener != null) {
2934             mRestrictedCaptionAreaRect.set(left, top, right, bottom);
2935             mOnRestrictedCaptionAreaChangedListener.onRestrictedCaptionAreaChanged(
2936                     mRestrictedCaptionAreaRect);
2937         }
2938     }
2939 
2940     /**
2941      * Set what color should the caption controls be. By default the system will try to determine
2942      * the color from the theme. You can overwrite this by using {@link #DECOR_CAPTION_SHADE_DARK},
2943      * {@link #DECOR_CAPTION_SHADE_LIGHT}, or {@link #DECOR_CAPTION_SHADE_AUTO}.
2944      * @see #DECOR_CAPTION_SHADE_DARK
2945      * @see #DECOR_CAPTION_SHADE_LIGHT
2946      * @see #DECOR_CAPTION_SHADE_AUTO
2947      */
setDecorCaptionShade(int decorCaptionShade)2948     public abstract void setDecorCaptionShade(int decorCaptionShade);
2949 
2950     /**
2951      * Set the drawable that is drawn underneath the caption during the resizing.
2952      *
2953      * During the resizing the caption might not be drawn fast enough to match the new dimensions.
2954      * There is a second caption drawn underneath it that will be fast enough. By default the
2955      * caption is constructed from the theme. You can provide a drawable, that will be drawn instead
2956      * to better match your application.
2957      *
2958      * Starting in Android 15, this API is a no-op. New window decorations introduced in Android 14
2959      * are drawn in SystemUI process, and OEMs are responsible to make them responsive to resizing.
2960      * There is no need to set a background drawable to improve UX anymore since then. Additionally,
2961      * the foremost activity can draw in caption areas starting in Android 15. Check
2962      * {@link WindowInsetsController#APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND},
2963      * {@link WindowInsetsController#APPEARANCE_LIGHT_CAPTION_BARS},
2964      * {@link WindowInsetsController#setSystemBarsAppearance(int, int)} and
2965      * {@link WindowInsets#getBoundingRects(int)}.
2966      */
setResizingCaptionDrawable(Drawable drawable)2967     public abstract void setResizingCaptionDrawable(Drawable drawable);
2968 
2969     /**
2970      * Called when the activity changes from fullscreen mode to multi-window mode and visa-versa.
2971      * @hide
2972      */
2973     @SuppressWarnings("HiddenAbstractMethod")
onMultiWindowModeChanged()2974     public abstract void onMultiWindowModeChanged();
2975 
2976     /**
2977      * Called when the activity changes to/from picture-in-picture mode.
2978      * @hide
2979      */
2980     @SuppressWarnings("HiddenAbstractMethod")
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)2981     public abstract void onPictureInPictureModeChanged(boolean isInPictureInPictureMode);
2982 
2983     /**
2984      * @return The {@link WindowInsetsController} associated with this window
2985      * @see View#getWindowInsetsController()
2986      */
getInsetsController()2987     public @Nullable WindowInsetsController getInsetsController() {
2988         return null;
2989     }
2990 
2991     /**
2992      * This will be null before a content view is added, e.g. via
2993      * {@link #setContentView} or {@link #addContentView}. See
2994      * {@link android.view.View#getRootSurfaceControl}.
2995      *
2996      * @return The {@link android.view.AttachedSurfaceControl} interface for this Window
2997      */
getRootSurfaceControl()2998     public @Nullable AttachedSurfaceControl getRootSurfaceControl() {
2999         return null;
3000     }
3001 
3002     /**
3003      * Returns the {@link OnBackInvokedDispatcher} instance associated with this window.
3004      */
3005     @NonNull
getOnBackInvokedDispatcher()3006     public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
3007         throw new RuntimeException("Not implemented. Must override in a subclass.");
3008     }
3009 }
3010