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