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