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