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 android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.annotation.SystemService;
23 import android.annotation.TestApi;
24 import android.app.KeyguardManager;
25 import android.app.Presentation;
26 import android.content.Context;
27 import android.content.pm.ActivityInfo;
28 import android.graphics.PixelFormat;
29 import android.graphics.Rect;
30 import android.os.IBinder;
31 import android.os.Parcel;
32 import android.os.Parcelable;
33 import android.text.TextUtils;
34 import android.util.Log;
35 
36 import java.lang.annotation.Retention;
37 import java.lang.annotation.RetentionPolicy;
38 import java.util.List;
39 import java.util.Objects;
40 
41 /**
42  * The interface that apps use to talk to the window manager.
43  * </p><p>
44  * Each window manager instance is bound to a particular {@link Display}.
45  * To obtain a {@link WindowManager} for a different display, use
46  * {@link Context#createDisplayContext} to obtain a {@link Context} for that
47  * display, then use <code>Context.getSystemService(Context.WINDOW_SERVICE)</code>
48  * to get the WindowManager.
49  * </p><p>
50  * The simplest way to show a window on another display is to create a
51  * {@link Presentation}.  The presentation will automatically obtain a
52  * {@link WindowManager} and {@link Context} for that display.
53  * </p>
54  */
55 @SystemService(Context.WINDOW_SERVICE)
56 public interface WindowManager extends ViewManager {
57 
58     /** @hide */
59     int DOCKED_INVALID = -1;
60     /** @hide */
61     int DOCKED_LEFT = 1;
62     /** @hide */
63     int DOCKED_TOP = 2;
64     /** @hide */
65     int DOCKED_RIGHT = 3;
66     /** @hide */
67     int DOCKED_BOTTOM = 4;
68 
69     /** @hide */
70     final static String INPUT_CONSUMER_PIP = "pip_input_consumer";
71     /** @hide */
72     final static String INPUT_CONSUMER_NAVIGATION = "nav_input_consumer";
73     /** @hide */
74     final static String INPUT_CONSUMER_WALLPAPER = "wallpaper_input_consumer";
75 
76     /**
77      * Exception that is thrown when trying to add view whose
78      * {@link LayoutParams} {@link LayoutParams#token}
79      * is invalid.
80      */
81     public static class BadTokenException extends RuntimeException {
BadTokenException()82         public BadTokenException() {
83         }
84 
BadTokenException(String name)85         public BadTokenException(String name) {
86             super(name);
87         }
88     }
89 
90     /**
91      * Exception that is thrown when calling {@link #addView} to a secondary display that cannot
92      * be found. See {@link android.app.Presentation} for more information on secondary displays.
93      */
94     public static class InvalidDisplayException extends RuntimeException {
InvalidDisplayException()95         public InvalidDisplayException() {
96         }
97 
InvalidDisplayException(String name)98         public InvalidDisplayException(String name) {
99             super(name);
100         }
101     }
102 
103     /**
104      * Returns the {@link Display} upon which this {@link WindowManager} instance
105      * will create new windows.
106      * <p>
107      * Despite the name of this method, the display that is returned is not
108      * necessarily the primary display of the system (see {@link Display#DEFAULT_DISPLAY}).
109      * The returned display could instead be a secondary display that this
110      * window manager instance is managing.  Think of it as the display that
111      * this {@link WindowManager} instance uses by default.
112      * </p><p>
113      * To create windows on a different display, you need to obtain a
114      * {@link WindowManager} for that {@link Display}.  (See the {@link WindowManager}
115      * class documentation for more information.)
116      * </p>
117      *
118      * @return The display that this window manager is managing.
119      */
getDefaultDisplay()120     public Display getDefaultDisplay();
121 
122     /**
123      * Special variation of {@link #removeView} that immediately invokes
124      * the given view hierarchy's {@link View#onDetachedFromWindow()
125      * View.onDetachedFromWindow()} methods before returning.  This is not
126      * for normal applications; using it correctly requires great care.
127      *
128      * @param view The view to be removed.
129      */
removeViewImmediate(View view)130     public void removeViewImmediate(View view);
131 
132     /**
133      * Used to asynchronously request Keyboard Shortcuts from the focused window.
134      *
135      * @hide
136      */
137     public interface KeyboardShortcutsReceiver {
138         /**
139          * Callback used when the focused window keyboard shortcuts are ready to be displayed.
140          *
141          * @param result The keyboard shortcuts to be displayed.
142          */
onKeyboardShortcutsReceived(List<KeyboardShortcutGroup> result)143         void onKeyboardShortcutsReceived(List<KeyboardShortcutGroup> result);
144     }
145 
146     /**
147      * Message for taking fullscreen screenshot
148      * @hide
149      */
150     final int TAKE_SCREENSHOT_FULLSCREEN = 1;
151 
152     /**
153      * Message for taking screenshot of selected region.
154      * @hide
155      */
156     final int TAKE_SCREENSHOT_SELECTED_REGION = 2;
157 
158     /**
159      * @hide
160      */
161     public static final String PARCEL_KEY_SHORTCUTS_ARRAY = "shortcuts_array";
162 
163     /**
164      * Request for keyboard shortcuts to be retrieved asynchronously.
165      *
166      * @param receiver The callback to be triggered when the result is ready.
167      *
168      * @hide
169      */
requestAppKeyboardShortcuts(final KeyboardShortcutsReceiver receiver, int deviceId)170     public void requestAppKeyboardShortcuts(final KeyboardShortcutsReceiver receiver, int deviceId);
171 
172     public static class LayoutParams extends ViewGroup.LayoutParams implements Parcelable {
173         /**
174          * X position for this window.  With the default gravity it is ignored.
175          * When using {@link Gravity#LEFT} or {@link Gravity#START} or {@link Gravity#RIGHT} or
176          * {@link Gravity#END} it provides an offset from the given edge.
177          */
178         @ViewDebug.ExportedProperty
179         public int x;
180 
181         /**
182          * Y position for this window.  With the default gravity it is ignored.
183          * When using {@link Gravity#TOP} or {@link Gravity#BOTTOM} it provides
184          * an offset from the given edge.
185          */
186         @ViewDebug.ExportedProperty
187         public int y;
188 
189         /**
190          * Indicates how much of the extra space will be allocated horizontally
191          * to the view associated with these LayoutParams. Specify 0 if the view
192          * should not be stretched. Otherwise the extra pixels will be pro-rated
193          * among all views whose weight is greater than 0.
194          */
195         @ViewDebug.ExportedProperty
196         public float horizontalWeight;
197 
198         /**
199          * Indicates how much of the extra space will be allocated vertically
200          * to the view associated with these LayoutParams. Specify 0 if the view
201          * should not be stretched. Otherwise the extra pixels will be pro-rated
202          * among all views whose weight is greater than 0.
203          */
204         @ViewDebug.ExportedProperty
205         public float verticalWeight;
206 
207         /**
208          * The general type of window.  There are three main classes of
209          * window types:
210          * <ul>
211          * <li> <strong>Application windows</strong> (ranging from
212          * {@link #FIRST_APPLICATION_WINDOW} to
213          * {@link #LAST_APPLICATION_WINDOW}) are normal top-level application
214          * windows.  For these types of windows, the {@link #token} must be
215          * set to the token of the activity they are a part of (this will
216          * normally be done for you if {@link #token} is null).
217          * <li> <strong>Sub-windows</strong> (ranging from
218          * {@link #FIRST_SUB_WINDOW} to
219          * {@link #LAST_SUB_WINDOW}) are associated with another top-level
220          * window.  For these types of windows, the {@link #token} must be
221          * the token of the window it is attached to.
222          * <li> <strong>System windows</strong> (ranging from
223          * {@link #FIRST_SYSTEM_WINDOW} to
224          * {@link #LAST_SYSTEM_WINDOW}) are special types of windows for
225          * use by the system for specific purposes.  They should not normally
226          * be used by applications, and a special permission is required
227          * to use them.
228          * </ul>
229          *
230          * @see #TYPE_BASE_APPLICATION
231          * @see #TYPE_APPLICATION
232          * @see #TYPE_APPLICATION_STARTING
233          * @see #TYPE_DRAWN_APPLICATION
234          * @see #TYPE_APPLICATION_PANEL
235          * @see #TYPE_APPLICATION_MEDIA
236          * @see #TYPE_APPLICATION_SUB_PANEL
237          * @see #TYPE_APPLICATION_ABOVE_SUB_PANEL
238          * @see #TYPE_APPLICATION_ATTACHED_DIALOG
239          * @see #TYPE_STATUS_BAR
240          * @see #TYPE_SEARCH_BAR
241          * @see #TYPE_PHONE
242          * @see #TYPE_SYSTEM_ALERT
243          * @see #TYPE_TOAST
244          * @see #TYPE_SYSTEM_OVERLAY
245          * @see #TYPE_PRIORITY_PHONE
246          * @see #TYPE_STATUS_BAR_PANEL
247          * @see #TYPE_SYSTEM_DIALOG
248          * @see #TYPE_KEYGUARD_DIALOG
249          * @see #TYPE_SYSTEM_ERROR
250          * @see #TYPE_INPUT_METHOD
251          * @see #TYPE_INPUT_METHOD_DIALOG
252          */
253         @ViewDebug.ExportedProperty(mapping = {
254                 @ViewDebug.IntToString(from = TYPE_BASE_APPLICATION,
255                         to = "TYPE_BASE_APPLICATION"),
256                 @ViewDebug.IntToString(from = TYPE_APPLICATION,
257                         to = "TYPE_APPLICATION"),
258                 @ViewDebug.IntToString(from = TYPE_APPLICATION_STARTING,
259                         to = "TYPE_APPLICATION_STARTING"),
260                 @ViewDebug.IntToString(from = TYPE_DRAWN_APPLICATION,
261                         to = "TYPE_DRAWN_APPLICATION"),
262                 @ViewDebug.IntToString(from = TYPE_APPLICATION_PANEL,
263                         to = "TYPE_APPLICATION_PANEL"),
264                 @ViewDebug.IntToString(from = TYPE_APPLICATION_MEDIA,
265                         to = "TYPE_APPLICATION_MEDIA"),
266                 @ViewDebug.IntToString(from = TYPE_APPLICATION_SUB_PANEL,
267                         to = "TYPE_APPLICATION_SUB_PANEL"),
268                 @ViewDebug.IntToString(from = TYPE_APPLICATION_ABOVE_SUB_PANEL,
269                         to = "TYPE_APPLICATION_ABOVE_SUB_PANEL"),
270                 @ViewDebug.IntToString(from = TYPE_APPLICATION_ATTACHED_DIALOG,
271                         to = "TYPE_APPLICATION_ATTACHED_DIALOG"),
272                 @ViewDebug.IntToString(from = TYPE_APPLICATION_MEDIA_OVERLAY,
273                         to = "TYPE_APPLICATION_MEDIA_OVERLAY"),
274                 @ViewDebug.IntToString(from = TYPE_STATUS_BAR,
275                         to = "TYPE_STATUS_BAR"),
276                 @ViewDebug.IntToString(from = TYPE_SEARCH_BAR,
277                         to = "TYPE_SEARCH_BAR"),
278                 @ViewDebug.IntToString(from = TYPE_PHONE,
279                         to = "TYPE_PHONE"),
280                 @ViewDebug.IntToString(from = TYPE_SYSTEM_ALERT,
281                         to = "TYPE_SYSTEM_ALERT"),
282                 @ViewDebug.IntToString(from = TYPE_TOAST,
283                         to = "TYPE_TOAST"),
284                 @ViewDebug.IntToString(from = TYPE_SYSTEM_OVERLAY,
285                         to = "TYPE_SYSTEM_OVERLAY"),
286                 @ViewDebug.IntToString(from = TYPE_PRIORITY_PHONE,
287                         to = "TYPE_PRIORITY_PHONE"),
288                 @ViewDebug.IntToString(from = TYPE_SYSTEM_DIALOG,
289                         to = "TYPE_SYSTEM_DIALOG"),
290                 @ViewDebug.IntToString(from = TYPE_KEYGUARD_DIALOG,
291                         to = "TYPE_KEYGUARD_DIALOG"),
292                 @ViewDebug.IntToString(from = TYPE_SYSTEM_ERROR,
293                         to = "TYPE_SYSTEM_ERROR"),
294                 @ViewDebug.IntToString(from = TYPE_INPUT_METHOD,
295                         to = "TYPE_INPUT_METHOD"),
296                 @ViewDebug.IntToString(from = TYPE_INPUT_METHOD_DIALOG,
297                         to = "TYPE_INPUT_METHOD_DIALOG"),
298                 @ViewDebug.IntToString(from = TYPE_WALLPAPER,
299                         to = "TYPE_WALLPAPER"),
300                 @ViewDebug.IntToString(from = TYPE_STATUS_BAR_PANEL,
301                         to = "TYPE_STATUS_BAR_PANEL"),
302                 @ViewDebug.IntToString(from = TYPE_SECURE_SYSTEM_OVERLAY,
303                         to = "TYPE_SECURE_SYSTEM_OVERLAY"),
304                 @ViewDebug.IntToString(from = TYPE_DRAG,
305                         to = "TYPE_DRAG"),
306                 @ViewDebug.IntToString(from = TYPE_STATUS_BAR_SUB_PANEL,
307                         to = "TYPE_STATUS_BAR_SUB_PANEL"),
308                 @ViewDebug.IntToString(from = TYPE_POINTER,
309                         to = "TYPE_POINTER"),
310                 @ViewDebug.IntToString(from = TYPE_NAVIGATION_BAR,
311                         to = "TYPE_NAVIGATION_BAR"),
312                 @ViewDebug.IntToString(from = TYPE_VOLUME_OVERLAY,
313                         to = "TYPE_VOLUME_OVERLAY"),
314                 @ViewDebug.IntToString(from = TYPE_BOOT_PROGRESS,
315                         to = "TYPE_BOOT_PROGRESS"),
316                 @ViewDebug.IntToString(from = TYPE_INPUT_CONSUMER,
317                         to = "TYPE_INPUT_CONSUMER"),
318                 @ViewDebug.IntToString(from = TYPE_DREAM,
319                         to = "TYPE_DREAM"),
320                 @ViewDebug.IntToString(from = TYPE_NAVIGATION_BAR_PANEL,
321                         to = "TYPE_NAVIGATION_BAR_PANEL"),
322                 @ViewDebug.IntToString(from = TYPE_DISPLAY_OVERLAY,
323                         to = "TYPE_DISPLAY_OVERLAY"),
324                 @ViewDebug.IntToString(from = TYPE_MAGNIFICATION_OVERLAY,
325                         to = "TYPE_MAGNIFICATION_OVERLAY"),
326                 @ViewDebug.IntToString(from = TYPE_PRESENTATION,
327                         to = "TYPE_PRESENTATION"),
328                 @ViewDebug.IntToString(from = TYPE_PRIVATE_PRESENTATION,
329                         to = "TYPE_PRIVATE_PRESENTATION"),
330                 @ViewDebug.IntToString(from = TYPE_VOICE_INTERACTION,
331                         to = "TYPE_VOICE_INTERACTION"),
332                 @ViewDebug.IntToString(from = TYPE_VOICE_INTERACTION_STARTING,
333                         to = "TYPE_VOICE_INTERACTION_STARTING"),
334                 @ViewDebug.IntToString(from = TYPE_DOCK_DIVIDER,
335                         to = "TYPE_DOCK_DIVIDER"),
336                 @ViewDebug.IntToString(from = TYPE_QS_DIALOG,
337                         to = "TYPE_QS_DIALOG"),
338                 @ViewDebug.IntToString(from = TYPE_SCREENSHOT,
339                         to = "TYPE_SCREENSHOT"),
340                 @ViewDebug.IntToString(from = TYPE_APPLICATION_OVERLAY,
341                         to = "TYPE_APPLICATION_OVERLAY")
342         })
343         public int type;
344 
345         /**
346          * Start of window types that represent normal application windows.
347          */
348         public static final int FIRST_APPLICATION_WINDOW = 1;
349 
350         /**
351          * Window type: an application window that serves as the "base" window
352          * of the overall application; all other application windows will
353          * appear on top of it.
354          * In multiuser systems shows only on the owning user's window.
355          */
356         public static final int TYPE_BASE_APPLICATION   = 1;
357 
358         /**
359          * Window type: a normal application window.  The {@link #token} must be
360          * an Activity token identifying who the window belongs to.
361          * In multiuser systems shows only on the owning user's window.
362          */
363         public static final int TYPE_APPLICATION        = 2;
364 
365         /**
366          * Window type: special application window that is displayed while the
367          * application is starting.  Not for use by applications themselves;
368          * this is used by the system to display something until the
369          * application can show its own windows.
370          * In multiuser systems shows on all users' windows.
371          */
372         public static final int TYPE_APPLICATION_STARTING = 3;
373 
374         /**
375          * Window type: a variation on TYPE_APPLICATION that ensures the window
376          * manager will wait for this window to be drawn before the app is shown.
377          * In multiuser systems shows only on the owning user's window.
378          */
379         public static final int TYPE_DRAWN_APPLICATION = 4;
380 
381         /**
382          * End of types of application windows.
383          */
384         public static final int LAST_APPLICATION_WINDOW = 99;
385 
386         /**
387          * Start of types of sub-windows.  The {@link #token} of these windows
388          * must be set to the window they are attached to.  These types of
389          * windows are kept next to their attached window in Z-order, and their
390          * coordinate space is relative to their attached window.
391          */
392         public static final int FIRST_SUB_WINDOW = 1000;
393 
394         /**
395          * Window type: a panel on top of an application window.  These windows
396          * appear on top of their attached window.
397          */
398         public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW;
399 
400         /**
401          * Window type: window for showing media (such as video).  These windows
402          * are displayed behind their attached window.
403          */
404         public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1;
405 
406         /**
407          * Window type: a sub-panel on top of an application window.  These
408          * windows are displayed on top their attached window and any
409          * {@link #TYPE_APPLICATION_PANEL} panels.
410          */
411         public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2;
412 
413         /** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout
414          * of the window happens as that of a top-level window, <em>not</em>
415          * as a child of its container.
416          */
417         public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3;
418 
419         /**
420          * Window type: window for showing overlays on top of media windows.
421          * These windows are displayed between TYPE_APPLICATION_MEDIA and the
422          * application window.  They should be translucent to be useful.  This
423          * is a big ugly hack so:
424          * @hide
425          */
426         public static final int TYPE_APPLICATION_MEDIA_OVERLAY  = FIRST_SUB_WINDOW + 4;
427 
428         /**
429          * Window type: a above sub-panel on top of an application window and it's
430          * sub-panel windows. These windows are displayed on top of their attached window
431          * and any {@link #TYPE_APPLICATION_SUB_PANEL} panels.
432          * @hide
433          */
434         public static final int TYPE_APPLICATION_ABOVE_SUB_PANEL = FIRST_SUB_WINDOW + 5;
435 
436         /**
437          * End of types of sub-windows.
438          */
439         public static final int LAST_SUB_WINDOW = 1999;
440 
441         /**
442          * Start of system-specific window types.  These are not normally
443          * created by applications.
444          */
445         public static final int FIRST_SYSTEM_WINDOW     = 2000;
446 
447         /**
448          * Window type: the status bar.  There can be only one status bar
449          * window; it is placed at the top of the screen, and all other
450          * windows are shifted down so they are below it.
451          * In multiuser systems shows on all users' windows.
452          */
453         public static final int TYPE_STATUS_BAR         = FIRST_SYSTEM_WINDOW;
454 
455         /**
456          * Window type: the search bar.  There can be only one search bar
457          * window; it is placed at the top of the screen.
458          * In multiuser systems shows on all users' windows.
459          */
460         public static final int TYPE_SEARCH_BAR         = FIRST_SYSTEM_WINDOW+1;
461 
462         /**
463          * Window type: phone.  These are non-application windows providing
464          * user interaction with the phone (in particular incoming calls).
465          * These windows are normally placed above all applications, but behind
466          * the status bar.
467          * In multiuser systems shows on all users' windows.
468          * @deprecated for non-system apps. Use {@link #TYPE_APPLICATION_OVERLAY} instead.
469          */
470         @Deprecated
471         public static final int TYPE_PHONE              = FIRST_SYSTEM_WINDOW+2;
472 
473         /**
474          * Window type: system window, such as low power alert. These windows
475          * are always on top of application windows.
476          * In multiuser systems shows only on the owning user's window.
477          * @deprecated for non-system apps. Use {@link #TYPE_APPLICATION_OVERLAY} instead.
478          */
479         @Deprecated
480         public static final int TYPE_SYSTEM_ALERT       = FIRST_SYSTEM_WINDOW+3;
481 
482         /**
483          * Window type: keyguard window.
484          * In multiuser systems shows on all users' windows.
485          * @removed
486          */
487         public static final int TYPE_KEYGUARD           = FIRST_SYSTEM_WINDOW+4;
488 
489         /**
490          * Window type: transient notifications.
491          * In multiuser systems shows only on the owning user's window.
492          * @deprecated for non-system apps. Use {@link #TYPE_APPLICATION_OVERLAY} instead.
493          */
494         @Deprecated
495         public static final int TYPE_TOAST              = FIRST_SYSTEM_WINDOW+5;
496 
497         /**
498          * Window type: system overlay windows, which need to be displayed
499          * on top of everything else.  These windows must not take input
500          * focus, or they will interfere with the keyguard.
501          * In multiuser systems shows only on the owning user's window.
502          * @deprecated for non-system apps. Use {@link #TYPE_APPLICATION_OVERLAY} instead.
503          */
504         @Deprecated
505         public static final int TYPE_SYSTEM_OVERLAY     = FIRST_SYSTEM_WINDOW+6;
506 
507         /**
508          * Window type: priority phone UI, which needs to be displayed even if
509          * the keyguard is active.  These windows must not take input
510          * focus, or they will interfere with the keyguard.
511          * In multiuser systems shows on all users' windows.
512          * @deprecated for non-system apps. Use {@link #TYPE_APPLICATION_OVERLAY} instead.
513          */
514         @Deprecated
515         public static final int TYPE_PRIORITY_PHONE     = FIRST_SYSTEM_WINDOW+7;
516 
517         /**
518          * Window type: panel that slides out from the status bar
519          * In multiuser systems shows on all users' windows.
520          */
521         public static final int TYPE_SYSTEM_DIALOG      = FIRST_SYSTEM_WINDOW+8;
522 
523         /**
524          * Window type: dialogs that the keyguard shows
525          * In multiuser systems shows on all users' windows.
526          */
527         public static final int TYPE_KEYGUARD_DIALOG    = FIRST_SYSTEM_WINDOW+9;
528 
529         /**
530          * Window type: internal system error windows, appear on top of
531          * everything they can.
532          * In multiuser systems shows only on the owning user's window.
533          * @deprecated for non-system apps. Use {@link #TYPE_APPLICATION_OVERLAY} instead.
534          */
535         @Deprecated
536         public static final int TYPE_SYSTEM_ERROR       = FIRST_SYSTEM_WINDOW+10;
537 
538         /**
539          * Window type: internal input methods windows, which appear above
540          * the normal UI.  Application windows may be resized or panned to keep
541          * the input focus visible while this window is displayed.
542          * In multiuser systems shows only on the owning user's window.
543          */
544         public static final int TYPE_INPUT_METHOD       = FIRST_SYSTEM_WINDOW+11;
545 
546         /**
547          * Window type: internal input methods dialog windows, which appear above
548          * the current input method window.
549          * In multiuser systems shows only on the owning user's window.
550          */
551         public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12;
552 
553         /**
554          * Window type: wallpaper window, placed behind any window that wants
555          * to sit on top of the wallpaper.
556          * In multiuser systems shows only on the owning user's window.
557          */
558         public static final int TYPE_WALLPAPER          = FIRST_SYSTEM_WINDOW+13;
559 
560         /**
561          * Window type: panel that slides out from over the status bar
562          * In multiuser systems shows on all users' windows.
563          */
564         public static final int TYPE_STATUS_BAR_PANEL   = FIRST_SYSTEM_WINDOW+14;
565 
566         /**
567          * Window type: secure system overlay windows, which need to be displayed
568          * on top of everything else.  These windows must not take input
569          * focus, or they will interfere with the keyguard.
570          *
571          * This is exactly like {@link #TYPE_SYSTEM_OVERLAY} except that only the
572          * system itself is allowed to create these overlays.  Applications cannot
573          * obtain permission to create secure system overlays.
574          *
575          * In multiuser systems shows only on the owning user's window.
576          * @hide
577          */
578         public static final int TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15;
579 
580         /**
581          * Window type: the drag-and-drop pseudowindow.  There is only one
582          * drag layer (at most), and it is placed on top of all other windows.
583          * In multiuser systems shows only on the owning user's window.
584          * @hide
585          */
586         public static final int TYPE_DRAG               = FIRST_SYSTEM_WINDOW+16;
587 
588         /**
589          * Window type: panel that slides out from under the status bar
590          * In multiuser systems shows on all users' windows.
591          * @hide
592          */
593         public static final int TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17;
594 
595         /**
596          * Window type: (mouse) pointer
597          * In multiuser systems shows on all users' windows.
598          * @hide
599          */
600         public static final int TYPE_POINTER = FIRST_SYSTEM_WINDOW+18;
601 
602         /**
603          * Window type: Navigation bar (when distinct from status bar)
604          * In multiuser systems shows on all users' windows.
605          * @hide
606          */
607         public static final int TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;
608 
609         /**
610          * Window type: The volume level overlay/dialog shown when the user
611          * changes the system volume.
612          * In multiuser systems shows on all users' windows.
613          * @hide
614          */
615         public static final int TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20;
616 
617         /**
618          * Window type: The boot progress dialog, goes on top of everything
619          * in the world.
620          * In multiuser systems shows on all users' windows.
621          * @hide
622          */
623         public static final int TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21;
624 
625         /**
626          * Window type to consume input events when the systemUI bars are hidden.
627          * In multiuser systems shows on all users' windows.
628          * @hide
629          */
630         public static final int TYPE_INPUT_CONSUMER = FIRST_SYSTEM_WINDOW+22;
631 
632         /**
633          * Window type: Dreams (screen saver) window, just above keyguard.
634          * In multiuser systems shows only on the owning user's window.
635          * @hide
636          */
637         public static final int TYPE_DREAM = FIRST_SYSTEM_WINDOW+23;
638 
639         /**
640          * Window type: Navigation bar panel (when navigation bar is distinct from status bar)
641          * In multiuser systems shows on all users' windows.
642          * @hide
643          */
644         public static final int TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24;
645 
646         /**
647          * Window type: Display overlay window.  Used to simulate secondary display devices.
648          * In multiuser systems shows on all users' windows.
649          * @hide
650          */
651         public static final int TYPE_DISPLAY_OVERLAY = FIRST_SYSTEM_WINDOW+26;
652 
653         /**
654          * Window type: Magnification overlay window. Used to highlight the magnified
655          * portion of a display when accessibility magnification is enabled.
656          * In multiuser systems shows on all users' windows.
657          * @hide
658          */
659         public static final int TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+27;
660 
661         /**
662          * Window type: Window for Presentation on top of private
663          * virtual display.
664          */
665         public static final int TYPE_PRIVATE_PRESENTATION = FIRST_SYSTEM_WINDOW+30;
666 
667         /**
668          * Window type: Windows in the voice interaction layer.
669          * @hide
670          */
671         public static final int TYPE_VOICE_INTERACTION = FIRST_SYSTEM_WINDOW+31;
672 
673         /**
674          * Window type: Windows that are overlaid <em>only</em> by a connected {@link
675          * android.accessibilityservice.AccessibilityService} for interception of
676          * user interactions without changing the windows an accessibility service
677          * can introspect. In particular, an accessibility service can introspect
678          * only windows that a sighted user can interact with which is they can touch
679          * these windows or can type into these windows. For example, if there
680          * is a full screen accessibility overlay that is touchable, the windows
681          * below it will be introspectable by an accessibility service even though
682          * they are covered by a touchable window.
683          */
684         public static final int TYPE_ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW+32;
685 
686         /**
687          * Window type: Starting window for voice interaction layer.
688          * @hide
689          */
690         public static final int TYPE_VOICE_INTERACTION_STARTING = FIRST_SYSTEM_WINDOW+33;
691 
692         /**
693          * Window for displaying a handle used for resizing docked stacks. This window is owned
694          * by the system process.
695          * @hide
696          */
697         public static final int TYPE_DOCK_DIVIDER = FIRST_SYSTEM_WINDOW+34;
698 
699         /**
700          * Window type: like {@link #TYPE_APPLICATION_ATTACHED_DIALOG}, but used
701          * by Quick Settings Tiles.
702          * @hide
703          */
704         public static final int TYPE_QS_DIALOG = FIRST_SYSTEM_WINDOW+35;
705 
706         /**
707          * Window type: shares similar characteristics with {@link #TYPE_DREAM}. The layer is
708          * reserved for screenshot region selection. These windows must not take input focus.
709          * @hide
710          */
711         public static final int TYPE_SCREENSHOT = FIRST_SYSTEM_WINDOW + 36;
712 
713         /**
714          * Window type: Window for Presentation on an external display.
715          * @see android.app.Presentation
716          * @hide
717          */
718         public static final int TYPE_PRESENTATION = FIRST_SYSTEM_WINDOW + 37;
719 
720         /**
721          * Window type: Application overlay windows are displayed above all activity windows
722          * (types between {@link #FIRST_APPLICATION_WINDOW} and {@link #LAST_APPLICATION_WINDOW})
723          * but below critical system windows like the status bar or IME.
724          * <p>
725          * The system may change the position, size, or visibility of these windows at anytime
726          * to reduce visual clutter to the user and also manage resources.
727          * <p>
728          * Requires {@link android.Manifest.permission#SYSTEM_ALERT_WINDOW} permission.
729          * <p>
730          * The system will adjust the importance of processes with this window type to reduce the
731          * chance of the low-memory-killer killing them.
732          * <p>
733          * In multi-user systems shows only on the owning user's screen.
734          */
735         public static final int TYPE_APPLICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 38;
736 
737         /**
738          * End of types of system windows.
739          */
740         public static final int LAST_SYSTEM_WINDOW      = 2999;
741 
742         /**
743          * @hide
744          * Used internally when there is no suitable type available.
745          */
746         public static final int INVALID_WINDOW_TYPE = -1;
747 
748         /**
749          * Return true if the window type is an alert window.
750          *
751          * @param type The window type.
752          * @return If the window type is an alert window.
753          * @hide
754          */
isSystemAlertWindowType(int type)755         public static boolean isSystemAlertWindowType(int type) {
756             switch (type) {
757                 case TYPE_PHONE:
758                 case TYPE_PRIORITY_PHONE:
759                 case TYPE_SYSTEM_ALERT:
760                 case TYPE_SYSTEM_ERROR:
761                 case TYPE_SYSTEM_OVERLAY:
762                 case TYPE_APPLICATION_OVERLAY:
763                     return true;
764             }
765             return false;
766         }
767 
768         /** @deprecated this is ignored, this value is set automatically when needed. */
769         @Deprecated
770         public static final int MEMORY_TYPE_NORMAL = 0;
771         /** @deprecated this is ignored, this value is set automatically when needed. */
772         @Deprecated
773         public static final int MEMORY_TYPE_HARDWARE = 1;
774         /** @deprecated this is ignored, this value is set automatically when needed. */
775         @Deprecated
776         public static final int MEMORY_TYPE_GPU = 2;
777         /** @deprecated this is ignored, this value is set automatically when needed. */
778         @Deprecated
779         public static final int MEMORY_TYPE_PUSH_BUFFERS = 3;
780 
781         /**
782          * @deprecated this is ignored
783          */
784         @Deprecated
785         public int memoryType;
786 
787         /** Window flag: as long as this window is visible to the user, allow
788          *  the lock screen to activate while the screen is on.
789          *  This can be used independently, or in combination with
790          *  {@link #FLAG_KEEP_SCREEN_ON} and/or {@link #FLAG_SHOW_WHEN_LOCKED} */
791         public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON     = 0x00000001;
792 
793         /** Window flag: everything behind this window will be dimmed.
794          *  Use {@link #dimAmount} to control the amount of dim. */
795         public static final int FLAG_DIM_BEHIND        = 0x00000002;
796 
797         /** Window flag: blur everything behind this window.
798          * @deprecated Blurring is no longer supported. */
799         @Deprecated
800         public static final int FLAG_BLUR_BEHIND        = 0x00000004;
801 
802         /** Window flag: this window won't ever get key input focus, so the
803          * user can not send key or other button events to it.  Those will
804          * instead go to whatever focusable window is behind it.  This flag
805          * will also enable {@link #FLAG_NOT_TOUCH_MODAL} whether or not that
806          * is explicitly set.
807          *
808          * <p>Setting this flag also implies that the window will not need to
809          * interact with
810          * a soft input method, so it will be Z-ordered and positioned
811          * independently of any active input method (typically this means it
812          * gets Z-ordered on top of the input method, so it can use the full
813          * screen for its content and cover the input method if needed.  You
814          * can use {@link #FLAG_ALT_FOCUSABLE_IM} to modify this behavior. */
815         public static final int FLAG_NOT_FOCUSABLE      = 0x00000008;
816 
817         /** Window flag: this window can never receive touch events. */
818         public static final int FLAG_NOT_TOUCHABLE      = 0x00000010;
819 
820         /** Window flag: even when this window is focusable (its
821          * {@link #FLAG_NOT_FOCUSABLE} is not set), allow any pointer events
822          * outside of the window to be sent to the windows behind it.  Otherwise
823          * it will consume all pointer events itself, regardless of whether they
824          * are inside of the window. */
825         public static final int FLAG_NOT_TOUCH_MODAL    = 0x00000020;
826 
827         /** Window flag: when set, if the device is asleep when the touch
828          * screen is pressed, you will receive this first touch event.  Usually
829          * the first touch event is consumed by the system since the user can
830          * not see what they are pressing on.
831          *
832          * @deprecated This flag has no effect.
833          */
834         @Deprecated
835         public static final int FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040;
836 
837         /** Window flag: as long as this window is visible to the user, keep
838          *  the device's screen turned on and bright. */
839         public static final int FLAG_KEEP_SCREEN_ON     = 0x00000080;
840 
841         /** Window flag: place the window within the entire screen, ignoring
842          *  decorations around the border (such as the status bar).  The
843          *  window must correctly position its contents to take the screen
844          *  decoration into account.  This flag is normally set for you
845          *  by Window as described in {@link Window#setFlags}. */
846         public static final int FLAG_LAYOUT_IN_SCREEN   = 0x00000100;
847 
848         /** Window flag: allow window to extend outside of the screen. */
849         public static final int FLAG_LAYOUT_NO_LIMITS   = 0x00000200;
850 
851         /**
852          * Window flag: hide all screen decorations (such as the status bar) while
853          * this window is displayed.  This allows the window to use the entire
854          * display space for itself -- the status bar will be hidden when
855          * an app window with this flag set is on the top layer. A fullscreen window
856          * will ignore a value of {@link #SOFT_INPUT_ADJUST_RESIZE} for the window's
857          * {@link #softInputMode} field; the window will stay fullscreen
858          * and will not resize.
859          *
860          * <p>This flag can be controlled in your theme through the
861          * {@link android.R.attr#windowFullscreen} attribute; this attribute
862          * is automatically set for you in the standard fullscreen themes
863          * such as {@link android.R.style#Theme_NoTitleBar_Fullscreen},
864          * {@link android.R.style#Theme_Black_NoTitleBar_Fullscreen},
865          * {@link android.R.style#Theme_Light_NoTitleBar_Fullscreen},
866          * {@link android.R.style#Theme_Holo_NoActionBar_Fullscreen},
867          * {@link android.R.style#Theme_Holo_Light_NoActionBar_Fullscreen},
868          * {@link android.R.style#Theme_DeviceDefault_NoActionBar_Fullscreen}, and
869          * {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_Fullscreen}.</p>
870          */
871         public static final int FLAG_FULLSCREEN      = 0x00000400;
872 
873         /** Window flag: override {@link #FLAG_FULLSCREEN} and force the
874          *  screen decorations (such as the status bar) to be shown. */
875         public static final int FLAG_FORCE_NOT_FULLSCREEN   = 0x00000800;
876 
877         /** Window flag: turn on dithering when compositing this window to
878          *  the screen.
879          * @deprecated This flag is no longer used. */
880         @Deprecated
881         public static final int FLAG_DITHER             = 0x00001000;
882 
883         /** Window flag: treat the content of the window as secure, preventing
884          * it from appearing in screenshots or from being viewed on non-secure
885          * displays.
886          *
887          * <p>See {@link android.view.Display#FLAG_SECURE} for more details about
888          * secure surfaces and secure displays.
889          */
890         public static final int FLAG_SECURE             = 0x00002000;
891 
892         /** Window flag: a special mode where the layout parameters are used
893          * to perform scaling of the surface when it is composited to the
894          * screen. */
895         public static final int FLAG_SCALED             = 0x00004000;
896 
897         /** Window flag: intended for windows that will often be used when the user is
898          * holding the screen against their face, it will aggressively filter the event
899          * stream to prevent unintended presses in this situation that may not be
900          * desired for a particular window, when such an event stream is detected, the
901          * application will receive a CANCEL motion event to indicate this so applications
902          * can handle this accordingly by taking no action on the event
903          * until the finger is released. */
904         public static final int FLAG_IGNORE_CHEEK_PRESSES    = 0x00008000;
905 
906         /** Window flag: a special option only for use in combination with
907          * {@link #FLAG_LAYOUT_IN_SCREEN}.  When requesting layout in the
908          * screen your window may appear on top of or behind screen decorations
909          * such as the status bar.  By also including this flag, the window
910          * manager will report the inset rectangle needed to ensure your
911          * content is not covered by screen decorations.  This flag is normally
912          * set for you by Window as described in {@link Window#setFlags}.*/
913         public static final int FLAG_LAYOUT_INSET_DECOR = 0x00010000;
914 
915         /** Window flag: invert the state of {@link #FLAG_NOT_FOCUSABLE} with
916          * respect to how this window interacts with the current method.  That
917          * is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the
918          * window will behave as if it needs to interact with the input method
919          * and thus be placed behind/away from it; if FLAG_NOT_FOCUSABLE is
920          * not set and this flag is set, then the window will behave as if it
921          * doesn't need to interact with the input method and can be placed
922          * to use more space and cover the input method.
923          */
924         public static final int FLAG_ALT_FOCUSABLE_IM = 0x00020000;
925 
926         /** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you
927          * can set this flag to receive a single special MotionEvent with
928          * the action
929          * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for
930          * touches that occur outside of your window.  Note that you will not
931          * receive the full down/move/up gesture, only the location of the
932          * first down as an ACTION_OUTSIDE.
933          */
934         public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;
935 
936         /** Window flag: special flag to let windows be shown when the screen
937          * is locked. This will let application windows take precedence over
938          * key guard or any other lock screens. Can be used with
939          * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows
940          * directly before showing the key guard window.  Can be used with
941          * {@link #FLAG_DISMISS_KEYGUARD} to automatically fully dismisss
942          * non-secure keyguards.  This flag only applies to the top-most
943          * full-screen window.
944          */
945         public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000;
946 
947         /** Window flag: ask that the system wallpaper be shown behind
948          * your window.  The window surface must be translucent to be able
949          * to actually see the wallpaper behind it; this flag just ensures
950          * that the wallpaper surface will be there if this window actually
951          * has translucent regions.
952          *
953          * <p>This flag can be controlled in your theme through the
954          * {@link android.R.attr#windowShowWallpaper} attribute; this attribute
955          * is automatically set for you in the standard wallpaper themes
956          * such as {@link android.R.style#Theme_Wallpaper},
957          * {@link android.R.style#Theme_Wallpaper_NoTitleBar},
958          * {@link android.R.style#Theme_Wallpaper_NoTitleBar_Fullscreen},
959          * {@link android.R.style#Theme_Holo_Wallpaper},
960          * {@link android.R.style#Theme_Holo_Wallpaper_NoTitleBar},
961          * {@link android.R.style#Theme_DeviceDefault_Wallpaper}, and
962          * {@link android.R.style#Theme_DeviceDefault_Wallpaper_NoTitleBar}.</p>
963          */
964         public static final int FLAG_SHOW_WALLPAPER = 0x00100000;
965 
966         /** Window flag: when set as a window is being added or made
967          * visible, once the window has been shown then the system will
968          * poke the power manager's user activity (as if the user had woken
969          * up the device) to turn the screen on. */
970         public static final int FLAG_TURN_SCREEN_ON = 0x00200000;
971 
972         /** Window flag: when set the window will cause the keyguard to
973          * be dismissed, only if it is not a secure lock keyguard. Because such
974          * a keyguard is not needed for security, it will never re-appear if
975          * the user navigates to another window (in contrast to
976          * {@link #FLAG_SHOW_WHEN_LOCKED}, which will only temporarily
977          * hide both secure and non-secure keyguards but ensure they reappear
978          * when the user moves to another UI that doesn't hide them).
979          * If the keyguard is currently active and is secure (requires an
980          * unlock credential) than the user will still need to confirm it before
981          * seeing this window, unless {@link #FLAG_SHOW_WHEN_LOCKED} has
982          * also been set.
983          * @deprecated Use {@link #FLAG_SHOW_WHEN_LOCKED} or {@link KeyguardManager#dismissKeyguard}
984          * instead. Since keyguard was dismissed all the time as long as an activity with this flag
985          * on its window was focused, keyguard couldn't guard against unintentional touches on the
986          * screen, which isn't desired.
987          */
988         @Deprecated
989         public static final int FLAG_DISMISS_KEYGUARD = 0x00400000;
990 
991         /** Window flag: when set the window will accept for touch events
992          * outside of its bounds to be sent to other windows that also
993          * support split touch.  When this flag is not set, the first pointer
994          * that goes down determines the window to which all subsequent touches
995          * go until all pointers go up.  When this flag is set, each pointer
996          * (not necessarily the first) that goes down determines the window
997          * to which all subsequent touches of that pointer will go until that
998          * pointer goes up thereby enabling touches with multiple pointers
999          * to be split across multiple windows.
1000          */
1001         public static final int FLAG_SPLIT_TOUCH = 0x00800000;
1002 
1003         /**
1004          * <p>Indicates whether this window should be hardware accelerated.
1005          * Requesting hardware acceleration does not guarantee it will happen.</p>
1006          *
1007          * <p>This flag can be controlled programmatically <em>only</em> to enable
1008          * hardware acceleration. To enable hardware acceleration for a given
1009          * window programmatically, do the following:</p>
1010          *
1011          * <pre>
1012          * Window w = activity.getWindow(); // in Activity's onCreate() for instance
1013          * w.setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
1014          *         WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
1015          * </pre>
1016          *
1017          * <p>It is important to remember that this flag <strong>must</strong>
1018          * be set before setting the content view of your activity or dialog.</p>
1019          *
1020          * <p>This flag cannot be used to disable hardware acceleration after it
1021          * was enabled in your manifest using
1022          * {@link android.R.attr#hardwareAccelerated}. If you need to selectively
1023          * and programmatically disable hardware acceleration (for automated testing
1024          * for instance), make sure it is turned off in your manifest and enable it
1025          * on your activity or dialog when you need it instead, using the method
1026          * described above.</p>
1027          *
1028          * <p>This flag is automatically set by the system if the
1029          * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated}
1030          * XML attribute is set to true on an activity or on the application.</p>
1031          */
1032         public static final int FLAG_HARDWARE_ACCELERATED = 0x01000000;
1033 
1034         /**
1035          * Window flag: allow window contents to extend in to the screen's
1036          * overscan area, if there is one.  The window should still correctly
1037          * position its contents to take the overscan area into account.
1038          *
1039          * <p>This flag can be controlled in your theme through the
1040          * {@link android.R.attr#windowOverscan} attribute; this attribute
1041          * is automatically set for you in the standard overscan themes
1042          * such as
1043          * {@link android.R.style#Theme_Holo_NoActionBar_Overscan},
1044          * {@link android.R.style#Theme_Holo_Light_NoActionBar_Overscan},
1045          * {@link android.R.style#Theme_DeviceDefault_NoActionBar_Overscan}, and
1046          * {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_Overscan}.</p>
1047          *
1048          * <p>When this flag is enabled for a window, its normal content may be obscured
1049          * to some degree by the overscan region of the display.  To ensure key parts of
1050          * that content are visible to the user, you can use
1051          * {@link View#setFitsSystemWindows(boolean) View.setFitsSystemWindows(boolean)}
1052          * to set the point in the view hierarchy where the appropriate offsets should
1053          * be applied.  (This can be done either by directly calling this function, using
1054          * the {@link android.R.attr#fitsSystemWindows} attribute in your view hierarchy,
1055          * or implementing you own {@link View#fitSystemWindows(android.graphics.Rect)
1056          * View.fitSystemWindows(Rect)} method).</p>
1057          *
1058          * <p>This mechanism for positioning content elements is identical to its equivalent
1059          * use with layout and {@link View#setSystemUiVisibility(int)
1060          * View.setSystemUiVisibility(int)}; here is an example layout that will correctly
1061          * position its UI elements with this overscan flag is set:</p>
1062          *
1063          * {@sample development/samples/ApiDemos/res/layout/overscan_activity.xml complete}
1064          */
1065         public static final int FLAG_LAYOUT_IN_OVERSCAN = 0x02000000;
1066 
1067         /**
1068          * Window flag: request a translucent status bar with minimal system-provided
1069          * background protection.
1070          *
1071          * <p>This flag can be controlled in your theme through the
1072          * {@link android.R.attr#windowTranslucentStatus} attribute; this attribute
1073          * is automatically set for you in the standard translucent decor themes
1074          * such as
1075          * {@link android.R.style#Theme_Holo_NoActionBar_TranslucentDecor},
1076          * {@link android.R.style#Theme_Holo_Light_NoActionBar_TranslucentDecor},
1077          * {@link android.R.style#Theme_DeviceDefault_NoActionBar_TranslucentDecor}, and
1078          * {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor}.</p>
1079          *
1080          * <p>When this flag is enabled for a window, it automatically sets
1081          * the system UI visibility flags {@link View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1082          * {@link View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.</p>
1083          */
1084         public static final int FLAG_TRANSLUCENT_STATUS = 0x04000000;
1085 
1086         /**
1087          * Window flag: request a translucent navigation bar with minimal system-provided
1088          * background protection.
1089          *
1090          * <p>This flag can be controlled in your theme through the
1091          * {@link android.R.attr#windowTranslucentNavigation} attribute; this attribute
1092          * is automatically set for you in the standard translucent decor themes
1093          * such as
1094          * {@link android.R.style#Theme_Holo_NoActionBar_TranslucentDecor},
1095          * {@link android.R.style#Theme_Holo_Light_NoActionBar_TranslucentDecor},
1096          * {@link android.R.style#Theme_DeviceDefault_NoActionBar_TranslucentDecor}, and
1097          * {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor}.</p>
1098          *
1099          * <p>When this flag is enabled for a window, it automatically sets
1100          * the system UI visibility flags {@link View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
1101          * {@link View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}.</p>
1102          */
1103         public static final int FLAG_TRANSLUCENT_NAVIGATION = 0x08000000;
1104 
1105         /**
1106          * Flag for a window in local focus mode.
1107          * Window in local focus mode can control focus independent of window manager using
1108          * {@link Window#setLocalFocus(boolean, boolean)}.
1109          * Usually window in this mode will not get touch/key events from window manager, but will
1110          * get events only via local injection using {@link Window#injectInputEvent(InputEvent)}.
1111          */
1112         public static final int FLAG_LOCAL_FOCUS_MODE = 0x10000000;
1113 
1114         /** Window flag: Enable touches to slide out of a window into neighboring
1115          * windows in mid-gesture instead of being captured for the duration of
1116          * the gesture.
1117          *
1118          * This flag changes the behavior of touch focus for this window only.
1119          * Touches can slide out of the window but they cannot necessarily slide
1120          * back in (unless the other window with touch focus permits it).
1121          *
1122          * {@hide}
1123          */
1124         public static final int FLAG_SLIPPERY = 0x20000000;
1125 
1126         /**
1127          * Window flag: When requesting layout with an attached window, the attached window may
1128          * overlap with the screen decorations of the parent window such as the navigation bar. By
1129          * including this flag, the window manager will layout the attached window within the decor
1130          * frame of the parent window such that it doesn't overlap with screen decorations.
1131          */
1132         public static final int FLAG_LAYOUT_ATTACHED_IN_DECOR = 0x40000000;
1133 
1134         /**
1135          * Flag indicating that this Window is responsible for drawing the background for the
1136          * system bars. If set, the system bars are drawn with a transparent background and the
1137          * corresponding areas in this window are filled with the colors specified in
1138          * {@link Window#getStatusBarColor()} and {@link Window#getNavigationBarColor()}.
1139          */
1140         public static final int FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000;
1141 
1142         /**
1143          * Various behavioral options/flags.  Default is none.
1144          *
1145          * @see #FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
1146          * @see #FLAG_DIM_BEHIND
1147          * @see #FLAG_NOT_FOCUSABLE
1148          * @see #FLAG_NOT_TOUCHABLE
1149          * @see #FLAG_NOT_TOUCH_MODAL
1150          * @see #FLAG_TOUCHABLE_WHEN_WAKING
1151          * @see #FLAG_KEEP_SCREEN_ON
1152          * @see #FLAG_LAYOUT_IN_SCREEN
1153          * @see #FLAG_LAYOUT_NO_LIMITS
1154          * @see #FLAG_FULLSCREEN
1155          * @see #FLAG_FORCE_NOT_FULLSCREEN
1156          * @see #FLAG_SECURE
1157          * @see #FLAG_SCALED
1158          * @see #FLAG_IGNORE_CHEEK_PRESSES
1159          * @see #FLAG_LAYOUT_INSET_DECOR
1160          * @see #FLAG_ALT_FOCUSABLE_IM
1161          * @see #FLAG_WATCH_OUTSIDE_TOUCH
1162          * @see #FLAG_SHOW_WHEN_LOCKED
1163          * @see #FLAG_SHOW_WALLPAPER
1164          * @see #FLAG_TURN_SCREEN_ON
1165          * @see #FLAG_DISMISS_KEYGUARD
1166          * @see #FLAG_SPLIT_TOUCH
1167          * @see #FLAG_HARDWARE_ACCELERATED
1168          * @see #FLAG_LOCAL_FOCUS_MODE
1169          * @see #FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
1170          */
1171         @ViewDebug.ExportedProperty(flagMapping = {
1172             @ViewDebug.FlagToString(mask = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON, equals = FLAG_ALLOW_LOCK_WHILE_SCREEN_ON,
1173                     name = "FLAG_ALLOW_LOCK_WHILE_SCREEN_ON"),
1174             @ViewDebug.FlagToString(mask = FLAG_DIM_BEHIND, equals = FLAG_DIM_BEHIND,
1175                     name = "FLAG_DIM_BEHIND"),
1176             @ViewDebug.FlagToString(mask = FLAG_BLUR_BEHIND, equals = FLAG_BLUR_BEHIND,
1177                     name = "FLAG_BLUR_BEHIND"),
1178             @ViewDebug.FlagToString(mask = FLAG_NOT_FOCUSABLE, equals = FLAG_NOT_FOCUSABLE,
1179                     name = "FLAG_NOT_FOCUSABLE"),
1180             @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCHABLE, equals = FLAG_NOT_TOUCHABLE,
1181                     name = "FLAG_NOT_TOUCHABLE"),
1182             @ViewDebug.FlagToString(mask = FLAG_NOT_TOUCH_MODAL, equals = FLAG_NOT_TOUCH_MODAL,
1183                     name = "FLAG_NOT_TOUCH_MODAL"),
1184             @ViewDebug.FlagToString(mask = FLAG_TOUCHABLE_WHEN_WAKING, equals = FLAG_TOUCHABLE_WHEN_WAKING,
1185                     name = "FLAG_TOUCHABLE_WHEN_WAKING"),
1186             @ViewDebug.FlagToString(mask = FLAG_KEEP_SCREEN_ON, equals = FLAG_KEEP_SCREEN_ON,
1187                     name = "FLAG_KEEP_SCREEN_ON"),
1188             @ViewDebug.FlagToString(mask = FLAG_LAYOUT_IN_SCREEN, equals = FLAG_LAYOUT_IN_SCREEN,
1189                     name = "FLAG_LAYOUT_IN_SCREEN"),
1190             @ViewDebug.FlagToString(mask = FLAG_LAYOUT_NO_LIMITS, equals = FLAG_LAYOUT_NO_LIMITS,
1191                     name = "FLAG_LAYOUT_NO_LIMITS"),
1192             @ViewDebug.FlagToString(mask = FLAG_FULLSCREEN, equals = FLAG_FULLSCREEN,
1193                     name = "FLAG_FULLSCREEN"),
1194             @ViewDebug.FlagToString(mask = FLAG_FORCE_NOT_FULLSCREEN, equals = FLAG_FORCE_NOT_FULLSCREEN,
1195                     name = "FLAG_FORCE_NOT_FULLSCREEN"),
1196             @ViewDebug.FlagToString(mask = FLAG_DITHER, equals = FLAG_DITHER,
1197                     name = "FLAG_DITHER"),
1198             @ViewDebug.FlagToString(mask = FLAG_SECURE, equals = FLAG_SECURE,
1199                     name = "FLAG_SECURE"),
1200             @ViewDebug.FlagToString(mask = FLAG_SCALED, equals = FLAG_SCALED,
1201                     name = "FLAG_SCALED"),
1202             @ViewDebug.FlagToString(mask = FLAG_IGNORE_CHEEK_PRESSES, equals = FLAG_IGNORE_CHEEK_PRESSES,
1203                     name = "FLAG_IGNORE_CHEEK_PRESSES"),
1204             @ViewDebug.FlagToString(mask = FLAG_LAYOUT_INSET_DECOR, equals = FLAG_LAYOUT_INSET_DECOR,
1205                     name = "FLAG_LAYOUT_INSET_DECOR"),
1206             @ViewDebug.FlagToString(mask = FLAG_ALT_FOCUSABLE_IM, equals = FLAG_ALT_FOCUSABLE_IM,
1207                     name = "FLAG_ALT_FOCUSABLE_IM"),
1208             @ViewDebug.FlagToString(mask = FLAG_WATCH_OUTSIDE_TOUCH, equals = FLAG_WATCH_OUTSIDE_TOUCH,
1209                     name = "FLAG_WATCH_OUTSIDE_TOUCH"),
1210             @ViewDebug.FlagToString(mask = FLAG_SHOW_WHEN_LOCKED, equals = FLAG_SHOW_WHEN_LOCKED,
1211                     name = "FLAG_SHOW_WHEN_LOCKED"),
1212             @ViewDebug.FlagToString(mask = FLAG_SHOW_WALLPAPER, equals = FLAG_SHOW_WALLPAPER,
1213                     name = "FLAG_SHOW_WALLPAPER"),
1214             @ViewDebug.FlagToString(mask = FLAG_TURN_SCREEN_ON, equals = FLAG_TURN_SCREEN_ON,
1215                     name = "FLAG_TURN_SCREEN_ON"),
1216             @ViewDebug.FlagToString(mask = FLAG_DISMISS_KEYGUARD, equals = FLAG_DISMISS_KEYGUARD,
1217                     name = "FLAG_DISMISS_KEYGUARD"),
1218             @ViewDebug.FlagToString(mask = FLAG_SPLIT_TOUCH, equals = FLAG_SPLIT_TOUCH,
1219                     name = "FLAG_SPLIT_TOUCH"),
1220             @ViewDebug.FlagToString(mask = FLAG_HARDWARE_ACCELERATED, equals = FLAG_HARDWARE_ACCELERATED,
1221                     name = "FLAG_HARDWARE_ACCELERATED"),
1222             @ViewDebug.FlagToString(mask = FLAG_LOCAL_FOCUS_MODE, equals = FLAG_LOCAL_FOCUS_MODE,
1223                     name = "FLAG_LOCAL_FOCUS_MODE"),
1224             @ViewDebug.FlagToString(mask = FLAG_TRANSLUCENT_STATUS, equals = FLAG_TRANSLUCENT_STATUS,
1225                     name = "FLAG_TRANSLUCENT_STATUS"),
1226             @ViewDebug.FlagToString(mask = FLAG_TRANSLUCENT_NAVIGATION, equals = FLAG_TRANSLUCENT_NAVIGATION,
1227                     name = "FLAG_TRANSLUCENT_NAVIGATION"),
1228             @ViewDebug.FlagToString(mask = FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, equals = FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
1229                     name = "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS")
1230         }, formatToHexString = true)
1231         public int flags;
1232 
1233         /**
1234          * If the window has requested hardware acceleration, but this is not
1235          * allowed in the process it is in, then still render it as if it is
1236          * hardware accelerated.  This is used for the starting preview windows
1237          * in the system process, which don't need to have the overhead of
1238          * hardware acceleration (they are just a static rendering), but should
1239          * be rendered as such to match the actual window of the app even if it
1240          * is hardware accelerated.
1241          * Even if the window isn't hardware accelerated, still do its rendering
1242          * as if it was.
1243          * Like {@link #FLAG_HARDWARE_ACCELERATED} except for trusted system windows
1244          * that need hardware acceleration (e.g. LockScreen), where hardware acceleration
1245          * is generally disabled. This flag must be specified in addition to
1246          * {@link #FLAG_HARDWARE_ACCELERATED} to enable hardware acceleration for system
1247          * windows.
1248          *
1249          * @hide
1250          */
1251         public static final int PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED = 0x00000001;
1252 
1253         /**
1254          * In the system process, we globally do not use hardware acceleration
1255          * because there are many threads doing UI there and they conflict.
1256          * If certain parts of the UI that really do want to use hardware
1257          * acceleration, this flag can be set to force it.  This is basically
1258          * for the lock screen.  Anyone else using it, you are probably wrong.
1259          *
1260          * @hide
1261          */
1262         public static final int PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED = 0x00000002;
1263 
1264         /**
1265          * By default, wallpapers are sent new offsets when the wallpaper is scrolled. Wallpapers
1266          * may elect to skip these notifications if they are not doing anything productive with
1267          * them (they do not affect the wallpaper scrolling operation) by calling
1268          * {@link
1269          * android.service.wallpaper.WallpaperService.Engine#setOffsetNotificationsEnabled(boolean)}.
1270          *
1271          * @hide
1272          */
1273         public static final int PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS = 0x00000004;
1274 
1275         /** In a multiuser system if this flag is set and the owner is a system process then this
1276          * window will appear on all user screens. This overrides the default behavior of window
1277          * types that normally only appear on the owning user's screen. Refer to each window type
1278          * to determine its default behavior.
1279          *
1280          * {@hide} */
1281         public static final int PRIVATE_FLAG_SHOW_FOR_ALL_USERS = 0x00000010;
1282 
1283         /**
1284          * Never animate position changes of the window.
1285          *
1286          * {@hide}
1287          */
1288         @TestApi
1289         public static final int PRIVATE_FLAG_NO_MOVE_ANIMATION = 0x00000040;
1290 
1291         /** Window flag: special flag to limit the size of the window to be
1292          * original size ([320x480] x density). Used to create window for applications
1293          * running under compatibility mode.
1294          *
1295          * {@hide} */
1296         public static final int PRIVATE_FLAG_COMPATIBLE_WINDOW = 0x00000080;
1297 
1298         /** Window flag: a special option intended for system dialogs.  When
1299          * this flag is set, the window will demand focus unconditionally when
1300          * it is created.
1301          * {@hide} */
1302         public static final int PRIVATE_FLAG_SYSTEM_ERROR = 0x00000100;
1303 
1304         /** Window flag: maintain the previous translucent decor state when this window
1305          * becomes top-most.
1306          * {@hide} */
1307         public static final int PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR = 0x00000200;
1308 
1309         /**
1310          * Flag whether the current window is a keyguard window, meaning that it will hide all other
1311          * windows behind it except for windows with flag {@link #FLAG_SHOW_WHEN_LOCKED} set.
1312          * Further, this can only be set by {@link LayoutParams#TYPE_STATUS_BAR}.
1313          * {@hide}
1314          */
1315         public static final int PRIVATE_FLAG_KEYGUARD = 0x00000400;
1316 
1317         /**
1318          * Flag that prevents the wallpaper behind the current window from receiving touch events.
1319          *
1320          * {@hide}
1321          */
1322         public static final int PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS = 0x00000800;
1323 
1324         /**
1325          * Flag to force the status bar window to be visible all the time. If the bar is hidden when
1326          * this flag is set it will be shown again and the bar will have a transparent background.
1327          * This can only be set by {@link LayoutParams#TYPE_STATUS_BAR}.
1328          *
1329          * {@hide}
1330          */
1331         public static final int PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT = 0x00001000;
1332 
1333         /**
1334          * Flag indicating that the x, y, width, and height members should be
1335          * ignored (and thus their previous value preserved). For example
1336          * because they are being managed externally through repositionChild.
1337          *
1338          * {@hide}
1339          */
1340         public static final int PRIVATE_FLAG_PRESERVE_GEOMETRY = 0x00002000;
1341 
1342         /**
1343          * Flag that will make window ignore app visibility and instead depend purely on the decor
1344          * view visibility for determining window visibility. This is used by recents to keep
1345          * drawing after it launches an app.
1346          * @hide
1347          */
1348         public static final int PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY = 0x00004000;
1349 
1350         /**
1351          * Flag to indicate that this window is not expected to be replaced across
1352          * configuration change triggered activity relaunches. In general the WindowManager
1353          * expects Windows to be replaced after relaunch, and thus it will preserve their surfaces
1354          * until the replacement is ready to show in order to prevent visual glitch. However
1355          * some windows, such as PopupWindows expect to be cleared across configuration change,
1356          * and thus should hint to the WindowManager that it should not wait for a replacement.
1357          * @hide
1358          */
1359         public static final int PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH = 0x00008000;
1360 
1361         /**
1362          * Flag to indicate that this child window should always be laid-out in the parent
1363          * frame regardless of the current windowing mode configuration.
1364          * @hide
1365          */
1366         public static final int PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME = 0x00010000;
1367 
1368         /**
1369          * Flag to indicate that this window is always drawing the status bar background, no matter
1370          * what the other flags are.
1371          * @hide
1372          */
1373         public static final int PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND = 0x00020000;
1374 
1375         /**
1376          * Flag to indicate that this window needs Sustained Performance Mode if
1377          * the device supports it.
1378          * @hide
1379          */
1380         public static final int PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE = 0x00040000;
1381 
1382         /**
1383          * Flag to indicate that this window is used as a task snapshot window. A task snapshot
1384          * window is a starting window that gets shown with a screenshot from the previous state
1385          * that is active until the app has drawn its first frame.
1386          *
1387          * <p>If this flag is set, SystemUI flags are ignored such that the real window behind can
1388          * set the SystemUI flags.
1389          * @hide
1390          */
1391         public static final int PRIVATE_FLAG_TASK_SNAPSHOT = 0x00080000;
1392 
1393         /**
1394          * Control flags that are private to the platform.
1395          * @hide
1396          */
1397         @TestApi
1398         public int privateFlags;
1399 
1400         /**
1401          * Value for {@link #needsMenuKey} for a window that has not explicitly specified if it
1402          * needs {@link #NEEDS_MENU_SET_TRUE} or doesn't need {@link #NEEDS_MENU_SET_FALSE} a menu
1403          * key. For this case, we should look at windows behind it to determine the appropriate
1404          * value.
1405          *
1406          * @hide
1407          */
1408         public static final int NEEDS_MENU_UNSET = 0;
1409 
1410         /**
1411          * Value for {@link #needsMenuKey} for a window that has explicitly specified it needs a
1412          * menu key.
1413          *
1414          * @hide
1415          */
1416         public static final int NEEDS_MENU_SET_TRUE = 1;
1417 
1418         /**
1419          * Value for {@link #needsMenuKey} for a window that has explicitly specified it doesn't
1420          * needs a menu key.
1421          *
1422          * @hide
1423          */
1424         public static final int NEEDS_MENU_SET_FALSE = 2;
1425 
1426         /**
1427          * State variable for a window belonging to an activity that responds to
1428          * {@link KeyEvent#KEYCODE_MENU} and therefore needs a Menu key. For devices where Menu is a
1429          * physical button this variable is ignored, but on devices where the Menu key is drawn in
1430          * software it may be hidden unless this variable is set to {@link #NEEDS_MENU_SET_TRUE}.
1431          *
1432          *  (Note that Action Bars, when available, are the preferred way to offer additional
1433          * functions otherwise accessed via an options menu.)
1434          *
1435          * {@hide}
1436          */
1437         public int needsMenuKey = NEEDS_MENU_UNSET;
1438 
1439         /**
1440          * Given a particular set of window manager flags, determine whether
1441          * such a window may be a target for an input method when it has
1442          * focus.  In particular, this checks the
1443          * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
1444          * flags and returns true if the combination of the two corresponds
1445          * to a window that needs to be behind the input method so that the
1446          * user can type into it.
1447          *
1448          * @param flags The current window manager flags.
1449          *
1450          * @return Returns true if such a window should be behind/interact
1451          * with an input method, false if not.
1452          */
mayUseInputMethod(int flags)1453         public static boolean mayUseInputMethod(int flags) {
1454             switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1455                 case 0:
1456                 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
1457                     return true;
1458             }
1459             return false;
1460         }
1461 
1462         /**
1463          * Mask for {@link #softInputMode} of the bits that determine the
1464          * desired visibility state of the soft input area for this window.
1465          */
1466         public static final int SOFT_INPUT_MASK_STATE = 0x0f;
1467 
1468         /**
1469          * Visibility state for {@link #softInputMode}: no state has been specified.
1470          */
1471         public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
1472 
1473         /**
1474          * Visibility state for {@link #softInputMode}: please don't change the state of
1475          * the soft input area.
1476          */
1477         public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
1478 
1479         /**
1480          * Visibility state for {@link #softInputMode}: please hide any soft input
1481          * area when normally appropriate (when the user is navigating
1482          * forward to your window).
1483          */
1484         public static final int SOFT_INPUT_STATE_HIDDEN = 2;
1485 
1486         /**
1487          * Visibility state for {@link #softInputMode}: please always hide any
1488          * soft input area when this window receives focus.
1489          */
1490         public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
1491 
1492         /**
1493          * Visibility state for {@link #softInputMode}: please show the soft
1494          * input area when normally appropriate (when the user is navigating
1495          * forward to your window).
1496          */
1497         public static final int SOFT_INPUT_STATE_VISIBLE = 4;
1498 
1499         /**
1500          * Visibility state for {@link #softInputMode}: please always make the
1501          * soft input area visible when this window receives input focus.
1502          */
1503         public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
1504 
1505         /**
1506          * Mask for {@link #softInputMode} of the bits that determine the
1507          * way that the window should be adjusted to accommodate the soft
1508          * input window.
1509          */
1510         public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
1511 
1512         /** Adjustment option for {@link #softInputMode}: nothing specified.
1513          * The system will try to pick one or
1514          * the other depending on the contents of the window.
1515          */
1516         public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
1517 
1518         /** Adjustment option for {@link #softInputMode}: set to allow the
1519          * window to be resized when an input
1520          * method is shown, so that its contents are not covered by the input
1521          * method.  This can <em>not</em> be combined with
1522          * {@link #SOFT_INPUT_ADJUST_PAN}; if
1523          * neither of these are set, then the system will try to pick one or
1524          * the other depending on the contents of the window. If the window's
1525          * layout parameter flags include {@link #FLAG_FULLSCREEN}, this
1526          * value for {@link #softInputMode} will be ignored; the window will
1527          * not resize, but will stay fullscreen.
1528          */
1529         public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
1530 
1531         /** Adjustment option for {@link #softInputMode}: set to have a window
1532          * pan when an input method is
1533          * shown, so it doesn't need to deal with resizing but just panned
1534          * by the framework to ensure the current input focus is visible.  This
1535          * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
1536          * neither of these are set, then the system will try to pick one or
1537          * the other depending on the contents of the window.
1538          */
1539         public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
1540 
1541         /** Adjustment option for {@link #softInputMode}: set to have a window
1542          * not adjust for a shown input method.  The window will not be resized,
1543          * and it will not be panned to make its focus visible.
1544          */
1545         public static final int SOFT_INPUT_ADJUST_NOTHING = 0x30;
1546 
1547         /**
1548          * Bit for {@link #softInputMode}: set when the user has navigated
1549          * forward to the window.  This is normally set automatically for
1550          * you by the system, though you may want to set it in certain cases
1551          * when you are displaying a window yourself.  This flag will always
1552          * be cleared automatically after the window is displayed.
1553          */
1554         public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
1555 
1556         /**
1557          * An internal annotation for flags that can be specified to {@link #softInputMode}.
1558          *
1559          * @hide
1560          */
1561         @Retention(RetentionPolicy.SOURCE)
1562         @IntDef(flag = true, value = {
1563                 SOFT_INPUT_STATE_UNSPECIFIED,
1564                 SOFT_INPUT_STATE_UNCHANGED,
1565                 SOFT_INPUT_STATE_HIDDEN,
1566                 SOFT_INPUT_STATE_ALWAYS_HIDDEN,
1567                 SOFT_INPUT_STATE_VISIBLE,
1568                 SOFT_INPUT_STATE_ALWAYS_VISIBLE,
1569                 SOFT_INPUT_ADJUST_UNSPECIFIED,
1570                 SOFT_INPUT_ADJUST_RESIZE,
1571                 SOFT_INPUT_ADJUST_PAN,
1572                 SOFT_INPUT_ADJUST_NOTHING,
1573                 SOFT_INPUT_IS_FORWARD_NAVIGATION,
1574         })
1575         public @interface SoftInputModeFlags {}
1576 
1577         /**
1578          * Desired operating mode for any soft input area.  May be any combination
1579          * of:
1580          *
1581          * <ul>
1582          * <li> One of the visibility states
1583          * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
1584          * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_HIDDEN},
1585          * {@link #SOFT_INPUT_STATE_VISIBLE}, or {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}.
1586          * <li> One of the adjustment options
1587          * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED}, {@link #SOFT_INPUT_ADJUST_RESIZE},
1588          * {@link #SOFT_INPUT_ADJUST_PAN}, or {@link #SOFT_INPUT_ADJUST_NOTHING}.
1589          * </ul>
1590          *
1591          *
1592          * <p>This flag can be controlled in your theme through the
1593          * {@link android.R.attr#windowSoftInputMode} attribute.</p>
1594          */
1595         @SoftInputModeFlags
1596         public int softInputMode;
1597 
1598         /**
1599          * Placement of window within the screen as per {@link Gravity}.  Both
1600          * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1601          * android.graphics.Rect) Gravity.apply} and
1602          * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
1603          * Gravity.applyDisplay} are used during window layout, with this value
1604          * given as the desired gravity.  For example you can specify
1605          * {@link Gravity#DISPLAY_CLIP_HORIZONTAL Gravity.DISPLAY_CLIP_HORIZONTAL} and
1606          * {@link Gravity#DISPLAY_CLIP_VERTICAL Gravity.DISPLAY_CLIP_VERTICAL} here
1607          * to control the behavior of
1608          * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
1609          * Gravity.applyDisplay}.
1610          *
1611          * @see Gravity
1612          */
1613         public int gravity;
1614 
1615         /**
1616          * The horizontal margin, as a percentage of the container's width,
1617          * between the container and the widget.  See
1618          * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1619          * android.graphics.Rect) Gravity.apply} for how this is used.  This
1620          * field is added with {@link #x} to supply the <var>xAdj</var> parameter.
1621          */
1622         public float horizontalMargin;
1623 
1624         /**
1625          * The vertical margin, as a percentage of the container's height,
1626          * between the container and the widget.  See
1627          * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1628          * android.graphics.Rect) Gravity.apply} for how this is used.  This
1629          * field is added with {@link #y} to supply the <var>yAdj</var> parameter.
1630          */
1631         public float verticalMargin;
1632 
1633         /**
1634          * Positive insets between the drawing surface and window content.
1635          *
1636          * @hide
1637          */
1638         public final Rect surfaceInsets = new Rect();
1639 
1640         /**
1641          * Whether the surface insets have been manually set. When set to
1642          * {@code false}, the view root will automatically determine the
1643          * appropriate surface insets.
1644          *
1645          * @see #surfaceInsets
1646          * @hide
1647          */
1648         public boolean hasManualSurfaceInsets;
1649 
1650         /**
1651          * Whether the previous surface insets should be used vs. what is currently set. When set
1652          * to {@code true}, the view root will ignore surfaces insets in this object and use what
1653          * it currently has.
1654          *
1655          * @see #surfaceInsets
1656          * @hide
1657          */
1658         public boolean preservePreviousSurfaceInsets = true;
1659 
1660         /**
1661          * The desired bitmap format.  May be one of the constants in
1662          * {@link android.graphics.PixelFormat}. The choice of format
1663          * might be overridden by {@link #setColorMode(int)}. Default is OPAQUE.
1664          */
1665         public int format;
1666 
1667         /**
1668          * A style resource defining the animations to use for this window.
1669          * This must be a system resource; it can not be an application resource
1670          * because the window manager does not have access to applications.
1671          */
1672         public int windowAnimations;
1673 
1674         /**
1675          * An alpha value to apply to this entire window.
1676          * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
1677          */
1678         public float alpha = 1.0f;
1679 
1680         /**
1681          * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
1682          * to apply.  Range is from 1.0 for completely opaque to 0.0 for no
1683          * dim.
1684          */
1685         public float dimAmount = 1.0f;
1686 
1687         /**
1688          * Default value for {@link #screenBrightness} and {@link #buttonBrightness}
1689          * indicating that the brightness value is not overridden for this window
1690          * and normal brightness policy should be used.
1691          */
1692         public static final float BRIGHTNESS_OVERRIDE_NONE = -1.0f;
1693 
1694         /**
1695          * Value for {@link #screenBrightness} and {@link #buttonBrightness}
1696          * indicating that the screen or button backlight brightness should be set
1697          * to the lowest value when this window is in front.
1698          */
1699         public static final float BRIGHTNESS_OVERRIDE_OFF = 0.0f;
1700 
1701         /**
1702          * Value for {@link #screenBrightness} and {@link #buttonBrightness}
1703          * indicating that the screen or button backlight brightness should be set
1704          * to the hightest value when this window is in front.
1705          */
1706         public static final float BRIGHTNESS_OVERRIDE_FULL = 1.0f;
1707 
1708         /**
1709          * This can be used to override the user's preferred brightness of
1710          * the screen.  A value of less than 0, the default, means to use the
1711          * preferred screen brightness.  0 to 1 adjusts the brightness from
1712          * dark to full bright.
1713          */
1714         public float screenBrightness = BRIGHTNESS_OVERRIDE_NONE;
1715 
1716         /**
1717          * This can be used to override the standard behavior of the button and
1718          * keyboard backlights.  A value of less than 0, the default, means to
1719          * use the standard backlight behavior.  0 to 1 adjusts the brightness
1720          * from dark to full bright.
1721          */
1722         public float buttonBrightness = BRIGHTNESS_OVERRIDE_NONE;
1723 
1724         /**
1725          * Value for {@link #rotationAnimation} which specifies that this
1726          * window will visually rotate in or out following a rotation.
1727          */
1728         public static final int ROTATION_ANIMATION_ROTATE = 0;
1729 
1730         /**
1731          * Value for {@link #rotationAnimation} which specifies that this
1732          * window will fade in or out following a rotation.
1733          */
1734         public static final int ROTATION_ANIMATION_CROSSFADE = 1;
1735 
1736         /**
1737          * Value for {@link #rotationAnimation} which specifies that this window
1738          * will immediately disappear or appear following a rotation.
1739          */
1740         public static final int ROTATION_ANIMATION_JUMPCUT = 2;
1741 
1742         /**
1743          * Value for {@link #rotationAnimation} to specify seamless rotation mode.
1744          * This works like JUMPCUT but will fall back to CROSSFADE if rotation
1745          * can't be applied without pausing the screen. For example, this is ideal
1746          * for Camera apps which don't want the viewfinder contents to ever rotate
1747          * or fade (and rather to be seamless) but also don't want ROTATION_ANIMATION_JUMPCUT
1748          * during app transition scenarios where seamless rotation can't be applied.
1749          */
1750         public static final int ROTATION_ANIMATION_SEAMLESS = 3;
1751 
1752         /**
1753          * Define the exit and entry animations used on this window when the device is rotated.
1754          * This only has an affect if the incoming and outgoing topmost
1755          * opaque windows have the #FLAG_FULLSCREEN bit set and are not covered
1756          * by other windows. All other situations default to the
1757          * {@link #ROTATION_ANIMATION_ROTATE} behavior.
1758          *
1759          * @see #ROTATION_ANIMATION_ROTATE
1760          * @see #ROTATION_ANIMATION_CROSSFADE
1761          * @see #ROTATION_ANIMATION_JUMPCUT
1762          */
1763         public int rotationAnimation = ROTATION_ANIMATION_ROTATE;
1764 
1765         /**
1766          * Identifier for this window.  This will usually be filled in for
1767          * you.
1768          */
1769         public IBinder token = null;
1770 
1771         /**
1772          * Name of the package owning this window.
1773          */
1774         public String packageName = null;
1775 
1776         /**
1777          * Specific orientation value for a window.
1778          * May be any of the same values allowed
1779          * for {@link android.content.pm.ActivityInfo#screenOrientation}.
1780          * If not set, a default value of
1781          * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
1782          * will be used.
1783          */
1784         public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
1785 
1786         /**
1787          * The preferred refresh rate for the window.
1788          *
1789          * This must be one of the supported refresh rates obtained for the display(s) the window
1790          * is on. The selected refresh rate will be applied to the display's default mode.
1791          *
1792          * This value is ignored if {@link #preferredDisplayModeId} is set.
1793          *
1794          * @see Display#getSupportedRefreshRates()
1795          * @deprecated use {@link #preferredDisplayModeId} instead
1796          */
1797         @Deprecated
1798         public float preferredRefreshRate;
1799 
1800         /**
1801          * Id of the preferred display mode for the window.
1802          * <p>
1803          * This must be one of the supported modes obtained for the display(s) the window is on.
1804          * A value of {@code 0} means no preference.
1805          *
1806          * @see Display#getSupportedModes()
1807          * @see Display.Mode#getModeId()
1808          */
1809         public int preferredDisplayModeId;
1810 
1811         /**
1812          * Control the visibility of the status bar.
1813          *
1814          * @see View#STATUS_BAR_VISIBLE
1815          * @see View#STATUS_BAR_HIDDEN
1816          */
1817         public int systemUiVisibility;
1818 
1819         /**
1820          * @hide
1821          * The ui visibility as requested by the views in this hierarchy.
1822          * the combined value should be systemUiVisibility | subtreeSystemUiVisibility.
1823          */
1824         public int subtreeSystemUiVisibility;
1825 
1826         /**
1827          * Get callbacks about the system ui visibility changing.
1828          *
1829          * TODO: Maybe there should be a bitfield of optional callbacks that we need.
1830          *
1831          * @hide
1832          */
1833         public boolean hasSystemUiListeners;
1834 
1835         /**
1836          * When this window has focus, disable touch pad pointer gesture processing.
1837          * The window will receive raw position updates from the touch pad instead
1838          * of pointer movements and synthetic touch events.
1839          *
1840          * @hide
1841          */
1842         public static final int INPUT_FEATURE_DISABLE_POINTER_GESTURES = 0x00000001;
1843 
1844         /**
1845          * Does not construct an input channel for this window.  The channel will therefore
1846          * be incapable of receiving input.
1847          *
1848          * @hide
1849          */
1850         public static final int INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002;
1851 
1852         /**
1853          * When this window has focus, does not call user activity for all input events so
1854          * the application will have to do it itself.  Should only be used by
1855          * the keyguard and phone app.
1856          * <p>
1857          * Should only be used by the keyguard and phone app.
1858          * </p>
1859          *
1860          * @hide
1861          */
1862         public static final int INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004;
1863 
1864         /**
1865          * Control special features of the input subsystem.
1866          *
1867          * @see #INPUT_FEATURE_DISABLE_POINTER_GESTURES
1868          * @see #INPUT_FEATURE_NO_INPUT_CHANNEL
1869          * @see #INPUT_FEATURE_DISABLE_USER_ACTIVITY
1870          * @hide
1871          */
1872         public int inputFeatures;
1873 
1874         /**
1875          * Sets the number of milliseconds before the user activity timeout occurs
1876          * when this window has focus.  A value of -1 uses the standard timeout.
1877          * A value of 0 uses the minimum support display timeout.
1878          * <p>
1879          * This property can only be used to reduce the user specified display timeout;
1880          * it can never make the timeout longer than it normally would be.
1881          * </p><p>
1882          * Should only be used by the keyguard and phone app.
1883          * </p>
1884          *
1885          * @hide
1886          */
1887         public long userActivityTimeout = -1;
1888 
1889         /**
1890          * For windows with an anchor (e.g. PopupWindow), keeps track of the View that anchors the
1891          * window.
1892          *
1893          * @hide
1894          */
1895         public int accessibilityIdOfAnchor = -1;
1896 
1897         /**
1898          * The window title isn't kept in sync with what is displayed in the title bar, so we
1899          * separately track the currently shown title to provide to accessibility.
1900          *
1901          * @hide
1902          */
1903         @TestApi
1904         public CharSequence accessibilityTitle;
1905 
1906         /**
1907          * Sets a timeout in milliseconds before which the window will be hidden
1908          * by the window manager. Useful for transient notifications like toasts
1909          * so we don't have to rely on client cooperation to ensure the window
1910          * is hidden. Must be specified at window creation time. Note that apps
1911          * are not prepared to handle their windows being removed without their
1912          * explicit request and may try to interact with the removed window
1913          * resulting in undefined behavior and crashes. Therefore, we do hide
1914          * such windows to prevent them from overlaying other apps.
1915          *
1916          * @hide
1917          */
1918         public long hideTimeoutMilliseconds = -1;
1919 
1920         /**
1921          * The color mode requested by this window. The target display may
1922          * not be able to honor the request. When the color mode is not set
1923          * to {@link ActivityInfo#COLOR_MODE_DEFAULT}, it might override the
1924          * pixel format specified in {@link #format}.
1925          *
1926          * @hide
1927          */
1928         @ActivityInfo.ColorMode
1929         private int mColorMode = ActivityInfo.COLOR_MODE_DEFAULT;
1930 
LayoutParams()1931         public LayoutParams() {
1932             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1933             type = TYPE_APPLICATION;
1934             format = PixelFormat.OPAQUE;
1935         }
1936 
LayoutParams(int _type)1937         public LayoutParams(int _type) {
1938             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1939             type = _type;
1940             format = PixelFormat.OPAQUE;
1941         }
1942 
LayoutParams(int _type, int _flags)1943         public LayoutParams(int _type, int _flags) {
1944             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1945             type = _type;
1946             flags = _flags;
1947             format = PixelFormat.OPAQUE;
1948         }
1949 
LayoutParams(int _type, int _flags, int _format)1950         public LayoutParams(int _type, int _flags, int _format) {
1951             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1952             type = _type;
1953             flags = _flags;
1954             format = _format;
1955         }
1956 
LayoutParams(int w, int h, int _type, int _flags, int _format)1957         public LayoutParams(int w, int h, int _type, int _flags, int _format) {
1958             super(w, h);
1959             type = _type;
1960             flags = _flags;
1961             format = _format;
1962         }
1963 
LayoutParams(int w, int h, int xpos, int ypos, int _type, int _flags, int _format)1964         public LayoutParams(int w, int h, int xpos, int ypos, int _type,
1965                 int _flags, int _format) {
1966             super(w, h);
1967             x = xpos;
1968             y = ypos;
1969             type = _type;
1970             flags = _flags;
1971             format = _format;
1972         }
1973 
setTitle(CharSequence title)1974         public final void setTitle(CharSequence title) {
1975             if (null == title)
1976                 title = "";
1977 
1978             mTitle = TextUtils.stringOrSpannedString(title);
1979         }
1980 
getTitle()1981         public final CharSequence getTitle() {
1982             return mTitle != null ? mTitle : "";
1983         }
1984 
1985         /**
1986          * Sets the surface insets based on the elevation (visual z position) of the input view.
1987          * @hide
1988          */
setSurfaceInsets(View view, boolean manual, boolean preservePrevious)1989         public final void setSurfaceInsets(View view, boolean manual, boolean preservePrevious) {
1990             final int surfaceInset = (int) Math.ceil(view.getZ() * 2);
1991             // Partial workaround for b/28318973. Every inset change causes a freeform window
1992             // to jump a little for a few frames. If we never allow surface insets to decrease,
1993             // they will stabilize quickly (often from the very beginning, as most windows start
1994             // as focused).
1995             // TODO(b/22668382) to fix this properly.
1996             if (surfaceInset == 0) {
1997                 // OK to have 0 (this is the case for non-freeform windows).
1998                 surfaceInsets.set(0, 0, 0, 0);
1999             } else {
2000                 surfaceInsets.set(
2001                         Math.max(surfaceInset, surfaceInsets.left),
2002                         Math.max(surfaceInset, surfaceInsets.top),
2003                         Math.max(surfaceInset, surfaceInsets.right),
2004                         Math.max(surfaceInset, surfaceInsets.bottom));
2005             }
2006             hasManualSurfaceInsets = manual;
2007             preservePreviousSurfaceInsets = preservePrevious;
2008         }
2009 
2010         /**
2011          * <p>Set the color mode of the window. Setting the color mode might
2012          * override the window's pixel {@link WindowManager.LayoutParams#format format}.</p>
2013          *
2014          * <p>The color mode must be one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
2015          * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or
2016          * {@link ActivityInfo#COLOR_MODE_HDR}.</p>
2017          *
2018          * @see #getColorMode()
2019          */
setColorMode(@ctivityInfo.ColorMode int colorMode)2020         public void setColorMode(@ActivityInfo.ColorMode int colorMode) {
2021             mColorMode = colorMode;
2022         }
2023 
2024         /**
2025          * Returns the color mode of the window, one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
2026          * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or {@link ActivityInfo#COLOR_MODE_HDR}.
2027          *
2028          * @see #setColorMode(int)
2029          */
2030         @ActivityInfo.ColorMode
getColorMode()2031         public int getColorMode() {
2032             return mColorMode;
2033         }
2034 
2035         /** @hide */
2036         @SystemApi
setUserActivityTimeout(long timeout)2037         public final void setUserActivityTimeout(long timeout) {
2038             userActivityTimeout = timeout;
2039         }
2040 
2041         /** @hide */
2042         @SystemApi
getUserActivityTimeout()2043         public final long getUserActivityTimeout() {
2044             return userActivityTimeout;
2045         }
2046 
describeContents()2047         public int describeContents() {
2048             return 0;
2049         }
2050 
writeToParcel(Parcel out, int parcelableFlags)2051         public void writeToParcel(Parcel out, int parcelableFlags) {
2052             out.writeInt(width);
2053             out.writeInt(height);
2054             out.writeInt(x);
2055             out.writeInt(y);
2056             out.writeInt(type);
2057             out.writeInt(flags);
2058             out.writeInt(privateFlags);
2059             out.writeInt(softInputMode);
2060             out.writeInt(gravity);
2061             out.writeFloat(horizontalMargin);
2062             out.writeFloat(verticalMargin);
2063             out.writeInt(format);
2064             out.writeInt(windowAnimations);
2065             out.writeFloat(alpha);
2066             out.writeFloat(dimAmount);
2067             out.writeFloat(screenBrightness);
2068             out.writeFloat(buttonBrightness);
2069             out.writeInt(rotationAnimation);
2070             out.writeStrongBinder(token);
2071             out.writeString(packageName);
2072             TextUtils.writeToParcel(mTitle, out, parcelableFlags);
2073             out.writeInt(screenOrientation);
2074             out.writeFloat(preferredRefreshRate);
2075             out.writeInt(preferredDisplayModeId);
2076             out.writeInt(systemUiVisibility);
2077             out.writeInt(subtreeSystemUiVisibility);
2078             out.writeInt(hasSystemUiListeners ? 1 : 0);
2079             out.writeInt(inputFeatures);
2080             out.writeLong(userActivityTimeout);
2081             out.writeInt(surfaceInsets.left);
2082             out.writeInt(surfaceInsets.top);
2083             out.writeInt(surfaceInsets.right);
2084             out.writeInt(surfaceInsets.bottom);
2085             out.writeInt(hasManualSurfaceInsets ? 1 : 0);
2086             out.writeInt(preservePreviousSurfaceInsets ? 1 : 0);
2087             out.writeInt(needsMenuKey);
2088             out.writeInt(accessibilityIdOfAnchor);
2089             TextUtils.writeToParcel(accessibilityTitle, out, parcelableFlags);
2090             out.writeLong(hideTimeoutMilliseconds);
2091         }
2092 
2093         public static final Parcelable.Creator<LayoutParams> CREATOR
2094                     = new Parcelable.Creator<LayoutParams>() {
2095             public LayoutParams createFromParcel(Parcel in) {
2096                 return new LayoutParams(in);
2097             }
2098 
2099             public LayoutParams[] newArray(int size) {
2100                 return new LayoutParams[size];
2101             }
2102         };
2103 
2104 
LayoutParams(Parcel in)2105         public LayoutParams(Parcel in) {
2106             width = in.readInt();
2107             height = in.readInt();
2108             x = in.readInt();
2109             y = in.readInt();
2110             type = in.readInt();
2111             flags = in.readInt();
2112             privateFlags = in.readInt();
2113             softInputMode = in.readInt();
2114             gravity = in.readInt();
2115             horizontalMargin = in.readFloat();
2116             verticalMargin = in.readFloat();
2117             format = in.readInt();
2118             windowAnimations = in.readInt();
2119             alpha = in.readFloat();
2120             dimAmount = in.readFloat();
2121             screenBrightness = in.readFloat();
2122             buttonBrightness = in.readFloat();
2123             rotationAnimation = in.readInt();
2124             token = in.readStrongBinder();
2125             packageName = in.readString();
2126             mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
2127             screenOrientation = in.readInt();
2128             preferredRefreshRate = in.readFloat();
2129             preferredDisplayModeId = in.readInt();
2130             systemUiVisibility = in.readInt();
2131             subtreeSystemUiVisibility = in.readInt();
2132             hasSystemUiListeners = in.readInt() != 0;
2133             inputFeatures = in.readInt();
2134             userActivityTimeout = in.readLong();
2135             surfaceInsets.left = in.readInt();
2136             surfaceInsets.top = in.readInt();
2137             surfaceInsets.right = in.readInt();
2138             surfaceInsets.bottom = in.readInt();
2139             hasManualSurfaceInsets = in.readInt() != 0;
2140             preservePreviousSurfaceInsets = in.readInt() != 0;
2141             needsMenuKey = in.readInt();
2142             accessibilityIdOfAnchor = in.readInt();
2143             accessibilityTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
2144             hideTimeoutMilliseconds = in.readLong();
2145         }
2146 
2147         @SuppressWarnings({"PointlessBitwiseExpression"})
2148         public static final int LAYOUT_CHANGED = 1<<0;
2149         public static final int TYPE_CHANGED = 1<<1;
2150         public static final int FLAGS_CHANGED = 1<<2;
2151         public static final int FORMAT_CHANGED = 1<<3;
2152         public static final int ANIMATION_CHANGED = 1<<4;
2153         public static final int DIM_AMOUNT_CHANGED = 1<<5;
2154         public static final int TITLE_CHANGED = 1<<6;
2155         public static final int ALPHA_CHANGED = 1<<7;
2156         public static final int MEMORY_TYPE_CHANGED = 1<<8;
2157         public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
2158         public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
2159         public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
2160         public static final int ROTATION_ANIMATION_CHANGED = 1<<12;
2161         /** {@hide} */
2162         public static final int BUTTON_BRIGHTNESS_CHANGED = 1<<13;
2163         /** {@hide} */
2164         public static final int SYSTEM_UI_VISIBILITY_CHANGED = 1<<14;
2165         /** {@hide} */
2166         public static final int SYSTEM_UI_LISTENER_CHANGED = 1<<15;
2167         /** {@hide} */
2168         public static final int INPUT_FEATURES_CHANGED = 1<<16;
2169         /** {@hide} */
2170         public static final int PRIVATE_FLAGS_CHANGED = 1<<17;
2171         /** {@hide} */
2172         public static final int USER_ACTIVITY_TIMEOUT_CHANGED = 1<<18;
2173         /** {@hide} */
2174         public static final int TRANSLUCENT_FLAGS_CHANGED = 1<<19;
2175         /** {@hide} */
2176         public static final int SURFACE_INSETS_CHANGED = 1<<20;
2177         /** {@hide} */
2178         public static final int PREFERRED_REFRESH_RATE_CHANGED = 1 << 21;
2179         /** {@hide} */
2180         public static final int NEEDS_MENU_KEY_CHANGED = 1 << 22;
2181         /** {@hide} */
2182         public static final int PREFERRED_DISPLAY_MODE_ID = 1 << 23;
2183         /** {@hide} */
2184         public static final int ACCESSIBILITY_ANCHOR_CHANGED = 1 << 24;
2185         /** {@hide} */
2186         @TestApi
2187         public static final int ACCESSIBILITY_TITLE_CHANGED = 1 << 25;
2188         /** {@hide} */
2189         public static final int EVERYTHING_CHANGED = 0xffffffff;
2190 
2191         // internal buffer to backup/restore parameters under compatibility mode.
2192         private int[] mCompatibilityParamsBackup = null;
2193 
copyFrom(LayoutParams o)2194         public final int copyFrom(LayoutParams o) {
2195             int changes = 0;
2196 
2197             if (width != o.width) {
2198                 width = o.width;
2199                 changes |= LAYOUT_CHANGED;
2200             }
2201             if (height != o.height) {
2202                 height = o.height;
2203                 changes |= LAYOUT_CHANGED;
2204             }
2205             if (x != o.x) {
2206                 x = o.x;
2207                 changes |= LAYOUT_CHANGED;
2208             }
2209             if (y != o.y) {
2210                 y = o.y;
2211                 changes |= LAYOUT_CHANGED;
2212             }
2213             if (horizontalWeight != o.horizontalWeight) {
2214                 horizontalWeight = o.horizontalWeight;
2215                 changes |= LAYOUT_CHANGED;
2216             }
2217             if (verticalWeight != o.verticalWeight) {
2218                 verticalWeight = o.verticalWeight;
2219                 changes |= LAYOUT_CHANGED;
2220             }
2221             if (horizontalMargin != o.horizontalMargin) {
2222                 horizontalMargin = o.horizontalMargin;
2223                 changes |= LAYOUT_CHANGED;
2224             }
2225             if (verticalMargin != o.verticalMargin) {
2226                 verticalMargin = o.verticalMargin;
2227                 changes |= LAYOUT_CHANGED;
2228             }
2229             if (type != o.type) {
2230                 type = o.type;
2231                 changes |= TYPE_CHANGED;
2232             }
2233             if (flags != o.flags) {
2234                 final int diff = flags ^ o.flags;
2235                 if ((diff & (FLAG_TRANSLUCENT_STATUS | FLAG_TRANSLUCENT_NAVIGATION)) != 0) {
2236                     changes |= TRANSLUCENT_FLAGS_CHANGED;
2237                 }
2238                 flags = o.flags;
2239                 changes |= FLAGS_CHANGED;
2240             }
2241             if (privateFlags != o.privateFlags) {
2242                 privateFlags = o.privateFlags;
2243                 changes |= PRIVATE_FLAGS_CHANGED;
2244             }
2245             if (softInputMode != o.softInputMode) {
2246                 softInputMode = o.softInputMode;
2247                 changes |= SOFT_INPUT_MODE_CHANGED;
2248             }
2249             if (gravity != o.gravity) {
2250                 gravity = o.gravity;
2251                 changes |= LAYOUT_CHANGED;
2252             }
2253             if (format != o.format) {
2254                 format = o.format;
2255                 changes |= FORMAT_CHANGED;
2256             }
2257             if (windowAnimations != o.windowAnimations) {
2258                 windowAnimations = o.windowAnimations;
2259                 changes |= ANIMATION_CHANGED;
2260             }
2261             if (token == null) {
2262                 // NOTE: token only copied if the recipient doesn't
2263                 // already have one.
2264                 token = o.token;
2265             }
2266             if (packageName == null) {
2267                 // NOTE: packageName only copied if the recipient doesn't
2268                 // already have one.
2269                 packageName = o.packageName;
2270             }
2271             if (!Objects.equals(mTitle, o.mTitle) && o.mTitle != null) {
2272                 // NOTE: mTitle only copied if the originator set one.
2273                 mTitle = o.mTitle;
2274                 changes |= TITLE_CHANGED;
2275             }
2276             if (alpha != o.alpha) {
2277                 alpha = o.alpha;
2278                 changes |= ALPHA_CHANGED;
2279             }
2280             if (dimAmount != o.dimAmount) {
2281                 dimAmount = o.dimAmount;
2282                 changes |= DIM_AMOUNT_CHANGED;
2283             }
2284             if (screenBrightness != o.screenBrightness) {
2285                 screenBrightness = o.screenBrightness;
2286                 changes |= SCREEN_BRIGHTNESS_CHANGED;
2287             }
2288             if (buttonBrightness != o.buttonBrightness) {
2289                 buttonBrightness = o.buttonBrightness;
2290                 changes |= BUTTON_BRIGHTNESS_CHANGED;
2291             }
2292             if (rotationAnimation != o.rotationAnimation) {
2293                 rotationAnimation = o.rotationAnimation;
2294                 changes |= ROTATION_ANIMATION_CHANGED;
2295             }
2296 
2297             if (screenOrientation != o.screenOrientation) {
2298                 screenOrientation = o.screenOrientation;
2299                 changes |= SCREEN_ORIENTATION_CHANGED;
2300             }
2301 
2302             if (preferredRefreshRate != o.preferredRefreshRate) {
2303                 preferredRefreshRate = o.preferredRefreshRate;
2304                 changes |= PREFERRED_REFRESH_RATE_CHANGED;
2305             }
2306 
2307             if (preferredDisplayModeId != o.preferredDisplayModeId) {
2308                 preferredDisplayModeId = o.preferredDisplayModeId;
2309                 changes |= PREFERRED_DISPLAY_MODE_ID;
2310             }
2311 
2312             if (systemUiVisibility != o.systemUiVisibility
2313                     || subtreeSystemUiVisibility != o.subtreeSystemUiVisibility) {
2314                 systemUiVisibility = o.systemUiVisibility;
2315                 subtreeSystemUiVisibility = o.subtreeSystemUiVisibility;
2316                 changes |= SYSTEM_UI_VISIBILITY_CHANGED;
2317             }
2318 
2319             if (hasSystemUiListeners != o.hasSystemUiListeners) {
2320                 hasSystemUiListeners = o.hasSystemUiListeners;
2321                 changes |= SYSTEM_UI_LISTENER_CHANGED;
2322             }
2323 
2324             if (inputFeatures != o.inputFeatures) {
2325                 inputFeatures = o.inputFeatures;
2326                 changes |= INPUT_FEATURES_CHANGED;
2327             }
2328 
2329             if (userActivityTimeout != o.userActivityTimeout) {
2330                 userActivityTimeout = o.userActivityTimeout;
2331                 changes |= USER_ACTIVITY_TIMEOUT_CHANGED;
2332             }
2333 
2334             if (!surfaceInsets.equals(o.surfaceInsets)) {
2335                 surfaceInsets.set(o.surfaceInsets);
2336                 changes |= SURFACE_INSETS_CHANGED;
2337             }
2338 
2339             if (hasManualSurfaceInsets != o.hasManualSurfaceInsets) {
2340                 hasManualSurfaceInsets = o.hasManualSurfaceInsets;
2341                 changes |= SURFACE_INSETS_CHANGED;
2342             }
2343 
2344             if (preservePreviousSurfaceInsets != o.preservePreviousSurfaceInsets) {
2345                 preservePreviousSurfaceInsets = o.preservePreviousSurfaceInsets;
2346                 changes |= SURFACE_INSETS_CHANGED;
2347             }
2348 
2349             if (needsMenuKey != o.needsMenuKey) {
2350                 needsMenuKey = o.needsMenuKey;
2351                 changes |= NEEDS_MENU_KEY_CHANGED;
2352             }
2353 
2354             if (accessibilityIdOfAnchor != o.accessibilityIdOfAnchor) {
2355                 accessibilityIdOfAnchor = o.accessibilityIdOfAnchor;
2356                 changes |= ACCESSIBILITY_ANCHOR_CHANGED;
2357             }
2358 
2359             if (!Objects.equals(accessibilityTitle, o.accessibilityTitle)
2360                     && o.accessibilityTitle != null) {
2361                 // NOTE: accessibilityTitle only copied if the originator set one.
2362                 accessibilityTitle = o.accessibilityTitle;
2363                 changes |= ACCESSIBILITY_TITLE_CHANGED;
2364             }
2365 
2366             // This can't change, it's only set at window creation time.
2367             hideTimeoutMilliseconds = o.hideTimeoutMilliseconds;
2368 
2369             return changes;
2370         }
2371 
2372         @Override
debug(String output)2373         public String debug(String output) {
2374             output += "Contents of " + this + ":";
2375             Log.d("Debug", output);
2376             output = super.debug("");
2377             Log.d("Debug", output);
2378             Log.d("Debug", "");
2379             Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
2380             return "";
2381         }
2382 
2383         @Override
toString()2384         public String toString() {
2385             StringBuilder sb = new StringBuilder(256);
2386             sb.append("WM.LayoutParams{");
2387             sb.append("(");
2388             sb.append(x);
2389             sb.append(',');
2390             sb.append(y);
2391             sb.append(")(");
2392             sb.append((width == MATCH_PARENT ? "fill" : (width == WRAP_CONTENT
2393                     ? "wrap" : String.valueOf(width))));
2394             sb.append('x');
2395             sb.append((height == MATCH_PARENT ? "fill" : (height == WRAP_CONTENT
2396                     ? "wrap" : String.valueOf(height))));
2397             sb.append(")");
2398             if (horizontalMargin != 0) {
2399                 sb.append(" hm=");
2400                 sb.append(horizontalMargin);
2401             }
2402             if (verticalMargin != 0) {
2403                 sb.append(" vm=");
2404                 sb.append(verticalMargin);
2405             }
2406             if (gravity != 0) {
2407                 sb.append(" gr=#");
2408                 sb.append(Integer.toHexString(gravity));
2409             }
2410             if (softInputMode != 0) {
2411                 sb.append(" sim=#");
2412                 sb.append(Integer.toHexString(softInputMode));
2413             }
2414             sb.append(" ty=");
2415             sb.append(type);
2416             sb.append(" fl=#");
2417             sb.append(Integer.toHexString(flags));
2418             if (privateFlags != 0) {
2419                 if ((privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0) {
2420                     sb.append(" compatible=true");
2421                 }
2422                 sb.append(" pfl=0x").append(Integer.toHexString(privateFlags));
2423             }
2424             if (format != PixelFormat.OPAQUE) {
2425                 sb.append(" fmt=");
2426                 sb.append(format);
2427             }
2428             if (windowAnimations != 0) {
2429                 sb.append(" wanim=0x");
2430                 sb.append(Integer.toHexString(windowAnimations));
2431             }
2432             if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
2433                 sb.append(" or=");
2434                 sb.append(screenOrientation);
2435             }
2436             if (alpha != 1.0f) {
2437                 sb.append(" alpha=");
2438                 sb.append(alpha);
2439             }
2440             if (screenBrightness != BRIGHTNESS_OVERRIDE_NONE) {
2441                 sb.append(" sbrt=");
2442                 sb.append(screenBrightness);
2443             }
2444             if (buttonBrightness != BRIGHTNESS_OVERRIDE_NONE) {
2445                 sb.append(" bbrt=");
2446                 sb.append(buttonBrightness);
2447             }
2448             if (rotationAnimation != ROTATION_ANIMATION_ROTATE) {
2449                 sb.append(" rotAnim=");
2450                 sb.append(rotationAnimation);
2451             }
2452             if (preferredRefreshRate != 0) {
2453                 sb.append(" preferredRefreshRate=");
2454                 sb.append(preferredRefreshRate);
2455             }
2456             if (preferredDisplayModeId != 0) {
2457                 sb.append(" preferredDisplayMode=");
2458                 sb.append(preferredDisplayModeId);
2459             }
2460             if (systemUiVisibility != 0) {
2461                 sb.append(" sysui=0x");
2462                 sb.append(Integer.toHexString(systemUiVisibility));
2463             }
2464             if (subtreeSystemUiVisibility != 0) {
2465                 sb.append(" vsysui=0x");
2466                 sb.append(Integer.toHexString(subtreeSystemUiVisibility));
2467             }
2468             if (hasSystemUiListeners) {
2469                 sb.append(" sysuil=");
2470                 sb.append(hasSystemUiListeners);
2471             }
2472             if (inputFeatures != 0) {
2473                 sb.append(" if=0x").append(Integer.toHexString(inputFeatures));
2474             }
2475             if (userActivityTimeout >= 0) {
2476                 sb.append(" userActivityTimeout=").append(userActivityTimeout);
2477             }
2478             if (surfaceInsets.left != 0 || surfaceInsets.top != 0 || surfaceInsets.right != 0 ||
2479                     surfaceInsets.bottom != 0 || hasManualSurfaceInsets
2480                     || !preservePreviousSurfaceInsets) {
2481                 sb.append(" surfaceInsets=").append(surfaceInsets);
2482                 if (hasManualSurfaceInsets) {
2483                     sb.append(" (manual)");
2484                 }
2485                 if (!preservePreviousSurfaceInsets) {
2486                     sb.append(" (!preservePreviousSurfaceInsets)");
2487                 }
2488             }
2489             if (needsMenuKey != NEEDS_MENU_UNSET) {
2490                 sb.append(" needsMenuKey=");
2491                 sb.append(needsMenuKey);
2492             }
2493             sb.append(" colorMode=").append(mColorMode);
2494             sb.append('}');
2495             return sb.toString();
2496         }
2497 
2498         /**
2499          * Scale the layout params' coordinates and size.
2500          * @hide
2501          */
scale(float scale)2502         public void scale(float scale) {
2503             x = (int) (x * scale + 0.5f);
2504             y = (int) (y * scale + 0.5f);
2505             if (width > 0) {
2506                 width = (int) (width * scale + 0.5f);
2507             }
2508             if (height > 0) {
2509                 height = (int) (height * scale + 0.5f);
2510             }
2511         }
2512 
2513         /**
2514          * Backup the layout parameters used in compatibility mode.
2515          * @see LayoutParams#restore()
2516          */
backup()2517         void backup() {
2518             int[] backup = mCompatibilityParamsBackup;
2519             if (backup == null) {
2520                 // we backup 4 elements, x, y, width, height
2521                 backup = mCompatibilityParamsBackup = new int[4];
2522             }
2523             backup[0] = x;
2524             backup[1] = y;
2525             backup[2] = width;
2526             backup[3] = height;
2527         }
2528 
2529         /**
2530          * Restore the layout params' coordinates, size and gravity
2531          * @see LayoutParams#backup()
2532          */
restore()2533         void restore() {
2534             int[] backup = mCompatibilityParamsBackup;
2535             if (backup != null) {
2536                 x = backup[0];
2537                 y = backup[1];
2538                 width = backup[2];
2539                 height = backup[3];
2540             }
2541         }
2542 
2543         private CharSequence mTitle = null;
2544 
2545         /** @hide */
2546         @Override
encodeProperties(@onNull ViewHierarchyEncoder encoder)2547         protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
2548             super.encodeProperties(encoder);
2549 
2550             encoder.addProperty("x", x);
2551             encoder.addProperty("y", y);
2552             encoder.addProperty("horizontalWeight", horizontalWeight);
2553             encoder.addProperty("verticalWeight", verticalWeight);
2554             encoder.addProperty("type", type);
2555             encoder.addProperty("flags", flags);
2556         }
2557     }
2558 }
2559