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