blob: 415357d6ceafb8d93f5ac16716600692a0cef7ec [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
2 * Copyright (C) 2012 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 com.android.server.wm;
18
Wale Ogunwale65ebd952018-04-25 15:41:44 -070019import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
Wale Ogunwale61911492017-10-11 08:50:50 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070021import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale44f036f2017-09-29 05:09:09 -070022import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070023import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
24import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
27import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale687b4272017-07-27 02:56:23 -070028import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
29import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070030import static android.view.Display.DEFAULT_DISPLAY;
31import static android.view.Display.FLAG_PRIVATE;
chaviwff2e7d82018-11-02 11:11:27 -070032import static android.view.InsetsState.TYPE_IME;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070033import static android.view.Surface.ROTATION_0;
34import static android.view.Surface.ROTATION_180;
35import static android.view.Surface.ROTATION_270;
36import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070037import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070038import static android.view.WindowManager.DOCKED_BOTTOM;
39import static android.view.WindowManager.DOCKED_INVALID;
40import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080041import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
43import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070044import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070045import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070046import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
47import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070048import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070051import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080052import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070053import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070054import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070055import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070057import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070058import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
59import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070060import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070061import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale3a256e62018-12-06 14:41:18 -080062import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080063import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
Wale Ogunwale3a256e62018-12-06 14:41:18 -080064import static android.view.WindowManager.TRANSIT_TASK_OPEN;
65import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Tiger Huang51c5a1d2018-12-11 20:24:51 +080066
Adrian Roose99bc052017-11-20 17:55:31 +010067import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
68import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
69import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
70import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080071import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS;
lumark588a3e82018-07-20 18:53:54 +080072import static com.android.server.wm.DisplayContentProto.APP_TRANSITION;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080073import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS;
74import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES;
75import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO;
76import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER;
77import static com.android.server.wm.DisplayContentProto.DPI;
Tiger Huang1e5b10a2018-07-30 20:19:51 +080078import static com.android.server.wm.DisplayContentProto.FOCUSED_APP;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080079import static com.android.server.wm.DisplayContentProto.ID;
80import static com.android.server.wm.DisplayContentProto.IME_WINDOWS;
81import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER;
82import static com.android.server.wm.DisplayContentProto.ROTATION;
83import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION;
84import static com.android.server.wm.DisplayContentProto.STACKS;
85import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
lumark588a3e82018-07-20 18:53:54 +080087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwale494009b82016-10-21 09:01:38 -070088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070096import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070097import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070098import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080099import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700101import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700102import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700103import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800104import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700105import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Tiger Huang51c5a1d2018-12-11 20:24:51 +0800106import static com.android.server.wm.WindowManagerService.H.REPORT_FOCUS_CHANGE;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800107import static com.android.server.wm.WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800108import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700109import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
110import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700111import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700112import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700113import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
114import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800115import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
116import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
117import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700118import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700119import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700120import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700121import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700122import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700123import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700124import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700125import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700126import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700127
lumark588a3e82018-07-20 18:53:54 +0800128import android.animation.AnimationHandler;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700129import android.annotation.CallSuper;
Riddle Hsuf53da812018-08-15 22:00:27 +0800130import android.annotation.IntDef;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700131import android.annotation.NonNull;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200132import android.annotation.Nullable;
Dean Harding3e5a1522017-10-06 09:19:01 -0700133import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700134import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700135import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700136import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700137import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800138import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700139import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700140import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100141import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700142import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700143import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700144import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700145import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700146import android.os.RemoteException;
147import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100148import android.os.Trace;
Riddle Hsuf53da812018-08-15 22:00:27 +0800149import android.os.UserHandle;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800150import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700151import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700152import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700153import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700154import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100155import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700156import android.view.DisplayInfo;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800157import android.view.Gravity;
Arthur Hungbe5ce212018-09-13 18:41:56 +0800158import android.view.InputChannel;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700159import android.view.InputDevice;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200160import android.view.InsetsState.InternalInsetType;
Robert Carrb1579c82017-09-05 14:54:47 -0700161import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700162import android.view.Surface;
163import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100164import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700165import android.view.SurfaceSession;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800166import android.view.View;
lumark588a3e82018-07-20 18:53:54 +0800167import android.view.WindowManager;
Evan Rosky39b6f232018-10-30 18:35:41 -0700168import android.view.WindowManagerPolicyConstants.PointerEventListener;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700169
Bryce Lee48f4b572017-04-10 10:54:15 -0700170import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800171import com.android.internal.util.ToBooleanFunction;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200172import com.android.internal.util.function.TriConsumer;
Adrian Roose99bc052017-11-20 17:55:31 +0100173import com.android.server.policy.WindowManagerPolicy;
Issei Suzuki43190bd2018-08-20 17:28:41 +0200174import com.android.server.wm.utils.DisplayRotationUtil;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100175import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100176import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700177
178import java.io.PrintWriter;
Riddle Hsuf53da812018-08-15 22:00:27 +0800179import java.lang.annotation.Retention;
180import java.lang.annotation.RetentionPolicy;
Craig Mautner59c00972012-07-30 12:10:24 -0700181import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700182import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700183import java.util.HashMap;
184import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700185import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700186import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100187import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800188import java.util.function.Consumer;
189import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700190
Craig Mautner59c00972012-07-30 12:10:24 -0700191/**
192 * Utility class for keeping track of the WindowStates and other pertinent contents of a
193 * particular Display.
Craig Mautner59c00972012-07-30 12:10:24 -0700194 */
Riddle Hsuad256a12018-07-18 16:11:30 +0800195class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
196 implements WindowManagerPolicy.DisplayContentInfo {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700197 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700198
Riddle Hsuf53da812018-08-15 22:00:27 +0800199 /** The default scaling mode that scales content automatically. */
200 static final int FORCE_SCALING_MODE_AUTO = 0;
201 /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */
202 static final int FORCE_SCALING_MODE_DISABLED = 1;
203
204 @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = {
205 FORCE_SCALING_MODE_AUTO,
206 FORCE_SCALING_MODE_DISABLED
207 })
208 @Retention(RetentionPolicy.SOURCE)
209 @interface ForceScalingMode {}
210
Craig Mautner59c00972012-07-30 12:10:24 -0700211 /** Unique identifier of this stack. */
212 private final int mDisplayId;
213
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800214 // TODO: Remove once unification is complete.
215 ActivityDisplay mAcitvityDisplay;
216
Wale Ogunwale3a931692016-11-02 16:49:48 -0700217 /** The containers below are the only child containers the display can have. */
218 // Contains all window containers that are related to apps (Activities)
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800219 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700220 // Contains all non-app window containers that should be displayed above the app containers
221 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800222 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800223 new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700224 // Contains all non-app window containers that should be displayed below the app containers
225 // (e.g. Wallpaper).
226 private final NonAppWindowContainers mBelowAppWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800227 new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700228 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
229 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
Robert Carr9034d962018-01-04 18:27:42 -0800230 // window containers together and move them in-sync if/when needed. We use a subclass of
231 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
232 private final NonMagnifiableWindowContainers mImeWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800233 new NonMagnifiableWindowContainers("mImeWindowsContainers", mWmService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700234
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000235 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800236 private WindowState mTmpWindow2;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800237 private boolean mTmpRecoveringMemory;
238 private boolean mUpdateImeTarget;
239 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700240 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700241
lumark588a3e82018-07-20 18:53:54 +0800242 final AppTransition mAppTransition;
243 final AppTransitionController mAppTransitionController;
244 boolean mSkipAppTransitionAnimation = false;
245
246 final ArraySet<AppWindowToken> mOpeningApps = new ArraySet<>();
247 final ArraySet<AppWindowToken> mClosingApps = new ArraySet<>();
248 final UnknownAppVisibilityController mUnknownAppVisibilityController;
249 BoundsAnimationController mBoundsAnimationController;
250
251 /**
252 * List of clients without a transtiton animation that we notify once we are done
253 * transitioning since they won't be notified through the app window animator.
254 */
255 final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>();
256
Wale Ogunwale02319a62016-09-26 15:21:22 -0700257 // Mapping from a token IBinder to a WindowToken object on this display.
258 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
259
Andrii Kuliancd097992017-03-23 18:31:59 -0700260 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700261 int mInitialDisplayWidth = 0;
262 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700263 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700264
Adrian Roos1cf585052018-01-03 18:43:27 +0100265 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100266 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100267 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100268
Andrii Kuliancd097992017-03-23 18:31:59 -0700269 /**
270 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
271 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
272 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
273 */
Craig Mautner59c00972012-07-30 12:10:24 -0700274 int mBaseDisplayWidth = 0;
275 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700276 /**
277 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
278 * but can be set from Settings or via shell command "adb shell wm density".
279 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
280 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700281 int mBaseDisplayDensity = 0;
Riddle Hsuf53da812018-08-15 22:00:27 +0800282
283 /**
284 * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling".
285 * @see WindowManagerService#setForcedDisplayScalingMode(int, int)
286 */
Jeff Brownd46747a2015-04-15 19:02:36 -0700287 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700288 private final DisplayInfo mDisplayInfo = new DisplayInfo();
289 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700290 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800291 private final DisplayPolicy mDisplayPolicy;
292 private DisplayRotation mDisplayRotation;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000293 DisplayFrames mDisplayFrames;
294
Andrii Kulian06d07d62017-03-14 11:11:47 -0700295 /**
296 * For default display it contains real metrics, empty for others.
297 * @see WindowManagerService#createWatermarkInTransaction()
298 */
299 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800300
301 /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */
Andrii Kulian06d07d62017-03-14 11:11:47 -0700302 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700303
Andrii Kulian06d07d62017-03-14 11:11:47 -0700304 /**
305 * Compat metrics computed based on {@link #mDisplayMetrics}.
306 * @see #updateDisplayAndOrientation(int)
307 */
308 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
309
310 /** The desired scaling factor for compatible apps. */
311 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700312
Andrii Kulian8ee72852017-03-10 10:36:45 -0800313 /**
314 * Current rotation of the display.
315 * Constants as per {@link android.view.Surface.Rotation}.
316 *
Robert Carrae606b42018-02-15 15:36:23 -0800317 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800318 */
319 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700320
Andrii Kulian8ee72852017-03-10 10:36:45 -0800321 /**
322 * Last applied orientation of the display.
323 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
324 *
Riddle Hsu4e611772018-10-31 18:58:28 +0800325 * @see #updateOrientationFromAppTokens()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800326 */
327 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700328
Andrii Kulian8ee72852017-03-10 10:36:45 -0800329 /**
330 * Flag indicating that the application is receiving an orientation that has different metrics
331 * than it expected. E.g. Portrait instead of Landscape.
332 *
Robert Carrae606b42018-02-15 15:36:23 -0800333 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800334 */
335 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700336
Andrii Kulian8ee72852017-03-10 10:36:45 -0800337 /**
338 * Orientation forced by some window. If there is no visible window that specifies orientation
339 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
340 *
341 * @see NonAppWindowContainers#getOrientation()
342 */
343 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700344
Andrii Kulian8ee72852017-03-10 10:36:45 -0800345 /**
346 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
347 * occluded.
348 *
349 * @see NonAppWindowContainers#getOrientation()
350 */
351 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
352
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700353 /**
354 * Keep track of wallpaper visibility to notify changes.
355 */
356 private boolean mLastWallpaperVisible = false;
357
Andrii Kulian06d07d62017-03-14 11:11:47 -0700358 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700359
Craig Mautner39834192012-09-02 07:47:24 -0700360 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700361 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700362 int pendingLayoutChanges;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800363 int mDeferredRotationPauseCount;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800364
Vishnu Nairba183352018-11-21 11:16:49 -0800365 /**
366 * Used to gate application window layout until we have sent the complete configuration.
367 * TODO: There are still scenarios where we may be out of sync with the client. Ideally
368 * we want to replace this flag with a mechanism that will confirm the configuration
369 * applied by the client is the one expected by the system server.
370 */
371 boolean mWaitingForConfig;
372
Andrii Kulian839def92016-11-02 10:58:58 -0700373 // TODO(multi-display): remove some of the usages.
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800374 @VisibleForTesting
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800375 boolean isDefaultDisplay;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800376
Andrii Kulianf0379de2018-03-14 16:24:07 -0700377 /**
378 * Flag indicating whether WindowManager should override info for this display in
379 * DisplayManager.
380 */
381 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700382
Craig Mautnerdc548482014-02-05 13:35:24 -0800383 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700384 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800385
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700386 /** Detect user tapping outside of current focused task bounds .*/
387 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700388
Craig Mautner6601b7b2013-04-29 10:29:11 -0700389 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700390 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700391
Craig Mautner6601b7b2013-04-29 10:29:11 -0700392 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800393 private final Rect mTmpRect = new Rect();
394 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700395 private final RectF mTmpRectF = new RectF();
396 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800397 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700398
Issei Suzuki43190bd2018-08-20 17:28:41 +0200399
Bryce Leef3c6a472017-11-14 14:53:06 -0800400 /** Used for handing back size of display */
401 private final Rect mTmpBounds = new Rect();
402
Craig Mautner95da1082014-02-24 17:54:35 -0800403 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700404 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800405
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700406 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700407 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700408
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800409 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800410 /** A collection of windows that provide tap exclude regions inside of them. */
411 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800412
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000413 private boolean mHaveBootMsg = false;
414 private boolean mHaveApp = false;
415 private boolean mHaveWallpaper = false;
416 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700417
418 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
419
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700420 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
421 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000422 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
423 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700424
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700425 // True if this display is in the process of being removed. Used to determine if the removal of
426 // the display's direct children should be allowed.
427 private boolean mRemovingDisplay = false;
428
Bryce Leed1871262017-06-12 14:12:29 -0700429 // {@code false} if this display is in the processing of being created.
430 private boolean mDisplayReady = false;
431
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800432 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700433
wilsonshihc32538e2018-11-07 17:27:34 +0800434 boolean mWallpaperMayChange = false;
435
Robert Carrb1579c82017-09-05 14:54:47 -0700436 private final SurfaceSession mSession = new SurfaceSession();
437
438 /**
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800439 * Window that is currently interacting with the user. This window is responsible for receiving
440 * key events and pointer events from the user.
441 */
442 WindowState mCurrentFocus = null;
443
444 /**
445 * The last focused window that we've notified the client that the focus is changed.
446 */
447 WindowState mLastFocus = null;
448
449 /**
450 * Windows that have lost input focus and are waiting for the new focus window to be displayed
451 * before they are told about this.
452 */
453 ArrayList<WindowState> mLosingFocus = new ArrayList<>();
454
455 /**
456 * The foreground app of this display. Windows below this app cannot be the focused window. If
457 * the user taps on the area outside of the task of the focused app, we will notify AM about the
458 * new task the user wants to interact with.
459 */
460 AppWindowToken mFocusedApp = null;
461
462 /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
463 final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>();
464
465 /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
466 final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>();
467
468 /**
Robert Carrb1579c82017-09-05 14:54:47 -0700469 * We organize all top-level Surfaces in to the following layers.
470 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800471 * and omitted from Screen-Magnification, for example the strict mode flash or
472 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700473 * {@link #mWindowingLayer} contains everything else.
474 */
475 private SurfaceControl mOverlayLayer;
476
477 /**
478 * See {@link #mOverlayLayer}
479 */
480 private SurfaceControl mWindowingLayer;
481
482 /**
Adrian Roos5251b1d2018-03-23 18:57:43 +0100483 * Sequence number for the current layout pass.
484 */
485 int mLayoutSeq = 0;
486
Chavi Weingarten3a748552018-05-14 17:32:42 +0000487 /**
488 * Specifies the count to determine whether to defer updating the IME target until ready.
489 */
490 private int mDeferUpdateImeTargetCount;
491
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100492 /** Temporary float array to retrieve 3x3 matrix values. */
493 private final float[] mTmpFloats = new float[9];
494
Robert Carr24be9ab2018-04-30 17:54:53 -0700495 private MagnificationSpec mMagnificationSpec;
496
Arthur Hung95b38a92018-07-20 18:56:12 +0800497 private InputMonitor mInputMonitor;
498
Jorim Jaggif1292892018-09-10 11:58:13 +0200499 /** Caches the value whether told display manager that we have content. */
500 private boolean mLastHasContent;
501
Issei Suzuki43190bd2018-08-20 17:28:41 +0200502 private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil();
503
lumark90120a82018-08-15 00:33:03 +0800504 /**
505 * The input method window for this display.
506 */
507 WindowState mInputMethodWindow;
508
lumarkff0ab692018-11-05 20:32:30 +0800509 /**
510 * This just indicates the window the input method is on top of, not
511 * necessarily the window its input is going to.
512 */
513 WindowState mInputMethodTarget;
514
515 /** If true hold off on modifying the animation layer of mInputMethodTarget */
516 boolean mInputMethodTargetWaitingAnim;
517
Arthur Hungbe5ce212018-09-13 18:41:56 +0800518 private final PointerEventDispatcher mPointerEventDispatcher;
519
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200520 private final InsetsStateController mInsetsStateController;
521
Tiger Huang7c610aa2018-10-27 00:01:01 +0800522 // Last systemUiVisibility we received from status bar.
523 private int mLastStatusBarVisibility = 0;
524 // Last systemUiVisibility we dispatched to windows.
525 private int mLastDispatchedSystemUiVisibility = 0;
526
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800527 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
528 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800529 final AppWindowToken atoken = w.mAppToken;
530 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200531 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800532 if (w.performShowLocked()) {
533 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
534 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800535 mWmService.mWindowPlacerLocked.debugLayoutRepeats(
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800536 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
537 }
538 }
539 }
540 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800541 };
542
543 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
544 final WindowStateAnimator winAnimator = w.mWinAnimator;
545 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
546 return;
547 }
548
Jorim Jaggi8f520872018-08-14 17:00:20 +0200549 // If this window is animating, ensure the animation background is set.
550 final AnimationAdapter anim = w.mAppToken != null
551 ? w.mAppToken.getAnimation()
552 : w.getAnimation();
553 if (anim != null) {
554 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800555 if (color != 0) {
556 final TaskStack stack = w.getStack();
557 if (stack != null) {
558 stack.setAnimationBackground(winAnimator, color);
559 }
560 }
561 }
562 };
563
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800564 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
565 final int lostFocusUid = mTmpWindow.mOwnerUid;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800566 final Handler handler = mWmService.mH;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800567 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
568 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
569 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
570 w.mAttrs.hideTimeoutMilliseconds);
571 }
572 }
573 };
574
575 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800576 final AppWindowToken focusedApp = mFocusedApp;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800577 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
578 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
579
580 if (!w.canReceiveKeys()) {
581 return false;
582 }
583
584 final AppWindowToken wtoken = w.mAppToken;
585
586 // If this window's application has been removed, just skip it.
587 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
588 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
589 + (wtoken.removed ? "removed" : "sendingToBottom"));
590 return false;
591 }
592
593 if (focusedApp == null) {
594 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
595 + " using new focus @ " + w);
596 mTmpWindow = w;
597 return true;
598 }
599
600 if (!focusedApp.windowsAreFocusable()) {
601 // Current focused app windows aren't focusable...
602 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
603 + " focusable using new focus @ " + w);
604 mTmpWindow = w;
605 return true;
606 }
607
608 // Descend through all of the app tokens and find the first that either matches
609 // win.mAppToken (return win) or mFocusedApp (return null).
610 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
611 if (focusedApp.compareTo(wtoken) > 0) {
612 // App stack below focused app stack. No focus for you!!!
613 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
614 "findFocusedWindow: Reached focused app=" + focusedApp);
615 mTmpWindow = null;
616 return true;
617 }
618 }
619
620 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
621 mTmpWindow = w;
622 return true;
623 };
624
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800625 private final Consumer<WindowState> mPerformLayout = w -> {
626 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
627 // wasting time and funky changes while a window is animating away.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800628 final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w))
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800629 || w.isGoneForLayoutLw();
630
631 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
632 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
633 + " mLayoutAttached=" + w.mLayoutAttached
634 + " screen changed=" + w.isConfigChanged());
635 final AppWindowToken atoken = w.mAppToken;
636 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200637 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800638 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
639 + " parentHidden=" + w.isParentWindowHidden());
640 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200641 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800642 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
643 + " parentHidden=" + w.isParentWindowHidden());
644 }
645
646 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
647 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
648 // since that means "perform layout as normal, just don't display").
649 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
650 || ((w.isConfigChanged() || w.setReportResizeHints())
651 && !w.isGoneForLayoutLw() &&
652 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
653 (w.mHasSurface && w.mAppToken != null &&
654 w.mAppToken.layoutConfigChanges)))) {
655 if (!w.mLayoutAttached) {
656 if (mTmpInitial) {
657 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700658 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800659 }
660 if (w.mAttrs.type == TYPE_DREAM) {
661 // Don't layout windows behind a dream, so that if it does stuff like hide
662 // the status bar we won't get a bad transition when it goes away.
663 mTmpWindow = w;
664 }
665 w.mLayoutNeeded = false;
666 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200667 final boolean firstLayout = !w.isLaidOut();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800668 getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100669 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800670
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200671 // If this is the first layout, we need to initialize the last inset values as
672 // otherwise we'd immediately cause an unnecessary resize.
673 if (firstLayout) {
674 w.updateLastInsetValues();
675 }
676
Adrian Roos23df3a32018-03-15 15:41:13 +0100677 if (w.mAppToken != null) {
678 w.mAppToken.layoutLetterbox(w);
679 }
680
chaviw492139a2018-07-16 16:07:35 -0700681 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700682 + " mContainingFrame=" + w.getContainingFrame()
683 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800684 }
685 }
686 };
687
688 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
689 if (w.mLayoutAttached) {
690 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
691 + " mViewVisibility=" + w.mViewVisibility
692 + " mRelayoutCalled=" + w.mRelayoutCalled);
693 // If this view is GONE, then skip it -- keep the current frame, and let the caller
694 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
695 // windows, since that means "perform layout as normal, just don't display").
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800696 if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800697 return;
698 }
699 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
700 || w.mLayoutNeeded) {
701 if (mTmpInitial) {
702 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700703 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800704 }
705 w.mLayoutNeeded = false;
706 w.prelayout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800707 getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100708 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700709 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700710 + " mContainingFrame=" + w.getContainingFrame()
711 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800712 }
713 } else if (w.mAttrs.type == TYPE_DREAM) {
714 // Don't layout windows behind a dream, so that if it does stuff like hide the
715 // status bar we won't get a bad transition when it goes away.
716 mTmpWindow = mTmpWindow2;
717 }
718 };
719
720 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
721 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
722 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
723 return w.canBeImeTarget();
724 };
725
726 private final Consumer<WindowState> mApplyPostLayoutPolicy =
Tiger Huang7c610aa2018-10-27 00:01:01 +0800727 w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
lumarkff0ab692018-11-05 20:32:30 +0800728 mInputMethodTarget);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800729
730 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800731 final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800732 final boolean obscuredChanged = w.mObscured !=
733 mTmpApplySurfaceChangesTransactionState.obscured;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800734 final RootWindowContainer root = mWmService.mRoot;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800735
736 // Update effect.
737 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
738 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
739 final boolean isDisplayed = w.isDisplayedLw();
740
741 if (isDisplayed && w.isObscuringDisplay()) {
742 // This window completely covers everything behind it, so we want to leave all
743 // of them as undimmed (for performance reasons).
744 root.mObscuringWindow = w;
745 mTmpApplySurfaceChangesTransactionState.obscured = true;
746 }
747
748 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
749 root.handleNotObscuredLocked(w,
750 mTmpApplySurfaceChangesTransactionState.obscured,
751 mTmpApplySurfaceChangesTransactionState.syswin);
752
753 if (w.mHasSurface && isDisplayed) {
754 final int type = w.mAttrs.type;
755 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
756 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
757 mTmpApplySurfaceChangesTransactionState.syswin = true;
758 }
759 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
760 && w.mAttrs.preferredRefreshRate != 0) {
761 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
762 = w.mAttrs.preferredRefreshRate;
763 }
764 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
765 && w.mAttrs.preferredDisplayModeId != 0) {
766 mTmpApplySurfaceChangesTransactionState.preferredModeId
767 = w.mAttrs.preferredDisplayModeId;
768 }
769 }
770 }
771
wilsonshihc32538e2018-11-07 17:27:34 +0800772 if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800773 // This is the wallpaper target and its obscured state changed... make sure the
774 // current wallpaper's visibility has been updated accordingly.
775 mWallpaperController.updateWallpaperVisibility();
776 }
777
chaviw161ea3e2018-01-31 12:01:12 -0800778 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800779
780 final WindowStateAnimator winAnimator = w.mWinAnimator;
781
782 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
chaviw1454b392018-08-06 09:54:04 -0700783 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800784
785 // Moved from updateWindowsAndWallpaperLocked().
786 if (w.mHasSurface) {
787 // Take care of the window being ready to display.
788 final boolean committed = winAnimator.commitFinishDrawingLocked();
789 if (isDefaultDisplay && committed) {
790 if (w.mAttrs.type == TYPE_DREAM) {
791 // HACK: When a dream is shown, it may at that point hide the lock screen.
792 // So we need to redo the layout to let the phone window manager make this
793 // happen.
794 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
795 if (DEBUG_LAYOUT_REPEATS) {
796 surfacePlacer.debugLayoutRepeats(
797 "dream and commitFinishDrawingLocked true",
798 pendingLayoutChanges);
799 }
800 }
801 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
802 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
803 "First draw done in potential wallpaper target " + w);
wilsonshihc32538e2018-11-07 17:27:34 +0800804 mWallpaperMayChange = true;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800805 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
806 if (DEBUG_LAYOUT_REPEATS) {
807 surfacePlacer.debugLayoutRepeats(
808 "wallpaper and commitFinishDrawingLocked true",
809 pendingLayoutChanges);
810 }
811 }
812 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800813 }
814
815 final AppWindowToken atoken = w.mAppToken;
816 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100817 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800818 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
819 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
820 mTmpUpdateAllDrawn.add(atoken);
821 }
822 }
823
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800824 if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800825 mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800826 }
827
828 w.updateResizingWindowIfNeeded();
829 };
830
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800831 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800832 * Create new {@link DisplayContent} instance, add itself to the root window container and
833 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700834 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800835 * @param service You know.
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800836 * @param activityDisplay The ActivityDisplay for the display container.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700837 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700838 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800839 ActivityDisplay activityDisplay) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100840 super(service);
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800841 mAcitvityDisplay = activityDisplay;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800842 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
843 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
844 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
845 + " new=" + display);
846 }
847
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700848 mDisplay = display;
849 mDisplayId = display.getDisplayId();
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800850 mWallpaperController = new WallpaperController(mWmService, this);
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700851 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700852 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700853 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100854 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
855 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700856 initializeDisplayBaseInfo();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700857
lumark588a3e82018-07-20 18:53:54 +0800858 mAppTransition = new AppTransition(service.mContext, service, this);
859 mAppTransition.registerListenerLocked(service.mActivityManagerAppTransitionNotifier);
860 mAppTransitionController = new AppTransitionController(service, this);
861 mUnknownAppVisibilityController = new UnknownAppVisibilityController(service, this);
862
863 AnimationHandler animationHandler = new AnimationHandler();
864 mBoundsAnimationController = new BoundsAnimationController(service.mContext,
865 mAppTransition, SurfaceAnimationThread.getHandler(), animationHandler);
866
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800867 if (mWmService.mInputManager != null) {
868 final InputChannel inputChannel = mWmService.mInputManager.monitorInput("Display "
Tiger Huang7c610aa2018-10-27 00:01:01 +0800869 + mDisplayId, mDisplayId);
870 mPointerEventDispatcher = inputChannel != null
871 ? new PointerEventDispatcher(inputChannel) : null;
872 } else {
873 mPointerEventDispatcher = null;
874 }
875 mDisplayPolicy = new DisplayPolicy(service, this);
876 mDisplayRotation = new DisplayRotation(service, this);
877 if (isDefaultDisplay) {
878 // The policy may be invoked right after here, so it requires the necessary default
879 // fields of this display content.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800880 mWmService.mPolicy.setDefaultDisplay(this);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800881 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800882 if (mWmService.mDisplayReady) {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800883 mDisplayPolicy.onConfigurationChanged();
884 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800885 if (mWmService.mSystemReady) {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800886 mDisplayPolicy.systemReady();
887 }
888 mDividerControllerLocked = new DockedStackDividerController(service, this);
889 mPinnedStackControllerLocked = new PinnedStackController(service, this);
890
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800891 final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(mSession).setOpaque(true);
Robert Carrb1579c82017-09-05 14:54:47 -0700892 mWindowingLayer = b.setName("Display Root").build();
893 mOverlayLayer = b.setName("Display Overlays").build();
894
Robert Carrf59b8dd2017-10-02 18:58:36 -0700895 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700896 .setLayerStack(mWindowingLayer, mDisplayId)
897 .show(mWindowingLayer)
898 .setLayer(mOverlayLayer, 1)
899 .setLayerStack(mOverlayLayer, mDisplayId)
900 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700901 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700902
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700903 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700904 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700905 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700906 super.addChild(mAboveAppWindowsContainers, null);
907 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800908
909 // Add itself as a child to the root container.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800910 mWmService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700911
912 // TODO(b/62541591): evaluate whether this is the best spot to declare the
913 // {@link DisplayContent} ready for use.
914 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800915
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800916 mWmService.mAnimator.addDisplayLocked(mDisplayId);
Arthur Hung39134b22018-08-14 11:58:28 +0800917 mInputMonitor = new InputMonitor(service, mDisplayId);
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200918 mInsetsStateController = new InsetsStateController(this);
Bryce Leed1871262017-06-12 14:12:29 -0700919 }
920
921 boolean isReady() {
922 // The display is ready when the system and the individual display are both ready.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800923 return mWmService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700924 }
925
926 int getDisplayId() {
927 return mDisplayId;
928 }
929
Wale Ogunwale02319a62016-09-26 15:21:22 -0700930 WindowToken getWindowToken(IBinder binder) {
931 return mTokenMap.get(binder);
932 }
933
934 AppWindowToken getAppWindowToken(IBinder binder) {
935 final WindowToken token = getWindowToken(binder);
936 if (token == null) {
937 return null;
938 }
939 return token.asAppWindowToken();
940 }
941
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700942 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800943 final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700944 if (dc != null) {
945 // We currently don't support adding a window token to the display if the display
946 // already has the binder mapped to another token. If there is a use case for supporting
947 // this moving forward we will either need to merge the WindowTokens some how or have
948 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700949 throw new IllegalArgumentException("Can't map token=" + token + " to display="
950 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700951 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700952 if (binder == null) {
953 throw new IllegalArgumentException("Can't map token=" + token + " to display="
954 + getName() + " binder is null");
955 }
956 if (token == null) {
957 throw new IllegalArgumentException("Can't map null token to display="
958 + getName() + " binder=" + binder);
959 }
960
Wale Ogunwale02319a62016-09-26 15:21:22 -0700961 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700962
963 if (token.asAppWindowToken() == null) {
964 // Add non-app token to container hierarchy on the display. App tokens are added through
965 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700966 switch (token.windowType) {
967 case TYPE_WALLPAPER:
968 mBelowAppWindowsContainers.addChild(token);
969 break;
970 case TYPE_INPUT_METHOD:
971 case TYPE_INPUT_METHOD_DIALOG:
972 mImeWindowsContainers.addChild(token);
973 break;
974 default:
975 mAboveAppWindowsContainers.addChild(token);
976 break;
977 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700978 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700979 }
980
981 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700982 final WindowToken token = mTokenMap.remove(binder);
983 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800984 token.setExiting();
985 }
986 return token;
987 }
988
989 /** Changes the display the input window token is housed on to this one. */
990 void reParentWindowToken(WindowToken token) {
991 final DisplayContent prevDc = token.getDisplayContent();
992 if (prevDc == this) {
993 return;
994 }
Riddle Hsu85bd04b2018-11-17 00:34:36 +0800995 if (prevDc != null) {
996 if (prevDc.mTokenMap.remove(token.token) != null && token.asAppWindowToken() == null) {
997 // Removed the token from the map, but made sure it's not an app token before
998 // removing from parent.
999 token.getParent().removeChild(token);
1000 }
1001 if (prevDc.mLastFocus == mCurrentFocus) {
1002 // The window has become the focus of this display, so it should not be notified
1003 // that it lost focus from the previous display.
1004 prevDc.mLastFocus = null;
1005 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001006 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -08001007
1008 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -07001009 }
1010
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001011 void removeAppToken(IBinder binder) {
1012 final WindowToken token = removeWindowToken(binder);
1013 if (token == null) {
1014 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
1015 return;
1016 }
1017
1018 final AppWindowToken appToken = token.asAppWindowToken();
1019
1020 if (appToken == null) {
1021 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
1022 return;
1023 }
1024
1025 appToken.onRemovedFromDisplay();
1026 }
1027
Riddle Hsuad256a12018-07-18 16:11:30 +08001028 @Override
1029 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -07001030 return mDisplay;
1031 }
1032
Craig Mautner59c00972012-07-30 12:10:24 -07001033 DisplayInfo getDisplayInfo() {
1034 return mDisplayInfo;
1035 }
1036
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001037 DisplayMetrics getDisplayMetrics() {
1038 return mDisplayMetrics;
1039 }
1040
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001041 DisplayPolicy getDisplayPolicy() {
1042 return mDisplayPolicy;
1043 }
1044
Riddle Hsuad256a12018-07-18 16:11:30 +08001045 @Override
1046 public DisplayRotation getDisplayRotation() {
1047 return mDisplayRotation;
1048 }
1049
Jorim Jaggif96c90a2018-09-26 16:55:15 +02001050 /**
1051 * Marks a window as providing insets for the rest of the windows in the system.
1052 *
1053 * @param type The type of inset this window provides.
1054 * @param win The window.
1055 * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of
1056 * the window should be taken.
1057 */
1058 void setInsetProvider(@InternalInsetType int type, WindowState win,
1059 @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider) {
1060 mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider);
1061 }
1062
1063 InsetsStateController getInsetsStateController() {
1064 return mInsetsStateController;
1065 }
1066
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001067 @VisibleForTesting
1068 void setDisplayRotation(DisplayRotation displayRotation) {
1069 mDisplayRotation = displayRotation;
1070 }
1071
Andrii Kulian8ee72852017-03-10 10:36:45 -08001072 int getRotation() {
1073 return mRotation;
1074 }
1075
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001076 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -08001077 void setRotation(int newRotation) {
1078 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +08001079 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001080 }
1081
1082 int getLastOrientation() {
1083 return mLastOrientation;
1084 }
1085
Andrii Kulian8ee72852017-03-10 10:36:45 -08001086 boolean getAltOrientation() {
1087 return mAltOrientation;
1088 }
1089
Andrii Kulian8ee72852017-03-10 10:36:45 -08001090 int getLastWindowForcedOrientation() {
1091 return mLastWindowForcedOrientation;
1092 }
1093
Andrii Kulian06d07d62017-03-14 11:11:47 -07001094 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +08001095 * Temporarily pauses rotation changes until resumed.
1096 *
1097 * This can be used to prevent rotation changes from occurring while the user is
1098 * performing certain operations, such as drag and drop.
1099 *
1100 * This call nests and must be matched by an equal number of calls to
1101 * {@link #resumeRotationLocked}.
1102 */
1103 void pauseRotationLocked() {
1104 mDeferredRotationPauseCount++;
1105 }
1106
1107 /**
1108 * Resumes normal rotation changes after being paused.
1109 */
1110 void resumeRotationLocked() {
1111 if (mDeferredRotationPauseCount <= 0) {
1112 return;
1113 }
1114
1115 mDeferredRotationPauseCount--;
1116 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001117 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001118 }
1119 }
1120
1121 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001122 * If this is true we have updated our desired orientation, but not yet changed the real
1123 * orientation our applied our screen rotation animation. For example, because a previous
1124 * screen rotation was in progress.
1125 *
1126 * @return {@code true} if the there is an ongoing rotation change.
1127 */
1128 boolean rotationNeedsUpdate() {
1129 final int lastOrientation = getLastOrientation();
1130 final int oldRotation = getRotation();
1131 final boolean oldAltOrientation = getAltOrientation();
1132
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001133 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001134 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1135 lastOrientation, rotation);
1136 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1137 return false;
1138 }
1139 return true;
1140 }
1141
Wale Ogunwale3a256e62018-12-06 14:41:18 -08001142 /**
1143 * The display content may have configuration set from {@link #DisplayWindowSettings}. This
1144 * callback let the owner of container know there is existing configuration to prevent the
1145 * values from being replaced by the initializing {@link #ActivityDisplay}.
1146 */
1147 void initializeDisplayOverrideConfiguration() {
1148 if (mAcitvityDisplay != null) {
1149 mAcitvityDisplay.onInitializeOverrideConfiguration(getRequestedOverrideConfiguration());
1150 }
1151 }
1152
Riddle Hsu4e611772018-10-31 18:58:28 +08001153 /** Notify the configuration change of this display. */
1154 void sendNewConfiguration() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001155 mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget();
Riddle Hsu4e611772018-10-31 18:58:28 +08001156 }
1157
1158 /**
1159 * Determine the new desired orientation of this display.
1160 *
1161 * The orientation is computed from non-application windows first. If none of the
1162 * non-application windows specify orientation, the orientation is computed from application
1163 * tokens.
1164 *
1165 * @return {@code true} if the orientation is changed.
1166 */
1167 boolean updateOrientationFromAppTokens() {
1168 return updateOrientationFromAppTokens(false /* forceUpdate */);
1169 }
1170
1171 boolean updateOrientationFromAppTokens(boolean forceUpdate) {
1172 final int req = getOrientation();
1173 if (req != mLastOrientation || forceUpdate) {
1174 mLastOrientation = req;
1175 mDisplayRotation.setCurrentOrientation(req);
1176 return updateRotationUnchecked(forceUpdate);
1177 }
1178 return false;
1179 }
1180
Riddle Hsuad256a12018-07-18 16:11:30 +08001181 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001182 * Update rotation of the display and send configuration if the rotation is changed.
1183 *
1184 * @return {@code true} if the rotation has been changed and the new config is sent.
1185 */
1186 boolean updateRotationAndSendNewConfigIfNeeded() {
1187 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1188 if (changed) {
Riddle Hsu4e611772018-10-31 18:58:28 +08001189 sendNewConfiguration();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001190 }
1191 return changed;
1192 }
1193
1194 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001195 * Update rotation of the display.
1196 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001197 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1198 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001199 */
Robert Carrae606b42018-02-15 15:36:23 -08001200 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001201 return updateRotationUnchecked(false /* forceUpdate */);
1202 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001203
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001204 /**
Evan Roskye747c3e2018-10-30 20:06:41 -07001205 * Update rotation of the DisplayContent with an option to force the update. This updates
1206 * the container's perception of rotation and, depending on the top activities, will freeze
1207 * the screen or start seamless rotation. The display itself gets rotated in
1208 * {@link #applyRotationLocked} during {@link WindowManagerService#sendNewConfiguration}.
1209 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001210 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1211 * orientation because we're waiting for some rotation to finish or display
1212 * to unfreeze, which results in configuration of the previously visible
1213 * activity being applied to a newly visible one. Forcing the rotation
1214 * update allows to workaround this issue.
1215 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
Evan Roskye747c3e2018-10-30 20:06:41 -07001216 * {@link WindowManagerService#sendNewConfiguration(int)} TO COMPLETE THE ROTATION AND
1217 * UNFREEZE THE SCREEN.
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001218 */
1219 boolean updateRotationUnchecked(boolean forceUpdate) {
1220 ScreenRotationAnimation screenRotationAnimation;
1221 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001222 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001223 // Rotation updates have been paused temporarily. Defer the update until
1224 // updates have been resumed.
1225 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1226 return false;
1227 }
1228
1229 screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001230 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001231 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1232 // Rotation updates cannot be performed while the previous rotation change
1233 // animation is still in progress. Skip this update. We will try updating
1234 // again after the animation is finished and the display is unfrozen.
1235 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1236 return false;
1237 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001238 if (mWmService.mDisplayFrozen) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001239 // Even if the screen rotation animation has finished (e.g. isAnimating
1240 // returns false), there is still some time where we haven't yet unfrozen
1241 // the display. We also need to abort rotation here.
1242 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1243 "Deferring rotation, still finishing previous rotation");
1244 return false;
1245 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001246 }
1247
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001248 if (!mWmService.mDisplayEnabled) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001249 // No point choosing a rotation if the display is not enabled.
1250 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1251 return false;
1252 }
1253
1254 final int oldRotation = mRotation;
1255 final int lastOrientation = mLastOrientation;
1256 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001257 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001258 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1259 + mDisplayId + " based on lastOrientation=" + lastOrientation
1260 + " and oldRotation=" + oldRotation);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001261 boolean mayRotateSeamlessly = mDisplayPolicy.shouldRotateSeamlessly(mDisplayRotation,
Riddle Hsuad256a12018-07-18 16:11:30 +08001262 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001263
Robert Carr0e007272017-10-02 13:00:55 -07001264 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001265 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001266 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001267 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1268 // to complete (that is, waiting for windows to redraw). It's tempting to check
1269 // w.mSeamlessRotationCount but that could be incorrect in the case of
1270 // window-removal.
1271 return false;
1272 }
Robert Carr0e007272017-10-02 13:00:55 -07001273
1274 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001275 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001276 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001277 mayRotateSeamlessly = false;
1278 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001279 for (int i = 0; i < mWmService.mSessions.size(); i++) {
1280 if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
Robert Carr0e007272017-10-02 13:00:55 -07001281 mayRotateSeamlessly = false;
1282 break;
1283 }
1284 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001285 }
Robert Carr0e007272017-10-02 13:00:55 -07001286 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001287
1288 // TODO: Implement forced rotation changes.
1289 // Set mAltOrientation to indicate that the application is receiving
1290 // an orientation that has different metrics than it expected.
1291 // eg. Portrait instead of Landscape.
1292
Riddle Hsuad256a12018-07-18 16:11:30 +08001293 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001294 lastOrientation, rotation);
1295
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001296 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1297 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001298 + ", got rotation " + rotation + " which has "
1299 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1300
1301 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1302 // No change.
1303 return false;
1304 }
1305
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001306 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1307 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001308 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1309 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1310
1311 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
Vishnu Nairba183352018-11-21 11:16:49 -08001312 mWaitingForConfig = true;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001313 }
1314
Evan Roskye747c3e2018-10-30 20:06:41 -07001315 mRotation = rotation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001316 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001317
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001318 mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1319 mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
Riddle Hsu654a6f92018-07-13 22:59:36 +08001320 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001321
1322 setLayoutNeeded();
1323 final int[] anim = new int[2];
Tiger Huang7c610aa2018-10-27 00:01:01 +08001324 mDisplayPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001325
1326 if (!rotateSeamlessly) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001327 mWmService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001328 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001329 } else {
1330 // The screen rotation animation uses a screenshot to freeze the screen
1331 // while windows resize underneath.
1332 // When we are rotating seamlessly, we allow the elements to transition
1333 // to their rotated state independently and without a freeze required.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001334 mWmService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001335 }
1336
Evan Roskye747c3e2018-10-30 20:06:41 -07001337 return true;
1338 }
1339
1340 /**
1341 * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked}
1342 * (if it returned {@code true}) to actually finish the rotation.
1343 *
1344 * @param oldRotation the rotation we are coming from.
1345 * @param rotation the rotation to apply.
1346 */
1347 void applyRotationLocked(final int oldRotation, final int rotation) {
1348 mDisplayRotation.setRotation(rotation);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001349 final boolean rotateSeamlessly = mWmService.isRotatingSeamlessly();
Evan Roskye747c3e2018-10-30 20:06:41 -07001350 ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001351 ? null : mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001352 // We need to update our screen size information to match the new rotation. If the rotation
1353 // has actually changed then this method will return true and, according to the comment at
1354 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1355 // By updating the Display info here it will be available to
1356 // #computeScreenConfiguration() later.
1357 updateDisplayAndOrientation(getConfiguration().uiMode);
1358
Robert Carrae606b42018-02-15 15:36:23 -08001359 // NOTE: We disable the rotation in the emulator because
1360 // it doesn't support hardware OpenGL emulation yet.
1361 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1362 && screenRotationAnimation.hasScreenshot()) {
1363 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001364 MAX_ANIMATION_DURATION, mWmService.getTransitionAnimationScaleLocked(),
Robert Carrae606b42018-02-15 15:36:23 -08001365 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001366 mWmService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001367 }
1368 }
1369
Vishnu Nair83537a72018-07-19 21:27:48 -07001370 forAllWindows(w -> {
Vishnu Nairddd80742018-08-21 14:12:46 -07001371 w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation,
1372 rotateSeamlessly);
Vishnu Nair83537a72018-07-19 21:27:48 -07001373 }, true /* traverseTopToBottom */);
1374
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001375 mWmService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
Robert Carrae606b42018-02-15 15:36:23 -08001376 scheduleAnimation();
1377
Andrii Kulian06d07d62017-03-14 11:11:47 -07001378 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001379 if (w.mHasSurface && !rotateSeamlessly) {
1380 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001381 w.setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001382 mWmService.mRoot.mOrientationChangeComplete = false;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001383 w.mLastFreezeDuration = 0;
1384 }
1385 w.mReportOrientationChanged = true;
1386 }, true /* traverseTopToBottom */);
1387
1388 if (rotateSeamlessly) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001389 mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
Riddle Hsu654a6f92018-07-13 22:59:36 +08001390 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001391 }
1392
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001393 for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001394 final WindowManagerService.RotationWatcher rotationWatcher
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001395 = mWmService.mRotationWatchers.get(i);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001396 if (rotationWatcher.mDisplayId == mDisplayId) {
1397 try {
1398 rotationWatcher.mWatcher.onRotationChanged(rotation);
1399 } catch (RemoteException e) {
1400 // Ignore
1401 }
1402 }
1403 }
1404
1405 // TODO (multi-display): Magnification is supported only for the default display.
1406 // Announce rotation only if we will not animate as we already have the
1407 // windows in final state. Otherwise, we make this call at the rotation end.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001408 if (screenRotationAnimation == null && mWmService.mAccessibilityController != null
Andrii Kulian06d07d62017-03-14 11:11:47 -07001409 && isDefaultDisplay) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001410 mWmService.mAccessibilityController.onRotationChangedLocked(this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001411 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001412 }
1413
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001414 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001415 final int width = mBaseDisplayWidth;
1416 final int height = mBaseDisplayHeight;
1417 final int shortSize;
1418 final int longSize;
1419 if (width > height) {
1420 shortSize = height;
1421 longSize = width;
1422 } else {
1423 shortSize = width;
1424 longSize = height;
1425 }
1426
1427 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1428 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1429
1430 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1431 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001432
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001433 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1434 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Arthur Hungbe5ce212018-09-13 18:41:56 +08001435
1436 // Tap Listeners are supported for:
1437 // 1. All physical displays (multi-display).
1438 // 2. VirtualDisplays on VR, AA (and everything else).
1439 if (mPointerEventDispatcher != null && mTapDetector == null) {
1440 if (DEBUG_DISPLAY) {
1441 Slog.d(TAG,
1442 "Registering PointerEventListener for DisplayId: " + mDisplayId);
1443 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001444 mTapDetector = new TaskTapPointerEventListener(mWmService, this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08001445 registerPointerEventListener(mTapDetector);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001446 registerPointerEventListener(mWmService.mMousePositionTracker);
Arthur Hungbe5ce212018-09-13 18:41:56 +08001447 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001448 }
1449
Andrii Kulian06d07d62017-03-14 11:11:47 -07001450 /**
1451 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1452 * changed.
1453 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1454 */
1455 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1456 // Use the effective "visual" dimensions based on current rotation
1457 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1458 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1459 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1460 int dw = realdw;
1461 int dh = realdh;
1462
1463 if (mAltOrientation) {
1464 if (realdw > realdh) {
1465 // Turn landscape into portrait.
1466 int maxw = (int)(realdh/1.3f);
1467 if (maxw < realdw) {
1468 dw = maxw;
1469 }
1470 } else {
1471 // Turn portrait into landscape.
1472 int maxh = (int)(realdw/1.3f);
1473 if (maxh < realdh) {
1474 dh = maxh;
1475 }
1476 }
1477 }
1478
1479 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001480 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1481 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1482
Tiger Huang7c610aa2018-10-27 00:01:01 +08001483 final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
1484 displayCutout);
1485 final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
1486 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001487 mDisplayInfo.rotation = mRotation;
1488 mDisplayInfo.logicalWidth = dw;
1489 mDisplayInfo.logicalHeight = dh;
1490 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1491 mDisplayInfo.appWidth = appWidth;
1492 mDisplayInfo.appHeight = appHeight;
1493 if (isDefaultDisplay) {
1494 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1495 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1496 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001497 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001498 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1499 if (mDisplayScalingDisabled) {
1500 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1501 } else {
1502 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1503 }
1504
Andrii Kulianf0379de2018-03-14 16:24:07 -07001505 // We usually set the override info in DisplayManager so that we get consistent display
1506 // metrics values when displays are changing and don't send out new values until WM is aware
1507 // of them. However, we don't do this for displays that serve as containers for ActivityView
1508 // because we don't want letter-/pillar-boxing during resize.
1509 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1510 ? mDisplayInfo : null;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001511 mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001512 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001513
1514 mBaseDisplayRect.set(0, 0, dw, dh);
1515
1516 if (isDefaultDisplay) {
1517 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1518 mCompatDisplayMetrics);
1519 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001520
Andrii Kulian06d07d62017-03-14 11:11:47 -07001521 return mDisplayInfo;
1522 }
1523
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001524 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001525 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1526 }
1527
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001528 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001529 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001530 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001531 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001532 }
Adrian Roos11c25582018-02-19 18:06:36 +01001533 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001534 return WmDisplayCutout.computeSafeInsets(
1535 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001536 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001537 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Issei Suzuki43190bd2018-08-20 17:28:41 +02001538 final Rect[] newBounds = mRotationUtil.getRotatedBounds(
1539 WmDisplayCutout.computeSafeInsets(
Jorim Jaggi60640512018-06-29 01:14:31 +02001540 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
Issei Suzuki43190bd2018-08-20 17:28:41 +02001541 .getDisplayCutout().getBoundingRectsAll(),
1542 rotation, mInitialDisplayWidth, mInitialDisplayHeight);
1543 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds),
Adrian Roos24264212018-02-19 16:26:15 +01001544 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1545 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001546 }
1547
Andrii Kulian06d07d62017-03-14 11:11:47 -07001548 /**
1549 * Compute display configuration based on display properties and policy settings.
1550 * Do not call if mDisplayReady == false.
1551 */
1552 void computeScreenConfiguration(Configuration config) {
1553 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
Evan Roskye747c3e2018-10-30 20:06:41 -07001554 calculateBounds(displayInfo, mTmpBounds);
1555 config.windowConfiguration.setBounds(mTmpBounds);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001556
1557 final int dw = displayInfo.logicalWidth;
1558 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001559 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001560 config.windowConfiguration.setWindowingMode(getWindowingMode());
Yunfan Chen7daa6ac2018-11-29 18:16:44 -08001561 config.windowConfiguration.setDisplayWindowingMode(getWindowingMode());
Evan Roskye747c3e2018-10-30 20:06:41 -07001562 config.windowConfiguration.setRotation(displayInfo.rotation);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001563
Adrian Roos11c25582018-02-19 18:06:36 +01001564 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001565 config.screenWidthDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001566 (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
1567 config.uiMode, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001568 config.screenHeightDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001569 (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
1570 config.uiMode, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001571
Tiger Huang7c610aa2018-10-27 00:01:01 +08001572 mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001573 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001574 final int leftInset = mTmpRect.left;
1575 final int topInset = mTmpRect.top;
1576 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001577 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1578 leftInset + displayInfo.appWidth /* right */,
1579 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001580 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1581 || displayInfo.rotation == Surface.ROTATION_270);
1582
Tiger Huang7c610aa2018-10-27 00:01:01 +08001583 computeSizeRangesAndScreenLayout(displayInfo, rotated, config.uiMode, dw, dh, density,
1584 config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001585
1586 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1587 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1588 ? Configuration.SCREENLAYOUT_ROUND_YES
1589 : Configuration.SCREENLAYOUT_ROUND_NO);
1590
1591 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1592 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1593 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001594 dh, displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001595 config.densityDpi = displayInfo.logicalDensityDpi;
1596
1597 config.colorMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001598 ((displayInfo.isHdr() && mWmService.hasHdrSupport())
Andrii Kulian06d07d62017-03-14 11:11:47 -07001599 ? Configuration.COLOR_MODE_HDR_YES
1600 : Configuration.COLOR_MODE_HDR_NO)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001601 | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001602 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1603 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1604
1605 // Update the configuration based on available input devices, lid switch,
1606 // and platform configuration.
1607 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1608 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1609 config.navigation = Configuration.NAVIGATION_NONAV;
1610
1611 int keyboardPresence = 0;
1612 int navigationPresence = 0;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001613 final InputDevice[] devices = mWmService.mInputManager.getInputDevices();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001614 final int len = devices != null ? devices.length : 0;
1615 for (int i = 0; i < len; i++) {
1616 InputDevice device = devices[i];
1617 if (!device.isVirtual()) {
1618 final int sources = device.getSources();
1619 final int presenceFlag = device.isExternal() ?
1620 WindowManagerPolicy.PRESENCE_EXTERNAL :
1621 WindowManagerPolicy.PRESENCE_INTERNAL;
1622
1623 // TODO(multi-display): Configure on per-display basis.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001624 if (mWmService.mIsTouchDevice) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001625 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1626 InputDevice.SOURCE_TOUCHSCREEN) {
1627 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1628 }
1629 } else {
1630 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1631 }
1632
1633 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1634 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1635 navigationPresence |= presenceFlag;
1636 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1637 && config.navigation == Configuration.NAVIGATION_NONAV) {
1638 config.navigation = Configuration.NAVIGATION_DPAD;
1639 navigationPresence |= presenceFlag;
1640 }
1641
1642 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1643 config.keyboard = Configuration.KEYBOARD_QWERTY;
1644 keyboardPresence |= presenceFlag;
1645 }
1646 }
1647 }
1648
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001649 if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001650 config.navigation = Configuration.NAVIGATION_DPAD;
1651 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1652 }
1653
1654 // Determine whether a hard keyboard is available and enabled.
1655 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1656 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001657 if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) {
1658 mWmService.mHardKeyboardAvailable = hardKeyboardAvailable;
1659 mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1660 mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001661 }
1662
Tiger Huang7c610aa2018-10-27 00:01:01 +08001663 mDisplayPolicy.updateConfigurationDependentBehaviors();
1664
Andrii Kulian06d07d62017-03-14 11:11:47 -07001665 // Let the policy update hidden states.
1666 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1667 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1668 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001669 mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001670 }
1671
1672 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001673 DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001674 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1675 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1676 final int unrotDw, unrotDh;
1677 if (rotated) {
1678 unrotDw = dh;
1679 unrotDh = dw;
1680 } else {
1681 unrotDw = dw;
1682 unrotDh = dh;
1683 }
1684 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001685 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001686 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001687 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001688 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001689 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001690 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001691 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001692 return sw;
1693 }
1694
1695 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001696 DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) {
1697 dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
1698 displayCutout);
1699 dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode,
1700 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001701 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1702 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1703 if (curSize == 0 || size < curSize) {
1704 curSize = size;
1705 }
1706 return curSize;
1707 }
1708
Tiger Huang7c610aa2018-10-27 00:01:01 +08001709 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
1710 int uiMode, int dw, int dh, float density, Configuration outConfig) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001711
1712 // We need to determine the smallest width that will occur under normal
1713 // operation. To this, start with the base screen size and compute the
1714 // width under the different possible rotations. We need to un-rotate
1715 // the current screen dimensions before doing this.
1716 int unrotDw, unrotDh;
1717 if (rotated) {
1718 unrotDw = dh;
1719 unrotDh = dw;
1720 } else {
1721 unrotDw = dw;
1722 unrotDh = dh;
1723 }
1724 displayInfo.smallestNominalAppWidth = 1<<30;
1725 displayInfo.smallestNominalAppHeight = 1<<30;
1726 displayInfo.largestNominalAppWidth = 0;
1727 displayInfo.largestNominalAppHeight = 0;
Tiger Huang7c610aa2018-10-27 00:01:01 +08001728 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh);
1729 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw);
1730 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh);
1731 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001732 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1733 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001734 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001735 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001736 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001737 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001738 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001739 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001740 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001741 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1742 outConfig.screenLayout = sl;
1743 }
1744
1745 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001746 int uiMode, DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001747 // Get the app screen size at this rotation.
Tiger Huang7c610aa2018-10-27 00:01:01 +08001748 int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout);
1749 int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001750
1751 // Compute the screen layout size class for this rotation.
1752 int longSize = w;
1753 int shortSize = h;
1754 if (longSize < shortSize) {
1755 int tmp = longSize;
1756 longSize = shortSize;
1757 shortSize = tmp;
1758 }
1759 longSize = (int)(longSize/density);
1760 shortSize = (int)(shortSize/density);
1761 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1762 }
1763
Tiger Huang7c610aa2018-10-27 00:01:01 +08001764 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001765 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001766 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1767 rotation).getDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +08001768 final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
1769 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001770 if (width < displayInfo.smallestNominalAppWidth) {
1771 displayInfo.smallestNominalAppWidth = width;
1772 }
1773 if (width > displayInfo.largestNominalAppWidth) {
1774 displayInfo.largestNominalAppWidth = width;
1775 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001776 final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
1777 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001778 if (height < displayInfo.smallestNominalAppHeight) {
1779 displayInfo.smallestNominalAppHeight = height;
1780 }
1781 if (height > displayInfo.largestNominalAppHeight) {
1782 displayInfo.largestNominalAppHeight = height;
1783 }
1784 }
1785
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001786 /**
1787 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1788 * theme attribute) on devices that feature a physical options menu key attempt to position
1789 * their menu panel window along the edge of the screen nearest the physical menu key.
1790 * This lowers the travel distance between invoking the menu panel and selecting
1791 * a menu option.
1792 *
1793 * This method helps control where that menu is placed. Its current implementation makes
1794 * assumptions about the menu key and its relationship to the screen based on whether
1795 * the device's natural orientation is portrait (width < height) or landscape.
1796 *
1797 * The menu key is assumed to be located along the bottom edge of natural-portrait
1798 * devices and along the right edge of natural-landscape devices. If these assumptions
1799 * do not hold for the target device, this method should be changed to reflect that.
1800 *
1801 * @return A {@link Gravity} value for placing the options menu window.
1802 */
1803 int getPreferredOptionsPanelGravity() {
1804 final int rotation = getRotation();
1805 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1806 // On devices with a natural orientation of portrait.
1807 switch (rotation) {
1808 default:
1809 case Surface.ROTATION_0:
1810 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1811 case Surface.ROTATION_90:
1812 return Gravity.RIGHT | Gravity.BOTTOM;
1813 case Surface.ROTATION_180:
1814 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1815 case Surface.ROTATION_270:
1816 return Gravity.START | Gravity.BOTTOM;
1817 }
1818 }
1819
1820 // On devices with a natural orientation of landscape.
1821 switch (rotation) {
1822 default:
1823 case Surface.ROTATION_0:
1824 return Gravity.RIGHT | Gravity.BOTTOM;
1825 case Surface.ROTATION_90:
1826 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1827 case Surface.ROTATION_180:
1828 return Gravity.START | Gravity.BOTTOM;
1829 case Surface.ROTATION_270:
1830 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1831 }
1832 }
1833
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001834 DockedStackDividerController getDockedDividerController() {
1835 return mDividerControllerLocked;
1836 }
1837
Winson Chung655332c2016-10-31 13:14:28 -07001838 PinnedStackController getPinnedStackController() {
1839 return mPinnedStackControllerLocked;
1840 }
1841
Jeff Browna506a6e2013-06-04 00:02:38 -07001842 /**
1843 * Returns true if the specified UID has access to this display.
1844 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001845 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001846 return mDisplay.hasAccess(uid);
1847 }
1848
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001849 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001850 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001851 }
1852
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001853 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001854 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001855 }
1856
Wale Ogunwale61911492017-10-11 08:50:50 -07001857 /**
1858 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1859 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001860 TaskStack getSplitScreenPrimaryStack() {
1861 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001862 return (stack != null && stack.isVisible()) ? stack : null;
1863 }
1864
Robert Carr9785cf32018-04-25 15:06:07 -07001865 boolean hasSplitScreenPrimaryStack() {
1866 return getSplitScreenPrimaryStack() != null;
1867 }
1868
Wale Ogunwale61911492017-10-11 08:50:50 -07001869 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001870 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001871 * not visible.
1872 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001873 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1874 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001875 }
1876
1877 TaskStack getPinnedStack() {
1878 return mTaskStackContainers.getPinnedStack();
1879 }
1880
1881 private boolean hasPinnedStack() {
1882 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001883 }
1884
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001885 /**
1886 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1887 * Null is no compatible stack on the display.
1888 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001889 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001890 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1891 }
1892
1893 /**
1894 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1895 * activity type. Null is no compatible stack on the display.
1896 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001897 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001898 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001899 }
1900
Bryce Lee48f4b572017-04-10 10:54:15 -07001901 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001902 WindowList<TaskStack> getStacks() {
1903 return mTaskStackContainers.mChildren;
1904 }
1905
1906 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001907 TaskStack getTopStack() {
1908 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001909 }
1910
Winson Chunge2d72172018-01-25 17:46:20 +00001911 ArrayList<Task> getVisibleTasks() {
1912 return mTaskStackContainers.getVisibleTasks();
1913 }
1914
Wale Ogunwale61911492017-10-11 08:50:50 -07001915 void onStackWindowingModeChanged(TaskStack stack) {
1916 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001917 }
1918
Andrii Kulian441e4492016-09-29 15:25:00 -07001919 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001920 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001921 super.onConfigurationChanged(newParentConfig);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001922 if (mDisplayPolicy != null) {
1923 mDisplayPolicy.onConfigurationChanged();
1924 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001925
Evan Roskye747c3e2018-10-30 20:06:41 -07001926 // If there was no pinned stack, we still need to notify the controller of the display info
1927 // update as a result of the config change.
1928 if (mPinnedStackControllerLocked != null && !hasPinnedStack()) {
1929 mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo());
1930 }
Evan Roskye747c3e2018-10-30 20:06:41 -07001931 }
1932
1933 /**
1934 * Updates the resources used by docked/pinned controllers. This needs to be called at the
1935 * beginning of a configuration update cascade since the metrics from these resources are used
1936 * for bounds calculations. Since ActivityDisplay initiates the configuration update, this
1937 * should be called from there instead of DisplayContent's onConfigurationChanged.
1938 */
1939 void preOnConfigurationChanged() {
Bryce Leef3c6a472017-11-14 14:53:06 -08001940 final DockedStackDividerController dividerController = getDockedDividerController();
1941
1942 if (dividerController != null) {
1943 getDockedDividerController().onConfigurationChanged();
1944 }
1945
1946 final PinnedStackController pinnedStackController = getPinnedStackController();
1947
1948 if (pinnedStackController != null) {
1949 getPinnedStackController().onConfigurationChanged();
1950 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001951 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001952
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001953 @Override
1954 boolean fillsParent() {
1955 return true;
1956 }
1957
1958 @Override
1959 boolean isVisible() {
1960 return true;
1961 }
1962
1963 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001964 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001965 super.onAppTransitionDone();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001966 mWmService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001967 }
1968
Yunfan Chen7daa6ac2018-11-29 18:16:44 -08001969 @Override
1970 public void setWindowingMode(int windowingMode) {
1971 super.setWindowingMode(windowingMode);
1972 super.setDisplayWindowingMode(windowingMode);
1973 }
1974
1975 @Override
1976 void setDisplayWindowingMode(int windowingMode) {
1977 setWindowingMode(windowingMode);
1978 }
1979
Robert Carr9785cf32018-04-25 15:06:07 -07001980 /**
1981 * In split-screen mode we process the IME containers above the docked divider
1982 * rather than directly above their target.
1983 */
1984 private boolean skipTraverseChild(WindowContainer child) {
lumarkff0ab692018-11-05 20:32:30 +08001985 if (child == mImeWindowsContainers && mInputMethodTarget != null
Robert Carr9785cf32018-04-25 15:06:07 -07001986 && !hasSplitScreenPrimaryStack()) {
1987 return true;
1988 }
1989 return false;
1990 }
1991
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001992 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001993 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1994 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1995 // target, or here in order if there isn't an IME target.
1996 if (traverseTopToBottom) {
1997 for (int i = mChildren.size() - 1; i >= 0; --i) {
1998 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001999 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002000 continue;
2001 }
Robert Carr9785cf32018-04-25 15:06:07 -07002002
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002003 if (child.forAllWindows(callback, traverseTopToBottom)) {
2004 return true;
2005 }
2006 }
2007 } else {
2008 final int count = mChildren.size();
2009 for (int i = 0; i < count; i++) {
2010 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07002011 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002012 continue;
2013 }
Robert Carr9785cf32018-04-25 15:06:07 -07002014
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002015 if (child.forAllWindows(callback, traverseTopToBottom)) {
2016 return true;
2017 }
2018 }
2019 }
2020 return false;
2021 }
2022
2023 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
2024 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
2025 }
2026
Wale Ogunwale399c8692017-05-08 14:22:42 -07002027 @Override
2028 int getOrientation() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002029 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002030
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002031 if (mWmService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08002032 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002033 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2034 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002035 // If the display is frozen, some activities may be in the middle of restarting, and
2036 // thus have removed their old window. If the window has the flag to hide the lock
2037 // screen, then the lock screen can re-appear and inflict its own orientation on us.
2038 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002039 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002040 } else if (policy.isKeyguardLocked()) {
2041 // Use the last orientation the while the display is frozen with the keyguard
2042 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
2043 // window. We don't want to check the show when locked window directly though as
2044 // things aren't stable while the display is frozen, for example the window could be
2045 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002046 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2047 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08002048 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07002049 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002050 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002051 final int orientation = mAboveAppWindowsContainers.getOrientation();
2052 if (orientation != SCREEN_ORIENTATION_UNSET) {
2053 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002054 }
Wale Ogunwale51362492016-09-08 17:49:17 -07002055 }
2056
Wale Ogunwale399c8692017-05-08 14:22:42 -07002057 // Top system windows are not requesting an orientation. Start searching from apps.
2058 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07002059 }
2060
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002061 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07002062 // Check if display metrics changed and update base values if needed.
2063 updateBaseDisplayMetricsIfNeeded();
2064
Craig Mautner722285e2012-09-07 13:55:58 -07002065 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07002066 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07002067
Garfield Tan2f145f22018-11-01 15:27:03 -07002068 onDisplayChanged(this);
Craig Mautner722285e2012-09-07 13:55:58 -07002069 }
2070
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002071 void initializeDisplayBaseInfo() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002072 final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002073 if (displayManagerInternal != null) {
2074 // Bootstrap the default logical display from the display manager.
2075 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
2076 if (newDisplayInfo != null) {
2077 mDisplayInfo.copyFrom(newDisplayInfo);
2078 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002079 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002080
Andrii Kuliancd097992017-03-23 18:31:59 -07002081 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
2082 mDisplayInfo.logicalDensityDpi);
2083 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
2084 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
2085 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002086 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002087 }
2088
Andrii Kuliancd097992017-03-23 18:31:59 -07002089 /**
2090 * If display metrics changed, overrides are not set and it's not just a rotation - update base
2091 * values.
2092 */
2093 private void updateBaseDisplayMetricsIfNeeded() {
2094 // Get real display metrics without overrides from WM.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002095 mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
Andrii Kuliancd097992017-03-23 18:31:59 -07002096 final int orientation = mDisplayInfo.rotation;
2097 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2098 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
2099 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
2100 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002101 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07002102
2103 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
2104 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01002105 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
2106 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07002107
2108 if (displayMetricsChanged) {
2109 // Check if display size or density is forced.
2110 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
2111 || mBaseDisplayHeight != mInitialDisplayHeight;
2112 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
2113
2114 // If there is an override set for base values - use it, otherwise use new values.
2115 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
2116 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
2117 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
2118
2119 // Real display metrics changed, so we should also update initial values.
2120 mInitialDisplayWidth = newWidth;
2121 mInitialDisplayHeight = newHeight;
2122 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01002123 mInitialDisplayCutout = newCutout;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002124 mWmService.reconfigureDisplayLocked(this);
Andrii Kuliancd097992017-03-23 18:31:59 -07002125 }
2126 }
2127
Bryce Lee27cec322017-03-21 09:41:37 -07002128 /** Sets the maximum width the screen resolution can be */
2129 void setMaxUiWidth(int width) {
2130 if (DEBUG_DISPLAY) {
2131 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
2132 }
2133
2134 mMaxUiWidth = width;
2135
2136 // Update existing metrics.
2137 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
2138 }
2139
2140 /** Update base (override) display metrics. */
2141 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
2142 mBaseDisplayWidth = baseWidth;
2143 mBaseDisplayHeight = baseHeight;
2144 mBaseDisplayDensity = baseDensity;
2145
2146 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
2147 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
2148 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
2149 mBaseDisplayWidth = mMaxUiWidth;
2150
2151 if (DEBUG_DISPLAY) {
2152 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
2153 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
2154 + " on display:" + getDisplayId());
2155 }
2156 }
2157
2158 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08002159
2160 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07002161 }
2162
Riddle Hsuf53da812018-08-15 22:00:27 +08002163 /**
2164 * Forces this display to use the specified density.
2165 *
2166 * @param density The density in DPI to use. If the value equals to initial density, the setting
2167 * will be cleared.
2168 * @param userId The target user to apply. Only meaningful when this is default display. If the
2169 * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings
2170 * so only need to configure display.
2171 */
2172 void setForcedDensity(int density, int userId) {
2173 final boolean clear = density == mInitialDisplayDensity;
2174 final boolean updateCurrent = userId == UserHandle.USER_CURRENT;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002175 if (mWmService.mCurrentUserId == userId || updateCurrent) {
Riddle Hsuf53da812018-08-15 22:00:27 +08002176 mBaseDisplayDensity = density;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002177 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002178 }
2179 if (updateCurrent) {
2180 // We are applying existing settings so no need to save it again.
2181 return;
2182 }
2183
2184 if (density == mInitialDisplayDensity) {
2185 density = 0;
2186 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002187 mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId);
Riddle Hsuf53da812018-08-15 22:00:27 +08002188 }
2189
2190 /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */
2191 void setForcedScalingMode(@ForceScalingMode int mode) {
2192 if (mode != FORCE_SCALING_MODE_DISABLED) {
2193 mode = FORCE_SCALING_MODE_AUTO;
2194 }
2195
2196 mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO);
2197 Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto"));
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002198 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002199
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002200 mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode);
Riddle Hsuf53da812018-08-15 22:00:27 +08002201 }
2202
2203 /** If the given width and height equal to initial size, the setting will be cleared. */
2204 void setForcedSize(int width, int height) {
2205 final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height;
2206 if (!clear) {
2207 // Set some sort of reasonable bounds on the size of the display that we will try
2208 // to emulate.
2209 final int minSize = 200;
2210 final int maxScale = 2;
2211 width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale);
2212 height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale);
2213 }
2214
2215 Slog.i(TAG_WM, "Using new display size: " + width + "x" + height);
2216 updateBaseDisplayMetrics(width, height, mBaseDisplayDensity);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002217 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002218
2219 if (clear) {
2220 width = height = 0;
2221 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002222 mWmService.mDisplayWindowSettings.setForcedSize(this, width, height);
Riddle Hsuf53da812018-08-15 22:00:27 +08002223 }
2224
Wale Ogunwaledb506192017-12-08 10:57:32 -08002225 void getStableRect(Rect out) {
2226 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08002227 }
2228
Wale Ogunwale61911492017-10-11 08:50:50 -07002229 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002230 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
2231 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07002232
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002233 final TaskStack stack = new TaskStack(mWmService, stackId, controller);
Wale Ogunwale61911492017-10-11 08:50:50 -07002234 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08002235 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07002236 }
2237
Andrii Kulian51c1b672017-04-07 18:39:32 -07002238 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002239 final DisplayContent prevDc = stack.getDisplayContent();
2240 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07002241 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
2242 + " which is not currently attached to any display");
2243 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08002244 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07002245 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2246 + " to its current displayId=" + mDisplayId);
2247 }
2248
lumark588a3e82018-07-20 18:53:54 +08002249 // Clean up all pending transitions when stack reparent to another display.
2250 stack.forAllAppWindows(AppWindowToken::removeFromPendingTransition);
2251
Wale Ogunwale61911492017-10-11 08:50:50 -07002252 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002253 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002254 }
2255
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002256 @Override
2257 protected void addChild(DisplayChildWindowContainer child,
2258 Comparator<DisplayChildWindowContainer> comparator) {
2259 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2260 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002261
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002262 @Override
2263 protected void addChild(DisplayChildWindowContainer child, int index) {
2264 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2265 }
2266
2267 @Override
2268 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002269 // Only allow removal of direct children from this display if the display is in the process
2270 // of been removed.
2271 if (mRemovingDisplay) {
2272 super.removeChild(child);
2273 return;
2274 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002275 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002276 }
2277
Andrii Kuliand2765632016-12-12 22:26:34 -08002278 @Override
2279 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2280 // Children of the display are statically ordered, so the real intention here is to perform
2281 // the operation on the display and not the static direct children.
2282 getParent().positionChildAt(position, this, includingParents);
2283 }
2284
Riddle Hsu57831b52018-07-27 00:31:48 +08002285 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2286 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002287 layoutAndAssignWindowLayersIfNeeded();
2288 }
2289
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002290 /**
2291 * Used to obtain task ID when user taps on coordinate (x, y) in this display, and outside
2292 * current task in focus.
2293 *
2294 * This returns the task ID of the foremost task at (x, y) if the task is not home. Otherwise it
2295 * returns -1.
2296 *
2297 * @param x horizontal coordinate of the tap position
2298 * @param y vertical coordinate of the tap position
2299 * @return the task ID if a non-home task is found; -1 if not
2300 */
2301 int taskForTapOutside(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002302 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2303 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002304 if (stack.isActivityTypeHome() && !stack.inMultiWindowMode()) {
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002305 // We skip not only home stack, but also everything behind home because user can't
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002306 // see them when home stack is isn't in multi-window mode.
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002307 break;
2308 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002309 final int taskId = stack.taskIdFromPoint(x, y);
2310 if (taskId != -1) {
2311 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002312 }
2313 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002314 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002315 }
2316
Chong Zhang8e89b312015-09-09 15:09:30 -07002317 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002318 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002319 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002320 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002321 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002322 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002323 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002324 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2325 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002326 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002327 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002328 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002329
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002330 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2331 if (mTmpTaskForResizePointSearchResult.searchDone) {
2332 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002333 }
2334 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002335 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002336 }
2337
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002338 void updateTouchExcludeRegion() {
2339 final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null);
David Stevensee9e2772017-02-09 16:30:27 -08002340 if (focusedTask == null) {
2341 mTouchExcludeRegion.setEmpty();
2342 } else {
2343 mTouchExcludeRegion.set(mBaseDisplayRect);
2344 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2345 mTmpRect2.setEmpty();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002346 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0;
2347 --stackNdx) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002348 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002349 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2350 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002351 }
2352 // If we removed the focused task above, add it back and only leave its
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002353 // outside touch area in the exclusion. TapDetector is not interested in
David Stevensee9e2772017-02-09 16:30:27 -08002354 // any touch inside the focused task itself.
2355 if (!mTmpRect2.isEmpty()) {
2356 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2357 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002358 }
lumark90120a82018-08-15 00:33:03 +08002359 if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) {
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002360 // If the input method is visible and the user is typing, we don't want these touch
2361 // events to be intercepted and used to change focus. This would likely cause a
2362 // disappearance of the input method.
lumark90120a82018-08-15 00:33:03 +08002363 mInputMethodWindow.getTouchableRegion(mTmpRegion);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002364 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002365 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002366 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002367 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002368 win.getTouchableRegion(mTmpRegion);
2369 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2370 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002371 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2372 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2373 win.amendTapExcludeRegion(mTouchExcludeRegion);
2374 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002375 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002376 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002377 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002378 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002379 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2380 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002381 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002382 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002383 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002384 }
2385
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002386 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002387 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002388 super.switchUser();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002389 mWmService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002390 }
2391
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002392 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002393 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2394 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002395 }
2396 }
2397
Wale Ogunwale10124582016-09-15 20:25:50 -07002398 @Override
2399 void removeIfPossible() {
2400 if (isAnimating()) {
2401 mDeferredRemoval = true;
2402 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002403 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002404 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002405 }
2406
Wale Ogunwale10124582016-09-15 20:25:50 -07002407 @Override
2408 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002409 mRemovingDisplay = true;
2410 try {
lumark588a3e82018-07-20 18:53:54 +08002411 // Clear all transitions & screen frozen states when removing display.
2412 mOpeningApps.clear();
2413 mClosingApps.clear();
2414 mUnknownAppVisibilityController.clear();
2415 mAppTransition.removeAppTransitionTimeoutCallbacks();
2416 handleAnimatingStoppedAndTransition();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002417 mWmService.stopFreezingDisplayLocked();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002418 super.removeImmediately();
2419 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002420 if (mPointerEventDispatcher != null && mTapDetector != null) {
2421 unregisterPointerEventListener(mTapDetector);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002422 unregisterPointerEventListener(mWmService.mMousePositionTracker);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002423 mTapDetector = null;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002424 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002425 mWmService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002426 mWindowingLayer.release();
2427 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002428 } finally {
Riddle Hsu4e611772018-10-31 18:58:28 +08002429 mDisplayReady = false;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002430 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002431 }
Robert Carr679ccb02018-08-08 15:32:35 -07002432
Tiger Huang7c610aa2018-10-27 00:01:01 +08002433 mDisplayPolicy.onDisplayRemoved();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002434 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautner95da1082014-02-24 17:54:35 -08002435 }
2436
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002437 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002438 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002439 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002440 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2441
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002442 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002443 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002444 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002445 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002446 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002447 }
2448
Andrii Kulian0214ed92017-05-16 13:44:05 -07002449 /** @return 'true' if removal of this display content is deferred due to active animation. */
2450 boolean isRemovalDeferred() {
2451 return mDeferredRemoval;
2452 }
2453
Wale Ogunwale10124582016-09-15 20:25:50 -07002454 boolean animateForIme(float interpolatedValue, float animationTarget,
2455 float dividerAnimationTarget) {
2456 boolean updated = false;
2457
Wale Ogunwale61911492017-10-11 08:50:50 -07002458 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2459 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002460 if (stack == null || !stack.isAdjustedForIme()) {
2461 continue;
2462 }
2463
2464 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2465 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2466 updated = true;
2467 } else {
2468 mDividerControllerLocked.mLastAnimationProgress =
2469 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2470 mDividerControllerLocked.mLastDividerProgress =
2471 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2472 updated |= stack.updateAdjustForIme(
2473 mDividerControllerLocked.mLastAnimationProgress,
2474 mDividerControllerLocked.mLastDividerProgress,
2475 false /* force */);
2476 }
2477 if (interpolatedValue >= 1f) {
2478 stack.endImeAdjustAnimation();
2479 }
2480 }
2481
2482 return updated;
2483 }
2484
2485 boolean clearImeAdjustAnimation() {
2486 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002487 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2488 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002489 if (stack != null && stack.isAdjustedForIme()) {
2490 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2491 changed = true;
2492 }
2493 }
2494 return changed;
2495 }
2496
2497 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002498 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2499 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002500 if (stack.isVisible() && stack.isAdjustedForIme()) {
2501 stack.beginImeAdjustAnimation();
2502 }
2503 }
2504 }
2505
2506 void adjustForImeIfNeeded() {
lumark90120a82018-08-15 00:33:03 +08002507 final WindowState imeWin = mInputMethodWindow;
Wale Ogunwale10124582016-09-15 20:25:50 -07002508 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2509 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002510 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002511 final TaskStack imeTargetStack = mWmService.getImeFocusStackLocked();
Wale Ogunwale10124582016-09-15 20:25:50 -07002512 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2513 imeTargetStack.getDockSide() : DOCKED_INVALID;
2514 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2515 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2516 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002517 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002518 final boolean imeHeightChanged = imeVisible &&
2519 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2520
2521 // The divider could be adjusted for IME position, or be thinner than usual,
2522 // or both. There are three possible cases:
2523 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2524 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2525 // - If IME is not visible, divider is not moved and is normal width.
2526
2527 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002528 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2529 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002530 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002531 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2532 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002533 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2534 } else {
2535 stack.resetAdjustedForIme(false);
2536 }
2537 }
2538 mDividerControllerLocked.setAdjustedForIme(
2539 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2540 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002541 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2542 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002543 stack.resetAdjustedForIme(!dockVisible);
2544 }
2545 mDividerControllerLocked.setAdjustedForIme(
2546 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2547 }
Winson Chung655332c2016-10-31 13:14:28 -07002548 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002549 }
2550
2551 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002552 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2553 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002554 stack.prepareFreezingTaskBounds();
2555 }
2556 }
2557
Wale Ogunwale94744212015-09-21 19:01:47 -07002558 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002559 getBounds(mTmpRect, newRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002560 rotateBounds(mTmpRect, oldRotation, newRotation, bounds);
2561 }
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002562
Evan Rosky39b6f232018-10-30 18:35:41 -07002563 void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002564 // Compute a transform matrix to undo the coordinate space transformation,
2565 // and present the window at the same physical position it previously occupied.
2566 final int deltaRotation = deltaRotation(newRotation, oldRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002567 createRotationMatrix(
2568 deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002569
2570 mTmpRectF.set(bounds);
2571 mTmpMatrix.mapRect(mTmpRectF);
2572 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002573 }
2574
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002575 static int deltaRotation(int oldRotation, int newRotation) {
2576 int delta = newRotation - oldRotation;
2577 if (delta < 0) delta += 4;
2578 return delta;
2579 }
2580
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002581 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002582 Matrix outMatrix) {
2583 // For rotations without Z-ordering we don't need the target rectangle's position.
2584 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2585 displayHeight, outMatrix);
2586 }
2587
2588 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2589 float displayWidth, float displayHeight, Matrix outMatrix) {
2590 switch (rotation) {
2591 case ROTATION_0:
2592 outMatrix.reset();
2593 break;
2594 case ROTATION_270:
2595 outMatrix.setRotate(270, 0, 0);
2596 outMatrix.postTranslate(0, displayHeight);
2597 outMatrix.postTranslate(rectTop, 0);
2598 break;
2599 case ROTATION_180:
2600 outMatrix.reset();
2601 break;
2602 case ROTATION_90:
2603 outMatrix.setRotate(90, 0, 0);
2604 outMatrix.postTranslate(displayWidth, 0);
2605 outMatrix.postTranslate(-rectTop, rectLeft);
2606 break;
2607 }
2608 }
2609
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002610 @CallSuper
2611 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002612 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002613 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002614 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002615 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002616 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2617 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002618 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002619 }
2620 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2621 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002622 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2623 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002624 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002625 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002626 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2627 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002628 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002629 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002630 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2631 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002632 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002633 }
2634 proto.write(DPI, mBaseDisplayDensity);
2635 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002636 proto.write(ROTATION, mRotation);
2637 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002638 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002639 if (screenRotationAnimation != null) {
2640 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2641 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002642 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
lumark588a3e82018-07-20 18:53:54 +08002643 mAppTransition.writeToProto(proto, APP_TRANSITION);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002644 if (mFocusedApp != null) {
2645 mFocusedApp.writeNameToProto(proto, FOCUSED_APP);
2646 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002647 proto.end(token);
2648 }
2649
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002650 @Override
2651 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2652 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002653 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2654 final String subPrefix = " " + prefix;
2655 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2656 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2657 pw.print("dpi");
2658 if (mInitialDisplayWidth != mBaseDisplayWidth
2659 || mInitialDisplayHeight != mBaseDisplayHeight
2660 || mInitialDisplayDensity != mBaseDisplayDensity) {
2661 pw.print(" base=");
2662 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2663 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2664 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002665 if (mDisplayScalingDisabled) {
2666 pw.println(" noscale");
2667 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002668 pw.print(" cur=");
2669 pw.print(mDisplayInfo.logicalWidth);
2670 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2671 pw.print(" app=");
2672 pw.print(mDisplayInfo.appWidth);
2673 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2674 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2675 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2676 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2677 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002678 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002679 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002680 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002681
Craig Mautnerdc548482014-02-05 13:35:24 -08002682 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002683 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002684 pw.print(prefix);
2685 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002686
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002687 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
2688 if (mLastFocus != mCurrentFocus) {
2689 pw.print(" mLastFocus="); pw.println(mLastFocus);
2690 }
2691 if (mLosingFocus.size() > 0) {
2692 pw.println();
2693 pw.println(" Windows losing focus:");
2694 for (int i = mLosingFocus.size() - 1; i >= 0; i--) {
2695 final WindowState w = mLosingFocus.get(i);
2696 pw.print(" Losing #"); pw.print(i); pw.print(' ');
2697 pw.print(w);
2698 if (dumpAll) {
2699 pw.println(":");
2700 w.dump(pw, " ", true);
2701 } else {
2702 pw.println();
2703 }
2704 }
2705 }
2706 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
Tiger Huang7c610aa2018-10-27 00:01:01 +08002707 if (mLastStatusBarVisibility != 0) {
2708 pw.print(" mLastStatusBarVisibility=0x");
2709 pw.println(Integer.toHexString(mLastStatusBarVisibility));
2710 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002711
Adrian Roos5251b1d2018-03-23 18:57:43 +01002712 pw.println();
wilsonshihc32538e2018-11-07 17:27:34 +08002713 mWallpaperController.dump(pw, " ");
2714
2715 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002716 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002717 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2718 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002719 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002720 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002721
Craig Mautnerdc548482014-02-05 13:35:24 -08002722 pw.println();
2723 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002724 pw.println();
2725 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002726 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002727 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002728 pw.print(" Exiting #"); pw.print(i);
2729 pw.print(' '); pw.print(token);
2730 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002731 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002732 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002733 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002734
Jorim Jaggi31f71702016-05-04 16:43:04 -07002735 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002736
2737 // Dump stack references
2738 final TaskStack homeStack = getHomeStack();
2739 if (homeStack != null) {
2740 pw.println(prefix + "homeStack=" + homeStack.getName());
2741 }
2742 final TaskStack pinnedStack = getPinnedStack();
2743 if (pinnedStack != null) {
2744 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2745 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002746 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002747 if (splitScreenPrimaryStack != null) {
2748 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2749 }
2750
2751 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002752 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002753 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002754 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002755
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002756 pw.println();
2757 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002758 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002759 mDisplayPolicy.dump(prefix, pw);
2760 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002761 mDisplayRotation.dump(prefix, pw);
2762 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002763 mInputMonitor.dump(pw, " ");
Jorim Jaggif96c90a2018-09-26 16:55:15 +02002764 pw.println();
2765 mInsetsStateController.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002766 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002767
2768 @Override
2769 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002770 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002771 }
2772
2773 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002774 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002775 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002776
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002777 /** Returns true if the stack in the windowing mode is visible. */
2778 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002779 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002780 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002781 }
2782
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002783 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002784 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002785 final int x = (int) xf;
2786 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002787 final WindowState touchedWin = getWindow(w -> {
2788 final int flags = w.mAttrs.flags;
2789 if (!w.isVisibleLw()) {
2790 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002791 }
2792 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002793 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002794 }
2795
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002796 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002797 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002798 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002799 }
2800
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002801 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002802
2803 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002804 return mTmpRegion.contains(x, y) || touchFlags == 0;
2805 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002806
2807 return touchedWin;
2808 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002809
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002810 boolean canAddToastWindowForUid(int uid) {
2811 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002812 // Also if the app is focused adding more than one toast at
2813 // a time for better backwards compatibility.
2814 final WindowState focusedWindowForUid = getWindow(w ->
2815 w.mOwnerUid == uid && w.isFocused());
2816 if (focusedWindowForUid != null) {
2817 return true;
2818 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002819 final WindowState win = getWindow(w ->
2820 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2821 && !w.mWindowRemovalAllowed);
2822 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002823 }
2824
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002825 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002826 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2827 return;
2828 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002829
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002830 // Used to communicate the old focus to the callback method.
2831 mTmpWindow = oldFocus;
2832
2833 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002834 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002835
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002836 WindowState findFocusedWindowIfNeeded() {
2837 return (mWmService.mPerDisplayFocusEnabled
2838 || mWmService.mRoot.mTopFocusedAppByProcess.isEmpty()) ? findFocusedWindow() : null;
2839 }
2840
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002841 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002842 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002843
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002844 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002845
2846 if (mTmpWindow == null) {
2847 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2848 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002849 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002850 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002851 }
2852
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002853 /**
2854 * Update the focused window and make some adjustments if the focus has changed.
2855 *
2856 * @param mode Indicates the situation we are in. Possible modes are:
2857 * {@link WindowManagerService#UPDATE_FOCUS_NORMAL},
2858 * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES},
2859 * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES},
2860 * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS}
2861 * @param updateInputWindows Whether to sync the window information to the input module.
2862 * @return {@code true} if the focused window has changed.
2863 */
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002864 boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
2865 WindowState newFocus = findFocusedWindowIfNeeded();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002866 if (mCurrentFocus == newFocus) {
2867 return false;
2868 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002869 boolean imWindowChanged = false;
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002870 final WindowState imWindow = mInputMethodWindow;
2871 if (imWindow != null) {
2872 final WindowState prevTarget = mInputMethodTarget;
2873 final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/);
2874 imWindowChanged = prevTarget != newTarget;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002875
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002876 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS
2877 && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2878 assignWindowLayers(false /* setLayoutNeeded */);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002879 }
2880 }
2881
2882 if (imWindowChanged) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002883 mWmService.mWindowsChanged = true;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002884 setLayoutNeeded();
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002885 newFocus = findFocusedWindowIfNeeded();
2886 }
2887 if (mCurrentFocus != newFocus) {
2888 mWmService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002889 }
2890
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002891 if (DEBUG_FOCUS_LIGHT || mWmService.localLOGV) Slog.v(TAG_WM, "Changing focus from "
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002892 + mCurrentFocus + " to " + newFocus + " displayId=" + getDisplayId()
2893 + " Callers=" + Debug.getCallers(4));
2894 final WindowState oldFocus = mCurrentFocus;
2895 mCurrentFocus = newFocus;
2896 mLosingFocus.remove(newFocus);
2897
2898 if (newFocus != null) {
2899 mWinAddedSinceNullFocus.clear();
2900 mWinRemovedSinceNullFocus.clear();
2901
2902 if (newFocus.canReceiveKeys()) {
2903 // Displaying a window implicitly causes dispatching to be unpaused.
2904 // This is to protect against bugs if someone pauses dispatching but
2905 // forgets to resume.
2906 newFocus.mToken.paused = false;
2907 }
2908 }
2909
Tiger Huang7c610aa2018-10-27 00:01:01 +08002910 int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002911
2912 if (imWindowChanged && oldFocus != mInputMethodWindow) {
2913 // Focus of the input method window changed. Perform layout if needed.
2914 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2915 performLayout(true /*initial*/, updateInputWindows);
2916 focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT;
2917 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2918 // Client will do the layout, but we need to assign layers
2919 // for handleNewWindowLocked() below.
2920 assignWindowLayers(false /* setLayoutNeeded */);
2921 }
2922 }
2923
2924 if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2925 // The change in focus caused us to need to do a layout. Okay.
2926 setLayoutNeeded();
2927 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2928 performLayout(true /*initial*/, updateInputWindows);
2929 } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002930 mWmService.mRoot.performSurfacePlacement(false);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002931 }
2932 }
2933
2934 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
2935 // If we defer assigning layers, then the caller is responsible for doing this part.
2936 getInputMonitor().setInputFocusLw(newFocus, updateInputWindows);
2937 }
2938
2939 adjustForImeIfNeeded();
2940
2941 // We may need to schedule some toast windows to be removed. The toasts for an app that
2942 // does not have input focus are removed within a timeout to prevent apps to redress
2943 // other apps' UI.
2944 scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus);
2945
2946 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2947 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2948 }
2949 return true;
2950 }
2951
2952 /**
2953 * Set the new focused app to this display.
2954 *
2955 * @param newFocus the new focused AppWindowToken.
2956 * @return true if the focused app is changed.
2957 */
2958 boolean setFocusedApp(AppWindowToken newFocus) {
2959 if (newFocus != null) {
2960 final DisplayContent appDisplay = newFocus.getDisplayContent();
2961 if (appDisplay != this) {
2962 throw new IllegalStateException(newFocus + " is not on " + getName()
2963 + " but " + ((appDisplay != null) ? appDisplay.getName() : "none"));
2964 }
2965 }
2966 if (mFocusedApp == newFocus) {
2967 return false;
2968 }
2969 mFocusedApp = newFocus;
2970 getInputMonitor().setFocusedAppLw(newFocus);
2971 updateTouchExcludeRegion();
2972 return true;
2973 }
2974
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002975 /** Updates the layer assignment of windows on this display. */
2976 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002977 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002978 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002979 if (setLayoutNeeded) {
2980 setLayoutNeeded();
2981 }
Robert Carrb1579c82017-09-05 14:54:47 -07002982
Robert Carrf59b8dd2017-10-02 18:58:36 -07002983 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002984 // the application of this transaction until the animation pass triggers
2985 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2986 // the hiding and showing of surfaces.
2987 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002988 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002989 }
2990
Wale Ogunwale1666e312016-12-16 11:27:18 -08002991 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2992 // moving containers or resizing them. Need to investigate the best way to have it automatically
2993 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002994 void layoutAndAssignWindowLayersIfNeeded() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002995 mWmService.mWindowsChanged = true;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002996 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002997
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002998 if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002999 false /*updateInputWindows*/)) {
3000 assignWindowLayers(false /* setLayoutNeeded */);
3001 }
3002
Arthur Hung95b38a92018-07-20 18:56:12 +08003003 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003004 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08003005 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003006 }
3007
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003008 /** Returns true if a leaked surface was destroyed */
3009 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003010 // Used to indicate that a surface was leaked.
3011 mTmpWindow = null;
3012 forAllWindows(w -> {
3013 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003014 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003015 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003016 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003017 if (!mWmService.mSessions.contains(wsa.mSession)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003018 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003019 + w + " surface=" + wsa.mSurfaceController
3020 + " token=" + w.mToken
3021 + " pid=" + w.mSession.mPid
3022 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003023 wsa.destroySurface();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003024 mWmService.mForceRemoves.add(w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003025 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07003026 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003027 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003028 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003029 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003030 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003031 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003032 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003033 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003034 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003035
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003036 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003037 }
3038
3039 /**
lumark90120a82018-08-15 00:33:03 +08003040 * Set input method window for the display.
3041 * @param win Set when window added or Null when destroyed.
3042 */
3043 void setInputMethodWindowLocked(WindowState win) {
3044 mInputMethodWindow = win;
lumark70865a82018-09-17 16:56:26 +08003045 // Update display configuration for IME process.
3046 if (mInputMethodWindow != null) {
3047 final int imePid = mInputMethodWindow.mSession.mPid;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003048 mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid,
lumark70865a82018-09-17 16:56:26 +08003049 mInputMethodWindow.getDisplayId());
3050 }
lumark90120a82018-08-15 00:33:03 +08003051 computeImeTarget(true /* updateImeTarget */);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003052 mInsetsStateController.getSourceProvider(TYPE_IME).setWindow(win,
3053 null /* frameProvider */);
lumark90120a82018-08-15 00:33:03 +08003054 }
3055
3056 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003057 * Determine and return the window that should be the IME target.
3058 * @param updateImeTarget If true the system IME target will be updated to match what we found.
3059 * @return The window that should be used as the IME target or null if there isn't any.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003060 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003061 WindowState computeImeTarget(boolean updateImeTarget) {
lumark90120a82018-08-15 00:33:03 +08003062 if (mInputMethodWindow == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003063 // There isn't an IME so there shouldn't be a target...That was easy!
3064 if (updateImeTarget) {
3065 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
lumarkff0ab692018-11-05 20:32:30 +08003066 + mInputMethodTarget + " to null since mInputMethodWindow is null");
3067 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003068 }
3069 return null;
3070 }
3071
lumarkff0ab692018-11-05 20:32:30 +08003072 final WindowState curTarget = mInputMethodTarget;
Chavi Weingarten3a748552018-05-14 17:32:42 +00003073 if (!canUpdateImeTarget()) {
3074 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
3075 return curTarget;
3076 }
3077
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003078 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
3079 // same display. Or even when the current IME/target are not on the same screen as the next
3080 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08003081 mUpdateImeTarget = updateImeTarget;
3082 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003083
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003084
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003085 // Yet more tricksyness! If this window is a "starting" window, we do actually want
3086 // to be on top of it, but it is not -really- where input will go. So look down below
3087 // for a real window to target...
3088 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
3089 final AppWindowToken token = target.mAppToken;
3090 if (token != null) {
3091 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
3092 if (betterTarget != null) {
3093 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003094 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003095 }
3096 }
3097
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003098 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
lumarkff0ab692018-11-05 20:32:30 +08003099 "Proposed new IME target: " + target + " for display: " + getDisplayId());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003100
chaviw1c13ad32018-06-12 16:44:23 -07003101 // Now, a special case -- if the last target's window is in the process of exiting, but
3102 // not removed, and the new target is home, keep on the last target to avoid flicker.
3103 // Home is a special case since its above other stacks in the ordering list, but layed
3104 // out below the others.
3105 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
3106 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07003107 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00003108 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003109 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003110 }
3111
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003112 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
3113 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003114
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003115 if (target == null) {
3116 if (updateImeTarget) {
3117 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
3118 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
3119 + Debug.getCallers(4) : ""));
lumarkff0ab692018-11-05 20:32:30 +08003120 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003121 }
3122
3123 return null;
3124 }
3125
3126 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003127 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
3128 if (token != null) {
3129
3130 // Now some fun for dealing with window animations that modify the Z order. We need
3131 // to look at all windows below the current target that are in this app, finding the
3132 // highest visible one in layering.
3133 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003134 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003135 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003136 }
3137
3138 if (highestTarget != null) {
lumark588a3e82018-07-20 18:53:54 +08003139 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, mAppTransition + " " + highestTarget
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003140 + " animating=" + highestTarget.isAnimating());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003141
lumark588a3e82018-07-20 18:53:54 +08003142 if (mAppTransition.isTransitionSet()) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003143 // If we are currently setting up for an animation, hold everything until we
3144 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003145 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003146 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003147 }
3148 }
3149 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003150
3151 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
3152 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003153 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003154 }
3155
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003156 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003157 }
3158
lumarkff0ab692018-11-05 20:32:30 +08003159 /**
3160 * Calling {@link #computeImeTarget(boolean)} to update the input method target window in
3161 * the candidate app window token if needed.
3162 */
3163 void computeImeTargetIfNeeded(AppWindowToken candidate) {
3164 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == candidate) {
3165 computeImeTarget(true /* updateImeTarget */);
3166 }
3167 }
3168
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003169 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
lumarkff0ab692018-11-05 20:32:30 +08003170 if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003171 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003172 }
3173
lumarkff0ab692018-11-05 20:32:30 +08003174 mInputMethodTarget = target;
3175 mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003176 assignWindowLayers(false /* setLayoutNeeded */);
3177 }
3178
3179 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
3180 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3181 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
3182 }
3183
3184 // Used to indicate we have reached the first window in the range we are interested in.
3185 mTmpWindow = null;
3186
3187 // TODO: Figure-out a more efficient way to do this.
3188 final WindowState candidate = getWindow(w -> {
3189 if (w == top) {
3190 // Reached the first window in the range we are interested in.
3191 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003192 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003193 if (mTmpWindow == null) {
3194 return false;
3195 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003196
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003197 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3198 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003199 }
3200 // If we reached the bottom of the range of windows we are considering,
3201 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003202 if (w == bottom) {
3203 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003204 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003205 return false;
3206 });
3207
3208 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003209 }
3210
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003211 void setLayoutNeeded() {
3212 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
3213 mLayoutNeeded = true;
3214 }
3215
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003216 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003217 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
3218 mLayoutNeeded = false;
3219 }
3220
3221 boolean isLayoutNeeded() {
3222 return mLayoutNeeded;
3223 }
3224
Wale Ogunwale02319a62016-09-26 15:21:22 -07003225 void dumpTokens(PrintWriter pw, boolean dumpAll) {
3226 if (mTokenMap.isEmpty()) {
3227 return;
3228 }
3229 pw.println(" Display #" + mDisplayId);
3230 final Iterator<WindowToken> it = mTokenMap.values().iterator();
3231 while (it.hasNext()) {
3232 final WindowToken token = it.next();
3233 pw.print(" ");
3234 pw.print(token);
3235 if (dumpAll) {
3236 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003237 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07003238 } else {
3239 pw.println();
3240 }
3241 }
lumark588a3e82018-07-20 18:53:54 +08003242
3243 if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty()) {
3244 pw.println();
3245 if (mOpeningApps.size() > 0) {
3246 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
3247 }
3248 if (mClosingApps.size() > 0) {
3249 pw.print(" mClosingApps="); pw.println(mClosingApps);
3250 }
3251 }
3252
3253 mUnknownAppVisibilityController.dump(pw, " ");
Wale Ogunwale02319a62016-09-26 15:21:22 -07003254 }
3255
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003256 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003257 final int[] index = new int[1];
3258 forAllWindows(w -> {
3259 final WindowStateAnimator wAnim = w.mWinAnimator;
3260 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
3261 index[0] = index[0] + 1;
3262 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003263 }
3264
Jorim Jaggife762342016-10-13 14:33:27 +02003265 /**
3266 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
3267 */
3268 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003269 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003270 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02003271 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
3272 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01003273 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02003274 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003275 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02003276 }
3277
Wale Ogunwale494009b82016-10-21 09:01:38 -07003278 boolean checkWaitingForWindows() {
3279
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003280 mHaveBootMsg = false;
3281 mHaveApp = false;
3282 mHaveWallpaper = false;
3283 mHaveKeyguard = true;
3284
3285 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003286 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
3287 return true;
3288 }
3289 if (w.isDrawnLw()) {
3290 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003291 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003292 } else if (w.mAttrs.type == TYPE_APPLICATION
3293 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003294 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003295 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003296 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003297 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003298 mHaveKeyguard = mWmService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003299 }
3300 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003301 return false;
3302 });
3303
3304 if (visibleWindow != null) {
3305 // We have a visible window.
3306 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003307 }
3308
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003309 // if the wallpaper service is disabled on the device, we're never going to have
3310 // wallpaper, don't bother waiting for it
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003311 boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean(
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003312 com.android.internal.R.bool.config_enableWallpaperService)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003313 && mWmService.mContext.getResources().getBoolean(
Daichi Hironoc1432222018-03-29 13:06:07 +09003314 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003315 && !mWmService.mOnlyCore;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003316
Wale Ogunwale494009b82016-10-21 09:01:38 -07003317 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003318 "******** booted=" + mWmService.mSystemBooted
3319 + " msg=" + mWmService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003320 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
3321 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
3322 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003323
3324 // If we are turning on the screen to show the boot message, don't do it until the boot
3325 // message is actually displayed.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003326 if (!mWmService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003327 return true;
3328 }
3329
3330 // If we are turning on the screen after the boot is completed normally, don't do so until
3331 // we have the application and wallpaper.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003332 if (mWmService.mSystemBooted
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003333 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003334 return true;
3335 }
3336
3337 return false;
3338 }
3339
Jorim Jaggi8f520872018-08-14 17:00:20 +02003340 void updateWindowsForAnimator() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003341 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003342 }
3343
Jorim Jaggi8f520872018-08-14 17:00:20 +02003344 /**
3345 * Updates the {@link TaskStack#setAnimationBackground} for all windows.
3346 */
3347 void updateBackgroundForAnimator() {
Jorim Jaggi7156b652016-10-25 08:31:58 -07003348 resetAnimationBackgroundAnimator();
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003349 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003350 }
3351
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003352 boolean isInputMethodClientFocus(int uid, int pid) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003353 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003354 if (imFocus == null) {
3355 return false;
3356 }
3357
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003358 if (DEBUG_INPUT_METHOD) {
3359 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003360 Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId);
3361 Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003362 }
3363
Wale Ogunwale494009b82016-10-21 09:01:38 -07003364 if (DEBUG_INPUT_METHOD) {
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003365 Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid
3366 + "/" + imFocus.mSession.mPid);
3367 Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003368 }
3369
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003370 return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003371 }
3372
3373 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003374 final WindowState win = getWindow(
3375 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
3376 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003377 }
3378
Tiger Huang7c610aa2018-10-27 00:01:01 +08003379 void statusBarVisibilityChanged(int visibility) {
3380 mLastStatusBarVisibility = visibility;
3381 visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility);
3382 updateStatusBarVisibilityLocked(visibility);
3383 }
3384
3385 private boolean updateStatusBarVisibilityLocked(int visibility) {
3386 if (mLastDispatchedSystemUiVisibility == visibility) {
3387 return false;
3388 }
3389 final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility)
3390 // We are only interested in differences of one of the
3391 // clearable flags...
3392 & View.SYSTEM_UI_CLEARABLE_FLAGS
3393 // ...if it has actually been cleared.
3394 & ~visibility;
3395
3396 mLastDispatchedSystemUiVisibility = visibility;
3397 if (isDefaultDisplay) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003398 mWmService.mInputManager.setSystemUiVisibility(visibility);
Tiger Huang7c610aa2018-10-27 00:01:01 +08003399 }
3400 updateSystemUiVisibility(visibility, globalDiff);
3401 return true;
3402 }
3403
Wale Ogunwale494009b82016-10-21 09:01:38 -07003404 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003405 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003406 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003407 final int curValue = w.mSystemUiVisibility;
3408 final int diff = (curValue ^ visibility) & globalDiff;
3409 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003410 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003411 w.mSeq++;
3412 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003413 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003414 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
3415 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07003416 visibility, newValue, diff);
3417 }
3418 } catch (RemoteException e) {
3419 // so sorry
3420 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003421 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003422 }
3423
Tiger Huang7c610aa2018-10-27 00:01:01 +08003424 void reevaluateStatusBarVisibility() {
3425 int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility);
3426 if (updateStatusBarVisibilityLocked(visibility)) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003427 mWmService.mWindowPlacerLocked.requestTraversal();
Tiger Huang7c610aa2018-10-27 00:01:01 +08003428 }
3429 }
3430
Wale Ogunwale494009b82016-10-21 09:01:38 -07003431 void onWindowFreezeTimeout() {
3432 Slog.w(TAG_WM, "Window freeze timeout expired.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003433 mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003434
3435 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003436 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003437 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003438 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07003439 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003440 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003441 - mWmService.mDisplayFreezeTime);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003442 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003443 }, true /* traverseTopToBottom */);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003444 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003445 }
3446
3447 void waitForAllWindowsDrawn() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003448 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003449 forAllWindows(w -> {
3450 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
3451 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
3452 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003453 // Force add to mResizingWindows.
chaviw9c81e632018-07-31 11:17:52 -07003454 w.resetLastContentInsets();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003455 mWmService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003456 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003457 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003458 }
3459
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003460 // TODO: Super crazy long method that should be broken down...
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003461 void applySurfaceChangesTransaction(boolean recoveringMemory) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003462 final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003463
3464 mTmpUpdateAllDrawn.clear();
3465
3466 int repeats = 0;
3467 do {
3468 repeats++;
3469 if (repeats > 6) {
3470 Slog.w(TAG, "Animation repeat aborted after too many iterations");
3471 clearLayoutNeeded();
3472 break;
3473 }
3474
3475 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
3476 pendingLayoutChanges);
3477
wilsonshihc32538e2018-11-07 17:27:34 +08003478 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
3479 mWallpaperController.adjustWallpaperWindows();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003480 }
3481
Riddle Hsu654a6f92018-07-13 22:59:36 +08003482 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003483 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Riddle Hsu4e611772018-10-31 18:58:28 +08003484 if (updateOrientationFromAppTokens()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003485 setLayoutNeeded();
Riddle Hsu4e611772018-10-31 18:58:28 +08003486 sendNewConfiguration();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003487 }
3488 }
3489
3490 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3491 setLayoutNeeded();
3492 }
3493
3494 // FIRST LOOP: Perform a layout, if needed.
3495 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3496 performLayout(repeats == 1, false /* updateInputWindows */);
3497 } else {
3498 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3499 }
3500
3501 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3502 pendingLayoutChanges = 0;
3503
Tiger Huang7c610aa2018-10-27 00:01:01 +08003504 mDisplayPolicy.beginPostLayoutPolicyLw();
3505 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
3506 pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw();
3507 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3508 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003509 mInsetsStateController.onPostLayout();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003510 } while (pendingLayoutChanges != 0);
3511
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003512 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003513
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003514 mTmpRecoveringMemory = recoveringMemory;
3515 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003516 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003517
Jorim Jaggif1292892018-09-10 11:58:13 +02003518 mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003519 mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggif1292892018-09-10 11:58:13 +02003520 mLastHasContent,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003521 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3522 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003523 true /* inTraversal, must call performTraversalInTrans... below */);
3524
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003525 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3526 if (wallpaperVisible != mLastWallpaperVisible) {
3527 mLastWallpaperVisible = wallpaperVisible;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003528 mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003529 }
3530
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003531 while (!mTmpUpdateAllDrawn.isEmpty()) {
3532 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3533 // See if any windows have been drawn, so they (and others associated with them)
3534 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003535 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003536 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003537 }
3538
Bryce Leef3c6a472017-11-14 14:53:06 -08003539 private void updateBounds() {
Evan Rosky39b6f232018-10-30 18:35:41 -07003540 calculateBounds(mDisplayInfo, mTmpBounds);
Bryce Leef3c6a472017-11-14 14:53:06 -08003541 setBounds(mTmpBounds);
3542 }
3543
3544 // Determines the current display bounds based on the current state
Evan Rosky39b6f232018-10-30 18:35:41 -07003545 private void calculateBounds(DisplayInfo displayInfo, Rect out) {
Bryce Leef3c6a472017-11-14 14:53:06 -08003546 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Evan Rosky39b6f232018-10-30 18:35:41 -07003547 final int rotation = displayInfo.rotation;
3548 boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Bryce Leef3c6a472017-11-14 14:53:06 -08003549 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3550 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Evan Rosky39b6f232018-10-30 18:35:41 -07003551 int width = displayInfo.logicalWidth;
Bryce Leef3c6a472017-11-14 14:53:06 -08003552 int left = (physWidth - width) / 2;
Evan Rosky39b6f232018-10-30 18:35:41 -07003553 int height = displayInfo.logicalHeight;
Bryce Leef3c6a472017-11-14 14:53:06 -08003554 int top = (physHeight - height) / 2;
3555 out.set(left, top, left + width, top + height);
3556 }
3557
3558 @Override
3559 public void getBounds(Rect out) {
Evan Rosky39b6f232018-10-30 18:35:41 -07003560 calculateBounds(mDisplayInfo, out);
Bryce Leef3c6a472017-11-14 14:53:06 -08003561 }
3562
3563 private void getBounds(Rect out, int orientation) {
3564 getBounds(out);
3565
3566 // Rotate the Rect if needed.
3567 final int currentRotation = mDisplayInfo.rotation;
3568 final int rotationDelta = deltaRotation(currentRotation, orientation);
3569 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3570 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3571 mTmpRectF.set(out);
3572 mTmpMatrix.mapRect(mTmpRectF);
3573 mTmpRectF.round(out);
3574 }
3575 }
3576
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003577 void performLayout(boolean initial, boolean updateInputWindows) {
3578 if (!isLayoutNeeded()) {
3579 return;
3580 }
3581 clearLayoutNeeded();
3582
3583 final int dw = mDisplayInfo.logicalWidth;
3584 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003585 if (DEBUG_LAYOUT) {
3586 Slog.v(TAG, "-------------------------------------");
3587 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3588 }
3589
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003590 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3591 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003592 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3593 // display info above...
3594 mDisplayFrames.mRotation = mRotation;
Tiger Huang7c610aa2018-10-27 00:01:01 +08003595 mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003596
Adrian Roos5251b1d2018-03-23 18:57:43 +01003597 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003598 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003599 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003600
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003601 // Used to indicate that we have processed the dream window and all additional windows are
3602 // behind it.
3603 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003604 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003605
3606 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003607 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003608
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003609 // Used to indicate that we have processed the dream window and all additional attached
3610 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003611 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003612 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003613
3614 // Now perform layout of attached windows, which usually depend on the position of the
3615 // window they are attached to. XXX does not deal with windows that are attached to windows
3616 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003617 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003618
3619 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003620 mInputMonitor.layoutInputConsumers(dw, dh);
3621 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003622 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003623 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003624 }
3625
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003626 mWmService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003627 }
3628
3629 /**
3630 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3631 * In portrait mode, it grabs the full screenshot.
3632 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003633 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003634 */
chaviw0315a1a2018-03-05 15:28:35 -08003635 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003636 if (!mWmService.mPolicy.isScreenOn()) {
chaviw0315a1a2018-03-05 15:28:35 -08003637 if (DEBUG_SCREENSHOT) {
3638 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003639 }
chaviw0315a1a2018-03-05 15:28:35 -08003640 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003641 }
chaviwfbe47df2017-11-10 16:14:49 -08003642
chaviw0315a1a2018-03-05 15:28:35 -08003643 int dw = mDisplayInfo.logicalWidth;
3644 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003645
chaviw0315a1a2018-03-05 15:28:35 -08003646 if (dw <= 0 || dh <= 0) {
3647 return null;
3648 }
chaviwfbe47df2017-11-10 16:14:49 -08003649
chaviw0315a1a2018-03-05 15:28:35 -08003650 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003651
chaviw0315a1a2018-03-05 15:28:35 -08003652 // The screenshot API does not apply the current screen rotation.
3653 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003654
chaviw0315a1a2018-03-05 15:28:35 -08003655 if (rot == ROTATION_90 || rot == ROTATION_270) {
3656 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3657 }
chaviwfbe47df2017-11-10 16:14:49 -08003658
chaviw0315a1a2018-03-05 15:28:35 -08003659 // SurfaceFlinger is not aware of orientation, so convert our logical
3660 // crop to SurfaceFlinger's portrait orientation.
3661 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3662
3663 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003664 mWmService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
chaviw0315a1a2018-03-05 15:28:35 -08003665 final boolean inRotation = screenRotationAnimation != null &&
3666 screenRotationAnimation.isAnimating();
3667 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3668
3669 // TODO(b/68392460): We should screenshot Task controls directly
3670 // but it's difficult at the moment as the Task doesn't have the
3671 // correct size set.
chaviw08520a02018-09-10 16:44:56 -07003672 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot);
chaviw0315a1a2018-03-05 15:28:35 -08003673 if (bitmap == null) {
3674 Slog.w(TAG_WM, "Failed to take screenshot");
3675 return null;
3676 }
3677
3678 // Create a copy of the screenshot that is immutable and backed in ashmem.
3679 // This greatly reduces the overhead of passing the bitmap between processes.
3680 final Bitmap ret = bitmap.createAshmemBitmap(config);
3681 bitmap.recycle();
3682 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003683 }
3684
3685 // TODO: Can this use createRotationMatrix()?
3686 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3687 if (rot == Surface.ROTATION_90) {
3688 final int tmp = crop.top;
3689 crop.top = dw - crop.right;
3690 crop.right = crop.bottom;
3691 crop.bottom = dw - crop.left;
3692 crop.left = tmp;
3693 } else if (rot == Surface.ROTATION_180) {
3694 int tmp = crop.top;
3695 crop.top = dh - crop.bottom;
3696 crop.bottom = dh - tmp;
3697 tmp = crop.right;
3698 crop.right = dw - crop.left;
3699 crop.left = dw - tmp;
3700 } else if (rot == Surface.ROTATION_270) {
3701 final int tmp = crop.top;
3702 crop.top = crop.left;
3703 crop.left = dh - crop.bottom;
3704 crop.bottom = crop.right;
3705 crop.right = dh - tmp;
3706 }
3707 }
3708
3709 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003710 // Used to indicate the layout is needed.
3711 mTmpWindow = null;
3712
3713 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003714 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003715 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003716 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003717 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003718 w.setDisplayLayoutNeeded();
Vishnu Nairba183352018-11-21 11:16:49 -08003719 w.finishSeamlessRotation(true /* timeout */);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003720 mWmService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003721 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003722
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003723 if (mTmpWindow != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003724 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003725 }
3726 }
3727
Wale Ogunwale1666e312016-12-16 11:27:18 -08003728 void setExitingTokensHasVisible(boolean hasVisible) {
3729 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3730 mExitingTokens.get(i).hasVisible = hasVisible;
3731 }
3732
3733 // Initialize state of exiting applications.
3734 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3735 }
3736
3737 void removeExistingTokensIfPossible() {
3738 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3739 final WindowToken token = mExitingTokens.get(i);
3740 if (!token.hasVisible) {
3741 mExitingTokens.remove(i);
3742 }
3743 }
3744
3745 // Time to remove any exiting applications?
3746 mTaskStackContainers.removeExistingAppTokensIfPossible();
3747 }
3748
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003749 @Override
3750 void onDescendantOverrideConfigurationChanged() {
3751 setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003752 mWmService.requestTraversal();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003753 }
3754
David Stevens9440dc82017-03-16 19:00:20 -07003755 boolean okToDisplay() {
3756 if (mDisplayId == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003757 return !mWmService.mDisplayFrozen
3758 && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn();
David Stevens9440dc82017-03-16 19:00:20 -07003759 }
3760 return mDisplayInfo.state == Display.STATE_ON;
3761 }
3762
3763 boolean okToAnimate() {
3764 return okToDisplay() &&
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003765 (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate());
David Stevens9440dc82017-03-16 19:00:20 -07003766 }
3767
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003768 static final class TaskForResizePointSearchResult {
3769 boolean searchDone;
3770 Task taskForResize;
3771
3772 void reset() {
3773 searchDone = false;
3774 taskForResize = null;
3775 }
3776 }
Robert Carr3b716242016-08-16 16:02:21 -07003777
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003778 private static final class ApplySurfaceChangesTransactionState {
3779 boolean displayHasContent;
3780 boolean obscured;
3781 boolean syswin;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003782 float preferredRefreshRate;
3783 int preferredModeId;
3784
3785 void reset() {
3786 displayHasContent = false;
3787 obscured = false;
3788 syswin = false;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003789 preferredRefreshRate = 0;
3790 preferredModeId = 0;
3791 }
3792 }
3793
3794 private static final class ScreenshotApplicationState {
3795 WindowState appWin;
3796 int maxLayer;
3797 int minLayer;
3798 boolean screenshotReady;
3799
3800 void reset(boolean screenshotReady) {
3801 appWin = null;
3802 maxLayer = 0;
3803 minLayer = 0;
3804 this.screenshotReady = screenshotReady;
3805 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3806 }
3807 }
3808
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003809 /**
3810 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3811 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3812 * homogeneous children type which is currently required by sub-classes of
3813 * {@link WindowContainer} class.
3814 */
3815 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3816
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003817 DisplayChildWindowContainer(WindowManagerService service) {
3818 super(service);
3819 }
3820
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003821 @Override
3822 boolean fillsParent() {
3823 return true;
3824 }
3825
3826 @Override
3827 boolean isVisible() {
3828 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003829 }
3830 }
3831
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003832 /**
3833 * Window container class that contains all containers on this display relating to Apps.
3834 * I.e Activities.
3835 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003836 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003837 /**
3838 * A control placed at the appropriate level for transitions to occur.
3839 */
chaviw23ee71c2017-12-18 11:29:41 -08003840 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003841 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003842 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003843
Robert Carrf7a7ca82017-12-06 13:17:07 -08003844 /**
3845 * Given that the split-screen divider does not have an AppWindowToken, it
3846 * will have to live inside of a "NonAppWindowContainer", in particular
3847 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3848 * it will need to be interleaved with some of our children, appearing on top of
3849 * both docked stacks but underneath any assistant stacks.
3850 *
3851 * To solve this problem we have this anchor control, which will always exist so
3852 * we can always assign it the correct value in our {@link #assignChildLayers}.
3853 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3854 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3855 * events between the two containers.
3856 */
3857 SurfaceControl mSplitScreenDividerAnchor = null;
3858
Wale Ogunwale61911492017-10-11 08:50:50 -07003859 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3860 // through the list to find them.
3861 private TaskStack mHomeStack = null;
3862 private TaskStack mPinnedStack = null;
3863 private TaskStack mSplitScreenPrimaryStack = null;
3864
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003865 TaskStackContainers(WindowManagerService service) {
3866 super(service);
3867 }
3868
Wale Ogunwale61911492017-10-11 08:50:50 -07003869 /**
3870 * Returns the topmost stack on the display that is compatible with the input windowing mode
3871 * and activity type. Null is no compatible stack on the display.
3872 */
3873 TaskStack getStack(int windowingMode, int activityType) {
3874 if (activityType == ACTIVITY_TYPE_HOME) {
3875 return mHomeStack;
3876 }
3877 if (windowingMode == WINDOWING_MODE_PINNED) {
3878 return mPinnedStack;
3879 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3880 return mSplitScreenPrimaryStack;
3881 }
3882 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3883 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003884 if (activityType == ACTIVITY_TYPE_UNDEFINED
3885 && windowingMode == stack.getWindowingMode()) {
3886 // Passing in undefined type means we want to match the topmost stack with the
3887 // windowing mode.
3888 return stack;
3889 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003890 if (stack.isCompatible(windowingMode, activityType)) {
3891 return stack;
3892 }
3893 }
3894 return null;
3895 }
3896
3897 @VisibleForTesting
3898 TaskStack getTopStack() {
3899 return mTaskStackContainers.getChildCount() > 0
3900 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3901 }
3902
3903 TaskStack getHomeStack() {
3904 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3905 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3906 }
3907 return mHomeStack;
3908 }
3909
3910 TaskStack getPinnedStack() {
3911 return mPinnedStack;
3912 }
3913
Matthew Ng64e77cf2017-10-31 14:01:31 -07003914 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003915 return mSplitScreenPrimaryStack;
3916 }
3917
Winson Chunge2d72172018-01-25 17:46:20 +00003918 ArrayList<Task> getVisibleTasks() {
3919 final ArrayList<Task> visibleTasks = new ArrayList<>();
3920 forAllTasks(task -> {
3921 if (task.isVisible()) {
3922 visibleTasks.add(task);
3923 }
3924 });
3925 return visibleTasks;
3926 }
3927
Andrii Kulian839def92016-11-02 10:58:58 -07003928 /**
3929 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003930 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003931 */
3932 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003933 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003934 addChild(stack, onTop);
3935 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003936 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003937
Wale Ogunwale61911492017-10-11 08:50:50 -07003938 void onStackWindowingModeChanged(TaskStack stack) {
3939 removeStackReferenceIfNeeded(stack);
3940 addStackReferenceIfNeeded(stack);
3941 if (stack == mPinnedStack && getTopStack() != stack) {
3942 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3943 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3944 }
3945 }
3946
3947 private void addStackReferenceIfNeeded(TaskStack stack) {
3948 if (stack.isActivityTypeHome()) {
3949 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08003950 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003951 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08003952
Wale Ogunwale61911492017-10-11 08:50:50 -07003953 }
Louis Chang7d0037c2018-08-13 12:42:06 +08003954 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003955 }
3956 final int windowingMode = stack.getWindowingMode();
3957 if (windowingMode == WINDOWING_MODE_PINNED) {
3958 if (mPinnedStack != null) {
3959 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3960 + mPinnedStack + " already exist on display=" + this
3961 + " stack=" + stack);
3962 }
3963 mPinnedStack = stack;
3964 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3965 if (mSplitScreenPrimaryStack != null) {
3966 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3967 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3968 + " already exist on display=" + this + " stack=" + stack);
3969 }
3970 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003971 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003972 }
3973 }
3974
3975 private void removeStackReferenceIfNeeded(TaskStack stack) {
3976 if (stack == mHomeStack) {
3977 mHomeStack = null;
3978 } else if (stack == mPinnedStack) {
3979 mPinnedStack = null;
3980 } else if (stack == mSplitScreenPrimaryStack) {
3981 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003982 // Re-set the split-screen create mode whenever the split-screen stack is removed.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003983 mWmService.setDockedStackCreateStateLocked(
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003984 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3985 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003986 }
Andrii Kulian839def92016-11-02 10:58:58 -07003987 }
3988
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003989 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003990 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3991 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003992 addChild(stack, addIndex);
3993 setLayoutNeeded();
3994 }
3995
Wale Ogunwale61911492017-10-11 08:50:50 -07003996 @Override
3997 protected void removeChild(TaskStack stack) {
3998 super.removeChild(stack);
3999 removeStackReferenceIfNeeded(stack);
4000 }
Bryce Lee00d586d2017-07-28 20:48:43 -07004001
4002 @Override
4003 boolean isOnTop() {
4004 // Considered always on top
4005 return true;
4006 }
4007
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004008 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08004009 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07004010 if (child.getWindowConfiguration().isAlwaysOnTop()
4011 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08004012 // This stack is always-on-top, override the default behavior.
4013 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
4014
4015 // Moving to its current position, as we must call super but we don't want to
4016 // perform any meaningful action.
4017 final int currentPosition = mChildren.indexOf(child);
4018 super.positionChildAt(currentPosition, child, false /* includingParents */);
4019 return;
4020 }
4021
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004022 final int targetPosition = findPositionForStack(position, child, false /* adding */);
4023 super.positionChildAt(targetPosition, child, includingParents);
4024
Riddle Hsu2f6e1742018-08-23 22:44:36 +08004025 if (includingParents) {
4026 // We still want to move the display of this stack container to top because even the
4027 // target position is adjusted to non-top, the intention of the condition is to have
4028 // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front
4029 // in a non-top display which is using picture-in-picture mode).
4030 final int topChildPosition = getChildCount() - 1;
4031 if (targetPosition < topChildPosition && position >= topChildPosition) {
4032 getParent().positionChildAt(POSITION_TOP, this /* child */,
4033 true /* includingParents */);
4034 }
4035 }
4036
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004037 setLayoutNeeded();
4038 }
4039
4040 /**
4041 * When stack is added or repositioned, find a proper position for it.
4042 * This will make sure that pinned stack always stays on top.
4043 * @param requestedPosition Position requested by caller.
4044 * @param stack Stack to be added or positioned.
4045 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
4046 * @return The proper position for the stack.
4047 */
4048 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004049 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09004050 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09004051 }
4052
Kazuki Takisef85197b2018-06-18 18:18:36 +09004053 final int topChildPosition = mChildren.size() - 1;
4054 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
4055 for (int i = topChildPosition; i >= 0; --i) {
4056 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
4057 belowAlwaysOnTopPosition = i;
4058 break;
4059 }
4060 }
4061
4062 // The max possible position we can insert the stack at.
4063 int maxPosition = POSITION_TOP;
4064 // The min possible position we can insert the stack at.
4065 int minPosition = POSITION_BOTTOM;
4066
4067 if (stack.isAlwaysOnTop()) {
4068 if (hasPinnedStack()) {
4069 // Always-on-top stacks go below the pinned stack.
4070 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
4071 }
4072 // Always-on-top stacks need to be above all other stacks.
4073 minPosition = belowAlwaysOnTopPosition !=
4074 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
4075 } else {
4076 // Other stacks need to be below the always-on-top stacks.
4077 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08004078 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09004079 }
4080
4081 int targetPosition = requestedPosition;
4082 targetPosition = Math.min(targetPosition, maxPosition);
4083 targetPosition = Math.max(targetPosition, minPosition);
4084
4085 int prevPosition = getStacks().indexOf(stack);
4086 // The positions we calculated above (maxPosition, minPosition) do not take into
4087 // consideration the following edge cases.
4088 // 1) We need to adjust the position depending on the value "adding".
4089 // 2) When we are moving a stack to another position, we also need to adjust the
4090 // position depending on whether the stack is moving to a higher or lower position.
4091 if ((targetPosition != requestedPosition) &&
4092 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004093 targetPosition++;
4094 }
4095
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004096 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08004097 }
4098
4099 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004100 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
4101 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004102 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004103 if (super.forAllWindows(callback, traverseTopToBottom)) {
4104 return true;
4105 }
4106 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4107 return true;
4108 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004109 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004110 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4111 return true;
4112 }
4113 if (super.forAllWindows(callback, traverseTopToBottom)) {
4114 return true;
4115 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004116 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004117 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004118 }
4119
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004120 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004121 boolean traverseTopToBottom) {
4122 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
4123 // app tokens.
4124 // TODO: Investigate if we need to continue to do this or if we can just process them
4125 // in-order.
4126 if (traverseTopToBottom) {
4127 for (int i = mChildren.size() - 1; i >= 0; --i) {
4128 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4129 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004130 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4131 traverseTopToBottom)) {
4132 return true;
4133 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004134 }
4135 }
4136 } else {
4137 final int count = mChildren.size();
4138 for (int i = 0; i < count; ++i) {
4139 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4140 final int appTokensCount = appTokens.size();
4141 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004142 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4143 traverseTopToBottom)) {
4144 return true;
4145 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004146 }
4147 }
4148 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004149 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004150 }
4151
Wale Ogunwale1666e312016-12-16 11:27:18 -08004152 void setExitingTokensHasVisible(boolean hasVisible) {
4153 for (int i = mChildren.size() - 1; i >= 0; --i) {
4154 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4155 for (int j = appTokens.size() - 1; j >= 0; --j) {
4156 appTokens.get(j).hasVisible = hasVisible;
4157 }
4158 }
4159 }
4160
4161 void removeExistingAppTokensIfPossible() {
4162 for (int i = mChildren.size() - 1; i >= 0; --i) {
4163 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4164 for (int j = appTokens.size() - 1; j >= 0; --j) {
4165 final AppWindowToken token = appTokens.get(j);
lumark588a3e82018-07-20 18:53:54 +08004166 if (!token.hasVisible && !mClosingApps.contains(token)
Wale Ogunwale1666e312016-12-16 11:27:18 -08004167 && (!token.mIsExiting || token.isEmpty())) {
4168 // Make sure there is no animation running on this token, so any windows
4169 // associated with it will be removed as soon as their animations are
4170 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02004171 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08004172 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4173 "performLayout: App token exiting now removed" + token);
4174 token.removeIfPossible();
4175 }
4176 }
4177 }
4178 }
4179
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004180 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004181 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004182 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
4183 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004184 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07004185 // docked or freeform stack is visible...except for the home stack if the docked
4186 // stack is minimized and it actually set something and the bounds is different from
4187 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004188 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004189 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004190 && !(mDividerControllerLocked.isHomeStackResizable()
4191 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004192 final int orientation = mHomeStack.getOrientation();
4193 if (orientation != SCREEN_ORIENTATION_UNSET) {
4194 return orientation;
4195 }
4196 }
4197 return SCREEN_ORIENTATION_UNSPECIFIED;
4198 }
4199
4200 final int orientation = super.getOrientation();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004201 boolean isCar = mWmService.mContext.getPackageManager().hasSystemFeature(
Dean Harding3e5a1522017-10-06 09:19:01 -07004202 PackageManager.FEATURE_AUTOMOTIVE);
4203 if (isCar) {
4204 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
4205 // allow anything but the default orientation.
4206 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004207 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
4208 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07004209 return SCREEN_ORIENTATION_UNSPECIFIED;
4210 }
4211
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004212 if (orientation != SCREEN_ORIENTATION_UNSET
4213 && orientation != SCREEN_ORIENTATION_BEHIND) {
4214 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004215 "App is requesting an orientation, return " + orientation
4216 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004217 return orientation;
4218 }
4219
4220 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004221 "No app is requesting an orientation, return " + mLastOrientation
4222 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004223 // The next app has not been requested to be visible, so we keep the current orientation
4224 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08004225 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004226 }
Robert Carrb1579c82017-09-05 14:54:47 -07004227
4228 @Override
4229 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004230 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004231
Robert Carr2f8aa392018-01-31 14:46:51 -08004232 for (int i = 0; i < mChildren.size(); i++) {
4233 final TaskStack s = mChildren.get(i);
4234 s.assignChildLayers(t);
4235 }
4236 }
4237
4238 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02004239
Robert Carrf7a7ca82017-12-06 13:17:07 -08004240 final int HOME_STACK_STATE = 0;
4241 final int NORMAL_STACK_STATE = 1;
4242 final int ALWAYS_ON_TOP_STATE = 2;
4243
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004244 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004245 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02004246 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02004247 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004248
Robert Carrf7a7ca82017-12-06 13:17:07 -08004249 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
4250 for (int i = 0; i < mChildren.size(); i++) {
4251 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08004252 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
4253 continue;
4254 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
4255 || s.isAlwaysOnTop())) {
4256 continue;
4257 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
4258 continue;
4259 }
4260 s.assignLayer(t, layer++);
4261 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
4262 t.setLayer(mSplitScreenDividerAnchor, layer++);
4263 }
Winson Chungd41f71d2018-03-16 15:26:07 -07004264 if ((s.isTaskAnimating() || s.isAppAnimating())
4265 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004266 // Ensure the animation layer ends up above the
4267 // highest animating stack and no higher.
4268 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004269 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004270 if (state != ALWAYS_ON_TOP_STATE) {
4271 layerForBoostedAnimationLayer = layer++;
4272 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08004273 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004274 if (state == HOME_STACK_STATE) {
4275 layerForHomeAnimationLayer = layer++;
4276 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004277 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004278 if (mAppAnimationLayer != null) {
4279 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004280 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004281 if (mBoostedAppAnimationLayer != null) {
4282 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
4283 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004284 if (mHomeAppAnimationLayer != null) {
4285 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
4286 }
Robert Carrb1579c82017-09-05 14:54:47 -07004287 }
4288
4289 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02004290 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
4291 switch (animationLayer) {
4292 case ANIMATION_LAYER_BOOSTED:
4293 return mBoostedAppAnimationLayer;
4294 case ANIMATION_LAYER_HOME:
4295 return mHomeAppAnimationLayer;
4296 case ANIMATION_LAYER_STANDARD:
4297 default:
4298 return mAppAnimationLayer;
4299 }
chaviw23ee71c2017-12-18 11:29:41 -08004300 }
4301
Robert Carrf7a7ca82017-12-06 13:17:07 -08004302 SurfaceControl getSplitScreenDividerAnchor() {
4303 return mSplitScreenDividerAnchor;
4304 }
4305
chaviw23ee71c2017-12-18 11:29:41 -08004306 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004307 void onParentSet() {
4308 super.onParentSet();
4309 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08004310 mAppAnimationLayer = makeChildSurface(null)
4311 .setName("animationLayer")
4312 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02004313 mBoostedAppAnimationLayer = makeChildSurface(null)
4314 .setName("boostedAnimationLayer")
4315 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02004316 mHomeAppAnimationLayer = makeChildSurface(null)
4317 .setName("homeAnimationLayer")
4318 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08004319 mSplitScreenDividerAnchor = makeChildSurface(null)
4320 .setName("splitScreenDividerAnchor")
4321 .build();
4322 getPendingTransaction()
4323 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02004324 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02004325 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08004326 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08004327 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07004328 } else {
chaviw23ee71c2017-12-18 11:29:41 -08004329 mAppAnimationLayer.destroy();
4330 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02004331 mBoostedAppAnimationLayer.destroy();
4332 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02004333 mHomeAppAnimationLayer.destroy();
4334 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004335 mSplitScreenDividerAnchor.destroy();
4336 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07004337 }
4338 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004339 }
4340
Robert Carree4d4b92017-11-22 12:21:46 -08004341 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004342 AboveAppWindowContainers(String name, WindowManagerService service) {
4343 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08004344 }
4345
Robert Carrb9506032018-02-13 13:54:00 -08004346 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07004347 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
4348 final SurfaceControl.Builder builder = super.makeChildSurface(child);
4349 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
4350 // To draw above the ColorFade layer during the screen off transition, the
4351 // rounded corner overlays need to be at the root of the surface hierarchy.
4352 // TODO: move the ColorLayer into the display overlay layer such that this is not
4353 // necessary anymore.
4354 builder.setParent(null);
4355 }
4356 return builder;
4357 }
4358
4359 @Override
Robert Carrb9506032018-02-13 13:54:00 -08004360 void assignChildLayers(SurfaceControl.Transaction t) {
4361 assignChildLayers(t, null /* imeContainer */);
4362 }
4363
Robert Carree4d4b92017-11-22 12:21:46 -08004364 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
4365 boolean needAssignIme = imeContainer != null
4366 && imeContainer.getSurfaceControl() != null;
4367 for (int j = 0; j < mChildren.size(); ++j) {
4368 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004369
4370 // See {@link mSplitScreenDividerAnchor}
4371 if (wt.windowType == TYPE_DOCK_DIVIDER) {
4372 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
4373 continue;
4374 }
Vishnu Nair83537a72018-07-19 21:27:48 -07004375 if (wt.mRoundedCornerOverlay) {
4376 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
4377 continue;
4378 }
Robert Carree4d4b92017-11-22 12:21:46 -08004379 wt.assignLayer(t, j);
4380 wt.assignChildLayers(t);
4381
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004382 int layer = mWmService.mPolicy.getWindowLayerFromTypeLw(
Robert Carree4d4b92017-11-22 12:21:46 -08004383 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08004384
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004385 if (needAssignIme && layer >= mWmService.mPolicy.getWindowLayerFromTypeLw(
Robert Carrb8e78fa2017-11-28 13:07:58 -08004386 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004387 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08004388 needAssignIme = false;
4389 }
4390 }
4391 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004392 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08004393 }
4394 }
4395 }
4396
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004397 /**
4398 * Window container class that contains all containers on this display that are not related to
4399 * Apps. E.g. status bar.
4400 */
Robert Carree4d4b92017-11-22 12:21:46 -08004401 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07004402 /**
4403 * Compares two child window tokens returns -1 if the first is lesser than the second in
4404 * terms of z-order and 1 otherwise.
4405 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004406 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07004407 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004408 mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004409 token1.mOwnerCanManageAppTokens)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004410 < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004411 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004412
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004413 private final Predicate<WindowState> mGetOrientingWindow = w -> {
4414 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
4415 return false;
4416 }
4417 final int req = w.mAttrs.screenOrientation;
4418 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
4419 || req == SCREEN_ORIENTATION_UNSET) {
4420 return false;
4421 }
4422 return true;
4423 };
4424
Wale Ogunwale3a931692016-11-02 16:49:48 -07004425 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08004426 private final Dimmer mDimmer = new Dimmer(this);
4427 private final Rect mTmpDimBoundsRect = new Rect();
4428
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004429 NonAppWindowContainers(String name, WindowManagerService service) {
4430 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07004431 mName = name;
4432 }
4433
4434 void addChild(WindowToken token) {
4435 addChild(token, mWindowComparator);
4436 }
4437
4438 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004439 int getOrientation() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004440 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004441 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004442 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004443
4444 if (win != null) {
4445 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004446 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004447 mLastKeyguardForcedOrientation = req;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004448 if (mWmService.mKeyguardGoingAway) {
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07004449 // Keyguard can't affect the orientation if it is going away...
4450 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
4451 return SCREEN_ORIENTATION_UNSET;
4452 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004453 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004454 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
4455 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08004456 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004457 }
4458
Andrii Kulian8ee72852017-03-10 10:36:45 -08004459 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004460
Jorim Jaggi1c530592018-04-06 15:11:47 +02004461 // Only allow force setting the orientation when all unknown visibilities have been
4462 // resolved, as otherwise we just may be starting another occluding activity.
4463 final boolean isUnoccluding =
lumark588a3e82018-07-20 18:53:54 +08004464 mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
4465 && mUnknownAppVisibilityController.allResolved();
Jorim Jaggi1c530592018-04-06 15:11:47 +02004466 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004467 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004468 }
4469
4470 return SCREEN_ORIENTATION_UNSET;
4471 }
4472
4473 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004474 String getName() {
4475 return mName;
4476 }
chaviwf29223e2018-01-31 13:23:51 -08004477
4478 @Override
4479 Dimmer getDimmer() {
4480 return mDimmer;
4481 }
4482
4483 @Override
4484 void prepareSurfaces() {
4485 mDimmer.resetDimStates();
4486 super.prepareSurfaces();
4487 getBounds(mTmpDimBoundsRect);
4488
4489 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4490 scheduleAnimation();
4491 }
4492 }
Robert Carr3b716242016-08-16 16:02:21 -07004493 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004494
Robert Carr9034d962018-01-04 18:27:42 -08004495 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4496 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4497 super(name, service);
4498 }
4499
4500 @Override
4501 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4502 }
4503 };
4504
Robert Carrb1579c82017-09-05 14:54:47 -07004505 SurfaceControl.Builder makeSurface(SurfaceSession s) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004506 return mWmService.makeSurfaceBuilder(s)
Robert Carrb1579c82017-09-05 14:54:47 -07004507 .setParent(mWindowingLayer);
4508 }
4509
4510 @Override
4511 SurfaceSession getSession() {
4512 return mSession;
4513 }
4514
4515 @Override
4516 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004517 SurfaceSession s = child != null ? child.getSession() : getSession();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004518 final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004519 if (child == null) {
4520 return b;
4521 }
4522
Robert Carree4d4b92017-11-22 12:21:46 -08004523 return b.setName(child.getName())
4524 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004525 }
4526
4527 /**
4528 * The makeSurface variants are for use by the window-container
4529 * hierarchy. makeOverlay here is a function for various non windowing
4530 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4531 * and other potpourii.
4532 */
4533 SurfaceControl.Builder makeOverlay() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004534 return mWmService.makeSurfaceBuilder(mSession)
Robert Carrb1579c82017-09-05 14:54:47 -07004535 .setParent(mOverlayLayer);
4536 }
4537
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004538 /**
4539 * Reparents the given surface to mOverlayLayer.
4540 */
4541 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4542 transaction.reparent(surface, mOverlayLayer.getHandle());
4543 }
4544
Robert Carrb1579c82017-09-05 14:54:47 -07004545 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004546 if (spec.scale != 1.0) {
4547 mMagnificationSpec = spec;
4548 } else {
4549 mMagnificationSpec = null;
4550 }
4551
Robert Carrf59b8dd2017-10-02 18:58:36 -07004552 applyMagnificationSpec(getPendingTransaction(), spec);
4553 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004554 }
4555
Robert Carr24be9ab2018-04-30 17:54:53 -07004556 void reapplyMagnificationSpec() {
4557 if (mMagnificationSpec != null) {
4558 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4559 }
4560 }
4561
Robert Carrb1579c82017-09-05 14:54:47 -07004562 @Override
4563 void onParentSet() {
4564 // Since we are the top of the SurfaceControl hierarchy here
4565 // we create the root surfaces explicitly rather than chaining
4566 // up as the default implementation in onParentSet does. So we
4567 // explicitly do NOT call super here.
4568 }
4569
4570 @Override
4571 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004572
4573 // These are layers as children of "mWindowingLayer"
4574 mBelowAppWindowsContainers.assignLayer(t, 0);
4575 mTaskStackContainers.assignLayer(t, 1);
4576 mAboveAppWindowsContainers.assignLayer(t, 2);
4577
lumarkff0ab692018-11-05 20:32:30 +08004578 final WindowState imeTarget = mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004579 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004580
Robert Carree4d4b92017-11-22 12:21:46 -08004581 // In the case where we have an IME target that is not in split-screen
4582 // mode IME assignment is easy. We just need the IME to go directly above
4583 // the target. This way children of the target will naturally go above the IME
4584 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004585 //
Robert Carree4d4b92017-11-22 12:21:46 -08004586 // In the case of split-screen windowing mode, we need to elevate the IME above the
4587 // docked divider while keeping the app itself below the docked divider, so instead
4588 // we use relative layering of the IME targets child windows, and place the
4589 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004590 //
Robert Carr234b6332018-03-20 13:38:16 -07004591 // In the case the IME target is animating, the animation Z order may be different
4592 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4593 // IME target. In this case we just layer the IME over all transitions by placing it in the
4594 // above applications layer.
4595 //
Robert Carree4d4b92017-11-22 12:21:46 -08004596 // In the case where we have no IME target we assign it where it's base layer would
4597 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004598 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4599 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004600 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004601 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004602 // TODO: We need to use an extra level on the app surface to ensure
4603 // this is always above SurfaceView but always below attached window.
4604 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004605 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004606 }
4607
4608 // Above we have assigned layers to our children, now we ask them to assign
4609 // layers to their children.
4610 mBelowAppWindowsContainers.assignChildLayers(t);
4611 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004612 mAboveAppWindowsContainers.assignChildLayers(t,
4613 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004614 mImeWindowsContainers.assignChildLayers(t);
4615 }
4616
4617 /**
4618 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4619 * that the IME target is one of the docked applications. We'd like the docked divider to be
4620 * above both of the applications, and we'd like the IME to be above the docked divider.
4621 * However we need child windows of the applications to be above the IME (Text drag handles).
4622 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4623 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
Tiger Huang7c610aa2018-10-27 00:01:01 +08004624 * with {@link WindowState#assignLayer}
Robert Carrb1579c82017-09-05 14:54:47 -07004625 */
4626 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004627 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004628 }
4629
4630 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004631 void prepareSurfaces() {
4632 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004633 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004634 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4635 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4636 mPendingTransaction.setMatrix(mWindowingLayer,
4637 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4638 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4639 mPendingTransaction.setPosition(mWindowingLayer,
4640 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4641 mPendingTransaction.setAlpha(mWindowingLayer,
4642 screenRotationAnimation.getEnterTransformation().getAlpha());
4643 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004644
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004645 super.prepareSurfaces();
4646 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004647
Jorim Jaggibe418292018-03-26 16:14:12 +02004648 void assignStackOrdering() {
4649 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004650 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004651
4652 /**
4653 * Increment the deferral count to determine whether to update the IME target.
4654 */
4655 void deferUpdateImeTarget() {
4656 mDeferUpdateImeTargetCount++;
4657 }
4658
4659 /**
4660 * Decrement the deferral count to determine whether to update the IME target. If the count
4661 * reaches 0, a new ime target will get computed.
4662 */
4663 void continueUpdateImeTarget() {
4664 if (mDeferUpdateImeTargetCount == 0) {
4665 return;
4666 }
4667
4668 mDeferUpdateImeTargetCount--;
4669 if (mDeferUpdateImeTargetCount == 0) {
4670 computeImeTarget(true /* updateImeTarget */);
4671 }
4672 }
4673
4674 /**
4675 * @return Whether a new IME target should be computed.
4676 */
4677 private boolean canUpdateImeTarget() {
4678 return mDeferUpdateImeTargetCount == 0;
4679 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004680
4681 InputMonitor getInputMonitor() {
4682 return mInputMonitor;
4683 }
Jorim Jaggif1292892018-09-10 11:58:13 +02004684
4685 /**
4686 * @return Cached value whether we told display manager that we have content.
4687 */
4688 boolean getLastHasContent() {
4689 return mLastHasContent;
4690 }
Arthur Hungbe5ce212018-09-13 18:41:56 +08004691
4692 void registerPointerEventListener(@NonNull PointerEventListener listener) {
4693 if (mPointerEventDispatcher != null) {
4694 mPointerEventDispatcher.registerInputEventListener(listener);
4695 }
4696 }
4697
4698 void unregisterPointerEventListener(@NonNull PointerEventListener listener) {
4699 if (mPointerEventDispatcher != null) {
4700 mPointerEventDispatcher.unregisterInputEventListener(listener);
4701 }
4702 }
lumark588a3e82018-07-20 18:53:54 +08004703
4704 void prepareAppTransition(@WindowManager.TransitionType int transit,
Wale Ogunwale3a256e62018-12-06 14:41:18 -08004705 boolean alwaysKeepCurrent) {
4706 prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */);
4707 }
4708
4709 void prepareAppTransition(@WindowManager.TransitionType int transit,
lumark588a3e82018-07-20 18:53:54 +08004710 boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags,
4711 boolean forceOverride) {
4712 final boolean prepared = mAppTransition.prepareAppTransitionLocked(
4713 transit, alwaysKeepCurrent, flags, forceOverride);
4714 if (prepared && okToAnimate()) {
4715 mSkipAppTransitionAnimation = false;
4716 }
4717 }
4718
4719 void executeAppTransition() {
4720 if (mAppTransition.isTransitionSet()) {
4721 if (DEBUG_APP_TRANSITIONS) {
4722 Slog.w(TAG_WM, "Execute app transition: " + mAppTransition + ", displayId: "
4723 + mDisplayId + " Callers=" + Debug.getCallers(5));
4724 }
4725 mAppTransition.setReady();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004726 mWmService.mWindowPlacerLocked.requestTraversal();
lumark588a3e82018-07-20 18:53:54 +08004727 }
4728 }
4729
4730 /**
4731 * Update pendingLayoutChanges after app transition has finished.
4732 */
4733 void handleAnimatingStoppedAndTransition() {
4734 int changes = 0;
4735
4736 mAppTransition.setIdle();
4737
4738 for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) {
4739 final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i);
4740 mAppTransition.notifyAppTransitionFinishedLocked(token);
4741 }
4742 mNoAnimationNotifyOnTransitionFinished.clear();
4743
4744 mWallpaperController.hideDeferredWallpapersIfNeeded();
4745
4746 onAppTransitionDone();
4747
4748 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4749 if (DEBUG_WALLPAPER_LIGHT) {
4750 Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout");
4751 }
4752 computeImeTarget(true /* updateImeTarget */);
wilsonshihc32538e2018-11-07 17:27:34 +08004753 mWallpaperMayChange = true;
lumark588a3e82018-07-20 18:53:54 +08004754 // Since the window list has been rebuilt, focus might have to be recomputed since the
4755 // actual order of windows might have changed again.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004756 mWmService.mFocusMayChange = true;
lumark588a3e82018-07-20 18:53:54 +08004757
4758 pendingLayoutChanges |= changes;
4759 }
Andrii Kulian15cfb422018-11-07 13:38:49 -08004760
Wale Ogunwale3a256e62018-12-06 14:41:18 -08004761 /** Check if pending app transition is for activity / task launch. */
4762 boolean isNextTransitionForward() {
4763 final int transit = mAppTransition.getAppTransition();
4764 return transit == TRANSIT_ACTIVITY_OPEN
4765 || transit == TRANSIT_TASK_OPEN
4766 || transit == TRANSIT_TASK_TO_FRONT;
4767 }
4768
Andrii Kulian15cfb422018-11-07 13:38:49 -08004769 /**
4770 * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
4771 */
4772 boolean supportsSystemDecorations() {
4773 // TODO(b/114338689): Read the setting from DisplaySettings.
4774 return mDisplay.supportsSystemDecorations()
4775 // TODO (b/111363427): Remove this and set the new FLAG_SHOULD_SHOW_LAUNCHER flag
4776 // (b/114338689) whenever vr 2d display id is set.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004777 || mDisplayId == mWmService.mVr2dDisplayId
4778 || mWmService.mForceDesktopModeOnExternalDisplays;
Andrii Kulian15cfb422018-11-07 13:38:49 -08004779 }
chaviwff2e7d82018-11-02 11:11:27 -07004780
4781 /**
4782 * Re-parent the DisplayContent's top surfaces, {@link #mWindowingLayer} and
4783 * {@link #mOverlayLayer} to the specified surfaceControl.
4784 *
4785 * @param surfaceControlHandle The handle for the new SurfaceControl, where the DisplayContent's
4786 * surfaces will be re-parented to.
4787 */
4788 void reparentDisplayContent(IBinder surfaceControlHandle) {
4789 mPendingTransaction.reparent(mWindowingLayer, surfaceControlHandle)
4790 .reparent(mOverlayLayer, surfaceControlHandle);
4791 }
Craig Mautner59c00972012-07-30 12:10:24 -07004792}