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