Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
| 20 | import android.app.AppOpsManager; |
| 21 | import android.content.Context; |
| 22 | import android.content.res.Configuration; |
| 23 | import android.graphics.Matrix; |
| 24 | import android.graphics.PixelFormat; |
| 25 | import android.graphics.Point; |
| 26 | import android.graphics.Rect; |
| 27 | import android.graphics.Region; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 28 | import android.os.Binder; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 29 | import android.os.Debug; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 30 | import android.os.IBinder; |
| 31 | import android.os.PowerManager; |
| 32 | import android.os.RemoteCallbackList; |
| 33 | import android.os.RemoteException; |
| 34 | import android.os.SystemClock; |
| 35 | import android.os.Trace; |
| 36 | import android.os.UserHandle; |
| 37 | import android.os.WorkSource; |
| 38 | import android.util.DisplayMetrics; |
| 39 | import android.util.Slog; |
| 40 | import android.util.TimeUtils; |
| 41 | import android.view.Display; |
| 42 | import android.view.DisplayInfo; |
| 43 | import android.view.Gravity; |
| 44 | import android.view.IApplicationToken; |
| 45 | import android.view.IWindow; |
| 46 | import android.view.IWindowFocusObserver; |
| 47 | import android.view.IWindowId; |
| 48 | import android.view.InputChannel; |
| 49 | import android.view.InputEvent; |
| 50 | import android.view.InputEventReceiver; |
| 51 | import android.view.View; |
| 52 | import android.view.ViewTreeObserver; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 53 | import android.view.WindowInfo; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 54 | import android.view.WindowManager; |
| 55 | import android.view.WindowManagerPolicy; |
| 56 | |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 57 | import com.android.server.input.InputWindowHandle; |
| 58 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 59 | import java.io.PrintWriter; |
| 60 | import java.util.ArrayList; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 61 | import java.util.Comparator; |
| 62 | import java.util.LinkedList; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 63 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 64 | import static android.app.ActivityManager.StackId; |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 65 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 66 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 67 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 68 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 69 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; |
| 70 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 71 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
| 72 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 73 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 74 | import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 75 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 76 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 77 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 78 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 79 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 80 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 81 | import static android.view.WindowManager.LayoutParams.FLAG_SCALED; |
Wale Ogunwale | 945d197 | 2016-03-23 13:16:41 -0700 | [diff] [blame] | 82 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 83 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 84 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 85 | import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 86 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 87 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 88 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 89 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 90 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 91 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 92 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 93 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 94 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 95 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 96 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 97 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 98 | import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 99 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 100 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 101 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 102 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 103 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 104 | import static android.view.WindowManagerPolicy.TRANSIT_ENTER; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 105 | import static android.view.WindowManagerPolicy.TRANSIT_EXIT; |
| 106 | import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 107 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 108 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 109 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 110 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 111 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
| 112 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 113 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 114 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 115 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 116 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
| 117 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 118 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
| 119 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 120 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
| 121 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 122 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 123 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 124 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 125 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 126 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 127 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 128 | import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 129 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER; |
| 130 | import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 131 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
| 132 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 133 | import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 134 | import static com.android.server.wm.WindowManagerService.localLOGV; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 135 | import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 136 | import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 137 | import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN; |
| 138 | import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 139 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 140 | class WindowList extends ArrayList<WindowState> { |
Wale Ogunwale | 33fde7d | 2016-03-05 22:38:51 -0800 | [diff] [blame] | 141 | WindowList() {} |
| 142 | WindowList(WindowList windowList) { |
| 143 | super(windowList); |
| 144 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 147 | /** A window in the window manager. */ |
| 148 | class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 149 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 150 | |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 151 | // 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] | 152 | // TODO(multi-window): fix the min sizes when we have mininum width/height support, |
| 153 | // use hard-coded min sizes for now. |
| 154 | static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48; |
| 155 | static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 156 | |
| 157 | // The thickness of a window resize handle outside the window bounds on the free form workspace |
| 158 | // to capture touch events in that area. |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 159 | static final int RESIZE_HANDLE_WIDTH_IN_DP = 30; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 160 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 161 | private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false; |
Robert Carr | 7098dbd | 2016-02-01 12:31:01 -0800 | [diff] [blame] | 162 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 163 | final WindowManagerService mService; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 164 | final WindowManagerPolicy mPolicy; |
| 165 | final Context mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 166 | final Session mSession; |
| 167 | final IWindow mClient; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 168 | final int mAppOp; |
| 169 | // UserId and appId of the owner. Don't display windows of non-current user. |
| 170 | final int mOwnerUid; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 171 | final IWindowId mWindowId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 172 | WindowToken mToken; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 173 | // 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] | 174 | AppWindowToken mAppToken; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 175 | |
| 176 | // mAttrs.flags is tested in animation without being locked. If the bits tested are ever |
| 177 | // modified they will need to be locked. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 178 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 179 | final DeathRecipient mDeathRecipient; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 180 | private boolean mIsChildWindow; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 181 | final int mBaseLayer; |
| 182 | final int mSubLayer; |
| 183 | final boolean mLayoutAttached; |
| 184 | final boolean mIsImWindow; |
| 185 | final boolean mIsWallpaper; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 186 | private final boolean mIsFloatingLayer; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 187 | int mSeq; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 188 | boolean mEnforceSizeCompat; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 189 | int mViewVisibility; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 190 | int mSystemUiVisibility; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 191 | /** |
| 192 | * The visibility of the window based on policy like {@link WindowManagerPolicy}. |
| 193 | * Normally set by calling {@link #showLw} and {@link #hideLw}. |
| 194 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 195 | boolean mPolicyVisibility = true; |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 196 | /** |
| 197 | * What {@link #mPolicyVisibility} should be set to after a transition animation. |
| 198 | * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and |
| 199 | * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit |
| 200 | * animation is done. |
| 201 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 202 | boolean mPolicyVisibilityAfterAnim = true; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 203 | private boolean mAppOpVisibility = true; |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 204 | boolean mPermanentlyHidden; // the window should never be shown again |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 205 | boolean mAppFreezing; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 206 | boolean mHidden; // Used to determine if to show child windows. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 207 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 208 | private boolean mDragResizing; |
| 209 | private boolean mDragResizingChangeReported; |
| 210 | private int mResizeMode; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 211 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 212 | private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 213 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 214 | /** |
| 215 | * The window size that was requested by the application. These are in |
| 216 | * the application's coordinate space (without compatibility scale applied). |
| 217 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 218 | int mRequestedWidth; |
| 219 | int mRequestedHeight; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 220 | private int mLastRequestedWidth; |
| 221 | private int mLastRequestedHeight; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 222 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 223 | int mLayer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 224 | boolean mHaveFrame; |
| 225 | boolean mObscured; |
| 226 | boolean mTurnOnScreen; |
| 227 | |
| 228 | int mLayoutSeq = -1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 229 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 230 | /** |
| 231 | * Used to store last reported to client configuration and check if we have newer available. |
| 232 | * We'll send configuration to client only if it is different from the last applied one and |
| 233 | * client won't perform unnecessary updates. |
| 234 | */ |
| 235 | private final Configuration mLastReportedConfiguration = new Configuration(); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 236 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 237 | /** |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 238 | * Actual position of the surface shown on-screen (may be modified by animation). These are |
| 239 | * in the screen's coordinate space (WITH the compatibility scale applied). |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 240 | */ |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 241 | final Point mShownPosition = new Point(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 242 | |
| 243 | /** |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 244 | * Insets that determine the actually visible area. These are in the application's |
| 245 | * coordinate space (without compatibility scale applied). |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 246 | */ |
| 247 | final Rect mVisibleInsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 248 | private final Rect mLastVisibleInsets = new Rect(); |
| 249 | private boolean mVisibleInsetsChanged; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 250 | |
| 251 | /** |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 252 | * Insets that are covered by system windows (such as the status bar) and |
| 253 | * 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] | 254 | * coordinate space (without compatibility scale applied). |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 255 | */ |
| 256 | final Rect mContentInsets = new Rect(); |
| 257 | final Rect mLastContentInsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 258 | private boolean mContentInsetsChanged; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 259 | |
| 260 | /** |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 261 | * Insets that determine the area covered by the display overscan region. These are in the |
| 262 | * application's coordinate space (without compatibility scale applied). |
| 263 | */ |
| 264 | final Rect mOverscanInsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 265 | private final Rect mLastOverscanInsets = new Rect(); |
| 266 | private boolean mOverscanInsetsChanged; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 267 | |
| 268 | /** |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 269 | * Insets that determine the area covered by the stable system windows. These are in the |
| 270 | * application's coordinate space (without compatibility scale applied). |
| 271 | */ |
| 272 | final Rect mStableInsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 273 | private final Rect mLastStableInsets = new Rect(); |
| 274 | private boolean mStableInsetsChanged; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 275 | |
| 276 | /** |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 277 | * Outsets determine the area outside of the surface where we want to pretend that it's possible |
| 278 | * to draw anyway. |
| 279 | */ |
| 280 | final Rect mOutsets = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 281 | private final Rect mLastOutsets = new Rect(); |
| 282 | private boolean mOutsetsChanged = false; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 283 | |
| 284 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 285 | * Set to true if we are waiting for this window to receive its |
| 286 | * given internal insets before laying out other windows based on it. |
| 287 | */ |
| 288 | boolean mGivenInsetsPending; |
| 289 | |
| 290 | /** |
| 291 | * These are the content insets that were given during layout for |
| 292 | * this window, to be applied to windows behind it. |
| 293 | */ |
| 294 | final Rect mGivenContentInsets = new Rect(); |
| 295 | |
| 296 | /** |
| 297 | * These are the visible insets that were given during layout for |
| 298 | * this window, to be applied to windows behind it. |
| 299 | */ |
| 300 | final Rect mGivenVisibleInsets = new Rect(); |
| 301 | |
| 302 | /** |
| 303 | * This is the given touchable area relative to the window frame, or null if none. |
| 304 | */ |
| 305 | final Region mGivenTouchableRegion = new Region(); |
| 306 | |
| 307 | /** |
| 308 | * Flag indicating whether the touchable region should be adjusted by |
| 309 | * the visible insets; if false the area outside the visible insets is |
| 310 | * NOT touchable, so we must use those to adjust the frame during hit |
| 311 | * tests. |
| 312 | */ |
| 313 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 314 | |
| 315 | // Current transformation being applied. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 316 | float mGlobalScale=1; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 317 | float mInvGlobalScale=1; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 318 | float mHScale=1, mVScale=1; |
| 319 | float mLastHScale=1, mLastVScale=1; |
| 320 | final Matrix mTmpMatrix = new Matrix(); |
| 321 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 322 | // "Real" frame that the application sees, in display coordinate space. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 323 | final Rect mFrame = new Rect(); |
| 324 | final Rect mLastFrame = new Rect(); |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 325 | private boolean mFrameSizeChanged = false; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 326 | // Frame that is scaled to the application's coordinate space when in |
| 327 | // screen size compatibility mode. |
| 328 | final Rect mCompatFrame = new Rect(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 329 | |
| 330 | final Rect mContainingFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 331 | |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 332 | private final Rect mParentFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 333 | |
Wale Ogunwale | 9459665 | 2015-02-06 19:27:34 -0800 | [diff] [blame] | 334 | // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the |
| 335 | // screen area of the device. |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 336 | final Rect mDisplayFrame = new Rect(); |
| 337 | |
| 338 | // The region of the display frame that the display type supports displaying content on. This |
| 339 | // is mostly a special case for TV where some displays don’t have the entire display usable. |
| 340 | // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow |
| 341 | // window display contents to extend into the overscan region. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 342 | private final Rect mOverscanFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 343 | |
| 344 | // The display frame minus the stable insets. This value is always constant regardless of if |
| 345 | // the status bar or navigation bar is visible. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 346 | private final Rect mStableFrame = new Rect(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 347 | |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 348 | // The area not occupied by the status and navigation bars. So, if both status and navigation |
| 349 | // bars are visible, the decor frame is equal to the stable frame. |
| 350 | final Rect mDecorFrame = new Rect(); |
| 351 | |
| 352 | // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame |
| 353 | // minus the area occupied by the IME if the IME is present. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 354 | private final Rect mContentFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 355 | |
| 356 | // Legacy stuff. Generally equal to the content frame expect when the IME for older apps |
| 357 | // displays hint text. |
| 358 | final Rect mVisibleFrame = new Rect(); |
| 359 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 360 | // Frame that includes dead area outside of the surface but where we want to pretend that it's |
| 361 | // possible to draw. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 362 | private final Rect mOutsetFrame = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 363 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 364 | /** |
| 365 | * Usually empty. Set to the task's tempInsetFrame. See |
| 366 | *{@link android.app.IActivityManager#resizeDockedStack}. |
| 367 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 368 | private final Rect mInsetFrame = new Rect(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 369 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 370 | boolean mContentChanged; |
| 371 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 372 | // If a window showing a wallpaper: the requested offset for the |
| 373 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 374 | float mWallpaperX = -1; |
| 375 | float mWallpaperY = -1; |
| 376 | |
| 377 | // If a window showing a wallpaper: what fraction of the offset |
| 378 | // range corresponds to a full virtual screen. |
| 379 | float mWallpaperXStep = -1; |
| 380 | float mWallpaperYStep = -1; |
| 381 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 382 | // If a window showing a wallpaper: a raw pixel offset to forcibly apply |
| 383 | // to its window; if a wallpaper window: not used. |
| 384 | int mWallpaperDisplayOffsetX = Integer.MIN_VALUE; |
| 385 | int mWallpaperDisplayOffsetY = Integer.MIN_VALUE; |
| 386 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 387 | // Wallpaper windows: pixels offset based on above variables. |
| 388 | int mXOffset; |
| 389 | int mYOffset; |
| 390 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 391 | /** |
| 392 | * This is set after IWindowSession.relayout() has been called at |
| 393 | * least once for the window. It allows us to detect the situation |
| 394 | * where we don't yet have a surface, but should have one soon, so |
| 395 | * we can give the window focus before waiting for the relayout. |
| 396 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 397 | boolean mRelayoutCalled; |
| 398 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 399 | boolean mInRelayout; |
| 400 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 401 | /** |
| 402 | * If the application has called relayout() with changes that can |
| 403 | * impact its window's size, we need to perform a layout pass on it |
| 404 | * even if it is not currently visible for layout. This is set |
| 405 | * when in that case until the layout is done. |
| 406 | */ |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 407 | boolean mLayoutNeeded; |
| 408 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 409 | /** Currently running an exit animation? */ |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 410 | boolean mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 411 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 412 | /** Currently on the mDestroySurface list? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 413 | boolean mDestroying; |
| 414 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 415 | /** Completely remove from window manager after exit animation? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 416 | boolean mRemoveOnExit; |
| 417 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 418 | /** |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 419 | * Whether the app died while it was visible, if true we might need |
| 420 | * to continue to show it until it's restarted. |
| 421 | */ |
| 422 | boolean mAppDied; |
| 423 | |
| 424 | /** |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 425 | * Set when the orientation is changing and this window has not yet |
| 426 | * been updated for the new orientation. |
| 427 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 428 | boolean mOrientationChanging; |
| 429 | |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 430 | /** |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 431 | * The orientation during the last visible call to relayout. If our |
| 432 | * current orientation is different, the window can't be ready |
| 433 | * to be shown. |
| 434 | */ |
| 435 | int mLastVisibleLayoutRotation = -1; |
| 436 | |
| 437 | /** |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 438 | * How long we last kept the screen frozen. |
| 439 | */ |
| 440 | int mLastFreezeDuration; |
| 441 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 442 | /** Is this window now (or just being) removed? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 443 | boolean mRemoved; |
| 444 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 445 | /** |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 446 | * It is save to remove the window and destroy the surface because the client requested removal |
| 447 | * or some other higher level component said so (e.g. activity manager). |
| 448 | * 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] | 449 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 450 | private boolean mWindowRemovalAllowed; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 451 | |
| 452 | /** |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 453 | * Temp for keeping track of windows that have been removed when |
| 454 | * rebuilding window list. |
| 455 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 456 | boolean mRebuilding; |
| 457 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 458 | // Input channel and input window handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 459 | final InputWindowHandle mInputWindowHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 460 | InputChannel mInputChannel; |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 461 | private InputChannel mClientChannel; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 462 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 463 | // Used to improve performance of toString() |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 464 | private String mStringNameCache; |
| 465 | private CharSequence mLastTitle; |
| 466 | private boolean mWasExiting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 467 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 468 | final WindowStateAnimator mWinAnimator; |
| 469 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 470 | boolean mHasSurface = false; |
| 471 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 472 | /** When true this window can be displayed on screens owther than mOwnerUid's */ |
| 473 | private boolean mShowToOwnerOnly; |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 474 | |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 475 | // Whether the window has a saved surface from last pause, which can be |
| 476 | // used to start an entering animation earlier. |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 477 | private boolean mSurfaceSaved = false; |
| 478 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 479 | // Whether we're performing an entering animation with a saved surface. This flag is |
| 480 | // true during the time we're showing a window with a previously saved surface. It's |
| 481 | // cleared when surface is destroyed, saved, or re-drawn by the app. |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 482 | private boolean mAnimatingWithSavedSurface; |
| 483 | |
| 484 | // Whether the window was visible when we set the app to invisible last time. WM uses |
| 485 | // this as a hint to restore the surface (if available) for early animation next time |
| 486 | // the app is brought visible. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 487 | private boolean mWasVisibleBeforeClientHidden; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 488 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 489 | // This window will be replaced due to relaunch. This allows window manager |
| 490 | // to differentiate between simple removal of a window and replacement. In the latter case it |
| 491 | // will preserve the old window until the new one is drawn. |
| 492 | boolean mWillReplaceWindow = false; |
| 493 | // If true, the replaced window was already requested to be removed. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 494 | private boolean mReplacingRemoveRequested = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 495 | // Whether the replacement of the window should trigger app transition animation. |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 496 | private boolean mAnimateReplacingWindow = false; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 497 | // If not null, the window that will be used to replace the old one. This is being set when |
| 498 | // 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] | 499 | private WindowState mReplacementWindow = null; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 500 | // For the new window in the replacement transition, if we have |
| 501 | // requested to replace without animation, then we should |
| 502 | // make sure we also don't apply an enter animation for |
| 503 | // the new window. |
| 504 | boolean mSkipEnterAnimationForSeamlessReplacement = false; |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 505 | // Whether this window is being moved via the resize API |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 506 | private boolean mMovedByResize; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 507 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 508 | /** |
| 509 | * Wake lock for drawing. |
| 510 | * Even though it's slightly more expensive to do so, we will use a separate wake lock |
| 511 | * for each app that is requesting to draw while dozing so that we can accurately track |
| 512 | * who is preventing the system from suspending. |
| 513 | * This lock is only acquired on first use. |
| 514 | */ |
Wale Ogunwale | d4a00a0 | 2016-10-10 11:29:17 -0700 | [diff] [blame] | 515 | private PowerManager.WakeLock mDrawLock; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 516 | |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 517 | final private Rect mTmpRect = new Rect(); |
| 518 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 519 | /** |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 520 | * See {@link #notifyMovedInStack}. |
| 521 | */ |
| 522 | private boolean mJustMovedInStack; |
| 523 | |
| 524 | /** |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 525 | * Whether the window was resized by us while it was gone for layout. |
| 526 | */ |
| 527 | boolean mResizedWhileGone = false; |
| 528 | |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 529 | /** @see #isResizedWhileNotDragResizing(). */ |
| 530 | private boolean mResizedWhileNotDragResizing; |
| 531 | |
| 532 | /** @see #isResizedWhileNotDragResizingReported(). */ |
| 533 | private boolean mResizedWhileNotDragResizingReported; |
Jorim Jaggi | f3df0aa | 2016-04-06 15:56:33 -0700 | [diff] [blame] | 534 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 535 | /** |
| 536 | * During seamless rotation we have two phases, first the old window contents |
| 537 | * are rotated to look as if they didn't move in the new coordinate system. Then we |
| 538 | * have to freeze updates to this layer (to preserve the transformation) until |
| 539 | * the resize actually occurs. This is true from when the transformation is set |
| 540 | * and false until the transaction to resize is sent. |
| 541 | */ |
| 542 | boolean mSeamlesslyRotated = false; |
| 543 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 544 | private static final Region sEmptyRegion = new Region(); |
| 545 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 546 | /** |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame^] | 547 | * 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] | 548 | * of z-order and 1 otherwise. |
| 549 | */ |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 550 | private static final Comparator<WindowState> sWindowSubLayerComparator = (w1, w2) -> { |
| 551 | final int layer1 = w1.mSubLayer; |
| 552 | final int layer2 = w2.mSubLayer; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 553 | if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) { |
| 554 | // We insert the child window into the list ordered by the sub-layer. |
| 555 | // For same sub-layers, the negative one should go below others; the positive one should |
| 556 | // go above others. |
| 557 | return -1; |
| 558 | } |
| 559 | return 1; |
| 560 | }; |
| 561 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 562 | WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, |
Wale Ogunwale | 7ed4d37 | 2016-07-09 15:28:55 -0700 | [diff] [blame] | 563 | WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a, |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 564 | int viewVisibility, int ownerId) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 565 | mService = service; |
| 566 | mSession = s; |
| 567 | mClient = c; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 568 | mAppOp = appOp; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 569 | mToken = token; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 570 | mAppToken = mToken.asAppWindowToken(); |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 571 | mOwnerUid = ownerId; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 572 | mWindowId = new IWindowId.Stub() { |
| 573 | @Override |
| 574 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 575 | WindowState.this.registerFocusObserver(observer); |
| 576 | } |
| 577 | @Override |
| 578 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 579 | WindowState.this.unregisterFocusObserver(observer); |
| 580 | } |
| 581 | @Override |
| 582 | public boolean isFocused() { |
| 583 | return WindowState.this.isFocused(); |
| 584 | } |
| 585 | }; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 586 | mAttrs.copyFrom(a); |
| 587 | mViewVisibility = viewVisibility; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 588 | mPolicy = mService.mPolicy; |
| 589 | mContext = mService.mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 590 | DeathRecipient deathRecipient = new DeathRecipient(); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 591 | mSeq = seq; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 592 | mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 593 | if (localLOGV) Slog.v( |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 594 | TAG, "Window " + this + " client=" + c.asBinder() |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 595 | + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 596 | try { |
| 597 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 598 | } catch (RemoteException e) { |
| 599 | mDeathRecipient = null; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 600 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 601 | mLayoutAttached = false; |
| 602 | mIsImWindow = false; |
| 603 | mIsWallpaper = false; |
| 604 | mIsFloatingLayer = false; |
| 605 | mBaseLayer = 0; |
| 606 | mSubLayer = 0; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 607 | mInputWindowHandle = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 608 | mWinAnimator = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 609 | return; |
| 610 | } |
| 611 | mDeathRecipient = deathRecipient; |
| 612 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 613 | if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 614 | // The multiplier here is to reserve space for multiple |
| 615 | // windows in the same type layer. |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 616 | mBaseLayer = mPolicy.windowTypeToLayerLw(parentWindow.mAttrs.type) |
| 617 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 618 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 619 | mIsChildWindow = true; |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 620 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 621 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow); |
| 622 | parentWindow.addChild(this, sWindowSubLayerComparator); |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 623 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 624 | mLayoutAttached = mAttrs.type != |
| 625 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
Wale Ogunwale | 7ed4d37 | 2016-07-09 15:28:55 -0700 | [diff] [blame] | 626 | mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 627 | || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 628 | mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 629 | } else { |
| 630 | // The multiplier here is to reserve space for multiple |
| 631 | // windows in the same type layer. |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 632 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 633 | * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 634 | mSubLayer = 0; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 635 | mIsChildWindow = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 636 | mLayoutAttached = false; |
| 637 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 638 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 639 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 640 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 641 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 642 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 643 | if (mAppToken != null && mAppToken.showForAllUsers) { |
| 644 | // Windows for apps that can show for all users should also show when the device is |
| 645 | // locked. |
| 646 | mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED; |
Craig Mautner | 19ab828 | 2014-05-07 10:35:34 -0700 | [diff] [blame] | 647 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 648 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 649 | mWinAnimator = new WindowStateAnimator(this); |
| 650 | mWinAnimator.mAlpha = a.alpha; |
| 651 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 652 | mRequestedWidth = 0; |
| 653 | mRequestedHeight = 0; |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 654 | mLastRequestedWidth = 0; |
| 655 | mLastRequestedHeight = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 656 | mXOffset = 0; |
| 657 | mYOffset = 0; |
| 658 | mLayer = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 659 | mInputWindowHandle = new InputWindowHandle( |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame^] | 660 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, getDisplayId()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | void attach() { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 664 | if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 665 | mSession.windowAddedLocked(); |
| 666 | } |
| 667 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 668 | @Override |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 669 | public int getOwningUid() { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 670 | return mOwnerUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | @Override |
| 674 | public String getOwningPackage() { |
| 675 | return mAttrs.packageName; |
| 676 | } |
| 677 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 678 | /** |
| 679 | * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame} |
| 680 | * from {@param frame}. In other words, it applies the insets that would result if |
| 681 | * {@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] | 682 | * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum |
| 683 | * width/height applied and insets should be overridden. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 684 | */ |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 685 | private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) { |
| 686 | final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left)); |
| 687 | final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top)); |
| 688 | final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right); |
| 689 | 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] | 690 | frame.inset(left, top, right, bottom); |
| 691 | } |
| 692 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 693 | @Override |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 694 | public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf, |
| 695 | Rect osf) { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 696 | if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 697 | // This window is being replaced and either already got information that it's being |
| 698 | // removed or we are still waiting for some information. Because of this we don't |
| 699 | // want to apply any more changes to it, so it remains in this state until new window |
| 700 | // appears. |
| 701 | return; |
| 702 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 703 | mHaveFrame = true; |
| 704 | |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 705 | final Task task = getTask(); |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 706 | final boolean fullscreenTask = !isInMultiWindowMode(); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 707 | final boolean windowsAreFloating = task != null && task.isFloating(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 708 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 709 | |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 710 | // If the task has temp inset bounds set, we have to make sure all its windows uses |
| 711 | // the temp inset frame. Otherwise different display frames get applied to the main |
| 712 | // window and the child window, making them misaligned. |
| 713 | if (fullscreenTask) { |
| 714 | mInsetFrame.setEmpty(); |
| 715 | } else { |
| 716 | task.getTempInsetBounds(mInsetFrame); |
| 717 | } |
| 718 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 719 | // Denotes the actual frame used to calculate the insets and to perform the layout. When |
| 720 | // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the |
| 721 | // insets temporarily. By the notion of a task having a different layout frame, we can |
| 722 | // achieve that while still moving the task around. |
| 723 | final Rect layoutContainingFrame; |
| 724 | final Rect layoutDisplayFrame; |
| 725 | |
| 726 | // The offset from the layout containing frame to the actual containing frame. |
| 727 | final int layoutXDiff; |
| 728 | final int layoutYDiff; |
Wale Ogunwale | 7cd4b01 | 2016-05-07 12:41:22 -0700 | [diff] [blame] | 729 | if (fullscreenTask || layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 730 | // We use the parent frame as the containing frame for fullscreen and child windows |
| 731 | mContainingFrame.set(pf); |
| 732 | mDisplayFrame.set(df); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 733 | layoutDisplayFrame = df; |
| 734 | layoutContainingFrame = pf; |
| 735 | layoutXDiff = 0; |
| 736 | layoutYDiff = 0; |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 737 | } else { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 738 | task.getBounds(mContainingFrame); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 739 | if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) { |
| 740 | |
| 741 | // If the bounds are frozen, we still want to translate the window freely and only |
| 742 | // freeze the size. |
| 743 | Rect frozen = mAppToken.mFrozenBounds.peek(); |
| 744 | mContainingFrame.right = mContainingFrame.left + frozen.width(); |
| 745 | mContainingFrame.bottom = mContainingFrame.top + frozen.height(); |
| 746 | } |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 747 | final WindowState imeWin = mService.mInputMethodWindow; |
Robert Carr | fc03b2b | 2016-03-31 15:22:02 -0700 | [diff] [blame] | 748 | // IME is up and obscuring this window. Adjust the window position so it is visible. |
| 749 | if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) { |
| 750 | if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) { |
| 751 | // In freeform we want to move the top up directly. |
| 752 | // TODO: Investigate why this is cf not pf. |
| 753 | mContainingFrame.top -= mContainingFrame.bottom - cf.bottom; |
| 754 | } else if (mContainingFrame.bottom > pf.bottom) { |
| 755 | // But in docked we want to behave like fullscreen |
| 756 | // and behave as if the task were given smaller bounds |
| 757 | // for the purposes of layout. |
| 758 | mContainingFrame.bottom = pf.bottom; |
| 759 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 760 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 761 | |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 762 | if (windowsAreFloating) { |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 763 | // In floating modes (e.g. freeform, pinned) we have only to set the rectangle |
| 764 | // 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] | 765 | // "content frame" since it is allowed to be outside the visible desktop. |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 766 | if (mContainingFrame.isEmpty()) { |
| 767 | mContainingFrame.set(cf); |
| 768 | } |
Doris Liu | 06d582d | 2015-06-01 13:18:43 -0700 | [diff] [blame] | 769 | } |
Wale Ogunwale | 9459665 | 2015-02-06 19:27:34 -0800 | [diff] [blame] | 770 | mDisplayFrame.set(mContainingFrame); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 771 | layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0; |
| 772 | layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0; |
| 773 | layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame; |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 774 | mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight); |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 775 | subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 776 | if (!layoutInParentFrame()) { |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 777 | subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect); |
| 778 | subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 779 | } |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 780 | layoutDisplayFrame = df; |
| 781 | layoutDisplayFrame.intersect(layoutContainingFrame); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 782 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 783 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 784 | final int pw = mContainingFrame.width(); |
| 785 | final int ph = mContainingFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 786 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 787 | if (!mParentFrame.equals(pf)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 788 | //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 789 | // + " to " + pf); |
| 790 | mParentFrame.set(pf); |
| 791 | mContentChanged = true; |
| 792 | } |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 793 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 794 | mLastRequestedWidth = mRequestedWidth; |
| 795 | mLastRequestedHeight = mRequestedHeight; |
| 796 | mContentChanged = true; |
| 797 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 798 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 799 | mOverscanFrame.set(of); |
| 800 | mContentFrame.set(cf); |
| 801 | mVisibleFrame.set(vf); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 802 | mDecorFrame.set(dcf); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 803 | mStableFrame.set(sf); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 804 | final boolean hasOutsets = osf != null; |
| 805 | if (hasOutsets) { |
| 806 | mOutsetFrame.set(osf); |
| 807 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 808 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 809 | final int fw = mFrame.width(); |
| 810 | final int fh = mFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 811 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 812 | applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame); |
| 813 | |
Filip Gruszczynski | aaf1811 | 2015-06-05 13:37:40 -0700 | [diff] [blame] | 814 | // Calculate the outsets before the content frame gets shrinked to the window frame. |
| 815 | if (hasOutsets) { |
| 816 | mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0), |
| 817 | Math.max(mContentFrame.top - mOutsetFrame.top, 0), |
| 818 | Math.max(mOutsetFrame.right - mContentFrame.right, 0), |
| 819 | Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0)); |
| 820 | } else { |
| 821 | mOutsets.set(0, 0, 0, 0); |
| 822 | } |
| 823 | |
Craig Mautner | a248eee | 2013-05-07 11:41:27 -0700 | [diff] [blame] | 824 | // Make sure the content and visible frames are inside of the |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 825 | // final window frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 826 | if (windowsAreFloating && !mFrame.isEmpty()) { |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 827 | // Keep the frame out of the blocked system area, limit it in size to the content area |
| 828 | // and make sure that there is always a minimum visible so that the user can drag it |
| 829 | // into a usable area.. |
| 830 | final int height = Math.min(mFrame.height(), mContentFrame.height()); |
| 831 | final int width = Math.min(mContentFrame.width(), mFrame.width()); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 832 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
Kazuhiro Inaba | 63e24d1 | 2016-07-14 13:02:55 +0900 | [diff] [blame] | 833 | final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel( |
| 834 | MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics)); |
| 835 | final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel( |
| 836 | MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics)); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 837 | final int top = Math.max(mContentFrame.top, |
| 838 | Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight)); |
| 839 | final int left = Math.max(mContentFrame.left + minVisibleWidth - width, |
| 840 | Math.min(mFrame.left, mContentFrame.right - minVisibleWidth)); |
| 841 | mFrame.set(left, top, left + width, top + height); |
| 842 | mContentFrame.set(mFrame); |
| 843 | mVisibleFrame.set(mContentFrame); |
| 844 | mStableFrame.set(mContentFrame); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 845 | } else if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 846 | dc.getDockedDividerController().positionDockedStackedDivider(mFrame); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 847 | mContentFrame.set(mFrame); |
| 848 | if (!mFrame.equals(mLastFrame)) { |
| 849 | mMovedByResize = true; |
Filip Gruszczynski | ae10080 | 2015-11-11 15:58:03 -0800 | [diff] [blame] | 850 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 851 | } else { |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 852 | mContentFrame.set(Math.max(mContentFrame.left, mFrame.left), |
| 853 | Math.max(mContentFrame.top, mFrame.top), |
| 854 | Math.min(mContentFrame.right, mFrame.right), |
| 855 | Math.min(mContentFrame.bottom, mFrame.bottom)); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 856 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 857 | mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left), |
| 858 | Math.max(mVisibleFrame.top, mFrame.top), |
| 859 | Math.min(mVisibleFrame.right, mFrame.right), |
| 860 | Math.min(mVisibleFrame.bottom, mFrame.bottom)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 861 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 862 | mStableFrame.set(Math.max(mStableFrame.left, mFrame.left), |
| 863 | Math.max(mStableFrame.top, mFrame.top), |
| 864 | Math.min(mStableFrame.right, mFrame.right), |
| 865 | Math.min(mStableFrame.bottom, mFrame.bottom)); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 866 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 867 | |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 868 | if (fullscreenTask && !windowsAreFloating) { |
| 869 | // Windows that are not fullscreen can be positioned outside of the display frame, |
| 870 | // but that is not a reason to provide them with overscan insets. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 871 | mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0), |
| 872 | Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0), |
| 873 | Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0), |
| 874 | Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0)); |
Filip Gruszczynski | 01ef404d5 | 2016-01-28 18:14:27 -0800 | [diff] [blame] | 875 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 876 | |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 877 | if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 878 | // For the docked divider, we calculate the stable insets like a full-screen window |
| 879 | // so it can use it to calculate the snap positions. |
| 880 | mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0), |
| 881 | Math.max(mStableFrame.top - mDisplayFrame.top, 0), |
| 882 | Math.max(mDisplayFrame.right - mStableFrame.right, 0), |
| 883 | Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0)); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 884 | |
| 885 | // The divider doesn't care about insets in any case, so set it to empty so we don't |
| 886 | // trigger a relayout when moving it. |
| 887 | mContentInsets.setEmpty(); |
| 888 | mVisibleInsets.setEmpty(); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 889 | } else { |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 890 | getDisplayContent().getLogicalDisplayRect(mTmpRect); |
Andrii Kulian | a9d168c | 2016-03-23 13:19:32 -0700 | [diff] [blame] | 891 | // Override right and/or bottom insets in case if the frame doesn't fit the screen in |
| 892 | // non-fullscreen mode. |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 893 | boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right; |
| 894 | boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom; |
| 895 | mContentInsets.set(mContentFrame.left - mFrame.left, |
| 896 | mContentFrame.top - mFrame.top, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 897 | overrideRightInset ? mTmpRect.right - mContentFrame.right |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 898 | : mFrame.right - mContentFrame.right, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 899 | overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 900 | : mFrame.bottom - mContentFrame.bottom); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 901 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 902 | mVisibleInsets.set(mVisibleFrame.left - mFrame.left, |
| 903 | mVisibleFrame.top - mFrame.top, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 904 | overrideRightInset ? mTmpRect.right - mVisibleFrame.right |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 905 | : mFrame.right - mVisibleFrame.right, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 906 | overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 907 | : mFrame.bottom - mVisibleFrame.bottom); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 908 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 909 | mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0), |
| 910 | Math.max(mStableFrame.top - mFrame.top, 0), |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 911 | overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0) |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 912 | : Math.max(mFrame.right - mStableFrame.right, 0), |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 913 | overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0) |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 914 | : Math.max(mFrame.bottom - mStableFrame.bottom, 0)); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 915 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 916 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 917 | // Offset the actual frame by the amount layout frame is off. |
| 918 | mFrame.offset(-layoutXDiff, -layoutYDiff); |
| 919 | mCompatFrame.offset(-layoutXDiff, -layoutYDiff); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 920 | mContentFrame.offset(-layoutXDiff, -layoutYDiff); |
| 921 | mVisibleFrame.offset(-layoutXDiff, -layoutYDiff); |
| 922 | mStableFrame.offset(-layoutXDiff, -layoutYDiff); |
| 923 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 924 | mCompatFrame.set(mFrame); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 925 | if (mEnforceSizeCompat) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 926 | // If there is a size compatibility scale being applied to the |
| 927 | // window, we need to apply this to its insets so that they are |
| 928 | // reported to the app in its coordinate space. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 929 | mOverscanInsets.scale(mInvGlobalScale); |
| 930 | mContentInsets.scale(mInvGlobalScale); |
| 931 | mVisibleInsets.scale(mInvGlobalScale); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 932 | mStableInsets.scale(mInvGlobalScale); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 933 | mOutsets.scale(mInvGlobalScale); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 934 | |
| 935 | // Also the scaled frame that we report to the app needs to be |
| 936 | // adjusted to be in its coordinate space. |
| 937 | mCompatFrame.scale(mInvGlobalScale); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 938 | } |
| 939 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 940 | if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 941 | final DisplayContent displayContent = getDisplayContent(); |
| 942 | if (displayContent != null) { |
| 943 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 944 | mService.mWallpaperControllerLocked.updateWallpaperOffset( |
| 945 | this, displayInfo.logicalWidth, displayInfo.logicalHeight, false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 946 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 947 | } |
| 948 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 949 | if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG, |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 950 | "Resolving (mRequestedWidth=" |
| 951 | + mRequestedWidth + ", mRequestedheight=" |
| 952 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 953 | + "): frame=" + mFrame.toShortString() |
| 954 | + " ci=" + mContentInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 955 | + " vi=" + mVisibleInsets.toShortString() |
Andrii Kulian | a9d168c | 2016-03-23 13:19:32 -0700 | [diff] [blame] | 956 | + " si=" + mStableInsets.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 957 | + " of=" + mOutsets.toShortString()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 958 | } |
| 959 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 960 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 961 | public Rect getFrameLw() { |
| 962 | return mFrame; |
| 963 | } |
| 964 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 965 | @Override |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 966 | public Point getShownPositionLw() { |
| 967 | return mShownPosition; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 968 | } |
| 969 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 970 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 971 | public Rect getDisplayFrameLw() { |
| 972 | return mDisplayFrame; |
| 973 | } |
| 974 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 975 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 976 | public Rect getOverscanFrameLw() { |
| 977 | return mOverscanFrame; |
| 978 | } |
| 979 | |
| 980 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 981 | public Rect getContentFrameLw() { |
| 982 | return mContentFrame; |
| 983 | } |
| 984 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 985 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 986 | public Rect getVisibleFrameLw() { |
| 987 | return mVisibleFrame; |
| 988 | } |
| 989 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 990 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 991 | public boolean getGivenInsetsPendingLw() { |
| 992 | return mGivenInsetsPending; |
| 993 | } |
| 994 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 995 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 996 | public Rect getGivenContentInsetsLw() { |
| 997 | return mGivenContentInsets; |
| 998 | } |
| 999 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1000 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1001 | public Rect getGivenVisibleInsetsLw() { |
| 1002 | return mGivenVisibleInsets; |
| 1003 | } |
| 1004 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1005 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1006 | public WindowManager.LayoutParams getAttrs() { |
| 1007 | return mAttrs; |
| 1008 | } |
| 1009 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1010 | @Override |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1011 | public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { |
| 1012 | int index = -1; |
| 1013 | WindowState ws = this; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1014 | WindowList windows = getWindowList(); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1015 | while (true) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 1016 | if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) { |
| 1017 | return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE; |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1018 | } |
| 1019 | // If we reached the bottom of the range of windows we are considering, |
| 1020 | // assume no menu is needed. |
| 1021 | if (ws == bottom) { |
| 1022 | return false; |
| 1023 | } |
| 1024 | // The current window hasn't specified whether menu key is needed; |
| 1025 | // look behind it. |
| 1026 | // First, we may need to determine the starting position. |
| 1027 | if (index < 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1028 | index = windows.indexOf(ws); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1029 | } |
| 1030 | index--; |
| 1031 | if (index < 0) { |
| 1032 | return false; |
| 1033 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1034 | ws = windows.get(index); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1038 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1039 | public int getSystemUiVisibility() { |
| 1040 | return mSystemUiVisibility; |
| 1041 | } |
| 1042 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1043 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1044 | public int getSurfaceLayer() { |
| 1045 | return mLayer; |
| 1046 | } |
| 1047 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1048 | @Override |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1049 | public int getBaseType() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 1050 | return getTopParentWindow().mAttrs.type; |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1054 | public IApplicationToken getAppToken() { |
| 1055 | return mAppToken != null ? mAppToken.appToken : null; |
| 1056 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1057 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1058 | @Override |
| 1059 | public boolean isVoiceInteraction() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1060 | return mAppToken != null && mAppToken.voiceInteraction; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1063 | boolean setReportResizeHints() { |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1064 | mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets); |
| 1065 | mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets); |
| 1066 | mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1067 | mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1068 | mOutsetsChanged |= !mLastOutsets.equals(mOutsets); |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1069 | mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) || |
| 1070 | (mLastFrame.height() != mFrame.height()); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1071 | return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 1072 | || mOutsetsChanged || mFrameSizeChanged; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1073 | } |
| 1074 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1075 | /** |
| 1076 | * Adds the window to the resizing list if any of the parameters we use to track the window |
| 1077 | * dimensions or insets have changed. |
| 1078 | */ |
| 1079 | void updateResizingWindowIfNeeded() { |
| 1080 | final WindowStateAnimator winAnimator = mWinAnimator; |
| 1081 | if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) { |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | final Task task = getTask(); |
| 1086 | // In the case of stack bound animations, the window frames will update (unlike other |
| 1087 | // animations which just modify various transformation properties). We don't want to |
| 1088 | // notify the client of frame changes in this case. Not only is it a lot of churn, but |
| 1089 | // the frame may not correspond to the surface size or the onscreen area at various |
| 1090 | // phases in the animation, and the client will become sad and confused. |
| 1091 | if (task != null && task.mStack.getBoundsAnimating()) { |
| 1092 | return; |
| 1093 | } |
| 1094 | |
| 1095 | setReportResizeHints(); |
| 1096 | boolean configChanged = isConfigChanged(); |
| 1097 | if (DEBUG_CONFIGURATION && configChanged) { |
| 1098 | Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration()); |
| 1099 | } |
| 1100 | |
| 1101 | final boolean dragResizingChanged = isDragResizeChanged() |
| 1102 | && !isDragResizingChangeReported(); |
| 1103 | |
| 1104 | if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged |
| 1105 | + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame |
| 1106 | + " frame=" + mFrame); |
| 1107 | |
| 1108 | // We update mLastFrame always rather than in the conditional with the last inset |
| 1109 | // variables, because mFrameSizeChanged only tracks the width and height changing. |
| 1110 | mLastFrame.set(mFrame); |
| 1111 | |
| 1112 | if (mContentInsetsChanged |
| 1113 | || mVisibleInsetsChanged |
| 1114 | || winAnimator.mSurfaceResized |
| 1115 | || mOutsetsChanged |
| 1116 | || mFrameSizeChanged |
| 1117 | || configChanged |
| 1118 | || dragResizingChanged |
| 1119 | || !isResizedWhileNotDragResizingReported()) { |
| 1120 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 1121 | Slog.v(TAG_WM, "Resize reasons for w=" + this + ": " |
| 1122 | + " contentInsetsChanged=" + mContentInsetsChanged |
| 1123 | + " " + mContentInsets.toShortString() |
| 1124 | + " visibleInsetsChanged=" + mVisibleInsetsChanged |
| 1125 | + " " + mVisibleInsets.toShortString() |
| 1126 | + " stableInsetsChanged=" + mStableInsetsChanged |
| 1127 | + " " + mStableInsets.toShortString() |
| 1128 | + " outsetsChanged=" + mOutsetsChanged |
| 1129 | + " " + mOutsets.toShortString() |
| 1130 | + " surfaceResized=" + winAnimator.mSurfaceResized |
| 1131 | + " configChanged=" + configChanged |
| 1132 | + " dragResizingChanged=" + dragResizingChanged |
| 1133 | + " resizedWhileNotDragResizingReported=" |
| 1134 | + isResizedWhileNotDragResizingReported()); |
| 1135 | } |
| 1136 | |
| 1137 | // If it's a dead window left on screen, and the configuration changed, there is nothing |
| 1138 | // we can do about it. Remove the window now. |
| 1139 | if (mAppToken != null && mAppDied) { |
| 1140 | mAppToken.removeDeadWindows(); |
| 1141 | return; |
| 1142 | } |
| 1143 | |
| 1144 | mLastOverscanInsets.set(mOverscanInsets); |
| 1145 | mLastContentInsets.set(mContentInsets); |
| 1146 | mLastVisibleInsets.set(mVisibleInsets); |
| 1147 | mLastStableInsets.set(mStableInsets); |
| 1148 | mLastOutsets.set(mOutsets); |
| 1149 | mService.makeWindowFreezingScreenIfNeededLocked(this); |
| 1150 | |
| 1151 | // If the orientation is changing, or we're starting or ending a drag resizing action, |
| 1152 | // then we need to hold off on unfreezing the display until this window has been |
| 1153 | // redrawn; to do that, we need to go through the process of getting informed by the |
| 1154 | // application when it has finished drawing. |
| 1155 | if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) { |
| 1156 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) { |
| 1157 | Slog.v(TAG_WM, "Orientation or resize start waiting for draw" |
| 1158 | + ", mDrawState=DRAW_PENDING in " + this |
| 1159 | + ", surfaceController " + winAnimator.mSurfaceController); |
| 1160 | } |
| 1161 | winAnimator.mDrawState = DRAW_PENDING; |
| 1162 | if (mAppToken != null) { |
| 1163 | mAppToken.clearAllDrawn(); |
| 1164 | } |
| 1165 | } |
| 1166 | if (!mService.mResizingWindows.contains(this)) { |
| 1167 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this); |
| 1168 | mService.mResizingWindows.add(this); |
| 1169 | } |
| 1170 | } else if (mOrientationChanging) { |
| 1171 | if (isDrawnLw()) { |
| 1172 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in " |
| 1173 | + this + ", surfaceController " + winAnimator.mSurfaceController); |
| 1174 | mOrientationChanging = false; |
| 1175 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 1176 | - mService.mDisplayFreezeTime); |
| 1177 | } |
| 1178 | } |
| 1179 | } |
| 1180 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1181 | DisplayContent getDisplayContent() { |
| 1182 | return mToken.getDisplayContent(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1185 | DisplayInfo getDisplayInfo() { |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 1186 | final DisplayContent displayContent = getDisplayContent(); |
| 1187 | return displayContent != null ? displayContent.getDisplayInfo() : null; |
| 1188 | } |
| 1189 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1190 | int getDisplayId() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1191 | final DisplayContent displayContent = getDisplayContent(); |
| 1192 | if (displayContent == null) { |
| 1193 | return -1; |
| 1194 | } |
| 1195 | return displayContent.getDisplayId(); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1198 | Task getTask() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 1199 | return mAppToken != null ? mAppToken.mTask : null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | TaskStack getStack() { |
| 1203 | Task task = getTask(); |
| 1204 | if (task != null) { |
| 1205 | if (task.mStack != null) { |
| 1206 | return task.mStack; |
Craig Mautner | f06b8c1 | 2013-04-18 14:27:28 -0700 | [diff] [blame] | 1207 | } |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1208 | } |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1209 | // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still |
| 1210 | // associate them with some stack to enable dimming. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1211 | final DisplayContent dc = getDisplayContent(); |
| 1212 | return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1215 | /** |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1216 | * Retrieves the visible bounds of the window. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1217 | * @param bounds The rect which gets the bounds. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1218 | */ |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1219 | void getVisibleBounds(Rect bounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1220 | final Task task = getTask(); |
| 1221 | boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds(); |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1222 | bounds.setEmpty(); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1223 | mTmpRect.setEmpty(); |
| 1224 | if (intersectWithStackBounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1225 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1226 | if (stack != null) { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1227 | stack.getDimBounds(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1228 | } else { |
| 1229 | intersectWithStackBounds = false; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1230 | } |
| 1231 | } |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1232 | |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1233 | bounds.set(mVisibleFrame); |
| 1234 | if (intersectWithStackBounds) { |
| 1235 | bounds.intersect(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1238 | if (bounds.isEmpty()) { |
| 1239 | bounds.set(mFrame); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1240 | if (intersectWithStackBounds) { |
| 1241 | bounds.intersect(mTmpRect); |
| 1242 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1243 | return; |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1244 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1247 | public long getInputDispatchingTimeoutNanos() { |
| 1248 | return mAppToken != null |
| 1249 | ? mAppToken.inputDispatchingTimeoutNanos |
| 1250 | : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 1251 | } |
| 1252 | |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1253 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1254 | public boolean hasAppShownWindows() { |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 1255 | return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1258 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 1259 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 1260 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 1261 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 1262 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 1263 | return true; |
| 1264 | } |
| 1265 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1266 | void prelayout() { |
| 1267 | if (mEnforceSizeCompat) { |
| 1268 | mGlobalScale = mService.mCompatibleScreenScale; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1269 | mInvGlobalScale = 1/mGlobalScale; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1270 | } else { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1271 | mGlobalScale = mInvGlobalScale = 1; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1275 | @Override |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1276 | boolean hasContentToDisplay() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1277 | // If we're animating with a saved surface, we're already visible. |
| 1278 | // Return true so that the alpha doesn't get cleared. |
| 1279 | if (!mAppFreezing && isDrawnLw() |
| 1280 | && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface() |
| 1281 | || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) { |
| 1282 | return true; |
| 1283 | } |
| 1284 | |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1285 | return super.hasContentToDisplay(); |
| 1286 | } |
| 1287 | |
| 1288 | @Override |
| 1289 | boolean isVisible() { |
Wale Ogunwale | e471be6 | 2016-10-03 07:53:55 -0700 | [diff] [blame] | 1290 | // TODO: The check for hiddenRequested is commented out below, because the window can still |
| 1291 | // be visible on screen when the flag is true. We would like the isVisible() method to |
| 1292 | // return an answer closer to if the window is truly visible (can't be an exact answer |
| 1293 | // without checking the surface state), so comment out the check for now so we can test to |
| 1294 | // see what problem it causes. |
| 1295 | // If it doesn't cause any issues, then we can remove just before we lock down the current |
| 1296 | // release (O) and also consolidate this method with #isVisibleUnchecked() and possibly |
| 1297 | // other methods like isVisibleNow(). |
| 1298 | // If it does cause problems, then we can look if there are other ways to solve the problem. |
| 1299 | // If there isn't then uncomment and document here why it is needed. |
| 1300 | if (/*(mAppToken == null || !mAppToken.hiddenRequested) && */isVisibleUnchecked() |
| 1301 | // TODO: The window isn't considered visible when the token is hidden, however |
| 1302 | // uncommenting the check below breaks the visual transition from an app to the launcher |
| 1303 | // if the home buttons is pressed. Need to investigate an fix that issue before |
| 1304 | // uncommenting. |
| 1305 | /* && !mToken.hidden*/) { |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1306 | // Is this window visible? It is not visible if there is no surface, or we are in the |
| 1307 | // process of running an exit animation that will remove the surface, or its app token |
| 1308 | // has been hidden. |
| 1309 | return true; |
| 1310 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1311 | return false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1314 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1315 | * Does the minimal check for visibility. Callers generally want to use one of the public |
| 1316 | * methods as they perform additional checks on the app token. |
| 1317 | * TODO: See if there are other places we can use this check below instead of duplicating... |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1318 | */ |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1319 | private boolean isVisibleUnchecked() { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1320 | return mHasSurface && mPolicyVisibility && !isParentWindowHidden() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1321 | && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1324 | @Override |
| 1325 | public boolean isVisibleLw() { |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1326 | return isVisible(); |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | /** |
| 1330 | * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the |
| 1331 | * keyguard as visible. This allows us to apply things like window flags that impact the |
| 1332 | * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this |
| 1333 | * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1334 | */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1335 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1336 | public boolean isVisibleOrBehindKeyguardLw() { |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1337 | if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 1338 | return false; |
| 1339 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1340 | final AppWindowToken atoken = mAppToken; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1341 | final boolean animating = atoken != null && atoken.mAppAnimator.animation != null; |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1342 | return mHasSurface && !mDestroying && !mAnimatingExit |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1343 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1344 | && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1345 | || mWinAnimator.mAnimation != null || animating); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1349 | * Is this window visible, ignoring its app token? It is not visible if there is no surface, |
| 1350 | * 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] | 1351 | */ |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1352 | // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this? |
| 1353 | boolean isWinVisibleLw() { |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1354 | return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating) |
| 1355 | && isVisibleUnchecked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1359 | * The same as isVisible(), but follows the current hidden state of the associated app token, |
| 1360 | * not the pending requested hidden state. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1361 | */ |
| 1362 | boolean isVisibleNow() { |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1363 | return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING) |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1364 | && isVisibleUnchecked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | /** |
| 1368 | * Can this window possibly be a drag/drop target? The test here is |
| 1369 | * a combination of the above "visible now" with the check that the |
| 1370 | * Input Manager uses when discarding windows from input consideration. |
| 1371 | */ |
| 1372 | boolean isPotentialDragTarget() { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1373 | return isVisibleNow() && !mRemoved |
| 1374 | && mInputChannel != null && mInputWindowHandle != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /** |
| 1378 | * Same as isVisible(), but we also count it as visible between the |
| 1379 | * call to IWindowSession.add() and the first relayout(). |
| 1380 | */ |
| 1381 | boolean isVisibleOrAdding() { |
| 1382 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 1383 | return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1384 | && mPolicyVisibility && !isParentWindowHidden() |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1385 | && (atoken == null || !atoken.hiddenRequested) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1386 | && !mAnimatingExit && !mDestroying; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /** |
| 1390 | * Is this window currently on-screen? It is on-screen either if it |
| 1391 | * is visible or it is currently running an animation before no longer |
| 1392 | * being visible. |
| 1393 | */ |
| 1394 | boolean isOnScreen() { |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 1395 | return mPolicyVisibility && isOnScreenIgnoringKeyguard(); |
| 1396 | } |
| 1397 | |
| 1398 | /** |
| 1399 | * Like isOnScreen(), but ignores any force hiding of the window due |
| 1400 | * to the keyguard. |
| 1401 | */ |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 1402 | private boolean isOnScreenIgnoringKeyguard() { |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 1403 | if (!mHasSurface || mDestroying) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1404 | return false; |
| 1405 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1406 | final AppWindowToken atoken = mAppToken; |
| 1407 | if (atoken != null) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1408 | return ((!isParentWindowHidden() && !atoken.hiddenRequested) |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1409 | || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1410 | } |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1411 | return !isParentWindowHidden() || mWinAnimator.mAnimation != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | /** |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1415 | * Whether this window's drawn state might affect the drawn states of the app token. |
| 1416 | * |
| 1417 | * @param visibleOnly Whether we should consider only the windows that's currently |
| 1418 | * visible in layout. If true, windows that has not relayout to VISIBLE |
| 1419 | * would always return false. |
| 1420 | * |
| 1421 | * @return true if the window should be considered while evaluating allDrawn flags. |
| 1422 | */ |
| 1423 | boolean mightAffectAllDrawn(boolean visibleOnly) { |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 1424 | final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden) |
| 1425 | && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1426 | return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible) |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 1427 | || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION |
| 1428 | || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION) |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1429 | && !mAnimatingExit && !mDestroying; |
| 1430 | } |
| 1431 | |
| 1432 | /** |
| 1433 | * Whether this window is "interesting" when evaluating allDrawn. If it's interesting, |
| 1434 | * it must be drawn before allDrawn can become true. |
| 1435 | */ |
| 1436 | boolean isInteresting() { |
| 1437 | return mAppToken != null && !mAppDied |
| 1438 | && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing); |
| 1439 | } |
| 1440 | |
| 1441 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1442 | * Like isOnScreen(), but we don't return true if the window is part |
| 1443 | * of a transition that has not yet been started. |
| 1444 | */ |
| 1445 | boolean isReadyForDisplay() { |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1446 | if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1447 | return false; |
| 1448 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1449 | return mHasSurface && mPolicyVisibility && !mDestroying |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1450 | && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1451 | || mWinAnimator.mAnimation != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1452 | || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null))); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1453 | } |
| 1454 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1455 | /** |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1456 | * Like isReadyForDisplay(), but ignores any force hiding of the window due |
| 1457 | * to the keyguard. |
| 1458 | */ |
| 1459 | boolean isReadyForDisplayIgnoringKeyguard() { |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1460 | if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1461 | return false; |
| 1462 | } |
| 1463 | final AppWindowToken atoken = mAppToken; |
| 1464 | if (atoken == null && !mPolicyVisibility) { |
| 1465 | // If this is not an app window, and the policy has asked to force |
| 1466 | // hide, then we really do want to hide. |
| 1467 | return false; |
| 1468 | } |
| 1469 | return mHasSurface && !mDestroying |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1470 | && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden) |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1471 | || mWinAnimator.mAnimation != null |
Craig Mautner | 9c5bf3b | 2012-06-22 15:19:13 -0700 | [diff] [blame] | 1472 | || ((atoken != null) && (atoken.mAppAnimator.animation != null) |
Chong Zhang | 83caa36 | 2016-08-14 18:47:54 -0700 | [diff] [blame] | 1473 | && !mWinAnimator.isDummyAnimation()) |
| 1474 | || isAnimatingWithSavedSurface()); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1478 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 1479 | * been drawn. |
| 1480 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1481 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1482 | public boolean isDisplayedLw() { |
| 1483 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 1484 | return isDrawnLw() && mPolicyVisibility |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1485 | && ((!isParentWindowHidden() && |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1486 | (atoken == null || !atoken.hiddenRequested)) |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1487 | || mWinAnimator.mAnimating |
| 1488 | || (atoken != null && atoken.mAppAnimator.animation != null)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1491 | /** |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1492 | * Return true if this window or its app token is currently animating. |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1493 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1494 | @Override |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1495 | public boolean isAnimatingLw() { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1496 | return mWinAnimator.mAnimation != null |
| 1497 | || (mAppToken != null && mAppToken.mAppAnimator.animation != null); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1500 | @Override |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1501 | public boolean isGoneForLayoutLw() { |
| 1502 | final AppWindowToken atoken = mAppToken; |
| 1503 | return mViewVisibility == View.GONE |
| 1504 | || !mRelayoutCalled |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 1505 | || (atoken == null && mToken.hidden) |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 1506 | || (atoken != null && atoken.hiddenRequested) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1507 | || isParentWindowHidden() |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1508 | || (mAnimatingExit && !isAnimatingLw()) |
Craig Mautner | 0e415c6 | 2013-04-29 16:10:58 -0700 | [diff] [blame] | 1509 | || mDestroying; |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1510 | } |
| 1511 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1512 | /** |
| 1513 | * Returns true if the window has a surface that it has drawn a |
| 1514 | * complete UI in to. |
| 1515 | */ |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1516 | public boolean isDrawFinishedLw() { |
| 1517 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 1518 | (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING |
| 1519 | || mWinAnimator.mDrawState == READY_TO_SHOW |
| 1520 | || mWinAnimator.mDrawState == HAS_DRAWN); |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * Returns true if the window has a surface that it has drawn a |
| 1525 | * complete UI in to. |
| 1526 | */ |
Adrian Roos | 76d2fe4 | 2015-07-09 14:54:08 -0700 | [diff] [blame] | 1527 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1528 | public boolean isDrawnLw() { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1529 | return mHasSurface && !mDestroying && |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1530 | (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * Return true if the window is opaque and fully drawn. This indicates |
| 1535 | * it may obscure windows behind it. |
| 1536 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1537 | private boolean isOpaqueDrawn() { |
Chong Zhang | 66bf071d | 2016-02-05 14:42:36 -0800 | [diff] [blame] | 1538 | // When there is keyguard, wallpaper could be placed over the secure app |
| 1539 | // window but invisible. We need to check wallpaper visibility explicitly |
| 1540 | // to determine if it's occluding apps. |
| 1541 | return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE) |
| 1542 | || (mIsWallpaper && mWallpaperVisible)) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1543 | && isDrawnLw() && mWinAnimator.mAnimation == null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1544 | && (mAppToken == null || mAppToken.mAppAnimator.animation == null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1545 | } |
| 1546 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1547 | @Override |
| 1548 | void onMovedByResize() { |
| 1549 | if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1550 | mMovedByResize = true; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1551 | super.onMovedByResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) { |
| 1555 | boolean changed = false; |
| 1556 | |
| 1557 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1558 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1559 | changed |= c.onAppVisibilityChanged(visible, runningAppAnimation); |
| 1560 | } |
| 1561 | |
| 1562 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 1563 | // Starting window that's exiting will be removed when the animation finishes. |
| 1564 | // Mark all relevant flags for that onExitAnimationDone will proceed all the way |
| 1565 | // to actually remove it. |
| 1566 | if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) { |
| 1567 | mAnimatingExit = true; |
| 1568 | mRemoveOnExit = true; |
| 1569 | mWindowRemovalAllowed = true; |
| 1570 | } |
| 1571 | return changed; |
| 1572 | } |
| 1573 | |
| 1574 | if (visible != isVisibleNow()) { |
| 1575 | if (!runningAppAnimation) { |
| 1576 | final AccessibilityController accessibilityController = |
| 1577 | mService.mAccessibilityController; |
| 1578 | final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT; |
| 1579 | mWinAnimator.applyAnimationLocked(winTransit, visible); |
| 1580 | //TODO (multidisplay): Magnification is supported only for the default |
| 1581 | if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) { |
| 1582 | accessibilityController.onWindowTransitionLocked(this, winTransit); |
| 1583 | } |
| 1584 | } |
| 1585 | changed = true; |
| 1586 | setDisplayLayoutNeeded(); |
| 1587 | } |
| 1588 | |
| 1589 | return changed; |
| 1590 | } |
| 1591 | |
| 1592 | boolean onSetAppExiting() { |
| 1593 | final DisplayContent displayContent = getDisplayContent(); |
| 1594 | boolean changed = false; |
| 1595 | |
| 1596 | if (isVisibleNow()) { |
| 1597 | mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false); |
| 1598 | //TODO (multidisplay): Magnification is supported only for the default |
| 1599 | if (mService.mAccessibilityController != null && isDefaultDisplay()) { |
| 1600 | mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT); |
| 1601 | } |
| 1602 | changed = true; |
| 1603 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 1604 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1609 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1610 | changed |= c.onSetAppExiting(); |
| 1611 | } |
| 1612 | |
| 1613 | return changed; |
| 1614 | } |
| 1615 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1616 | @Override |
| 1617 | void onResize() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1618 | // Some windows won't go through the resizing process, if they don't have a surface, so |
| 1619 | // destroy all saved surfaces here. |
| 1620 | destroySavedSurface(); |
| 1621 | |
| 1622 | final ArrayList<WindowState> resizingWindows = mService.mResizingWindows; |
| 1623 | if (mHasSurface && !resizingWindows.contains(this)) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1624 | if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1625 | resizingWindows.add(this); |
| 1626 | |
| 1627 | // If we are not drag resizing, force recreating of a new surface so updating |
| 1628 | // the content and positioning that surface will be in sync. |
| 1629 | // |
| 1630 | // As we use this flag as a hint to freeze surface boundary updates, we'd like to only |
| 1631 | // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could |
| 1632 | // appear to not be drag resizing while they resize, but we'd still like to manipulate |
| 1633 | // their frame to update crop, etc... |
| 1634 | // |
| 1635 | // Anyway we don't need to synchronize position and content updates for these |
| 1636 | // windows since they aren't at the base layer and could be moved around anyway. |
| 1637 | if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION && |
| 1638 | !getTask().mStack.getBoundsAnimating() && !isGoneForLayoutLw() && |
| 1639 | !getTask().inPinnedWorkspace()) { |
| 1640 | setResizedWhileNotDragResizing(true); |
| 1641 | } |
| 1642 | } |
| 1643 | if (isGoneForLayoutLw()) { |
| 1644 | mResizedWhileGone = true; |
| 1645 | } |
| 1646 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1647 | super.onResize(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | void onUnfreezeBounds() { |
| 1651 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1652 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1653 | c.onUnfreezeBounds(); |
| 1654 | } |
| 1655 | |
| 1656 | if (!mHasSurface) { |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | mLayoutNeeded = true; |
| 1661 | setDisplayLayoutNeeded(); |
| 1662 | if (!mService.mResizingWindows.contains(this)) { |
| 1663 | mService.mResizingWindows.add(this); |
| 1664 | } |
| 1665 | } |
| 1666 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1667 | /** |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1668 | * If the window has moved due to its containing content frame changing, then notify the |
| 1669 | * listeners and optionally animate it. Simply checking a change of position is not enough, |
| 1670 | * because being move due to dock divider is not a trigger for animation. |
| 1671 | */ |
| 1672 | void handleWindowMovedIfNeeded() { |
| 1673 | if (!hasMoved()) { |
| 1674 | return; |
| 1675 | } |
| 1676 | |
| 1677 | // Frame has moved, containing content frame has also moved, and we're not currently |
| 1678 | // animating... let's do something. |
| 1679 | final int left = mFrame.left; |
| 1680 | final int top = mFrame.top; |
| 1681 | final Task task = getTask(); |
| 1682 | final boolean adjustedForMinimizedDockOrIme = task != null |
| 1683 | && (task.mStack.isAdjustedForMinimizedDockedStack() |
| 1684 | || task.mStack.isAdjustedForIme()); |
| 1685 | if (mService.okToDisplay() |
| 1686 | && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0 |
| 1687 | && !isDragResizing() && !adjustedForMinimizedDockOrIme |
| 1688 | && (task == null || getTask().mStack.hasMovementAnimations()) |
| 1689 | && !mWinAnimator.mLastHidden) { |
| 1690 | mWinAnimator.setMoveAnimation(left, top); |
| 1691 | } |
| 1692 | |
| 1693 | //TODO (multidisplay): Accessibility supported only for the default display. |
| 1694 | if (mService.mAccessibilityController != null |
| 1695 | && getDisplayContent().getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1696 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
| 1697 | } |
| 1698 | |
| 1699 | try { |
| 1700 | mClient.moved(left, top); |
| 1701 | } catch (RemoteException e) { |
| 1702 | } |
| 1703 | mMovedByResize = false; |
| 1704 | } |
| 1705 | |
| 1706 | /** |
Craig Mautner | 4557c08 | 2015-04-27 13:07:40 -0700 | [diff] [blame] | 1707 | * Return whether this window has moved. (Only makes |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1708 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 1709 | */ |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1710 | private boolean hasMoved() { |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 1711 | return mHasSurface && (mContentChanged || mMovedByResize) |
Robert Carr | c67c2a9 | 2016-09-22 13:25:45 -0700 | [diff] [blame] | 1712 | && !mAnimatingExit |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 1713 | && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1714 | && (!mIsChildWindow || !getParentWindow().hasMoved()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1715 | } |
| 1716 | |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1717 | boolean isObscuringFullscreen(final DisplayInfo displayInfo) { |
| 1718 | Task task = getTask(); |
Wale Ogunwale | 14a3fb9 | 2016-09-11 15:19:05 -0700 | [diff] [blame] | 1719 | if (task != null && task.mStack != null && !task.mStack.fillsParent()) { |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1720 | return false; |
| 1721 | } |
| 1722 | if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) { |
| 1723 | return false; |
| 1724 | } |
| 1725 | return true; |
| 1726 | } |
| 1727 | |
| 1728 | boolean isFrameFullscreen(final DisplayInfo displayInfo) { |
| 1729 | return mFrame.left <= 0 && mFrame.top <= 0 |
| 1730 | && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1731 | } |
| 1732 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 1733 | /** Returns true if last applied config was not yet requested by client. */ |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1734 | boolean isConfigChanged() { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 1735 | return !mLastReportedConfiguration.equals(getConfiguration()); |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Jorim Jaggi | b72c9ad | 2016-04-11 18:27:58 -0700 | [diff] [blame] | 1738 | boolean isAdjustedForMinimizedDock() { |
| 1739 | return mAppToken != null && mAppToken.mTask != null |
| 1740 | && mAppToken.mTask.mStack.isAdjustedForMinimizedDock(); |
| 1741 | } |
| 1742 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1743 | void onWindowReplacementTimeout() { |
| 1744 | if (mWillReplaceWindow) { |
| 1745 | // Since the window already timed out, remove it immediately now. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1746 | // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1747 | // delays removal on certain conditions, which will leave the stale window in the |
| 1748 | // stack and marked mWillReplaceWindow=false, so the window will never be removed. |
| 1749 | // |
| 1750 | // Also removes child windows. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1751 | removeImmediately(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1752 | } else { |
| 1753 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1754 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1755 | c.onWindowReplacementTimeout(); |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1760 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1761 | void forceWindowsScaleableInTransaction(boolean force) { |
| 1762 | if (mWinAnimator != null && mWinAnimator.hasSurface()) { |
| 1763 | mWinAnimator.mSurfaceController.forceScaleableInTransaction(force); |
| 1764 | } |
| 1765 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1766 | super.forceWindowsScaleableInTransaction(force); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1769 | @Override |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1770 | void removeImmediately() { |
| 1771 | super.removeImmediately(); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 1772 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1773 | if (mRemoved) { |
| 1774 | // Nothing to do. |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1775 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1776 | "WS.removeImmediately: " + this + " Already removed..."); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1777 | return; |
| 1778 | } |
| 1779 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1780 | mRemoved = true; |
| 1781 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1782 | mWillReplaceWindow = false; |
| 1783 | if (mReplacementWindow != null) { |
| 1784 | mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false; |
| 1785 | } |
| 1786 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1787 | if (mService.mInputMethodTarget == this) { |
| 1788 | mService.moveInputMethodWindowsIfNeededLocked(false); |
| 1789 | } |
| 1790 | |
| 1791 | final int type = mAttrs.type; |
| 1792 | if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) { |
| 1793 | final DisplayContent displaycontent = getDisplayContent(); |
| 1794 | displaycontent.mTapExcludedWindows.remove(this); |
| 1795 | } |
| 1796 | mPolicy.removeWindowLw(this); |
| 1797 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1798 | disposeInputChannel(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1799 | |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1800 | mWinAnimator.destroyDeferredSurfaceLocked(); |
| 1801 | mWinAnimator.destroySurfaceLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1802 | mSession.windowRemovedLocked(); |
| 1803 | try { |
| 1804 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 1805 | } catch (RuntimeException e) { |
| 1806 | // Ignore if it has already been removed (usually because |
| 1807 | // we are doing this as part of processing a death note.) |
| 1808 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 1809 | |
| 1810 | mService.postWindowRemoveCleanupLocked(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1811 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1812 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1813 | @Override |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1814 | void removeIfPossible() { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1815 | super.removeIfPossible(); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1816 | removeIfPossible(false /*keepVisibleDeadWindow*/); |
| 1817 | } |
| 1818 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1819 | private void removeIfPossible(boolean keepVisibleDeadWindow) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1820 | mWindowRemovalAllowed = true; |
| 1821 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, |
| 1822 | "removeIfPossible: " + this + " callers=" + Debug.getCallers(5)); |
| 1823 | |
| 1824 | final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 1825 | if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM, |
| 1826 | "Starting window removed " + this); |
| 1827 | |
| 1828 | if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus) |
| 1829 | Slog.v(TAG_WM, "Remove " + this + " client=" |
| 1830 | + Integer.toHexString(System.identityHashCode(mClient.asBinder())) |
| 1831 | + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers=" |
| 1832 | + Debug.getCallers(5)); |
| 1833 | |
| 1834 | final long origId = Binder.clearCallingIdentity(); |
| 1835 | |
| 1836 | disposeInputChannel(); |
| 1837 | |
| 1838 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this |
| 1839 | + ": mSurfaceController=" + mWinAnimator.mSurfaceController |
| 1840 | + " mAnimatingExit=" + mAnimatingExit |
| 1841 | + " mRemoveOnExit=" + mRemoveOnExit |
| 1842 | + " mHasSurface=" + mHasSurface |
| 1843 | + " surfaceShowing=" + mWinAnimator.getShown() |
| 1844 | + " isAnimationSet=" + mWinAnimator.isAnimationSet() |
| 1845 | + " app-animation=" |
| 1846 | + (mAppToken != null ? mAppToken.mAppAnimator.animation : null) |
| 1847 | + " mWillReplaceWindow=" + mWillReplaceWindow |
| 1848 | + " inPendingTransaction=" |
| 1849 | + (mAppToken != null ? mAppToken.inPendingTransaction : false) |
| 1850 | + " mDisplayFrozen=" + mService.mDisplayFrozen |
| 1851 | + " callers=" + Debug.getCallers(6)); |
| 1852 | |
| 1853 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 1854 | boolean wasVisible = false; |
| 1855 | |
| 1856 | // First, see if we need to run an animation. If we do, we have to hold off on removing the |
| 1857 | // window until the animation is done. If the display is frozen, just remove immediately, |
| 1858 | // since the animation wouldn't be seen. |
| 1859 | if (mHasSurface && mService.okToDisplay()) { |
| 1860 | if (mWillReplaceWindow) { |
| 1861 | // This window is going to be replaced. We need to keep it around until the new one |
| 1862 | // gets added, then we will get rid of this one. |
| 1863 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1864 | "Preserving " + this + " until the new one is " + "added"); |
| 1865 | // TODO: We are overloading mAnimatingExit flag to prevent the window state from |
| 1866 | // been removed. We probably need another flag to indicate that window removal |
| 1867 | // should be deffered vs. overloading the flag that says we are playing an exit |
| 1868 | // animation. |
| 1869 | mAnimatingExit = true; |
| 1870 | mReplacingRemoveRequested = true; |
| 1871 | Binder.restoreCallingIdentity(origId); |
| 1872 | return; |
| 1873 | } |
| 1874 | |
| 1875 | if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) { |
| 1876 | // We started enter animation early with a saved surface, now the app asks to remove |
| 1877 | // this window. If we remove it now and the app is not yet drawn, we'll show a |
| 1878 | // flicker. Delay the removal now until it's really drawn. |
| 1879 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 1880 | "removeWindowLocked: delay removal of " + this + " due to early animation"); |
| 1881 | // Do not set mAnimatingExit to true here, it will cause the surface to be hidden |
| 1882 | // immediately after the enter animation is done. If the app is not yet drawn then |
| 1883 | // it will show up as a flicker. |
| 1884 | setupWindowForRemoveOnExit(); |
| 1885 | Binder.restoreCallingIdentity(origId); |
| 1886 | return; |
| 1887 | } |
| 1888 | // If we are not currently running the exit animation, we need to see about starting one |
| 1889 | wasVisible = isWinVisibleLw(); |
| 1890 | |
| 1891 | if (keepVisibleDeadWindow) { |
| 1892 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1893 | "Not removing " + this + " because app died while it's visible"); |
| 1894 | |
| 1895 | mAppDied = true; |
| 1896 | setDisplayLayoutNeeded(); |
| 1897 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 1898 | |
| 1899 | // Set up a replacement input channel since the app is now dead. |
| 1900 | // We need to catch tapping on the dead window to restart the app. |
| 1901 | openInputChannel(null); |
| 1902 | mService.mInputMonitor.updateInputWindowsLw(true /*force*/); |
| 1903 | |
| 1904 | Binder.restoreCallingIdentity(origId); |
| 1905 | return; |
| 1906 | } |
| 1907 | |
| 1908 | if (wasVisible) { |
| 1909 | final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE; |
| 1910 | |
| 1911 | // Try starting an animation. |
| 1912 | if (mWinAnimator.applyAnimationLocked(transit, false)) { |
| 1913 | mAnimatingExit = true; |
| 1914 | } |
| 1915 | //TODO (multidisplay): Magnification is supported only for the default display. |
| 1916 | if (mService.mAccessibilityController != null |
| 1917 | && getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1918 | mService.mAccessibilityController.onWindowTransitionLocked(this, transit); |
| 1919 | } |
| 1920 | } |
| 1921 | final boolean isAnimating = |
| 1922 | mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation(); |
| 1923 | final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1924 | && mAppToken.isLastWindow(this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1925 | // We delay the removal of a window if it has a showing surface that can be used to run |
| 1926 | // exit animation and it is marked as exiting. |
| 1927 | // Also, If isn't the an animating starting window that is the last window in the app. |
| 1928 | // We allow the removal of the non-animating starting window now as there is no |
| 1929 | // additional window or animation that will trigger its removal. |
| 1930 | if (mWinAnimator.getShown() && mAnimatingExit |
| 1931 | && (!lastWindowIsStartingWindow || isAnimating)) { |
| 1932 | // The exit animation is running or should run... wait for it! |
| 1933 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 1934 | "Not removing " + this + " due to exit animation "); |
| 1935 | setupWindowForRemoveOnExit(); |
| 1936 | if (mAppToken != null) { |
| 1937 | mAppToken.updateReportedVisibilityLocked(); |
| 1938 | } |
| 1939 | Binder.restoreCallingIdentity(origId); |
| 1940 | return; |
| 1941 | } |
| 1942 | } |
| 1943 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 1944 | removeImmediately(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1945 | // Removing a visible window will effect the computed orientation |
| 1946 | // So just update orientation if needed. |
| 1947 | if (wasVisible && mService.updateOrientationFromAppTokensLocked(false)) { |
| 1948 | mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION); |
| 1949 | } |
| 1950 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| 1951 | Binder.restoreCallingIdentity(origId); |
| 1952 | } |
| 1953 | |
| 1954 | private void setupWindowForRemoveOnExit() { |
| 1955 | mRemoveOnExit = true; |
| 1956 | setDisplayLayoutNeeded(); |
| 1957 | // Request a focus update as this window's input channel is already gone. Otherwise |
| 1958 | // we could have no focused window in input manager. |
| 1959 | final boolean focusChanged = mService.updateFocusedWindowLocked( |
| 1960 | UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/); |
| 1961 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 1962 | if (focusChanged) { |
| 1963 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
| 1964 | } |
| 1965 | } |
| 1966 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 1967 | void setHasSurface(boolean hasSurface) { |
| 1968 | mHasSurface = hasSurface; |
| 1969 | } |
| 1970 | |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1971 | int getAnimLayerAdjustment() { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 1972 | final boolean isImeType = |
| 1973 | mAttrs.type == TYPE_INPUT_METHOD || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 1974 | if (isImeType && mService.mInputMethodTarget != null) { |
| 1975 | final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken; |
| 1976 | if (appToken != null) { |
| 1977 | return appToken.mAppAnimator.animLayerAdjustment; |
| 1978 | } |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1979 | } |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 1980 | |
| 1981 | if (mAppToken != null) { |
| 1982 | return mAppToken.mAppAnimator.animLayerAdjustment; |
| 1983 | } |
| 1984 | |
| 1985 | // Nothing is animating, so there is no animation adjustment. |
| 1986 | return 0; |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | void scheduleAnimationIfDimming() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1990 | final DisplayContent dc = getDisplayContent(); |
| 1991 | if (dc == null) { |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1992 | return; |
| 1993 | } |
| 1994 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 1995 | if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) { |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1996 | // Force an animation pass just to update the mDimLayer layer. |
| 1997 | mService.scheduleAnimationLocked(); |
| 1998 | } |
| 1999 | } |
| 2000 | |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 2001 | /** |
| 2002 | * Notifies this window that the corresponding task has just moved in the stack. |
| 2003 | * <p> |
| 2004 | * This is used to fix the following: If we moved in the stack, and if the last clip rect was |
| 2005 | * empty, meaning that our task was completely offscreen, we need to keep it invisible because |
| 2006 | * the actual app transition that updates the visibility is delayed by a few transactions. |
| 2007 | * Instead of messing around with the ordering and timing how transitions and transactions are |
| 2008 | * executed, we introduce this little hack which prevents this window of getting visible again |
| 2009 | * with the wrong bounds until the app transitions has started. |
| 2010 | * <p> |
| 2011 | * This method notifies the window about that we just moved in the stack so we can apply this |
| 2012 | * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop} |
| 2013 | */ |
| 2014 | void notifyMovedInStack() { |
| 2015 | mJustMovedInStack = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2016 | |
| 2017 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2018 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2019 | c.notifyMovedInStack(); |
| 2020 | } |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * See {@link #notifyMovedInStack}. |
| 2025 | * |
| 2026 | * @return Whether we just got moved in the corresponding stack. |
| 2027 | */ |
| 2028 | boolean hasJustMovedInStack() { |
| 2029 | return mJustMovedInStack; |
| 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}. |
| 2034 | */ |
| 2035 | void resetJustMovedInStack() { |
| 2036 | mJustMovedInStack = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2037 | |
| 2038 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2039 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2040 | c.resetJustMovedInStack(); |
| 2041 | } |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 2042 | } |
| 2043 | |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2044 | private final class DeadWindowEventReceiver extends InputEventReceiver { |
| 2045 | DeadWindowEventReceiver(InputChannel inputChannel) { |
| 2046 | super(inputChannel, mService.mH.getLooper()); |
| 2047 | } |
| 2048 | @Override |
| 2049 | public void onInputEvent(InputEvent event) { |
| 2050 | finishInputEvent(event, true); |
| 2051 | } |
| 2052 | } |
| 2053 | /** |
| 2054 | * Dummy event receiver for windows that died visible. |
| 2055 | */ |
| 2056 | private DeadWindowEventReceiver mDeadWindowEventReceiver; |
| 2057 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2058 | void openInputChannel(InputChannel outInputChannel) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2059 | if (mInputChannel != null) { |
| 2060 | throw new IllegalStateException("Window already has an input channel."); |
| 2061 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2062 | String name = getName(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2063 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2064 | mInputChannel = inputChannels[0]; |
| 2065 | mClientChannel = inputChannels[1]; |
| 2066 | mInputWindowHandle.inputChannel = inputChannels[0]; |
| 2067 | if (outInputChannel != null) { |
| 2068 | mClientChannel.transferTo(outInputChannel); |
| 2069 | mClientChannel.dispose(); |
| 2070 | mClientChannel = null; |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2071 | } else { |
| 2072 | // If the window died visible, we setup a dummy input channel, so that taps |
| 2073 | // can still detected by input monitor channel, and we can relaunch the app. |
| 2074 | // Create dummy event receiver that simply reports all events as handled. |
| 2075 | mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2076 | } |
| 2077 | mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2080 | void disposeInputChannel() { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 2081 | if (mDeadWindowEventReceiver != null) { |
| 2082 | mDeadWindowEventReceiver.dispose(); |
| 2083 | mDeadWindowEventReceiver = null; |
| 2084 | } |
| 2085 | |
| 2086 | // unregister server channel first otherwise it complains about broken channel |
| 2087 | if (mInputChannel != null) { |
| 2088 | mService.mInputManager.unregisterInputChannel(mInputChannel); |
| 2089 | mInputChannel.dispose(); |
| 2090 | mInputChannel = null; |
| 2091 | } |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2092 | if (mClientChannel != null) { |
| 2093 | mClientChannel.dispose(); |
| 2094 | mClientChannel = null; |
| 2095 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 2096 | mInputWindowHandle.inputChannel = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2097 | } |
| 2098 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2099 | void applyDimLayerIfNeeded() { |
Chong Zhang | eb91732 | 2015-11-10 14:05:40 -0800 | [diff] [blame] | 2100 | // When the app is terminated (eg. from Recents), the task might have already been |
| 2101 | // removed with the window pending removal. Don't apply dim in such cases, as there |
| 2102 | // will be no more updateDimLayer() calls, which leaves the dimlayer invalid. |
| 2103 | final AppWindowToken token = mAppToken; |
| 2104 | if (token != null && token.removed) { |
| 2105 | return; |
| 2106 | } |
| 2107 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2108 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2109 | if (!mAnimatingExit && mAppDied) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2110 | // If app died visible, apply a dim over the window to indicate that it's inactive |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2111 | dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2112 | } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2113 | && dc != null && !mAnimatingExit && isVisibleUnchecked()) { |
| 2114 | dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2118 | private DimLayer.DimLayerUser getDimLayerUser() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 2119 | Task task = getTask(); |
| 2120 | if (task != null) { |
| 2121 | return task; |
| 2122 | } |
| 2123 | return getStack(); |
| 2124 | } |
| 2125 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2126 | /** Returns true if the replacement window was removed. */ |
| 2127 | boolean removeReplacedWindowIfNeeded(WindowState replacement) { |
| 2128 | if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) { |
| 2129 | replacement.mSkipEnterAnimationForSeamlessReplacement = false; |
| 2130 | removeReplacedWindow(); |
| 2131 | return true; |
| 2132 | } |
| 2133 | |
| 2134 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2135 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2136 | if (c.removeReplacedWindowIfNeeded(replacement)) { |
| 2137 | return true; |
| 2138 | } |
| 2139 | } |
| 2140 | return false; |
| 2141 | } |
| 2142 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2143 | void removeReplacedWindow() { |
| 2144 | if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this); |
| 2145 | if (isDimming()) { |
| 2146 | transferDimToReplacement(); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 2147 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2148 | mWillReplaceWindow = false; |
| 2149 | mAnimateReplacingWindow = false; |
| 2150 | mReplacingRemoveRequested = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2151 | mReplacementWindow = null; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2152 | if (mAnimatingExit || !mAnimateReplacingWindow) { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 2153 | removeImmediately(); |
Filip Gruszczynski | 76cc44f | 2015-09-03 16:03:10 -0700 | [diff] [blame] | 2154 | } |
| 2155 | } |
| 2156 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2157 | boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) { |
| 2158 | boolean replacementSet = false; |
| 2159 | |
| 2160 | if (mWillReplaceWindow && mReplacementWindow == null |
| 2161 | && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) { |
| 2162 | |
| 2163 | mReplacementWindow = replacementCandidate; |
| 2164 | replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow; |
| 2165 | replacementSet = true; |
| 2166 | } |
| 2167 | |
| 2168 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2169 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2170 | replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate); |
| 2171 | } |
| 2172 | |
| 2173 | return replacementSet; |
| 2174 | } |
| 2175 | |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2176 | void setDisplayLayoutNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2177 | final DisplayContent dc = getDisplayContent(); |
| 2178 | if (dc != null) { |
| 2179 | dc.setLayoutNeeded(); |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 2180 | } |
| 2181 | } |
| 2182 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 2183 | // TODO: Strange usage of word workspace here and above. |
| 2184 | boolean inPinnedWorkspace() { |
| 2185 | final Task task = getTask(); |
| 2186 | return task != null && task.inPinnedWorkspace(); |
| 2187 | } |
| 2188 | |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 2189 | void applyAdjustForImeIfNeeded() { |
| 2190 | final Task task = getTask(); |
| 2191 | if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) { |
| 2192 | task.mStack.applyAdjustForImeIfNeeded(task); |
| 2193 | } |
| 2194 | } |
| 2195 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2196 | int getTouchableRegion(Region region, int flags) { |
| 2197 | final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0; |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2198 | if (modal && mAppToken != null) { |
| 2199 | // Limit the outer touch to the activity stack region. |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2200 | flags |= FLAG_NOT_TOUCH_MODAL; |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2201 | // If this is a modal window we need to dismiss it if it's not full screen and the |
| 2202 | // touch happens outside of the frame that displays the content. This means we |
| 2203 | // need to intercept touches outside of that window. The dim layer user |
| 2204 | // associated with the window (task or stack) will give us the good bounds, as |
| 2205 | // they would be used to display the dim layer. |
| 2206 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
| 2207 | if (dimLayerUser != null) { |
| 2208 | dimLayerUser.getDimBounds(mTmpRect); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2209 | } else { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2210 | getVisibleBounds(mTmpRect); |
| 2211 | } |
| 2212 | if (inFreeformWorkspace()) { |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2213 | // For freeform windows we the touch region to include the whole surface for the |
| 2214 | // shadows. |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 2215 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
| 2216 | final int delta = WindowManagerService.dipToPixel( |
| 2217 | RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics); |
| 2218 | mTmpRect.inset(-delta, -delta); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2219 | } |
| 2220 | region.set(mTmpRect); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2221 | cropRegionToStackBoundsIfNeeded(region); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 2222 | } else { |
| 2223 | // Not modal or full screen modal |
| 2224 | getTouchableRegion(region); |
| 2225 | } |
| 2226 | return flags; |
| 2227 | } |
| 2228 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2229 | void checkPolicyVisibilityChange() { |
| 2230 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 2231 | if (DEBUG_VISIBILITY) { |
| 2232 | Slog.v(TAG, "Policy visibility changing after anim in " + |
| 2233 | mWinAnimator + ": " + mPolicyVisibilityAfterAnim); |
| 2234 | } |
| 2235 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 2236 | setDisplayLayoutNeeded(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2237 | if (!mPolicyVisibility) { |
| 2238 | if (mService.mCurrentFocus == this) { |
| 2239 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
| 2240 | "setAnimationLocked: setting mFocusMayChange true"); |
| 2241 | mService.mFocusMayChange = true; |
| 2242 | } |
| 2243 | // Window is no longer visible -- make sure if we were waiting |
| 2244 | // for it to be displayed before enabling the display, that |
| 2245 | // we allow the display to be enabled now. |
| 2246 | mService.enableScreenIfNeededLocked(); |
| 2247 | } |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | void setRequestedSize(int requestedWidth, int requestedHeight) { |
| 2252 | if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) { |
| 2253 | mLayoutNeeded = true; |
| 2254 | mRequestedWidth = requestedWidth; |
| 2255 | mRequestedHeight = requestedHeight; |
| 2256 | } |
| 2257 | } |
| 2258 | |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2259 | void prepareWindowToDisplayDuringRelayout(Configuration outConfig) { |
| 2260 | if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST) |
| 2261 | == SOFT_INPUT_ADJUST_RESIZE) { |
| 2262 | mLayoutNeeded = true; |
| 2263 | } |
| 2264 | if (isDrawnLw() && mService.okToDisplay()) { |
| 2265 | mWinAnimator.applyEnterAnimationLocked(); |
| 2266 | } |
| 2267 | if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) { |
| 2268 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this); |
| 2269 | mTurnOnScreen = true; |
| 2270 | } |
| 2271 | if (isConfigChanged()) { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 2272 | outConfig.setTo(getConfiguration()); |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2273 | if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: " |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 2274 | + outConfig); |
| 2275 | mLastReportedConfiguration.setTo(outConfig); |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | void adjustStartingWindowFlags() { |
| 2280 | if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null |
| 2281 | && mAppToken.startingWindow != null) { |
| 2282 | // Special handling of starting window over the base |
| 2283 | // window of the app: propagate lock screen flags to it, |
| 2284 | // to provide the correct semantics while starting. |
| 2285 | final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD |
| 2286 | | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 2287 | WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs; |
| 2288 | sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask); |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | void setWindowScale(int requestedWidth, int requestedHeight) { |
| 2293 | final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0; |
| 2294 | |
| 2295 | if (scaledWindow) { |
| 2296 | // requested{Width|Height} Surface's physical size |
| 2297 | // attrs.{width|height} Size on screen |
| 2298 | // TODO: We don't check if attrs != null here. Is it implicitly checked? |
| 2299 | mHScale = (mAttrs.width != requestedWidth) ? |
| 2300 | (mAttrs.width / (float)requestedWidth) : 1.0f; |
| 2301 | mVScale = (mAttrs.height != requestedHeight) ? |
| 2302 | (mAttrs.height / (float)requestedHeight) : 1.0f; |
| 2303 | } else { |
| 2304 | mHScale = mVScale = 1; |
| 2305 | } |
| 2306 | } |
| 2307 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2308 | private class DeathRecipient implements IBinder.DeathRecipient { |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 2309 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2310 | public void binderDied() { |
| 2311 | try { |
| 2312 | synchronized(mService.mWindowMap) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2313 | final WindowState win = mService.windowForClientLocked(mSession, mClient, false); |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2314 | Slog.i(TAG, "WIN DEATH: " + win); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2315 | if (win != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 2316 | win.removeIfPossible(shouldKeepVisibleDeadAppWindow()); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2317 | if (win.mAttrs.type == TYPE_DOCK_DIVIDER) { |
| 2318 | // The owner of the docked divider died :( We reset the docked stack, |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 2319 | // just in case they have the divider at an unstable position. Better |
| 2320 | // also reset drag resizing state, because the owner can't do it |
| 2321 | // anymore. |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2322 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
| 2323 | if (stack != null) { |
| 2324 | stack.resetDockedStackToMiddle(); |
| 2325 | } |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 2326 | mService.setDockedStackResizing(false); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 2327 | } |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 2328 | } else if (mHasSurface) { |
Craig Mautner | a99764e | 2013-03-06 10:22:16 -0800 | [diff] [blame] | 2329 | Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid."); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 2330 | WindowState.this.removeIfPossible(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | } catch (IllegalArgumentException ex) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 2334 | // This will happen if the window has already been removed. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | } |
| 2338 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2339 | /** |
| 2340 | * Returns true if this window is visible and belongs to a dead app and shouldn't be removed, |
| 2341 | * because we want to preserve its location on screen to be re-activated later when the user |
| 2342 | * interacts with it. |
| 2343 | */ |
| 2344 | boolean shouldKeepVisibleDeadAppWindow() { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 2345 | if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) { |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2346 | // Not a visible app window or the app isn't dead. |
| 2347 | return false; |
| 2348 | } |
| 2349 | |
Wale Ogunwale | 51d1d91 | 2016-05-04 13:27:18 -0700 | [diff] [blame] | 2350 | if (mAttrs.token != mClient.asBinder()) { |
| 2351 | // The window was add by a client using another client's app token. We don't want to |
| 2352 | // keep the dead window around for this case since this is meant for 'real' apps. |
| 2353 | return false; |
| 2354 | } |
| 2355 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 2356 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2357 | // We don't keep starting windows since they were added by the window manager before |
| 2358 | // the app even launched. |
| 2359 | return false; |
| 2360 | } |
| 2361 | |
| 2362 | final TaskStack stack = getStack(); |
| 2363 | return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId); |
| 2364 | } |
| 2365 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2366 | /** @return true if this window desires key events. */ |
| 2367 | boolean canReceiveKeys() { |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 2368 | return isVisibleOrAdding() |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 2369 | && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 2370 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0) |
Jorim Jaggi | b72c9ad | 2016-04-11 18:27:58 -0700 | [diff] [blame] | 2371 | && (mAppToken == null || mAppToken.windowsAreFocusable()) |
| 2372 | && !isAdjustedForMinimizedDock(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2375 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2376 | public boolean hasDrawnLw() { |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2377 | return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2378 | } |
| 2379 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 2380 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2381 | public boolean showLw(boolean doAnimation) { |
| 2382 | return showLw(doAnimation, true); |
| 2383 | } |
| 2384 | |
| 2385 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2386 | if (isHiddenFromUserLocked()) { |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 2387 | return false; |
| 2388 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2389 | if (!mAppOpVisibility) { |
| 2390 | // Being hidden due to app op request. |
| 2391 | return false; |
| 2392 | } |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2393 | if (mPermanentlyHidden) { |
| 2394 | // Permanently hidden until the app exists as apps aren't prepared |
| 2395 | // to handle their windows being removed from under them. |
| 2396 | return false; |
| 2397 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2398 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 2399 | // Already showing. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2400 | return false; |
| 2401 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2402 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2403 | if (doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2404 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2405 | + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation); |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 2406 | if (!mService.okToDisplay()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2407 | doAnimation = false; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2408 | } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2409 | // Check for the case where we are currently visible and |
| 2410 | // not animating; we do not want to do animation at such a |
| 2411 | // point to become visible when we already are. |
| 2412 | doAnimation = false; |
| 2413 | } |
| 2414 | } |
| 2415 | mPolicyVisibility = true; |
| 2416 | mPolicyVisibilityAfterAnim = true; |
| 2417 | if (doAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2418 | mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2419 | } |
| 2420 | if (requestAnim) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 2421 | mService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2422 | } |
| 2423 | return true; |
| 2424 | } |
| 2425 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2426 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2427 | public boolean hideLw(boolean doAnimation) { |
| 2428 | return hideLw(doAnimation, true); |
| 2429 | } |
| 2430 | |
| 2431 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| 2432 | if (doAnimation) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 2433 | if (!mService.okToDisplay()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2434 | doAnimation = false; |
| 2435 | } |
| 2436 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2437 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2438 | if (!current) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 2439 | // Already hiding. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2440 | return false; |
| 2441 | } |
| 2442 | if (doAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2443 | mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 2444 | if (mWinAnimator.mAnimation == null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2445 | doAnimation = false; |
| 2446 | } |
| 2447 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2448 | mPolicyVisibilityAfterAnim = false; |
| 2449 | if (!doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 2450 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2451 | mPolicyVisibility = false; |
| 2452 | // Window is no longer visible -- make sure if we were waiting |
| 2453 | // for it to be displayed before enabling the display, that |
| 2454 | // we allow the display to be enabled now. |
| 2455 | mService.enableScreenIfNeededLocked(); |
| 2456 | if (mService.mCurrentFocus == this) { |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 2457 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 2458 | "WindowState.hideLw: setting mFocusMayChange true"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2459 | mService.mFocusMayChange = true; |
| 2460 | } |
| 2461 | } |
| 2462 | if (requestAnim) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 2463 | mService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2464 | } |
| 2465 | return true; |
| 2466 | } |
| 2467 | |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 2468 | public void setAppOpVisibilityLw(boolean state) { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2469 | if (mAppOpVisibility != state) { |
| 2470 | mAppOpVisibility = state; |
| 2471 | if (state) { |
| 2472 | // If the policy visibility had last been to hide, then this |
| 2473 | // will incorrectly show at this point since we lost that |
| 2474 | // information. Not a big deal -- for the windows that have app |
| 2475 | // ops modifies they should only be hidden by policy due to the |
| 2476 | // lock screen, and the user won't be changing this if locked. |
| 2477 | // 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] | 2478 | showLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2479 | } else { |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 2480 | hideLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2481 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2482 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2483 | } |
| 2484 | |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 2485 | public void hidePermanentlyLw() { |
| 2486 | if (!mPermanentlyHidden) { |
| 2487 | mPermanentlyHidden = true; |
| 2488 | hideLw(true, true); |
| 2489 | } |
| 2490 | } |
| 2491 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2492 | public void pokeDrawLockLw(long timeout) { |
| 2493 | if (isVisibleOrAdding()) { |
| 2494 | if (mDrawLock == null) { |
| 2495 | // We want the tag name to be somewhat stable so that it is easier to correlate |
| 2496 | // in wake lock statistics. So in particular, we don't want to include the |
| 2497 | // window's hash code as in toString(). |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2498 | final CharSequence tag = getWindowTag(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2499 | mDrawLock = mService.mPowerManager.newWakeLock( |
| 2500 | PowerManager.DRAW_WAKE_LOCK, "Window:" + tag); |
| 2501 | mDrawLock.setReferenceCounted(false); |
| 2502 | mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName)); |
| 2503 | } |
| 2504 | // Each call to acquire resets the timeout. |
| 2505 | if (DEBUG_POWER) { |
| 2506 | Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by " |
| 2507 | + mAttrs.packageName); |
| 2508 | } |
| 2509 | mDrawLock.acquire(timeout); |
| 2510 | } else if (DEBUG_POWER) { |
| 2511 | Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window " |
| 2512 | + "owned by " + mAttrs.packageName); |
| 2513 | } |
| 2514 | } |
| 2515 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2516 | @Override |
| 2517 | public boolean isAlive() { |
| 2518 | return mClient.asBinder().isBinderAlive(); |
| 2519 | } |
| 2520 | |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2521 | boolean isClosing() { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2522 | return mAnimatingExit || (mService.mClosingApps.contains(mAppToken)); |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 2525 | boolean isAnimatingWithSavedSurface() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2526 | return mAnimatingWithSavedSurface; |
| 2527 | } |
| 2528 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2529 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2530 | boolean isAnimating() { |
| 2531 | if (mWinAnimator.isAnimationSet() || mAnimatingExit) { |
| 2532 | return true; |
| 2533 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2534 | return super.isAnimating(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2537 | boolean isAnimatingInvisibleWithSavedSurface() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2538 | if (mAnimatingWithSavedSurface |
| 2539 | && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) { |
| 2540 | return true; |
| 2541 | } |
| 2542 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2543 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2544 | if (c.isAnimatingInvisibleWithSavedSurface()) { |
| 2545 | return true; |
| 2546 | } |
| 2547 | } |
| 2548 | return false; |
| 2549 | } |
| 2550 | |
| 2551 | void stopUsingSavedSurface() { |
| 2552 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2553 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2554 | c.stopUsingSavedSurface(); |
| 2555 | } |
| 2556 | |
| 2557 | if (!isAnimatingInvisibleWithSavedSurface()) { |
| 2558 | return; |
| 2559 | } |
| 2560 | |
| 2561 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this); |
| 2562 | clearAnimatingWithSavedSurface(); |
| 2563 | mDestroying = true; |
| 2564 | mWinAnimator.hide("stopUsingSavedSurface"); |
| 2565 | mService.mWallpaperControllerLocked.hideWallpapers(this); |
| 2566 | } |
| 2567 | |
| 2568 | void markSavedSurfaceExiting() { |
| 2569 | if (isAnimatingInvisibleWithSavedSurface()) { |
| 2570 | mAnimatingExit = true; |
| 2571 | mWinAnimator.mAnimating = true; |
| 2572 | } |
| 2573 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2574 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2575 | c.markSavedSurfaceExiting(); |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) { |
| 2580 | animators.add(mWinAnimator); |
| 2581 | |
| 2582 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2583 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2584 | c.addWinAnimatorToList(animators); |
| 2585 | } |
| 2586 | } |
| 2587 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2588 | void sendAppVisibilityToClients() { |
| 2589 | super.sendAppVisibilityToClients(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2590 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2591 | final boolean clientHidden = mAppToken.clientHidden; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2592 | if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) { |
| 2593 | // Don't hide the starting window. |
| 2594 | return; |
| 2595 | } |
| 2596 | |
| 2597 | try { |
| 2598 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2599 | "Setting visibility of " + this + ": " + (!clientHidden)); |
| 2600 | mClient.dispatchAppVisibility(!clientHidden); |
| 2601 | } catch (RemoteException e) { |
| 2602 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2605 | public void setVisibleBeforeClientHidden() { |
| 2606 | mWasVisibleBeforeClientHidden |= |
| 2607 | (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2608 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 2609 | super.setVisibleBeforeClientHidden(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2610 | } |
| 2611 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2612 | public void clearWasVisibleBeforeClientHidden() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2613 | mWasVisibleBeforeClientHidden = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2614 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2615 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2616 | c.clearWasVisibleBeforeClientHidden(); |
| 2617 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | public boolean wasVisibleBeforeClientHidden() { |
| 2621 | return mWasVisibleBeforeClientHidden; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2624 | void onStartFreezingScreen() { |
| 2625 | mAppFreezing = true; |
| 2626 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2627 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2628 | c.onStartFreezingScreen(); |
| 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | boolean onStopFreezingScreen() { |
| 2633 | boolean unfrozeWindows = false; |
| 2634 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2635 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2636 | unfrozeWindows |= c.onStopFreezingScreen(); |
| 2637 | } |
| 2638 | |
| 2639 | if (!mAppFreezing) { |
| 2640 | return unfrozeWindows; |
| 2641 | } |
| 2642 | |
Wale Ogunwale | 953171d | 2016-09-30 09:17:30 -0700 | [diff] [blame] | 2643 | mAppFreezing = false; |
| 2644 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2645 | if (mHasSurface && !mOrientationChanging |
| 2646 | && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) { |
| 2647 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this); |
| 2648 | mOrientationChanging = true; |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 2649 | mService.mRoot.mOrientationChangeComplete = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2650 | } |
| 2651 | mLastFreezeDuration = 0; |
| 2652 | setDisplayLayoutNeeded(); |
| 2653 | return true; |
| 2654 | } |
| 2655 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2656 | private boolean shouldSaveSurface() { |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2657 | if (mWinAnimator.mSurfaceController == null) { |
| 2658 | // Don't bother if the surface controller is gone for any reason. |
| 2659 | return false; |
| 2660 | } |
| 2661 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2662 | if (!mWasVisibleBeforeClientHidden) { |
| 2663 | return false; |
| 2664 | } |
| 2665 | |
Wale Ogunwale | 945d197 | 2016-03-23 13:16:41 -0700 | [diff] [blame] | 2666 | if ((mAttrs.flags & FLAG_SECURE) != 0) { |
| 2667 | // We don't save secure surfaces since their content shouldn't be shown while the app |
| 2668 | // isn't on screen and content might leak through during the transition animation with |
| 2669 | // saved surface. |
| 2670 | return false; |
| 2671 | } |
| 2672 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2673 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 2674 | // Don't save surfaces on Svelte devices. |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2675 | return false; |
| 2676 | } |
| 2677 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2678 | Task task = getTask(); |
| 2679 | if (task == null || task.inHomeStack()) { |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2680 | // Don't save surfaces for home stack apps. These usually resume and draw |
| 2681 | // first frame very fast. Saving surfaces are mostly a waste of memory. |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2682 | return false; |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2683 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2684 | |
| 2685 | final AppWindowToken taskTop = task.getTopVisibleAppToken(); |
| 2686 | if (taskTop != null && taskTop != mAppToken) { |
| 2687 | // Don't save if the window is not the topmost window. |
| 2688 | return false; |
| 2689 | } |
| 2690 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 2691 | if (mResizedWhileGone) { |
| 2692 | // Somebody resized our window while we were gone for layout, which means that the |
| 2693 | // client got an old size, so we have an outdated surface here. |
| 2694 | return false; |
| 2695 | } |
| 2696 | |
Robert Carr | 7098dbd | 2016-02-01 12:31:01 -0800 | [diff] [blame] | 2697 | if (DEBUG_DISABLE_SAVING_SURFACES) { |
| 2698 | return false; |
| 2699 | } |
| 2700 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2701 | return mAppToken.shouldSaveSurface(); |
| 2702 | } |
| 2703 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2704 | boolean destroySurface(boolean cleanupOnResume, boolean appStopped) { |
| 2705 | boolean destroyedSomething = false; |
| 2706 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2707 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2708 | destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped); |
| 2709 | } |
| 2710 | |
| 2711 | if (appStopped || mWindowRemovalAllowed || cleanupOnResume) { |
| 2712 | |
| 2713 | mWinAnimator.destroyPreservedSurfaceLocked(); |
| 2714 | |
| 2715 | if (mDestroying) { |
| 2716 | if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this |
| 2717 | + " destroySurfaces: appStopped=" + appStopped |
| 2718 | + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed |
| 2719 | + " win.mRemoveOnExit=" + mRemoveOnExit); |
| 2720 | |
| 2721 | if (!cleanupOnResume || mRemoveOnExit) { |
| 2722 | destroyOrSaveSurface(); |
| 2723 | } |
| 2724 | if (mRemoveOnExit) { |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 2725 | removeImmediately(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2726 | } |
| 2727 | if (cleanupOnResume) { |
| 2728 | requestUpdateWallpaperIfNeeded(); |
| 2729 | } |
| 2730 | mDestroying = false; |
| 2731 | destroyedSomething = true; |
| 2732 | } |
| 2733 | } |
| 2734 | return destroyedSomething; |
| 2735 | } |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 2736 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2737 | void destroyOrSaveSurface() { |
| 2738 | mSurfaceSaved = shouldSaveSurface(); |
| 2739 | if (mSurfaceSaved) { |
| 2740 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 2741 | Slog.v(TAG, "Saving surface: " + this); |
| 2742 | } |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 2743 | // Previous user of the surface may have set a transparent region signaling a portion |
| 2744 | // doesn't need to be composited, so reset to default empty state. |
| 2745 | mSession.setTransparentRegion(mClient, sEmptyRegion); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2746 | |
| 2747 | mWinAnimator.hide("saved surface"); |
| 2748 | mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE; |
| 2749 | setHasSurface(false); |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 2750 | // The client should have disconnected at this point, but if it doesn't, |
| 2751 | // we need to make sure it's disconnected. Otherwise when we reuse the surface |
| 2752 | // the client can't reconnect to the buffer queue, and rendering will fail. |
| 2753 | if (mWinAnimator.mSurfaceController != null) { |
| 2754 | mWinAnimator.mSurfaceController.disconnectInTransaction(); |
| 2755 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2756 | mAnimatingWithSavedSurface = false; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2757 | } else { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2758 | mWinAnimator.destroySurfaceLocked(); |
| 2759 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2760 | // Clear animating flags now, since the surface is now gone. (Note this is true even |
| 2761 | // if the surface is saved, to outside world the surface is still NO_SURFACE.) |
| 2762 | mAnimatingExit = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2763 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2764 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2765 | void destroySavedSurface() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2766 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2767 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2768 | c.destroySavedSurface(); |
| 2769 | } |
| 2770 | |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2771 | if (mSurfaceSaved) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2772 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2773 | mWinAnimator.destroySurfaceLocked(); |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2774 | mSurfaceSaved = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2775 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2776 | mWasVisibleBeforeClientHidden = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2777 | } |
| 2778 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2779 | /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/ |
| 2780 | int restoreSavedSurfaceForInterestingWindow() { |
| 2781 | int interestingNotDrawn = -1; |
| 2782 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2783 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2784 | final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow(); |
| 2785 | if (childInterestingNotDrawn != -1) { |
| 2786 | if (interestingNotDrawn == -1) { |
| 2787 | interestingNotDrawn = childInterestingNotDrawn; |
| 2788 | } else { |
| 2789 | interestingNotDrawn += childInterestingNotDrawn; |
| 2790 | } |
| 2791 | } |
Chong Zhang | 4113ffa | 2016-02-18 12:39:13 -0800 | [diff] [blame] | 2792 | } |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2793 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2794 | if (mAttrs.type == TYPE_APPLICATION_STARTING |
| 2795 | || mAppDied || !wasVisibleBeforeClientHidden() |
| 2796 | || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) { |
| 2797 | // Window isn't interesting... |
| 2798 | return interestingNotDrawn; |
| 2799 | } |
| 2800 | |
| 2801 | restoreSavedSurface(); |
| 2802 | |
| 2803 | if (!isDrawnLw()) { |
| 2804 | if (interestingNotDrawn == -1) { |
| 2805 | interestingNotDrawn = 1; |
| 2806 | } else { |
| 2807 | interestingNotDrawn++; |
| 2808 | } |
| 2809 | } |
| 2810 | return interestingNotDrawn; |
| 2811 | } |
| 2812 | |
| 2813 | /** Returns true if the saved surface was restored. */ |
| 2814 | boolean restoreSavedSurface() { |
| 2815 | if (!mSurfaceSaved) { |
| 2816 | return false; |
| 2817 | } |
| 2818 | |
| 2819 | // Sometimes we save surfaces due to layout invisible directly after rotation occurs. |
| 2820 | // However this means the surface was never laid out in the new orientation. |
| 2821 | // We can only restore to the last rotation we were laid out as visible in. |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2822 | if (mLastVisibleLayoutRotation != mService.mRotation) { |
| 2823 | destroySavedSurface(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2824 | return false; |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2825 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2826 | mSurfaceSaved = false; |
Robert Carr | 237028a | 2016-07-26 10:39:45 -0700 | [diff] [blame] | 2827 | |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2828 | if (mWinAnimator.mSurfaceController != null) { |
| 2829 | setHasSurface(true); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 2830 | mWinAnimator.mDrawState = READY_TO_SHOW; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2831 | mAnimatingWithSavedSurface = true; |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2832 | |
Chong Zhang | 6e9872b | 2016-08-17 10:19:05 -0700 | [diff] [blame] | 2833 | requestUpdateWallpaperIfNeeded(); |
| 2834 | |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2835 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 2836 | Slog.v(TAG, "Restoring saved surface: " + this); |
| 2837 | } |
| 2838 | } else { |
| 2839 | // mSurfaceController shouldn't be null if mSurfaceSaved was still true at |
| 2840 | // this point. Even if we destroyed the saved surface because of rotation |
| 2841 | // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf. |
| 2842 | Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2843 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2844 | |
| 2845 | return true; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2846 | } |
| 2847 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2848 | boolean canRestoreSurface() { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2849 | if (mWasVisibleBeforeClientHidden && mSurfaceSaved) { |
| 2850 | return true; |
| 2851 | } |
| 2852 | |
| 2853 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 2854 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 2855 | if (c.canRestoreSurface()) { |
| 2856 | return true; |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | return false; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | boolean hasSavedSurface() { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2864 | return mSurfaceSaved; |
| 2865 | } |
| 2866 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2867 | void clearHasSavedSurface() { |
| 2868 | mSurfaceSaved = false; |
| 2869 | mAnimatingWithSavedSurface = false; |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 2870 | if (mWasVisibleBeforeClientHidden) { |
| 2871 | mAppToken.destroySavedSurfaces(); |
| 2872 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2873 | } |
| 2874 | |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2875 | boolean clearAnimatingWithSavedSurface() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2876 | if (mAnimatingWithSavedSurface) { |
| 2877 | // App has drawn something to its windows, we're no longer animating with |
| 2878 | // the saved surfaces. |
| 2879 | if (DEBUG_ANIM) Slog.d(TAG, |
| 2880 | "clearAnimatingWithSavedSurface(): win=" + this); |
| 2881 | mAnimatingWithSavedSurface = false; |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2882 | return true; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2883 | } |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2884 | return false; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2887 | @Override |
| 2888 | public boolean isDefaultDisplay() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2889 | final DisplayContent displayContent = getDisplayContent(); |
| 2890 | if (displayContent == null) { |
| 2891 | // Only a window that was on a non-default display can be detached from it. |
| 2892 | return false; |
| 2893 | } |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 2894 | return displayContent.isDefaultDisplay; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 2897 | @Override |
| 2898 | public boolean isDimming() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 2899 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2900 | final DisplayContent dc = getDisplayContent(); |
| 2901 | return dimLayerUser != null && dc != null |
| 2902 | && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator); |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 2903 | } |
| 2904 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2905 | void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) { |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2906 | mShowToOwnerOnly = showToOwnerOnly; |
| 2907 | } |
| 2908 | |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2909 | boolean isHiddenFromUserLocked() { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 2910 | // Child windows are evaluated based on their parent window. |
| 2911 | final WindowState win = getTopParentWindow(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 2912 | if (win.mAttrs.type < FIRST_SYSTEM_WINDOW |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2913 | && win.mAppToken != null && win.mAppToken.showForAllUsers) { |
Jorim Jaggi | dbe44ac | 2016-04-22 19:50:13 -0700 | [diff] [blame] | 2914 | |
| 2915 | // All window frames that are fullscreen extend above status bar, but some don't extend |
| 2916 | // below navigation bar. Thus, check for display frame for top/left and stable frame for |
| 2917 | // bottom right. |
| 2918 | if (win.mFrame.left <= win.mDisplayFrame.left |
| 2919 | && win.mFrame.top <= win.mDisplayFrame.top |
| 2920 | && win.mFrame.right >= win.mStableFrame.right |
| 2921 | && win.mFrame.bottom >= win.mStableFrame.bottom) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2922 | // Is a fullscreen window, like the clock alarm. Show to everyone. |
| 2923 | return false; |
| 2924 | } |
| 2925 | } |
| 2926 | |
Craig Mautner | 341220f | 2012-10-16 15:20:09 -0700 | [diff] [blame] | 2927 | return win.mShowToOwnerOnly |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 2928 | && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid)); |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2931 | private static void applyInsets(Region outRegion, Rect frame, Rect inset) { |
| 2932 | outRegion.set( |
| 2933 | frame.left + inset.left, frame.top + inset.top, |
| 2934 | frame.right - inset.right, frame.bottom - inset.bottom); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2935 | } |
| 2936 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2937 | void getTouchableRegion(Region outRegion) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2938 | final Rect frame = mFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2939 | switch (mTouchableInsets) { |
| 2940 | default: |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2941 | case TOUCHABLE_INSETS_FRAME: |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2942 | outRegion.set(frame); |
| 2943 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2944 | case TOUCHABLE_INSETS_CONTENT: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2945 | applyInsets(outRegion, frame, mGivenContentInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2946 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2947 | case TOUCHABLE_INSETS_VISIBLE: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2948 | applyInsets(outRegion, frame, mGivenVisibleInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2949 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2950 | case TOUCHABLE_INSETS_REGION: { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2951 | final Region givenTouchableRegion = mGivenTouchableRegion; |
| 2952 | outRegion.set(givenTouchableRegion); |
| 2953 | outRegion.translate(frame.left, frame.top); |
| 2954 | break; |
| 2955 | } |
| 2956 | } |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2957 | cropRegionToStackBoundsIfNeeded(outRegion); |
| 2958 | } |
| 2959 | |
| 2960 | void cropRegionToStackBoundsIfNeeded(Region region) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2961 | final Task task = getTask(); |
| 2962 | if (task == null || !task.cropWindowsToStackBounds()) { |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2963 | return; |
| 2964 | } |
| 2965 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2966 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2967 | if (stack == null) { |
| 2968 | return; |
| 2969 | } |
| 2970 | |
| 2971 | stack.getDimBounds(mTmpRect); |
| 2972 | region.op(mTmpRect, Region.Op.INTERSECT); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2973 | } |
| 2974 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 2975 | // TODO: This is one reason why WindowList are bad...prime candidate for removal once we |
| 2976 | // figure-out a good way to replace WindowList with WindowContainer hierarchy. |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2977 | WindowList getWindowList() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2978 | final DisplayContent displayContent = getDisplayContent(); |
| 2979 | return displayContent == null ? null : displayContent.getWindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2982 | /** |
| 2983 | * Report a focus change. Must be called with no locks held, and consistently |
| 2984 | * from the same serialized thread (such as dispatched from a handler). |
| 2985 | */ |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame^] | 2986 | void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) { |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2987 | try { |
| 2988 | mClient.windowFocusChanged(focused, inTouchMode); |
| 2989 | } catch (RemoteException e) { |
| 2990 | } |
| 2991 | if (mFocusCallbacks != null) { |
| 2992 | final int N = mFocusCallbacks.beginBroadcast(); |
| 2993 | for (int i=0; i<N; i++) { |
| 2994 | IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i); |
| 2995 | try { |
| 2996 | if (focused) { |
| 2997 | obs.focusGained(mWindowId.asBinder()); |
| 2998 | } else { |
| 2999 | obs.focusLost(mWindowId.asBinder()); |
| 3000 | } |
| 3001 | } catch (RemoteException e) { |
| 3002 | } |
| 3003 | } |
| 3004 | mFocusCallbacks.finishBroadcast(); |
| 3005 | } |
| 3006 | } |
| 3007 | |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3008 | @Override |
| 3009 | public Configuration getConfiguration() { |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3010 | if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3011 | return mAppToken.mFrozenMergedConfig.peek(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3012 | } |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3013 | |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3014 | return super.getConfiguration(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3017 | void reportResized() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3018 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag()); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3019 | try { |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 3020 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this |
| 3021 | + ": " + mCompatFrame); |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3022 | final Configuration newConfig; |
| 3023 | if (isConfigChanged()) { |
| 3024 | newConfig = new Configuration(getConfiguration()); |
| 3025 | mLastReportedConfiguration.setTo(newConfig); |
| 3026 | } else { |
| 3027 | newConfig = null; |
| 3028 | } |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3029 | if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING) |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 3030 | Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING"); |
| 3031 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3032 | final Rect frame = mFrame; |
| 3033 | final Rect overscanInsets = mLastOverscanInsets; |
| 3034 | final Rect contentInsets = mLastContentInsets; |
| 3035 | final Rect visibleInsets = mLastVisibleInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3036 | final Rect stableInsets = mLastStableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3037 | final Rect outsets = mLastOutsets; |
Wale Ogunwale | 19e452e | 2016-10-12 12:36:29 -0700 | [diff] [blame] | 3038 | final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING; |
Chet Haase | 8eb48d2 | 2014-09-24 07:31:29 -0700 | [diff] [blame] | 3039 | if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 3040 | && mClient instanceof IWindow.Stub) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3041 | // To prevent deadlock simulate one-way call if win.mClient is a local object. |
| 3042 | mService.mH.post(new Runnable() { |
| 3043 | @Override |
| 3044 | public void run() { |
| 3045 | try { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3046 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, |
| 3047 | stableInsets, outsets, reportDraw, newConfig); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3048 | } catch (RemoteException e) { |
| 3049 | // Not a remote call, RemoteException won't be raised. |
| 3050 | } |
| 3051 | } |
| 3052 | }); |
| 3053 | } else { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3054 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3055 | outsets, reportDraw, newConfig); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3056 | } |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3057 | |
| 3058 | //TODO (multidisplay): Accessibility supported only for the default display. |
| 3059 | if (mService.mAccessibilityController != null |
| 3060 | && getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 3061 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3064 | mOverscanInsetsChanged = false; |
| 3065 | mContentInsetsChanged = false; |
| 3066 | mVisibleInsetsChanged = false; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3067 | mStableInsetsChanged = false; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3068 | mOutsetsChanged = false; |
Robert Carr | 31aa98b | 2016-07-20 15:29:03 -0700 | [diff] [blame] | 3069 | mFrameSizeChanged = false; |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 3070 | mResizedWhileNotDragResizingReported = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3071 | mWinAnimator.mSurfaceResized = false; |
| 3072 | } catch (RemoteException e) { |
| 3073 | mOrientationChanging = false; |
| 3074 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 3075 | - mService.mDisplayFreezeTime); |
tiger_huang | 950ee77 | 2014-07-11 18:41:48 +0800 | [diff] [blame] | 3076 | // We are assuming the hosting process is dead or in a zombie state. |
| 3077 | Slog.w(TAG, "Failed to report 'resized' to the client of " + this |
| 3078 | + ", removing this window."); |
| 3079 | mService.mPendingRemove.add(this); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 3080 | mService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3081 | } |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3082 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3083 | } |
| 3084 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3085 | Rect getBackdropFrame(Rect frame) { |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 3086 | // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing |
| 3087 | // start even if we haven't received the relayout window, so that the client requests |
| 3088 | // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen |
| 3089 | // until the window to small size, otherwise the multithread renderer will shift last |
| 3090 | // one or more frame to wrong offset. So here we send fullscreen backdrop if either |
| 3091 | // isDragResizing() or isDragResizeChanged() is true. |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3092 | boolean resizing = isDragResizing() || isDragResizeChanged(); |
| 3093 | if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) { |
| 3094 | return frame; |
| 3095 | } |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame^] | 3096 | final DisplayInfo displayInfo = getDisplayInfo(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3097 | mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3098 | return mTmpRect; |
| 3099 | } |
| 3100 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 3101 | @Override |
| 3102 | public int getStackId() { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 3103 | final TaskStack stack = getStack(); |
| 3104 | if (stack == null) { |
| 3105 | return INVALID_STACK_ID; |
| 3106 | } |
| 3107 | return stack.mStackId; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
| 3111 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
| 3112 | Configuration newConfig) throws RemoteException { |
Chong Zhang | edaf305 | 2016-04-22 15:04:31 -0700 | [diff] [blame] | 3113 | final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing; |
| 3114 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 3115 | mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets, |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 3116 | reportDraw, newConfig, getBackdropFrame(frame), |
Chong Zhang | edaf305 | 2016-04-22 15:04:31 -0700 | [diff] [blame] | 3117 | forceRelayout, mPolicy.isNavBarForcedShownLw(this)); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3118 | mDragResizingChangeReported = true; |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 3119 | } |
| 3120 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 3121 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 3122 | synchronized(mService.mWindowMap) { |
| 3123 | if (mFocusCallbacks == null) { |
| 3124 | mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>(); |
| 3125 | } |
| 3126 | mFocusCallbacks.register(observer); |
| 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 3131 | synchronized(mService.mWindowMap) { |
| 3132 | if (mFocusCallbacks != null) { |
| 3133 | mFocusCallbacks.unregister(observer); |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | public boolean isFocused() { |
| 3139 | synchronized(mService.mWindowMap) { |
| 3140 | return mService.mCurrentFocus == this; |
| 3141 | } |
| 3142 | } |
| 3143 | |
Filip Gruszczynski | 1a1d831 | 2015-08-26 17:00:47 -0700 | [diff] [blame] | 3144 | boolean inFreeformWorkspace() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 3145 | final Task task = getTask(); |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 3146 | return task != null && task.inFreeformWorkspace(); |
| 3147 | } |
| 3148 | |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 3149 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 3150 | public boolean isInMultiWindowMode() { |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 3151 | final Task task = getTask(); |
| 3152 | return task != null && !task.isFullscreen(); |
| 3153 | } |
| 3154 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3155 | boolean isDragResizeChanged() { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3156 | return mDragResizing != computeDragResizing(); |
| 3157 | } |
| 3158 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3159 | @Override |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3160 | void setWaitingForDrawnIfResizingChanged() { |
| 3161 | if (isDragResizeChanged()) { |
| 3162 | mService.mWaitingForDrawn.add(this); |
| 3163 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3164 | super.setWaitingForDrawnIfResizingChanged(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3167 | /** |
| 3168 | * @return Whether we reported a drag resize change to the application or not already. |
| 3169 | */ |
| 3170 | boolean isDragResizingChangeReported() { |
| 3171 | return mDragResizingChangeReported; |
| 3172 | } |
| 3173 | |
| 3174 | /** |
| 3175 | * Resets the state whether we reported a drag resize change to the app. |
| 3176 | */ |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3177 | @Override |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3178 | void resetDragResizingChangeReported() { |
| 3179 | mDragResizingChangeReported = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 3180 | super.resetDragResizingChangeReported(); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3181 | } |
| 3182 | |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 3183 | /** |
| 3184 | * Set whether we got resized but drag resizing flag was false. |
| 3185 | * @see #isResizedWhileNotDragResizing(). |
| 3186 | */ |
| 3187 | void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) { |
| 3188 | mResizedWhileNotDragResizing = resizedWhileNotDragResizing; |
| 3189 | mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing; |
| 3190 | } |
| 3191 | |
| 3192 | /** |
| 3193 | * Indicates whether we got resized but drag resizing flag was false. In this case, we also |
| 3194 | * need to recreate the surface and defer surface bound updates in order to make sure the |
| 3195 | * buffer contents and the positioning/size stay in sync. |
| 3196 | */ |
| 3197 | boolean isResizedWhileNotDragResizing() { |
| 3198 | return mResizedWhileNotDragResizing; |
| 3199 | } |
| 3200 | |
| 3201 | /** |
| 3202 | * @return Whether we reported "resize while not drag resizing" to the application. |
| 3203 | * @see #isResizedWhileNotDragResizing() |
| 3204 | */ |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3205 | private boolean isResizedWhileNotDragResizingReported() { |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 3206 | return mResizedWhileNotDragResizingReported; |
| 3207 | } |
| 3208 | |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 3209 | int getResizeMode() { |
| 3210 | return mResizeMode; |
| 3211 | } |
| 3212 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3213 | private boolean computeDragResizing() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 3214 | final Task task = getTask(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3215 | if (task == null) { |
| 3216 | return false; |
| 3217 | } |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 3218 | if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) { |
| 3219 | |
| 3220 | // Floating windows never enter drag resize mode. |
| 3221 | return false; |
| 3222 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 3223 | if (task.isDragResizing()) { |
| 3224 | return true; |
| 3225 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 3226 | |
| 3227 | // If the bounds are currently frozen, it means that the layout size that the app sees |
| 3228 | // and the bounds we clip this window to might be different. In order to avoid holes, we |
| 3229 | // simulate that we are still resizing so the app fills the hole with the resizing |
| 3230 | // background. |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3231 | return (getDisplayContent().mDividerControllerLocked.isResizing() |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 3232 | || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) && |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 3233 | !task.inFreeformWorkspace() && !isGoneForLayoutLw(); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3234 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | void setDragResizing() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 3238 | final boolean resizing = computeDragResizing(); |
| 3239 | if (resizing == mDragResizing) { |
| 3240 | return; |
| 3241 | } |
| 3242 | mDragResizing = resizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3243 | final Task task = getTask(); |
| 3244 | if (task != null && task.isDragResizing()) { |
| 3245 | mResizeMode = task.getDragResizeMode(); |
| 3246 | } else { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3247 | mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing() |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 3248 | ? DRAG_RESIZE_MODE_DOCKED_DIVIDER |
| 3249 | : DRAG_RESIZE_MODE_FREEFORM; |
| 3250 | } |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | boolean isDragResizing() { |
| 3254 | return mDragResizing; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 3257 | boolean isDockedResizing() { |
| 3258 | return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 3259 | } |
| 3260 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3261 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Wale Ogunwale | 30cc7bf | 2015-02-04 16:47:57 -0800 | [diff] [blame] | 3262 | final TaskStack stack = getStack(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3263 | pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId()); |
Wale Ogunwale | 30cc7bf | 2015-02-04 16:47:57 -0800 | [diff] [blame] | 3264 | if (stack != null) { |
| 3265 | pw.print(" stackId="); pw.print(stack.mStackId); |
| 3266 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 3267 | pw.print(" mSession="); pw.print(mSession); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3268 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 3269 | pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 3270 | pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly); |
| 3271 | pw.print(" package="); pw.print(mAttrs.packageName); |
| 3272 | pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3273 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3274 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| 3275 | pw.print(" h="); pw.print(mRequestedHeight); |
| 3276 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 3277 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 3278 | pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth); |
| 3279 | pw.print(" h="); pw.println(mLastRequestedHeight); |
| 3280 | } |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3281 | if (mIsChildWindow || mLayoutAttached) { |
| 3282 | pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3283 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 3284 | } |
| 3285 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 3286 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 3287 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| 3288 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 3289 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| 3290 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3291 | if (dumpAll) { |
| 3292 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 3293 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 3294 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 3295 | pw.print(getAnimLayerAdjustment()); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 3296 | pw.print("="); pw.print(mWinAnimator.mAnimLayer); |
| 3297 | pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 3298 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3299 | if (dumpAll) { |
| 3300 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3301 | if (mAppToken != null) { |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 3302 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 3303 | pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()="); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 3304 | pw.print(isAnimatingWithSavedSurface()); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 3305 | pw.print(" mAppDied=");pw.println(mAppDied); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3306 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3307 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 3308 | pw.print(Integer.toHexString(mViewVisibility)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3309 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 3310 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 3311 | pw.print(prefix); pw.print("mSeq="); pw.print(mSeq); |
| 3312 | pw.print(" mSystemUiVisibility=0x"); |
| 3313 | pw.println(Integer.toHexString(mSystemUiVisibility)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3314 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 3315 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility |
Svetoslav Ganov | 71c5102 | 2016-09-02 17:54:37 -0700 | [diff] [blame] | 3316 | || isParentWindowHidden()|| mPermanentlyHidden) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3317 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 3318 | pw.print(mPolicyVisibility); |
| 3319 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 3320 | pw.print(mPolicyVisibilityAfterAnim); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 3321 | pw.print(" mAppOpVisibility="); |
| 3322 | pw.print(mAppOpVisibility); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3323 | pw.print(" parentHidden="); pw.println(isParentWindowHidden()); |
Svetoslav Ganov | aa07653 | 2016-08-01 19:16:43 -0700 | [diff] [blame] | 3324 | pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3325 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 3326 | if (!mRelayoutCalled || mLayoutNeeded) { |
| 3327 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled); |
| 3328 | pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3329 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3330 | if (mXOffset != 0 || mYOffset != 0) { |
| 3331 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 3332 | pw.print(" y="); pw.println(mYOffset); |
| 3333 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3334 | if (dumpAll) { |
| 3335 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 3336 | mGivenContentInsets.printShortString(pw); |
| 3337 | pw.print(" mGivenVisibleInsets="); |
| 3338 | mGivenVisibleInsets.printShortString(pw); |
| 3339 | pw.println(); |
| 3340 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 3341 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 3342 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3343 | Region region = new Region(); |
| 3344 | getTouchableRegion(region); |
| 3345 | pw.print(prefix); pw.print("touchable region="); pw.println(region); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3346 | } |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 3347 | pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration()); |
| 3348 | pw.print(prefix); pw.print("mLastReportedConfiguration="); |
| 3349 | pw.println(mLastReportedConfiguration); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3350 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 3351 | pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface); |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 3352 | pw.print(" mShownPosition="); mShownPosition.printShortString(pw); |
Chong Zhang | a8975bd | 2016-01-28 17:13:47 -0800 | [diff] [blame] | 3353 | pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay()); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 3354 | pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface()); |
| 3355 | pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3356 | if (dumpAll) { |
| 3357 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 3358 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 3359 | pw.println(); |
| 3360 | } |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3361 | if (mEnforceSizeCompat) { |
| 3362 | pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 3363 | pw.println(); |
| 3364 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3365 | if (dumpAll) { |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3366 | pw.print(prefix); pw.print("Frames: containing="); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3367 | mContainingFrame.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3368 | pw.print(" parent="); mParentFrame.printShortString(pw); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3369 | pw.println(); |
| 3370 | pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw); |
| 3371 | pw.print(" overscan="); mOverscanFrame.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3372 | pw.println(); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 3373 | pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3374 | pw.print(" visible="); mVisibleFrame.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3375 | pw.println(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3376 | pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw); |
| 3377 | pw.println(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3378 | pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw); |
| 3379 | pw.println(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3380 | pw.print(prefix); pw.print("Cur insets: overscan="); |
| 3381 | mOverscanInsets.printShortString(pw); |
| 3382 | pw.print(" content="); mContentInsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3383 | pw.print(" visible="); mVisibleInsets.printShortString(pw); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3384 | pw.print(" stable="); mStableInsets.printShortString(pw); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 3385 | pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3386 | pw.print(" outsets="); mOutsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3387 | pw.println(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3388 | pw.print(prefix); pw.print("Lst insets: overscan="); |
| 3389 | mLastOverscanInsets.printShortString(pw); |
| 3390 | pw.print(" content="); mLastContentInsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 3391 | pw.print(" visible="); mLastVisibleInsets.printShortString(pw); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3392 | pw.print(" stable="); mLastStableInsets.printShortString(pw); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3393 | pw.print(" physical="); mLastOutsets.printShortString(pw); |
| 3394 | pw.print(" outset="); mLastOutsets.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 3395 | pw.println(); |
| 3396 | } |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 3397 | pw.print(prefix); pw.print(mWinAnimator); pw.println(":"); |
| 3398 | mWinAnimator.dump(pw, prefix + " ", dumpAll); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3399 | if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) { |
| 3400 | pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3401 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 3402 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 3403 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 3404 | } |
| 3405 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| 3406 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 3407 | pw.print(mOrientationChanging); |
| 3408 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 3409 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| 3410 | } |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 3411 | if (mLastFreezeDuration != 0) { |
| 3412 | pw.print(prefix); pw.print("mLastFreezeDuration="); |
| 3413 | TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println(); |
| 3414 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3415 | if (mHScale != 1 || mVScale != 1) { |
| 3416 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 3417 | pw.print(" mVScale="); pw.println(mVScale); |
| 3418 | } |
| 3419 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| 3420 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 3421 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 3422 | } |
| 3423 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 3424 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 3425 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 3426 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3427 | if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE |
| 3428 | || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 3429 | pw.print(prefix); pw.print("mWallpaperDisplayOffsetX="); |
| 3430 | pw.print(mWallpaperDisplayOffsetX); |
| 3431 | pw.print(" mWallpaperDisplayOffsetY="); |
| 3432 | pw.println(mWallpaperDisplayOffsetY); |
| 3433 | } |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3434 | if (mDrawLock != null) { |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 3435 | pw.print(prefix); pw.println("mDrawLock=" + mDrawLock); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 3436 | } |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 3437 | if (isDragResizing()) { |
| 3438 | pw.print(prefix); pw.println("isDragResizing=" + isDragResizing()); |
| 3439 | } |
| 3440 | if (computeDragResizing()) { |
| 3441 | pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing()); |
| 3442 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3443 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 3444 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3445 | @Override |
| 3446 | String getName() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3447 | return Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3448 | + " " + getWindowTag(); |
| 3449 | } |
| 3450 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3451 | CharSequence getWindowTag() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3452 | CharSequence tag = mAttrs.getTitle(); |
| 3453 | if (tag == null || tag.length() <= 0) { |
| 3454 | tag = mAttrs.packageName; |
| 3455 | } |
| 3456 | return tag; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | @Override |
| 3460 | public String toString() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 3461 | final CharSequence title = getWindowTag(); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3462 | if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 3463 | mLastTitle = title; |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3464 | mWasExiting = mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3465 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3466 | + " u" + UserHandle.getUserId(mOwnerUid) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 3467 | + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3468 | } |
| 3469 | return mStringNameCache; |
| 3470 | } |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3471 | |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3472 | void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) { |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3473 | if (mHScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3474 | clipRect.left = (int) (clipRect.left / mHScale); |
| 3475 | clipRect.right = (int) Math.ceil(clipRect.right / mHScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3476 | } |
| 3477 | if (mVScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 3478 | clipRect.top = (int) (clipRect.top / mVScale); |
| 3479 | clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 3480 | } |
| 3481 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3482 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3483 | void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) { |
| 3484 | final int pw = containingFrame.width(); |
| 3485 | final int ph = containingFrame.height(); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3486 | final Task task = getTask(); |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 3487 | final boolean nonFullscreenTask = isInMultiWindowMode(); |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 3488 | final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0; |
| 3489 | |
| 3490 | // We need to fit it to the display if either |
| 3491 | // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless |
| 3492 | // windows) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3493 | // b) If it's a secondary app window, we also need to fit it to the display unless |
| 3494 | // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on screen, |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 3495 | // but SurfaceViews want to be always at a specific location so we don't fit it to the |
| 3496 | // display. |
| 3497 | final boolean fitToDisplay = (task == null || !nonFullscreenTask) |
Robert Carr | 6f44db1 | 2016-07-21 14:54:43 -0700 | [diff] [blame] | 3498 | || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3499 | float x, y; |
| 3500 | int w,h; |
| 3501 | |
| 3502 | if ((mAttrs.flags & FLAG_SCALED) != 0) { |
| 3503 | if (mAttrs.width < 0) { |
| 3504 | w = pw; |
| 3505 | } else if (mEnforceSizeCompat) { |
| 3506 | w = (int)(mAttrs.width * mGlobalScale + .5f); |
| 3507 | } else { |
| 3508 | w = mAttrs.width; |
| 3509 | } |
| 3510 | if (mAttrs.height < 0) { |
| 3511 | h = ph; |
| 3512 | } else if (mEnforceSizeCompat) { |
| 3513 | h = (int)(mAttrs.height * mGlobalScale + .5f); |
| 3514 | } else { |
| 3515 | h = mAttrs.height; |
| 3516 | } |
| 3517 | } else { |
| 3518 | if (mAttrs.width == MATCH_PARENT) { |
| 3519 | w = pw; |
| 3520 | } else if (mEnforceSizeCompat) { |
| 3521 | w = (int)(mRequestedWidth * mGlobalScale + .5f); |
| 3522 | } else { |
| 3523 | w = mRequestedWidth; |
| 3524 | } |
| 3525 | if (mAttrs.height == MATCH_PARENT) { |
| 3526 | h = ph; |
| 3527 | } else if (mEnforceSizeCompat) { |
| 3528 | h = (int)(mRequestedHeight * mGlobalScale + .5f); |
| 3529 | } else { |
| 3530 | h = mRequestedHeight; |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | if (mEnforceSizeCompat) { |
| 3535 | x = mAttrs.x * mGlobalScale; |
| 3536 | y = mAttrs.y * mGlobalScale; |
| 3537 | } else { |
| 3538 | x = mAttrs.x; |
| 3539 | y = mAttrs.y; |
| 3540 | } |
| 3541 | |
Robert Carr | 1d2bacb | 2016-03-30 14:29:35 -0700 | [diff] [blame] | 3542 | if (nonFullscreenTask && !layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 3543 | // 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] | 3544 | // required by {@link Gravity#apply} call. |
| 3545 | w = Math.min(w, pw); |
| 3546 | h = Math.min(h, ph); |
| 3547 | } |
| 3548 | |
| 3549 | // Set mFrame |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3550 | Gravity.apply(mAttrs.gravity, w, h, containingFrame, |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3551 | (int) (x + mAttrs.horizontalMargin * pw), |
| 3552 | (int) (y + mAttrs.verticalMargin * ph), mFrame); |
| 3553 | |
| 3554 | // Now make sure the window fits in the overall display frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3555 | if (fitToDisplay) { |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 3556 | Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 3557 | } |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 3558 | |
| 3559 | // We need to make sure we update the CompatFrame as it is used for |
| 3560 | // cropping decisions, etc, on systems where we lack a decor layer. |
| 3561 | mCompatFrame.set(mFrame); |
| 3562 | if (mEnforceSizeCompat) { |
| 3563 | // See comparable block in computeFrameLw. |
| 3564 | mCompatFrame.scale(mInvGlobalScale); |
| 3565 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 3566 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 3567 | |
| 3568 | boolean isChildWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3569 | return mIsChildWindow; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * Returns the bottom child window in regards to z-order of this window or null if no children. |
| 3574 | */ |
| 3575 | WindowState getBottomChild() { |
| 3576 | // Child windows are z-ordered based on sub-layer using {@link #sWindowSubLayerComparator} |
| 3577 | // and the child with the lowest z-order will be at the head of the list. |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3578 | WindowState c = mChildren.peekFirst(); |
| 3579 | return c == null ? null : c; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3582 | boolean layoutInParentFrame() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3583 | return mIsChildWindow |
| 3584 | && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0; |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3587 | /** Returns the parent window if this is a child of another window, else null. */ |
| 3588 | WindowState getParentWindow() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3589 | // NOTE: We are not calling getParent() directly as the WindowState might be a child of a |
| 3590 | // WindowContainer that isn't a WindowState. |
| 3591 | return (mIsChildWindow) ? ((WindowState) super.getParent()) : null; |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | /** Returns the topmost parent window if this is a child of another window, else this. */ |
| 3595 | WindowState getTopParentWindow() { |
| 3596 | WindowState w = this; |
Wale Ogunwale | a6cc361 | 2016-08-04 07:25:33 -0700 | [diff] [blame] | 3597 | while (w != null && w.mIsChildWindow) { |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 3598 | w = w.getParentWindow(); |
| 3599 | } |
| 3600 | return w; |
| 3601 | } |
| 3602 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3603 | boolean isParentWindowHidden() { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3604 | final WindowState parent = getParentWindow(); |
| 3605 | return (parent == null) ? false : parent.mHidden; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3608 | void setWillReplaceWindow(boolean animate) { |
| 3609 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3610 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3611 | c.setWillReplaceWindow(animate); |
| 3612 | } |
| 3613 | |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3614 | if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0 |
| 3615 | || mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 3616 | // We don't set replacing on starting windows since they are added by window manager and |
| 3617 | // not the client so won't be replaced by the client. |
| 3618 | return; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3619 | } |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3620 | |
| 3621 | mWillReplaceWindow = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3622 | mReplacementWindow = null; |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 3623 | mAnimateReplacingWindow = animate; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 3624 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3625 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3626 | void clearWillReplaceWindow() { |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3627 | mWillReplaceWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3628 | mReplacementWindow = null; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3629 | mAnimateReplacingWindow = false; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3630 | |
| 3631 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3632 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3633 | c.clearWillReplaceWindow(); |
| 3634 | } |
| 3635 | } |
| 3636 | |
| 3637 | boolean waitingForReplacement() { |
| 3638 | if (mWillReplaceWindow) { |
| 3639 | return true; |
| 3640 | } |
| 3641 | |
| 3642 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3643 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3644 | if (c.waitingForReplacement()) { |
| 3645 | return true; |
| 3646 | } |
| 3647 | } |
| 3648 | return false; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 3649 | } |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3650 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3651 | void requestUpdateWallpaperIfNeeded() { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3652 | final DisplayContent dc = getDisplayContent(); |
| 3653 | if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 3654 | dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 3655 | dc.setLayoutNeeded(); |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3656 | mService.mWindowPlacerLocked.requestTraversal(); |
| 3657 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3658 | |
| 3659 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3660 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3661 | c.requestUpdateWallpaperIfNeeded(); |
| 3662 | } |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 3665 | float translateToWindowX(float x) { |
| 3666 | float winX = x - mFrame.left; |
| 3667 | if (mEnforceSizeCompat) { |
| 3668 | winX *= mGlobalScale; |
| 3669 | } |
| 3670 | return winX; |
| 3671 | } |
| 3672 | |
| 3673 | float translateToWindowY(float y) { |
| 3674 | float winY = y - mFrame.top; |
| 3675 | if (mEnforceSizeCompat) { |
| 3676 | winY *= mGlobalScale; |
| 3677 | } |
| 3678 | return winY; |
| 3679 | } |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3680 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3681 | private void transferDimToReplacement() { |
Robert Carr | 9fe459d | 2016-04-07 23:32:28 -0700 | [diff] [blame] | 3682 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3683 | final DisplayContent dc = getDisplayContent(); |
| 3684 | if (dimLayerUser != null && dc != null) { |
| 3685 | dc.mDimLayerController.applyDim(dimLayerUser, |
| 3686 | mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0); |
Robert Carr | 9fe459d | 2016-04-07 23:32:28 -0700 | [diff] [blame] | 3687 | } |
| 3688 | } |
| 3689 | |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3690 | // During activity relaunch due to resize, we sometimes use window replacement |
| 3691 | // for only child windows (as the main window is handled by window preservation) |
| 3692 | // and the big surface. |
| 3693 | // |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 3694 | // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to |
| 3695 | // TYPE_BASE_APPLICATION) are not children in the sense of an attached window, |
| 3696 | // we also want to replace them at such phases, as they won't be covered by window |
| 3697 | // preservation, and in general we expect them to return following relaunch. |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3698 | boolean shouldBeReplacedWithChildren() { |
Chong Zhang | 921f8e3 | 2016-08-17 14:26:57 -0700 | [diff] [blame] | 3699 | return mIsChildWindow || mAttrs.type == TYPE_APPLICATION |
Chong Zhang | fea963e | 2016-08-15 17:14:16 -0700 | [diff] [blame] | 3700 | || mAttrs.type == TYPE_DRAWN_APPLICATION; |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 3701 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3702 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3703 | void setWillReplaceChildWindows() { |
| 3704 | if (shouldBeReplacedWithChildren()) { |
| 3705 | setWillReplaceWindow(false /* animate */); |
| 3706 | } |
| 3707 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3708 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3709 | c.setWillReplaceChildWindows(); |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | WindowState getReplacingWindow() { |
| 3714 | if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) { |
| 3715 | return this; |
| 3716 | } |
| 3717 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3718 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3719 | final WindowState replacing = c.getReplacingWindow(); |
| 3720 | if (replacing != null) { |
| 3721 | return replacing; |
| 3722 | } |
| 3723 | } |
| 3724 | return null; |
| 3725 | } |
| 3726 | |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 3727 | public int getRotationAnimationHint() { |
| 3728 | if (mAppToken != null) { |
| 3729 | return mAppToken.mRotationAnimationHint; |
| 3730 | } else { |
| 3731 | return -1; |
| 3732 | } |
| 3733 | } |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3734 | |
| 3735 | // This must be called while inside a transaction. |
| 3736 | boolean performShowLocked() { |
| 3737 | if (isHiddenFromUserLocked()) { |
| 3738 | if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid); |
| 3739 | hideLw(false); |
| 3740 | return false; |
| 3741 | } |
| 3742 | |
| 3743 | logPerformShow("performShow on "); |
| 3744 | |
| 3745 | if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplayIgnoringKeyguard()) { |
| 3746 | return false; |
| 3747 | } |
| 3748 | |
| 3749 | logPerformShow("Showing "); |
| 3750 | |
| 3751 | mService.enableScreenIfNeededLocked(); |
| 3752 | mWinAnimator.applyEnterAnimationLocked(); |
| 3753 | |
| 3754 | // Force the show in the next prepareSurfaceLocked() call. |
| 3755 | mWinAnimator.mLastAlpha = -1; |
| 3756 | if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG, |
| 3757 | "performShowLocked: mDrawState=HAS_DRAWN in " + this); |
| 3758 | mWinAnimator.mDrawState = HAS_DRAWN; |
| 3759 | mService.scheduleAnimationLocked(); |
| 3760 | |
| 3761 | if (mHidden) { |
| 3762 | mHidden = false; |
| 3763 | final DisplayContent displayContent = getDisplayContent(); |
| 3764 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3765 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3766 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3767 | if (c.mWinAnimator.mSurfaceController != null) { |
| 3768 | c.performShowLocked(); |
| 3769 | // It hadn't been shown, which means layout not performed on it, so now we |
| 3770 | // want to make sure to do a layout. If called from within the transaction |
| 3771 | // loop, this will cause it to restart with a new layout. |
| 3772 | if (displayContent != null) { |
Wale Ogunwale | 2b06bfc | 2016-09-28 14:17:05 -0700 | [diff] [blame] | 3773 | displayContent.setLayoutNeeded(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) { |
| 3780 | mAppToken.onFirstWindowDrawn(this, mWinAnimator); |
| 3781 | } |
| 3782 | |
| 3783 | if (mAttrs.type == TYPE_INPUT_METHOD) { |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3784 | getDisplayContent().mDividerControllerLocked.resetImeHideRequested(); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | return true; |
| 3788 | } |
| 3789 | |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3790 | private void logPerformShow(String prefix) { |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3791 | if (DEBUG_VISIBILITY |
| 3792 | || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) { |
| 3793 | Slog.v(TAG, prefix + this |
| 3794 | + ": mDrawState=" + mWinAnimator.drawStateToString() |
| 3795 | + " readyForDisplay=" + isReadyForDisplayIgnoringKeyguard() |
| 3796 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING) |
| 3797 | + " during animation: policyVis=" + mPolicyVisibility |
| 3798 | + " parentHidden=" + isParentWindowHidden() |
| 3799 | + " tok.hiddenRequested=" |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3800 | + (mAppToken != null && mAppToken.hiddenRequested) |
| 3801 | + " tok.hidden=" + (mAppToken != null && mAppToken.hidden) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3802 | + " animating=" + mWinAnimator.mAnimating |
| 3803 | + " tok animating=" |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3804 | + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating) |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 3805 | + " Callers=" + Debug.getCallers(4)); |
| 3806 | } |
| 3807 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3808 | |
| 3809 | WindowInfo getWindowInfo() { |
| 3810 | WindowInfo windowInfo = WindowInfo.obtain(); |
| 3811 | windowInfo.type = mAttrs.type; |
| 3812 | windowInfo.layer = mLayer; |
| 3813 | windowInfo.token = mClient.asBinder(); |
| 3814 | windowInfo.title = mAttrs.accessibilityTitle; |
| 3815 | windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor; |
| 3816 | windowInfo.focused = isFocused(); |
| 3817 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3818 | if (mIsChildWindow) { |
| 3819 | windowInfo.parentToken = getParentWindow().mClient.asBinder(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3822 | final int childCount = mChildren.size(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3823 | if (childCount > 0) { |
| 3824 | if (windowInfo.childTokens == null) { |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3825 | windowInfo.childTokens = new ArrayList(childCount); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3826 | } |
| 3827 | for (int j = 0; j < childCount; j++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3828 | final WindowState child = mChildren.get(j); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3829 | windowInfo.childTokens.add(child.mClient.asBinder()); |
| 3830 | } |
| 3831 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3832 | return windowInfo; |
| 3833 | } |
| 3834 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3835 | int getHighestAnimLayer() { |
| 3836 | int highest = mWinAnimator.mAnimLayer; |
| 3837 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3838 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3839 | final int childLayer = c.getHighestAnimLayer(); |
| 3840 | if (childLayer > highest) { |
| 3841 | highest = childLayer; |
| 3842 | } |
| 3843 | } |
| 3844 | return highest; |
| 3845 | } |
| 3846 | |
| 3847 | int adjustAnimLayer(int adj) { |
| 3848 | int highestAnimLayer = mWinAnimator.mAnimLayer = mLayer + adj; |
| 3849 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG_WM, |
| 3850 | "adjustAnimLayer win=" + this + " anim layer: " + mWinAnimator.mAnimLayer); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3851 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3852 | final WindowState childWindow = mChildren.get(i); |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3853 | childWindow.adjustAnimLayer(adj); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3854 | if (childWindow.mWinAnimator.mAnimLayer > highestAnimLayer) { |
| 3855 | highestAnimLayer = childWindow.mWinAnimator.mAnimLayer; |
| 3856 | } |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3857 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3858 | return highestAnimLayer; |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3859 | } |
| 3860 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3861 | @Override |
Wale Ogunwale | 360a8bc | 2016-10-10 13:25:26 -0700 | [diff] [blame] | 3862 | int rebuildWindowList(int addIndex) { |
| 3863 | return reAddWindow(addIndex); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 3864 | } |
| 3865 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3866 | // TODO: come-up with a better name for this method that represents what it does. |
| 3867 | // Or, it is probably not going to matter anyways if we are successful in getting rid of |
| 3868 | // the WindowList concept. |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 3869 | int reAddWindow(int index) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3870 | final WindowList windows = getWindowList(); |
| 3871 | // Adding child windows relies on child windows being ordered by mSubLayer using |
| 3872 | // {@link #sWindowSubLayerComparator}. |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3873 | final int childCount = mChildren.size(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3874 | boolean winAdded = false; |
| 3875 | for (int j = 0; j < childCount; j++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3876 | final WindowState child = mChildren.get(j); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3877 | if (!winAdded && child.mSubLayer >= 0) { |
| 3878 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, |
| 3879 | "Re-adding child window at " + index + ": " + child); |
| 3880 | mRebuilding = false; |
| 3881 | windows.add(index, this); |
| 3882 | index++; |
| 3883 | winAdded = true; |
| 3884 | } |
| 3885 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + child); |
| 3886 | child.mRebuilding = false; |
| 3887 | windows.add(index, child); |
| 3888 | index++; |
| 3889 | } |
| 3890 | if (!winAdded) { |
| 3891 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + this); |
| 3892 | mRebuilding = false; |
| 3893 | windows.add(index, this); |
| 3894 | index++; |
| 3895 | } |
| 3896 | mService.mWindowsChanged = true; |
| 3897 | return index; |
| 3898 | } |
| 3899 | |
| 3900 | int removeFromWindowList(int interestingPos) { |
| 3901 | final WindowList windows = getWindowList(); |
| 3902 | int wpos = windows.indexOf(this); |
| 3903 | if (wpos < 0) { |
| 3904 | return interestingPos; |
| 3905 | } |
| 3906 | |
| 3907 | if (wpos < interestingPos) interestingPos--; |
| 3908 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this); |
| 3909 | windows.remove(wpos); |
| 3910 | mService.mWindowsChanged = true; |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3911 | int childCount = mChildren.size(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3912 | while (childCount > 0) { |
| 3913 | childCount--; |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3914 | final WindowState cw = mChildren.get(childCount); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3915 | int cpos = windows.indexOf(cw); |
| 3916 | if (cpos >= 0) { |
| 3917 | if (cpos < interestingPos) interestingPos--; |
| 3918 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, |
| 3919 | "Temp removing child at " + cpos + ": " + cw); |
| 3920 | windows.remove(cpos); |
| 3921 | } |
| 3922 | } |
| 3923 | return interestingPos; |
| 3924 | } |
| 3925 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3926 | boolean isWindowAnimationSet() { |
| 3927 | if (mWinAnimator.isWindowAnimationSet()) { |
| 3928 | return true; |
| 3929 | } |
| 3930 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3931 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 3932 | if (c.isWindowAnimationSet()) { |
| 3933 | return true; |
| 3934 | } |
| 3935 | } |
| 3936 | return false; |
| 3937 | } |
| 3938 | |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3939 | void onExitAnimationDone() { |
| 3940 | if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this |
| 3941 | + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit |
| 3942 | + " windowAnimating=" + mWinAnimator.isWindowAnimationSet()); |
| 3943 | |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3944 | if (!mChildren.isEmpty()) { |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3945 | // Copying to a different list as multiple children can be removed. |
Wale Ogunwale | e4343ef | 2016-07-19 08:00:46 -0700 | [diff] [blame] | 3946 | // TODO: Not sure if we really need to copy this into a different list. |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3947 | final LinkedList<WindowState> childWindows = new LinkedList(mChildren); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3948 | for (int i = childWindows.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 3949 | childWindows.get(i).onExitAnimationDone(); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | if (mWinAnimator.mEnteringAnimation) { |
| 3954 | mWinAnimator.mEnteringAnimation = false; |
| 3955 | mService.requestTraversal(); |
| 3956 | // System windows don't have an activity and an app token as a result, but need a way |
| 3957 | // to be informed about their entrance animation end. |
| 3958 | if (mAppToken == null) { |
| 3959 | try { |
| 3960 | mClient.dispatchWindowShown(); |
| 3961 | } catch (RemoteException e) { |
| 3962 | } |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | if (!mWinAnimator.isWindowAnimationSet()) { |
| 3967 | //TODO (multidisplay): Accessibility is supported only for the default display. |
| 3968 | if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) { |
| 3969 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | if (!mAnimatingExit) { |
| 3974 | return; |
| 3975 | } |
| 3976 | |
| 3977 | if (mWinAnimator.isWindowAnimationSet()) { |
| 3978 | return; |
| 3979 | } |
| 3980 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 3981 | if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 3982 | "Exit animation finished in " + this + ": remove=" + mRemoveOnExit); |
| 3983 | |
| 3984 | mDestroying = true; |
| 3985 | |
| 3986 | final boolean hasSurface = mWinAnimator.hasSurface(); |
| 3987 | if (hasSurface) { |
| 3988 | mWinAnimator.hide("onExitAnimationDone"); |
| 3989 | } |
| 3990 | |
| 3991 | // If we have an app token, we ask it to destroy the surface for us, so that it can take |
| 3992 | // care to ensure the activity has actually stopped and the surface is not still in use. |
| 3993 | // Otherwise we add the service to mDestroySurface and allow it to be processed in our next |
| 3994 | // transaction. |
| 3995 | if (mAppToken != null) { |
| 3996 | mAppToken.destroySurfaces(); |
| 3997 | } else { |
| 3998 | if (hasSurface) { |
| 3999 | mService.mDestroySurface.add(this); |
| 4000 | } |
| 4001 | if (mRemoveOnExit) { |
| 4002 | mService.mPendingRemove.add(this); |
| 4003 | mRemoveOnExit = false; |
| 4004 | } |
| 4005 | } |
| 4006 | mAnimatingExit = false; |
| 4007 | mService.mWallpaperControllerLocked.hideWallpapers(this); |
| 4008 | } |
Dan Willemsen | 117197f | 2016-07-30 13:02:59 -0700 | [diff] [blame] | 4009 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4010 | boolean clearAnimatingFlags() { |
| 4011 | boolean didSomething = false; |
| 4012 | // We don't want to clear it out for windows that get replaced, because the |
| 4013 | // animation depends on the flag to remove the replaced window. |
| 4014 | // |
| 4015 | // We also don't clear the mAnimatingExit flag for windows which have the |
| 4016 | // mRemoveOnExit flag. This indicates an explicit remove request has been issued |
| 4017 | // by the client. We should let animation proceed and not clear this flag or |
| 4018 | // they won't eventually be removed by WindowStateAnimator#finishExit. |
| 4019 | if (!mWillReplaceWindow && !mRemoveOnExit) { |
| 4020 | // Clear mAnimating flag together with mAnimatingExit. When animation |
| 4021 | // changes from exiting to entering, we need to clear this flag until the |
| 4022 | // new animation gets applied, so that isAnimationStarting() becomes true |
| 4023 | // until then. |
| 4024 | // Otherwise applySurfaceChangesTransaction will fail to skip surface |
| 4025 | // placement for this window during this period, one or more frame will |
| 4026 | // show up with wrong position or scale. |
| 4027 | if (mAnimatingExit) { |
| 4028 | mAnimatingExit = false; |
| 4029 | didSomething = true; |
| 4030 | } |
| 4031 | if (mWinAnimator.mAnimating) { |
| 4032 | mWinAnimator.mAnimating = false; |
| 4033 | didSomething = true; |
| 4034 | } |
| 4035 | if (mDestroying) { |
| 4036 | mDestroying = false; |
| 4037 | mService.mDestroySurface.remove(this); |
| 4038 | didSomething = true; |
| 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4043 | didSomething |= (mChildren.get(i)).clearAnimatingFlags(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | return didSomething; |
| 4047 | } |
| 4048 | |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4049 | public boolean isRtl() { |
Andrii Kulian | 9d91ca6 | 2016-09-29 22:28:09 -0700 | [diff] [blame] | 4050 | return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; |
Winson | 4b4ba90 | 2016-07-27 19:45:52 -0700 | [diff] [blame] | 4051 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4052 | |
| 4053 | void hideWallpaperWindow(boolean wasDeferred, String reason) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4054 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4055 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4056 | c.hideWallpaperWindow(wasDeferred, reason); |
| 4057 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 4058 | if (!mWinAnimator.mLastHidden || wasDeferred) { |
| 4059 | mWinAnimator.hide(reason); |
| 4060 | dispatchWallpaperVisibility(false); |
| 4061 | final DisplayContent displayContent = getDisplayContent(); |
| 4062 | if (displayContent != null) { |
| 4063 | displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 4064 | } |
| 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | /** |
| 4069 | * Check wallpaper window for visibility change and notify window if so. |
| 4070 | * @param visible Current visibility. |
| 4071 | */ |
| 4072 | void dispatchWallpaperVisibility(final boolean visible) { |
| 4073 | final boolean hideAllowed = |
| 4074 | mService.mWallpaperControllerLocked.mDeferredHideWallpaper == null; |
| 4075 | |
| 4076 | // Only send notification if the visibility actually changed and we are not trying to hide |
| 4077 | // the wallpaper when we are deferring hiding of the wallpaper. |
| 4078 | if (mWallpaperVisible != visible && (hideAllowed || visible)) { |
| 4079 | mWallpaperVisible = visible; |
| 4080 | try { |
| 4081 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, |
| 4082 | "Updating vis of wallpaper " + this |
| 4083 | + ": " + visible + " from:\n" + Debug.getCallers(4, " ")); |
| 4084 | mClient.dispatchAppVisibility(visible); |
| 4085 | } catch (RemoteException e) { |
| 4086 | } |
| 4087 | } |
| 4088 | } |
| 4089 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4090 | boolean hasVisibleNotDrawnWallpaper() { |
| 4091 | if (mWallpaperVisible && !isDrawnLw()) { |
| 4092 | return true; |
| 4093 | } |
| 4094 | for (int j = mChildren.size() - 1; j >= 0; --j) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4095 | final WindowState c = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4096 | if (c.hasVisibleNotDrawnWallpaper()) { |
| 4097 | return true; |
| 4098 | } |
| 4099 | } |
| 4100 | return false; |
| 4101 | } |
| 4102 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4103 | void updateReportedVisibility(UpdateReportedVisibilityResults results) { |
| 4104 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 4105 | final WindowState c = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 4106 | c.updateReportedVisibility(results); |
| 4107 | } |
| 4108 | |
| 4109 | if (mAppFreezing || mViewVisibility != View.VISIBLE |
| 4110 | || mAttrs.type == TYPE_APPLICATION_STARTING |
| 4111 | || mDestroying) { |
| 4112 | return; |
| 4113 | } |
| 4114 | if (DEBUG_VISIBILITY) { |
| 4115 | Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw() |
| 4116 | + ", isAnimationSet=" + mWinAnimator.isAnimationSet()); |
| 4117 | if (!isDrawnLw()) { |
| 4118 | Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController |
| 4119 | + " pv=" + mPolicyVisibility |
| 4120 | + " mDrawState=" + mWinAnimator.mDrawState |
| 4121 | + " ph=" + isParentWindowHidden() |
| 4122 | + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| 4123 | + " a=" + mWinAnimator.mAnimating); |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | results.numInteresting++; |
| 4128 | if (isDrawnLw()) { |
| 4129 | results.numDrawn++; |
| 4130 | if (!mWinAnimator.isAnimationSet()) { |
| 4131 | results.numVisible++; |
| 4132 | } |
| 4133 | results.nowGone = false; |
| 4134 | } else if (mWinAnimator.isAnimationSet()) { |
| 4135 | results.nowGone = false; |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | // TODO: Hack to work around the number of states AppWindowToken needs to access without having |
| 4140 | // access to its windows children. Need to investigate re-writing |
| 4141 | // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed. |
| 4142 | static final class UpdateReportedVisibilityResults { |
| 4143 | int numInteresting; |
| 4144 | int numVisible; |
| 4145 | int numDrawn; |
| 4146 | boolean nowGone = true; |
| 4147 | |
| 4148 | void reset() { |
| 4149 | numInteresting = 0; |
| 4150 | numVisible = 0; |
| 4151 | numDrawn = 0; |
| 4152 | nowGone = true; |
| 4153 | } |
| 4154 | } |
satok | cef37fb | 2011-10-24 21:49:38 +0900 | [diff] [blame] | 4155 | } |