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