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