• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.view;
18 
19 import 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 any window added by an application process that is of type
1384          * {@link #TYPE_TOAST} or that requires
1385          * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
1386          * this window is visible.
1387          * @hide
1388          */
1389         public static final int PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS = 0x00080000;
1390 
1391         /**
1392          * Control flags that are private to the platform.
1393          * @hide
1394          */
1395         @TestApi
1396         public int privateFlags;
1397 
1398         /**
1399          * Value for {@link #needsMenuKey} for a window that has not explicitly specified if it
1400          * needs {@link #NEEDS_MENU_SET_TRUE} or doesn't need {@link #NEEDS_MENU_SET_FALSE} a menu
1401          * key. For this case, we should look at windows behind it to determine the appropriate
1402          * value.
1403          *
1404          * @hide
1405          */
1406         public static final int NEEDS_MENU_UNSET = 0;
1407 
1408         /**
1409          * Value for {@link #needsMenuKey} for a window that has explicitly specified it needs a
1410          * menu key.
1411          *
1412          * @hide
1413          */
1414         public static final int NEEDS_MENU_SET_TRUE = 1;
1415 
1416         /**
1417          * Value for {@link #needsMenuKey} for a window that has explicitly specified it doesn't
1418          * needs a menu key.
1419          *
1420          * @hide
1421          */
1422         public static final int NEEDS_MENU_SET_FALSE = 2;
1423 
1424         /**
1425          * State variable for a window belonging to an activity that responds to
1426          * {@link KeyEvent#KEYCODE_MENU} and therefore needs a Menu key. For devices where Menu is a
1427          * physical button this variable is ignored, but on devices where the Menu key is drawn in
1428          * software it may be hidden unless this variable is set to {@link #NEEDS_MENU_SET_TRUE}.
1429          *
1430          *  (Note that Action Bars, when available, are the preferred way to offer additional
1431          * functions otherwise accessed via an options menu.)
1432          *
1433          * {@hide}
1434          */
1435         public int needsMenuKey = NEEDS_MENU_UNSET;
1436 
1437         /**
1438          * Given a particular set of window manager flags, determine whether
1439          * such a window may be a target for an input method when it has
1440          * focus.  In particular, this checks the
1441          * {@link #FLAG_NOT_FOCUSABLE} and {@link #FLAG_ALT_FOCUSABLE_IM}
1442          * flags and returns true if the combination of the two corresponds
1443          * to a window that needs to be behind the input method so that the
1444          * user can type into it.
1445          *
1446          * @param flags The current window manager flags.
1447          *
1448          * @return Returns true if such a window should be behind/interact
1449          * with an input method, false if not.
1450          */
mayUseInputMethod(int flags)1451         public static boolean mayUseInputMethod(int flags) {
1452             switch (flags&(FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) {
1453                 case 0:
1454                 case FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM:
1455                     return true;
1456             }
1457             return false;
1458         }
1459 
1460         /**
1461          * Mask for {@link #softInputMode} of the bits that determine the
1462          * desired visibility state of the soft input area for this window.
1463          */
1464         public static final int SOFT_INPUT_MASK_STATE = 0x0f;
1465 
1466         /**
1467          * Visibility state for {@link #softInputMode}: no state has been specified.
1468          */
1469         public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;
1470 
1471         /**
1472          * Visibility state for {@link #softInputMode}: please don't change the state of
1473          * the soft input area.
1474          */
1475         public static final int SOFT_INPUT_STATE_UNCHANGED = 1;
1476 
1477         /**
1478          * Visibility state for {@link #softInputMode}: please hide any soft input
1479          * area when normally appropriate (when the user is navigating
1480          * forward to your window).
1481          */
1482         public static final int SOFT_INPUT_STATE_HIDDEN = 2;
1483 
1484         /**
1485          * Visibility state for {@link #softInputMode}: please always hide any
1486          * soft input area when this window receives focus.
1487          */
1488         public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;
1489 
1490         /**
1491          * Visibility state for {@link #softInputMode}: please show the soft
1492          * input area when normally appropriate (when the user is navigating
1493          * forward to your window).
1494          */
1495         public static final int SOFT_INPUT_STATE_VISIBLE = 4;
1496 
1497         /**
1498          * Visibility state for {@link #softInputMode}: please always make the
1499          * soft input area visible when this window receives input focus.
1500          */
1501         public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;
1502 
1503         /**
1504          * Mask for {@link #softInputMode} of the bits that determine the
1505          * way that the window should be adjusted to accommodate the soft
1506          * input window.
1507          */
1508         public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;
1509 
1510         /** Adjustment option for {@link #softInputMode}: nothing specified.
1511          * The system will try to pick one or
1512          * the other depending on the contents of the window.
1513          */
1514         public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;
1515 
1516         /** Adjustment option for {@link #softInputMode}: set to allow the
1517          * window to be resized when an input
1518          * method is shown, so that its contents are not covered by the input
1519          * method.  This can <em>not</em> be combined with
1520          * {@link #SOFT_INPUT_ADJUST_PAN}; if
1521          * neither of these are set, then the system will try to pick one or
1522          * the other depending on the contents of the window. If the window's
1523          * layout parameter flags include {@link #FLAG_FULLSCREEN}, this
1524          * value for {@link #softInputMode} will be ignored; the window will
1525          * not resize, but will stay fullscreen.
1526          */
1527         public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
1528 
1529         /** Adjustment option for {@link #softInputMode}: set to have a window
1530          * pan when an input method is
1531          * shown, so it doesn't need to deal with resizing but just panned
1532          * by the framework to ensure the current input focus is visible.  This
1533          * can <em>not</em> be combined with {@link #SOFT_INPUT_ADJUST_RESIZE}; if
1534          * neither of these are set, then the system will try to pick one or
1535          * the other depending on the contents of the window.
1536          */
1537         public static final int SOFT_INPUT_ADJUST_PAN = 0x20;
1538 
1539         /** Adjustment option for {@link #softInputMode}: set to have a window
1540          * not adjust for a shown input method.  The window will not be resized,
1541          * and it will not be panned to make its focus visible.
1542          */
1543         public static final int SOFT_INPUT_ADJUST_NOTHING = 0x30;
1544 
1545         /**
1546          * Bit for {@link #softInputMode}: set when the user has navigated
1547          * forward to the window.  This is normally set automatically for
1548          * you by the system, though you may want to set it in certain cases
1549          * when you are displaying a window yourself.  This flag will always
1550          * be cleared automatically after the window is displayed.
1551          */
1552         public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;
1553 
1554         /**
1555          * An internal annotation for flags that can be specified to {@link #softInputMode}.
1556          *
1557          * @hide
1558          */
1559         @Retention(RetentionPolicy.SOURCE)
1560         @IntDef(flag = true, value = {
1561                 SOFT_INPUT_STATE_UNSPECIFIED,
1562                 SOFT_INPUT_STATE_UNCHANGED,
1563                 SOFT_INPUT_STATE_HIDDEN,
1564                 SOFT_INPUT_STATE_ALWAYS_HIDDEN,
1565                 SOFT_INPUT_STATE_VISIBLE,
1566                 SOFT_INPUT_STATE_ALWAYS_VISIBLE,
1567                 SOFT_INPUT_ADJUST_UNSPECIFIED,
1568                 SOFT_INPUT_ADJUST_RESIZE,
1569                 SOFT_INPUT_ADJUST_PAN,
1570                 SOFT_INPUT_ADJUST_NOTHING,
1571                 SOFT_INPUT_IS_FORWARD_NAVIGATION,
1572         })
1573         public @interface SoftInputModeFlags {}
1574 
1575         /**
1576          * Desired operating mode for any soft input area.  May be any combination
1577          * of:
1578          *
1579          * <ul>
1580          * <li> One of the visibility states
1581          * {@link #SOFT_INPUT_STATE_UNSPECIFIED}, {@link #SOFT_INPUT_STATE_UNCHANGED},
1582          * {@link #SOFT_INPUT_STATE_HIDDEN}, {@link #SOFT_INPUT_STATE_ALWAYS_HIDDEN},
1583          * {@link #SOFT_INPUT_STATE_VISIBLE}, or {@link #SOFT_INPUT_STATE_ALWAYS_VISIBLE}.
1584          * <li> One of the adjustment options
1585          * {@link #SOFT_INPUT_ADJUST_UNSPECIFIED}, {@link #SOFT_INPUT_ADJUST_RESIZE},
1586          * {@link #SOFT_INPUT_ADJUST_PAN}, or {@link #SOFT_INPUT_ADJUST_NOTHING}.
1587          * </ul>
1588          *
1589          *
1590          * <p>This flag can be controlled in your theme through the
1591          * {@link android.R.attr#windowSoftInputMode} attribute.</p>
1592          */
1593         @SoftInputModeFlags
1594         public int softInputMode;
1595 
1596         /**
1597          * Placement of window within the screen as per {@link Gravity}.  Both
1598          * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1599          * android.graphics.Rect) Gravity.apply} and
1600          * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
1601          * Gravity.applyDisplay} are used during window layout, with this value
1602          * given as the desired gravity.  For example you can specify
1603          * {@link Gravity#DISPLAY_CLIP_HORIZONTAL Gravity.DISPLAY_CLIP_HORIZONTAL} and
1604          * {@link Gravity#DISPLAY_CLIP_VERTICAL Gravity.DISPLAY_CLIP_VERTICAL} here
1605          * to control the behavior of
1606          * {@link Gravity#applyDisplay(int, android.graphics.Rect, android.graphics.Rect)
1607          * Gravity.applyDisplay}.
1608          *
1609          * @see Gravity
1610          */
1611         public int gravity;
1612 
1613         /**
1614          * The horizontal margin, as a percentage of the container's width,
1615          * between the container and the widget.  See
1616          * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1617          * android.graphics.Rect) Gravity.apply} for how this is used.  This
1618          * field is added with {@link #x} to supply the <var>xAdj</var> parameter.
1619          */
1620         public float horizontalMargin;
1621 
1622         /**
1623          * The vertical margin, as a percentage of the container's height,
1624          * between the container and the widget.  See
1625          * {@link Gravity#apply(int, int, int, android.graphics.Rect, int, int,
1626          * android.graphics.Rect) Gravity.apply} for how this is used.  This
1627          * field is added with {@link #y} to supply the <var>yAdj</var> parameter.
1628          */
1629         public float verticalMargin;
1630 
1631         /**
1632          * Positive insets between the drawing surface and window content.
1633          *
1634          * @hide
1635          */
1636         public final Rect surfaceInsets = new Rect();
1637 
1638         /**
1639          * Whether the surface insets have been manually set. When set to
1640          * {@code false}, the view root will automatically determine the
1641          * appropriate surface insets.
1642          *
1643          * @see #surfaceInsets
1644          * @hide
1645          */
1646         public boolean hasManualSurfaceInsets;
1647 
1648         /**
1649          * Whether the previous surface insets should be used vs. what is currently set. When set
1650          * to {@code true}, the view root will ignore surfaces insets in this object and use what
1651          * it currently has.
1652          *
1653          * @see #surfaceInsets
1654          * @hide
1655          */
1656         public boolean preservePreviousSurfaceInsets = true;
1657 
1658         /**
1659          * The desired bitmap format.  May be one of the constants in
1660          * {@link android.graphics.PixelFormat}. The choice of format
1661          * might be overridden by {@link #setColorMode(int)}. Default is OPAQUE.
1662          */
1663         public int format;
1664 
1665         /**
1666          * A style resource defining the animations to use for this window.
1667          * This must be a system resource; it can not be an application resource
1668          * because the window manager does not have access to applications.
1669          */
1670         public int windowAnimations;
1671 
1672         /**
1673          * An alpha value to apply to this entire window.
1674          * An alpha of 1.0 means fully opaque and 0.0 means fully transparent
1675          */
1676         public float alpha = 1.0f;
1677 
1678         /**
1679          * When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
1680          * to apply.  Range is from 1.0 for completely opaque to 0.0 for no
1681          * dim.
1682          */
1683         public float dimAmount = 1.0f;
1684 
1685         /**
1686          * Default value for {@link #screenBrightness} and {@link #buttonBrightness}
1687          * indicating that the brightness value is not overridden for this window
1688          * and normal brightness policy should be used.
1689          */
1690         public static final float BRIGHTNESS_OVERRIDE_NONE = -1.0f;
1691 
1692         /**
1693          * Value for {@link #screenBrightness} and {@link #buttonBrightness}
1694          * indicating that the screen or button backlight brightness should be set
1695          * to the lowest value when this window is in front.
1696          */
1697         public static final float BRIGHTNESS_OVERRIDE_OFF = 0.0f;
1698 
1699         /**
1700          * Value for {@link #screenBrightness} and {@link #buttonBrightness}
1701          * indicating that the screen or button backlight brightness should be set
1702          * to the hightest value when this window is in front.
1703          */
1704         public static final float BRIGHTNESS_OVERRIDE_FULL = 1.0f;
1705 
1706         /**
1707          * This can be used to override the user's preferred brightness of
1708          * the screen.  A value of less than 0, the default, means to use the
1709          * preferred screen brightness.  0 to 1 adjusts the brightness from
1710          * dark to full bright.
1711          */
1712         public float screenBrightness = BRIGHTNESS_OVERRIDE_NONE;
1713 
1714         /**
1715          * This can be used to override the standard behavior of the button and
1716          * keyboard backlights.  A value of less than 0, the default, means to
1717          * use the standard backlight behavior.  0 to 1 adjusts the brightness
1718          * from dark to full bright.
1719          */
1720         public float buttonBrightness = BRIGHTNESS_OVERRIDE_NONE;
1721 
1722         /**
1723          * Value for {@link #rotationAnimation} which specifies that this
1724          * window will visually rotate in or out following a rotation.
1725          */
1726         public static final int ROTATION_ANIMATION_ROTATE = 0;
1727 
1728         /**
1729          * Value for {@link #rotationAnimation} which specifies that this
1730          * window will fade in or out following a rotation.
1731          */
1732         public static final int ROTATION_ANIMATION_CROSSFADE = 1;
1733 
1734         /**
1735          * Value for {@link #rotationAnimation} which specifies that this window
1736          * will immediately disappear or appear following a rotation.
1737          */
1738         public static final int ROTATION_ANIMATION_JUMPCUT = 2;
1739 
1740         /**
1741          * Value for {@link #rotationAnimation} to specify seamless rotation mode.
1742          * This works like JUMPCUT but will fall back to CROSSFADE if rotation
1743          * can't be applied without pausing the screen. For example, this is ideal
1744          * for Camera apps which don't want the viewfinder contents to ever rotate
1745          * or fade (and rather to be seamless) but also don't want ROTATION_ANIMATION_JUMPCUT
1746          * during app transition scenarios where seamless rotation can't be applied.
1747          */
1748         public static final int ROTATION_ANIMATION_SEAMLESS = 3;
1749 
1750         /**
1751          * Define the exit and entry animations used on this window when the device is rotated.
1752          * This only has an affect if the incoming and outgoing topmost
1753          * opaque windows have the #FLAG_FULLSCREEN bit set and are not covered
1754          * by other windows. All other situations default to the
1755          * {@link #ROTATION_ANIMATION_ROTATE} behavior.
1756          *
1757          * @see #ROTATION_ANIMATION_ROTATE
1758          * @see #ROTATION_ANIMATION_CROSSFADE
1759          * @see #ROTATION_ANIMATION_JUMPCUT
1760          */
1761         public int rotationAnimation = ROTATION_ANIMATION_ROTATE;
1762 
1763         /**
1764          * Identifier for this window.  This will usually be filled in for
1765          * you.
1766          */
1767         public IBinder token = null;
1768 
1769         /**
1770          * Name of the package owning this window.
1771          */
1772         public String packageName = null;
1773 
1774         /**
1775          * Specific orientation value for a window.
1776          * May be any of the same values allowed
1777          * for {@link android.content.pm.ActivityInfo#screenOrientation}.
1778          * If not set, a default value of
1779          * {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}
1780          * will be used.
1781          */
1782         public int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
1783 
1784         /**
1785          * The preferred refresh rate for the window.
1786          *
1787          * This must be one of the supported refresh rates obtained for the display(s) the window
1788          * is on. The selected refresh rate will be applied to the display's default mode.
1789          *
1790          * This value is ignored if {@link #preferredDisplayModeId} is set.
1791          *
1792          * @see Display#getSupportedRefreshRates()
1793          * @deprecated use {@link #preferredDisplayModeId} instead
1794          */
1795         @Deprecated
1796         public float preferredRefreshRate;
1797 
1798         /**
1799          * Id of the preferred display mode for the window.
1800          * <p>
1801          * This must be one of the supported modes obtained for the display(s) the window is on.
1802          * A value of {@code 0} means no preference.
1803          *
1804          * @see Display#getSupportedModes()
1805          * @see Display.Mode#getModeId()
1806          */
1807         public int preferredDisplayModeId;
1808 
1809         /**
1810          * Control the visibility of the status bar.
1811          *
1812          * @see View#STATUS_BAR_VISIBLE
1813          * @see View#STATUS_BAR_HIDDEN
1814          */
1815         public int systemUiVisibility;
1816 
1817         /**
1818          * @hide
1819          * The ui visibility as requested by the views in this hierarchy.
1820          * the combined value should be systemUiVisibility | subtreeSystemUiVisibility.
1821          */
1822         public int subtreeSystemUiVisibility;
1823 
1824         /**
1825          * Get callbacks about the system ui visibility changing.
1826          *
1827          * TODO: Maybe there should be a bitfield of optional callbacks that we need.
1828          *
1829          * @hide
1830          */
1831         public boolean hasSystemUiListeners;
1832 
1833         /**
1834          * When this window has focus, disable touch pad pointer gesture processing.
1835          * The window will receive raw position updates from the touch pad instead
1836          * of pointer movements and synthetic touch events.
1837          *
1838          * @hide
1839          */
1840         public static final int INPUT_FEATURE_DISABLE_POINTER_GESTURES = 0x00000001;
1841 
1842         /**
1843          * Does not construct an input channel for this window.  The channel will therefore
1844          * be incapable of receiving input.
1845          *
1846          * @hide
1847          */
1848         public static final int INPUT_FEATURE_NO_INPUT_CHANNEL = 0x00000002;
1849 
1850         /**
1851          * When this window has focus, does not call user activity for all input events so
1852          * the application will have to do it itself.  Should only be used by
1853          * the keyguard and phone app.
1854          * <p>
1855          * Should only be used by the keyguard and phone app.
1856          * </p>
1857          *
1858          * @hide
1859          */
1860         public static final int INPUT_FEATURE_DISABLE_USER_ACTIVITY = 0x00000004;
1861 
1862         /**
1863          * Control special features of the input subsystem.
1864          *
1865          * @see #INPUT_FEATURE_DISABLE_POINTER_GESTURES
1866          * @see #INPUT_FEATURE_NO_INPUT_CHANNEL
1867          * @see #INPUT_FEATURE_DISABLE_USER_ACTIVITY
1868          * @hide
1869          */
1870         public int inputFeatures;
1871 
1872         /**
1873          * Sets the number of milliseconds before the user activity timeout occurs
1874          * when this window has focus.  A value of -1 uses the standard timeout.
1875          * A value of 0 uses the minimum support display timeout.
1876          * <p>
1877          * This property can only be used to reduce the user specified display timeout;
1878          * it can never make the timeout longer than it normally would be.
1879          * </p><p>
1880          * Should only be used by the keyguard and phone app.
1881          * </p>
1882          *
1883          * @hide
1884          */
1885         public long userActivityTimeout = -1;
1886 
1887         /**
1888          * For windows with an anchor (e.g. PopupWindow), keeps track of the View that anchors the
1889          * window.
1890          *
1891          * @hide
1892          */
1893         public int accessibilityIdOfAnchor = -1;
1894 
1895         /**
1896          * The window title isn't kept in sync with what is displayed in the title bar, so we
1897          * separately track the currently shown title to provide to accessibility.
1898          *
1899          * @hide
1900          */
1901         @TestApi
1902         public CharSequence accessibilityTitle;
1903 
1904         /**
1905          * Sets a timeout in milliseconds before which the window will be hidden
1906          * by the window manager. Useful for transient notifications like toasts
1907          * so we don't have to rely on client cooperation to ensure the window
1908          * is hidden. Must be specified at window creation time. Note that apps
1909          * are not prepared to handle their windows being removed without their
1910          * explicit request and may try to interact with the removed window
1911          * resulting in undefined behavior and crashes. Therefore, we do hide
1912          * such windows to prevent them from overlaying other apps.
1913          *
1914          * @hide
1915          */
1916         public long hideTimeoutMilliseconds = -1;
1917 
1918         /**
1919          * The color mode requested by this window. The target display may
1920          * not be able to honor the request. When the color mode is not set
1921          * to {@link ActivityInfo#COLOR_MODE_DEFAULT}, it might override the
1922          * pixel format specified in {@link #format}.
1923          *
1924          * @hide
1925          */
1926         @ActivityInfo.ColorMode
1927         private int mColorMode = ActivityInfo.COLOR_MODE_DEFAULT;
1928 
LayoutParams()1929         public LayoutParams() {
1930             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1931             type = TYPE_APPLICATION;
1932             format = PixelFormat.OPAQUE;
1933         }
1934 
LayoutParams(int _type)1935         public LayoutParams(int _type) {
1936             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1937             type = _type;
1938             format = PixelFormat.OPAQUE;
1939         }
1940 
LayoutParams(int _type, int _flags)1941         public LayoutParams(int _type, int _flags) {
1942             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1943             type = _type;
1944             flags = _flags;
1945             format = PixelFormat.OPAQUE;
1946         }
1947 
LayoutParams(int _type, int _flags, int _format)1948         public LayoutParams(int _type, int _flags, int _format) {
1949             super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
1950             type = _type;
1951             flags = _flags;
1952             format = _format;
1953         }
1954 
LayoutParams(int w, int h, int _type, int _flags, int _format)1955         public LayoutParams(int w, int h, int _type, int _flags, int _format) {
1956             super(w, h);
1957             type = _type;
1958             flags = _flags;
1959             format = _format;
1960         }
1961 
LayoutParams(int w, int h, int xpos, int ypos, int _type, int _flags, int _format)1962         public LayoutParams(int w, int h, int xpos, int ypos, int _type,
1963                 int _flags, int _format) {
1964             super(w, h);
1965             x = xpos;
1966             y = ypos;
1967             type = _type;
1968             flags = _flags;
1969             format = _format;
1970         }
1971 
setTitle(CharSequence title)1972         public final void setTitle(CharSequence title) {
1973             if (null == title)
1974                 title = "";
1975 
1976             mTitle = TextUtils.stringOrSpannedString(title);
1977         }
1978 
getTitle()1979         public final CharSequence getTitle() {
1980             return mTitle != null ? mTitle : "";
1981         }
1982 
1983         /**
1984          * Sets the surface insets based on the elevation (visual z position) of the input view.
1985          * @hide
1986          */
setSurfaceInsets(View view, boolean manual, boolean preservePrevious)1987         public final void setSurfaceInsets(View view, boolean manual, boolean preservePrevious) {
1988             final int surfaceInset = (int) Math.ceil(view.getZ() * 2);
1989             // Partial workaround for b/28318973. Every inset change causes a freeform window
1990             // to jump a little for a few frames. If we never allow surface insets to decrease,
1991             // they will stabilize quickly (often from the very beginning, as most windows start
1992             // as focused).
1993             // TODO(b/22668382) to fix this properly.
1994             if (surfaceInset == 0) {
1995                 // OK to have 0 (this is the case for non-freeform windows).
1996                 surfaceInsets.set(0, 0, 0, 0);
1997             } else {
1998                 surfaceInsets.set(
1999                         Math.max(surfaceInset, surfaceInsets.left),
2000                         Math.max(surfaceInset, surfaceInsets.top),
2001                         Math.max(surfaceInset, surfaceInsets.right),
2002                         Math.max(surfaceInset, surfaceInsets.bottom));
2003             }
2004             hasManualSurfaceInsets = manual;
2005             preservePreviousSurfaceInsets = preservePrevious;
2006         }
2007 
2008         /**
2009          * <p>Set the color mode of the window. Setting the color mode might
2010          * override the window's pixel {@link WindowManager.LayoutParams#format format}.</p>
2011          *
2012          * <p>The color mode must be one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
2013          * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or
2014          * {@link ActivityInfo#COLOR_MODE_HDR}.</p>
2015          *
2016          * @see #getColorMode()
2017          */
setColorMode(@ctivityInfo.ColorMode int colorMode)2018         public void setColorMode(@ActivityInfo.ColorMode int colorMode) {
2019             mColorMode = colorMode;
2020         }
2021 
2022         /**
2023          * Returns the color mode of the window, one of {@link ActivityInfo#COLOR_MODE_DEFAULT},
2024          * {@link ActivityInfo#COLOR_MODE_WIDE_COLOR_GAMUT} or {@link ActivityInfo#COLOR_MODE_HDR}.
2025          *
2026          * @see #setColorMode(int)
2027          */
2028         @ActivityInfo.ColorMode
getColorMode()2029         public int getColorMode() {
2030             return mColorMode;
2031         }
2032 
2033         /** @hide */
2034         @SystemApi
setUserActivityTimeout(long timeout)2035         public final void setUserActivityTimeout(long timeout) {
2036             userActivityTimeout = timeout;
2037         }
2038 
2039         /** @hide */
2040         @SystemApi
getUserActivityTimeout()2041         public final long getUserActivityTimeout() {
2042             return userActivityTimeout;
2043         }
2044 
describeContents()2045         public int describeContents() {
2046             return 0;
2047         }
2048 
writeToParcel(Parcel out, int parcelableFlags)2049         public void writeToParcel(Parcel out, int parcelableFlags) {
2050             out.writeInt(width);
2051             out.writeInt(height);
2052             out.writeInt(x);
2053             out.writeInt(y);
2054             out.writeInt(type);
2055             out.writeInt(flags);
2056             out.writeInt(privateFlags);
2057             out.writeInt(softInputMode);
2058             out.writeInt(gravity);
2059             out.writeFloat(horizontalMargin);
2060             out.writeFloat(verticalMargin);
2061             out.writeInt(format);
2062             out.writeInt(windowAnimations);
2063             out.writeFloat(alpha);
2064             out.writeFloat(dimAmount);
2065             out.writeFloat(screenBrightness);
2066             out.writeFloat(buttonBrightness);
2067             out.writeInt(rotationAnimation);
2068             out.writeStrongBinder(token);
2069             out.writeString(packageName);
2070             TextUtils.writeToParcel(mTitle, out, parcelableFlags);
2071             out.writeInt(screenOrientation);
2072             out.writeFloat(preferredRefreshRate);
2073             out.writeInt(preferredDisplayModeId);
2074             out.writeInt(systemUiVisibility);
2075             out.writeInt(subtreeSystemUiVisibility);
2076             out.writeInt(hasSystemUiListeners ? 1 : 0);
2077             out.writeInt(inputFeatures);
2078             out.writeLong(userActivityTimeout);
2079             out.writeInt(surfaceInsets.left);
2080             out.writeInt(surfaceInsets.top);
2081             out.writeInt(surfaceInsets.right);
2082             out.writeInt(surfaceInsets.bottom);
2083             out.writeInt(hasManualSurfaceInsets ? 1 : 0);
2084             out.writeInt(preservePreviousSurfaceInsets ? 1 : 0);
2085             out.writeInt(needsMenuKey);
2086             out.writeInt(accessibilityIdOfAnchor);
2087             TextUtils.writeToParcel(accessibilityTitle, out, parcelableFlags);
2088             out.writeLong(hideTimeoutMilliseconds);
2089         }
2090 
2091         public static final Parcelable.Creator<LayoutParams> CREATOR
2092                     = new Parcelable.Creator<LayoutParams>() {
2093             public LayoutParams createFromParcel(Parcel in) {
2094                 return new LayoutParams(in);
2095             }
2096 
2097             public LayoutParams[] newArray(int size) {
2098                 return new LayoutParams[size];
2099             }
2100         };
2101 
2102 
LayoutParams(Parcel in)2103         public LayoutParams(Parcel in) {
2104             width = in.readInt();
2105             height = in.readInt();
2106             x = in.readInt();
2107             y = in.readInt();
2108             type = in.readInt();
2109             flags = in.readInt();
2110             privateFlags = in.readInt();
2111             softInputMode = in.readInt();
2112             gravity = in.readInt();
2113             horizontalMargin = in.readFloat();
2114             verticalMargin = in.readFloat();
2115             format = in.readInt();
2116             windowAnimations = in.readInt();
2117             alpha = in.readFloat();
2118             dimAmount = in.readFloat();
2119             screenBrightness = in.readFloat();
2120             buttonBrightness = in.readFloat();
2121             rotationAnimation = in.readInt();
2122             token = in.readStrongBinder();
2123             packageName = in.readString();
2124             mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
2125             screenOrientation = in.readInt();
2126             preferredRefreshRate = in.readFloat();
2127             preferredDisplayModeId = in.readInt();
2128             systemUiVisibility = in.readInt();
2129             subtreeSystemUiVisibility = in.readInt();
2130             hasSystemUiListeners = in.readInt() != 0;
2131             inputFeatures = in.readInt();
2132             userActivityTimeout = in.readLong();
2133             surfaceInsets.left = in.readInt();
2134             surfaceInsets.top = in.readInt();
2135             surfaceInsets.right = in.readInt();
2136             surfaceInsets.bottom = in.readInt();
2137             hasManualSurfaceInsets = in.readInt() != 0;
2138             preservePreviousSurfaceInsets = in.readInt() != 0;
2139             needsMenuKey = in.readInt();
2140             accessibilityIdOfAnchor = in.readInt();
2141             accessibilityTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
2142             hideTimeoutMilliseconds = in.readLong();
2143         }
2144 
2145         @SuppressWarnings({"PointlessBitwiseExpression"})
2146         public static final int LAYOUT_CHANGED = 1<<0;
2147         public static final int TYPE_CHANGED = 1<<1;
2148         public static final int FLAGS_CHANGED = 1<<2;
2149         public static final int FORMAT_CHANGED = 1<<3;
2150         public static final int ANIMATION_CHANGED = 1<<4;
2151         public static final int DIM_AMOUNT_CHANGED = 1<<5;
2152         public static final int TITLE_CHANGED = 1<<6;
2153         public static final int ALPHA_CHANGED = 1<<7;
2154         public static final int MEMORY_TYPE_CHANGED = 1<<8;
2155         public static final int SOFT_INPUT_MODE_CHANGED = 1<<9;
2156         public static final int SCREEN_ORIENTATION_CHANGED = 1<<10;
2157         public static final int SCREEN_BRIGHTNESS_CHANGED = 1<<11;
2158         public static final int ROTATION_ANIMATION_CHANGED = 1<<12;
2159         /** {@hide} */
2160         public static final int BUTTON_BRIGHTNESS_CHANGED = 1<<13;
2161         /** {@hide} */
2162         public static final int SYSTEM_UI_VISIBILITY_CHANGED = 1<<14;
2163         /** {@hide} */
2164         public static final int SYSTEM_UI_LISTENER_CHANGED = 1<<15;
2165         /** {@hide} */
2166         public static final int INPUT_FEATURES_CHANGED = 1<<16;
2167         /** {@hide} */
2168         public static final int PRIVATE_FLAGS_CHANGED = 1<<17;
2169         /** {@hide} */
2170         public static final int USER_ACTIVITY_TIMEOUT_CHANGED = 1<<18;
2171         /** {@hide} */
2172         public static final int TRANSLUCENT_FLAGS_CHANGED = 1<<19;
2173         /** {@hide} */
2174         public static final int SURFACE_INSETS_CHANGED = 1<<20;
2175         /** {@hide} */
2176         public static final int PREFERRED_REFRESH_RATE_CHANGED = 1 << 21;
2177         /** {@hide} */
2178         public static final int NEEDS_MENU_KEY_CHANGED = 1 << 22;
2179         /** {@hide} */
2180         public static final int PREFERRED_DISPLAY_MODE_ID = 1 << 23;
2181         /** {@hide} */
2182         public static final int ACCESSIBILITY_ANCHOR_CHANGED = 1 << 24;
2183         /** {@hide} */
2184         @TestApi
2185         public static final int ACCESSIBILITY_TITLE_CHANGED = 1 << 25;
2186         /** {@hide} */
2187         public static final int EVERYTHING_CHANGED = 0xffffffff;
2188 
2189         // internal buffer to backup/restore parameters under compatibility mode.
2190         private int[] mCompatibilityParamsBackup = null;
2191 
copyFrom(LayoutParams o)2192         public final int copyFrom(LayoutParams o) {
2193             int changes = 0;
2194 
2195             if (width != o.width) {
2196                 width = o.width;
2197                 changes |= LAYOUT_CHANGED;
2198             }
2199             if (height != o.height) {
2200                 height = o.height;
2201                 changes |= LAYOUT_CHANGED;
2202             }
2203             if (x != o.x) {
2204                 x = o.x;
2205                 changes |= LAYOUT_CHANGED;
2206             }
2207             if (y != o.y) {
2208                 y = o.y;
2209                 changes |= LAYOUT_CHANGED;
2210             }
2211             if (horizontalWeight != o.horizontalWeight) {
2212                 horizontalWeight = o.horizontalWeight;
2213                 changes |= LAYOUT_CHANGED;
2214             }
2215             if (verticalWeight != o.verticalWeight) {
2216                 verticalWeight = o.verticalWeight;
2217                 changes |= LAYOUT_CHANGED;
2218             }
2219             if (horizontalMargin != o.horizontalMargin) {
2220                 horizontalMargin = o.horizontalMargin;
2221                 changes |= LAYOUT_CHANGED;
2222             }
2223             if (verticalMargin != o.verticalMargin) {
2224                 verticalMargin = o.verticalMargin;
2225                 changes |= LAYOUT_CHANGED;
2226             }
2227             if (type != o.type) {
2228                 type = o.type;
2229                 changes |= TYPE_CHANGED;
2230             }
2231             if (flags != o.flags) {
2232                 final int diff = flags ^ o.flags;
2233                 if ((diff & (FLAG_TRANSLUCENT_STATUS | FLAG_TRANSLUCENT_NAVIGATION)) != 0) {
2234                     changes |= TRANSLUCENT_FLAGS_CHANGED;
2235                 }
2236                 flags = o.flags;
2237                 changes |= FLAGS_CHANGED;
2238             }
2239             if (privateFlags != o.privateFlags) {
2240                 privateFlags = o.privateFlags;
2241                 changes |= PRIVATE_FLAGS_CHANGED;
2242             }
2243             if (softInputMode != o.softInputMode) {
2244                 softInputMode = o.softInputMode;
2245                 changes |= SOFT_INPUT_MODE_CHANGED;
2246             }
2247             if (gravity != o.gravity) {
2248                 gravity = o.gravity;
2249                 changes |= LAYOUT_CHANGED;
2250             }
2251             if (format != o.format) {
2252                 format = o.format;
2253                 changes |= FORMAT_CHANGED;
2254             }
2255             if (windowAnimations != o.windowAnimations) {
2256                 windowAnimations = o.windowAnimations;
2257                 changes |= ANIMATION_CHANGED;
2258             }
2259             if (token == null) {
2260                 // NOTE: token only copied if the recipient doesn't
2261                 // already have one.
2262                 token = o.token;
2263             }
2264             if (packageName == null) {
2265                 // NOTE: packageName only copied if the recipient doesn't
2266                 // already have one.
2267                 packageName = o.packageName;
2268             }
2269             if (!Objects.equals(mTitle, o.mTitle) && o.mTitle != null) {
2270                 // NOTE: mTitle only copied if the originator set one.
2271                 mTitle = o.mTitle;
2272                 changes |= TITLE_CHANGED;
2273             }
2274             if (alpha != o.alpha) {
2275                 alpha = o.alpha;
2276                 changes |= ALPHA_CHANGED;
2277             }
2278             if (dimAmount != o.dimAmount) {
2279                 dimAmount = o.dimAmount;
2280                 changes |= DIM_AMOUNT_CHANGED;
2281             }
2282             if (screenBrightness != o.screenBrightness) {
2283                 screenBrightness = o.screenBrightness;
2284                 changes |= SCREEN_BRIGHTNESS_CHANGED;
2285             }
2286             if (buttonBrightness != o.buttonBrightness) {
2287                 buttonBrightness = o.buttonBrightness;
2288                 changes |= BUTTON_BRIGHTNESS_CHANGED;
2289             }
2290             if (rotationAnimation != o.rotationAnimation) {
2291                 rotationAnimation = o.rotationAnimation;
2292                 changes |= ROTATION_ANIMATION_CHANGED;
2293             }
2294 
2295             if (screenOrientation != o.screenOrientation) {
2296                 screenOrientation = o.screenOrientation;
2297                 changes |= SCREEN_ORIENTATION_CHANGED;
2298             }
2299 
2300             if (preferredRefreshRate != o.preferredRefreshRate) {
2301                 preferredRefreshRate = o.preferredRefreshRate;
2302                 changes |= PREFERRED_REFRESH_RATE_CHANGED;
2303             }
2304 
2305             if (preferredDisplayModeId != o.preferredDisplayModeId) {
2306                 preferredDisplayModeId = o.preferredDisplayModeId;
2307                 changes |= PREFERRED_DISPLAY_MODE_ID;
2308             }
2309 
2310             if (systemUiVisibility != o.systemUiVisibility
2311                     || subtreeSystemUiVisibility != o.subtreeSystemUiVisibility) {
2312                 systemUiVisibility = o.systemUiVisibility;
2313                 subtreeSystemUiVisibility = o.subtreeSystemUiVisibility;
2314                 changes |= SYSTEM_UI_VISIBILITY_CHANGED;
2315             }
2316 
2317             if (hasSystemUiListeners != o.hasSystemUiListeners) {
2318                 hasSystemUiListeners = o.hasSystemUiListeners;
2319                 changes |= SYSTEM_UI_LISTENER_CHANGED;
2320             }
2321 
2322             if (inputFeatures != o.inputFeatures) {
2323                 inputFeatures = o.inputFeatures;
2324                 changes |= INPUT_FEATURES_CHANGED;
2325             }
2326 
2327             if (userActivityTimeout != o.userActivityTimeout) {
2328                 userActivityTimeout = o.userActivityTimeout;
2329                 changes |= USER_ACTIVITY_TIMEOUT_CHANGED;
2330             }
2331 
2332             if (!surfaceInsets.equals(o.surfaceInsets)) {
2333                 surfaceInsets.set(o.surfaceInsets);
2334                 changes |= SURFACE_INSETS_CHANGED;
2335             }
2336 
2337             if (hasManualSurfaceInsets != o.hasManualSurfaceInsets) {
2338                 hasManualSurfaceInsets = o.hasManualSurfaceInsets;
2339                 changes |= SURFACE_INSETS_CHANGED;
2340             }
2341 
2342             if (preservePreviousSurfaceInsets != o.preservePreviousSurfaceInsets) {
2343                 preservePreviousSurfaceInsets = o.preservePreviousSurfaceInsets;
2344                 changes |= SURFACE_INSETS_CHANGED;
2345             }
2346 
2347             if (needsMenuKey != o.needsMenuKey) {
2348                 needsMenuKey = o.needsMenuKey;
2349                 changes |= NEEDS_MENU_KEY_CHANGED;
2350             }
2351 
2352             if (accessibilityIdOfAnchor != o.accessibilityIdOfAnchor) {
2353                 accessibilityIdOfAnchor = o.accessibilityIdOfAnchor;
2354                 changes |= ACCESSIBILITY_ANCHOR_CHANGED;
2355             }
2356 
2357             if (!Objects.equals(accessibilityTitle, o.accessibilityTitle)
2358                     && o.accessibilityTitle != null) {
2359                 // NOTE: accessibilityTitle only copied if the originator set one.
2360                 accessibilityTitle = o.accessibilityTitle;
2361                 changes |= ACCESSIBILITY_TITLE_CHANGED;
2362             }
2363 
2364             // This can't change, it's only set at window creation time.
2365             hideTimeoutMilliseconds = o.hideTimeoutMilliseconds;
2366 
2367             return changes;
2368         }
2369 
2370         @Override
debug(String output)2371         public String debug(String output) {
2372             output += "Contents of " + this + ":";
2373             Log.d("Debug", output);
2374             output = super.debug("");
2375             Log.d("Debug", output);
2376             Log.d("Debug", "");
2377             Log.d("Debug", "WindowManager.LayoutParams={title=" + mTitle + "}");
2378             return "";
2379         }
2380 
2381         @Override
toString()2382         public String toString() {
2383             StringBuilder sb = new StringBuilder(256);
2384             sb.append("WM.LayoutParams{");
2385             sb.append("(");
2386             sb.append(x);
2387             sb.append(',');
2388             sb.append(y);
2389             sb.append(")(");
2390             sb.append((width == MATCH_PARENT ? "fill" : (width == WRAP_CONTENT
2391                     ? "wrap" : String.valueOf(width))));
2392             sb.append('x');
2393             sb.append((height == MATCH_PARENT ? "fill" : (height == WRAP_CONTENT
2394                     ? "wrap" : String.valueOf(height))));
2395             sb.append(")");
2396             if (horizontalMargin != 0) {
2397                 sb.append(" hm=");
2398                 sb.append(horizontalMargin);
2399             }
2400             if (verticalMargin != 0) {
2401                 sb.append(" vm=");
2402                 sb.append(verticalMargin);
2403             }
2404             if (gravity != 0) {
2405                 sb.append(" gr=#");
2406                 sb.append(Integer.toHexString(gravity));
2407             }
2408             if (softInputMode != 0) {
2409                 sb.append(" sim=#");
2410                 sb.append(Integer.toHexString(softInputMode));
2411             }
2412             sb.append(" ty=");
2413             sb.append(type);
2414             sb.append(" fl=#");
2415             sb.append(Integer.toHexString(flags));
2416             if (privateFlags != 0) {
2417                 if ((privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0) {
2418                     sb.append(" compatible=true");
2419                 }
2420                 sb.append(" pfl=0x").append(Integer.toHexString(privateFlags));
2421             }
2422             if (format != PixelFormat.OPAQUE) {
2423                 sb.append(" fmt=");
2424                 sb.append(format);
2425             }
2426             if (windowAnimations != 0) {
2427                 sb.append(" wanim=0x");
2428                 sb.append(Integer.toHexString(windowAnimations));
2429             }
2430             if (screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
2431                 sb.append(" or=");
2432                 sb.append(screenOrientation);
2433             }
2434             if (alpha != 1.0f) {
2435                 sb.append(" alpha=");
2436                 sb.append(alpha);
2437             }
2438             if (screenBrightness != BRIGHTNESS_OVERRIDE_NONE) {
2439                 sb.append(" sbrt=");
2440                 sb.append(screenBrightness);
2441             }
2442             if (buttonBrightness != BRIGHTNESS_OVERRIDE_NONE) {
2443                 sb.append(" bbrt=");
2444                 sb.append(buttonBrightness);
2445             }
2446             if (rotationAnimation != ROTATION_ANIMATION_ROTATE) {
2447                 sb.append(" rotAnim=");
2448                 sb.append(rotationAnimation);
2449             }
2450             if (preferredRefreshRate != 0) {
2451                 sb.append(" preferredRefreshRate=");
2452                 sb.append(preferredRefreshRate);
2453             }
2454             if (preferredDisplayModeId != 0) {
2455                 sb.append(" preferredDisplayMode=");
2456                 sb.append(preferredDisplayModeId);
2457             }
2458             if (systemUiVisibility != 0) {
2459                 sb.append(" sysui=0x");
2460                 sb.append(Integer.toHexString(systemUiVisibility));
2461             }
2462             if (subtreeSystemUiVisibility != 0) {
2463                 sb.append(" vsysui=0x");
2464                 sb.append(Integer.toHexString(subtreeSystemUiVisibility));
2465             }
2466             if (hasSystemUiListeners) {
2467                 sb.append(" sysuil=");
2468                 sb.append(hasSystemUiListeners);
2469             }
2470             if (inputFeatures != 0) {
2471                 sb.append(" if=0x").append(Integer.toHexString(inputFeatures));
2472             }
2473             if (userActivityTimeout >= 0) {
2474                 sb.append(" userActivityTimeout=").append(userActivityTimeout);
2475             }
2476             if (surfaceInsets.left != 0 || surfaceInsets.top != 0 || surfaceInsets.right != 0 ||
2477                     surfaceInsets.bottom != 0 || hasManualSurfaceInsets
2478                     || !preservePreviousSurfaceInsets) {
2479                 sb.append(" surfaceInsets=").append(surfaceInsets);
2480                 if (hasManualSurfaceInsets) {
2481                     sb.append(" (manual)");
2482                 }
2483                 if (!preservePreviousSurfaceInsets) {
2484                     sb.append(" (!preservePreviousSurfaceInsets)");
2485                 }
2486             }
2487             if (needsMenuKey != NEEDS_MENU_UNSET) {
2488                 sb.append(" needsMenuKey=");
2489                 sb.append(needsMenuKey);
2490             }
2491             sb.append(" colorMode=").append(mColorMode);
2492             sb.append('}');
2493             return sb.toString();
2494         }
2495 
2496         /**
2497          * Scale the layout params' coordinates and size.
2498          * @hide
2499          */
scale(float scale)2500         public void scale(float scale) {
2501             x = (int) (x * scale + 0.5f);
2502             y = (int) (y * scale + 0.5f);
2503             if (width > 0) {
2504                 width = (int) (width * scale + 0.5f);
2505             }
2506             if (height > 0) {
2507                 height = (int) (height * scale + 0.5f);
2508             }
2509         }
2510 
2511         /**
2512          * Backup the layout parameters used in compatibility mode.
2513          * @see LayoutParams#restore()
2514          */
backup()2515         void backup() {
2516             int[] backup = mCompatibilityParamsBackup;
2517             if (backup == null) {
2518                 // we backup 4 elements, x, y, width, height
2519                 backup = mCompatibilityParamsBackup = new int[4];
2520             }
2521             backup[0] = x;
2522             backup[1] = y;
2523             backup[2] = width;
2524             backup[3] = height;
2525         }
2526 
2527         /**
2528          * Restore the layout params' coordinates, size and gravity
2529          * @see LayoutParams#backup()
2530          */
restore()2531         void restore() {
2532             int[] backup = mCompatibilityParamsBackup;
2533             if (backup != null) {
2534                 x = backup[0];
2535                 y = backup[1];
2536                 width = backup[2];
2537                 height = backup[3];
2538             }
2539         }
2540 
2541         private CharSequence mTitle = null;
2542 
2543         /** @hide */
2544         @Override
encodeProperties(@onNull ViewHierarchyEncoder encoder)2545         protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
2546             super.encodeProperties(encoder);
2547 
2548             encoder.addProperty("x", x);
2549             encoder.addProperty("y", y);
2550             encoder.addProperty("horizontalWeight", horizontalWeight);
2551             encoder.addProperty("verticalWeight", verticalWeight);
2552             encoder.addProperty("type", type);
2553             encoder.addProperty("flags", flags);
2554         }
2555     }
2556 }
2557