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