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