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 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 20 | import static android.app.AppOpsManager.MODE_ALLOWED; |
| 21 | import static android.app.AppOpsManager.MODE_DEFAULT; |
| 22 | import static android.app.AppOpsManager.OP_NONE; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 23 | import static android.os.PowerManager.DRAW_WAKE_LOCK; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 24 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
| 25 | import static android.view.Display.DEFAULT_DISPLAY; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 26 | import static android.view.SurfaceControl.Transaction; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 27 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; |
| 28 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 29 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
| 30 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE; |
| 31 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 32 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
| 33 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 34 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 35 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 36 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 38 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 39 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
| 40 | import static android.view.WindowManager.LayoutParams.FLAG_SCALED; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 42 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 43 | import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 44 | import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 45 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 46 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 47 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
| 48 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 49 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME; |
| 50 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; |
| 51 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH; |
| 52 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 53 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 54 | import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 55 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 56 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
Vishnu Nair | 1d0fa07 | 2018-01-04 07:53:00 -0800 | [diff] [blame] | 57 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 58 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 59 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 60 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 61 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
| 62 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 63 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 64 | import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; |
| 65 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 66 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 67 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 68 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 69 | import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 70 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED; |
| 71 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM; |
| 72 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME; |
| 73 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 74 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 75 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 76 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER; |
| 77 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT; |
| 78 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 79 | import static com.android.server.wm.AnimationSpecProto.MOVE; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 80 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 81 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 82 | import static com.android.server.wm.IdentifierProto.HASH_CODE; |
| 83 | import static com.android.server.wm.IdentifierProto.TITLE; |
| 84 | import static com.android.server.wm.IdentifierProto.USER_ID; |
| 85 | import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS; |
| 86 | import static com.android.server.wm.MoveAnimationSpecProto.FROM; |
| 87 | import static com.android.server.wm.MoveAnimationSpecProto.TO; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 88 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 89 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 90 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
| 91 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION; |
| 92 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
| 93 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
| 94 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 95 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 96 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 97 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 98 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
| 99 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE; |
| 100 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 101 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 102 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 103 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
| 104 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 105 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 106 | import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 107 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
| 108 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
| 109 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Tiger Huang | 8af6ba4 | 2018-06-07 19:24:09 +0800 | [diff] [blame] | 110 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 111 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
| 112 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
| 113 | import static com.android.server.wm.WindowManagerService.localLOGV; |
| 114 | import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING; |
| 115 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
| 116 | import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN; |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 117 | import static com.android.server.wm.WindowStateAnimator.PRESERVED_SURFACE_LAYER; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 118 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 119 | import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT; |
| 120 | import static com.android.server.wm.WindowStateProto.ANIMATOR; |
| 121 | import static com.android.server.wm.WindowStateProto.ATTRIBUTES; |
| 122 | import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 123 | import static com.android.server.wm.WindowStateProto.DESTROYING; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 124 | import static com.android.server.wm.WindowStateProto.DISPLAY_ID; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 125 | import static com.android.server.wm.WindowStateProto.FINISHED_SEAMLESS_ROTATION_FRAME; |
| 126 | import static com.android.server.wm.WindowStateProto.FORCE_SEAMLESS_ROTATION; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 127 | import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS; |
| 128 | import static com.android.server.wm.WindowStateProto.HAS_SURFACE; |
| 129 | import static com.android.server.wm.WindowStateProto.IDENTIFIER; |
| 130 | import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN; |
| 131 | import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY; |
| 132 | import static com.android.server.wm.WindowStateProto.IS_VISIBLE; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 133 | import static com.android.server.wm.WindowStateProto.PENDING_SEAMLESS_ROTATION; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 134 | import static com.android.server.wm.WindowStateProto.REMOVED; |
| 135 | import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT; |
| 136 | import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT; |
| 137 | import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 138 | import static com.android.server.wm.WindowStateProto.STACK_ID; |
| 139 | import static com.android.server.wm.WindowStateProto.SURFACE_INSETS; |
| 140 | import static com.android.server.wm.WindowStateProto.SURFACE_POSITION; |
| 141 | import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY; |
| 142 | import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 143 | import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER; |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 144 | import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 145 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 146 | import android.annotation.CallSuper; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 147 | import android.annotation.Nullable; |
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; |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 160 | import android.os.PowerManager.WakeReason; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 161 | import android.os.RemoteCallbackList; |
| 162 | import android.os.RemoteException; |
| 163 | import android.os.SystemClock; |
| 164 | import android.os.Trace; |
| 165 | import android.os.UserHandle; |
| 166 | import android.os.WorkSource; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 167 | import android.provider.Settings; |
Phil Weaver | bb2f28a | 2017-12-22 09:44:28 -0800 | [diff] [blame] | 168 | import android.text.TextUtils; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 169 | import android.util.DisplayMetrics; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 170 | import android.util.MergedConfiguration; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 171 | import android.util.Slog; |
| 172 | import android.util.TimeUtils; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 173 | import android.util.proto.ProtoOutputStream; |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 174 | import android.view.Display; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 175 | import android.view.DisplayCutout; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 176 | import android.view.DisplayInfo; |
| 177 | import android.view.Gravity; |
| 178 | import android.view.IApplicationToken; |
| 179 | import android.view.IWindow; |
| 180 | import android.view.IWindowFocusObserver; |
| 181 | import android.view.IWindowId; |
| 182 | import android.view.InputChannel; |
| 183 | import android.view.InputEvent; |
| 184 | import android.view.InputEventReceiver; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 185 | import android.view.InputWindowHandle; |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 186 | import android.view.Surface.Rotation; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 187 | import android.view.SurfaceControl; |
| 188 | import android.view.SurfaceSession; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 189 | import android.view.View; |
| 190 | import android.view.ViewTreeObserver; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 191 | import android.view.WindowInfo; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 192 | import android.view.WindowManager; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 193 | import android.view.animation.Animation; |
| 194 | import android.view.animation.AnimationUtils; |
| 195 | import android.view.animation.Interpolator; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 196 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 197 | import com.android.internal.annotations.VisibleForTesting; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 198 | import com.android.internal.util.ToBooleanFunction; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 199 | import com.android.server.policy.WindowManagerPolicy; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 200 | import com.android.server.wm.LocalAnimationAdapter.AnimationSpec; |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 201 | import com.android.server.wm.utils.InsetUtils; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 202 | import com.android.server.wm.utils.WmDisplayCutout; |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 203 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 204 | import java.io.PrintWriter; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 205 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 206 | import java.util.ArrayList; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 207 | import java.util.Comparator; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 208 | import java.util.List; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 209 | import java.util.function.Predicate; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 210 | |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 211 | /** A window in the window manager. */ |
| 212 | class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 213 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 214 | |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 215 | // 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] | 216 | // TODO(multi-window): fix the min sizes when we have mininum width/height support, |
| 217 | // use hard-coded min sizes for now. |
| 218 | static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48; |
| 219 | static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 220 | |
| 221 | // The thickness of a window resize handle outside the window bounds on the free form workspace |
| 222 | // to capture touch events in that area. |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 223 | static final int RESIZE_HANDLE_WIDTH_IN_DP = 30; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 224 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 225 | final WindowManagerPolicy mPolicy; |
| 226 | final Context mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 227 | final Session mSession; |
| 228 | final IWindow mClient; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 229 | final int mAppOp; |
| 230 | // UserId and appId of the owner. Don't display windows of non-current user. |
| 231 | final int mOwnerUid; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 232 | /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */ |
| 233 | final boolean mOwnerCanAddInternalSystemWindow; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 234 | final WindowId mWindowId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 235 | WindowToken mToken; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 236 | // 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] | 237 | AppWindowToken mAppToken; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 238 | |
| 239 | // mAttrs.flags is tested in animation without being locked. If the bits tested are ever |
| 240 | // modified they will need to be locked. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 241 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 242 | final DeathRecipient mDeathRecipient; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 243 | private boolean mIsChildWindow; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 244 | final int mBaseLayer; |
| 245 | final int mSubLayer; |
| 246 | final boolean mLayoutAttached; |
| 247 | final boolean mIsImWindow; |
| 248 | final boolean mIsWallpaper; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 249 | private final boolean mIsFloatingLayer; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 250 | int mSeq; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 251 | int mViewVisibility; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 252 | int mSystemUiVisibility; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 253 | /** |
| 254 | * The visibility of the window based on policy like {@link WindowManagerPolicy}. |
| 255 | * Normally set by calling {@link #showLw} and {@link #hideLw}. |
| 256 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 257 | boolean mPolicyVisibility = true; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 258 | /** |
| 259 | * What {@link #mPolicyVisibility} should be set to after a transition animation. |
| 260 | * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and |
| 261 | * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit |
| 262 | * animation is done. |
| 263 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 264 | boolean mPolicyVisibilityAfterAnim = true; |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 265 | // overlay window is hidden because the owning app is suspended |
| 266 | private boolean mHiddenWhileSuspended; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 267 | private boolean mAppOpVisibility = true; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 268 | boolean mPermanentlyHidden; // the window should never be shown again |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 269 | // This is a non-system overlay window that is currently force hidden. |
| 270 | private boolean mForceHideNonSystemOverlayWindow; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 271 | boolean mAppFreezing; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 272 | boolean mHidden = true; // Used to determine if to show child windows. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 273 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 274 | private boolean mDragResizing; |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 275 | private boolean mDragResizingChangeReported = true; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 276 | private int mResizeMode; |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Special mode that is intended only for the rounded corner overlay: during rotation |
| 279 | * transition, we un-rotate the window token such that the window appears as it did before the |
| 280 | * rotation. |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 281 | */ |
| 282 | final boolean mForceSeamlesslyRotate; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 283 | SeamlessRotator mPendingSeamlessRotate; |
| 284 | long mFinishSeamlessRotateFrameNumber; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 285 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 286 | private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 287 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 288 | /** |
| 289 | * The window size that was requested by the application. These are in |
| 290 | * the application's coordinate space (without compatibility scale applied). |
| 291 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 292 | int mRequestedWidth; |
| 293 | int mRequestedHeight; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 294 | private int mLastRequestedWidth; |
| 295 | private int mLastRequestedHeight; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 296 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 297 | int mLayer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 298 | boolean mHaveFrame; |
| 299 | boolean mObscured; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 300 | |
| 301 | int mLayoutSeq = -1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 302 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 303 | /** |
| 304 | * Used to store last reported to client configuration and check if we have newer available. |
| 305 | * We'll send configuration to client only if it is different from the last applied one and |
| 306 | * client won't perform unnecessary updates. |
| 307 | */ |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 308 | private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 309 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 310 | private final Configuration mTempConfiguration = new Configuration(); |
| 311 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 312 | /** |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 313 | * The last content insets returned to the client in relayout. We use |
| 314 | * these in the bounds animation to ensure we only observe inset changes |
| 315 | * at the same time that a client resizes it's surface so that we may use |
| 316 | * the geometryAppliesWithResize synchronization mechanism to keep |
| 317 | * the contents in place. |
| 318 | */ |
| 319 | final Rect mLastRelayoutContentInsets = new Rect(); |
| 320 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 321 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 322 | * Set to true if we are waiting for this window to receive its |
| 323 | * given internal insets before laying out other windows based on it. |
| 324 | */ |
| 325 | boolean mGivenInsetsPending; |
| 326 | |
| 327 | /** |
| 328 | * These are the content insets that were given during layout for |
| 329 | * this window, to be applied to windows behind it. |
| 330 | */ |
| 331 | final Rect mGivenContentInsets = new Rect(); |
| 332 | |
| 333 | /** |
| 334 | * These are the visible insets that were given during layout for |
| 335 | * this window, to be applied to windows behind it. |
| 336 | */ |
| 337 | final Rect mGivenVisibleInsets = new Rect(); |
| 338 | |
| 339 | /** |
| 340 | * This is the given touchable area relative to the window frame, or null if none. |
| 341 | */ |
| 342 | final Region mGivenTouchableRegion = new Region(); |
| 343 | |
| 344 | /** |
| 345 | * Flag indicating whether the touchable region should be adjusted by |
| 346 | * the visible insets; if false the area outside the visible insets is |
| 347 | * NOT touchable, so we must use those to adjust the frame during hit |
| 348 | * tests. |
| 349 | */ |
| 350 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 351 | |
| 352 | // Current transformation being applied. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 353 | float mGlobalScale=1; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 354 | float mInvGlobalScale=1; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 355 | float mHScale=1, mVScale=1; |
| 356 | float mLastHScale=1, mLastVScale=1; |
| 357 | final Matrix mTmpMatrix = new Matrix(); |
| 358 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 359 | private final WindowFrames mWindowFrames = new WindowFrames(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 360 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 361 | /** |
| 362 | * Usually empty. Set to the task's tempInsetFrame. See |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 363 | *{@link android.app.IActivityTaskManager#resizeDockedStack}. |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 364 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 365 | private final Rect mInsetFrame = new Rect(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 366 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 367 | /** |
| 368 | * List of rects where system gestures should be ignored. |
| 369 | * |
| 370 | * Coordinates are relative to the window's position. |
| 371 | */ |
| 372 | private final List<Rect> mExclusionRects = new ArrayList<>(); |
| 373 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 374 | // If a window showing a wallpaper: the requested offset for the |
| 375 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 376 | float mWallpaperX = -1; |
| 377 | float mWallpaperY = -1; |
| 378 | |
| 379 | // If a window showing a wallpaper: what fraction of the offset |
| 380 | // range corresponds to a full virtual screen. |
| 381 | float mWallpaperXStep = -1; |
| 382 | float mWallpaperYStep = -1; |
| 383 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 384 | // If a window showing a wallpaper: a raw pixel offset to forcibly apply |
| 385 | // to its window; if a wallpaper window: not used. |
| 386 | int mWallpaperDisplayOffsetX = Integer.MIN_VALUE; |
| 387 | int mWallpaperDisplayOffsetY = Integer.MIN_VALUE; |
| 388 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 389 | /** |
| 390 | * This is set after IWindowSession.relayout() has been called at |
| 391 | * least once for the window. It allows us to detect the situation |
| 392 | * where we don't yet have a surface, but should have one soon, so |
| 393 | * we can give the window focus before waiting for the relayout. |
| 394 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 395 | boolean mRelayoutCalled; |
| 396 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 397 | boolean mInRelayout; |
| 398 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 399 | /** |
| 400 | * If the application has called relayout() with changes that can |
| 401 | * impact its window's size, we need to perform a layout pass on it |
| 402 | * even if it is not currently visible for layout. This is set |
| 403 | * when in that case until the layout is done. |
| 404 | */ |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 405 | boolean mLayoutNeeded; |
| 406 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 407 | /** Currently running an exit animation? */ |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 408 | boolean mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 409 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 410 | /** Currently on the mDestroySurface list? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 411 | boolean mDestroying; |
| 412 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 413 | /** Completely remove from window manager after exit animation? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 414 | boolean mRemoveOnExit; |
| 415 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 416 | /** |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 417 | * Whether the app died while it was visible, if true we might need |
| 418 | * to continue to show it until it's restarted. |
| 419 | */ |
| 420 | boolean mAppDied; |
| 421 | |
| 422 | /** |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 423 | * Set when the orientation is changing and this window has not yet |
| 424 | * been updated for the new orientation. |
| 425 | */ |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 426 | private boolean mOrientationChanging; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 427 | |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 428 | /** |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 429 | * Sometimes in addition to the mOrientationChanging |
| 430 | * flag we report that the orientation is changing |
| 431 | * due to a mismatch in current and reported configuration. |
| 432 | * |
| 433 | * In the case of timeout we still need to make sure we |
| 434 | * leave the orientation changing state though, so we |
| 435 | * use this as a special time out escape hatch. |
| 436 | */ |
| 437 | private boolean mOrientationChangeTimedOut; |
| 438 | |
| 439 | /** |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 440 | * The orientation during the last visible call to relayout. If our |
| 441 | * current orientation is different, the window can't be ready |
| 442 | * to be shown. |
| 443 | */ |
| 444 | int mLastVisibleLayoutRotation = -1; |
| 445 | |
| 446 | /** |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 447 | * Set when we need to report the orientation change to client to trigger a relayout. |
| 448 | */ |
| 449 | boolean mReportOrientationChanged; |
| 450 | |
| 451 | /** |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 452 | * How long we last kept the screen frozen. |
| 453 | */ |
| 454 | int mLastFreezeDuration; |
| 455 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 456 | /** Is this window now (or just being) removed? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 457 | boolean mRemoved; |
| 458 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 459 | /** |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 460 | * It is save to remove the window and destroy the surface because the client requested removal |
| 461 | * or some other higher level component said so (e.g. activity manager). |
| 462 | * 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] | 463 | */ |
Svetoslav Ganov | 200adfb | 2016-10-18 13:29:27 -0700 | [diff] [blame] | 464 | boolean mWindowRemovalAllowed; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 465 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 466 | // Input channel and input window handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 467 | final InputWindowHandle mInputWindowHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 468 | InputChannel mInputChannel; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 469 | private InputChannel mClientChannel; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 470 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 471 | // Used to improve performance of toString() |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 472 | private String mStringNameCache; |
| 473 | private CharSequence mLastTitle; |
| 474 | private boolean mWasExiting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 475 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 476 | final WindowStateAnimator mWinAnimator; |
| 477 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 478 | boolean mHasSurface = false; |
| 479 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 480 | /** When true this window can be displayed on screens owther than mOwnerUid's */ |
| 481 | private boolean mShowToOwnerOnly; |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 482 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 483 | // Whether the window was visible when we set the app to invisible last time. WM uses |
| 484 | // this as a hint to restore the surface (if available) for early animation next time |
| 485 | // the app is brought visible. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 486 | private boolean mWasVisibleBeforeClientHidden; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 487 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 488 | // This window will be replaced due to relaunch. This allows window manager |
| 489 | // to differentiate between simple removal of a window and replacement. In the latter case it |
| 490 | // will preserve the old window until the new one is drawn. |
| 491 | boolean mWillReplaceWindow = false; |
| 492 | // If true, the replaced window was already requested to be removed. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 493 | private boolean mReplacingRemoveRequested = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 494 | // Whether the replacement of the window should trigger app transition animation. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 495 | private boolean mAnimateReplacingWindow = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 496 | // If not null, the window that will be used to replace the old one. This is being set when |
| 497 | // 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] | 498 | private WindowState mReplacementWindow = null; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 499 | // For the new window in the replacement transition, if we have |
| 500 | // requested to replace without animation, then we should |
| 501 | // make sure we also don't apply an enter animation for |
| 502 | // the new window. |
| 503 | boolean mSkipEnterAnimationForSeamlessReplacement = false; |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 504 | // Whether this window is being moved via the resize API |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 505 | private boolean mMovedByResize; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 506 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 507 | /** |
| 508 | * Wake lock for drawing. |
| 509 | * Even though it's slightly more expensive to do so, we will use a separate wake lock |
| 510 | * for each app that is requesting to draw while dozing so that we can accurately track |
| 511 | * who is preventing the system from suspending. |
| 512 | * This lock is only acquired on first use. |
| 513 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 514 | private PowerManager.WakeLock mDrawLock; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 515 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 516 | private final Rect mTmpRect = new Rect(); |
| 517 | private final Point mTmpPoint = new Point(); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 518 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 519 | /** |
| 520 | * Whether the window was resized by us while it was gone for layout. |
| 521 | */ |
| 522 | boolean mResizedWhileGone = false; |
| 523 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 524 | /** |
| 525 | * During seamless rotation we have two phases, first the old window contents |
| 526 | * are rotated to look as if they didn't move in the new coordinate system. Then we |
| 527 | * have to freeze updates to this layer (to preserve the transformation) until |
| 528 | * the resize actually occurs. This is true from when the transformation is set |
| 529 | * and false until the transaction to resize is sent. |
| 530 | */ |
| 531 | boolean mSeamlesslyRotated = false; |
| 532 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 533 | /** |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 534 | * Surface insets from the previous call to relayout(), used to track |
| 535 | * if we are changing the Surface insets. |
| 536 | */ |
| 537 | final Rect mLastSurfaceInsets = new Rect(); |
| 538 | |
| 539 | /** |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 540 | * A flag set by the {@link WindowState} parent to indicate that the parent has examined this |
| 541 | * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to |
| 542 | * make sure all children have been considered. |
| 543 | */ |
| 544 | private boolean mDrawnStateEvaluated; |
| 545 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 546 | private final Point mSurfacePosition = new Point(); |
| 547 | |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 548 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 549 | * A region inside of this window to be excluded from touch. |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 550 | */ |
| 551 | private TapExcludeRegionHolder mTapExcludeRegionHolder; |
| 552 | |
| 553 | /** |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 554 | * Used for testing because the real PowerManager is final. |
| 555 | */ |
| 556 | private PowerManagerWrapper mPowerManagerWrapper; |
| 557 | |
| 558 | /** |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 559 | * A frame number in which changes requested in this layout will be rendered. |
| 560 | */ |
| 561 | private long mFrameNumber = -1; |
| 562 | |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 563 | private static final StringBuilder sTmpSB = new StringBuilder(); |
| 564 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 565 | /** |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 566 | * 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] | 567 | * of z-order and 1 otherwise. |
| 568 | */ |
Griff Hazen | 51d00d8 | 2016-11-22 15:39:24 -0800 | [diff] [blame] | 569 | private static final Comparator<WindowState> sWindowSubLayerComparator = |
| 570 | new Comparator<WindowState>() { |
| 571 | @Override |
| 572 | public int compare(WindowState w1, WindowState w2) { |
| 573 | final int layer1 = w1.mSubLayer; |
| 574 | final int layer2 = w2.mSubLayer; |
| 575 | if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) { |
| 576 | // We insert the child window into the list ordered by |
| 577 | // the sub-layer. For same sub-layers, the negative one |
| 578 | // should go below others; the positive one should go |
| 579 | // above others. |
| 580 | return -1; |
| 581 | } |
| 582 | return 1; |
| 583 | }; |
| 584 | }; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 585 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 586 | /** |
| 587 | * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host |
| 588 | * container. |
| 589 | */ |
| 590 | private boolean mIsDimming = false; |
| 591 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 592 | private @Nullable InsetsSourceProvider mInsetProvider; |
| 593 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 594 | private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f; |
| 595 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 596 | void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation, |
| 597 | @Rotation int rotation, boolean requested) { |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 598 | // Invisible windows and the wallpaper do not participate in the seamless rotation animation |
| 599 | if (!isVisibleNow() || mIsWallpaper) { |
| 600 | return; |
| 601 | } |
Adrian Roos | faa102f | 2018-08-02 15:56:15 +0200 | [diff] [blame] | 602 | |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 603 | if (mPendingSeamlessRotate != null) { |
| 604 | oldRotation = mPendingSeamlessRotate.getOldRotation(); |
| 605 | } |
| 606 | |
| 607 | if (mForceSeamlesslyRotate || requested) { |
| 608 | mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo()); |
Vishnu Nair | ec63406 | 2018-09-20 20:16:18 -0700 | [diff] [blame] | 609 | mPendingSeamlessRotate.unrotate(transaction, this); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 610 | mWmService.markForSeamlessRotation(this, true); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 614 | void finishSeamlessRotation(boolean timeout) { |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 615 | if (mPendingSeamlessRotate != null) { |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 616 | mPendingSeamlessRotate.finish(this, timeout); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 617 | mFinishSeamlessRotateFrameNumber = getFrameNumber(); |
| 618 | mPendingSeamlessRotate = null; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 619 | mWmService.markForSeamlessRotation(this, false); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 623 | List<Rect> getSystemGestureExclusion() { |
| 624 | return mExclusionRects; |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * Sets the system gesture exclusion rects. |
| 629 | * |
| 630 | * @return {@code true} if anything changed |
| 631 | */ |
| 632 | boolean setSystemGestureExclusion(List<Rect> exclusionRects) { |
| 633 | if (mExclusionRects.equals(exclusionRects)) { |
| 634 | return false; |
| 635 | } |
| 636 | mExclusionRects.clear(); |
| 637 | mExclusionRects.addAll(exclusionRects); |
| 638 | return true; |
| 639 | } |
| 640 | |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 641 | interface PowerManagerWrapper { |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 642 | void wakeUp(long time, @WakeReason int reason, String details); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 643 | |
| 644 | boolean isInteractive(); |
| 645 | |
| 646 | } |
| 647 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 648 | WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 649 | WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a, |
| 650 | int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) { |
| 651 | this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId, |
| 652 | ownerCanAddInternalSystemWindow, new PowerManagerWrapper() { |
| 653 | @Override |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 654 | public void wakeUp(long time, @WakeReason int reason, String details) { |
| 655 | service.mPowerManager.wakeUp(time, reason, details); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | @Override |
| 659 | public boolean isInteractive() { |
| 660 | return service.mPowerManager.isInteractive(); |
| 661 | } |
| 662 | }); |
| 663 | } |
| 664 | |
| 665 | WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, |
| 666 | WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a, |
| 667 | int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow, |
| 668 | PowerManagerWrapper powerManagerWrapper) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 669 | super(service); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 670 | mSession = s; |
| 671 | mClient = c; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 672 | mAppOp = appOp; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 673 | mToken = token; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 674 | mAppToken = mToken.asAppWindowToken(); |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 675 | mOwnerUid = ownerId; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 676 | mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 677 | mWindowId = new WindowId(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 678 | mAttrs.copyFrom(a); |
Robert Carr | b08ed04 | 2018-03-12 15:49:08 -0700 | [diff] [blame] | 679 | mLastSurfaceInsets.set(mAttrs.surfaceInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 680 | mViewVisibility = viewVisibility; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 681 | mPolicy = mWmService.mPolicy; |
| 682 | mContext = mWmService.mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 683 | DeathRecipient deathRecipient = new DeathRecipient(); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 684 | mSeq = seq; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 685 | mPowerManagerWrapper = powerManagerWrapper; |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 686 | mForceSeamlesslyRotate = token.mRoundedCornerOverlay; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 687 | if (localLOGV) Slog.v( |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 688 | TAG, "Window " + this + " client=" + c.asBinder() |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 689 | + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 690 | try { |
| 691 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 692 | } catch (RemoteException e) { |
| 693 | mDeathRecipient = null; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 694 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 695 | mLayoutAttached = false; |
| 696 | mIsImWindow = false; |
| 697 | mIsWallpaper = false; |
| 698 | mIsFloatingLayer = false; |
| 699 | mBaseLayer = 0; |
| 700 | mSubLayer = 0; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 701 | mInputWindowHandle = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 702 | mWinAnimator = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 703 | return; |
| 704 | } |
| 705 | mDeathRecipient = deathRecipient; |
| 706 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 707 | if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 708 | // The multiplier here is to reserve space for multiple |
| 709 | // windows in the same type layer. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 710 | mBaseLayer = mPolicy.getWindowLayerLw(parentWindow) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 711 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 712 | mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 713 | mIsChildWindow = true; |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 714 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 715 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow); |
| 716 | parentWindow.addChild(this, sWindowSubLayerComparator); |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 717 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 718 | mLayoutAttached = mAttrs.type != |
| 719 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
Wale Ogunwale | 7ed4d37 | 2016-07-09 15:28:55 -0700 | [diff] [blame] | 720 | mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 721 | || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 722 | mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 723 | } else { |
| 724 | // The multiplier here is to reserve space for multiple |
| 725 | // windows in the same type layer. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 726 | mBaseLayer = mPolicy.getWindowLayerLw(this) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 727 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 728 | mSubLayer = 0; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 729 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 730 | mLayoutAttached = false; |
| 731 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 732 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 733 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 734 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 735 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 736 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 737 | if (mAppToken != null && mAppToken.mShowForAllUsers) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 738 | // Windows for apps that can show for all users should also show when the device is |
| 739 | // locked. |
| 740 | mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED; |
Craig Mautner | 19ab828 | 2014-05-07 10:35:34 -0700 | [diff] [blame] | 741 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 742 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 743 | mWinAnimator = new WindowStateAnimator(this); |
| 744 | mWinAnimator.mAlpha = a.alpha; |
| 745 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 746 | mRequestedWidth = 0; |
| 747 | mRequestedHeight = 0; |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 748 | mLastRequestedWidth = 0; |
| 749 | mLastRequestedHeight = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 750 | mLayer = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 751 | mInputWindowHandle = new InputWindowHandle( |
Robert Carr | e0a353c | 2018-08-02 16:38:04 -0700 | [diff] [blame] | 752 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, c, |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 753 | getDisplayId()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | void attach() { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 757 | if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken); |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 758 | mSession.windowAddedLocked(mAttrs.packageName); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 759 | } |
| 760 | |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 761 | /** |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 762 | * @return {@code true} if the application runs in size compatibility mode. |
| 763 | * @see android.content.res.CompatibilityInfo#supportsScreen |
| 764 | * @see ActivityRecord#inSizeCompatMode |
| 765 | */ |
| 766 | boolean inSizeCompatMode() { |
| 767 | return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0 |
| 768 | || (mAppToken != null && mAppToken.inSizeCompatMode() |
| 769 | // Exclude starting window because it is not displayed by the application. |
| 770 | && mAttrs.type != TYPE_APPLICATION_STARTING); |
| 771 | } |
| 772 | |
| 773 | /** |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 774 | * Returns whether this {@link WindowState} has been considered for drawing by its parent. |
| 775 | */ |
Bryce Lee | 6311c4b | 2017-07-06 14:09:29 -0700 | [diff] [blame] | 776 | boolean getDrawnStateEvaluated() { |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 777 | return mDrawnStateEvaluated; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should |
| 782 | * be cleared when detached from parent. |
| 783 | */ |
| 784 | void setDrawnStateEvaluated(boolean evaluated) { |
| 785 | mDrawnStateEvaluated = evaluated; |
| 786 | } |
| 787 | |
| 788 | @Override |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 789 | void onParentChanged() { |
| 790 | super.onParentChanged(); |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 791 | setDrawnStateEvaluated(false /*evaluated*/); |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 792 | |
| 793 | getDisplayContent().reapplyMagnificationSpec(); |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 796 | @Override |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 797 | public int getOwningUid() { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 798 | return mOwnerUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | @Override |
| 802 | public String getOwningPackage() { |
| 803 | return mAttrs.packageName; |
| 804 | } |
| 805 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 806 | @Override |
| 807 | public boolean canAddInternalSystemWindow() { |
| 808 | return mOwnerCanAddInternalSystemWindow; |
| 809 | } |
| 810 | |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 811 | @Override |
| 812 | public boolean canAcquireSleepToken() { |
| 813 | return mSession.mCanAcquireSleepToken; |
| 814 | } |
| 815 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 816 | /** |
| 817 | * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame} |
| 818 | * from {@param frame}. In other words, it applies the insets that would result if |
| 819 | * {@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] | 820 | * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum |
| 821 | * width/height applied and insets should be overridden. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 822 | */ |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 823 | private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) { |
| 824 | final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left)); |
| 825 | final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top)); |
| 826 | final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right); |
| 827 | 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] | 828 | frame.inset(left, top, right, bottom); |
| 829 | } |
| 830 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 831 | @Override |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 832 | public Rect getDisplayedBounds() { |
| 833 | final Task task = getTask(); |
| 834 | if (task != null) { |
| 835 | Rect bounds = task.getOverrideDisplayedBounds(); |
| 836 | if (!bounds.isEmpty()) { |
| 837 | return bounds; |
| 838 | } |
| 839 | } |
| 840 | return super.getDisplayedBounds(); |
| 841 | } |
| 842 | |
| 843 | @Override |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 844 | public void computeFrameLw() { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 845 | if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 846 | // This window is being replaced and either already got information that it's being |
| 847 | // removed or we are still waiting for some information. Because of this we don't |
| 848 | // want to apply any more changes to it, so it remains in this state until new window |
| 849 | // appears. |
| 850 | return; |
| 851 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 852 | mHaveFrame = true; |
| 853 | |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 854 | final Task task = getTask(); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 855 | final boolean isFullscreenAndFillsDisplay = !inMultiWindowMode() && matchesDisplayBounds(); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 856 | final boolean windowsAreFloating = task != null && task.isFloating(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 857 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 858 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 859 | mInsetFrame.set(getBounds()); |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 860 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 861 | // Denotes the actual frame used to calculate the insets and to perform the layout. When |
| 862 | // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the |
| 863 | // insets temporarily. By the notion of a task having a different layout frame, we can |
| 864 | // achieve that while still moving the task around. |
| 865 | final Rect layoutContainingFrame; |
| 866 | final Rect layoutDisplayFrame; |
| 867 | |
| 868 | // The offset from the layout containing frame to the actual containing frame. |
| 869 | final int layoutXDiff; |
| 870 | final int layoutYDiff; |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 871 | final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow(); |
| 872 | final boolean isImeTarget = |
| 873 | imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget(); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 874 | if (isFullscreenAndFillsDisplay || layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 875 | // We use the parent frame as the containing frame for fullscreen and child windows |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 876 | mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame); |
| 877 | layoutDisplayFrame = mWindowFrames.mDisplayFrame; |
| 878 | layoutContainingFrame = mWindowFrames.mParentFrame; |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 879 | layoutXDiff = 0; |
| 880 | layoutYDiff = 0; |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 881 | } else { |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 882 | mWindowFrames.mContainingFrame.set(getDisplayedBounds()); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 883 | if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) { |
| 884 | |
| 885 | // If the bounds are frozen, we still want to translate the window freely and only |
| 886 | // freeze the size. |
| 887 | Rect frozen = mAppToken.mFrozenBounds.peek(); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 888 | mWindowFrames.mContainingFrame.right = |
| 889 | mWindowFrames.mContainingFrame.left + frozen.width(); |
| 890 | mWindowFrames.mContainingFrame.bottom = |
| 891 | mWindowFrames.mContainingFrame.top + frozen.height(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 892 | } |
Robert Carr | fc03b2b | 2016-03-31 15:22:02 -0700 | [diff] [blame] | 893 | // IME is up and obscuring this window. Adjust the window position so it is visible. |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 894 | if (isImeTarget) { |
| 895 | if (inFreeformWindowingMode()) { |
| 896 | // Push the freeform window up to make room for the IME. However, don't push |
| 897 | // it up past the top of the screen. |
| 898 | final int bottomOverlap = mWindowFrames.mContainingFrame.bottom |
| 899 | - mWindowFrames.mVisibleFrame.bottom; |
| 900 | if (bottomOverlap > 0) { |
| 901 | final int distanceToTop = Math.max(mWindowFrames.mContainingFrame.top |
| 902 | - mWindowFrames.mDisplayFrame.top, 0); |
| 903 | int offs = Math.min(bottomOverlap, distanceToTop); |
| 904 | mWindowFrames.mContainingFrame.top -= offs; |
| 905 | } |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 906 | } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 907 | > mWindowFrames.mParentFrame.bottom) { |
Winson Chung | d73e94b | 2017-05-31 16:25:30 -0700 | [diff] [blame] | 908 | // But in docked we want to behave like fullscreen and behave as if the task |
| 909 | // were given smaller bounds for the purposes of layout. Skip adjustments for |
| 910 | // the pinned stack, they are handled separately in the PinnedStackController. |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 911 | mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom; |
Winson Chung | d73e94b | 2017-05-31 16:25:30 -0700 | [diff] [blame] | 912 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 913 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 914 | |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 915 | if (windowsAreFloating) { |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 916 | // In floating modes (e.g. freeform, pinned) we have only to set the rectangle |
| 917 | // 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] | 918 | // "content frame" since it is allowed to be outside the visible desktop. |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 919 | if (mWindowFrames.mContainingFrame.isEmpty()) { |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 920 | mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 921 | } |
Doris Liu | 06d582d | 2015-06-01 13:18:43 -0700 | [diff] [blame] | 922 | } |
Adrian Roos | 604ef95 | 2018-05-15 20:13:13 +0200 | [diff] [blame] | 923 | |
| 924 | final TaskStack stack = getStack(); |
| 925 | if (inPinnedWindowingMode() && stack != null |
| 926 | && stack.lastAnimatingBoundsWasToFullscreen()) { |
| 927 | // PIP edge case: When going from pinned to fullscreen, we apply a |
| 928 | // tempInsetFrame for the full task - but we're still at the start of the animation. |
| 929 | // To prevent a jump if there's a letterbox, restrict to the parent frame. |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 930 | mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame); |
| 931 | mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame); |
Adrian Roos | 604ef95 | 2018-05-15 20:13:13 +0200 | [diff] [blame] | 932 | } |
| 933 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 934 | layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 935 | mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame); |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 936 | layoutXDiff = mInsetFrame.left - mWindowFrames.mContainingFrame.left; |
| 937 | layoutYDiff = mInsetFrame.top - mWindowFrames.mContainingFrame.top; |
| 938 | layoutContainingFrame = mInsetFrame; |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 939 | mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 940 | subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame, |
| 941 | mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 942 | if (!layoutInParentFrame()) { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 943 | subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame, |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 944 | mWindowFrames.mParentFrame, mTmpRect); |
| 945 | subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame, |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 946 | mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 947 | } |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 948 | layoutDisplayFrame.intersect(layoutContainingFrame); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 949 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 950 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 951 | final int pw = mWindowFrames.mContainingFrame.width(); |
| 952 | final int ph = mWindowFrames.mContainingFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 953 | |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 954 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 955 | mLastRequestedWidth = mRequestedWidth; |
| 956 | mLastRequestedHeight = mRequestedHeight; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 957 | mWindowFrames.setContentChanged(true); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 958 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 959 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 960 | final int fw = mWindowFrames.mFrame.width(); |
| 961 | final int fh = mWindowFrames.mFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 962 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 963 | applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame); |
| 964 | |
Filip Gruszczynski | aaf1811 | 2015-06-05 13:37:40 -0700 | [diff] [blame] | 965 | // Calculate the outsets before the content frame gets shrinked to the window frame. |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 966 | mWindowFrames.calculateOutsets(); |
Filip Gruszczynski | aaf1811 | 2015-06-05 13:37:40 -0700 | [diff] [blame] | 967 | |
Craig Mautner | a248eee | 2013-05-07 11:41:27 -0700 | [diff] [blame] | 968 | // Make sure the content and visible frames are inside of the |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 969 | // final window frame. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 970 | if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) { |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 971 | final int visBottom = mWindowFrames.mVisibleFrame.bottom; |
| 972 | final int contentBottom = mWindowFrames.mContentFrame.bottom; |
Evan Rosky | 60dba2f | 2019-02-01 10:58:38 -0800 | [diff] [blame] | 973 | mWindowFrames.mContentFrame.set(mWindowFrames.mFrame); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 974 | mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame); |
| 975 | mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame); |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 976 | if (isImeTarget && inFreeformWindowingMode()) { |
| 977 | // After displacing a freeform window to make room for the ime, any part of |
| 978 | // the window still covered by IME should be inset. |
| 979 | if (contentBottom + layoutYDiff < mWindowFrames.mContentFrame.bottom) { |
| 980 | mWindowFrames.mContentFrame.bottom = contentBottom + layoutYDiff; |
| 981 | } |
| 982 | if (visBottom + layoutYDiff < mWindowFrames.mVisibleFrame.bottom) { |
| 983 | mWindowFrames.mVisibleFrame.bottom = visBottom + layoutYDiff; |
| 984 | } |
| 985 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 986 | } else if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 987 | dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame); |
| 988 | mWindowFrames.mContentFrame.set(mWindowFrames.mFrame); |
| 989 | if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) { |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 990 | mMovedByResize = true; |
Filip Gruszczynski | ae10080 | 2015-11-11 15:58:03 -0800 | [diff] [blame] | 991 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 992 | } else { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 993 | mWindowFrames.mContentFrame.set( |
| 994 | Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left), |
| 995 | Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top), |
| 996 | Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right), |
| 997 | Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom)); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 998 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 999 | mWindowFrames.mVisibleFrame.set( |
| 1000 | Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left), |
| 1001 | Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top), |
| 1002 | Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right), |
| 1003 | Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1004 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1005 | mWindowFrames.mStableFrame.set( |
| 1006 | Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left), |
| 1007 | Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top), |
| 1008 | Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right), |
| 1009 | Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom)); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 1010 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1011 | |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1012 | if (isFullscreenAndFillsDisplay && !windowsAreFloating) { |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 1013 | // Windows that are not fullscreen can be positioned outside of the display frame, |
| 1014 | // but that is not a reason to provide them with overscan insets. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1015 | InsetUtils.insetsBetweenFrames(layoutContainingFrame, mWindowFrames.mOverscanFrame, |
| 1016 | mWindowFrames.mOverscanInsets); |
Filip Gruszczynski | 01ef404d5 | 2016-01-28 18:14:27 -0800 | [diff] [blame] | 1017 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1018 | |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 1019 | if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1020 | final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo( |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1021 | mWindowFrames.mDisplayFrame); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1022 | mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets()); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 1023 | } else { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1024 | getDisplayContent().getBounds(mTmpRect); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1025 | mWindowFrames.calculateInsets( |
| 1026 | windowsAreFloating, isFullscreenAndFillsDisplay, mTmpRect); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 1027 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1028 | |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 1029 | mWindowFrames.setDisplayCutout( |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1030 | mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame)); |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 1031 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 1032 | // Offset the actual frame by the amount layout frame is off. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1033 | mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 1034 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1035 | mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 1036 | if (inSizeCompatMode()) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1037 | // If there is a size compatibility scale being applied to the |
| 1038 | // window, we need to apply this to its insets so that they are |
| 1039 | // reported to the app in its coordinate space. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1040 | mWindowFrames.scaleInsets(mInvGlobalScale); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1041 | |
| 1042 | // Also the scaled frame that we report to the app needs to be |
| 1043 | // adjusted to be in its coordinate space. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1044 | mWindowFrames.mCompatFrame.scale(mInvGlobalScale); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1047 | if (mIsWallpaper && (fw != mWindowFrames.mFrame.width() |
| 1048 | || fh != mWindowFrames.mFrame.height())) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1049 | final DisplayContent displayContent = getDisplayContent(); |
| 1050 | if (displayContent != null) { |
| 1051 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1052 | getDisplayContent().mWallpaperController.updateWallpaperOffset(this, |
| 1053 | displayInfo.logicalWidth, displayInfo.logicalHeight, false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1054 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1055 | } |
| 1056 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1057 | if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG, |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 1058 | "Resolving (mRequestedWidth=" |
| 1059 | + mRequestedWidth + ", mRequestedheight=" |
| 1060 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1061 | + "): frame=" + mWindowFrames.mFrame.toShortString() |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1062 | + " " + mWindowFrames.getInsetsInfo()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1065 | // TODO: Look into whether this override is still necessary. |
| 1066 | @Override |
| 1067 | public Rect getBounds() { |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1068 | if (mAppToken != null) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1069 | return mAppToken.getBounds(); |
| 1070 | } else { |
| 1071 | return super.getBounds(); |
| 1072 | } |
| 1073 | } |
| 1074 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1075 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1076 | public Rect getFrameLw() { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1077 | return mWindowFrames.mFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1078 | } |
| 1079 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1080 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1081 | public Rect getDisplayFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1082 | return mWindowFrames.mDisplayFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1085 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1086 | public Rect getOverscanFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1087 | return mWindowFrames.mOverscanFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1091 | public Rect getContentFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1092 | return mWindowFrames.mContentFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1093 | } |
| 1094 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1095 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1096 | public Rect getVisibleFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1097 | return mWindowFrames.mVisibleFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 1100 | Rect getStableFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1101 | return mWindowFrames.mStableFrame; |
| 1102 | } |
| 1103 | |
| 1104 | Rect getDecorFrame() { |
| 1105 | return mWindowFrames.mDecorFrame; |
| 1106 | } |
| 1107 | |
| 1108 | Rect getParentFrame() { |
| 1109 | return mWindowFrames.mParentFrame; |
| 1110 | } |
| 1111 | |
| 1112 | Rect getContainingFrame() { |
| 1113 | return mWindowFrames.mContainingFrame; |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 1116 | WmDisplayCutout getWmDisplayCutout() { |
| 1117 | return mWindowFrames.mDisplayCutout; |
| 1118 | } |
| 1119 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1120 | void getCompatFrame(Rect outFrame) { |
| 1121 | outFrame.set(mWindowFrames.mCompatFrame); |
| 1122 | } |
| 1123 | |
| 1124 | void getCompatFrameSize(Rect outFrame) { |
| 1125 | outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height()); |
| 1126 | } |
| 1127 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1128 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1129 | public boolean getGivenInsetsPendingLw() { |
| 1130 | return mGivenInsetsPending; |
| 1131 | } |
| 1132 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1133 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1134 | public Rect getGivenContentInsetsLw() { |
| 1135 | return mGivenContentInsets; |
| 1136 | } |
| 1137 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1138 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1139 | public Rect getGivenVisibleInsetsLw() { |
| 1140 | return mGivenVisibleInsets; |
| 1141 | } |
| 1142 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1143 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1144 | public WindowManager.LayoutParams getAttrs() { |
| 1145 | return mAttrs; |
| 1146 | } |
| 1147 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1148 | @Override |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1149 | public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1150 | return getDisplayContent().getNeedsMenu(this, bottom); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1153 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1154 | public int getSystemUiVisibility() { |
| 1155 | return mSystemUiVisibility; |
| 1156 | } |
| 1157 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1158 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1159 | public int getSurfaceLayer() { |
| 1160 | return mLayer; |
| 1161 | } |
| 1162 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1163 | @Override |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1164 | public int getBaseType() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 1165 | return getTopParentWindow().mAttrs.type; |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1169 | public IApplicationToken getAppToken() { |
| 1170 | return mAppToken != null ? mAppToken.appToken : null; |
| 1171 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1172 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1173 | @Override |
| 1174 | public boolean isVoiceInteraction() { |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 1175 | return mAppToken != null && mAppToken.mVoiceInteraction; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1178 | boolean setReportResizeHints() { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1179 | return mWindowFrames.setReportResizeHints(); |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1180 | } |
| 1181 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1182 | /** |
| 1183 | * Adds the window to the resizing list if any of the parameters we use to track the window |
| 1184 | * dimensions or insets have changed. |
| 1185 | */ |
| 1186 | void updateResizingWindowIfNeeded() { |
| 1187 | final WindowStateAnimator winAnimator = mWinAnimator; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 1188 | if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1189 | return; |
| 1190 | } |
| 1191 | |
| 1192 | final Task task = getTask(); |
| 1193 | // In the case of stack bound animations, the window frames will update (unlike other |
| 1194 | // animations which just modify various transformation properties). We don't want to |
| 1195 | // notify the client of frame changes in this case. Not only is it a lot of churn, but |
| 1196 | // the frame may not correspond to the surface size or the onscreen area at various |
| 1197 | // phases in the animation, and the client will become sad and confused. |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 1198 | if (task != null && task.mStack.isAnimatingBounds()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1199 | return; |
| 1200 | } |
| 1201 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1202 | boolean didFrameInsetsChange = setReportResizeHints(); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1203 | boolean configChanged = isConfigChanged(); |
| 1204 | if (DEBUG_CONFIGURATION && configChanged) { |
| 1205 | Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration()); |
| 1206 | } |
| 1207 | |
| 1208 | final boolean dragResizingChanged = isDragResizeChanged() |
| 1209 | && !isDragResizingChangeReported(); |
| 1210 | |
| 1211 | if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1212 | + " dragResizingChanged=" + dragResizingChanged |
| 1213 | + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1214 | |
| 1215 | // We update mLastFrame always rather than in the conditional with the last inset |
| 1216 | // variables, because mFrameSizeChanged only tracks the width and height changing. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1217 | mWindowFrames.mLastFrame.set(mWindowFrames.mFrame); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1218 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1219 | if (didFrameInsetsChange |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1220 | || winAnimator.mSurfaceResized |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1221 | || configChanged |
| 1222 | || dragResizingChanged |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1223 | || mReportOrientationChanged) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1224 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 1225 | Slog.v(TAG_WM, "Resize reasons for w=" + this + ": " |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1226 | + " " + mWindowFrames.getInsetsChangedInfo() |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1227 | + " surfaceResized=" + winAnimator.mSurfaceResized |
| 1228 | + " configChanged=" + configChanged |
| 1229 | + " dragResizingChanged=" + dragResizingChanged |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1230 | + " reportOrientationChanged=" + mReportOrientationChanged); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | // If it's a dead window left on screen, and the configuration changed, there is nothing |
| 1234 | // we can do about it. Remove the window now. |
| 1235 | if (mAppToken != null && mAppDied) { |
| 1236 | mAppToken.removeDeadWindows(); |
| 1237 | return; |
| 1238 | } |
| 1239 | |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 1240 | updateLastInsetValues(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1241 | mWmService.makeWindowFreezingScreenIfNeededLocked(this); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1242 | |
| 1243 | // If the orientation is changing, or we're starting or ending a drag resizing action, |
| 1244 | // then we need to hold off on unfreezing the display until this window has been |
| 1245 | // redrawn; to do that, we need to go through the process of getting informed by the |
| 1246 | // application when it has finished drawing. |
Robert Carr | 09286c9 | 2018-02-15 13:52:31 -0800 | [diff] [blame] | 1247 | if (getOrientationChanging() || dragResizingChanged) { |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 1248 | if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1249 | Slog.v(TAG_WM, "Orientation or resize start waiting for draw" |
| 1250 | + ", mDrawState=DRAW_PENDING in " + this |
| 1251 | + ", surfaceController " + winAnimator.mSurfaceController); |
| 1252 | } |
| 1253 | winAnimator.mDrawState = DRAW_PENDING; |
| 1254 | if (mAppToken != null) { |
| 1255 | mAppToken.clearAllDrawn(); |
| 1256 | } |
| 1257 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1258 | if (!mWmService.mResizingWindows.contains(this)) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1259 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1260 | mWmService.mResizingWindows.add(this); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1261 | } |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1262 | } else if (getOrientationChanging()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1263 | if (isDrawnLw()) { |
| 1264 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in " |
| 1265 | + this + ", surfaceController " + winAnimator.mSurfaceController); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1266 | setOrientationChanging(false); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1267 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1268 | - mWmService.mDisplayFreezeTime); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1273 | boolean getOrientationChanging() { |
| 1274 | // In addition to the local state flag, we must also consider the difference in the last |
| 1275 | // reported configuration vs. the current state. If the client code has not been informed of |
| 1276 | // the change, logic dependent on having finished processing the orientation, such as |
| 1277 | // unfreezing, could be improperly triggered. |
| 1278 | // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as |
| 1279 | // this is not necessarily what the client has processed yet. Find a |
| 1280 | // better indicator consistent with the client. |
Robert Carr | 926643f | 2017-08-02 12:01:12 -0700 | [diff] [blame] | 1281 | return (mOrientationChanging || (isVisible() |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 1282 | && getConfiguration().orientation != getLastReportedConfiguration().orientation)) |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 1283 | && !mSeamlesslyRotated |
| 1284 | && !mOrientationChangeTimedOut; |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | void setOrientationChanging(boolean changing) { |
| 1288 | mOrientationChanging = changing; |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 1289 | mOrientationChangeTimedOut = false; |
| 1290 | } |
| 1291 | |
| 1292 | void orientationChangeTimedOut() { |
| 1293 | mOrientationChangeTimedOut = true; |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1296 | DisplayContent getDisplayContent() { |
| 1297 | return mToken.getDisplayContent(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 1300 | @Override |
| 1301 | void onDisplayChanged(DisplayContent dc) { |
| 1302 | super.onDisplayChanged(dc); |
| 1303 | // Window was not laid out for this display yet, so make sure mLayoutSeq does not match. |
| 1304 | if (dc != null) { |
| 1305 | mLayoutSeq = dc.mLayoutSeq - 1; |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 1306 | mInputWindowHandle.displayId = dc.getDisplayId(); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1310 | DisplayInfo getDisplayInfo() { |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 1311 | final DisplayContent displayContent = getDisplayContent(); |
| 1312 | return displayContent != null ? displayContent.getDisplayInfo() : null; |
| 1313 | } |
| 1314 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1315 | @Override |
| 1316 | public int getDisplayId() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1317 | final DisplayContent displayContent = getDisplayContent(); |
| 1318 | if (displayContent == null) { |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 1319 | return Display.INVALID_DISPLAY; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1320 | } |
| 1321 | return displayContent.getDisplayId(); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1324 | Task getTask() { |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 1325 | return mAppToken != null ? mAppToken.getTask() : null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | TaskStack getStack() { |
| 1329 | Task task = getTask(); |
| 1330 | if (task != null) { |
| 1331 | if (task.mStack != null) { |
| 1332 | return task.mStack; |
Craig Mautner | f06b8c1 | 2013-04-18 14:27:28 -0700 | [diff] [blame] | 1333 | } |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1334 | } |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1335 | // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still |
| 1336 | // associate them with some stack to enable dimming. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1337 | final DisplayContent dc = getDisplayContent(); |
| 1338 | return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1341 | /** |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1342 | * Retrieves the visible bounds of the window. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1343 | * @param bounds The rect which gets the bounds. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1344 | */ |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1345 | void getVisibleBounds(Rect bounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1346 | final Task task = getTask(); |
| 1347 | boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds(); |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1348 | bounds.setEmpty(); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1349 | mTmpRect.setEmpty(); |
| 1350 | if (intersectWithStackBounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1351 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1352 | if (stack != null) { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1353 | stack.getDimBounds(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1354 | } else { |
| 1355 | intersectWithStackBounds = false; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1356 | } |
| 1357 | } |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1358 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1359 | bounds.set(mWindowFrames.mVisibleFrame); |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1360 | if (intersectWithStackBounds) { |
| 1361 | bounds.intersect(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1364 | if (bounds.isEmpty()) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1365 | bounds.set(mWindowFrames.mFrame); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1366 | if (intersectWithStackBounds) { |
| 1367 | bounds.intersect(mTmpRect); |
| 1368 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1369 | return; |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1370 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1373 | public long getInputDispatchingTimeoutNanos() { |
| 1374 | return mAppToken != null |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 1375 | ? mAppToken.mInputDispatchingTimeoutNanos |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1376 | : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 1377 | } |
| 1378 | |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1379 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1380 | public boolean hasAppShownWindows() { |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 1381 | return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1384 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 1385 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 1386 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 1387 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 1388 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 1389 | return true; |
| 1390 | } |
| 1391 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1392 | void prelayout() { |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 1393 | if (inSizeCompatMode()) { |
| 1394 | mGlobalScale = mToken.getSizeCompatScale(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1395 | mInvGlobalScale = 1 / mGlobalScale; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1396 | } else { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1397 | mGlobalScale = mInvGlobalScale = 1; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1398 | } |
| 1399 | } |
| 1400 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1401 | @Override |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1402 | boolean hasContentToDisplay() { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1403 | if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1404 | || (isAnimating() && !getDisplayContent().mAppTransition.isTransitionSet()))) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1405 | return true; |
| 1406 | } |
| 1407 | |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1408 | return super.hasContentToDisplay(); |
| 1409 | } |
| 1410 | |
| 1411 | @Override |
| 1412 | boolean isVisible() { |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 1413 | return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility |
| 1414 | // If we don't have a provider, this window isn't used as a window generating |
| 1415 | // insets, so nobody can hide it over the inset APIs. |
| 1416 | && (mInsetProvider == null || mInsetProvider.isClientVisible()); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1419 | /** |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 1420 | * @return {@code true} if the window would be visible if we'd ignore policy visibility, |
| 1421 | * {@code false} otherwise. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1422 | */ |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1423 | boolean wouldBeVisibleIfPolicyIgnored() { |
Jorim Jaggi | 43530c9 | 2017-05-18 01:53:56 +0200 | [diff] [blame] | 1424 | return mHasSurface && !isParentWindowHidden() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1425 | && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1426 | } |
| 1427 | |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1428 | @Override |
| 1429 | public boolean isVisibleLw() { |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1430 | return isVisible(); |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1434 | * Is this window visible, ignoring its app token? It is not visible if there is no surface, |
| 1435 | * 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] | 1436 | */ |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1437 | // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this? |
| 1438 | boolean isWinVisibleLw() { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1439 | return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating()) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1440 | && isVisible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1444 | * The same as isVisible(), but follows the current hidden state of the associated app token, |
| 1445 | * not the pending requested hidden state. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1446 | */ |
| 1447 | boolean isVisibleNow() { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1448 | return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1449 | && isVisible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * Can this window possibly be a drag/drop target? The test here is |
| 1454 | * a combination of the above "visible now" with the check that the |
| 1455 | * Input Manager uses when discarding windows from input consideration. |
| 1456 | */ |
| 1457 | boolean isPotentialDragTarget() { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1458 | return isVisibleNow() && !mRemoved |
| 1459 | && mInputChannel != null && mInputWindowHandle != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /** |
| 1463 | * Same as isVisible(), but we also count it as visible between the |
| 1464 | * call to IWindowSession.add() and the first relayout(). |
| 1465 | */ |
| 1466 | boolean isVisibleOrAdding() { |
| 1467 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 1468 | return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1469 | && mPolicyVisibility && !isParentWindowHidden() |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1470 | && (atoken == null || !atoken.hiddenRequested) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1471 | && !mAnimatingExit && !mDestroying; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | /** |
| 1475 | * Is this window currently on-screen? It is on-screen either if it |
| 1476 | * is visible or it is currently running an animation before no longer |
| 1477 | * being visible. |
| 1478 | */ |
| 1479 | boolean isOnScreen() { |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 1480 | if (!mHasSurface || mDestroying || !mPolicyVisibility) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1481 | return false; |
| 1482 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1483 | final AppWindowToken atoken = mAppToken; |
| 1484 | if (atoken != null) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1485 | return ((!isParentWindowHidden() && !atoken.hiddenRequested) |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1486 | || isAnimating()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1487 | } |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1488 | return !isParentWindowHidden() || isAnimating(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | /** |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1492 | * Whether this window's drawn state might affect the drawn states of the app token. |
| 1493 | * |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1494 | * @return true if the window should be considered while evaluating allDrawn flags. |
| 1495 | */ |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1496 | boolean mightAffectAllDrawn() { |
| 1497 | final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION |
| 1498 | || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION; |
| 1499 | return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /** |
| 1503 | * Whether this window is "interesting" when evaluating allDrawn. If it's interesting, |
| 1504 | * it must be drawn before allDrawn can become true. |
| 1505 | */ |
| 1506 | boolean isInteresting() { |
| 1507 | return mAppToken != null && !mAppDied |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 1508 | && (!mAppToken.isFreezingScreen() || !mAppFreezing); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1512 | * Like isOnScreen(), but we don't return true if the window is part |
| 1513 | * of a transition that has not yet been started. |
| 1514 | */ |
| 1515 | boolean isReadyForDisplay() { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1516 | if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1517 | return false; |
| 1518 | } |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1519 | final boolean parentAndClientVisible = !isParentWindowHidden() |
| 1520 | && mViewVisibility == View.VISIBLE && !mToken.isHidden(); |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1521 | return mHasSurface && mPolicyVisibility && !mDestroying |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1522 | && (parentAndClientVisible || isAnimating()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1525 | // TODO: Another visibility method that was added late in the release to minimize risk. |
| 1526 | @Override |
| 1527 | public boolean canAffectSystemUiFlags() { |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1528 | final boolean translucent = mAttrs.alpha == 0.0f; |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 1529 | if (translucent) { |
| 1530 | return false; |
| 1531 | } |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1532 | if (mAppToken == null) { |
| 1533 | final boolean shown = mWinAnimator.getShown(); |
| 1534 | final boolean exiting = mAnimatingExit || mDestroying; |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 1535 | return shown && !exiting; |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1536 | } else { |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 1537 | final Task task = getTask(); |
| 1538 | final boolean canFromTask = task != null && task.canAffectSystemUiFlags(); |
| 1539 | return canFromTask && !mAppToken.isHidden(); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1540 | } |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1541 | } |
| 1542 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1543 | /** |
| 1544 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 1545 | * been drawn. |
| 1546 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1547 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1548 | public boolean isDisplayedLw() { |
| 1549 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 1550 | return isDrawnLw() && mPolicyVisibility |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1551 | && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested)) |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1552 | || isAnimating()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1553 | } |
| 1554 | |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1555 | /** |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1556 | * Return true if this window or its app token is currently animating. |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1557 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1558 | @Override |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1559 | public boolean isAnimatingLw() { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1560 | return isAnimating(); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1563 | @Override |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1564 | public boolean isGoneForLayoutLw() { |
| 1565 | final AppWindowToken atoken = mAppToken; |
| 1566 | return mViewVisibility == View.GONE |
| 1567 | || !mRelayoutCalled |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1568 | || (atoken == null && mToken.isHidden()) |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 1569 | || (atoken != null && atoken.hiddenRequested) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1570 | || isParentWindowHidden() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1571 | || (mAnimatingExit && !isAnimatingLw()) |
Craig Mautner | 0e415c6 | 2013-04-29 16:10:58 -0700 | [diff] [blame] | 1572 | || mDestroying; |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1573 | } |
| 1574 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1575 | /** |
| 1576 | * Returns true if the window has a surface that it has drawn a |
| 1577 | * complete UI in to. |
| 1578 | */ |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1579 | public boolean isDrawFinishedLw() { |
| 1580 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1581 | (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING |
| 1582 | || mWinAnimator.mDrawState == READY_TO_SHOW |
| 1583 | || mWinAnimator.mDrawState == HAS_DRAWN); |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * Returns true if the window has a surface that it has drawn a |
| 1588 | * complete UI in to. |
| 1589 | */ |
Adrian Roos | 76d2fe4 | 2015-07-09 14:54:08 -0700 | [diff] [blame] | 1590 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1591 | public boolean isDrawnLw() { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1592 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1593 | (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | /** |
| 1597 | * Return true if the window is opaque and fully drawn. This indicates |
| 1598 | * it may obscure windows behind it. |
| 1599 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1600 | private boolean isOpaqueDrawn() { |
Chong Zhang | 66bf071d | 2016-02-05 14:42:36 -0800 | [diff] [blame] | 1601 | // When there is keyguard, wallpaper could be placed over the secure app |
| 1602 | // window but invisible. We need to check wallpaper visibility explicitly |
| 1603 | // to determine if it's occluding apps. |
| 1604 | return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE) |
| 1605 | || (mIsWallpaper && mWallpaperVisible)) |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1606 | && isDrawnLw() && !isAnimating(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1607 | } |
| 1608 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1609 | @Override |
| 1610 | void onMovedByResize() { |
| 1611 | if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1612 | mMovedByResize = true; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1613 | super.onMovedByResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) { |
| 1617 | boolean changed = false; |
| 1618 | |
| 1619 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1620 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1621 | changed |= c.onAppVisibilityChanged(visible, runningAppAnimation); |
| 1622 | } |
| 1623 | |
| 1624 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 1625 | // Starting window that's exiting will be removed when the animation finishes. |
| 1626 | // Mark all relevant flags for that onExitAnimationDone will proceed all the way |
| 1627 | // to actually remove it. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1628 | if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1629 | mAnimatingExit = true; |
| 1630 | mRemoveOnExit = true; |
| 1631 | mWindowRemovalAllowed = true; |
| 1632 | } |
| 1633 | return changed; |
| 1634 | } |
| 1635 | |
chaviw | e390cbd | 2018-04-16 15:29:38 -0700 | [diff] [blame] | 1636 | final boolean isVisibleNow = isVisibleNow(); |
| 1637 | if (visible != isVisibleNow) { |
| 1638 | // Run exit animation if: |
| 1639 | // 1. App visibility and WS visibility are different |
| 1640 | // 2. App is not running an animation |
| 1641 | // 3. WS is currently visible |
| 1642 | if (!runningAppAnimation && isVisibleNow) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1643 | final AccessibilityController accessibilityController = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1644 | mWmService.mAccessibilityController; |
chaviw | e390cbd | 2018-04-16 15:29:38 -0700 | [diff] [blame] | 1645 | final int winTransit = TRANSIT_EXIT; |
| 1646 | mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */); |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1647 | if (accessibilityController != null) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1648 | accessibilityController.onWindowTransitionLocked(this, winTransit); |
| 1649 | } |
| 1650 | } |
| 1651 | changed = true; |
| 1652 | setDisplayLayoutNeeded(); |
| 1653 | } |
| 1654 | |
| 1655 | return changed; |
| 1656 | } |
| 1657 | |
| 1658 | boolean onSetAppExiting() { |
| 1659 | final DisplayContent displayContent = getDisplayContent(); |
| 1660 | boolean changed = false; |
| 1661 | |
| 1662 | if (isVisibleNow()) { |
| 1663 | mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false); |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1664 | if (mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1665 | mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1666 | } |
| 1667 | changed = true; |
| 1668 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1669 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1674 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1675 | changed |= c.onSetAppExiting(); |
| 1676 | } |
| 1677 | |
| 1678 | return changed; |
| 1679 | } |
| 1680 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1681 | @Override |
| 1682 | void onResize() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1683 | final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows; |
Andrii Kulian | 3dcdf64 | 2018-05-23 17:14:00 -0700 | [diff] [blame] | 1684 | if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1685 | if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1686 | resizingWindows.add(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1687 | } |
| 1688 | if (isGoneForLayoutLw()) { |
| 1689 | mResizedWhileGone = true; |
| 1690 | } |
| 1691 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1692 | super.onResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | void onUnfreezeBounds() { |
| 1696 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1697 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1698 | c.onUnfreezeBounds(); |
| 1699 | } |
| 1700 | |
| 1701 | if (!mHasSurface) { |
| 1702 | return; |
| 1703 | } |
| 1704 | |
| 1705 | mLayoutNeeded = true; |
| 1706 | setDisplayLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1707 | if (!mWmService.mResizingWindows.contains(this)) { |
| 1708 | mWmService.mResizingWindows.add(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1712 | /** |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1713 | * If the window has moved due to its containing content frame changing, then notify the |
| 1714 | * listeners and optionally animate it. Simply checking a change of position is not enough, |
| 1715 | * because being move due to dock divider is not a trigger for animation. |
| 1716 | */ |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 1717 | void handleWindowMovedIfNeeded() { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1718 | if (!hasMoved()) { |
| 1719 | return; |
| 1720 | } |
| 1721 | |
| 1722 | // Frame has moved, containing content frame has also moved, and we're not currently |
| 1723 | // animating... let's do something. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1724 | final int left = mWindowFrames.mFrame.left; |
| 1725 | final int top = mWindowFrames.mFrame.top; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1726 | final Task task = getTask(); |
| 1727 | final boolean adjustedForMinimizedDockOrIme = task != null |
| 1728 | && (task.mStack.isAdjustedForMinimizedDockedStack() |
| 1729 | || task.mStack.isAdjustedForIme()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1730 | if (mToken.okToAnimate() |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1731 | && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0 |
| 1732 | && !isDragResizing() && !adjustedForMinimizedDockOrIme |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1733 | && getWindowConfiguration().hasMovementAnimations() |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 1734 | && !mWinAnimator.mLastHidden |
| 1735 | && !mSeamlesslyRotated) { |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 1736 | startMoveAnimation(left, top); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | //TODO (multidisplay): Accessibility supported only for the default display. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1740 | if (mWmService.mAccessibilityController != null |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1741 | && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1742 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | try { |
| 1746 | mClient.moved(left, top); |
| 1747 | } catch (RemoteException e) { |
| 1748 | } |
| 1749 | mMovedByResize = false; |
| 1750 | } |
| 1751 | |
| 1752 | /** |
Craig Mautner | 4557c08 | 2015-04-27 13:07:40 -0700 | [diff] [blame] | 1753 | * Return whether this window has moved. (Only makes |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1754 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 1755 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1756 | private boolean hasMoved() { |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1757 | return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize) |
Robert Carr | c67c2a9 | 2016-09-22 13:25:45 -0700 | [diff] [blame] | 1758 | && !mAnimatingExit |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1759 | && (mWindowFrames.mFrame.top != mWindowFrames.mLastFrame.top |
| 1760 | || mWindowFrames.mFrame.left != mWindowFrames.mLastFrame.left) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1761 | && (!mIsChildWindow || !getParentWindow().hasMoved()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1762 | } |
| 1763 | |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1764 | boolean isObscuringDisplay() { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1765 | Task task = getTask(); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1766 | if (task != null && task.mStack != null && !task.mStack.fillsParent()) { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1767 | return false; |
| 1768 | } |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1769 | return isOpaqueDrawn() && fillsDisplay(); |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1770 | } |
| 1771 | |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1772 | boolean fillsDisplay() { |
| 1773 | final DisplayInfo displayInfo = getDisplayInfo(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1774 | return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0 |
| 1775 | && mWindowFrames.mFrame.right >= displayInfo.appWidth |
| 1776 | && mWindowFrames.mFrame.bottom >= displayInfo.appHeight; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1777 | } |
| 1778 | |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1779 | private boolean matchesDisplayBounds() { |
| 1780 | return getDisplayContent().getBounds().equals(getBounds()); |
| 1781 | } |
| 1782 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 1783 | /** Returns true if last applied config was not yet requested by client. */ |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1784 | boolean isConfigChanged() { |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 1785 | return !getLastReportedConfiguration().equals(getConfiguration()); |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1788 | void onWindowReplacementTimeout() { |
| 1789 | if (mWillReplaceWindow) { |
| 1790 | // Since the window already timed out, remove it immediately now. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1791 | // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1792 | // delays removal on certain conditions, which will leave the stale window in the |
| 1793 | // stack and marked mWillReplaceWindow=false, so the window will never be removed. |
| 1794 | // |
| 1795 | // Also removes child windows. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1796 | removeImmediately(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1797 | } else { |
| 1798 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1799 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1800 | c.onWindowReplacementTimeout(); |
| 1801 | } |
| 1802 | } |
| 1803 | } |
| 1804 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1805 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1806 | void forceWindowsScaleableInTransaction(boolean force) { |
| 1807 | if (mWinAnimator != null && mWinAnimator.hasSurface()) { |
| 1808 | mWinAnimator.mSurfaceController.forceScaleableInTransaction(force); |
| 1809 | } |
| 1810 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1811 | super.forceWindowsScaleableInTransaction(force); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1814 | @Override |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1815 | void removeImmediately() { |
| 1816 | super.removeImmediately(); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1817 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1818 | if (mRemoved) { |
| 1819 | // Nothing to do. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1820 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1821 | "WS.removeImmediately: " + this + " Already removed..."); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1822 | return; |
| 1823 | } |
| 1824 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1825 | mRemoved = true; |
| 1826 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1827 | mWillReplaceWindow = false; |
| 1828 | if (mReplacementWindow != null) { |
| 1829 | mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false; |
| 1830 | } |
| 1831 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1832 | final DisplayContent dc = getDisplayContent(); |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 1833 | if (isInputMethodTarget()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1834 | dc.computeImeTarget(true /* updateImeTarget */); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | final int type = mAttrs.type; |
| 1838 | if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1839 | dc.mTapExcludedWindows.remove(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1840 | } |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 1841 | if (mTapExcludeRegionHolder != null) { |
| 1842 | // If a tap exclude region container was initialized for this window, then it should've |
| 1843 | // also been registered in display. |
| 1844 | dc.mTapExcludeProvidingWindows.remove(this); |
| 1845 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1846 | dc.getDisplayPolicy().removeWindowLw(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1847 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1848 | disposeInputChannel(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1849 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1850 | mWinAnimator.destroyDeferredSurfaceLocked(); |
| 1851 | mWinAnimator.destroySurfaceLocked(); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 1852 | mSession.windowRemovedLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1853 | try { |
| 1854 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 1855 | } catch (RuntimeException e) { |
| 1856 | // Ignore if it has already been removed (usually because |
| 1857 | // we are doing this as part of processing a death note.) |
| 1858 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1859 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1860 | mWmService.postWindowRemoveCleanupLocked(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1861 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1862 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1863 | @Override |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1864 | void removeIfPossible() { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1865 | super.removeIfPossible(); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1866 | removeIfPossible(false /*keepVisibleDeadWindow*/); |
| 1867 | } |
| 1868 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1869 | private void removeIfPossible(boolean keepVisibleDeadWindow) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1870 | mWindowRemovalAllowed = true; |
| 1871 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, |
| 1872 | "removeIfPossible: " + this + " callers=" + Debug.getCallers(5)); |
| 1873 | |
| 1874 | final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 1875 | if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM, |
| 1876 | "Starting window removed " + this); |
| 1877 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 1878 | if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && isFocused()) |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1879 | Slog.v(TAG_WM, "Remove " + this + " client=" |
| 1880 | + Integer.toHexString(System.identityHashCode(mClient.asBinder())) |
| 1881 | + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers=" |
| 1882 | + Debug.getCallers(5)); |
| 1883 | |
| 1884 | final long origId = Binder.clearCallingIdentity(); |
| 1885 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1886 | try { |
| 1887 | disposeInputChannel(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1888 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1889 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this |
| 1890 | + ": mSurfaceController=" + mWinAnimator.mSurfaceController |
| 1891 | + " mAnimatingExit=" + mAnimatingExit |
| 1892 | + " mRemoveOnExit=" + mRemoveOnExit |
| 1893 | + " mHasSurface=" + mHasSurface |
| 1894 | + " surfaceShowing=" + mWinAnimator.getShown() |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1895 | + " animating=" + isAnimating() |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1896 | + " app-animation=" |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1897 | + (mAppToken != null ? mAppToken.isSelfAnimating() : "false") |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1898 | + " mWillReplaceWindow=" + mWillReplaceWindow |
| 1899 | + " inPendingTransaction=" |
| 1900 | + (mAppToken != null ? mAppToken.inPendingTransaction : false) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1901 | + " mDisplayFrozen=" + mWmService.mDisplayFrozen |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1902 | + " callers=" + Debug.getCallers(6)); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1903 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1904 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1905 | boolean wasVisible = false; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1906 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1907 | final int displayId = getDisplayId(); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1908 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1909 | // First, see if we need to run an animation. If we do, we have to hold off on removing the |
| 1910 | // window until the animation is done. If the display is frozen, just remove immediately, |
| 1911 | // since the animation wouldn't be seen. |
| 1912 | if (mHasSurface && mToken.okToAnimate()) { |
| 1913 | if (mWillReplaceWindow) { |
| 1914 | // This window is going to be replaced. We need to keep it around until the new one |
| 1915 | // gets added, then we will get rid of this one. |
| 1916 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1917 | "Preserving " + this + " until the new one is " + "added"); |
| 1918 | // TODO: We are overloading mAnimatingExit flag to prevent the window state from |
| 1919 | // been removed. We probably need another flag to indicate that window removal |
| 1920 | // should be deffered vs. overloading the flag that says we are playing an exit |
| 1921 | // animation. |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1922 | mAnimatingExit = true; |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1923 | mReplacingRemoveRequested = true; |
| 1924 | return; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1925 | } |
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 | // If we are not currently running the exit animation, we need to see about starting one |
| 1928 | wasVisible = isWinVisibleLw(); |
| 1929 | |
| 1930 | if (keepVisibleDeadWindow) { |
| 1931 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1932 | "Not removing " + this + " because app died while it's visible"); |
| 1933 | |
| 1934 | mAppDied = true; |
| 1935 | setDisplayLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1936 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1937 | |
| 1938 | // Set up a replacement input channel since the app is now dead. |
| 1939 | // We need to catch tapping on the dead window to restart the app. |
| 1940 | openInputChannel(null); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 1941 | getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1942 | return; |
| 1943 | } |
| 1944 | |
| 1945 | if (wasVisible) { |
| 1946 | final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE; |
| 1947 | |
| 1948 | // Try starting an animation. |
| 1949 | if (mWinAnimator.applyAnimationLocked(transit, false)) { |
| 1950 | mAnimatingExit = true; |
Jorim Jaggi | f41e882 | 2018-04-06 17:22:03 +0200 | [diff] [blame] | 1951 | |
| 1952 | // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that |
| 1953 | // any change from that is performed immediately. |
| 1954 | setDisplayLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1955 | mWmService.requestTraversal(); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1956 | } |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1957 | if (mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1958 | mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1959 | } |
| 1960 | } |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1961 | final boolean isAnimating = isAnimating() |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1962 | && (mAppToken == null || !mAppToken.isWaitingForTransitionStart()); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1963 | final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null |
| 1964 | && mAppToken.isLastWindow(this); |
| 1965 | // We delay the removal of a window if it has a showing surface that can be used to run |
| 1966 | // exit animation and it is marked as exiting. |
| 1967 | // Also, If isn't the an animating starting window that is the last window in the app. |
| 1968 | // We allow the removal of the non-animating starting window now as there is no |
| 1969 | // additional window or animation that will trigger its removal. |
| 1970 | if (mWinAnimator.getShown() && mAnimatingExit |
| 1971 | && (!lastWindowIsStartingWindow || isAnimating)) { |
| 1972 | // The exit animation is running or should run... wait for it! |
| 1973 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1974 | "Not removing " + this + " due to exit animation "); |
| 1975 | setupWindowForRemoveOnExit(); |
| 1976 | if (mAppToken != null) { |
| 1977 | mAppToken.updateReportedVisibilityLocked(); |
| 1978 | } |
| 1979 | return; |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | removeImmediately(); |
| 1984 | // Removing a visible window will effect the computed orientation |
| 1985 | // So just update orientation if needed. |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 1986 | if (wasVisible) { |
| 1987 | final DisplayContent displayContent = getDisplayContent(); |
| 1988 | if (displayContent.updateOrientationFromAppTokens()) { |
| 1989 | displayContent.sendNewConfiguration(); |
| 1990 | } |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1991 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1992 | mWmService.updateFocusedWindowLocked(isFocused() |
Tiger Huang | 8af6ba4 | 2018-06-07 19:24:09 +0800 | [diff] [blame] | 1993 | ? UPDATE_FOCUS_REMOVING_FOCUS |
| 1994 | : UPDATE_FOCUS_NORMAL, |
| 1995 | true /*updateInputWindows*/); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 1996 | } finally { |
| 1997 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1998 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | private void setupWindowForRemoveOnExit() { |
| 2002 | mRemoveOnExit = true; |
| 2003 | setDisplayLayoutNeeded(); |
| 2004 | // Request a focus update as this window's input channel is already gone. Otherwise |
| 2005 | // we could have no focused window in input manager. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2006 | final boolean focusChanged = mWmService.updateFocusedWindowLocked( |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2007 | UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2008 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2009 | if (focusChanged) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2010 | getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 2014 | void setHasSurface(boolean hasSurface) { |
| 2015 | mHasSurface = hasSurface; |
| 2016 | } |
| 2017 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2018 | boolean canBeImeTarget() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 2019 | if (mIsImWindow) { |
| 2020 | // IME windows can't be IME targets. IME targets are required to be below the IME |
| 2021 | // windows and that wouldn't be possible if the IME window is its own target...silly. |
| 2022 | return false; |
| 2023 | } |
| 2024 | |
Winson Chung | 3d0a74a | 2017-07-12 12:37:19 -0700 | [diff] [blame] | 2025 | final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable(); |
Winson Chung | b154934 | 2017-07-11 09:59:56 -0700 | [diff] [blame] | 2026 | if (!windowsAreFocusable) { |
| 2027 | // This window can't be an IME target if the app's windows should not be focusable. |
| 2028 | return false; |
| 2029 | } |
| 2030 | |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 2031 | final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2032 | final int type = mAttrs.type; |
| 2033 | |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 2034 | // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or |
| 2035 | // both are cleared...and not a starting window. |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2036 | if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM) |
| 2037 | && type != TYPE_APPLICATION_STARTING) { |
| 2038 | return false; |
| 2039 | } |
| 2040 | |
| 2041 | if (DEBUG_INPUT_METHOD) { |
| 2042 | Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding()); |
| 2043 | if (!isVisibleOrAdding()) { |
| 2044 | Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController |
| 2045 | + " relayoutCalled=" + mRelayoutCalled |
| 2046 | + " viewVis=" + mViewVisibility |
| 2047 | + " policyVis=" + mPolicyVisibility |
| 2048 | + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim |
| 2049 | + " parentHidden=" + isParentWindowHidden() |
| 2050 | + " exiting=" + mAnimatingExit + " destroying=" + mDestroying); |
| 2051 | if (mAppToken != null) { |
| 2052 | Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested); |
| 2053 | } |
| 2054 | } |
| 2055 | } |
| 2056 | return isVisibleOrAdding(); |
| 2057 | } |
| 2058 | |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2059 | private final class DeadWindowEventReceiver extends InputEventReceiver { |
| 2060 | DeadWindowEventReceiver(InputChannel inputChannel) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2061 | super(inputChannel, mWmService.mH.getLooper()); |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2062 | } |
| 2063 | @Override |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 2064 | public void onInputEvent(InputEvent event) { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2065 | finishInputEvent(event, true); |
| 2066 | } |
| 2067 | } |
| 2068 | /** |
| 2069 | * Dummy event receiver for windows that died visible. |
| 2070 | */ |
| 2071 | private DeadWindowEventReceiver mDeadWindowEventReceiver; |
| 2072 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2073 | void openInputChannel(InputChannel outInputChannel) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2074 | if (mInputChannel != null) { |
| 2075 | throw new IllegalStateException("Window already has an input channel."); |
| 2076 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2077 | String name = getName(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2078 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2079 | mInputChannel = inputChannels[0]; |
| 2080 | mClientChannel = inputChannels[1]; |
Robert Carr | eadae82 | 2018-10-11 19:07:03 -0700 | [diff] [blame] | 2081 | mInputWindowHandle.token = mClient.asBinder(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2082 | if (outInputChannel != null) { |
| 2083 | mClientChannel.transferTo(outInputChannel); |
| 2084 | mClientChannel.dispose(); |
| 2085 | mClientChannel = null; |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2086 | } else { |
| 2087 | // If the window died visible, we setup a dummy input channel, so that taps |
| 2088 | // can still detected by input monitor channel, and we can relaunch the app. |
| 2089 | // Create dummy event receiver that simply reports all events as handled. |
| 2090 | mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2091 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2092 | mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder()); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2095 | void disposeInputChannel() { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2096 | if (mDeadWindowEventReceiver != null) { |
| 2097 | mDeadWindowEventReceiver.dispose(); |
| 2098 | mDeadWindowEventReceiver = null; |
| 2099 | } |
| 2100 | |
| 2101 | // unregister server channel first otherwise it complains about broken channel |
| 2102 | if (mInputChannel != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2103 | mWmService.mInputManager.unregisterInputChannel(mInputChannel); |
Robert Carr | e0a353c | 2018-08-02 16:38:04 -0700 | [diff] [blame] | 2104 | |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2105 | mInputChannel.dispose(); |
| 2106 | mInputChannel = null; |
| 2107 | } |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2108 | if (mClientChannel != null) { |
| 2109 | mClientChannel.dispose(); |
| 2110 | mClientChannel = null; |
| 2111 | } |
Robert Carr | eadae82 | 2018-10-11 19:07:03 -0700 | [diff] [blame] | 2112 | mInputWindowHandle.token = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2115 | /** Returns true if the replacement window was removed. */ |
| 2116 | boolean removeReplacedWindowIfNeeded(WindowState replacement) { |
| 2117 | if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) { |
| 2118 | replacement.mSkipEnterAnimationForSeamlessReplacement = false; |
| 2119 | removeReplacedWindow(); |
| 2120 | return true; |
| 2121 | } |
| 2122 | |
| 2123 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2124 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2125 | if (c.removeReplacedWindowIfNeeded(replacement)) { |
| 2126 | return true; |
| 2127 | } |
| 2128 | } |
| 2129 | return false; |
| 2130 | } |
| 2131 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2132 | private void removeReplacedWindow() { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2133 | if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2134 | mWillReplaceWindow = false; |
| 2135 | mAnimateReplacingWindow = false; |
| 2136 | mReplacingRemoveRequested = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2137 | mReplacementWindow = null; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2138 | if (mAnimatingExit || !mAnimateReplacingWindow) { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 2139 | removeImmediately(); |
Filip Gruszczynski | 76cc44f | 2015-09-03 16:03:10 -0700 | [diff] [blame] | 2140 | } |
| 2141 | } |
| 2142 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2143 | boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) { |
| 2144 | boolean replacementSet = false; |
| 2145 | |
| 2146 | if (mWillReplaceWindow && mReplacementWindow == null |
| 2147 | && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) { |
| 2148 | |
| 2149 | mReplacementWindow = replacementCandidate; |
| 2150 | replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow; |
| 2151 | replacementSet = true; |
| 2152 | } |
| 2153 | |
| 2154 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2155 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2156 | replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate); |
| 2157 | } |
| 2158 | |
| 2159 | return replacementSet; |
| 2160 | } |
| 2161 | |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2162 | void setDisplayLayoutNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2163 | final DisplayContent dc = getDisplayContent(); |
| 2164 | if (dc != null) { |
| 2165 | dc.setLayoutNeeded(); |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 2169 | void applyAdjustForImeIfNeeded() { |
| 2170 | final Task task = getTask(); |
| 2171 | if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) { |
| 2172 | task.mStack.applyAdjustForImeIfNeeded(task); |
| 2173 | } |
| 2174 | } |
| 2175 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2176 | @Override |
| 2177 | void switchUser() { |
| 2178 | super.switchUser(); |
| 2179 | if (isHiddenFromUserLocked()) { |
| 2180 | if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this |
| 2181 | + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid); |
| 2182 | hideLw(false); |
| 2183 | } |
| 2184 | } |
| 2185 | |
Riddle Hsu | ff03df5 | 2018-12-05 21:43:02 +0800 | [diff] [blame] | 2186 | int getSurfaceTouchableRegion(Region region, int flags) { |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2187 | final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 2188 | if (mAppToken != null && !mAppToken.getResolvedOverrideBounds().isEmpty()) { |
| 2189 | // There may have touchable letterboxes around the activity, so in order to let the |
| 2190 | // letterboxes are able to receive touch event and slip to activity, the activity with |
| 2191 | // compatibility bounds cannot occupy full screen touchable region. |
| 2192 | if (modal) { |
| 2193 | // A modal window uses the whole compatibility bounds. |
| 2194 | flags |= FLAG_NOT_TOUCH_MODAL; |
| 2195 | mTmpRect.set(mAppToken.getResolvedOverrideBounds()); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 2196 | } else { |
| 2197 | // Non-modal uses the application based frame. |
| 2198 | mTmpRect.set(mWindowFrames.mCompatFrame); |
| 2199 | } |
| 2200 | // The offset of compatibility bounds is applied to surface of {@link #AppWindowToken} |
| 2201 | // and frame, so it is unnecessary to translate twice in surface based coordinates. |
| 2202 | final int surfaceOffsetX = mAppToken.inSizeCompatMode() |
| 2203 | ? mAppToken.getBounds().left : 0; |
| 2204 | mTmpRect.offset(surfaceOffsetX - mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top); |
| 2205 | region.set(mTmpRect); |
| 2206 | return flags; |
| 2207 | } |
| 2208 | |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2209 | if (modal && mAppToken != null) { |
| 2210 | // Limit the outer touch to the activity stack region. |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2211 | flags |= FLAG_NOT_TOUCH_MODAL; |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2212 | // If this is a modal window we need to dismiss it if it's not full screen and the |
| 2213 | // touch happens outside of the frame that displays the content. This means we |
| 2214 | // need to intercept touches outside of that window. The dim layer user |
| 2215 | // associated with the window (task or stack) will give us the good bounds, as |
| 2216 | // they would be used to display the dim layer. |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 2217 | final Task task = getTask(); |
| 2218 | if (task != null) { |
| 2219 | task.getDimBounds(mTmpRect); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2220 | } else { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 2221 | getStack().getDimBounds(mTmpRect); |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2222 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2223 | if (inFreeformWindowingMode()) { |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2224 | // For freeform windows we the touch region to include the whole surface for the |
| 2225 | // shadows. |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2226 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
| 2227 | final int delta = WindowManagerService.dipToPixel( |
| 2228 | RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics); |
| 2229 | mTmpRect.inset(-delta, -delta); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2230 | } |
| 2231 | region.set(mTmpRect); |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 2232 | cropRegionToStackBoundsIfNeeded(region); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2233 | subtractTouchExcludeRegionIfNeeded(region); |
| 2234 | } else if (modal && mTapExcludeRegionHolder != null) { |
| 2235 | final Region touchExcludeRegion = Region.obtain(); |
| 2236 | amendTapExcludeRegion(touchExcludeRegion); |
| 2237 | if (!touchExcludeRegion.isEmpty()) { |
| 2238 | // Remove touch modal because there are some areas that cannot be touched. |
| 2239 | flags |= FLAG_NOT_TOUCH_MODAL; |
| 2240 | // Give it a large touchable region at first because it was touch modal. The window |
| 2241 | // might be moved on the display, so the touchable region should be large enough to |
| 2242 | // ensure it covers the whole display, no matter where it is moved. |
| 2243 | getDisplayContent().getBounds(mTmpRect); |
| 2244 | final int dw = mTmpRect.width(); |
| 2245 | final int dh = mTmpRect.height(); |
| 2246 | region.set(-dw, -dh, dw + dw, dh + dh); |
| 2247 | // Subtract the area that cannot be touched. |
| 2248 | region.op(touchExcludeRegion, Region.Op.DIFFERENCE); |
| 2249 | } |
| 2250 | touchExcludeRegion.recycle(); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2251 | } else { |
| 2252 | // Not modal or full screen modal |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 2253 | getTouchableRegion(region); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2254 | } |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 2255 | // Translate to surface based coordinates. |
| 2256 | region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top); |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 2257 | |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2258 | return flags; |
| 2259 | } |
| 2260 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2261 | void checkPolicyVisibilityChange() { |
| 2262 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 2263 | if (DEBUG_VISIBILITY) { |
| 2264 | Slog.v(TAG, "Policy visibility changing after anim in " + |
| 2265 | mWinAnimator + ": " + mPolicyVisibilityAfterAnim); |
| 2266 | } |
| 2267 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2268 | if (!mPolicyVisibility) { |
Jorim Jaggi | 2e05af2 | 2017-12-28 15:15:11 +0100 | [diff] [blame] | 2269 | mWinAnimator.hide("checkPolicyVisibilityChange"); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2270 | if (isFocused()) { |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2271 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
| 2272 | "setAnimationLocked: setting mFocusMayChange true"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2273 | mWmService.mFocusMayChange = true; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2274 | } |
Tetsutoki Shiozawa | 64c5f0c | 2018-05-18 10:55:01 +0900 | [diff] [blame] | 2275 | setDisplayLayoutNeeded(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2276 | // Window is no longer visible -- make sure if we were waiting |
| 2277 | // for it to be displayed before enabling the display, that |
| 2278 | // we allow the display to be enabled now. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2279 | mWmService.enableScreenIfNeededLocked(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | void setRequestedSize(int requestedWidth, int requestedHeight) { |
| 2285 | if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) { |
| 2286 | mLayoutNeeded = true; |
| 2287 | mRequestedWidth = requestedWidth; |
| 2288 | mRequestedHeight = requestedHeight; |
| 2289 | } |
| 2290 | } |
| 2291 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2292 | void prepareWindowToDisplayDuringRelayout(boolean wasVisible) { |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2293 | // We need to turn on screen regardless of visibility. |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 2294 | boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0; |
| 2295 | boolean allowTheaterMode = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2296 | mWmService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt( |
| 2297 | mWmService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0) |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 2298 | == 0; |
| 2299 | boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn(); |
| 2300 | |
| 2301 | // The screen will turn on if the following conditions are met |
| 2302 | // 1. The window has the flag FLAG_TURN_SCREEN_ON |
| 2303 | // 2. The WMS allows theater mode. |
| 2304 | // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once |
| 2305 | // per resume to prevent the screen getting getting turned on for each relayout. Set |
| 2306 | // canTurnScreenOn will be set to false so the window doesn't turn the screen on again |
| 2307 | // during this resume. |
| 2308 | // 4. When the screen is not interactive. This is because when the screen is already |
| 2309 | // interactive, the value may persist until the next animation, which could potentially |
| 2310 | // be occurring while turning off the screen. This would lead to the screen incorrectly |
| 2311 | // turning back on. |
chaviw | 474093d | 2018-03-07 15:03:38 -0800 | [diff] [blame] | 2312 | if (hasTurnScreenOnFlag) { |
| 2313 | if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) { |
| 2314 | if (DEBUG_VISIBILITY || DEBUG_POWER) { |
| 2315 | Slog.v(TAG, "Relayout window turning screen on: " + this); |
| 2316 | } |
| 2317 | mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(), |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 2318 | PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG"); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 2319 | } |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 2320 | |
| 2321 | if (mAppToken != null) { |
| 2322 | mAppToken.setCanTurnScreenOn(false); |
| 2323 | } |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2324 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2325 | |
| 2326 | // If we were already visible, skip rest of preparation. |
| 2327 | if (wasVisible) { |
| 2328 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2329 | "Already visible and does not turn on screen, skip preparing: " + this); |
| 2330 | return; |
| 2331 | } |
| 2332 | |
| 2333 | if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST) |
| 2334 | == SOFT_INPUT_ADJUST_RESIZE) { |
| 2335 | mLayoutNeeded = true; |
| 2336 | } |
| 2337 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2338 | if (isDrawnLw() && mToken.okToAnimate()) { |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2339 | mWinAnimator.applyEnterAnimationLocked(); |
| 2340 | } |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2341 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2342 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 2343 | private Configuration getProcessGlobalConfiguration() { |
| 2344 | // For child windows we want to use the pid for the parent window in case the the child |
| 2345 | // window was added from another process. |
Yunfan Chen | 79b9606 | 2018-10-17 12:45:23 -0700 | [diff] [blame] | 2346 | final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid; |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 2347 | final Configuration processConfig = |
| 2348 | mWmService.mAtmService.getGlobalConfigurationForPid(pid); |
| 2349 | mTempConfiguration.setTo(processConfig == null |
| 2350 | ? mWmService.mRoot.getConfiguration() : processConfig); |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 2351 | return mTempConfiguration; |
| 2352 | } |
| 2353 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2354 | void getMergedConfiguration(MergedConfiguration outConfiguration) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 2355 | final Configuration globalConfig = getProcessGlobalConfiguration(); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2356 | final Configuration overrideConfig = getMergedOverrideConfiguration(); |
| 2357 | outConfiguration.setConfiguration(globalConfig, overrideConfig); |
| 2358 | } |
| 2359 | |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 2360 | void setLastReportedMergedConfiguration(MergedConfiguration config) { |
| 2361 | mLastReportedConfiguration.setTo(config); |
| 2362 | } |
| 2363 | |
| 2364 | void getLastReportedMergedConfiguration(MergedConfiguration config) { |
| 2365 | config.setTo(mLastReportedConfiguration); |
| 2366 | } |
| 2367 | |
| 2368 | private Configuration getLastReportedConfiguration() { |
| 2369 | return mLastReportedConfiguration.getMergedConfiguration(); |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2370 | } |
| 2371 | |
| 2372 | void adjustStartingWindowFlags() { |
| 2373 | if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null |
| 2374 | && mAppToken.startingWindow != null) { |
| 2375 | // Special handling of starting window over the base |
| 2376 | // window of the app: propagate lock screen flags to it, |
| 2377 | // to provide the correct semantics while starting. |
| 2378 | final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD |
| 2379 | | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 2380 | WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs; |
| 2381 | sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask); |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | void setWindowScale(int requestedWidth, int requestedHeight) { |
| 2386 | final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0; |
| 2387 | |
| 2388 | if (scaledWindow) { |
| 2389 | // requested{Width|Height} Surface's physical size |
| 2390 | // attrs.{width|height} Size on screen |
| 2391 | // TODO: We don't check if attrs != null here. Is it implicitly checked? |
| 2392 | mHScale = (mAttrs.width != requestedWidth) ? |
| 2393 | (mAttrs.width / (float)requestedWidth) : 1.0f; |
| 2394 | mVScale = (mAttrs.height != requestedHeight) ? |
| 2395 | (mAttrs.height / (float)requestedHeight) : 1.0f; |
| 2396 | } else { |
| 2397 | mHScale = mVScale = 1; |
| 2398 | } |
| 2399 | } |
| 2400 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2401 | private class DeathRecipient implements IBinder.DeathRecipient { |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 2402 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2403 | public void binderDied() { |
| 2404 | try { |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2405 | boolean resetSplitScreenResizing = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2406 | synchronized (mWmService.mGlobalLock) { |
| 2407 | final WindowState win = mWmService |
| 2408 | .windowForClientLocked(mSession, mClient, false); |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2409 | Slog.i(TAG, "WIN DEATH: " + win); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2410 | if (win != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2411 | final DisplayContent dc = getDisplayContent(); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 2412 | if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2413 | mWmService.mTaskSnapshotController.onAppDied(win.mAppToken); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 2414 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2415 | win.removeIfPossible(shouldKeepVisibleDeadAppWindow()); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2416 | if (win.mAttrs.type == TYPE_DOCK_DIVIDER) { |
| 2417 | // The owner of the docked divider died :( We reset the docked stack, |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 2418 | // just in case they have the divider at an unstable position. Better |
| 2419 | // also reset drag resizing state, because the owner can't do it |
| 2420 | // anymore. |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 2421 | final TaskStack stack = |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2422 | dc.getSplitScreenPrimaryStackIgnoringVisibility(); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2423 | if (stack != null) { |
| 2424 | stack.resetDockedStackToMiddle(); |
| 2425 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2426 | resetSplitScreenResizing = true; |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2427 | } |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 2428 | } else if (mHasSurface) { |
Craig Mautner | a99764e | 2013-03-06 10:22:16 -0800 | [diff] [blame] | 2429 | Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid."); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 2430 | WindowState.this.removeIfPossible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2431 | } |
| 2432 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2433 | if (resetSplitScreenResizing) { |
| 2434 | try { |
| 2435 | // Note: this calls into ActivityManager, so we must *not* hold the window |
| 2436 | // manager lock while calling this. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2437 | mWmService.mActivityTaskManager.setSplitScreenResizing(false); |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2438 | } catch (RemoteException e) { |
| 2439 | // Local call, shouldn't return RemoteException. |
| 2440 | throw e.rethrowAsRuntimeException(); |
| 2441 | } |
| 2442 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2443 | } catch (IllegalArgumentException ex) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 2444 | // This will happen if the window has already been removed. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2445 | } |
| 2446 | } |
| 2447 | } |
| 2448 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2449 | /** |
| 2450 | * Returns true if this window is visible and belongs to a dead app and shouldn't be removed, |
| 2451 | * because we want to preserve its location on screen to be re-activated later when the user |
| 2452 | * interacts with it. |
| 2453 | */ |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2454 | private boolean shouldKeepVisibleDeadAppWindow() { |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2455 | if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) { |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2456 | // Not a visible app window or the app isn't dead. |
| 2457 | return false; |
| 2458 | } |
| 2459 | |
Wale Ogunwale | 51d1d91 | 2016-05-04 13:27:18 -0700 | [diff] [blame] | 2460 | if (mAttrs.token != mClient.asBinder()) { |
| 2461 | // The window was add by a client using another client's app token. We don't want to |
| 2462 | // keep the dead window around for this case since this is meant for 'real' apps. |
| 2463 | return false; |
| 2464 | } |
| 2465 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2466 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2467 | // We don't keep starting windows since they were added by the window manager before |
| 2468 | // the app even launched. |
| 2469 | return false; |
| 2470 | } |
| 2471 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2472 | return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen(); |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2473 | } |
| 2474 | |
Tiger Huang | 513d5e1 | 2018-07-16 21:49:50 +0800 | [diff] [blame] | 2475 | @Override |
| 2476 | public boolean canReceiveKeys() { |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 2477 | return isVisibleOrAdding() |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 2478 | && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2479 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0) |
Jorim Jaggi | b72c9ad | 2016-04-11 18:27:58 -0700 | [diff] [blame] | 2480 | && (mAppToken == null || mAppToken.windowsAreFocusable()) |
Robert Carr | ebdf858 | 2018-09-04 14:50:15 -0700 | [diff] [blame] | 2481 | && !cantReceiveTouchInput(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 2482 | } |
| 2483 | |
lumark | 31e4f8e | 2019-01-10 20:48:18 +0800 | [diff] [blame] | 2484 | @Override |
| 2485 | public boolean canShowWhenLocked() { |
| 2486 | final boolean showBecauseOfActivity = |
| 2487 | mAppToken != null && mAppToken.mActivityRecord.canShowWhenLocked(); |
| 2488 | final boolean showBecauseOfWindow = (getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 2489 | return showBecauseOfActivity || showBecauseOfWindow; |
| 2490 | } |
| 2491 | |
Robert Carr | ebdf858 | 2018-09-04 14:50:15 -0700 | [diff] [blame] | 2492 | /** @return false if this window desires touch events. */ |
| 2493 | boolean cantReceiveTouchInput() { |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 2494 | return mAppToken != null && mAppToken.getTask() != null |
Arthur Hung | 0b650ba | 2019-01-30 19:23:53 +0800 | [diff] [blame] | 2495 | && (mAppToken.getTask().mStack.shouldIgnoreInput() || mAppToken.hiddenRequested); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2496 | } |
| 2497 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2498 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2499 | public boolean hasDrawnLw() { |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2500 | return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2501 | } |
| 2502 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2503 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2504 | public boolean showLw(boolean doAnimation) { |
| 2505 | return showLw(doAnimation, true); |
| 2506 | } |
| 2507 | |
| 2508 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2509 | if (isHiddenFromUserLocked()) { |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 2510 | return false; |
| 2511 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2512 | if (!mAppOpVisibility) { |
| 2513 | // Being hidden due to app op request. |
| 2514 | return false; |
| 2515 | } |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2516 | if (mPermanentlyHidden) { |
| 2517 | // Permanently hidden until the app exists as apps aren't prepared |
| 2518 | // to handle their windows being removed from under them. |
| 2519 | return false; |
| 2520 | } |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 2521 | if (mHiddenWhileSuspended) { |
| 2522 | // Being hidden due to owner package being suspended. |
| 2523 | return false; |
| 2524 | } |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 2525 | if (mForceHideNonSystemOverlayWindow) { |
| 2526 | // This is an alert window that is currently force hidden. |
| 2527 | return false; |
| 2528 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2529 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 2530 | // Already showing. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2531 | return false; |
| 2532 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2533 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2534 | if (doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2535 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 2536 | + mPolicyVisibility + " animating=" + isAnimating()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2537 | if (!mToken.okToAnimate()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2538 | doAnimation = false; |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 2539 | } else if (mPolicyVisibility && !isAnimating()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2540 | // Check for the case where we are currently visible and |
| 2541 | // not animating; we do not want to do animation at such a |
| 2542 | // point to become visible when we already are. |
| 2543 | doAnimation = false; |
| 2544 | } |
| 2545 | } |
| 2546 | mPolicyVisibility = true; |
| 2547 | mPolicyVisibilityAfterAnim = true; |
| 2548 | if (doAnimation) { |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 2549 | mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2550 | } |
| 2551 | if (requestAnim) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2552 | mWmService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2553 | } |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2554 | if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2555 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */); |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2556 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2557 | return true; |
| 2558 | } |
| 2559 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2560 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2561 | public boolean hideLw(boolean doAnimation) { |
| 2562 | return hideLw(doAnimation, true); |
| 2563 | } |
| 2564 | |
| 2565 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| 2566 | if (doAnimation) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2567 | if (!mToken.okToAnimate()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2568 | doAnimation = false; |
| 2569 | } |
| 2570 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2571 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2572 | if (!current) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 2573 | // Already hiding. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2574 | return false; |
| 2575 | } |
| 2576 | if (doAnimation) { |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 2577 | mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false); |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 2578 | if (!isAnimating()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2579 | doAnimation = false; |
| 2580 | } |
| 2581 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2582 | mPolicyVisibilityAfterAnim = false; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2583 | final boolean isFocused = isFocused(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2584 | if (!doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2585 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2586 | mPolicyVisibility = false; |
| 2587 | // Window is no longer visible -- make sure if we were waiting |
| 2588 | // for it to be displayed before enabling the display, that |
| 2589 | // we allow the display to be enabled now. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2590 | mWmService.enableScreenIfNeededLocked(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2591 | if (isFocused) { |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2592 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 2593 | "WindowState.hideLw: setting mFocusMayChange true"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2594 | mWmService.mFocusMayChange = true; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | if (requestAnim) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2598 | mWmService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2599 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2600 | if (isFocused) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2601 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */); |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2602 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2603 | return true; |
| 2604 | } |
| 2605 | |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 2606 | void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) { |
| 2607 | if (mOwnerCanAddInternalSystemWindow |
| 2608 | || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) { |
| 2609 | return; |
| 2610 | } |
| 2611 | if (mForceHideNonSystemOverlayWindow == forceHide) { |
| 2612 | return; |
| 2613 | } |
| 2614 | mForceHideNonSystemOverlayWindow = forceHide; |
| 2615 | if (forceHide) { |
| 2616 | hideLw(true /* doAnimation */, true /* requestAnim */); |
| 2617 | } else { |
| 2618 | showLw(true /* doAnimation */, true /* requestAnim */); |
| 2619 | } |
| 2620 | } |
| 2621 | |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 2622 | void setHiddenWhileSuspended(boolean hide) { |
| 2623 | if (mOwnerCanAddInternalSystemWindow |
| 2624 | || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) { |
| 2625 | return; |
| 2626 | } |
| 2627 | if (mHiddenWhileSuspended == hide) { |
| 2628 | return; |
| 2629 | } |
| 2630 | mHiddenWhileSuspended = hide; |
| 2631 | if (hide) { |
| 2632 | hideLw(true, true); |
| 2633 | } else { |
| 2634 | showLw(true, true); |
| 2635 | } |
| 2636 | } |
| 2637 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2638 | private void setAppOpVisibilityLw(boolean state) { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2639 | if (mAppOpVisibility != state) { |
| 2640 | mAppOpVisibility = state; |
| 2641 | if (state) { |
| 2642 | // If the policy visibility had last been to hide, then this |
| 2643 | // will incorrectly show at this point since we lost that |
| 2644 | // information. Not a big deal -- for the windows that have app |
| 2645 | // ops modifies they should only be hidden by policy due to the |
| 2646 | // lock screen, and the user won't be changing this if locked. |
| 2647 | // 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] | 2648 | showLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2649 | } else { |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 2650 | hideLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2651 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2652 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2653 | } |
| 2654 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2655 | void initAppOpsState() { |
| 2656 | if (mAppOp == OP_NONE || !mAppOpVisibility) { |
| 2657 | return; |
| 2658 | } |
| 2659 | // If the app op was MODE_DEFAULT we would have checked the permission |
| 2660 | // and add the window only if the permission was granted. Therefore, if |
| 2661 | // the mode is MODE_DEFAULT we want the op to succeed as the window is |
| 2662 | // shown. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2663 | final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2664 | getOwningUid(), getOwningPackage(), true); |
| 2665 | if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) { |
| 2666 | setAppOpVisibilityLw(false); |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | void resetAppOpsState() { |
| 2671 | if (mAppOp != OP_NONE && mAppOpVisibility) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2672 | mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage()); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | void updateAppOpsState() { |
| 2677 | if (mAppOp == OP_NONE) { |
| 2678 | return; |
| 2679 | } |
| 2680 | final int uid = getOwningUid(); |
| 2681 | final String packageName = getOwningPackage(); |
| 2682 | if (mAppOpVisibility) { |
| 2683 | // There is a race between the check and the finish calls but this is fine |
| 2684 | // as this would mean we will get another change callback and will reconcile. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2685 | int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2686 | if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2687 | mWmService.mAppOps.finishOp(mAppOp, uid, packageName); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2688 | setAppOpVisibilityLw(false); |
| 2689 | } |
| 2690 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2691 | final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2692 | if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) { |
| 2693 | setAppOpVisibilityLw(true); |
| 2694 | } |
| 2695 | } |
| 2696 | } |
| 2697 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2698 | public void hidePermanentlyLw() { |
| 2699 | if (!mPermanentlyHidden) { |
| 2700 | mPermanentlyHidden = true; |
| 2701 | hideLw(true, true); |
| 2702 | } |
| 2703 | } |
| 2704 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2705 | public void pokeDrawLockLw(long timeout) { |
| 2706 | if (isVisibleOrAdding()) { |
| 2707 | if (mDrawLock == null) { |
| 2708 | // We want the tag name to be somewhat stable so that it is easier to correlate |
| 2709 | // in wake lock statistics. So in particular, we don't want to include the |
| 2710 | // window's hash code as in toString(). |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2711 | final CharSequence tag = getWindowTag(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2712 | mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2713 | mDrawLock.setReferenceCounted(false); |
| 2714 | mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName)); |
| 2715 | } |
| 2716 | // Each call to acquire resets the timeout. |
| 2717 | if (DEBUG_POWER) { |
| 2718 | Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by " |
| 2719 | + mAttrs.packageName); |
| 2720 | } |
| 2721 | mDrawLock.acquire(timeout); |
| 2722 | } else if (DEBUG_POWER) { |
| 2723 | Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window " |
| 2724 | + "owned by " + mAttrs.packageName); |
| 2725 | } |
| 2726 | } |
| 2727 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2728 | @Override |
| 2729 | public boolean isAlive() { |
| 2730 | return mClient.asBinder().isBinderAlive(); |
| 2731 | } |
| 2732 | |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2733 | boolean isClosing() { |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2734 | return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip()); |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2737 | void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) { |
| 2738 | animators.add(mWinAnimator); |
| 2739 | |
| 2740 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2741 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2742 | c.addWinAnimatorToList(animators); |
| 2743 | } |
| 2744 | } |
| 2745 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2746 | void sendAppVisibilityToClients() { |
| 2747 | super.sendAppVisibilityToClients(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2748 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2749 | final boolean clientHidden = mAppToken.isClientHidden(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2750 | if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) { |
| 2751 | // Don't hide the starting window. |
| 2752 | return; |
| 2753 | } |
| 2754 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2755 | if (clientHidden) { |
| 2756 | // Once we are notifying the client that it's visibility has changed, we need to prevent |
| 2757 | // it from destroying child surfaces until the animation has finished. We do this by |
| 2758 | // detaching any surface control the client added from the client. |
| 2759 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 2760 | final WindowState c = mChildren.get(i); |
| 2761 | c.mWinAnimator.detachChildren(); |
| 2762 | } |
| 2763 | |
| 2764 | mWinAnimator.detachChildren(); |
| 2765 | } |
| 2766 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2767 | try { |
| 2768 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2769 | "Setting visibility of " + this + ": " + (!clientHidden)); |
| 2770 | mClient.dispatchAppVisibility(!clientHidden); |
| 2771 | } catch (RemoteException e) { |
| 2772 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2775 | void onStartFreezingScreen() { |
| 2776 | mAppFreezing = true; |
| 2777 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2778 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2779 | c.onStartFreezingScreen(); |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | boolean onStopFreezingScreen() { |
| 2784 | boolean unfrozeWindows = false; |
| 2785 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2786 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2787 | unfrozeWindows |= c.onStopFreezingScreen(); |
| 2788 | } |
| 2789 | |
| 2790 | if (!mAppFreezing) { |
| 2791 | return unfrozeWindows; |
| 2792 | } |
| 2793 | |
Wale Ogunwale | 953171d | 2016-09-30 09:17:30 -0700 | [diff] [blame] | 2794 | mAppFreezing = false; |
| 2795 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 2796 | if (mHasSurface && !getOrientationChanging() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2797 | && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2798 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 2799 | setOrientationChanging(true); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2800 | mWmService.mRoot.mOrientationChangeComplete = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2801 | } |
| 2802 | mLastFreezeDuration = 0; |
| 2803 | setDisplayLayoutNeeded(); |
| 2804 | return true; |
| 2805 | } |
| 2806 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2807 | boolean destroySurface(boolean cleanupOnResume, boolean appStopped) { |
| 2808 | boolean destroyedSomething = false; |
Jorim Jaggi | 59f3e92 | 2018-01-05 15:40:32 +0100 | [diff] [blame] | 2809 | |
| 2810 | // Copying to a different list as multiple children can be removed. |
| 2811 | final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren); |
| 2812 | for (int i = childWindows.size() - 1; i >= 0; --i) { |
| 2813 | final WindowState c = childWindows.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2814 | destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped); |
| 2815 | } |
| 2816 | |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2817 | if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) { |
| 2818 | return destroyedSomething; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2819 | } |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2820 | |
| 2821 | if (appStopped || mWindowRemovalAllowed) { |
| 2822 | mWinAnimator.destroyPreservedSurfaceLocked(); |
| 2823 | } |
| 2824 | |
| 2825 | if (mDestroying) { |
| 2826 | if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this |
| 2827 | + " destroySurfaces: appStopped=" + appStopped |
| 2828 | + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed |
| 2829 | + " win.mRemoveOnExit=" + mRemoveOnExit); |
| 2830 | if (!cleanupOnResume || mRemoveOnExit) { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 2831 | destroySurfaceUnchecked(); |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2832 | } |
| 2833 | if (mRemoveOnExit) { |
| 2834 | removeImmediately(); |
| 2835 | } |
| 2836 | if (cleanupOnResume) { |
| 2837 | requestUpdateWallpaperIfNeeded(); |
| 2838 | } |
| 2839 | mDestroying = false; |
| 2840 | destroyedSomething = true; |
| 2841 | } |
| 2842 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2843 | return destroyedSomething; |
| 2844 | } |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 2845 | |
Robert Carr | 89a28ab | 2017-04-24 15:33:11 -0700 | [diff] [blame] | 2846 | // Destroy or save the application surface without checking |
| 2847 | // various indicators of whether the client has released the surface. |
| 2848 | // This is in general unsafe, and most callers should use {@link #destroySurface} |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 2849 | void destroySurfaceUnchecked() { |
| 2850 | mWinAnimator.destroySurfaceLocked(); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2851 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2852 | // Clear animating flags now, since the surface is now gone. (Note this is true even |
| 2853 | // if the surface is saved, to outside world the surface is still NO_SURFACE.) |
| 2854 | mAnimatingExit = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2855 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2856 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2857 | @Override |
| 2858 | public boolean isDefaultDisplay() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2859 | final DisplayContent displayContent = getDisplayContent(); |
| 2860 | if (displayContent == null) { |
| 2861 | // Only a window that was on a non-default display can be detached from it. |
| 2862 | return false; |
| 2863 | } |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 2864 | return displayContent.isDefaultDisplay; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2867 | void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) { |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2868 | mShowToOwnerOnly = showToOwnerOnly; |
| 2869 | } |
| 2870 | |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 2871 | private boolean isHiddenFromUserLocked() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 2872 | // Child windows are evaluated based on their parent window. |
| 2873 | final WindowState win = getTopParentWindow(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2874 | if (win.mAttrs.type < FIRST_SYSTEM_WINDOW |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 2875 | && win.mAppToken != null && win.mAppToken.mShowForAllUsers) { |
Jorim Jaggi | dbe44ac | 2016-04-22 19:50:13 -0700 | [diff] [blame] | 2876 | |
| 2877 | // All window frames that are fullscreen extend above status bar, but some don't extend |
| 2878 | // below navigation bar. Thus, check for display frame for top/left and stable frame for |
| 2879 | // bottom right. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 2880 | if (win.getFrameLw().left <= win.getDisplayFrameLw().left |
| 2881 | && win.getFrameLw().top <= win.getDisplayFrameLw().top |
| 2882 | && win.getFrameLw().right >= win.getStableFrameLw().right |
| 2883 | && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2884 | // Is a fullscreen window, like the clock alarm. Show to everyone. |
| 2885 | return false; |
| 2886 | } |
| 2887 | } |
| 2888 | |
Craig Mautner | 341220f | 2012-10-16 15:20:09 -0700 | [diff] [blame] | 2889 | return win.mShowToOwnerOnly |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2890 | && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid)); |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2893 | private static void applyInsets(Region outRegion, Rect frame, Rect inset) { |
| 2894 | outRegion.set( |
| 2895 | frame.left + inset.left, frame.top + inset.top, |
| 2896 | frame.right - inset.right, frame.bottom - inset.bottom); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2897 | } |
| 2898 | |
Riddle Hsu | ff03df5 | 2018-12-05 21:43:02 +0800 | [diff] [blame] | 2899 | /** Get the touchable region in global coordinates. */ |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2900 | void getTouchableRegion(Region outRegion) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 2901 | final Rect frame = mWindowFrames.mFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2902 | switch (mTouchableInsets) { |
| 2903 | default: |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2904 | case TOUCHABLE_INSETS_FRAME: |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2905 | outRegion.set(frame); |
| 2906 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2907 | case TOUCHABLE_INSETS_CONTENT: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2908 | applyInsets(outRegion, frame, mGivenContentInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2909 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2910 | case TOUCHABLE_INSETS_VISIBLE: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2911 | applyInsets(outRegion, frame, mGivenVisibleInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2912 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2913 | case TOUCHABLE_INSETS_REGION: { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2914 | outRegion.set(mGivenTouchableRegion); |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 2915 | outRegion.translate(frame.left, frame.top); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2916 | break; |
| 2917 | } |
| 2918 | } |
Vishnu Nair | b924632 | 2018-12-06 13:54:02 -0800 | [diff] [blame] | 2919 | cropRegionToStackBoundsIfNeeded(outRegion); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2920 | subtractTouchExcludeRegionIfNeeded(outRegion); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2921 | } |
| 2922 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 2923 | private void cropRegionToStackBoundsIfNeeded(Region region) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2924 | final Task task = getTask(); |
| 2925 | if (task == null || !task.cropWindowsToStackBounds()) { |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2926 | return; |
| 2927 | } |
| 2928 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2929 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2930 | if (stack == null) { |
| 2931 | return; |
| 2932 | } |
| 2933 | |
| 2934 | stack.getDimBounds(mTmpRect); |
| 2935 | region.op(mTmpRect, Region.Op.INTERSECT); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2936 | } |
| 2937 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2938 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2939 | * If this window has areas that cannot be touched, we subtract those areas from its touchable |
| 2940 | * region. |
| 2941 | */ |
| 2942 | private void subtractTouchExcludeRegionIfNeeded(Region touchableRegion) { |
| 2943 | if (mTapExcludeRegionHolder == null) { |
| 2944 | return; |
| 2945 | } |
| 2946 | final Region touchExcludeRegion = Region.obtain(); |
| 2947 | amendTapExcludeRegion(touchExcludeRegion); |
| 2948 | if (!touchExcludeRegion.isEmpty()) { |
| 2949 | touchableRegion.op(touchExcludeRegion, Region.Op.DIFFERENCE); |
| 2950 | } |
| 2951 | touchExcludeRegion.recycle(); |
| 2952 | } |
| 2953 | |
| 2954 | /** |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2955 | * Report a focus change. Must be called with no locks held, and consistently |
| 2956 | * from the same serialized thread (such as dispatched from a handler). |
| 2957 | */ |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2958 | void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2959 | try { |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2960 | mClient.windowFocusChanged(focused, inTouchMode); |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2961 | } catch (RemoteException e) { |
| 2962 | } |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 2963 | if (mFocusCallbacks != null) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2964 | final int N = mFocusCallbacks.beginBroadcast(); |
| 2965 | for (int i=0; i<N; i++) { |
| 2966 | IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i); |
| 2967 | try { |
| 2968 | if (focused) { |
| 2969 | obs.focusGained(mWindowId.asBinder()); |
| 2970 | } else { |
| 2971 | obs.focusLost(mWindowId.asBinder()); |
| 2972 | } |
| 2973 | } catch (RemoteException e) { |
| 2974 | } |
| 2975 | } |
| 2976 | mFocusCallbacks.finishBroadcast(); |
| 2977 | } |
| 2978 | } |
| 2979 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 2980 | @Override |
| 2981 | public Configuration getConfiguration() { |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 2982 | if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 2983 | return mAppToken.mFrozenMergedConfig.peek(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 2984 | } |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 2985 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 2986 | // We use the process config this window is associated with as the based global config since |
| 2987 | // the process can override it config, but isn't part of the window hierarchy. |
| 2988 | final Configuration config = getProcessGlobalConfiguration(); |
| 2989 | config.updateFrom(getMergedOverrideConfiguration()); |
| 2990 | return config; |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2993 | void reportResized() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2994 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag()); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2995 | try { |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 2996 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 2997 | + ": " + mWindowFrames.mCompatFrame); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2998 | final MergedConfiguration mergedConfiguration = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2999 | new MergedConfiguration(mWmService.mRoot.getConfiguration(), |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3000 | getMergedOverrideConfiguration()); |
| 3001 | |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 3002 | setLastReportedMergedConfiguration(mergedConfiguration); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3003 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3004 | if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING) |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 3005 | Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING"); |
| 3006 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3007 | final Rect frame = mWindowFrames.mCompatFrame; |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3008 | final Rect overscanInsets = mWindowFrames.mLastOverscanInsets; |
| 3009 | final Rect contentInsets = mWindowFrames.mLastContentInsets; |
| 3010 | final Rect visibleInsets = mWindowFrames.mLastVisibleInsets; |
| 3011 | final Rect stableInsets = mWindowFrames.mLastStableInsets; |
| 3012 | final Rect outsets = mWindowFrames.mLastOutsets; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3013 | final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3014 | final boolean reportOrientation = mReportOrientationChanged; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3015 | final int displayId = getDisplayId(); |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 3016 | final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout(); |
Chet Haase | 8eb48d2 | 2014-09-24 07:31:29 -0700 | [diff] [blame] | 3017 | if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 3018 | && mClient instanceof IWindow.Stub) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3019 | // To prevent deadlock simulate one-way call if win.mClient is a local object. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3020 | mWmService.mH.post(new Runnable() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3021 | @Override |
| 3022 | public void run() { |
| 3023 | try { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3024 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3025 | stableInsets, outsets, reportDraw, mergedConfiguration, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3026 | reportOrientation, displayId, displayCutout); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3027 | } catch (RemoteException e) { |
| 3028 | // Not a remote call, RemoteException won't be raised. |
| 3029 | } |
| 3030 | } |
| 3031 | }); |
| 3032 | } else { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3033 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3034 | outsets, reportDraw, mergedConfiguration, reportOrientation, displayId, |
| 3035 | displayCutout); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3036 | } |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3037 | |
| 3038 | //TODO (multidisplay): Accessibility supported only for the default display. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3039 | if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) { |
| 3040 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3043 | mWindowFrames.resetInsetsChanged(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3044 | mWinAnimator.mSurfaceResized = false; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3045 | mReportOrientationChanged = false; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3046 | } catch (RemoteException e) { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3047 | setOrientationChanging(false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3048 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3049 | - mWmService.mDisplayFreezeTime); |
tiger_huang | 950ee77 | 2014-07-11 18:41:48 +0800 | [diff] [blame] | 3050 | // We are assuming the hosting process is dead or in a zombie state. |
| 3051 | Slog.w(TAG, "Failed to report 'resized' to the client of " + this |
| 3052 | + ", removing this window."); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3053 | mWmService.mPendingRemove.add(this); |
| 3054 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3055 | } |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3056 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3057 | } |
| 3058 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3059 | /** |
| 3060 | * Called when the insets state changed. |
| 3061 | */ |
| 3062 | void notifyInsetsChanged() { |
| 3063 | try { |
| 3064 | mClient.insetsChanged( |
| 3065 | getDisplayContent().getInsetsStateController().getInsetsForDispatch(this)); |
| 3066 | } catch (RemoteException e) { |
| 3067 | Slog.w(TAG, "Failed to deliver inset state change", e); |
| 3068 | } |
| 3069 | } |
| 3070 | |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 3071 | void notifyInsetsControlChanged() { |
| 3072 | final InsetsStateController stateController = |
| 3073 | getDisplayContent().getInsetsStateController(); |
| 3074 | try { |
| 3075 | mClient.insetsControlChanged(stateController.getInsetsForDispatch(this), |
| 3076 | stateController.getControlsForDispatch(this)); |
| 3077 | } catch (RemoteException e) { |
| 3078 | Slog.w(TAG, "Failed to deliver inset state change", e); |
| 3079 | } |
| 3080 | } |
| 3081 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3082 | Rect getBackdropFrame(Rect frame) { |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 3083 | // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing |
| 3084 | // start even if we haven't received the relayout window, so that the client requests |
| 3085 | // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen |
| 3086 | // until the window to small size, otherwise the multithread renderer will shift last |
| 3087 | // one or more frame to wrong offset. So here we send fullscreen backdrop if either |
| 3088 | // isDragResizing() or isDragResizeChanged() is true. |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3089 | boolean resizing = isDragResizing() || isDragResizeChanged(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 3090 | if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) { |
Garfield Tan | fbd8ea6 | 2018-10-16 17:09:49 -0700 | [diff] [blame] | 3091 | // Surface position is now inherited from parent, and BackdropFrameRenderer uses |
| 3092 | // backdrop frame to position content. Thus we just keep the size of backdrop frame, and |
| 3093 | // remove the offset to avoid double offset from display origin. |
| 3094 | mTmpRect.set(frame); |
| 3095 | mTmpRect.offsetTo(0, 0); |
| 3096 | return mTmpRect; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3097 | } |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 3098 | final DisplayInfo displayInfo = getDisplayInfo(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3099 | mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3100 | return mTmpRect; |
| 3101 | } |
| 3102 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3103 | private int getStackId() { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3104 | final TaskStack stack = getStack(); |
| 3105 | if (stack == null) { |
| 3106 | return INVALID_STACK_ID; |
| 3107 | } |
| 3108 | return stack.mStackId; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
| 3112 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3113 | MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId, |
| 3114 | DisplayCutout displayCutout) |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3115 | throws RemoteException { |
Robert Carr | 09286c9 | 2018-02-15 13:52:31 -0800 | [diff] [blame] | 3116 | final boolean forceRelayout = isDragResizeChanged() || reportOrientation; |
Chong Zhang | edaf305 | 2016-04-22 15:04:31 -0700 | [diff] [blame] | 3117 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 3118 | mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3119 | reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout, |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 3120 | getDisplayContent().getDisplayPolicy().isNavBarForcedShownLw(this), displayId, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3121 | new DisplayCutout.ParcelableWrapper(displayCutout)); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3122 | mDragResizingChangeReported = true; |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3123 | } |
| 3124 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3125 | public void registerFocusObserver(IWindowFocusObserver observer) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3126 | synchronized (mWmService.mGlobalLock) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3127 | if (mFocusCallbacks == null) { |
| 3128 | mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>(); |
| 3129 | } |
| 3130 | mFocusCallbacks.register(observer); |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3135 | synchronized (mWmService.mGlobalLock) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3136 | if (mFocusCallbacks != null) { |
| 3137 | mFocusCallbacks.unregister(observer); |
| 3138 | } |
| 3139 | } |
| 3140 | } |
| 3141 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3142 | boolean isFocused() { |
| 3143 | return getDisplayContent().mCurrentFocus == this; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3144 | } |
| 3145 | |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 3146 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3147 | /** Is this window in a container that takes up the entire screen space? */ |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3148 | private boolean inAppWindowThatMatchesParentBounds() { |
| 3149 | return mAppToken == null || (mAppToken.matchParentBounds() && !inMultiWindowMode()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3152 | /** @return true when the window is in fullscreen mode, but has non-fullscreen bounds set, or |
| 3153 | * is transitioning into/out-of fullscreen. */ |
Andrii Kulian | 283acd2 | 2017-08-03 04:03:51 -0700 | [diff] [blame] | 3154 | boolean isLetterboxedAppWindow() { |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3155 | return !inMultiWindowMode() && !matchesDisplayBounds() |
Adrian Roos | 865c70f | 2018-01-10 17:32:27 +0100 | [diff] [blame] | 3156 | || isLetterboxedForDisplayCutoutLw(); |
Adrian Roos | 4d18a2e | 2017-12-19 19:08:05 +0100 | [diff] [blame] | 3157 | } |
| 3158 | |
Adrian Roos | 865c70f | 2018-01-10 17:32:27 +0100 | [diff] [blame] | 3159 | @Override |
| 3160 | public boolean isLetterboxedForDisplayCutoutLw() { |
| 3161 | if (mAppToken == null) { |
| 3162 | // Only windows with an AppWindowToken are letterboxed. |
| 3163 | return false; |
| 3164 | } |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 3165 | if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) { |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 3166 | // Cutout didn't make a difference, no letterbox |
Adrian Roos | 4d18a2e | 2017-12-19 19:08:05 +0100 | [diff] [blame] | 3167 | return false; |
| 3168 | } |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 3169 | if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) { |
Adrian Roos | 4d18a2e | 2017-12-19 19:08:05 +0100 | [diff] [blame] | 3170 | // Layout in cutout, no letterbox. |
| 3171 | return false; |
| 3172 | } |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 3173 | if (!mAttrs.isFullscreen()) { |
| 3174 | // Not filling the parent frame, no letterbox |
| 3175 | return false; |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 3176 | } |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 3177 | // Otherwise we need a letterbox if the layout was smaller than the app window token allowed |
| 3178 | // it to be. |
| 3179 | return !frameCoversEntireAppTokenBounds(); |
| 3180 | } |
| 3181 | |
| 3182 | /** |
| 3183 | * @return true if this window covers the entire bounds of its app window token |
| 3184 | * @throws NullPointerException if there is no app window token for this window |
| 3185 | */ |
| 3186 | private boolean frameCoversEntireAppTokenBounds() { |
| 3187 | mTmpRect.set(mAppToken.getBounds()); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3188 | mTmpRect.intersectUnchecked(mWindowFrames.mFrame); |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 3189 | return mAppToken.getBounds().equals(mTmpRect); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3190 | } |
| 3191 | |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 3192 | @Override |
| 3193 | public boolean isLetterboxedOverlappingWith(Rect rect) { |
| 3194 | return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect); |
| 3195 | } |
| 3196 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3197 | boolean isDragResizeChanged() { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3198 | return mDragResizing != computeDragResizing(); |
| 3199 | } |
| 3200 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3201 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3202 | void setWaitingForDrawnIfResizingChanged() { |
| 3203 | if (isDragResizeChanged()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3204 | mWmService.mWaitingForDrawn.add(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3205 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3206 | super.setWaitingForDrawnIfResizingChanged(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3209 | /** |
| 3210 | * @return Whether we reported a drag resize change to the application or not already. |
| 3211 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3212 | private boolean isDragResizingChangeReported() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3213 | return mDragResizingChangeReported; |
| 3214 | } |
| 3215 | |
| 3216 | /** |
| 3217 | * Resets the state whether we reported a drag resize change to the app. |
| 3218 | */ |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3219 | @Override |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3220 | void resetDragResizingChangeReported() { |
| 3221 | mDragResizingChangeReported = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3222 | super.resetDragResizingChangeReported(); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3223 | } |
| 3224 | |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 3225 | int getResizeMode() { |
| 3226 | return mResizeMode; |
| 3227 | } |
| 3228 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3229 | private boolean computeDragResizing() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 3230 | final Task task = getTask(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3231 | if (task == null) { |
| 3232 | return false; |
| 3233 | } |
Tomasz Mikolajewski | af20b8d | 2017-11-20 16:11:33 +0900 | [diff] [blame] | 3234 | if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) { |
Winson Chung | 2af04b3 | 2017-01-24 16:21:13 -0800 | [diff] [blame] | 3235 | return false; |
| 3236 | } |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 3237 | if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) { |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 3238 | // Floating windows never enter drag resize mode. |
| 3239 | return false; |
| 3240 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3241 | if (task.isDragResizing()) { |
| 3242 | return true; |
| 3243 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 3244 | |
| 3245 | // If the bounds are currently frozen, it means that the layout size that the app sees |
| 3246 | // and the bounds we clip this window to might be different. In order to avoid holes, we |
| 3247 | // simulate that we are still resizing so the app fills the hole with the resizing |
| 3248 | // background. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3249 | return (getDisplayContent().mDividerControllerLocked.isResizing() |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 3250 | || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) && |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3251 | !task.inFreeformWindowingMode() && !isGoneForLayoutLw(); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3252 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | void setDragResizing() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3256 | final boolean resizing = computeDragResizing(); |
| 3257 | if (resizing == mDragResizing) { |
| 3258 | return; |
| 3259 | } |
| 3260 | mDragResizing = resizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3261 | final Task task = getTask(); |
| 3262 | if (task != null && task.isDragResizing()) { |
| 3263 | mResizeMode = task.getDragResizeMode(); |
| 3264 | } else { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3265 | mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing() |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3266 | ? DRAG_RESIZE_MODE_DOCKED_DIVIDER |
| 3267 | : DRAG_RESIZE_MODE_FREEFORM; |
| 3268 | } |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | boolean isDragResizing() { |
| 3272 | return mDragResizing; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 3273 | } |
| 3274 | |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 3275 | boolean isDockedResizing() { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 3276 | return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER) |
| 3277 | || (isChildWindow() && getParentWindow().isDockedResizing()); |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 3280 | @CallSuper |
| 3281 | @Override |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3282 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 3283 | @WindowTraceLogLevel int logLevel) { |
| 3284 | boolean isVisible = isVisible(); |
| 3285 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) { |
| 3286 | return; |
| 3287 | } |
| 3288 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3289 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3290 | super.writeToProto(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3291 | writeIdentifierToProto(proto, IDENTIFIER); |
| 3292 | proto.write(DISPLAY_ID, getDisplayId()); |
| 3293 | proto.write(STACK_ID, getStackId()); |
| 3294 | mAttrs.writeToProto(proto, ATTRIBUTES); |
| 3295 | mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 3296 | mWindowFrames.writeToProto(proto, WINDOW_FRAMES); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3297 | mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS); |
Jorim Jaggi | 45be1c4c | 2017-12-15 18:44:43 +0100 | [diff] [blame] | 3298 | mSurfacePosition.writeToProto(proto, SURFACE_POSITION); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3299 | mWinAnimator.writeToProto(proto, ANIMATOR); |
| 3300 | proto.write(ANIMATING_EXIT, mAnimatingExit); |
| 3301 | for (int i = 0; i < mChildren.size(); i++) { |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3302 | mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3303 | } |
Vishnu Nair | 1d0fa07 | 2018-01-04 07:53:00 -0800 | [diff] [blame] | 3304 | proto.write(REQUESTED_WIDTH, mRequestedWidth); |
| 3305 | proto.write(REQUESTED_HEIGHT, mRequestedHeight); |
| 3306 | proto.write(VIEW_VISIBILITY, mViewVisibility); |
| 3307 | proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility); |
| 3308 | proto.write(HAS_SURFACE, mHasSurface); |
| 3309 | proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay()); |
Vishnu Nair | 1d0fa07 | 2018-01-04 07:53:00 -0800 | [diff] [blame] | 3310 | proto.write(REMOVE_ON_EXIT, mRemoveOnExit); |
| 3311 | proto.write(DESTROYING, mDestroying); |
| 3312 | proto.write(REMOVED, mRemoved); |
| 3313 | proto.write(IS_ON_SCREEN, isOnScreen()); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3314 | proto.write(IS_VISIBLE, isVisible); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 3315 | proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null); |
| 3316 | proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber); |
| 3317 | proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3318 | proto.end(token); |
| 3319 | } |
| 3320 | |
Vishnu Nair | 9a3e406 | 2018-01-11 08:42:54 -0800 | [diff] [blame] | 3321 | @Override |
| 3322 | public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) { |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3323 | final long token = proto.start(fieldId); |
| 3324 | proto.write(HASH_CODE, System.identityHashCode(this)); |
| 3325 | proto.write(USER_ID, UserHandle.getUserId(mOwnerUid)); |
| 3326 | final CharSequence title = getWindowTag(); |
| 3327 | if (title != null) { |
| 3328 | proto.write(TITLE, title.toString()); |
| 3329 | } |
| 3330 | proto.end(token); |
| 3331 | } |
| 3332 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 3333 | @Override |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3334 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Wale Ogunwale | 30cc7bf | 2015-02-04 16:47:57 -0800 | [diff] [blame] | 3335 | final TaskStack stack = getStack(); |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3336 | pw.print(prefix + "mDisplayId=" + getDisplayId()); |
| 3337 | if (stack != null) { |
| 3338 | pw.print(" stackId=" + stack.mStackId); |
| 3339 | } |
| 3340 | pw.println(" mSession=" + mSession |
| 3341 | + " mClient=" + mClient.asBinder()); |
| 3342 | pw.println(prefix + "mOwnerUid=" + mOwnerUid |
| 3343 | + " mShowToOwnerOnly=" + mShowToOwnerOnly |
| 3344 | + " package=" + mAttrs.packageName |
| 3345 | + " appop=" + AppOpsManager.opToName(mAppOp)); |
| 3346 | pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix)); |
| 3347 | pw.println(prefix + "Requested w=" + mRequestedWidth |
| 3348 | + " h=" + mRequestedHeight |
| 3349 | + " mLayoutSeq=" + mLayoutSeq); |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 3350 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3351 | pw.println(prefix + "LastRequested w=" + mLastRequestedWidth |
| 3352 | + " h=" + mLastRequestedHeight); |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 3353 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3354 | if (mIsChildWindow || mLayoutAttached) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3355 | pw.println(prefix + "mParentWindow=" + getParentWindow() |
| 3356 | + " mLayoutAttached=" + mLayoutAttached); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3357 | } |
| 3358 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3359 | pw.println(prefix + "mIsImWindow=" + mIsImWindow |
| 3360 | + " mIsWallpaper=" + mIsWallpaper |
| 3361 | + " mIsFloatingLayer=" + mIsFloatingLayer |
| 3362 | + " mWallpaperVisible=" + mWallpaperVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3363 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3364 | if (dumpAll) { |
Jorim Jaggi | 35d328a | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3365 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 3366 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3367 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3368 | if (dumpAll) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3369 | pw.println(prefix + "mToken=" + mToken); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3370 | if (mAppToken != null) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3371 | pw.println(prefix + "mAppToken=" + mAppToken); |
| 3372 | pw.print(prefix + "mAppDied=" + mAppDied); |
| 3373 | pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated()); |
| 3374 | pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn()); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3375 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3376 | pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility) |
| 3377 | + " mHaveFrame=" + mHaveFrame |
| 3378 | + " mObscured=" + mObscured); |
| 3379 | pw.println(prefix + "mSeq=" + mSeq |
| 3380 | + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3381 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 3382 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3383 | || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 3384 | || mHiddenWhileSuspended) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3385 | pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility |
| 3386 | + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim |
| 3387 | + " mAppOpVisibility=" + mAppOpVisibility |
| 3388 | + " parentHidden=" + isParentWindowHidden() |
| 3389 | + " mPermanentlyHidden=" + mPermanentlyHidden |
| 3390 | + " mHiddenWhileSuspended=" + mHiddenWhileSuspended |
| 3391 | + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3392 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 3393 | if (!mRelayoutCalled || mLayoutNeeded) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3394 | pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled |
| 3395 | + " mLayoutNeeded=" + mLayoutNeeded); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3396 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3397 | if (dumpAll) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3398 | pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB) |
| 3399 | + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3400 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3401 | pw.println(prefix + "mTouchableInsets=" + mTouchableInsets |
| 3402 | + " mGivenInsetsPending=" + mGivenInsetsPending); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3403 | Region region = new Region(); |
| 3404 | getTouchableRegion(region); |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3405 | pw.println(prefix + "touchable region=" + region); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3406 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3407 | pw.println(prefix + "mFullConfiguration=" + getConfiguration()); |
| 3408 | pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3409 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3410 | pw.println(prefix + "mHasSurface=" + mHasSurface |
| 3411 | + " isReadyForDisplay()=" + isReadyForDisplay() |
| 3412 | + " mWindowRemovalAllowed=" + mWindowRemovalAllowed); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3413 | if (inSizeCompatMode()) { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3414 | pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB)); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3415 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3416 | if (dumpAll) { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 3417 | mWindowFrames.dump(pw, prefix); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3418 | pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3419 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 3420 | super.dump(pw, prefix, dumpAll); |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3421 | pw.println(prefix + mWinAnimator + ":"); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 3422 | mWinAnimator.dump(pw, prefix + " ", dumpAll); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3423 | if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3424 | pw.println(prefix + "mAnimatingExit=" + mAnimatingExit |
| 3425 | + " mRemoveOnExit=" + mRemoveOnExit |
| 3426 | + " mDestroying=" + mDestroying |
| 3427 | + " mRemoved=" + mRemoved); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3428 | } |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 3429 | if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3430 | pw.println(prefix + "mOrientationChanging=" + mOrientationChanging |
| 3431 | + " configOrientationChanging=" |
| 3432 | + (getLastReportedConfiguration().orientation != getConfiguration().orientation) |
| 3433 | + " mAppFreezing=" + mAppFreezing |
| 3434 | + " mReportOrientationChanged=" + mReportOrientationChanged); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3435 | } |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 3436 | if (mLastFreezeDuration != 0) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3437 | pw.print(prefix + "mLastFreezeDuration="); |
| 3438 | TimeUtils.formatDuration(mLastFreezeDuration, pw); |
| 3439 | pw.println(); |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 3440 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3441 | pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate |
| 3442 | + " seamlesslyRotate: pending="); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 3443 | if (mPendingSeamlessRotate != null) { |
| 3444 | mPendingSeamlessRotate.dump(pw); |
| 3445 | } else { |
| 3446 | pw.print("null"); |
Adrian Roos | 27a90d2 | 2018-07-06 02:39:54 -0700 | [diff] [blame] | 3447 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3448 | pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 3449 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3450 | if (mHScale != 1 || mVScale != 1) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3451 | pw.println(prefix + "mHScale=" + mHScale |
| 3452 | + " mVScale=" + mVScale); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3453 | } |
| 3454 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3455 | pw.println(prefix + "mWallpaperX=" + mWallpaperX |
| 3456 | + " mWallpaperY=" + mWallpaperY); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3457 | } |
| 3458 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3459 | pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep |
| 3460 | + " mWallpaperYStep=" + mWallpaperYStep); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3461 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3462 | if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE |
| 3463 | || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3464 | pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX |
| 3465 | + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3466 | } |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3467 | if (mDrawLock != null) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3468 | pw.println(prefix + "mDrawLock=" + mDrawLock); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3469 | } |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3470 | if (isDragResizing()) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3471 | pw.println(prefix + "isDragResizing=" + isDragResizing()); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3472 | } |
| 3473 | if (computeDragResizing()) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3474 | pw.println(prefix + "computeDragResizing=" + computeDragResizing()); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3475 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3476 | pw.println(prefix + "isOnScreen=" + isOnScreen()); |
| 3477 | pw.println(prefix + "isVisible=" + isVisible()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3478 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3479 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3480 | @Override |
| 3481 | String getName() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3482 | return Integer.toHexString(System.identityHashCode(this)) |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 3483 | + " " + getWindowTag(); |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3486 | CharSequence getWindowTag() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3487 | CharSequence tag = mAttrs.getTitle(); |
| 3488 | if (tag == null || tag.length() <= 0) { |
| 3489 | tag = mAttrs.packageName; |
| 3490 | } |
| 3491 | return tag; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | @Override |
| 3495 | public String toString() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3496 | final CharSequence title = getWindowTag(); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3497 | if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 3498 | mLastTitle = title; |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3499 | mWasExiting = mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3500 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3501 | + " u" + UserHandle.getUserId(mOwnerUid) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3502 | + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3503 | } |
| 3504 | return mStringNameCache; |
| 3505 | } |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3506 | |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3507 | void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) { |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3508 | if (mHScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3509 | clipRect.left = (int) (clipRect.left / mHScale); |
| 3510 | clipRect.right = (int) Math.ceil(clipRect.right / mHScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3511 | } |
| 3512 | if (mVScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3513 | clipRect.top = (int) (clipRect.top / mVScale); |
| 3514 | clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3515 | } |
| 3516 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3517 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3518 | private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) { |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3519 | final int pw = containingFrame.width(); |
| 3520 | final int ph = containingFrame.height(); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3521 | final Task task = getTask(); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3522 | final boolean inNonFullscreenContainer = !inAppWindowThatMatchesParentBounds(); |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 3523 | final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0; |
| 3524 | |
| 3525 | // We need to fit it to the display if either |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3526 | // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen |
| 3527 | // for the taskless windows) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3528 | // 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] | 3529 | // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on |
| 3530 | // screen, but SurfaceViews want to be always at a specific location so we don't fit it to |
| 3531 | // the display. |
| 3532 | final boolean fitToDisplay = (task == null || !inNonFullscreenContainer) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3533 | || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3534 | float x, y; |
| 3535 | int w,h; |
| 3536 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3537 | final boolean inSizeCompatMode = inSizeCompatMode(); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3538 | if ((mAttrs.flags & FLAG_SCALED) != 0) { |
| 3539 | if (mAttrs.width < 0) { |
| 3540 | w = pw; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3541 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3542 | w = (int)(mAttrs.width * mGlobalScale + .5f); |
| 3543 | } else { |
| 3544 | w = mAttrs.width; |
| 3545 | } |
| 3546 | if (mAttrs.height < 0) { |
| 3547 | h = ph; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3548 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3549 | h = (int)(mAttrs.height * mGlobalScale + .5f); |
| 3550 | } else { |
| 3551 | h = mAttrs.height; |
| 3552 | } |
| 3553 | } else { |
| 3554 | if (mAttrs.width == MATCH_PARENT) { |
| 3555 | w = pw; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3556 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3557 | w = (int)(mRequestedWidth * mGlobalScale + .5f); |
| 3558 | } else { |
| 3559 | w = mRequestedWidth; |
| 3560 | } |
| 3561 | if (mAttrs.height == MATCH_PARENT) { |
| 3562 | h = ph; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3563 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3564 | h = (int)(mRequestedHeight * mGlobalScale + .5f); |
| 3565 | } else { |
| 3566 | h = mRequestedHeight; |
| 3567 | } |
| 3568 | } |
| 3569 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3570 | if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3571 | x = mAttrs.x * mGlobalScale; |
| 3572 | y = mAttrs.y * mGlobalScale; |
| 3573 | } else { |
| 3574 | x = mAttrs.x; |
| 3575 | y = mAttrs.y; |
| 3576 | } |
| 3577 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3578 | if (inNonFullscreenContainer && !layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 3579 | // 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] | 3580 | // required by {@link Gravity#apply} call. |
| 3581 | w = Math.min(w, pw); |
| 3582 | h = Math.min(h, ph); |
| 3583 | } |
| 3584 | |
| 3585 | // Set mFrame |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3586 | Gravity.apply(mAttrs.gravity, w, h, containingFrame, |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3587 | (int) (x + mAttrs.horizontalMargin * pw), |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3588 | (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3589 | |
| 3590 | // Now make sure the window fits in the overall display frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3591 | if (fitToDisplay) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3592 | Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3593 | } |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3594 | |
| 3595 | // We need to make sure we update the CompatFrame as it is used for |
| 3596 | // cropping decisions, etc, on systems where we lack a decor layer. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3597 | mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3598 | if (inSizeCompatMode) { |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3599 | // See comparable block in computeFrameLw. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3600 | mWindowFrames.mCompatFrame.scale(mInvGlobalScale); |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3601 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3602 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 3603 | |
| 3604 | boolean isChildWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3605 | return mIsChildWindow; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3608 | boolean layoutInParentFrame() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3609 | return mIsChildWindow |
| 3610 | && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0; |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 3613 | /** |
| 3614 | * Returns true if any window added by an application process that if of type |
| 3615 | * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires |
| 3616 | * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when |
| 3617 | * this window is visible. |
| 3618 | */ |
| 3619 | boolean hideNonSystemOverlayWindowsWhenVisible() { |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 3620 | return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0 |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 3621 | && mSession.mCanHideNonSystemOverlayWindows; |
| 3622 | } |
| 3623 | |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3624 | /** Returns the parent window if this is a child of another window, else null. */ |
| 3625 | WindowState getParentWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3626 | // NOTE: We are not calling getParent() directly as the WindowState might be a child of a |
| 3627 | // WindowContainer that isn't a WindowState. |
| 3628 | return (mIsChildWindow) ? ((WindowState) super.getParent()) : null; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | /** Returns the topmost parent window if this is a child of another window, else this. */ |
| 3632 | WindowState getTopParentWindow() { |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3633 | WindowState current = this; |
| 3634 | WindowState topParent = current; |
| 3635 | while (current != null && current.mIsChildWindow) { |
| 3636 | current = current.getParentWindow(); |
| 3637 | // Parent window can be null if the child is detached from it's parent already, but |
| 3638 | // someone still has a reference to access it. So, we return the top parent value we |
| 3639 | // already have instead of null. |
| 3640 | if (current != null) { |
| 3641 | topParent = current; |
| 3642 | } |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3643 | } |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3644 | return topParent; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3647 | boolean isParentWindowHidden() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3648 | final WindowState parent = getParentWindow(); |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3649 | return parent != null && parent.mHidden; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3650 | } |
| 3651 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3652 | void setWillReplaceWindow(boolean animate) { |
| 3653 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3654 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3655 | c.setWillReplaceWindow(animate); |
| 3656 | } |
| 3657 | |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3658 | if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0 |
| 3659 | || mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 3660 | // We don't set replacing on starting windows since they are added by window manager and |
| 3661 | // not the client so won't be replaced by the client. |
| 3662 | return; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3663 | } |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3664 | |
| 3665 | mWillReplaceWindow = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3666 | mReplacementWindow = null; |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3667 | mAnimateReplacingWindow = animate; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3668 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3669 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3670 | void clearWillReplaceWindow() { |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3671 | mWillReplaceWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3672 | mReplacementWindow = null; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3673 | mAnimateReplacingWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3674 | |
| 3675 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3676 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3677 | c.clearWillReplaceWindow(); |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | boolean waitingForReplacement() { |
| 3682 | if (mWillReplaceWindow) { |
| 3683 | return true; |
| 3684 | } |
| 3685 | |
| 3686 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3687 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3688 | if (c.waitingForReplacement()) { |
| 3689 | return true; |
| 3690 | } |
| 3691 | } |
| 3692 | return false; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3693 | } |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3694 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3695 | void requestUpdateWallpaperIfNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3696 | final DisplayContent dc = getDisplayContent(); |
| 3697 | if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 3698 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 3699 | dc.setLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3700 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3701 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3702 | |
| 3703 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3704 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3705 | c.requestUpdateWallpaperIfNeeded(); |
| 3706 | } |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3709 | float translateToWindowX(float x) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3710 | float winX = x - mWindowFrames.mFrame.left; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3711 | if (inSizeCompatMode()) { |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3712 | winX *= mGlobalScale; |
| 3713 | } |
| 3714 | return winX; |
| 3715 | } |
| 3716 | |
| 3717 | float translateToWindowY(float y) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3718 | float winY = y - mWindowFrames.mFrame.top; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3719 | if (inSizeCompatMode()) { |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3720 | winY *= mGlobalScale; |
| 3721 | } |
| 3722 | return winY; |
| 3723 | } |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3724 | |
| 3725 | // During activity relaunch due to resize, we sometimes use window replacement |
| 3726 | // for only child windows (as the main window is handled by window preservation) |
| 3727 | // and the big surface. |
| 3728 | // |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 3729 | // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to |
| 3730 | // TYPE_BASE_APPLICATION) are not children in the sense of an attached window, |
| 3731 | // we also want to replace them at such phases, as they won't be covered by window |
| 3732 | // preservation, and in general we expect them to return following relaunch. |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3733 | boolean shouldBeReplacedWithChildren() { |
Chong Zhang | 921f8e3 | 2016-08-17 14:26:57 -0700 | [diff] [blame] | 3734 | return mIsChildWindow || mAttrs.type == TYPE_APPLICATION |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 3735 | || mAttrs.type == TYPE_DRAWN_APPLICATION; |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3736 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3737 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3738 | void setWillReplaceChildWindows() { |
| 3739 | if (shouldBeReplacedWithChildren()) { |
| 3740 | setWillReplaceWindow(false /* animate */); |
| 3741 | } |
| 3742 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3743 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3744 | c.setWillReplaceChildWindows(); |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | WindowState getReplacingWindow() { |
| 3749 | if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) { |
| 3750 | return this; |
| 3751 | } |
| 3752 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3753 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3754 | final WindowState replacing = c.getReplacingWindow(); |
| 3755 | if (replacing != null) { |
| 3756 | return replacing; |
| 3757 | } |
| 3758 | } |
| 3759 | return null; |
| 3760 | } |
| 3761 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3762 | @Override |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3763 | public int getRotationAnimationHint() { |
| 3764 | if (mAppToken != null) { |
| 3765 | return mAppToken.mRotationAnimationHint; |
| 3766 | } else { |
| 3767 | return -1; |
| 3768 | } |
| 3769 | } |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3770 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3771 | @Override |
| 3772 | public boolean isInputMethodWindow() { |
| 3773 | return mIsImWindow; |
| 3774 | } |
| 3775 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3776 | // This must be called while inside a transaction. |
| 3777 | boolean performShowLocked() { |
| 3778 | if (isHiddenFromUserLocked()) { |
| 3779 | if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid); |
| 3780 | hideLw(false); |
| 3781 | return false; |
| 3782 | } |
| 3783 | |
| 3784 | logPerformShow("performShow on "); |
| 3785 | |
Jorim Jaggi | a50da60 | 2016-12-29 11:51:42 +0100 | [diff] [blame] | 3786 | final int drawState = mWinAnimator.mDrawState; |
| 3787 | if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW) |
| 3788 | && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) { |
| 3789 | mAppToken.onFirstWindowDrawn(this, mWinAnimator); |
| 3790 | } |
| 3791 | |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 3792 | if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3793 | return false; |
| 3794 | } |
| 3795 | |
| 3796 | logPerformShow("Showing "); |
| 3797 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3798 | mWmService.enableScreenIfNeededLocked(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3799 | mWinAnimator.applyEnterAnimationLocked(); |
| 3800 | |
| 3801 | // Force the show in the next prepareSurfaceLocked() call. |
| 3802 | mWinAnimator.mLastAlpha = -1; |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 3803 | if (DEBUG_ANIM) Slog.v(TAG, |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3804 | "performShowLocked: mDrawState=HAS_DRAWN in " + this); |
| 3805 | mWinAnimator.mDrawState = HAS_DRAWN; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3806 | mWmService.scheduleAnimationLocked(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3807 | |
| 3808 | if (mHidden) { |
| 3809 | mHidden = false; |
| 3810 | final DisplayContent displayContent = getDisplayContent(); |
| 3811 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3812 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3813 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3814 | if (c.mWinAnimator.mSurfaceController != null) { |
| 3815 | c.performShowLocked(); |
| 3816 | // It hadn't been shown, which means layout not performed on it, so now we |
| 3817 | // want to make sure to do a layout. If called from within the transaction |
| 3818 | // loop, this will cause it to restart with a new layout. |
| 3819 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3820 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3821 | } |
| 3822 | } |
| 3823 | } |
| 3824 | } |
| 3825 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3826 | if (mAttrs.type == TYPE_INPUT_METHOD) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3827 | getDisplayContent().mDividerControllerLocked.resetImeHideRequested(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | return true; |
| 3831 | } |
| 3832 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3833 | private void logPerformShow(String prefix) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3834 | if (DEBUG_VISIBILITY |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 3835 | || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3836 | Slog.v(TAG, prefix + this |
| 3837 | + ": mDrawState=" + mWinAnimator.drawStateToString() |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 3838 | + " readyForDisplay=" + isReadyForDisplay() |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3839 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING) |
| 3840 | + " during animation: policyVis=" + mPolicyVisibility |
| 3841 | + " parentHidden=" + isParentWindowHidden() |
| 3842 | + " tok.hiddenRequested=" |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3843 | + (mAppToken != null && mAppToken.hiddenRequested) |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3844 | + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden()) |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 3845 | + " animating=" + isAnimating() |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3846 | + " tok animating=" |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 3847 | + (mAppToken != null && mAppToken.isSelfAnimating()) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3848 | + " Callers=" + Debug.getCallers(4)); |
| 3849 | } |
| 3850 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3851 | |
| 3852 | WindowInfo getWindowInfo() { |
| 3853 | WindowInfo windowInfo = WindowInfo.obtain(); |
| 3854 | windowInfo.type = mAttrs.type; |
| 3855 | windowInfo.layer = mLayer; |
| 3856 | windowInfo.token = mClient.asBinder(); |
Phil Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 3857 | if (mAppToken != null) { |
| 3858 | windowInfo.activityToken = mAppToken.appToken.asBinder(); |
| 3859 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3860 | windowInfo.title = mAttrs.accessibilityTitle; |
Phil Weaver | bb2f28a | 2017-12-22 09:44:28 -0800 | [diff] [blame] | 3861 | // Panel windows have no public way to set the a11y title directly. Use the |
| 3862 | // regular title as a fallback. |
Phil Weaver | 568cf66 | 2018-04-24 17:09:26 -0700 | [diff] [blame] | 3863 | final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW) |
| 3864 | && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW); |
| 3865 | // Accessibility overlays should have titles that work for accessibility, and can't set |
| 3866 | // the a11y title themselves. |
| 3867 | final boolean isAccessibilityOverlay = |
| 3868 | windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; |
| 3869 | if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) { |
Jackal Guo | 25a33cbd | 2018-08-01 16:08:45 +0800 | [diff] [blame] | 3870 | final CharSequence title = mAttrs.getTitle(); |
| 3871 | windowInfo.title = TextUtils.isEmpty(title) ? null : title; |
Phil Weaver | bb2f28a | 2017-12-22 09:44:28 -0800 | [diff] [blame] | 3872 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3873 | windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor; |
| 3874 | windowInfo.focused = isFocused(); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 3875 | Task task = getTask(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3876 | windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode(); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 3877 | windowInfo.hasFlagWatchOutsideTouch = |
| 3878 | (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3879 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3880 | if (mIsChildWindow) { |
| 3881 | windowInfo.parentToken = getParentWindow().mClient.asBinder(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3884 | final int childCount = mChildren.size(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3885 | if (childCount > 0) { |
| 3886 | if (windowInfo.childTokens == null) { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3887 | windowInfo.childTokens = new ArrayList(childCount); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3888 | } |
| 3889 | for (int j = 0; j < childCount; j++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3890 | final WindowState child = mChildren.get(j); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3891 | windowInfo.childTokens.add(child.mClient.asBinder()); |
| 3892 | } |
| 3893 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3894 | return windowInfo; |
| 3895 | } |
| 3896 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3897 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3898 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3899 | if (mChildren.isEmpty()) { |
| 3900 | // The window has no children so we just return it. |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 3901 | return applyInOrderWithImeWindows(callback, traverseTopToBottom); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3905 | return forAllWindowTopToBottom(callback); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3906 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3907 | return forAllWindowBottomToTop(callback); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3908 | } |
| 3909 | } |
| 3910 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3911 | private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3912 | // 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] | 3913 | // below the parent, then this window (the parent), and then the positive sublayer children |
| 3914 | // because they need to appear above the parent. |
| 3915 | int i = 0; |
| 3916 | final int count = mChildren.size(); |
| 3917 | WindowState child = mChildren.get(i); |
| 3918 | |
| 3919 | while (i < count && child.mSubLayer < 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3920 | if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3921 | return true; |
| 3922 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3923 | i++; |
| 3924 | if (i >= count) { |
| 3925 | break; |
| 3926 | } |
| 3927 | child = mChildren.get(i); |
| 3928 | } |
| 3929 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 3930 | if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3931 | return true; |
| 3932 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3933 | |
| 3934 | while (i < count) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3935 | if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3936 | return true; |
| 3937 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3938 | i++; |
| 3939 | if (i >= count) { |
| 3940 | break; |
| 3941 | } |
| 3942 | child = mChildren.get(i); |
| 3943 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3944 | |
| 3945 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3946 | } |
| 3947 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3948 | private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3949 | // 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] | 3950 | // above the parent, then this window (the parent), and then the negative sublayer children |
| 3951 | // because they need to appear above the parent. |
| 3952 | int i = mChildren.size() - 1; |
| 3953 | WindowState child = mChildren.get(i); |
| 3954 | |
| 3955 | while (i >= 0 && child.mSubLayer >= 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3956 | if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3957 | return true; |
| 3958 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3959 | --i; |
| 3960 | if (i < 0) { |
| 3961 | break; |
| 3962 | } |
| 3963 | child = mChildren.get(i); |
| 3964 | } |
| 3965 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 3966 | if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3967 | return true; |
| 3968 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3969 | |
| 3970 | while (i >= 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 3971 | if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3972 | return true; |
| 3973 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3974 | --i; |
| 3975 | if (i < 0) { |
| 3976 | break; |
| 3977 | } |
| 3978 | child = mChildren.get(i); |
| 3979 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 3980 | |
| 3981 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 3984 | private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback, |
| 3985 | boolean traverseTopToBottom) { |
| 3986 | // If this window is the current IME target, so we need to process the IME windows |
| 3987 | // directly above it. The exception is if we are in split screen |
| 3988 | // in which case we process the IME at the DisplayContent level to |
| 3989 | // ensure it is above the docked divider. |
| 3990 | if (isInputMethodTarget() && !inSplitScreenWindowingMode()) { |
| 3991 | if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) { |
| 3992 | return true; |
| 3993 | } |
| 3994 | } |
| 3995 | return false; |
| 3996 | } |
| 3997 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 3998 | private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback, |
| 3999 | boolean traverseTopToBottom) { |
| 4000 | if (traverseTopToBottom) { |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 4001 | if (applyImeWindowsIfNeeded(callback, traverseTopToBottom) |
| 4002 | || callback.apply(this)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4003 | return true; |
| 4004 | } |
| 4005 | } else { |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 4006 | if (callback.apply(this) |
| 4007 | || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4008 | return true; |
| 4009 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4010 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4011 | return false; |
| 4012 | } |
| 4013 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4014 | WindowState getWindow(Predicate<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4015 | if (mChildren.isEmpty()) { |
| 4016 | return callback.test(this) ? this : null; |
| 4017 | } |
| 4018 | |
| 4019 | // We want to consume the positive sublayer children first because they need to appear |
| 4020 | // above the parent, then this window (the parent), and then the negative sublayer children |
| 4021 | // because they need to appear above the parent. |
| 4022 | int i = mChildren.size() - 1; |
| 4023 | WindowState child = mChildren.get(i); |
| 4024 | |
| 4025 | while (i >= 0 && child.mSubLayer >= 0) { |
| 4026 | if (callback.test(child)) { |
| 4027 | return child; |
| 4028 | } |
| 4029 | --i; |
| 4030 | if (i < 0) { |
| 4031 | break; |
| 4032 | } |
| 4033 | child = mChildren.get(i); |
| 4034 | } |
| 4035 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4036 | if (callback.test(this)) { |
| 4037 | return this; |
| 4038 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4039 | |
| 4040 | while (i >= 0) { |
| 4041 | if (callback.test(child)) { |
| 4042 | return child; |
| 4043 | } |
| 4044 | --i; |
| 4045 | if (i < 0) { |
| 4046 | break; |
| 4047 | } |
| 4048 | child = mChildren.get(i); |
| 4049 | } |
| 4050 | |
| 4051 | return null; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4052 | } |
| 4053 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 4054 | /** |
| 4055 | * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false |
| 4056 | * otherwise. |
| 4057 | */ |
| 4058 | @VisibleForTesting |
| 4059 | boolean isSelfOrAncestorWindowAnimatingExit() { |
| 4060 | WindowState window = this; |
| 4061 | do { |
| 4062 | if (window.mAnimatingExit) { |
| 4063 | return true; |
| 4064 | } |
| 4065 | window = window.getParentWindow(); |
| 4066 | } while (window != null); |
| 4067 | return false; |
| 4068 | } |
| 4069 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4070 | void onExitAnimationDone() { |
| 4071 | if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this |
| 4072 | + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4073 | + " selfAnimating=" + isSelfAnimating()); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4074 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4075 | if (!mChildren.isEmpty()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4076 | // Copying to a different list as multiple children can be removed. |
Jorim Jaggi | 59f3e92 | 2018-01-05 15:40:32 +0100 | [diff] [blame] | 4077 | final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4078 | for (int i = childWindows.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4079 | childWindows.get(i).onExitAnimationDone(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | if (mWinAnimator.mEnteringAnimation) { |
| 4084 | mWinAnimator.mEnteringAnimation = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4085 | mWmService.requestTraversal(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4086 | // System windows don't have an activity and an app token as a result, but need a way |
| 4087 | // to be informed about their entrance animation end. |
| 4088 | if (mAppToken == null) { |
| 4089 | try { |
| 4090 | mClient.dispatchWindowShown(); |
| 4091 | } catch (RemoteException e) { |
| 4092 | } |
| 4093 | } |
| 4094 | } |
| 4095 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4096 | if (isSelfAnimating()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4097 | return; |
| 4098 | } |
| 4099 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4100 | //TODO (multidisplay): Accessibility is supported only for the default display. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4101 | if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) { |
| 4102 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4103 | } |
| 4104 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 4105 | if (!isSelfOrAncestorWindowAnimatingExit()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4106 | return; |
| 4107 | } |
| 4108 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 4109 | if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4110 | "Exit animation finished in " + this + ": remove=" + mRemoveOnExit); |
| 4111 | |
| 4112 | mDestroying = true; |
| 4113 | |
| 4114 | final boolean hasSurface = mWinAnimator.hasSurface(); |
Jorim Jaggi | 5057590 | 2018-04-10 17:49:30 +0200 | [diff] [blame] | 4115 | |
| 4116 | // Use pendingTransaction here so hide is done the same transaction as the other |
| 4117 | // animations when exiting |
| 4118 | mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4119 | |
| 4120 | // If we have an app token, we ask it to destroy the surface for us, so that it can take |
| 4121 | // care to ensure the activity has actually stopped and the surface is not still in use. |
| 4122 | // Otherwise we add the service to mDestroySurface and allow it to be processed in our next |
| 4123 | // transaction. |
| 4124 | if (mAppToken != null) { |
| 4125 | mAppToken.destroySurfaces(); |
| 4126 | } else { |
| 4127 | if (hasSurface) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4128 | mWmService.mDestroySurface.add(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4129 | } |
| 4130 | if (mRemoveOnExit) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4131 | mWmService.mPendingRemove.add(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4132 | mRemoveOnExit = false; |
| 4133 | } |
| 4134 | } |
| 4135 | mAnimatingExit = false; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 4136 | getDisplayContent().mWallpaperController.hideWallpapers(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4137 | } |
Dan Willemsen | 117197f | 2016-07-30 13:02:59 -0700 | [diff] [blame] | 4138 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4139 | boolean clearAnimatingFlags() { |
| 4140 | boolean didSomething = false; |
| 4141 | // We don't want to clear it out for windows that get replaced, because the |
| 4142 | // animation depends on the flag to remove the replaced window. |
| 4143 | // |
| 4144 | // We also don't clear the mAnimatingExit flag for windows which have the |
| 4145 | // mRemoveOnExit flag. This indicates an explicit remove request has been issued |
| 4146 | // by the client. We should let animation proceed and not clear this flag or |
| 4147 | // they won't eventually be removed by WindowStateAnimator#finishExit. |
| 4148 | if (!mWillReplaceWindow && !mRemoveOnExit) { |
| 4149 | // Clear mAnimating flag together with mAnimatingExit. When animation |
| 4150 | // changes from exiting to entering, we need to clear this flag until the |
| 4151 | // new animation gets applied, so that isAnimationStarting() becomes true |
| 4152 | // until then. |
| 4153 | // Otherwise applySurfaceChangesTransaction will fail to skip surface |
| 4154 | // placement for this window during this period, one or more frame will |
| 4155 | // show up with wrong position or scale. |
| 4156 | if (mAnimatingExit) { |
| 4157 | mAnimatingExit = false; |
| 4158 | didSomething = true; |
| 4159 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4160 | if (mDestroying) { |
| 4161 | mDestroying = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4162 | mWmService.mDestroySurface.remove(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4163 | didSomething = true; |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4168 | didSomething |= (mChildren.get(i)).clearAnimatingFlags(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | return didSomething; |
| 4172 | } |
| 4173 | |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4174 | public boolean isRtl() { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 4175 | return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4176 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4177 | |
| 4178 | void hideWallpaperWindow(boolean wasDeferred, String reason) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4179 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4180 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4181 | c.hideWallpaperWindow(wasDeferred, reason); |
| 4182 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4183 | if (!mWinAnimator.mLastHidden || wasDeferred) { |
| 4184 | mWinAnimator.hide(reason); |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 4185 | getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4186 | dispatchWallpaperVisibility(false); |
| 4187 | final DisplayContent displayContent = getDisplayContent(); |
| 4188 | if (displayContent != null) { |
| 4189 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 4190 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4191 | mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this, |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 4192 | displayContent.pendingLayoutChanges); |
| 4193 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4194 | } |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | /** |
| 4199 | * Check wallpaper window for visibility change and notify window if so. |
| 4200 | * @param visible Current visibility. |
| 4201 | */ |
| 4202 | void dispatchWallpaperVisibility(final boolean visible) { |
| 4203 | final boolean hideAllowed = |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 4204 | getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4205 | |
| 4206 | // Only send notification if the visibility actually changed and we are not trying to hide |
| 4207 | // the wallpaper when we are deferring hiding of the wallpaper. |
| 4208 | if (mWallpaperVisible != visible && (hideAllowed || visible)) { |
| 4209 | mWallpaperVisible = visible; |
| 4210 | try { |
| 4211 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 4212 | "Updating vis of wallpaper " + this |
| 4213 | + ": " + visible + " from:\n" + Debug.getCallers(4, " ")); |
| 4214 | mClient.dispatchAppVisibility(visible); |
| 4215 | } catch (RemoteException e) { |
| 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4220 | boolean hasVisibleNotDrawnWallpaper() { |
| 4221 | if (mWallpaperVisible && !isDrawnLw()) { |
| 4222 | return true; |
| 4223 | } |
| 4224 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4225 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4226 | if (c.hasVisibleNotDrawnWallpaper()) { |
| 4227 | return true; |
| 4228 | } |
| 4229 | } |
| 4230 | return false; |
| 4231 | } |
| 4232 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4233 | void updateReportedVisibility(UpdateReportedVisibilityResults results) { |
| 4234 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4235 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4236 | c.updateReportedVisibility(results); |
| 4237 | } |
| 4238 | |
| 4239 | if (mAppFreezing || mViewVisibility != View.VISIBLE |
| 4240 | || mAttrs.type == TYPE_APPLICATION_STARTING |
| 4241 | || mDestroying) { |
| 4242 | return; |
| 4243 | } |
| 4244 | if (DEBUG_VISIBILITY) { |
| 4245 | Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw() |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 4246 | + ", animating=" + isAnimating()); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4247 | if (!isDrawnLw()) { |
| 4248 | Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController |
| 4249 | + " pv=" + mPolicyVisibility |
| 4250 | + " mDrawState=" + mWinAnimator.mDrawState |
| 4251 | + " ph=" + isParentWindowHidden() |
| 4252 | + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 4253 | + " a=" + isAnimating()); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4254 | } |
| 4255 | } |
| 4256 | |
| 4257 | results.numInteresting++; |
| 4258 | if (isDrawnLw()) { |
| 4259 | results.numDrawn++; |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 4260 | if (!isAnimating()) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4261 | results.numVisible++; |
| 4262 | } |
| 4263 | results.nowGone = false; |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 4264 | } else if (isAnimating()) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4265 | results.nowGone = false; |
| 4266 | } |
| 4267 | } |
| 4268 | |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 4269 | private boolean skipDecorCrop() { |
| 4270 | // The decor frame is used to specify the region not covered by the system |
| 4271 | // decorations (nav bar, status bar). In case this is empty, for example with |
| 4272 | // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping. |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 4273 | if (mWindowFrames.mDecorFrame.isEmpty()) { |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 4274 | return true; |
| 4275 | } |
| 4276 | |
| 4277 | // But if we have a frame, and are an application window, then we must be cropped. |
| 4278 | if (mAppToken != null) { |
| 4279 | return false; |
| 4280 | } |
| 4281 | |
| 4282 | // For non application windows, we may be allowed to extend over the decor bars |
| 4283 | // depending on our type and permissions assosciated with our token. |
| 4284 | return mToken.canLayerAboveSystemBars(); |
| 4285 | } |
| 4286 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4287 | /** |
| 4288 | * Calculate the window crop according to system decor policy. In general this is |
| 4289 | * the system decor rect (see #calculateSystemDecorRect), but we also have some |
| 4290 | * special cases. This rectangle is in screen space. |
| 4291 | */ |
| 4292 | void calculatePolicyCrop(Rect policyCrop) { |
| 4293 | final DisplayContent displayContent = getDisplayContent(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4294 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4295 | if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4296 | // On a different display there is no system decor. Crop the window |
| 4297 | // by the screen boundaries. |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4298 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 4299 | policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(), |
| 4300 | mWindowFrames.mCompatFrame.height()); |
| 4301 | policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top, |
| 4302 | displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left, |
| 4303 | displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top); |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 4304 | } else if (skipDecorCrop()) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4305 | // Windows without policy decor aren't cropped. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 4306 | policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(), |
| 4307 | mWindowFrames.mCompatFrame.height()); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4308 | } else { |
| 4309 | // Crop to the system decor specified by policy. |
| 4310 | calculateSystemDecorRect(policyCrop); |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | /** |
| 4315 | * The system decor rect is the region of the window which is not covered |
| 4316 | * by system decorations. |
| 4317 | */ |
| 4318 | private void calculateSystemDecorRect(Rect systemDecorRect) { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 4319 | final Rect decorRect = mWindowFrames.mDecorFrame; |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4320 | final int width = mWindowFrames.mFrame.width(); |
| 4321 | final int height = mWindowFrames.mFrame.height(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4322 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4323 | final int left = mWindowFrames.mFrame.left; |
| 4324 | final int top = mWindowFrames.mFrame.top; |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4325 | |
| 4326 | // Initialize the decor rect to the entire frame. |
| 4327 | if (isDockedResizing()) { |
| 4328 | // If we are resizing with the divider, the task bounds might be smaller than the |
| 4329 | // stack bounds. The system decor is used to clip to the task bounds, which we don't |
| 4330 | // want in this case in order to avoid holes. |
| 4331 | // |
| 4332 | // We take care to not shrink the width, for surfaces which are larger than |
| 4333 | // the display region. Of course this area will not eventually be visible |
| 4334 | // but if we truncate the width now, we will calculate incorrectly |
| 4335 | // when adjusting to the stack bounds. |
| 4336 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
| 4337 | systemDecorRect.set(0, 0, |
| 4338 | Math.max(width, displayInfo.logicalWidth), |
| 4339 | Math.max(height, displayInfo.logicalHeight)); |
| 4340 | } else { |
| 4341 | systemDecorRect.set(0, 0, width, height); |
| 4342 | } |
| 4343 | |
| 4344 | // If a freeform window is animating from a position where it would be cutoff, it would be |
| 4345 | // cutoff during the animation. We don't want that, so for the duration of the animation |
| 4346 | // we ignore the decor cropping and depend on layering to position windows correctly. |
chaviw | 9513662 | 2018-04-09 15:20:06 -0700 | [diff] [blame] | 4347 | |
| 4348 | // We also ignore cropping when the window is currently being drag resized in split screen |
| 4349 | // to prevent issues with the crop for screenshot. |
| 4350 | final boolean cropToDecor = |
| 4351 | !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4352 | if (cropToDecor) { |
| 4353 | // Intersect with the decor rect, offsetted by window position. |
| 4354 | systemDecorRect.intersect(decorRect.left - left, decorRect.top - top, |
| 4355 | decorRect.right - left, decorRect.bottom - top); |
| 4356 | } |
| 4357 | |
| 4358 | // If size compatibility is being applied to the window, the |
| 4359 | // surface is scaled relative to the screen. Also apply this |
| 4360 | // scaling to the crop rect. We aren't using the standard rect |
| 4361 | // scale function because we want to round things to make the crop |
| 4362 | // always round to a larger rect to ensure we don't crop too |
| 4363 | // much and hide part of the window that should be seen. |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4364 | if (inSizeCompatMode() && mInvGlobalScale != 1.0f) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4365 | final float scale = mInvGlobalScale; |
| 4366 | systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f); |
| 4367 | systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f); |
| 4368 | systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f); |
| 4369 | systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f); |
| 4370 | } |
| 4371 | |
| 4372 | } |
| 4373 | |
| 4374 | /** |
| 4375 | * Expand the given rectangle by this windows surface insets. This |
| 4376 | * takes you from the 'window size' to the 'surface size'. |
| 4377 | * The surface insets are positive in each direction, so we inset by |
| 4378 | * the inverse. |
| 4379 | */ |
| 4380 | void expandForSurfaceInsets(Rect r) { |
| 4381 | r.inset(-mAttrs.surfaceInsets.left, |
| 4382 | -mAttrs.surfaceInsets.top, |
| 4383 | -mAttrs.surfaceInsets.right, |
| 4384 | -mAttrs.surfaceInsets.bottom); |
| 4385 | } |
| 4386 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4387 | boolean surfaceInsetsChanging() { |
| 4388 | return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets); |
| 4389 | } |
| 4390 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 4391 | int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) { |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 4392 | final boolean wasVisible = isVisibleLw(); |
| 4393 | |
| 4394 | result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0; |
Robert Carr | 7b3d11d | 2018-03-15 14:34:45 -0700 | [diff] [blame] | 4395 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4396 | if (mAnimatingExit) { |
| 4397 | Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit=" |
| 4398 | + mRemoveOnExit + ", mDestroying=" + mDestroying); |
| 4399 | |
Riddle Hsu | b8d704b | 2019-02-22 12:44:12 +0800 | [diff] [blame] | 4400 | // Cancel the existing exit animation for the next enter animation. |
| 4401 | if (isSelfAnimating()) { |
| 4402 | cancelAnimation(); |
| 4403 | destroySurfaceUnchecked(); |
| 4404 | } |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4405 | mAnimatingExit = false; |
| 4406 | } |
| 4407 | if (mDestroying) { |
| 4408 | mDestroying = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4409 | mWmService.mDestroySurface.remove(this); |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4410 | } |
| 4411 | if (oldVisibility == View.GONE) { |
| 4412 | mWinAnimator.mEnterAnimationPending = true; |
| 4413 | } |
| 4414 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4415 | mLastVisibleLayoutRotation = getDisplayContent().getRotation(); |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4416 | |
| 4417 | mWinAnimator.mEnteringAnimation = true; |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 4418 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 4419 | prepareWindowToDisplayDuringRelayout(wasVisible); |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 4420 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4421 | if ((attrChanges & FORMAT_CHANGED) != 0) { |
| 4422 | // If the format can't be changed in place, preserve the old surface until the app draws |
| 4423 | // on the new one. This prevents blinking when we change elevation of freeform and |
| 4424 | // pinned windows. |
| 4425 | if (!mWinAnimator.tryChangeFormatInPlaceLocked()) { |
| 4426 | mWinAnimator.preserveSurfaceLocked(); |
| 4427 | result |= RELAYOUT_RES_SURFACE_CHANGED |
| 4428 | | RELAYOUT_RES_FIRST_TIME; |
| 4429 | } |
| 4430 | } |
| 4431 | |
| 4432 | // When we change the Surface size, in scenarios which may require changing |
| 4433 | // the surface position in sync with the resize, we use a preserved surface |
| 4434 | // so we can freeze it while waiting for the client to report draw on the newly |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 4435 | // sized surface. At the moment this logic is only in place for switching |
| 4436 | // in and out of the big surface for split screen resize. |
| 4437 | if (isDragResizeChanged()) { |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4438 | setDragResizing(); |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4439 | // We can only change top level windows to the full-screen surface when |
| 4440 | // resizing (as we only have one full-screen surface). So there is no need |
| 4441 | // to preserve and destroy windows which are attached to another, they |
| 4442 | // will keep their surface and its size may change over time. |
| 4443 | if (mHasSurface && !isChildWindow()) { |
| 4444 | mWinAnimator.preserveSurfaceLocked(); |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 4445 | result |= RELAYOUT_RES_SURFACE_CHANGED | |
| 4446 | RELAYOUT_RES_FIRST_TIME; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4447 | } |
| 4448 | } |
| 4449 | final boolean freeformResizing = isDragResizing() |
| 4450 | && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM; |
| 4451 | final boolean dockedResizing = isDragResizing() |
| 4452 | && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 4453 | result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0; |
| 4454 | result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4455 | return result; |
| 4456 | } |
| 4457 | |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 4458 | /** |
| 4459 | * @return True if this window has been laid out at least once; false otherwise. |
| 4460 | */ |
| 4461 | boolean isLaidOut() { |
| 4462 | return mLayoutSeq != -1; |
| 4463 | } |
| 4464 | |
| 4465 | /** |
| 4466 | * Updates the last inset values to the current ones. |
| 4467 | */ |
| 4468 | void updateLastInsetValues() { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 4469 | mWindowFrames.updateLastInsetValues(); |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 4470 | } |
| 4471 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4472 | void startAnimation(Animation anim) { |
Jorim Jaggi | a2759b2 | 2019-01-24 13:21:40 +0100 | [diff] [blame] | 4473 | |
| 4474 | // If we are an inset provider, all our animations are driven by the inset client. |
| 4475 | if (mInsetProvider != null && mInsetProvider.isControllable()) { |
| 4476 | return; |
| 4477 | } |
| 4478 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4479 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4480 | anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(), |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4481 | displayInfo.appWidth, displayInfo.appHeight); |
| 4482 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4483 | anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked()); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4484 | final AnimationAdapter adapter = new LocalAnimationAdapter( |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 4485 | new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */, |
| 4486 | mWmService.mWindowCornerRadius), |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4487 | mWmService.mSurfaceAnimationRunner); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4488 | startAnimation(mPendingTransaction, adapter); |
| 4489 | commitPendingTransaction(); |
| 4490 | } |
| 4491 | |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 4492 | private void startMoveAnimation(int left, int top) { |
Jorim Jaggi | a2759b2 | 2019-01-24 13:21:40 +0100 | [diff] [blame] | 4493 | |
| 4494 | // If we are an inset provider, all our animations are driven by the inset client. |
| 4495 | if (mInsetProvider != null && mInsetProvider.isControllable()) { |
| 4496 | return; |
| 4497 | } |
| 4498 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4499 | if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this); |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4500 | final Point oldPosition = new Point(); |
| 4501 | final Point newPosition = new Point(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4502 | transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top, |
| 4503 | oldPosition); |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4504 | transformFrameToSurfacePosition(left, top, newPosition); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4505 | final AnimationAdapter adapter = new LocalAnimationAdapter( |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4506 | new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y), |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4507 | mWmService.mSurfaceAnimationRunner); |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 4508 | startAnimation(getPendingTransaction(), adapter); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | private void startAnimation(Transaction t, AnimationAdapter adapter) { |
| 4512 | startAnimation(t, adapter, mWinAnimator.mLastHidden); |
| 4513 | } |
| 4514 | |
| 4515 | @Override |
| 4516 | protected void onAnimationFinished() { |
chaviw | ccd5d50 | 2019-02-22 13:30:31 -0800 | [diff] [blame] | 4517 | super.onAnimationFinished(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4518 | mWinAnimator.onAnimationFinished(); |
| 4519 | } |
| 4520 | |
Jorim Jaggi | eb0d3bc | 2017-12-15 14:56:19 +0100 | [diff] [blame] | 4521 | /** |
| 4522 | * Retrieves the current transformation matrix of the window, relative to the display. |
| 4523 | * |
| 4524 | * @param float9 A temporary array of 9 floats. |
| 4525 | * @param outMatrix Matrix to fill in the transformation. |
| 4526 | */ |
| 4527 | void getTransformationMatrix(float[] float9, Matrix outMatrix) { |
| 4528 | float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx; |
| 4529 | float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx; |
| 4530 | float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy; |
| 4531 | float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy; |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 4532 | int x = mSurfacePosition.x; |
| 4533 | int y = mSurfacePosition.y; |
Jorim Jaggi | 72d4dee | 2017-12-28 13:49:21 +0100 | [diff] [blame] | 4534 | |
| 4535 | // If changed, also adjust transformFrameToSurfacePosition |
| 4536 | final WindowContainer parent = getParent(); |
| 4537 | if (isChildWindow()) { |
| 4538 | final WindowState parentWindow = getParentWindow(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4539 | x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left; |
| 4540 | y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top; |
Jorim Jaggi | 72d4dee | 2017-12-28 13:49:21 +0100 | [diff] [blame] | 4541 | } else if (parent != null) { |
| 4542 | final Rect parentBounds = parent.getBounds(); |
| 4543 | x += parentBounds.left; |
| 4544 | y += parentBounds.top; |
| 4545 | } |
| 4546 | float9[Matrix.MTRANS_X] = x; |
| 4547 | float9[Matrix.MTRANS_Y] = y; |
Jorim Jaggi | eb0d3bc | 2017-12-15 14:56:19 +0100 | [diff] [blame] | 4548 | float9[Matrix.MPERSP_0] = 0; |
| 4549 | float9[Matrix.MPERSP_1] = 0; |
| 4550 | float9[Matrix.MPERSP_2] = 1; |
| 4551 | outMatrix.setValues(float9); |
| 4552 | } |
| 4553 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4554 | // TODO: Hack to work around the number of states AppWindowToken needs to access without having |
| 4555 | // access to its windows children. Need to investigate re-writing |
| 4556 | // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed. |
| 4557 | static final class UpdateReportedVisibilityResults { |
| 4558 | int numInteresting; |
| 4559 | int numVisible; |
| 4560 | int numDrawn; |
| 4561 | boolean nowGone = true; |
| 4562 | |
| 4563 | void reset() { |
| 4564 | numInteresting = 0; |
| 4565 | numVisible = 0; |
| 4566 | numDrawn = 0; |
| 4567 | nowGone = true; |
| 4568 | } |
| 4569 | } |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 4570 | |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 4571 | private static final class WindowId extends IWindowId.Stub { |
| 4572 | private final WeakReference<WindowState> mOuter; |
| 4573 | |
| 4574 | private WindowId(WindowState outer) { |
| 4575 | |
| 4576 | // Use a weak reference for the outer class. This is important to prevent the following |
| 4577 | // leak: Since we send this class to the client process, binder will keep it alive as |
| 4578 | // long as the client keeps it alive. Now, if the window is removed, we need to clear |
| 4579 | // out our reference so even though this class is kept alive we don't leak WindowState, |
| 4580 | // which can keep a whole lot of classes alive. |
| 4581 | mOuter = new WeakReference<>(outer); |
| 4582 | } |
| 4583 | |
| 4584 | @Override |
| 4585 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 4586 | final WindowState outer = mOuter.get(); |
| 4587 | if (outer != null) { |
| 4588 | outer.registerFocusObserver(observer); |
| 4589 | } |
| 4590 | } |
| 4591 | @Override |
| 4592 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 4593 | final WindowState outer = mOuter.get(); |
| 4594 | if (outer != null) { |
| 4595 | outer.unregisterFocusObserver(observer); |
| 4596 | } |
| 4597 | } |
| 4598 | @Override |
| 4599 | public boolean isFocused() { |
| 4600 | final WindowState outer = mOuter.get(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 4601 | if (outer != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4602 | synchronized (outer.mWmService.mGlobalLock) { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 4603 | return outer.isFocused(); |
| 4604 | } |
| 4605 | } |
| 4606 | return false; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 4607 | } |
| 4608 | } |
| 4609 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4610 | |
| 4611 | @Override |
| 4612 | boolean shouldMagnify() { |
| 4613 | if (mAttrs.type == TYPE_INPUT_METHOD || |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4614 | mAttrs.type == TYPE_INPUT_METHOD_DIALOG || |
| 4615 | mAttrs.type == TYPE_MAGNIFICATION_OVERLAY || |
| 4616 | mAttrs.type == TYPE_NAVIGATION_BAR || |
| 4617 | // It's tempting to wonder: Have we forgotten the rounded corners overlay? |
| 4618 | // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL |
Eugene Susla | 9552b26 | 2018-03-13 12:24:50 -0700 | [diff] [blame] | 4619 | mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4620 | return false; |
| 4621 | } |
| 4622 | return true; |
| 4623 | } |
| 4624 | |
| 4625 | @Override |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4626 | SurfaceSession getSession() { |
| 4627 | if (mSession.mSurfaceSession != null) { |
| 4628 | return mSession.mSurfaceSession; |
| 4629 | } else { |
| 4630 | return getParent().getSession(); |
| 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | @Override |
| 4635 | boolean needsZBoost() { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 4636 | final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget; |
| 4637 | if (mIsImWindow && inputMethodTarget != null) { |
| 4638 | final AppWindowToken appToken = inputMethodTarget.mAppToken; |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 4639 | if (appToken != null) { |
| 4640 | return appToken.needsZBoost(); |
| 4641 | } |
| 4642 | } |
| 4643 | return mWillReplaceWindow; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4644 | } |
| 4645 | |
Robert Carr | f07ef9e | 2017-11-21 12:12:49 -0800 | [diff] [blame] | 4646 | private void applyDims(Dimmer dimmer) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4647 | if (!mAnimatingExit && mAppDied) { |
| 4648 | mIsDimming = true; |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 4649 | dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW); |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 4650 | } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) { |
chaviw | 1407615 | 2018-02-02 14:51:20 -0800 | [diff] [blame] | 4651 | // Only show a dim behind when the following is satisfied: |
| 4652 | // 1. The window has the flag FLAG_DIM_BEHIND |
| 4653 | // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting. |
| 4654 | // 3. The WS is considered visible according to the isVisible() method |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 4655 | // 4. The WS is not hidden. |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4656 | mIsDimming = true; |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 4657 | dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4658 | } |
Robert Carr | f07ef9e | 2017-11-21 12:12:49 -0800 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | @Override |
| 4662 | void prepareSurfaces() { |
| 4663 | final Dimmer dimmer = getDimmer(); |
| 4664 | mIsDimming = false; |
| 4665 | if (dimmer != null) { |
| 4666 | applyDims(dimmer); |
| 4667 | } |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 4668 | updateSurfacePosition(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4669 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4670 | mWinAnimator.prepareSurfaceLocked(true); |
| 4671 | super.prepareSurfaces(); |
| 4672 | } |
| 4673 | |
| 4674 | @Override |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4675 | public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) { |
| 4676 | super.onAnimationLeashCreated(t, leash); |
| 4677 | |
| 4678 | // Leash is now responsible for position, so set our position to 0. |
| 4679 | t.setPosition(mSurfaceControl, 0, 0); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 4680 | mLastSurfacePosition.set(0, 0); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | @Override |
| 4684 | public void onAnimationLeashDestroyed(Transaction t) { |
| 4685 | super.onAnimationLeashDestroyed(t); |
| 4686 | updateSurfacePosition(t); |
| 4687 | } |
| 4688 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 4689 | @Override |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 4690 | void updateSurfacePosition() { |
| 4691 | updateSurfacePosition(getPendingTransaction()); |
| 4692 | } |
| 4693 | |
Vishnu Nair | d8c664b | 2018-09-24 12:52:35 -0700 | [diff] [blame] | 4694 | @VisibleForTesting |
| 4695 | void updateSurfacePosition(Transaction t) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4696 | if (mSurfaceControl == null) { |
| 4697 | return; |
| 4698 | } |
| 4699 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4700 | transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top, |
| 4701 | mSurfacePosition); |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 4702 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 4703 | // Freeze position while we're unrotated, so the surface remains at the position it was |
| 4704 | // prior to the rotation. |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 4705 | if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null |
| 4706 | && !mLastSurfacePosition.equals(mSurfacePosition)) { |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4707 | t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 4708 | mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y); |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 4709 | if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) { |
| 4710 | mLastSurfaceInsets.set(mAttrs.surfaceInsets); |
| 4711 | t.deferTransactionUntil(mSurfaceControl, |
| 4712 | mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(), |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 4713 | getFrameNumber()); |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 4714 | } |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4715 | } |
| 4716 | } |
| 4717 | |
| 4718 | private void transformFrameToSurfacePosition(int left, int top, Point outPoint) { |
| 4719 | outPoint.set(left, top); |
Jorim Jaggi | 72d4dee | 2017-12-28 13:49:21 +0100 | [diff] [blame] | 4720 | |
| 4721 | // If changed, also adjust getTransformationMatrix |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 4722 | final WindowContainer parentWindowContainer = getParent(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4723 | if (isChildWindow()) { |
| 4724 | // TODO: This probably falls apart at some point and we should |
| 4725 | // actually compute relative coordinates. |
Jorim Jaggi | 50d3f8f | 2017-12-27 17:41:25 +0100 | [diff] [blame] | 4726 | |
| 4727 | // Since the parent was outset by its surface insets, we need to undo the outsetting |
| 4728 | // with insetting by the same amount. |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4729 | final WindowState parent = getParentWindow(); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4730 | transformSurfaceInsetsPosition(mTmpPoint, parent.mAttrs.surfaceInsets); |
| 4731 | outPoint.offset(-parent.mWindowFrames.mFrame.left + mTmpPoint.x, |
| 4732 | -parent.mWindowFrames.mFrame.top + mTmpPoint.y); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 4733 | } else if (parentWindowContainer != null) { |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 4734 | final Rect parentBounds = parentWindowContainer.getDisplayedBounds(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 4735 | outPoint.offset(-parentBounds.left, -parentBounds.top); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4736 | } |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4737 | |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 4738 | TaskStack stack = getStack(); |
| 4739 | |
| 4740 | // If we have stack outsets, that means the top-left |
| 4741 | // will be outset, and we need to inset ourselves |
| 4742 | // to account for it. If we actually have shadows we will |
| 4743 | // then un-inset ourselves by the surfaceInsets. |
| 4744 | if (stack != null) { |
| 4745 | final int outset = stack.getStackOutset(); |
| 4746 | outPoint.offset(outset, outset); |
| 4747 | } |
| 4748 | |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 4749 | // Expand for surface insets. See WindowState.expandForSurfaceInsets. |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4750 | transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets); |
| 4751 | outPoint.offset(-mTmpPoint.x, -mTmpPoint.y); |
| 4752 | } |
| 4753 | |
| 4754 | /** |
| 4755 | * The surface insets from layout parameter are in application coordinate. If the window is |
| 4756 | * scaled, the insets also need to be scaled for surface position in global coordinate. |
| 4757 | */ |
| 4758 | private void transformSurfaceInsetsPosition(Point outPos, Rect surfaceInsets) { |
| 4759 | if (!inSizeCompatMode()) { |
| 4760 | outPos.x = surfaceInsets.left; |
| 4761 | outPos.y = surfaceInsets.top; |
| 4762 | return; |
| 4763 | } |
| 4764 | outPos.x = (int) (surfaceInsets.left * mGlobalScale + 0.5f); |
| 4765 | outPos.y = (int) (surfaceInsets.top * mGlobalScale + 0.5f); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4766 | } |
| 4767 | |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 4768 | boolean needsRelativeLayeringToIme() { |
| 4769 | // We only use the relative layering mode in split screen, as part of elevating the IME |
| 4770 | // and windows above it's target above the docked divider. |
| 4771 | if (!inSplitScreenWindowingMode()) { |
| 4772 | return false; |
| 4773 | } |
| 4774 | |
| 4775 | if (isChildWindow()) { |
| 4776 | // If we are a child of the input method target we need this promotion. |
| 4777 | if (getParentWindow().isInputMethodTarget()) { |
| 4778 | return true; |
| 4779 | } |
| 4780 | } else if (mAppToken != null) { |
| 4781 | // Likewise if we share a token with the Input method target and are ordered |
| 4782 | // above it but not necessarily a child (e.g. a Dialog) then we also need |
| 4783 | // this promotion. |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 4784 | final WindowState imeTarget = getDisplayContent().mInputMethodTarget; |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 4785 | boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this |
| 4786 | && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0; |
| 4787 | return inTokenWithAndAboveImeTarget; |
| 4788 | } |
| 4789 | return false; |
| 4790 | } |
| 4791 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4792 | @Override |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4793 | void assignLayer(Transaction t, int layer) { |
| 4794 | // See comment in assignRelativeLayerForImeTargetChild |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 4795 | if (needsRelativeLayeringToIme()) { |
| 4796 | getDisplayContent().assignRelativeLayerForImeTargetChild(t, this); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4797 | return; |
| 4798 | } |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 4799 | super.assignLayer(t, layer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4800 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 4801 | |
| 4802 | @Override |
| 4803 | public boolean isDimming() { |
| 4804 | return mIsDimming; |
| 4805 | } |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 4806 | |
| 4807 | // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA |
| 4808 | // then we can drop all negative layering on the windowing side and simply inherit |
| 4809 | // the default implementation here. |
| 4810 | public void assignChildLayers(Transaction t) { |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 4811 | // The surface of the main window might be preserved. So the child window on top of the main |
| 4812 | // window should be also on top of the preserved surface. |
| 4813 | int layer = PRESERVED_SURFACE_LAYER + 1; |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 4814 | for (int i = 0; i < mChildren.size(); i++) { |
| 4815 | final WindowState w = mChildren.get(i); |
| 4816 | |
| 4817 | // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA |
| 4818 | // while they both need to go below the main window. However the |
| 4819 | // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never |
| 4820 | // been defined and so we can use static layers and leave it that way. |
| 4821 | if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) { |
| 4822 | w.assignLayer(t, -2); |
| 4823 | } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) { |
| 4824 | w.assignLayer(t, -1); |
| 4825 | } else { |
| 4826 | w.assignLayer(t, layer); |
| 4827 | } |
| 4828 | w.assignChildLayers(t); |
| 4829 | layer++; |
| 4830 | } |
| 4831 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4832 | |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 4833 | /** |
| 4834 | * Update a tap exclude region with a rectangular area identified by provided id. The requested |
| 4835 | * area will be clipped to the window bounds. |
| 4836 | */ |
| 4837 | void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) { |
| 4838 | final DisplayContent currentDisplay = getDisplayContent(); |
| 4839 | if (currentDisplay == null) { |
| 4840 | throw new IllegalStateException("Trying to update window not attached to any display."); |
| 4841 | } |
| 4842 | |
| 4843 | if (mTapExcludeRegionHolder == null) { |
| 4844 | mTapExcludeRegionHolder = new TapExcludeRegionHolder(); |
| 4845 | |
| 4846 | // Make sure that this window is registered as one that provides a tap exclude region |
| 4847 | // for its containing display. |
| 4848 | currentDisplay.mTapExcludeProvidingWindows.add(this); |
| 4849 | } |
| 4850 | |
| 4851 | mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height); |
| 4852 | // Trigger touch exclude region update on current display. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 4853 | currentDisplay.updateTouchExcludeRegion(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4854 | // Trigger touchable region update for this window. |
| 4855 | currentDisplay.getInputMonitor().updateInputWindowsLw(true /* force */); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 4856 | } |
| 4857 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4858 | /** |
| 4859 | * Union the region with current tap exclude region that this window provides. |
| 4860 | * |
| 4861 | * @param region The region to be amended. It is on the screen coordinates. |
| 4862 | */ |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 4863 | void amendTapExcludeRegion(Region region) { |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 4864 | final Region tempRegion = Region.obtain(); |
| 4865 | mTmpRect.set(mWindowFrames.mFrame); |
| 4866 | mTmpRect.offsetTo(0, 0); |
| 4867 | mTapExcludeRegionHolder.amendRegion(tempRegion, mTmpRect); |
| 4868 | // The region held by the holder is on the window coordinates. We need to translate it to |
| 4869 | // the screen coordinates. |
| 4870 | tempRegion.translate(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top); |
| 4871 | region.op(tempRegion, Region.Op.UNION); |
| 4872 | tempRegion.recycle(); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 4873 | } |
| 4874 | |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 4875 | @Override |
| 4876 | public boolean isInputMethodTarget() { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 4877 | return getDisplayContent().mInputMethodTarget == this; |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 4878 | } |
| 4879 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 4880 | long getFrameNumber() { |
| 4881 | return mFrameNumber; |
| 4882 | } |
| 4883 | |
| 4884 | void setFrameNumber(long frameNumber) { |
| 4885 | mFrameNumber = frameNumber; |
| 4886 | } |
| 4887 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 4888 | public void getMaxVisibleBounds(Rect out) { |
| 4889 | if (out.isEmpty()) { |
| 4890 | out.set(mWindowFrames.mVisibleFrame); |
| 4891 | return; |
| 4892 | } |
| 4893 | |
| 4894 | if (mWindowFrames.mVisibleFrame.left < out.left) { |
| 4895 | out.left = mWindowFrames.mVisibleFrame.left; |
| 4896 | } |
| 4897 | if (mWindowFrames.mVisibleFrame.top < out.top) { |
| 4898 | out.top = mWindowFrames.mVisibleFrame.top; |
| 4899 | } |
| 4900 | if (mWindowFrames.mVisibleFrame.right > out.right) { |
| 4901 | out.right = mWindowFrames.mVisibleFrame.right; |
| 4902 | } |
| 4903 | if (mWindowFrames.mVisibleFrame.bottom > out.bottom) { |
| 4904 | out.bottom = mWindowFrames.mVisibleFrame.bottom; |
| 4905 | } |
| 4906 | } |
| 4907 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 4908 | /** |
| 4909 | * Copy the inset values over so they can be sent back to the client when a relayout occurs. |
| 4910 | */ |
| 4911 | void getInsetsForRelayout(Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets, |
| 4912 | Rect outStableInsets, Rect outOutsets) { |
| 4913 | outOverscanInsets.set(mWindowFrames.mOverscanInsets); |
| 4914 | outContentInsets.set(mWindowFrames.mContentInsets); |
| 4915 | outVisibleInsets.set(mWindowFrames.mVisibleInsets); |
| 4916 | outStableInsets.set(mWindowFrames.mStableInsets); |
| 4917 | outOutsets.set(mWindowFrames.mOutsets); |
| 4918 | |
| 4919 | mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets); |
| 4920 | } |
| 4921 | |
| 4922 | void getContentInsets(Rect outContentInsets) { |
| 4923 | outContentInsets.set(mWindowFrames.mContentInsets); |
| 4924 | } |
| 4925 | |
| 4926 | Rect getContentInsets() { |
| 4927 | return mWindowFrames.mContentInsets; |
| 4928 | } |
| 4929 | |
| 4930 | void getStableInsets(Rect outStableInsets) { |
| 4931 | outStableInsets.set(mWindowFrames.mStableInsets); |
| 4932 | } |
| 4933 | |
| 4934 | Rect getStableInsets() { |
| 4935 | return mWindowFrames.mStableInsets; |
| 4936 | } |
| 4937 | |
| 4938 | void resetLastContentInsets() { |
| 4939 | mWindowFrames.resetLastContentInsets(); |
| 4940 | } |
| 4941 | |
| 4942 | Rect getVisibleInsets() { |
| 4943 | return mWindowFrames.mVisibleInsets; |
| 4944 | } |
| 4945 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 4946 | @Override |
| 4947 | public WindowFrames getWindowFrames() { |
| 4948 | return mWindowFrames; |
| 4949 | } |
| 4950 | |
| 4951 | void resetContentChanged() { |
| 4952 | mWindowFrames.setContentChanged(false); |
| 4953 | } |
| 4954 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 4955 | void setInsetProvider(InsetsSourceProvider insetProvider) { |
| 4956 | mInsetProvider = insetProvider; |
| 4957 | } |
| 4958 | |
| 4959 | InsetsSourceProvider getInsetProvider() { |
| 4960 | return mInsetProvider; |
| 4961 | } |
| 4962 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4963 | private final class MoveAnimationSpec implements AnimationSpec { |
| 4964 | |
| 4965 | private final long mDuration; |
| 4966 | private Interpolator mInterpolator; |
| 4967 | private Point mFrom = new Point(); |
| 4968 | private Point mTo = new Point(); |
| 4969 | |
| 4970 | private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) { |
| 4971 | final Animation anim = AnimationUtils.loadAnimation(mContext, |
| 4972 | com.android.internal.R.anim.window_move_from_decor); |
Jorim Jaggi | 08f75cf | 2018-01-08 14:38:53 +0100 | [diff] [blame] | 4973 | mDuration = (long) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4974 | (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked()); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4975 | mInterpolator = anim.getInterpolator(); |
| 4976 | mFrom.set(fromX, fromY); |
| 4977 | mTo.set(toX, toY); |
| 4978 | } |
| 4979 | |
| 4980 | @Override |
| 4981 | public long getDuration() { |
| 4982 | return mDuration; |
| 4983 | } |
| 4984 | |
| 4985 | @Override |
| 4986 | public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) { |
| 4987 | final float fraction = (float) currentPlayTime / getDuration(); |
| 4988 | final float v = mInterpolator.getInterpolation(fraction); |
| 4989 | t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v, |
| 4990 | mFrom.y + (mTo.y - mFrom.y) * v); |
| 4991 | } |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 4992 | |
| 4993 | @Override |
| 4994 | public void dump(PrintWriter pw, String prefix) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 4995 | pw.println(prefix + "from=" + mFrom |
| 4996 | + " to=" + mTo |
| 4997 | + " duration=" + mDuration); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | @Override |
| 5001 | public void writeToProtoInner(ProtoOutputStream proto) { |
| 5002 | final long token = proto.start(MOVE); |
| 5003 | mFrom.writeToProto(proto, FROM); |
| 5004 | mTo.writeToProto(proto, TO); |
Kweku Adams | 21b8d26 | 2018-03-30 12:19:58 -0700 | [diff] [blame] | 5005 | proto.write(DURATION_MS, mDuration); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 5006 | proto.end(token); |
| 5007 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5008 | } |
satok | cef37fb | 2011-10-24 21:49:38 +0900 | [diff] [blame] | 5009 | } |