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