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