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