blob: ae76740b5d26ecfdebd0b1cd335da694b94b793b [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;
Tarandeep Singh215929b2019-01-11 18:24:37 -080023import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070024import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
25import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070027import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
28import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale687b4272017-07-27 02:56:23 -070029import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
30import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070031import static android.view.Display.DEFAULT_DISPLAY;
32import static android.view.Display.FLAG_PRIVATE;
Tiger Huang04dc4cc2019-01-17 18:41:41 +080033import static android.view.Display.INVALID_DISPLAY;
chaviwff2e7d82018-11-02 11:11:27 -070034import static android.view.InsetsState.TYPE_IME;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070035import static android.view.Surface.ROTATION_0;
36import static android.view.Surface.ROTATION_180;
37import static android.view.Surface.ROTATION_270;
38import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070039import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070040import static android.view.WindowManager.DOCKED_BOTTOM;
41import static android.view.WindowManager.DOCKED_INVALID;
42import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080043import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
44import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
45import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070046import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070047import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Tiger Huang04dc4cc2019-01-17 18:41:41 +080048import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070049import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
50import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070051import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070052import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070053import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070054import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080055import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070056import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070057import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070058import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
59import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070060import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070061import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
62import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070063import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070064import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale3a256e62018-12-06 14:41:18 -080065import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080066import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
Wale Ogunwale3a256e62018-12-06 14:41:18 -080067import static android.view.WindowManager.TRANSIT_TASK_OPEN;
68import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Tiger Huang51c5a1d2018-12-11 20:24:51 +080069
Adrian Roose99bc052017-11-20 17:55:31 +010070import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
71import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
72import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
73import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080074import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS;
lumark588a3e82018-07-20 18:53:54 +080075import static com.android.server.wm.DisplayContentProto.APP_TRANSITION;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080076import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS;
77import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES;
78import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO;
79import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER;
80import static com.android.server.wm.DisplayContentProto.DPI;
Tiger Huang1e5b10a2018-07-30 20:19:51 +080081import static com.android.server.wm.DisplayContentProto.FOCUSED_APP;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080082import static com.android.server.wm.DisplayContentProto.ID;
83import static com.android.server.wm.DisplayContentProto.IME_WINDOWS;
84import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER;
85import static com.android.server.wm.DisplayContentProto.ROTATION;
86import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION;
87import static com.android.server.wm.DisplayContentProto.STACKS;
88import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
lumark588a3e82018-07-20 18:53:54 +080090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwale494009b82016-10-21 09:01:38 -070091import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070096import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070097import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020098import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070099import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -0700101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700104import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700105import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700106import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800107import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700108import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Tiger Huang51c5a1d2018-12-11 20:24:51 +0800109import static com.android.server.wm.WindowManagerService.H.REPORT_FOCUS_CHANGE;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800110import static com.android.server.wm.WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800111import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700112import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
113import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700114import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700115import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700116import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
117import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800118import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
119import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
120import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700121import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700122import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700123import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700124import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700125import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700126import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700127import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700128import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700129import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700130
lumark588a3e82018-07-20 18:53:54 +0800131import android.animation.AnimationHandler;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700132import android.annotation.CallSuper;
Riddle Hsuf53da812018-08-15 22:00:27 +0800133import android.annotation.IntDef;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700134import android.annotation.NonNull;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200135import android.annotation.Nullable;
Dean Harding3e5a1522017-10-06 09:19:01 -0700136import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700137import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700138import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700139import android.graphics.Bitmap;
Issei Suzukia5dbf522019-02-01 17:58:15 +0100140import android.graphics.Insets;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700141import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800142import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700143import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700144import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100145import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700146import android.hardware.display.DisplayManagerInternal;
Susi Kharraz-Post9893b8c2019-02-12 14:21:29 -0500147import android.metrics.LogMaker;
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800148import android.os.Binder;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700149import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700150import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700151import android.os.IBinder;
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800152import android.os.Process;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700153import android.os.RemoteException;
154import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100155import android.os.Trace;
Riddle Hsuf53da812018-08-15 22:00:27 +0800156import android.os.UserHandle;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800157import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700158import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700159import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700160import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700161import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100162import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700163import android.view.DisplayInfo;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800164import android.view.Gravity;
Arthur Hungbe5ce212018-09-13 18:41:56 +0800165import android.view.InputChannel;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700166import android.view.InputDevice;
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800167import android.view.InputWindowHandle;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200168import android.view.InsetsState.InternalInsetType;
Robert Carrb1579c82017-09-05 14:54:47 -0700169import android.view.MagnificationSpec;
Evan Rosky966759f2019-01-15 10:33:58 -0800170import android.view.RemoteAnimationDefinition;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700171import android.view.Surface;
172import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100173import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700174import android.view.SurfaceSession;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800175import android.view.View;
lumark588a3e82018-07-20 18:53:54 +0800176import android.view.WindowManager;
Evan Rosky39b6f232018-10-30 18:35:41 -0700177import android.view.WindowManagerPolicyConstants.PointerEventListener;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700178
Bryce Lee48f4b572017-04-10 10:54:15 -0700179import com.android.internal.annotations.VisibleForTesting;
Susi Kharraz-Post9893b8c2019-02-12 14:21:29 -0500180import com.android.internal.logging.MetricsLogger;
181import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800182import com.android.internal.util.ToBooleanFunction;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200183import com.android.internal.util.function.TriConsumer;
Winson Chung6ba767a2018-12-13 18:20:11 -0800184import com.android.server.AnimationThread;
Adrian Roose99bc052017-11-20 17:55:31 +0100185import com.android.server.policy.WindowManagerPolicy;
Issei Suzuki43190bd2018-08-20 17:28:41 +0200186import com.android.server.wm.utils.DisplayRotationUtil;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100187import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100188import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700189
190import java.io.PrintWriter;
Riddle Hsuf53da812018-08-15 22:00:27 +0800191import java.lang.annotation.Retention;
192import java.lang.annotation.RetentionPolicy;
Craig Mautner59c00972012-07-30 12:10:24 -0700193import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700194import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700195import java.util.HashMap;
196import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700197import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700198import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100199import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800200import java.util.function.Consumer;
201import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700202
Craig Mautner59c00972012-07-30 12:10:24 -0700203/**
204 * Utility class for keeping track of the WindowStates and other pertinent contents of a
205 * particular Display.
Craig Mautner59c00972012-07-30 12:10:24 -0700206 */
Riddle Hsuad256a12018-07-18 16:11:30 +0800207class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
208 implements WindowManagerPolicy.DisplayContentInfo {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700209 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700210
Riddle Hsuf53da812018-08-15 22:00:27 +0800211 /** The default scaling mode that scales content automatically. */
212 static final int FORCE_SCALING_MODE_AUTO = 0;
213 /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */
214 static final int FORCE_SCALING_MODE_DISABLED = 1;
215
216 @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = {
217 FORCE_SCALING_MODE_AUTO,
218 FORCE_SCALING_MODE_DISABLED
219 })
220 @Retention(RetentionPolicy.SOURCE)
221 @interface ForceScalingMode {}
222
Craig Mautner59c00972012-07-30 12:10:24 -0700223 /** Unique identifier of this stack. */
224 private final int mDisplayId;
225
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800226 // TODO: Remove once unification is complete.
227 ActivityDisplay mAcitvityDisplay;
228
Wale Ogunwale3a931692016-11-02 16:49:48 -0700229 /** The containers below are the only child containers the display can have. */
230 // Contains all window containers that are related to apps (Activities)
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800231 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700232 // Contains all non-app window containers that should be displayed above the app containers
233 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800234 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800235 new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700236 // Contains all non-app window containers that should be displayed below the app containers
237 // (e.g. Wallpaper).
238 private final NonAppWindowContainers mBelowAppWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800239 new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700240 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
241 // 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 -0800242 // window containers together and move them in-sync if/when needed. We use a subclass of
243 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
244 private final NonMagnifiableWindowContainers mImeWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800245 new NonMagnifiableWindowContainers("mImeWindowsContainers", mWmService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700246
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000247 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800248 private WindowState mTmpWindow2;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800249 private boolean mTmpRecoveringMemory;
250 private boolean mUpdateImeTarget;
251 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700252 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700253
lumark588a3e82018-07-20 18:53:54 +0800254 final AppTransition mAppTransition;
255 final AppTransitionController mAppTransitionController;
256 boolean mSkipAppTransitionAnimation = false;
257
258 final ArraySet<AppWindowToken> mOpeningApps = new ArraySet<>();
259 final ArraySet<AppWindowToken> mClosingApps = new ArraySet<>();
Evan Rosky2289ba12018-11-19 18:28:18 -0800260 final ArraySet<AppWindowToken> mChangingApps = new ArraySet<>();
lumark588a3e82018-07-20 18:53:54 +0800261 final UnknownAppVisibilityController mUnknownAppVisibilityController;
262 BoundsAnimationController mBoundsAnimationController;
263
Susi Kharraz-Post9893b8c2019-02-12 14:21:29 -0500264 private MetricsLogger mMetricsLogger;
265
lumark588a3e82018-07-20 18:53:54 +0800266 /**
267 * List of clients without a transtiton animation that we notify once we are done
268 * transitioning since they won't be notified through the app window animator.
269 */
270 final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>();
271
Wale Ogunwale02319a62016-09-26 15:21:22 -0700272 // Mapping from a token IBinder to a WindowToken object on this display.
273 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
274
Andrii Kuliancd097992017-03-23 18:31:59 -0700275 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700276 int mInitialDisplayWidth = 0;
277 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700278 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700279
Adrian Roos1cf585052018-01-03 18:43:27 +0100280 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100281 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100282 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100283
Andrii Kuliancd097992017-03-23 18:31:59 -0700284 /**
285 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
286 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
287 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
288 */
Craig Mautner59c00972012-07-30 12:10:24 -0700289 int mBaseDisplayWidth = 0;
290 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700291 /**
292 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
293 * but can be set from Settings or via shell command "adb shell wm density".
294 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
295 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700296 int mBaseDisplayDensity = 0;
Riddle Hsuf53da812018-08-15 22:00:27 +0800297
298 /**
299 * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling".
300 * @see WindowManagerService#setForcedDisplayScalingMode(int, int)
301 */
Jeff Brownd46747a2015-04-15 19:02:36 -0700302 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700303 private final DisplayInfo mDisplayInfo = new DisplayInfo();
304 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700305 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800306 private final DisplayPolicy mDisplayPolicy;
307 private DisplayRotation mDisplayRotation;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000308 DisplayFrames mDisplayFrames;
309
Andrii Kulian06d07d62017-03-14 11:11:47 -0700310 /**
311 * For default display it contains real metrics, empty for others.
312 * @see WindowManagerService#createWatermarkInTransaction()
313 */
314 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800315
316 /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */
Andrii Kulian06d07d62017-03-14 11:11:47 -0700317 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700318
Andrii Kulian06d07d62017-03-14 11:11:47 -0700319 /**
320 * Compat metrics computed based on {@link #mDisplayMetrics}.
321 * @see #updateDisplayAndOrientation(int)
322 */
323 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
324
325 /** The desired scaling factor for compatible apps. */
326 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700327
Andrii Kulian8ee72852017-03-10 10:36:45 -0800328 /**
329 * Current rotation of the display.
330 * Constants as per {@link android.view.Surface.Rotation}.
331 *
Robert Carrae606b42018-02-15 15:36:23 -0800332 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800333 */
334 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700335
Andrii Kulian8ee72852017-03-10 10:36:45 -0800336 /**
337 * Last applied orientation of the display.
338 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
339 *
Riddle Hsu4e611772018-10-31 18:58:28 +0800340 * @see #updateOrientationFromAppTokens()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800341 */
342 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700343
Andrii Kulian8ee72852017-03-10 10:36:45 -0800344 /**
Andrii Kulian8ee72852017-03-10 10:36:45 -0800345 * Orientation forced by some window. If there is no visible window that specifies orientation
346 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
347 *
348 * @see NonAppWindowContainers#getOrientation()
349 */
350 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700351
Andrii Kulian8ee72852017-03-10 10:36:45 -0800352 /**
353 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
354 * occluded.
355 *
356 * @see NonAppWindowContainers#getOrientation()
357 */
358 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
359
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700360 /**
361 * Keep track of wallpaper visibility to notify changes.
362 */
363 private boolean mLastWallpaperVisible = false;
364
Andrii Kulian06d07d62017-03-14 11:11:47 -0700365 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700366
Craig Mautner39834192012-09-02 07:47:24 -0700367 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700368 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700369 int pendingLayoutChanges;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800370 int mDeferredRotationPauseCount;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800371
Vishnu Nairba183352018-11-21 11:16:49 -0800372 /**
373 * Used to gate application window layout until we have sent the complete configuration.
374 * TODO: There are still scenarios where we may be out of sync with the client. Ideally
375 * we want to replace this flag with a mechanism that will confirm the configuration
376 * applied by the client is the one expected by the system server.
377 */
378 boolean mWaitingForConfig;
379
Andrii Kulian839def92016-11-02 10:58:58 -0700380 // TODO(multi-display): remove some of the usages.
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800381 @VisibleForTesting
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800382 boolean isDefaultDisplay;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800383
Andrii Kulianf0379de2018-03-14 16:24:07 -0700384 /**
385 * Flag indicating whether WindowManager should override info for this display in
386 * DisplayManager.
387 */
388 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700389
Craig Mautnerdc548482014-02-05 13:35:24 -0800390 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700391 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800392
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700393 /** Detect user tapping outside of current focused task bounds .*/
394 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700395
Craig Mautner6601b7b2013-04-29 10:29:11 -0700396 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700397 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700398
Craig Mautner6601b7b2013-04-29 10:29:11 -0700399 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800400 private final Rect mTmpRect = new Rect();
401 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700402 private final RectF mTmpRectF = new RectF();
403 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800404 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700405
Bryce Leef3c6a472017-11-14 14:53:06 -0800406 /** Used for handing back size of display */
407 private final Rect mTmpBounds = new Rect();
408
Garfield Tan90b04282018-12-11 14:04:42 -0800409 private final Configuration mTmpConfiguration = new Configuration();
410
Craig Mautner95da1082014-02-24 17:54:35 -0800411 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700412 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800413
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700414 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700415 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700416
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800417 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800418 /** A collection of windows that provide tap exclude regions inside of them. */
419 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800420
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000421 private boolean mHaveBootMsg = false;
422 private boolean mHaveApp = false;
423 private boolean mHaveWallpaper = false;
424 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700425
426 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
427
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700428 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
429 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000430 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
431 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700432
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700433 // True if this display is in the process of being removed. Used to determine if the removal of
434 // the display's direct children should be allowed.
435 private boolean mRemovingDisplay = false;
436
Bryce Leed1871262017-06-12 14:12:29 -0700437 // {@code false} if this display is in the processing of being created.
438 private boolean mDisplayReady = false;
439
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800440 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700441
wilsonshihc32538e2018-11-07 17:27:34 +0800442 boolean mWallpaperMayChange = false;
443
Robert Carrb1579c82017-09-05 14:54:47 -0700444 private final SurfaceSession mSession = new SurfaceSession();
445
446 /**
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800447 * Window that is currently interacting with the user. This window is responsible for receiving
448 * key events and pointer events from the user.
449 */
450 WindowState mCurrentFocus = null;
451
452 /**
453 * The last focused window that we've notified the client that the focus is changed.
454 */
455 WindowState mLastFocus = null;
456
457 /**
458 * Windows that have lost input focus and are waiting for the new focus window to be displayed
459 * before they are told about this.
460 */
461 ArrayList<WindowState> mLosingFocus = new ArrayList<>();
462
463 /**
464 * The foreground app of this display. Windows below this app cannot be the focused window. If
465 * the user taps on the area outside of the task of the focused app, we will notify AM about the
466 * new task the user wants to interact with.
467 */
468 AppWindowToken mFocusedApp = null;
469
470 /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
471 final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>();
472
473 /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
474 final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>();
475
476 /**
Robert Carrb1579c82017-09-05 14:54:47 -0700477 * We organize all top-level Surfaces in to the following layers.
478 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800479 * and omitted from Screen-Magnification, for example the strict mode flash or
480 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700481 * {@link #mWindowingLayer} contains everything else.
482 */
483 private SurfaceControl mOverlayLayer;
484
485 /**
486 * See {@link #mOverlayLayer}
487 */
488 private SurfaceControl mWindowingLayer;
489
490 /**
Adrian Roos5251b1d2018-03-23 18:57:43 +0100491 * Sequence number for the current layout pass.
492 */
493 int mLayoutSeq = 0;
494
Chavi Weingarten3a748552018-05-14 17:32:42 +0000495 /**
496 * Specifies the count to determine whether to defer updating the IME target until ready.
497 */
498 private int mDeferUpdateImeTargetCount;
499
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100500 /** Temporary float array to retrieve 3x3 matrix values. */
501 private final float[] mTmpFloats = new float[9];
502
Robert Carr24be9ab2018-04-30 17:54:53 -0700503 private MagnificationSpec mMagnificationSpec;
504
Arthur Hung95b38a92018-07-20 18:56:12 +0800505 private InputMonitor mInputMonitor;
506
Jorim Jaggif1292892018-09-10 11:58:13 +0200507 /** Caches the value whether told display manager that we have content. */
508 private boolean mLastHasContent;
509
Issei Suzuki43190bd2018-08-20 17:28:41 +0200510 private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil();
511
lumark90120a82018-08-15 00:33:03 +0800512 /**
513 * The input method window for this display.
514 */
515 WindowState mInputMethodWindow;
516
lumarkff0ab692018-11-05 20:32:30 +0800517 /**
518 * This just indicates the window the input method is on top of, not
519 * necessarily the window its input is going to.
520 */
521 WindowState mInputMethodTarget;
522
523 /** If true hold off on modifying the animation layer of mInputMethodTarget */
524 boolean mInputMethodTargetWaitingAnim;
525
Arthur Hungbe5ce212018-09-13 18:41:56 +0800526 private final PointerEventDispatcher mPointerEventDispatcher;
527
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200528 private final InsetsStateController mInsetsStateController;
529
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800530 private SurfaceControl mParentSurfaceControl;
531 private InputWindowHandle mPortalWindowHandle;
532
Tiger Huang7c610aa2018-10-27 00:01:01 +0800533 // Last systemUiVisibility we received from status bar.
534 private int mLastStatusBarVisibility = 0;
535 // Last systemUiVisibility we dispatched to windows.
536 private int mLastDispatchedSystemUiVisibility = 0;
537
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800538 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
539 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800540 final AppWindowToken atoken = w.mAppToken;
541 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200542 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800543 if (w.performShowLocked()) {
544 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
545 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800546 mWmService.mWindowPlacerLocked.debugLayoutRepeats(
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800547 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
548 }
549 }
550 }
551 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800552 };
553
554 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
555 final WindowStateAnimator winAnimator = w.mWinAnimator;
556 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
557 return;
558 }
559
Jorim Jaggi8f520872018-08-14 17:00:20 +0200560 // If this window is animating, ensure the animation background is set.
561 final AnimationAdapter anim = w.mAppToken != null
562 ? w.mAppToken.getAnimation()
563 : w.getAnimation();
564 if (anim != null) {
565 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800566 if (color != 0) {
567 final TaskStack stack = w.getStack();
568 if (stack != null) {
569 stack.setAnimationBackground(winAnimator, color);
570 }
571 }
572 }
573 };
574
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800575 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
576 final int lostFocusUid = mTmpWindow.mOwnerUid;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800577 final Handler handler = mWmService.mH;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800578 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
579 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
580 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
581 w.mAttrs.hideTimeoutMilliseconds);
582 }
583 }
584 };
585
586 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800587 final AppWindowToken focusedApp = mFocusedApp;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800588 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
589 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
590
591 if (!w.canReceiveKeys()) {
592 return false;
593 }
594
595 final AppWindowToken wtoken = w.mAppToken;
596
597 // If this window's application has been removed, just skip it.
598 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
599 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
600 + (wtoken.removed ? "removed" : "sendingToBottom"));
601 return false;
602 }
603
604 if (focusedApp == null) {
605 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
606 + " using new focus @ " + w);
607 mTmpWindow = w;
608 return true;
609 }
610
611 if (!focusedApp.windowsAreFocusable()) {
612 // Current focused app windows aren't focusable...
613 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
614 + " focusable using new focus @ " + w);
615 mTmpWindow = w;
616 return true;
617 }
618
619 // Descend through all of the app tokens and find the first that either matches
620 // win.mAppToken (return win) or mFocusedApp (return null).
621 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
622 if (focusedApp.compareTo(wtoken) > 0) {
623 // App stack below focused app stack. No focus for you!!!
624 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
625 "findFocusedWindow: Reached focused app=" + focusedApp);
626 mTmpWindow = null;
627 return true;
628 }
629 }
630
631 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
632 mTmpWindow = w;
633 return true;
634 };
635
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800636 private final Consumer<WindowState> mPerformLayout = w -> {
637 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
638 // wasting time and funky changes while a window is animating away.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800639 final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w))
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800640 || w.isGoneForLayoutLw();
641
642 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
643 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
644 + " mLayoutAttached=" + w.mLayoutAttached
645 + " screen changed=" + w.isConfigChanged());
646 final AppWindowToken atoken = w.mAppToken;
647 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200648 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800649 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
650 + " parentHidden=" + w.isParentWindowHidden());
651 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200652 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800653 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
654 + " parentHidden=" + w.isParentWindowHidden());
655 }
656
657 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
658 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
659 // since that means "perform layout as normal, just don't display").
660 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
661 || ((w.isConfigChanged() || w.setReportResizeHints())
662 && !w.isGoneForLayoutLw() &&
663 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
664 (w.mHasSurface && w.mAppToken != null &&
665 w.mAppToken.layoutConfigChanges)))) {
666 if (!w.mLayoutAttached) {
667 if (mTmpInitial) {
668 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700669 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800670 }
671 if (w.mAttrs.type == TYPE_DREAM) {
672 // Don't layout windows behind a dream, so that if it does stuff like hide
673 // the status bar we won't get a bad transition when it goes away.
674 mTmpWindow = w;
675 }
676 w.mLayoutNeeded = false;
677 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200678 final boolean firstLayout = !w.isLaidOut();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800679 getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100680 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800681
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200682 // If this is the first layout, we need to initialize the last inset values as
683 // otherwise we'd immediately cause an unnecessary resize.
684 if (firstLayout) {
685 w.updateLastInsetValues();
686 }
687
Adrian Roos23df3a32018-03-15 15:41:13 +0100688 if (w.mAppToken != null) {
689 w.mAppToken.layoutLetterbox(w);
690 }
691
chaviw492139a2018-07-16 16:07:35 -0700692 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700693 + " mContainingFrame=" + w.getContainingFrame()
694 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800695 }
696 }
697 };
698
699 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
700 if (w.mLayoutAttached) {
701 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
702 + " mViewVisibility=" + w.mViewVisibility
703 + " mRelayoutCalled=" + w.mRelayoutCalled);
704 // If this view is GONE, then skip it -- keep the current frame, and let the caller
705 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
706 // windows, since that means "perform layout as normal, just don't display").
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800707 if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800708 return;
709 }
710 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
711 || w.mLayoutNeeded) {
712 if (mTmpInitial) {
713 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700714 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800715 }
716 w.mLayoutNeeded = false;
717 w.prelayout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800718 getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100719 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700720 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700721 + " mContainingFrame=" + w.getContainingFrame()
722 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800723 }
724 } else if (w.mAttrs.type == TYPE_DREAM) {
725 // Don't layout windows behind a dream, so that if it does stuff like hide the
726 // status bar we won't get a bad transition when it goes away.
727 mTmpWindow = mTmpWindow2;
728 }
729 };
730
731 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
732 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
733 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
734 return w.canBeImeTarget();
735 };
736
737 private final Consumer<WindowState> mApplyPostLayoutPolicy =
Tiger Huang7c610aa2018-10-27 00:01:01 +0800738 w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
lumarkff0ab692018-11-05 20:32:30 +0800739 mInputMethodTarget);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800740
741 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800742 final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800743 final boolean obscuredChanged = w.mObscured !=
744 mTmpApplySurfaceChangesTransactionState.obscured;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800745 final RootWindowContainer root = mWmService.mRoot;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800746
747 // Update effect.
748 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
749 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
750 final boolean isDisplayed = w.isDisplayedLw();
751
752 if (isDisplayed && w.isObscuringDisplay()) {
753 // This window completely covers everything behind it, so we want to leave all
754 // of them as undimmed (for performance reasons).
755 root.mObscuringWindow = w;
756 mTmpApplySurfaceChangesTransactionState.obscured = true;
757 }
758
759 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
760 root.handleNotObscuredLocked(w,
761 mTmpApplySurfaceChangesTransactionState.obscured,
762 mTmpApplySurfaceChangesTransactionState.syswin);
763
764 if (w.mHasSurface && isDisplayed) {
765 final int type = w.mAttrs.type;
766 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
767 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
768 mTmpApplySurfaceChangesTransactionState.syswin = true;
769 }
770 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
771 && w.mAttrs.preferredRefreshRate != 0) {
772 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
773 = w.mAttrs.preferredRefreshRate;
774 }
775 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
776 && w.mAttrs.preferredDisplayModeId != 0) {
777 mTmpApplySurfaceChangesTransactionState.preferredModeId
778 = w.mAttrs.preferredDisplayModeId;
779 }
780 }
781 }
782
wilsonshihc32538e2018-11-07 17:27:34 +0800783 if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800784 // This is the wallpaper target and its obscured state changed... make sure the
785 // current wallpaper's visibility has been updated accordingly.
786 mWallpaperController.updateWallpaperVisibility();
787 }
788
chaviw161ea3e2018-01-31 12:01:12 -0800789 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800790
791 final WindowStateAnimator winAnimator = w.mWinAnimator;
792
793 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
chaviw1454b392018-08-06 09:54:04 -0700794 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800795
796 // Moved from updateWindowsAndWallpaperLocked().
797 if (w.mHasSurface) {
798 // Take care of the window being ready to display.
799 final boolean committed = winAnimator.commitFinishDrawingLocked();
800 if (isDefaultDisplay && committed) {
801 if (w.mAttrs.type == TYPE_DREAM) {
802 // HACK: When a dream is shown, it may at that point hide the lock screen.
803 // So we need to redo the layout to let the phone window manager make this
804 // happen.
805 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
806 if (DEBUG_LAYOUT_REPEATS) {
807 surfacePlacer.debugLayoutRepeats(
808 "dream and commitFinishDrawingLocked true",
809 pendingLayoutChanges);
810 }
811 }
812 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
813 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
814 "First draw done in potential wallpaper target " + w);
wilsonshihc32538e2018-11-07 17:27:34 +0800815 mWallpaperMayChange = true;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800816 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
817 if (DEBUG_LAYOUT_REPEATS) {
818 surfacePlacer.debugLayoutRepeats(
819 "wallpaper and commitFinishDrawingLocked true",
820 pendingLayoutChanges);
821 }
822 }
823 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800824 }
825
826 final AppWindowToken atoken = w.mAppToken;
827 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100828 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800829 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
830 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
831 mTmpUpdateAllDrawn.add(atoken);
832 }
833 }
834
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800835 if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800836 mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800837 }
838
839 w.updateResizingWindowIfNeeded();
840 };
841
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800842 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800843 * Create new {@link DisplayContent} instance, add itself to the root window container and
844 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700845 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800846 * @param service You know.
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800847 * @param activityDisplay The ActivityDisplay for the display container.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700848 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700849 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800850 ActivityDisplay activityDisplay) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100851 super(service);
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800852 mAcitvityDisplay = activityDisplay;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800853 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
854 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
855 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
856 + " new=" + display);
857 }
858
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700859 mDisplay = display;
860 mDisplayId = display.getDisplayId();
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800861 mWallpaperController = new WallpaperController(mWmService, this);
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700862 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700863 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700864 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100865 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
866 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700867 initializeDisplayBaseInfo();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700868
lumark588a3e82018-07-20 18:53:54 +0800869 mAppTransition = new AppTransition(service.mContext, service, this);
870 mAppTransition.registerListenerLocked(service.mActivityManagerAppTransitionNotifier);
871 mAppTransitionController = new AppTransitionController(service, this);
872 mUnknownAppVisibilityController = new UnknownAppVisibilityController(service, this);
873
874 AnimationHandler animationHandler = new AnimationHandler();
875 mBoundsAnimationController = new BoundsAnimationController(service.mContext,
Winson Chung6ba767a2018-12-13 18:20:11 -0800876 mAppTransition, AnimationThread.getHandler(), animationHandler);
lumark588a3e82018-07-20 18:53:54 +0800877
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800878 if (mWmService.mInputManager != null) {
879 final InputChannel inputChannel = mWmService.mInputManager.monitorInput("Display "
Tiger Huang7c610aa2018-10-27 00:01:01 +0800880 + mDisplayId, mDisplayId);
881 mPointerEventDispatcher = inputChannel != null
882 ? new PointerEventDispatcher(inputChannel) : null;
883 } else {
884 mPointerEventDispatcher = null;
885 }
886 mDisplayPolicy = new DisplayPolicy(service, this);
887 mDisplayRotation = new DisplayRotation(service, this);
888 if (isDefaultDisplay) {
889 // The policy may be invoked right after here, so it requires the necessary default
890 // fields of this display content.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800891 mWmService.mPolicy.setDefaultDisplay(this);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800892 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800893 if (mWmService.mDisplayReady) {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800894 mDisplayPolicy.onConfigurationChanged();
895 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800896 if (mWmService.mSystemReady) {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800897 mDisplayPolicy.systemReady();
898 }
899 mDividerControllerLocked = new DockedStackDividerController(service, this);
900 mPinnedStackControllerLocked = new PinnedStackController(service, this);
901
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +0000902 final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(mSession)
903 .setOpaque(true)
904 .setContainerLayer();
Robert Carrb1579c82017-09-05 14:54:47 -0700905 mWindowingLayer = b.setName("Display Root").build();
906 mOverlayLayer = b.setName("Display Overlays").build();
907
Robert Carrf59b8dd2017-10-02 18:58:36 -0700908 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700909 .setLayerStack(mWindowingLayer, mDisplayId)
910 .show(mWindowingLayer)
911 .setLayer(mOverlayLayer, 1)
912 .setLayerStack(mOverlayLayer, mDisplayId)
913 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700914 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700915
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700916 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700917 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700918 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700919 super.addChild(mAboveAppWindowsContainers, null);
920 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800921
922 // Add itself as a child to the root container.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800923 mWmService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700924
925 // TODO(b/62541591): evaluate whether this is the best spot to declare the
926 // {@link DisplayContent} ready for use.
927 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800928
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800929 mWmService.mAnimator.addDisplayLocked(mDisplayId);
Arthur Hung39134b22018-08-14 11:58:28 +0800930 mInputMonitor = new InputMonitor(service, mDisplayId);
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200931 mInsetsStateController = new InsetsStateController(this);
Bryce Leed1871262017-06-12 14:12:29 -0700932 }
933
934 boolean isReady() {
935 // The display is ready when the system and the individual display are both ready.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800936 return mWmService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700937 }
938
939 int getDisplayId() {
940 return mDisplayId;
941 }
942
Wale Ogunwale02319a62016-09-26 15:21:22 -0700943 WindowToken getWindowToken(IBinder binder) {
944 return mTokenMap.get(binder);
945 }
946
947 AppWindowToken getAppWindowToken(IBinder binder) {
948 final WindowToken token = getWindowToken(binder);
949 if (token == null) {
950 return null;
951 }
952 return token.asAppWindowToken();
953 }
954
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700955 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800956 final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700957 if (dc != null) {
958 // We currently don't support adding a window token to the display if the display
959 // already has the binder mapped to another token. If there is a use case for supporting
960 // this moving forward we will either need to merge the WindowTokens some how or have
961 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700962 throw new IllegalArgumentException("Can't map token=" + token + " to display="
963 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700964 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700965 if (binder == null) {
966 throw new IllegalArgumentException("Can't map token=" + token + " to display="
967 + getName() + " binder is null");
968 }
969 if (token == null) {
970 throw new IllegalArgumentException("Can't map null token to display="
971 + getName() + " binder=" + binder);
972 }
973
Wale Ogunwale02319a62016-09-26 15:21:22 -0700974 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700975
976 if (token.asAppWindowToken() == null) {
977 // Add non-app token to container hierarchy on the display. App tokens are added through
978 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700979 switch (token.windowType) {
980 case TYPE_WALLPAPER:
981 mBelowAppWindowsContainers.addChild(token);
982 break;
983 case TYPE_INPUT_METHOD:
984 case TYPE_INPUT_METHOD_DIALOG:
985 mImeWindowsContainers.addChild(token);
986 break;
987 default:
988 mAboveAppWindowsContainers.addChild(token);
989 break;
990 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700991 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700992 }
993
994 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700995 final WindowToken token = mTokenMap.remove(binder);
996 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800997 token.setExiting();
998 }
999 return token;
1000 }
1001
1002 /** Changes the display the input window token is housed on to this one. */
1003 void reParentWindowToken(WindowToken token) {
1004 final DisplayContent prevDc = token.getDisplayContent();
1005 if (prevDc == this) {
1006 return;
1007 }
Riddle Hsu85bd04b2018-11-17 00:34:36 +08001008 if (prevDc != null) {
1009 if (prevDc.mTokenMap.remove(token.token) != null && token.asAppWindowToken() == null) {
1010 // Removed the token from the map, but made sure it's not an app token before
1011 // removing from parent.
1012 token.getParent().removeChild(token);
1013 }
1014 if (prevDc.mLastFocus == mCurrentFocus) {
1015 // The window has become the focus of this display, so it should not be notified
1016 // that it lost focus from the previous display.
1017 prevDc.mLastFocus = null;
1018 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001019 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -08001020
1021 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -07001022 }
1023
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001024 void removeAppToken(IBinder binder) {
1025 final WindowToken token = removeWindowToken(binder);
1026 if (token == null) {
1027 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
1028 return;
1029 }
1030
1031 final AppWindowToken appToken = token.asAppWindowToken();
1032
1033 if (appToken == null) {
1034 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
1035 return;
1036 }
1037
1038 appToken.onRemovedFromDisplay();
1039 }
1040
Riddle Hsuad256a12018-07-18 16:11:30 +08001041 @Override
1042 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -07001043 return mDisplay;
1044 }
1045
Craig Mautner59c00972012-07-30 12:10:24 -07001046 DisplayInfo getDisplayInfo() {
1047 return mDisplayInfo;
1048 }
1049
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001050 DisplayMetrics getDisplayMetrics() {
1051 return mDisplayMetrics;
1052 }
1053
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001054 DisplayPolicy getDisplayPolicy() {
1055 return mDisplayPolicy;
1056 }
1057
Riddle Hsuad256a12018-07-18 16:11:30 +08001058 @Override
1059 public DisplayRotation getDisplayRotation() {
1060 return mDisplayRotation;
1061 }
1062
Jorim Jaggif96c90a2018-09-26 16:55:15 +02001063 /**
1064 * Marks a window as providing insets for the rest of the windows in the system.
1065 *
1066 * @param type The type of inset this window provides.
1067 * @param win The window.
1068 * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of
1069 * the window should be taken.
1070 */
1071 void setInsetProvider(@InternalInsetType int type, WindowState win,
1072 @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider) {
1073 mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider);
1074 }
1075
1076 InsetsStateController getInsetsStateController() {
1077 return mInsetsStateController;
1078 }
1079
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001080 @VisibleForTesting
1081 void setDisplayRotation(DisplayRotation displayRotation) {
1082 mDisplayRotation = displayRotation;
1083 }
1084
Andrii Kulian8ee72852017-03-10 10:36:45 -08001085 int getRotation() {
1086 return mRotation;
1087 }
1088
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001089 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -08001090 void setRotation(int newRotation) {
1091 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +08001092 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001093 }
1094
1095 int getLastOrientation() {
1096 return mLastOrientation;
1097 }
1098
Andrii Kulian8ee72852017-03-10 10:36:45 -08001099 int getLastWindowForcedOrientation() {
1100 return mLastWindowForcedOrientation;
1101 }
1102
Evan Rosky966759f2019-01-15 10:33:58 -08001103 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
1104 mAppTransitionController.registerRemoteAnimations(definition);
1105 }
1106
Andrii Kulian06d07d62017-03-14 11:11:47 -07001107 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +08001108 * Temporarily pauses rotation changes until resumed.
1109 *
1110 * This can be used to prevent rotation changes from occurring while the user is
1111 * performing certain operations, such as drag and drop.
1112 *
1113 * This call nests and must be matched by an equal number of calls to
1114 * {@link #resumeRotationLocked}.
1115 */
1116 void pauseRotationLocked() {
1117 mDeferredRotationPauseCount++;
1118 }
1119
1120 /**
1121 * Resumes normal rotation changes after being paused.
1122 */
1123 void resumeRotationLocked() {
1124 if (mDeferredRotationPauseCount <= 0) {
1125 return;
1126 }
1127
1128 mDeferredRotationPauseCount--;
1129 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001130 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001131 }
1132 }
1133
1134 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001135 * If this is true we have updated our desired orientation, but not yet changed the real
1136 * orientation our applied our screen rotation animation. For example, because a previous
1137 * screen rotation was in progress.
1138 *
1139 * @return {@code true} if the there is an ongoing rotation change.
1140 */
1141 boolean rotationNeedsUpdate() {
1142 final int lastOrientation = getLastOrientation();
1143 final int oldRotation = getRotation();
Riddle Hsuad256a12018-07-18 16:11:30 +08001144
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001145 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Garfield Tan4bb83472019-01-16 14:37:04 -08001146 return oldRotation != rotation;
Riddle Hsuad256a12018-07-18 16:11:30 +08001147 }
1148
Wale Ogunwale3a256e62018-12-06 14:41:18 -08001149 /**
1150 * The display content may have configuration set from {@link #DisplayWindowSettings}. This
1151 * callback let the owner of container know there is existing configuration to prevent the
1152 * values from being replaced by the initializing {@link #ActivityDisplay}.
1153 */
1154 void initializeDisplayOverrideConfiguration() {
1155 if (mAcitvityDisplay != null) {
1156 mAcitvityDisplay.onInitializeOverrideConfiguration(getRequestedOverrideConfiguration());
1157 }
1158 }
1159
Riddle Hsu4e611772018-10-31 18:58:28 +08001160 /** Notify the configuration change of this display. */
1161 void sendNewConfiguration() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001162 mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget();
Riddle Hsu4e611772018-10-31 18:58:28 +08001163 }
1164
Garfield Tan90b04282018-12-11 14:04:42 -08001165 @Override
1166 boolean onDescendantOrientationChanged(IBinder freezeDisplayToken,
1167 ConfigurationContainer requestingContainer) {
1168 final Configuration config = updateOrientationFromAppTokens(
1169 getRequestedOverrideConfiguration(), freezeDisplayToken, false);
Garfield Tan49dae102019-02-04 09:51:59 -08001170 // If display rotation class tells us that it doesn't consider app requested orientation,
1171 // this display won't rotate just because of an app changes its requested orientation. Thus
1172 // it indicates that this display chooses not to handle this request.
1173 final boolean handled = getDisplayRotation().respectAppRequestedOrientation();
Garfield Tan90b04282018-12-11 14:04:42 -08001174 if (config == null) {
1175 return handled;
1176 }
1177
1178 if (handled && requestingContainer instanceof ActivityRecord) {
1179 final ActivityRecord activityRecord = (ActivityRecord) requestingContainer;
1180 final boolean kept = mWmService.mAtmService.updateDisplayOverrideConfigurationLocked(
1181 config, activityRecord, false /* deferResume */, getDisplayId());
1182 activityRecord.frozenBeforeDestroy = true;
1183 if (!kept) {
1184 mWmService.mAtmService.mRootActivityContainer.resumeFocusedStacksTopActivities();
1185 }
1186 } else {
1187 // We have a new configuration to push so we need to update ATMS for now.
1188 // TODO: Clean up display configuration push between ATMS and WMS after unification.
1189 mWmService.mAtmService.updateDisplayOverrideConfigurationLocked(
1190 config, null /* starting */, false /* deferResume */, getDisplayId());
1191 }
1192 return handled;
1193 }
1194
Garfield Tan49dae102019-02-04 09:51:59 -08001195 @Override
1196 boolean handlesOrientationChangeFromDescendant() {
1197 return getDisplayRotation().respectAppRequestedOrientation();
1198 }
1199
Riddle Hsu4e611772018-10-31 18:58:28 +08001200 /**
1201 * Determine the new desired orientation of this display.
1202 *
1203 * The orientation is computed from non-application windows first. If none of the
1204 * non-application windows specify orientation, the orientation is computed from application
1205 * tokens.
1206 *
1207 * @return {@code true} if the orientation is changed.
1208 */
1209 boolean updateOrientationFromAppTokens() {
1210 return updateOrientationFromAppTokens(false /* forceUpdate */);
1211 }
1212
Garfield Tan90b04282018-12-11 14:04:42 -08001213 /**
1214 * Update orientation of the target display, returning a non-null new Configuration if it has
1215 * changed from the current orientation. If a non-null configuration is returned, someone must
1216 * call {@link WindowManagerService#setNewDisplayOverrideConfiguration(Configuration,
1217 * DisplayContent)} to tell the window manager it can unfreeze the screen. This will typically
1218 * be done by calling {@link WindowManagerService#sendNewConfiguration(int)}.
1219 */
1220 Configuration updateOrientationFromAppTokens(Configuration currentConfig,
1221 IBinder freezeDisplayToken, boolean forceUpdate) {
1222 if (!mDisplayReady) {
1223 return null;
1224 }
1225
1226 Configuration config = null;
1227 if (updateOrientationFromAppTokens(forceUpdate)) {
1228 // If we changed the orientation but mOrientationChangeComplete is already true,
1229 // we used seamless rotation, and we don't need to freeze the screen.
1230 if (freezeDisplayToken != null && !mWmService.mRoot.mOrientationChangeComplete) {
1231 final AppWindowToken atoken = getAppWindowToken(freezeDisplayToken);
1232 if (atoken != null) {
1233 atoken.startFreezingScreen();
1234 }
1235 }
1236 config = new Configuration();
1237 computeScreenConfiguration(config);
1238 } else if (currentConfig != null) {
1239 // No obvious action we need to take, but if our current state mismatches the
1240 // activity manager's, update it, disregarding font scale, which should remain set
1241 // to the value of the previous configuration.
1242 // Here we're calling Configuration#unset() instead of setToDefaults() because we
1243 // need to keep override configs clear of non-empty values (e.g. fontSize).
1244 mTmpConfiguration.unset();
1245 mTmpConfiguration.updateFrom(currentConfig);
1246 computeScreenConfiguration(mTmpConfiguration);
1247 if (currentConfig.diff(mTmpConfiguration) != 0) {
1248 mWaitingForConfig = true;
1249 setLayoutNeeded();
1250 int[] anim = new int[2];
1251 getDisplayPolicy().selectRotationAnimationLw(anim);
1252
1253 mWmService.startFreezingDisplayLocked(anim[0], anim[1], this);
1254 config = new Configuration(mTmpConfiguration);
1255 }
1256 }
1257
1258 return config;
1259 }
1260
1261
1262 private boolean updateOrientationFromAppTokens(boolean forceUpdate) {
Riddle Hsu4e611772018-10-31 18:58:28 +08001263 final int req = getOrientation();
1264 if (req != mLastOrientation || forceUpdate) {
1265 mLastOrientation = req;
1266 mDisplayRotation.setCurrentOrientation(req);
1267 return updateRotationUnchecked(forceUpdate);
1268 }
1269 return false;
1270 }
1271
Riddle Hsuad256a12018-07-18 16:11:30 +08001272 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001273 * Update rotation of the display and send configuration if the rotation is changed.
1274 *
1275 * @return {@code true} if the rotation has been changed and the new config is sent.
1276 */
1277 boolean updateRotationAndSendNewConfigIfNeeded() {
1278 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1279 if (changed) {
Riddle Hsu4e611772018-10-31 18:58:28 +08001280 sendNewConfiguration();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001281 }
1282 return changed;
1283 }
1284
1285 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001286 * Update rotation of the display.
1287 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001288 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1289 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001290 */
Robert Carrae606b42018-02-15 15:36:23 -08001291 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001292 return updateRotationUnchecked(false /* forceUpdate */);
1293 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001294
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001295 /**
Evan Roskye747c3e2018-10-30 20:06:41 -07001296 * Update rotation of the DisplayContent with an option to force the update. This updates
1297 * the container's perception of rotation and, depending on the top activities, will freeze
1298 * the screen or start seamless rotation. The display itself gets rotated in
1299 * {@link #applyRotationLocked} during {@link WindowManagerService#sendNewConfiguration}.
1300 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001301 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1302 * orientation because we're waiting for some rotation to finish or display
1303 * to unfreeze, which results in configuration of the previously visible
1304 * activity being applied to a newly visible one. Forcing the rotation
1305 * update allows to workaround this issue.
1306 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
Evan Roskye747c3e2018-10-30 20:06:41 -07001307 * {@link WindowManagerService#sendNewConfiguration(int)} TO COMPLETE THE ROTATION AND
1308 * UNFREEZE THE SCREEN.
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001309 */
1310 boolean updateRotationUnchecked(boolean forceUpdate) {
1311 ScreenRotationAnimation screenRotationAnimation;
1312 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001313 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001314 // Rotation updates have been paused temporarily. Defer the update until
1315 // updates have been resumed.
1316 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1317 return false;
1318 }
1319
1320 screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001321 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001322 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1323 // Rotation updates cannot be performed while the previous rotation change
1324 // animation is still in progress. Skip this update. We will try updating
1325 // again after the animation is finished and the display is unfrozen.
1326 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1327 return false;
1328 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001329 if (mWmService.mDisplayFrozen) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001330 // Even if the screen rotation animation has finished (e.g. isAnimating
1331 // returns false), there is still some time where we haven't yet unfrozen
1332 // the display. We also need to abort rotation here.
1333 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1334 "Deferring rotation, still finishing previous rotation");
1335 return false;
1336 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001337 }
1338
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001339 if (!mWmService.mDisplayEnabled) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001340 // No point choosing a rotation if the display is not enabled.
1341 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1342 return false;
1343 }
1344
1345 final int oldRotation = mRotation;
1346 final int lastOrientation = mLastOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001347 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001348 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1349 + mDisplayId + " based on lastOrientation=" + lastOrientation
1350 + " and oldRotation=" + oldRotation);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001351 boolean mayRotateSeamlessly = mDisplayPolicy.shouldRotateSeamlessly(mDisplayRotation,
Riddle Hsuad256a12018-07-18 16:11:30 +08001352 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001353
Robert Carr0e007272017-10-02 13:00:55 -07001354 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001355 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001356 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001357 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1358 // to complete (that is, waiting for windows to redraw). It's tempting to check
1359 // w.mSeamlessRotationCount but that could be incorrect in the case of
1360 // window-removal.
1361 return false;
1362 }
Robert Carr0e007272017-10-02 13:00:55 -07001363
1364 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001365 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001366 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001367 mayRotateSeamlessly = false;
1368 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001369 for (int i = 0; i < mWmService.mSessions.size(); i++) {
1370 if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
Robert Carr0e007272017-10-02 13:00:55 -07001371 mayRotateSeamlessly = false;
1372 break;
1373 }
1374 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001375 }
Robert Carr0e007272017-10-02 13:00:55 -07001376 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001377
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001378 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1379 + " selected orientation " + lastOrientation
Garfield Tan49dae102019-02-04 09:51:59 -08001380 + ", got rotation " + rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001381
Garfield Tan4bb83472019-01-16 14:37:04 -08001382 if (oldRotation == rotation) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001383 // No change.
1384 return false;
1385 }
1386
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001387 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1388 + " rotation changed to " + rotation
Garfield Tan4bb83472019-01-16 14:37:04 -08001389 + " from " + oldRotation
1390 + ", lastOrientation=" + lastOrientation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001391
1392 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
Vishnu Nairba183352018-11-21 11:16:49 -08001393 mWaitingForConfig = true;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001394 }
1395
Evan Roskye747c3e2018-10-30 20:06:41 -07001396 mRotation = rotation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001397
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001398 mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1399 mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
Riddle Hsu654a6f92018-07-13 22:59:36 +08001400 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001401
1402 setLayoutNeeded();
1403 final int[] anim = new int[2];
Tiger Huang7c610aa2018-10-27 00:01:01 +08001404 mDisplayPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001405
1406 if (!rotateSeamlessly) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001407 mWmService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001408 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001409 } else {
1410 // The screen rotation animation uses a screenshot to freeze the screen
1411 // while windows resize underneath.
1412 // When we are rotating seamlessly, we allow the elements to transition
1413 // to their rotated state independently and without a freeze required.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001414 mWmService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001415 }
1416
Evan Roskye747c3e2018-10-30 20:06:41 -07001417 return true;
1418 }
1419
1420 /**
1421 * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked}
1422 * (if it returned {@code true}) to actually finish the rotation.
1423 *
1424 * @param oldRotation the rotation we are coming from.
1425 * @param rotation the rotation to apply.
1426 */
1427 void applyRotationLocked(final int oldRotation, final int rotation) {
1428 mDisplayRotation.setRotation(rotation);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001429 final boolean rotateSeamlessly = mWmService.isRotatingSeamlessly();
Evan Roskye747c3e2018-10-30 20:06:41 -07001430 ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001431 ? null : mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001432 // We need to update our screen size information to match the new rotation. If the rotation
1433 // has actually changed then this method will return true and, according to the comment at
1434 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1435 // By updating the Display info here it will be available to
1436 // #computeScreenConfiguration() later.
1437 updateDisplayAndOrientation(getConfiguration().uiMode);
1438
Robert Carrae606b42018-02-15 15:36:23 -08001439 // NOTE: We disable the rotation in the emulator because
1440 // it doesn't support hardware OpenGL emulation yet.
1441 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1442 && screenRotationAnimation.hasScreenshot()) {
1443 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001444 MAX_ANIMATION_DURATION, mWmService.getTransitionAnimationScaleLocked(),
Robert Carrae606b42018-02-15 15:36:23 -08001445 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001446 mWmService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001447 }
1448 }
1449
Vishnu Nair83537a72018-07-19 21:27:48 -07001450 forAllWindows(w -> {
Vishnu Nairddd80742018-08-21 14:12:46 -07001451 w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation,
1452 rotateSeamlessly);
Vishnu Nair83537a72018-07-19 21:27:48 -07001453 }, true /* traverseTopToBottom */);
1454
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001455 mWmService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
Robert Carrae606b42018-02-15 15:36:23 -08001456 scheduleAnimation();
1457
Andrii Kulian06d07d62017-03-14 11:11:47 -07001458 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001459 if (w.mHasSurface && !rotateSeamlessly) {
1460 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001461 w.setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001462 mWmService.mRoot.mOrientationChangeComplete = false;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001463 w.mLastFreezeDuration = 0;
1464 }
1465 w.mReportOrientationChanged = true;
1466 }, true /* traverseTopToBottom */);
1467
1468 if (rotateSeamlessly) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001469 mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
Riddle Hsu654a6f92018-07-13 22:59:36 +08001470 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001471 }
1472
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001473 for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001474 final WindowManagerService.RotationWatcher rotationWatcher
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001475 = mWmService.mRotationWatchers.get(i);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001476 if (rotationWatcher.mDisplayId == mDisplayId) {
1477 try {
1478 rotationWatcher.mWatcher.onRotationChanged(rotation);
1479 } catch (RemoteException e) {
1480 // Ignore
1481 }
1482 }
1483 }
1484
Andrii Kulian06d07d62017-03-14 11:11:47 -07001485 // Announce rotation only if we will not animate as we already have the
1486 // windows in final state. Otherwise, we make this call at the rotation end.
Rhed Jao02655dc2018-10-30 20:44:52 +08001487 if (screenRotationAnimation == null && mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001488 mWmService.mAccessibilityController.onRotationChangedLocked(this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001489 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001490 }
1491
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001492 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001493 final int width = mBaseDisplayWidth;
1494 final int height = mBaseDisplayHeight;
1495 final int shortSize;
1496 final int longSize;
1497 if (width > height) {
1498 shortSize = height;
1499 longSize = width;
1500 } else {
1501 shortSize = width;
1502 longSize = height;
1503 }
1504
1505 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1506 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1507
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001508 mDisplayPolicy.configure(width, height, shortSizeDp);
Tiger Huang3d2b8982019-01-29 22:56:48 +08001509 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001510
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001511 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1512 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Arthur Hungbe5ce212018-09-13 18:41:56 +08001513
1514 // Tap Listeners are supported for:
1515 // 1. All physical displays (multi-display).
1516 // 2. VirtualDisplays on VR, AA (and everything else).
1517 if (mPointerEventDispatcher != null && mTapDetector == null) {
1518 if (DEBUG_DISPLAY) {
1519 Slog.d(TAG,
1520 "Registering PointerEventListener for DisplayId: " + mDisplayId);
1521 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001522 mTapDetector = new TaskTapPointerEventListener(mWmService, this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08001523 registerPointerEventListener(mTapDetector);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001524 registerPointerEventListener(mWmService.mMousePositionTracker);
Arthur Hungbe5ce212018-09-13 18:41:56 +08001525 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001526 }
1527
Andrii Kulian06d07d62017-03-14 11:11:47 -07001528 /**
1529 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1530 * changed.
1531 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1532 */
1533 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1534 // Use the effective "visual" dimensions based on current rotation
1535 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
Garfield Tan4bb83472019-01-16 14:37:04 -08001536 final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1537 final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001538
1539 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001540 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1541 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1542
Tiger Huang7c610aa2018-10-27 00:01:01 +08001543 final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
1544 displayCutout);
1545 final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
1546 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001547 mDisplayInfo.rotation = mRotation;
1548 mDisplayInfo.logicalWidth = dw;
1549 mDisplayInfo.logicalHeight = dh;
1550 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1551 mDisplayInfo.appWidth = appWidth;
1552 mDisplayInfo.appHeight = appHeight;
1553 if (isDefaultDisplay) {
1554 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1555 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1556 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001557 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001558 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1559 if (mDisplayScalingDisabled) {
1560 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1561 } else {
1562 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1563 }
1564
Andrii Kulianf0379de2018-03-14 16:24:07 -07001565 // We usually set the override info in DisplayManager so that we get consistent display
1566 // metrics values when displays are changing and don't send out new values until WM is aware
1567 // of them. However, we don't do this for displays that serve as containers for ActivityView
1568 // because we don't want letter-/pillar-boxing during resize.
1569 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1570 ? mDisplayInfo : null;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001571 mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001572 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001573
1574 mBaseDisplayRect.set(0, 0, dw, dh);
1575
1576 if (isDefaultDisplay) {
1577 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1578 mCompatDisplayMetrics);
1579 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001580
Andrii Kulian06d07d62017-03-14 11:11:47 -07001581 return mDisplayInfo;
1582 }
1583
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001584 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001585 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1586 }
1587
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001588 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001589 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001590 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001591 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001592 }
Adrian Roos11c25582018-02-19 18:06:36 +01001593 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001594 return WmDisplayCutout.computeSafeInsets(
1595 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001596 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001597 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Issei Suzuki43190bd2018-08-20 17:28:41 +02001598 final Rect[] newBounds = mRotationUtil.getRotatedBounds(
1599 WmDisplayCutout.computeSafeInsets(
Jorim Jaggi60640512018-06-29 01:14:31 +02001600 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
Issei Suzuki43190bd2018-08-20 17:28:41 +02001601 .getDisplayCutout().getBoundingRectsAll(),
1602 rotation, mInitialDisplayWidth, mInitialDisplayHeight);
1603 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds),
Adrian Roos24264212018-02-19 16:26:15 +01001604 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1605 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001606 }
1607
Andrii Kulian06d07d62017-03-14 11:11:47 -07001608 /**
1609 * Compute display configuration based on display properties and policy settings.
1610 * Do not call if mDisplayReady == false.
1611 */
1612 void computeScreenConfiguration(Configuration config) {
1613 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
Evan Roskye747c3e2018-10-30 20:06:41 -07001614 calculateBounds(displayInfo, mTmpBounds);
1615 config.windowConfiguration.setBounds(mTmpBounds);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001616
1617 final int dw = displayInfo.logicalWidth;
1618 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001619 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001620 config.windowConfiguration.setWindowingMode(getWindowingMode());
Yunfan Chen7daa6ac2018-11-29 18:16:44 -08001621 config.windowConfiguration.setDisplayWindowingMode(getWindowingMode());
Evan Roskye747c3e2018-10-30 20:06:41 -07001622 config.windowConfiguration.setRotation(displayInfo.rotation);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001623
Adrian Roos11c25582018-02-19 18:06:36 +01001624 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001625 config.screenWidthDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001626 (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
1627 config.uiMode, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001628 config.screenHeightDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001629 (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
1630 config.uiMode, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001631
Tiger Huang7c610aa2018-10-27 00:01:01 +08001632 mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001633 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001634 final int leftInset = mTmpRect.left;
1635 final int topInset = mTmpRect.top;
1636 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001637 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1638 leftInset + displayInfo.appWidth /* right */,
1639 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001640 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1641 || displayInfo.rotation == Surface.ROTATION_270);
1642
Tiger Huang7c610aa2018-10-27 00:01:01 +08001643 computeSizeRangesAndScreenLayout(displayInfo, rotated, config.uiMode, dw, dh, density,
1644 config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001645
1646 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1647 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1648 ? Configuration.SCREENLAYOUT_ROUND_YES
1649 : Configuration.SCREENLAYOUT_ROUND_NO);
1650
1651 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1652 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1653 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001654 dh, displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001655 config.densityDpi = displayInfo.logicalDensityDpi;
1656
1657 config.colorMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001658 ((displayInfo.isHdr() && mWmService.hasHdrSupport())
Andrii Kulian06d07d62017-03-14 11:11:47 -07001659 ? Configuration.COLOR_MODE_HDR_YES
1660 : Configuration.COLOR_MODE_HDR_NO)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001661 | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001662 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1663 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1664
1665 // Update the configuration based on available input devices, lid switch,
1666 // and platform configuration.
1667 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1668 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1669 config.navigation = Configuration.NAVIGATION_NONAV;
1670
1671 int keyboardPresence = 0;
1672 int navigationPresence = 0;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001673 final InputDevice[] devices = mWmService.mInputManager.getInputDevices();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001674 final int len = devices != null ? devices.length : 0;
1675 for (int i = 0; i < len; i++) {
1676 InputDevice device = devices[i];
Arthur Hung82bbfc32018-11-29 20:24:51 +08001677 // Ignore virtual input device.
1678 if (device.isVirtual()) {
1679 continue;
1680 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001681
Arthur Hung82bbfc32018-11-29 20:24:51 +08001682 // Check if input device can dispatch events to current display.
1683 // If display type is virtual, will follow the default display.
1684 if (!mWmService.mInputManager.canDispatchToDisplay(device.getId(),
1685 displayInfo.type == Display.TYPE_VIRTUAL ? DEFAULT_DISPLAY : mDisplayId)) {
1686 continue;
1687 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001688
Arthur Hung82bbfc32018-11-29 20:24:51 +08001689 final int sources = device.getSources();
1690 final int presenceFlag = device.isExternal()
1691 ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001692
Arthur Hung82bbfc32018-11-29 20:24:51 +08001693 if (mWmService.mIsTouchDevice) {
1694 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
1695 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001696 }
Arthur Hung82bbfc32018-11-29 20:24:51 +08001697 } else {
1698 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1699 }
1700
1701 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1702 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1703 navigationPresence |= presenceFlag;
1704 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1705 && config.navigation == Configuration.NAVIGATION_NONAV) {
1706 config.navigation = Configuration.NAVIGATION_DPAD;
1707 navigationPresence |= presenceFlag;
1708 }
1709
1710 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1711 config.keyboard = Configuration.KEYBOARD_QWERTY;
1712 keyboardPresence |= presenceFlag;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001713 }
1714 }
1715
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001716 if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001717 config.navigation = Configuration.NAVIGATION_DPAD;
1718 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1719 }
1720
1721 // Determine whether a hard keyboard is available and enabled.
1722 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1723 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001724 if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) {
1725 mWmService.mHardKeyboardAvailable = hardKeyboardAvailable;
1726 mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1727 mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001728 }
1729
Tiger Huang7c610aa2018-10-27 00:01:01 +08001730 mDisplayPolicy.updateConfigurationDependentBehaviors();
1731
Andrii Kulian06d07d62017-03-14 11:11:47 -07001732 // Let the policy update hidden states.
1733 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1734 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1735 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001736 mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001737 }
1738
1739 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001740 DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001741 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1742 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1743 final int unrotDw, unrotDh;
1744 if (rotated) {
1745 unrotDw = dh;
1746 unrotDh = dw;
1747 } else {
1748 unrotDw = dw;
1749 unrotDh = dh;
1750 }
1751 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001752 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001753 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001754 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001755 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001756 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001757 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001758 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001759 return sw;
1760 }
1761
1762 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001763 DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) {
1764 dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
1765 displayCutout);
1766 dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode,
1767 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001768 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1769 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1770 if (curSize == 0 || size < curSize) {
1771 curSize = size;
1772 }
1773 return curSize;
1774 }
1775
Tiger Huang7c610aa2018-10-27 00:01:01 +08001776 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
1777 int uiMode, int dw, int dh, float density, Configuration outConfig) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001778
1779 // We need to determine the smallest width that will occur under normal
1780 // operation. To this, start with the base screen size and compute the
1781 // width under the different possible rotations. We need to un-rotate
1782 // the current screen dimensions before doing this.
1783 int unrotDw, unrotDh;
1784 if (rotated) {
1785 unrotDw = dh;
1786 unrotDh = dw;
1787 } else {
1788 unrotDw = dw;
1789 unrotDh = dh;
1790 }
1791 displayInfo.smallestNominalAppWidth = 1<<30;
1792 displayInfo.smallestNominalAppHeight = 1<<30;
1793 displayInfo.largestNominalAppWidth = 0;
1794 displayInfo.largestNominalAppHeight = 0;
Tiger Huang7c610aa2018-10-27 00:01:01 +08001795 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh);
1796 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw);
1797 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh);
1798 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001799 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1800 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001801 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001802 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001803 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001804 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001805 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001806 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001807 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001808 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1809 outConfig.screenLayout = sl;
1810 }
1811
1812 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001813 int uiMode, DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001814 // Get the app screen size at this rotation.
Tiger Huang7c610aa2018-10-27 00:01:01 +08001815 int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout);
1816 int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001817
1818 // Compute the screen layout size class for this rotation.
1819 int longSize = w;
1820 int shortSize = h;
1821 if (longSize < shortSize) {
1822 int tmp = longSize;
1823 longSize = shortSize;
1824 shortSize = tmp;
1825 }
1826 longSize = (int)(longSize/density);
1827 shortSize = (int)(shortSize/density);
1828 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1829 }
1830
Tiger Huang7c610aa2018-10-27 00:01:01 +08001831 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001832 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001833 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1834 rotation).getDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +08001835 final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
1836 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001837 if (width < displayInfo.smallestNominalAppWidth) {
1838 displayInfo.smallestNominalAppWidth = width;
1839 }
1840 if (width > displayInfo.largestNominalAppWidth) {
1841 displayInfo.largestNominalAppWidth = width;
1842 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001843 final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
1844 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001845 if (height < displayInfo.smallestNominalAppHeight) {
1846 displayInfo.smallestNominalAppHeight = height;
1847 }
1848 if (height > displayInfo.largestNominalAppHeight) {
1849 displayInfo.largestNominalAppHeight = height;
1850 }
1851 }
1852
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001853 /**
1854 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1855 * theme attribute) on devices that feature a physical options menu key attempt to position
1856 * their menu panel window along the edge of the screen nearest the physical menu key.
1857 * This lowers the travel distance between invoking the menu panel and selecting
1858 * a menu option.
1859 *
1860 * This method helps control where that menu is placed. Its current implementation makes
1861 * assumptions about the menu key and its relationship to the screen based on whether
1862 * the device's natural orientation is portrait (width < height) or landscape.
1863 *
1864 * The menu key is assumed to be located along the bottom edge of natural-portrait
1865 * devices and along the right edge of natural-landscape devices. If these assumptions
1866 * do not hold for the target device, this method should be changed to reflect that.
1867 *
1868 * @return A {@link Gravity} value for placing the options menu window.
1869 */
1870 int getPreferredOptionsPanelGravity() {
1871 final int rotation = getRotation();
1872 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1873 // On devices with a natural orientation of portrait.
1874 switch (rotation) {
1875 default:
1876 case Surface.ROTATION_0:
1877 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1878 case Surface.ROTATION_90:
1879 return Gravity.RIGHT | Gravity.BOTTOM;
1880 case Surface.ROTATION_180:
1881 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1882 case Surface.ROTATION_270:
1883 return Gravity.START | Gravity.BOTTOM;
1884 }
1885 }
1886
1887 // On devices with a natural orientation of landscape.
1888 switch (rotation) {
1889 default:
1890 case Surface.ROTATION_0:
1891 return Gravity.RIGHT | Gravity.BOTTOM;
1892 case Surface.ROTATION_90:
1893 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1894 case Surface.ROTATION_180:
1895 return Gravity.START | Gravity.BOTTOM;
1896 case Surface.ROTATION_270:
1897 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1898 }
1899 }
1900
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001901 DockedStackDividerController getDockedDividerController() {
1902 return mDividerControllerLocked;
1903 }
1904
Winson Chung655332c2016-10-31 13:14:28 -07001905 PinnedStackController getPinnedStackController() {
1906 return mPinnedStackControllerLocked;
1907 }
1908
Jeff Browna506a6e2013-06-04 00:02:38 -07001909 /**
1910 * Returns true if the specified UID has access to this display.
1911 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001912 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001913 return mDisplay.hasAccess(uid);
1914 }
1915
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001916 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001917 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001918 }
1919
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001920 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001921 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001922 }
1923
Wale Ogunwale61911492017-10-11 08:50:50 -07001924 /**
1925 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1926 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001927 TaskStack getSplitScreenPrimaryStack() {
1928 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001929 return (stack != null && stack.isVisible()) ? stack : null;
1930 }
1931
Robert Carr9785cf32018-04-25 15:06:07 -07001932 boolean hasSplitScreenPrimaryStack() {
1933 return getSplitScreenPrimaryStack() != null;
1934 }
1935
Wale Ogunwale61911492017-10-11 08:50:50 -07001936 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001937 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001938 * not visible.
1939 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001940 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1941 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001942 }
1943
1944 TaskStack getPinnedStack() {
1945 return mTaskStackContainers.getPinnedStack();
1946 }
1947
1948 private boolean hasPinnedStack() {
1949 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001950 }
1951
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001952 /**
1953 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1954 * Null is no compatible stack on the display.
1955 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001956 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001957 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1958 }
1959
1960 /**
1961 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1962 * activity type. Null is no compatible stack on the display.
1963 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001964 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001965 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001966 }
1967
Bryce Lee48f4b572017-04-10 10:54:15 -07001968 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001969 WindowList<TaskStack> getStacks() {
1970 return mTaskStackContainers.mChildren;
1971 }
1972
1973 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001974 TaskStack getTopStack() {
1975 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001976 }
1977
Winson Chunge2d72172018-01-25 17:46:20 +00001978 ArrayList<Task> getVisibleTasks() {
1979 return mTaskStackContainers.getVisibleTasks();
1980 }
1981
Wale Ogunwale61911492017-10-11 08:50:50 -07001982 void onStackWindowingModeChanged(TaskStack stack) {
1983 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001984 }
1985
Andrii Kulian441e4492016-09-29 15:25:00 -07001986 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001987 public void onConfigurationChanged(Configuration newParentConfig) {
Susi Kharraz-Post9893b8c2019-02-12 14:21:29 -05001988 final int lastOrientation = getConfiguration().orientation;
Andrii Kulian441e4492016-09-29 15:25:00 -07001989 super.onConfigurationChanged(newParentConfig);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001990 if (mDisplayPolicy != null) {
1991 mDisplayPolicy.onConfigurationChanged();
1992 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001993
Susi Kharraz-Post9893b8c2019-02-12 14:21:29 -05001994 if (lastOrientation != getConfiguration().orientation) {
1995 getMetricsLogger().write(
1996 new LogMaker(MetricsEvent.ACTION_PHONE_ORIENTATION_CHANGED)
1997 .setSubtype(getConfiguration().orientation)
1998 .addTaggedData(MetricsEvent.FIELD_DISPLAY_ID, getDisplayId()));
1999 }
2000
Evan Roskye747c3e2018-10-30 20:06:41 -07002001 // If there was no pinned stack, we still need to notify the controller of the display info
2002 // update as a result of the config change.
2003 if (mPinnedStackControllerLocked != null && !hasPinnedStack()) {
2004 mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo());
2005 }
Evan Roskye747c3e2018-10-30 20:06:41 -07002006 }
2007
2008 /**
2009 * Updates the resources used by docked/pinned controllers. This needs to be called at the
2010 * beginning of a configuration update cascade since the metrics from these resources are used
2011 * for bounds calculations. Since ActivityDisplay initiates the configuration update, this
2012 * should be called from there instead of DisplayContent's onConfigurationChanged.
2013 */
2014 void preOnConfigurationChanged() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002015 final DockedStackDividerController dividerController = getDockedDividerController();
2016
2017 if (dividerController != null) {
2018 getDockedDividerController().onConfigurationChanged();
2019 }
2020
2021 final PinnedStackController pinnedStackController = getPinnedStackController();
2022
2023 if (pinnedStackController != null) {
2024 getPinnedStackController().onConfigurationChanged();
2025 }
Andrii Kulian441e4492016-09-29 15:25:00 -07002026 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07002027
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002028 @Override
2029 boolean fillsParent() {
2030 return true;
2031 }
2032
2033 @Override
2034 boolean isVisible() {
2035 return true;
2036 }
2037
2038 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002039 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002040 super.onAppTransitionDone();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002041 mWmService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002042 }
2043
Yunfan Chen7daa6ac2018-11-29 18:16:44 -08002044 @Override
2045 public void setWindowingMode(int windowingMode) {
2046 super.setWindowingMode(windowingMode);
2047 super.setDisplayWindowingMode(windowingMode);
2048 }
2049
2050 @Override
2051 void setDisplayWindowingMode(int windowingMode) {
2052 setWindowingMode(windowingMode);
2053 }
2054
Robert Carr9785cf32018-04-25 15:06:07 -07002055 /**
2056 * In split-screen mode we process the IME containers above the docked divider
2057 * rather than directly above their target.
2058 */
2059 private boolean skipTraverseChild(WindowContainer child) {
lumarkff0ab692018-11-05 20:32:30 +08002060 if (child == mImeWindowsContainers && mInputMethodTarget != null
Robert Carr9785cf32018-04-25 15:06:07 -07002061 && !hasSplitScreenPrimaryStack()) {
2062 return true;
2063 }
2064 return false;
2065 }
2066
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002067 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002068 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
2069 // Special handling so we can process IME windows with #forAllImeWindows above their IME
2070 // target, or here in order if there isn't an IME target.
2071 if (traverseTopToBottom) {
2072 for (int i = mChildren.size() - 1; i >= 0; --i) {
2073 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07002074 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002075 continue;
2076 }
Robert Carr9785cf32018-04-25 15:06:07 -07002077
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002078 if (child.forAllWindows(callback, traverseTopToBottom)) {
2079 return true;
2080 }
2081 }
2082 } else {
2083 final int count = mChildren.size();
2084 for (int i = 0; i < count; i++) {
2085 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07002086 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002087 continue;
2088 }
Robert Carr9785cf32018-04-25 15:06:07 -07002089
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002090 if (child.forAllWindows(callback, traverseTopToBottom)) {
2091 return true;
2092 }
2093 }
2094 }
2095 return false;
2096 }
2097
2098 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
2099 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
2100 }
2101
Wale Ogunwale399c8692017-05-08 14:22:42 -07002102 @Override
2103 int getOrientation() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002104 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002105
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002106 if (mWmService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08002107 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002108 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2109 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002110 // If the display is frozen, some activities may be in the middle of restarting, and
2111 // thus have removed their old window. If the window has the flag to hide the lock
2112 // screen, then the lock screen can re-appear and inflict its own orientation on us.
2113 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002114 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002115 } else if (policy.isKeyguardLocked()) {
2116 // Use the last orientation the while the display is frozen with the keyguard
2117 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
2118 // window. We don't want to check the show when locked window directly though as
2119 // things aren't stable while the display is frozen, for example the window could be
2120 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002121 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2122 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08002123 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07002124 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002125 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002126 final int orientation = mAboveAppWindowsContainers.getOrientation();
2127 if (orientation != SCREEN_ORIENTATION_UNSET) {
2128 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002129 }
Wale Ogunwale51362492016-09-08 17:49:17 -07002130 }
2131
Wale Ogunwale399c8692017-05-08 14:22:42 -07002132 // Top system windows are not requesting an orientation. Start searching from apps.
2133 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07002134 }
2135
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002136 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07002137 // Check if display metrics changed and update base values if needed.
2138 updateBaseDisplayMetricsIfNeeded();
2139
Craig Mautner722285e2012-09-07 13:55:58 -07002140 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07002141 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07002142
Garfield Tan2f145f22018-11-01 15:27:03 -07002143 onDisplayChanged(this);
Craig Mautner722285e2012-09-07 13:55:58 -07002144 }
2145
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002146 void initializeDisplayBaseInfo() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002147 final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002148 if (displayManagerInternal != null) {
2149 // Bootstrap the default logical display from the display manager.
2150 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
2151 if (newDisplayInfo != null) {
2152 mDisplayInfo.copyFrom(newDisplayInfo);
2153 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002154 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002155
Andrii Kuliancd097992017-03-23 18:31:59 -07002156 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
2157 mDisplayInfo.logicalDensityDpi);
2158 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
2159 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
2160 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002161 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002162 }
2163
Andrii Kuliancd097992017-03-23 18:31:59 -07002164 /**
2165 * If display metrics changed, overrides are not set and it's not just a rotation - update base
2166 * values.
2167 */
2168 private void updateBaseDisplayMetricsIfNeeded() {
2169 // Get real display metrics without overrides from WM.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002170 mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
Andrii Kuliancd097992017-03-23 18:31:59 -07002171 final int orientation = mDisplayInfo.rotation;
2172 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2173 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
2174 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
2175 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002176 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07002177
2178 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
2179 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01002180 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
2181 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07002182
2183 if (displayMetricsChanged) {
2184 // Check if display size or density is forced.
2185 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
2186 || mBaseDisplayHeight != mInitialDisplayHeight;
2187 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
2188
2189 // If there is an override set for base values - use it, otherwise use new values.
2190 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
2191 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
2192 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
2193
2194 // Real display metrics changed, so we should also update initial values.
2195 mInitialDisplayWidth = newWidth;
2196 mInitialDisplayHeight = newHeight;
2197 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01002198 mInitialDisplayCutout = newCutout;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002199 mWmService.reconfigureDisplayLocked(this);
Andrii Kuliancd097992017-03-23 18:31:59 -07002200 }
2201 }
2202
Bryce Lee27cec322017-03-21 09:41:37 -07002203 /** Sets the maximum width the screen resolution can be */
2204 void setMaxUiWidth(int width) {
2205 if (DEBUG_DISPLAY) {
2206 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
2207 }
2208
2209 mMaxUiWidth = width;
2210
2211 // Update existing metrics.
2212 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
2213 }
2214
2215 /** Update base (override) display metrics. */
2216 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
2217 mBaseDisplayWidth = baseWidth;
2218 mBaseDisplayHeight = baseHeight;
2219 mBaseDisplayDensity = baseDensity;
2220
2221 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
2222 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
2223 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
2224 mBaseDisplayWidth = mMaxUiWidth;
2225
2226 if (DEBUG_DISPLAY) {
2227 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
2228 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
2229 + " on display:" + getDisplayId());
2230 }
2231 }
2232
2233 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08002234
2235 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07002236 }
2237
Riddle Hsuf53da812018-08-15 22:00:27 +08002238 /**
2239 * Forces this display to use the specified density.
2240 *
2241 * @param density The density in DPI to use. If the value equals to initial density, the setting
2242 * will be cleared.
2243 * @param userId The target user to apply. Only meaningful when this is default display. If the
2244 * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings
2245 * so only need to configure display.
2246 */
2247 void setForcedDensity(int density, int userId) {
2248 final boolean clear = density == mInitialDisplayDensity;
2249 final boolean updateCurrent = userId == UserHandle.USER_CURRENT;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002250 if (mWmService.mCurrentUserId == userId || updateCurrent) {
Riddle Hsuf53da812018-08-15 22:00:27 +08002251 mBaseDisplayDensity = density;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002252 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002253 }
2254 if (updateCurrent) {
2255 // We are applying existing settings so no need to save it again.
2256 return;
2257 }
2258
2259 if (density == mInitialDisplayDensity) {
2260 density = 0;
2261 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002262 mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId);
Riddle Hsuf53da812018-08-15 22:00:27 +08002263 }
2264
2265 /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */
2266 void setForcedScalingMode(@ForceScalingMode int mode) {
2267 if (mode != FORCE_SCALING_MODE_DISABLED) {
2268 mode = FORCE_SCALING_MODE_AUTO;
2269 }
2270
2271 mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO);
2272 Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto"));
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002273 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002274
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002275 mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode);
Riddle Hsuf53da812018-08-15 22:00:27 +08002276 }
2277
2278 /** If the given width and height equal to initial size, the setting will be cleared. */
2279 void setForcedSize(int width, int height) {
2280 final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height;
2281 if (!clear) {
2282 // Set some sort of reasonable bounds on the size of the display that we will try
2283 // to emulate.
2284 final int minSize = 200;
2285 final int maxScale = 2;
2286 width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale);
2287 height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale);
2288 }
2289
2290 Slog.i(TAG_WM, "Using new display size: " + width + "x" + height);
2291 updateBaseDisplayMetrics(width, height, mBaseDisplayDensity);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002292 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002293
2294 if (clear) {
2295 width = height = 0;
2296 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002297 mWmService.mDisplayWindowSettings.setForcedSize(this, width, height);
Riddle Hsuf53da812018-08-15 22:00:27 +08002298 }
2299
Wale Ogunwaledb506192017-12-08 10:57:32 -08002300 void getStableRect(Rect out) {
2301 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08002302 }
2303
Yunfan Chen279f5582018-12-12 15:24:50 -08002304 void setStackOnDisplay(int stackId, boolean onTop, TaskStack stack) {
2305 if (DEBUG_STACK) {
2306 Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId=" + mDisplayId);
2307 }
Andrii Kulian839def92016-11-02 10:58:58 -07002308
Wale Ogunwale61911492017-10-11 08:50:50 -07002309 mTaskStackContainers.addStackToDisplay(stack, onTop);
Andrii Kulian839def92016-11-02 10:58:58 -07002310 }
2311
Andrii Kulian51c1b672017-04-07 18:39:32 -07002312 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002313 final DisplayContent prevDc = stack.getDisplayContent();
2314 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07002315 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
2316 + " which is not currently attached to any display");
2317 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08002318 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07002319 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2320 + " to its current displayId=" + mDisplayId);
2321 }
2322
lumark588a3e82018-07-20 18:53:54 +08002323 // Clean up all pending transitions when stack reparent to another display.
2324 stack.forAllAppWindows(AppWindowToken::removeFromPendingTransition);
2325
Wale Ogunwale61911492017-10-11 08:50:50 -07002326 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002327 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002328 }
2329
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002330 @Override
2331 protected void addChild(DisplayChildWindowContainer child,
2332 Comparator<DisplayChildWindowContainer> comparator) {
2333 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2334 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002335
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002336 @Override
2337 protected void addChild(DisplayChildWindowContainer child, int index) {
2338 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2339 }
2340
2341 @Override
2342 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002343 // Only allow removal of direct children from this display if the display is in the process
2344 // of been removed.
2345 if (mRemovingDisplay) {
2346 super.removeChild(child);
2347 return;
2348 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002349 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002350 }
2351
Andrii Kuliand2765632016-12-12 22:26:34 -08002352 @Override
2353 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2354 // Children of the display are statically ordered, so the real intention here is to perform
2355 // the operation on the display and not the static direct children.
2356 getParent().positionChildAt(position, this, includingParents);
2357 }
2358
Riddle Hsu57831b52018-07-27 00:31:48 +08002359 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2360 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002361 layoutAndAssignWindowLayersIfNeeded();
2362 }
2363
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002364 /**
2365 * Used to obtain task ID when user taps on coordinate (x, y) in this display, and outside
2366 * current task in focus.
2367 *
2368 * This returns the task ID of the foremost task at (x, y) if the task is not home. Otherwise it
2369 * returns -1.
2370 *
2371 * @param x horizontal coordinate of the tap position
2372 * @param y vertical coordinate of the tap position
2373 * @return the task ID if a non-home task is found; -1 if not
2374 */
2375 int taskForTapOutside(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002376 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2377 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002378 if (stack.isActivityTypeHome() && !stack.inMultiWindowMode()) {
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002379 // We skip not only home stack, but also everything behind home because user can't
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002380 // see them when home stack is isn't in multi-window mode.
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002381 break;
2382 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002383 final int taskId = stack.taskIdFromPoint(x, y);
2384 if (taskId != -1) {
2385 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002386 }
2387 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002388 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002389 }
2390
Chong Zhang8e89b312015-09-09 15:09:30 -07002391 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002392 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002393 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002394 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002395 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002396 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002397 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002398 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2399 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002400 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002401 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002402 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002403
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002404 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2405 if (mTmpTaskForResizePointSearchResult.searchDone) {
2406 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002407 }
2408 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002409 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002410 }
2411
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002412 void updateTouchExcludeRegion() {
2413 final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null);
David Stevensee9e2772017-02-09 16:30:27 -08002414 if (focusedTask == null) {
2415 mTouchExcludeRegion.setEmpty();
2416 } else {
2417 mTouchExcludeRegion.set(mBaseDisplayRect);
2418 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2419 mTmpRect2.setEmpty();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002420 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0;
2421 --stackNdx) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002422 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002423 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2424 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002425 }
2426 // If we removed the focused task above, add it back and only leave its
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002427 // outside touch area in the exclusion. TapDetector is not interested in
David Stevensee9e2772017-02-09 16:30:27 -08002428 // any touch inside the focused task itself.
2429 if (!mTmpRect2.isEmpty()) {
2430 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2431 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002432 }
lumark90120a82018-08-15 00:33:03 +08002433 if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) {
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002434 // If the input method is visible and the user is typing, we don't want these touch
2435 // events to be intercepted and used to change focus. This would likely cause a
2436 // disappearance of the input method.
lumark90120a82018-08-15 00:33:03 +08002437 mInputMethodWindow.getTouchableRegion(mTmpRegion);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002438 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002439 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002440 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002441 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002442 win.getTouchableRegion(mTmpRegion);
2443 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2444 }
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002445 amendWindowTapExcludeRegion(mTouchExcludeRegion);
Andrii Kulian03c403d2016-11-11 11:14:12 -08002446 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002447 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002448 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002449 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002450 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2451 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002452 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002453 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002454 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002455 }
2456
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002457 /**
2458 * Union the region with all the tap exclude region provided by windows on this display.
2459 *
2460 * @param inOutRegion The region to be amended.
2461 */
2462 void amendWindowTapExcludeRegion(Region inOutRegion) {
2463 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2464 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2465 win.amendTapExcludeRegion(inOutRegion);
2466 }
2467 }
2468
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002469 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002470 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002471 super.switchUser();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002472 mWmService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002473 }
2474
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002475 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002476 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2477 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002478 }
2479 }
2480
Wale Ogunwale10124582016-09-15 20:25:50 -07002481 @Override
2482 void removeIfPossible() {
2483 if (isAnimating()) {
2484 mDeferredRemoval = true;
2485 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002486 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002487 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002488 }
2489
Wale Ogunwale10124582016-09-15 20:25:50 -07002490 @Override
2491 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002492 mRemovingDisplay = true;
2493 try {
lumark588a3e82018-07-20 18:53:54 +08002494 // Clear all transitions & screen frozen states when removing display.
2495 mOpeningApps.clear();
2496 mClosingApps.clear();
Evan Rosky2289ba12018-11-19 18:28:18 -08002497 mChangingApps.clear();
lumark588a3e82018-07-20 18:53:54 +08002498 mUnknownAppVisibilityController.clear();
2499 mAppTransition.removeAppTransitionTimeoutCallbacks();
2500 handleAnimatingStoppedAndTransition();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002501 mWmService.stopFreezingDisplayLocked();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002502 super.removeImmediately();
2503 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002504 if (mPointerEventDispatcher != null && mTapDetector != null) {
2505 unregisterPointerEventListener(mTapDetector);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002506 unregisterPointerEventListener(mWmService.mMousePositionTracker);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002507 mTapDetector = null;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002508 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002509 mWmService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002510 mWindowingLayer.release();
2511 mOverlayLayer.release();
Jorim Jaggiae962e62018-12-27 17:23:48 +01002512 mInputMonitor.onDisplayRemoved();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002513 } finally {
Riddle Hsu4e611772018-10-31 18:58:28 +08002514 mDisplayReady = false;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002515 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002516 }
Robert Carr679ccb02018-08-08 15:32:35 -07002517
Tiger Huang7c610aa2018-10-27 00:01:01 +08002518 mDisplayPolicy.onDisplayRemoved();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002519 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautner95da1082014-02-24 17:54:35 -08002520 }
2521
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002522 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002523 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002524 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002525 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2526
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002527 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002528 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002529 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002530 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002531 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002532 }
2533
Andrii Kulian0214ed92017-05-16 13:44:05 -07002534 /** @return 'true' if removal of this display content is deferred due to active animation. */
2535 boolean isRemovalDeferred() {
2536 return mDeferredRemoval;
2537 }
2538
Wale Ogunwale10124582016-09-15 20:25:50 -07002539 boolean animateForIme(float interpolatedValue, float animationTarget,
2540 float dividerAnimationTarget) {
2541 boolean updated = false;
2542
Wale Ogunwale61911492017-10-11 08:50:50 -07002543 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2544 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002545 if (stack == null || !stack.isAdjustedForIme()) {
2546 continue;
2547 }
2548
2549 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2550 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2551 updated = true;
2552 } else {
2553 mDividerControllerLocked.mLastAnimationProgress =
2554 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2555 mDividerControllerLocked.mLastDividerProgress =
2556 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2557 updated |= stack.updateAdjustForIme(
2558 mDividerControllerLocked.mLastAnimationProgress,
2559 mDividerControllerLocked.mLastDividerProgress,
2560 false /* force */);
2561 }
2562 if (interpolatedValue >= 1f) {
2563 stack.endImeAdjustAnimation();
2564 }
2565 }
2566
2567 return updated;
2568 }
2569
2570 boolean clearImeAdjustAnimation() {
2571 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002572 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2573 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002574 if (stack != null && stack.isAdjustedForIme()) {
2575 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2576 changed = true;
2577 }
2578 }
2579 return changed;
2580 }
2581
2582 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002583 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2584 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002585 if (stack.isVisible() && stack.isAdjustedForIme()) {
2586 stack.beginImeAdjustAnimation();
2587 }
2588 }
2589 }
2590
2591 void adjustForImeIfNeeded() {
lumark90120a82018-08-15 00:33:03 +08002592 final WindowState imeWin = mInputMethodWindow;
Wale Ogunwale10124582016-09-15 20:25:50 -07002593 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2594 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002595 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002596 final TaskStack imeTargetStack = mWmService.getImeFocusStackLocked();
Wale Ogunwale10124582016-09-15 20:25:50 -07002597 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2598 imeTargetStack.getDockSide() : DOCKED_INVALID;
2599 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2600 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2601 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002602 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002603 final boolean imeHeightChanged = imeVisible &&
2604 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2605
2606 // The divider could be adjusted for IME position, or be thinner than usual,
2607 // or both. There are three possible cases:
2608 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2609 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2610 // - If IME is not visible, divider is not moved and is normal width.
2611
2612 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002613 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2614 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002615 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002616 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2617 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002618 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2619 } else {
2620 stack.resetAdjustedForIme(false);
2621 }
2622 }
2623 mDividerControllerLocked.setAdjustedForIme(
2624 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2625 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002626 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2627 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002628 stack.resetAdjustedForIme(!dockVisible);
2629 }
2630 mDividerControllerLocked.setAdjustedForIme(
2631 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2632 }
Winson Chung655332c2016-10-31 13:14:28 -07002633 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002634 }
2635
2636 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002637 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2638 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002639 stack.prepareFreezingTaskBounds();
2640 }
2641 }
2642
Wale Ogunwale94744212015-09-21 19:01:47 -07002643 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002644 getBounds(mTmpRect, newRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002645 rotateBounds(mTmpRect, oldRotation, newRotation, bounds);
2646 }
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002647
Evan Rosky39b6f232018-10-30 18:35:41 -07002648 void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002649 // Compute a transform matrix to undo the coordinate space transformation,
2650 // and present the window at the same physical position it previously occupied.
2651 final int deltaRotation = deltaRotation(newRotation, oldRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002652 createRotationMatrix(
2653 deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002654
2655 mTmpRectF.set(bounds);
2656 mTmpMatrix.mapRect(mTmpRectF);
2657 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002658 }
2659
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002660 static int deltaRotation(int oldRotation, int newRotation) {
2661 int delta = newRotation - oldRotation;
2662 if (delta < 0) delta += 4;
2663 return delta;
2664 }
2665
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002666 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002667 Matrix outMatrix) {
2668 // For rotations without Z-ordering we don't need the target rectangle's position.
2669 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2670 displayHeight, outMatrix);
2671 }
2672
2673 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2674 float displayWidth, float displayHeight, Matrix outMatrix) {
2675 switch (rotation) {
2676 case ROTATION_0:
2677 outMatrix.reset();
2678 break;
2679 case ROTATION_270:
2680 outMatrix.setRotate(270, 0, 0);
2681 outMatrix.postTranslate(0, displayHeight);
2682 outMatrix.postTranslate(rectTop, 0);
2683 break;
2684 case ROTATION_180:
2685 outMatrix.reset();
2686 break;
2687 case ROTATION_90:
2688 outMatrix.setRotate(90, 0, 0);
2689 outMatrix.postTranslate(displayWidth, 0);
2690 outMatrix.postTranslate(-rectTop, rectLeft);
2691 break;
2692 }
2693 }
2694
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002695 @CallSuper
2696 @Override
Nataniel Borges023ecb52019-01-16 14:15:43 -08002697 public void writeToProto(ProtoOutputStream proto, long fieldId,
2698 @WindowTraceLogLevel int logLevel) {
2699 // Critical log level logs only visible elements to mitigate performance overheard
2700 if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) {
2701 return;
2702 }
2703
Steven Timotiusaf03df62017-07-18 16:56:43 -07002704 final long token = proto.start(fieldId);
Nataniel Borges023ecb52019-01-16 14:15:43 -08002705 super.writeToProto(proto, WINDOW_CONTAINER, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002706 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002707 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2708 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Nataniel Borges023ecb52019-01-16 14:15:43 -08002709 stack.writeToProto(proto, STACKS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002710 }
2711 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2712 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002713 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2714 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Nataniel Borges023ecb52019-01-16 14:15:43 -08002715 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002716 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002717 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2718 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Nataniel Borges023ecb52019-01-16 14:15:43 -08002719 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002720 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002721 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2722 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Nataniel Borges023ecb52019-01-16 14:15:43 -08002723 windowToken.writeToProto(proto, IME_WINDOWS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002724 }
2725 proto.write(DPI, mBaseDisplayDensity);
2726 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002727 proto.write(ROTATION, mRotation);
2728 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002729 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002730 if (screenRotationAnimation != null) {
2731 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2732 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002733 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
lumark588a3e82018-07-20 18:53:54 +08002734 mAppTransition.writeToProto(proto, APP_TRANSITION);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002735 if (mFocusedApp != null) {
2736 mFocusedApp.writeNameToProto(proto, FOCUSED_APP);
2737 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002738 proto.end(token);
2739 }
2740
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002741 @Override
2742 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2743 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002744 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2745 final String subPrefix = " " + prefix;
2746 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2747 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2748 pw.print("dpi");
2749 if (mInitialDisplayWidth != mBaseDisplayWidth
2750 || mInitialDisplayHeight != mBaseDisplayHeight
2751 || mInitialDisplayDensity != mBaseDisplayDensity) {
2752 pw.print(" base=");
2753 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2754 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2755 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002756 if (mDisplayScalingDisabled) {
2757 pw.println(" noscale");
2758 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002759 pw.print(" cur=");
2760 pw.print(mDisplayInfo.logicalWidth);
2761 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2762 pw.print(" app=");
2763 pw.print(mDisplayInfo.appWidth);
2764 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2765 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2766 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2767 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2768 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002769 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002770 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002771 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002772
Craig Mautnerdc548482014-02-05 13:35:24 -08002773 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002774 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002775 pw.print(prefix);
2776 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002777
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002778 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
2779 if (mLastFocus != mCurrentFocus) {
2780 pw.print(" mLastFocus="); pw.println(mLastFocus);
2781 }
2782 if (mLosingFocus.size() > 0) {
2783 pw.println();
2784 pw.println(" Windows losing focus:");
2785 for (int i = mLosingFocus.size() - 1; i >= 0; i--) {
2786 final WindowState w = mLosingFocus.get(i);
2787 pw.print(" Losing #"); pw.print(i); pw.print(' ');
2788 pw.print(w);
2789 if (dumpAll) {
2790 pw.println(":");
2791 w.dump(pw, " ", true);
2792 } else {
2793 pw.println();
2794 }
2795 }
2796 }
2797 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
Tiger Huang7c610aa2018-10-27 00:01:01 +08002798 if (mLastStatusBarVisibility != 0) {
2799 pw.print(" mLastStatusBarVisibility=0x");
2800 pw.println(Integer.toHexString(mLastStatusBarVisibility));
2801 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002802
Adrian Roos5251b1d2018-03-23 18:57:43 +01002803 pw.println();
wilsonshihc32538e2018-11-07 17:27:34 +08002804 mWallpaperController.dump(pw, " ");
2805
2806 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002807 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002808 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2809 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002810 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002811 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002812
Craig Mautnerdc548482014-02-05 13:35:24 -08002813 pw.println();
2814 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002815 pw.println();
2816 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002817 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002818 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002819 pw.print(" Exiting #"); pw.print(i);
2820 pw.print(' '); pw.print(token);
2821 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002822 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002823 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002824 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002825
Jorim Jaggi31f71702016-05-04 16:43:04 -07002826 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002827
2828 // Dump stack references
2829 final TaskStack homeStack = getHomeStack();
2830 if (homeStack != null) {
2831 pw.println(prefix + "homeStack=" + homeStack.getName());
2832 }
2833 final TaskStack pinnedStack = getPinnedStack();
2834 if (pinnedStack != null) {
2835 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2836 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002837 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002838 if (splitScreenPrimaryStack != null) {
2839 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2840 }
2841
2842 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002843 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002844 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002845 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002846
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002847 pw.println();
2848 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002849 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002850 mDisplayPolicy.dump(prefix, pw);
2851 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002852 mDisplayRotation.dump(prefix, pw);
2853 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002854 mInputMonitor.dump(pw, " ");
Jorim Jaggif96c90a2018-09-26 16:55:15 +02002855 pw.println();
2856 mInsetsStateController.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002857 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002858
2859 @Override
2860 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002861 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002862 }
2863
2864 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002865 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002866 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002867
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002868 /** Returns true if the stack in the windowing mode is visible. */
2869 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002870 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002871 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002872 }
2873
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002874 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002875 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002876 final int x = (int) xf;
2877 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002878 final WindowState touchedWin = getWindow(w -> {
2879 final int flags = w.mAttrs.flags;
2880 if (!w.isVisibleLw()) {
2881 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002882 }
2883 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002884 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002885 }
2886
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002887 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002888 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002889 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002890 }
2891
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002892 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002893
2894 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002895 return mTmpRegion.contains(x, y) || touchFlags == 0;
2896 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002897
2898 return touchedWin;
2899 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002900
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002901 boolean canAddToastWindowForUid(int uid) {
2902 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002903 // Also if the app is focused adding more than one toast at
2904 // a time for better backwards compatibility.
2905 final WindowState focusedWindowForUid = getWindow(w ->
2906 w.mOwnerUid == uid && w.isFocused());
2907 if (focusedWindowForUid != null) {
2908 return true;
2909 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002910 final WindowState win = getWindow(w ->
2911 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2912 && !w.mWindowRemovalAllowed);
2913 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002914 }
2915
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002916 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002917 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2918 return;
2919 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002920
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002921 // Used to communicate the old focus to the callback method.
2922 mTmpWindow = oldFocus;
2923
2924 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002925 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002926
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002927 WindowState findFocusedWindowIfNeeded() {
2928 return (mWmService.mPerDisplayFocusEnabled
2929 || mWmService.mRoot.mTopFocusedAppByProcess.isEmpty()) ? findFocusedWindow() : null;
2930 }
2931
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002932 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002933 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002934
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002935 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002936
2937 if (mTmpWindow == null) {
2938 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2939 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002940 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002941 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002942 }
2943
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002944 /**
2945 * Update the focused window and make some adjustments if the focus has changed.
2946 *
2947 * @param mode Indicates the situation we are in. Possible modes are:
2948 * {@link WindowManagerService#UPDATE_FOCUS_NORMAL},
2949 * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES},
2950 * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES},
2951 * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS}
2952 * @param updateInputWindows Whether to sync the window information to the input module.
2953 * @return {@code true} if the focused window has changed.
2954 */
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002955 boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
2956 WindowState newFocus = findFocusedWindowIfNeeded();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002957 if (mCurrentFocus == newFocus) {
2958 return false;
2959 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002960 boolean imWindowChanged = false;
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002961 final WindowState imWindow = mInputMethodWindow;
2962 if (imWindow != null) {
2963 final WindowState prevTarget = mInputMethodTarget;
2964 final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/);
2965 imWindowChanged = prevTarget != newTarget;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002966
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002967 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS
2968 && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2969 assignWindowLayers(false /* setLayoutNeeded */);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002970 }
2971 }
2972
2973 if (imWindowChanged) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002974 mWmService.mWindowsChanged = true;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002975 setLayoutNeeded();
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002976 newFocus = findFocusedWindowIfNeeded();
2977 }
2978 if (mCurrentFocus != newFocus) {
2979 mWmService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002980 }
2981
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002982 if (DEBUG_FOCUS_LIGHT || mWmService.localLOGV) Slog.v(TAG_WM, "Changing focus from "
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002983 + mCurrentFocus + " to " + newFocus + " displayId=" + getDisplayId()
2984 + " Callers=" + Debug.getCallers(4));
2985 final WindowState oldFocus = mCurrentFocus;
2986 mCurrentFocus = newFocus;
2987 mLosingFocus.remove(newFocus);
2988
2989 if (newFocus != null) {
2990 mWinAddedSinceNullFocus.clear();
2991 mWinRemovedSinceNullFocus.clear();
2992
2993 if (newFocus.canReceiveKeys()) {
2994 // Displaying a window implicitly causes dispatching to be unpaused.
2995 // This is to protect against bugs if someone pauses dispatching but
2996 // forgets to resume.
2997 newFocus.mToken.paused = false;
2998 }
2999 }
3000
Tiger Huang7c610aa2018-10-27 00:01:01 +08003001 int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003002
3003 if (imWindowChanged && oldFocus != mInputMethodWindow) {
3004 // Focus of the input method window changed. Perform layout if needed.
3005 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
3006 performLayout(true /*initial*/, updateInputWindows);
3007 focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT;
3008 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
3009 // Client will do the layout, but we need to assign layers
3010 // for handleNewWindowLocked() below.
3011 assignWindowLayers(false /* setLayoutNeeded */);
3012 }
3013 }
3014
3015 if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3016 // The change in focus caused us to need to do a layout. Okay.
3017 setLayoutNeeded();
3018 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
3019 performLayout(true /*initial*/, updateInputWindows);
3020 } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003021 mWmService.mRoot.performSurfacePlacement(false);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003022 }
3023 }
3024
3025 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
3026 // If we defer assigning layers, then the caller is responsible for doing this part.
3027 getInputMonitor().setInputFocusLw(newFocus, updateInputWindows);
3028 }
3029
3030 adjustForImeIfNeeded();
3031
3032 // We may need to schedule some toast windows to be removed. The toasts for an app that
3033 // does not have input focus are removed within a timeout to prevent apps to redress
3034 // other apps' UI.
3035 scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus);
3036
3037 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
3038 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
3039 }
3040 return true;
3041 }
3042
3043 /**
3044 * Set the new focused app to this display.
3045 *
3046 * @param newFocus the new focused AppWindowToken.
3047 * @return true if the focused app is changed.
3048 */
3049 boolean setFocusedApp(AppWindowToken newFocus) {
3050 if (newFocus != null) {
3051 final DisplayContent appDisplay = newFocus.getDisplayContent();
3052 if (appDisplay != this) {
3053 throw new IllegalStateException(newFocus + " is not on " + getName()
3054 + " but " + ((appDisplay != null) ? appDisplay.getName() : "none"));
3055 }
3056 }
3057 if (mFocusedApp == newFocus) {
3058 return false;
3059 }
3060 mFocusedApp = newFocus;
3061 getInputMonitor().setFocusedAppLw(newFocus);
3062 updateTouchExcludeRegion();
3063 return true;
3064 }
3065
Wale Ogunwalec69694a2016-10-18 13:51:15 -07003066 /** Updates the layer assignment of windows on this display. */
3067 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003068 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07003069 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07003070 if (setLayoutNeeded) {
3071 setLayoutNeeded();
3072 }
Robert Carrb1579c82017-09-05 14:54:47 -07003073
Robert Carrf59b8dd2017-10-02 18:58:36 -07003074 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07003075 // the application of this transaction until the animation pass triggers
3076 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
3077 // the hiding and showing of surfaces.
3078 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003079 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07003080 }
3081
Wale Ogunwale1666e312016-12-16 11:27:18 -08003082 // TODO: This should probably be called any time a visual change is made to the hierarchy like
3083 // moving containers or resizing them. Need to investigate the best way to have it automatically
3084 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003085 void layoutAndAssignWindowLayersIfNeeded() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003086 mWmService.mWindowsChanged = true;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003087 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003088
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003089 if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003090 false /*updateInputWindows*/)) {
3091 assignWindowLayers(false /* setLayoutNeeded */);
3092 }
3093
Arthur Hung95b38a92018-07-20 18:56:12 +08003094 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003095 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08003096 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003097 }
3098
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003099 /** Returns true if a leaked surface was destroyed */
3100 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003101 // Used to indicate that a surface was leaked.
3102 mTmpWindow = null;
3103 forAllWindows(w -> {
3104 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003105 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003106 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003107 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003108 if (!mWmService.mSessions.contains(wsa.mSession)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003109 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003110 + w + " surface=" + wsa.mSurfaceController
3111 + " token=" + w.mToken
3112 + " pid=" + w.mSession.mPid
3113 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003114 wsa.destroySurface();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003115 mWmService.mForceRemoves.add(w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003116 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07003117 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003118 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003119 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003120 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003121 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003122 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003123 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003124 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003125 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003126
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003127 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003128 }
3129
3130 /**
lumark90120a82018-08-15 00:33:03 +08003131 * Set input method window for the display.
3132 * @param win Set when window added or Null when destroyed.
3133 */
3134 void setInputMethodWindowLocked(WindowState win) {
3135 mInputMethodWindow = win;
lumark70865a82018-09-17 16:56:26 +08003136 // Update display configuration for IME process.
3137 if (mInputMethodWindow != null) {
3138 final int imePid = mInputMethodWindow.mSession.mPid;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003139 mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid,
lumark70865a82018-09-17 16:56:26 +08003140 mInputMethodWindow.getDisplayId());
3141 }
lumark90120a82018-08-15 00:33:03 +08003142 computeImeTarget(true /* updateImeTarget */);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003143 mInsetsStateController.getSourceProvider(TYPE_IME).setWindow(win,
3144 null /* frameProvider */);
lumark90120a82018-08-15 00:33:03 +08003145 }
3146
3147 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003148 * Determine and return the window that should be the IME target.
3149 * @param updateImeTarget If true the system IME target will be updated to match what we found.
3150 * @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 +00003151 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003152 WindowState computeImeTarget(boolean updateImeTarget) {
lumark90120a82018-08-15 00:33:03 +08003153 if (mInputMethodWindow == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003154 // There isn't an IME so there shouldn't be a target...That was easy!
3155 if (updateImeTarget) {
3156 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
lumarkff0ab692018-11-05 20:32:30 +08003157 + mInputMethodTarget + " to null since mInputMethodWindow is null");
3158 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003159 }
3160 return null;
3161 }
3162
lumarkff0ab692018-11-05 20:32:30 +08003163 final WindowState curTarget = mInputMethodTarget;
Chavi Weingarten3a748552018-05-14 17:32:42 +00003164 if (!canUpdateImeTarget()) {
3165 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
3166 return curTarget;
3167 }
3168
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003169 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
3170 // same display. Or even when the current IME/target are not on the same screen as the next
3171 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08003172 mUpdateImeTarget = updateImeTarget;
3173 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003174
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003175
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003176 // Yet more tricksyness! If this window is a "starting" window, we do actually want
3177 // to be on top of it, but it is not -really- where input will go. So look down below
3178 // for a real window to target...
3179 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
3180 final AppWindowToken token = target.mAppToken;
3181 if (token != null) {
3182 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
3183 if (betterTarget != null) {
3184 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003185 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003186 }
3187 }
3188
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003189 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
lumarkff0ab692018-11-05 20:32:30 +08003190 "Proposed new IME target: " + target + " for display: " + getDisplayId());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003191
chaviw1c13ad32018-06-12 16:44:23 -07003192 // Now, a special case -- if the last target's window is in the process of exiting, but
3193 // not removed, and the new target is home, keep on the last target to avoid flicker.
3194 // Home is a special case since its above other stacks in the ordering list, but layed
3195 // out below the others.
3196 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
3197 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07003198 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00003199 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003200 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003201 }
3202
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003203 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
3204 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003205
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003206 if (target == null) {
3207 if (updateImeTarget) {
3208 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
3209 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
3210 + Debug.getCallers(4) : ""));
lumarkff0ab692018-11-05 20:32:30 +08003211 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003212 }
3213
3214 return null;
3215 }
3216
3217 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003218 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
3219 if (token != null) {
3220
3221 // Now some fun for dealing with window animations that modify the Z order. We need
3222 // to look at all windows below the current target that are in this app, finding the
3223 // highest visible one in layering.
3224 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003225 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003226 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003227 }
3228
3229 if (highestTarget != null) {
lumark588a3e82018-07-20 18:53:54 +08003230 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, mAppTransition + " " + highestTarget
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003231 + " animating=" + highestTarget.isAnimating());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003232
lumark588a3e82018-07-20 18:53:54 +08003233 if (mAppTransition.isTransitionSet()) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003234 // If we are currently setting up for an animation, hold everything until we
3235 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003236 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003237 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003238 }
3239 }
3240 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003241
3242 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
3243 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003244 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003245 }
3246
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003247 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003248 }
3249
lumarkff0ab692018-11-05 20:32:30 +08003250 /**
3251 * Calling {@link #computeImeTarget(boolean)} to update the input method target window in
3252 * the candidate app window token if needed.
3253 */
3254 void computeImeTargetIfNeeded(AppWindowToken candidate) {
3255 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == candidate) {
3256 computeImeTarget(true /* updateImeTarget */);
3257 }
3258 }
3259
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003260 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
lumarkff0ab692018-11-05 20:32:30 +08003261 if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003262 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003263 }
3264
lumarkff0ab692018-11-05 20:32:30 +08003265 mInputMethodTarget = target;
3266 mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003267 assignWindowLayers(false /* setLayoutNeeded */);
Tarandeep Singh215929b2019-01-11 18:24:37 -08003268 mInsetsStateController.onImeTargetChanged(target);
Tarandeep Singha6f35612019-01-11 19:50:46 -08003269 updateImeParent();
3270 }
3271
3272 private void updateImeParent() {
Tarandeep Singha6f35612019-01-11 19:50:46 -08003273 final SurfaceControl newParent = computeImeParent();
3274 if (newParent != null) {
3275 mPendingTransaction.reparent(mImeWindowsContainers.mSurfaceControl, newParent);
3276 scheduleAnimation();
3277 }
3278 }
3279
3280 /**
3281 * Computes the window the IME should be attached to.
3282 */
3283 @VisibleForTesting
3284 SurfaceControl computeImeParent() {
3285
3286 // Attach it to app if the target is part of an app and such app is covering the entire
3287 // screen. If it's not covering the entire screen the IME might extend beyond the apps
3288 // bounds.
3289 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken != null &&
3290 mInputMethodTarget.getWindowingMode() == WINDOWING_MODE_FULLSCREEN) {
3291 return mInputMethodTarget.mAppToken.getSurfaceControl();
3292 }
3293
3294 // Otherwise, we just attach it to the display.
3295 return mWindowingLayer;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003296 }
3297
3298 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
3299 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3300 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
3301 }
3302
3303 // Used to indicate we have reached the first window in the range we are interested in.
3304 mTmpWindow = null;
3305
3306 // TODO: Figure-out a more efficient way to do this.
3307 final WindowState candidate = getWindow(w -> {
3308 if (w == top) {
3309 // Reached the first window in the range we are interested in.
3310 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003311 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003312 if (mTmpWindow == null) {
3313 return false;
3314 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003315
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003316 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3317 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003318 }
3319 // If we reached the bottom of the range of windows we are considering,
3320 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003321 if (w == bottom) {
3322 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003323 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003324 return false;
3325 });
3326
3327 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003328 }
3329
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003330 void setLayoutNeeded() {
3331 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
3332 mLayoutNeeded = true;
3333 }
3334
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003335 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003336 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
3337 mLayoutNeeded = false;
3338 }
3339
3340 boolean isLayoutNeeded() {
3341 return mLayoutNeeded;
3342 }
3343
Wale Ogunwale02319a62016-09-26 15:21:22 -07003344 void dumpTokens(PrintWriter pw, boolean dumpAll) {
3345 if (mTokenMap.isEmpty()) {
3346 return;
3347 }
3348 pw.println(" Display #" + mDisplayId);
3349 final Iterator<WindowToken> it = mTokenMap.values().iterator();
3350 while (it.hasNext()) {
3351 final WindowToken token = it.next();
3352 pw.print(" ");
3353 pw.print(token);
3354 if (dumpAll) {
3355 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003356 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07003357 } else {
3358 pw.println();
3359 }
3360 }
lumark588a3e82018-07-20 18:53:54 +08003361
Evan Rosky2289ba12018-11-19 18:28:18 -08003362 if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty() || !mChangingApps.isEmpty()) {
lumark588a3e82018-07-20 18:53:54 +08003363 pw.println();
3364 if (mOpeningApps.size() > 0) {
3365 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
3366 }
3367 if (mClosingApps.size() > 0) {
3368 pw.print(" mClosingApps="); pw.println(mClosingApps);
3369 }
Evan Rosky2289ba12018-11-19 18:28:18 -08003370 if (mChangingApps.size() > 0) {
3371 pw.print(" mChangingApps="); pw.println(mChangingApps);
3372 }
lumark588a3e82018-07-20 18:53:54 +08003373 }
3374
3375 mUnknownAppVisibilityController.dump(pw, " ");
Wale Ogunwale02319a62016-09-26 15:21:22 -07003376 }
3377
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003378 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003379 final int[] index = new int[1];
3380 forAllWindows(w -> {
3381 final WindowStateAnimator wAnim = w.mWinAnimator;
3382 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
3383 index[0] = index[0] + 1;
3384 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003385 }
3386
Jorim Jaggife762342016-10-13 14:33:27 +02003387 /**
3388 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
3389 */
3390 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003391 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003392 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02003393 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
3394 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01003395 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02003396 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003397 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02003398 }
3399
Wale Ogunwale494009b82016-10-21 09:01:38 -07003400 boolean checkWaitingForWindows() {
3401
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003402 mHaveBootMsg = false;
3403 mHaveApp = false;
3404 mHaveWallpaper = false;
3405 mHaveKeyguard = true;
3406
3407 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003408 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
3409 return true;
3410 }
3411 if (w.isDrawnLw()) {
3412 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003413 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003414 } else if (w.mAttrs.type == TYPE_APPLICATION
3415 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003416 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003417 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003418 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003419 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003420 mHaveKeyguard = mWmService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003421 }
3422 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003423 return false;
3424 });
3425
3426 if (visibleWindow != null) {
3427 // We have a visible window.
3428 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003429 }
3430
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003431 // if the wallpaper service is disabled on the device, we're never going to have
3432 // wallpaper, don't bother waiting for it
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003433 boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean(
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003434 com.android.internal.R.bool.config_enableWallpaperService)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003435 && mWmService.mContext.getResources().getBoolean(
Daichi Hironoc1432222018-03-29 13:06:07 +09003436 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003437 && !mWmService.mOnlyCore;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003438
Wale Ogunwale494009b82016-10-21 09:01:38 -07003439 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003440 "******** booted=" + mWmService.mSystemBooted
3441 + " msg=" + mWmService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003442 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
3443 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
3444 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003445
3446 // If we are turning on the screen to show the boot message, don't do it until the boot
3447 // message is actually displayed.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003448 if (!mWmService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003449 return true;
3450 }
3451
3452 // If we are turning on the screen after the boot is completed normally, don't do so until
3453 // we have the application and wallpaper.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003454 if (mWmService.mSystemBooted
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003455 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003456 return true;
3457 }
3458
3459 return false;
3460 }
3461
Jorim Jaggi8f520872018-08-14 17:00:20 +02003462 void updateWindowsForAnimator() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003463 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003464 }
3465
Jorim Jaggi8f520872018-08-14 17:00:20 +02003466 /**
3467 * Updates the {@link TaskStack#setAnimationBackground} for all windows.
3468 */
3469 void updateBackgroundForAnimator() {
Jorim Jaggi7156b652016-10-25 08:31:58 -07003470 resetAnimationBackgroundAnimator();
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003471 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003472 }
3473
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003474 boolean isInputMethodClientFocus(int uid, int pid) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003475 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003476 if (imFocus == null) {
3477 return false;
3478 }
3479
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003480 if (DEBUG_INPUT_METHOD) {
3481 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003482 Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId);
3483 Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003484 }
3485
Wale Ogunwale494009b82016-10-21 09:01:38 -07003486 if (DEBUG_INPUT_METHOD) {
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003487 Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid
3488 + "/" + imFocus.mSession.mPid);
3489 Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003490 }
3491
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003492 return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003493 }
3494
3495 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003496 final WindowState win = getWindow(
3497 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
3498 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003499 }
3500
Tiger Huang7c610aa2018-10-27 00:01:01 +08003501 void statusBarVisibilityChanged(int visibility) {
3502 mLastStatusBarVisibility = visibility;
3503 visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility);
3504 updateStatusBarVisibilityLocked(visibility);
3505 }
3506
3507 private boolean updateStatusBarVisibilityLocked(int visibility) {
3508 if (mLastDispatchedSystemUiVisibility == visibility) {
3509 return false;
3510 }
3511 final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility)
3512 // We are only interested in differences of one of the
3513 // clearable flags...
3514 & View.SYSTEM_UI_CLEARABLE_FLAGS
3515 // ...if it has actually been cleared.
3516 & ~visibility;
3517
3518 mLastDispatchedSystemUiVisibility = visibility;
3519 if (isDefaultDisplay) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003520 mWmService.mInputManager.setSystemUiVisibility(visibility);
Tiger Huang7c610aa2018-10-27 00:01:01 +08003521 }
3522 updateSystemUiVisibility(visibility, globalDiff);
3523 return true;
3524 }
3525
Wale Ogunwale494009b82016-10-21 09:01:38 -07003526 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003527 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003528 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003529 final int curValue = w.mSystemUiVisibility;
3530 final int diff = (curValue ^ visibility) & globalDiff;
3531 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003532 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003533 w.mSeq++;
3534 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003535 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003536 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
3537 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07003538 visibility, newValue, diff);
3539 }
3540 } catch (RemoteException e) {
3541 // so sorry
3542 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003543 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003544 }
3545
Tiger Huang7c610aa2018-10-27 00:01:01 +08003546 void reevaluateStatusBarVisibility() {
3547 int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility);
3548 if (updateStatusBarVisibilityLocked(visibility)) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003549 mWmService.mWindowPlacerLocked.requestTraversal();
Tiger Huang7c610aa2018-10-27 00:01:01 +08003550 }
3551 }
3552
Wale Ogunwale494009b82016-10-21 09:01:38 -07003553 void onWindowFreezeTimeout() {
3554 Slog.w(TAG_WM, "Window freeze timeout expired.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003555 mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003556
3557 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003558 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003559 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003560 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07003561 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003562 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003563 - mWmService.mDisplayFreezeTime);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003564 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003565 }, true /* traverseTopToBottom */);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003566 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003567 }
3568
3569 void waitForAllWindowsDrawn() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003570 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003571 forAllWindows(w -> {
3572 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
3573 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
3574 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003575 // Force add to mResizingWindows.
chaviw9c81e632018-07-31 11:17:52 -07003576 w.resetLastContentInsets();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003577 mWmService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003578 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003579 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003580 }
3581
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003582 // TODO: Super crazy long method that should be broken down...
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003583 void applySurfaceChangesTransaction(boolean recoveringMemory) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003584 final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003585
3586 mTmpUpdateAllDrawn.clear();
3587
3588 int repeats = 0;
3589 do {
3590 repeats++;
3591 if (repeats > 6) {
3592 Slog.w(TAG, "Animation repeat aborted after too many iterations");
3593 clearLayoutNeeded();
3594 break;
3595 }
3596
3597 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
3598 pendingLayoutChanges);
3599
wilsonshihc32538e2018-11-07 17:27:34 +08003600 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
3601 mWallpaperController.adjustWallpaperWindows();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003602 }
3603
Riddle Hsu654a6f92018-07-13 22:59:36 +08003604 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003605 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Riddle Hsu4e611772018-10-31 18:58:28 +08003606 if (updateOrientationFromAppTokens()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003607 setLayoutNeeded();
Riddle Hsu4e611772018-10-31 18:58:28 +08003608 sendNewConfiguration();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003609 }
3610 }
3611
3612 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3613 setLayoutNeeded();
3614 }
3615
3616 // FIRST LOOP: Perform a layout, if needed.
3617 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3618 performLayout(repeats == 1, false /* updateInputWindows */);
3619 } else {
3620 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3621 }
3622
3623 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3624 pendingLayoutChanges = 0;
3625
Tiger Huang7c610aa2018-10-27 00:01:01 +08003626 mDisplayPolicy.beginPostLayoutPolicyLw();
3627 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
3628 pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw();
3629 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3630 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003631 mInsetsStateController.onPostLayout();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003632 } while (pendingLayoutChanges != 0);
3633
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003634 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003635
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003636 mTmpRecoveringMemory = recoveringMemory;
3637 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003638 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003639
Jorim Jaggif1292892018-09-10 11:58:13 +02003640 mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003641 mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggif1292892018-09-10 11:58:13 +02003642 mLastHasContent,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003643 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3644 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003645 true /* inTraversal, must call performTraversalInTrans... below */);
3646
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003647 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3648 if (wallpaperVisible != mLastWallpaperVisible) {
3649 mLastWallpaperVisible = wallpaperVisible;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003650 mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003651 }
3652
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003653 while (!mTmpUpdateAllDrawn.isEmpty()) {
3654 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3655 // See if any windows have been drawn, so they (and others associated with them)
3656 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003657 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003658 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003659 }
3660
Bryce Leef3c6a472017-11-14 14:53:06 -08003661 private void updateBounds() {
Evan Rosky39b6f232018-10-30 18:35:41 -07003662 calculateBounds(mDisplayInfo, mTmpBounds);
Bryce Leef3c6a472017-11-14 14:53:06 -08003663 setBounds(mTmpBounds);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08003664 if (mPortalWindowHandle != null && mParentSurfaceControl != null) {
3665 mPortalWindowHandle.touchableRegion.getBounds(mTmpRect);
3666 if (!mTmpBounds.equals(mTmpRect)) {
3667 mPortalWindowHandle.touchableRegion.set(mTmpBounds);
3668 mPendingTransaction.setInputWindowInfo(mParentSurfaceControl, mPortalWindowHandle);
3669 }
3670 }
Bryce Leef3c6a472017-11-14 14:53:06 -08003671 }
3672
3673 // Determines the current display bounds based on the current state
Evan Rosky39b6f232018-10-30 18:35:41 -07003674 private void calculateBounds(DisplayInfo displayInfo, Rect out) {
Bryce Leef3c6a472017-11-14 14:53:06 -08003675 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Evan Rosky39b6f232018-10-30 18:35:41 -07003676 final int rotation = displayInfo.rotation;
3677 boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Bryce Leef3c6a472017-11-14 14:53:06 -08003678 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3679 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Evan Rosky39b6f232018-10-30 18:35:41 -07003680 int width = displayInfo.logicalWidth;
Bryce Leef3c6a472017-11-14 14:53:06 -08003681 int left = (physWidth - width) / 2;
Evan Rosky39b6f232018-10-30 18:35:41 -07003682 int height = displayInfo.logicalHeight;
Bryce Leef3c6a472017-11-14 14:53:06 -08003683 int top = (physHeight - height) / 2;
3684 out.set(left, top, left + width, top + height);
3685 }
3686
3687 @Override
3688 public void getBounds(Rect out) {
Evan Rosky39b6f232018-10-30 18:35:41 -07003689 calculateBounds(mDisplayInfo, out);
Bryce Leef3c6a472017-11-14 14:53:06 -08003690 }
3691
3692 private void getBounds(Rect out, int orientation) {
3693 getBounds(out);
3694
3695 // Rotate the Rect if needed.
3696 final int currentRotation = mDisplayInfo.rotation;
3697 final int rotationDelta = deltaRotation(currentRotation, orientation);
3698 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3699 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3700 mTmpRectF.set(out);
3701 mTmpMatrix.mapRect(mTmpRectF);
3702 mTmpRectF.round(out);
3703 }
3704 }
3705
Evan Rosky730f6e82018-12-03 17:40:11 -08003706 /** @returns the orientation of the display when it's rotation is ROTATION_0. */
3707 int getNaturalOrientation() {
3708 return mBaseDisplayWidth < mBaseDisplayHeight
3709 ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
3710 }
3711
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003712 void performLayout(boolean initial, boolean updateInputWindows) {
3713 if (!isLayoutNeeded()) {
3714 return;
3715 }
3716 clearLayoutNeeded();
3717
3718 final int dw = mDisplayInfo.logicalWidth;
3719 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003720 if (DEBUG_LAYOUT) {
3721 Slog.v(TAG, "-------------------------------------");
3722 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3723 }
3724
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003725 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3726 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003727 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3728 // display info above...
3729 mDisplayFrames.mRotation = mRotation;
Tiger Huang7c610aa2018-10-27 00:01:01 +08003730 mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003731
Adrian Roos5251b1d2018-03-23 18:57:43 +01003732 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003733 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003734 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003735
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003736 // Used to indicate that we have processed the dream window and all additional windows are
3737 // behind it.
3738 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003739 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003740
3741 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003742 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003743
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003744 // Used to indicate that we have processed the dream window and all additional attached
3745 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003746 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003747 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003748
3749 // Now perform layout of attached windows, which usually depend on the position of the
3750 // window they are attached to. XXX does not deal with windows that are attached to windows
3751 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003752 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003753
3754 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003755 mInputMonitor.layoutInputConsumers(dw, dh);
3756 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003757 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003758 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003759 }
3760
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003761 mWmService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003762 }
3763
3764 /**
3765 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3766 * In portrait mode, it grabs the full screenshot.
3767 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003768 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003769 */
chaviw0315a1a2018-03-05 15:28:35 -08003770 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003771 if (!mWmService.mPolicy.isScreenOn()) {
chaviw0315a1a2018-03-05 15:28:35 -08003772 if (DEBUG_SCREENSHOT) {
3773 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003774 }
chaviw0315a1a2018-03-05 15:28:35 -08003775 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003776 }
chaviwfbe47df2017-11-10 16:14:49 -08003777
chaviw0315a1a2018-03-05 15:28:35 -08003778 int dw = mDisplayInfo.logicalWidth;
3779 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003780
chaviw0315a1a2018-03-05 15:28:35 -08003781 if (dw <= 0 || dh <= 0) {
3782 return null;
3783 }
chaviwfbe47df2017-11-10 16:14:49 -08003784
chaviw0315a1a2018-03-05 15:28:35 -08003785 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003786
chaviw0315a1a2018-03-05 15:28:35 -08003787 // The screenshot API does not apply the current screen rotation.
3788 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003789
chaviw0315a1a2018-03-05 15:28:35 -08003790 if (rot == ROTATION_90 || rot == ROTATION_270) {
3791 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3792 }
chaviwfbe47df2017-11-10 16:14:49 -08003793
chaviw0315a1a2018-03-05 15:28:35 -08003794 // SurfaceFlinger is not aware of orientation, so convert our logical
3795 // crop to SurfaceFlinger's portrait orientation.
3796 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3797
3798 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003799 mWmService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
chaviw0315a1a2018-03-05 15:28:35 -08003800 final boolean inRotation = screenRotationAnimation != null &&
3801 screenRotationAnimation.isAnimating();
3802 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3803
3804 // TODO(b/68392460): We should screenshot Task controls directly
3805 // but it's difficult at the moment as the Task doesn't have the
3806 // correct size set.
chaviw08520a02018-09-10 16:44:56 -07003807 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot);
chaviw0315a1a2018-03-05 15:28:35 -08003808 if (bitmap == null) {
3809 Slog.w(TAG_WM, "Failed to take screenshot");
3810 return null;
3811 }
3812
3813 // Create a copy of the screenshot that is immutable and backed in ashmem.
3814 // This greatly reduces the overhead of passing the bitmap between processes.
3815 final Bitmap ret = bitmap.createAshmemBitmap(config);
3816 bitmap.recycle();
3817 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003818 }
3819
3820 // TODO: Can this use createRotationMatrix()?
3821 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3822 if (rot == Surface.ROTATION_90) {
3823 final int tmp = crop.top;
3824 crop.top = dw - crop.right;
3825 crop.right = crop.bottom;
3826 crop.bottom = dw - crop.left;
3827 crop.left = tmp;
3828 } else if (rot == Surface.ROTATION_180) {
3829 int tmp = crop.top;
3830 crop.top = dh - crop.bottom;
3831 crop.bottom = dh - tmp;
3832 tmp = crop.right;
3833 crop.right = dw - crop.left;
3834 crop.left = dw - tmp;
3835 } else if (rot == Surface.ROTATION_270) {
3836 final int tmp = crop.top;
3837 crop.top = crop.left;
3838 crop.left = dh - crop.bottom;
3839 crop.bottom = crop.right;
3840 crop.right = dh - tmp;
3841 }
3842 }
3843
3844 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003845 // Used to indicate the layout is needed.
3846 mTmpWindow = null;
3847
3848 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003849 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003850 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003851 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003852 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003853 w.setDisplayLayoutNeeded();
Vishnu Nairba183352018-11-21 11:16:49 -08003854 w.finishSeamlessRotation(true /* timeout */);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003855 mWmService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003856 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003857
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003858 if (mTmpWindow != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003859 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003860 }
3861 }
3862
Wale Ogunwale1666e312016-12-16 11:27:18 -08003863 void setExitingTokensHasVisible(boolean hasVisible) {
3864 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3865 mExitingTokens.get(i).hasVisible = hasVisible;
3866 }
3867
3868 // Initialize state of exiting applications.
3869 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3870 }
3871
3872 void removeExistingTokensIfPossible() {
3873 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3874 final WindowToken token = mExitingTokens.get(i);
3875 if (!token.hasVisible) {
3876 mExitingTokens.remove(i);
3877 }
3878 }
3879
3880 // Time to remove any exiting applications?
3881 mTaskStackContainers.removeExistingAppTokensIfPossible();
3882 }
3883
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003884 @Override
3885 void onDescendantOverrideConfigurationChanged() {
3886 setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003887 mWmService.requestTraversal();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003888 }
3889
David Stevens9440dc82017-03-16 19:00:20 -07003890 boolean okToDisplay() {
3891 if (mDisplayId == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003892 return !mWmService.mDisplayFrozen
3893 && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn();
David Stevens9440dc82017-03-16 19:00:20 -07003894 }
3895 return mDisplayInfo.state == Display.STATE_ON;
3896 }
3897
3898 boolean okToAnimate() {
3899 return okToDisplay() &&
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003900 (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate());
David Stevens9440dc82017-03-16 19:00:20 -07003901 }
3902
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003903 static final class TaskForResizePointSearchResult {
3904 boolean searchDone;
3905 Task taskForResize;
3906
3907 void reset() {
3908 searchDone = false;
3909 taskForResize = null;
3910 }
3911 }
Robert Carr3b716242016-08-16 16:02:21 -07003912
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003913 private static final class ApplySurfaceChangesTransactionState {
3914 boolean displayHasContent;
3915 boolean obscured;
3916 boolean syswin;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003917 float preferredRefreshRate;
3918 int preferredModeId;
3919
3920 void reset() {
3921 displayHasContent = false;
3922 obscured = false;
3923 syswin = false;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003924 preferredRefreshRate = 0;
3925 preferredModeId = 0;
3926 }
3927 }
3928
3929 private static final class ScreenshotApplicationState {
3930 WindowState appWin;
3931 int maxLayer;
3932 int minLayer;
3933 boolean screenshotReady;
3934
3935 void reset(boolean screenshotReady) {
3936 appWin = null;
3937 maxLayer = 0;
3938 minLayer = 0;
3939 this.screenshotReady = screenshotReady;
3940 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3941 }
3942 }
3943
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003944 /**
3945 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3946 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3947 * homogeneous children type which is currently required by sub-classes of
3948 * {@link WindowContainer} class.
3949 */
3950 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3951
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003952 DisplayChildWindowContainer(WindowManagerService service) {
3953 super(service);
3954 }
3955
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003956 @Override
3957 boolean fillsParent() {
3958 return true;
3959 }
3960
3961 @Override
3962 boolean isVisible() {
3963 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003964 }
3965 }
3966
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003967 /**
3968 * Window container class that contains all containers on this display relating to Apps.
3969 * I.e Activities.
3970 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003971 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003972 /**
3973 * A control placed at the appropriate level for transitions to occur.
3974 */
chaviw23ee71c2017-12-18 11:29:41 -08003975 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003976 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003977 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003978
Robert Carrf7a7ca82017-12-06 13:17:07 -08003979 /**
3980 * Given that the split-screen divider does not have an AppWindowToken, it
3981 * will have to live inside of a "NonAppWindowContainer", in particular
3982 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3983 * it will need to be interleaved with some of our children, appearing on top of
3984 * both docked stacks but underneath any assistant stacks.
3985 *
3986 * To solve this problem we have this anchor control, which will always exist so
3987 * we can always assign it the correct value in our {@link #assignChildLayers}.
3988 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3989 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3990 * events between the two containers.
3991 */
3992 SurfaceControl mSplitScreenDividerAnchor = null;
3993
Wale Ogunwale61911492017-10-11 08:50:50 -07003994 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3995 // through the list to find them.
3996 private TaskStack mHomeStack = null;
3997 private TaskStack mPinnedStack = null;
3998 private TaskStack mSplitScreenPrimaryStack = null;
3999
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004000 TaskStackContainers(WindowManagerService service) {
4001 super(service);
4002 }
4003
Wale Ogunwale61911492017-10-11 08:50:50 -07004004 /**
4005 * Returns the topmost stack on the display that is compatible with the input windowing mode
4006 * and activity type. Null is no compatible stack on the display.
4007 */
4008 TaskStack getStack(int windowingMode, int activityType) {
4009 if (activityType == ACTIVITY_TYPE_HOME) {
4010 return mHomeStack;
4011 }
4012 if (windowingMode == WINDOWING_MODE_PINNED) {
4013 return mPinnedStack;
4014 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
4015 return mSplitScreenPrimaryStack;
4016 }
4017 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
4018 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08004019 if (activityType == ACTIVITY_TYPE_UNDEFINED
4020 && windowingMode == stack.getWindowingMode()) {
4021 // Passing in undefined type means we want to match the topmost stack with the
4022 // windowing mode.
4023 return stack;
4024 }
Wale Ogunwale61911492017-10-11 08:50:50 -07004025 if (stack.isCompatible(windowingMode, activityType)) {
4026 return stack;
4027 }
4028 }
4029 return null;
4030 }
4031
4032 @VisibleForTesting
4033 TaskStack getTopStack() {
4034 return mTaskStackContainers.getChildCount() > 0
4035 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
4036 }
4037
4038 TaskStack getHomeStack() {
4039 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
4040 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
4041 }
4042 return mHomeStack;
4043 }
4044
4045 TaskStack getPinnedStack() {
4046 return mPinnedStack;
4047 }
4048
Matthew Ng64e77cf2017-10-31 14:01:31 -07004049 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07004050 return mSplitScreenPrimaryStack;
4051 }
4052
Winson Chunge2d72172018-01-25 17:46:20 +00004053 ArrayList<Task> getVisibleTasks() {
4054 final ArrayList<Task> visibleTasks = new ArrayList<>();
4055 forAllTasks(task -> {
4056 if (task.isVisible()) {
4057 visibleTasks.add(task);
4058 }
4059 });
4060 return visibleTasks;
4061 }
4062
Andrii Kulian839def92016-11-02 10:58:58 -07004063 /**
4064 * Adds the stack to this container.
Andrii Kulian839def92016-11-02 10:58:58 -07004065 */
4066 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07004067 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004068 addChild(stack, onTop);
4069 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07004070 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004071
Wale Ogunwale61911492017-10-11 08:50:50 -07004072 void onStackWindowingModeChanged(TaskStack stack) {
4073 removeStackReferenceIfNeeded(stack);
4074 addStackReferenceIfNeeded(stack);
4075 if (stack == mPinnedStack && getTopStack() != stack) {
4076 // Looks like this stack changed windowing mode to pinned. Move it to the top.
4077 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
4078 }
4079 }
4080
4081 private void addStackReferenceIfNeeded(TaskStack stack) {
4082 if (stack.isActivityTypeHome()) {
4083 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08004084 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07004085 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08004086
Wale Ogunwale61911492017-10-11 08:50:50 -07004087 }
Louis Chang7d0037c2018-08-13 12:42:06 +08004088 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07004089 }
4090 final int windowingMode = stack.getWindowingMode();
4091 if (windowingMode == WINDOWING_MODE_PINNED) {
4092 if (mPinnedStack != null) {
4093 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
4094 + mPinnedStack + " already exist on display=" + this
4095 + " stack=" + stack);
4096 }
4097 mPinnedStack = stack;
4098 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
4099 if (mSplitScreenPrimaryStack != null) {
4100 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
4101 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
4102 + " already exist on display=" + this + " stack=" + stack);
4103 }
4104 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08004105 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07004106 }
4107 }
4108
4109 private void removeStackReferenceIfNeeded(TaskStack stack) {
4110 if (stack == mHomeStack) {
4111 mHomeStack = null;
4112 } else if (stack == mPinnedStack) {
4113 mPinnedStack = null;
4114 } else if (stack == mSplitScreenPrimaryStack) {
4115 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08004116 // Re-set the split-screen create mode whenever the split-screen stack is removed.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004117 mWmService.setDockedStackCreateStateLocked(
Wale Ogunwale30e441d2017-11-09 08:28:45 -08004118 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
4119 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07004120 }
Andrii Kulian839def92016-11-02 10:58:58 -07004121 }
4122
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004123 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004124 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
4125 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004126 addChild(stack, addIndex);
4127 setLayoutNeeded();
4128 }
4129
Wale Ogunwale61911492017-10-11 08:50:50 -07004130 @Override
4131 protected void removeChild(TaskStack stack) {
4132 super.removeChild(stack);
4133 removeStackReferenceIfNeeded(stack);
4134 }
Bryce Lee00d586d2017-07-28 20:48:43 -07004135
4136 @Override
4137 boolean isOnTop() {
4138 // Considered always on top
4139 return true;
4140 }
4141
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004142 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08004143 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07004144 if (child.getWindowConfiguration().isAlwaysOnTop()
4145 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08004146 // This stack is always-on-top, override the default behavior.
4147 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
4148
4149 // Moving to its current position, as we must call super but we don't want to
4150 // perform any meaningful action.
4151 final int currentPosition = mChildren.indexOf(child);
4152 super.positionChildAt(currentPosition, child, false /* includingParents */);
4153 return;
4154 }
4155
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004156 final int targetPosition = findPositionForStack(position, child, false /* adding */);
4157 super.positionChildAt(targetPosition, child, includingParents);
4158
Riddle Hsu2f6e1742018-08-23 22:44:36 +08004159 if (includingParents) {
4160 // We still want to move the display of this stack container to top because even the
4161 // target position is adjusted to non-top, the intention of the condition is to have
4162 // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front
4163 // in a non-top display which is using picture-in-picture mode).
4164 final int topChildPosition = getChildCount() - 1;
4165 if (targetPosition < topChildPosition && position >= topChildPosition) {
4166 getParent().positionChildAt(POSITION_TOP, this /* child */,
4167 true /* includingParents */);
4168 }
4169 }
4170
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004171 setLayoutNeeded();
4172 }
4173
4174 /**
4175 * When stack is added or repositioned, find a proper position for it.
4176 * This will make sure that pinned stack always stays on top.
4177 * @param requestedPosition Position requested by caller.
4178 * @param stack Stack to be added or positioned.
4179 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
4180 * @return The proper position for the stack.
4181 */
4182 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004183 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09004184 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09004185 }
4186
Kazuki Takisef85197b2018-06-18 18:18:36 +09004187 final int topChildPosition = mChildren.size() - 1;
4188 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
4189 for (int i = topChildPosition; i >= 0; --i) {
4190 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
4191 belowAlwaysOnTopPosition = i;
4192 break;
4193 }
4194 }
4195
4196 // The max possible position we can insert the stack at.
4197 int maxPosition = POSITION_TOP;
4198 // The min possible position we can insert the stack at.
4199 int minPosition = POSITION_BOTTOM;
4200
4201 if (stack.isAlwaysOnTop()) {
4202 if (hasPinnedStack()) {
4203 // Always-on-top stacks go below the pinned stack.
4204 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
4205 }
4206 // Always-on-top stacks need to be above all other stacks.
4207 minPosition = belowAlwaysOnTopPosition !=
4208 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
4209 } else {
4210 // Other stacks need to be below the always-on-top stacks.
4211 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08004212 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09004213 }
4214
4215 int targetPosition = requestedPosition;
4216 targetPosition = Math.min(targetPosition, maxPosition);
4217 targetPosition = Math.max(targetPosition, minPosition);
4218
4219 int prevPosition = getStacks().indexOf(stack);
4220 // The positions we calculated above (maxPosition, minPosition) do not take into
4221 // consideration the following edge cases.
4222 // 1) We need to adjust the position depending on the value "adding".
4223 // 2) When we are moving a stack to another position, we also need to adjust the
4224 // position depending on whether the stack is moving to a higher or lower position.
4225 if ((targetPosition != requestedPosition) &&
4226 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004227 targetPosition++;
4228 }
4229
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004230 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08004231 }
4232
4233 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004234 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
4235 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004236 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004237 if (super.forAllWindows(callback, traverseTopToBottom)) {
4238 return true;
4239 }
4240 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4241 return true;
4242 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004243 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004244 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4245 return true;
4246 }
4247 if (super.forAllWindows(callback, traverseTopToBottom)) {
4248 return true;
4249 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004250 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004251 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004252 }
4253
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004254 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004255 boolean traverseTopToBottom) {
4256 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
4257 // app tokens.
4258 // TODO: Investigate if we need to continue to do this or if we can just process them
4259 // in-order.
4260 if (traverseTopToBottom) {
4261 for (int i = mChildren.size() - 1; i >= 0; --i) {
4262 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4263 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004264 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4265 traverseTopToBottom)) {
4266 return true;
4267 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004268 }
4269 }
4270 } else {
4271 final int count = mChildren.size();
4272 for (int i = 0; i < count; ++i) {
4273 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4274 final int appTokensCount = appTokens.size();
4275 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004276 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4277 traverseTopToBottom)) {
4278 return true;
4279 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004280 }
4281 }
4282 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004283 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004284 }
4285
Wale Ogunwale1666e312016-12-16 11:27:18 -08004286 void setExitingTokensHasVisible(boolean hasVisible) {
4287 for (int i = mChildren.size() - 1; i >= 0; --i) {
4288 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4289 for (int j = appTokens.size() - 1; j >= 0; --j) {
4290 appTokens.get(j).hasVisible = hasVisible;
4291 }
4292 }
4293 }
4294
4295 void removeExistingAppTokensIfPossible() {
4296 for (int i = mChildren.size() - 1; i >= 0; --i) {
4297 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4298 for (int j = appTokens.size() - 1; j >= 0; --j) {
4299 final AppWindowToken token = appTokens.get(j);
lumark588a3e82018-07-20 18:53:54 +08004300 if (!token.hasVisible && !mClosingApps.contains(token)
Wale Ogunwale1666e312016-12-16 11:27:18 -08004301 && (!token.mIsExiting || token.isEmpty())) {
4302 // Make sure there is no animation running on this token, so any windows
4303 // associated with it will be removed as soon as their animations are
4304 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02004305 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08004306 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4307 "performLayout: App token exiting now removed" + token);
4308 token.removeIfPossible();
4309 }
4310 }
4311 }
4312 }
4313
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004314 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004315 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004316 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
4317 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004318 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07004319 // docked or freeform stack is visible...except for the home stack if the docked
4320 // stack is minimized and it actually set something and the bounds is different from
4321 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004322 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004323 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004324 && !(mDividerControllerLocked.isHomeStackResizable()
4325 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004326 final int orientation = mHomeStack.getOrientation();
4327 if (orientation != SCREEN_ORIENTATION_UNSET) {
4328 return orientation;
4329 }
4330 }
4331 return SCREEN_ORIENTATION_UNSPECIFIED;
4332 }
4333
4334 final int orientation = super.getOrientation();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004335 boolean isCar = mWmService.mContext.getPackageManager().hasSystemFeature(
Dean Harding3e5a1522017-10-06 09:19:01 -07004336 PackageManager.FEATURE_AUTOMOTIVE);
4337 if (isCar) {
4338 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
4339 // allow anything but the default orientation.
4340 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004341 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
4342 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07004343 return SCREEN_ORIENTATION_UNSPECIFIED;
4344 }
4345
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004346 if (orientation != SCREEN_ORIENTATION_UNSET
4347 && orientation != SCREEN_ORIENTATION_BEHIND) {
4348 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004349 "App is requesting an orientation, return " + orientation
4350 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004351 return orientation;
4352 }
4353
4354 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004355 "No app is requesting an orientation, return " + mLastOrientation
4356 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004357 // The next app has not been requested to be visible, so we keep the current orientation
4358 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08004359 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004360 }
Robert Carrb1579c82017-09-05 14:54:47 -07004361
4362 @Override
4363 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004364 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004365
Robert Carr2f8aa392018-01-31 14:46:51 -08004366 for (int i = 0; i < mChildren.size(); i++) {
4367 final TaskStack s = mChildren.get(i);
4368 s.assignChildLayers(t);
4369 }
4370 }
4371
4372 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02004373
Robert Carrf7a7ca82017-12-06 13:17:07 -08004374 final int HOME_STACK_STATE = 0;
4375 final int NORMAL_STACK_STATE = 1;
4376 final int ALWAYS_ON_TOP_STATE = 2;
4377
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004378 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004379 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02004380 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02004381 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004382
Robert Carrf7a7ca82017-12-06 13:17:07 -08004383 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
4384 for (int i = 0; i < mChildren.size(); i++) {
4385 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08004386 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
4387 continue;
4388 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
4389 || s.isAlwaysOnTop())) {
4390 continue;
4391 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
4392 continue;
4393 }
4394 s.assignLayer(t, layer++);
4395 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
4396 t.setLayer(mSplitScreenDividerAnchor, layer++);
4397 }
Winson Chungd41f71d2018-03-16 15:26:07 -07004398 if ((s.isTaskAnimating() || s.isAppAnimating())
4399 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004400 // Ensure the animation layer ends up above the
4401 // highest animating stack and no higher.
4402 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004403 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004404 if (state != ALWAYS_ON_TOP_STATE) {
4405 layerForBoostedAnimationLayer = layer++;
4406 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08004407 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004408 if (state == HOME_STACK_STATE) {
4409 layerForHomeAnimationLayer = layer++;
4410 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004411 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004412 if (mAppAnimationLayer != null) {
4413 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004414 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004415 if (mBoostedAppAnimationLayer != null) {
4416 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
4417 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004418 if (mHomeAppAnimationLayer != null) {
4419 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
4420 }
Robert Carrb1579c82017-09-05 14:54:47 -07004421 }
4422
4423 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02004424 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
4425 switch (animationLayer) {
4426 case ANIMATION_LAYER_BOOSTED:
4427 return mBoostedAppAnimationLayer;
4428 case ANIMATION_LAYER_HOME:
4429 return mHomeAppAnimationLayer;
4430 case ANIMATION_LAYER_STANDARD:
4431 default:
4432 return mAppAnimationLayer;
4433 }
chaviw23ee71c2017-12-18 11:29:41 -08004434 }
4435
Robert Carrf7a7ca82017-12-06 13:17:07 -08004436 SurfaceControl getSplitScreenDividerAnchor() {
4437 return mSplitScreenDividerAnchor;
4438 }
4439
chaviw23ee71c2017-12-18 11:29:41 -08004440 @Override
Riddle Hsu3a4bb612019-01-31 00:02:22 +08004441 void onParentChanged() {
4442 super.onParentChanged();
Robert Carrb1579c82017-09-05 14:54:47 -07004443 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08004444 mAppAnimationLayer = makeChildSurface(null)
4445 .setName("animationLayer")
4446 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02004447 mBoostedAppAnimationLayer = makeChildSurface(null)
4448 .setName("boostedAnimationLayer")
4449 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02004450 mHomeAppAnimationLayer = makeChildSurface(null)
4451 .setName("homeAnimationLayer")
4452 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08004453 mSplitScreenDividerAnchor = makeChildSurface(null)
4454 .setName("splitScreenDividerAnchor")
4455 .build();
4456 getPendingTransaction()
4457 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02004458 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02004459 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08004460 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08004461 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07004462 } else {
Robert Carr5ea304d2019-02-04 16:04:55 -08004463 mAppAnimationLayer.remove();
chaviw23ee71c2017-12-18 11:29:41 -08004464 mAppAnimationLayer = null;
Robert Carr5ea304d2019-02-04 16:04:55 -08004465 mBoostedAppAnimationLayer.remove();
Jorim Jaggibe418292018-03-26 16:14:12 +02004466 mBoostedAppAnimationLayer = null;
Robert Carr5ea304d2019-02-04 16:04:55 -08004467 mHomeAppAnimationLayer.remove();
Jorim Jaggi391790622018-04-18 15:30:44 +02004468 mHomeAppAnimationLayer = null;
Robert Carr5ea304d2019-02-04 16:04:55 -08004469 mSplitScreenDividerAnchor.remove();
Robert Carrf7a7ca82017-12-06 13:17:07 -08004470 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07004471 }
4472 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004473 }
4474
Robert Carree4d4b92017-11-22 12:21:46 -08004475 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004476 AboveAppWindowContainers(String name, WindowManagerService service) {
4477 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08004478 }
4479
Robert Carrb9506032018-02-13 13:54:00 -08004480 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07004481 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
4482 final SurfaceControl.Builder builder = super.makeChildSurface(child);
4483 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
4484 // To draw above the ColorFade layer during the screen off transition, the
4485 // rounded corner overlays need to be at the root of the surface hierarchy.
4486 // TODO: move the ColorLayer into the display overlay layer such that this is not
4487 // necessary anymore.
4488 builder.setParent(null);
4489 }
4490 return builder;
4491 }
4492
4493 @Override
Robert Carrb9506032018-02-13 13:54:00 -08004494 void assignChildLayers(SurfaceControl.Transaction t) {
4495 assignChildLayers(t, null /* imeContainer */);
4496 }
4497
Robert Carree4d4b92017-11-22 12:21:46 -08004498 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
4499 boolean needAssignIme = imeContainer != null
4500 && imeContainer.getSurfaceControl() != null;
4501 for (int j = 0; j < mChildren.size(); ++j) {
4502 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004503
4504 // See {@link mSplitScreenDividerAnchor}
4505 if (wt.windowType == TYPE_DOCK_DIVIDER) {
4506 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
4507 continue;
4508 }
Vishnu Nair83537a72018-07-19 21:27:48 -07004509 if (wt.mRoundedCornerOverlay) {
4510 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
4511 continue;
4512 }
Robert Carree4d4b92017-11-22 12:21:46 -08004513 wt.assignLayer(t, j);
4514 wt.assignChildLayers(t);
4515
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004516 int layer = mWmService.mPolicy.getWindowLayerFromTypeLw(
Robert Carree4d4b92017-11-22 12:21:46 -08004517 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08004518
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004519 if (needAssignIme && layer >= mWmService.mPolicy.getWindowLayerFromTypeLw(
Robert Carrb8e78fa2017-11-28 13:07:58 -08004520 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004521 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08004522 needAssignIme = false;
4523 }
4524 }
4525 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004526 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08004527 }
4528 }
4529 }
4530
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004531 /**
4532 * Window container class that contains all containers on this display that are not related to
4533 * Apps. E.g. status bar.
4534 */
Robert Carree4d4b92017-11-22 12:21:46 -08004535 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07004536 /**
4537 * Compares two child window tokens returns -1 if the first is lesser than the second in
4538 * terms of z-order and 1 otherwise.
4539 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004540 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07004541 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004542 mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004543 token1.mOwnerCanManageAppTokens)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004544 < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004545 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004546
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004547 private final Predicate<WindowState> mGetOrientingWindow = w -> {
4548 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
4549 return false;
4550 }
4551 final int req = w.mAttrs.screenOrientation;
4552 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
4553 || req == SCREEN_ORIENTATION_UNSET) {
4554 return false;
4555 }
4556 return true;
4557 };
4558
Wale Ogunwale3a931692016-11-02 16:49:48 -07004559 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08004560 private final Dimmer mDimmer = new Dimmer(this);
4561 private final Rect mTmpDimBoundsRect = new Rect();
4562
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004563 NonAppWindowContainers(String name, WindowManagerService service) {
4564 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07004565 mName = name;
4566 }
4567
4568 void addChild(WindowToken token) {
4569 addChild(token, mWindowComparator);
4570 }
4571
4572 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004573 int getOrientation() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004574 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004575 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004576 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004577
4578 if (win != null) {
4579 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004580 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004581 mLastKeyguardForcedOrientation = req;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004582 if (mWmService.mKeyguardGoingAway) {
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07004583 // Keyguard can't affect the orientation if it is going away...
4584 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
4585 return SCREEN_ORIENTATION_UNSET;
4586 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004587 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004588 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
4589 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08004590 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004591 }
4592
Andrii Kulian8ee72852017-03-10 10:36:45 -08004593 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004594
Jorim Jaggi1c530592018-04-06 15:11:47 +02004595 // Only allow force setting the orientation when all unknown visibilities have been
4596 // resolved, as otherwise we just may be starting another occluding activity.
4597 final boolean isUnoccluding =
lumark588a3e82018-07-20 18:53:54 +08004598 mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
4599 && mUnknownAppVisibilityController.allResolved();
Jorim Jaggi1c530592018-04-06 15:11:47 +02004600 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004601 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004602 }
4603
4604 return SCREEN_ORIENTATION_UNSET;
4605 }
4606
4607 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004608 String getName() {
4609 return mName;
4610 }
chaviwf29223e2018-01-31 13:23:51 -08004611
4612 @Override
4613 Dimmer getDimmer() {
4614 return mDimmer;
4615 }
4616
4617 @Override
4618 void prepareSurfaces() {
4619 mDimmer.resetDimStates();
4620 super.prepareSurfaces();
4621 getBounds(mTmpDimBoundsRect);
4622
4623 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4624 scheduleAnimation();
4625 }
4626 }
Robert Carr3b716242016-08-16 16:02:21 -07004627 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004628
Robert Carr9034d962018-01-04 18:27:42 -08004629 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4630 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4631 super(name, service);
4632 }
4633
4634 @Override
4635 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4636 }
4637 };
4638
Robert Carrb1579c82017-09-05 14:54:47 -07004639 SurfaceControl.Builder makeSurface(SurfaceSession s) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004640 return mWmService.makeSurfaceBuilder(s)
Robert Carrb1579c82017-09-05 14:54:47 -07004641 .setParent(mWindowingLayer);
4642 }
4643
4644 @Override
4645 SurfaceSession getSession() {
4646 return mSession;
4647 }
4648
4649 @Override
4650 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004651 SurfaceSession s = child != null ? child.getSession() : getSession();
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +00004652 final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s).setContainerLayer();
Robert Carrf59b8dd2017-10-02 18:58:36 -07004653 if (child == null) {
4654 return b;
4655 }
4656
Robert Carree4d4b92017-11-22 12:21:46 -08004657 return b.setName(child.getName())
4658 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004659 }
4660
4661 /**
4662 * The makeSurface variants are for use by the window-container
4663 * hierarchy. makeOverlay here is a function for various non windowing
4664 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4665 * and other potpourii.
4666 */
4667 SurfaceControl.Builder makeOverlay() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004668 return mWmService.makeSurfaceBuilder(mSession)
Robert Carrb1579c82017-09-05 14:54:47 -07004669 .setParent(mOverlayLayer);
4670 }
4671
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004672 /**
4673 * Reparents the given surface to mOverlayLayer.
4674 */
4675 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
Robert Carr10584fa2019-01-14 15:55:19 -08004676 transaction.reparent(surface, mOverlayLayer);
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004677 }
4678
Robert Carrb1579c82017-09-05 14:54:47 -07004679 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004680 if (spec.scale != 1.0) {
4681 mMagnificationSpec = spec;
4682 } else {
4683 mMagnificationSpec = null;
4684 }
4685
Robert Carrf59b8dd2017-10-02 18:58:36 -07004686 applyMagnificationSpec(getPendingTransaction(), spec);
4687 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004688 }
4689
Robert Carr24be9ab2018-04-30 17:54:53 -07004690 void reapplyMagnificationSpec() {
4691 if (mMagnificationSpec != null) {
4692 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4693 }
4694 }
4695
Robert Carrb1579c82017-09-05 14:54:47 -07004696 @Override
Riddle Hsu3a4bb612019-01-31 00:02:22 +08004697 void onParentChanged() {
Robert Carrb1579c82017-09-05 14:54:47 -07004698 // Since we are the top of the SurfaceControl hierarchy here
4699 // we create the root surfaces explicitly rather than chaining
Riddle Hsu3a4bb612019-01-31 00:02:22 +08004700 // up as the default implementation in onParentChanged does. So we
Robert Carrb1579c82017-09-05 14:54:47 -07004701 // explicitly do NOT call super here.
4702 }
4703
4704 @Override
4705 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004706
4707 // These are layers as children of "mWindowingLayer"
4708 mBelowAppWindowsContainers.assignLayer(t, 0);
4709 mTaskStackContainers.assignLayer(t, 1);
4710 mAboveAppWindowsContainers.assignLayer(t, 2);
4711
lumarkff0ab692018-11-05 20:32:30 +08004712 final WindowState imeTarget = mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004713 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004714
Robert Carree4d4b92017-11-22 12:21:46 -08004715 // In the case where we have an IME target that is not in split-screen
4716 // mode IME assignment is easy. We just need the IME to go directly above
4717 // the target. This way children of the target will naturally go above the IME
4718 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004719 //
Robert Carree4d4b92017-11-22 12:21:46 -08004720 // In the case of split-screen windowing mode, we need to elevate the IME above the
4721 // docked divider while keeping the app itself below the docked divider, so instead
4722 // we use relative layering of the IME targets child windows, and place the
4723 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004724 //
Robert Carr234b6332018-03-20 13:38:16 -07004725 // In the case the IME target is animating, the animation Z order may be different
4726 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4727 // IME target. In this case we just layer the IME over all transitions by placing it in the
4728 // above applications layer.
4729 //
Robert Carree4d4b92017-11-22 12:21:46 -08004730 // In the case where we have no IME target we assign it where it's base layer would
4731 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004732 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4733 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004734 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004735 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004736 // TODO: We need to use an extra level on the app surface to ensure
4737 // this is always above SurfaceView but always below attached window.
4738 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004739 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004740 }
4741
4742 // Above we have assigned layers to our children, now we ask them to assign
4743 // layers to their children.
4744 mBelowAppWindowsContainers.assignChildLayers(t);
4745 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004746 mAboveAppWindowsContainers.assignChildLayers(t,
4747 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004748 mImeWindowsContainers.assignChildLayers(t);
4749 }
4750
4751 /**
4752 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4753 * that the IME target is one of the docked applications. We'd like the docked divider to be
4754 * above both of the applications, and we'd like the IME to be above the docked divider.
4755 * However we need child windows of the applications to be above the IME (Text drag handles).
4756 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4757 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
Tiger Huang7c610aa2018-10-27 00:01:01 +08004758 * with {@link WindowState#assignLayer}
Robert Carrb1579c82017-09-05 14:54:47 -07004759 */
4760 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004761 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004762 }
4763
4764 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004765 void prepareSurfaces() {
4766 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004767 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004768 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4769 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4770 mPendingTransaction.setMatrix(mWindowingLayer,
4771 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4772 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4773 mPendingTransaction.setPosition(mWindowingLayer,
4774 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4775 mPendingTransaction.setAlpha(mWindowingLayer,
4776 screenRotationAnimation.getEnterTransformation().getAlpha());
4777 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004778
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004779 super.prepareSurfaces();
4780 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004781
Jorim Jaggibe418292018-03-26 16:14:12 +02004782 void assignStackOrdering() {
4783 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004784 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004785
4786 /**
4787 * Increment the deferral count to determine whether to update the IME target.
4788 */
4789 void deferUpdateImeTarget() {
4790 mDeferUpdateImeTargetCount++;
4791 }
4792
4793 /**
4794 * Decrement the deferral count to determine whether to update the IME target. If the count
4795 * reaches 0, a new ime target will get computed.
4796 */
4797 void continueUpdateImeTarget() {
4798 if (mDeferUpdateImeTargetCount == 0) {
4799 return;
4800 }
4801
4802 mDeferUpdateImeTargetCount--;
4803 if (mDeferUpdateImeTargetCount == 0) {
4804 computeImeTarget(true /* updateImeTarget */);
4805 }
4806 }
4807
4808 /**
4809 * @return Whether a new IME target should be computed.
4810 */
4811 private boolean canUpdateImeTarget() {
4812 return mDeferUpdateImeTargetCount == 0;
4813 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004814
4815 InputMonitor getInputMonitor() {
4816 return mInputMonitor;
4817 }
Jorim Jaggif1292892018-09-10 11:58:13 +02004818
4819 /**
4820 * @return Cached value whether we told display manager that we have content.
4821 */
4822 boolean getLastHasContent() {
4823 return mLastHasContent;
4824 }
Arthur Hungbe5ce212018-09-13 18:41:56 +08004825
4826 void registerPointerEventListener(@NonNull PointerEventListener listener) {
4827 if (mPointerEventDispatcher != null) {
4828 mPointerEventDispatcher.registerInputEventListener(listener);
4829 }
4830 }
4831
4832 void unregisterPointerEventListener(@NonNull PointerEventListener listener) {
4833 if (mPointerEventDispatcher != null) {
4834 mPointerEventDispatcher.unregisterInputEventListener(listener);
4835 }
4836 }
lumark588a3e82018-07-20 18:53:54 +08004837
4838 void prepareAppTransition(@WindowManager.TransitionType int transit,
Wale Ogunwale3a256e62018-12-06 14:41:18 -08004839 boolean alwaysKeepCurrent) {
4840 prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */);
4841 }
4842
4843 void prepareAppTransition(@WindowManager.TransitionType int transit,
lumark588a3e82018-07-20 18:53:54 +08004844 boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags,
4845 boolean forceOverride) {
4846 final boolean prepared = mAppTransition.prepareAppTransitionLocked(
4847 transit, alwaysKeepCurrent, flags, forceOverride);
4848 if (prepared && okToAnimate()) {
4849 mSkipAppTransitionAnimation = false;
4850 }
4851 }
4852
4853 void executeAppTransition() {
4854 if (mAppTransition.isTransitionSet()) {
4855 if (DEBUG_APP_TRANSITIONS) {
4856 Slog.w(TAG_WM, "Execute app transition: " + mAppTransition + ", displayId: "
4857 + mDisplayId + " Callers=" + Debug.getCallers(5));
4858 }
4859 mAppTransition.setReady();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004860 mWmService.mWindowPlacerLocked.requestTraversal();
lumark588a3e82018-07-20 18:53:54 +08004861 }
4862 }
4863
4864 /**
4865 * Update pendingLayoutChanges after app transition has finished.
4866 */
4867 void handleAnimatingStoppedAndTransition() {
4868 int changes = 0;
4869
4870 mAppTransition.setIdle();
4871
4872 for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) {
4873 final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i);
4874 mAppTransition.notifyAppTransitionFinishedLocked(token);
4875 }
4876 mNoAnimationNotifyOnTransitionFinished.clear();
4877
4878 mWallpaperController.hideDeferredWallpapersIfNeeded();
4879
4880 onAppTransitionDone();
4881
4882 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4883 if (DEBUG_WALLPAPER_LIGHT) {
4884 Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout");
4885 }
4886 computeImeTarget(true /* updateImeTarget */);
wilsonshihc32538e2018-11-07 17:27:34 +08004887 mWallpaperMayChange = true;
lumark588a3e82018-07-20 18:53:54 +08004888 // Since the window list has been rebuilt, focus might have to be recomputed since the
4889 // actual order of windows might have changed again.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004890 mWmService.mFocusMayChange = true;
lumark588a3e82018-07-20 18:53:54 +08004891
4892 pendingLayoutChanges |= changes;
4893 }
Andrii Kulian15cfb422018-11-07 13:38:49 -08004894
Wale Ogunwale3a256e62018-12-06 14:41:18 -08004895 /** Check if pending app transition is for activity / task launch. */
4896 boolean isNextTransitionForward() {
4897 final int transit = mAppTransition.getAppTransition();
4898 return transit == TRANSIT_ACTIVITY_OPEN
4899 || transit == TRANSIT_TASK_OPEN
4900 || transit == TRANSIT_TASK_TO_FRONT;
4901 }
4902
Andrii Kulian15cfb422018-11-07 13:38:49 -08004903 /**
4904 * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
4905 */
4906 boolean supportsSystemDecorations() {
4907 // TODO(b/114338689): Read the setting from DisplaySettings.
4908 return mDisplay.supportsSystemDecorations()
4909 // TODO (b/111363427): Remove this and set the new FLAG_SHOULD_SHOW_LAUNCHER flag
4910 // (b/114338689) whenever vr 2d display id is set.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004911 || mDisplayId == mWmService.mVr2dDisplayId
4912 || mWmService.mForceDesktopModeOnExternalDisplays;
Andrii Kulian15cfb422018-11-07 13:38:49 -08004913 }
chaviwff2e7d82018-11-02 11:11:27 -07004914
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004915 /**
chaviwff2e7d82018-11-02 11:11:27 -07004916 * Re-parent the DisplayContent's top surfaces, {@link #mWindowingLayer} and
4917 * {@link #mOverlayLayer} to the specified surfaceControl.
4918 *
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004919 * @param sc The new SurfaceControl, where the DisplayContent's surfaces will be re-parented to.
chaviwff2e7d82018-11-02 11:11:27 -07004920 */
Robert Carr10584fa2019-01-14 15:55:19 -08004921 void reparentDisplayContent(SurfaceControl sc) {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004922 mParentSurfaceControl = sc;
4923 if (mPortalWindowHandle == null) {
4924 mPortalWindowHandle = createPortalWindowHandle(sc.toString());
4925 }
4926 mPendingTransaction.setInputWindowInfo(sc, mPortalWindowHandle)
4927 .reparent(mWindowingLayer, sc).reparent(mOverlayLayer, sc);
4928 }
4929
Tarandeep Singha6f35612019-01-11 19:50:46 -08004930 @VisibleForTesting
4931 SurfaceControl getWindowingLayer() {
4932 return mWindowingLayer;
4933 }
4934
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004935 /**
4936 * Create a portal window handle for input. This window transports any touch to the display
4937 * indicated by {@link InputWindowHandle#portalToDisplayId} if the touch hits this window.
4938 *
4939 * @param name The name of the portal window handle.
4940 * @return the new portal window handle.
4941 */
4942 private InputWindowHandle createPortalWindowHandle(String name) {
4943 // Let surface flinger to set the display ID of this input window handle because we don't
4944 // know which display the parent surface control is on.
4945 final InputWindowHandle portalWindowHandle = new InputWindowHandle(
4946 null /* inputApplicationHandle */, null /* clientWindow */, INVALID_DISPLAY);
4947 portalWindowHandle.name = name;
4948 portalWindowHandle.token = new Binder();
4949 portalWindowHandle.layoutParamsFlags =
4950 FLAG_SPLIT_TOUCH | FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL;
4951 getBounds(mTmpBounds);
4952 portalWindowHandle.touchableRegion.set(mTmpBounds);
4953 portalWindowHandle.scaleFactor = 1f;
4954 portalWindowHandle.ownerPid = Process.myPid();
4955 portalWindowHandle.ownerUid = Process.myUid();
4956 portalWindowHandle.portalToDisplayId = mDisplayId;
4957 return portalWindowHandle;
chaviwff2e7d82018-11-02 11:11:27 -07004958 }
Issei Suzukia5dbf522019-02-01 17:58:15 +01004959
4960 /**
4961 * @see IWindowManager#setForwardedInsets
4962 */
4963 public void setForwardedInsets(Insets insets) {
4964 if (insets == null) {
4965 insets = Insets.NONE;
4966 }
4967 if (mDisplayPolicy.getForwardedInsets().equals(insets)) {
4968 return;
4969 }
4970 mDisplayPolicy.setForwardedInsets(insets);
4971 setLayoutNeeded();
4972 mWmService.mWindowPlacerLocked.requestTraversal();
4973 }
Susi Kharraz-Post9893b8c2019-02-12 14:21:29 -05004974
4975 protected MetricsLogger getMetricsLogger() {
4976 if (mMetricsLogger == null) {
4977 mMetricsLogger = new MetricsLogger();
4978 }
4979 return mMetricsLogger;
4980 }
Craig Mautner59c00972012-07-30 12:10:24 -07004981}