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