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; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.isSplitScreenWindowingMode; |
| 24 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 25 | import static android.os.PowerManager.DRAW_WAKE_LOCK; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 26 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 27 | import static android.view.SurfaceControl.Transaction; |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 28 | import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 29 | import static android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 30 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; |
| 31 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 32 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
| 33 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 34 | import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 36 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
| 37 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 38 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 39 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 40 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
| 41 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 42 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
| 43 | import static android.view.WindowManager.LayoutParams.FLAG_SCALED; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 44 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 45 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
| 46 | import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 47 | import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 48 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 49 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 50 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
| 51 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 52 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME; |
| 53 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; |
| 54 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH; |
| 55 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 56 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 57 | 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] | 58 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 59 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
Vishnu Nair | 1d0fa07 | 2018-01-04 07:53:00 -0800 | [diff] [blame] | 60 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 61 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 62 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 63 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 64 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
| 65 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 66 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 67 | import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY; |
| 68 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 69 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 71 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 72 | import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 73 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED; |
| 74 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM; |
| 75 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME; |
| 76 | import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 77 | |
Yunfan Chen | b4fe58c | 2019-03-27 18:35:06 +0900 | [diff] [blame] | 78 | import static com.android.server.am.ActivityManagerService.MY_PID; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 79 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
| 80 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER; |
| 81 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT; |
| 82 | import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 83 | import static com.android.server.wm.AnimationSpecProto.MOVE; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 84 | import static com.android.server.wm.DisplayContent.logsGestureExclusionRestrictions; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 85 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 86 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 87 | import static com.android.server.wm.IdentifierProto.HASH_CODE; |
| 88 | import static com.android.server.wm.IdentifierProto.TITLE; |
| 89 | import static com.android.server.wm.IdentifierProto.USER_ID; |
| 90 | import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS; |
| 91 | import static com.android.server.wm.MoveAnimationSpecProto.FROM; |
| 92 | import static com.android.server.wm.MoveAnimationSpecProto.TO; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 93 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; |
| 94 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
| 95 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS; |
| 96 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; |
| 97 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; |
| 98 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_RESIZE; |
| 99 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 100 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 101 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 102 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 103 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 104 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 105 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 106 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 107 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 108 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 109 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 110 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 111 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
| 112 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 113 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 114 | import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 115 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
| 116 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
| 117 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Tiger Huang | 8af6ba4 | 2018-06-07 19:24:09 +0800 | [diff] [blame] | 118 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 119 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
| 120 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 121 | import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING; |
| 122 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
| 123 | import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN; |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 124 | import static com.android.server.wm.WindowStateAnimator.PRESERVED_SURFACE_LAYER; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 125 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 126 | import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT; |
| 127 | import static com.android.server.wm.WindowStateProto.ANIMATOR; |
| 128 | import static com.android.server.wm.WindowStateProto.ATTRIBUTES; |
| 129 | import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 130 | import static com.android.server.wm.WindowStateProto.DESTROYING; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 131 | import static com.android.server.wm.WindowStateProto.DISPLAY_ID; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 132 | import static com.android.server.wm.WindowStateProto.FINISHED_SEAMLESS_ROTATION_FRAME; |
| 133 | import static com.android.server.wm.WindowStateProto.FORCE_SEAMLESS_ROTATION; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 134 | import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS; |
| 135 | import static com.android.server.wm.WindowStateProto.HAS_SURFACE; |
| 136 | import static com.android.server.wm.WindowStateProto.IDENTIFIER; |
| 137 | import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN; |
| 138 | import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY; |
| 139 | import static com.android.server.wm.WindowStateProto.IS_VISIBLE; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 140 | import static com.android.server.wm.WindowStateProto.PENDING_SEAMLESS_ROTATION; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 141 | import static com.android.server.wm.WindowStateProto.REMOVED; |
| 142 | import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT; |
| 143 | import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT; |
| 144 | import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 145 | import static com.android.server.wm.WindowStateProto.STACK_ID; |
| 146 | import static com.android.server.wm.WindowStateProto.SURFACE_INSETS; |
| 147 | import static com.android.server.wm.WindowStateProto.SURFACE_POSITION; |
| 148 | import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY; |
| 149 | import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 150 | import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER; |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 151 | import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 152 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 153 | import android.annotation.CallSuper; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 154 | import android.annotation.Nullable; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 155 | import android.app.AppOpsManager; |
| 156 | import android.content.Context; |
| 157 | import android.content.res.Configuration; |
| 158 | import android.graphics.Matrix; |
| 159 | import android.graphics.PixelFormat; |
| 160 | import android.graphics.Point; |
| 161 | import android.graphics.Rect; |
| 162 | import android.graphics.Region; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 163 | import android.os.Binder; |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 164 | import android.os.Build; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 165 | import android.os.Debug; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 166 | import android.os.IBinder; |
| 167 | import android.os.PowerManager; |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 168 | import android.os.PowerManager.WakeReason; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 169 | import android.os.RemoteCallbackList; |
| 170 | import android.os.RemoteException; |
| 171 | import android.os.SystemClock; |
| 172 | import android.os.Trace; |
| 173 | import android.os.UserHandle; |
| 174 | import android.os.WorkSource; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 175 | import android.provider.Settings; |
Phil Weaver | bb2f28a | 2017-12-22 09:44:28 -0800 | [diff] [blame] | 176 | import android.text.TextUtils; |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 177 | import android.util.ArraySet; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 178 | import android.util.DisplayMetrics; |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 179 | import android.util.MergedConfiguration; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 180 | import android.util.Slog; |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 181 | import android.util.StatsLog; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 182 | import android.util.TimeUtils; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 183 | import android.util.proto.ProtoOutputStream; |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 184 | import android.view.Display; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 185 | import android.view.DisplayCutout; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 186 | import android.view.DisplayInfo; |
| 187 | import android.view.Gravity; |
| 188 | import android.view.IApplicationToken; |
| 189 | import android.view.IWindow; |
| 190 | import android.view.IWindowFocusObserver; |
| 191 | import android.view.IWindowId; |
| 192 | import android.view.InputChannel; |
| 193 | import android.view.InputEvent; |
| 194 | import android.view.InputEventReceiver; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 195 | import android.view.InputWindowHandle; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 196 | import android.view.InsetsState; |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 197 | import android.view.Surface.Rotation; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 198 | import android.view.SurfaceControl; |
| 199 | import android.view.SurfaceSession; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 200 | import android.view.View; |
| 201 | import android.view.ViewTreeObserver; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 202 | import android.view.WindowInfo; |
Tarandeep Singh | 0bedd94 | 2019-09-26 13:34:03 -0700 | [diff] [blame] | 203 | import android.view.WindowInsets.Type.InsetType; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 204 | import android.view.WindowManager; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 205 | import android.view.animation.Animation; |
| 206 | import android.view.animation.AnimationUtils; |
| 207 | import android.view.animation.Interpolator; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 208 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 209 | import com.android.internal.annotations.VisibleForTesting; |
Vishnu Nair | 539334a | 2019-09-20 10:46:21 -0700 | [diff] [blame] | 210 | import com.android.internal.policy.KeyInterceptionInfo; |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 211 | import com.android.internal.util.ToBooleanFunction; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 212 | import com.android.server.policy.WindowManagerPolicy; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 213 | import com.android.server.protolog.common.ProtoLog; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 214 | import com.android.server.wm.LocalAnimationAdapter.AnimationSpec; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 215 | import com.android.server.wm.utils.WmDisplayCutout; |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 216 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 217 | import java.io.PrintWriter; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 218 | import java.lang.ref.WeakReference; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 219 | import java.util.ArrayList; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 220 | import java.util.Comparator; |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 221 | import java.util.List; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 222 | import java.util.function.Predicate; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 223 | |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 224 | /** A window in the window manager. */ |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 225 | class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState, |
| 226 | InsetsControlTarget { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 227 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 228 | |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 229 | // The minimal size of a window within the usable area of the freeform stack. |
Vishnu Nair | 93d68c2 | 2019-03-22 13:45:31 -0700 | [diff] [blame] | 230 | // TODO(multi-window): fix the min sizes when we have minimum width/height support, |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 231 | // use hard-coded min sizes for now. |
| 232 | static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48; |
| 233 | static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 234 | |
| 235 | // The thickness of a window resize handle outside the window bounds on the free form workspace |
| 236 | // to capture touch events in that area. |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 237 | static final int RESIZE_HANDLE_WIDTH_IN_DP = 30; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 238 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 239 | static final int EXCLUSION_LEFT = 0; |
| 240 | static final int EXCLUSION_RIGHT = 1; |
| 241 | |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 242 | final WindowManagerPolicy mPolicy; |
| 243 | final Context mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 244 | final Session mSession; |
| 245 | final IWindow mClient; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 246 | final int mAppOp; |
| 247 | // UserId and appId of the owner. Don't display windows of non-current user. |
| 248 | final int mOwnerUid; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 249 | /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */ |
| 250 | final boolean mOwnerCanAddInternalSystemWindow; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 251 | final WindowId mWindowId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 252 | WindowToken mToken; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 253 | // The same object as mToken if this is an app window and null for non-app windows. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 254 | ActivityRecord mActivityRecord; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 255 | |
| 256 | // mAttrs.flags is tested in animation without being locked. If the bits tested are ever |
| 257 | // modified they will need to be locked. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 258 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 259 | final DeathRecipient mDeathRecipient; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 260 | private boolean mIsChildWindow; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 261 | final int mBaseLayer; |
| 262 | final int mSubLayer; |
| 263 | final boolean mLayoutAttached; |
| 264 | final boolean mIsImWindow; |
| 265 | final boolean mIsWallpaper; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 266 | private final boolean mIsFloatingLayer; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 267 | int mSeq; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 268 | int mViewVisibility; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 269 | int mSystemUiVisibility; |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 270 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 271 | /** |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 272 | * The visibility flag of the window based on policy like {@link WindowManagerPolicy}. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 273 | * Normally set by calling {@link #showLw} and {@link #hideLw}. |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 274 | * |
| 275 | * TODO: b/131253938 This will eventually be split into individual visibility policy flags. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 276 | */ |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 277 | static final int LEGACY_POLICY_VISIBILITY = 1; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 278 | /** |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 279 | * The visibility flag that determines whether this window is visible for the current user. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 280 | */ |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 281 | private static final int VISIBLE_FOR_USER = 1 << 1; |
| 282 | private static final int POLICY_VISIBILITY_ALL = VISIBLE_FOR_USER | LEGACY_POLICY_VISIBILITY; |
| 283 | /** |
| 284 | * The Bitwise-or of flags that contribute to visibility of the WindowState |
| 285 | */ |
| 286 | private int mPolicyVisibility = POLICY_VISIBILITY_ALL; |
| 287 | |
| 288 | /** |
| 289 | * Whether {@link #LEGACY_POLICY_VISIBILITY} flag should be set after a transition animation. |
| 290 | * For example, {@link #LEGACY_POLICY_VISIBILITY} might be set during an exit animation to hide |
| 291 | * it and then unset when the value of {@link #mLegacyPolicyVisibilityAfterAnim} is false |
| 292 | * after the exit animation is done. |
| 293 | * |
| 294 | * TODO: b/131253938 Determine whether this can be changed to use a visibility flag instead. |
| 295 | */ |
| 296 | boolean mLegacyPolicyVisibilityAfterAnim = true; |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 297 | // overlay window is hidden because the owning app is suspended |
| 298 | private boolean mHiddenWhileSuspended; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 299 | private boolean mAppOpVisibility = true; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 300 | boolean mPermanentlyHidden; // the window should never be shown again |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 301 | // This is a non-system overlay window that is currently force hidden. |
| 302 | private boolean mForceHideNonSystemOverlayWindow; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 303 | boolean mAppFreezing; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 304 | boolean mHidden = true; // Used to determine if to show child windows. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 305 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 306 | private boolean mDragResizing; |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 307 | private boolean mDragResizingChangeReported = true; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 308 | private int mResizeMode; |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 309 | /** |
| 310 | * Special mode that is intended only for the rounded corner overlay: during rotation |
| 311 | * transition, we un-rotate the window token such that the window appears as it did before the |
| 312 | * rotation. |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 313 | */ |
| 314 | final boolean mForceSeamlesslyRotate; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 315 | SeamlessRotator mPendingSeamlessRotate; |
| 316 | long mFinishSeamlessRotateFrameNumber; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 317 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 318 | private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 319 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 320 | /** |
| 321 | * The window size that was requested by the application. These are in |
| 322 | * the application's coordinate space (without compatibility scale applied). |
| 323 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 324 | int mRequestedWidth; |
| 325 | int mRequestedHeight; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 326 | private int mLastRequestedWidth; |
| 327 | private int mLastRequestedHeight; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 328 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 329 | int mLayer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 330 | boolean mHaveFrame; |
| 331 | boolean mObscured; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 332 | |
| 333 | int mLayoutSeq = -1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 334 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 335 | /** @see #addEmbeddedDisplayContent(DisplayContent dc) */ |
| 336 | private final ArraySet<DisplayContent> mEmbeddedDisplayContents = new ArraySet<>(); |
| 337 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 338 | /** |
| 339 | * Used to store last reported to client configuration and check if we have newer available. |
| 340 | * We'll send configuration to client only if it is different from the last applied one and |
| 341 | * client won't perform unnecessary updates. |
| 342 | */ |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 343 | private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 344 | |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 345 | /** @see #isLastConfigReportedToClient() */ |
| 346 | private boolean mLastConfigReportedToClient; |
| 347 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 348 | private final Configuration mTempConfiguration = new Configuration(); |
| 349 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 350 | /** |
Robert Carr | 18f622f | 2017-05-08 11:20:43 -0700 | [diff] [blame] | 351 | * The last content insets returned to the client in relayout. We use |
| 352 | * these in the bounds animation to ensure we only observe inset changes |
| 353 | * at the same time that a client resizes it's surface so that we may use |
| 354 | * the geometryAppliesWithResize synchronization mechanism to keep |
| 355 | * the contents in place. |
| 356 | */ |
| 357 | final Rect mLastRelayoutContentInsets = new Rect(); |
| 358 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 359 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 360 | * Set to true if we are waiting for this window to receive its |
| 361 | * given internal insets before laying out other windows based on it. |
| 362 | */ |
| 363 | boolean mGivenInsetsPending; |
| 364 | |
| 365 | /** |
| 366 | * These are the content insets that were given during layout for |
| 367 | * this window, to be applied to windows behind it. |
| 368 | */ |
| 369 | final Rect mGivenContentInsets = new Rect(); |
| 370 | |
| 371 | /** |
| 372 | * These are the visible insets that were given during layout for |
| 373 | * this window, to be applied to windows behind it. |
| 374 | */ |
| 375 | final Rect mGivenVisibleInsets = new Rect(); |
| 376 | |
| 377 | /** |
| 378 | * This is the given touchable area relative to the window frame, or null if none. |
| 379 | */ |
| 380 | final Region mGivenTouchableRegion = new Region(); |
| 381 | |
| 382 | /** |
| 383 | * Flag indicating whether the touchable region should be adjusted by |
| 384 | * the visible insets; if false the area outside the visible insets is |
| 385 | * NOT touchable, so we must use those to adjust the frame during hit |
| 386 | * tests. |
| 387 | */ |
| 388 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 389 | |
| 390 | // Current transformation being applied. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 391 | float mGlobalScale=1; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 392 | float mInvGlobalScale=1; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 393 | float mHScale=1, mVScale=1; |
| 394 | float mLastHScale=1, mLastVScale=1; |
| 395 | final Matrix mTmpMatrix = new Matrix(); |
| 396 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 397 | private final WindowFrames mWindowFrames = new WindowFrames(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 398 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 399 | /** |
| 400 | * Usually empty. Set to the task's tempInsetFrame. See |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 401 | *{@link android.app.IActivityTaskManager#resizeDockedStack}. |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 402 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 403 | private final Rect mInsetFrame = new Rect(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 404 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 405 | /** |
| 406 | * List of rects where system gestures should be ignored. |
| 407 | * |
| 408 | * Coordinates are relative to the window's position. |
| 409 | */ |
| 410 | private final List<Rect> mExclusionRects = new ArrayList<>(); |
| 411 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 412 | // 0 = left, 1 = right |
| 413 | private final int[] mLastRequestedExclusionHeight = {0, 0}; |
| 414 | private final int[] mLastGrantedExclusionHeight = {0, 0}; |
| 415 | private final long[] mLastExclusionLogUptimeMillis = {0, 0}; |
| 416 | |
| 417 | private boolean mLastShownChangedReported; |
| 418 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 419 | // If a window showing a wallpaper: the requested offset for the |
| 420 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 421 | float mWallpaperX = -1; |
| 422 | float mWallpaperY = -1; |
| 423 | |
| 424 | // If a window showing a wallpaper: what fraction of the offset |
| 425 | // range corresponds to a full virtual screen. |
| 426 | float mWallpaperXStep = -1; |
| 427 | float mWallpaperYStep = -1; |
| 428 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 429 | // If a window showing a wallpaper: a raw pixel offset to forcibly apply |
| 430 | // to its window; if a wallpaper window: not used. |
| 431 | int mWallpaperDisplayOffsetX = Integer.MIN_VALUE; |
| 432 | int mWallpaperDisplayOffsetY = Integer.MIN_VALUE; |
| 433 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 434 | /** |
| 435 | * This is set after IWindowSession.relayout() has been called at |
| 436 | * least once for the window. It allows us to detect the situation |
| 437 | * where we don't yet have a surface, but should have one soon, so |
| 438 | * we can give the window focus before waiting for the relayout. |
| 439 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 440 | boolean mRelayoutCalled; |
| 441 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 442 | boolean mInRelayout; |
| 443 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 444 | /** |
| 445 | * If the application has called relayout() with changes that can |
| 446 | * impact its window's size, we need to perform a layout pass on it |
| 447 | * even if it is not currently visible for layout. This is set |
| 448 | * when in that case until the layout is done. |
| 449 | */ |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 450 | boolean mLayoutNeeded; |
| 451 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 452 | /** Currently running an exit animation? */ |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 453 | boolean mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 454 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 455 | /** Currently on the mDestroySurface list? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 456 | boolean mDestroying; |
| 457 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 458 | /** Completely remove from window manager after exit animation? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 459 | boolean mRemoveOnExit; |
| 460 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 461 | /** |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 462 | * Whether the app died while it was visible, if true we might need |
| 463 | * to continue to show it until it's restarted. |
| 464 | */ |
| 465 | boolean mAppDied; |
| 466 | |
| 467 | /** |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 468 | * Set when the orientation is changing and this window has not yet |
| 469 | * been updated for the new orientation. |
| 470 | */ |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 471 | private boolean mOrientationChanging; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 472 | |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 473 | /** |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 474 | * Sometimes in addition to the mOrientationChanging |
| 475 | * flag we report that the orientation is changing |
| 476 | * due to a mismatch in current and reported configuration. |
| 477 | * |
| 478 | * In the case of timeout we still need to make sure we |
| 479 | * leave the orientation changing state though, so we |
| 480 | * use this as a special time out escape hatch. |
| 481 | */ |
| 482 | private boolean mOrientationChangeTimedOut; |
| 483 | |
| 484 | /** |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 485 | * The orientation during the last visible call to relayout. If our |
| 486 | * current orientation is different, the window can't be ready |
| 487 | * to be shown. |
| 488 | */ |
| 489 | int mLastVisibleLayoutRotation = -1; |
| 490 | |
| 491 | /** |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 492 | * Set when we need to report the orientation change to client to trigger a relayout. |
| 493 | */ |
| 494 | boolean mReportOrientationChanged; |
| 495 | |
| 496 | /** |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 497 | * How long we last kept the screen frozen. |
| 498 | */ |
| 499 | int mLastFreezeDuration; |
| 500 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 501 | /** Is this window now (or just being) removed? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 502 | boolean mRemoved; |
| 503 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 504 | /** |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 505 | * It is save to remove the window and destroy the surface because the client requested removal |
| 506 | * or some other higher level component said so (e.g. activity manager). |
| 507 | * 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] | 508 | */ |
Svetoslav Ganov | 200adfb | 2016-10-18 13:29:27 -0700 | [diff] [blame] | 509 | boolean mWindowRemovalAllowed; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 510 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 511 | // Input channel and input window handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 512 | final InputWindowHandle mInputWindowHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 513 | InputChannel mInputChannel; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 514 | private InputChannel mClientChannel; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 515 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 516 | // Used to improve performance of toString() |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 517 | private String mStringNameCache; |
| 518 | private CharSequence mLastTitle; |
| 519 | private boolean mWasExiting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 520 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 521 | final WindowStateAnimator mWinAnimator; |
| 522 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 523 | boolean mHasSurface = false; |
| 524 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 525 | /** When true this window can be displayed on screens owther than mOwnerUid's */ |
| 526 | private boolean mShowToOwnerOnly; |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 527 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 528 | // This window will be replaced due to relaunch. This allows window manager |
| 529 | // to differentiate between simple removal of a window and replacement. In the latter case it |
| 530 | // will preserve the old window until the new one is drawn. |
| 531 | boolean mWillReplaceWindow = false; |
| 532 | // If true, the replaced window was already requested to be removed. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 533 | private boolean mReplacingRemoveRequested = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 534 | // Whether the replacement of the window should trigger app transition animation. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 535 | private boolean mAnimateReplacingWindow = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 536 | // If not null, the window that will be used to replace the old one. This is being set when |
| 537 | // 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] | 538 | private WindowState mReplacementWindow = null; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 539 | // For the new window in the replacement transition, if we have |
| 540 | // requested to replace without animation, then we should |
| 541 | // make sure we also don't apply an enter animation for |
| 542 | // the new window. |
| 543 | boolean mSkipEnterAnimationForSeamlessReplacement = false; |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 544 | // Whether this window is being moved via the resize API |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 545 | private boolean mMovedByResize; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 546 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 547 | /** |
| 548 | * Wake lock for drawing. |
| 549 | * Even though it's slightly more expensive to do so, we will use a separate wake lock |
| 550 | * for each app that is requesting to draw while dozing so that we can accurately track |
| 551 | * who is preventing the system from suspending. |
| 552 | * This lock is only acquired on first use. |
| 553 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 554 | private PowerManager.WakeLock mDrawLock; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 555 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 556 | private final Rect mTmpRect = new Rect(); |
| 557 | private final Point mTmpPoint = new Point(); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 558 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 559 | /** |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 560 | * If a window is on a display which has been re-parented to a view in another window, |
| 561 | * use this offset to indicate the correct location. |
| 562 | */ |
| 563 | private final Point mLastReportedDisplayOffset = new Point(); |
| 564 | |
| 565 | /** |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 566 | * Whether the window was resized by us while it was gone for layout. |
| 567 | */ |
| 568 | boolean mResizedWhileGone = false; |
| 569 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 570 | /** |
| 571 | * During seamless rotation we have two phases, first the old window contents |
| 572 | * are rotated to look as if they didn't move in the new coordinate system. Then we |
| 573 | * have to freeze updates to this layer (to preserve the transformation) until |
| 574 | * the resize actually occurs. This is true from when the transformation is set |
| 575 | * and false until the transaction to resize is sent. |
| 576 | */ |
| 577 | boolean mSeamlesslyRotated = false; |
| 578 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 579 | /** |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 580 | * Surface insets from the previous call to relayout(), used to track |
| 581 | * if we are changing the Surface insets. |
| 582 | */ |
| 583 | final Rect mLastSurfaceInsets = new Rect(); |
| 584 | |
| 585 | /** |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 586 | * A flag set by the {@link WindowState} parent to indicate that the parent has examined this |
| 587 | * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to |
| 588 | * make sure all children have been considered. |
| 589 | */ |
| 590 | private boolean mDrawnStateEvaluated; |
| 591 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 592 | private final Point mSurfacePosition = new Point(); |
| 593 | |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 594 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 595 | * A region inside of this window to be excluded from touch. |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 596 | */ |
| 597 | private TapExcludeRegionHolder mTapExcludeRegionHolder; |
| 598 | |
| 599 | /** |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 600 | * Used for testing because the real PowerManager is final. |
| 601 | */ |
| 602 | private PowerManagerWrapper mPowerManagerWrapper; |
| 603 | |
| 604 | /** |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 605 | * A frame number in which changes requested in this layout will be rendered. |
| 606 | */ |
| 607 | private long mFrameNumber = -1; |
| 608 | |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 609 | private static final StringBuilder sTmpSB = new StringBuilder(); |
| 610 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 611 | /** |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 612 | * 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] | 613 | * of z-order and 1 otherwise. |
| 614 | */ |
Griff Hazen | 51d00d8 | 2016-11-22 15:39:24 -0800 | [diff] [blame] | 615 | private static final Comparator<WindowState> sWindowSubLayerComparator = |
| 616 | new Comparator<WindowState>() { |
| 617 | @Override |
| 618 | public int compare(WindowState w1, WindowState w2) { |
| 619 | final int layer1 = w1.mSubLayer; |
| 620 | final int layer2 = w2.mSubLayer; |
| 621 | if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) { |
| 622 | // We insert the child window into the list ordered by |
| 623 | // the sub-layer. For same sub-layers, the negative one |
| 624 | // should go below others; the positive one should go |
| 625 | // above others. |
| 626 | return -1; |
| 627 | } |
| 628 | return 1; |
| 629 | }; |
| 630 | }; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 631 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 632 | /** |
| 633 | * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host |
| 634 | * container. |
| 635 | */ |
| 636 | private boolean mIsDimming = false; |
| 637 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 638 | private @Nullable InsetsSourceProvider mControllableInsetProvider; |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 639 | private InsetsState mClientInsetsState; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 640 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 641 | private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f; |
Vishnu Nair | 539334a | 2019-09-20 10:46:21 -0700 | [diff] [blame] | 642 | private KeyInterceptionInfo mKeyInterceptionInfo; |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 643 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 644 | InsetsState getClientInsetsState() { |
| 645 | return mClientInsetsState; |
| 646 | } |
| 647 | |
| 648 | void setClientInsetsState(InsetsState state) { |
| 649 | mClientInsetsState = state; |
| 650 | } |
| 651 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 652 | void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation, |
| 653 | @Rotation int rotation, boolean requested) { |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 654 | // Invisible windows and the wallpaper do not participate in the seamless rotation animation |
| 655 | if (!isVisibleNow() || mIsWallpaper) { |
| 656 | return; |
| 657 | } |
Adrian Roos | faa102f | 2018-08-02 15:56:15 +0200 | [diff] [blame] | 658 | |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 659 | if (mPendingSeamlessRotate != null) { |
| 660 | oldRotation = mPendingSeamlessRotate.getOldRotation(); |
| 661 | } |
| 662 | |
| 663 | if (mForceSeamlesslyRotate || requested) { |
| 664 | mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo()); |
Vishnu Nair | ec63406 | 2018-09-20 20:16:18 -0700 | [diff] [blame] | 665 | mPendingSeamlessRotate.unrotate(transaction, this); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 666 | getDisplayContent().getDisplayRotation().markForSeamlessRotation(this, |
| 667 | true /* seamlesslyRotated */); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 671 | void finishSeamlessRotation(boolean timeout) { |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 672 | if (mPendingSeamlessRotate != null) { |
Vishnu Nair | ba18335 | 2018-11-21 11:16:49 -0800 | [diff] [blame] | 673 | mPendingSeamlessRotate.finish(this, timeout); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 674 | mFinishSeamlessRotateFrameNumber = getFrameNumber(); |
| 675 | mPendingSeamlessRotate = null; |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 676 | getDisplayContent().getDisplayRotation().markForSeamlessRotation(this, |
| 677 | false /* seamlesslyRotated */); |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Adrian Roos | 4ffc897 | 2019-02-07 20:45:11 +0100 | [diff] [blame] | 681 | List<Rect> getSystemGestureExclusion() { |
| 682 | return mExclusionRects; |
| 683 | } |
| 684 | |
| 685 | /** |
| 686 | * Sets the system gesture exclusion rects. |
| 687 | * |
| 688 | * @return {@code true} if anything changed |
| 689 | */ |
| 690 | boolean setSystemGestureExclusion(List<Rect> exclusionRects) { |
| 691 | if (mExclusionRects.equals(exclusionRects)) { |
| 692 | return false; |
| 693 | } |
| 694 | mExclusionRects.clear(); |
| 695 | mExclusionRects.addAll(exclusionRects); |
| 696 | return true; |
| 697 | } |
| 698 | |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 699 | boolean isImplicitlyExcludingAllSystemGestures() { |
| 700 | final int immersiveStickyFlags = |
| 701 | SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 702 | final boolean immersiveSticky = |
| 703 | (mSystemUiVisibility & immersiveStickyFlags) == immersiveStickyFlags; |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 704 | return immersiveSticky && mWmService.mConstants.mSystemGestureExcludedByPreQStickyImmersive |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 705 | && mActivityRecord != null && mActivityRecord.mTargetSdk < Build.VERSION_CODES.Q; |
Adrian Roos | 019a52b | 2019-07-02 16:47:44 +0200 | [diff] [blame] | 706 | } |
| 707 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 708 | void setLastExclusionHeights(int side, int requested, int granted) { |
| 709 | boolean changed = mLastGrantedExclusionHeight[side] != granted |
| 710 | || mLastRequestedExclusionHeight[side] != requested; |
| 711 | |
| 712 | if (changed) { |
| 713 | if (mLastShownChangedReported) { |
| 714 | logExclusionRestrictions(side); |
| 715 | } |
| 716 | |
| 717 | mLastGrantedExclusionHeight[side] = granted; |
| 718 | mLastRequestedExclusionHeight[side] = requested; |
| 719 | } |
| 720 | } |
| 721 | |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 722 | interface PowerManagerWrapper { |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 723 | void wakeUp(long time, @WakeReason int reason, String details); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 724 | |
| 725 | boolean isInteractive(); |
| 726 | |
| 727 | } |
| 728 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 729 | WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 730 | WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a, |
| 731 | int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) { |
| 732 | this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId, |
| 733 | ownerCanAddInternalSystemWindow, new PowerManagerWrapper() { |
| 734 | @Override |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 735 | public void wakeUp(long time, @WakeReason int reason, String details) { |
| 736 | service.mPowerManager.wakeUp(time, reason, details); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | @Override |
| 740 | public boolean isInteractive() { |
| 741 | return service.mPowerManager.isInteractive(); |
| 742 | } |
| 743 | }); |
| 744 | } |
| 745 | |
| 746 | WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, |
| 747 | WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a, |
| 748 | int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow, |
| 749 | PowerManagerWrapper powerManagerWrapper) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 750 | super(service); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 751 | mSession = s; |
| 752 | mClient = c; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 753 | mAppOp = appOp; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 754 | mToken = token; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 755 | mActivityRecord = mToken.asActivityRecord(); |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 756 | mOwnerUid = ownerId; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 757 | mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 758 | mWindowId = new WindowId(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 759 | mAttrs.copyFrom(a); |
Robert Carr | b08ed04 | 2018-03-12 15:49:08 -0700 | [diff] [blame] | 760 | mLastSurfaceInsets.set(mAttrs.surfaceInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 761 | mViewVisibility = viewVisibility; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 762 | mPolicy = mWmService.mPolicy; |
| 763 | mContext = mWmService.mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 764 | DeathRecipient deathRecipient = new DeathRecipient(); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 765 | mSeq = seq; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 766 | mPowerManagerWrapper = powerManagerWrapper; |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 767 | mForceSeamlesslyRotate = token.mRoundedCornerOverlay; |
Tiger Huang | 0dbd537 | 2019-10-26 00:24:22 +0800 | [diff] [blame] | 768 | mClientInsetsState = |
| 769 | getDisplayContent().getInsetsStateController().getInsetsForDispatch(this); |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 770 | if (DEBUG) { |
| 771 | Slog.v(TAG, "Window " + this + " client=" + c.asBinder() |
| 772 | + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); |
| 773 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 774 | try { |
| 775 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 776 | } catch (RemoteException e) { |
| 777 | mDeathRecipient = null; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 778 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 779 | mLayoutAttached = false; |
| 780 | mIsImWindow = false; |
| 781 | mIsWallpaper = false; |
| 782 | mIsFloatingLayer = false; |
| 783 | mBaseLayer = 0; |
| 784 | mSubLayer = 0; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 785 | mInputWindowHandle = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 786 | mWinAnimator = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 787 | return; |
| 788 | } |
| 789 | mDeathRecipient = deathRecipient; |
| 790 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 791 | if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 792 | // The multiplier here is to reserve space for multiple |
| 793 | // windows in the same type layer. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 794 | mBaseLayer = mPolicy.getWindowLayerLw(parentWindow) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 795 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 796 | mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 797 | mIsChildWindow = true; |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 798 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 799 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Adding %s to %s", this, parentWindow); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 800 | parentWindow.addChild(this, sWindowSubLayerComparator); |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 801 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 802 | mLayoutAttached = mAttrs.type != |
| 803 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
Wale Ogunwale | 7ed4d37 | 2016-07-09 15:28:55 -0700 | [diff] [blame] | 804 | mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 805 | || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 806 | mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 807 | } else { |
| 808 | // The multiplier here is to reserve space for multiple |
| 809 | // windows in the same type layer. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 810 | mBaseLayer = mPolicy.getWindowLayerLw(this) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 811 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 812 | mSubLayer = 0; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 813 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 814 | mLayoutAttached = false; |
| 815 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 816 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 817 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 818 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 819 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 820 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 821 | if (mActivityRecord != null && mActivityRecord.mShowForAllUsers) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 822 | // Windows for apps that can show for all users should also show when the device is |
| 823 | // locked. |
| 824 | mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED; |
Craig Mautner | 19ab828 | 2014-05-07 10:35:34 -0700 | [diff] [blame] | 825 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 826 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 827 | mWinAnimator = new WindowStateAnimator(this); |
| 828 | mWinAnimator.mAlpha = a.alpha; |
| 829 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 830 | mRequestedWidth = 0; |
| 831 | mRequestedHeight = 0; |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 832 | mLastRequestedWidth = 0; |
| 833 | mLastRequestedHeight = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 834 | mLayer = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 835 | mInputWindowHandle = new InputWindowHandle( |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 836 | mActivityRecord != null ? mActivityRecord.mInputApplicationHandle : null, |
| 837 | getDisplayId()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | void attach() { |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 841 | if (DEBUG) Slog.v(TAG, "Attaching " + this + " token=" + mToken); |
Wale Ogunwale | 387e4c6 | 2017-02-13 09:50:02 -0800 | [diff] [blame] | 842 | mSession.windowAddedLocked(mAttrs.packageName); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 843 | } |
| 844 | |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 845 | /** |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 846 | * @return {@code true} if the application runs in size compatibility mode. |
| 847 | * @see android.content.res.CompatibilityInfo#supportsScreen |
| 848 | * @see ActivityRecord#inSizeCompatMode |
| 849 | */ |
| 850 | boolean inSizeCompatMode() { |
| 851 | return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0 |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 852 | || (mActivityRecord != null && mActivityRecord.hasSizeCompatBounds() |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 853 | // Exclude starting window because it is not displayed by the application. |
| 854 | && mAttrs.type != TYPE_APPLICATION_STARTING); |
| 855 | } |
| 856 | |
| 857 | /** |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 858 | * Returns whether this {@link WindowState} has been considered for drawing by its parent. |
| 859 | */ |
Bryce Lee | 6311c4b | 2017-07-06 14:09:29 -0700 | [diff] [blame] | 860 | boolean getDrawnStateEvaluated() { |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 861 | return mDrawnStateEvaluated; |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should |
| 866 | * be cleared when detached from parent. |
| 867 | */ |
| 868 | void setDrawnStateEvaluated(boolean evaluated) { |
| 869 | mDrawnStateEvaluated = evaluated; |
| 870 | } |
| 871 | |
| 872 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 873 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
| 874 | super.onParentChanged(newParent, oldParent); |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 875 | setDrawnStateEvaluated(false /*evaluated*/); |
Robert Carr | 24be9ab | 2018-04-30 17:54:53 -0700 | [diff] [blame] | 876 | |
| 877 | getDisplayContent().reapplyMagnificationSpec(); |
Bryce Lee | d390deb | 2017-06-22 13:14:28 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 880 | @Override |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 881 | public int getOwningUid() { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 882 | return mOwnerUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | @Override |
| 886 | public String getOwningPackage() { |
| 887 | return mAttrs.packageName; |
| 888 | } |
| 889 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 890 | @Override |
| 891 | public boolean canAddInternalSystemWindow() { |
| 892 | return mOwnerCanAddInternalSystemWindow; |
| 893 | } |
| 894 | |
Jorim Jaggi | f12ec0f | 2017-08-23 16:14:10 +0200 | [diff] [blame] | 895 | @Override |
| 896 | public boolean canAcquireSleepToken() { |
| 897 | return mSession.mCanAcquireSleepToken; |
| 898 | } |
| 899 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 900 | /** |
| 901 | * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame} |
| 902 | * from {@param frame}. In other words, it applies the insets that would result if |
| 903 | * {@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] | 904 | * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum |
| 905 | * width/height applied and insets should be overridden. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 906 | */ |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 907 | private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) { |
| 908 | final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left)); |
| 909 | final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top)); |
| 910 | final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right); |
| 911 | 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] | 912 | frame.inset(left, top, right, bottom); |
| 913 | } |
| 914 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 915 | @Override |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 916 | public Rect getDisplayedBounds() { |
| 917 | final Task task = getTask(); |
| 918 | if (task != null) { |
| 919 | Rect bounds = task.getOverrideDisplayedBounds(); |
| 920 | if (!bounds.isEmpty()) { |
| 921 | return bounds; |
| 922 | } |
| 923 | } |
| 924 | return super.getDisplayedBounds(); |
| 925 | } |
| 926 | |
| 927 | @Override |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 928 | public void computeFrameLw() { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 929 | if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 930 | // This window is being replaced and either already got information that it's being |
| 931 | // removed or we are still waiting for some information. Because of this we don't |
| 932 | // want to apply any more changes to it, so it remains in this state until new window |
| 933 | // appears. |
| 934 | return; |
| 935 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 936 | mHaveFrame = true; |
| 937 | |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 938 | final Task task = getTask(); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 939 | final boolean isFullscreenAndFillsDisplay = !inMultiWindowMode() && matchesDisplayBounds(); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 940 | final boolean windowsAreFloating = task != null && task.isFloating(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 941 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 942 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 943 | mInsetFrame.set(getBounds()); |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 944 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 945 | // Denotes the actual frame used to calculate the insets and to perform the layout. When |
| 946 | // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the |
| 947 | // insets temporarily. By the notion of a task having a different layout frame, we can |
| 948 | // achieve that while still moving the task around. |
| 949 | final Rect layoutContainingFrame; |
| 950 | final Rect layoutDisplayFrame; |
| 951 | |
| 952 | // The offset from the layout containing frame to the actual containing frame. |
| 953 | final int layoutXDiff; |
| 954 | final int layoutYDiff; |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 955 | final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow(); |
| 956 | final boolean isImeTarget = |
| 957 | imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget(); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 958 | if (isFullscreenAndFillsDisplay || layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 959 | // 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] | 960 | mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame); |
| 961 | layoutDisplayFrame = mWindowFrames.mDisplayFrame; |
| 962 | layoutContainingFrame = mWindowFrames.mParentFrame; |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 963 | layoutXDiff = 0; |
| 964 | layoutYDiff = 0; |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 965 | } else { |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 966 | mWindowFrames.mContainingFrame.set(getDisplayedBounds()); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 967 | if (mActivityRecord != null && !mActivityRecord.mFrozenBounds.isEmpty()) { |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 968 | |
| 969 | // If the bounds are frozen, we still want to translate the window freely and only |
| 970 | // freeze the size. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 971 | Rect frozen = mActivityRecord.mFrozenBounds.peek(); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 972 | mWindowFrames.mContainingFrame.right = |
| 973 | mWindowFrames.mContainingFrame.left + frozen.width(); |
| 974 | mWindowFrames.mContainingFrame.bottom = |
| 975 | mWindowFrames.mContainingFrame.top + frozen.height(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 976 | } |
Robert Carr | fc03b2b | 2016-03-31 15:22:02 -0700 | [diff] [blame] | 977 | // IME is up and obscuring this window. Adjust the window position so it is visible. |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 978 | if (isImeTarget) { |
| 979 | if (inFreeformWindowingMode()) { |
| 980 | // Push the freeform window up to make room for the IME. However, don't push |
| 981 | // it up past the top of the screen. |
| 982 | final int bottomOverlap = mWindowFrames.mContainingFrame.bottom |
| 983 | - mWindowFrames.mVisibleFrame.bottom; |
| 984 | if (bottomOverlap > 0) { |
| 985 | final int distanceToTop = Math.max(mWindowFrames.mContainingFrame.top |
| 986 | - mWindowFrames.mDisplayFrame.top, 0); |
| 987 | int offs = Math.min(bottomOverlap, distanceToTop); |
| 988 | mWindowFrames.mContainingFrame.top -= offs; |
| 989 | } |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 990 | } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 991 | > mWindowFrames.mParentFrame.bottom) { |
Winson Chung | d73e94b | 2017-05-31 16:25:30 -0700 | [diff] [blame] | 992 | // But in docked we want to behave like fullscreen and behave as if the task |
| 993 | // were given smaller bounds for the purposes of layout. Skip adjustments for |
| 994 | // the pinned stack, they are handled separately in the PinnedStackController. |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 995 | mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom; |
Winson Chung | d73e94b | 2017-05-31 16:25:30 -0700 | [diff] [blame] | 996 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 997 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 998 | |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 999 | if (windowsAreFloating) { |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 1000 | // In floating modes (e.g. freeform, pinned) we have only to set the rectangle |
| 1001 | // 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] | 1002 | // "content frame" since it is allowed to be outside the visible desktop. |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1003 | if (mWindowFrames.mContainingFrame.isEmpty()) { |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1004 | mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 1005 | } |
Doris Liu | 06d582d | 2015-06-01 13:18:43 -0700 | [diff] [blame] | 1006 | } |
Adrian Roos | 604ef95 | 2018-05-15 20:13:13 +0200 | [diff] [blame] | 1007 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1008 | final ActivityStack stack = getStack(); |
Adrian Roos | 604ef95 | 2018-05-15 20:13:13 +0200 | [diff] [blame] | 1009 | if (inPinnedWindowingMode() && stack != null |
| 1010 | && stack.lastAnimatingBoundsWasToFullscreen()) { |
| 1011 | // PIP edge case: When going from pinned to fullscreen, we apply a |
| 1012 | // tempInsetFrame for the full task - but we're still at the start of the animation. |
| 1013 | // 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] | 1014 | mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame); |
| 1015 | mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame); |
Adrian Roos | 604ef95 | 2018-05-15 20:13:13 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1018 | layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1019 | mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame); |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 1020 | layoutXDiff = mInsetFrame.left - mWindowFrames.mContainingFrame.left; |
| 1021 | layoutYDiff = mInsetFrame.top - mWindowFrames.mContainingFrame.top; |
| 1022 | layoutContainingFrame = mInsetFrame; |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1023 | mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1024 | subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame, |
| 1025 | mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 1026 | if (!layoutInParentFrame()) { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1027 | subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame, |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1028 | mWindowFrames.mParentFrame, mTmpRect); |
| 1029 | subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame, |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1030 | mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 1031 | } |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 1032 | layoutDisplayFrame.intersect(layoutContainingFrame); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1033 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1034 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1035 | final int pw = mWindowFrames.mContainingFrame.width(); |
| 1036 | final int ph = mWindowFrames.mContainingFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1037 | |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 1038 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 1039 | mLastRequestedWidth = mRequestedWidth; |
| 1040 | mLastRequestedHeight = mRequestedHeight; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1041 | mWindowFrames.setContentChanged(true); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1042 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1043 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1044 | final int fw = mWindowFrames.mFrame.width(); |
| 1045 | final int fh = mWindowFrames.mFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1046 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 1047 | applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame); |
| 1048 | |
Craig Mautner | a248eee | 2013-05-07 11:41:27 -0700 | [diff] [blame] | 1049 | // Make sure the content and visible frames are inside of the |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1050 | // final window frame. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1051 | if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) { |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 1052 | final int visBottom = mWindowFrames.mVisibleFrame.bottom; |
| 1053 | final int contentBottom = mWindowFrames.mContentFrame.bottom; |
Evan Rosky | 60dba2f | 2019-02-01 10:58:38 -0800 | [diff] [blame] | 1054 | mWindowFrames.mContentFrame.set(mWindowFrames.mFrame); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1055 | mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame); |
| 1056 | mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame); |
Evan Rosky | 0d654cb | 2019-02-26 10:59:10 -0800 | [diff] [blame] | 1057 | if (isImeTarget && inFreeformWindowingMode()) { |
| 1058 | // After displacing a freeform window to make room for the ime, any part of |
| 1059 | // the window still covered by IME should be inset. |
| 1060 | if (contentBottom + layoutYDiff < mWindowFrames.mContentFrame.bottom) { |
| 1061 | mWindowFrames.mContentFrame.bottom = contentBottom + layoutYDiff; |
| 1062 | } |
| 1063 | if (visBottom + layoutYDiff < mWindowFrames.mVisibleFrame.bottom) { |
| 1064 | mWindowFrames.mVisibleFrame.bottom = visBottom + layoutYDiff; |
| 1065 | } |
| 1066 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 1067 | } else if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1068 | dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame); |
| 1069 | mWindowFrames.mContentFrame.set(mWindowFrames.mFrame); |
| 1070 | if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) { |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1071 | mMovedByResize = true; |
Filip Gruszczynski | ae10080 | 2015-11-11 15:58:03 -0800 | [diff] [blame] | 1072 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 1073 | } else { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1074 | mWindowFrames.mContentFrame.set( |
| 1075 | Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left), |
| 1076 | Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top), |
| 1077 | Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right), |
| 1078 | Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom)); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1079 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1080 | mWindowFrames.mVisibleFrame.set( |
| 1081 | Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left), |
| 1082 | Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top), |
| 1083 | Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right), |
| 1084 | Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1085 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1086 | mWindowFrames.mStableFrame.set( |
| 1087 | Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left), |
| 1088 | Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top), |
| 1089 | Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right), |
| 1090 | Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom)); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 1091 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1092 | |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 1093 | if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1094 | final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo( |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1095 | mWindowFrames.mDisplayFrame); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1096 | mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets()); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 1097 | } else { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1098 | getDisplayContent().getBounds(mTmpRect); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1099 | mWindowFrames.calculateInsets( |
| 1100 | windowsAreFloating, isFullscreenAndFillsDisplay, mTmpRect); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 1101 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1102 | |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 1103 | mWindowFrames.setDisplayCutout( |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1104 | mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame)); |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 1105 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 1106 | // Offset the actual frame by the amount layout frame is off. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1107 | mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 1108 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1109 | mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 1110 | if (inSizeCompatMode()) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1111 | // If there is a size compatibility scale being applied to the |
| 1112 | // window, we need to apply this to its insets so that they are |
| 1113 | // reported to the app in its coordinate space. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1114 | mWindowFrames.scaleInsets(mInvGlobalScale); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1115 | |
| 1116 | // Also the scaled frame that we report to the app needs to be |
| 1117 | // adjusted to be in its coordinate space. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1118 | mWindowFrames.mCompatFrame.scale(mInvGlobalScale); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1121 | if (mIsWallpaper && (fw != mWindowFrames.mFrame.width() |
| 1122 | || fh != mWindowFrames.mFrame.height())) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1123 | final DisplayContent displayContent = getDisplayContent(); |
| 1124 | if (displayContent != null) { |
| 1125 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1126 | getDisplayContent().mWallpaperController.updateWallpaperOffset(this, |
| 1127 | displayInfo.logicalWidth, displayInfo.logicalHeight, false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1128 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1129 | } |
| 1130 | |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 1131 | // Calculate relative frame |
| 1132 | mWindowFrames.mRelFrame.set(mWindowFrames.mFrame); |
| 1133 | WindowContainer parent = getParent(); |
| 1134 | int parentLeft = 0; |
| 1135 | int parentTop = 0; |
| 1136 | if (mIsChildWindow) { |
| 1137 | parentLeft = ((WindowState) parent).mWindowFrames.mFrame.left; |
| 1138 | parentTop = ((WindowState) parent).mWindowFrames.mFrame.top; |
| 1139 | } else if (parent != null) { |
| 1140 | final Rect parentBounds = parent.getDisplayedBounds(); |
| 1141 | parentLeft = parentBounds.left; |
| 1142 | parentTop = parentBounds.top; |
| 1143 | } |
| 1144 | mWindowFrames.mRelFrame.offsetTo(mWindowFrames.mFrame.left - parentLeft, |
| 1145 | mWindowFrames.mFrame.top - parentTop); |
| 1146 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 1147 | if (DEBUG_LAYOUT || DEBUG) { |
| 1148 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| 1149 | + mRequestedWidth + ", mRequestedheight=" |
| 1150 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 1151 | + "): frame=" + mWindowFrames.mFrame.toShortString() |
| 1152 | + " " + mWindowFrames.getInsetsInfo() |
| 1153 | + " " + mAttrs.getTitle()); |
| 1154 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1155 | } |
| 1156 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1157 | // TODO: Look into whether this override is still necessary. |
| 1158 | @Override |
| 1159 | public Rect getBounds() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1160 | if (mActivityRecord != null) { |
| 1161 | return mActivityRecord.getBounds(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1162 | } else { |
| 1163 | return super.getBounds(); |
| 1164 | } |
| 1165 | } |
| 1166 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1167 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1168 | public Rect getFrameLw() { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1169 | return mWindowFrames.mFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1170 | } |
| 1171 | |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 1172 | /** Accessor for testing */ |
| 1173 | Rect getRelativeFrameLw() { |
| 1174 | return mWindowFrames.mRelFrame; |
| 1175 | } |
| 1176 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1177 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1178 | public Rect getDisplayFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1179 | return mWindowFrames.mDisplayFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1180 | } |
| 1181 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1182 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1183 | public Rect getContentFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1184 | return mWindowFrames.mContentFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1185 | } |
| 1186 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1187 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1188 | public Rect getVisibleFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1189 | return mWindowFrames.mVisibleFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1190 | } |
| 1191 | |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 1192 | Rect getStableFrameLw() { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1193 | return mWindowFrames.mStableFrame; |
| 1194 | } |
| 1195 | |
| 1196 | Rect getDecorFrame() { |
| 1197 | return mWindowFrames.mDecorFrame; |
| 1198 | } |
| 1199 | |
| 1200 | Rect getParentFrame() { |
| 1201 | return mWindowFrames.mParentFrame; |
| 1202 | } |
| 1203 | |
| 1204 | Rect getContainingFrame() { |
| 1205 | return mWindowFrames.mContainingFrame; |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 1208 | WmDisplayCutout getWmDisplayCutout() { |
| 1209 | return mWindowFrames.mDisplayCutout; |
| 1210 | } |
| 1211 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1212 | void getCompatFrame(Rect outFrame) { |
| 1213 | outFrame.set(mWindowFrames.mCompatFrame); |
| 1214 | } |
| 1215 | |
| 1216 | void getCompatFrameSize(Rect outFrame) { |
| 1217 | outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height()); |
| 1218 | } |
| 1219 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1220 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1221 | public boolean getGivenInsetsPendingLw() { |
| 1222 | return mGivenInsetsPending; |
| 1223 | } |
| 1224 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1225 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1226 | public Rect getGivenContentInsetsLw() { |
| 1227 | return mGivenContentInsets; |
| 1228 | } |
| 1229 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1230 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1231 | public Rect getGivenVisibleInsetsLw() { |
| 1232 | return mGivenVisibleInsets; |
| 1233 | } |
| 1234 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1235 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1236 | public WindowManager.LayoutParams getAttrs() { |
| 1237 | return mAttrs; |
| 1238 | } |
| 1239 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1240 | @Override |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1241 | public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1242 | return getDisplayContent().getNeedsMenu(this, bottom); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1245 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1246 | public int getSystemUiVisibility() { |
| 1247 | return mSystemUiVisibility; |
| 1248 | } |
| 1249 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1250 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1251 | public int getSurfaceLayer() { |
| 1252 | return mLayer; |
| 1253 | } |
| 1254 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1255 | @Override |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1256 | public int getBaseType() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 1257 | return getTopParentWindow().mAttrs.type; |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1261 | public IApplicationToken getAppToken() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1262 | return mActivityRecord != null ? mActivityRecord.appToken : null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1263 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1264 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1265 | @Override |
| 1266 | public boolean isVoiceInteraction() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1267 | return mActivityRecord != null && mActivityRecord.mVoiceInteraction; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1270 | boolean setReportResizeHints() { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1271 | return mWindowFrames.setReportResizeHints(); |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1274 | /** |
| 1275 | * Adds the window to the resizing list if any of the parameters we use to track the window |
| 1276 | * dimensions or insets have changed. |
| 1277 | */ |
| 1278 | void updateResizingWindowIfNeeded() { |
| 1279 | final WindowStateAnimator winAnimator = mWinAnimator; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 1280 | if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1281 | return; |
| 1282 | } |
| 1283 | |
| 1284 | final Task task = getTask(); |
| 1285 | // In the case of stack bound animations, the window frames will update (unlike other |
| 1286 | // animations which just modify various transformation properties). We don't want to |
| 1287 | // notify the client of frame changes in this case. Not only is it a lot of churn, but |
| 1288 | // the frame may not correspond to the surface size or the onscreen area at various |
| 1289 | // phases in the animation, and the client will become sad and confused. |
Wale Ogunwale | 8577a05 | 2019-10-26 23:22:34 -0700 | [diff] [blame] | 1290 | if (task != null && task.getTaskStack().isAnimatingBounds()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1291 | return; |
| 1292 | } |
| 1293 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1294 | boolean didFrameInsetsChange = setReportResizeHints(); |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 1295 | boolean configChanged = !isLastConfigReportedToClient(); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1296 | if (DEBUG_CONFIGURATION && configChanged) { |
| 1297 | Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration()); |
| 1298 | } |
| 1299 | |
| 1300 | final boolean dragResizingChanged = isDragResizeChanged() |
| 1301 | && !isDragResizingChangeReported(); |
| 1302 | |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 1303 | if (DEBUG) { |
| 1304 | Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged |
| 1305 | + " dragResizingChanged=" + dragResizingChanged |
| 1306 | + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame); |
| 1307 | } |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1308 | |
| 1309 | // We update mLastFrame always rather than in the conditional with the last inset |
| 1310 | // variables, because mFrameSizeChanged only tracks the width and height changing. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1311 | mWindowFrames.mLastFrame.set(mWindowFrames.mFrame); |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 1312 | mWindowFrames.mLastRelFrame.set(mWindowFrames.mRelFrame); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1313 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 1314 | if (didFrameInsetsChange |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1315 | || winAnimator.mSurfaceResized |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1316 | || configChanged |
| 1317 | || dragResizingChanged |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1318 | || mReportOrientationChanged) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1319 | ProtoLog.v(WM_DEBUG_RESIZE, |
| 1320 | "Resize reasons for w=%s: %s surfaceResized=%b configChanged=%b " |
| 1321 | + "dragResizingChanged=%b reportOrientationChanged=%b", |
| 1322 | this, mWindowFrames.getInsetsChangedInfo(), winAnimator.mSurfaceResized, |
| 1323 | configChanged, dragResizingChanged, mReportOrientationChanged); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1324 | |
| 1325 | // If it's a dead window left on screen, and the configuration changed, there is nothing |
| 1326 | // we can do about it. Remove the window now. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1327 | if (mActivityRecord != null && mAppDied) { |
| 1328 | mActivityRecord.removeDeadWindows(); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1329 | return; |
| 1330 | } |
| 1331 | |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 1332 | updateLastInsetValues(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1333 | mWmService.makeWindowFreezingScreenIfNeededLocked(this); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1334 | |
| 1335 | // If the orientation is changing, or we're starting or ending a drag resizing action, |
| 1336 | // then we need to hold off on unfreezing the display until this window has been |
| 1337 | // redrawn; to do that, we need to go through the process of getting informed by the |
| 1338 | // application when it has finished drawing. |
Robert Carr | 09286c9 | 2018-02-15 13:52:31 -0800 | [diff] [blame] | 1339 | if (getOrientationChanging() || dragResizingChanged) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1340 | if (getOrientationChanging()) { |
| 1341 | Slog.v(TAG_WM, "Orientation start waiting for draw" |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1342 | + ", mDrawState=DRAW_PENDING in " + this |
| 1343 | + ", surfaceController " + winAnimator.mSurfaceController); |
| 1344 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1345 | if (dragResizingChanged) { |
| 1346 | ProtoLog.v(WM_DEBUG_RESIZE, |
| 1347 | "Resize start waiting for draw, " |
| 1348 | + "mDrawState=DRAW_PENDING in %s, surfaceController %s", |
| 1349 | this, winAnimator.mSurfaceController); |
| 1350 | } |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1351 | winAnimator.mDrawState = DRAW_PENDING; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1352 | if (mActivityRecord != null) { |
| 1353 | mActivityRecord.clearAllDrawn(); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1354 | } |
| 1355 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1356 | if (!mWmService.mResizingWindows.contains(this)) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1357 | ProtoLog.v(WM_DEBUG_RESIZE, "Resizing window %s", this); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1358 | mWmService.mResizingWindows.add(this); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1359 | } |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1360 | } else if (getOrientationChanging()) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1361 | if (isDrawnLw()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1362 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 1363 | "Orientation not waiting for draw in %s, surfaceController %s", this, |
| 1364 | winAnimator.mSurfaceController); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1365 | setOrientationChanging(false); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1366 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1367 | - mWmService.mDisplayFreezeTime); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | } |
| 1371 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1372 | boolean getOrientationChanging() { |
| 1373 | // In addition to the local state flag, we must also consider the difference in the last |
| 1374 | // reported configuration vs. the current state. If the client code has not been informed of |
| 1375 | // the change, logic dependent on having finished processing the orientation, such as |
| 1376 | // unfreezing, could be improperly triggered. |
| 1377 | // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as |
| 1378 | // this is not necessarily what the client has processed yet. Find a |
| 1379 | // better indicator consistent with the client. |
Robert Carr | 926643f | 2017-08-02 12:01:12 -0700 | [diff] [blame] | 1380 | return (mOrientationChanging || (isVisible() |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 1381 | && getConfiguration().orientation != getLastReportedConfiguration().orientation)) |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 1382 | && !mSeamlesslyRotated |
| 1383 | && !mOrientationChangeTimedOut; |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | void setOrientationChanging(boolean changing) { |
| 1387 | mOrientationChanging = changing; |
Robert Carr | 9c1c3a0 | 2017-08-08 12:59:01 -0700 | [diff] [blame] | 1388 | mOrientationChangeTimedOut = false; |
| 1389 | } |
| 1390 | |
| 1391 | void orientationChangeTimedOut() { |
| 1392 | mOrientationChangeTimedOut = true; |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 1395 | @Override |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1396 | DisplayContent getDisplayContent() { |
| 1397 | return mToken.getDisplayContent(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1398 | } |
| 1399 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 1400 | @Override |
| 1401 | void onDisplayChanged(DisplayContent dc) { |
| 1402 | super.onDisplayChanged(dc); |
| 1403 | // Window was not laid out for this display yet, so make sure mLayoutSeq does not match. |
Garfield Tan | e223e68 | 2019-04-15 09:59:25 -0700 | [diff] [blame] | 1404 | if (dc != null && mInputWindowHandle.displayId != dc.getDisplayId()) { |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 1405 | mLayoutSeq = dc.mLayoutSeq - 1; |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 1406 | mInputWindowHandle.displayId = dc.getDisplayId(); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 1407 | } |
| 1408 | } |
| 1409 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1410 | DisplayInfo getDisplayInfo() { |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 1411 | final DisplayContent displayContent = getDisplayContent(); |
| 1412 | return displayContent != null ? displayContent.getDisplayInfo() : null; |
| 1413 | } |
| 1414 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1415 | @Override |
| 1416 | public int getDisplayId() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1417 | final DisplayContent displayContent = getDisplayContent(); |
| 1418 | if (displayContent == null) { |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 1419 | return Display.INVALID_DISPLAY; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1420 | } |
| 1421 | return displayContent.getDisplayId(); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1424 | Task getTask() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1425 | return mActivityRecord != null ? mActivityRecord.getTask() : null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1428 | ActivityStack getStack() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1429 | Task task = getTask(); |
| 1430 | if (task != null) { |
Wale Ogunwale | 8577a05 | 2019-10-26 23:22:34 -0700 | [diff] [blame] | 1431 | if (task.getTaskStack() != null) { |
| 1432 | return task.getTaskStack(); |
Craig Mautner | f06b8c1 | 2013-04-18 14:27:28 -0700 | [diff] [blame] | 1433 | } |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1434 | } |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1435 | // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still |
| 1436 | // associate them with some stack to enable dimming. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1437 | final DisplayContent dc = getDisplayContent(); |
| 1438 | return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1441 | /** |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1442 | * Retrieves the visible bounds of the window. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1443 | * @param bounds The rect which gets the bounds. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1444 | */ |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1445 | void getVisibleBounds(Rect bounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1446 | final Task task = getTask(); |
| 1447 | boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds(); |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1448 | bounds.setEmpty(); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1449 | mTmpRect.setEmpty(); |
| 1450 | if (intersectWithStackBounds) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 1451 | final ActivityStack stack = task.getTaskStack(); |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1452 | if (stack != null) { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1453 | stack.getDimBounds(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1454 | } else { |
| 1455 | intersectWithStackBounds = false; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1456 | } |
| 1457 | } |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1458 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 1459 | bounds.set(mWindowFrames.mVisibleFrame); |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1460 | if (intersectWithStackBounds) { |
| 1461 | bounds.intersect(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1464 | if (bounds.isEmpty()) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1465 | bounds.set(mWindowFrames.mFrame); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1466 | if (intersectWithStackBounds) { |
| 1467 | bounds.intersect(mTmpRect); |
| 1468 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1469 | return; |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1470 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1473 | public long getInputDispatchingTimeoutNanos() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1474 | return mActivityRecord != null |
| 1475 | ? mActivityRecord.mInputDispatchingTimeoutNanos |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1476 | : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 1477 | } |
| 1478 | |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1479 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1480 | public boolean hasAppShownWindows() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1481 | return mActivityRecord != null && (mActivityRecord.firstWindowDrawn || mActivityRecord.startingDisplayed); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1482 | } |
| 1483 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1484 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 1485 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 1486 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 1487 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 1488 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 1489 | return true; |
| 1490 | } |
| 1491 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1492 | void prelayout() { |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 1493 | if (inSizeCompatMode()) { |
| 1494 | mGlobalScale = mToken.getSizeCompatScale(); |
Andrii Kulian | 06d07d6 | 2017-03-14 11:11:47 -0700 | [diff] [blame] | 1495 | mInvGlobalScale = 1 / mGlobalScale; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1496 | } else { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1497 | mGlobalScale = mInvGlobalScale = 1; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1498 | } |
| 1499 | } |
| 1500 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1501 | @Override |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1502 | boolean hasContentToDisplay() { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1503 | if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1504 | || (isAnimating(TRANSITION | PARENTS) |
| 1505 | && !getDisplayContent().mAppTransition.isTransitionSet()))) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1506 | return true; |
| 1507 | } |
| 1508 | |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1509 | return super.hasContentToDisplay(); |
| 1510 | } |
| 1511 | |
| 1512 | @Override |
| 1513 | boolean isVisible() { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1514 | return wouldBeVisibleIfPolicyIgnored() && isVisibleByPolicy() |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 1515 | // If we don't have a provider, this window isn't used as a window generating |
| 1516 | // insets, so nobody can hide it over the inset APIs. |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 1517 | && (mControllableInsetProvider == null |
| 1518 | || mControllableInsetProvider.isClientVisible()); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1521 | /** |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1522 | * Ensures that all the policy visibility bits are set. |
| 1523 | * @return {@code true} if all flags about visiblity are set |
| 1524 | */ |
| 1525 | boolean isVisibleByPolicy() { |
| 1526 | return (mPolicyVisibility & POLICY_VISIBILITY_ALL) == POLICY_VISIBILITY_ALL; |
| 1527 | } |
| 1528 | |
| 1529 | void clearPolicyVisibilityFlag(int policyVisibilityFlag) { |
| 1530 | mPolicyVisibility &= ~policyVisibilityFlag; |
chaviw | bb6bd8a | 2019-05-28 17:05:28 -0700 | [diff] [blame] | 1531 | mWmService.scheduleAnimationLocked(); |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | void setPolicyVisibilityFlag(int policyVisibilityFlag) { |
| 1535 | mPolicyVisibility |= policyVisibilityFlag; |
chaviw | bb6bd8a | 2019-05-28 17:05:28 -0700 | [diff] [blame] | 1536 | mWmService.scheduleAnimationLocked(); |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | private boolean isLegacyPolicyVisibility() { |
| 1540 | return (mPolicyVisibility & LEGACY_POLICY_VISIBILITY) != 0; |
| 1541 | } |
| 1542 | |
| 1543 | /** |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 1544 | * @return {@code true} if the window would be visible if we'd ignore policy visibility, |
| 1545 | * {@code false} otherwise. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1546 | */ |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1547 | boolean wouldBeVisibleIfPolicyIgnored() { |
Jorim Jaggi | 43530c9 | 2017-05-18 01:53:56 +0200 | [diff] [blame] | 1548 | return mHasSurface && !isParentWindowHidden() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1549 | && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1552 | @Override |
| 1553 | public boolean isVisibleLw() { |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1554 | return isVisible(); |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1558 | * Is this window visible, ignoring its app token? It is not visible if there is no surface, |
| 1559 | * 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] | 1560 | */ |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1561 | // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this? |
| 1562 | boolean isWinVisibleLw() { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 1563 | return (mActivityRecord == null || mActivityRecord.mVisibleRequested |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1564 | || mActivityRecord.isAnimating(TRANSITION)) && isVisible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1568 | * The same as isVisible(), but follows the current hidden state of the associated app token, |
| 1569 | * not the pending requested hidden state. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1570 | */ |
| 1571 | boolean isVisibleNow() { |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 1572 | return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING) |
Jorim Jaggi | c6ae42a | 2017-05-08 23:42:02 +0200 | [diff] [blame] | 1573 | && isVisible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | /** |
| 1577 | * Can this window possibly be a drag/drop target? The test here is |
| 1578 | * a combination of the above "visible now" with the check that the |
| 1579 | * Input Manager uses when discarding windows from input consideration. |
| 1580 | */ |
| 1581 | boolean isPotentialDragTarget() { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1582 | return isVisibleNow() && !mRemoved |
| 1583 | && mInputChannel != null && mInputWindowHandle != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * Same as isVisible(), but we also count it as visible between the |
| 1588 | * call to IWindowSession.add() and the first relayout(). |
| 1589 | */ |
| 1590 | boolean isVisibleOrAdding() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1591 | final ActivityRecord atoken = mActivityRecord; |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 1592 | return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1593 | && isVisibleByPolicy() && !isParentWindowHidden() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 1594 | && (atoken == null || atoken.mVisibleRequested) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1595 | && !mAnimatingExit && !mDestroying; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | /** |
| 1599 | * Is this window currently on-screen? It is on-screen either if it |
| 1600 | * is visible or it is currently running an animation before no longer |
| 1601 | * being visible. |
| 1602 | */ |
| 1603 | boolean isOnScreen() { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1604 | if (!mHasSurface || mDestroying || !isVisibleByPolicy()) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1605 | return false; |
| 1606 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1607 | final ActivityRecord atoken = mActivityRecord; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1608 | if (atoken != null) { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 1609 | return ((!isParentWindowHidden() && atoken.mVisibleRequested) |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1610 | || isAnimating(TRANSITION | PARENTS)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1611 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1612 | return !isParentWindowHidden() || isAnimating(TRANSITION | PARENTS); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | /** |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1616 | * Whether this window's drawn state might affect the drawn states of the app token. |
| 1617 | * |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1618 | * @return true if the window should be considered while evaluating allDrawn flags. |
| 1619 | */ |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1620 | boolean mightAffectAllDrawn() { |
| 1621 | final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION |
| 1622 | || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION; |
| 1623 | return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * Whether this window is "interesting" when evaluating allDrawn. If it's interesting, |
| 1628 | * it must be drawn before allDrawn can become true. |
| 1629 | */ |
| 1630 | boolean isInteresting() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1631 | return mActivityRecord != null && !mAppDied |
| 1632 | && (!mActivityRecord.isFreezingScreen() || !mAppFreezing) |
Jorim Jaggi | 995e106 | 2019-06-06 14:03:41 +0200 | [diff] [blame] | 1633 | && mViewVisibility == View.VISIBLE; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1637 | * Like isOnScreen(), but we don't return true if the window is part |
| 1638 | * of a transition that has not yet been started. |
| 1639 | */ |
| 1640 | boolean isReadyForDisplay() { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1641 | if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1642 | return false; |
| 1643 | } |
Jorim Jaggi | 5bdccba | 2018-08-13 16:40:49 +0200 | [diff] [blame] | 1644 | final boolean parentAndClientVisible = !isParentWindowHidden() |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 1645 | && mViewVisibility == View.VISIBLE && !mToken.isHidden(); |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1646 | return mHasSurface && isVisibleByPolicy() && !mDestroying |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1647 | && (parentAndClientVisible || isAnimating(TRANSITION | PARENTS)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1648 | } |
| 1649 | |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1650 | // TODO: Another visibility method that was added late in the release to minimize risk. |
| 1651 | @Override |
| 1652 | public boolean canAffectSystemUiFlags() { |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1653 | final boolean translucent = mAttrs.alpha == 0.0f; |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 1654 | if (translucent) { |
| 1655 | return false; |
| 1656 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1657 | if (mActivityRecord == null) { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1658 | final boolean shown = mWinAnimator.getShown(); |
| 1659 | final boolean exiting = mAnimatingExit || mDestroying; |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 1660 | return shown && !exiting; |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1661 | } else { |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 1662 | final Task task = getTask(); |
| 1663 | final boolean canFromTask = task != null && task.canAffectSystemUiFlags(); |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 1664 | return canFromTask && !mActivityRecord.isHidden(); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 1665 | } |
Jorim Jaggi | 23cc9aa | 2017-05-23 16:05:35 +0200 | [diff] [blame] | 1666 | } |
| 1667 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1668 | /** |
| 1669 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 1670 | * been drawn. |
| 1671 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1672 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1673 | public boolean isDisplayedLw() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1674 | final ActivityRecord atoken = mActivityRecord; |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 1675 | return isDrawnLw() && isVisibleByPolicy() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 1676 | && ((!isParentWindowHidden() && (atoken == null || atoken.mVisibleRequested)) |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1677 | || isAnimating(TRANSITION | PARENTS)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1678 | } |
| 1679 | |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1680 | /** |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1681 | * Return true if this window or its app token is currently animating. |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1682 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1683 | @Override |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1684 | public boolean isAnimatingLw() { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1685 | return isAnimating(TRANSITION | PARENTS); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1688 | @Override |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1689 | public boolean isGoneForLayoutLw() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 1690 | final ActivityRecord atoken = mActivityRecord; |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1691 | return mViewVisibility == View.GONE |
| 1692 | || !mRelayoutCalled |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 1693 | || (atoken == null && mToken.isHidden()) |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 1694 | || (atoken != null && !atoken.mVisibleRequested) |
Jorim Jaggi | b52b045 | 2019-07-16 17:43:15 +0200 | [diff] [blame] | 1695 | || isParentWindowGoneForLayout() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1696 | || (mAnimatingExit && !isAnimatingLw()) |
Craig Mautner | 0e415c6 | 2013-04-29 16:10:58 -0700 | [diff] [blame] | 1697 | || mDestroying; |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1698 | } |
| 1699 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1700 | /** |
| 1701 | * Returns true if the window has a surface that it has drawn a |
| 1702 | * complete UI in to. |
| 1703 | */ |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1704 | public boolean isDrawFinishedLw() { |
| 1705 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1706 | (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING |
| 1707 | || mWinAnimator.mDrawState == READY_TO_SHOW |
| 1708 | || mWinAnimator.mDrawState == HAS_DRAWN); |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | /** |
| 1712 | * Returns true if the window has a surface that it has drawn a |
| 1713 | * complete UI in to. |
| 1714 | */ |
Adrian Roos | 76d2fe4 | 2015-07-09 14:54:08 -0700 | [diff] [blame] | 1715 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1716 | public boolean isDrawnLw() { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1717 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1718 | (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * Return true if the window is opaque and fully drawn. This indicates |
| 1723 | * it may obscure windows behind it. |
| 1724 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1725 | private boolean isOpaqueDrawn() { |
Chong Zhang | 66bf071d | 2016-02-05 14:42:36 -0800 | [diff] [blame] | 1726 | // When there is keyguard, wallpaper could be placed over the secure app |
| 1727 | // window but invisible. We need to check wallpaper visibility explicitly |
| 1728 | // to determine if it's occluding apps. |
| 1729 | return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE) |
| 1730 | || (mIsWallpaper && mWallpaperVisible)) |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1731 | && isDrawnLw() && !isAnimating(TRANSITION | PARENTS); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1732 | } |
| 1733 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1734 | @Override |
| 1735 | void onMovedByResize() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1736 | ProtoLog.d(WM_DEBUG_RESIZE, "onMovedByResize: Moving %s", this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1737 | mMovedByResize = true; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1738 | super.onMovedByResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) { |
| 1742 | boolean changed = false; |
| 1743 | |
| 1744 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1745 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1746 | changed |= c.onAppVisibilityChanged(visible, runningAppAnimation); |
| 1747 | } |
| 1748 | |
| 1749 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 1750 | // Starting window that's exiting will be removed when the animation finishes. |
| 1751 | // Mark all relevant flags for that onExitAnimationDone will proceed all the way |
| 1752 | // to actually remove it. |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1753 | if (!visible && isVisibleNow() && mActivityRecord.isAnimating(TRANSITION)) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1754 | mAnimatingExit = true; |
| 1755 | mRemoveOnExit = true; |
| 1756 | mWindowRemovalAllowed = true; |
| 1757 | } |
| 1758 | return changed; |
| 1759 | } |
| 1760 | |
chaviw | e390cbd | 2018-04-16 15:29:38 -0700 | [diff] [blame] | 1761 | final boolean isVisibleNow = isVisibleNow(); |
| 1762 | if (visible != isVisibleNow) { |
| 1763 | // Run exit animation if: |
| 1764 | // 1. App visibility and WS visibility are different |
| 1765 | // 2. App is not running an animation |
| 1766 | // 3. WS is currently visible |
| 1767 | if (!runningAppAnimation && isVisibleNow) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1768 | final AccessibilityController accessibilityController = |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1769 | mWmService.mAccessibilityController; |
chaviw | e390cbd | 2018-04-16 15:29:38 -0700 | [diff] [blame] | 1770 | final int winTransit = TRANSIT_EXIT; |
| 1771 | mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */); |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1772 | if (accessibilityController != null) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1773 | accessibilityController.onWindowTransitionLocked(this, winTransit); |
| 1774 | } |
| 1775 | } |
| 1776 | changed = true; |
| 1777 | setDisplayLayoutNeeded(); |
| 1778 | } |
| 1779 | |
| 1780 | return changed; |
| 1781 | } |
| 1782 | |
| 1783 | boolean onSetAppExiting() { |
| 1784 | final DisplayContent displayContent = getDisplayContent(); |
| 1785 | boolean changed = false; |
| 1786 | |
| 1787 | if (isVisibleNow()) { |
| 1788 | mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false); |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 1789 | if (mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1790 | mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1791 | } |
| 1792 | changed = true; |
| 1793 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1794 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1799 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1800 | changed |= c.onSetAppExiting(); |
| 1801 | } |
| 1802 | |
| 1803 | return changed; |
| 1804 | } |
| 1805 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1806 | @Override |
| 1807 | void onResize() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1808 | final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows; |
Andrii Kulian | 3dcdf64 | 2018-05-23 17:14:00 -0700 | [diff] [blame] | 1809 | if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1810 | ProtoLog.d(WM_DEBUG_RESIZE, "onResize: Resizing %s", this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1811 | resizingWindows.add(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1812 | } |
| 1813 | if (isGoneForLayoutLw()) { |
| 1814 | mResizedWhileGone = true; |
| 1815 | } |
| 1816 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1817 | super.onResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | void onUnfreezeBounds() { |
| 1821 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1822 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1823 | c.onUnfreezeBounds(); |
| 1824 | } |
| 1825 | |
| 1826 | if (!mHasSurface) { |
| 1827 | return; |
| 1828 | } |
| 1829 | |
| 1830 | mLayoutNeeded = true; |
| 1831 | setDisplayLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1832 | if (!mWmService.mResizingWindows.contains(this)) { |
| 1833 | mWmService.mResizingWindows.add(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1834 | } |
| 1835 | } |
| 1836 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1837 | /** |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1838 | * If the window has moved due to its containing content frame changing, then notify the |
| 1839 | * listeners and optionally animate it. Simply checking a change of position is not enough, |
| 1840 | * because being move due to dock divider is not a trigger for animation. |
| 1841 | */ |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 1842 | void handleWindowMovedIfNeeded() { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1843 | if (!hasMoved()) { |
| 1844 | return; |
| 1845 | } |
| 1846 | |
| 1847 | // Frame has moved, containing content frame has also moved, and we're not currently |
| 1848 | // animating... let's do something. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1849 | final int left = mWindowFrames.mFrame.left; |
| 1850 | final int top = mWindowFrames.mFrame.top; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1851 | final Task task = getTask(); |
| 1852 | final boolean adjustedForMinimizedDockOrIme = task != null |
Wale Ogunwale | 8577a05 | 2019-10-26 23:22:34 -0700 | [diff] [blame] | 1853 | && (task.getTaskStack().isAdjustedForMinimizedDockedStack() |
| 1854 | || task.getTaskStack().isAdjustedForIme()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1855 | if (mToken.okToAnimate() |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1856 | && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0 |
| 1857 | && !isDragResizing() && !adjustedForMinimizedDockOrIme |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 1858 | && getWindowConfiguration().hasMovementAnimations() |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 1859 | && !mWinAnimator.mLastHidden |
| 1860 | && !mSeamlesslyRotated) { |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 1861 | startMoveAnimation(left, top); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Jacky Kao | f93252b | 2019-07-18 15:19:52 +0800 | [diff] [blame] | 1864 | if (mWmService.mAccessibilityController != null) { |
| 1865 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(getDisplayId()); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1866 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 1867 | updateLocationInParentDisplayIfNeeded(); |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1868 | |
| 1869 | try { |
| 1870 | mClient.moved(left, top); |
| 1871 | } catch (RemoteException e) { |
| 1872 | } |
| 1873 | mMovedByResize = false; |
| 1874 | } |
| 1875 | |
| 1876 | /** |
Craig Mautner | 4557c08 | 2015-04-27 13:07:40 -0700 | [diff] [blame] | 1877 | * Return whether this window has moved. (Only makes |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1878 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 1879 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1880 | private boolean hasMoved() { |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 1881 | return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize) |
Robert Carr | c67c2a9 | 2016-09-22 13:25:45 -0700 | [diff] [blame] | 1882 | && !mAnimatingExit |
Evan Rosky | 7021370 | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 1883 | && (mWindowFrames.mRelFrame.top != mWindowFrames.mLastRelFrame.top |
| 1884 | || mWindowFrames.mRelFrame.left != mWindowFrames.mLastRelFrame.left) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1885 | && (!mIsChildWindow || !getParentWindow().hasMoved()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1886 | } |
| 1887 | |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1888 | boolean isObscuringDisplay() { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1889 | Task task = getTask(); |
Wale Ogunwale | 8577a05 | 2019-10-26 23:22:34 -0700 | [diff] [blame] | 1890 | if (task != null && task.getTaskStack() != null && !task.getTaskStack().fillsParent()) { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1891 | return false; |
| 1892 | } |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1893 | return isOpaqueDrawn() && fillsDisplay(); |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1894 | } |
| 1895 | |
Wale Ogunwale | ca9e061 | 2016-12-02 07:45:59 -0800 | [diff] [blame] | 1896 | boolean fillsDisplay() { |
| 1897 | final DisplayInfo displayInfo = getDisplayInfo(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 1898 | return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0 |
| 1899 | && mWindowFrames.mFrame.right >= displayInfo.appWidth |
| 1900 | && mWindowFrames.mFrame.bottom >= displayInfo.appHeight; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1901 | } |
| 1902 | |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 1903 | private boolean matchesDisplayBounds() { |
| 1904 | return getDisplayContent().getBounds().equals(getBounds()); |
| 1905 | } |
| 1906 | |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 1907 | /** |
| 1908 | * @return {@code true} if last applied config was reported to the client already, {@code false} |
| 1909 | * otherwise. |
| 1910 | */ |
| 1911 | boolean isLastConfigReportedToClient() { |
| 1912 | return mLastConfigReportedToClient; |
| 1913 | } |
| 1914 | |
| 1915 | @Override |
| 1916 | void onMergedOverrideConfigurationChanged() { |
| 1917 | super.onMergedOverrideConfigurationChanged(); |
| 1918 | mLastConfigReportedToClient = false; |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1921 | void onWindowReplacementTimeout() { |
| 1922 | if (mWillReplaceWindow) { |
| 1923 | // Since the window already timed out, remove it immediately now. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1924 | // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1925 | // delays removal on certain conditions, which will leave the stale window in the |
| 1926 | // stack and marked mWillReplaceWindow=false, so the window will never be removed. |
| 1927 | // |
| 1928 | // Also removes child windows. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1929 | removeImmediately(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1930 | } else { |
| 1931 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1932 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1933 | c.onWindowReplacementTimeout(); |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1938 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1939 | void forceWindowsScaleableInTransaction(boolean force) { |
| 1940 | if (mWinAnimator != null && mWinAnimator.hasSurface()) { |
| 1941 | mWinAnimator.mSurfaceController.forceScaleableInTransaction(force); |
| 1942 | } |
| 1943 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1944 | super.forceWindowsScaleableInTransaction(force); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1947 | @Override |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1948 | void removeImmediately() { |
| 1949 | super.removeImmediately(); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1950 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1951 | if (mRemoved) { |
| 1952 | // Nothing to do. |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 1953 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
| 1954 | "WS.removeImmediately: %s Already removed...", this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1955 | return; |
| 1956 | } |
| 1957 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1958 | mRemoved = true; |
| 1959 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1960 | mWillReplaceWindow = false; |
| 1961 | if (mReplacementWindow != null) { |
| 1962 | mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false; |
| 1963 | } |
| 1964 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1965 | final DisplayContent dc = getDisplayContent(); |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 1966 | if (isInputMethodTarget()) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1967 | dc.computeImeTarget(true /* updateImeTarget */); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | final int type = mAttrs.type; |
| 1971 | if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 1972 | dc.mTapExcludedWindows.remove(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1973 | } |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 1974 | if (mTapExcludeRegionHolder != null) { |
| 1975 | // If a tap exclude region container was initialized for this window, then it should've |
| 1976 | // also been registered in display. |
| 1977 | dc.mTapExcludeProvidingWindows.remove(this); |
| 1978 | } |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1979 | dc.getDisplayPolicy().removeWindowLw(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1980 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1981 | disposeInputChannel(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1982 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1983 | mWinAnimator.destroyDeferredSurfaceLocked(); |
| 1984 | mWinAnimator.destroySurfaceLocked(); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 1985 | mSession.windowRemovedLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1986 | try { |
| 1987 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 1988 | } catch (RuntimeException e) { |
| 1989 | // Ignore if it has already been removed (usually because |
| 1990 | // we are doing this as part of processing a death note.) |
| 1991 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1992 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1993 | mWmService.postWindowRemoveCleanupLocked(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1994 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1995 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1996 | @Override |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1997 | void removeIfPossible() { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1998 | super.removeIfPossible(); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1999 | removeIfPossible(false /*keepVisibleDeadWindow*/); |
| 2000 | } |
| 2001 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 2002 | private void removeIfPossible(boolean keepVisibleDeadWindow) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2003 | mWindowRemovalAllowed = true; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2004 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
| 2005 | "removeIfPossible: %s callers=%s", this, Debug.getCallers(5)); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2006 | |
| 2007 | final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2008 | if (startingWindow) { |
| 2009 | ProtoLog.d(WM_DEBUG_STARTING_WINDOW, "Starting window removed %s", this); |
Adam Pardyl | 8c2d19c | 2019-09-16 17:15:38 +0200 | [diff] [blame] | 2010 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2011 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2012 | ProtoLog.v(WM_DEBUG_FOCUS, "Remove client=%x, surfaceController=%s Callers=%s", |
| 2013 | System.identityHashCode(mClient.asBinder()), |
| 2014 | mWinAnimator.mSurfaceController, |
| 2015 | Debug.getCallers(5)); |
| 2016 | |
| 2017 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2018 | final long origId = Binder.clearCallingIdentity(); |
| 2019 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2020 | try { |
| 2021 | disposeInputChannel(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2022 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2023 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS, |
| 2024 | "Remove %s: mSurfaceController=%s mAnimatingExit=%b mRemoveOnExit=%b " |
| 2025 | + "mHasSurface=%b surfaceShowing=%b animating=%b app-animation=%b " |
Issei Suzuki | 860fbc0 | 2019-10-31 16:49:35 +0100 | [diff] [blame] | 2026 | + "mWillReplaceWindow=%b mDisplayFrozen=%b callers=%s", |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2027 | this, mWinAnimator.mSurfaceController, mAnimatingExit, mRemoveOnExit, |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2028 | mHasSurface, mWinAnimator.getShown(), |
| 2029 | isAnimating(TRANSITION | PARENTS), |
| 2030 | mActivityRecord != null && mActivityRecord.isAnimating(TRANSITION), |
| 2031 | mWillReplaceWindow, |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2032 | mWmService.mDisplayFrozen, Debug.getCallers(6)); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2033 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2034 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2035 | boolean wasVisible = false; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2036 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2037 | // First, see if we need to run an animation. If we do, we have to hold off on removing the |
| 2038 | // window until the animation is done. If the display is frozen, just remove immediately, |
| 2039 | // since the animation wouldn't be seen. |
| 2040 | if (mHasSurface && mToken.okToAnimate()) { |
| 2041 | if (mWillReplaceWindow) { |
| 2042 | // This window is going to be replaced. We need to keep it around until the new one |
| 2043 | // gets added, then we will get rid of this one. |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2044 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
| 2045 | "Preserving %s until the new one is added", this); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2046 | // TODO: We are overloading mAnimatingExit flag to prevent the window state from |
| 2047 | // been removed. We probably need another flag to indicate that window removal |
| 2048 | // should be deffered vs. overloading the flag that says we are playing an exit |
| 2049 | // animation. |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2050 | mAnimatingExit = true; |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2051 | mReplacingRemoveRequested = true; |
| 2052 | return; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2053 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2054 | |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2055 | // If we are not currently running the exit animation, we need to see about starting one |
| 2056 | wasVisible = isWinVisibleLw(); |
| 2057 | |
| 2058 | if (keepVisibleDeadWindow) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2059 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
| 2060 | "Not removing %s because app died while it's visible", this); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2061 | |
| 2062 | mAppDied = true; |
| 2063 | setDisplayLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2064 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2065 | |
| 2066 | // Set up a replacement input channel since the app is now dead. |
| 2067 | // We need to catch tapping on the dead window to restart the app. |
| 2068 | openInputChannel(null); |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2069 | getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2070 | return; |
| 2071 | } |
| 2072 | |
| 2073 | if (wasVisible) { |
| 2074 | final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE; |
| 2075 | |
| 2076 | // Try starting an animation. |
| 2077 | if (mWinAnimator.applyAnimationLocked(transit, false)) { |
| 2078 | mAnimatingExit = true; |
Jorim Jaggi | f41e882 | 2018-04-06 17:22:03 +0200 | [diff] [blame] | 2079 | |
| 2080 | // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that |
| 2081 | // any change from that is performed immediately. |
| 2082 | setDisplayLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2083 | mWmService.requestTraversal(); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2084 | } |
Rhed Jao | 02655dc | 2018-10-30 20:44:52 +0800 | [diff] [blame] | 2085 | if (mWmService.mAccessibilityController != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2086 | mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2087 | } |
| 2088 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2089 | final boolean isAnimating = isAnimating(TRANSITION | PARENTS) |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2090 | && (mActivityRecord == null || !mActivityRecord.isWaitingForTransitionStart()); |
| 2091 | final boolean lastWindowIsStartingWindow = startingWindow && mActivityRecord != null |
| 2092 | && mActivityRecord.isLastWindow(this); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2093 | // We delay the removal of a window if it has a showing surface that can be used to run |
| 2094 | // exit animation and it is marked as exiting. |
| 2095 | // Also, If isn't the an animating starting window that is the last window in the app. |
| 2096 | // We allow the removal of the non-animating starting window now as there is no |
| 2097 | // additional window or animation that will trigger its removal. |
| 2098 | if (mWinAnimator.getShown() && mAnimatingExit |
| 2099 | && (!lastWindowIsStartingWindow || isAnimating)) { |
| 2100 | // The exit animation is running or should run... wait for it! |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2101 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, |
| 2102 | "Not removing %s due to exit animation", this); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2103 | setupWindowForRemoveOnExit(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2104 | if (mActivityRecord != null) { |
| 2105 | mActivityRecord.updateReportedVisibilityLocked(); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2106 | } |
| 2107 | return; |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | removeImmediately(); |
| 2112 | // Removing a visible window will effect the computed orientation |
| 2113 | // So just update orientation if needed. |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 2114 | if (wasVisible) { |
| 2115 | final DisplayContent displayContent = getDisplayContent(); |
Riddle Hsu | ccf0940 | 2019-08-13 00:33:06 +0800 | [diff] [blame] | 2116 | if (displayContent.updateOrientation()) { |
Shivam Agrawal | 6472e0e | 2019-07-03 16:27:49 -0700 | [diff] [blame] | 2117 | displayContent.sendNewConfiguration(); |
Riddle Hsu | 4e61177 | 2018-10-31 18:58:28 +0800 | [diff] [blame] | 2118 | } |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2119 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2120 | mWmService.updateFocusedWindowLocked(isFocused() |
Tiger Huang | 8af6ba4 | 2018-06-07 19:24:09 +0800 | [diff] [blame] | 2121 | ? UPDATE_FOCUS_REMOVING_FOCUS |
| 2122 | : UPDATE_FOCUS_NORMAL, |
| 2123 | true /*updateInputWindows*/); |
Peter Visontay | 3556a3b | 2017-11-01 17:23:17 +0000 | [diff] [blame] | 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(origId); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2126 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | private void setupWindowForRemoveOnExit() { |
| 2130 | mRemoveOnExit = true; |
| 2131 | setDisplayLayoutNeeded(); |
| 2132 | // Request a focus update as this window's input channel is already gone. Otherwise |
| 2133 | // we could have no focused window in input manager. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2134 | final boolean focusChanged = mWmService.updateFocusedWindowLocked( |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2135 | UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2136 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2137 | if (focusChanged) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 2138 | getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2139 | } |
| 2140 | } |
| 2141 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 2142 | void setHasSurface(boolean hasSurface) { |
| 2143 | mHasSurface = hasSurface; |
| 2144 | } |
| 2145 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2146 | boolean canBeImeTarget() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 2147 | if (mIsImWindow) { |
| 2148 | // IME windows can't be IME targets. IME targets are required to be below the IME |
| 2149 | // windows and that wouldn't be possible if the IME window is its own target...silly. |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2153 | final boolean windowsAreFocusable = mActivityRecord == null || mActivityRecord.windowsAreFocusable(); |
Winson Chung | b154934 | 2017-07-11 09:59:56 -0700 | [diff] [blame] | 2154 | if (!windowsAreFocusable) { |
| 2155 | // This window can't be an IME target if the app's windows should not be focusable. |
| 2156 | return false; |
| 2157 | } |
| 2158 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2159 | final ActivityStack stack = getStack(); |
lumark | f948afe | 2019-05-23 21:22:36 +0800 | [diff] [blame] | 2160 | if (stack != null && stack.shouldIgnoreInput()) { |
| 2161 | // Ignore when the stack shouldn't receive input event. |
| 2162 | // (i.e. the minimized stack in split screen mode.) |
| 2163 | return false; |
| 2164 | } |
| 2165 | |
Tarandeep Singh | 0ffa15a | 2019-11-04 13:40:15 -0800 | [diff] [blame] | 2166 | // Can be an IME target only if: |
| 2167 | // 1. FLAG_NOT_FOCUSABLE is not set |
| 2168 | // 2. FLAG_ALT_FOCUSABLE_IM is not set |
| 2169 | // 3. not a starting window. |
| 2170 | if (!WindowManager.LayoutParams.mayUseInputMethod(mAttrs.flags) |
| 2171 | || mAttrs.type == TYPE_APPLICATION_STARTING) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2172 | return false; |
| 2173 | } |
| 2174 | |
| 2175 | if (DEBUG_INPUT_METHOD) { |
| 2176 | Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding()); |
| 2177 | if (!isVisibleOrAdding()) { |
| 2178 | Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController |
| 2179 | + " relayoutCalled=" + mRelayoutCalled |
| 2180 | + " viewVis=" + mViewVisibility |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2181 | + " policyVis=" + isVisibleByPolicy() |
| 2182 | + " policyVisAfterAnim=" + mLegacyPolicyVisibilityAfterAnim |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2183 | + " parentHidden=" + isParentWindowHidden() |
| 2184 | + " exiting=" + mAnimatingExit + " destroying=" + mDestroying); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2185 | if (mActivityRecord != null) { |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 2186 | Slog.i(TAG_WM, " mActivityRecord.visibleRequested=" |
| 2187 | + mActivityRecord.mVisibleRequested); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2188 | } |
| 2189 | } |
| 2190 | } |
| 2191 | return isVisibleOrAdding(); |
| 2192 | } |
| 2193 | |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2194 | private final class DeadWindowEventReceiver extends InputEventReceiver { |
| 2195 | DeadWindowEventReceiver(InputChannel inputChannel) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2196 | super(inputChannel, mWmService.mH.getLooper()); |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2197 | } |
| 2198 | @Override |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 2199 | public void onInputEvent(InputEvent event) { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2200 | finishInputEvent(event, true); |
| 2201 | } |
| 2202 | } |
| 2203 | /** |
| 2204 | * Dummy event receiver for windows that died visible. |
| 2205 | */ |
| 2206 | private DeadWindowEventReceiver mDeadWindowEventReceiver; |
| 2207 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2208 | void openInputChannel(InputChannel outInputChannel) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2209 | if (mInputChannel != null) { |
| 2210 | throw new IllegalStateException("Window already has an input channel."); |
| 2211 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2212 | String name = getName(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2213 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2214 | mInputChannel = inputChannels[0]; |
| 2215 | mClientChannel = inputChannels[1]; |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 2216 | mWmService.mInputManager.registerInputChannel(mInputChannel); |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 2217 | mInputWindowHandle.token = mInputChannel.getToken(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2218 | if (outInputChannel != null) { |
| 2219 | mClientChannel.transferTo(outInputChannel); |
| 2220 | mClientChannel.dispose(); |
| 2221 | mClientChannel = null; |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2222 | } else { |
| 2223 | // If the window died visible, we setup a dummy input channel, so that taps |
| 2224 | // can still detected by input monitor channel, and we can relaunch the app. |
| 2225 | // Create dummy event receiver that simply reports all events as handled. |
| 2226 | mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2227 | } |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 2228 | mWmService.mInputToWindowMap.put(mInputWindowHandle.token, this); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2231 | void disposeInputChannel() { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2232 | if (mDeadWindowEventReceiver != null) { |
| 2233 | mDeadWindowEventReceiver.dispose(); |
| 2234 | mDeadWindowEventReceiver = null; |
| 2235 | } |
| 2236 | |
| 2237 | // unregister server channel first otherwise it complains about broken channel |
| 2238 | if (mInputChannel != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2239 | mWmService.mInputManager.unregisterInputChannel(mInputChannel); |
Robert Carr | e0a353c | 2018-08-02 16:38:04 -0700 | [diff] [blame] | 2240 | |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2241 | mInputChannel.dispose(); |
| 2242 | mInputChannel = null; |
| 2243 | } |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2244 | if (mClientChannel != null) { |
| 2245 | mClientChannel.dispose(); |
| 2246 | mClientChannel = null; |
| 2247 | } |
Vishnu Nair | 539334a | 2019-09-20 10:46:21 -0700 | [diff] [blame] | 2248 | mWmService.mKeyInterceptionInfoForToken.remove(mInputWindowHandle.token); |
Vishnu Nair | 1878216 | 2019-10-08 14:57:16 -0700 | [diff] [blame] | 2249 | mWmService.mInputToWindowMap.remove(mInputWindowHandle.token); |
Robert Carr | eadae82 | 2018-10-11 19:07:03 -0700 | [diff] [blame] | 2250 | mInputWindowHandle.token = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2251 | } |
| 2252 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2253 | /** Returns true if the replacement window was removed. */ |
| 2254 | boolean removeReplacedWindowIfNeeded(WindowState replacement) { |
| 2255 | if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) { |
| 2256 | replacement.mSkipEnterAnimationForSeamlessReplacement = false; |
| 2257 | removeReplacedWindow(); |
| 2258 | return true; |
| 2259 | } |
| 2260 | |
| 2261 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2262 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2263 | if (c.removeReplacedWindowIfNeeded(replacement)) { |
| 2264 | return true; |
| 2265 | } |
| 2266 | } |
| 2267 | return false; |
| 2268 | } |
| 2269 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2270 | private void removeReplacedWindow() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2271 | ProtoLog.d(WM_DEBUG_ADD_REMOVE, "Removing replaced window: %s", this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2272 | mWillReplaceWindow = false; |
| 2273 | mAnimateReplacingWindow = false; |
| 2274 | mReplacingRemoveRequested = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2275 | mReplacementWindow = null; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2276 | if (mAnimatingExit || !mAnimateReplacingWindow) { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 2277 | removeImmediately(); |
Filip Gruszczynski | 76cc44f | 2015-09-03 16:03:10 -0700 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2281 | boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) { |
| 2282 | boolean replacementSet = false; |
| 2283 | |
| 2284 | if (mWillReplaceWindow && mReplacementWindow == null |
| 2285 | && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) { |
| 2286 | |
| 2287 | mReplacementWindow = replacementCandidate; |
| 2288 | replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow; |
| 2289 | replacementSet = true; |
| 2290 | } |
| 2291 | |
| 2292 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2293 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2294 | replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate); |
| 2295 | } |
| 2296 | |
| 2297 | return replacementSet; |
| 2298 | } |
| 2299 | |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2300 | void setDisplayLayoutNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2301 | final DisplayContent dc = getDisplayContent(); |
| 2302 | if (dc != null) { |
| 2303 | dc.setLayoutNeeded(); |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2304 | } |
| 2305 | } |
| 2306 | |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 2307 | void applyAdjustForImeIfNeeded() { |
| 2308 | final Task task = getTask(); |
Wale Ogunwale | 8577a05 | 2019-10-26 23:22:34 -0700 | [diff] [blame] | 2309 | if (task != null && task.getTaskStack() != null && task.getTaskStack().isAdjustedForIme()) { |
| 2310 | task.getTaskStack().applyAdjustForImeIfNeeded(task); |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2314 | @Override |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2315 | void switchUser(int userId) { |
| 2316 | super.switchUser(userId); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2317 | if (isHiddenFromUserLocked()) { |
| 2318 | if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this |
| 2319 | + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid); |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2320 | clearPolicyVisibilityFlag(VISIBLE_FOR_USER); |
| 2321 | } else { |
| 2322 | setPolicyVisibilityFlag(VISIBLE_FOR_USER); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | |
Vishnu Nair | 93d68c2 | 2019-03-22 13:45:31 -0700 | [diff] [blame] | 2326 | int getSurfaceTouchableRegion(InputWindowHandle inputWindowHandle, int flags) { |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2327 | final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0; |
Vishnu Nair | 93d68c2 | 2019-03-22 13:45:31 -0700 | [diff] [blame] | 2328 | final Region region = inputWindowHandle.touchableRegion; |
| 2329 | setTouchableRegionCropIfNeeded(inputWindowHandle); |
| 2330 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2331 | if (modal && mActivityRecord != null) { |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2332 | // Limit the outer touch to the activity stack region. |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2333 | flags |= FLAG_NOT_TOUCH_MODAL; |
Riddle Hsu | 69de5fb | 2019-02-23 01:19:50 +0800 | [diff] [blame] | 2334 | // If the inner bounds of letterbox is available, then it will be used as the touchable |
| 2335 | // region so it won't cover the touchable letterbox and the touch events can slip to |
| 2336 | // activity from letterbox. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2337 | mActivityRecord.getLetterboxInnerBounds(mTmpRect); |
Riddle Hsu | 69de5fb | 2019-02-23 01:19:50 +0800 | [diff] [blame] | 2338 | if (mTmpRect.isEmpty()) { |
| 2339 | // If this is a modal window we need to dismiss it if it's not full screen and the |
| 2340 | // touch happens outside of the frame that displays the content. This means we need |
| 2341 | // to intercept touches outside of that window. The dim layer user associated with |
| 2342 | // the window (task or stack) will give us the good bounds, as they would be used to |
| 2343 | // display the dim layer. |
| 2344 | final Task task = getTask(); |
| 2345 | if (task != null) { |
| 2346 | task.getDimBounds(mTmpRect); |
| 2347 | } else { |
| 2348 | getStack().getDimBounds(mTmpRect); |
| 2349 | } |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2350 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2351 | if (inFreeformWindowingMode()) { |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2352 | // For freeform windows we the touch region to include the whole surface for the |
| 2353 | // shadows. |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2354 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
| 2355 | final int delta = WindowManagerService.dipToPixel( |
| 2356 | RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics); |
| 2357 | mTmpRect.inset(-delta, -delta); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2358 | } |
| 2359 | region.set(mTmpRect); |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 2360 | cropRegionToStackBoundsIfNeeded(region); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2361 | subtractTouchExcludeRegionIfNeeded(region); |
| 2362 | } else if (modal && mTapExcludeRegionHolder != null) { |
| 2363 | final Region touchExcludeRegion = Region.obtain(); |
| 2364 | amendTapExcludeRegion(touchExcludeRegion); |
| 2365 | if (!touchExcludeRegion.isEmpty()) { |
| 2366 | // Remove touch modal because there are some areas that cannot be touched. |
| 2367 | flags |= FLAG_NOT_TOUCH_MODAL; |
| 2368 | // Give it a large touchable region at first because it was touch modal. The window |
| 2369 | // might be moved on the display, so the touchable region should be large enough to |
| 2370 | // ensure it covers the whole display, no matter where it is moved. |
| 2371 | getDisplayContent().getBounds(mTmpRect); |
| 2372 | final int dw = mTmpRect.width(); |
| 2373 | final int dh = mTmpRect.height(); |
| 2374 | region.set(-dw, -dh, dw + dw, dh + dh); |
| 2375 | // Subtract the area that cannot be touched. |
| 2376 | region.op(touchExcludeRegion, Region.Op.DIFFERENCE); |
Vishnu Nair | 93d68c2 | 2019-03-22 13:45:31 -0700 | [diff] [blame] | 2377 | inputWindowHandle.setTouchableRegionCrop(null); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 2378 | } |
| 2379 | touchExcludeRegion.recycle(); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2380 | } else { |
| 2381 | // Not modal or full screen modal |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 2382 | getTouchableRegion(region); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2383 | } |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 2384 | // Translate to surface based coordinates. |
| 2385 | region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top); |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 2386 | |
Shivam Agrawal | 780b5bb | 2019-07-17 10:17:11 -0700 | [diff] [blame] | 2387 | // TODO(b/139804591): sizecompat layout needs to be reworked. Currently mFrame is post- |
| 2388 | // scaling but the existing logic doesn't expect that. The result is that the already- |
| 2389 | // scaled region ends up getting sent to surfaceflinger which then applies the scale |
| 2390 | // (again). Until this is resolved, apply an inverse-scale here. |
| 2391 | if (mActivityRecord != null && mActivityRecord.hasSizeCompatBounds() |
| 2392 | && mGlobalScale != 1.f) { |
| 2393 | region.scale(mInvGlobalScale); |
| 2394 | } |
| 2395 | |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2396 | return flags; |
| 2397 | } |
| 2398 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2399 | void checkPolicyVisibilityChange() { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2400 | if (isLegacyPolicyVisibility() != mLegacyPolicyVisibilityAfterAnim) { |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2401 | if (DEBUG_VISIBILITY) { |
| 2402 | Slog.v(TAG, "Policy visibility changing after anim in " + |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2403 | mWinAnimator + ": " + mLegacyPolicyVisibilityAfterAnim); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2404 | } |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2405 | if (mLegacyPolicyVisibilityAfterAnim) { |
| 2406 | setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY); |
| 2407 | } else { |
| 2408 | clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY); |
| 2409 | } |
| 2410 | if (!isVisibleByPolicy()) { |
Jorim Jaggi | 2e05af2 | 2017-12-28 15:15:11 +0100 | [diff] [blame] | 2411 | mWinAnimator.hide("checkPolicyVisibilityChange"); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2412 | if (isFocused()) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2413 | ProtoLog.i(WM_DEBUG_FOCUS_LIGHT, |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2414 | "setAnimationLocked: setting mFocusMayChange true"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2415 | mWmService.mFocusMayChange = true; |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2416 | } |
Tetsutoki Shiozawa | 64c5f0c | 2018-05-18 10:55:01 +0900 | [diff] [blame] | 2417 | setDisplayLayoutNeeded(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2418 | // Window is no longer visible -- make sure if we were waiting |
| 2419 | // for it to be displayed before enabling the display, that |
| 2420 | // we allow the display to be enabled now. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2421 | mWmService.enableScreenIfNeededLocked(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2422 | } |
| 2423 | } |
| 2424 | } |
| 2425 | |
| 2426 | void setRequestedSize(int requestedWidth, int requestedHeight) { |
| 2427 | if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) { |
| 2428 | mLayoutNeeded = true; |
| 2429 | mRequestedWidth = requestedWidth; |
| 2430 | mRequestedHeight = requestedHeight; |
| 2431 | } |
| 2432 | } |
| 2433 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2434 | void prepareWindowToDisplayDuringRelayout(boolean wasVisible) { |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2435 | // We need to turn on screen regardless of visibility. |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 2436 | final boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0 |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2437 | || (mActivityRecord != null && mActivityRecord.canTurnScreenOn()); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 2438 | |
| 2439 | // The screen will turn on if the following conditions are met |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 2440 | // 1. The window has the flag FLAG_TURN_SCREEN_ON or ActivityRecord#canTurnScreenOn. |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 2441 | // 2. The WMS allows theater mode. |
| 2442 | // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once |
| 2443 | // per resume to prevent the screen getting getting turned on for each relayout. Set |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2444 | // currentLaunchCanTurnScreenOn will be set to false so the window doesn't turn the screen |
| 2445 | // on again during this resume. |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 2446 | // 4. When the screen is not interactive. This is because when the screen is already |
| 2447 | // interactive, the value may persist until the next animation, which could potentially |
| 2448 | // be occurring while turning off the screen. This would lead to the screen incorrectly |
| 2449 | // turning back on. |
chaviw | 474093d | 2018-03-07 15:03:38 -0800 | [diff] [blame] | 2450 | if (hasTurnScreenOnFlag) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 2451 | boolean allowTheaterMode = mWmService.mAllowTheaterModeWakeFromLayout |
| 2452 | || Settings.Global.getInt(mWmService.mContext.getContentResolver(), |
| 2453 | Settings.Global.THEATER_MODE_ON, 0) == 0; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2454 | boolean canTurnScreenOn = mActivityRecord == null || mActivityRecord.currentLaunchCanTurnScreenOn(); |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 2455 | |
chaviw | 474093d | 2018-03-07 15:03:38 -0800 | [diff] [blame] | 2456 | if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) { |
| 2457 | if (DEBUG_VISIBILITY || DEBUG_POWER) { |
| 2458 | Slog.v(TAG, "Relayout window turning screen on: " + this); |
| 2459 | } |
| 2460 | mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(), |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 2461 | PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG"); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 2462 | } |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 2463 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2464 | if (mActivityRecord != null) { |
| 2465 | mActivityRecord.setCurrentLaunchCanTurnScreenOn(false); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 2466 | } |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2467 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2468 | |
| 2469 | // If we were already visible, skip rest of preparation. |
| 2470 | if (wasVisible) { |
| 2471 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2472 | "Already visible and does not turn on screen, skip preparing: " + this); |
| 2473 | return; |
| 2474 | } |
| 2475 | |
| 2476 | if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST) |
| 2477 | == SOFT_INPUT_ADJUST_RESIZE) { |
| 2478 | mLayoutNeeded = true; |
| 2479 | } |
| 2480 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2481 | if (isDrawnLw() && mToken.okToAnimate()) { |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2482 | mWinAnimator.applyEnterAnimationLocked(); |
| 2483 | } |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2484 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 2485 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 2486 | private Configuration getProcessGlobalConfiguration() { |
| 2487 | // For child windows we want to use the pid for the parent window in case the the child |
| 2488 | // window was added from another process. |
Yunfan Chen | b4fe58c | 2019-03-27 18:35:06 +0900 | [diff] [blame] | 2489 | final WindowState parentWindow = getParentWindow(); |
| 2490 | final int pid = parentWindow != null ? parentWindow.mSession.mPid : mSession.mPid; |
Yunfan Chen | c2ff6cf | 2018-12-04 16:56:21 -0800 | [diff] [blame] | 2491 | final Configuration processConfig = |
| 2492 | mWmService.mAtmService.getGlobalConfigurationForPid(pid); |
Yunfan Chen | b4fe58c | 2019-03-27 18:35:06 +0900 | [diff] [blame] | 2493 | return processConfig; |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 2494 | } |
| 2495 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2496 | void getMergedConfiguration(MergedConfiguration outConfiguration) { |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 2497 | final Configuration globalConfig = getProcessGlobalConfiguration(); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 2498 | final Configuration overrideConfig = getMergedOverrideConfiguration(); |
| 2499 | outConfiguration.setConfiguration(globalConfig, overrideConfig); |
| 2500 | } |
| 2501 | |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 2502 | void setLastReportedMergedConfiguration(MergedConfiguration config) { |
| 2503 | mLastReportedConfiguration.setTo(config); |
Jorim Jaggi | 381cd72 | 2019-03-27 17:33:02 +0100 | [diff] [blame] | 2504 | mLastConfigReportedToClient = true; |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | void getLastReportedMergedConfiguration(MergedConfiguration config) { |
| 2508 | config.setTo(mLastReportedConfiguration); |
| 2509 | } |
| 2510 | |
| 2511 | private Configuration getLastReportedConfiguration() { |
| 2512 | return mLastReportedConfiguration.getMergedConfiguration(); |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | void adjustStartingWindowFlags() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2516 | if (mAttrs.type == TYPE_BASE_APPLICATION && mActivityRecord != null |
| 2517 | && mActivityRecord.startingWindow != null) { |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2518 | // Special handling of starting window over the base |
| 2519 | // window of the app: propagate lock screen flags to it, |
| 2520 | // to provide the correct semantics while starting. |
| 2521 | final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD |
| 2522 | | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2523 | WindowManager.LayoutParams sa = mActivityRecord.startingWindow.mAttrs; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2524 | sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask); |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | void setWindowScale(int requestedWidth, int requestedHeight) { |
| 2529 | final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0; |
| 2530 | |
| 2531 | if (scaledWindow) { |
| 2532 | // requested{Width|Height} Surface's physical size |
| 2533 | // attrs.{width|height} Size on screen |
| 2534 | // TODO: We don't check if attrs != null here. Is it implicitly checked? |
| 2535 | mHScale = (mAttrs.width != requestedWidth) ? |
| 2536 | (mAttrs.width / (float)requestedWidth) : 1.0f; |
| 2537 | mVScale = (mAttrs.height != requestedHeight) ? |
| 2538 | (mAttrs.height / (float)requestedHeight) : 1.0f; |
| 2539 | } else { |
| 2540 | mHScale = mVScale = 1; |
| 2541 | } |
| 2542 | } |
| 2543 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2544 | private class DeathRecipient implements IBinder.DeathRecipient { |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 2545 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2546 | public void binderDied() { |
| 2547 | try { |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2548 | boolean resetSplitScreenResizing = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2549 | synchronized (mWmService.mGlobalLock) { |
| 2550 | final WindowState win = mWmService |
| 2551 | .windowForClientLocked(mSession, mClient, false); |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2552 | Slog.i(TAG, "WIN DEATH: " + win); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2553 | if (win != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2554 | final DisplayContent dc = getDisplayContent(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2555 | if (win.mActivityRecord != null && win.mActivityRecord.findMainWindow() == win) { |
| 2556 | mWmService.mTaskSnapshotController.onAppDied(win.mActivityRecord); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 2557 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2558 | win.removeIfPossible(shouldKeepVisibleDeadAppWindow()); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2559 | if (win.mAttrs.type == TYPE_DOCK_DIVIDER) { |
| 2560 | // The owner of the docked divider died :( We reset the docked stack, |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 2561 | // just in case they have the divider at an unstable position. Better |
| 2562 | // also reset drag resizing state, because the owner can't do it |
| 2563 | // anymore. |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 2564 | final ActivityStack stack = |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 2565 | dc.getSplitScreenPrimaryStackIgnoringVisibility(); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2566 | if (stack != null) { |
| 2567 | stack.resetDockedStackToMiddle(); |
| 2568 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2569 | resetSplitScreenResizing = true; |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2570 | } |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 2571 | } else if (mHasSurface) { |
Craig Mautner | a99764e | 2013-03-06 10:22:16 -0800 | [diff] [blame] | 2572 | Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid."); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 2573 | WindowState.this.removeIfPossible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2574 | } |
| 2575 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2576 | if (resetSplitScreenResizing) { |
| 2577 | try { |
| 2578 | // Note: this calls into ActivityManager, so we must *not* hold the window |
| 2579 | // manager lock while calling this. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2580 | mWmService.mActivityTaskManager.setSplitScreenResizing(false); |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2581 | } catch (RemoteException e) { |
| 2582 | // Local call, shouldn't return RemoteException. |
| 2583 | throw e.rethrowAsRuntimeException(); |
| 2584 | } |
| 2585 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2586 | } catch (IllegalArgumentException ex) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 2587 | // This will happen if the window has already been removed. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | } |
| 2591 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2592 | /** |
| 2593 | * Returns true if this window is visible and belongs to a dead app and shouldn't be removed, |
| 2594 | * because we want to preserve its location on screen to be re-activated later when the user |
| 2595 | * interacts with it. |
| 2596 | */ |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2597 | private boolean shouldKeepVisibleDeadAppWindow() { |
Issei Suzuki | e63eac7 | 2019-11-14 15:59:15 +0100 | [diff] [blame] | 2598 | if (!isWinVisibleLw() || mActivityRecord == null || mActivityRecord.isClientHidden()) { |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2599 | // Not a visible app window or the app isn't dead. |
| 2600 | return false; |
| 2601 | } |
| 2602 | |
Wale Ogunwale | 51d1d91 | 2016-05-04 13:27:18 -0700 | [diff] [blame] | 2603 | if (mAttrs.token != mClient.asBinder()) { |
| 2604 | // The window was add by a client using another client's app token. We don't want to |
| 2605 | // keep the dead window around for this case since this is meant for 'real' apps. |
| 2606 | return false; |
| 2607 | } |
| 2608 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2609 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2610 | // We don't keep starting windows since they were added by the window manager before |
| 2611 | // the app even launched. |
| 2612 | return false; |
| 2613 | } |
| 2614 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2615 | return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen(); |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2616 | } |
| 2617 | |
Tiger Huang | 513d5e1 | 2018-07-16 21:49:50 +0800 | [diff] [blame] | 2618 | @Override |
| 2619 | public boolean canReceiveKeys() { |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 2620 | return isVisibleOrAdding() |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 2621 | && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2622 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0) |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2623 | && (mActivityRecord == null || mActivityRecord.windowsAreFocusable()) |
Robert Carr | ebdf858 | 2018-09-04 14:50:15 -0700 | [diff] [blame] | 2624 | && !cantReceiveTouchInput(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 2625 | } |
| 2626 | |
lumark | 31e4f8e | 2019-01-10 20:48:18 +0800 | [diff] [blame] | 2627 | @Override |
| 2628 | public boolean canShowWhenLocked() { |
| 2629 | final boolean showBecauseOfActivity = |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2630 | mActivityRecord != null && mActivityRecord.canShowWhenLocked(); |
lumark | 31e4f8e | 2019-01-10 20:48:18 +0800 | [diff] [blame] | 2631 | final boolean showBecauseOfWindow = (getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0; |
| 2632 | return showBecauseOfActivity || showBecauseOfWindow; |
| 2633 | } |
| 2634 | |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 2635 | /** @return {@code false} if this window desires touch events. */ |
Robert Carr | ebdf858 | 2018-09-04 14:50:15 -0700 | [diff] [blame] | 2636 | boolean cantReceiveTouchInput() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2637 | if (mActivityRecord == null || mActivityRecord.getTask() == null) { |
Vinit Nayak | 8009e92 | 2019-09-05 11:49:53 -0700 | [diff] [blame] | 2638 | return false; |
| 2639 | } |
| 2640 | |
Wale Ogunwale | 8577a05 | 2019-10-26 23:22:34 -0700 | [diff] [blame] | 2641 | return mActivityRecord.getTask().getTaskStack().shouldIgnoreInput() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 2642 | || !mActivityRecord.mVisibleRequested |
Vinit Nayak | 8009e92 | 2019-09-05 11:49:53 -0700 | [diff] [blame] | 2643 | || isAnimatingToRecents(); |
| 2644 | } |
| 2645 | |
| 2646 | /** |
| 2647 | * Returns {@code true} if the window is animating to home as part of the recents animation. |
| 2648 | */ |
| 2649 | private boolean isAnimatingToRecents() { |
| 2650 | final RecentsAnimationController recentsAnimationController = |
| 2651 | mWmService.getRecentsAnimationController(); |
| 2652 | return recentsAnimationController != null |
| 2653 | && recentsAnimationController.isAnimatingTask(getTask()) |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2654 | && !recentsAnimationController.isTargetApp(mActivityRecord); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2655 | } |
| 2656 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2657 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2658 | public boolean hasDrawnLw() { |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2659 | return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2660 | } |
| 2661 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2662 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2663 | public boolean showLw(boolean doAnimation) { |
| 2664 | return showLw(doAnimation, true); |
| 2665 | } |
| 2666 | |
| 2667 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2668 | if (isLegacyPolicyVisibility() && mLegacyPolicyVisibilityAfterAnim) { |
Jorim Jaggi | 5015015 | 2019-03-27 23:08:58 +0100 | [diff] [blame] | 2669 | // Already showing. |
| 2670 | return false; |
| 2671 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2672 | if (isHiddenFromUserLocked()) { |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 2673 | return false; |
| 2674 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2675 | if (!mAppOpVisibility) { |
| 2676 | // Being hidden due to app op request. |
| 2677 | return false; |
| 2678 | } |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2679 | if (mPermanentlyHidden) { |
| 2680 | // Permanently hidden until the app exists as apps aren't prepared |
| 2681 | // to handle their windows being removed from under them. |
| 2682 | return false; |
| 2683 | } |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 2684 | if (mHiddenWhileSuspended) { |
| 2685 | // Being hidden due to owner package being suspended. |
| 2686 | return false; |
| 2687 | } |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 2688 | if (mForceHideNonSystemOverlayWindow) { |
| 2689 | // This is an alert window that is currently force hidden. |
| 2690 | return false; |
| 2691 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2692 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2693 | if (doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2694 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2695 | + isLegacyPolicyVisibility() |
| 2696 | + " animating=" + isAnimating(TRANSITION | PARENTS)); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2697 | if (!mToken.okToAnimate()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2698 | doAnimation = false; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2699 | } else if (isLegacyPolicyVisibility() && !isAnimating(TRANSITION | PARENTS)) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2700 | // Check for the case where we are currently visible and |
| 2701 | // not animating; we do not want to do animation at such a |
| 2702 | // point to become visible when we already are. |
| 2703 | doAnimation = false; |
| 2704 | } |
| 2705 | } |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2706 | setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY); |
| 2707 | mLegacyPolicyVisibilityAfterAnim = true; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2708 | if (doAnimation) { |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 2709 | mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2710 | } |
| 2711 | if (requestAnim) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2712 | mWmService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2713 | } |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2714 | if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2715 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */); |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2716 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2717 | return true; |
| 2718 | } |
| 2719 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2720 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2721 | public boolean hideLw(boolean doAnimation) { |
| 2722 | return hideLw(doAnimation, true); |
| 2723 | } |
| 2724 | |
| 2725 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| 2726 | if (doAnimation) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2727 | if (!mToken.okToAnimate()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2728 | doAnimation = false; |
| 2729 | } |
| 2730 | } |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2731 | boolean current = |
| 2732 | doAnimation ? mLegacyPolicyVisibilityAfterAnim : isLegacyPolicyVisibility(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2733 | if (!current) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 2734 | // Already hiding. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2735 | return false; |
| 2736 | } |
| 2737 | if (doAnimation) { |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 2738 | mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false); |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2739 | if (!isAnimating(TRANSITION | PARENTS)) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2740 | doAnimation = false; |
| 2741 | } |
| 2742 | } |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2743 | mLegacyPolicyVisibilityAfterAnim = false; |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2744 | final boolean isFocused = isFocused(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2745 | if (!doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2746 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 2747 | clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2748 | // Window is no longer visible -- make sure if we were waiting |
| 2749 | // for it to be displayed before enabling the display, that |
| 2750 | // we allow the display to be enabled now. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2751 | mWmService.enableScreenIfNeededLocked(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2752 | if (isFocused) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2753 | ProtoLog.i(WM_DEBUG_FOCUS_LIGHT, |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 2754 | "WindowState.hideLw: setting mFocusMayChange true"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2755 | mWmService.mFocusMayChange = true; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2756 | } |
| 2757 | } |
| 2758 | if (requestAnim) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2759 | mWmService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2760 | } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 2761 | if (isFocused) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2762 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */); |
Jorim Jaggi | c8c4a8e | 2017-04-04 15:09:51 +0200 | [diff] [blame] | 2763 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2764 | return true; |
| 2765 | } |
| 2766 | |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 2767 | void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) { |
| 2768 | if (mOwnerCanAddInternalSystemWindow |
| 2769 | || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) { |
| 2770 | return; |
| 2771 | } |
| 2772 | if (mForceHideNonSystemOverlayWindow == forceHide) { |
| 2773 | return; |
| 2774 | } |
| 2775 | mForceHideNonSystemOverlayWindow = forceHide; |
| 2776 | if (forceHide) { |
| 2777 | hideLw(true /* doAnimation */, true /* requestAnim */); |
| 2778 | } else { |
| 2779 | showLw(true /* doAnimation */, true /* requestAnim */); |
| 2780 | } |
| 2781 | } |
| 2782 | |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 2783 | void setHiddenWhileSuspended(boolean hide) { |
| 2784 | if (mOwnerCanAddInternalSystemWindow |
| 2785 | || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) { |
| 2786 | return; |
| 2787 | } |
| 2788 | if (mHiddenWhileSuspended == hide) { |
| 2789 | return; |
| 2790 | } |
| 2791 | mHiddenWhileSuspended = hide; |
| 2792 | if (hide) { |
| 2793 | hideLw(true, true); |
| 2794 | } else { |
| 2795 | showLw(true, true); |
| 2796 | } |
| 2797 | } |
| 2798 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2799 | private void setAppOpVisibilityLw(boolean state) { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2800 | if (mAppOpVisibility != state) { |
| 2801 | mAppOpVisibility = state; |
| 2802 | if (state) { |
| 2803 | // If the policy visibility had last been to hide, then this |
| 2804 | // will incorrectly show at this point since we lost that |
| 2805 | // information. Not a big deal -- for the windows that have app |
| 2806 | // ops modifies they should only be hidden by policy due to the |
| 2807 | // lock screen, and the user won't be changing this if locked. |
| 2808 | // 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] | 2809 | showLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2810 | } else { |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 2811 | hideLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2812 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2813 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2814 | } |
| 2815 | |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2816 | void initAppOpsState() { |
| 2817 | if (mAppOp == OP_NONE || !mAppOpVisibility) { |
| 2818 | return; |
| 2819 | } |
| 2820 | // If the app op was MODE_DEFAULT we would have checked the permission |
| 2821 | // and add the window only if the permission was granted. Therefore, if |
| 2822 | // the mode is MODE_DEFAULT we want the op to succeed as the window is |
| 2823 | // shown. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2824 | final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2825 | getOwningUid(), getOwningPackage(), true); |
| 2826 | if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) { |
| 2827 | setAppOpVisibilityLw(false); |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | void resetAppOpsState() { |
| 2832 | if (mAppOp != OP_NONE && mAppOpVisibility) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2833 | mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage()); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | void updateAppOpsState() { |
| 2838 | if (mAppOp == OP_NONE) { |
| 2839 | return; |
| 2840 | } |
| 2841 | final int uid = getOwningUid(); |
| 2842 | final String packageName = getOwningPackage(); |
| 2843 | if (mAppOpVisibility) { |
| 2844 | // There is a race between the check and the finish calls but this is fine |
| 2845 | // 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] | 2846 | int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2847 | if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2848 | mWmService.mAppOps.finishOp(mAppOp, uid, packageName); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2849 | setAppOpVisibilityLw(false); |
| 2850 | } |
| 2851 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2852 | final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true); |
Svet Ganov | f7b4725 | 2018-02-26 11:11:27 -0800 | [diff] [blame] | 2853 | if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) { |
| 2854 | setAppOpVisibilityLw(true); |
| 2855 | } |
| 2856 | } |
| 2857 | } |
| 2858 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2859 | public void hidePermanentlyLw() { |
| 2860 | if (!mPermanentlyHidden) { |
| 2861 | mPermanentlyHidden = true; |
| 2862 | hideLw(true, true); |
| 2863 | } |
| 2864 | } |
| 2865 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2866 | public void pokeDrawLockLw(long timeout) { |
| 2867 | if (isVisibleOrAdding()) { |
| 2868 | if (mDrawLock == null) { |
| 2869 | // We want the tag name to be somewhat stable so that it is easier to correlate |
| 2870 | // in wake lock statistics. So in particular, we don't want to include the |
| 2871 | // window's hash code as in toString(). |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2872 | final CharSequence tag = getWindowTag(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2873 | mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2874 | mDrawLock.setReferenceCounted(false); |
| 2875 | mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName)); |
| 2876 | } |
| 2877 | // Each call to acquire resets the timeout. |
| 2878 | if (DEBUG_POWER) { |
| 2879 | Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by " |
| 2880 | + mAttrs.packageName); |
| 2881 | } |
| 2882 | mDrawLock.acquire(timeout); |
| 2883 | } else if (DEBUG_POWER) { |
| 2884 | Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window " |
| 2885 | + "owned by " + mAttrs.packageName); |
| 2886 | } |
| 2887 | } |
| 2888 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2889 | @Override |
| 2890 | public boolean isAlive() { |
| 2891 | return mClient.asBinder().isBinderAlive(); |
| 2892 | } |
| 2893 | |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2894 | boolean isClosing() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2895 | return mAnimatingExit || (mActivityRecord != null && mActivityRecord.isClosingOrEnteringPip()); |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2898 | void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) { |
| 2899 | animators.add(mWinAnimator); |
| 2900 | |
| 2901 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2902 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2903 | c.addWinAnimatorToList(animators); |
| 2904 | } |
| 2905 | } |
| 2906 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2907 | void sendAppVisibilityToClients() { |
| 2908 | super.sendAppVisibilityToClients(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2909 | |
Issei Suzuki | e63eac7 | 2019-11-14 15:59:15 +0100 | [diff] [blame] | 2910 | final boolean clientHidden = mActivityRecord.isClientHidden(); |
| 2911 | if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2912 | // Don't hide the starting window. |
| 2913 | return; |
| 2914 | } |
| 2915 | |
Issei Suzuki | e63eac7 | 2019-11-14 15:59:15 +0100 | [diff] [blame] | 2916 | if (clientHidden) { |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2917 | // Once we are notifying the client that it's visibility has changed, we need to prevent |
| 2918 | // it from destroying child surfaces until the animation has finished. We do this by |
| 2919 | // detaching any surface control the client added from the client. |
| 2920 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 2921 | final WindowState c = mChildren.get(i); |
| 2922 | c.mWinAnimator.detachChildren(); |
| 2923 | } |
| 2924 | |
| 2925 | mWinAnimator.detachChildren(); |
| 2926 | } |
| 2927 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2928 | try { |
| 2929 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Issei Suzuki | e63eac7 | 2019-11-14 15:59:15 +0100 | [diff] [blame] | 2930 | "Setting visibility of " + this + ": " + (!clientHidden)); |
| 2931 | mClient.dispatchAppVisibility(!clientHidden); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2932 | } catch (RemoteException e) { |
| 2933 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2936 | void onStartFreezingScreen() { |
| 2937 | mAppFreezing = true; |
| 2938 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2939 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2940 | c.onStartFreezingScreen(); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | boolean onStopFreezingScreen() { |
| 2945 | boolean unfrozeWindows = false; |
| 2946 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2947 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2948 | unfrozeWindows |= c.onStopFreezingScreen(); |
| 2949 | } |
| 2950 | |
| 2951 | if (!mAppFreezing) { |
| 2952 | return unfrozeWindows; |
| 2953 | } |
| 2954 | |
Wale Ogunwale | 953171d | 2016-09-30 09:17:30 -0700 | [diff] [blame] | 2955 | mAppFreezing = false; |
| 2956 | |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 2957 | if (mHasSurface && !getOrientationChanging() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2958 | && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2959 | ProtoLog.v(WM_DEBUG_ORIENTATION, |
| 2960 | "set mOrientationChanging of %s", this); |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 2961 | setOrientationChanging(true); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2962 | mWmService.mRoot.mOrientationChangeComplete = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2963 | } |
| 2964 | mLastFreezeDuration = 0; |
| 2965 | setDisplayLayoutNeeded(); |
| 2966 | return true; |
| 2967 | } |
| 2968 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2969 | boolean destroySurface(boolean cleanupOnResume, boolean appStopped) { |
| 2970 | boolean destroyedSomething = false; |
Jorim Jaggi | 59f3e92 | 2018-01-05 15:40:32 +0100 | [diff] [blame] | 2971 | |
| 2972 | // Copying to a different list as multiple children can be removed. |
| 2973 | final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren); |
| 2974 | for (int i = childWindows.size() - 1; i >= 0; --i) { |
| 2975 | final WindowState c = childWindows.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2976 | destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped); |
| 2977 | } |
| 2978 | |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2979 | if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) { |
| 2980 | return destroyedSomething; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2981 | } |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2982 | |
| 2983 | if (appStopped || mWindowRemovalAllowed) { |
| 2984 | mWinAnimator.destroyPreservedSurfaceLocked(); |
| 2985 | } |
| 2986 | |
| 2987 | if (mDestroying) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 2988 | ProtoLog.e(WM_DEBUG_ADD_REMOVE, "win=%s" |
| 2989 | + " destroySurfaces: appStopped=%b" |
| 2990 | + " win.mWindowRemovalAllowed=%b" |
| 2991 | + " win.mRemoveOnExit=%b", this, appStopped, |
| 2992 | mWindowRemovalAllowed, mRemoveOnExit); |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2993 | if (!cleanupOnResume || mRemoveOnExit) { |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 2994 | destroySurfaceUnchecked(); |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 2995 | } |
| 2996 | if (mRemoveOnExit) { |
| 2997 | removeImmediately(); |
| 2998 | } |
| 2999 | if (cleanupOnResume) { |
| 3000 | requestUpdateWallpaperIfNeeded(); |
| 3001 | } |
| 3002 | mDestroying = false; |
| 3003 | destroyedSomething = true; |
lumark | a668116 | 2019-04-12 01:47:54 +0800 | [diff] [blame] | 3004 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3005 | // Since mDestroying will affect ActivityRecord#allDrawn, we need to perform another |
lumark | a668116 | 2019-04-12 01:47:54 +0800 | [diff] [blame] | 3006 | // traversal in case we are waiting on this window to start the transition. |
| 3007 | if (getDisplayContent().mAppTransition.isTransitionSet() |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3008 | && getDisplayContent().mOpeningApps.contains(mActivityRecord)) { |
lumark | a668116 | 2019-04-12 01:47:54 +0800 | [diff] [blame] | 3009 | mWmService.mWindowPlacerLocked.requestTraversal(); |
| 3010 | } |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 3011 | } |
| 3012 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3013 | return destroyedSomething; |
| 3014 | } |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 3015 | |
Robert Carr | 89a28ab | 2017-04-24 15:33:11 -0700 | [diff] [blame] | 3016 | // Destroy or save the application surface without checking |
| 3017 | // various indicators of whether the client has released the surface. |
| 3018 | // This is in general unsafe, and most callers should use {@link #destroySurface} |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 3019 | void destroySurfaceUnchecked() { |
| 3020 | mWinAnimator.destroySurfaceLocked(); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 3021 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 3022 | // Clear animating flags now, since the surface is now gone. (Note this is true even |
| 3023 | // if the surface is saved, to outside world the surface is still NO_SURFACE.) |
| 3024 | mAnimatingExit = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 3025 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 3026 | |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 3027 | void onSurfaceShownChanged(boolean shown) { |
| 3028 | if (mLastShownChangedReported == shown) { |
| 3029 | return; |
| 3030 | } |
| 3031 | mLastShownChangedReported = shown; |
| 3032 | |
| 3033 | if (shown) { |
| 3034 | initExclusionRestrictions(); |
| 3035 | } else { |
| 3036 | logExclusionRestrictions(EXCLUSION_LEFT); |
| 3037 | logExclusionRestrictions(EXCLUSION_RIGHT); |
| 3038 | } |
| 3039 | } |
| 3040 | |
| 3041 | private void logExclusionRestrictions(int side) { |
| 3042 | if (!logsGestureExclusionRestrictions(this) |
| 3043 | || SystemClock.uptimeMillis() < mLastExclusionLogUptimeMillis[side] |
Adrian Roos | 1c2e9a1 | 2019-08-20 18:23:47 +0200 | [diff] [blame] | 3044 | + mWmService.mConstants.mSystemGestureExclusionLogDebounceTimeoutMillis) { |
Adrian Roos | 5f2c9a1 | 2019-07-03 18:31:46 +0200 | [diff] [blame] | 3045 | // Drop the log if we have just logged; this is okay, because what we would have logged |
| 3046 | // was true only for a short duration. |
| 3047 | return; |
| 3048 | } |
| 3049 | |
| 3050 | final long now = SystemClock.uptimeMillis(); |
| 3051 | final long duration = now - mLastExclusionLogUptimeMillis[side]; |
| 3052 | mLastExclusionLogUptimeMillis[side] = now; |
| 3053 | |
| 3054 | final int requested = mLastRequestedExclusionHeight[side]; |
| 3055 | final int granted = mLastGrantedExclusionHeight[side]; |
| 3056 | |
| 3057 | StatsLog.write(StatsLog.EXCLUSION_RECT_STATE_CHANGED, |
| 3058 | mAttrs.packageName, requested, requested - granted /* rejected */, |
| 3059 | side + 1 /* Sides are 1-indexed in atoms.proto */, |
| 3060 | (getConfiguration().orientation == ORIENTATION_LANDSCAPE), |
| 3061 | isSplitScreenWindowingMode(getWindowingMode()), (int) duration); |
| 3062 | } |
| 3063 | |
| 3064 | private void initExclusionRestrictions() { |
| 3065 | final long now = SystemClock.uptimeMillis(); |
| 3066 | mLastExclusionLogUptimeMillis[EXCLUSION_LEFT] = now; |
| 3067 | mLastExclusionLogUptimeMillis[EXCLUSION_RIGHT] = now; |
| 3068 | } |
| 3069 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3070 | @Override |
| 3071 | public boolean isDefaultDisplay() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3072 | final DisplayContent displayContent = getDisplayContent(); |
| 3073 | if (displayContent == null) { |
| 3074 | // Only a window that was on a non-default display can be detached from it. |
| 3075 | return false; |
| 3076 | } |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 3077 | return displayContent.isDefaultDisplay; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3078 | } |
| 3079 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3080 | void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) { |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 3081 | mShowToOwnerOnly = showToOwnerOnly; |
| 3082 | } |
| 3083 | |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3084 | private boolean isHiddenFromUserLocked() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3085 | // Child windows are evaluated based on their parent window. |
| 3086 | final WindowState win = getTopParentWindow(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3087 | if (win.mAttrs.type < FIRST_SYSTEM_WINDOW |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3088 | && win.mActivityRecord != null && win.mActivityRecord.mShowForAllUsers) { |
Jorim Jaggi | dbe44ac | 2016-04-22 19:50:13 -0700 | [diff] [blame] | 3089 | |
| 3090 | // All window frames that are fullscreen extend above status bar, but some don't extend |
| 3091 | // below navigation bar. Thus, check for display frame for top/left and stable frame for |
| 3092 | // bottom right. |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3093 | if (win.getFrameLw().left <= win.getDisplayFrameLw().left |
| 3094 | && win.getFrameLw().top <= win.getDisplayFrameLw().top |
| 3095 | && win.getFrameLw().right >= win.getStableFrameLw().right |
| 3096 | && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 3097 | // Is a fullscreen window, like the clock alarm. Show to everyone. |
| 3098 | return false; |
| 3099 | } |
| 3100 | } |
| 3101 | |
Craig Mautner | 341220f | 2012-10-16 15:20:09 -0700 | [diff] [blame] | 3102 | return win.mShowToOwnerOnly |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3103 | && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid)); |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3106 | private static void applyInsets(Region outRegion, Rect frame, Rect inset) { |
| 3107 | outRegion.set( |
| 3108 | frame.left + inset.left, frame.top + inset.top, |
| 3109 | frame.right - inset.right, frame.bottom - inset.bottom); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3110 | } |
| 3111 | |
Riddle Hsu | ff03df5 | 2018-12-05 21:43:02 +0800 | [diff] [blame] | 3112 | /** Get the touchable region in global coordinates. */ |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3113 | void getTouchableRegion(Region outRegion) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3114 | final Rect frame = mWindowFrames.mFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3115 | switch (mTouchableInsets) { |
| 3116 | default: |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3117 | case TOUCHABLE_INSETS_FRAME: |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3118 | outRegion.set(frame); |
| 3119 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3120 | case TOUCHABLE_INSETS_CONTENT: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3121 | applyInsets(outRegion, frame, mGivenContentInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3122 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3123 | case TOUCHABLE_INSETS_VISIBLE: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3124 | applyInsets(outRegion, frame, mGivenVisibleInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3125 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3126 | case TOUCHABLE_INSETS_REGION: { |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3127 | outRegion.set(mGivenTouchableRegion); |
Riddle Hsu | b5e960f | 2018-12-07 14:51:26 +0800 | [diff] [blame] | 3128 | outRegion.translate(frame.left, frame.top); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3129 | break; |
| 3130 | } |
| 3131 | } |
Vishnu Nair | b924632 | 2018-12-06 13:54:02 -0800 | [diff] [blame] | 3132 | cropRegionToStackBoundsIfNeeded(outRegion); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3133 | subtractTouchExcludeRegionIfNeeded(outRegion); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3134 | } |
| 3135 | |
Adrian Roos | b106379 | 2019-06-28 12:10:51 +0200 | [diff] [blame] | 3136 | /** |
| 3137 | * Get the effective touchable region in global coordinates. |
| 3138 | * |
| 3139 | * In contrast to {@link #getTouchableRegion}, this takes into account |
| 3140 | * {@link WindowManager.LayoutParams#FLAG_NOT_TOUCH_MODAL touch modality.} |
| 3141 | */ |
| 3142 | void getEffectiveTouchableRegion(Region outRegion) { |
| 3143 | final boolean modal = (mAttrs.flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0; |
| 3144 | final DisplayContent dc = getDisplayContent(); |
| 3145 | |
| 3146 | if (modal && dc != null) { |
| 3147 | outRegion.set(dc.getBounds()); |
| 3148 | cropRegionToStackBoundsIfNeeded(outRegion); |
| 3149 | subtractTouchExcludeRegionIfNeeded(outRegion); |
| 3150 | } else { |
| 3151 | getTouchableRegion(outRegion); |
| 3152 | } |
| 3153 | } |
| 3154 | |
Vishnu Nair | 93d68c2 | 2019-03-22 13:45:31 -0700 | [diff] [blame] | 3155 | private void setTouchableRegionCropIfNeeded(InputWindowHandle handle) { |
| 3156 | final Task task = getTask(); |
| 3157 | if (task == null || !task.cropWindowsToStackBounds()) { |
| 3158 | return; |
| 3159 | } |
| 3160 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3161 | final ActivityStack stack = task.getTaskStack(); |
Vishnu Nair | 93d68c2 | 2019-03-22 13:45:31 -0700 | [diff] [blame] | 3162 | if (stack == null) { |
| 3163 | return; |
| 3164 | } |
| 3165 | |
| 3166 | handle.setTouchableRegionCrop(stack.getSurfaceControl()); |
| 3167 | } |
| 3168 | |
Wale Ogunwale | ae9adbf | 2016-10-18 15:17:06 -0700 | [diff] [blame] | 3169 | private void cropRegionToStackBoundsIfNeeded(Region region) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 3170 | final Task task = getTask(); |
| 3171 | if (task == null || !task.cropWindowsToStackBounds()) { |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3172 | return; |
| 3173 | } |
| 3174 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3175 | final ActivityStack stack = task.getTaskStack(); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 3176 | if (stack == null) { |
| 3177 | return; |
| 3178 | } |
| 3179 | |
| 3180 | stack.getDimBounds(mTmpRect); |
| 3181 | region.op(mTmpRect, Region.Op.INTERSECT); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3182 | } |
| 3183 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3184 | /** |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 3185 | * If this window has areas that cannot be touched, we subtract those areas from its touchable |
| 3186 | * region. |
| 3187 | */ |
| 3188 | private void subtractTouchExcludeRegionIfNeeded(Region touchableRegion) { |
| 3189 | if (mTapExcludeRegionHolder == null) { |
| 3190 | return; |
| 3191 | } |
| 3192 | final Region touchExcludeRegion = Region.obtain(); |
| 3193 | amendTapExcludeRegion(touchExcludeRegion); |
| 3194 | if (!touchExcludeRegion.isEmpty()) { |
| 3195 | touchableRegion.op(touchExcludeRegion, Region.Op.DIFFERENCE); |
| 3196 | } |
| 3197 | touchExcludeRegion.recycle(); |
| 3198 | } |
| 3199 | |
| 3200 | /** |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3201 | * Report a focus change. Must be called with no locks held, and consistently |
| 3202 | * from the same serialized thread (such as dispatched from a handler). |
| 3203 | */ |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3204 | void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3205 | try { |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3206 | mClient.windowFocusChanged(focused, inTouchMode); |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3207 | } catch (RemoteException e) { |
| 3208 | } |
Tiger Huang | 51c5a1d | 2018-12-11 20:24:51 +0800 | [diff] [blame] | 3209 | if (mFocusCallbacks != null) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3210 | final int N = mFocusCallbacks.beginBroadcast(); |
| 3211 | for (int i=0; i<N; i++) { |
| 3212 | IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i); |
| 3213 | try { |
| 3214 | if (focused) { |
| 3215 | obs.focusGained(mWindowId.asBinder()); |
| 3216 | } else { |
| 3217 | obs.focusLost(mWindowId.asBinder()); |
| 3218 | } |
| 3219 | } catch (RemoteException e) { |
| 3220 | } |
| 3221 | } |
| 3222 | mFocusCallbacks.finishBroadcast(); |
| 3223 | } |
| 3224 | } |
| 3225 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3226 | @Override |
| 3227 | public Configuration getConfiguration() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3228 | if (mActivityRecord != null && mActivityRecord.mFrozenMergedConfig.size() > 0) { |
| 3229 | return mActivityRecord.mFrozenMergedConfig.peek(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3230 | } |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3231 | |
Yunfan Chen | b4fe58c | 2019-03-27 18:35:06 +0900 | [diff] [blame] | 3232 | // If the process has not registered to any display to listen to the configuration change, |
| 3233 | // we can simply return the mFullConfiguration as default. |
| 3234 | if (!registeredForDisplayConfigChanges()) { |
| 3235 | return super.getConfiguration(); |
| 3236 | } |
| 3237 | |
Yunfan Chen | 75157d7 | 2018-07-27 14:47:21 +0900 | [diff] [blame] | 3238 | // We use the process config this window is associated with as the based global config since |
Yunfan Chen | b4fe58c | 2019-03-27 18:35:06 +0900 | [diff] [blame] | 3239 | // the process can override its config, but isn't part of the window hierarchy. |
| 3240 | mTempConfiguration.setTo(getProcessGlobalConfiguration()); |
| 3241 | mTempConfiguration.updateFrom(getMergedOverrideConfiguration()); |
| 3242 | return mTempConfiguration; |
| 3243 | } |
| 3244 | |
| 3245 | /** @return {@code true} if the process registered to a display as a config listener. */ |
| 3246 | private boolean registeredForDisplayConfigChanges() { |
| 3247 | final WindowState parentWindow = getParentWindow(); |
| 3248 | final Session session = parentWindow != null ? parentWindow.mSession : mSession; |
| 3249 | // System process or invalid process cannot register to display config change. |
| 3250 | if (session.mPid == MY_PID || session.mPid < 0) return false; |
| 3251 | WindowProcessController app = |
| 3252 | mWmService.mAtmService.getProcessController(session.mPid, session.mUid); |
| 3253 | if (app == null || !app.registeredForDisplayConfigChanges()) return false; |
| 3254 | return true; |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3257 | void reportResized() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3258 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag()); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3259 | try { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3260 | ProtoLog.v(WM_DEBUG_RESIZE, |
| 3261 | "Reporting new frame to %s: %s", this, |
| 3262 | mWindowFrames.mCompatFrame); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3263 | final MergedConfiguration mergedConfiguration = |
Andrii Kulian | 859f0a5 | 2019-05-20 12:18:09 +0000 | [diff] [blame] | 3264 | new MergedConfiguration(mWmService.mRoot.getConfiguration(), |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3265 | getMergedOverrideConfiguration()); |
| 3266 | |
Bryce Lee | 2b17afd | 2017-09-21 10:38:20 -0700 | [diff] [blame] | 3267 | setLastReportedMergedConfiguration(mergedConfiguration); |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 3268 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 3269 | if (mWinAnimator.mDrawState == DRAW_PENDING) { |
| 3270 | ProtoLog.i(WM_DEBUG_ORIENTATION, |
| 3271 | "Resizing %s WITH DRAW PENDING", this); |
| 3272 | } |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 3273 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3274 | final Rect frame = mWindowFrames.mCompatFrame; |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3275 | final Rect contentInsets = mWindowFrames.mLastContentInsets; |
| 3276 | final Rect visibleInsets = mWindowFrames.mLastVisibleInsets; |
| 3277 | final Rect stableInsets = mWindowFrames.mLastStableInsets; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3278 | final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3279 | final boolean reportOrientation = mReportOrientationChanged; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3280 | final int displayId = getDisplayId(); |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 3281 | final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout(); |
Chet Haase | 8eb48d2 | 2014-09-24 07:31:29 -0700 | [diff] [blame] | 3282 | if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 3283 | && mClient instanceof IWindow.Stub) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3284 | // 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] | 3285 | mWmService.mH.post(new Runnable() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3286 | @Override |
| 3287 | public void run() { |
| 3288 | try { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 3289 | dispatchResized(frame, contentInsets, visibleInsets, |
| 3290 | stableInsets, reportDraw, mergedConfiguration, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3291 | reportOrientation, displayId, displayCutout); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3292 | } catch (RemoteException e) { |
| 3293 | // Not a remote call, RemoteException won't be raised. |
| 3294 | } |
| 3295 | } |
| 3296 | }); |
| 3297 | } else { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 3298 | dispatchResized(frame, contentInsets, visibleInsets, stableInsets, |
| 3299 | reportDraw, mergedConfiguration, reportOrientation, displayId, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3300 | displayCutout); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3301 | } |
Jacky Kao | f93252b | 2019-07-18 15:19:52 +0800 | [diff] [blame] | 3302 | if (mWmService.mAccessibilityController != null) { |
| 3303 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked( |
| 3304 | getDisplayId()); |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3305 | } |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 3306 | updateLocationInParentDisplayIfNeeded(); |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3307 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3308 | mWindowFrames.resetInsetsChanged(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3309 | mWinAnimator.mSurfaceResized = false; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 3310 | mReportOrientationChanged = false; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3311 | } catch (RemoteException e) { |
Bryce Lee | 8c3cf38 | 2017-07-06 19:47:10 -0700 | [diff] [blame] | 3312 | setOrientationChanging(false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3313 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3314 | - mWmService.mDisplayFreezeTime); |
tiger_huang | 950ee77 | 2014-07-11 18:41:48 +0800 | [diff] [blame] | 3315 | // We are assuming the hosting process is dead or in a zombie state. |
| 3316 | Slog.w(TAG, "Failed to report 'resized' to the client of " + this |
| 3317 | + ", removing this window."); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3318 | mWmService.mPendingRemove.add(this); |
| 3319 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3320 | } |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3321 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3322 | } |
| 3323 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 3324 | void updateLocationInParentDisplayIfNeeded() { |
| 3325 | final int embeddedDisplayContentsSize = mEmbeddedDisplayContents.size(); |
| 3326 | // If there is any embedded display which is re-parented to this window, we need to |
| 3327 | // notify all windows in the embedded display about the location change. |
| 3328 | if (embeddedDisplayContentsSize != 0) { |
| 3329 | for (int i = embeddedDisplayContentsSize - 1; i >= 0; i--) { |
| 3330 | final DisplayContent edc = mEmbeddedDisplayContents.valueAt(i); |
| 3331 | edc.notifyLocationInParentDisplayChanged(); |
| 3332 | } |
| 3333 | } |
| 3334 | // If this window is in a embedded display which is re-parented to another window, |
| 3335 | // we may need to update its correct on-screen location. |
| 3336 | final DisplayContent dc = getDisplayContent(); |
| 3337 | if (dc.getParentWindow() == null) { |
| 3338 | return; |
| 3339 | } |
| 3340 | |
| 3341 | final Point offset = dc.getLocationInParentDisplay(); |
| 3342 | if (mLastReportedDisplayOffset.equals(offset)) { |
| 3343 | return; |
| 3344 | } |
| 3345 | |
| 3346 | mLastReportedDisplayOffset.set(offset.x, offset.y); |
| 3347 | try { |
| 3348 | mClient.locationInParentDisplayChanged(mLastReportedDisplayOffset); |
| 3349 | } catch (RemoteException e) { |
| 3350 | Slog.e(TAG, "Failed to update offset from DisplayContent", e); |
| 3351 | } |
| 3352 | } |
| 3353 | |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3354 | /** |
| 3355 | * Called when the insets state changed. |
| 3356 | */ |
| 3357 | void notifyInsetsChanged() { |
| 3358 | try { |
| 3359 | mClient.insetsChanged( |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3360 | getDisplayContent().getInsetsPolicy().getInsetsForDispatch(this)); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3361 | } catch (RemoteException e) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 3362 | Slog.w(TAG, "Failed to deliver inset state change w=" + this, e); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | |
Jorim Jaggi | 2862047 | 2019-01-02 23:21:49 +0100 | [diff] [blame] | 3366 | @Override |
| 3367 | public void notifyInsetsControlChanged() { |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 3368 | final InsetsStateController stateController = |
| 3369 | getDisplayContent().getInsetsStateController(); |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3370 | final InsetsPolicy policy = getDisplayContent().getInsetsPolicy(); |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 3371 | try { |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3372 | mClient.insetsControlChanged(policy.getInsetsForDispatch(this), |
Jorim Jaggi | b603095 | 2018-10-23 18:31:52 +0200 | [diff] [blame] | 3373 | stateController.getControlsForDispatch(this)); |
| 3374 | } catch (RemoteException e) { |
| 3375 | Slog.w(TAG, "Failed to deliver inset state change", e); |
| 3376 | } |
| 3377 | } |
| 3378 | |
Tarandeep Singh | 0bedd94 | 2019-09-26 13:34:03 -0700 | [diff] [blame] | 3379 | @Override |
| 3380 | public void showInsets(@InsetType int types, boolean fromIme) { |
| 3381 | try { |
| 3382 | mClient.showInsets(types, fromIme); |
| 3383 | } catch (RemoteException e) { |
| 3384 | Slog.w(TAG, "Failed to deliver showInsets", e); |
| 3385 | } |
| 3386 | } |
| 3387 | |
Taran Singh | f1e0887 | 2019-10-10 14:38:52 +0200 | [diff] [blame] | 3388 | @Override |
| 3389 | public void hideInsets(@InsetType int types, boolean fromIme) { |
| 3390 | try { |
| 3391 | mClient.hideInsets(types, fromIme); |
| 3392 | } catch (RemoteException e) { |
| 3393 | Slog.w(TAG, "Failed to deliver showInsets", e); |
| 3394 | } |
| 3395 | } |
| 3396 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 3397 | @Override |
| 3398 | public boolean canShowTransient() { |
| 3399 | return (mAttrs.insetsFlags.behavior & BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) != 0; |
| 3400 | } |
| 3401 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3402 | Rect getBackdropFrame(Rect frame) { |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 3403 | // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing |
| 3404 | // start even if we haven't received the relayout window, so that the client requests |
| 3405 | // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen |
| 3406 | // until the window to small size, otherwise the multithread renderer will shift last |
| 3407 | // one or more frame to wrong offset. So here we send fullscreen backdrop if either |
| 3408 | // isDragResizing() or isDragResizeChanged() is true. |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3409 | boolean resizing = isDragResizing() || isDragResizeChanged(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 3410 | if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) { |
Garfield Tan | fbd8ea6 | 2018-10-16 17:09:49 -0700 | [diff] [blame] | 3411 | // Surface position is now inherited from parent, and BackdropFrameRenderer uses |
| 3412 | // backdrop frame to position content. Thus we just keep the size of backdrop frame, and |
| 3413 | // remove the offset to avoid double offset from display origin. |
| 3414 | mTmpRect.set(frame); |
| 3415 | mTmpRect.offsetTo(0, 0); |
| 3416 | return mTmpRect; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3417 | } |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 3418 | final DisplayInfo displayInfo = getDisplayInfo(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3419 | mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3420 | return mTmpRect; |
| 3421 | } |
| 3422 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3423 | private int getStackId() { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3424 | final ActivityStack stack = getStack(); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3425 | if (stack == null) { |
| 3426 | return INVALID_STACK_ID; |
| 3427 | } |
| 3428 | return stack.mStackId; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3429 | } |
| 3430 | |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 3431 | private void dispatchResized(Rect frame, Rect contentInsets, |
| 3432 | Rect visibleInsets, Rect stableInsets, boolean reportDraw, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3433 | MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId, |
| 3434 | DisplayCutout displayCutout) |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3435 | throws RemoteException { |
Robert Carr | 09286c9 | 2018-02-15 13:52:31 -0800 | [diff] [blame] | 3436 | final boolean forceRelayout = isDragResizeChanged() || reportOrientation; |
Chong Zhang | edaf305 | 2016-04-22 15:04:31 -0700 | [diff] [blame] | 3437 | |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 3438 | mClient.resized(frame, contentInsets, visibleInsets, stableInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3439 | reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout, |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 3440 | getDisplayContent().getDisplayPolicy().areSystemBarsForcedShownLw(this), displayId, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 3441 | new DisplayCutout.ParcelableWrapper(displayCutout)); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3442 | mDragResizingChangeReported = true; |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3443 | } |
| 3444 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3445 | public void registerFocusObserver(IWindowFocusObserver observer) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3446 | synchronized (mWmService.mGlobalLock) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3447 | if (mFocusCallbacks == null) { |
| 3448 | mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>(); |
| 3449 | } |
| 3450 | mFocusCallbacks.register(observer); |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3455 | synchronized (mWmService.mGlobalLock) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3456 | if (mFocusCallbacks != null) { |
| 3457 | mFocusCallbacks.unregister(observer); |
| 3458 | } |
| 3459 | } |
| 3460 | } |
| 3461 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3462 | boolean isFocused() { |
| 3463 | return getDisplayContent().mCurrentFocus == this; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3464 | } |
| 3465 | |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 3466 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3467 | /** Is this window in a container that takes up the entire screen space? */ |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3468 | private boolean inAppWindowThatMatchesParentBounds() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3469 | return mActivityRecord == null || (mActivityRecord.matchParentBounds() && !inMultiWindowMode()); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3472 | /** @return true when the window is in fullscreen mode, but has non-fullscreen bounds set, or |
| 3473 | * is transitioning into/out-of fullscreen. */ |
Andrii Kulian | 283acd2 | 2017-08-03 04:03:51 -0700 | [diff] [blame] | 3474 | boolean isLetterboxedAppWindow() { |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3475 | return !inMultiWindowMode() && !matchesDisplayBounds() |
Adrian Roos | 865c70f | 2018-01-10 17:32:27 +0100 | [diff] [blame] | 3476 | || isLetterboxedForDisplayCutoutLw(); |
Adrian Roos | 4d18a2e | 2017-12-19 19:08:05 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
Adrian Roos | 865c70f | 2018-01-10 17:32:27 +0100 | [diff] [blame] | 3479 | @Override |
| 3480 | public boolean isLetterboxedForDisplayCutoutLw() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3481 | if (mActivityRecord == null) { |
| 3482 | // Only windows with an ActivityRecord are letterboxed. |
Adrian Roos | 865c70f | 2018-01-10 17:32:27 +0100 | [diff] [blame] | 3483 | return false; |
| 3484 | } |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 3485 | if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) { |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 3486 | // Cutout didn't make a difference, no letterbox |
Adrian Roos | 4d18a2e | 2017-12-19 19:08:05 +0100 | [diff] [blame] | 3487 | return false; |
| 3488 | } |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 3489 | if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) { |
Adrian Roos | 4d18a2e | 2017-12-19 19:08:05 +0100 | [diff] [blame] | 3490 | // Layout in cutout, no letterbox. |
| 3491 | return false; |
| 3492 | } |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 3493 | if (!mAttrs.isFullscreen()) { |
| 3494 | // Not filling the parent frame, no letterbox |
| 3495 | return false; |
Adrian Roos | fa02da6 | 2018-01-15 16:01:18 +0100 | [diff] [blame] | 3496 | } |
Adrian Roos | 5ed644f | 2018-03-19 17:01:05 +0100 | [diff] [blame] | 3497 | // Otherwise we need a letterbox if the layout was smaller than the app window token allowed |
| 3498 | // it to be. |
| 3499 | return !frameCoversEntireAppTokenBounds(); |
| 3500 | } |
| 3501 | |
| 3502 | /** |
| 3503 | * @return true if this window covers the entire bounds of its app window token |
| 3504 | * @throws NullPointerException if there is no app window token for this window |
| 3505 | */ |
| 3506 | private boolean frameCoversEntireAppTokenBounds() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3507 | mTmpRect.set(mActivityRecord.getBounds()); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3508 | mTmpRect.intersectUnchecked(mWindowFrames.mFrame); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3509 | return mActivityRecord.getBounds().equals(mTmpRect); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3510 | } |
| 3511 | |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 3512 | @Override |
| 3513 | public boolean isLetterboxedOverlappingWith(Rect rect) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3514 | return mActivityRecord != null && mActivityRecord.isLetterboxOverlappingWith(rect); |
Adrian Roos | 23df3a3 | 2018-03-15 15:41:13 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3517 | boolean isDragResizeChanged() { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3518 | return mDragResizing != computeDragResizing(); |
| 3519 | } |
| 3520 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3521 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3522 | void setWaitingForDrawnIfResizingChanged() { |
| 3523 | if (isDragResizeChanged()) { |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 3524 | mWmService.mRoot.mWaitingForDrawn.add(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3525 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3526 | super.setWaitingForDrawnIfResizingChanged(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3529 | /** |
| 3530 | * @return Whether we reported a drag resize change to the application or not already. |
| 3531 | */ |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3532 | private boolean isDragResizingChangeReported() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3533 | return mDragResizingChangeReported; |
| 3534 | } |
| 3535 | |
| 3536 | /** |
| 3537 | * Resets the state whether we reported a drag resize change to the app. |
| 3538 | */ |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3539 | @Override |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3540 | void resetDragResizingChangeReported() { |
| 3541 | mDragResizingChangeReported = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3542 | super.resetDragResizingChangeReported(); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3543 | } |
| 3544 | |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 3545 | int getResizeMode() { |
| 3546 | return mResizeMode; |
| 3547 | } |
| 3548 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3549 | private boolean computeDragResizing() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 3550 | final Task task = getTask(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3551 | if (task == null) { |
| 3552 | return false; |
| 3553 | } |
Tomasz Mikolajewski | af20b8d | 2017-11-20 16:11:33 +0900 | [diff] [blame] | 3554 | if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) { |
Winson Chung | 2af04b3 | 2017-01-24 16:21:13 -0800 | [diff] [blame] | 3555 | return false; |
| 3556 | } |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 3557 | if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) { |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 3558 | // Floating windows never enter drag resize mode. |
| 3559 | return false; |
| 3560 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3561 | if (task.isDragResizing()) { |
| 3562 | return true; |
| 3563 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 3564 | |
| 3565 | // If the bounds are currently frozen, it means that the layout size that the app sees |
| 3566 | // and the bounds we clip this window to might be different. In order to avoid holes, we |
| 3567 | // simulate that we are still resizing so the app fills the hole with the resizing |
| 3568 | // background. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3569 | return (getDisplayContent().mDividerControllerLocked.isResizing() |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3570 | || mActivityRecord != null && !mActivityRecord.mFrozenBounds.isEmpty()) && |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3571 | !task.inFreeformWindowingMode() && !isGoneForLayoutLw(); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3572 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3573 | } |
| 3574 | |
| 3575 | void setDragResizing() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3576 | final boolean resizing = computeDragResizing(); |
| 3577 | if (resizing == mDragResizing) { |
| 3578 | return; |
| 3579 | } |
| 3580 | mDragResizing = resizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3581 | final Task task = getTask(); |
| 3582 | if (task != null && task.isDragResizing()) { |
| 3583 | mResizeMode = task.getDragResizeMode(); |
| 3584 | } else { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3585 | mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing() |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3586 | ? DRAG_RESIZE_MODE_DOCKED_DIVIDER |
| 3587 | : DRAG_RESIZE_MODE_FREEFORM; |
| 3588 | } |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | boolean isDragResizing() { |
| 3592 | return mDragResizing; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 3595 | boolean isDockedResizing() { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 3596 | return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER) |
| 3597 | || (isChildWindow() && getParentWindow().isDockedResizing()); |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 3598 | } |
| 3599 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 3600 | @CallSuper |
| 3601 | @Override |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3602 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 3603 | @WindowTraceLogLevel int logLevel) { |
| 3604 | boolean isVisible = isVisible(); |
| 3605 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) { |
| 3606 | return; |
| 3607 | } |
| 3608 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3609 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3610 | super.writeToProto(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3611 | writeIdentifierToProto(proto, IDENTIFIER); |
| 3612 | proto.write(DISPLAY_ID, getDisplayId()); |
| 3613 | proto.write(STACK_ID, getStackId()); |
| 3614 | mAttrs.writeToProto(proto, ATTRIBUTES); |
| 3615 | mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 3616 | mWindowFrames.writeToProto(proto, WINDOW_FRAMES); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3617 | mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS); |
Jorim Jaggi | 45be1c4c | 2017-12-15 18:44:43 +0100 | [diff] [blame] | 3618 | mSurfacePosition.writeToProto(proto, SURFACE_POSITION); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3619 | mWinAnimator.writeToProto(proto, ANIMATOR); |
| 3620 | proto.write(ANIMATING_EXIT, mAnimatingExit); |
| 3621 | for (int i = 0; i < mChildren.size(); i++) { |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3622 | mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3623 | } |
Vishnu Nair | 1d0fa07 | 2018-01-04 07:53:00 -0800 | [diff] [blame] | 3624 | proto.write(REQUESTED_WIDTH, mRequestedWidth); |
| 3625 | proto.write(REQUESTED_HEIGHT, mRequestedHeight); |
| 3626 | proto.write(VIEW_VISIBILITY, mViewVisibility); |
| 3627 | proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility); |
| 3628 | proto.write(HAS_SURFACE, mHasSurface); |
| 3629 | proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay()); |
Vishnu Nair | 1d0fa07 | 2018-01-04 07:53:00 -0800 | [diff] [blame] | 3630 | proto.write(REMOVE_ON_EXIT, mRemoveOnExit); |
| 3631 | proto.write(DESTROYING, mDestroying); |
| 3632 | proto.write(REMOVED, mRemoved); |
| 3633 | proto.write(IS_ON_SCREEN, isOnScreen()); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 3634 | proto.write(IS_VISIBLE, isVisible); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 3635 | proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null); |
| 3636 | proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber); |
| 3637 | proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3638 | proto.end(token); |
| 3639 | } |
| 3640 | |
Vishnu Nair | 9a3e406 | 2018-01-11 08:42:54 -0800 | [diff] [blame] | 3641 | @Override |
| 3642 | public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) { |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 3643 | final long token = proto.start(fieldId); |
| 3644 | proto.write(HASH_CODE, System.identityHashCode(this)); |
| 3645 | proto.write(USER_ID, UserHandle.getUserId(mOwnerUid)); |
| 3646 | final CharSequence title = getWindowTag(); |
| 3647 | if (title != null) { |
| 3648 | proto.write(TITLE, title.toString()); |
| 3649 | } |
| 3650 | proto.end(token); |
| 3651 | } |
| 3652 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 3653 | @Override |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3654 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 3655 | final ActivityStack stack = getStack(); |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3656 | pw.print(prefix + "mDisplayId=" + getDisplayId()); |
| 3657 | if (stack != null) { |
| 3658 | pw.print(" stackId=" + stack.mStackId); |
| 3659 | } |
| 3660 | pw.println(" mSession=" + mSession |
| 3661 | + " mClient=" + mClient.asBinder()); |
| 3662 | pw.println(prefix + "mOwnerUid=" + mOwnerUid |
| 3663 | + " mShowToOwnerOnly=" + mShowToOwnerOnly |
| 3664 | + " package=" + mAttrs.packageName |
| 3665 | + " appop=" + AppOpsManager.opToName(mAppOp)); |
| 3666 | pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix)); |
| 3667 | pw.println(prefix + "Requested w=" + mRequestedWidth |
| 3668 | + " h=" + mRequestedHeight |
| 3669 | + " mLayoutSeq=" + mLayoutSeq); |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 3670 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3671 | pw.println(prefix + "LastRequested w=" + mLastRequestedWidth |
| 3672 | + " h=" + mLastRequestedHeight); |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 3673 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3674 | if (mIsChildWindow || mLayoutAttached) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3675 | pw.println(prefix + "mParentWindow=" + getParentWindow() |
| 3676 | + " mLayoutAttached=" + mLayoutAttached); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3677 | } |
| 3678 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3679 | pw.println(prefix + "mIsImWindow=" + mIsImWindow |
| 3680 | + " mIsWallpaper=" + mIsWallpaper |
| 3681 | + " mIsFloatingLayer=" + mIsFloatingLayer |
| 3682 | + " mWallpaperVisible=" + mWallpaperVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3683 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3684 | if (dumpAll) { |
Jorim Jaggi | 35d328a | 2018-08-14 17:00:20 +0200 | [diff] [blame] | 3685 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 3686 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3687 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3688 | if (dumpAll) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3689 | pw.println(prefix + "mToken=" + mToken); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 3690 | if (mActivityRecord != null) { |
| 3691 | pw.println(prefix + "mActivityRecord=" + mActivityRecord); |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3692 | pw.print(prefix + "mAppDied=" + mAppDied); |
| 3693 | pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated()); |
| 3694 | pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn()); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3695 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3696 | pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility) |
| 3697 | + " mHaveFrame=" + mHaveFrame |
| 3698 | + " mObscured=" + mObscured); |
| 3699 | pw.println(prefix + "mSeq=" + mSeq |
| 3700 | + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3701 | } |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 3702 | if (!isVisibleByPolicy() || !mLegacyPolicyVisibilityAfterAnim || !mAppOpVisibility |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3703 | || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 3704 | || mHiddenWhileSuspended) { |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 3705 | pw.println(prefix + "mPolicyVisibility=" + isVisibleByPolicy() |
| 3706 | + " mLegacyPolicyVisibilityAfterAnim=" + mLegacyPolicyVisibilityAfterAnim |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3707 | + " mAppOpVisibility=" + mAppOpVisibility |
| 3708 | + " parentHidden=" + isParentWindowHidden() |
| 3709 | + " mPermanentlyHidden=" + mPermanentlyHidden |
| 3710 | + " mHiddenWhileSuspended=" + mHiddenWhileSuspended |
| 3711 | + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3712 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 3713 | if (!mRelayoutCalled || mLayoutNeeded) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3714 | pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled |
| 3715 | + " mLayoutNeeded=" + mLayoutNeeded); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3716 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3717 | if (dumpAll) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3718 | pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB) |
| 3719 | + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3720 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3721 | pw.println(prefix + "mTouchableInsets=" + mTouchableInsets |
| 3722 | + " mGivenInsetsPending=" + mGivenInsetsPending); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3723 | Region region = new Region(); |
| 3724 | getTouchableRegion(region); |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3725 | pw.println(prefix + "touchable region=" + region); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3726 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3727 | pw.println(prefix + "mFullConfiguration=" + getConfiguration()); |
| 3728 | pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3729 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3730 | pw.println(prefix + "mHasSurface=" + mHasSurface |
| 3731 | + " isReadyForDisplay()=" + isReadyForDisplay() |
| 3732 | + " mWindowRemovalAllowed=" + mWindowRemovalAllowed); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3733 | if (inSizeCompatMode()) { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3734 | pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB)); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3735 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3736 | if (dumpAll) { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 3737 | mWindowFrames.dump(pw, prefix); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3738 | pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3739 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 3740 | super.dump(pw, prefix, dumpAll); |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3741 | pw.println(prefix + mWinAnimator + ":"); |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 3742 | mWinAnimator.dump(pw, prefix + " ", dumpAll); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3743 | if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3744 | pw.println(prefix + "mAnimatingExit=" + mAnimatingExit |
| 3745 | + " mRemoveOnExit=" + mRemoveOnExit |
| 3746 | + " mDestroying=" + mDestroying |
| 3747 | + " mRemoved=" + mRemoved); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3748 | } |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 3749 | if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3750 | pw.println(prefix + "mOrientationChanging=" + mOrientationChanging |
| 3751 | + " configOrientationChanging=" |
| 3752 | + (getLastReportedConfiguration().orientation != getConfiguration().orientation) |
| 3753 | + " mAppFreezing=" + mAppFreezing |
| 3754 | + " mReportOrientationChanged=" + mReportOrientationChanged); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3755 | } |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 3756 | if (mLastFreezeDuration != 0) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3757 | pw.print(prefix + "mLastFreezeDuration="); |
| 3758 | TimeUtils.formatDuration(mLastFreezeDuration, pw); |
| 3759 | pw.println(); |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 3760 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3761 | pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate |
| 3762 | + " seamlesslyRotate: pending="); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 3763 | if (mPendingSeamlessRotate != null) { |
| 3764 | mPendingSeamlessRotate.dump(pw); |
| 3765 | } else { |
| 3766 | pw.print("null"); |
Adrian Roos | 27a90d2 | 2018-07-06 02:39:54 -0700 | [diff] [blame] | 3767 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3768 | pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber); |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 3769 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3770 | if (mHScale != 1 || mVScale != 1) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3771 | pw.println(prefix + "mHScale=" + mHScale |
| 3772 | + " mVScale=" + mVScale); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3773 | } |
| 3774 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3775 | pw.println(prefix + "mWallpaperX=" + mWallpaperX |
| 3776 | + " mWallpaperY=" + mWallpaperY); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3777 | } |
| 3778 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3779 | pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep |
| 3780 | + " mWallpaperYStep=" + mWallpaperYStep); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3781 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3782 | if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE |
| 3783 | || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3784 | pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX |
| 3785 | + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3786 | } |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3787 | if (mDrawLock != null) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3788 | pw.println(prefix + "mDrawLock=" + mDrawLock); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3789 | } |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3790 | if (isDragResizing()) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3791 | pw.println(prefix + "isDragResizing=" + isDragResizing()); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3792 | } |
| 3793 | if (computeDragResizing()) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3794 | pw.println(prefix + "computeDragResizing=" + computeDragResizing()); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3795 | } |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 3796 | pw.println(prefix + "isOnScreen=" + isOnScreen()); |
| 3797 | pw.println(prefix + "isVisible=" + isVisible()); |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 3798 | pw.println(prefix + "mEmbeddedDisplayContents=" + mEmbeddedDisplayContents); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3799 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3800 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3801 | @Override |
| 3802 | String getName() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3803 | return Integer.toHexString(System.identityHashCode(this)) |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 3804 | + " " + getWindowTag(); |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3805 | } |
| 3806 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3807 | CharSequence getWindowTag() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3808 | CharSequence tag = mAttrs.getTitle(); |
| 3809 | if (tag == null || tag.length() <= 0) { |
| 3810 | tag = mAttrs.packageName; |
| 3811 | } |
| 3812 | return tag; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | @Override |
| 3816 | public String toString() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3817 | final CharSequence title = getWindowTag(); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3818 | if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 3819 | mLastTitle = title; |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3820 | mWasExiting = mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3821 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3822 | + " u" + UserHandle.getUserId(mOwnerUid) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3823 | + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3824 | } |
| 3825 | return mStringNameCache; |
| 3826 | } |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3827 | |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3828 | void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) { |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 3829 | if (mHScale == 1 && mVScale == 1) { |
| 3830 | return; |
| 3831 | } |
| 3832 | if (mHScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3833 | clipRect.left = (int) (clipRect.left / mHScale); |
| 3834 | clipRect.right = (int) Math.ceil(clipRect.right / mHScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3835 | } |
| 3836 | if (mVScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3837 | clipRect.top = (int) (clipRect.top / mVScale); |
| 3838 | clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3839 | } |
| 3840 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3841 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3842 | private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) { |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3843 | final int pw = containingFrame.width(); |
| 3844 | final int ph = containingFrame.height(); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3845 | final Task task = getTask(); |
Evan Rosky | 4fb1e91 | 2019-03-06 13:54:43 -0800 | [diff] [blame] | 3846 | final boolean inNonFullscreenContainer = !inAppWindowThatMatchesParentBounds(); |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 3847 | final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0; |
| 3848 | |
| 3849 | // We need to fit it to the display if either |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3850 | // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen |
| 3851 | // for the taskless windows) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3852 | // 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] | 3853 | // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on |
| 3854 | // screen, but SurfaceViews want to be always at a specific location so we don't fit it to |
| 3855 | // the display. |
| 3856 | final boolean fitToDisplay = (task == null || !inNonFullscreenContainer) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3857 | || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3858 | float x, y; |
| 3859 | int w,h; |
| 3860 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3861 | final boolean inSizeCompatMode = inSizeCompatMode(); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3862 | if ((mAttrs.flags & FLAG_SCALED) != 0) { |
| 3863 | if (mAttrs.width < 0) { |
| 3864 | w = pw; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3865 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3866 | w = (int)(mAttrs.width * mGlobalScale + .5f); |
| 3867 | } else { |
| 3868 | w = mAttrs.width; |
| 3869 | } |
| 3870 | if (mAttrs.height < 0) { |
| 3871 | h = ph; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3872 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3873 | h = (int)(mAttrs.height * mGlobalScale + .5f); |
| 3874 | } else { |
| 3875 | h = mAttrs.height; |
| 3876 | } |
| 3877 | } else { |
| 3878 | if (mAttrs.width == MATCH_PARENT) { |
| 3879 | w = pw; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3880 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3881 | w = (int)(mRequestedWidth * mGlobalScale + .5f); |
| 3882 | } else { |
| 3883 | w = mRequestedWidth; |
| 3884 | } |
| 3885 | if (mAttrs.height == MATCH_PARENT) { |
| 3886 | h = ph; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3887 | } else if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3888 | h = (int)(mRequestedHeight * mGlobalScale + .5f); |
| 3889 | } else { |
| 3890 | h = mRequestedHeight; |
| 3891 | } |
| 3892 | } |
| 3893 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3894 | if (inSizeCompatMode) { |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3895 | x = mAttrs.x * mGlobalScale; |
| 3896 | y = mAttrs.y * mGlobalScale; |
| 3897 | } else { |
| 3898 | x = mAttrs.x; |
| 3899 | y = mAttrs.y; |
| 3900 | } |
| 3901 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 3902 | if (inNonFullscreenContainer && !layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 3903 | // 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] | 3904 | // required by {@link Gravity#apply} call. |
| 3905 | w = Math.min(w, pw); |
| 3906 | h = Math.min(h, ph); |
| 3907 | } |
| 3908 | |
| 3909 | // Set mFrame |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3910 | Gravity.apply(mAttrs.gravity, w, h, containingFrame, |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3911 | (int) (x + mAttrs.horizontalMargin * pw), |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3912 | (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3913 | |
| 3914 | // Now make sure the window fits in the overall display frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3915 | if (fitToDisplay) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 3916 | Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3917 | } |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3918 | |
| 3919 | // We need to make sure we update the CompatFrame as it is used for |
| 3920 | // cropping decisions, etc, on systems where we lack a decor layer. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3921 | mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 3922 | if (inSizeCompatMode) { |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3923 | // See comparable block in computeFrameLw. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 3924 | mWindowFrames.mCompatFrame.scale(mInvGlobalScale); |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3925 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3926 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 3927 | |
| 3928 | boolean isChildWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3929 | return mIsChildWindow; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3932 | boolean layoutInParentFrame() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3933 | return mIsChildWindow |
| 3934 | && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0; |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3935 | } |
| 3936 | |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 3937 | /** |
| 3938 | * Returns true if any window added by an application process that if of type |
| 3939 | * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires |
| 3940 | * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when |
| 3941 | * this window is visible. |
| 3942 | */ |
| 3943 | boolean hideNonSystemOverlayWindowsWhenVisible() { |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 3944 | return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0 |
Wale Ogunwale | 01ad434 | 2017-06-30 07:07:01 -0700 | [diff] [blame] | 3945 | && mSession.mCanHideNonSystemOverlayWindows; |
| 3946 | } |
| 3947 | |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3948 | /** Returns the parent window if this is a child of another window, else null. */ |
| 3949 | WindowState getParentWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3950 | // NOTE: We are not calling getParent() directly as the WindowState might be a child of a |
| 3951 | // WindowContainer that isn't a WindowState. |
| 3952 | return (mIsChildWindow) ? ((WindowState) super.getParent()) : null; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /** Returns the topmost parent window if this is a child of another window, else this. */ |
| 3956 | WindowState getTopParentWindow() { |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3957 | WindowState current = this; |
| 3958 | WindowState topParent = current; |
| 3959 | while (current != null && current.mIsChildWindow) { |
| 3960 | current = current.getParentWindow(); |
| 3961 | // Parent window can be null if the child is detached from it's parent already, but |
| 3962 | // someone still has a reference to access it. So, we return the top parent value we |
| 3963 | // already have instead of null. |
| 3964 | if (current != null) { |
| 3965 | topParent = current; |
| 3966 | } |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3967 | } |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3968 | return topParent; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3971 | boolean isParentWindowHidden() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3972 | final WindowState parent = getParentWindow(); |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 3973 | return parent != null && parent.mHidden; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
Jorim Jaggi | b52b045 | 2019-07-16 17:43:15 +0200 | [diff] [blame] | 3976 | private boolean isParentWindowGoneForLayout() { |
| 3977 | final WindowState parent = getParentWindow(); |
| 3978 | return parent != null && parent.isGoneForLayoutLw(); |
| 3979 | } |
| 3980 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3981 | void setWillReplaceWindow(boolean animate) { |
| 3982 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3983 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3984 | c.setWillReplaceWindow(animate); |
| 3985 | } |
| 3986 | |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3987 | if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0 |
| 3988 | || mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 3989 | // We don't set replacing on starting windows since they are added by window manager and |
| 3990 | // not the client so won't be replaced by the client. |
| 3991 | return; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3992 | } |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3993 | |
| 3994 | mWillReplaceWindow = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3995 | mReplacementWindow = null; |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3996 | mAnimateReplacingWindow = animate; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3997 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3998 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3999 | void clearWillReplaceWindow() { |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 4000 | mWillReplaceWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4001 | mReplacementWindow = null; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 4002 | mAnimateReplacingWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4003 | |
| 4004 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4005 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4006 | c.clearWillReplaceWindow(); |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | boolean waitingForReplacement() { |
| 4011 | if (mWillReplaceWindow) { |
| 4012 | return true; |
| 4013 | } |
| 4014 | |
| 4015 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4016 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4017 | if (c.waitingForReplacement()) { |
| 4018 | return true; |
| 4019 | } |
| 4020 | } |
| 4021 | return false; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 4022 | } |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 4023 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 4024 | void requestUpdateWallpaperIfNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 4025 | final DisplayContent dc = getDisplayContent(); |
| 4026 | if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 4027 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 4028 | dc.setLayoutNeeded(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4029 | mWmService.mWindowPlacerLocked.requestTraversal(); |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 4030 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4031 | |
| 4032 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4033 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4034 | c.requestUpdateWallpaperIfNeeded(); |
| 4035 | } |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 4036 | } |
| 4037 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 4038 | float translateToWindowX(float x) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4039 | float winX = x - mWindowFrames.mFrame.left; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4040 | if (inSizeCompatMode()) { |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 4041 | winX *= mGlobalScale; |
| 4042 | } |
| 4043 | return winX; |
| 4044 | } |
| 4045 | |
| 4046 | float translateToWindowY(float y) { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4047 | float winY = y - mWindowFrames.mFrame.top; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4048 | if (inSizeCompatMode()) { |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 4049 | winY *= mGlobalScale; |
| 4050 | } |
| 4051 | return winY; |
| 4052 | } |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 4053 | |
| 4054 | // During activity relaunch due to resize, we sometimes use window replacement |
| 4055 | // for only child windows (as the main window is handled by window preservation) |
| 4056 | // and the big surface. |
| 4057 | // |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 4058 | // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to |
| 4059 | // TYPE_BASE_APPLICATION) are not children in the sense of an attached window, |
| 4060 | // we also want to replace them at such phases, as they won't be covered by window |
| 4061 | // preservation, and in general we expect them to return following relaunch. |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 4062 | boolean shouldBeReplacedWithChildren() { |
Chong Zhang | 921f8e3 | 2016-08-17 14:26:57 -0700 | [diff] [blame] | 4063 | return mIsChildWindow || mAttrs.type == TYPE_APPLICATION |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 4064 | || mAttrs.type == TYPE_DRAWN_APPLICATION; |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 4065 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 4066 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4067 | void setWillReplaceChildWindows() { |
| 4068 | if (shouldBeReplacedWithChildren()) { |
| 4069 | setWillReplaceWindow(false /* animate */); |
| 4070 | } |
| 4071 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4072 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4073 | c.setWillReplaceChildWindows(); |
| 4074 | } |
| 4075 | } |
| 4076 | |
| 4077 | WindowState getReplacingWindow() { |
| 4078 | if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) { |
| 4079 | return this; |
| 4080 | } |
| 4081 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4082 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4083 | final WindowState replacing = c.getReplacingWindow(); |
| 4084 | if (replacing != null) { |
| 4085 | return replacing; |
| 4086 | } |
| 4087 | } |
| 4088 | return null; |
| 4089 | } |
| 4090 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4091 | @Override |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 4092 | public int getRotationAnimationHint() { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4093 | if (mActivityRecord != null) { |
| 4094 | return mActivityRecord.mRotationAnimationHint; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 4095 | } else { |
| 4096 | return -1; |
| 4097 | } |
| 4098 | } |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4099 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4100 | @Override |
| 4101 | public boolean isInputMethodWindow() { |
| 4102 | return mIsImWindow; |
| 4103 | } |
| 4104 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4105 | // This must be called while inside a transaction. |
| 4106 | boolean performShowLocked() { |
| 4107 | if (isHiddenFromUserLocked()) { |
| 4108 | if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid); |
chaviw | bb6bd8a | 2019-05-28 17:05:28 -0700 | [diff] [blame] | 4109 | clearPolicyVisibilityFlag(VISIBLE_FOR_USER); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4110 | return false; |
| 4111 | } |
| 4112 | |
| 4113 | logPerformShow("performShow on "); |
| 4114 | |
Jorim Jaggi | a50da60 | 2016-12-29 11:51:42 +0100 | [diff] [blame] | 4115 | final int drawState = mWinAnimator.mDrawState; |
| 4116 | if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW) |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4117 | && mAttrs.type != TYPE_APPLICATION_STARTING && mActivityRecord != null) { |
| 4118 | mActivityRecord.onFirstWindowDrawn(this, mWinAnimator); |
Jorim Jaggi | a50da60 | 2016-12-29 11:51:42 +0100 | [diff] [blame] | 4119 | } |
| 4120 | |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 4121 | if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4122 | return false; |
| 4123 | } |
| 4124 | |
| 4125 | logPerformShow("Showing "); |
| 4126 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4127 | mWmService.enableScreenIfNeededLocked(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4128 | mWinAnimator.applyEnterAnimationLocked(); |
| 4129 | |
| 4130 | // Force the show in the next prepareSurfaceLocked() call. |
| 4131 | mWinAnimator.mLastAlpha = -1; |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 4132 | if (DEBUG_ANIM) Slog.v(TAG, |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4133 | "performShowLocked: mDrawState=HAS_DRAWN in " + this); |
| 4134 | mWinAnimator.mDrawState = HAS_DRAWN; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4135 | mWmService.scheduleAnimationLocked(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4136 | |
| 4137 | if (mHidden) { |
| 4138 | mHidden = false; |
| 4139 | final DisplayContent displayContent = getDisplayContent(); |
| 4140 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4141 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4142 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4143 | if (c.mWinAnimator.mSurfaceController != null) { |
| 4144 | c.performShowLocked(); |
| 4145 | // It hadn't been shown, which means layout not performed on it, so now we |
| 4146 | // want to make sure to do a layout. If called from within the transaction |
| 4147 | // loop, this will cause it to restart with a new layout. |
| 4148 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 4149 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4150 | } |
| 4151 | } |
| 4152 | } |
| 4153 | } |
| 4154 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4155 | if (mAttrs.type == TYPE_INPUT_METHOD) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 4156 | getDisplayContent().mDividerControllerLocked.resetImeHideRequested(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | return true; |
| 4160 | } |
| 4161 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 4162 | private void logPerformShow(String prefix) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4163 | if (DEBUG_VISIBILITY |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 4164 | || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4165 | Slog.v(TAG, prefix + this |
| 4166 | + ": mDrawState=" + mWinAnimator.drawStateToString() |
Jorim Jaggi | b0d2734 | 2016-11-01 16:10:42 -0700 | [diff] [blame] | 4167 | + " readyForDisplay=" + isReadyForDisplay() |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4168 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING) |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 4169 | + " during animation: policyVis=" + isVisibleByPolicy() |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4170 | + " parentHidden=" + isParentWindowHidden() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4171 | + " tok.visibleRequested=" |
| 4172 | + (mActivityRecord != null && mActivityRecord.mVisibleRequested) |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 4173 | + " tok.hidden=" + (mActivityRecord != null && mActivityRecord.isHidden()) |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4174 | + " animating=" + isAnimating(TRANSITION | PARENTS) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4175 | + " tok animating=" |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4176 | + (mActivityRecord != null && mActivityRecord.isAnimating(TRANSITION)) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 4177 | + " Callers=" + Debug.getCallers(4)); |
| 4178 | } |
| 4179 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4180 | |
| 4181 | WindowInfo getWindowInfo() { |
| 4182 | WindowInfo windowInfo = WindowInfo.obtain(); |
RyanlwLin | 25a3651 | 2019-05-28 21:01:52 +0800 | [diff] [blame] | 4183 | windowInfo.displayId = getDisplayId(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4184 | windowInfo.type = mAttrs.type; |
| 4185 | windowInfo.layer = mLayer; |
| 4186 | windowInfo.token = mClient.asBinder(); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4187 | if (mActivityRecord != null) { |
| 4188 | windowInfo.activityToken = mActivityRecord.appToken.asBinder(); |
Phil Weaver | 5dc3ebc | 2017-08-16 13:04:20 -0700 | [diff] [blame] | 4189 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4190 | windowInfo.title = mAttrs.accessibilityTitle; |
Phil Weaver | bb2f28a | 2017-12-22 09:44:28 -0800 | [diff] [blame] | 4191 | // Panel windows have no public way to set the a11y title directly. Use the |
| 4192 | // regular title as a fallback. |
Phil Weaver | 568cf66 | 2018-04-24 17:09:26 -0700 | [diff] [blame] | 4193 | final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW) |
| 4194 | && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW); |
| 4195 | // Accessibility overlays should have titles that work for accessibility, and can't set |
| 4196 | // the a11y title themselves. |
| 4197 | final boolean isAccessibilityOverlay = |
| 4198 | windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; |
| 4199 | if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) { |
Jackal Guo | 25a33cbd | 2018-08-01 16:08:45 +0800 | [diff] [blame] | 4200 | final CharSequence title = mAttrs.getTitle(); |
| 4201 | windowInfo.title = TextUtils.isEmpty(title) ? null : title; |
Phil Weaver | bb2f28a | 2017-12-22 09:44:28 -0800 | [diff] [blame] | 4202 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4203 | windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor; |
| 4204 | windowInfo.focused = isFocused(); |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 4205 | Task task = getTask(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4206 | windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode(); |
Jackal Guo | ac2b62e | 2018-08-22 18:28:46 +0800 | [diff] [blame] | 4207 | windowInfo.hasFlagWatchOutsideTouch = |
| 4208 | (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4209 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4210 | if (mIsChildWindow) { |
| 4211 | windowInfo.parentToken = getParentWindow().mClient.asBinder(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4212 | } |
| 4213 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4214 | final int childCount = mChildren.size(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4215 | if (childCount > 0) { |
| 4216 | if (windowInfo.childTokens == null) { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4217 | windowInfo.childTokens = new ArrayList(childCount); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4218 | } |
| 4219 | for (int j = 0; j < childCount; j++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4220 | final WindowState child = mChildren.get(j); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4221 | windowInfo.childTokens.add(child.mClient.asBinder()); |
| 4222 | } |
| 4223 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4224 | return windowInfo; |
| 4225 | } |
| 4226 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 4227 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4228 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4229 | if (mChildren.isEmpty()) { |
| 4230 | // The window has no children so we just return it. |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4231 | return applyInOrderWithImeWindows(callback, traverseTopToBottom); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | if (traverseTopToBottom) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4235 | return forAllWindowTopToBottom(callback); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4236 | } else { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4237 | return forAllWindowBottomToTop(callback); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4238 | } |
| 4239 | } |
| 4240 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4241 | private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4242 | // 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] | 4243 | // below the parent, then this window (the parent), and then the positive sublayer children |
| 4244 | // because they need to appear above the parent. |
| 4245 | int i = 0; |
| 4246 | final int count = mChildren.size(); |
| 4247 | WindowState child = mChildren.get(i); |
| 4248 | |
| 4249 | while (i < count && child.mSubLayer < 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4250 | if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4251 | return true; |
| 4252 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4253 | i++; |
| 4254 | if (i >= count) { |
| 4255 | break; |
| 4256 | } |
| 4257 | child = mChildren.get(i); |
| 4258 | } |
| 4259 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4260 | if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4261 | return true; |
| 4262 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4263 | |
| 4264 | while (i < count) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4265 | if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4266 | return true; |
| 4267 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4268 | i++; |
| 4269 | if (i >= count) { |
| 4270 | break; |
| 4271 | } |
| 4272 | child = mChildren.get(i); |
| 4273 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4274 | |
| 4275 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4276 | } |
| 4277 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4278 | private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4279 | // 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] | 4280 | // above the parent, then this window (the parent), and then the negative sublayer children |
| 4281 | // because they need to appear above the parent. |
| 4282 | int i = mChildren.size() - 1; |
| 4283 | WindowState child = mChildren.get(i); |
| 4284 | |
| 4285 | while (i >= 0 && child.mSubLayer >= 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4286 | if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4287 | return true; |
| 4288 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4289 | --i; |
| 4290 | if (i < 0) { |
| 4291 | break; |
| 4292 | } |
| 4293 | child = mChildren.get(i); |
| 4294 | } |
| 4295 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4296 | if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4297 | return true; |
| 4298 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4299 | |
| 4300 | while (i >= 0) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4301 | if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4302 | return true; |
| 4303 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4304 | --i; |
| 4305 | if (i < 0) { |
| 4306 | break; |
| 4307 | } |
| 4308 | child = mChildren.get(i); |
| 4309 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 4310 | |
| 4311 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 4314 | private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback, |
| 4315 | boolean traverseTopToBottom) { |
| 4316 | // If this window is the current IME target, so we need to process the IME windows |
| 4317 | // directly above it. The exception is if we are in split screen |
| 4318 | // in which case we process the IME at the DisplayContent level to |
| 4319 | // ensure it is above the docked divider. |
| 4320 | if (isInputMethodTarget() && !inSplitScreenWindowingMode()) { |
| 4321 | if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) { |
| 4322 | return true; |
| 4323 | } |
| 4324 | } |
| 4325 | return false; |
| 4326 | } |
| 4327 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4328 | private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback, |
| 4329 | boolean traverseTopToBottom) { |
| 4330 | if (traverseTopToBottom) { |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 4331 | if (applyImeWindowsIfNeeded(callback, traverseTopToBottom) |
| 4332 | || callback.apply(this)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4333 | return true; |
| 4334 | } |
| 4335 | } else { |
Robert Carr | 9785cf3 | 2018-04-25 15:06:07 -0700 | [diff] [blame] | 4336 | if (callback.apply(this) |
| 4337 | || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4338 | return true; |
| 4339 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4340 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 4341 | return false; |
| 4342 | } |
| 4343 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4344 | WindowState getWindow(Predicate<WindowState> callback) { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4345 | if (mChildren.isEmpty()) { |
| 4346 | return callback.test(this) ? this : null; |
| 4347 | } |
| 4348 | |
| 4349 | // We want to consume the positive sublayer children first because they need to appear |
| 4350 | // above the parent, then this window (the parent), and then the negative sublayer children |
| 4351 | // because they need to appear above the parent. |
| 4352 | int i = mChildren.size() - 1; |
| 4353 | WindowState child = mChildren.get(i); |
| 4354 | |
| 4355 | while (i >= 0 && child.mSubLayer >= 0) { |
| 4356 | if (callback.test(child)) { |
| 4357 | return child; |
| 4358 | } |
| 4359 | --i; |
| 4360 | if (i < 0) { |
| 4361 | break; |
| 4362 | } |
| 4363 | child = mChildren.get(i); |
| 4364 | } |
| 4365 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4366 | if (callback.test(this)) { |
| 4367 | return this; |
| 4368 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 4369 | |
| 4370 | while (i >= 0) { |
| 4371 | if (callback.test(child)) { |
| 4372 | return child; |
| 4373 | } |
| 4374 | --i; |
| 4375 | if (i < 0) { |
| 4376 | break; |
| 4377 | } |
| 4378 | child = mChildren.get(i); |
| 4379 | } |
| 4380 | |
| 4381 | return null; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 4382 | } |
| 4383 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 4384 | /** |
| 4385 | * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false |
| 4386 | * otherwise. |
| 4387 | */ |
| 4388 | @VisibleForTesting |
| 4389 | boolean isSelfOrAncestorWindowAnimatingExit() { |
| 4390 | WindowState window = this; |
| 4391 | do { |
| 4392 | if (window.mAnimatingExit) { |
| 4393 | return true; |
| 4394 | } |
| 4395 | window = window.getParentWindow(); |
| 4396 | } while (window != null); |
| 4397 | return false; |
| 4398 | } |
| 4399 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4400 | void onExitAnimationDone() { |
| 4401 | if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this |
| 4402 | + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4403 | + " selfAnimating=" + isAnimating()); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4404 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 4405 | if (!mChildren.isEmpty()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4406 | // Copying to a different list as multiple children can be removed. |
Jorim Jaggi | 59f3e92 | 2018-01-05 15:40:32 +0100 | [diff] [blame] | 4407 | final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4408 | for (int i = childWindows.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4409 | childWindows.get(i).onExitAnimationDone(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | if (mWinAnimator.mEnteringAnimation) { |
| 4414 | mWinAnimator.mEnteringAnimation = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4415 | mWmService.requestTraversal(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4416 | // System windows don't have an activity and an app token as a result, but need a way |
| 4417 | // to be informed about their entrance animation end. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4418 | if (mActivityRecord == null) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4419 | try { |
| 4420 | mClient.dispatchWindowShown(); |
| 4421 | } catch (RemoteException e) { |
| 4422 | } |
| 4423 | } |
| 4424 | } |
| 4425 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4426 | if (isAnimating()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4427 | return; |
| 4428 | } |
Jacky Kao | f93252b | 2019-07-18 15:19:52 +0800 | [diff] [blame] | 4429 | if (mWmService.mAccessibilityController != null) { |
| 4430 | mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(getDisplayId()); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4431 | } |
| 4432 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 4433 | if (!isSelfOrAncestorWindowAnimatingExit()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4434 | return; |
| 4435 | } |
| 4436 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 4437 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Exit animation finished in %s: remove=%b", |
| 4438 | this, mRemoveOnExit); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4439 | |
| 4440 | mDestroying = true; |
| 4441 | |
| 4442 | final boolean hasSurface = mWinAnimator.hasSurface(); |
Jorim Jaggi | 5057590 | 2018-04-10 17:49:30 +0200 | [diff] [blame] | 4443 | |
| 4444 | // Use pendingTransaction here so hide is done the same transaction as the other |
| 4445 | // animations when exiting |
| 4446 | mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4447 | |
| 4448 | // If we have an app token, we ask it to destroy the surface for us, so that it can take |
| 4449 | // care to ensure the activity has actually stopped and the surface is not still in use. |
| 4450 | // Otherwise we add the service to mDestroySurface and allow it to be processed in our next |
| 4451 | // transaction. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4452 | if (mActivityRecord != null) { |
| 4453 | mActivityRecord.destroySurfaces(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4454 | } else { |
| 4455 | if (hasSurface) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4456 | mWmService.mDestroySurface.add(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4457 | } |
| 4458 | if (mRemoveOnExit) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4459 | mWmService.mPendingRemove.add(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4460 | mRemoveOnExit = false; |
| 4461 | } |
| 4462 | } |
| 4463 | mAnimatingExit = false; |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 4464 | getDisplayContent().mWallpaperController.hideWallpapers(this); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 4465 | } |
Dan Willemsen | 117197f | 2016-07-30 13:02:59 -0700 | [diff] [blame] | 4466 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4467 | boolean clearAnimatingFlags() { |
| 4468 | boolean didSomething = false; |
| 4469 | // We don't want to clear it out for windows that get replaced, because the |
| 4470 | // animation depends on the flag to remove the replaced window. |
| 4471 | // |
| 4472 | // We also don't clear the mAnimatingExit flag for windows which have the |
| 4473 | // mRemoveOnExit flag. This indicates an explicit remove request has been issued |
| 4474 | // by the client. We should let animation proceed and not clear this flag or |
| 4475 | // they won't eventually be removed by WindowStateAnimator#finishExit. |
| 4476 | if (!mWillReplaceWindow && !mRemoveOnExit) { |
| 4477 | // Clear mAnimating flag together with mAnimatingExit. When animation |
| 4478 | // changes from exiting to entering, we need to clear this flag until the |
| 4479 | // new animation gets applied, so that isAnimationStarting() becomes true |
| 4480 | // until then. |
| 4481 | // Otherwise applySurfaceChangesTransaction will fail to skip surface |
| 4482 | // placement for this window during this period, one or more frame will |
| 4483 | // show up with wrong position or scale. |
| 4484 | if (mAnimatingExit) { |
| 4485 | mAnimatingExit = false; |
| 4486 | didSomething = true; |
| 4487 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4488 | if (mDestroying) { |
| 4489 | mDestroying = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4490 | mWmService.mDestroySurface.remove(this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4491 | didSomething = true; |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4496 | didSomething |= (mChildren.get(i)).clearAnimatingFlags(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | return didSomething; |
| 4500 | } |
| 4501 | |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4502 | public boolean isRtl() { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 4503 | return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4504 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4505 | |
| 4506 | void hideWallpaperWindow(boolean wasDeferred, String reason) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4507 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4508 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4509 | c.hideWallpaperWindow(wasDeferred, reason); |
| 4510 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4511 | if (!mWinAnimator.mLastHidden || wasDeferred) { |
| 4512 | mWinAnimator.hide(reason); |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 4513 | getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4514 | dispatchWallpaperVisibility(false); |
| 4515 | final DisplayContent displayContent = getDisplayContent(); |
| 4516 | if (displayContent != null) { |
| 4517 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 4518 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4519 | mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this, |
Tiger Huang | 50d4546 | 2018-05-25 22:57:52 +0800 | [diff] [blame] | 4520 | displayContent.pendingLayoutChanges); |
| 4521 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4522 | } |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | /** |
| 4527 | * Check wallpaper window for visibility change and notify window if so. |
| 4528 | * @param visible Current visibility. |
| 4529 | */ |
| 4530 | void dispatchWallpaperVisibility(final boolean visible) { |
| 4531 | final boolean hideAllowed = |
Wale Ogunwale | 0303c57 | 2016-10-20 10:16:29 -0700 | [diff] [blame] | 4532 | getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4533 | |
| 4534 | // Only send notification if the visibility actually changed and we are not trying to hide |
| 4535 | // the wallpaper when we are deferring hiding of the wallpaper. |
| 4536 | if (mWallpaperVisible != visible && (hideAllowed || visible)) { |
| 4537 | mWallpaperVisible = visible; |
| 4538 | try { |
| 4539 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 4540 | "Updating vis of wallpaper " + this |
| 4541 | + ": " + visible + " from:\n" + Debug.getCallers(4, " ")); |
| 4542 | mClient.dispatchAppVisibility(visible); |
| 4543 | } catch (RemoteException e) { |
| 4544 | } |
| 4545 | } |
| 4546 | } |
| 4547 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4548 | boolean hasVisibleNotDrawnWallpaper() { |
| 4549 | if (mWallpaperVisible && !isDrawnLw()) { |
| 4550 | return true; |
| 4551 | } |
| 4552 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4553 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4554 | if (c.hasVisibleNotDrawnWallpaper()) { |
| 4555 | return true; |
| 4556 | } |
| 4557 | } |
| 4558 | return false; |
| 4559 | } |
| 4560 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4561 | void updateReportedVisibility(UpdateReportedVisibilityResults results) { |
| 4562 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4563 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4564 | c.updateReportedVisibility(results); |
| 4565 | } |
| 4566 | |
| 4567 | if (mAppFreezing || mViewVisibility != View.VISIBLE |
| 4568 | || mAttrs.type == TYPE_APPLICATION_STARTING |
| 4569 | || mDestroying) { |
| 4570 | return; |
| 4571 | } |
| 4572 | if (DEBUG_VISIBILITY) { |
| 4573 | Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw() |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4574 | + ", animating=" + isAnimating(TRANSITION | PARENTS)); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4575 | if (!isDrawnLw()) { |
| 4576 | Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 4577 | + " pv=" + isVisibleByPolicy() |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4578 | + " mDrawState=" + mWinAnimator.mDrawState |
| 4579 | + " ph=" + isParentWindowHidden() |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 4580 | + " th=" + (mActivityRecord != null && mActivityRecord.mVisibleRequested) |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4581 | + " a=" + isAnimating(TRANSITION | PARENTS)); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | results.numInteresting++; |
| 4586 | if (isDrawnLw()) { |
| 4587 | results.numDrawn++; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4588 | if (!isAnimating(TRANSITION | PARENTS)) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4589 | results.numVisible++; |
| 4590 | } |
| 4591 | results.nowGone = false; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4592 | } else if (isAnimating(TRANSITION | PARENTS)) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4593 | results.nowGone = false; |
| 4594 | } |
| 4595 | } |
| 4596 | |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 4597 | private boolean skipDecorCrop() { |
| 4598 | // The decor frame is used to specify the region not covered by the system |
| 4599 | // decorations (nav bar, status bar). In case this is empty, for example with |
| 4600 | // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping. |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 4601 | if (mWindowFrames.mDecorFrame.isEmpty()) { |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 4602 | return true; |
| 4603 | } |
| 4604 | |
| 4605 | // But if we have a frame, and are an application window, then we must be cropped. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4606 | if (mActivityRecord != null) { |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 4607 | return false; |
| 4608 | } |
| 4609 | |
| 4610 | // For non application windows, we may be allowed to extend over the decor bars |
| 4611 | // depending on our type and permissions assosciated with our token. |
| 4612 | return mToken.canLayerAboveSystemBars(); |
| 4613 | } |
| 4614 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4615 | /** |
| 4616 | * Calculate the window crop according to system decor policy. In general this is |
| 4617 | * the system decor rect (see #calculateSystemDecorRect), but we also have some |
| 4618 | * special cases. This rectangle is in screen space. |
| 4619 | */ |
| 4620 | void calculatePolicyCrop(Rect policyCrop) { |
| 4621 | final DisplayContent displayContent = getDisplayContent(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4622 | |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4623 | if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4624 | // On a different display there is no system decor. Crop the window |
| 4625 | // by the screen boundaries. |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 4626 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 4627 | policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(), |
| 4628 | mWindowFrames.mCompatFrame.height()); |
| 4629 | policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top, |
| 4630 | displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left, |
| 4631 | displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top); |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 4632 | } else if (skipDecorCrop()) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4633 | // Windows without policy decor aren't cropped. |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 4634 | policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(), |
| 4635 | mWindowFrames.mCompatFrame.height()); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4636 | } else { |
| 4637 | // Crop to the system decor specified by policy. |
| 4638 | calculateSystemDecorRect(policyCrop); |
| 4639 | } |
| 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * The system decor rect is the region of the window which is not covered |
| 4644 | * by system decorations. |
| 4645 | */ |
| 4646 | private void calculateSystemDecorRect(Rect systemDecorRect) { |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 4647 | final Rect decorRect = mWindowFrames.mDecorFrame; |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4648 | final int width = mWindowFrames.mFrame.width(); |
| 4649 | final int height = mWindowFrames.mFrame.height(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4650 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4651 | final int left = mWindowFrames.mFrame.left; |
| 4652 | final int top = mWindowFrames.mFrame.top; |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4653 | |
| 4654 | // Initialize the decor rect to the entire frame. |
| 4655 | if (isDockedResizing()) { |
| 4656 | // If we are resizing with the divider, the task bounds might be smaller than the |
| 4657 | // stack bounds. The system decor is used to clip to the task bounds, which we don't |
| 4658 | // want in this case in order to avoid holes. |
| 4659 | // |
| 4660 | // We take care to not shrink the width, for surfaces which are larger than |
| 4661 | // the display region. Of course this area will not eventually be visible |
| 4662 | // but if we truncate the width now, we will calculate incorrectly |
| 4663 | // when adjusting to the stack bounds. |
| 4664 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
| 4665 | systemDecorRect.set(0, 0, |
| 4666 | Math.max(width, displayInfo.logicalWidth), |
| 4667 | Math.max(height, displayInfo.logicalHeight)); |
| 4668 | } else { |
| 4669 | systemDecorRect.set(0, 0, width, height); |
| 4670 | } |
| 4671 | |
| 4672 | // If a freeform window is animating from a position where it would be cutoff, it would be |
| 4673 | // cutoff during the animation. We don't want that, so for the duration of the animation |
| 4674 | // we ignore the decor cropping and depend on layering to position windows correctly. |
chaviw | 9513662 | 2018-04-09 15:20:06 -0700 | [diff] [blame] | 4675 | |
| 4676 | // We also ignore cropping when the window is currently being drag resized in split screen |
| 4677 | // to prevent issues with the crop for screenshot. |
| 4678 | final boolean cropToDecor = |
| 4679 | !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4680 | if (cropToDecor) { |
| 4681 | // Intersect with the decor rect, offsetted by window position. |
| 4682 | systemDecorRect.intersect(decorRect.left - left, decorRect.top - top, |
| 4683 | decorRect.right - left, decorRect.bottom - top); |
| 4684 | } |
| 4685 | |
| 4686 | // If size compatibility is being applied to the window, the |
| 4687 | // surface is scaled relative to the screen. Also apply this |
| 4688 | // scaling to the crop rect. We aren't using the standard rect |
| 4689 | // scale function because we want to round things to make the crop |
| 4690 | // always round to a larger rect to ensure we don't crop too |
| 4691 | // much and hide part of the window that should be seen. |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4692 | if (mInvGlobalScale != 1.0f && inSizeCompatMode()) { |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 4693 | final float scale = mInvGlobalScale; |
| 4694 | systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f); |
| 4695 | systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f); |
| 4696 | systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f); |
| 4697 | systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f); |
| 4698 | } |
| 4699 | |
| 4700 | } |
| 4701 | |
| 4702 | /** |
| 4703 | * Expand the given rectangle by this windows surface insets. This |
| 4704 | * takes you from the 'window size' to the 'surface size'. |
| 4705 | * The surface insets are positive in each direction, so we inset by |
| 4706 | * the inverse. |
| 4707 | */ |
| 4708 | void expandForSurfaceInsets(Rect r) { |
| 4709 | r.inset(-mAttrs.surfaceInsets.left, |
| 4710 | -mAttrs.surfaceInsets.top, |
| 4711 | -mAttrs.surfaceInsets.right, |
| 4712 | -mAttrs.surfaceInsets.bottom); |
| 4713 | } |
| 4714 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4715 | boolean surfaceInsetsChanging() { |
| 4716 | return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets); |
| 4717 | } |
| 4718 | |
Tiger Huang | 1ffefc2 | 2019-04-08 15:49:18 +0800 | [diff] [blame] | 4719 | int relayoutVisibleWindow(int result, int attrChanges) { |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 4720 | final boolean wasVisible = isVisibleLw(); |
| 4721 | |
| 4722 | result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0; |
Robert Carr | 7b3d11d | 2018-03-15 14:34:45 -0700 | [diff] [blame] | 4723 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4724 | if (mAnimatingExit) { |
| 4725 | Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit=" |
| 4726 | + mRemoveOnExit + ", mDestroying=" + mDestroying); |
| 4727 | |
Riddle Hsu | b8d704b | 2019-02-22 12:44:12 +0800 | [diff] [blame] | 4728 | // Cancel the existing exit animation for the next enter animation. |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 4729 | if (isAnimating()) { |
Riddle Hsu | b8d704b | 2019-02-22 12:44:12 +0800 | [diff] [blame] | 4730 | cancelAnimation(); |
| 4731 | destroySurfaceUnchecked(); |
| 4732 | } |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4733 | mAnimatingExit = false; |
| 4734 | } |
| 4735 | if (mDestroying) { |
| 4736 | mDestroying = false; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4737 | mWmService.mDestroySurface.remove(this); |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4738 | } |
Tiger Huang | 1ffefc2 | 2019-04-08 15:49:18 +0800 | [diff] [blame] | 4739 | if (!wasVisible) { |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4740 | mWinAnimator.mEnterAnimationPending = true; |
| 4741 | } |
| 4742 | |
Andrii Kulian | 8ee7285 | 2017-03-10 10:36:45 -0800 | [diff] [blame] | 4743 | mLastVisibleLayoutRotation = getDisplayContent().getRotation(); |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4744 | |
| 4745 | mWinAnimator.mEnteringAnimation = true; |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 4746 | |
Jorim Jaggi | 4981f15 | 2019-03-26 18:58:45 +0100 | [diff] [blame] | 4747 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "prepareToDisplay"); |
| 4748 | try { |
| 4749 | prepareWindowToDisplayDuringRelayout(wasVisible); |
| 4750 | } finally { |
| 4751 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 4752 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 4753 | |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4754 | if ((attrChanges & FORMAT_CHANGED) != 0) { |
| 4755 | // If the format can't be changed in place, preserve the old surface until the app draws |
| 4756 | // on the new one. This prevents blinking when we change elevation of freeform and |
| 4757 | // pinned windows. |
| 4758 | if (!mWinAnimator.tryChangeFormatInPlaceLocked()) { |
| 4759 | mWinAnimator.preserveSurfaceLocked(); |
| 4760 | result |= RELAYOUT_RES_SURFACE_CHANGED |
| 4761 | | RELAYOUT_RES_FIRST_TIME; |
| 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | // When we change the Surface size, in scenarios which may require changing |
| 4766 | // the surface position in sync with the resize, we use a preserved surface |
| 4767 | // 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] | 4768 | // sized surface. At the moment this logic is only in place for switching |
| 4769 | // in and out of the big surface for split screen resize. |
| 4770 | if (isDragResizeChanged()) { |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4771 | setDragResizing(); |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4772 | // We can only change top level windows to the full-screen surface when |
| 4773 | // resizing (as we only have one full-screen surface). So there is no need |
| 4774 | // to preserve and destroy windows which are attached to another, they |
| 4775 | // will keep their surface and its size may change over time. |
| 4776 | if (mHasSurface && !isChildWindow()) { |
| 4777 | mWinAnimator.preserveSurfaceLocked(); |
Robert Carr | db2f6e6 | 2017-03-01 20:17:58 -0800 | [diff] [blame] | 4778 | result |= RELAYOUT_RES_SURFACE_CHANGED | |
| 4779 | RELAYOUT_RES_FIRST_TIME; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4780 | } |
| 4781 | } |
| 4782 | final boolean freeformResizing = isDragResizing() |
| 4783 | && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM; |
| 4784 | final boolean dockedResizing = isDragResizing() |
| 4785 | && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 4786 | result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0; |
| 4787 | result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0; |
Robert Carr | c91d1c3 | 2017-02-15 19:37:46 -0800 | [diff] [blame] | 4788 | return result; |
| 4789 | } |
| 4790 | |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 4791 | /** |
| 4792 | * @return True if this window has been laid out at least once; false otherwise. |
| 4793 | */ |
| 4794 | boolean isLaidOut() { |
| 4795 | return mLayoutSeq != -1; |
| 4796 | } |
| 4797 | |
| 4798 | /** |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 4799 | * Add the DisplayContent of the embedded display which is re-parented to this window to |
| 4800 | * the list of embedded displays. |
| 4801 | * |
| 4802 | * @param dc DisplayContent of the re-parented embedded display. |
| 4803 | * @return {@code true} if the giving DisplayContent is added, {@code false} otherwise. |
| 4804 | */ |
| 4805 | boolean addEmbeddedDisplayContent(DisplayContent dc) { |
| 4806 | return mEmbeddedDisplayContents.add(dc); |
| 4807 | } |
| 4808 | |
| 4809 | /** |
| 4810 | * Remove the DisplayContent of the embedded display which is re-parented to this window from |
| 4811 | * the list of embedded displays. |
| 4812 | * |
| 4813 | * @param dc DisplayContent of the re-parented embedded display. |
| 4814 | * @return {@code true} if the giving DisplayContent is removed, {@code false} otherwise. |
| 4815 | */ |
| 4816 | boolean removeEmbeddedDisplayContent(DisplayContent dc) { |
| 4817 | return mEmbeddedDisplayContents.remove(dc); |
| 4818 | } |
| 4819 | |
| 4820 | /** |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 4821 | * Updates the last inset values to the current ones. |
| 4822 | */ |
| 4823 | void updateLastInsetValues() { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 4824 | mWindowFrames.updateLastInsetValues(); |
Jorim Jaggi | dc9385a | 2017-05-13 02:00:31 +0200 | [diff] [blame] | 4825 | } |
| 4826 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4827 | void startAnimation(Animation anim) { |
Jorim Jaggi | a2759b2 | 2019-01-24 13:21:40 +0100 | [diff] [blame] | 4828 | |
| 4829 | // If we are an inset provider, all our animations are driven by the inset client. |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 4830 | if (mControllableInsetProvider != null) { |
Jorim Jaggi | a2759b2 | 2019-01-24 13:21:40 +0100 | [diff] [blame] | 4831 | return; |
| 4832 | } |
| 4833 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4834 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4835 | anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(), |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4836 | displayInfo.appWidth, displayInfo.appHeight); |
| 4837 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4838 | anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked()); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4839 | final AnimationAdapter adapter = new LocalAnimationAdapter( |
Lucas Dupin | 3e1dc20 | 2018-12-02 15:14:20 -0800 | [diff] [blame] | 4840 | new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */, |
Lucas Dupin | 95acf43 | 2019-04-29 17:55:38 -0700 | [diff] [blame] | 4841 | 0 /* windowCornerRadius */), |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4842 | mWmService.mSurfaceAnimationRunner); |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 4843 | startAnimation(getPendingTransaction(), adapter); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4844 | commitPendingTransaction(); |
| 4845 | } |
| 4846 | |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 4847 | private void startMoveAnimation(int left, int top) { |
Jorim Jaggi | a2759b2 | 2019-01-24 13:21:40 +0100 | [diff] [blame] | 4848 | |
| 4849 | // If we are an inset provider, all our animations are driven by the inset client. |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 4850 | if (mControllableInsetProvider != null) { |
Jorim Jaggi | a2759b2 | 2019-01-24 13:21:40 +0100 | [diff] [blame] | 4851 | return; |
| 4852 | } |
| 4853 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4854 | if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this); |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4855 | final Point oldPosition = new Point(); |
| 4856 | final Point newPosition = new Point(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4857 | transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top, |
| 4858 | oldPosition); |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4859 | transformFrameToSurfacePosition(left, top, newPosition); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4860 | final AnimationAdapter adapter = new LocalAnimationAdapter( |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 4861 | new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y), |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4862 | mWmService.mSurfaceAnimationRunner); |
chaviw | 161ea3e | 2018-01-31 12:01:12 -0800 | [diff] [blame] | 4863 | startAnimation(getPendingTransaction(), adapter); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | private void startAnimation(Transaction t, AnimationAdapter adapter) { |
| 4867 | startAnimation(t, adapter, mWinAnimator.mLastHidden); |
| 4868 | } |
| 4869 | |
| 4870 | @Override |
| 4871 | protected void onAnimationFinished() { |
chaviw | ccd5d50 | 2019-02-22 13:30:31 -0800 | [diff] [blame] | 4872 | super.onAnimationFinished(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 4873 | mWinAnimator.onAnimationFinished(); |
| 4874 | } |
| 4875 | |
Jorim Jaggi | eb0d3bc | 2017-12-15 14:56:19 +0100 | [diff] [blame] | 4876 | /** |
| 4877 | * Retrieves the current transformation matrix of the window, relative to the display. |
| 4878 | * |
| 4879 | * @param float9 A temporary array of 9 floats. |
| 4880 | * @param outMatrix Matrix to fill in the transformation. |
| 4881 | */ |
| 4882 | void getTransformationMatrix(float[] float9, Matrix outMatrix) { |
| 4883 | float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx; |
| 4884 | float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx; |
| 4885 | float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy; |
| 4886 | float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy; |
Robert Carr | 217e7cc | 2018-01-31 18:08:39 -0800 | [diff] [blame] | 4887 | int x = mSurfacePosition.x; |
| 4888 | int y = mSurfacePosition.y; |
Jorim Jaggi | 72d4dee | 2017-12-28 13:49:21 +0100 | [diff] [blame] | 4889 | |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 4890 | // We might be on a display which has been re-parented to a view in another window, so here |
| 4891 | // computes the global location of our display. |
| 4892 | DisplayContent dc = getDisplayContent(); |
| 4893 | while (dc != null && dc.getParentWindow() != null) { |
| 4894 | final WindowState displayParent = dc.getParentWindow(); |
| 4895 | x += displayParent.mWindowFrames.mFrame.left - displayParent.mAttrs.surfaceInsets.left |
| 4896 | + (dc.getLocationInParentWindow().x * displayParent.mGlobalScale + 0.5f); |
| 4897 | y += displayParent.mWindowFrames.mFrame.top - displayParent.mAttrs.surfaceInsets.top |
| 4898 | + (dc.getLocationInParentWindow().y * displayParent.mGlobalScale + 0.5f); |
| 4899 | dc = displayParent.getDisplayContent(); |
| 4900 | } |
| 4901 | |
Jorim Jaggi | 72d4dee | 2017-12-28 13:49:21 +0100 | [diff] [blame] | 4902 | // If changed, also adjust transformFrameToSurfacePosition |
| 4903 | final WindowContainer parent = getParent(); |
| 4904 | if (isChildWindow()) { |
| 4905 | final WindowState parentWindow = getParentWindow(); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 4906 | x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left; |
| 4907 | y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top; |
Jorim Jaggi | 72d4dee | 2017-12-28 13:49:21 +0100 | [diff] [blame] | 4908 | } else if (parent != null) { |
| 4909 | final Rect parentBounds = parent.getBounds(); |
| 4910 | x += parentBounds.left; |
| 4911 | y += parentBounds.top; |
| 4912 | } |
| 4913 | float9[Matrix.MTRANS_X] = x; |
| 4914 | float9[Matrix.MTRANS_Y] = y; |
Jorim Jaggi | eb0d3bc | 2017-12-15 14:56:19 +0100 | [diff] [blame] | 4915 | float9[Matrix.MPERSP_0] = 0; |
| 4916 | float9[Matrix.MPERSP_1] = 0; |
| 4917 | float9[Matrix.MPERSP_2] = 1; |
| 4918 | outMatrix.setValues(float9); |
| 4919 | } |
| 4920 | |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4921 | // TODO: Hack to work around the number of states ActivityRecord needs to access without having |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4922 | // access to its windows children. Need to investigate re-writing |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 4923 | // {@link ActivityRecord#updateReportedVisibilityLocked} so this can be removed. |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4924 | static final class UpdateReportedVisibilityResults { |
| 4925 | int numInteresting; |
| 4926 | int numVisible; |
| 4927 | int numDrawn; |
| 4928 | boolean nowGone = true; |
| 4929 | |
| 4930 | void reset() { |
| 4931 | numInteresting = 0; |
| 4932 | numVisible = 0; |
| 4933 | numDrawn = 0; |
| 4934 | nowGone = true; |
| 4935 | } |
| 4936 | } |
Robert Carr | af422a8 | 2017-04-10 18:34:33 -0700 | [diff] [blame] | 4937 | |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 4938 | private static final class WindowId extends IWindowId.Stub { |
| 4939 | private final WeakReference<WindowState> mOuter; |
| 4940 | |
| 4941 | private WindowId(WindowState outer) { |
| 4942 | |
| 4943 | // Use a weak reference for the outer class. This is important to prevent the following |
| 4944 | // leak: Since we send this class to the client process, binder will keep it alive as |
| 4945 | // long as the client keeps it alive. Now, if the window is removed, we need to clear |
| 4946 | // out our reference so even though this class is kept alive we don't leak WindowState, |
| 4947 | // which can keep a whole lot of classes alive. |
| 4948 | mOuter = new WeakReference<>(outer); |
| 4949 | } |
| 4950 | |
| 4951 | @Override |
| 4952 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 4953 | final WindowState outer = mOuter.get(); |
| 4954 | if (outer != null) { |
| 4955 | outer.registerFocusObserver(observer); |
| 4956 | } |
| 4957 | } |
| 4958 | @Override |
| 4959 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 4960 | final WindowState outer = mOuter.get(); |
| 4961 | if (outer != null) { |
| 4962 | outer.unregisterFocusObserver(observer); |
| 4963 | } |
| 4964 | } |
| 4965 | @Override |
| 4966 | public boolean isFocused() { |
| 4967 | final WindowState outer = mOuter.get(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 4968 | if (outer != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4969 | synchronized (outer.mWmService.mGlobalLock) { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 4970 | return outer.isFocused(); |
| 4971 | } |
| 4972 | } |
| 4973 | return false; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 4974 | } |
| 4975 | } |
| 4976 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4977 | |
| 4978 | @Override |
| 4979 | boolean shouldMagnify() { |
| 4980 | if (mAttrs.type == TYPE_INPUT_METHOD || |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 4981 | mAttrs.type == TYPE_INPUT_METHOD_DIALOG || |
| 4982 | mAttrs.type == TYPE_MAGNIFICATION_OVERLAY || |
| 4983 | mAttrs.type == TYPE_NAVIGATION_BAR || |
| 4984 | // It's tempting to wonder: Have we forgotten the rounded corners overlay? |
| 4985 | // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL |
Eugene Susla | 9552b26 | 2018-03-13 12:24:50 -0700 | [diff] [blame] | 4986 | mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4987 | return false; |
| 4988 | } |
| 4989 | return true; |
| 4990 | } |
| 4991 | |
| 4992 | @Override |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 4993 | SurfaceSession getSession() { |
| 4994 | if (mSession.mSurfaceSession != null) { |
| 4995 | return mSession.mSurfaceSession; |
| 4996 | } else { |
| 4997 | return getParent().getSession(); |
| 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | @Override |
| 5002 | boolean needsZBoost() { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 5003 | final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget; |
| 5004 | if (mIsImWindow && inputMethodTarget != null) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5005 | final ActivityRecord activity = inputMethodTarget.mActivityRecord; |
| 5006 | if (activity != null) { |
| 5007 | return activity.needsZBoost(); |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 5008 | } |
| 5009 | } |
| 5010 | return mWillReplaceWindow; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5011 | } |
| 5012 | |
Robert Carr | f07ef9e | 2017-11-21 12:12:49 -0800 | [diff] [blame] | 5013 | private void applyDims(Dimmer dimmer) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 5014 | if (!mAnimatingExit && mAppDied) { |
| 5015 | mIsDimming = true; |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 5016 | dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW); |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 5017 | } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) { |
chaviw | 1407615 | 2018-02-02 14:51:20 -0800 | [diff] [blame] | 5018 | // Only show a dim behind when the following is satisfied: |
| 5019 | // 1. The window has the flag FLAG_DIM_BEHIND |
| 5020 | // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting. |
| 5021 | // 3. The WS is considered visible according to the isVisible() method |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 5022 | // 4. The WS is not hidden. |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 5023 | mIsDimming = true; |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 5024 | dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 5025 | } |
Robert Carr | f07ef9e | 2017-11-21 12:12:49 -0800 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | @Override |
| 5029 | void prepareSurfaces() { |
| 5030 | final Dimmer dimmer = getDimmer(); |
| 5031 | mIsDimming = false; |
| 5032 | if (dimmer != null) { |
| 5033 | applyDims(dimmer); |
| 5034 | } |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 5035 | updateSurfacePosition(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5036 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5037 | mWinAnimator.prepareSurfaceLocked(true); |
| 5038 | super.prepareSurfaces(); |
| 5039 | } |
| 5040 | |
| 5041 | @Override |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5042 | public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) { |
| 5043 | super.onAnimationLeashCreated(t, leash); |
| 5044 | |
| 5045 | // Leash is now responsible for position, so set our position to 0. |
| 5046 | t.setPosition(mSurfaceControl, 0, 0); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 5047 | mLastSurfacePosition.set(0, 0); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | @Override |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 5051 | public void onAnimationLeashLost(Transaction t) { |
| 5052 | super.onAnimationLeashLost(t); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5053 | updateSurfacePosition(t); |
| 5054 | } |
| 5055 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 5056 | @Override |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 5057 | void updateSurfacePosition() { |
| 5058 | updateSurfacePosition(getPendingTransaction()); |
| 5059 | } |
| 5060 | |
Vishnu Nair | d8c664b | 2018-09-24 12:52:35 -0700 | [diff] [blame] | 5061 | @VisibleForTesting |
| 5062 | void updateSurfacePosition(Transaction t) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5063 | if (mSurfaceControl == null) { |
| 5064 | return; |
| 5065 | } |
| 5066 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 5067 | transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top, |
| 5068 | mSurfacePosition); |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 5069 | |
Vishnu Nair | 83537a7 | 2018-07-19 21:27:48 -0700 | [diff] [blame] | 5070 | // Freeze position while we're unrotated, so the surface remains at the position it was |
| 5071 | // prior to the rotation. |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 5072 | if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null |
| 5073 | && !mLastSurfacePosition.equals(mSurfacePosition)) { |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 5074 | t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 5075 | mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y); |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 5076 | if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) { |
| 5077 | mLastSurfaceInsets.set(mAttrs.surfaceInsets); |
| 5078 | t.deferTransactionUntil(mSurfaceControl, |
Vishnu Nair | bc9beab | 2019-06-25 17:28:58 -0700 | [diff] [blame] | 5079 | mWinAnimator.mSurfaceController.mSurfaceControl, |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 5080 | getFrameNumber()); |
Robert Carr | c6d5af5 | 2018-02-26 17:46:00 -0800 | [diff] [blame] | 5081 | } |
Jorim Jaggi | 313d7e0 | 2017-12-14 14:40:48 +0100 | [diff] [blame] | 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | private void transformFrameToSurfacePosition(int left, int top, Point outPoint) { |
| 5086 | outPoint.set(left, top); |
Jorim Jaggi | 72d4dee | 2017-12-28 13:49:21 +0100 | [diff] [blame] | 5087 | |
| 5088 | // If changed, also adjust getTransformationMatrix |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 5089 | final WindowContainer parentWindowContainer = getParent(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5090 | if (isChildWindow()) { |
| 5091 | // TODO: This probably falls apart at some point and we should |
| 5092 | // actually compute relative coordinates. |
Jorim Jaggi | 50d3f8f | 2017-12-27 17:41:25 +0100 | [diff] [blame] | 5093 | |
| 5094 | // Since the parent was outset by its surface insets, we need to undo the outsetting |
| 5095 | // with insetting by the same amount. |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5096 | final WindowState parent = getParentWindow(); |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 5097 | transformSurfaceInsetsPosition(mTmpPoint, parent.mAttrs.surfaceInsets); |
| 5098 | outPoint.offset(-parent.mWindowFrames.mFrame.left + mTmpPoint.x, |
| 5099 | -parent.mWindowFrames.mFrame.top + mTmpPoint.y); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 5100 | } else if (parentWindowContainer != null) { |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5101 | final Rect parentBounds = parentWindowContainer.getDisplayedBounds(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 5102 | outPoint.offset(-parentBounds.left, -parentBounds.top); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5103 | } |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 5104 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 5105 | ActivityStack stack = getStack(); |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 5106 | |
| 5107 | // If we have stack outsets, that means the top-left |
| 5108 | // will be outset, and we need to inset ourselves |
| 5109 | // to account for it. If we actually have shadows we will |
| 5110 | // then un-inset ourselves by the surfaceInsets. |
| 5111 | if (stack != null) { |
| 5112 | final int outset = stack.getStackOutset(); |
| 5113 | outPoint.offset(outset, outset); |
| 5114 | } |
| 5115 | |
Jorim Jaggi | 9af095b | 2017-12-12 17:18:57 +0100 | [diff] [blame] | 5116 | // Expand for surface insets. See WindowState.expandForSurfaceInsets. |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 5117 | transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets); |
| 5118 | outPoint.offset(-mTmpPoint.x, -mTmpPoint.y); |
| 5119 | } |
| 5120 | |
| 5121 | /** |
| 5122 | * The surface insets from layout parameter are in application coordinate. If the window is |
| 5123 | * scaled, the insets also need to be scaled for surface position in global coordinate. |
| 5124 | */ |
| 5125 | private void transformSurfaceInsetsPosition(Point outPos, Rect surfaceInsets) { |
| 5126 | if (!inSizeCompatMode()) { |
| 5127 | outPos.x = surfaceInsets.left; |
| 5128 | outPos.y = surfaceInsets.top; |
| 5129 | return; |
| 5130 | } |
| 5131 | outPos.x = (int) (surfaceInsets.left * mGlobalScale + 0.5f); |
| 5132 | outPos.y = (int) (surfaceInsets.top * mGlobalScale + 0.5f); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5133 | } |
| 5134 | |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 5135 | boolean needsRelativeLayeringToIme() { |
| 5136 | // We only use the relative layering mode in split screen, as part of elevating the IME |
| 5137 | // and windows above it's target above the docked divider. |
| 5138 | if (!inSplitScreenWindowingMode()) { |
| 5139 | return false; |
| 5140 | } |
| 5141 | |
| 5142 | if (isChildWindow()) { |
| 5143 | // If we are a child of the input method target we need this promotion. |
| 5144 | if (getParentWindow().isInputMethodTarget()) { |
| 5145 | return true; |
| 5146 | } |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 5147 | } else if (mActivityRecord != null) { |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 5148 | // Likewise if we share a token with the Input method target and are ordered |
| 5149 | // above it but not necessarily a child (e.g. a Dialog) then we also need |
| 5150 | // this promotion. |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 5151 | final WindowState imeTarget = getDisplayContent().mInputMethodTarget; |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 5152 | boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this |
| 5153 | && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0; |
| 5154 | return inTokenWithAndAboveImeTarget; |
| 5155 | } |
| 5156 | return false; |
| 5157 | } |
| 5158 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5159 | @Override |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5160 | void assignLayer(Transaction t, int layer) { |
| 5161 | // See comment in assignRelativeLayerForImeTargetChild |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 5162 | if (needsRelativeLayeringToIme()) { |
| 5163 | getDisplayContent().assignRelativeLayerForImeTargetChild(t, this); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5164 | return; |
| 5165 | } |
Robert Carr | 4a1cdbd | 2018-04-16 11:09:22 -0700 | [diff] [blame] | 5166 | super.assignLayer(t, layer); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 5167 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 5168 | |
| 5169 | @Override |
| 5170 | public boolean isDimming() { |
| 5171 | return mIsDimming; |
| 5172 | } |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 5173 | |
| 5174 | // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA |
| 5175 | // then we can drop all negative layering on the windowing side and simply inherit |
| 5176 | // the default implementation here. |
| 5177 | public void assignChildLayers(Transaction t) { |
Tiger Huang | 9c8ee26 | 2019-02-19 20:44:27 +0800 | [diff] [blame] | 5178 | // The surface of the main window might be preserved. So the child window on top of the main |
| 5179 | // window should be also on top of the preserved surface. |
| 5180 | int layer = PRESERVED_SURFACE_LAYER + 1; |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 5181 | for (int i = 0; i < mChildren.size(); i++) { |
| 5182 | final WindowState w = mChildren.get(i); |
| 5183 | |
| 5184 | // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA |
| 5185 | // while they both need to go below the main window. However the |
| 5186 | // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never |
| 5187 | // been defined and so we can use static layers and leave it that way. |
| 5188 | if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) { |
shubang | cdc23b5 | 2019-06-19 11:08:10 -0700 | [diff] [blame] | 5189 | if (mWinAnimator.hasSurface()) { |
| 5190 | w.assignRelativeLayer(t, mWinAnimator.mSurfaceController.mSurfaceControl, -2); |
| 5191 | } else { |
| 5192 | w.assignLayer(t, -2); |
| 5193 | } |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 5194 | } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) { |
shubang | cdc23b5 | 2019-06-19 11:08:10 -0700 | [diff] [blame] | 5195 | if (mWinAnimator.hasSurface()) { |
| 5196 | w.assignRelativeLayer(t, mWinAnimator.mSurfaceController.mSurfaceControl, -1); |
| 5197 | } else { |
| 5198 | w.assignLayer(t, -1); |
| 5199 | } |
Robert Carr | 0eff187 | 2017-12-01 14:27:04 -0800 | [diff] [blame] | 5200 | } else { |
| 5201 | w.assignLayer(t, layer); |
| 5202 | } |
| 5203 | w.assignChildLayers(t); |
| 5204 | layer++; |
| 5205 | } |
| 5206 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5207 | |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 5208 | /** |
Tiger Huang | 2b210c2 | 2019-03-18 21:21:26 +0800 | [diff] [blame] | 5209 | * Update a tap exclude region identified by provided id. The requested area will be clipped to |
| 5210 | * the window bounds. |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 5211 | */ |
Tiger Huang | 2b210c2 | 2019-03-18 21:21:26 +0800 | [diff] [blame] | 5212 | void updateTapExcludeRegion(int regionId, Region region) { |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 5213 | final DisplayContent currentDisplay = getDisplayContent(); |
| 5214 | if (currentDisplay == null) { |
| 5215 | throw new IllegalStateException("Trying to update window not attached to any display."); |
| 5216 | } |
| 5217 | |
| 5218 | if (mTapExcludeRegionHolder == null) { |
| 5219 | mTapExcludeRegionHolder = new TapExcludeRegionHolder(); |
| 5220 | |
| 5221 | // Make sure that this window is registered as one that provides a tap exclude region |
| 5222 | // for its containing display. |
| 5223 | currentDisplay.mTapExcludeProvidingWindows.add(this); |
| 5224 | } |
| 5225 | |
Tiger Huang | 2b210c2 | 2019-03-18 21:21:26 +0800 | [diff] [blame] | 5226 | mTapExcludeRegionHolder.updateRegion(regionId, region); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 5227 | // Trigger touch exclude region update on current display. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5228 | currentDisplay.updateTouchExcludeRegion(); |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5229 | // Trigger touchable region update for this window. |
| 5230 | currentDisplay.getInputMonitor().updateInputWindowsLw(true /* force */); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 5231 | } |
| 5232 | |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5233 | /** |
| 5234 | * Union the region with current tap exclude region that this window provides. |
| 5235 | * |
| 5236 | * @param region The region to be amended. It is on the screen coordinates. |
| 5237 | */ |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 5238 | void amendTapExcludeRegion(Region region) { |
Tiger Huang | 04dc4cc | 2019-01-17 18:41:41 +0800 | [diff] [blame] | 5239 | final Region tempRegion = Region.obtain(); |
| 5240 | mTmpRect.set(mWindowFrames.mFrame); |
| 5241 | mTmpRect.offsetTo(0, 0); |
| 5242 | mTapExcludeRegionHolder.amendRegion(tempRegion, mTmpRect); |
| 5243 | // The region held by the holder is on the window coordinates. We need to translate it to |
| 5244 | // the screen coordinates. |
| 5245 | tempRegion.translate(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top); |
| 5246 | region.op(tempRegion, Region.Op.UNION); |
| 5247 | tempRegion.recycle(); |
Andrii Kulian | 4b6599e | 2018-01-15 17:24:08 -0800 | [diff] [blame] | 5248 | } |
| 5249 | |
Jackal Guo | c43a0a6 | 2019-04-23 09:15:14 +0800 | [diff] [blame] | 5250 | boolean hasTapExcludeRegion() { |
| 5251 | return mTapExcludeRegionHolder != null && !mTapExcludeRegionHolder.isEmpty(); |
| 5252 | } |
| 5253 | |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 5254 | @Override |
| 5255 | public boolean isInputMethodTarget() { |
lumark | ff0ab69 | 2018-11-05 20:32:30 +0800 | [diff] [blame] | 5256 | return getDisplayContent().mInputMethodTarget == this; |
Robert Carr | 825581a | 2018-03-30 14:00:53 -0700 | [diff] [blame] | 5257 | } |
| 5258 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 5259 | long getFrameNumber() { |
| 5260 | return mFrameNumber; |
| 5261 | } |
| 5262 | |
| 5263 | void setFrameNumber(long frameNumber) { |
| 5264 | mFrameNumber = frameNumber; |
| 5265 | } |
| 5266 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 5267 | public void getMaxVisibleBounds(Rect out) { |
| 5268 | if (out.isEmpty()) { |
| 5269 | out.set(mWindowFrames.mVisibleFrame); |
| 5270 | return; |
| 5271 | } |
| 5272 | |
| 5273 | if (mWindowFrames.mVisibleFrame.left < out.left) { |
| 5274 | out.left = mWindowFrames.mVisibleFrame.left; |
| 5275 | } |
| 5276 | if (mWindowFrames.mVisibleFrame.top < out.top) { |
| 5277 | out.top = mWindowFrames.mVisibleFrame.top; |
| 5278 | } |
| 5279 | if (mWindowFrames.mVisibleFrame.right > out.right) { |
| 5280 | out.right = mWindowFrames.mVisibleFrame.right; |
| 5281 | } |
| 5282 | if (mWindowFrames.mVisibleFrame.bottom > out.bottom) { |
| 5283 | out.bottom = mWindowFrames.mVisibleFrame.bottom; |
| 5284 | } |
| 5285 | } |
| 5286 | |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 5287 | /** |
| 5288 | * Copy the inset values over so they can be sent back to the client when a relayout occurs. |
| 5289 | */ |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame] | 5290 | void getInsetsForRelayout(Rect outContentInsets, Rect outVisibleInsets, |
| 5291 | Rect outStableInsets) { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 5292 | outContentInsets.set(mWindowFrames.mContentInsets); |
| 5293 | outVisibleInsets.set(mWindowFrames.mVisibleInsets); |
| 5294 | outStableInsets.set(mWindowFrames.mStableInsets); |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 5295 | |
| 5296 | mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets); |
| 5297 | } |
| 5298 | |
| 5299 | void getContentInsets(Rect outContentInsets) { |
| 5300 | outContentInsets.set(mWindowFrames.mContentInsets); |
| 5301 | } |
| 5302 | |
| 5303 | Rect getContentInsets() { |
| 5304 | return mWindowFrames.mContentInsets; |
| 5305 | } |
| 5306 | |
| 5307 | void getStableInsets(Rect outStableInsets) { |
| 5308 | outStableInsets.set(mWindowFrames.mStableInsets); |
| 5309 | } |
| 5310 | |
| 5311 | Rect getStableInsets() { |
| 5312 | return mWindowFrames.mStableInsets; |
| 5313 | } |
| 5314 | |
| 5315 | void resetLastContentInsets() { |
| 5316 | mWindowFrames.resetLastContentInsets(); |
| 5317 | } |
| 5318 | |
| 5319 | Rect getVisibleInsets() { |
| 5320 | return mWindowFrames.mVisibleInsets; |
| 5321 | } |
| 5322 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 5323 | @Override |
| 5324 | public WindowFrames getWindowFrames() { |
| 5325 | return mWindowFrames; |
| 5326 | } |
| 5327 | |
| 5328 | void resetContentChanged() { |
| 5329 | mWindowFrames.setContentChanged(false); |
| 5330 | } |
| 5331 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 5332 | /** |
| 5333 | * Set's an {@link InsetsSourceProvider} to be associated with this window, but only if the |
| 5334 | * provider itself is controllable, as one window can be the provider of more than one inset |
| 5335 | * type (i.e. gesture insets). If this window is controllable, all its animations must be |
| 5336 | * controlled by its control target, and the visibility of this window should be taken account |
| 5337 | * into the state of the control target. |
| 5338 | * |
| 5339 | * @param insetProvider the provider which should not be visible to the client. |
| 5340 | * @see InsetsStateController#getInsetsForDispatch(WindowState) |
| 5341 | */ |
| 5342 | void setControllableInsetProvider(InsetsSourceProvider insetProvider) { |
| 5343 | mControllableInsetProvider = insetProvider; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 5344 | } |
| 5345 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 5346 | InsetsSourceProvider getControllableInsetProvider() { |
| 5347 | return mControllableInsetProvider; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 5348 | } |
| 5349 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5350 | private final class MoveAnimationSpec implements AnimationSpec { |
| 5351 | |
| 5352 | private final long mDuration; |
| 5353 | private Interpolator mInterpolator; |
| 5354 | private Point mFrom = new Point(); |
| 5355 | private Point mTo = new Point(); |
| 5356 | |
| 5357 | private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) { |
| 5358 | final Animation anim = AnimationUtils.loadAnimation(mContext, |
| 5359 | com.android.internal.R.anim.window_move_from_decor); |
Jorim Jaggi | 08f75cf | 2018-01-08 14:38:53 +0100 | [diff] [blame] | 5360 | mDuration = (long) |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5361 | (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked()); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5362 | mInterpolator = anim.getInterpolator(); |
| 5363 | mFrom.set(fromX, fromY); |
| 5364 | mTo.set(toX, toY); |
| 5365 | } |
| 5366 | |
| 5367 | @Override |
| 5368 | public long getDuration() { |
| 5369 | return mDuration; |
| 5370 | } |
| 5371 | |
| 5372 | @Override |
| 5373 | public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) { |
| 5374 | final float fraction = (float) currentPlayTime / getDuration(); |
| 5375 | final float v = mInterpolator.getInterpolation(fraction); |
| 5376 | t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v, |
| 5377 | mFrom.y + (mTo.y - mFrom.y) * v); |
| 5378 | } |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 5379 | |
| 5380 | @Override |
| 5381 | public void dump(PrintWriter pw, String prefix) { |
chaviw | c65fa58 | 2018-08-09 15:33:13 -0700 | [diff] [blame] | 5382 | pw.println(prefix + "from=" + mFrom |
| 5383 | + " to=" + mTo |
| 5384 | + " duration=" + mDuration); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | @Override |
| 5388 | public void writeToProtoInner(ProtoOutputStream proto) { |
| 5389 | final long token = proto.start(MOVE); |
| 5390 | mFrom.writeToProto(proto, FROM); |
| 5391 | mTo.writeToProto(proto, TO); |
Kweku Adams | 21b8d26 | 2018-03-30 12:19:58 -0700 | [diff] [blame] | 5392 | proto.write(DURATION_MS, mDuration); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 5393 | proto.end(token); |
| 5394 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 5395 | } |
Vishnu Nair | 539334a | 2019-09-20 10:46:21 -0700 | [diff] [blame] | 5396 | |
| 5397 | KeyInterceptionInfo getKeyInterceptionInfo() { |
| 5398 | if (mKeyInterceptionInfo == null |
| 5399 | || mKeyInterceptionInfo.layoutParamsPrivateFlags != getAttrs().privateFlags |
| 5400 | || mKeyInterceptionInfo.layoutParamsType != getAttrs().type |
| 5401 | || mKeyInterceptionInfo.windowTitle != getWindowTag()) { |
| 5402 | mKeyInterceptionInfo = new KeyInterceptionInfo(getAttrs().type, getAttrs().privateFlags, |
| 5403 | getWindowTag().toString()); |
| 5404 | } |
| 5405 | return mKeyInterceptionInfo; |
| 5406 | } |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 5407 | |
| 5408 | @Override |
| 5409 | void getAnimationFrames(Rect outFrame, Rect outInsets, Rect outStableInsets, |
| 5410 | Rect outSurfaceInsets) { |
| 5411 | // Containing frame will usually cover the whole screen, including dialog windows. |
| 5412 | // For freeform workspace windows it will not cover the whole screen and it also |
| 5413 | // won't exactly match the final freeform window frame (e.g. when overlapping with |
| 5414 | // the status bar). In that case we need to use the final frame. |
| 5415 | if (inFreeformWindowingMode()) { |
| 5416 | outFrame.set(getFrameLw()); |
| 5417 | } else if (isLetterboxedAppWindow()) { |
| 5418 | outFrame.set(getTask().getBounds()); |
| 5419 | } else if (isDockedResizing()) { |
| 5420 | // If we are animating while docked resizing, then use the stack bounds as the |
| 5421 | // animation target (which will be different than the task bounds) |
| 5422 | outFrame.set(getTask().getParent().getBounds()); |
| 5423 | } else { |
| 5424 | outFrame.set(getContainingFrame()); |
| 5425 | } |
| 5426 | outSurfaceInsets.set(getAttrs().surfaceInsets); |
| 5427 | // TODO(b/72757033): These are insets relative to the window frame, but we're really |
| 5428 | // interested in the insets relative to the frame we chose in the if-blocks above. |
| 5429 | getContentInsets(outInsets); |
| 5430 | getStableInsets(outStableInsets); |
| 5431 | } |
satok | cef37fb | 2011-10-24 21:49:38 +0900 | [diff] [blame] | 5432 | } |