Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Wale Ogunwale | a77e146 | 2016-09-28 10:09:46 -0700 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 24 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 25 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 26 | import static android.view.Display.DEFAULT_DISPLAY; |
| 27 | import static android.view.Display.FLAG_PRIVATE; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 28 | import static android.view.Surface.ROTATION_0; |
| 29 | import static android.view.Surface.ROTATION_180; |
| 30 | import static android.view.Surface.ROTATION_270; |
| 31 | import static android.view.Surface.ROTATION_90; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 32 | import static android.view.View.GONE; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 33 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 34 | import static android.view.WindowManager.DOCKED_INVALID; |
| 35 | import static android.view.WindowManager.DOCKED_TOP; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 36 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 38 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 39 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 40 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE; |
| 42 | import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 43 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 44 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 45 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 46 | import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 47 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 48 | import static android.view.WindowManager.LayoutParams.TYPE_DREAM; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 49 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 50 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 51 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 52 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
| 53 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 54 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 55 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 56 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 57 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| 58 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 59 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 60 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 61 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 62 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 63 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 64 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 65 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 66 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 67 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 68 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 69 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 70 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 71 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 72 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 73 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 74 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 75 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 76 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 77 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 78 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 79 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 80 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 81 | import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 82 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
| 83 | import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 84 | import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 85 | import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 86 | import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION; |
| 87 | import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 88 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
| 89 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
| 90 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 91 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 92 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 93 | import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 94 | import static com.android.server.wm.WindowManagerService.dipToPixel; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 95 | import static com.android.server.wm.WindowManagerService.logSurface; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 96 | import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 97 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 98 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 99 | import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 100 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 101 | import android.annotation.NonNull; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 102 | import android.app.ActivityManager.StackId; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 103 | import android.content.res.CompatibilityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 104 | import android.content.res.Configuration; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 105 | import android.graphics.Bitmap; |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 106 | import android.graphics.GraphicBuffer; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 107 | import android.graphics.Matrix; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 108 | import android.graphics.Rect; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 109 | import android.graphics.RectF; |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 110 | import android.graphics.Region; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 111 | import android.graphics.Region.Op; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 112 | import android.hardware.display.DisplayManagerInternal; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 113 | import android.os.Debug; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 114 | import android.os.Handler; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 115 | import android.os.IBinder; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 116 | import android.os.RemoteException; |
| 117 | import android.os.SystemClock; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 118 | import android.util.DisplayMetrics; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 119 | import android.util.MutableBoolean; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 120 | import android.util.Slog; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 121 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 122 | import android.view.DisplayInfo; |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 123 | import android.view.InputDevice; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 124 | import android.view.Surface; |
| 125 | import android.view.SurfaceControl; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 126 | import android.view.WindowManagerPolicy; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 127 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 128 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 129 | import com.android.internal.util.ToBooleanFunction; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 130 | import com.android.internal.view.IInputMethodClient; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 131 | |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 132 | import java.io.FileDescriptor; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 133 | import java.io.PrintWriter; |
| 134 | import java.util.ArrayList; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 135 | import java.util.Comparator; |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 136 | import java.util.HashMap; |
| 137 | import java.util.Iterator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 138 | import java.util.LinkedList; |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 139 | import java.util.List; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 140 | import java.util.function.Consumer; |
| 141 | import java.util.function.Predicate; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 142 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 143 | /** |
| 144 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 145 | * particular Display. |
| 146 | * |
| 147 | * IMPORTANT: No method from this class should ever be used without holding |
| 148 | * WindowManagerService.mWindowMap. |
| 149 | */ |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 150 | class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 151 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 152 | |
| 153 | /** Unique identifier of this stack. */ |
| 154 | private final int mDisplayId; |
| 155 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 156 | /** The containers below are the only child containers the display can have. */ |
| 157 | // Contains all window containers that are related to apps (Activities) |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 158 | private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 159 | // Contains all non-app window containers that should be displayed above the app containers |
| 160 | // (e.g. Status bar) |
| 161 | private final NonAppWindowContainers mAboveAppWindowsContainers = |
| 162 | new NonAppWindowContainers("mAboveAppWindowsContainers"); |
| 163 | // Contains all non-app window containers that should be displayed below the app containers |
| 164 | // (e.g. Wallpaper). |
| 165 | private final NonAppWindowContainers mBelowAppWindowsContainers = |
| 166 | new NonAppWindowContainers("mBelowAppWindowsContainers"); |
| 167 | // Contains all IME window containers. Note that the z-ordering of the IME windows will depend |
| 168 | // on the IME target. We mainly have this container grouping so we can keep track of all the IME |
| 169 | // window containers together and move them in-sync if/when needed. |
| 170 | private final NonAppWindowContainers mImeWindowsContainers = |
| 171 | new NonAppWindowContainers("mImeWindowsContainers"); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 172 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 173 | private WindowState mTmpWindow; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 174 | private WindowState mTmpWindow2; |
| 175 | private WindowAnimator mTmpWindowAnimator; |
| 176 | private boolean mTmpRecoveringMemory; |
| 177 | private boolean mUpdateImeTarget; |
| 178 | private boolean mTmpInitial; |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 179 | private int mMaxUiWidth; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 180 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 181 | // Mapping from a token IBinder to a WindowToken object on this display. |
| 182 | private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap(); |
| 183 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 184 | // Initial display metrics. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 185 | int mInitialDisplayWidth = 0; |
| 186 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 187 | int mInitialDisplayDensity = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Overridden display size. Initialized with {@link #mInitialDisplayWidth} |
| 191 | * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size". |
| 192 | * @see WindowManagerService#setForcedDisplaySize(int, int, int) |
| 193 | */ |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 194 | int mBaseDisplayWidth = 0; |
| 195 | int mBaseDisplayHeight = 0; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity} |
| 198 | * but can be set from Settings or via shell command "adb shell wm density". |
| 199 | * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int) |
| 200 | */ |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 201 | int mBaseDisplayDensity = 0; |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 202 | boolean mDisplayScalingDisabled; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 203 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 204 | private final Display mDisplay; |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 205 | private final DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 206 | /** |
| 207 | * For default display it contains real metrics, empty for others. |
| 208 | * @see WindowManagerService#createWatermarkInTransaction() |
| 209 | */ |
| 210 | final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics(); |
| 211 | /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */ |
| 212 | private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics(); |
| 213 | /** |
| 214 | * Compat metrics computed based on {@link #mDisplayMetrics}. |
| 215 | * @see #updateDisplayAndOrientation(int) |
| 216 | */ |
| 217 | private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics(); |
| 218 | |
| 219 | /** The desired scaling factor for compatible apps. */ |
| 220 | float mCompatibleScreenScale; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 221 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 222 | /** |
| 223 | * Current rotation of the display. |
| 224 | * Constants as per {@link android.view.Surface.Rotation}. |
| 225 | * |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 226 | * @see #updateRotationUnchecked(boolean) |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 227 | */ |
| 228 | private int mRotation = 0; |
| 229 | /** |
| 230 | * Last applied orientation of the display. |
| 231 | * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}. |
| 232 | * |
| 233 | * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int) |
| 234 | */ |
| 235 | private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 236 | /** |
| 237 | * Flag indicating that the application is receiving an orientation that has different metrics |
| 238 | * than it expected. E.g. Portrait instead of Landscape. |
| 239 | * |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 240 | * @see #updateRotationUnchecked(boolean) |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 241 | */ |
| 242 | private boolean mAltOrientation = false; |
| 243 | /** |
| 244 | * Orientation forced by some window. If there is no visible window that specifies orientation |
| 245 | * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}. |
| 246 | * |
| 247 | * @see NonAppWindowContainers#getOrientation() |
| 248 | */ |
| 249 | private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 250 | /** |
| 251 | * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not |
| 252 | * occluded. |
| 253 | * |
| 254 | * @see NonAppWindowContainers#getOrientation() |
| 255 | */ |
| 256 | private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 257 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 258 | private Rect mBaseDisplayRect = new Rect(); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 259 | private Rect mContentRect = new Rect(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 260 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 261 | // Accessed directly by all users. |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 262 | private boolean mLayoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 263 | int pendingLayoutChanges; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 264 | // TODO(multi-display): remove some of the usages. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 265 | boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 266 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 267 | /** Window tokens that are in the process of exiting, but still on screen for animations. */ |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 268 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 269 | |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 270 | /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack |
| 271 | * (except a future lockscreen TaskStack) moves to the top. */ |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 272 | private TaskStack mHomeStack = null; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 273 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 274 | /** Detect user tapping outside of current focused task bounds .*/ |
| 275 | TaskTapPointerEventListener mTapDetector; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 276 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 277 | /** Detect user tapping outside of current focused stack bounds .*/ |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 278 | private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 279 | |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 280 | /** Save allocating when calculating rects */ |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 281 | private final Rect mTmpRect = new Rect(); |
| 282 | private final Rect mTmpRect2 = new Rect(); |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 283 | private final RectF mTmpRectF = new RectF(); |
| 284 | private final Matrix mTmpMatrix = new Matrix(); |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 285 | private final Region mTmpRegion = new Region(); |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 286 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 287 | WindowManagerService mService; |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 288 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 289 | /** Remove this display when animation on it has completed. */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 290 | private boolean mDeferredRemoval; |
Craig Mautner | 1bf2b87 | 2014-02-05 15:37:40 -0800 | [diff] [blame] | 291 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 292 | final DockedStackDividerController mDividerControllerLocked; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 293 | final PinnedStackController mPinnedStackControllerLocked; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 294 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 295 | DimLayerController mDimLayerController; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 296 | |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 297 | final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>(); |
| 298 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 299 | private boolean mHaveBootMsg = false; |
| 300 | private boolean mHaveApp = false; |
| 301 | private boolean mHaveWallpaper = false; |
| 302 | private boolean mHaveKeyguard = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 303 | |
| 304 | private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList(); |
| 305 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 306 | private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult = |
| 307 | new TaskForResizePointSearchResult(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 308 | private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState = |
| 309 | new ApplySurfaceChangesTransactionState(); |
| 310 | private final ScreenshotApplicationState mScreenshotApplicationState = |
| 311 | new ScreenshotApplicationState(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 312 | |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 313 | // True if this display is in the process of being removed. Used to determine if the removal of |
| 314 | // the display's direct children should be allowed. |
| 315 | private boolean mRemovingDisplay = false; |
| 316 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 317 | private final WindowLayersController mLayersController; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 318 | WallpaperController mWallpaperController; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 319 | int mInputMethodAnimLayerAdjustment; |
| 320 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 321 | private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> { |
| 322 | WindowStateAnimator winAnimator = w.mWinAnimator; |
| 323 | if (winAnimator.hasSurface()) { |
| 324 | final boolean wasAnimating = winAnimator.mWasAnimating; |
| 325 | final boolean nowAnimating = winAnimator.stepAnimationLocked( |
| 326 | mTmpWindowAnimator.mCurrentTime); |
| 327 | winAnimator.mWasAnimating = nowAnimating; |
| 328 | mTmpWindowAnimator.orAnimating(nowAnimating); |
| 329 | |
| 330 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 331 | w + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating); |
| 332 | |
| 333 | if (wasAnimating && !winAnimator.mAnimating |
| 334 | && mWallpaperController.isWallpaperTarget(w)) { |
| 335 | mTmpWindowAnimator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; |
| 336 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 337 | if (DEBUG_LAYOUT_REPEATS) { |
| 338 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 339 | "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges); |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | final AppWindowToken atoken = w.mAppToken; |
| 345 | if (winAnimator.mDrawState == READY_TO_SHOW) { |
| 346 | if (atoken == null || atoken.allDrawn) { |
| 347 | if (w.performShowLocked()) { |
| 348 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM; |
| 349 | if (DEBUG_LAYOUT_REPEATS) { |
| 350 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
| 351 | "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; |
| 357 | if (appAnimator != null && appAnimator.thumbnail != null) { |
| 358 | if (appAnimator.thumbnailTransactionSeq |
| 359 | != mTmpWindowAnimator.mAnimTransactionSequence) { |
| 360 | appAnimator.thumbnailTransactionSeq = |
| 361 | mTmpWindowAnimator.mAnimTransactionSequence; |
| 362 | appAnimator.thumbnailLayer = 0; |
| 363 | } |
| 364 | if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) { |
| 365 | appAnimator.thumbnailLayer = winAnimator.mAnimLayer; |
| 366 | } |
| 367 | } |
| 368 | }; |
| 369 | |
| 370 | private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> { |
| 371 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 372 | if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) { |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | final int flags = w.mAttrs.flags; |
| 377 | |
| 378 | // If this window is animating, make a note that we have an animating window and take |
| 379 | // care of a request to run a detached wallpaper animation. |
| 380 | if (winAnimator.mAnimating) { |
| 381 | if (winAnimator.mAnimation != null) { |
| 382 | if ((flags & FLAG_SHOW_WALLPAPER) != 0 |
| 383 | && winAnimator.mAnimation.getDetachWallpaper()) { |
| 384 | mTmpWindow = w; |
| 385 | } |
| 386 | final int color = winAnimator.mAnimation.getBackgroundColor(); |
| 387 | if (color != 0) { |
| 388 | final TaskStack stack = w.getStack(); |
| 389 | if (stack != null) { |
| 390 | stack.setAnimationBackground(winAnimator, color); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | mTmpWindowAnimator.setAnimating(true); |
| 395 | } |
| 396 | |
| 397 | // If this window's app token is running a detached wallpaper animation, make a note so |
| 398 | // we can ensure the wallpaper is displayed behind it. |
| 399 | final AppWindowAnimator appAnimator = winAnimator.mAppAnimator; |
| 400 | if (appAnimator != null && appAnimator.animation != null |
| 401 | && appAnimator.animating) { |
| 402 | if ((flags & FLAG_SHOW_WALLPAPER) != 0 |
| 403 | && appAnimator.animation.getDetachWallpaper()) { |
| 404 | mTmpWindow = w; |
| 405 | } |
| 406 | |
| 407 | final int color = appAnimator.animation.getBackgroundColor(); |
| 408 | if (color != 0) { |
| 409 | final TaskStack stack = w.getStack(); |
| 410 | if (stack != null) { |
| 411 | stack.setAnimationBackground(winAnimator, color); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | }; |
| 416 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 417 | private final Consumer<WindowState> mScheduleToastTimeout = w -> { |
| 418 | final int lostFocusUid = mTmpWindow.mOwnerUid; |
| 419 | final Handler handler = mService.mH; |
| 420 | if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) { |
| 421 | if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) { |
| 422 | handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), |
| 423 | w.mAttrs.hideTimeoutMilliseconds); |
| 424 | } |
| 425 | } |
| 426 | }; |
| 427 | |
| 428 | private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> { |
| 429 | final AppWindowToken focusedApp = mService.mFocusedApp; |
| 430 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w |
| 431 | + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys()); |
| 432 | |
| 433 | if (!w.canReceiveKeys()) { |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | final AppWindowToken wtoken = w.mAppToken; |
| 438 | |
| 439 | // If this window's application has been removed, just skip it. |
| 440 | if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) { |
| 441 | if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because " |
| 442 | + (wtoken.removed ? "removed" : "sendingToBottom")); |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | if (focusedApp == null) { |
| 447 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null" |
| 448 | + " using new focus @ " + w); |
| 449 | mTmpWindow = w; |
| 450 | return true; |
| 451 | } |
| 452 | |
| 453 | if (!focusedApp.windowsAreFocusable()) { |
| 454 | // Current focused app windows aren't focusable... |
| 455 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not" |
| 456 | + " focusable using new focus @ " + w); |
| 457 | mTmpWindow = w; |
| 458 | return true; |
| 459 | } |
| 460 | |
| 461 | // Descend through all of the app tokens and find the first that either matches |
| 462 | // win.mAppToken (return win) or mFocusedApp (return null). |
| 463 | if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 464 | if (focusedApp.compareTo(wtoken) > 0) { |
| 465 | // App stack below focused app stack. No focus for you!!! |
| 466 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, |
| 467 | "findFocusedWindow: Reached focused app=" + focusedApp); |
| 468 | mTmpWindow = null; |
| 469 | return true; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w); |
| 474 | mTmpWindow = w; |
| 475 | return true; |
| 476 | }; |
| 477 | |
| 478 | private final Consumer<WindowState> mPrepareWindowSurfaces = |
| 479 | w -> w.mWinAnimator.prepareSurfaceLocked(true); |
| 480 | |
| 481 | private final Consumer<WindowState> mPerformLayout = w -> { |
| 482 | // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid |
| 483 | // wasting time and funky changes while a window is animating away. |
| 484 | final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) |
| 485 | || w.isGoneForLayoutLw(); |
| 486 | |
| 487 | if (DEBUG_LAYOUT && !w.mLayoutAttached) { |
| 488 | Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame |
| 489 | + " mLayoutAttached=" + w.mLayoutAttached |
| 490 | + " screen changed=" + w.isConfigChanged()); |
| 491 | final AppWindowToken atoken = w.mAppToken; |
| 492 | if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility |
| 493 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden |
| 494 | + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested) |
| 495 | + " parentHidden=" + w.isParentWindowHidden()); |
| 496 | else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility |
| 497 | + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.hidden |
| 498 | + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested) |
| 499 | + " parentHidden=" + w.isParentWindowHidden()); |
| 500 | } |
| 501 | |
| 502 | // If this view is GONE, then skip it -- keep the current frame, and let the caller know |
| 503 | // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows, |
| 504 | // since that means "perform layout as normal, just don't display"). |
| 505 | if (!gone || !w.mHaveFrame || w.mLayoutNeeded |
| 506 | || ((w.isConfigChanged() || w.setReportResizeHints()) |
| 507 | && !w.isGoneForLayoutLw() && |
| 508 | ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 || |
| 509 | (w.mHasSurface && w.mAppToken != null && |
| 510 | w.mAppToken.layoutConfigChanges)))) { |
| 511 | if (!w.mLayoutAttached) { |
| 512 | if (mTmpInitial) { |
| 513 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
| 514 | w.mContentChanged = false; |
| 515 | } |
| 516 | if (w.mAttrs.type == TYPE_DREAM) { |
| 517 | // Don't layout windows behind a dream, so that if it does stuff like hide |
| 518 | // the status bar we won't get a bad transition when it goes away. |
| 519 | mTmpWindow = w; |
| 520 | } |
| 521 | w.mLayoutNeeded = false; |
| 522 | w.prelayout(); |
| 523 | mService.mPolicy.layoutWindowLw(w, null); |
| 524 | w.mLayoutSeq = mService.mLayoutSeq; |
| 525 | |
| 526 | // Window frames may have changed. Update dim layer with the new bounds. |
| 527 | final Task task = w.getTask(); |
| 528 | if (task != null) { |
| 529 | mDimLayerController.updateDimLayer(task); |
| 530 | } |
| 531 | |
| 532 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame |
| 533 | + " mContainingFrame=" + w.mContainingFrame |
| 534 | + " mDisplayFrame=" + w.mDisplayFrame); |
| 535 | } |
| 536 | } |
| 537 | }; |
| 538 | |
| 539 | private final Consumer<WindowState> mPerformLayoutAttached = w -> { |
| 540 | if (w.mLayoutAttached) { |
| 541 | if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame |
| 542 | + " mViewVisibility=" + w.mViewVisibility |
| 543 | + " mRelayoutCalled=" + w.mRelayoutCalled); |
| 544 | // If this view is GONE, then skip it -- keep the current frame, and let the caller |
| 545 | // know so they can ignore it if they want. (We do the normal layout for INVISIBLE |
| 546 | // windows, since that means "perform layout as normal, just don't display"). |
| 547 | if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) { |
| 548 | return; |
| 549 | } |
| 550 | if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame |
| 551 | || w.mLayoutNeeded) { |
| 552 | if (mTmpInitial) { |
| 553 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
| 554 | w.mContentChanged = false; |
| 555 | } |
| 556 | w.mLayoutNeeded = false; |
| 557 | w.prelayout(); |
| 558 | mService.mPolicy.layoutWindowLw(w, w.getParentWindow()); |
| 559 | w.mLayoutSeq = mService.mLayoutSeq; |
| 560 | if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame |
| 561 | + " mContainingFrame=" + w.mContainingFrame |
| 562 | + " mDisplayFrame=" + w.mDisplayFrame); |
| 563 | } |
| 564 | } else if (w.mAttrs.type == TYPE_DREAM) { |
| 565 | // Don't layout windows behind a dream, so that if it does stuff like hide the |
| 566 | // status bar we won't get a bad transition when it goes away. |
| 567 | mTmpWindow = mTmpWindow2; |
| 568 | } |
| 569 | }; |
| 570 | |
| 571 | private final Predicate<WindowState> mComputeImeTargetPredicate = w -> { |
| 572 | if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w |
| 573 | + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| 574 | return w.canBeImeTarget(); |
| 575 | }; |
| 576 | |
| 577 | private final Consumer<WindowState> mApplyPostLayoutPolicy = |
| 578 | w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), |
| 579 | mService.mInputMethodTarget); |
| 580 | |
| 581 | private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> { |
| 582 | final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked; |
| 583 | final boolean obscuredChanged = w.mObscured != |
| 584 | mTmpApplySurfaceChangesTransactionState.obscured; |
| 585 | final RootWindowContainer root = mService.mRoot; |
| 586 | // Only used if default window |
| 587 | final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty(); |
| 588 | |
| 589 | // Update effect. |
| 590 | w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured; |
| 591 | if (!mTmpApplySurfaceChangesTransactionState.obscured) { |
| 592 | final boolean isDisplayed = w.isDisplayedLw(); |
| 593 | |
| 594 | if (isDisplayed && w.isObscuringDisplay()) { |
| 595 | // This window completely covers everything behind it, so we want to leave all |
| 596 | // of them as undimmed (for performance reasons). |
| 597 | root.mObscuringWindow = w; |
| 598 | mTmpApplySurfaceChangesTransactionState.obscured = true; |
| 599 | } |
| 600 | |
| 601 | mTmpApplySurfaceChangesTransactionState.displayHasContent |= |
| 602 | root.handleNotObscuredLocked(w, |
| 603 | mTmpApplySurfaceChangesTransactionState.obscured, |
| 604 | mTmpApplySurfaceChangesTransactionState.syswin); |
| 605 | |
| 606 | if (w.mHasSurface && isDisplayed) { |
| 607 | final int type = w.mAttrs.type; |
| 608 | if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR |
| 609 | || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
| 610 | mTmpApplySurfaceChangesTransactionState.syswin = true; |
| 611 | } |
| 612 | if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0 |
| 613 | && w.mAttrs.preferredRefreshRate != 0) { |
| 614 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate |
| 615 | = w.mAttrs.preferredRefreshRate; |
| 616 | } |
| 617 | if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0 |
| 618 | && w.mAttrs.preferredDisplayModeId != 0) { |
| 619 | mTmpApplySurfaceChangesTransactionState.preferredModeId |
| 620 | = w.mAttrs.preferredDisplayModeId; |
| 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | w.applyDimLayerIfNeeded(); |
| 626 | |
| 627 | if (isDefaultDisplay && obscuredChanged && w.isVisibleLw() |
| 628 | && mWallpaperController.isWallpaperTarget(w)) { |
| 629 | // This is the wallpaper target and its obscured state changed... make sure the |
| 630 | // current wallpaper's visibility has been updated accordingly. |
| 631 | mWallpaperController.updateWallpaperVisibility(); |
| 632 | } |
| 633 | |
| 634 | w.handleWindowMovedIfNeeded(); |
| 635 | |
| 636 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 637 | |
| 638 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 639 | w.mContentChanged = false; |
| 640 | |
| 641 | // Moved from updateWindowsAndWallpaperLocked(). |
| 642 | if (w.mHasSurface) { |
| 643 | // Take care of the window being ready to display. |
| 644 | final boolean committed = winAnimator.commitFinishDrawingLocked(); |
| 645 | if (isDefaultDisplay && committed) { |
| 646 | if (w.mAttrs.type == TYPE_DREAM) { |
| 647 | // HACK: When a dream is shown, it may at that point hide the lock screen. |
| 648 | // So we need to redo the layout to let the phone window manager make this |
| 649 | // happen. |
| 650 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT; |
| 651 | if (DEBUG_LAYOUT_REPEATS) { |
| 652 | surfacePlacer.debugLayoutRepeats( |
| 653 | "dream and commitFinishDrawingLocked true", |
| 654 | pendingLayoutChanges); |
| 655 | } |
| 656 | } |
| 657 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 658 | if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 659 | "First draw done in potential wallpaper target " + w); |
| 660 | root.mWallpaperMayChange = true; |
| 661 | pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 662 | if (DEBUG_LAYOUT_REPEATS) { |
| 663 | surfacePlacer.debugLayoutRepeats( |
| 664 | "wallpaper and commitFinishDrawingLocked true", |
| 665 | pendingLayoutChanges); |
| 666 | } |
| 667 | } |
| 668 | } |
Robert Carr | 2117aaf | 2017-04-25 14:46:50 -0700 | [diff] [blame] | 669 | final TaskStack stack = w.getStack(); |
| 670 | if ((!winAnimator.isAnimationStarting() && !winAnimator.isWaitingForOpening()) |
| 671 | || (stack != null && stack.isAnimatingBounds())) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 672 | // Updates the shown frame before we set up the surface. This is needed |
| 673 | // because the resizing could change the top-left position (in addition to |
| 674 | // size) of the window. setSurfaceBoundariesLocked uses mShownPosition to |
| 675 | // position the surface. |
| 676 | // |
| 677 | // If an animation is being started, we can't call this method because the |
| 678 | // animation hasn't processed its initial transformation yet, but in general |
Robert Carr | 2117aaf | 2017-04-25 14:46:50 -0700 | [diff] [blame] | 679 | // we do want to update the position if the window is animating. We make an exception |
| 680 | // for the bounds animating state, where an application may have been waiting |
| 681 | // for an exit animation to start, but instead enters PiP. We need to ensure |
| 682 | // we always recompute the top-left in this case. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 683 | winAnimator.computeShownFrameLocked(); |
| 684 | } |
| 685 | winAnimator.setSurfaceBoundariesLocked(mTmpRecoveringMemory /* recoveringMemory */); |
| 686 | } |
| 687 | |
| 688 | final AppWindowToken atoken = w.mAppToken; |
| 689 | if (atoken != null) { |
| 690 | final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w); |
| 691 | if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) { |
| 692 | mTmpUpdateAllDrawn.add(atoken); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus |
| 697 | && w.isDisplayedLw()) { |
| 698 | mTmpApplySurfaceChangesTransactionState.focusDisplayed = true; |
| 699 | } |
| 700 | |
| 701 | w.updateResizingWindowIfNeeded(); |
| 702 | }; |
| 703 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 704 | /** |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 705 | * Create new {@link DisplayContent} instance, add itself to the root window container and |
| 706 | * initialize direct children. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 707 | * @param display May not be null. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 708 | * @param service You know. |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 709 | * @param layersController window layer controller used to assign layer to the windows on this |
| 710 | * display. |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 711 | * @param wallpaperController wallpaper windows controller used to adjust the positioning of the |
| 712 | * wallpaper windows in the window list. |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 713 | */ |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 714 | DisplayContent(Display display, WindowManagerService service, |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 715 | WindowLayersController layersController, WallpaperController wallpaperController) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 716 | |
| 717 | if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) { |
| 718 | throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() |
| 719 | + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId()) |
| 720 | + " new=" + display); |
| 721 | } |
| 722 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 723 | mDisplay = display; |
| 724 | mDisplayId = display.getDisplayId(); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 725 | mLayersController = layersController; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 726 | mWallpaperController = wallpaperController; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 727 | display.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 728 | display.getMetrics(mDisplayMetrics); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 729 | isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | 9d808b1 | 2013-08-06 18:00:25 -0700 | [diff] [blame] | 730 | mService = service; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 731 | initializeDisplayBaseInfo(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 732 | mDividerControllerLocked = new DockedStackDividerController(service, this); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 733 | mPinnedStackControllerLocked = new PinnedStackController(service, this); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 734 | mDimLayerController = new DimLayerController(this); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 735 | |
| 736 | // These are the only direct children we should ever have and they are permanent. |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 737 | super.addChild(mBelowAppWindowsContainers, null); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 738 | super.addChild(mTaskStackContainers, null); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 739 | super.addChild(mAboveAppWindowsContainers, null); |
| 740 | super.addChild(mImeWindowsContainers, null); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 741 | |
| 742 | // Add itself as a child to the root container. |
| 743 | mService.mRoot.addChild(this, null); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | int getDisplayId() { |
| 747 | return mDisplayId; |
| 748 | } |
| 749 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 750 | WindowToken getWindowToken(IBinder binder) { |
| 751 | return mTokenMap.get(binder); |
| 752 | } |
| 753 | |
| 754 | AppWindowToken getAppWindowToken(IBinder binder) { |
| 755 | final WindowToken token = getWindowToken(binder); |
| 756 | if (token == null) { |
| 757 | return null; |
| 758 | } |
| 759 | return token.asAppWindowToken(); |
| 760 | } |
| 761 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 762 | void addWindowToken(IBinder binder, WindowToken token) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 763 | final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token); |
| 764 | if (dc != null) { |
| 765 | // We currently don't support adding a window token to the display if the display |
| 766 | // already has the binder mapped to another token. If there is a use case for supporting |
| 767 | // this moving forward we will either need to merge the WindowTokens some how or have |
| 768 | // the binder map to a list of window tokens. |
| 769 | throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this |
| 770 | + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap); |
| 771 | } |
| 772 | mTokenMap.put(binder, token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 773 | |
| 774 | if (token.asAppWindowToken() == null) { |
| 775 | // Add non-app token to container hierarchy on the display. App tokens are added through |
| 776 | // the parent container managing them (e.g. Tasks). |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 777 | switch (token.windowType) { |
| 778 | case TYPE_WALLPAPER: |
| 779 | mBelowAppWindowsContainers.addChild(token); |
| 780 | break; |
| 781 | case TYPE_INPUT_METHOD: |
| 782 | case TYPE_INPUT_METHOD_DIALOG: |
| 783 | mImeWindowsContainers.addChild(token); |
| 784 | break; |
| 785 | default: |
| 786 | mAboveAppWindowsContainers.addChild(token); |
| 787 | break; |
| 788 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 789 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | WindowToken removeWindowToken(IBinder binder) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 793 | final WindowToken token = mTokenMap.remove(binder); |
| 794 | if (token != null && token.asAppWindowToken() == null) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 795 | token.setExiting(); |
| 796 | } |
| 797 | return token; |
| 798 | } |
| 799 | |
| 800 | /** Changes the display the input window token is housed on to this one. */ |
| 801 | void reParentWindowToken(WindowToken token) { |
| 802 | final DisplayContent prevDc = token.getDisplayContent(); |
| 803 | if (prevDc == this) { |
| 804 | return; |
| 805 | } |
Andrii Kulian | 6cc1a1d | 2016-12-27 23:52:59 -0800 | [diff] [blame] | 806 | if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null |
| 807 | && token.asAppWindowToken() == null) { |
| 808 | // Removed the token from the map, but made sure it's not an app token before removing |
| 809 | // from parent. |
| 810 | token.getParent().removeChild(token); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 811 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 812 | |
| 813 | addWindowToken(token.token, token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 816 | void removeAppToken(IBinder binder) { |
| 817 | final WindowToken token = removeWindowToken(binder); |
| 818 | if (token == null) { |
| 819 | Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder); |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | final AppWindowToken appToken = token.asAppWindowToken(); |
| 824 | |
| 825 | if (appToken == null) { |
| 826 | Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token); |
| 827 | return; |
| 828 | } |
| 829 | |
| 830 | appToken.onRemovedFromDisplay(); |
| 831 | } |
| 832 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 833 | Display getDisplay() { |
| 834 | return mDisplay; |
| 835 | } |
| 836 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 837 | DisplayInfo getDisplayInfo() { |
| 838 | return mDisplayInfo; |
| 839 | } |
| 840 | |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 841 | DisplayMetrics getDisplayMetrics() { |
| 842 | return mDisplayMetrics; |
| 843 | } |
| 844 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 845 | int getRotation() { |
| 846 | return mRotation; |
| 847 | } |
| 848 | |
| 849 | void setRotation(int newRotation) { |
| 850 | mRotation = newRotation; |
| 851 | } |
| 852 | |
| 853 | int getLastOrientation() { |
| 854 | return mLastOrientation; |
| 855 | } |
| 856 | |
| 857 | void setLastOrientation(int orientation) { |
| 858 | mLastOrientation = orientation; |
| 859 | } |
| 860 | |
| 861 | boolean getAltOrientation() { |
| 862 | return mAltOrientation; |
| 863 | } |
| 864 | |
| 865 | void setAltOrientation(boolean altOrientation) { |
| 866 | mAltOrientation = altOrientation; |
| 867 | } |
| 868 | |
| 869 | int getLastWindowForcedOrientation() { |
| 870 | return mLastWindowForcedOrientation; |
| 871 | } |
| 872 | |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 873 | /** |
| 874 | * Update rotation of the display. |
| 875 | * |
| 876 | * Returns true if the rotation has been changed. In this case YOU MUST CALL |
| 877 | * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN. |
| 878 | */ |
| 879 | boolean updateRotationUnchecked(boolean inTransaction) { |
| 880 | if (mService.mDeferredRotationPauseCount > 0) { |
| 881 | // Rotation updates have been paused temporarily. Defer the update until |
| 882 | // updates have been resumed. |
| 883 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused."); |
| 884 | return false; |
| 885 | } |
| 886 | |
| 887 | ScreenRotationAnimation screenRotationAnimation = |
| 888 | mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId); |
| 889 | if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) { |
| 890 | // Rotation updates cannot be performed while the previous rotation change |
| 891 | // animation is still in progress. Skip this update. We will try updating |
| 892 | // again after the animation is finished and the display is unfrozen. |
| 893 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress."); |
| 894 | return false; |
| 895 | } |
| 896 | if (mService.mDisplayFrozen) { |
| 897 | // Even if the screen rotation animation has finished (e.g. isAnimating |
| 898 | // returns false), there is still some time where we haven't yet unfrozen |
| 899 | // the display. We also need to abort rotation here. |
| 900 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 901 | "Deferring rotation, still finishing previous rotation"); |
| 902 | return false; |
| 903 | } |
| 904 | |
| 905 | if (!mService.mDisplayEnabled) { |
| 906 | // No point choosing a rotation if the display is not enabled. |
| 907 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled."); |
| 908 | return false; |
| 909 | } |
| 910 | |
| 911 | final int oldRotation = mRotation; |
| 912 | final int lastOrientation = mLastOrientation; |
| 913 | final boolean oldAltOrientation = mAltOrientation; |
| 914 | int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation); |
Robert Carr | 897215d | 2017-03-29 12:25:50 -0700 | [diff] [blame] | 915 | final boolean rotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation, |
| 916 | rotation); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 917 | |
Robert Carr | 897215d | 2017-03-29 12:25:50 -0700 | [diff] [blame] | 918 | if (rotateSeamlessly) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 919 | final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated); |
| 920 | if (seamlessRotated != null) { |
| 921 | // We can't rotate (seamlessly or not) while waiting for the last seamless rotation |
| 922 | // to complete (that is, waiting for windows to redraw). It's tempting to check |
| 923 | // w.mSeamlessRotationCount but that could be incorrect in the case of |
| 924 | // window-removal. |
| 925 | return false; |
| 926 | } |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | // TODO: Implement forced rotation changes. |
| 930 | // Set mAltOrientation to indicate that the application is receiving |
| 931 | // an orientation that has different metrics than it expected. |
| 932 | // eg. Portrait instead of Landscape. |
| 933 | |
| 934 | final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw( |
| 935 | lastOrientation, rotation); |
| 936 | |
| 937 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation |
| 938 | + ", got rotation " + rotation + " which has " |
| 939 | + (altOrientation ? "incompatible" : "compatible") + " metrics"); |
| 940 | |
| 941 | if (oldRotation == rotation && oldAltOrientation == altOrientation) { |
| 942 | // No change. |
| 943 | return false; |
| 944 | } |
| 945 | |
| 946 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation |
| 947 | + (altOrientation ? " (alt)" : "") + " from " + oldRotation |
| 948 | + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation); |
| 949 | |
| 950 | if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) { |
| 951 | mService.mWaitingForConfig = true; |
| 952 | } |
| 953 | |
| 954 | mRotation = rotation; |
| 955 | mAltOrientation = altOrientation; |
| 956 | if (isDefaultDisplay) { |
| 957 | mService.mPolicy.setRotationLw(rotation); |
| 958 | } |
| 959 | |
| 960 | mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE; |
| 961 | mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT); |
| 962 | mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT, |
| 963 | WINDOW_FREEZE_TIMEOUT_DURATION); |
| 964 | |
| 965 | setLayoutNeeded(); |
| 966 | final int[] anim = new int[2]; |
| 967 | if (isDimming()) { |
| 968 | anim[0] = anim[1] = 0; |
| 969 | } else { |
| 970 | mService.mPolicy.selectRotationAnimationLw(anim); |
| 971 | } |
| 972 | |
| 973 | if (!rotateSeamlessly) { |
| 974 | mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1]); |
| 975 | // startFreezingDisplayLocked can reset the ScreenRotationAnimation. |
| 976 | screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked( |
| 977 | mDisplayId); |
| 978 | } else { |
| 979 | // The screen rotation animation uses a screenshot to freeze the screen |
| 980 | // while windows resize underneath. |
| 981 | // When we are rotating seamlessly, we allow the elements to transition |
| 982 | // to their rotated state independently and without a freeze required. |
| 983 | screenRotationAnimation = null; |
| 984 | |
| 985 | // We have to reset this in case a window was removed before it |
| 986 | // finished seamless rotation. |
| 987 | mService.mSeamlessRotationCount = 0; |
| 988 | } |
| 989 | |
| 990 | // We need to update our screen size information to match the new rotation. If the rotation |
| 991 | // has actually changed then this method will return true and, according to the comment at |
| 992 | // the top of the method, the caller is obligated to call computeNewConfigurationLocked(). |
| 993 | // By updating the Display info here it will be available to |
| 994 | // #computeScreenConfiguration() later. |
| 995 | updateDisplayAndOrientation(getConfiguration().uiMode); |
| 996 | |
| 997 | if (!inTransaction) { |
| 998 | if (SHOW_TRANSACTIONS) { |
| 999 | Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 1000 | } |
| 1001 | mService.openSurfaceTransaction(); |
| 1002 | } |
| 1003 | try { |
| 1004 | // NOTE: We disable the rotation in the emulator because |
| 1005 | // it doesn't support hardware OpenGL emulation yet. |
| 1006 | if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null |
| 1007 | && screenRotationAnimation.hasScreenshot()) { |
| 1008 | if (screenRotationAnimation.setRotationInTransaction( |
| 1009 | rotation, mService.mFxSession, |
| 1010 | MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(), |
| 1011 | mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) { |
| 1012 | mService.scheduleAnimationLocked(); |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | if (rotateSeamlessly) { |
| 1017 | forAllWindows(w -> { |
| 1018 | w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation); |
| 1019 | }, true /* traverseTopToBottom */); |
| 1020 | } |
| 1021 | |
| 1022 | mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager(); |
| 1023 | } finally { |
| 1024 | if (!inTransaction) { |
| 1025 | mService.closeSurfaceTransaction(); |
| 1026 | if (SHOW_LIGHT_TRANSACTIONS) { |
| 1027 | Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | forAllWindows(w -> { |
| 1033 | // Discard surface after orientation change, these can't be reused. |
| 1034 | if (w.mAppToken != null) { |
| 1035 | w.mAppToken.destroySavedSurfaces(); |
| 1036 | } |
| 1037 | if (w.mHasSurface && !rotateSeamlessly) { |
| 1038 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w); |
| 1039 | w.mOrientationChanging = true; |
| 1040 | mService.mRoot.mOrientationChangeComplete = false; |
| 1041 | w.mLastFreezeDuration = 0; |
| 1042 | } |
| 1043 | w.mReportOrientationChanged = true; |
| 1044 | }, true /* traverseTopToBottom */); |
| 1045 | |
| 1046 | if (rotateSeamlessly) { |
| 1047 | mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT); |
| 1048 | mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT, |
| 1049 | SEAMLESS_ROTATION_TIMEOUT_DURATION); |
| 1050 | } |
| 1051 | |
| 1052 | for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) { |
| 1053 | final WindowManagerService.RotationWatcher rotationWatcher |
| 1054 | = mService.mRotationWatchers.get(i); |
| 1055 | if (rotationWatcher.mDisplayId == mDisplayId) { |
| 1056 | try { |
| 1057 | rotationWatcher.mWatcher.onRotationChanged(rotation); |
| 1058 | } catch (RemoteException e) { |
| 1059 | // Ignore |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | // TODO (multi-display): Magnification is supported only for the default display. |
| 1065 | // Announce rotation only if we will not animate as we already have the |
| 1066 | // windows in final state. Otherwise, we make this call at the rotation end. |
| 1067 | if (screenRotationAnimation == null && mService.mAccessibilityController != null |
| 1068 | && isDefaultDisplay) { |
| 1069 | mService.mAccessibilityController.onRotationChangedLocked(this); |
| 1070 | } |
| 1071 | |
| 1072 | return true; |
| 1073 | } |
| 1074 | |
| 1075 | /** |
| 1076 | * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config |
| 1077 | * changed. |
| 1078 | * Do not call if {@link WindowManagerService#mDisplayReady} == false. |
| 1079 | */ |
| 1080 | private DisplayInfo updateDisplayAndOrientation(int uiMode) { |
| 1081 | // Use the effective "visual" dimensions based on current rotation |
| 1082 | final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270); |
| 1083 | final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1084 | final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
| 1085 | int dw = realdw; |
| 1086 | int dh = realdh; |
| 1087 | |
| 1088 | if (mAltOrientation) { |
| 1089 | if (realdw > realdh) { |
| 1090 | // Turn landscape into portrait. |
| 1091 | int maxw = (int)(realdh/1.3f); |
| 1092 | if (maxw < realdw) { |
| 1093 | dw = maxw; |
| 1094 | } |
| 1095 | } else { |
| 1096 | // Turn portrait into landscape. |
| 1097 | int maxh = (int)(realdw/1.3f); |
| 1098 | if (maxh < realdh) { |
| 1099 | dh = maxh; |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | // Update application display metrics. |
| 1105 | final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode, |
| 1106 | mDisplayId); |
| 1107 | final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode, |
| 1108 | mDisplayId); |
| 1109 | mDisplayInfo.rotation = mRotation; |
| 1110 | mDisplayInfo.logicalWidth = dw; |
| 1111 | mDisplayInfo.logicalHeight = dh; |
| 1112 | mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity; |
| 1113 | mDisplayInfo.appWidth = appWidth; |
| 1114 | mDisplayInfo.appHeight = appHeight; |
| 1115 | if (isDefaultDisplay) { |
| 1116 | mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics, |
| 1117 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
| 1118 | } |
| 1119 | mDisplayInfo.getAppMetrics(mDisplayMetrics); |
| 1120 | if (mDisplayScalingDisabled) { |
| 1121 | mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED; |
| 1122 | } else { |
| 1123 | mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED; |
| 1124 | } |
| 1125 | |
| 1126 | mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId, |
| 1127 | mDisplayInfo); |
| 1128 | |
| 1129 | mBaseDisplayRect.set(0, 0, dw, dh); |
| 1130 | |
| 1131 | if (isDefaultDisplay) { |
| 1132 | mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics, |
| 1133 | mCompatDisplayMetrics); |
| 1134 | } |
| 1135 | return mDisplayInfo; |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * Compute display configuration based on display properties and policy settings. |
| 1140 | * Do not call if mDisplayReady == false. |
| 1141 | */ |
| 1142 | void computeScreenConfiguration(Configuration config) { |
| 1143 | final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode); |
| 1144 | |
| 1145 | final int dw = displayInfo.logicalWidth; |
| 1146 | final int dh = displayInfo.logicalHeight; |
| 1147 | config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT : |
| 1148 | Configuration.ORIENTATION_LANDSCAPE; |
| 1149 | config.screenWidthDp = |
| 1150 | (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation, |
| 1151 | config.uiMode, mDisplayId) / mDisplayMetrics.density); |
| 1152 | config.screenHeightDp = |
| 1153 | (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation, |
| 1154 | config.uiMode, mDisplayId) / mDisplayMetrics.density); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 1155 | |
| 1156 | mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, mTmpRect); |
| 1157 | final int leftInset = mTmpRect.left; |
| 1158 | final int topInset = mTmpRect.top; |
| 1159 | // appBounds at the root level should mirror the app screen size. |
| 1160 | config.setAppBounds(leftInset /*left*/, topInset /*top*/, leftInset + displayInfo.appWidth /*right*/, |
| 1161 | topInset + displayInfo.appHeight /*bottom*/); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1162 | final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90 |
| 1163 | || displayInfo.rotation == Surface.ROTATION_270); |
| 1164 | |
| 1165 | computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh, |
| 1166 | mDisplayMetrics.density, config); |
| 1167 | |
| 1168 | config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK) |
| 1169 | | ((displayInfo.flags & Display.FLAG_ROUND) != 0 |
| 1170 | ? Configuration.SCREENLAYOUT_ROUND_YES |
| 1171 | : Configuration.SCREENLAYOUT_ROUND_NO); |
| 1172 | |
| 1173 | config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale); |
| 1174 | config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale); |
| 1175 | config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw, |
| 1176 | dh, mDisplayId); |
| 1177 | config.densityDpi = displayInfo.logicalDensityDpi; |
| 1178 | |
| 1179 | config.colorMode = |
| 1180 | (displayInfo.isHdr() |
| 1181 | ? Configuration.COLOR_MODE_HDR_YES |
| 1182 | : Configuration.COLOR_MODE_HDR_NO) |
| 1183 | | (displayInfo.isWideColorGamut() |
| 1184 | ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES |
| 1185 | : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO); |
| 1186 | |
| 1187 | // Update the configuration based on available input devices, lid switch, |
| 1188 | // and platform configuration. |
| 1189 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1190 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 1191 | config.navigation = Configuration.NAVIGATION_NONAV; |
| 1192 | |
| 1193 | int keyboardPresence = 0; |
| 1194 | int navigationPresence = 0; |
| 1195 | final InputDevice[] devices = mService.mInputManager.getInputDevices(); |
| 1196 | final int len = devices != null ? devices.length : 0; |
| 1197 | for (int i = 0; i < len; i++) { |
| 1198 | InputDevice device = devices[i]; |
| 1199 | if (!device.isVirtual()) { |
| 1200 | final int sources = device.getSources(); |
| 1201 | final int presenceFlag = device.isExternal() ? |
| 1202 | WindowManagerPolicy.PRESENCE_EXTERNAL : |
| 1203 | WindowManagerPolicy.PRESENCE_INTERNAL; |
| 1204 | |
| 1205 | // TODO(multi-display): Configure on per-display basis. |
| 1206 | if (mService.mIsTouchDevice) { |
| 1207 | if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == |
| 1208 | InputDevice.SOURCE_TOUCHSCREEN) { |
| 1209 | config.touchscreen = Configuration.TOUCHSCREEN_FINGER; |
| 1210 | } |
| 1211 | } else { |
| 1212 | config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH; |
| 1213 | } |
| 1214 | |
| 1215 | if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) { |
| 1216 | config.navigation = Configuration.NAVIGATION_TRACKBALL; |
| 1217 | navigationPresence |= presenceFlag; |
| 1218 | } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD |
| 1219 | && config.navigation == Configuration.NAVIGATION_NONAV) { |
| 1220 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1221 | navigationPresence |= presenceFlag; |
| 1222 | } |
| 1223 | |
| 1224 | if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) { |
| 1225 | config.keyboard = Configuration.KEYBOARD_QWERTY; |
| 1226 | keyboardPresence |= presenceFlag; |
| 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) { |
| 1232 | config.navigation = Configuration.NAVIGATION_DPAD; |
| 1233 | navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL; |
| 1234 | } |
| 1235 | |
| 1236 | // Determine whether a hard keyboard is available and enabled. |
| 1237 | // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device? |
| 1238 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 1239 | if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) { |
| 1240 | mService.mHardKeyboardAvailable = hardKeyboardAvailable; |
| 1241 | mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 1242 | mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 1243 | } |
| 1244 | |
| 1245 | // Let the policy update hidden states. |
| 1246 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 1247 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 1248 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
| 1249 | mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence); |
| 1250 | } |
| 1251 | |
| 1252 | private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh, |
| 1253 | int displayId) { |
| 1254 | mTmpDisplayMetrics.setTo(mDisplayMetrics); |
| 1255 | final DisplayMetrics tmpDm = mTmpDisplayMetrics; |
| 1256 | final int unrotDw, unrotDh; |
| 1257 | if (rotated) { |
| 1258 | unrotDw = dh; |
| 1259 | unrotDh = dw; |
| 1260 | } else { |
| 1261 | unrotDw = dw; |
| 1262 | unrotDh = dh; |
| 1263 | } |
| 1264 | int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh, |
| 1265 | displayId); |
| 1266 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw, |
| 1267 | displayId); |
| 1268 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh, |
| 1269 | displayId); |
| 1270 | sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw, |
| 1271 | displayId); |
| 1272 | return sw; |
| 1273 | } |
| 1274 | |
| 1275 | private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode, |
| 1276 | DisplayMetrics dm, int dw, int dh, int displayId) { |
| 1277 | dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, |
| 1278 | displayId); |
| 1279 | dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, |
| 1280 | uiMode, displayId); |
| 1281 | float scale = CompatibilityInfo.computeCompatibleScaling(dm, null); |
| 1282 | int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f); |
| 1283 | if (curSize == 0 || size < curSize) { |
| 1284 | curSize = size; |
| 1285 | } |
| 1286 | return curSize; |
| 1287 | } |
| 1288 | |
| 1289 | private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId, |
| 1290 | boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) { |
| 1291 | |
| 1292 | // We need to determine the smallest width that will occur under normal |
| 1293 | // operation. To this, start with the base screen size and compute the |
| 1294 | // width under the different possible rotations. We need to un-rotate |
| 1295 | // the current screen dimensions before doing this. |
| 1296 | int unrotDw, unrotDh; |
| 1297 | if (rotated) { |
| 1298 | unrotDw = dh; |
| 1299 | unrotDh = dw; |
| 1300 | } else { |
| 1301 | unrotDw = dw; |
| 1302 | unrotDh = dh; |
| 1303 | } |
| 1304 | displayInfo.smallestNominalAppWidth = 1<<30; |
| 1305 | displayInfo.smallestNominalAppHeight = 1<<30; |
| 1306 | displayInfo.largestNominalAppWidth = 0; |
| 1307 | displayInfo.largestNominalAppHeight = 0; |
| 1308 | adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw, |
| 1309 | unrotDh); |
| 1310 | adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh, |
| 1311 | unrotDw); |
| 1312 | adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw, |
| 1313 | unrotDh); |
| 1314 | adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh, |
| 1315 | unrotDw); |
| 1316 | int sl = Configuration.resetScreenLayout(outConfig.screenLayout); |
| 1317 | sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode, |
| 1318 | displayId); |
| 1319 | sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode, |
| 1320 | displayId); |
| 1321 | sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode, |
| 1322 | displayId); |
| 1323 | sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode, |
| 1324 | displayId); |
| 1325 | outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density); |
| 1326 | outConfig.screenLayout = sl; |
| 1327 | } |
| 1328 | |
| 1329 | private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh, |
| 1330 | int uiMode, int displayId) { |
| 1331 | // Get the app screen size at this rotation. |
| 1332 | int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId); |
| 1333 | int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId); |
| 1334 | |
| 1335 | // Compute the screen layout size class for this rotation. |
| 1336 | int longSize = w; |
| 1337 | int shortSize = h; |
| 1338 | if (longSize < shortSize) { |
| 1339 | int tmp = longSize; |
| 1340 | longSize = shortSize; |
| 1341 | shortSize = tmp; |
| 1342 | } |
| 1343 | longSize = (int)(longSize/density); |
| 1344 | shortSize = (int)(shortSize/density); |
| 1345 | return Configuration.reduceScreenLayout(curLayout, longSize, shortSize); |
| 1346 | } |
| 1347 | |
| 1348 | private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation, |
| 1349 | int uiMode, int dw, int dh) { |
| 1350 | final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode, |
| 1351 | displayId); |
| 1352 | if (width < displayInfo.smallestNominalAppWidth) { |
| 1353 | displayInfo.smallestNominalAppWidth = width; |
| 1354 | } |
| 1355 | if (width > displayInfo.largestNominalAppWidth) { |
| 1356 | displayInfo.largestNominalAppWidth = width; |
| 1357 | } |
| 1358 | final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode, |
| 1359 | displayId); |
| 1360 | if (height < displayInfo.smallestNominalAppHeight) { |
| 1361 | displayInfo.smallestNominalAppHeight = height; |
| 1362 | } |
| 1363 | if (height > displayInfo.largestNominalAppHeight) { |
| 1364 | displayInfo.largestNominalAppHeight = height; |
| 1365 | } |
| 1366 | } |
| 1367 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 1368 | DockedStackDividerController getDockedDividerController() { |
| 1369 | return mDividerControllerLocked; |
| 1370 | } |
| 1371 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1372 | PinnedStackController getPinnedStackController() { |
| 1373 | return mPinnedStackControllerLocked; |
| 1374 | } |
| 1375 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1376 | /** |
| 1377 | * Returns true if the specified UID has access to this display. |
| 1378 | */ |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1379 | boolean hasAccess(int uid) { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1380 | return mDisplay.hasAccess(uid); |
| 1381 | } |
| 1382 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1383 | boolean isPrivate() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1384 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 1387 | TaskStack getHomeStack() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1388 | if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1389 | Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1390 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1391 | return mHomeStack; |
Craig Mautner | d5d5d0f | 2013-04-03 15:08:21 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 1394 | TaskStack getStackById(int stackId) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1395 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1396 | final TaskStack stack = mTaskStackContainers.get(i); |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 1397 | if (stack.mStackId == stackId) { |
| 1398 | return stack; |
| 1399 | } |
| 1400 | } |
| 1401 | return null; |
| 1402 | } |
| 1403 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 1404 | @VisibleForTesting |
| 1405 | int getStackCount() { |
| 1406 | return mTaskStackContainers.size(); |
| 1407 | } |
| 1408 | |
| 1409 | @VisibleForTesting |
| 1410 | int getStaskPosById(int stackId) { |
| 1411 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1412 | final TaskStack stack = mTaskStackContainers.get(i); |
| 1413 | if (stack.mStackId == stackId) { |
| 1414 | return i; |
| 1415 | } |
| 1416 | } |
| 1417 | return -1; |
| 1418 | } |
| 1419 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1420 | @Override |
| 1421 | void onConfigurationChanged(Configuration newParentConfig) { |
| 1422 | super.onConfigurationChanged(newParentConfig); |
| 1423 | |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 1424 | // The display size information is heavily dependent on the resources in the current |
| 1425 | // configuration, so we need to reconfigure it every time the configuration changes. |
| 1426 | // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh... |
| 1427 | mService.reconfigureDisplayLocked(this); |
| 1428 | |
| 1429 | getDockedDividerController().onConfigurationChanged(); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1430 | getPinnedStackController().onConfigurationChanged(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1431 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 1432 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1433 | /** |
| 1434 | * Callback used to trigger bounds update after configuration change and get ids of stacks whose |
| 1435 | * bounds were updated. |
| 1436 | */ |
| 1437 | void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1438 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1439 | final TaskStack stack = mTaskStackContainers.get(i); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 1440 | if (stack.updateBoundsAfterConfigChange()) { |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 1441 | changedStackList.add(stack.mStackId); |
| 1442 | } |
| 1443 | } |
Winson Chung | 32c566f | 2017-04-11 18:31:21 -0700 | [diff] [blame] | 1444 | |
| 1445 | // If there was no pinned stack, we still need to notify the controller of the display info |
| 1446 | // update as a result of the config change. We do this here to consolidate the flow between |
| 1447 | // changes when there is and is not a stack. |
| 1448 | if (getStackById(PINNED_STACK_ID) == null) { |
| 1449 | mPinnedStackControllerLocked.onDisplayInfoChanged(); |
| 1450 | } |
Andrii Kulian | 3a507b5 | 2016-09-19 18:14:12 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1453 | @Override |
| 1454 | boolean fillsParent() { |
| 1455 | return true; |
| 1456 | } |
| 1457 | |
| 1458 | @Override |
| 1459 | boolean isVisible() { |
| 1460 | return true; |
| 1461 | } |
| 1462 | |
| 1463 | @Override |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1464 | void onAppTransitionDone() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1465 | super.onAppTransitionDone(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1466 | mService.mWindowsChanged = true; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1469 | @Override |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 1470 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 1471 | // Special handling so we can process IME windows with #forAllImeWindows above their IME |
| 1472 | // target, or here in order if there isn't an IME target. |
| 1473 | if (traverseTopToBottom) { |
| 1474 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1475 | final DisplayChildWindowContainer child = mChildren.get(i); |
| 1476 | if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) { |
| 1477 | // In this case the Ime windows will be processed above their target so we skip |
| 1478 | // here. |
| 1479 | continue; |
| 1480 | } |
| 1481 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 1482 | return true; |
| 1483 | } |
| 1484 | } |
| 1485 | } else { |
| 1486 | final int count = mChildren.size(); |
| 1487 | for (int i = 0; i < count; i++) { |
| 1488 | final DisplayChildWindowContainer child = mChildren.get(i); |
| 1489 | if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) { |
| 1490 | // In this case the Ime windows will be processed above their target so we skip |
| 1491 | // here. |
| 1492 | continue; |
| 1493 | } |
| 1494 | if (child.forAllWindows(callback, traverseTopToBottom)) { |
| 1495 | return true; |
| 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | return false; |
| 1500 | } |
| 1501 | |
| 1502 | boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
| 1503 | return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom); |
| 1504 | } |
| 1505 | |
| 1506 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1507 | int getOrientation() { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1508 | final WindowManagerPolicy policy = mService.mPolicy; |
| 1509 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1510 | if (mService.mDisplayFrozen) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1511 | if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1512 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1513 | "Display is frozen, return " + mLastWindowForcedOrientation); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1514 | // If the display is frozen, some activities may be in the middle of restarting, and |
| 1515 | // thus have removed their old window. If the window has the flag to hide the lock |
| 1516 | // screen, then the lock screen can re-appear and inflict its own orientation on us. |
| 1517 | // Keep the orientation stable until this all settles down. |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1518 | return mLastWindowForcedOrientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1519 | } else if (policy.isKeyguardLocked()) { |
| 1520 | // Use the last orientation the while the display is frozen with the keyguard |
| 1521 | // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED |
| 1522 | // window. We don't want to check the show when locked window directly though as |
| 1523 | // things aren't stable while the display is frozen, for example the window could be |
| 1524 | // momentarily unavailable due to activity relaunch. |
| 1525 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, " |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 1526 | + "return " + mLastOrientation); |
| 1527 | return mLastOrientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1528 | } |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1529 | } else { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1530 | final int orientation = mAboveAppWindowsContainers.getOrientation(); |
| 1531 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 1532 | return orientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1533 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 1536 | // Top system windows are not requesting an orientation. Start searching from apps. |
| 1537 | return mTaskStackContainers.getOrientation(); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1540 | void updateDisplayInfo() { |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 1541 | // Check if display metrics changed and update base values if needed. |
| 1542 | updateBaseDisplayMetricsIfNeeded(); |
| 1543 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1544 | mDisplay.getDisplayInfo(mDisplayInfo); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 1545 | mDisplay.getMetrics(mDisplayMetrics); |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 1546 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1547 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1548 | mTaskStackContainers.get(i).updateDisplayInfo(null); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1549 | } |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 1552 | void initializeDisplayBaseInfo() { |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 1553 | final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal; |
| 1554 | if (displayManagerInternal != null) { |
| 1555 | // Bootstrap the default logical display from the display manager. |
| 1556 | final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId); |
| 1557 | if (newDisplayInfo != null) { |
| 1558 | mDisplayInfo.copyFrom(newDisplayInfo); |
| 1559 | } |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 1560 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 1561 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 1562 | updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight, |
| 1563 | mDisplayInfo.logicalDensityDpi); |
| 1564 | mInitialDisplayWidth = mDisplayInfo.logicalWidth; |
| 1565 | mInitialDisplayHeight = mDisplayInfo.logicalHeight; |
| 1566 | mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi; |
Wale Ogunwale | fd04d8c | 2015-09-30 10:09:39 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1569 | void getLogicalDisplayRect(Rect out) { |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1570 | // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1571 | final int orientation = mDisplayInfo.rotation; |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 1572 | boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1573 | final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth; |
| 1574 | final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1575 | int width = mDisplayInfo.logicalWidth; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1576 | int left = (physWidth - width) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1577 | int height = mDisplayInfo.logicalHeight; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1578 | int top = (physHeight - height) / 2; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1579 | out.set(left, top, left + width, top + height); |
| 1580 | } |
| 1581 | |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 1582 | private void getLogicalDisplayRect(Rect out, int orientation) { |
| 1583 | getLogicalDisplayRect(out); |
| 1584 | |
| 1585 | // Rotate the Rect if needed. |
| 1586 | final int currentRotation = mDisplayInfo.rotation; |
| 1587 | final int rotationDelta = deltaRotation(currentRotation, orientation); |
| 1588 | if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) { |
| 1589 | createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix); |
| 1590 | mTmpRectF.set(out); |
| 1591 | mTmpMatrix.mapRect(mTmpRectF); |
| 1592 | mTmpRectF.round(out); |
| 1593 | } |
| 1594 | } |
| 1595 | |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 1596 | /** |
| 1597 | * If display metrics changed, overrides are not set and it's not just a rotation - update base |
| 1598 | * values. |
| 1599 | */ |
| 1600 | private void updateBaseDisplayMetricsIfNeeded() { |
| 1601 | // Get real display metrics without overrides from WM. |
| 1602 | mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo); |
| 1603 | final int orientation = mDisplayInfo.rotation; |
| 1604 | final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270); |
| 1605 | final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth; |
| 1606 | final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight; |
| 1607 | final int newDensity = mDisplayInfo.logicalDensityDpi; |
| 1608 | |
| 1609 | final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth |
| 1610 | || mInitialDisplayHeight != newHeight |
| 1611 | || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi; |
| 1612 | |
| 1613 | if (displayMetricsChanged) { |
| 1614 | // Check if display size or density is forced. |
| 1615 | final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth |
| 1616 | || mBaseDisplayHeight != mInitialDisplayHeight; |
| 1617 | final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity; |
| 1618 | |
| 1619 | // If there is an override set for base values - use it, otherwise use new values. |
| 1620 | updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth, |
| 1621 | isDisplaySizeForced ? mBaseDisplayHeight : newHeight, |
| 1622 | isDisplayDensityForced ? mBaseDisplayDensity : newDensity); |
| 1623 | |
| 1624 | // Real display metrics changed, so we should also update initial values. |
| 1625 | mInitialDisplayWidth = newWidth; |
| 1626 | mInitialDisplayHeight = newHeight; |
| 1627 | mInitialDisplayDensity = newDensity; |
| 1628 | mService.reconfigureDisplayLocked(this); |
| 1629 | } |
| 1630 | } |
| 1631 | |
Bryce Lee | 27cec32 | 2017-03-21 09:41:37 -0700 | [diff] [blame] | 1632 | /** Sets the maximum width the screen resolution can be */ |
| 1633 | void setMaxUiWidth(int width) { |
| 1634 | if (DEBUG_DISPLAY) { |
| 1635 | Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId()); |
| 1636 | } |
| 1637 | |
| 1638 | mMaxUiWidth = width; |
| 1639 | |
| 1640 | // Update existing metrics. |
| 1641 | updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity); |
| 1642 | } |
| 1643 | |
| 1644 | /** Update base (override) display metrics. */ |
| 1645 | void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) { |
| 1646 | mBaseDisplayWidth = baseWidth; |
| 1647 | mBaseDisplayHeight = baseHeight; |
| 1648 | mBaseDisplayDensity = baseDensity; |
| 1649 | |
| 1650 | if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) { |
| 1651 | mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth; |
| 1652 | mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth; |
| 1653 | mBaseDisplayWidth = mMaxUiWidth; |
| 1654 | |
| 1655 | if (DEBUG_DISPLAY) { |
| 1656 | Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x" |
| 1657 | + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity |
| 1658 | + " on display:" + getDisplayId()); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight); |
| 1663 | } |
| 1664 | |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 1665 | void getContentRect(Rect out) { |
| 1666 | out.set(mContentRect); |
| 1667 | } |
| 1668 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1669 | TaskStack addStackToDisplay(int stackId, boolean onTop) { |
| 1670 | if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId=" |
| 1671 | + mDisplayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1672 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1673 | TaskStack stack = getStackById(stackId); |
| 1674 | if (stack != null) { |
| 1675 | // It's already attached to the display...clear mDeferRemoval and move stack to |
| 1676 | // appropriate z-order on display as needed. |
| 1677 | stack.mDeferRemoval = false; |
| 1678 | // We're not moving the display to front when we're adding stacks, only when |
| 1679 | // requested to change the position of stack explicitly. |
| 1680 | mTaskStackContainers.positionChildAt(onTop ? POSITION_TOP : POSITION_BOTTOM, stack, |
| 1681 | false /* includingParents */); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1682 | } else { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1683 | stack = new TaskStack(mService, stackId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1684 | mTaskStackContainers.addStackToDisplay(stack, onTop); |
| 1685 | } |
| 1686 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1687 | if (stackId == DOCKED_STACK_ID) { |
| 1688 | mDividerControllerLocked.notifyDockedStackExistsChanged(true); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1689 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1690 | return stack; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 1693 | void moveStackToDisplay(TaskStack stack, boolean onTop) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1694 | final DisplayContent prevDc = stack.getDisplayContent(); |
| 1695 | if (prevDc == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1696 | throw new IllegalStateException("Trying to move stackId=" + stack.mStackId |
| 1697 | + " which is not currently attached to any display"); |
| 1698 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1699 | if (prevDc.getDisplayId() == mDisplayId) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1700 | throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId |
| 1701 | + " to its current displayId=" + mDisplayId); |
| 1702 | } |
| 1703 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1704 | prevDc.mTaskStackContainers.removeStackFromDisplay(stack); |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 1705 | mTaskStackContainers.addStackToDisplay(stack, onTop); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 1706 | } |
| 1707 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1708 | @Override |
| 1709 | protected void addChild(DisplayChildWindowContainer child, |
| 1710 | Comparator<DisplayChildWindowContainer> comparator) { |
| 1711 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 1712 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1713 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1714 | @Override |
| 1715 | protected void addChild(DisplayChildWindowContainer child, int index) { |
| 1716 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
| 1717 | } |
| 1718 | |
| 1719 | @Override |
| 1720 | protected void removeChild(DisplayChildWindowContainer child) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 1721 | // Only allow removal of direct children from this display if the display is in the process |
| 1722 | // of been removed. |
| 1723 | if (mRemovingDisplay) { |
| 1724 | super.removeChild(child); |
| 1725 | return; |
| 1726 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1727 | throw new UnsupportedOperationException("See DisplayChildWindowContainer"); |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 1730 | @Override |
| 1731 | void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) { |
| 1732 | // Children of the display are statically ordered, so the real intention here is to perform |
| 1733 | // the operation on the display and not the static direct children. |
| 1734 | getParent().positionChildAt(position, this, includingParents); |
| 1735 | } |
| 1736 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1737 | int taskIdFromPoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1738 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1739 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1740 | final int taskId = stack.taskIdFromPoint(x, y); |
| 1741 | if (taskId != -1) { |
| 1742 | return taskId; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1743 | } |
| 1744 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1745 | return -1; |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 1748 | /** |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 1749 | * Find the task whose outside touch area (for resizing) (x, y) falls within. |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1750 | * Returns null if the touch doesn't fall into a resizing area. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 1751 | */ |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame] | 1752 | Task findTaskForResizePoint(int x, int y) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1753 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1754 | mTmpTaskForResizePointSearchResult.reset(); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1755 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1756 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1757 | if (!StackId.isTaskResizeAllowed(stack.mStackId)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1758 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 1759 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1760 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1761 | stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult); |
| 1762 | if (mTmpTaskForResizePointSearchResult.searchDone) { |
| 1763 | return mTmpTaskForResizePointSearchResult.taskForResize; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 1764 | } |
| 1765 | } |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1766 | return null; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1769 | void setTouchExcludeRegion(Task focusedTask) { |
David Stevens | ee9e277 | 2017-02-09 16:30:27 -0800 | [diff] [blame] | 1770 | // The provided task is the task on this display with focus, so if WindowManagerService's |
| 1771 | // focused app is not on this display, focusedTask will be null. |
| 1772 | if (focusedTask == null) { |
| 1773 | mTouchExcludeRegion.setEmpty(); |
| 1774 | } else { |
| 1775 | mTouchExcludeRegion.set(mBaseDisplayRect); |
| 1776 | final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics); |
| 1777 | mTmpRect2.setEmpty(); |
| 1778 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1779 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
| 1780 | stack.setTouchExcludeRegion( |
| 1781 | focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2); |
| 1782 | } |
| 1783 | // If we removed the focused task above, add it back and only leave its |
| 1784 | // outside touch area in the exclusion. TapDectector is not interested in |
| 1785 | // any touch inside the focused task itself. |
| 1786 | if (!mTmpRect2.isEmpty()) { |
| 1787 | mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION); |
| 1788 | } |
Chong Zhang | d8ceb85 | 2015-11-11 14:53:41 -0800 | [diff] [blame] | 1789 | } |
Filip Gruszczynski | 912d919 | 2015-12-01 16:14:04 -0800 | [diff] [blame] | 1790 | final WindowState inputMethod = mService.mInputMethodWindow; |
| 1791 | if (inputMethod != null && inputMethod.isVisibleLw()) { |
| 1792 | // If the input method is visible and the user is typing, we don't want these touch |
| 1793 | // events to be intercepted and used to change focus. This would likely cause a |
| 1794 | // disappearance of the input method. |
| 1795 | inputMethod.getTouchableRegion(mTmpRegion); |
| 1796 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 1797 | } |
Filip Gruszczynski | ecf6722 | 2015-12-11 15:16:36 -0800 | [diff] [blame] | 1798 | for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) { |
| 1799 | WindowState win = mTapExcludedWindows.get(i); |
| 1800 | win.getTouchableRegion(mTmpRegion); |
| 1801 | mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION); |
| 1802 | } |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 1803 | // TODO(multi-display): Support docked stacks on secondary displays. |
| 1804 | if (mDisplayId == DEFAULT_DISPLAY && getDockedStackLocked() != null) { |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 1805 | mDividerControllerLocked.getTouchRegion(mTmpRect); |
Jorim Jaggi | 7f19cb8 | 2016-03-25 19:37:44 -0700 | [diff] [blame] | 1806 | mTmpRegion.set(mTmpRect); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 1807 | mTouchExcludeRegion.op(mTmpRegion, Op.UNION); |
| 1808 | } |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 1809 | if (mTapDetector != null) { |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 1810 | mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion); |
Craig Mautner | 1bef389 | 2015-02-17 15:09:47 -0800 | [diff] [blame] | 1811 | } |
Craig Mautner | 6601b7b | 2013-04-29 10:29:11 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1814 | @Override |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 1815 | void switchUser() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1816 | super.switchUser(); |
| 1817 | mService.mWindowsChanged = true; |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 1820 | private void resetAnimationBackgroundAnimator() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1821 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1822 | mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | boolean animateDimLayers() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1827 | return mDimLayerController.animateDimLayers(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1830 | private void resetDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1831 | mDimLayerController.resetDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | boolean isDimming() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1835 | return mDimLayerController.isDimming(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 1838 | private void stopDimmingIfNeeded() { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1839 | mDimLayerController.stopDimmingIfNeeded(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1842 | @Override |
| 1843 | void removeIfPossible() { |
| 1844 | if (isAnimating()) { |
| 1845 | mDeferredRemoval = true; |
| 1846 | return; |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 1847 | } |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1848 | removeImmediately(); |
Craig Mautner | 2eb1534 | 2013-08-07 13:13:35 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1851 | @Override |
| 1852 | void removeImmediately() { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 1853 | mRemovingDisplay = true; |
| 1854 | try { |
| 1855 | super.removeImmediately(); |
| 1856 | if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); |
| 1857 | mDimLayerController.close(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1858 | if (mDisplayId == DEFAULT_DISPLAY && mService.canDispatchPointerEvents()) { |
Wale Ogunwale | 601a3f0 | 2016-10-17 08:39:39 -0700 | [diff] [blame] | 1859 | mService.unregisterPointerEventListener(mTapDetector); |
| 1860 | mService.unregisterPointerEventListener(mService.mMousePositionTracker); |
| 1861 | } |
| 1862 | } finally { |
| 1863 | mRemovingDisplay = false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 1864 | } |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1867 | /** Returns true if a removal action is still being deferred. */ |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1868 | @Override |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1869 | boolean checkCompleteDeferredRemoval() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1870 | final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval(); |
| 1871 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1872 | if (!stillDeferringRemoval && mDeferredRemoval) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1873 | removeImmediately(); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 1874 | mService.onDisplayRemoved(mDisplayId); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1875 | return false; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 1876 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1877 | return true; |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 1878 | } |
| 1879 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1880 | boolean animateForIme(float interpolatedValue, float animationTarget, |
| 1881 | float dividerAnimationTarget) { |
| 1882 | boolean updated = false; |
| 1883 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1884 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1885 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1886 | if (stack == null || !stack.isAdjustedForIme()) { |
| 1887 | continue; |
| 1888 | } |
| 1889 | |
| 1890 | if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) { |
| 1891 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 1892 | updated = true; |
| 1893 | } else { |
| 1894 | mDividerControllerLocked.mLastAnimationProgress = |
| 1895 | mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue); |
| 1896 | mDividerControllerLocked.mLastDividerProgress = |
| 1897 | mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue); |
| 1898 | updated |= stack.updateAdjustForIme( |
| 1899 | mDividerControllerLocked.mLastAnimationProgress, |
| 1900 | mDividerControllerLocked.mLastDividerProgress, |
| 1901 | false /* force */); |
| 1902 | } |
| 1903 | if (interpolatedValue >= 1f) { |
| 1904 | stack.endImeAdjustAnimation(); |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | return updated; |
| 1909 | } |
| 1910 | |
| 1911 | boolean clearImeAdjustAnimation() { |
| 1912 | boolean changed = false; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1913 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1914 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1915 | if (stack != null && stack.isAdjustedForIme()) { |
| 1916 | stack.resetAdjustedForIme(true /* adjustBoundsNow */); |
| 1917 | changed = true; |
| 1918 | } |
| 1919 | } |
| 1920 | return changed; |
| 1921 | } |
| 1922 | |
| 1923 | void beginImeAdjustAnimation() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1924 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1925 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1926 | if (stack.isVisible() && stack.isAdjustedForIme()) { |
| 1927 | stack.beginImeAdjustAnimation(); |
| 1928 | } |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | void adjustForImeIfNeeded() { |
| 1933 | final WindowState imeWin = mService.mInputMethodWindow; |
| 1934 | final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw() |
| 1935 | && !mDividerControllerLocked.isImeHideRequested(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 1936 | final boolean dockVisible = isStackVisible(DOCKED_STACK_ID); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1937 | final TaskStack imeTargetStack = mService.getImeFocusStackLocked(); |
| 1938 | final int imeDockSide = (dockVisible && imeTargetStack != null) ? |
| 1939 | imeTargetStack.getDockSide() : DOCKED_INVALID; |
| 1940 | final boolean imeOnTop = (imeDockSide == DOCKED_TOP); |
| 1941 | final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM); |
| 1942 | final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock(); |
| 1943 | final int imeHeight = mService.mPolicy.getInputMethodWindowVisibleHeightLw(); |
| 1944 | final boolean imeHeightChanged = imeVisible && |
| 1945 | imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor(); |
| 1946 | |
| 1947 | // The divider could be adjusted for IME position, or be thinner than usual, |
| 1948 | // or both. There are three possible cases: |
| 1949 | // - If IME is visible, and focus is on top, divider is not moved for IME but thinner. |
| 1950 | // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner. |
| 1951 | // - If IME is not visible, divider is not moved and is normal width. |
| 1952 | |
| 1953 | if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1954 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1955 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1956 | final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM; |
Winson Chung | fef058d | 2017-04-25 14:43:10 -0700 | [diff] [blame] | 1957 | if (stack.isVisible() && (imeOnBottom || isDockedOnBottom) && |
| 1958 | StackId.isStackAffectedByDragResizing(stack.mStackId)) { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1959 | stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged); |
| 1960 | } else { |
| 1961 | stack.resetAdjustedForIme(false); |
| 1962 | } |
| 1963 | } |
| 1964 | mDividerControllerLocked.setAdjustedForIme( |
| 1965 | imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight); |
| 1966 | } else { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1967 | for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) { |
| 1968 | final TaskStack stack = mTaskStackContainers.get(i); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1969 | stack.resetAdjustedForIme(!dockVisible); |
| 1970 | } |
| 1971 | mDividerControllerLocked.setAdjustedForIme( |
| 1972 | false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight); |
| 1973 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1974 | mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 1977 | void setInputMethodAnimLayerAdjustment(int adj) { |
| 1978 | if (DEBUG_LAYERS) Slog.v(TAG_WM, "Setting im layer adj to " + adj); |
| 1979 | mInputMethodAnimLayerAdjustment = adj; |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 1980 | assignWindowLayers(false /* relayoutNeeded */); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1983 | /** |
| 1984 | * If a window that has an animation specifying a colored background and the current wallpaper |
| 1985 | * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to |
| 1986 | * suddenly disappear. |
| 1987 | */ |
| 1988 | int getLayerForAnimationBackground(WindowStateAnimator winAnimator) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1989 | final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow( |
| 1990 | w -> w.mIsWallpaper && w.isVisibleNow()); |
| 1991 | |
| 1992 | if (visibleWallpaper != null) { |
| 1993 | return visibleWallpaper.mWinAnimator.mAnimLayer; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1994 | } |
| 1995 | return winAnimator.mAnimLayer; |
| 1996 | } |
| 1997 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 1998 | void prepareFreezingTaskBounds() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 1999 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2000 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 2001 | stack.prepareFreezingTaskBounds(); |
| 2002 | } |
| 2003 | } |
| 2004 | |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2005 | void rotateBounds(int oldRotation, int newRotation, Rect bounds) { |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2006 | getLogicalDisplayRect(mTmpRect, newRotation); |
| 2007 | |
| 2008 | // Compute a transform matrix to undo the coordinate space transformation, |
| 2009 | // and present the window at the same physical position it previously occupied. |
| 2010 | final int deltaRotation = deltaRotation(newRotation, oldRotation); |
| 2011 | createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix); |
| 2012 | |
| 2013 | mTmpRectF.set(bounds); |
| 2014 | mTmpMatrix.mapRect(mTmpRectF); |
| 2015 | mTmpRectF.round(bounds); |
Wale Ogunwale | 9474421 | 2015-09-21 19:01:47 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
Wale Ogunwale | 4a02d81 | 2015-02-12 23:01:38 -0800 | [diff] [blame] | 2018 | static int deltaRotation(int oldRotation, int newRotation) { |
| 2019 | int delta = newRotation - oldRotation; |
| 2020 | if (delta < 0) delta += 4; |
| 2021 | return delta; |
| 2022 | } |
| 2023 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2024 | private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight, |
Andrii Kulian | 4dfb9c4 | 2016-10-11 20:06:27 -0700 | [diff] [blame] | 2025 | Matrix outMatrix) { |
| 2026 | // For rotations without Z-ordering we don't need the target rectangle's position. |
| 2027 | createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth, |
| 2028 | displayHeight, outMatrix); |
| 2029 | } |
| 2030 | |
| 2031 | static void createRotationMatrix(int rotation, float rectLeft, float rectTop, |
| 2032 | float displayWidth, float displayHeight, Matrix outMatrix) { |
| 2033 | switch (rotation) { |
| 2034 | case ROTATION_0: |
| 2035 | outMatrix.reset(); |
| 2036 | break; |
| 2037 | case ROTATION_270: |
| 2038 | outMatrix.setRotate(270, 0, 0); |
| 2039 | outMatrix.postTranslate(0, displayHeight); |
| 2040 | outMatrix.postTranslate(rectTop, 0); |
| 2041 | break; |
| 2042 | case ROTATION_180: |
| 2043 | outMatrix.reset(); |
| 2044 | break; |
| 2045 | case ROTATION_90: |
| 2046 | outMatrix.setRotate(90, 0, 0); |
| 2047 | outMatrix.postTranslate(displayWidth, 0); |
| 2048 | outMatrix.postTranslate(-rectTop, rectLeft); |
| 2049 | break; |
| 2050 | } |
| 2051 | } |
| 2052 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2053 | public void dump(String prefix, PrintWriter pw) { |
| 2054 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 2055 | final String subPrefix = " " + prefix; |
| 2056 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 2057 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 2058 | pw.print("dpi"); |
| 2059 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 2060 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 2061 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 2062 | pw.print(" base="); |
| 2063 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 2064 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 2065 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 2066 | if (mDisplayScalingDisabled) { |
| 2067 | pw.println(" noscale"); |
| 2068 | } |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 2069 | pw.print(" cur="); |
| 2070 | pw.print(mDisplayInfo.logicalWidth); |
| 2071 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 2072 | pw.print(" app="); |
| 2073 | pw.print(mDisplayInfo.appWidth); |
| 2074 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 2075 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 2076 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 2077 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 2078 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 2079 | pw.println(subPrefix + "deferred=" + mDeferredRemoval |
| 2080 | + " mLayoutNeeded=" + mLayoutNeeded); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2081 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2082 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2083 | pw.println(prefix + "Application tokens in top down Z order:"); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2084 | for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2085 | final TaskStack stack = mTaskStackContainers.get(stackNdx); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2086 | stack.dump(prefix + " ", pw); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2087 | } |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2088 | |
Craig Mautner | dc54848 | 2014-02-05 13:35:24 -0800 | [diff] [blame] | 2089 | pw.println(); |
| 2090 | if (!mExitingTokens.isEmpty()) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2091 | pw.println(); |
| 2092 | pw.println(" Exiting tokens:"); |
Wale Ogunwale | b429e68 | 2016-01-06 12:36:34 -0800 | [diff] [blame] | 2093 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2094 | final WindowToken token = mExitingTokens.get(i); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2095 | pw.print(" Exiting #"); pw.print(i); |
| 2096 | pw.print(' '); pw.print(token); |
| 2097 | pw.println(':'); |
| 2098 | token.dump(pw, " "); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2099 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2100 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2101 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2102 | mDimLayerController.dump(prefix, pw); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 2103 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2104 | mDividerControllerLocked.dump(prefix, pw); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 2105 | pw.println(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 2106 | mPinnedStackControllerLocked.dump(prefix, pw); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2107 | |
| 2108 | if (mInputMethodAnimLayerAdjustment != 0) { |
| 2109 | pw.println(subPrefix |
| 2110 | + "mInputMethodAnimLayerAdjustment=" + mInputMethodAnimLayerAdjustment); |
| 2111 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2112 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2113 | |
| 2114 | @Override |
| 2115 | public String toString() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2116 | return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren; |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | String getName() { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2120 | return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\""; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2121 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2122 | |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 2123 | /** Checks if stack with provided id is visible on this display. */ |
| 2124 | boolean isStackVisible(int stackId) { |
| 2125 | final TaskStack stack = getStackById(stackId); |
| 2126 | return (stack != null && stack.isVisible()); |
| 2127 | } |
| 2128 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 2129 | /** |
| 2130 | * @return The docked stack, but only if it is visible, and {@code null} otherwise. |
| 2131 | */ |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 2132 | TaskStack getDockedStackLocked() { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2133 | final TaskStack stack = getStackById(DOCKED_STACK_ID); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2134 | return (stack != null && stack.isVisible()) ? stack : null; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 2135 | } |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2136 | |
| 2137 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 2138 | * Like {@link #getDockedStackLocked}, but also returns the docked stack if it's currently not |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2139 | * visible. |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 2140 | */ |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2141 | TaskStack getDockedStackIgnoringVisibility() { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2142 | return getStackById(DOCKED_STACK_ID); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 2143 | } |
| 2144 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2145 | /** Find the visible, touch-deliverable window under the given point */ |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2146 | WindowState getTouchableWinAtPointLocked(float xf, float yf) { |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2147 | final int x = (int) xf; |
| 2148 | final int y = (int) yf; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2149 | final WindowState touchedWin = getWindow(w -> { |
| 2150 | final int flags = w.mAttrs.flags; |
| 2151 | if (!w.isVisibleLw()) { |
| 2152 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2153 | } |
| 2154 | if ((flags & FLAG_NOT_TOUCHABLE) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2155 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2156 | } |
| 2157 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2158 | w.getVisibleBounds(mTmpRect); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2159 | if (!mTmpRect.contains(x, y)) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2160 | return false; |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2161 | } |
| 2162 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2163 | w.getTouchableRegion(mTmpRegion); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2164 | |
| 2165 | final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2166 | return mTmpRegion.contains(x, y) || touchFlags == 0; |
| 2167 | }); |
Vladislav Kaznacheev | 5d6bdeb | 2016-02-12 17:07:20 -0800 | [diff] [blame] | 2168 | |
| 2169 | return touchedWin; |
| 2170 | } |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 2171 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2172 | boolean canAddToastWindowForUid(int uid) { |
| 2173 | // We allow one toast window per UID being shown at a time. |
Svet Ganov | daca8ee | 2017-01-21 17:40:40 -0800 | [diff] [blame] | 2174 | // Also if the app is focused adding more than one toast at |
| 2175 | // a time for better backwards compatibility. |
| 2176 | final WindowState focusedWindowForUid = getWindow(w -> |
| 2177 | w.mOwnerUid == uid && w.isFocused()); |
| 2178 | if (focusedWindowForUid != null) { |
| 2179 | return true; |
| 2180 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2181 | final WindowState win = getWindow(w -> |
| 2182 | w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden |
| 2183 | && !w.mWindowRemovalAllowed); |
| 2184 | return win == null; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2187 | void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) { |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2188 | if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) { |
| 2189 | return; |
| 2190 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2191 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2192 | // Used to communicate the old focus to the callback method. |
| 2193 | mTmpWindow = oldFocus; |
| 2194 | |
| 2195 | forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2196 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2197 | |
| 2198 | WindowState findFocusedWindow() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2199 | mTmpWindow = null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2200 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2201 | forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2202 | |
| 2203 | if (mTmpWindow == null) { |
| 2204 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows."); |
| 2205 | return null; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 2206 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2207 | return mTmpWindow; |
Wale Ogunwale | ec73115 | 2016-09-08 20:18:57 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2210 | /** Updates the layer assignment of windows on this display. */ |
| 2211 | void assignWindowLayers(boolean setLayoutNeeded) { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 2212 | mLayersController.assignWindowLayers(this); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2213 | if (setLayoutNeeded) { |
| 2214 | setLayoutNeeded(); |
| 2215 | } |
| 2216 | } |
| 2217 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2218 | // TODO: This should probably be called any time a visual change is made to the hierarchy like |
| 2219 | // moving containers or resizing them. Need to investigate the best way to have it automatically |
| 2220 | // happen so we don't run into issues with programmers forgetting to do it. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2221 | void layoutAndAssignWindowLayersIfNeeded() { |
| 2222 | mService.mWindowsChanged = true; |
| 2223 | setLayoutNeeded(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2224 | |
| 2225 | if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2226 | false /*updateInputWindows*/)) { |
| 2227 | assignWindowLayers(false /* setLayoutNeeded */); |
| 2228 | } |
| 2229 | |
| 2230 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2231 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 2232 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 2233 | } |
| 2234 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2235 | /** Returns true if a leaked surface was destroyed */ |
| 2236 | boolean destroyLeakedSurfaces() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2237 | // Used to indicate that a surface was leaked. |
| 2238 | mTmpWindow = null; |
| 2239 | forAllWindows(w -> { |
| 2240 | final WindowStateAnimator wsa = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2241 | if (wsa.mSurfaceController == null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2242 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2243 | } |
| 2244 | if (!mService.mSessions.contains(wsa.mSession)) { |
| 2245 | Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2246 | + w + " surface=" + wsa.mSurfaceController |
| 2247 | + " token=" + w.mToken |
| 2248 | + " pid=" + w.mSession.mPid |
| 2249 | + " uid=" + w.mSession.mUid); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2250 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2251 | mService.mForceRemoves.add(w); |
| 2252 | mTmpWindow = w; |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2253 | } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2254 | Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2255 | + w + " surface=" + wsa.mSurfaceController |
| 2256 | + " token=" + w.mAppToken |
| 2257 | + " saved=" + w.hasSavedSurface()); |
| 2258 | if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2259 | wsa.destroySurface(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2260 | mTmpWindow = w; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2261 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2262 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2263 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2264 | return mTmpWindow != null; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | /** |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2268 | * Determine and return the window that should be the IME target. |
| 2269 | * @param updateImeTarget If true the system IME target will be updated to match what we found. |
| 2270 | * @return The window that should be used as the IME target or null if there isn't any. |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2271 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2272 | WindowState computeImeTarget(boolean updateImeTarget) { |
| 2273 | if (mService.mInputMethodWindow == null) { |
| 2274 | // There isn't an IME so there shouldn't be a target...That was easy! |
| 2275 | if (updateImeTarget) { |
| 2276 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " |
| 2277 | + mService.mInputMethodTarget + " to null since mInputMethodWindow is null"); |
| 2278 | setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0); |
| 2279 | } |
| 2280 | return null; |
| 2281 | } |
| 2282 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2283 | // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the |
| 2284 | // same display. Or even when the current IME/target are not on the same screen as the next |
| 2285 | // IME/target. For now only look for input windows on the main screen. |
Wale Ogunwale | 8e44f6c | 2017-03-09 15:25:10 -0800 | [diff] [blame] | 2286 | mUpdateImeTarget = updateImeTarget; |
| 2287 | WindowState target = getWindow(mComputeImeTargetPredicate); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2288 | |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2289 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2290 | // Yet more tricksyness! If this window is a "starting" window, we do actually want |
| 2291 | // to be on top of it, but it is not -really- where input will go. So look down below |
| 2292 | // for a real window to target... |
| 2293 | if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2294 | final AppWindowToken token = target.mAppToken; |
| 2295 | if (token != null) { |
| 2296 | final WindowState betterTarget = token.getImeTargetBelowWindow(target); |
| 2297 | if (betterTarget != null) { |
| 2298 | target = betterTarget; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2299 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2303 | if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM, |
| 2304 | "Proposed new IME target: " + target); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2305 | |
| 2306 | // Now, a special case -- if the last target's window is in the process of exiting, and is |
| 2307 | // above the new target, keep on the last target to avoid flicker. Consider for example a |
| 2308 | // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it |
| 2309 | // until it is completely gone so it doesn't drop behind the dialog or its full-screen |
| 2310 | // scrim. |
| 2311 | final WindowState curTarget = mService.mInputMethodTarget; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2312 | if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing() |
| 2313 | && (target == null |
| 2314 | || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2315 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing"); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2316 | return curTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2319 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target |
| 2320 | + " updateImeTarget=" + updateImeTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2321 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2322 | if (target == null) { |
| 2323 | if (updateImeTarget) { |
| 2324 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget |
| 2325 | + " to null." + (SHOW_STACK_CRAWLS ? " Callers=" |
| 2326 | + Debug.getCallers(4) : "")); |
| 2327 | setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim, 0); |
| 2328 | } |
| 2329 | |
| 2330 | return null; |
| 2331 | } |
| 2332 | |
| 2333 | if (updateImeTarget) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2334 | AppWindowToken token = curTarget == null ? null : curTarget.mAppToken; |
| 2335 | if (token != null) { |
| 2336 | |
| 2337 | // Now some fun for dealing with window animations that modify the Z order. We need |
| 2338 | // to look at all windows below the current target that are in this app, finding the |
| 2339 | // highest visible one in layering. |
| 2340 | WindowState highestTarget = null; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2341 | if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2342 | highestTarget = token.getHighestAnimLayerWindow(curTarget); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | if (highestTarget != null) { |
| 2346 | final AppTransition appTransition = mService.mAppTransition; |
| 2347 | if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget |
| 2348 | + " animating=" + highestTarget.mWinAnimator.isAnimationSet() |
| 2349 | + " layer=" + highestTarget.mWinAnimator.mAnimLayer |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2350 | + " new layer=" + target.mWinAnimator.mAnimLayer); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2351 | |
| 2352 | if (appTransition.isTransitionSet()) { |
| 2353 | // If we are currently setting up for an animation, hold everything until we |
| 2354 | // can find out what will happen. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2355 | setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment); |
| 2356 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2357 | } else if (highestTarget.mWinAnimator.isAnimationSet() && |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2358 | highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2359 | // If the window we are currently targeting is involved with an animation, |
| 2360 | // and it is on top of the next target we will be over, then hold off on |
| 2361 | // moving until that is done. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2362 | setInputMethodTarget(highestTarget, true, mInputMethodAnimLayerAdjustment); |
| 2363 | return highestTarget; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2364 | } |
| 2365 | } |
| 2366 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2367 | |
| 2368 | if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to " |
| 2369 | + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : "")); |
| 2370 | setInputMethodTarget(target, false, target.mAppToken != null |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 2371 | ? target.mAppToken.getAnimLayerAdjustment() : 0); |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2374 | return target; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2377 | private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim, int layerAdj) { |
| 2378 | if (target == mService.mInputMethodTarget |
| 2379 | && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim |
| 2380 | && mInputMethodAnimLayerAdjustment == layerAdj) { |
| 2381 | return; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2384 | mService.mInputMethodTarget = target; |
| 2385 | mService.mInputMethodTargetWaitingAnim = targetWaitingAnim; |
| 2386 | setInputMethodAnimLayerAdjustment(layerAdj); |
| 2387 | assignWindowLayers(false /* setLayoutNeeded */); |
| 2388 | } |
| 2389 | |
| 2390 | boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) { |
| 2391 | if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 2392 | return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
| 2393 | } |
| 2394 | |
| 2395 | // Used to indicate we have reached the first window in the range we are interested in. |
| 2396 | mTmpWindow = null; |
| 2397 | |
| 2398 | // TODO: Figure-out a more efficient way to do this. |
| 2399 | final WindowState candidate = getWindow(w -> { |
| 2400 | if (w == top) { |
| 2401 | // Reached the first window in the range we are interested in. |
| 2402 | mTmpWindow = w; |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2403 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2404 | if (mTmpWindow == null) { |
| 2405 | return false; |
| 2406 | } |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2407 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2408 | if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) { |
| 2409 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2410 | } |
| 2411 | // If we reached the bottom of the range of windows we are considering, |
| 2412 | // assume no menu is needed. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2413 | if (w == bottom) { |
| 2414 | return true; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2415 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2416 | return false; |
| 2417 | }); |
| 2418 | |
| 2419 | return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE; |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 2422 | void setLayoutNeeded() { |
| 2423 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 2424 | mLayoutNeeded = true; |
| 2425 | } |
| 2426 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2427 | private void clearLayoutNeeded() { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 2428 | if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3)); |
| 2429 | mLayoutNeeded = false; |
| 2430 | } |
| 2431 | |
| 2432 | boolean isLayoutNeeded() { |
| 2433 | return mLayoutNeeded; |
| 2434 | } |
| 2435 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 2436 | void dumpTokens(PrintWriter pw, boolean dumpAll) { |
| 2437 | if (mTokenMap.isEmpty()) { |
| 2438 | return; |
| 2439 | } |
| 2440 | pw.println(" Display #" + mDisplayId); |
| 2441 | final Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 2442 | while (it.hasNext()) { |
| 2443 | final WindowToken token = it.next(); |
| 2444 | pw.print(" "); |
| 2445 | pw.print(token); |
| 2446 | if (dumpAll) { |
| 2447 | pw.println(':'); |
| 2448 | token.dump(pw, " "); |
| 2449 | } else { |
| 2450 | pw.println(); |
| 2451 | } |
| 2452 | } |
| 2453 | } |
| 2454 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2455 | void dumpWindowAnimators(PrintWriter pw, String subPrefix) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2456 | final int[] index = new int[1]; |
| 2457 | forAllWindows(w -> { |
| 2458 | final WindowStateAnimator wAnim = w.mWinAnimator; |
| 2459 | pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim); |
| 2460 | index[0] = index[0] + 1; |
| 2461 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2464 | void enableSurfaceTrace(FileDescriptor fd) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2465 | forAllWindows(w -> { |
| 2466 | w.mWinAnimator.enableSurfaceTrace(fd); |
| 2467 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | void disableSurfaceTrace() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2471 | forAllWindows(w -> { |
| 2472 | w.mWinAnimator.disableSurfaceTrace(); |
| 2473 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2476 | /** |
| 2477 | * Starts the Keyguard exit animation on all windows that don't belong to an app token. |
| 2478 | */ |
| 2479 | void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) { |
| 2480 | final WindowManagerPolicy policy = mService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2481 | forAllWindows(w -> { |
| 2482 | if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)) { |
| 2483 | w.mWinAnimator.setAnimation( |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2484 | policy.createHiddenByKeyguardExit(onWallpaper, goingToShade)); |
| 2485 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2486 | }, true /* traverseTopToBottom */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2487 | } |
| 2488 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2489 | boolean checkWaitingForWindows() { |
| 2490 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2491 | mHaveBootMsg = false; |
| 2492 | mHaveApp = false; |
| 2493 | mHaveWallpaper = false; |
| 2494 | mHaveKeyguard = true; |
| 2495 | |
| 2496 | final WindowState visibleWindow = getWindow(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2497 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| 2498 | return true; |
| 2499 | } |
| 2500 | if (w.isDrawnLw()) { |
| 2501 | if (w.mAttrs.type == TYPE_BOOT_PROGRESS) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2502 | mHaveBootMsg = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2503 | } else if (w.mAttrs.type == TYPE_APPLICATION |
| 2504 | || w.mAttrs.type == TYPE_DRAWN_APPLICATION) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2505 | mHaveApp = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2506 | } else if (w.mAttrs.type == TYPE_WALLPAPER) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2507 | mHaveWallpaper = true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2508 | } else if (w.mAttrs.type == TYPE_STATUS_BAR) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2509 | mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw(); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2510 | } |
| 2511 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2512 | return false; |
| 2513 | }); |
| 2514 | |
| 2515 | if (visibleWindow != null) { |
| 2516 | // We have a visible window. |
| 2517 | return true; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2520 | // if the wallpaper service is disabled on the device, we're never going to have |
| 2521 | // wallpaper, don't bother waiting for it |
| 2522 | boolean wallpaperEnabled = mService.mContext.getResources().getBoolean( |
| 2523 | com.android.internal.R.bool.config_enableWallpaperService) |
| 2524 | && !mService.mOnlyCore; |
| 2525 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2526 | if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM, |
| 2527 | "******** booted=" + mService.mSystemBooted |
| 2528 | + " msg=" + mService.mShowingBootMessages |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2529 | + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp |
| 2530 | + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled |
| 2531 | + " haveKeyguard=" + mHaveKeyguard); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2532 | |
| 2533 | // If we are turning on the screen to show the boot message, don't do it until the boot |
| 2534 | // message is actually displayed. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2535 | if (!mService.mSystemBooted && !mHaveBootMsg) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2536 | return true; |
| 2537 | } |
| 2538 | |
| 2539 | // If we are turning on the screen after the boot is completed normally, don't do so until |
| 2540 | // we have the application and wallpaper. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2541 | if (mService.mSystemBooted |
| 2542 | && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2543 | return true; |
| 2544 | } |
| 2545 | |
| 2546 | return false; |
| 2547 | } |
| 2548 | |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2549 | void updateWindowsForAnimator(WindowAnimator animator) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2550 | mTmpWindowAnimator = animator; |
| 2551 | forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | void updateWallpaperForAnimator(WindowAnimator animator) { |
Jorim Jaggi | 7156b65 | 2016-10-25 08:31:58 -0700 | [diff] [blame] | 2555 | resetAnimationBackgroundAnimator(); |
| 2556 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2557 | // Used to indicate a detached wallpaper. |
| 2558 | mTmpWindow = null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2559 | mTmpWindowAnimator = animator; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2560 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2561 | forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2562 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2563 | if (animator.mWindowDetachedWallpaper != mTmpWindow) { |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2564 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from " |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2565 | + animator.mWindowDetachedWallpaper + " to " + mTmpWindow); |
| 2566 | animator.mWindowDetachedWallpaper = mTmpWindow; |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2567 | animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE; |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | void prepareWindowSurfaces() { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2572 | forAllWindows(mPrepareWindowSurfaces, false /* traverseTopToBottom */); |
Wale Ogunwale | 824ab5c | 2016-10-20 09:31:56 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2575 | boolean inputMethodClientHasFocus(IInputMethodClient client) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2576 | final WindowState imFocus = computeImeTarget(false /* updateImeTarget */); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2577 | if (imFocus == null) { |
| 2578 | return false; |
| 2579 | } |
| 2580 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2581 | if (DEBUG_INPUT_METHOD) { |
| 2582 | Slog.i(TAG_WM, "Desired input method target: " + imFocus); |
| 2583 | Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus); |
| 2584 | Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus); |
Jorim Jaggi | ffa5a9d | 2016-11-23 16:59:19 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2587 | final IInputMethodClient imeClient = imFocus.mSession.mClient; |
| 2588 | |
| 2589 | if (DEBUG_INPUT_METHOD) { |
| 2590 | Slog.i(TAG_WM, "IM target client: " + imeClient); |
| 2591 | if (imeClient != null) { |
| 2592 | Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder()); |
| 2593 | Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder()); |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | return imeClient != null && imeClient.asBinder() == client.asBinder(); |
| 2598 | } |
| 2599 | |
| 2600 | boolean hasSecureWindowOnScreen() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2601 | final WindowState win = getWindow( |
| 2602 | w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0); |
| 2603 | return win != null; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | void updateSystemUiVisibility(int visibility, int globalDiff) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2607 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2608 | try { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2609 | final int curValue = w.mSystemUiVisibility; |
| 2610 | final int diff = (curValue ^ visibility) & globalDiff; |
| 2611 | final int newValue = (curValue & ~diff) | (visibility & diff); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2612 | if (newValue != curValue) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2613 | w.mSeq++; |
| 2614 | w.mSystemUiVisibility = newValue; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2615 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2616 | if (newValue != curValue || w.mAttrs.hasSystemUiListeners) { |
| 2617 | w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq, |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2618 | visibility, newValue, diff); |
| 2619 | } |
| 2620 | } catch (RemoteException e) { |
| 2621 | // so sorry |
| 2622 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2623 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | void onWindowFreezeTimeout() { |
| 2627 | Slog.w(TAG_WM, "Window freeze timeout expired."); |
| 2628 | mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2629 | |
| 2630 | forAllWindows(w -> { |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2631 | if (!w.mOrientationChanging) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2632 | return; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2633 | } |
| 2634 | w.mOrientationChanging = false; |
| 2635 | w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 2636 | - mService.mDisplayFreezeTime); |
| 2637 | Slog.w(TAG_WM, "Force clearing orientation change: " + w); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2638 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2639 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 2640 | } |
| 2641 | |
| 2642 | void waitForAllWindowsDrawn() { |
| 2643 | final WindowManagerPolicy policy = mService.mPolicy; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2644 | forAllWindows(w -> { |
| 2645 | final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs); |
| 2646 | if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) { |
| 2647 | w.mWinAnimator.mDrawState = DRAW_PENDING; |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2648 | // Force add to mResizingWindows. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2649 | w.mLastContentInsets.set(-1, -1, -1, -1); |
| 2650 | mService.mWaitingForDrawn.add(w); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2651 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2652 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | 494009b8 | 2016-10-21 09:01:38 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2655 | // TODO: Super crazy long method that should be broken down... |
| 2656 | boolean applySurfaceChangesTransaction(boolean recoveringMemory) { |
| 2657 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2658 | final int dw = mDisplayInfo.logicalWidth; |
| 2659 | final int dh = mDisplayInfo.logicalHeight; |
| 2660 | final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked; |
| 2661 | |
| 2662 | mTmpUpdateAllDrawn.clear(); |
| 2663 | |
| 2664 | int repeats = 0; |
| 2665 | do { |
| 2666 | repeats++; |
| 2667 | if (repeats > 6) { |
| 2668 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 2669 | clearLayoutNeeded(); |
| 2670 | break; |
| 2671 | } |
| 2672 | |
| 2673 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner", |
| 2674 | pendingLayoutChanges); |
| 2675 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2676 | // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid |
| 2677 | // the wallpaper window jumping across displays. |
| 2678 | // Remove check for default display when there will be support for multiple wallpaper |
| 2679 | // targets (on different displays). |
| 2680 | if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2681 | mWallpaperController.adjustWallpaperWindows(this); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 2685 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 2686 | if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) { |
| 2687 | setLayoutNeeded(); |
Andrii Kulian | b17e869 | 2016-11-01 10:37:22 -0700 | [diff] [blame] | 2688 | mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 2693 | setLayoutNeeded(); |
| 2694 | } |
| 2695 | |
| 2696 | // FIRST LOOP: Perform a layout, if needed. |
| 2697 | if (repeats < LAYOUT_REPEAT_THRESHOLD) { |
| 2698 | performLayout(repeats == 1, false /* updateInputWindows */); |
| 2699 | } else { |
| 2700 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 2701 | } |
| 2702 | |
| 2703 | // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating. |
| 2704 | pendingLayoutChanges = 0; |
| 2705 | |
| 2706 | if (isDefaultDisplay) { |
| 2707 | mService.mPolicy.beginPostLayoutPolicyLw(dw, dh); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2708 | forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2709 | pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw(); |
| 2710 | if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats( |
| 2711 | "after finishPostLayoutPolicyLw", pendingLayoutChanges); |
| 2712 | } |
| 2713 | } while (pendingLayoutChanges != 0); |
| 2714 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2715 | mTmpApplySurfaceChangesTransactionState.reset(); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2716 | resetDimming(); |
| 2717 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2718 | mTmpRecoveringMemory = recoveringMemory; |
| 2719 | forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2720 | |
| 2721 | mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId, |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2722 | mTmpApplySurfaceChangesTransactionState.displayHasContent, |
| 2723 | mTmpApplySurfaceChangesTransactionState.preferredRefreshRate, |
| 2724 | mTmpApplySurfaceChangesTransactionState.preferredModeId, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2725 | true /* inTraversal, must call performTraversalInTrans... below */); |
| 2726 | |
| 2727 | stopDimmingIfNeeded(); |
| 2728 | |
| 2729 | while (!mTmpUpdateAllDrawn.isEmpty()) { |
| 2730 | final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast(); |
| 2731 | // See if any windows have been drawn, so they (and others associated with them) |
| 2732 | // can now be shown. |
| 2733 | atoken.updateAllDrawn(this); |
| 2734 | } |
| 2735 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2736 | return mTmpApplySurfaceChangesTransactionState.focusDisplayed; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | void performLayout(boolean initial, boolean updateInputWindows) { |
| 2740 | if (!isLayoutNeeded()) { |
| 2741 | return; |
| 2742 | } |
| 2743 | clearLayoutNeeded(); |
| 2744 | |
| 2745 | final int dw = mDisplayInfo.logicalWidth; |
| 2746 | final int dh = mDisplayInfo.logicalHeight; |
| 2747 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2748 | if (DEBUG_LAYOUT) { |
| 2749 | Slog.v(TAG, "-------------------------------------"); |
| 2750 | Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh); |
| 2751 | } |
| 2752 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2753 | mService.mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mRotation, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2754 | getConfiguration().uiMode); |
| 2755 | if (isDefaultDisplay) { |
| 2756 | // Not needed on non-default displays. |
| 2757 | mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw(); |
| 2758 | mService.mScreenRect.set(0, 0, dw, dh); |
| 2759 | } |
| 2760 | |
| 2761 | mService.mPolicy.getContentRectLw(mContentRect); |
| 2762 | |
| 2763 | int seq = mService.mLayoutSeq + 1; |
| 2764 | if (seq < 0) seq = 0; |
| 2765 | mService.mLayoutSeq = seq; |
| 2766 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2767 | // Used to indicate that we have processed the dream window and all additional windows are |
| 2768 | // behind it. |
| 2769 | mTmpWindow = null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2770 | mTmpInitial = initial; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2771 | |
| 2772 | // First perform layout of any root windows (not attached to another window). |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2773 | forAllWindows(mPerformLayout, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2774 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2775 | // Used to indicate that we have processed the dream window and all additional attached |
| 2776 | // windows are behind it. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2777 | mTmpWindow2 = mTmpWindow; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2778 | mTmpWindow = null; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2779 | |
| 2780 | // Now perform layout of attached windows, which usually depend on the position of the |
| 2781 | // window they are attached to. XXX does not deal with windows that are attached to windows |
| 2782 | // that are themselves attached. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 2783 | forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2784 | |
| 2785 | // Window frames may have changed. Tell the input dispatcher about it. |
| 2786 | mService.mInputMonitor.layoutInputConsumers(dw, dh); |
| 2787 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2788 | if (updateInputWindows) { |
| 2789 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 2790 | } |
| 2791 | |
| 2792 | mService.mPolicy.finishLayoutLw(); |
| 2793 | mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER); |
| 2794 | } |
| 2795 | |
| 2796 | /** |
| 2797 | * Takes a snapshot of the display. In landscape mode this grabs the whole screen. |
| 2798 | * In portrait mode, it grabs the full screenshot. |
| 2799 | * |
| 2800 | * @param width the width of the target bitmap |
| 2801 | * @param height the height of the target bitmap |
| 2802 | * @param includeFullDisplay true if the screen should not be cropped before capture |
| 2803 | * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1 |
| 2804 | * @param config of the output bitmap |
| 2805 | * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2806 | * @param includeDecor whether to include window decors, like the status or navigation bar |
| 2807 | * background of the window |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2808 | */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2809 | Bitmap screenshotApplications(IBinder appToken, int width, int height, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2810 | boolean includeFullDisplay, float frameScale, Bitmap.Config config, |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 2811 | boolean wallpaperOnly, boolean includeDecor) { |
| 2812 | Bitmap bitmap = screenshotApplications(appToken, width, height, includeFullDisplay, |
| 2813 | frameScale, wallpaperOnly, includeDecor, SurfaceControl::screenshot); |
Jorim Jaggi | 9f9d61f | 2017-01-17 11:15:37 +0100 | [diff] [blame] | 2814 | if (bitmap == null) { |
| 2815 | return null; |
| 2816 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 2817 | |
| 2818 | if (DEBUG_SCREENSHOT) { |
| 2819 | // TEST IF IT's ALL BLACK |
| 2820 | int[] buffer = new int[bitmap.getWidth() * bitmap.getHeight()]; |
| 2821 | bitmap.getPixels(buffer, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), |
| 2822 | bitmap.getHeight()); |
| 2823 | boolean allBlack = true; |
| 2824 | final int firstColor = buffer[0]; |
| 2825 | for (int i = 0; i < buffer.length; i++) { |
| 2826 | if (buffer[i] != firstColor) { |
| 2827 | allBlack = false; |
| 2828 | break; |
| 2829 | } |
| 2830 | } |
| 2831 | if (allBlack) { |
| 2832 | final WindowState appWin = mScreenshotApplicationState.appWin; |
| 2833 | final int maxLayer = mScreenshotApplicationState.maxLayer; |
| 2834 | final int minLayer = mScreenshotApplicationState.minLayer; |
| 2835 | Slog.i(TAG_WM, "Screenshot " + appWin + " was monochrome(" + |
| 2836 | Integer.toHexString(firstColor) + ")! mSurfaceLayer=" + |
| 2837 | (appWin != null ? |
| 2838 | appWin.mWinAnimator.mSurfaceController.getLayer() : "null") + |
| 2839 | " minLayer=" + minLayer + " maxLayer=" + maxLayer); |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | // Create a copy of the screenshot that is immutable and backed in ashmem. |
| 2844 | // This greatly reduces the overhead of passing the bitmap between processes. |
| 2845 | Bitmap ret = bitmap.createAshmemBitmap(config); |
| 2846 | bitmap.recycle(); |
| 2847 | return ret; |
| 2848 | } |
| 2849 | |
| 2850 | GraphicBuffer screenshotApplicationsToBuffer(IBinder appToken, int width, int height, |
| 2851 | boolean includeFullDisplay, float frameScale, boolean wallpaperOnly, |
| 2852 | boolean includeDecor) { |
| 2853 | return screenshotApplications(appToken, width, height, includeFullDisplay, frameScale, |
| 2854 | wallpaperOnly, includeDecor, SurfaceControl::screenshotToBuffer); |
| 2855 | } |
| 2856 | |
| 2857 | private <E> E screenshotApplications(IBinder appToken, int width, int height, |
| 2858 | boolean includeFullDisplay, float frameScale, boolean wallpaperOnly, |
| 2859 | boolean includeDecor, Screenshoter<E> screenshoter) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2860 | int dw = mDisplayInfo.logicalWidth; |
| 2861 | int dh = mDisplayInfo.logicalHeight; |
| 2862 | if (dw == 0 || dh == 0) { |
| 2863 | if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken |
| 2864 | + ": returning null. logical widthxheight=" + dw + "x" + dh); |
| 2865 | return null; |
| 2866 | } |
| 2867 | |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 2868 | E bitmap; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2869 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2870 | mScreenshotApplicationState.reset(appToken == null && !wallpaperOnly); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2871 | final Rect frame = new Rect(); |
| 2872 | final Rect stackBounds = new Rect(); |
| 2873 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2874 | boolean includeImeInScreenshot; |
| 2875 | synchronized(mService.mWindowMap) { |
| 2876 | final AppWindowToken imeTargetAppToken = mService.mInputMethodTarget != null |
| 2877 | ? mService.mInputMethodTarget.mAppToken : null; |
| 2878 | // We only include the Ime in the screenshot if the app we are screenshoting is the IME |
| 2879 | // target and isn't in multi-window mode. We don't screenshot the IME in multi-window |
| 2880 | // mode because the frame of the IME might not overlap with that of the app. |
| 2881 | // E.g. IME target app at the top in split-screen mode and the IME at the bottom |
| 2882 | // overlapping with the bottom app. |
| 2883 | includeImeInScreenshot = imeTargetAppToken != null |
| 2884 | && imeTargetAppToken.appToken != null |
| 2885 | && imeTargetAppToken.appToken.asBinder() == appToken |
| 2886 | && !mService.mInputMethodTarget.isInMultiWindowMode(); |
| 2887 | } |
| 2888 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 2889 | final int aboveAppLayer = (mService.mPolicy.getWindowLayerFromTypeLw(TYPE_APPLICATION) + 1) |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2890 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2891 | final MutableBoolean mutableIncludeFullDisplay = new MutableBoolean(includeFullDisplay); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2892 | synchronized(mService.mWindowMap) { |
| 2893 | // Figure out the part of the screen that is actually the app. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2894 | mScreenshotApplicationState.appWin = null; |
| 2895 | forAllWindows(w -> { |
| 2896 | if (!w.mHasSurface) { |
| 2897 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2898 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2899 | if (w.mLayer >= aboveAppLayer) { |
| 2900 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2901 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2902 | if (wallpaperOnly && !w.mIsWallpaper) { |
| 2903 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2904 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2905 | if (w.mIsImWindow) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2906 | if (!includeImeInScreenshot) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2907 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2908 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2909 | } else if (w.mIsWallpaper) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2910 | // If this is the wallpaper layer and we're only looking for the wallpaper layer |
| 2911 | // then the target window state is this one. |
| 2912 | if (wallpaperOnly) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2913 | mScreenshotApplicationState.appWin = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2916 | if (mScreenshotApplicationState.appWin == null) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2917 | // We have not ran across the target window yet, so it is probably behind |
| 2918 | // the wallpaper. This can happen when the keyguard is up and all windows |
| 2919 | // are moved behind the wallpaper. We don't want to include the wallpaper |
| 2920 | // layer in the screenshot as it will cover-up the layer of the target |
| 2921 | // window. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2922 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2923 | } |
| 2924 | // Fall through. The target window is in front of the wallpaper. For this |
| 2925 | // case we want to include the wallpaper layer in the screenshot because |
| 2926 | // the target window might have some transparent areas. |
| 2927 | } else if (appToken != null) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2928 | if (w.mAppToken == null || w.mAppToken.token != appToken) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2929 | // This app window is of no interest if it is not associated with the |
| 2930 | // screenshot app. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2931 | return false; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2932 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2933 | mScreenshotApplicationState.appWin = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | // Include this window. |
| 2937 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2938 | final WindowStateAnimator winAnim = w.mWinAnimator; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2939 | int layer = winAnim.mSurfaceController.getLayer(); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2940 | if (mScreenshotApplicationState.maxLayer < layer) { |
| 2941 | mScreenshotApplicationState.maxLayer = layer; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2942 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2943 | if (mScreenshotApplicationState.minLayer > layer) { |
| 2944 | mScreenshotApplicationState.minLayer = layer; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | // Don't include wallpaper in bounds calculation |
Jorim Jaggi | bfbd9dc | 2017-01-20 18:13:01 +0100 | [diff] [blame] | 2948 | if (!mutableIncludeFullDisplay.value && includeDecor) { |
| 2949 | final TaskStack stack = w.getStack(); |
| 2950 | if (stack != null) { |
| 2951 | stack.getBounds(frame); |
| 2952 | } |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 2953 | |
| 2954 | // We want to screenshot with the exact bounds of the surface of the app. Thus, |
| 2955 | // intersect it with the frame. |
| 2956 | frame.intersect(w.mFrame); |
| 2957 | }else if (!mutableIncludeFullDisplay.value && !w.mIsWallpaper) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2958 | final Rect wf = w.mFrame; |
| 2959 | final Rect cr = w.mContentInsets; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2960 | int left = wf.left + cr.left; |
| 2961 | int top = wf.top + cr.top; |
| 2962 | int right = wf.right - cr.right; |
| 2963 | int bottom = wf.bottom - cr.bottom; |
| 2964 | frame.union(left, top, right, bottom); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2965 | w.getVisibleBounds(stackBounds); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2966 | if (!Rect.intersects(frame, stackBounds)) { |
| 2967 | // Set frame empty if there's no intersection. |
| 2968 | frame.setEmpty(); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | final boolean foundTargetWs = |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2973 | (w.mAppToken != null && w.mAppToken.token == appToken) |
| 2974 | || (mScreenshotApplicationState.appWin != null && wallpaperOnly); |
Jorim Jaggi | 52e85da | 2017-01-24 16:21:39 +0100 | [diff] [blame] | 2975 | if (foundTargetWs && winAnim.getShown()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2976 | mScreenshotApplicationState.screenshotReady = true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2979 | if (w.isObscuringDisplay()){ |
| 2980 | return true; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2981 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2982 | return false; |
| 2983 | }, true /* traverseTopToBottom */); |
| 2984 | |
| 2985 | final WindowState appWin = mScreenshotApplicationState.appWin; |
| 2986 | final boolean screenshotReady = mScreenshotApplicationState.screenshotReady; |
| 2987 | final int maxLayer = mScreenshotApplicationState.maxLayer; |
| 2988 | final int minLayer = mScreenshotApplicationState.minLayer; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 2989 | |
| 2990 | if (appToken != null && appWin == null) { |
| 2991 | // Can't find a window to snapshot. |
| 2992 | if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, |
| 2993 | "Screenshot: Couldn't find a surface matching " + appToken); |
| 2994 | return null; |
| 2995 | } |
| 2996 | |
| 2997 | if (!screenshotReady) { |
| 2998 | Slog.i(TAG_WM, "Failed to capture screenshot of " + appToken + |
| 2999 | " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" + |
| 3000 | appWin.mWinAnimator.mDrawState))); |
| 3001 | return null; |
| 3002 | } |
| 3003 | |
| 3004 | // Screenshot is ready to be taken. Everything from here below will continue |
| 3005 | // through the bottom of the loop and return a value. We only stay in the loop |
| 3006 | // because we don't want to release the mWindowMap lock until the screenshot is |
| 3007 | // taken. |
| 3008 | |
| 3009 | if (maxLayer == 0) { |
| 3010 | if (DEBUG_SCREENSHOT) Slog.i(TAG_WM, "Screenshot of " + appToken |
| 3011 | + ": returning null maxLayer=" + maxLayer); |
| 3012 | return null; |
| 3013 | } |
| 3014 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3015 | if (!mutableIncludeFullDisplay.value) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3016 | // Constrain frame to the screen size. |
| 3017 | if (!frame.intersect(0, 0, dw, dh)) { |
| 3018 | frame.setEmpty(); |
| 3019 | } |
| 3020 | } else { |
| 3021 | // Caller just wants entire display. |
| 3022 | frame.set(0, 0, dw, dh); |
| 3023 | } |
| 3024 | if (frame.isEmpty()) { |
| 3025 | return null; |
| 3026 | } |
| 3027 | |
| 3028 | if (width < 0) { |
| 3029 | width = (int) (frame.width() * frameScale); |
| 3030 | } |
| 3031 | if (height < 0) { |
| 3032 | height = (int) (frame.height() * frameScale); |
| 3033 | } |
| 3034 | |
| 3035 | // Tell surface flinger what part of the image to crop. Take the top |
| 3036 | // right part of the application, and crop the larger dimension to fit. |
| 3037 | Rect crop = new Rect(frame); |
| 3038 | if (width / (float) frame.width() < height / (float) frame.height()) { |
| 3039 | int cropWidth = (int)((float)width / (float)height * frame.height()); |
| 3040 | crop.right = crop.left + cropWidth; |
| 3041 | } else { |
| 3042 | int cropHeight = (int)((float)height / (float)width * frame.width()); |
| 3043 | crop.bottom = crop.top + cropHeight; |
| 3044 | } |
| 3045 | |
| 3046 | // The screenshot API does not apply the current screen rotation. |
| 3047 | int rot = mDisplay.getRotation(); |
| 3048 | |
| 3049 | if (rot == ROTATION_90 || rot == ROTATION_270) { |
| 3050 | rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90; |
| 3051 | } |
| 3052 | |
| 3053 | // Surfaceflinger is not aware of orientation, so convert our logical |
| 3054 | // crop to surfaceflinger's portrait orientation. |
| 3055 | convertCropForSurfaceFlinger(crop, rot, dw, dh); |
| 3056 | |
| 3057 | if (DEBUG_SCREENSHOT) { |
| 3058 | Slog.i(TAG_WM, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to " |
| 3059 | + maxLayer + " appToken=" + appToken); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3060 | forAllWindows(w -> { |
| 3061 | final WindowSurfaceController controller = w.mWinAnimator.mSurfaceController; |
| 3062 | Slog.i(TAG_WM, w + ": " + w.mLayer |
| 3063 | + " animLayer=" + w.mWinAnimator.mAnimLayer |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3064 | + " surfaceLayer=" + ((controller == null) |
| 3065 | ? "null" : controller.getLayer())); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3066 | }, false /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | final ScreenRotationAnimation screenRotationAnimation = |
| 3070 | mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY); |
| 3071 | final boolean inRotation = screenRotationAnimation != null && |
| 3072 | screenRotationAnimation.isAnimating(); |
| 3073 | if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, |
| 3074 | "Taking screenshot while rotating"); |
| 3075 | |
| 3076 | // We force pending transactions to flush before taking |
| 3077 | // the screenshot by pushing an empty synchronous transaction. |
| 3078 | SurfaceControl.openTransaction(); |
| 3079 | SurfaceControl.closeTransactionSync(); |
| 3080 | |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 3081 | bitmap = screenshoter.screenshot(crop, width, height, minLayer, maxLayer, |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3082 | inRotation, rot); |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 3083 | if (bitmap == null) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3084 | Slog.w(TAG_WM, "Screenshot failure taking screenshot for (" + dw + "x" + dh |
| 3085 | + ") to layer " + maxLayer); |
| 3086 | return null; |
| 3087 | } |
| 3088 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 3089 | return bitmap; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | // TODO: Can this use createRotationMatrix()? |
| 3093 | private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) { |
| 3094 | if (rot == Surface.ROTATION_90) { |
| 3095 | final int tmp = crop.top; |
| 3096 | crop.top = dw - crop.right; |
| 3097 | crop.right = crop.bottom; |
| 3098 | crop.bottom = dw - crop.left; |
| 3099 | crop.left = tmp; |
| 3100 | } else if (rot == Surface.ROTATION_180) { |
| 3101 | int tmp = crop.top; |
| 3102 | crop.top = dh - crop.bottom; |
| 3103 | crop.bottom = dh - tmp; |
| 3104 | tmp = crop.right; |
| 3105 | crop.right = dw - crop.left; |
| 3106 | crop.left = dw - tmp; |
| 3107 | } else if (rot == Surface.ROTATION_270) { |
| 3108 | final int tmp = crop.top; |
| 3109 | crop.top = crop.left; |
| 3110 | crop.left = dh - crop.bottom; |
| 3111 | crop.bottom = crop.right; |
| 3112 | crop.right = dh - tmp; |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | void onSeamlessRotationTimeout() { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3117 | // Used to indicate the layout is needed. |
| 3118 | mTmpWindow = null; |
| 3119 | |
| 3120 | forAllWindows(w -> { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3121 | if (!w.mSeamlesslyRotated) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3122 | return; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3123 | } |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3124 | mTmpWindow = w; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3125 | w.setDisplayLayoutNeeded(); |
| 3126 | mService.markForSeamlessRotation(w, false); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3127 | }, true /* traverseTopToBottom */); |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3128 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3129 | if (mTmpWindow != null) { |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 3130 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 3131 | } |
| 3132 | } |
| 3133 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3134 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 3135 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 3136 | mExitingTokens.get(i).hasVisible = hasVisible; |
| 3137 | } |
| 3138 | |
| 3139 | // Initialize state of exiting applications. |
| 3140 | mTaskStackContainers.setExitingTokensHasVisible(hasVisible); |
| 3141 | } |
| 3142 | |
| 3143 | void removeExistingTokensIfPossible() { |
| 3144 | for (int i = mExitingTokens.size() - 1; i >= 0; i--) { |
| 3145 | final WindowToken token = mExitingTokens.get(i); |
| 3146 | if (!token.hasVisible) { |
| 3147 | mExitingTokens.remove(i); |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | // Time to remove any exiting applications? |
| 3152 | mTaskStackContainers.removeExistingAppTokensIfPossible(); |
| 3153 | } |
| 3154 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3155 | @Override |
| 3156 | void onDescendantOverrideConfigurationChanged() { |
| 3157 | setLayoutNeeded(); |
| 3158 | mService.requestTraversal(); |
| 3159 | } |
| 3160 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 3161 | static final class TaskForResizePointSearchResult { |
| 3162 | boolean searchDone; |
| 3163 | Task taskForResize; |
| 3164 | |
| 3165 | void reset() { |
| 3166 | searchDone = false; |
| 3167 | taskForResize = null; |
| 3168 | } |
| 3169 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3170 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3171 | private static final class ApplySurfaceChangesTransactionState { |
| 3172 | boolean displayHasContent; |
| 3173 | boolean obscured; |
| 3174 | boolean syswin; |
| 3175 | boolean focusDisplayed; |
| 3176 | float preferredRefreshRate; |
| 3177 | int preferredModeId; |
| 3178 | |
| 3179 | void reset() { |
| 3180 | displayHasContent = false; |
| 3181 | obscured = false; |
| 3182 | syswin = false; |
| 3183 | focusDisplayed = false; |
| 3184 | preferredRefreshRate = 0; |
| 3185 | preferredModeId = 0; |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | private static final class ScreenshotApplicationState { |
| 3190 | WindowState appWin; |
| 3191 | int maxLayer; |
| 3192 | int minLayer; |
| 3193 | boolean screenshotReady; |
| 3194 | |
| 3195 | void reset(boolean screenshotReady) { |
| 3196 | appWin = null; |
| 3197 | maxLayer = 0; |
| 3198 | minLayer = 0; |
| 3199 | this.screenshotReady = screenshotReady; |
| 3200 | minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE; |
| 3201 | } |
| 3202 | } |
| 3203 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3204 | /** |
| 3205 | * Base class for any direct child window container of {@link #DisplayContent} need to inherit |
| 3206 | * from. This is mainly a pass through class that allows {@link #DisplayContent} to have |
| 3207 | * homogeneous children type which is currently required by sub-classes of |
| 3208 | * {@link WindowContainer} class. |
| 3209 | */ |
| 3210 | static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> { |
| 3211 | |
| 3212 | int size() { |
| 3213 | return mChildren.size(); |
| 3214 | } |
| 3215 | |
| 3216 | E get(int index) { |
| 3217 | return mChildren.get(index); |
| 3218 | } |
| 3219 | |
| 3220 | @Override |
| 3221 | boolean fillsParent() { |
| 3222 | return true; |
| 3223 | } |
| 3224 | |
| 3225 | @Override |
| 3226 | boolean isVisible() { |
| 3227 | return true; |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3228 | } |
| 3229 | } |
| 3230 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3231 | /** |
| 3232 | * Window container class that contains all containers on this display relating to Apps. |
| 3233 | * I.e Activities. |
| 3234 | */ |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 3235 | private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3236 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3237 | /** |
| 3238 | * Adds the stack to this container. |
| 3239 | * @see WindowManagerService#addStackToDisplay(int, int, boolean) |
| 3240 | */ |
| 3241 | void addStackToDisplay(TaskStack stack, boolean onTop) { |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3242 | if (stack.mStackId == HOME_STACK_ID) { |
| 3243 | if (mHomeStack != null) { |
| 3244 | throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first."); |
| 3245 | } |
| 3246 | mHomeStack = stack; |
| 3247 | } |
| 3248 | addChild(stack, onTop); |
| 3249 | stack.onDisplayChanged(DisplayContent.this); |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3250 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3251 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3252 | /** Removes the stack from its container and prepare for changing the parent. */ |
| 3253 | void removeStackFromDisplay(TaskStack stack) { |
| 3254 | removeChild(stack); |
| 3255 | stack.onRemovedFromDisplay(); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3256 | } |
| 3257 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3258 | private void addChild(TaskStack stack, boolean toTop) { |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 3259 | final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack, |
| 3260 | true /* adding */); |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3261 | addChild(stack, addIndex); |
| 3262 | setLayoutNeeded(); |
| 3263 | } |
| 3264 | |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 3265 | @Override |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3266 | void positionChildAt(int position, TaskStack child, boolean includingParents) { |
| 3267 | if (StackId.isAlwaysOnTop(child.mStackId) && position != POSITION_TOP) { |
| 3268 | // This stack is always-on-top, override the default behavior. |
| 3269 | Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom"); |
| 3270 | |
| 3271 | // Moving to its current position, as we must call super but we don't want to |
| 3272 | // perform any meaningful action. |
| 3273 | final int currentPosition = mChildren.indexOf(child); |
| 3274 | super.positionChildAt(currentPosition, child, false /* includingParents */); |
| 3275 | return; |
| 3276 | } |
| 3277 | |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 3278 | final int targetPosition = findPositionForStack(position, child, false /* adding */); |
| 3279 | super.positionChildAt(targetPosition, child, includingParents); |
| 3280 | |
| 3281 | setLayoutNeeded(); |
| 3282 | } |
| 3283 | |
| 3284 | /** |
| 3285 | * When stack is added or repositioned, find a proper position for it. |
| 3286 | * This will make sure that pinned stack always stays on top. |
| 3287 | * @param requestedPosition Position requested by caller. |
| 3288 | * @param stack Stack to be added or positioned. |
| 3289 | * @param adding Flag indicates whether we're adding a new stack or positioning an existing. |
| 3290 | * @return The proper position for the stack. |
| 3291 | */ |
| 3292 | private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) { |
| 3293 | final int topChildPosition = mChildren.size() - 1; |
| 3294 | boolean toTop = requestedPosition == POSITION_TOP; |
| 3295 | toTop |= adding ? requestedPosition >= topChildPosition + 1 |
| 3296 | : requestedPosition >= topChildPosition; |
| 3297 | int targetPosition = requestedPosition; |
| 3298 | |
Bryce Lee | 48f4b57 | 2017-04-10 10:54:15 -0700 | [diff] [blame] | 3299 | if (toTop && stack.mStackId != PINNED_STACK_ID |
| 3300 | && getStackById(PINNED_STACK_ID) != null) { |
| 3301 | // The pinned stack is always the top most stack (always-on-top) when it is present. |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 3302 | TaskStack topStack = mChildren.get(topChildPosition); |
| 3303 | if (topStack.mStackId != PINNED_STACK_ID) { |
| 3304 | throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren); |
| 3305 | } |
| 3306 | |
| 3307 | // So, stack is moved just below the pinned stack. |
| 3308 | // When we're adding a new stack the target is the current pinned stack position. |
| 3309 | // When we're positioning an existing stack the target is the position below pinned |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 3310 | // stack, because WindowContainer#positionAt() first removes element and then adds |
| 3311 | // it to specified place. |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 3312 | targetPosition = adding ? topChildPosition : topChildPosition - 1; |
| 3313 | } |
| 3314 | |
| 3315 | return targetPosition; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3319 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, |
| 3320 | boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3321 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3322 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 3323 | return true; |
| 3324 | } |
| 3325 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 3326 | return true; |
| 3327 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3328 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3329 | if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) { |
| 3330 | return true; |
| 3331 | } |
| 3332 | if (super.forAllWindows(callback, traverseTopToBottom)) { |
| 3333 | return true; |
| 3334 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3335 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3336 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3337 | } |
| 3338 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3339 | private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback, |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3340 | boolean traverseTopToBottom) { |
| 3341 | // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the |
| 3342 | // app tokens. |
| 3343 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 3344 | // in-order. |
| 3345 | if (traverseTopToBottom) { |
| 3346 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 3347 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 3348 | for (int j = appTokens.size() - 1; j >= 0; --j) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3349 | if (appTokens.get(j).forAllWindowsUnchecked(callback, |
| 3350 | traverseTopToBottom)) { |
| 3351 | return true; |
| 3352 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | } else { |
| 3356 | final int count = mChildren.size(); |
| 3357 | for (int i = 0; i < count; ++i) { |
| 3358 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 3359 | final int appTokensCount = appTokens.size(); |
| 3360 | for (int j = 0; j < appTokensCount; j++) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3361 | if (appTokens.get(j).forAllWindowsUnchecked(callback, |
| 3362 | traverseTopToBottom)) { |
| 3363 | return true; |
| 3364 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3365 | } |
| 3366 | } |
| 3367 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3368 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3371 | void setExitingTokensHasVisible(boolean hasVisible) { |
| 3372 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 3373 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 3374 | for (int j = appTokens.size() - 1; j >= 0; --j) { |
| 3375 | appTokens.get(j).hasVisible = hasVisible; |
| 3376 | } |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | void removeExistingAppTokensIfPossible() { |
| 3381 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 3382 | final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens; |
| 3383 | for (int j = appTokens.size() - 1; j >= 0; --j) { |
| 3384 | final AppWindowToken token = appTokens.get(j); |
| 3385 | if (!token.hasVisible && !mService.mClosingApps.contains(token) |
| 3386 | && (!token.mIsExiting || token.isEmpty())) { |
| 3387 | // Make sure there is no animation running on this token, so any windows |
| 3388 | // associated with it will be removed as soon as their animations are |
| 3389 | // complete. |
| 3390 | token.mAppAnimator.clearAnimation(); |
| 3391 | token.mAppAnimator.animating = false; |
| 3392 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 3393 | "performLayout: App token exiting now removed" + token); |
| 3394 | token.removeIfPossible(); |
| 3395 | } |
| 3396 | } |
| 3397 | } |
| 3398 | } |
| 3399 | |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3400 | @Override |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 3401 | int getOrientation() { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3402 | if (isStackVisible(DOCKED_STACK_ID) || isStackVisible(FREEFORM_WORKSPACE_STACK_ID)) { |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 3403 | // Apps and their containers are not allowed to specify an orientation while the |
| 3404 | // docked or freeform stack is visible...except for the home stack/task if the |
| 3405 | // docked stack is minimized and it actually set something. |
| 3406 | if (mHomeStack != null && mHomeStack.isVisible() |
| 3407 | && mDividerControllerLocked.isMinimizedDock()) { |
| 3408 | final int orientation = mHomeStack.getOrientation(); |
| 3409 | if (orientation != SCREEN_ORIENTATION_UNSET) { |
| 3410 | return orientation; |
| 3411 | } |
| 3412 | } |
| 3413 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 3414 | } |
| 3415 | |
| 3416 | final int orientation = super.getOrientation(); |
| 3417 | if (orientation != SCREEN_ORIENTATION_UNSET |
| 3418 | && orientation != SCREEN_ORIENTATION_BEHIND) { |
| 3419 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
| 3420 | "App is requesting an orientation, return " + orientation); |
| 3421 | return orientation; |
| 3422 | } |
| 3423 | |
| 3424 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 3425 | "No app is requesting an orientation, return " + mLastOrientation); |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 3426 | // The next app has not been requested to be visible, so we keep the current orientation |
| 3427 | // to prevent freezing/unfreezing the display too early. |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 3428 | return mLastOrientation; |
Wale Ogunwale | e6f806e | 2016-10-20 15:29:42 -0700 | [diff] [blame] | 3429 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | /** |
| 3433 | * Window container class that contains all containers on this display that are not related to |
| 3434 | * Apps. E.g. status bar. |
| 3435 | */ |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 3436 | private final class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> { |
| 3437 | /** |
| 3438 | * Compares two child window tokens returns -1 if the first is lesser than the second in |
| 3439 | * terms of z-order and 1 otherwise. |
| 3440 | */ |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3441 | private final Comparator<WindowToken> mWindowComparator = (token1, token2) -> |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 3442 | // Tokens with higher base layer are z-ordered on-top. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 3443 | mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType, |
| 3444 | token1.mOwnerCanManageAppTokens) |
| 3445 | < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType, |
| 3446 | token2.mOwnerCanManageAppTokens) ? -1 : 1; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3447 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3448 | private final Predicate<WindowState> mGetOrientingWindow = w -> { |
| 3449 | if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) { |
| 3450 | return false; |
| 3451 | } |
| 3452 | final int req = w.mAttrs.screenOrientation; |
| 3453 | if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND |
| 3454 | || req == SCREEN_ORIENTATION_UNSET) { |
| 3455 | return false; |
| 3456 | } |
| 3457 | return true; |
| 3458 | }; |
| 3459 | |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 3460 | private final String mName; |
| 3461 | NonAppWindowContainers(String name) { |
| 3462 | mName = name; |
| 3463 | } |
| 3464 | |
| 3465 | void addChild(WindowToken token) { |
| 3466 | addChild(token, mWindowComparator); |
| 3467 | } |
| 3468 | |
| 3469 | @Override |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3470 | int getOrientation() { |
| 3471 | final WindowManagerPolicy policy = mService.mPolicy; |
| 3472 | // Find a window requesting orientation. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 3473 | final WindowState win = getWindow(mGetOrientingWindow); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3474 | |
| 3475 | if (win != null) { |
| 3476 | final int req = win.mAttrs.screenOrientation; |
| 3477 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req); |
| 3478 | if (policy.isKeyguardHostWindow(win.mAttrs)) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 3479 | mLastKeyguardForcedOrientation = req; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3480 | } |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 3481 | return (mLastWindowForcedOrientation = req); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3482 | } |
| 3483 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 3484 | mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3485 | |
| 3486 | if (policy.isKeyguardShowingAndNotOccluded()) { |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 3487 | return mLastKeyguardForcedOrientation; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | return SCREEN_ORIENTATION_UNSET; |
| 3491 | } |
| 3492 | |
| 3493 | @Override |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 3494 | String getName() { |
| 3495 | return mName; |
| 3496 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 3497 | } |
Jorim Jaggi | 6a7a859 | 2017-01-12 00:44:33 +0100 | [diff] [blame] | 3498 | |
| 3499 | /** |
| 3500 | * Interface to screenshot into various types, i.e. {@link Bitmap} and {@link GraphicBuffer}. |
| 3501 | */ |
| 3502 | @FunctionalInterface |
| 3503 | private interface Screenshoter<E> { |
| 3504 | E screenshot(Rect sourceCrop, int width, int height, int minLayer, int maxLayer, |
| 3505 | boolean useIdentityTransform, int rotation); |
| 3506 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3507 | } |