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