Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS; |
| 20 | import static android.app.ActivityManager.StackId; |
Winson Chung | d73e94b | 2017-05-31 16:25:30 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 22 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Winson Chung | d73e94b | 2017-05-31 16:25:30 -0700 | [diff] [blame] | 23 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 24 | import static android.app.ActivityManager.isLowRamDeviceStatic; |
| 25 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
| 26 | import static android.view.Display.DEFAULT_DISPLAY; |
| 27 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; |
| 28 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 29 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
| 30 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE; |
| 31 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 32 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
| 33 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 34 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 35 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 36 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 38 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 39 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
| 40 | import static android.view.WindowManager.LayoutParams.FLAG_SCALED; |
| 41 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
| 42 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 43 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 44 | import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 45 | import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 46 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| 47 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
| 48 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 49 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME; |
| 50 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; |
| 51 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH; |
| 52 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 53 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 54 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 55 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 56 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 57 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 58 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 59 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
| 60 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 61 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 62 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 63 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED; |
| 64 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM; |
| 65 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME; |
| 66 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 67 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 68 | import static android.view.WindowManagerPolicy.TRANSIT_ENTER; |
| 69 | import static android.view.WindowManagerPolicy.TRANSIT_EXIT; |
| 70 | import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 71 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 72 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM; |
| 73 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 74 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 75 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
| 76 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION; |
| 77 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 78 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
| 79 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 80 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
| 81 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 82 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
| 83 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE; |
| 84 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 85 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 86 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE; |
| 87 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 88 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
| 89 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 90 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 91 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
| 92 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
| 93 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
| 94 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
| 95 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
| 96 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
| 97 | import static com.android.server.wm.WindowManagerService.localLOGV; |
| 98 | import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING; |
| 99 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
| 100 | import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN; |
| 101 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
| 102 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 103 | import android.app.AppOpsManager; |
| 104 | import android.content.Context; |
| 105 | import android.content.res.Configuration; |
| 106 | import android.graphics.Matrix; |
| 107 | import android.graphics.PixelFormat; |
| 108 | import android.graphics.Point; |
| 109 | import android.graphics.Rect; |
| 110 | import android.graphics.Region; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 111 | import android.os.Binder; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 112 | import android.os.Debug; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 113 | import android.os.IBinder; |
| 114 | import android.os.PowerManager; |
| 115 | import android.os.RemoteCallbackList; |
| 116 | import android.os.RemoteException; |
| 117 | import android.os.SystemClock; |
| 118 | import android.os.Trace; |
| 119 | import android.os.UserHandle; |
| 120 | import android.os.WorkSource; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 121 | import android.util.MergedConfiguration; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 122 | import android.util.DisplayMetrics; |
| 123 | import android.util.Slog; |
| 124 | import android.util.TimeUtils; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 125 | import android.view.DisplayInfo; |
| 126 | import android.view.Gravity; |
| 127 | import android.view.IApplicationToken; |
| 128 | import android.view.IWindow; |
| 129 | import android.view.IWindowFocusObserver; |
| 130 | import android.view.IWindowId; |
| 131 | import android.view.InputChannel; |
| 132 | import android.view.InputEvent; |
| 133 | import android.view.InputEventReceiver; |
| 134 | import android.view.View; |
| 135 | import android.view.ViewTreeObserver; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 136 | import android.view.WindowInfo; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 137 | import android.view.WindowManager; |
| 138 | import android.view.WindowManagerPolicy; |
| 139 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 140 | import com.android.internal.util.ToBooleanFunction; |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 141 | import com.android.server.input.InputWindowHandle; |
| 142 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 143 | import java.io.PrintWriter; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 144 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 145 | import java.util.ArrayList; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 146 | import java.util.Comparator; |
| 147 | import java.util.LinkedList; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 148 | import java.util.function.Predicate; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 149 | |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 150 | /** A window in the window manager. */ |
| 151 | class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 152 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 153 | |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 154 | // The minimal size of a window within the usable area of the freeform stack. |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 155 | // TODO(multi-window): fix the min sizes when we have mininum width/height support, |
| 156 | // use hard-coded min sizes for now. |
| 157 | static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48; |
| 158 | static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 159 | |
| 160 | // The thickness of a window resize handle outside the window bounds on the free form workspace |
| 161 | // to capture touch events in that area. |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 162 | static final int RESIZE_HANDLE_WIDTH_IN_DP = 30; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 163 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 164 | private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false || |
| 165 | ENABLE_TASK_SNAPSHOTS; |
Robert Carr | 7098dbd | 2016-02-01 12:31:01 -0800 | [diff] [blame] | 166 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 167 | final WindowManagerService mService; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 168 | final WindowManagerPolicy mPolicy; |
| 169 | final Context mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 170 | final Session mSession; |
| 171 | final IWindow mClient; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 172 | final int mAppOp; |
| 173 | // UserId and appId of the owner. Don't display windows of non-current user. |
| 174 | final int mOwnerUid; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 175 | /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */ |
| 176 | final boolean mOwnerCanAddInternalSystemWindow; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 177 | final WindowId mWindowId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 178 | WindowToken mToken; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 179 | // The same object as mToken if this is an app window and null for non-app windows. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 180 | AppWindowToken mAppToken; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 181 | |
| 182 | // mAttrs.flags is tested in animation without being locked. If the bits tested are ever |
| 183 | // modified they will need to be locked. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 184 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 185 | final DeathRecipient mDeathRecipient; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 186 | private boolean mIsChildWindow; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 187 | final int mBaseLayer; |
| 188 | final int mSubLayer; |
| 189 | final boolean mLayoutAttached; |
| 190 | final boolean mIsImWindow; |
| 191 | final boolean mIsWallpaper; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 192 | private final boolean mIsFloatingLayer; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 193 | int mSeq; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 194 | boolean mEnforceSizeCompat; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 195 | int mViewVisibility; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 196 | int mSystemUiVisibility; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 197 | /** |
| 198 | * The visibility of the window based on policy like {@link WindowManagerPolicy}. |
| 199 | * Normally set by calling {@link #showLw} and {@link #hideLw}. |
| 200 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 201 | boolean mPolicyVisibility = true; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 202 | /** |
| 203 | * What {@link #mPolicyVisibility} should be set to after a transition animation. |
| 204 | * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and |
| 205 | * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit |
| 206 | * animation is done. |
| 207 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 208 | boolean mPolicyVisibilityAfterAnim = true; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 209 | private boolean mAppOpVisibility = true; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 210 | boolean mPermanentlyHidden; // the window should never be shown again |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 211 | boolean mAppFreezing; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 212 | boolean mHidden; // Used to determine if to show child windows. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 213 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 214 | private boolean mDragResizing; |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 215 | private boolean mDragResizingChangeReported = true; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 216 | private int mResizeMode; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 217 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 218 | private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 219 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 220 | /** |
| 221 | * The window size that was requested by the application. These are in |
| 222 | * the application's coordinate space (without compatibility scale applied). |
| 223 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 224 | int mRequestedWidth; |
| 225 | int mRequestedHeight; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 226 | private int mLastRequestedWidth; |
| 227 | private int mLastRequestedHeight; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 228 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 229 | int mLayer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 230 | boolean mHaveFrame; |
| 231 | boolean mObscured; |
| 232 | boolean mTurnOnScreen; |
| 233 | |
| 234 | int mLayoutSeq = -1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 235 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 236 | /** |
| 237 | * Used to store last reported to client configuration and check if we have newer available. |
| 238 | * We'll send configuration to client only if it is different from the last applied one and |
| 239 | * client won't perform unnecessary updates. |
| 240 | */ |
| 241 | private final Configuration mLastReportedConfiguration = new Configuration(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 242 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 243 | /** |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 244 | * Actual position of the surface shown on-screen (may be modified by animation). These are |
| 245 | * in the screen's coordinate space (WITH the compatibility scale applied). |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 246 | */ |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 247 | final Point mShownPosition = new Point(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 248 | |
| 249 | /** |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 250 | * Insets that determine the actually visible area. These are in the application's |
| 251 | * coordinate space (without compatibility scale applied). |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 252 | */ |
| 253 | final Rect mVisibleInsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 254 | private final Rect mLastVisibleInsets = new Rect(); |
| 255 | private boolean mVisibleInsetsChanged; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 256 | |
| 257 | /** |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 258 | * Insets that are covered by system windows (such as the status bar) and |
| 259 | * transient docking windows (such as the IME). These are in the application's |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 260 | * coordinate space (without compatibility scale applied). |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 261 | */ |
| 262 | final Rect mContentInsets = new Rect(); |
| 263 | final Rect mLastContentInsets = new Rect(); |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 264 | |
| 265 | /** |
| 266 | * The last content insets returned to the client in relayout. We use |
| 267 | * these in the bounds animation to ensure we only observe inset changes |
| 268 | * at the same time that a client resizes it's surface so that we may use |
| 269 | * the geometryAppliesWithResize synchronization mechanism to keep |
| 270 | * the contents in place. |
| 271 | */ |
| 272 | final Rect mLastRelayoutContentInsets = new Rect(); |
| 273 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 274 | private boolean mContentInsetsChanged; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 275 | |
| 276 | /** |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 277 | * Insets that determine the area covered by the display overscan region. These are in the |
| 278 | * application's coordinate space (without compatibility scale applied). |
| 279 | */ |
| 280 | final Rect mOverscanInsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 281 | private final Rect mLastOverscanInsets = new Rect(); |
| 282 | private boolean mOverscanInsetsChanged; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 283 | |
| 284 | /** |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 285 | * Insets that determine the area covered by the stable system windows. These are in the |
| 286 | * application's coordinate space (without compatibility scale applied). |
| 287 | */ |
| 288 | final Rect mStableInsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 289 | private final Rect mLastStableInsets = new Rect(); |
| 290 | private boolean mStableInsetsChanged; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 293 | * Outsets determine the area outside of the surface where we want to pretend that it's possible |
| 294 | * to draw anyway. |
| 295 | */ |
| 296 | final Rect mOutsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 297 | private final Rect mLastOutsets = new Rect(); |
| 298 | private boolean mOutsetsChanged = false; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 301 | * Set to true if we are waiting for this window to receive its |
| 302 | * given internal insets before laying out other windows based on it. |
| 303 | */ |
| 304 | boolean mGivenInsetsPending; |
| 305 | |
| 306 | /** |
| 307 | * These are the content insets that were given during layout for |
| 308 | * this window, to be applied to windows behind it. |
| 309 | */ |
| 310 | final Rect mGivenContentInsets = new Rect(); |
| 311 | |
| 312 | /** |
| 313 | * These are the visible insets that were given during layout for |
| 314 | * this window, to be applied to windows behind it. |
| 315 | */ |
| 316 | final Rect mGivenVisibleInsets = new Rect(); |
| 317 | |
| 318 | /** |
| 319 | * This is the given touchable area relative to the window frame, or null if none. |
| 320 | */ |
| 321 | final Region mGivenTouchableRegion = new Region(); |
| 322 | |
| 323 | /** |
| 324 | * Flag indicating whether the touchable region should be adjusted by |
| 325 | * the visible insets; if false the area outside the visible insets is |
| 326 | * NOT touchable, so we must use those to adjust the frame during hit |
| 327 | * tests. |
| 328 | */ |
| 329 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 330 | |
| 331 | // Current transformation being applied. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 332 | float mGlobalScale=1; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 333 | float mInvGlobalScale=1; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 334 | float mHScale=1, mVScale=1; |
| 335 | float mLastHScale=1, mLastVScale=1; |
| 336 | final Matrix mTmpMatrix = new Matrix(); |
| 337 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 338 | // "Real" frame that the application sees, in display coordinate space. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 339 | final Rect mFrame = new Rect(); |
| 340 | final Rect mLastFrame = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 341 | private boolean mFrameSizeChanged = false; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 342 | // Frame that is scaled to the application's coordinate space when in |
| 343 | // screen size compatibility mode. |
| 344 | final Rect mCompatFrame = new Rect(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 345 | |
| 346 | final Rect mContainingFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 347 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 348 | private final Rect mParentFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 349 | |
Wale Ogunwale | 9459665 | 2015-02-06 19:27:34 -0800 | [diff] [blame] | 350 | // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the |
| 351 | // screen area of the device. |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 352 | final Rect mDisplayFrame = new Rect(); |
| 353 | |
| 354 | // The region of the display frame that the display type supports displaying content on. This |
| 355 | // is mostly a special case for TV where some displays don’t have the entire display usable. |
| 356 | // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow |
| 357 | // window display contents to extend into the overscan region. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 358 | private final Rect mOverscanFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 359 | |
| 360 | // The display frame minus the stable insets. This value is always constant regardless of if |
| 361 | // the status bar or navigation bar is visible. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 362 | private final Rect mStableFrame = new Rect(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 363 | |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 364 | // The area not occupied by the status and navigation bars. So, if both status and navigation |
| 365 | // bars are visible, the decor frame is equal to the stable frame. |
| 366 | final Rect mDecorFrame = new Rect(); |
| 367 | |
| 368 | // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame |
| 369 | // minus the area occupied by the IME if the IME is present. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 370 | private final Rect mContentFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 371 | |
| 372 | // Legacy stuff. Generally equal to the content frame expect when the IME for older apps |
| 373 | // displays hint text. |
| 374 | final Rect mVisibleFrame = new Rect(); |
| 375 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 376 | // Frame that includes dead area outside of the surface but where we want to pretend that it's |
| 377 | // possible to draw. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 378 | private final Rect mOutsetFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 379 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 380 | /** |
| 381 | * Usually empty. Set to the task's tempInsetFrame. See |
| 382 | *{@link android.app.IActivityManager#resizeDockedStack}. |
| 383 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 384 | private final Rect mInsetFrame = new Rect(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 385 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 386 | boolean mContentChanged; |
| 387 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 388 | // If a window showing a wallpaper: the requested offset for the |
| 389 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 390 | float mWallpaperX = -1; |
| 391 | float mWallpaperY = -1; |
| 392 | |
| 393 | // If a window showing a wallpaper: what fraction of the offset |
| 394 | // range corresponds to a full virtual screen. |
| 395 | float mWallpaperXStep = -1; |
| 396 | float mWallpaperYStep = -1; |
| 397 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 398 | // If a window showing a wallpaper: a raw pixel offset to forcibly apply |
| 399 | // to its window; if a wallpaper window: not used. |
| 400 | int mWallpaperDisplayOffsetX = Integer.MIN_VALUE; |
| 401 | int mWallpaperDisplayOffsetY = Integer.MIN_VALUE; |
| 402 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 403 | // Wallpaper windows: pixels offset based on above variables. |
| 404 | int mXOffset; |
| 405 | int mYOffset; |
| 406 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 407 | /** |
| 408 | * This is set after IWindowSession.relayout() has been called at |
| 409 | * least once for the window. It allows us to detect the situation |
| 410 | * where we don't yet have a surface, but should have one soon, so |
| 411 | * we can give the window focus before waiting for the relayout. |
| 412 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 413 | boolean mRelayoutCalled; |
| 414 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 415 | boolean mInRelayout; |
| 416 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 417 | /** |
| 418 | * If the application has called relayout() with changes that can |
| 419 | * impact its window's size, we need to perform a layout pass on it |
| 420 | * even if it is not currently visible for layout. This is set |
| 421 | * when in that case until the layout is done. |
| 422 | */ |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 423 | boolean mLayoutNeeded; |
| 424 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 425 | /** Currently running an exit animation? */ |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 426 | boolean mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 427 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 428 | /** Currently on the mDestroySurface list? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 429 | boolean mDestroying; |
| 430 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 431 | /** Completely remove from window manager after exit animation? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 432 | boolean mRemoveOnExit; |
| 433 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 434 | /** |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 435 | * Whether the app died while it was visible, if true we might need |
| 436 | * to continue to show it until it's restarted. |
| 437 | */ |
| 438 | boolean mAppDied; |
| 439 | |
| 440 | /** |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 441 | * Set when the orientation is changing and this window has not yet |
| 442 | * been updated for the new orientation. |
| 443 | */ |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 444 | private boolean mOrientationChanging; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 445 | |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 446 | /** |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 447 | * Sometimes in addition to the mOrientationChanging |
| 448 | * flag we report that the orientation is changing |
| 449 | * due to a mismatch in current and reported configuration. |
| 450 | * |
| 451 | * In the case of timeout we still need to make sure we |
| 452 | * leave the orientation changing state though, so we |
| 453 | * use this as a special time out escape hatch. |
| 454 | */ |
| 455 | private boolean mOrientationChangeTimedOut; |
| 456 | |
| 457 | /** |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 458 | * The orientation during the last visible call to relayout. If our |
| 459 | * current orientation is different, the window can't be ready |
| 460 | * to be shown. |
| 461 | */ |
| 462 | int mLastVisibleLayoutRotation = -1; |
| 463 | |
| 464 | /** |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 465 | * Set when we need to report the orientation change to client to trigger a relayout. |
| 466 | */ |
| 467 | boolean mReportOrientationChanged; |
| 468 | |
| 469 | /** |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 470 | * How long we last kept the screen frozen. |
| 471 | */ |
| 472 | int mLastFreezeDuration; |
| 473 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 474 | /** Is this window now (or just being) removed? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 475 | boolean mRemoved; |
| 476 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 477 | /** |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 478 | * It is save to remove the window and destroy the surface because the client requested removal |
| 479 | * or some other higher level component said so (e.g. activity manager). |
| 480 | * TODO: We should either have different booleans for the removal reason or use a bit-field. |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 481 | */ |
Svetoslav Ganov | 200adfb | 2016-10-18 13:29:27 -0700 | [diff] [blame] | 482 | boolean mWindowRemovalAllowed; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 483 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 484 | // Input channel and input window handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 485 | final InputWindowHandle mInputWindowHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 486 | InputChannel mInputChannel; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 487 | private InputChannel mClientChannel; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 488 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 489 | // Used to improve performance of toString() |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 490 | private String mStringNameCache; |
| 491 | private CharSequence mLastTitle; |
| 492 | private boolean mWasExiting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 493 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 494 | final WindowStateAnimator mWinAnimator; |
| 495 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 496 | boolean mHasSurface = false; |
| 497 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 498 | /** When true this window can be displayed on screens owther than mOwnerUid's */ |
| 499 | private boolean mShowToOwnerOnly; |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 500 | |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 501 | // Whether the window has a saved surface from last pause, which can be |
| 502 | // used to start an entering animation earlier. |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 503 | private boolean mSurfaceSaved = false; |
| 504 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 505 | // Whether we're performing an entering animation with a saved surface. This flag is |
| 506 | // true during the time we're showing a window with a previously saved surface. It's |
| 507 | // cleared when surface is destroyed, saved, or re-drawn by the app. |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 508 | private boolean mAnimatingWithSavedSurface; |
| 509 | |
| 510 | // Whether the window was visible when we set the app to invisible last time. WM uses |
| 511 | // this as a hint to restore the surface (if available) for early animation next time |
| 512 | // the app is brought visible. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 513 | private boolean mWasVisibleBeforeClientHidden; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 514 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 515 | // This window will be replaced due to relaunch. This allows window manager |
| 516 | // to differentiate between simple removal of a window and replacement. In the latter case it |
| 517 | // will preserve the old window until the new one is drawn. |
| 518 | boolean mWillReplaceWindow = false; |
| 519 | // If true, the replaced window was already requested to be removed. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 520 | private boolean mReplacingRemoveRequested = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 521 | // Whether the replacement of the window should trigger app transition animation. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 522 | private boolean mAnimateReplacingWindow = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 523 | // If not null, the window that will be used to replace the old one. This is being set when |
| 524 | // the window is added and unset when this window reports its first draw. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 525 | private WindowState mReplacementWindow = null; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 526 | // For the new window in the replacement transition, if we have |
| 527 | // requested to replace without animation, then we should |
| 528 | // make sure we also don't apply an enter animation for |
| 529 | // the new window. |
| 530 | boolean mSkipEnterAnimationForSeamlessReplacement = false; |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 531 | // Whether this window is being moved via the resize API |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 532 | private boolean mMovedByResize; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 533 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 534 | /** |
| 535 | * Wake lock for drawing. |
| 536 | * Even though it's slightly more expensive to do so, we will use a separate wake lock |
| 537 | * for each app that is requesting to draw while dozing so that we can accurately track |
| 538 | * who is preventing the system from suspending. |
| 539 | * This lock is only acquired on first use. |
| 540 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 541 | private PowerManager.WakeLock mDrawLock; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 542 | |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 543 | final private Rect mTmpRect = new Rect(); |
| 544 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 545 | /** |
| 546 | * Whether the window was resized by us while it was gone for layout. |
| 547 | */ |
| 548 | boolean mResizedWhileGone = false; |
| 549 | |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 550 | /** @see #isResizedWhileNotDragResizing(). */ |
| 551 | private boolean mResizedWhileNotDragResizing; |
| 552 | |
| 553 | /** @see #isResizedWhileNotDragResizingReported(). */ |
| 554 | private boolean mResizedWhileNotDragResizingReported; |
Jorim Jaggi | f3df0aa | 2016-04-06 15:56:33 -0700 | [diff] [blame] | 555 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 556 | /** |
| 557 | * During seamless rotation we have two phases, first the old window contents |
| 558 | * are rotated to look as if they didn't move in the new coordinate system. Then we |
| 559 | * have to freeze updates to this layer (to preserve the transformation) until |
| 560 | * the resize actually occurs. This is true from when the transformation is set |
| 561 | * and false until the transaction to resize is sent. |
| 562 | */ |
| 563 | boolean mSeamlesslyRotated = false; |
| 564 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 565 | private static final Region sEmptyRegion = new Region(); |
| 566 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 567 | /** |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 568 | * Surface insets from the previous call to relayout(), used to track |
| 569 | * if we are changing the Surface insets. |
| 570 | */ |
| 571 | final Rect mLastSurfaceInsets = new Rect(); |
| 572 | |
| 573 | /** |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 574 | * A flag set by the {@link WindowState} parent to indicate that the parent has examined this |
| 575 | * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to |
| 576 | * make sure all children have been considered. |
| 577 | */ |
| 578 | private boolean mDrawnStateEvaluated; |
| 579 | |
| 580 | /** |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 581 | * Compares two window sub-layers and returns -1 if the first is lesser than the second in terms |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 582 | * of z-order and 1 otherwise. |
| 583 | */ |
Griff Hazen | 51d00d8 | 2016-11-22 15:39:24 -0800 | [diff] [blame] | 584 | private static final Comparator<WindowState> sWindowSubLayerComparator = |
| 585 | new Comparator<WindowState>() { |
| 586 | @Override |
| 587 | public int compare(WindowState w1, WindowState w2) { |
| 588 | final int layer1 = w1.mSubLayer; |
| 589 | final int layer2 = w2.mSubLayer; |
| 590 | if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) { |
| 591 | // We insert the child window into the list ordered by |
| 592 | // the sub-layer. For same sub-layers, the negative one |
| 593 | // should go below others; the positive one should go |
| 594 | // above others. |
| 595 | return -1; |
| 596 | } |
| 597 | return 1; |
| 598 | }; |
| 599 | }; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 600 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 601 | WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, |
Wale Ogunwale | 7ed4d37 | 2016-07-09 15:28:55 -0700 | [diff] [blame] | 602 | WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 603 | int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 604 | mService = service; |
| 605 | mSession = s; |
| 606 | mClient = c; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 607 | mAppOp = appOp; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 608 | mToken = token; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 609 | mAppToken = mToken.asAppWindowToken(); |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 610 | mOwnerUid = ownerId; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 611 | mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 612 | mWindowId = new WindowId(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 613 | mAttrs.copyFrom(a); |
| 614 | mViewVisibility = viewVisibility; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 615 | mPolicy = mService.mPolicy; |
| 616 | mContext = mService.mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 617 | DeathRecipient deathRecipient = new DeathRecipient(); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 618 | mSeq = seq; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 619 | mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 620 | if (localLOGV) Slog.v( |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 621 | TAG, "Window " + this + " client=" + c.asBinder() |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 622 | + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 623 | try { |
| 624 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 625 | } catch (RemoteException e) { |
| 626 | mDeathRecipient = null; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 627 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 628 | mLayoutAttached = false; |
| 629 | mIsImWindow = false; |
| 630 | mIsWallpaper = false; |
| 631 | mIsFloatingLayer = false; |
| 632 | mBaseLayer = 0; |
| 633 | mSubLayer = 0; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 634 | mInputWindowHandle = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 635 | mWinAnimator = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 636 | return; |
| 637 | } |
| 638 | mDeathRecipient = deathRecipient; |
| 639 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 640 | if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 641 | // The multiplier here is to reserve space for multiple |
| 642 | // windows in the same type layer. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 643 | mBaseLayer = mPolicy.getWindowLayerLw(parentWindow) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 644 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 645 | mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 646 | mIsChildWindow = true; |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 647 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 648 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow); |
| 649 | parentWindow.addChild(this, sWindowSubLayerComparator); |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 650 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 651 | mLayoutAttached = mAttrs.type != |
| 652 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
Wale Ogunwale | 7ed4d37 | 2016-07-09 15:28:55 -0700 | [diff] [blame] | 653 | mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 654 | || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 655 | mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 656 | } else { |
| 657 | // The multiplier here is to reserve space for multiple |
| 658 | // windows in the same type layer. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 659 | mBaseLayer = mPolicy.getWindowLayerLw(this) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 660 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 661 | mSubLayer = 0; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 662 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 663 | mLayoutAttached = false; |
| 664 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 665 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 666 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 667 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 668 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 669 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 670 | if (mAppToken != null && mAppToken.mShowForAllUsers) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 671 | // Windows for apps that can show for all users should also show when the device is |
| 672 | // locked. |
| 673 | mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED; |
Craig Mautner | 19ab828 | 2014-05-07 10:35:34 -0700 | [diff] [blame] | 674 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 675 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 676 | mWinAnimator = new WindowStateAnimator(this); |
| 677 | mWinAnimator.mAlpha = a.alpha; |
| 678 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 679 | mRequestedWidth = 0; |
| 680 | mRequestedHeight = 0; |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 681 | mLastRequestedWidth = 0; |
| 682 | mLastRequestedHeight = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 683 | mXOffset = 0; |
| 684 | mYOffset = 0; |
| 685 | mLayer = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 686 | mInputWindowHandle = new InputWindowHandle( |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 687 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c, |
| 688 | getDisplayId()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | void attach() { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 692 | if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken); |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 693 | mSession.windowAddedLocked(mAttrs.packageName); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 694 | } |
| 695 | |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 696 | /** |
| 697 | * Returns whether this {@link WindowState} has been considered for drawing by its parent. |
| 698 | */ |
Bryce Lee | 6311c4b | 2017-07-06 14:09:29 -0700 | [diff] [blame] | 699 | boolean getDrawnStateEvaluated() { |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 700 | return mDrawnStateEvaluated; |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should |
| 705 | * be cleared when detached from parent. |
| 706 | */ |
| 707 | void setDrawnStateEvaluated(boolean evaluated) { |
| 708 | mDrawnStateEvaluated = evaluated; |
| 709 | } |
| 710 | |
| 711 | @Override |
| 712 | void onParentSet() { |
| 713 | super.onParentSet(); |
| 714 | setDrawnStateEvaluated(false /*evaluated*/); |
| 715 | } |
| 716 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 717 | @Override |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 718 | public int getOwningUid() { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 719 | return mOwnerUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | @Override |
| 723 | public String getOwningPackage() { |
| 724 | return mAttrs.packageName; |
| 725 | } |
| 726 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 727 | @Override |
| 728 | public boolean canAddInternalSystemWindow() { |
| 729 | return mOwnerCanAddInternalSystemWindow; |
| 730 | } |
| 731 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 732 | /** |
| 733 | * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame} |
| 734 | * from {@param frame}. In other words, it applies the insets that would result if |
| 735 | * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 736 | * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum |
| 737 | * width/height applied and insets should be overridden. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 738 | */ |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 739 | private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) { |
| 740 | final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left)); |
| 741 | final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top)); |
| 742 | final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right); |
| 743 | final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 744 | frame.inset(left, top, right, bottom); |
| 745 | } |
| 746 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 747 | @Override |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 748 | public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame, |
| 749 | Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame, |
| 750 | Rect outsetFrame) { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 751 | if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 752 | // This window is being replaced and either already got information that it's being |
| 753 | // removed or we are still waiting for some information. Because of this we don't |
| 754 | // want to apply any more changes to it, so it remains in this state until new window |
| 755 | // appears. |
| 756 | return; |
| 757 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 758 | mHaveFrame = true; |
| 759 | |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 760 | final Task task = getTask(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 761 | final boolean inFullscreenContainer = inFullscreenContainer(); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 762 | final boolean windowsAreFloating = task != null && task.isFloating(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 763 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 764 | |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 765 | // If the task has temp inset bounds set, we have to make sure all its windows uses |
| 766 | // the temp inset frame. Otherwise different display frames get applied to the main |
| 767 | // window and the child window, making them misaligned. |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 768 | if (inFullscreenContainer || isLetterboxedAppWindow()) { |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 769 | mInsetFrame.setEmpty(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 770 | } else if (task != null && isInMultiWindowMode()) { |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 771 | task.getTempInsetBounds(mInsetFrame); |
| 772 | } |
| 773 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 774 | // Denotes the actual frame used to calculate the insets and to perform the layout. When |
| 775 | // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the |
| 776 | // insets temporarily. By the notion of a task having a different layout frame, we can |
| 777 | // achieve that while still moving the task around. |
| 778 | final Rect layoutContainingFrame; |
| 779 | final Rect layoutDisplayFrame; |
| 780 | |
| 781 | // The offset from the layout containing frame to the actual containing frame. |
| 782 | final int layoutXDiff; |
| 783 | final int layoutYDiff; |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 784 | if (inFullscreenContainer || layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 785 | // We use the parent frame as the containing frame for fullscreen and child windows |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 786 | mContainingFrame.set(parentFrame); |
| 787 | mDisplayFrame.set(displayFrame); |
| 788 | layoutDisplayFrame = displayFrame; |
| 789 | layoutContainingFrame = parentFrame; |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 790 | layoutXDiff = 0; |
| 791 | layoutYDiff = 0; |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 792 | } else { |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 793 | getContainerBounds(mContainingFrame); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 794 | if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) { |
| 795 | |
| 796 | // If the bounds are frozen, we still want to translate the window freely and only |
| 797 | // freeze the size. |
| 798 | Rect frozen = mAppToken.mFrozenBounds.peek(); |
| 799 | mContainingFrame.right = mContainingFrame.left + frozen.width(); |
| 800 | mContainingFrame.bottom = mContainingFrame.top + frozen.height(); |
| 801 | } |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 802 | final WindowState imeWin = mService.mInputMethodWindow; |
Robert Carr | fc03b2b | 2016-03-31 15:22:02 -0700 | [diff] [blame] | 803 | // IME is up and obscuring this window. Adjust the window position so it is visible. |
| 804 | if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) { |
Winson Chung | d73e94b | 2017-05-31 16:25:30 -0700 | [diff] [blame] | 805 | final int stackId = getStackId(); |
| 806 | if (stackId == FREEFORM_WORKSPACE_STACK_ID |
| 807 | && mContainingFrame.bottom > contentFrame.bottom) { |
| 808 | // In freeform we want to move the top up directly. |
| 809 | // TODO: Investigate why this is contentFrame not parentFrame. |
| 810 | mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom; |
| 811 | } else if (stackId != PINNED_STACK_ID |
| 812 | && mContainingFrame.bottom > parentFrame.bottom) { |
| 813 | // But in docked we want to behave like fullscreen and behave as if the task |
| 814 | // were given smaller bounds for the purposes of layout. Skip adjustments for |
| 815 | // the pinned stack, they are handled separately in the PinnedStackController. |
| 816 | mContainingFrame.bottom = parentFrame.bottom; |
| 817 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 818 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 819 | |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 820 | if (windowsAreFloating) { |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 821 | // In floating modes (e.g. freeform, pinned) we have only to set the rectangle |
| 822 | // if it wasn't set already. No need to intersect it with the (visible) |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 823 | // "content frame" since it is allowed to be outside the visible desktop. |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 824 | if (mContainingFrame.isEmpty()) { |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 825 | mContainingFrame.set(contentFrame); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 826 | } |
Doris Liu | 06d582d | 2015-06-01 13:18:43 -0700 | [diff] [blame] | 827 | } |
Wale Ogunwale | 9459665 | 2015-02-06 19:27:34 -0800 | [diff] [blame] | 828 | mDisplayFrame.set(mContainingFrame); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 829 | layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0; |
| 830 | layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0; |
| 831 | layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame; |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 832 | mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight); |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 833 | subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 834 | if (!layoutInParentFrame()) { |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 835 | subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect); |
| 836 | subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 837 | } |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 838 | layoutDisplayFrame = displayFrame; |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 839 | layoutDisplayFrame.intersect(layoutContainingFrame); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 840 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 841 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 842 | final int pw = mContainingFrame.width(); |
| 843 | final int ph = mContainingFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 844 | |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 845 | if (!mParentFrame.equals(parentFrame)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 846 | //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 847 | // + " to " + parentFrame); |
| 848 | mParentFrame.set(parentFrame); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 849 | mContentChanged = true; |
| 850 | } |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 851 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 852 | mLastRequestedWidth = mRequestedWidth; |
| 853 | mLastRequestedHeight = mRequestedHeight; |
| 854 | mContentChanged = true; |
| 855 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 856 | |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 857 | mOverscanFrame.set(overscanFrame); |
| 858 | mContentFrame.set(contentFrame); |
| 859 | mVisibleFrame.set(visibleFrame); |
| 860 | mDecorFrame.set(decorFrame); |
| 861 | mStableFrame.set(stableFrame); |
| 862 | final boolean hasOutsets = outsetFrame != null; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 863 | if (hasOutsets) { |
Robert Carr | 4352176 | 2016-10-28 13:15:04 -0700 | [diff] [blame] | 864 | mOutsetFrame.set(outsetFrame); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 865 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 866 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 867 | final int fw = mFrame.width(); |
| 868 | final int fh = mFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 869 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 870 | applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame); |
| 871 | |
Filip Gruszczynski | aaf1811 | 2015-06-05 13:37:40 -0700 | [diff] [blame] | 872 | // Calculate the outsets before the content frame gets shrinked to the window frame. |
| 873 | if (hasOutsets) { |
| 874 | mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0), |
| 875 | Math.max(mContentFrame.top - mOutsetFrame.top, 0), |
| 876 | Math.max(mOutsetFrame.right - mContentFrame.right, 0), |
| 877 | Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0)); |
| 878 | } else { |
| 879 | mOutsets.set(0, 0, 0, 0); |
| 880 | } |
| 881 | |
Craig Mautner | a248eee | 2013-05-07 11:41:27 -0700 | [diff] [blame] | 882 | // Make sure the content and visible frames are inside of the |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 883 | // final window frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 884 | if (windowsAreFloating && !mFrame.isEmpty()) { |
Robert Carr | e65a1c4 | 2017-02-28 16:52:59 -0800 | [diff] [blame] | 885 | // For pinned workspace the frame isn't limited in any particular |
| 886 | // way since SystemUI controls the bounds. For freeform however |
| 887 | // we want to keep things inside the content frame. |
| 888 | final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame; |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 889 | // Keep the frame out of the blocked system area, limit it in size to the content area |
| 890 | // and make sure that there is always a minimum visible so that the user can drag it |
| 891 | // into a usable area.. |
Robert Carr | e65a1c4 | 2017-02-28 16:52:59 -0800 | [diff] [blame] | 892 | final int height = Math.min(mFrame.height(), limitFrame.height()); |
| 893 | final int width = Math.min(limitFrame.width(), mFrame.width()); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 894 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
Kazuhiro Inaba | 63e24d1 | 2016-07-14 13:02:55 +0900 | [diff] [blame] | 895 | final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel( |
| 896 | MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics)); |
| 897 | final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel( |
| 898 | MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics)); |
Robert Carr | e65a1c4 | 2017-02-28 16:52:59 -0800 | [diff] [blame] | 899 | final int top = Math.max(limitFrame.top, |
| 900 | Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight)); |
| 901 | final int left = Math.max(limitFrame.left + minVisibleWidth - width, |
| 902 | Math.min(mFrame.left, limitFrame.right - minVisibleWidth)); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 903 | mFrame.set(left, top, left + width, top + height); |
| 904 | mContentFrame.set(mFrame); |
| 905 | mVisibleFrame.set(mContentFrame); |
| 906 | mStableFrame.set(mContentFrame); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 907 | } else if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 908 | dc.getDockedDividerController().positionDockedStackedDivider(mFrame); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 909 | mContentFrame.set(mFrame); |
| 910 | if (!mFrame.equals(mLastFrame)) { |
| 911 | mMovedByResize = true; |
Filip Gruszczynski | ae10080 | 2015-11-11 15:58:03 -0800 | [diff] [blame] | 912 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 913 | } else { |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 914 | mContentFrame.set(Math.max(mContentFrame.left, mFrame.left), |
| 915 | Math.max(mContentFrame.top, mFrame.top), |
| 916 | Math.min(mContentFrame.right, mFrame.right), |
| 917 | Math.min(mContentFrame.bottom, mFrame.bottom)); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 918 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 919 | mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left), |
| 920 | Math.max(mVisibleFrame.top, mFrame.top), |
| 921 | Math.min(mVisibleFrame.right, mFrame.right), |
| 922 | Math.min(mVisibleFrame.bottom, mFrame.bottom)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 923 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 924 | mStableFrame.set(Math.max(mStableFrame.left, mFrame.left), |
| 925 | Math.max(mStableFrame.top, mFrame.top), |
| 926 | Math.min(mStableFrame.right, mFrame.right), |
| 927 | Math.min(mStableFrame.bottom, mFrame.bottom)); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 928 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 929 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 930 | if (inFullscreenContainer && !windowsAreFloating) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 931 | // Windows that are not fullscreen can be positioned outside of the display frame, |
| 932 | // but that is not a reason to provide them with overscan insets. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 933 | mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0), |
| 934 | Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0), |
| 935 | Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0), |
| 936 | Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0)); |
Filip Gruszczynski | 01ef404d5 | 2016-01-28 18:14:27 -0800 | [diff] [blame] | 937 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 938 | |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 939 | if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 940 | // For the docked divider, we calculate the stable insets like a full-screen window |
| 941 | // so it can use it to calculate the snap positions. |
| 942 | mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0), |
| 943 | Math.max(mStableFrame.top - mDisplayFrame.top, 0), |
| 944 | Math.max(mDisplayFrame.right - mStableFrame.right, 0), |
| 945 | Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0)); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 946 | |
| 947 | // The divider doesn't care about insets in any case, so set it to empty so we don't |
| 948 | // trigger a relayout when moving it. |
| 949 | mContentInsets.setEmpty(); |
| 950 | mVisibleInsets.setEmpty(); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 951 | } else { |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 952 | getDisplayContent().getLogicalDisplayRect(mTmpRect); |
Andrii Kulian | a9d168c | 2016-03-23 13:19:32 -0700 | [diff] [blame] | 953 | // Override right and/or bottom insets in case if the frame doesn't fit the screen in |
| 954 | // non-fullscreen mode. |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 955 | boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer |
| 956 | && mFrame.right > mTmpRect.right; |
| 957 | boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer |
| 958 | && mFrame.bottom > mTmpRect.bottom; |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 959 | mContentInsets.set(mContentFrame.left - mFrame.left, |
| 960 | mContentFrame.top - mFrame.top, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 961 | overrideRightInset ? mTmpRect.right - mContentFrame.right |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 962 | : mFrame.right - mContentFrame.right, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 963 | overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 964 | : mFrame.bottom - mContentFrame.bottom); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 965 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 966 | mVisibleInsets.set(mVisibleFrame.left - mFrame.left, |
| 967 | mVisibleFrame.top - mFrame.top, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 968 | overrideRightInset ? mTmpRect.right - mVisibleFrame.right |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 969 | : mFrame.right - mVisibleFrame.right, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 970 | overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 971 | : mFrame.bottom - mVisibleFrame.bottom); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 972 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 973 | mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0), |
| 974 | Math.max(mStableFrame.top - mFrame.top, 0), |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 975 | overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0) |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 976 | : Math.max(mFrame.right - mStableFrame.right, 0), |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 977 | overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0) |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 978 | : Math.max(mFrame.bottom - mStableFrame.bottom, 0)); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 979 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 980 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 981 | // Offset the actual frame by the amount layout frame is off. |
| 982 | mFrame.offset(-layoutXDiff, -layoutYDiff); |
| 983 | mCompatFrame.offset(-layoutXDiff, -layoutYDiff); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 984 | mContentFrame.offset(-layoutXDiff, -layoutYDiff); |
| 985 | mVisibleFrame.offset(-layoutXDiff, -layoutYDiff); |
| 986 | mStableFrame.offset(-layoutXDiff, -layoutYDiff); |
| 987 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 988 | mCompatFrame.set(mFrame); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 989 | if (mEnforceSizeCompat) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 990 | // If there is a size compatibility scale being applied to the |
| 991 | // window, we need to apply this to its insets so that they are |
| 992 | // reported to the app in its coordinate space. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 993 | mOverscanInsets.scale(mInvGlobalScale); |
| 994 | mContentInsets.scale(mInvGlobalScale); |
| 995 | mVisibleInsets.scale(mInvGlobalScale); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 996 | mStableInsets.scale(mInvGlobalScale); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 997 | mOutsets.scale(mInvGlobalScale); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 998 | |
| 999 | // Also the scaled frame that we report to the app needs to be |
| 1000 | // adjusted to be in its coordinate space. |
| 1001 | mCompatFrame.scale(mInvGlobalScale); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1004 | if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1005 | final DisplayContent displayContent = getDisplayContent(); |
| 1006 | if (displayContent != null) { |
| 1007 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 1008 | getDisplayContent().mWallpaperController.updateWallpaperOffset( |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 1009 | this, displayInfo.logicalWidth, displayInfo.logicalHeight, false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1010 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1013 | if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG, |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 1014 | "Resolving (mRequestedWidth=" |
| 1015 | + mRequestedWidth + ", mRequestedheight=" |
| 1016 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 1017 | + "): frame=" + mFrame.toShortString() |
| 1018 | + " ci=" + mContentInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1019 | + " vi=" + mVisibleInsets.toShortString() |
Andrii Kulian | a9d168c | 2016-03-23 13:19:32 -0700 | [diff] [blame] | 1020 | + " si=" + mStableInsets.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1021 | + " of=" + mOutsets.toShortString()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1024 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1025 | public Rect getFrameLw() { |
| 1026 | return mFrame; |
| 1027 | } |
| 1028 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1029 | @Override |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 1030 | public Point getShownPositionLw() { |
| 1031 | return mShownPosition; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1032 | } |
| 1033 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1034 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1035 | public Rect getDisplayFrameLw() { |
| 1036 | return mDisplayFrame; |
| 1037 | } |
| 1038 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1039 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1040 | public Rect getOverscanFrameLw() { |
| 1041 | return mOverscanFrame; |
| 1042 | } |
| 1043 | |
| 1044 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1045 | public Rect getContentFrameLw() { |
| 1046 | return mContentFrame; |
| 1047 | } |
| 1048 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1049 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1050 | public Rect getVisibleFrameLw() { |
| 1051 | return mVisibleFrame; |
| 1052 | } |
| 1053 | |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 1054 | Rect getStableFrameLw() { |
| 1055 | return mStableFrame; |
| 1056 | } |
| 1057 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1058 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1059 | public boolean getGivenInsetsPendingLw() { |
| 1060 | return mGivenInsetsPending; |
| 1061 | } |
| 1062 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1063 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1064 | public Rect getGivenContentInsetsLw() { |
| 1065 | return mGivenContentInsets; |
| 1066 | } |
| 1067 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1068 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1069 | public Rect getGivenVisibleInsetsLw() { |
| 1070 | return mGivenVisibleInsets; |
| 1071 | } |
| 1072 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1073 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1074 | public WindowManager.LayoutParams getAttrs() { |
| 1075 | return mAttrs; |
| 1076 | } |
| 1077 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1078 | @Override |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1079 | public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1080 | return getDisplayContent().getNeedsMenu(this, bottom); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1083 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1084 | public int getSystemUiVisibility() { |
| 1085 | return mSystemUiVisibility; |
| 1086 | } |
| 1087 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1088 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1089 | public int getSurfaceLayer() { |
| 1090 | return mLayer; |
| 1091 | } |
| 1092 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1093 | @Override |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1094 | public int getBaseType() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 1095 | return getTopParentWindow().mAttrs.type; |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1099 | public IApplicationToken getAppToken() { |
| 1100 | return mAppToken != null ? mAppToken.appToken : null; |
| 1101 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1102 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1103 | @Override |
| 1104 | public boolean isVoiceInteraction() { |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 1105 | return mAppToken != null && mAppToken.mVoiceInteraction; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1108 | boolean setReportResizeHints() { |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1109 | mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets); |
| 1110 | mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets); |
| 1111 | mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1112 | mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1113 | mOutsetsChanged |= !mLastOutsets.equals(mOutsets); |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1114 | mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) || |
| 1115 | (mLastFrame.height() != mFrame.height()); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1116 | return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1117 | || mOutsetsChanged || mFrameSizeChanged; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1120 | /** |
| 1121 | * Adds the window to the resizing list if any of the parameters we use to track the window |
| 1122 | * dimensions or insets have changed. |
| 1123 | */ |
| 1124 | void updateResizingWindowIfNeeded() { |
| 1125 | final WindowStateAnimator winAnimator = mWinAnimator; |
| 1126 | if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) { |
| 1127 | return; |
| 1128 | } |
| 1129 | |
| 1130 | final Task task = getTask(); |
| 1131 | // In the case of stack bound animations, the window frames will update (unlike other |
| 1132 | // animations which just modify various transformation properties). We don't want to |
| 1133 | // notify the client of frame changes in this case. Not only is it a lot of churn, but |
| 1134 | // the frame may not correspond to the surface size or the onscreen area at various |
| 1135 | // phases in the animation, and the client will become sad and confused. |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1136 | if (task != null && task.mStack.isAnimatingBounds()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1137 | return; |
| 1138 | } |
| 1139 | |
| 1140 | setReportResizeHints(); |
| 1141 | boolean configChanged = isConfigChanged(); |
| 1142 | if (DEBUG_CONFIGURATION && configChanged) { |
| 1143 | Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration()); |
| 1144 | } |
| 1145 | |
| 1146 | final boolean dragResizingChanged = isDragResizeChanged() |
| 1147 | && !isDragResizingChangeReported(); |
| 1148 | |
| 1149 | if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged |
| 1150 | + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame |
| 1151 | + " frame=" + mFrame); |
| 1152 | |
| 1153 | // We update mLastFrame always rather than in the conditional with the last inset |
| 1154 | // variables, because mFrameSizeChanged only tracks the width and height changing. |
| 1155 | mLastFrame.set(mFrame); |
| 1156 | |
| 1157 | if (mContentInsetsChanged |
| 1158 | || mVisibleInsetsChanged |
| 1159 | || winAnimator.mSurfaceResized |
| 1160 | || mOutsetsChanged |
| 1161 | || mFrameSizeChanged |
| 1162 | || configChanged |
| 1163 | || dragResizingChanged |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1164 | || !isResizedWhileNotDragResizingReported() |
| 1165 | || mReportOrientationChanged) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1166 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 1167 | Slog.v(TAG_WM, "Resize reasons for w=" + this + ": " |
| 1168 | + " contentInsetsChanged=" + mContentInsetsChanged |
| 1169 | + " " + mContentInsets.toShortString() |
| 1170 | + " visibleInsetsChanged=" + mVisibleInsetsChanged |
| 1171 | + " " + mVisibleInsets.toShortString() |
| 1172 | + " stableInsetsChanged=" + mStableInsetsChanged |
| 1173 | + " " + mStableInsets.toShortString() |
| 1174 | + " outsetsChanged=" + mOutsetsChanged |
| 1175 | + " " + mOutsets.toShortString() |
| 1176 | + " surfaceResized=" + winAnimator.mSurfaceResized |
| 1177 | + " configChanged=" + configChanged |
| 1178 | + " dragResizingChanged=" + dragResizingChanged |
| 1179 | + " resizedWhileNotDragResizingReported=" |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1180 | + isResizedWhileNotDragResizingReported() |
| 1181 | + " reportOrientationChanged=" + mReportOrientationChanged); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | // If it's a dead window left on screen, and the configuration changed, there is nothing |
| 1185 | // we can do about it. Remove the window now. |
| 1186 | if (mAppToken != null && mAppDied) { |
| 1187 | mAppToken.removeDeadWindows(); |
| 1188 | return; |
| 1189 | } |
| 1190 | |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 1191 | updateLastInsetValues(); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1192 | mService.makeWindowFreezingScreenIfNeededLocked(this); |
| 1193 | |
| 1194 | // If the orientation is changing, or we're starting or ending a drag resizing action, |
| 1195 | // then we need to hold off on unfreezing the display until this window has been |
| 1196 | // redrawn; to do that, we need to go through the process of getting informed by the |
| 1197 | // application when it has finished drawing. |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1198 | if (getOrientationChanging() || dragResizingChanged |
| 1199 | || isResizedWhileNotDragResizing()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1200 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) { |
| 1201 | Slog.v(TAG_WM, "Orientation or resize start waiting for draw" |
| 1202 | + ", mDrawState=DRAW_PENDING in " + this |
| 1203 | + ", surfaceController " + winAnimator.mSurfaceController); |
| 1204 | } |
| 1205 | winAnimator.mDrawState = DRAW_PENDING; |
| 1206 | if (mAppToken != null) { |
| 1207 | mAppToken.clearAllDrawn(); |
| 1208 | } |
| 1209 | } |
| 1210 | if (!mService.mResizingWindows.contains(this)) { |
| 1211 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this); |
| 1212 | mService.mResizingWindows.add(this); |
| 1213 | } |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1214 | } else if (getOrientationChanging()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1215 | if (isDrawnLw()) { |
| 1216 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in " |
| 1217 | + this + ", surfaceController " + winAnimator.mSurfaceController); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1218 | setOrientationChanging(false); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1219 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 1220 | - mService.mDisplayFreezeTime); |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1225 | boolean getOrientationChanging() { |
| 1226 | // In addition to the local state flag, we must also consider the difference in the last |
| 1227 | // reported configuration vs. the current state. If the client code has not been informed of |
| 1228 | // the change, logic dependent on having finished processing the orientation, such as |
| 1229 | // unfreezing, could be improperly triggered. |
| 1230 | // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as |
| 1231 | // this is not necessarily what the client has processed yet. Find a |
| 1232 | // better indicator consistent with the client. |
Robert Carr | 926643f | 2017-08-02 12:01:12 -0700 | [diff] [blame] | 1233 | return (mOrientationChanging || (isVisible() |
| 1234 | && getConfiguration().orientation != mLastReportedConfiguration.orientation)) |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 1235 | && !mSeamlesslyRotated |
| 1236 | && !mOrientationChangeTimedOut; |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | void setOrientationChanging(boolean changing) { |
| 1240 | mOrientationChanging = changing; |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 1241 | mOrientationChangeTimedOut = false; |
| 1242 | } |
| 1243 | |
| 1244 | void orientationChangeTimedOut() { |
| 1245 | mOrientationChangeTimedOut = true; |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1248 | DisplayContent getDisplayContent() { |
| 1249 | return mToken.getDisplayContent(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1252 | DisplayInfo getDisplayInfo() { |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 1253 | final DisplayContent displayContent = getDisplayContent(); |
| 1254 | return displayContent != null ? displayContent.getDisplayInfo() : null; |
| 1255 | } |
| 1256 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1257 | @Override |
| 1258 | public int getDisplayId() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1259 | final DisplayContent displayContent = getDisplayContent(); |
| 1260 | if (displayContent == null) { |
| 1261 | return -1; |
| 1262 | } |
| 1263 | return displayContent.getDisplayId(); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1266 | Task getTask() { |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 1267 | return mAppToken != null ? mAppToken.getTask() : null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | TaskStack getStack() { |
| 1271 | Task task = getTask(); |
| 1272 | if (task != null) { |
| 1273 | if (task.mStack != null) { |
| 1274 | return task.mStack; |
Craig Mautner | f06b8c1 | 2013-04-18 14:27:28 -0700 | [diff] [blame] | 1275 | } |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1276 | } |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1277 | // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still |
| 1278 | // associate them with some stack to enable dimming. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1279 | final DisplayContent dc = getDisplayContent(); |
| 1280 | return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1283 | /** |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1284 | * Retrieves the visible bounds of the window. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1285 | * @param bounds The rect which gets the bounds. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1286 | */ |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1287 | void getVisibleBounds(Rect bounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1288 | final Task task = getTask(); |
| 1289 | boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds(); |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1290 | bounds.setEmpty(); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1291 | mTmpRect.setEmpty(); |
| 1292 | if (intersectWithStackBounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1293 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1294 | if (stack != null) { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1295 | stack.getDimBounds(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1296 | } else { |
| 1297 | intersectWithStackBounds = false; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1298 | } |
| 1299 | } |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1300 | |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1301 | bounds.set(mVisibleFrame); |
| 1302 | if (intersectWithStackBounds) { |
| 1303 | bounds.intersect(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1306 | if (bounds.isEmpty()) { |
| 1307 | bounds.set(mFrame); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1308 | if (intersectWithStackBounds) { |
| 1309 | bounds.intersect(mTmpRect); |
| 1310 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1311 | return; |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1312 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1315 | public long getInputDispatchingTimeoutNanos() { |
| 1316 | return mAppToken != null |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 1317 | ? mAppToken.mInputDispatchingTimeoutNanos |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1318 | : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 1319 | } |
| 1320 | |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1321 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1322 | public boolean hasAppShownWindows() { |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 1323 | return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1324 | } |
| 1325 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1326 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 1327 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 1328 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 1329 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 1330 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 1331 | return true; |
| 1332 | } |
| 1333 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1334 | void prelayout() { |
| 1335 | if (mEnforceSizeCompat) { |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1336 | mGlobalScale = getDisplayContent().mCompatibleScreenScale; |
| 1337 | mInvGlobalScale = 1 / mGlobalScale; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1338 | } else { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1339 | mGlobalScale = mInvGlobalScale = 1; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1343 | @Override |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1344 | boolean hasContentToDisplay() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1345 | // If we're animating with a saved surface, we're already visible. |
| 1346 | // Return true so that the alpha doesn't get cleared. |
| 1347 | if (!mAppFreezing && isDrawnLw() |
| 1348 | && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface() |
| 1349 | || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) { |
| 1350 | return true; |
| 1351 | } |
| 1352 | |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1353 | return super.hasContentToDisplay(); |
| 1354 | } |
| 1355 | |
| 1356 | @Override |
| 1357 | boolean isVisible() { |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1358 | return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1361 | /** |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1362 | * @return True if the window would be visible if we'd ignore policy visibility, false |
| 1363 | * otherwise. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1364 | */ |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1365 | boolean wouldBeVisibleIfPolicyIgnored() { |
Jorim Jaggi | 43530c9 | 2017-05-18 01:53:56 +0200 | [diff] [blame] | 1366 | return mHasSurface && !isParentWindowHidden() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1367 | && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1368 | } |
| 1369 | |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1370 | @Override |
| 1371 | public boolean isVisibleLw() { |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1372 | return isVisible(); |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1376 | * Is this window visible, ignoring its app token? It is not visible if there is no surface, |
| 1377 | * or we are in the process of running an exit animation that will remove the surface. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1378 | */ |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1379 | // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this? |
| 1380 | boolean isWinVisibleLw() { |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1381 | return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1382 | && isVisible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1386 | * The same as isVisible(), but follows the current hidden state of the associated app token, |
| 1387 | * not the pending requested hidden state. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1388 | */ |
| 1389 | boolean isVisibleNow() { |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1390 | return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1391 | && isVisible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** |
| 1395 | * Can this window possibly be a drag/drop target? The test here is |
| 1396 | * a combination of the above "visible now" with the check that the |
| 1397 | * Input Manager uses when discarding windows from input consideration. |
| 1398 | */ |
| 1399 | boolean isPotentialDragTarget() { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1400 | return isVisibleNow() && !mRemoved |
| 1401 | && mInputChannel != null && mInputWindowHandle != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | /** |
| 1405 | * Same as isVisible(), but we also count it as visible between the |
| 1406 | * call to IWindowSession.add() and the first relayout(). |
| 1407 | */ |
| 1408 | boolean isVisibleOrAdding() { |
| 1409 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 1410 | return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1411 | && mPolicyVisibility && !isParentWindowHidden() |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1412 | && (atoken == null || !atoken.hiddenRequested) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1413 | && !mAnimatingExit && !mDestroying; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | /** |
| 1417 | * Is this window currently on-screen? It is on-screen either if it |
| 1418 | * is visible or it is currently running an animation before no longer |
| 1419 | * being visible. |
| 1420 | */ |
| 1421 | boolean isOnScreen() { |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 1422 | if (!mHasSurface || mDestroying || !mPolicyVisibility) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1423 | return false; |
| 1424 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1425 | final AppWindowToken atoken = mAppToken; |
| 1426 | if (atoken != null) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1427 | return ((!isParentWindowHidden() && !atoken.hiddenRequested) |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1428 | || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1429 | } |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1430 | return !isParentWindowHidden() || mWinAnimator.mAnimation != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | /** |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1434 | * Whether this window's drawn state might affect the drawn states of the app token. |
| 1435 | * |
| 1436 | * @param visibleOnly Whether we should consider only the windows that's currently |
| 1437 | * visible in layout. If true, windows that has not relayout to VISIBLE |
| 1438 | * would always return false. |
| 1439 | * |
| 1440 | * @return true if the window should be considered while evaluating allDrawn flags. |
| 1441 | */ |
| 1442 | boolean mightAffectAllDrawn(boolean visibleOnly) { |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 1443 | final boolean isViewVisible = (mAppToken == null || !mAppToken.isClientHidden()) |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 1444 | && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed; |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 1445 | return (isOnScreen() && (!visibleOnly || isViewVisible) |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 1446 | || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION |
| 1447 | || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION) |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1448 | && !mAnimatingExit && !mDestroying; |
| 1449 | } |
| 1450 | |
| 1451 | /** |
| 1452 | * Whether this window is "interesting" when evaluating allDrawn. If it's interesting, |
| 1453 | * it must be drawn before allDrawn can become true. |
| 1454 | */ |
| 1455 | boolean isInteresting() { |
| 1456 | return mAppToken != null && !mAppDied |
| 1457 | && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing); |
| 1458 | } |
| 1459 | |
| 1460 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1461 | * Like isOnScreen(), but we don't return true if the window is part |
| 1462 | * of a transition that has not yet been started. |
| 1463 | */ |
| 1464 | boolean isReadyForDisplay() { |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1465 | if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1466 | return false; |
| 1467 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1468 | return mHasSurface && mPolicyVisibility && !mDestroying |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1469 | && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1470 | || mWinAnimator.mAnimation != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1471 | || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null))); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1472 | } |
| 1473 | |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1474 | // TODO: Another visibility method that was added late in the release to minimize risk. |
| 1475 | @Override |
| 1476 | public boolean canAffectSystemUiFlags() { |
| 1477 | final boolean shown = mWinAnimator.getShown(); |
Jorim Jaggi | c0c9324 | 2017-08-04 16:05:02 +0200 | [diff] [blame] | 1478 | |
| 1479 | // We only consider the app to be exiting when the animation has started. After the app |
| 1480 | // transition is executed the windows are marked exiting before the new windows have been |
| 1481 | // shown. Thus, wait considering a window to be exiting after the animation has actually |
| 1482 | // started. |
| 1483 | final boolean appAnimationStarting = mAppToken != null |
| 1484 | && mAppToken.mAppAnimator.isAnimationStarting(); |
| 1485 | final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting() |
| 1486 | && !appAnimationStarting); |
| 1487 | final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting; |
| 1488 | |
| 1489 | final boolean exiting = exitingSelf || mDestroying || appExiting; |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1490 | final boolean translucent = mAttrs.alpha == 0.0f; |
| 1491 | return shown && !exiting && !translucent; |
| 1492 | } |
| 1493 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1494 | /** |
| 1495 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 1496 | * been drawn. |
| 1497 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1498 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1499 | public boolean isDisplayedLw() { |
| 1500 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 1501 | return isDrawnLw() && mPolicyVisibility |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1502 | && ((!isParentWindowHidden() && |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1503 | (atoken == null || !atoken.hiddenRequested)) |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1504 | || mWinAnimator.mAnimating |
| 1505 | || (atoken != null && atoken.mAppAnimator.animation != null)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1506 | } |
| 1507 | |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1508 | /** |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1509 | * Return true if this window or its app token is currently animating. |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1510 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1511 | @Override |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1512 | public boolean isAnimatingLw() { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1513 | return mWinAnimator.mAnimation != null |
| 1514 | || (mAppToken != null && mAppToken.mAppAnimator.animation != null); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1517 | @Override |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1518 | public boolean isGoneForLayoutLw() { |
| 1519 | final AppWindowToken atoken = mAppToken; |
| 1520 | return mViewVisibility == View.GONE |
| 1521 | || !mRelayoutCalled |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1522 | || (atoken == null && mToken.hidden) |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 1523 | || (atoken != null && atoken.hiddenRequested) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1524 | || isParentWindowHidden() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1525 | || (mAnimatingExit && !isAnimatingLw()) |
Craig Mautner | 0e415c6 | 2013-04-29 16:10:58 -0700 | [diff] [blame] | 1526 | || mDestroying; |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1527 | } |
| 1528 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1529 | /** |
| 1530 | * Returns true if the window has a surface that it has drawn a |
| 1531 | * complete UI in to. |
| 1532 | */ |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1533 | public boolean isDrawFinishedLw() { |
| 1534 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1535 | (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING |
| 1536 | || mWinAnimator.mDrawState == READY_TO_SHOW |
| 1537 | || mWinAnimator.mDrawState == HAS_DRAWN); |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Returns true if the window has a surface that it has drawn a |
| 1542 | * complete UI in to. |
| 1543 | */ |
Adrian Roos | 76d2fe4 | 2015-07-09 14:54:08 -0700 | [diff] [blame] | 1544 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1545 | public boolean isDrawnLw() { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1546 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1547 | (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | /** |
| 1551 | * Return true if the window is opaque and fully drawn. This indicates |
| 1552 | * it may obscure windows behind it. |
| 1553 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1554 | private boolean isOpaqueDrawn() { |
Chong Zhang | 66bf071d | 2016-02-05 14:42:36 -0800 | [diff] [blame] | 1555 | // When there is keyguard, wallpaper could be placed over the secure app |
| 1556 | // window but invisible. We need to check wallpaper visibility explicitly |
| 1557 | // to determine if it's occluding apps. |
| 1558 | return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE) |
| 1559 | || (mIsWallpaper && mWallpaperVisible)) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1560 | && isDrawnLw() && mWinAnimator.mAnimation == null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1561 | && (mAppToken == null || mAppToken.mAppAnimator.animation == null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1562 | } |
| 1563 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1564 | @Override |
| 1565 | void onMovedByResize() { |
| 1566 | if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1567 | mMovedByResize = true; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1568 | super.onMovedByResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) { |
| 1572 | boolean changed = false; |
| 1573 | |
| 1574 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1575 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1576 | changed |= c.onAppVisibilityChanged(visible, runningAppAnimation); |
| 1577 | } |
| 1578 | |
| 1579 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 1580 | // Starting window that's exiting will be removed when the animation finishes. |
| 1581 | // Mark all relevant flags for that onExitAnimationDone will proceed all the way |
| 1582 | // to actually remove it. |
| 1583 | if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) { |
| 1584 | mAnimatingExit = true; |
| 1585 | mRemoveOnExit = true; |
| 1586 | mWindowRemovalAllowed = true; |
| 1587 | } |
| 1588 | return changed; |
| 1589 | } |
| 1590 | |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 1591 | // Next up we will notify the client that it's visibility has changed. |
| 1592 | // We need to prevent it from destroying child surfaces until |
| 1593 | // the animation has finished. |
| 1594 | if (!visible && isVisibleNow()) { |
| 1595 | mWinAnimator.detachChildren(); |
| 1596 | } |
| 1597 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1598 | if (visible != isVisibleNow()) { |
| 1599 | if (!runningAppAnimation) { |
| 1600 | final AccessibilityController accessibilityController = |
| 1601 | mService.mAccessibilityController; |
| 1602 | final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT; |
| 1603 | mWinAnimator.applyAnimationLocked(winTransit, visible); |
| 1604 | //TODO (multidisplay): Magnification is supported only for the default |
| 1605 | if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) { |
| 1606 | accessibilityController.onWindowTransitionLocked(this, winTransit); |
| 1607 | } |
| 1608 | } |
| 1609 | changed = true; |
| 1610 | setDisplayLayoutNeeded(); |
| 1611 | } |
| 1612 | |
| 1613 | return changed; |
| 1614 | } |
| 1615 | |
| 1616 | boolean onSetAppExiting() { |
| 1617 | final DisplayContent displayContent = getDisplayContent(); |
| 1618 | boolean changed = false; |
| 1619 | |
| 1620 | if (isVisibleNow()) { |
| 1621 | mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false); |
| 1622 | //TODO (multidisplay): Magnification is supported only for the default |
| 1623 | if (mService.mAccessibilityController != null && isDefaultDisplay()) { |
| 1624 | mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT); |
| 1625 | } |
| 1626 | changed = true; |
| 1627 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1628 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1633 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1634 | changed |= c.onSetAppExiting(); |
| 1635 | } |
| 1636 | |
| 1637 | return changed; |
| 1638 | } |
| 1639 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1640 | @Override |
| 1641 | void onResize() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1642 | // Some windows won't go through the resizing process, if they don't have a surface, so |
| 1643 | // destroy all saved surfaces here. |
| 1644 | destroySavedSurface(); |
| 1645 | |
| 1646 | final ArrayList<WindowState> resizingWindows = mService.mResizingWindows; |
| 1647 | if (mHasSurface && !resizingWindows.contains(this)) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1648 | if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1649 | resizingWindows.add(this); |
| 1650 | |
| 1651 | // If we are not drag resizing, force recreating of a new surface so updating |
| 1652 | // the content and positioning that surface will be in sync. |
| 1653 | // |
| 1654 | // As we use this flag as a hint to freeze surface boundary updates, we'd like to only |
| 1655 | // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could |
| 1656 | // appear to not be drag resizing while they resize, but we'd still like to manipulate |
| 1657 | // their frame to update crop, etc... |
| 1658 | // |
| 1659 | // Anyway we don't need to synchronize position and content updates for these |
| 1660 | // windows since they aren't at the base layer and could be moved around anyway. |
| 1661 | if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION && |
Robert Carr | 8f0a3ad | 2017-02-15 19:30:28 -0800 | [diff] [blame] | 1662 | !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() && |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1663 | !getTask().inPinnedWorkspace()) { |
| 1664 | setResizedWhileNotDragResizing(true); |
| 1665 | } |
| 1666 | } |
| 1667 | if (isGoneForLayoutLw()) { |
| 1668 | mResizedWhileGone = true; |
| 1669 | } |
| 1670 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1671 | super.onResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | void onUnfreezeBounds() { |
| 1675 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1676 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1677 | c.onUnfreezeBounds(); |
| 1678 | } |
| 1679 | |
| 1680 | if (!mHasSurface) { |
| 1681 | return; |
| 1682 | } |
| 1683 | |
| 1684 | mLayoutNeeded = true; |
| 1685 | setDisplayLayoutNeeded(); |
| 1686 | if (!mService.mResizingWindows.contains(this)) { |
| 1687 | mService.mResizingWindows.add(this); |
| 1688 | } |
| 1689 | } |
| 1690 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1691 | /** |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1692 | * If the window has moved due to its containing content frame changing, then notify the |
| 1693 | * listeners and optionally animate it. Simply checking a change of position is not enough, |
| 1694 | * because being move due to dock divider is not a trigger for animation. |
| 1695 | */ |
| 1696 | void handleWindowMovedIfNeeded() { |
| 1697 | if (!hasMoved()) { |
| 1698 | return; |
| 1699 | } |
| 1700 | |
| 1701 | // Frame has moved, containing content frame has also moved, and we're not currently |
| 1702 | // animating... let's do something. |
| 1703 | final int left = mFrame.left; |
| 1704 | final int top = mFrame.top; |
| 1705 | final Task task = getTask(); |
| 1706 | final boolean adjustedForMinimizedDockOrIme = task != null |
| 1707 | && (task.mStack.isAdjustedForMinimizedDockedStack() |
| 1708 | || task.mStack.isAdjustedForIme()); |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 1709 | if (mService.okToAnimate() |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1710 | && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0 |
| 1711 | && !isDragResizing() && !adjustedForMinimizedDockOrIme |
| 1712 | && (task == null || getTask().mStack.hasMovementAnimations()) |
| 1713 | && !mWinAnimator.mLastHidden) { |
| 1714 | mWinAnimator.setMoveAnimation(left, top); |
| 1715 | } |
| 1716 | |
| 1717 | //TODO (multidisplay): Accessibility supported only for the default display. |
| 1718 | if (mService.mAccessibilityController != null |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1719 | && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1720 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
| 1721 | } |
| 1722 | |
| 1723 | try { |
| 1724 | mClient.moved(left, top); |
| 1725 | } catch (RemoteException e) { |
| 1726 | } |
| 1727 | mMovedByResize = false; |
| 1728 | } |
| 1729 | |
| 1730 | /** |
Craig Mautner | 4557c08 | 2015-04-27 13:07:40 -0700 | [diff] [blame] | 1731 | * Return whether this window has moved. (Only makes |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1732 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 1733 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1734 | private boolean hasMoved() { |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 1735 | return mHasSurface && (mContentChanged || mMovedByResize) |
Robert Carr | c67c2a9 | 2016-09-22 13:25:45 -0700 | [diff] [blame] | 1736 | && !mAnimatingExit |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 1737 | && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1738 | && (!mIsChildWindow || !getParentWindow().hasMoved()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1739 | } |
| 1740 | |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1741 | boolean isObscuringDisplay() { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1742 | Task task = getTask(); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1743 | if (task != null && task.mStack != null && !task.mStack.fillsParent()) { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1744 | return false; |
| 1745 | } |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1746 | return isOpaqueDrawn() && fillsDisplay(); |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1749 | boolean fillsDisplay() { |
| 1750 | final DisplayInfo displayInfo = getDisplayInfo(); |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1751 | return mFrame.left <= 0 && mFrame.top <= 0 |
| 1752 | && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1753 | } |
| 1754 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 1755 | /** Returns true if last applied config was not yet requested by client. */ |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1756 | boolean isConfigChanged() { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 1757 | return !mLastReportedConfiguration.equals(getConfiguration()); |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1760 | void onWindowReplacementTimeout() { |
| 1761 | if (mWillReplaceWindow) { |
| 1762 | // Since the window already timed out, remove it immediately now. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1763 | // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1764 | // delays removal on certain conditions, which will leave the stale window in the |
| 1765 | // stack and marked mWillReplaceWindow=false, so the window will never be removed. |
| 1766 | // |
| 1767 | // Also removes child windows. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1768 | removeImmediately(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1769 | } else { |
| 1770 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1771 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1772 | c.onWindowReplacementTimeout(); |
| 1773 | } |
| 1774 | } |
| 1775 | } |
| 1776 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1777 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1778 | void forceWindowsScaleableInTransaction(boolean force) { |
| 1779 | if (mWinAnimator != null && mWinAnimator.hasSurface()) { |
| 1780 | mWinAnimator.mSurfaceController.forceScaleableInTransaction(force); |
| 1781 | } |
| 1782 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1783 | super.forceWindowsScaleableInTransaction(force); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1786 | @Override |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1787 | void removeImmediately() { |
| 1788 | super.removeImmediately(); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1789 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1790 | if (mRemoved) { |
| 1791 | // Nothing to do. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1792 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1793 | "WS.removeImmediately: " + this + " Already removed..."); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1794 | return; |
| 1795 | } |
| 1796 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1797 | mRemoved = true; |
| 1798 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1799 | mWillReplaceWindow = false; |
| 1800 | if (mReplacementWindow != null) { |
| 1801 | mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false; |
| 1802 | } |
| 1803 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1804 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1805 | if (mService.mInputMethodTarget == this) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1806 | dc.computeImeTarget(true /* updateImeTarget */); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | final int type = mAttrs.type; |
| 1810 | if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1811 | dc.mTapExcludedWindows.remove(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1812 | } |
| 1813 | mPolicy.removeWindowLw(this); |
| 1814 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1815 | disposeInputChannel(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1816 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1817 | mWinAnimator.destroyDeferredSurfaceLocked(); |
| 1818 | mWinAnimator.destroySurfaceLocked(); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 1819 | mSession.windowRemovedLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1820 | try { |
| 1821 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 1822 | } catch (RuntimeException e) { |
| 1823 | // Ignore if it has already been removed (usually because |
| 1824 | // we are doing this as part of processing a death note.) |
| 1825 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1826 | |
| 1827 | mService.postWindowRemoveCleanupLocked(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1828 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1829 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1830 | @Override |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1831 | void removeIfPossible() { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1832 | super.removeIfPossible(); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1833 | removeIfPossible(false /*keepVisibleDeadWindow*/); |
| 1834 | } |
| 1835 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1836 | private void removeIfPossible(boolean keepVisibleDeadWindow) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1837 | mWindowRemovalAllowed = true; |
| 1838 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, |
| 1839 | "removeIfPossible: " + this + " callers=" + Debug.getCallers(5)); |
| 1840 | |
| 1841 | final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 1842 | if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM, |
| 1843 | "Starting window removed " + this); |
| 1844 | |
| 1845 | if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus) |
| 1846 | Slog.v(TAG_WM, "Remove " + this + " client=" |
| 1847 | + Integer.toHexString(System.identityHashCode(mClient.asBinder())) |
| 1848 | + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers=" |
| 1849 | + Debug.getCallers(5)); |
| 1850 | |
| 1851 | final long origId = Binder.clearCallingIdentity(); |
| 1852 | |
| 1853 | disposeInputChannel(); |
| 1854 | |
| 1855 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this |
| 1856 | + ": mSurfaceController=" + mWinAnimator.mSurfaceController |
| 1857 | + " mAnimatingExit=" + mAnimatingExit |
| 1858 | + " mRemoveOnExit=" + mRemoveOnExit |
| 1859 | + " mHasSurface=" + mHasSurface |
| 1860 | + " surfaceShowing=" + mWinAnimator.getShown() |
| 1861 | + " isAnimationSet=" + mWinAnimator.isAnimationSet() |
| 1862 | + " app-animation=" |
| 1863 | + (mAppToken != null ? mAppToken.mAppAnimator.animation : null) |
| 1864 | + " mWillReplaceWindow=" + mWillReplaceWindow |
| 1865 | + " inPendingTransaction=" |
| 1866 | + (mAppToken != null ? mAppToken.inPendingTransaction : false) |
| 1867 | + " mDisplayFrozen=" + mService.mDisplayFrozen |
| 1868 | + " callers=" + Debug.getCallers(6)); |
| 1869 | |
| 1870 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1871 | boolean wasVisible = false; |
| 1872 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1873 | final int displayId = getDisplayId(); |
| 1874 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1875 | // First, see if we need to run an animation. If we do, we have to hold off on removing the |
| 1876 | // window until the animation is done. If the display is frozen, just remove immediately, |
| 1877 | // since the animation wouldn't be seen. |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 1878 | if (mHasSurface && mService.okToAnimate()) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1879 | if (mWillReplaceWindow) { |
| 1880 | // This window is going to be replaced. We need to keep it around until the new one |
| 1881 | // gets added, then we will get rid of this one. |
| 1882 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1883 | "Preserving " + this + " until the new one is " + "added"); |
| 1884 | // TODO: We are overloading mAnimatingExit flag to prevent the window state from |
| 1885 | // been removed. We probably need another flag to indicate that window removal |
| 1886 | // should be deffered vs. overloading the flag that says we are playing an exit |
| 1887 | // animation. |
| 1888 | mAnimatingExit = true; |
| 1889 | mReplacingRemoveRequested = true; |
| 1890 | Binder.restoreCallingIdentity(origId); |
| 1891 | return; |
| 1892 | } |
| 1893 | |
| 1894 | if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) { |
| 1895 | // We started enter animation early with a saved surface, now the app asks to remove |
| 1896 | // this window. If we remove it now and the app is not yet drawn, we'll show a |
| 1897 | // flicker. Delay the removal now until it's really drawn. |
| 1898 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 1899 | "removeWindowLocked: delay removal of " + this + " due to early animation"); |
| 1900 | // Do not set mAnimatingExit to true here, it will cause the surface to be hidden |
| 1901 | // immediately after the enter animation is done. If the app is not yet drawn then |
| 1902 | // it will show up as a flicker. |
| 1903 | setupWindowForRemoveOnExit(); |
| 1904 | Binder.restoreCallingIdentity(origId); |
| 1905 | return; |
| 1906 | } |
| 1907 | // If we are not currently running the exit animation, we need to see about starting one |
| 1908 | wasVisible = isWinVisibleLw(); |
| 1909 | |
| 1910 | if (keepVisibleDeadWindow) { |
| 1911 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1912 | "Not removing " + this + " because app died while it's visible"); |
| 1913 | |
| 1914 | mAppDied = true; |
| 1915 | setDisplayLayoutNeeded(); |
| 1916 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 1917 | |
| 1918 | // Set up a replacement input channel since the app is now dead. |
| 1919 | // We need to catch tapping on the dead window to restart the app. |
| 1920 | openInputChannel(null); |
| 1921 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
| 1922 | |
| 1923 | Binder.restoreCallingIdentity(origId); |
| 1924 | return; |
| 1925 | } |
| 1926 | |
| 1927 | if (wasVisible) { |
| 1928 | final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE; |
| 1929 | |
| 1930 | // Try starting an animation. |
| 1931 | if (mWinAnimator.applyAnimationLocked(transit, false)) { |
| 1932 | mAnimatingExit = true; |
| 1933 | } |
| 1934 | //TODO (multidisplay): Magnification is supported only for the default display. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1935 | if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1936 | mService.mAccessibilityController.onWindowTransitionLocked(this, transit); |
| 1937 | } |
| 1938 | } |
| 1939 | final boolean isAnimating = |
| 1940 | mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation(); |
| 1941 | final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1942 | && mAppToken.isLastWindow(this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1943 | // We delay the removal of a window if it has a showing surface that can be used to run |
| 1944 | // exit animation and it is marked as exiting. |
| 1945 | // Also, If isn't the an animating starting window that is the last window in the app. |
| 1946 | // We allow the removal of the non-animating starting window now as there is no |
| 1947 | // additional window or animation that will trigger its removal. |
| 1948 | if (mWinAnimator.getShown() && mAnimatingExit |
| 1949 | && (!lastWindowIsStartingWindow || isAnimating)) { |
| 1950 | // The exit animation is running or should run... wait for it! |
| 1951 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1952 | "Not removing " + this + " due to exit animation "); |
| 1953 | setupWindowForRemoveOnExit(); |
| 1954 | if (mAppToken != null) { |
| 1955 | mAppToken.updateReportedVisibilityLocked(); |
| 1956 | } |
| 1957 | Binder.restoreCallingIdentity(origId); |
| 1958 | return; |
| 1959 | } |
| 1960 | } |
| 1961 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1962 | removeImmediately(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1963 | // Removing a visible window will effect the computed orientation |
| 1964 | // So just update orientation if needed. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1965 | if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) { |
| 1966 | mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1967 | } |
| 1968 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| 1969 | Binder.restoreCallingIdentity(origId); |
| 1970 | } |
| 1971 | |
| 1972 | private void setupWindowForRemoveOnExit() { |
| 1973 | mRemoveOnExit = true; |
| 1974 | setDisplayLayoutNeeded(); |
| 1975 | // Request a focus update as this window's input channel is already gone. Otherwise |
| 1976 | // we could have no focused window in input manager. |
| 1977 | final boolean focusChanged = mService.updateFocusedWindowLocked( |
| 1978 | UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/); |
| 1979 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 1980 | if (focusChanged) { |
| 1981 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 1982 | } |
| 1983 | } |
| 1984 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 1985 | void setHasSurface(boolean hasSurface) { |
| 1986 | mHasSurface = hasSurface; |
| 1987 | } |
| 1988 | |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1989 | int getAnimLayerAdjustment() { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 1990 | if (mIsImWindow && mService.mInputMethodTarget != null) { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 1991 | final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken; |
| 1992 | if (appToken != null) { |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 1993 | return appToken.getAnimLayerAdjustment(); |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 1994 | } |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1995 | } |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 1996 | |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 1997 | return mToken.getAnimLayerAdjustment(); |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1998 | } |
| 1999 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2000 | int getSpecialWindowAnimLayerAdjustment() { |
| 2001 | int specialAdjustment = 0; |
| 2002 | if (mIsImWindow) { |
| 2003 | specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment; |
| 2004 | } else if (mIsWallpaper) { |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 2005 | specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment(); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | return mLayer + specialAdjustment; |
| 2009 | } |
| 2010 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2011 | boolean canBeImeTarget() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 2012 | if (mIsImWindow) { |
| 2013 | // IME windows can't be IME targets. IME targets are required to be below the IME |
| 2014 | // windows and that wouldn't be possible if the IME window is its own target...silly. |
| 2015 | return false; |
| 2016 | } |
| 2017 | |
Winson Chung | 3d0a74a | 2017-07-12 12:37:19 -0700 | [diff] [blame] | 2018 | final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable(); |
Winson Chung | b154934 | 2017-07-11 09:59:56 -0700 | [diff] [blame] | 2019 | if (!windowsAreFocusable) { |
| 2020 | // This window can't be an IME target if the app's windows should not be focusable. |
| 2021 | return false; |
| 2022 | } |
| 2023 | |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 2024 | final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2025 | final int type = mAttrs.type; |
| 2026 | |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 2027 | // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or |
| 2028 | // both are cleared...and not a starting window. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2029 | if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM) |
| 2030 | && type != TYPE_APPLICATION_STARTING) { |
| 2031 | return false; |
| 2032 | } |
| 2033 | |
| 2034 | if (DEBUG_INPUT_METHOD) { |
| 2035 | Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding()); |
| 2036 | if (!isVisibleOrAdding()) { |
| 2037 | Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController |
| 2038 | + " relayoutCalled=" + mRelayoutCalled |
| 2039 | + " viewVis=" + mViewVisibility |
| 2040 | + " policyVis=" + mPolicyVisibility |
| 2041 | + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim |
| 2042 | + " parentHidden=" + isParentWindowHidden() |
| 2043 | + " exiting=" + mAnimatingExit + " destroying=" + mDestroying); |
| 2044 | if (mAppToken != null) { |
| 2045 | Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested); |
| 2046 | } |
| 2047 | } |
| 2048 | } |
| 2049 | return isVisibleOrAdding(); |
| 2050 | } |
| 2051 | |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 2052 | void scheduleAnimationIfDimming() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2053 | final DisplayContent dc = getDisplayContent(); |
| 2054 | if (dc == null) { |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 2055 | return; |
| 2056 | } |
Jorim Jaggi | 1f83308 | 2017-08-04 18:06:56 +0200 | [diff] [blame] | 2057 | |
| 2058 | // If layout is currently deferred, we want to hold of with updating the layers. |
| 2059 | if (mService.mWindowPlacerLocked.isLayoutDeferred()) { |
| 2060 | return; |
| 2061 | } |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 2062 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2063 | if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) { |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 2064 | // Force an animation pass just to update the mDimLayer layer. |
| 2065 | mService.scheduleAnimationLocked(); |
| 2066 | } |
| 2067 | } |
| 2068 | |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2069 | private final class DeadWindowEventReceiver extends InputEventReceiver { |
| 2070 | DeadWindowEventReceiver(InputChannel inputChannel) { |
| 2071 | super(inputChannel, mService.mH.getLooper()); |
| 2072 | } |
| 2073 | @Override |
Tarandeep Singh | e1cfcf4 | 2017-07-10 18:50:00 -0700 | [diff] [blame] | 2074 | public void onInputEvent(InputEvent event, int displayId) { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2075 | finishInputEvent(event, true); |
| 2076 | } |
| 2077 | } |
| 2078 | /** |
| 2079 | * Dummy event receiver for windows that died visible. |
| 2080 | */ |
| 2081 | private DeadWindowEventReceiver mDeadWindowEventReceiver; |
| 2082 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2083 | void openInputChannel(InputChannel outInputChannel) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2084 | if (mInputChannel != null) { |
| 2085 | throw new IllegalStateException("Window already has an input channel."); |
| 2086 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2087 | String name = getName(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2088 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2089 | mInputChannel = inputChannels[0]; |
| 2090 | mClientChannel = inputChannels[1]; |
| 2091 | mInputWindowHandle.inputChannel = inputChannels[0]; |
| 2092 | if (outInputChannel != null) { |
| 2093 | mClientChannel.transferTo(outInputChannel); |
| 2094 | mClientChannel.dispose(); |
| 2095 | mClientChannel = null; |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2096 | } else { |
| 2097 | // If the window died visible, we setup a dummy input channel, so that taps |
| 2098 | // can still detected by input monitor channel, and we can relaunch the app. |
| 2099 | // Create dummy event receiver that simply reports all events as handled. |
| 2100 | mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2101 | } |
| 2102 | mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2105 | void disposeInputChannel() { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2106 | if (mDeadWindowEventReceiver != null) { |
| 2107 | mDeadWindowEventReceiver.dispose(); |
| 2108 | mDeadWindowEventReceiver = null; |
| 2109 | } |
| 2110 | |
| 2111 | // unregister server channel first otherwise it complains about broken channel |
| 2112 | if (mInputChannel != null) { |
| 2113 | mService.mInputManager.unregisterInputChannel(mInputChannel); |
| 2114 | mInputChannel.dispose(); |
| 2115 | mInputChannel = null; |
| 2116 | } |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2117 | if (mClientChannel != null) { |
| 2118 | mClientChannel.dispose(); |
| 2119 | mClientChannel = null; |
| 2120 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2121 | mInputWindowHandle.inputChannel = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2122 | } |
| 2123 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2124 | void applyDimLayerIfNeeded() { |
Chong Zhang | eb91732 | 2015-11-10 14:05:40 -0800 | [diff] [blame] | 2125 | // When the app is terminated (eg. from Recents), the task might have already been |
| 2126 | // removed with the window pending removal. Don't apply dim in such cases, as there |
| 2127 | // will be no more updateDimLayer() calls, which leaves the dimlayer invalid. |
| 2128 | final AppWindowToken token = mAppToken; |
| 2129 | if (token != null && token.removed) { |
| 2130 | return; |
| 2131 | } |
| 2132 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2133 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2134 | if (!mAnimatingExit && mAppDied) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2135 | // If app died visible, apply a dim over the window to indicate that it's inactive |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2136 | dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2137 | } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 2138 | && dc != null && !mAnimatingExit && isVisible()) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2139 | dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 2140 | } |
| 2141 | } |
| 2142 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2143 | private DimLayer.DimLayerUser getDimLayerUser() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 2144 | Task task = getTask(); |
| 2145 | if (task != null) { |
| 2146 | return task; |
| 2147 | } |
| 2148 | return getStack(); |
| 2149 | } |
| 2150 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2151 | /** Returns true if the replacement window was removed. */ |
| 2152 | boolean removeReplacedWindowIfNeeded(WindowState replacement) { |
| 2153 | if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) { |
| 2154 | replacement.mSkipEnterAnimationForSeamlessReplacement = false; |
| 2155 | removeReplacedWindow(); |
| 2156 | return true; |
| 2157 | } |
| 2158 | |
| 2159 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2160 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2161 | if (c.removeReplacedWindowIfNeeded(replacement)) { |
| 2162 | return true; |
| 2163 | } |
| 2164 | } |
| 2165 | return false; |
| 2166 | } |
| 2167 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2168 | private void removeReplacedWindow() { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2169 | if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this); |
| 2170 | if (isDimming()) { |
| 2171 | transferDimToReplacement(); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 2172 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2173 | mWillReplaceWindow = false; |
| 2174 | mAnimateReplacingWindow = false; |
| 2175 | mReplacingRemoveRequested = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2176 | mReplacementWindow = null; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2177 | if (mAnimatingExit || !mAnimateReplacingWindow) { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 2178 | removeImmediately(); |
Filip Gruszczynski | 76cc44f | 2015-09-03 16:03:10 -0700 | [diff] [blame] | 2179 | } |
| 2180 | } |
| 2181 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2182 | boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) { |
| 2183 | boolean replacementSet = false; |
| 2184 | |
| 2185 | if (mWillReplaceWindow && mReplacementWindow == null |
| 2186 | && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) { |
| 2187 | |
| 2188 | mReplacementWindow = replacementCandidate; |
| 2189 | replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow; |
| 2190 | replacementSet = true; |
| 2191 | } |
| 2192 | |
| 2193 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2194 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2195 | replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate); |
| 2196 | } |
| 2197 | |
| 2198 | return replacementSet; |
| 2199 | } |
| 2200 | |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2201 | void setDisplayLayoutNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2202 | final DisplayContent dc = getDisplayContent(); |
| 2203 | if (dc != null) { |
| 2204 | dc.setLayoutNeeded(); |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 2208 | // TODO: Strange usage of word workspace here and above. |
| 2209 | boolean inPinnedWorkspace() { |
| 2210 | final Task task = getTask(); |
| 2211 | return task != null && task.inPinnedWorkspace(); |
| 2212 | } |
| 2213 | |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 2214 | void applyAdjustForImeIfNeeded() { |
| 2215 | final Task task = getTask(); |
| 2216 | if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) { |
| 2217 | task.mStack.applyAdjustForImeIfNeeded(task); |
| 2218 | } |
| 2219 | } |
| 2220 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2221 | @Override |
| 2222 | void switchUser() { |
| 2223 | super.switchUser(); |
| 2224 | if (isHiddenFromUserLocked()) { |
| 2225 | if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this |
| 2226 | + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid); |
| 2227 | hideLw(false); |
| 2228 | } |
| 2229 | } |
| 2230 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2231 | int getTouchableRegion(Region region, int flags) { |
| 2232 | final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0; |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2233 | if (modal && mAppToken != null) { |
| 2234 | // Limit the outer touch to the activity stack region. |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2235 | flags |= FLAG_NOT_TOUCH_MODAL; |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2236 | // If this is a modal window we need to dismiss it if it's not full screen and the |
| 2237 | // touch happens outside of the frame that displays the content. This means we |
| 2238 | // need to intercept touches outside of that window. The dim layer user |
| 2239 | // associated with the window (task or stack) will give us the good bounds, as |
| 2240 | // they would be used to display the dim layer. |
| 2241 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
| 2242 | if (dimLayerUser != null) { |
| 2243 | dimLayerUser.getDimBounds(mTmpRect); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2244 | } else { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2245 | getVisibleBounds(mTmpRect); |
| 2246 | } |
| 2247 | if (inFreeformWorkspace()) { |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2248 | // For freeform windows we the touch region to include the whole surface for the |
| 2249 | // shadows. |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2250 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
| 2251 | final int delta = WindowManagerService.dipToPixel( |
| 2252 | RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics); |
| 2253 | mTmpRect.inset(-delta, -delta); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2254 | } |
| 2255 | region.set(mTmpRect); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2256 | cropRegionToStackBoundsIfNeeded(region); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2257 | } else { |
| 2258 | // Not modal or full screen modal |
| 2259 | getTouchableRegion(region); |
| 2260 | } |
| 2261 | return flags; |
| 2262 | } |
| 2263 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2264 | void checkPolicyVisibilityChange() { |
| 2265 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 2266 | if (DEBUG_VISIBILITY) { |
| 2267 | Slog.v(TAG, "Policy visibility changing after anim in " + |
| 2268 | mWinAnimator + ": " + mPolicyVisibilityAfterAnim); |
| 2269 | } |
| 2270 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 2271 | setDisplayLayoutNeeded(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2272 | if (!mPolicyVisibility) { |
| 2273 | if (mService.mCurrentFocus == this) { |
| 2274 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
| 2275 | "setAnimationLocked: setting mFocusMayChange true"); |
| 2276 | mService.mFocusMayChange = true; |
| 2277 | } |
| 2278 | // Window is no longer visible -- make sure if we were waiting |
| 2279 | // for it to be displayed before enabling the display, that |
| 2280 | // we allow the display to be enabled now. |
| 2281 | mService.enableScreenIfNeededLocked(); |
| 2282 | } |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | void setRequestedSize(int requestedWidth, int requestedHeight) { |
| 2287 | if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) { |
| 2288 | mLayoutNeeded = true; |
| 2289 | mRequestedWidth = requestedWidth; |
| 2290 | mRequestedHeight = requestedHeight; |
| 2291 | } |
| 2292 | } |
| 2293 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2294 | void prepareWindowToDisplayDuringRelayout(boolean wasVisible) { |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2295 | // We need to turn on screen regardless of visibility. |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2296 | if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) { |
| 2297 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this); |
| 2298 | mTurnOnScreen = true; |
| 2299 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2300 | |
| 2301 | // If we were already visible, skip rest of preparation. |
| 2302 | if (wasVisible) { |
| 2303 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2304 | "Already visible and does not turn on screen, skip preparing: " + this); |
| 2305 | return; |
| 2306 | } |
| 2307 | |
| 2308 | if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST) |
| 2309 | == SOFT_INPUT_ADJUST_RESIZE) { |
| 2310 | mLayoutNeeded = true; |
| 2311 | } |
| 2312 | |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 2313 | if (isDrawnLw() && mService.okToAnimate()) { |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2314 | mWinAnimator.applyEnterAnimationLocked(); |
| 2315 | } |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2316 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2317 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2318 | void getMergedConfiguration(MergedConfiguration outConfiguration) { |
| 2319 | final Configuration globalConfig = mService.mRoot.getConfiguration(); |
| 2320 | final Configuration overrideConfig = getMergedOverrideConfiguration(); |
| 2321 | outConfiguration.setConfiguration(globalConfig, overrideConfig); |
| 2322 | } |
| 2323 | |
| 2324 | void setReportedConfiguration(MergedConfiguration config) { |
| 2325 | mLastReportedConfiguration.setTo(config.getMergedConfiguration()); |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | void adjustStartingWindowFlags() { |
| 2329 | if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null |
| 2330 | && mAppToken.startingWindow != null) { |
| 2331 | // Special handling of starting window over the base |
| 2332 | // window of the app: propagate lock screen flags to it, |
| 2333 | // to provide the correct semantics while starting. |
| 2334 | final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD |
| 2335 | | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 2336 | WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs; |
| 2337 | sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask); |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | void setWindowScale(int requestedWidth, int requestedHeight) { |
| 2342 | final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0; |
| 2343 | |
| 2344 | if (scaledWindow) { |
| 2345 | // requested{Width|Height} Surface's physical size |
| 2346 | // attrs.{width|height} Size on screen |
| 2347 | // TODO: We don't check if attrs != null here. Is it implicitly checked? |
| 2348 | mHScale = (mAttrs.width != requestedWidth) ? |
| 2349 | (mAttrs.width / (float)requestedWidth) : 1.0f; |
| 2350 | mVScale = (mAttrs.height != requestedHeight) ? |
| 2351 | (mAttrs.height / (float)requestedHeight) : 1.0f; |
| 2352 | } else { |
| 2353 | mHScale = mVScale = 1; |
| 2354 | } |
| 2355 | } |
| 2356 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2357 | private class DeathRecipient implements IBinder.DeathRecipient { |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 2358 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2359 | public void binderDied() { |
| 2360 | try { |
| 2361 | synchronized(mService.mWindowMap) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2362 | final WindowState win = mService.windowForClientLocked(mSession, mClient, false); |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2363 | Slog.i(TAG, "WIN DEATH: " + win); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2364 | if (win != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2365 | final DisplayContent dc = getDisplayContent(); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 2366 | if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) { |
| 2367 | mService.mTaskSnapshotController.onAppDied(win.mAppToken); |
| 2368 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2369 | win.removeIfPossible(shouldKeepVisibleDeadAppWindow()); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2370 | if (win.mAttrs.type == TYPE_DOCK_DIVIDER) { |
| 2371 | // The owner of the docked divider died :( We reset the docked stack, |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 2372 | // just in case they have the divider at an unstable position. Better |
| 2373 | // also reset drag resizing state, because the owner can't do it |
| 2374 | // anymore. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2375 | final TaskStack stack = dc.getDockedStackIgnoringVisibility(); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2376 | if (stack != null) { |
| 2377 | stack.resetDockedStackToMiddle(); |
| 2378 | } |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 2379 | mService.setDockedStackResizing(false); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2380 | } |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 2381 | } else if (mHasSurface) { |
Craig Mautner | a99764e | 2013-03-06 10:22:16 -0800 | [diff] [blame] | 2382 | Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid."); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 2383 | WindowState.this.removeIfPossible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2384 | } |
| 2385 | } |
| 2386 | } catch (IllegalArgumentException ex) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 2387 | // This will happen if the window has already been removed. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2392 | /** |
| 2393 | * Returns true if this window is visible and belongs to a dead app and shouldn't be removed, |
| 2394 | * because we want to preserve its location on screen to be re-activated later when the user |
| 2395 | * interacts with it. |
| 2396 | */ |
| 2397 | boolean shouldKeepVisibleDeadAppWindow() { |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2398 | if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) { |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2399 | // Not a visible app window or the app isn't dead. |
| 2400 | return false; |
| 2401 | } |
| 2402 | |
Wale Ogunwale | 51d1d91 | 2016-05-04 13:27:18 -0700 | [diff] [blame] | 2403 | if (mAttrs.token != mClient.asBinder()) { |
| 2404 | // The window was add by a client using another client's app token. We don't want to |
| 2405 | // keep the dead window around for this case since this is meant for 'real' apps. |
| 2406 | return false; |
| 2407 | } |
| 2408 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2409 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2410 | // We don't keep starting windows since they were added by the window manager before |
| 2411 | // the app even launched. |
| 2412 | return false; |
| 2413 | } |
| 2414 | |
| 2415 | final TaskStack stack = getStack(); |
| 2416 | return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId); |
| 2417 | } |
| 2418 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2419 | /** @return true if this window desires key events. */ |
| 2420 | boolean canReceiveKeys() { |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 2421 | return isVisibleOrAdding() |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 2422 | && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2423 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0) |
Jorim Jaggi | b72c9ad | 2016-04-11 18:27:58 -0700 | [diff] [blame] | 2424 | && (mAppToken == null || mAppToken.windowsAreFocusable()) |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 2425 | && !canReceiveTouchInput(); |
| 2426 | } |
| 2427 | |
| 2428 | /** @return true if this window desires touch events. */ |
| 2429 | boolean canReceiveTouchInput() { |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 2430 | return mAppToken != null && mAppToken.getTask() != null |
| 2431 | && mAppToken.getTask().mStack.shouldIgnoreInput(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2432 | } |
| 2433 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2434 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2435 | public boolean hasDrawnLw() { |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2436 | return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2439 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2440 | public boolean showLw(boolean doAnimation) { |
| 2441 | return showLw(doAnimation, true); |
| 2442 | } |
| 2443 | |
| 2444 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2445 | if (isHiddenFromUserLocked()) { |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 2446 | return false; |
| 2447 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2448 | if (!mAppOpVisibility) { |
| 2449 | // Being hidden due to app op request. |
| 2450 | return false; |
| 2451 | } |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2452 | if (mPermanentlyHidden) { |
| 2453 | // Permanently hidden until the app exists as apps aren't prepared |
| 2454 | // to handle their windows being removed from under them. |
| 2455 | return false; |
| 2456 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2457 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 2458 | // Already showing. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2459 | return false; |
| 2460 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2461 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2462 | if (doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2463 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2464 | + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation); |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 2465 | if (!mService.okToAnimate()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2466 | doAnimation = false; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2467 | } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2468 | // Check for the case where we are currently visible and |
| 2469 | // not animating; we do not want to do animation at such a |
| 2470 | // point to become visible when we already are. |
| 2471 | doAnimation = false; |
| 2472 | } |
| 2473 | } |
| 2474 | mPolicyVisibility = true; |
| 2475 | mPolicyVisibilityAfterAnim = true; |
| 2476 | if (doAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2477 | mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2478 | } |
| 2479 | if (requestAnim) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 2480 | mService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2481 | } |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2482 | if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) { |
| 2483 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */); |
| 2484 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2485 | return true; |
| 2486 | } |
| 2487 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2488 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2489 | public boolean hideLw(boolean doAnimation) { |
| 2490 | return hideLw(doAnimation, true); |
| 2491 | } |
| 2492 | |
| 2493 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| 2494 | if (doAnimation) { |
Adrian Roos | e94c15c | 2017-05-09 13:17:54 -0700 | [diff] [blame] | 2495 | if (!mService.okToAnimate()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2496 | doAnimation = false; |
| 2497 | } |
| 2498 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2499 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2500 | if (!current) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 2501 | // Already hiding. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2502 | return false; |
| 2503 | } |
| 2504 | if (doAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2505 | mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2506 | if (mWinAnimator.mAnimation == null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2507 | doAnimation = false; |
| 2508 | } |
| 2509 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2510 | mPolicyVisibilityAfterAnim = false; |
| 2511 | if (!doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2512 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2513 | mPolicyVisibility = false; |
| 2514 | // Window is no longer visible -- make sure if we were waiting |
| 2515 | // for it to be displayed before enabling the display, that |
| 2516 | // we allow the display to be enabled now. |
| 2517 | mService.enableScreenIfNeededLocked(); |
| 2518 | if (mService.mCurrentFocus == this) { |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2519 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 2520 | "WindowState.hideLw: setting mFocusMayChange true"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2521 | mService.mFocusMayChange = true; |
| 2522 | } |
| 2523 | } |
| 2524 | if (requestAnim) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 2525 | mService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2526 | } |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2527 | if (mService.mCurrentFocus == this) { |
| 2528 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */); |
| 2529 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2530 | return true; |
| 2531 | } |
| 2532 | |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 2533 | public void setAppOpVisibilityLw(boolean state) { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2534 | if (mAppOpVisibility != state) { |
| 2535 | mAppOpVisibility = state; |
| 2536 | if (state) { |
| 2537 | // If the policy visibility had last been to hide, then this |
| 2538 | // will incorrectly show at this point since we lost that |
| 2539 | // information. Not a big deal -- for the windows that have app |
| 2540 | // ops modifies they should only be hidden by policy due to the |
| 2541 | // lock screen, and the user won't be changing this if locked. |
| 2542 | // Plus it will quickly be fixed the next time we do a layout. |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 2543 | showLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2544 | } else { |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 2545 | hideLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2546 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2547 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2548 | } |
| 2549 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2550 | public void hidePermanentlyLw() { |
| 2551 | if (!mPermanentlyHidden) { |
| 2552 | mPermanentlyHidden = true; |
| 2553 | hideLw(true, true); |
| 2554 | } |
| 2555 | } |
| 2556 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2557 | public void pokeDrawLockLw(long timeout) { |
| 2558 | if (isVisibleOrAdding()) { |
| 2559 | if (mDrawLock == null) { |
| 2560 | // We want the tag name to be somewhat stable so that it is easier to correlate |
| 2561 | // in wake lock statistics. So in particular, we don't want to include the |
| 2562 | // window's hash code as in toString(). |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2563 | final CharSequence tag = getWindowTag(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2564 | mDrawLock = mService.mPowerManager.newWakeLock( |
| 2565 | PowerManager.DRAW_WAKE_LOCK, "Window:" + tag); |
| 2566 | mDrawLock.setReferenceCounted(false); |
| 2567 | mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName)); |
| 2568 | } |
| 2569 | // Each call to acquire resets the timeout. |
| 2570 | if (DEBUG_POWER) { |
| 2571 | Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by " |
| 2572 | + mAttrs.packageName); |
| 2573 | } |
| 2574 | mDrawLock.acquire(timeout); |
| 2575 | } else if (DEBUG_POWER) { |
| 2576 | Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window " |
| 2577 | + "owned by " + mAttrs.packageName); |
| 2578 | } |
| 2579 | } |
| 2580 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2581 | @Override |
| 2582 | public boolean isAlive() { |
| 2583 | return mClient.asBinder().isBinderAlive(); |
| 2584 | } |
| 2585 | |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2586 | boolean isClosing() { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2587 | return mAnimatingExit || (mService.mClosingApps.contains(mAppToken)); |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 2590 | boolean isAnimatingWithSavedSurface() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2591 | return mAnimatingWithSavedSurface; |
| 2592 | } |
| 2593 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2594 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2595 | boolean isAnimating() { |
| 2596 | if (mWinAnimator.isAnimationSet() || mAnimatingExit) { |
| 2597 | return true; |
| 2598 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2599 | return super.isAnimating(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2602 | boolean isAnimatingInvisibleWithSavedSurface() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2603 | if (mAnimatingWithSavedSurface |
| 2604 | && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) { |
| 2605 | return true; |
| 2606 | } |
| 2607 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2608 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2609 | if (c.isAnimatingInvisibleWithSavedSurface()) { |
| 2610 | return true; |
| 2611 | } |
| 2612 | } |
| 2613 | return false; |
| 2614 | } |
| 2615 | |
| 2616 | void stopUsingSavedSurface() { |
| 2617 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2618 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2619 | c.stopUsingSavedSurface(); |
| 2620 | } |
| 2621 | |
| 2622 | if (!isAnimatingInvisibleWithSavedSurface()) { |
| 2623 | return; |
| 2624 | } |
| 2625 | |
| 2626 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this); |
| 2627 | clearAnimatingWithSavedSurface(); |
| 2628 | mDestroying = true; |
| 2629 | mWinAnimator.hide("stopUsingSavedSurface"); |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 2630 | getDisplayContent().mWallpaperController.hideWallpapers(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | void markSavedSurfaceExiting() { |
| 2634 | if (isAnimatingInvisibleWithSavedSurface()) { |
| 2635 | mAnimatingExit = true; |
| 2636 | mWinAnimator.mAnimating = true; |
| 2637 | } |
| 2638 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2639 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2640 | c.markSavedSurfaceExiting(); |
| 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) { |
| 2645 | animators.add(mWinAnimator); |
| 2646 | |
| 2647 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2648 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2649 | c.addWinAnimatorToList(animators); |
| 2650 | } |
| 2651 | } |
| 2652 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2653 | void sendAppVisibilityToClients() { |
| 2654 | super.sendAppVisibilityToClients(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2655 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2656 | final boolean clientHidden = mAppToken.isClientHidden(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2657 | if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) { |
| 2658 | // Don't hide the starting window. |
| 2659 | return; |
| 2660 | } |
| 2661 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2662 | if (clientHidden) { |
| 2663 | // Once we are notifying the client that it's visibility has changed, we need to prevent |
| 2664 | // it from destroying child surfaces until the animation has finished. We do this by |
| 2665 | // detaching any surface control the client added from the client. |
| 2666 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 2667 | final WindowState c = mChildren.get(i); |
| 2668 | c.mWinAnimator.detachChildren(); |
| 2669 | } |
| 2670 | |
| 2671 | mWinAnimator.detachChildren(); |
| 2672 | } |
| 2673 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2674 | try { |
| 2675 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2676 | "Setting visibility of " + this + ": " + (!clientHidden)); |
| 2677 | mClient.dispatchAppVisibility(!clientHidden); |
| 2678 | } catch (RemoteException e) { |
| 2679 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2682 | public void setVisibleBeforeClientHidden() { |
| 2683 | mWasVisibleBeforeClientHidden |= |
| 2684 | (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2685 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2686 | super.setVisibleBeforeClientHidden(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2689 | public void clearWasVisibleBeforeClientHidden() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2690 | mWasVisibleBeforeClientHidden = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2691 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2692 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2693 | c.clearWasVisibleBeforeClientHidden(); |
| 2694 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | public boolean wasVisibleBeforeClientHidden() { |
| 2698 | return mWasVisibleBeforeClientHidden; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2701 | void onStartFreezingScreen() { |
| 2702 | mAppFreezing = true; |
| 2703 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2704 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2705 | c.onStartFreezingScreen(); |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | boolean onStopFreezingScreen() { |
| 2710 | boolean unfrozeWindows = false; |
| 2711 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2712 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2713 | unfrozeWindows |= c.onStopFreezingScreen(); |
| 2714 | } |
| 2715 | |
| 2716 | if (!mAppFreezing) { |
| 2717 | return unfrozeWindows; |
| 2718 | } |
| 2719 | |
Wale Ogunwale | 953171d | 2016-09-30 09:17:30 -0700 | [diff] [blame] | 2720 | mAppFreezing = false; |
| 2721 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 2722 | if (mHasSurface && !getOrientationChanging() |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2723 | && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) { |
| 2724 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 2725 | setOrientationChanging(true); |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 2726 | mService.mRoot.mOrientationChangeComplete = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2727 | } |
| 2728 | mLastFreezeDuration = 0; |
| 2729 | setDisplayLayoutNeeded(); |
| 2730 | return true; |
| 2731 | } |
| 2732 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2733 | private boolean shouldSaveSurface() { |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2734 | if (mWinAnimator.mSurfaceController == null) { |
| 2735 | // Don't bother if the surface controller is gone for any reason. |
| 2736 | return false; |
| 2737 | } |
| 2738 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2739 | if (!mWasVisibleBeforeClientHidden) { |
| 2740 | return false; |
| 2741 | } |
| 2742 | |
Wale Ogunwale | 945d197 | 2016-03-23 13:16:41 -0700 | [diff] [blame] | 2743 | if ((mAttrs.flags & FLAG_SECURE) != 0) { |
| 2744 | // We don't save secure surfaces since their content shouldn't be shown while the app |
| 2745 | // isn't on screen and content might leak through during the transition animation with |
| 2746 | // saved surface. |
| 2747 | return false; |
| 2748 | } |
| 2749 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2750 | if (isLowRamDeviceStatic()) { |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2751 | // Don't save surfaces on Svelte devices. |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2752 | return false; |
| 2753 | } |
| 2754 | |
Jorim Jaggi | ab7ad38 | 2016-10-26 18:22:04 -0700 | [diff] [blame] | 2755 | final Task task = getTask(); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2756 | final AppWindowToken taskTop = task.getTopVisibleAppToken(); |
| 2757 | if (taskTop != null && taskTop != mAppToken) { |
| 2758 | // Don't save if the window is not the topmost window. |
| 2759 | return false; |
| 2760 | } |
| 2761 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 2762 | if (mResizedWhileGone) { |
| 2763 | // Somebody resized our window while we were gone for layout, which means that the |
| 2764 | // client got an old size, so we have an outdated surface here. |
| 2765 | return false; |
| 2766 | } |
| 2767 | |
Robert Carr | 7098dbd | 2016-02-01 12:31:01 -0800 | [diff] [blame] | 2768 | if (DEBUG_DISABLE_SAVING_SURFACES) { |
| 2769 | return false; |
| 2770 | } |
| 2771 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2772 | return mAppToken.shouldSaveSurface(); |
| 2773 | } |
| 2774 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2775 | boolean destroySurface(boolean cleanupOnResume, boolean appStopped) { |
| 2776 | boolean destroyedSomething = false; |
| 2777 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2778 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2779 | destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped); |
| 2780 | } |
| 2781 | |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2782 | if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) { |
| 2783 | return destroyedSomething; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2784 | } |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2785 | |
| 2786 | if (appStopped || mWindowRemovalAllowed) { |
| 2787 | mWinAnimator.destroyPreservedSurfaceLocked(); |
| 2788 | } |
| 2789 | |
| 2790 | if (mDestroying) { |
| 2791 | if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this |
| 2792 | + " destroySurfaces: appStopped=" + appStopped |
| 2793 | + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed |
| 2794 | + " win.mRemoveOnExit=" + mRemoveOnExit); |
| 2795 | if (!cleanupOnResume || mRemoveOnExit) { |
Robert Carr | 89a28ab | 2017-04-24 15:33:11 -0700 | [diff] [blame] | 2796 | destroyOrSaveSurfaceUnchecked(); |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2797 | } |
| 2798 | if (mRemoveOnExit) { |
| 2799 | removeImmediately(); |
| 2800 | } |
| 2801 | if (cleanupOnResume) { |
| 2802 | requestUpdateWallpaperIfNeeded(); |
| 2803 | } |
| 2804 | mDestroying = false; |
| 2805 | destroyedSomething = true; |
| 2806 | } |
| 2807 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2808 | return destroyedSomething; |
| 2809 | } |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 2810 | |
Robert Carr | 89a28ab | 2017-04-24 15:33:11 -0700 | [diff] [blame] | 2811 | // Destroy or save the application surface without checking |
| 2812 | // various indicators of whether the client has released the surface. |
| 2813 | // This is in general unsafe, and most callers should use {@link #destroySurface} |
| 2814 | void destroyOrSaveSurfaceUnchecked() { |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2815 | mSurfaceSaved = shouldSaveSurface(); |
| 2816 | if (mSurfaceSaved) { |
| 2817 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 2818 | Slog.v(TAG, "Saving surface: " + this); |
| 2819 | } |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 2820 | // Previous user of the surface may have set a transparent region signaling a portion |
| 2821 | // doesn't need to be composited, so reset to default empty state. |
| 2822 | mSession.setTransparentRegion(mClient, sEmptyRegion); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2823 | |
| 2824 | mWinAnimator.hide("saved surface"); |
| 2825 | mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE; |
| 2826 | setHasSurface(false); |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 2827 | // The client should have disconnected at this point, but if it doesn't, |
| 2828 | // we need to make sure it's disconnected. Otherwise when we reuse the surface |
| 2829 | // the client can't reconnect to the buffer queue, and rendering will fail. |
| 2830 | if (mWinAnimator.mSurfaceController != null) { |
| 2831 | mWinAnimator.mSurfaceController.disconnectInTransaction(); |
| 2832 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2833 | mAnimatingWithSavedSurface = false; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2834 | } else { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2835 | mWinAnimator.destroySurfaceLocked(); |
| 2836 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2837 | // Clear animating flags now, since the surface is now gone. (Note this is true even |
| 2838 | // if the surface is saved, to outside world the surface is still NO_SURFACE.) |
| 2839 | mAnimatingExit = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2840 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2841 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2842 | void destroySavedSurface() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2843 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2844 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2845 | c.destroySavedSurface(); |
| 2846 | } |
| 2847 | |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2848 | if (mSurfaceSaved) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2849 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2850 | mWinAnimator.destroySurfaceLocked(); |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2851 | mSurfaceSaved = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2852 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2853 | mWasVisibleBeforeClientHidden = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2854 | } |
| 2855 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2856 | /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/ |
| 2857 | int restoreSavedSurfaceForInterestingWindow() { |
| 2858 | int interestingNotDrawn = -1; |
| 2859 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2860 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2861 | final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow(); |
| 2862 | if (childInterestingNotDrawn != -1) { |
| 2863 | if (interestingNotDrawn == -1) { |
| 2864 | interestingNotDrawn = childInterestingNotDrawn; |
| 2865 | } else { |
| 2866 | interestingNotDrawn += childInterestingNotDrawn; |
| 2867 | } |
| 2868 | } |
Chong Zhang | 4113ffa | 2016-02-18 12:39:13 -0800 | [diff] [blame] | 2869 | } |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2870 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2871 | if (mAttrs.type == TYPE_APPLICATION_STARTING |
| 2872 | || mAppDied || !wasVisibleBeforeClientHidden() |
| 2873 | || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) { |
| 2874 | // Window isn't interesting... |
| 2875 | return interestingNotDrawn; |
| 2876 | } |
| 2877 | |
| 2878 | restoreSavedSurface(); |
| 2879 | |
| 2880 | if (!isDrawnLw()) { |
| 2881 | if (interestingNotDrawn == -1) { |
| 2882 | interestingNotDrawn = 1; |
| 2883 | } else { |
| 2884 | interestingNotDrawn++; |
| 2885 | } |
| 2886 | } |
| 2887 | return interestingNotDrawn; |
| 2888 | } |
| 2889 | |
| 2890 | /** Returns true if the saved surface was restored. */ |
| 2891 | boolean restoreSavedSurface() { |
| 2892 | if (!mSurfaceSaved) { |
| 2893 | return false; |
| 2894 | } |
| 2895 | |
| 2896 | // Sometimes we save surfaces due to layout invisible directly after rotation occurs. |
| 2897 | // However this means the surface was never laid out in the new orientation. |
| 2898 | // We can only restore to the last rotation we were laid out as visible in. |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 2899 | if (mLastVisibleLayoutRotation != getDisplayContent().getRotation()) { |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2900 | destroySavedSurface(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2901 | return false; |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2902 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2903 | mSurfaceSaved = false; |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2904 | |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2905 | if (mWinAnimator.mSurfaceController != null) { |
| 2906 | setHasSurface(true); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 2907 | mWinAnimator.mDrawState = READY_TO_SHOW; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2908 | mAnimatingWithSavedSurface = true; |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2909 | |
Chong Zhang | 6e9872b | 2016-08-17 10:19:05 -0700 | [diff] [blame] | 2910 | requestUpdateWallpaperIfNeeded(); |
| 2911 | |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2912 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 2913 | Slog.v(TAG, "Restoring saved surface: " + this); |
| 2914 | } |
| 2915 | } else { |
| 2916 | // mSurfaceController shouldn't be null if mSurfaceSaved was still true at |
| 2917 | // this point. Even if we destroyed the saved surface because of rotation |
| 2918 | // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf. |
| 2919 | Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2920 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2921 | |
| 2922 | return true; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2923 | } |
| 2924 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2925 | boolean canRestoreSurface() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2926 | if (mWasVisibleBeforeClientHidden && mSurfaceSaved) { |
| 2927 | return true; |
| 2928 | } |
| 2929 | |
| 2930 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2931 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2932 | if (c.canRestoreSurface()) { |
| 2933 | return true; |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | return false; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | boolean hasSavedSurface() { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2941 | return mSurfaceSaved; |
| 2942 | } |
| 2943 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2944 | void clearHasSavedSurface() { |
| 2945 | mSurfaceSaved = false; |
| 2946 | mAnimatingWithSavedSurface = false; |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 2947 | if (mWasVisibleBeforeClientHidden) { |
| 2948 | mAppToken.destroySavedSurfaces(); |
| 2949 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2952 | boolean clearAnimatingWithSavedSurface() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2953 | if (mAnimatingWithSavedSurface) { |
| 2954 | // App has drawn something to its windows, we're no longer animating with |
| 2955 | // the saved surfaces. |
| 2956 | if (DEBUG_ANIM) Slog.d(TAG, |
| 2957 | "clearAnimatingWithSavedSurface(): win=" + this); |
| 2958 | mAnimatingWithSavedSurface = false; |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2959 | return true; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2960 | } |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2961 | return false; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2964 | @Override |
| 2965 | public boolean isDefaultDisplay() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2966 | final DisplayContent displayContent = getDisplayContent(); |
| 2967 | if (displayContent == null) { |
| 2968 | // Only a window that was on a non-default display can be detached from it. |
| 2969 | return false; |
| 2970 | } |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 2971 | return displayContent.isDefaultDisplay; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 2974 | @Override |
| 2975 | public boolean isDimming() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 2976 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2977 | final DisplayContent dc = getDisplayContent(); |
| 2978 | return dimLayerUser != null && dc != null |
| 2979 | && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator); |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 2980 | } |
| 2981 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2982 | void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) { |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2983 | mShowToOwnerOnly = showToOwnerOnly; |
| 2984 | } |
| 2985 | |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 2986 | private boolean isHiddenFromUserLocked() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 2987 | // Child windows are evaluated based on their parent window. |
| 2988 | final WindowState win = getTopParentWindow(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2989 | if (win.mAttrs.type < FIRST_SYSTEM_WINDOW |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 2990 | && win.mAppToken != null && win.mAppToken.mShowForAllUsers) { |
Jorim Jaggi | dbe44ac | 2016-04-22 19:50:13 -0700 | [diff] [blame] | 2991 | |
| 2992 | // All window frames that are fullscreen extend above status bar, but some don't extend |
| 2993 | // below navigation bar. Thus, check for display frame for top/left and stable frame for |
| 2994 | // bottom right. |
| 2995 | if (win.mFrame.left <= win.mDisplayFrame.left |
| 2996 | && win.mFrame.top <= win.mDisplayFrame.top |
| 2997 | && win.mFrame.right >= win.mStableFrame.right |
| 2998 | && win.mFrame.bottom >= win.mStableFrame.bottom) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2999 | // Is a fullscreen window, like the clock alarm. Show to everyone. |
| 3000 | return false; |
| 3001 | } |
| 3002 | } |
| 3003 | |
Craig Mautner | 341220f | 2012-10-16 15:20:09 -0700 | [diff] [blame] | 3004 | return win.mShowToOwnerOnly |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 3005 | && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid)); |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3008 | private static void applyInsets(Region outRegion, Rect frame, Rect inset) { |
| 3009 | outRegion.set( |
| 3010 | frame.left + inset.left, frame.top + inset.top, |
| 3011 | frame.right - inset.right, frame.bottom - inset.bottom); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3012 | } |
| 3013 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3014 | void getTouchableRegion(Region outRegion) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3015 | final Rect frame = mFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3016 | switch (mTouchableInsets) { |
| 3017 | default: |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3018 | case TOUCHABLE_INSETS_FRAME: |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3019 | outRegion.set(frame); |
| 3020 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3021 | case TOUCHABLE_INSETS_CONTENT: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3022 | applyInsets(outRegion, frame, mGivenContentInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3023 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3024 | case TOUCHABLE_INSETS_VISIBLE: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3025 | applyInsets(outRegion, frame, mGivenVisibleInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3026 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3027 | case TOUCHABLE_INSETS_REGION: { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3028 | outRegion.set(mGivenTouchableRegion); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3029 | outRegion.translate(frame.left, frame.top); |
| 3030 | break; |
| 3031 | } |
| 3032 | } |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3033 | cropRegionToStackBoundsIfNeeded(outRegion); |
| 3034 | } |
| 3035 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3036 | private void cropRegionToStackBoundsIfNeeded(Region region) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 3037 | final Task task = getTask(); |
| 3038 | if (task == null || !task.cropWindowsToStackBounds()) { |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3039 | return; |
| 3040 | } |
| 3041 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 3042 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3043 | if (stack == null) { |
| 3044 | return; |
| 3045 | } |
| 3046 | |
| 3047 | stack.getDimBounds(mTmpRect); |
| 3048 | region.op(mTmpRect, Region.Op.INTERSECT); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3049 | } |
| 3050 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3051 | /** |
| 3052 | * Report a focus change. Must be called with no locks held, and consistently |
| 3053 | * from the same serialized thread (such as dispatched from a handler). |
| 3054 | */ |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 3055 | void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3056 | try { |
| 3057 | mClient.windowFocusChanged(focused, inTouchMode); |
| 3058 | } catch (RemoteException e) { |
| 3059 | } |
| 3060 | if (mFocusCallbacks != null) { |
| 3061 | final int N = mFocusCallbacks.beginBroadcast(); |
| 3062 | for (int i=0; i<N; i++) { |
| 3063 | IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i); |
| 3064 | try { |
| 3065 | if (focused) { |
| 3066 | obs.focusGained(mWindowId.asBinder()); |
| 3067 | } else { |
| 3068 | obs.focusLost(mWindowId.asBinder()); |
| 3069 | } |
| 3070 | } catch (RemoteException e) { |
| 3071 | } |
| 3072 | } |
| 3073 | mFocusCallbacks.finishBroadcast(); |
| 3074 | } |
| 3075 | } |
| 3076 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3077 | @Override |
| 3078 | public Configuration getConfiguration() { |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3079 | if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3080 | return mAppToken.mFrozenMergedConfig.peek(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3081 | } |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3082 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3083 | return super.getConfiguration(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3086 | void reportResized() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3087 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag()); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3088 | try { |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 3089 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this |
| 3090 | + ": " + mCompatFrame); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3091 | final MergedConfiguration mergedConfiguration = |
| 3092 | new MergedConfiguration(mService.mRoot.getConfiguration(), |
| 3093 | getMergedOverrideConfiguration()); |
| 3094 | |
| 3095 | setReportedConfiguration(mergedConfiguration); |
| 3096 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3097 | if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING) |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 3098 | Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING"); |
| 3099 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3100 | final Rect frame = mFrame; |
| 3101 | final Rect overscanInsets = mLastOverscanInsets; |
| 3102 | final Rect contentInsets = mLastContentInsets; |
| 3103 | final Rect visibleInsets = mLastVisibleInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3104 | final Rect stableInsets = mLastStableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3105 | final Rect outsets = mLastOutsets; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3106 | final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3107 | final boolean reportOrientation = mReportOrientationChanged; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3108 | final int displayId = getDisplayId(); |
Chet Haase | 8eb48d2 | 2014-09-24 07:31:29 -0700 | [diff] [blame] | 3109 | if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 3110 | && mClient instanceof IWindow.Stub) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3111 | // To prevent deadlock simulate one-way call if win.mClient is a local object. |
| 3112 | mService.mH.post(new Runnable() { |
| 3113 | @Override |
| 3114 | public void run() { |
| 3115 | try { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3116 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3117 | stableInsets, outsets, reportDraw, mergedConfiguration, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3118 | reportOrientation, displayId); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3119 | } catch (RemoteException e) { |
| 3120 | // Not a remote call, RemoteException won't be raised. |
| 3121 | } |
| 3122 | } |
| 3123 | }); |
| 3124 | } else { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3125 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3126 | outsets, reportDraw, mergedConfiguration, reportOrientation, displayId); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3127 | } |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3128 | |
| 3129 | //TODO (multidisplay): Accessibility supported only for the default display. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 3130 | if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 3131 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3132 | } |
| 3133 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3134 | mOverscanInsetsChanged = false; |
| 3135 | mContentInsetsChanged = false; |
| 3136 | mVisibleInsetsChanged = false; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3137 | mStableInsetsChanged = false; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3138 | mOutsetsChanged = false; |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 3139 | mFrameSizeChanged = false; |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 3140 | mResizedWhileNotDragResizingReported = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3141 | mWinAnimator.mSurfaceResized = false; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3142 | mReportOrientationChanged = false; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3143 | } catch (RemoteException e) { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3144 | setOrientationChanging(false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3145 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 3146 | - mService.mDisplayFreezeTime); |
tiger_huang | 950ee77 | 2014-07-11 18:41:48 +0800 | [diff] [blame] | 3147 | // We are assuming the hosting process is dead or in a zombie state. |
| 3148 | Slog.w(TAG, "Failed to report 'resized' to the client of " + this |
| 3149 | + ", removing this window."); |
| 3150 | mService.mPendingRemove.add(this); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 3151 | mService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3152 | } |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3153 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3154 | } |
| 3155 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3156 | Rect getBackdropFrame(Rect frame) { |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 3157 | // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing |
| 3158 | // start even if we haven't received the relayout window, so that the client requests |
| 3159 | // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen |
| 3160 | // until the window to small size, otherwise the multithread renderer will shift last |
| 3161 | // one or more frame to wrong offset. So here we send fullscreen backdrop if either |
| 3162 | // isDragResizing() or isDragResizeChanged() is true. |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3163 | boolean resizing = isDragResizing() || isDragResizeChanged(); |
| 3164 | if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) { |
| 3165 | return frame; |
| 3166 | } |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 3167 | final DisplayInfo displayInfo = getDisplayInfo(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3168 | mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3169 | return mTmpRect; |
| 3170 | } |
| 3171 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 3172 | @Override |
| 3173 | public int getStackId() { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3174 | final TaskStack stack = getStack(); |
| 3175 | if (stack == null) { |
| 3176 | return INVALID_STACK_ID; |
| 3177 | } |
| 3178 | return stack.mStackId; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
| 3182 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3183 | MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId) |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3184 | throws RemoteException { |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3185 | final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing |
| 3186 | || reportOrientation; |
Chong Zhang | edaf305 | 2016-04-22 15:04:31 -0700 | [diff] [blame] | 3187 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 3188 | mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3189 | reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout, |
| 3190 | mPolicy.isNavBarForcedShownLw(this), displayId); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3191 | mDragResizingChangeReported = true; |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3192 | } |
| 3193 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3194 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 3195 | synchronized(mService.mWindowMap) { |
| 3196 | if (mFocusCallbacks == null) { |
| 3197 | mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>(); |
| 3198 | } |
| 3199 | mFocusCallbacks.register(observer); |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 3204 | synchronized(mService.mWindowMap) { |
| 3205 | if (mFocusCallbacks != null) { |
| 3206 | mFocusCallbacks.unregister(observer); |
| 3207 | } |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | public boolean isFocused() { |
| 3212 | synchronized(mService.mWindowMap) { |
| 3213 | return mService.mCurrentFocus == this; |
| 3214 | } |
| 3215 | } |
| 3216 | |
Filip Gruszczynski | 1a1d831 | 2015-08-26 17:00:47 -0700 | [diff] [blame] | 3217 | boolean inFreeformWorkspace() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 3218 | final Task task = getTask(); |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 3219 | return task != null && task.inFreeformWorkspace(); |
| 3220 | } |
| 3221 | |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 3222 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 3223 | public boolean isInMultiWindowMode() { |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 3224 | final Task task = getTask(); |
| 3225 | return task != null && !task.isFullscreen(); |
| 3226 | } |
| 3227 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3228 | /** Is this window in a container that takes up the entire screen space? */ |
| 3229 | private boolean inFullscreenContainer() { |
| 3230 | if (mAppToken == null) { |
| 3231 | return true; |
| 3232 | } |
| 3233 | if (mAppToken.hasBounds()) { |
| 3234 | return false; |
| 3235 | } |
| 3236 | return !isInMultiWindowMode(); |
| 3237 | } |
| 3238 | |
Andrii Kulian | 283acd2 | 2017-08-03 04:03:51 -0700 | [diff] [blame] | 3239 | /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */ |
| 3240 | boolean isLetterboxedAppWindow() { |
| 3241 | final Task task = getTask(); |
| 3242 | final boolean taskIsFullscreen = task != null && task.isFullscreen(); |
| 3243 | final boolean appWindowIsFullscreen = mAppToken != null && !mAppToken.hasBounds(); |
| 3244 | |
| 3245 | return taskIsFullscreen && !appWindowIsFullscreen; |
| 3246 | } |
| 3247 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3248 | /** Returns the appropriate bounds to use for computing frames. */ |
| 3249 | private void getContainerBounds(Rect outBounds) { |
| 3250 | if (isInMultiWindowMode()) { |
| 3251 | getTask().getBounds(outBounds); |
| 3252 | } else if (mAppToken != null){ |
| 3253 | mAppToken.getBounds(outBounds); |
| 3254 | } else { |
| 3255 | outBounds.setEmpty(); |
| 3256 | } |
| 3257 | } |
| 3258 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3259 | boolean isDragResizeChanged() { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3260 | return mDragResizing != computeDragResizing(); |
| 3261 | } |
| 3262 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3263 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3264 | void setWaitingForDrawnIfResizingChanged() { |
| 3265 | if (isDragResizeChanged()) { |
| 3266 | mService.mWaitingForDrawn.add(this); |
| 3267 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3268 | super.setWaitingForDrawnIfResizingChanged(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3271 | /** |
| 3272 | * @return Whether we reported a drag resize change to the application or not already. |
| 3273 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3274 | private boolean isDragResizingChangeReported() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3275 | return mDragResizingChangeReported; |
| 3276 | } |
| 3277 | |
| 3278 | /** |
| 3279 | * Resets the state whether we reported a drag resize change to the app. |
| 3280 | */ |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3281 | @Override |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3282 | void resetDragResizingChangeReported() { |
| 3283 | mDragResizingChangeReported = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3284 | super.resetDragResizingChangeReported(); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3285 | } |
| 3286 | |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 3287 | /** |
| 3288 | * Set whether we got resized but drag resizing flag was false. |
| 3289 | * @see #isResizedWhileNotDragResizing(). |
| 3290 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3291 | private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) { |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 3292 | mResizedWhileNotDragResizing = resizedWhileNotDragResizing; |
| 3293 | mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing; |
| 3294 | } |
| 3295 | |
| 3296 | /** |
| 3297 | * Indicates whether we got resized but drag resizing flag was false. In this case, we also |
| 3298 | * need to recreate the surface and defer surface bound updates in order to make sure the |
| 3299 | * buffer contents and the positioning/size stay in sync. |
| 3300 | */ |
| 3301 | boolean isResizedWhileNotDragResizing() { |
| 3302 | return mResizedWhileNotDragResizing; |
| 3303 | } |
| 3304 | |
| 3305 | /** |
| 3306 | * @return Whether we reported "resize while not drag resizing" to the application. |
| 3307 | * @see #isResizedWhileNotDragResizing() |
| 3308 | */ |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3309 | private boolean isResizedWhileNotDragResizingReported() { |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 3310 | return mResizedWhileNotDragResizingReported; |
| 3311 | } |
| 3312 | |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 3313 | int getResizeMode() { |
| 3314 | return mResizeMode; |
| 3315 | } |
| 3316 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3317 | private boolean computeDragResizing() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 3318 | final Task task = getTask(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3319 | if (task == null) { |
| 3320 | return false; |
| 3321 | } |
Winson Chung | 2af04b3 | 2017-01-24 16:21:13 -0800 | [diff] [blame] | 3322 | if (!StackId.isStackAffectedByDragResizing(getStackId())) { |
| 3323 | return false; |
| 3324 | } |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 3325 | if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) { |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 3326 | // Floating windows never enter drag resize mode. |
| 3327 | return false; |
| 3328 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3329 | if (task.isDragResizing()) { |
| 3330 | return true; |
| 3331 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 3332 | |
| 3333 | // If the bounds are currently frozen, it means that the layout size that the app sees |
| 3334 | // and the bounds we clip this window to might be different. In order to avoid holes, we |
| 3335 | // simulate that we are still resizing so the app fills the hole with the resizing |
| 3336 | // background. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3337 | return (getDisplayContent().mDividerControllerLocked.isResizing() |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 3338 | || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) && |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 3339 | !task.inFreeformWorkspace() && !isGoneForLayoutLw(); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3340 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | void setDragResizing() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3344 | final boolean resizing = computeDragResizing(); |
| 3345 | if (resizing == mDragResizing) { |
| 3346 | return; |
| 3347 | } |
| 3348 | mDragResizing = resizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3349 | final Task task = getTask(); |
| 3350 | if (task != null && task.isDragResizing()) { |
| 3351 | mResizeMode = task.getDragResizeMode(); |
| 3352 | } else { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3353 | mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing() |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3354 | ? DRAG_RESIZE_MODE_DOCKED_DIVIDER |
| 3355 | : DRAG_RESIZE_MODE_FREEFORM; |
| 3356 | } |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | boolean isDragResizing() { |
| 3360 | return mDragResizing; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 3363 | boolean isDockedResizing() { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 3364 | return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER) |
| 3365 | || (isChildWindow() && getParentWindow().isDockedResizing()); |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3368 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Wale Ogunwale | 30cc7bf | 2015-02-04 16:47:57 -0800 | [diff] [blame] | 3369 | final TaskStack stack = getStack(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3370 | pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId()); |
Wale Ogunwale | 30cc7bf | 2015-02-04 16:47:57 -0800 | [diff] [blame] | 3371 | if (stack != null) { |
| 3372 | pw.print(" stackId="); pw.print(stack.mStackId); |
| 3373 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3374 | pw.print(" mSession="); pw.print(mSession); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3375 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 3376 | pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 3377 | pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly); |
| 3378 | pw.print(" package="); pw.print(mAttrs.packageName); |
| 3379 | pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3380 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3381 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| 3382 | pw.print(" h="); pw.print(mRequestedHeight); |
| 3383 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 3384 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 3385 | pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth); |
| 3386 | pw.print(" h="); pw.println(mLastRequestedHeight); |
| 3387 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3388 | if (mIsChildWindow || mLayoutAttached) { |
| 3389 | pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3390 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 3391 | } |
| 3392 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 3393 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 3394 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| 3395 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 3396 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| 3397 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3398 | if (dumpAll) { |
| 3399 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 3400 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 3401 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 3402 | pw.print(getAnimLayerAdjustment()); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3403 | pw.print("="); pw.print(mWinAnimator.mAnimLayer); |
| 3404 | pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3405 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3406 | if (dumpAll) { |
| 3407 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3408 | if (mAppToken != null) { |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 3409 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 3410 | pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()="); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 3411 | pw.print(isAnimatingWithSavedSurface()); |
Bryce Lee | 6311c4b | 2017-07-06 14:09:29 -0700 | [diff] [blame] | 3412 | pw.print(" mAppDied=");pw.print(mAppDied); |
| 3413 | pw.print(prefix); pw.print("drawnStateEvaluated="); |
| 3414 | pw.print(getDrawnStateEvaluated()); |
| 3415 | pw.print(prefix); pw.print("mightAffectAllDrawn="); |
| 3416 | pw.println(mightAffectAllDrawn(false /*visibleOnly*/)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3417 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3418 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 3419 | pw.print(Integer.toHexString(mViewVisibility)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3420 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 3421 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 3422 | pw.print(prefix); pw.print("mSeq="); pw.print(mSeq); |
| 3423 | pw.print(" mSystemUiVisibility=0x"); |
| 3424 | pw.println(Integer.toHexString(mSystemUiVisibility)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3425 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 3426 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility |
Svetoslav Ganov | 71c5102 | 2016-09-02 17:54:37 -0700 | [diff] [blame] | 3427 | || isParentWindowHidden()|| mPermanentlyHidden) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3428 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 3429 | pw.print(mPolicyVisibility); |
| 3430 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 3431 | pw.print(mPolicyVisibilityAfterAnim); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 3432 | pw.print(" mAppOpVisibility="); |
| 3433 | pw.print(mAppOpVisibility); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 3434 | pw.print(" parentHidden="); pw.print(isParentWindowHidden()); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3435 | pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3436 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 3437 | if (!mRelayoutCalled || mLayoutNeeded) { |
| 3438 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled); |
| 3439 | pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3440 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3441 | if (mXOffset != 0 || mYOffset != 0) { |
| 3442 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 3443 | pw.print(" y="); pw.println(mYOffset); |
| 3444 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3445 | if (dumpAll) { |
| 3446 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 3447 | mGivenContentInsets.printShortString(pw); |
| 3448 | pw.print(" mGivenVisibleInsets="); |
| 3449 | mGivenVisibleInsets.printShortString(pw); |
| 3450 | pw.println(); |
| 3451 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 3452 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 3453 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3454 | Region region = new Region(); |
| 3455 | getTouchableRegion(region); |
| 3456 | pw.print(prefix); pw.print("touchable region="); pw.println(region); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3457 | } |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3458 | pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration()); |
| 3459 | pw.print(prefix); pw.print("mLastReportedConfiguration="); |
| 3460 | pw.println(mLastReportedConfiguration); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3461 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 3462 | pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface); |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 3463 | pw.print(" mShownPosition="); mShownPosition.printShortString(pw); |
Chong Zhang | a8975bd | 2016-01-28 17:13:47 -0800 | [diff] [blame] | 3464 | pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay()); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 3465 | pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface()); |
| 3466 | pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3467 | if (dumpAll) { |
| 3468 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 3469 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 3470 | pw.println(); |
| 3471 | } |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3472 | if (mEnforceSizeCompat) { |
| 3473 | pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3474 | pw.println(); |
| 3475 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3476 | if (dumpAll) { |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3477 | pw.print(prefix); pw.print("Frames: containing="); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3478 | mContainingFrame.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3479 | pw.print(" parent="); mParentFrame.printShortString(pw); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3480 | pw.println(); |
| 3481 | pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw); |
| 3482 | pw.print(" overscan="); mOverscanFrame.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3483 | pw.println(); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3484 | pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3485 | pw.print(" visible="); mVisibleFrame.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3486 | pw.println(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3487 | pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw); |
| 3488 | pw.println(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3489 | pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw); |
| 3490 | pw.println(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3491 | pw.print(prefix); pw.print("Cur insets: overscan="); |
| 3492 | mOverscanInsets.printShortString(pw); |
| 3493 | pw.print(" content="); mContentInsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3494 | pw.print(" visible="); mVisibleInsets.printShortString(pw); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3495 | pw.print(" stable="); mStableInsets.printShortString(pw); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 3496 | pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3497 | pw.print(" outsets="); mOutsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3498 | pw.println(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3499 | pw.print(prefix); pw.print("Lst insets: overscan="); |
| 3500 | mLastOverscanInsets.printShortString(pw); |
| 3501 | pw.print(" content="); mLastContentInsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3502 | pw.print(" visible="); mLastVisibleInsets.printShortString(pw); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3503 | pw.print(" stable="); mLastStableInsets.printShortString(pw); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3504 | pw.print(" physical="); mLastOutsets.printShortString(pw); |
| 3505 | pw.print(" outset="); mLastOutsets.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3506 | pw.println(); |
| 3507 | } |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 3508 | pw.print(prefix); pw.print(mWinAnimator); pw.println(":"); |
| 3509 | mWinAnimator.dump(pw, prefix + " ", dumpAll); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3510 | if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) { |
| 3511 | pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3512 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 3513 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 3514 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 3515 | } |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3516 | if (getOrientationChanging() || mAppFreezing || mTurnOnScreen |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3517 | || mReportOrientationChanged) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3518 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 3519 | pw.print(mOrientationChanging); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3520 | pw.print(" configOrientationChanging="); |
| 3521 | pw.print(mLastReportedConfiguration.orientation |
| 3522 | != getConfiguration().orientation); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3523 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
Wale Ogunwale | bfa81ad | 2017-05-24 15:14:42 -0700 | [diff] [blame] | 3524 | pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen); |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3525 | pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3526 | } |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 3527 | if (mLastFreezeDuration != 0) { |
| 3528 | pw.print(prefix); pw.print("mLastFreezeDuration="); |
| 3529 | TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println(); |
| 3530 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3531 | if (mHScale != 1 || mVScale != 1) { |
| 3532 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 3533 | pw.print(" mVScale="); pw.println(mVScale); |
| 3534 | } |
| 3535 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| 3536 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 3537 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 3538 | } |
| 3539 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 3540 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 3541 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 3542 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3543 | if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE |
| 3544 | || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 3545 | pw.print(prefix); pw.print("mWallpaperDisplayOffsetX="); |
| 3546 | pw.print(mWallpaperDisplayOffsetX); |
| 3547 | pw.print(" mWallpaperDisplayOffsetY="); |
| 3548 | pw.println(mWallpaperDisplayOffsetY); |
| 3549 | } |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3550 | if (mDrawLock != null) { |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 3551 | pw.print(prefix); pw.println("mDrawLock=" + mDrawLock); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3552 | } |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3553 | if (isDragResizing()) { |
| 3554 | pw.print(prefix); pw.println("isDragResizing=" + isDragResizing()); |
| 3555 | } |
| 3556 | if (computeDragResizing()) { |
| 3557 | pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing()); |
| 3558 | } |
Bryce Lee | 6311c4b | 2017-07-06 14:09:29 -0700 | [diff] [blame] | 3559 | pw.print(prefix); pw.println("isOnScreen=" + isOnScreen()); |
| 3560 | pw.print(prefix); pw.println("isVisible=" + isVisible()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3561 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3562 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3563 | @Override |
| 3564 | String getName() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3565 | return Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3566 | + " " + getWindowTag(); |
| 3567 | } |
| 3568 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3569 | CharSequence getWindowTag() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3570 | CharSequence tag = mAttrs.getTitle(); |
| 3571 | if (tag == null || tag.length() <= 0) { |
| 3572 | tag = mAttrs.packageName; |
| 3573 | } |
| 3574 | return tag; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | @Override |
| 3578 | public String toString() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3579 | final CharSequence title = getWindowTag(); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3580 | if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 3581 | mLastTitle = title; |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3582 | mWasExiting = mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3583 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3584 | + " u" + UserHandle.getUserId(mOwnerUid) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3585 | + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3586 | } |
| 3587 | return mStringNameCache; |
| 3588 | } |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3589 | |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3590 | void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) { |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3591 | if (mHScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3592 | clipRect.left = (int) (clipRect.left / mHScale); |
| 3593 | clipRect.right = (int) Math.ceil(clipRect.right / mHScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3594 | } |
| 3595 | if (mVScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3596 | clipRect.top = (int) (clipRect.top / mVScale); |
| 3597 | clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3598 | } |
| 3599 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3600 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3601 | void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) { |
| 3602 | final int pw = containingFrame.width(); |
| 3603 | final int ph = containingFrame.height(); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3604 | final Task task = getTask(); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3605 | final boolean inNonFullscreenContainer = !inFullscreenContainer(); |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 3606 | final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0; |
| 3607 | |
| 3608 | // We need to fit it to the display if either |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3609 | // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen |
| 3610 | // for the taskless windows) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3611 | // b) If it's a secondary app window, we also need to fit it to the display unless |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3612 | // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on |
| 3613 | // screen, but SurfaceViews want to be always at a specific location so we don't fit it to |
| 3614 | // the display. |
| 3615 | final boolean fitToDisplay = (task == null || !inNonFullscreenContainer) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3616 | || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3617 | float x, y; |
| 3618 | int w,h; |
| 3619 | |
| 3620 | if ((mAttrs.flags & FLAG_SCALED) != 0) { |
| 3621 | if (mAttrs.width < 0) { |
| 3622 | w = pw; |
| 3623 | } else if (mEnforceSizeCompat) { |
| 3624 | w = (int)(mAttrs.width * mGlobalScale + .5f); |
| 3625 | } else { |
| 3626 | w = mAttrs.width; |
| 3627 | } |
| 3628 | if (mAttrs.height < 0) { |
| 3629 | h = ph; |
| 3630 | } else if (mEnforceSizeCompat) { |
| 3631 | h = (int)(mAttrs.height * mGlobalScale + .5f); |
| 3632 | } else { |
| 3633 | h = mAttrs.height; |
| 3634 | } |
| 3635 | } else { |
| 3636 | if (mAttrs.width == MATCH_PARENT) { |
| 3637 | w = pw; |
| 3638 | } else if (mEnforceSizeCompat) { |
| 3639 | w = (int)(mRequestedWidth * mGlobalScale + .5f); |
| 3640 | } else { |
| 3641 | w = mRequestedWidth; |
| 3642 | } |
| 3643 | if (mAttrs.height == MATCH_PARENT) { |
| 3644 | h = ph; |
| 3645 | } else if (mEnforceSizeCompat) { |
| 3646 | h = (int)(mRequestedHeight * mGlobalScale + .5f); |
| 3647 | } else { |
| 3648 | h = mRequestedHeight; |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | if (mEnforceSizeCompat) { |
| 3653 | x = mAttrs.x * mGlobalScale; |
| 3654 | y = mAttrs.y * mGlobalScale; |
| 3655 | } else { |
| 3656 | x = mAttrs.x; |
| 3657 | y = mAttrs.y; |
| 3658 | } |
| 3659 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3660 | if (inNonFullscreenContainer && !layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 3661 | // Make sure window fits in containing frame since it is in a non-fullscreen task as |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3662 | // required by {@link Gravity#apply} call. |
| 3663 | w = Math.min(w, pw); |
| 3664 | h = Math.min(h, ph); |
| 3665 | } |
| 3666 | |
| 3667 | // Set mFrame |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3668 | Gravity.apply(mAttrs.gravity, w, h, containingFrame, |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3669 | (int) (x + mAttrs.horizontalMargin * pw), |
| 3670 | (int) (y + mAttrs.verticalMargin * ph), mFrame); |
| 3671 | |
| 3672 | // Now make sure the window fits in the overall display frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3673 | if (fitToDisplay) { |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3674 | Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3675 | } |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3676 | |
| 3677 | // We need to make sure we update the CompatFrame as it is used for |
| 3678 | // cropping decisions, etc, on systems where we lack a decor layer. |
| 3679 | mCompatFrame.set(mFrame); |
| 3680 | if (mEnforceSizeCompat) { |
| 3681 | // See comparable block in computeFrameLw. |
| 3682 | mCompatFrame.scale(mInvGlobalScale); |
| 3683 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3684 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 3685 | |
| 3686 | boolean isChildWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3687 | return mIsChildWindow; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3690 | boolean layoutInParentFrame() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3691 | return mIsChildWindow |
| 3692 | && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0; |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3695 | /** Returns the parent window if this is a child of another window, else null. */ |
| 3696 | WindowState getParentWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3697 | // NOTE: We are not calling getParent() directly as the WindowState might be a child of a |
| 3698 | // WindowContainer that isn't a WindowState. |
| 3699 | return (mIsChildWindow) ? ((WindowState) super.getParent()) : null; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | /** Returns the topmost parent window if this is a child of another window, else this. */ |
| 3703 | WindowState getTopParentWindow() { |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3704 | WindowState current = this; |
| 3705 | WindowState topParent = current; |
| 3706 | while (current != null && current.mIsChildWindow) { |
| 3707 | current = current.getParentWindow(); |
| 3708 | // Parent window can be null if the child is detached from it's parent already, but |
| 3709 | // someone still has a reference to access it. So, we return the top parent value we |
| 3710 | // already have instead of null. |
| 3711 | if (current != null) { |
| 3712 | topParent = current; |
| 3713 | } |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3714 | } |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3715 | return topParent; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3718 | boolean isParentWindowHidden() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3719 | final WindowState parent = getParentWindow(); |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3720 | return parent != null && parent.mHidden; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3721 | } |
| 3722 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3723 | void setWillReplaceWindow(boolean animate) { |
| 3724 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3725 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3726 | c.setWillReplaceWindow(animate); |
| 3727 | } |
| 3728 | |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3729 | if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0 |
| 3730 | || mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 3731 | // We don't set replacing on starting windows since they are added by window manager and |
| 3732 | // not the client so won't be replaced by the client. |
| 3733 | return; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3734 | } |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3735 | |
| 3736 | mWillReplaceWindow = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3737 | mReplacementWindow = null; |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3738 | mAnimateReplacingWindow = animate; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3739 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3740 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3741 | void clearWillReplaceWindow() { |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3742 | mWillReplaceWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3743 | mReplacementWindow = null; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3744 | mAnimateReplacingWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3745 | |
| 3746 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3747 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3748 | c.clearWillReplaceWindow(); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | boolean waitingForReplacement() { |
| 3753 | if (mWillReplaceWindow) { |
| 3754 | return true; |
| 3755 | } |
| 3756 | |
| 3757 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3758 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3759 | if (c.waitingForReplacement()) { |
| 3760 | return true; |
| 3761 | } |
| 3762 | } |
| 3763 | return false; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3764 | } |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3765 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3766 | void requestUpdateWallpaperIfNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3767 | final DisplayContent dc = getDisplayContent(); |
| 3768 | if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 3769 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 3770 | dc.setLayoutNeeded(); |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3771 | mService.mWindowPlacerLocked.requestTraversal(); |
| 3772 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3773 | |
| 3774 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3775 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3776 | c.requestUpdateWallpaperIfNeeded(); |
| 3777 | } |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3780 | float translateToWindowX(float x) { |
| 3781 | float winX = x - mFrame.left; |
| 3782 | if (mEnforceSizeCompat) { |
| 3783 | winX *= mGlobalScale; |
| 3784 | } |
| 3785 | return winX; |
| 3786 | } |
| 3787 | |
| 3788 | float translateToWindowY(float y) { |
| 3789 | float winY = y - mFrame.top; |
| 3790 | if (mEnforceSizeCompat) { |
| 3791 | winY *= mGlobalScale; |
| 3792 | } |
| 3793 | return winY; |
| 3794 | } |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3795 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3796 | private void transferDimToReplacement() { |
Robert Carr | 9fe459d | 2016-04-07 23:32:28 -0700 | [diff] [blame] | 3797 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3798 | final DisplayContent dc = getDisplayContent(); |
| 3799 | if (dimLayerUser != null && dc != null) { |
| 3800 | dc.mDimLayerController.applyDim(dimLayerUser, |
| 3801 | mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0); |
Robert Carr | 9fe459d | 2016-04-07 23:32:28 -0700 | [diff] [blame] | 3802 | } |
| 3803 | } |
| 3804 | |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3805 | // During activity relaunch due to resize, we sometimes use window replacement |
| 3806 | // for only child windows (as the main window is handled by window preservation) |
| 3807 | // and the big surface. |
| 3808 | // |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 3809 | // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to |
| 3810 | // TYPE_BASE_APPLICATION) are not children in the sense of an attached window, |
| 3811 | // we also want to replace them at such phases, as they won't be covered by window |
| 3812 | // preservation, and in general we expect them to return following relaunch. |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3813 | boolean shouldBeReplacedWithChildren() { |
Chong Zhang | 921f8e3 | 2016-08-17 14:26:57 -0700 | [diff] [blame] | 3814 | return mIsChildWindow || mAttrs.type == TYPE_APPLICATION |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 3815 | || mAttrs.type == TYPE_DRAWN_APPLICATION; |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3816 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3817 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3818 | void setWillReplaceChildWindows() { |
| 3819 | if (shouldBeReplacedWithChildren()) { |
| 3820 | setWillReplaceWindow(false /* animate */); |
| 3821 | } |
| 3822 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3823 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3824 | c.setWillReplaceChildWindows(); |
| 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | WindowState getReplacingWindow() { |
| 3829 | if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) { |
| 3830 | return this; |
| 3831 | } |
| 3832 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3833 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3834 | final WindowState replacing = c.getReplacingWindow(); |
| 3835 | if (replacing != null) { |
| 3836 | return replacing; |
| 3837 | } |
| 3838 | } |
| 3839 | return null; |
| 3840 | } |
| 3841 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3842 | @Override |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3843 | public int getRotationAnimationHint() { |
| 3844 | if (mAppToken != null) { |
| 3845 | return mAppToken.mRotationAnimationHint; |
| 3846 | } else { |
| 3847 | return -1; |
| 3848 | } |
| 3849 | } |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3850 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3851 | @Override |
| 3852 | public boolean isInputMethodWindow() { |
| 3853 | return mIsImWindow; |
| 3854 | } |
| 3855 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3856 | // This must be called while inside a transaction. |
| 3857 | boolean performShowLocked() { |
| 3858 | if (isHiddenFromUserLocked()) { |
| 3859 | if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid); |
| 3860 | hideLw(false); |
| 3861 | return false; |
| 3862 | } |
| 3863 | |
| 3864 | logPerformShow("performShow on "); |
| 3865 | |
Jorim Jaggi | a50da60 | 2016-12-29 11:51:42 +0100 | [diff] [blame] | 3866 | final int drawState = mWinAnimator.mDrawState; |
| 3867 | if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW) |
| 3868 | && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) { |
| 3869 | mAppToken.onFirstWindowDrawn(this, mWinAnimator); |
| 3870 | } |
| 3871 | |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 3872 | if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3873 | return false; |
| 3874 | } |
| 3875 | |
| 3876 | logPerformShow("Showing "); |
| 3877 | |
| 3878 | mService.enableScreenIfNeededLocked(); |
| 3879 | mWinAnimator.applyEnterAnimationLocked(); |
| 3880 | |
| 3881 | // Force the show in the next prepareSurfaceLocked() call. |
| 3882 | mWinAnimator.mLastAlpha = -1; |
| 3883 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG, |
| 3884 | "performShowLocked: mDrawState=HAS_DRAWN in " + this); |
| 3885 | mWinAnimator.mDrawState = HAS_DRAWN; |
| 3886 | mService.scheduleAnimationLocked(); |
| 3887 | |
| 3888 | if (mHidden) { |
| 3889 | mHidden = false; |
| 3890 | final DisplayContent displayContent = getDisplayContent(); |
| 3891 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3892 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3893 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3894 | if (c.mWinAnimator.mSurfaceController != null) { |
| 3895 | c.performShowLocked(); |
| 3896 | // It hadn't been shown, which means layout not performed on it, so now we |
| 3897 | // want to make sure to do a layout. If called from within the transaction |
| 3898 | // loop, this will cause it to restart with a new layout. |
| 3899 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3900 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | } |
| 3904 | } |
| 3905 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3906 | if (mAttrs.type == TYPE_INPUT_METHOD) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3907 | getDisplayContent().mDividerControllerLocked.resetImeHideRequested(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | return true; |
| 3911 | } |
| 3912 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3913 | private void logPerformShow(String prefix) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3914 | if (DEBUG_VISIBILITY |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 3915 | || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3916 | Slog.v(TAG, prefix + this |
| 3917 | + ": mDrawState=" + mWinAnimator.drawStateToString() |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 3918 | + " readyForDisplay=" + isReadyForDisplay() |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3919 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING) |
| 3920 | + " during animation: policyVis=" + mPolicyVisibility |
| 3921 | + " parentHidden=" + isParentWindowHidden() |
| 3922 | + " tok.hiddenRequested=" |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3923 | + (mAppToken != null && mAppToken.hiddenRequested) |
| 3924 | + " tok.hidden=" + (mAppToken != null && mAppToken.hidden) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3925 | + " animating=" + mWinAnimator.mAnimating |
| 3926 | + " tok animating=" |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3927 | + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3928 | + " Callers=" + Debug.getCallers(4)); |
| 3929 | } |
| 3930 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3931 | |
| 3932 | WindowInfo getWindowInfo() { |
| 3933 | WindowInfo windowInfo = WindowInfo.obtain(); |
| 3934 | windowInfo.type = mAttrs.type; |
| 3935 | windowInfo.layer = mLayer; |
| 3936 | windowInfo.token = mClient.asBinder(); |
| 3937 | windowInfo.title = mAttrs.accessibilityTitle; |
| 3938 | windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor; |
| 3939 | windowInfo.focused = isFocused(); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 3940 | Task task = getTask(); |
| 3941 | windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3942 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3943 | if (mIsChildWindow) { |
| 3944 | windowInfo.parentToken = getParentWindow().mClient.asBinder(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3947 | final int childCount = mChildren.size(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3948 | if (childCount > 0) { |
| 3949 | if (windowInfo.childTokens == null) { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3950 | windowInfo.childTokens = new ArrayList(childCount); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3951 | } |
| 3952 | for (int j = 0; j < childCount; j++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3953 | final WindowState child = mChildren.get(j); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3954 | windowInfo.childTokens.add(child.mClient.asBinder()); |
| 3955 | } |
| 3956 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3957 | return windowInfo; |
| 3958 | } |
| 3959 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3960 | int getHighestAnimLayer() { |
| 3961 | int highest = mWinAnimator.mAnimLayer; |
| 3962 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3963 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3964 | final int childLayer = c.getHighestAnimLayer(); |
| 3965 | if (childLayer > highest) { |
| 3966 | highest = childLayer; |
| 3967 | } |
| 3968 | } |
| 3969 | return highest; |
| 3970 | } |
| 3971 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3972 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3973 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3974 | if (mChildren.isEmpty()) { |
| 3975 | // The window has no children so we just return it. |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 3976 | return applyInOrderWithImeWindows(callback, traverseTopToBottom); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3980 | return forAllWindowTopToBottom(callback); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3981 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3982 | return forAllWindowBottomToTop(callback); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3986 | private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3987 | // We want to consume the negative sublayer children first because they need to appear |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3988 | // below the parent, then this window (the parent), and then the positive sublayer children |
| 3989 | // because they need to appear above the parent. |
| 3990 | int i = 0; |
| 3991 | final int count = mChildren.size(); |
| 3992 | WindowState child = mChildren.get(i); |
| 3993 | |
| 3994 | while (i < count && child.mSubLayer < 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3995 | if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3996 | return true; |
| 3997 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3998 | i++; |
| 3999 | if (i >= count) { |
| 4000 | break; |
| 4001 | } |
| 4002 | child = mChildren.get(i); |
| 4003 | } |
| 4004 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4005 | if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4006 | return true; |
| 4007 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4008 | |
| 4009 | while (i < count) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4010 | if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4011 | return true; |
| 4012 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4013 | i++; |
| 4014 | if (i >= count) { |
| 4015 | break; |
| 4016 | } |
| 4017 | child = mChildren.get(i); |
| 4018 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4019 | |
| 4020 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4023 | private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4024 | // We want to consume the positive sublayer children first because they need to appear |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4025 | // above the parent, then this window (the parent), and then the negative sublayer children |
| 4026 | // because they need to appear above the parent. |
| 4027 | int i = mChildren.size() - 1; |
| 4028 | WindowState child = mChildren.get(i); |
| 4029 | |
| 4030 | while (i >= 0 && child.mSubLayer >= 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4031 | if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4032 | return true; |
| 4033 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4034 | --i; |
| 4035 | if (i < 0) { |
| 4036 | break; |
| 4037 | } |
| 4038 | child = mChildren.get(i); |
| 4039 | } |
| 4040 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4041 | if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4042 | return true; |
| 4043 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4044 | |
| 4045 | while (i >= 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4046 | if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4047 | return true; |
| 4048 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4049 | --i; |
| 4050 | if (i < 0) { |
| 4051 | break; |
| 4052 | } |
| 4053 | child = mChildren.get(i); |
| 4054 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4055 | |
| 4056 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4059 | private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback, |
| 4060 | boolean traverseTopToBottom) { |
| 4061 | if (traverseTopToBottom) { |
| 4062 | if (mService.mInputMethodTarget == this) { |
| 4063 | // This window is the current IME target, so we need to process the IME windows |
| 4064 | // directly above it. |
| 4065 | if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) { |
| 4066 | return true; |
| 4067 | } |
| 4068 | } |
| 4069 | if (callback.apply(this)) { |
| 4070 | return true; |
| 4071 | } |
| 4072 | } else { |
| 4073 | if (callback.apply(this)) { |
| 4074 | return true; |
| 4075 | } |
| 4076 | if (mService.mInputMethodTarget == this) { |
| 4077 | // This window is the current IME target, so we need to process the IME windows |
| 4078 | // directly above it. |
| 4079 | if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) { |
| 4080 | return true; |
| 4081 | } |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | return false; |
| 4086 | } |
| 4087 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4088 | WindowState getWindow(Predicate<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4089 | if (mChildren.isEmpty()) { |
| 4090 | return callback.test(this) ? this : null; |
| 4091 | } |
| 4092 | |
| 4093 | // We want to consume the positive sublayer children first because they need to appear |
| 4094 | // above the parent, then this window (the parent), and then the negative sublayer children |
| 4095 | // because they need to appear above the parent. |
| 4096 | int i = mChildren.size() - 1; |
| 4097 | WindowState child = mChildren.get(i); |
| 4098 | |
| 4099 | while (i >= 0 && child.mSubLayer >= 0) { |
| 4100 | if (callback.test(child)) { |
| 4101 | return child; |
| 4102 | } |
| 4103 | --i; |
| 4104 | if (i < 0) { |
| 4105 | break; |
| 4106 | } |
| 4107 | child = mChildren.get(i); |
| 4108 | } |
| 4109 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4110 | if (callback.test(this)) { |
| 4111 | return this; |
| 4112 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4113 | |
| 4114 | while (i >= 0) { |
| 4115 | if (callback.test(child)) { |
| 4116 | return child; |
| 4117 | } |
| 4118 | --i; |
| 4119 | if (i < 0) { |
| 4120 | break; |
| 4121 | } |
| 4122 | child = mChildren.get(i); |
| 4123 | } |
| 4124 | |
| 4125 | return null; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4126 | } |
| 4127 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4128 | boolean isWindowAnimationSet() { |
| 4129 | if (mWinAnimator.isWindowAnimationSet()) { |
| 4130 | return true; |
| 4131 | } |
| 4132 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4133 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4134 | if (c.isWindowAnimationSet()) { |
| 4135 | return true; |
| 4136 | } |
| 4137 | } |
| 4138 | return false; |
| 4139 | } |
| 4140 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4141 | void onExitAnimationDone() { |
| 4142 | if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this |
| 4143 | + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit |
| 4144 | + " windowAnimating=" + mWinAnimator.isWindowAnimationSet()); |
| 4145 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4146 | if (!mChildren.isEmpty()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4147 | // Copying to a different list as multiple children can be removed. |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4148 | // TODO: Not sure if we really need to copy this into a different list. |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4149 | final LinkedList<WindowState> childWindows = new LinkedList(mChildren); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4150 | for (int i = childWindows.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4151 | childWindows.get(i).onExitAnimationDone(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | if (mWinAnimator.mEnteringAnimation) { |
| 4156 | mWinAnimator.mEnteringAnimation = false; |
| 4157 | mService.requestTraversal(); |
| 4158 | // System windows don't have an activity and an app token as a result, but need a way |
| 4159 | // to be informed about their entrance animation end. |
| 4160 | if (mAppToken == null) { |
| 4161 | try { |
| 4162 | mClient.dispatchWindowShown(); |
| 4163 | } catch (RemoteException e) { |
| 4164 | } |
| 4165 | } |
| 4166 | } |
| 4167 | |
| 4168 | if (!mWinAnimator.isWindowAnimationSet()) { |
| 4169 | //TODO (multidisplay): Accessibility is supported only for the default display. |
| 4170 | if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) { |
| 4171 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
| 4172 | } |
| 4173 | } |
| 4174 | |
| 4175 | if (!mAnimatingExit) { |
| 4176 | return; |
| 4177 | } |
| 4178 | |
| 4179 | if (mWinAnimator.isWindowAnimationSet()) { |
| 4180 | return; |
| 4181 | } |
| 4182 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 4183 | if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4184 | "Exit animation finished in " + this + ": remove=" + mRemoveOnExit); |
| 4185 | |
| 4186 | mDestroying = true; |
| 4187 | |
| 4188 | final boolean hasSurface = mWinAnimator.hasSurface(); |
| 4189 | if (hasSurface) { |
| 4190 | mWinAnimator.hide("onExitAnimationDone"); |
| 4191 | } |
| 4192 | |
| 4193 | // If we have an app token, we ask it to destroy the surface for us, so that it can take |
| 4194 | // care to ensure the activity has actually stopped and the surface is not still in use. |
| 4195 | // Otherwise we add the service to mDestroySurface and allow it to be processed in our next |
| 4196 | // transaction. |
| 4197 | if (mAppToken != null) { |
| 4198 | mAppToken.destroySurfaces(); |
| 4199 | } else { |
| 4200 | if (hasSurface) { |
| 4201 | mService.mDestroySurface.add(this); |
| 4202 | } |
| 4203 | if (mRemoveOnExit) { |
| 4204 | mService.mPendingRemove.add(this); |
| 4205 | mRemoveOnExit = false; |
| 4206 | } |
| 4207 | } |
| 4208 | mAnimatingExit = false; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 4209 | getDisplayContent().mWallpaperController.hideWallpapers(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4210 | } |
Dan Willemsen | 117197f | 2016-07-30 13:02:59 -0700 | [diff] [blame] | 4211 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4212 | boolean clearAnimatingFlags() { |
| 4213 | boolean didSomething = false; |
| 4214 | // We don't want to clear it out for windows that get replaced, because the |
| 4215 | // animation depends on the flag to remove the replaced window. |
| 4216 | // |
| 4217 | // We also don't clear the mAnimatingExit flag for windows which have the |
| 4218 | // mRemoveOnExit flag. This indicates an explicit remove request has been issued |
| 4219 | // by the client. We should let animation proceed and not clear this flag or |
| 4220 | // they won't eventually be removed by WindowStateAnimator#finishExit. |
| 4221 | if (!mWillReplaceWindow && !mRemoveOnExit) { |
| 4222 | // Clear mAnimating flag together with mAnimatingExit. When animation |
| 4223 | // changes from exiting to entering, we need to clear this flag until the |
| 4224 | // new animation gets applied, so that isAnimationStarting() becomes true |
| 4225 | // until then. |
| 4226 | // Otherwise applySurfaceChangesTransaction will fail to skip surface |
| 4227 | // placement for this window during this period, one or more frame will |
| 4228 | // show up with wrong position or scale. |
| 4229 | if (mAnimatingExit) { |
| 4230 | mAnimatingExit = false; |
| 4231 | didSomething = true; |
| 4232 | } |
| 4233 | if (mWinAnimator.mAnimating) { |
| 4234 | mWinAnimator.mAnimating = false; |
| 4235 | didSomething = true; |
| 4236 | } |
| 4237 | if (mDestroying) { |
| 4238 | mDestroying = false; |
| 4239 | mService.mDestroySurface.remove(this); |
| 4240 | didSomething = true; |
| 4241 | } |
| 4242 | } |
| 4243 | |
| 4244 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4245 | didSomething |= (mChildren.get(i)).clearAnimatingFlags(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
| 4248 | return didSomething; |
| 4249 | } |
| 4250 | |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4251 | public boolean isRtl() { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 4252 | return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4253 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4254 | |
| 4255 | void hideWallpaperWindow(boolean wasDeferred, String reason) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4256 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4257 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4258 | c.hideWallpaperWindow(wasDeferred, reason); |
| 4259 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4260 | if (!mWinAnimator.mLastHidden || wasDeferred) { |
| 4261 | mWinAnimator.hide(reason); |
| 4262 | dispatchWallpaperVisibility(false); |
| 4263 | final DisplayContent displayContent = getDisplayContent(); |
| 4264 | if (displayContent != null) { |
| 4265 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 4266 | } |
| 4267 | } |
| 4268 | } |
| 4269 | |
| 4270 | /** |
| 4271 | * Check wallpaper window for visibility change and notify window if so. |
| 4272 | * @param visible Current visibility. |
| 4273 | */ |
| 4274 | void dispatchWallpaperVisibility(final boolean visible) { |
| 4275 | final boolean hideAllowed = |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 4276 | getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4277 | |
| 4278 | // Only send notification if the visibility actually changed and we are not trying to hide |
| 4279 | // the wallpaper when we are deferring hiding of the wallpaper. |
| 4280 | if (mWallpaperVisible != visible && (hideAllowed || visible)) { |
| 4281 | mWallpaperVisible = visible; |
| 4282 | try { |
| 4283 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 4284 | "Updating vis of wallpaper " + this |
| 4285 | + ": " + visible + " from:\n" + Debug.getCallers(4, " ")); |
| 4286 | mClient.dispatchAppVisibility(visible); |
| 4287 | } catch (RemoteException e) { |
| 4288 | } |
| 4289 | } |
| 4290 | } |
| 4291 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4292 | boolean hasVisibleNotDrawnWallpaper() { |
| 4293 | if (mWallpaperVisible && !isDrawnLw()) { |
| 4294 | return true; |
| 4295 | } |
| 4296 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4297 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4298 | if (c.hasVisibleNotDrawnWallpaper()) { |
| 4299 | return true; |
| 4300 | } |
| 4301 | } |
| 4302 | return false; |
| 4303 | } |
| 4304 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4305 | void updateReportedVisibility(UpdateReportedVisibilityResults results) { |
| 4306 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4307 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4308 | c.updateReportedVisibility(results); |
| 4309 | } |
| 4310 | |
| 4311 | if (mAppFreezing || mViewVisibility != View.VISIBLE |
| 4312 | || mAttrs.type == TYPE_APPLICATION_STARTING |
| 4313 | || mDestroying) { |
| 4314 | return; |
| 4315 | } |
| 4316 | if (DEBUG_VISIBILITY) { |
| 4317 | Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw() |
| 4318 | + ", isAnimationSet=" + mWinAnimator.isAnimationSet()); |
| 4319 | if (!isDrawnLw()) { |
| 4320 | Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController |
| 4321 | + " pv=" + mPolicyVisibility |
| 4322 | + " mDrawState=" + mWinAnimator.mDrawState |
| 4323 | + " ph=" + isParentWindowHidden() |
| 4324 | + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| 4325 | + " a=" + mWinAnimator.mAnimating); |
| 4326 | } |
| 4327 | } |
| 4328 | |
| 4329 | results.numInteresting++; |
| 4330 | if (isDrawnLw()) { |
| 4331 | results.numDrawn++; |
| 4332 | if (!mWinAnimator.isAnimationSet()) { |
| 4333 | results.numVisible++; |
| 4334 | } |
| 4335 | results.nowGone = false; |
| 4336 | } else if (mWinAnimator.isAnimationSet()) { |
| 4337 | results.nowGone = false; |
| 4338 | } |
| 4339 | } |
| 4340 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4341 | /** |
| 4342 | * Calculate the window crop according to system decor policy. In general this is |
| 4343 | * the system decor rect (see #calculateSystemDecorRect), but we also have some |
| 4344 | * special cases. This rectangle is in screen space. |
| 4345 | */ |
| 4346 | void calculatePolicyCrop(Rect policyCrop) { |
| 4347 | final DisplayContent displayContent = getDisplayContent(); |
| 4348 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 4349 | |
| 4350 | if (!isDefaultDisplay()) { |
| 4351 | // On a different display there is no system decor. Crop the window |
| 4352 | // by the screen boundaries. |
| 4353 | // TODO(multi-display) |
| 4354 | policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height()); |
| 4355 | policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top, |
| 4356 | displayInfo.logicalWidth - mCompatFrame.left, |
| 4357 | displayInfo.logicalHeight - mCompatFrame.top); |
| 4358 | } else if (mLayer >= mService.mSystemDecorLayer) { |
| 4359 | // Above the decor layer is easy, just use the entire window |
| 4360 | policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height()); |
| 4361 | } else if (mDecorFrame.isEmpty()) { |
| 4362 | // Windows without policy decor aren't cropped. |
| 4363 | policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height()); |
| 4364 | } else { |
| 4365 | // Crop to the system decor specified by policy. |
| 4366 | calculateSystemDecorRect(policyCrop); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | /** |
| 4371 | * The system decor rect is the region of the window which is not covered |
| 4372 | * by system decorations. |
| 4373 | */ |
| 4374 | private void calculateSystemDecorRect(Rect systemDecorRect) { |
| 4375 | final Rect decorRect = mDecorFrame; |
| 4376 | final int width = mFrame.width(); |
| 4377 | final int height = mFrame.height(); |
| 4378 | |
| 4379 | // Compute the offset of the window in relation to the decor rect. |
| 4380 | final int left = mXOffset + mFrame.left; |
| 4381 | final int top = mYOffset + mFrame.top; |
| 4382 | |
| 4383 | // Initialize the decor rect to the entire frame. |
| 4384 | if (isDockedResizing()) { |
| 4385 | // If we are resizing with the divider, the task bounds might be smaller than the |
| 4386 | // stack bounds. The system decor is used to clip to the task bounds, which we don't |
| 4387 | // want in this case in order to avoid holes. |
| 4388 | // |
| 4389 | // We take care to not shrink the width, for surfaces which are larger than |
| 4390 | // the display region. Of course this area will not eventually be visible |
| 4391 | // but if we truncate the width now, we will calculate incorrectly |
| 4392 | // when adjusting to the stack bounds. |
| 4393 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
| 4394 | systemDecorRect.set(0, 0, |
| 4395 | Math.max(width, displayInfo.logicalWidth), |
| 4396 | Math.max(height, displayInfo.logicalHeight)); |
| 4397 | } else { |
| 4398 | systemDecorRect.set(0, 0, width, height); |
| 4399 | } |
| 4400 | |
| 4401 | // If a freeform window is animating from a position where it would be cutoff, it would be |
| 4402 | // cutoff during the animation. We don't want that, so for the duration of the animation |
| 4403 | // we ignore the decor cropping and depend on layering to position windows correctly. |
| 4404 | final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw()); |
| 4405 | if (cropToDecor) { |
| 4406 | // Intersect with the decor rect, offsetted by window position. |
| 4407 | systemDecorRect.intersect(decorRect.left - left, decorRect.top - top, |
| 4408 | decorRect.right - left, decorRect.bottom - top); |
| 4409 | } |
| 4410 | |
| 4411 | // If size compatibility is being applied to the window, the |
| 4412 | // surface is scaled relative to the screen. Also apply this |
| 4413 | // scaling to the crop rect. We aren't using the standard rect |
| 4414 | // scale function because we want to round things to make the crop |
| 4415 | // always round to a larger rect to ensure we don't crop too |
| 4416 | // much and hide part of the window that should be seen. |
| 4417 | if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) { |
| 4418 | final float scale = mInvGlobalScale; |
| 4419 | systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f); |
| 4420 | systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f); |
| 4421 | systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f); |
| 4422 | systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f); |
| 4423 | } |
| 4424 | |
| 4425 | } |
| 4426 | |
| 4427 | /** |
| 4428 | * Expand the given rectangle by this windows surface insets. This |
| 4429 | * takes you from the 'window size' to the 'surface size'. |
| 4430 | * The surface insets are positive in each direction, so we inset by |
| 4431 | * the inverse. |
| 4432 | */ |
| 4433 | void expandForSurfaceInsets(Rect r) { |
| 4434 | r.inset(-mAttrs.surfaceInsets.left, |
| 4435 | -mAttrs.surfaceInsets.top, |
| 4436 | -mAttrs.surfaceInsets.right, |
| 4437 | -mAttrs.surfaceInsets.bottom); |
| 4438 | } |
| 4439 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4440 | boolean surfaceInsetsChanging() { |
| 4441 | return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets); |
| 4442 | } |
| 4443 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 4444 | int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) { |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 4445 | final boolean wasVisible = isVisibleLw(); |
| 4446 | |
| 4447 | result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4448 | if (mAnimatingExit) { |
| 4449 | Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit=" |
| 4450 | + mRemoveOnExit + ", mDestroying=" + mDestroying); |
| 4451 | |
| 4452 | mWinAnimator.cancelExitAnimationForNextAnimationLocked(); |
| 4453 | mAnimatingExit = false; |
| 4454 | } |
| 4455 | if (mDestroying) { |
| 4456 | mDestroying = false; |
| 4457 | mService.mDestroySurface.remove(this); |
| 4458 | } |
| 4459 | if (oldVisibility == View.GONE) { |
| 4460 | mWinAnimator.mEnterAnimationPending = true; |
| 4461 | } |
| 4462 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4463 | mLastVisibleLayoutRotation = getDisplayContent().getRotation(); |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4464 | |
| 4465 | mWinAnimator.mEnteringAnimation = true; |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 4466 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 4467 | prepareWindowToDisplayDuringRelayout(wasVisible); |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 4468 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4469 | if ((attrChanges & FORMAT_CHANGED) != 0) { |
| 4470 | // If the format can't be changed in place, preserve the old surface until the app draws |
| 4471 | // on the new one. This prevents blinking when we change elevation of freeform and |
| 4472 | // pinned windows. |
| 4473 | if (!mWinAnimator.tryChangeFormatInPlaceLocked()) { |
| 4474 | mWinAnimator.preserveSurfaceLocked(); |
| 4475 | result |= RELAYOUT_RES_SURFACE_CHANGED |
| 4476 | | RELAYOUT_RES_FIRST_TIME; |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | // When we change the Surface size, in scenarios which may require changing |
| 4481 | // the surface position in sync with the resize, we use a preserved surface |
| 4482 | // so we can freeze it while waiting for the client to report draw on the newly |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4483 | // sized surface. Don't preserve surfaces if the insets change while animating the pinned |
| 4484 | // stack since it can lead to issues if a new surface is created while calculating the |
| 4485 | // scale for the animation using the source hint rect |
| 4486 | // (see WindowStateAnimator#setSurfaceBoundariesLocked()). |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4487 | if (isDragResizeChanged() || isResizedWhileNotDragResizing() |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4488 | || (surfaceInsetsChanging() && !inPinnedWorkspace())) { |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4489 | mLastSurfaceInsets.set(mAttrs.surfaceInsets); |
| 4490 | |
| 4491 | setDragResizing(); |
| 4492 | setResizedWhileNotDragResizing(false); |
| 4493 | // We can only change top level windows to the full-screen surface when |
| 4494 | // resizing (as we only have one full-screen surface). So there is no need |
| 4495 | // to preserve and destroy windows which are attached to another, they |
| 4496 | // will keep their surface and its size may change over time. |
| 4497 | if (mHasSurface && !isChildWindow()) { |
| 4498 | mWinAnimator.preserveSurfaceLocked(); |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 4499 | result |= RELAYOUT_RES_SURFACE_CHANGED | |
| 4500 | RELAYOUT_RES_FIRST_TIME; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | final boolean freeformResizing = isDragResizing() |
| 4504 | && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM; |
| 4505 | final boolean dockedResizing = isDragResizing() |
| 4506 | && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 4507 | result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0; |
| 4508 | result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0; |
| 4509 | if (isAnimatingWithSavedSurface()) { |
| 4510 | // If we're animating with a saved surface now, request client to report draw. |
| 4511 | // We still need to know when the real thing is drawn. |
| 4512 | result |= RELAYOUT_RES_FIRST_TIME; |
| 4513 | } |
| 4514 | return result; |
| 4515 | } |
| 4516 | |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 4517 | /** |
| 4518 | * @return True if this window has been laid out at least once; false otherwise. |
| 4519 | */ |
| 4520 | boolean isLaidOut() { |
| 4521 | return mLayoutSeq != -1; |
| 4522 | } |
| 4523 | |
| 4524 | /** |
| 4525 | * Updates the last inset values to the current ones. |
| 4526 | */ |
| 4527 | void updateLastInsetValues() { |
| 4528 | mLastOverscanInsets.set(mOverscanInsets); |
| 4529 | mLastContentInsets.set(mContentInsets); |
| 4530 | mLastVisibleInsets.set(mVisibleInsets); |
| 4531 | mLastStableInsets.set(mStableInsets); |
| 4532 | mLastOutsets.set(mOutsets); |
| 4533 | } |
| 4534 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4535 | // TODO: Hack to work around the number of states AppWindowToken needs to access without having |
| 4536 | // access to its windows children. Need to investigate re-writing |
| 4537 | // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed. |
| 4538 | static final class UpdateReportedVisibilityResults { |
| 4539 | int numInteresting; |
| 4540 | int numVisible; |
| 4541 | int numDrawn; |
| 4542 | boolean nowGone = true; |
| 4543 | |
| 4544 | void reset() { |
| 4545 | numInteresting = 0; |
| 4546 | numVisible = 0; |
| 4547 | numDrawn = 0; |
| 4548 | nowGone = true; |
| 4549 | } |
| 4550 | } |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 4551 | |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 4552 | private static final class WindowId extends IWindowId.Stub { |
| 4553 | private final WeakReference<WindowState> mOuter; |
| 4554 | |
| 4555 | private WindowId(WindowState outer) { |
| 4556 | |
| 4557 | // Use a weak reference for the outer class. This is important to prevent the following |
| 4558 | // leak: Since we send this class to the client process, binder will keep it alive as |
| 4559 | // long as the client keeps it alive. Now, if the window is removed, we need to clear |
| 4560 | // out our reference so even though this class is kept alive we don't leak WindowState, |
| 4561 | // which can keep a whole lot of classes alive. |
| 4562 | mOuter = new WeakReference<>(outer); |
| 4563 | } |
| 4564 | |
| 4565 | @Override |
| 4566 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 4567 | final WindowState outer = mOuter.get(); |
| 4568 | if (outer != null) { |
| 4569 | outer.registerFocusObserver(observer); |
| 4570 | } |
| 4571 | } |
| 4572 | @Override |
| 4573 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 4574 | final WindowState outer = mOuter.get(); |
| 4575 | if (outer != null) { |
| 4576 | outer.unregisterFocusObserver(observer); |
| 4577 | } |
| 4578 | } |
| 4579 | @Override |
| 4580 | public boolean isFocused() { |
| 4581 | final WindowState outer = mOuter.get(); |
| 4582 | return outer != null && outer.isFocused(); |
| 4583 | } |
| 4584 | } |
| 4585 | |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 4586 | boolean usesRelativeZOrdering() { |
| 4587 | if (!isChildWindow()) { |
| 4588 | return false; |
| 4589 | } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) { |
| 4590 | return true; |
| 4591 | } else { |
| 4592 | return false; |
| 4593 | } |
| 4594 | } |
satok | cef37fb | 2011-10-24 21:49:38 +0900 | [diff] [blame] | 4595 | } |