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; |
| 28 | import android.os.IBinder; |
| 29 | import android.os.PowerManager; |
| 30 | import android.os.RemoteCallbackList; |
| 31 | import android.os.RemoteException; |
| 32 | import android.os.SystemClock; |
| 33 | import android.os.Trace; |
| 34 | import android.os.UserHandle; |
| 35 | import android.os.WorkSource; |
| 36 | import android.util.DisplayMetrics; |
| 37 | import android.util.Slog; |
| 38 | import android.util.TimeUtils; |
| 39 | import android.view.Display; |
| 40 | import android.view.DisplayInfo; |
| 41 | import android.view.Gravity; |
| 42 | import android.view.IApplicationToken; |
| 43 | import android.view.IWindow; |
| 44 | import android.view.IWindowFocusObserver; |
| 45 | import android.view.IWindowId; |
| 46 | import android.view.InputChannel; |
| 47 | import android.view.InputEvent; |
| 48 | import android.view.InputEventReceiver; |
| 49 | import android.view.View; |
| 50 | import android.view.ViewTreeObserver; |
| 51 | import android.view.WindowManager; |
| 52 | import android.view.WindowManagerPolicy; |
| 53 | |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 54 | import com.android.server.input.InputWindowHandle; |
| 55 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 56 | import java.io.PrintWriter; |
| 57 | import java.util.ArrayList; |
| 58 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 59 | import static android.app.ActivityManager.StackId; |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 60 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 61 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 62 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 63 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT; |
| 64 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 65 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION; |
| 66 | import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 67 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 68 | import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 69 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 70 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 71 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 72 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 73 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 74 | import static android.view.WindowManager.LayoutParams.FLAG_SCALED; |
Wale Ogunwale | 945d197 | 2016-03-23 13:16:41 -0700 | [diff] [blame] | 75 | import static android.view.WindowManager.LayoutParams.FLAG_SECURE; |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 76 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 77 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 78 | import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 79 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 80 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 81 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 82 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 83 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 84 | 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] | 85 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 86 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 87 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 88 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 89 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 90 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 91 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 92 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 93 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 94 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 95 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 96 | import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 97 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 98 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 99 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
| 100 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION; |
| 101 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
| 102 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT; |
| 103 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
| 104 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER; |
| 105 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE; |
| 106 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 107 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 108 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 109 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 110 | class WindowList extends ArrayList<WindowState> { |
Wale Ogunwale | 33fde7d | 2016-03-05 22:38:51 -0800 | [diff] [blame] | 111 | WindowList() {} |
| 112 | WindowList(WindowList windowList) { |
| 113 | super(windowList); |
| 114 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 117 | /** |
| 118 | * A window in the window manager. |
| 119 | */ |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 120 | final class WindowState implements WindowManagerPolicy.WindowState { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 121 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 122 | |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 123 | // 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] | 124 | // TODO(multi-window): fix the min sizes when we have mininum width/height support, |
| 125 | // use hard-coded min sizes for now. |
| 126 | static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48; |
| 127 | static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 128 | |
| 129 | // The thickness of a window resize handle outside the window bounds on the free form workspace |
| 130 | // to capture touch events in that area. |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 131 | static final int RESIZE_HANDLE_WIDTH_IN_DP = 30; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 132 | |
Robert Carr | 7098dbd | 2016-02-01 12:31:01 -0800 | [diff] [blame] | 133 | static final boolean DEBUG_DISABLE_SAVING_SURFACES = false; |
| 134 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 135 | final WindowManagerService mService; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 136 | final WindowManagerPolicy mPolicy; |
| 137 | final Context mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 138 | final Session mSession; |
| 139 | final IWindow mClient; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 140 | final int mAppOp; |
| 141 | // UserId and appId of the owner. Don't display windows of non-current user. |
| 142 | final int mOwnerUid; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 143 | final IWindowId mWindowId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 144 | WindowToken mToken; |
| 145 | WindowToken mRootToken; |
| 146 | AppWindowToken mAppToken; |
| 147 | AppWindowToken mTargetAppToken; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 148 | |
| 149 | // mAttrs.flags is tested in animation without being locked. If the bits tested are ever |
| 150 | // modified they will need to be locked. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 151 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 152 | final DeathRecipient mDeathRecipient; |
| 153 | final WindowState mAttachedWindow; |
Craig Mautner | 7b1aa77 | 2012-11-30 16:14:45 -0800 | [diff] [blame] | 154 | final WindowList mChildWindows = new WindowList(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 155 | final int mBaseLayer; |
| 156 | final int mSubLayer; |
| 157 | final boolean mLayoutAttached; |
| 158 | final boolean mIsImWindow; |
| 159 | final boolean mIsWallpaper; |
| 160 | final boolean mIsFloatingLayer; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 161 | int mSeq; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 162 | boolean mEnforceSizeCompat; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 163 | int mViewVisibility; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 164 | int mSystemUiVisibility; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 165 | boolean mPolicyVisibility = true; |
| 166 | boolean mPolicyVisibilityAfterAnim = true; |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 167 | boolean mAppOpVisibility = true; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 168 | boolean mAppFreezing; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 169 | boolean mAttachedHidden; // is our parent window hidden? |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 170 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 171 | boolean mDragResizing; |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 172 | boolean mDragResizingChangeReported; |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 173 | int mResizeMode; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 174 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 175 | RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks; |
| 176 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 177 | /** |
| 178 | * The window size that was requested by the application. These are in |
| 179 | * the application's coordinate space (without compatibility scale applied). |
| 180 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 181 | int mRequestedWidth; |
| 182 | int mRequestedHeight; |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 183 | int mLastRequestedWidth; |
| 184 | int mLastRequestedHeight; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 185 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 186 | int mLayer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 187 | boolean mHaveFrame; |
| 188 | boolean mObscured; |
| 189 | boolean mTurnOnScreen; |
| 190 | |
| 191 | int mLayoutSeq = -1; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 192 | |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 193 | private final Configuration mTmpConfig = new Configuration(); |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 194 | // Represents the changes from our override configuration applied |
| 195 | // to the global configuration. This is the only form of configuration |
| 196 | // which is suitable for delivery to the client. |
| 197 | private Configuration mMergedConfiguration = new Configuration(); |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 198 | // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned. |
| 199 | // Used only on {@link #TYPE_KEYGUARD}. |
| 200 | private boolean mConfigHasChanged; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 201 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 202 | /** |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 203 | * Actual position of the surface shown on-screen (may be modified by animation). These are |
| 204 | * in the screen's coordinate space (WITH the compatibility scale applied). |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 205 | */ |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 206 | final Point mShownPosition = new Point(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 207 | |
| 208 | /** |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 209 | * Insets that determine the actually visible area. These are in the application's |
| 210 | * coordinate space (without compatibility scale applied). |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 211 | */ |
| 212 | final Rect mVisibleInsets = new Rect(); |
| 213 | final Rect mLastVisibleInsets = new Rect(); |
| 214 | boolean mVisibleInsetsChanged; |
| 215 | |
| 216 | /** |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 217 | * Insets that are covered by system windows (such as the status bar) and |
| 218 | * 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] | 219 | * coordinate space (without compatibility scale applied). |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 220 | */ |
| 221 | final Rect mContentInsets = new Rect(); |
| 222 | final Rect mLastContentInsets = new Rect(); |
| 223 | boolean mContentInsetsChanged; |
| 224 | |
| 225 | /** |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 226 | * Insets that determine the area covered by the display overscan region. These are in the |
| 227 | * application's coordinate space (without compatibility scale applied). |
| 228 | */ |
| 229 | final Rect mOverscanInsets = new Rect(); |
| 230 | final Rect mLastOverscanInsets = new Rect(); |
| 231 | boolean mOverscanInsetsChanged; |
| 232 | |
| 233 | /** |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 234 | * Insets that determine the area covered by the stable system windows. These are in the |
| 235 | * application's coordinate space (without compatibility scale applied). |
| 236 | */ |
| 237 | final Rect mStableInsets = new Rect(); |
| 238 | final Rect mLastStableInsets = new Rect(); |
| 239 | boolean mStableInsetsChanged; |
| 240 | |
| 241 | /** |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 242 | * Outsets determine the area outside of the surface where we want to pretend that it's possible |
| 243 | * to draw anyway. |
| 244 | */ |
| 245 | final Rect mOutsets = new Rect(); |
| 246 | final Rect mLastOutsets = new Rect(); |
| 247 | boolean mOutsetsChanged = false; |
| 248 | |
| 249 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 250 | * Set to true if we are waiting for this window to receive its |
| 251 | * given internal insets before laying out other windows based on it. |
| 252 | */ |
| 253 | boolean mGivenInsetsPending; |
| 254 | |
| 255 | /** |
| 256 | * These are the content insets that were given during layout for |
| 257 | * this window, to be applied to windows behind it. |
| 258 | */ |
| 259 | final Rect mGivenContentInsets = new Rect(); |
| 260 | |
| 261 | /** |
| 262 | * These are the visible insets that were given during layout for |
| 263 | * this window, to be applied to windows behind it. |
| 264 | */ |
| 265 | final Rect mGivenVisibleInsets = new Rect(); |
| 266 | |
| 267 | /** |
| 268 | * This is the given touchable area relative to the window frame, or null if none. |
| 269 | */ |
| 270 | final Region mGivenTouchableRegion = new Region(); |
| 271 | |
| 272 | /** |
| 273 | * Flag indicating whether the touchable region should be adjusted by |
| 274 | * the visible insets; if false the area outside the visible insets is |
| 275 | * NOT touchable, so we must use those to adjust the frame during hit |
| 276 | * tests. |
| 277 | */ |
| 278 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| 279 | |
| 280 | // Current transformation being applied. |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 281 | float mGlobalScale=1; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 282 | float mInvGlobalScale=1; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 283 | float mHScale=1, mVScale=1; |
| 284 | float mLastHScale=1, mLastVScale=1; |
| 285 | final Matrix mTmpMatrix = new Matrix(); |
| 286 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 287 | // "Real" frame that the application sees, in display coordinate space. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 288 | final Rect mFrame = new Rect(); |
| 289 | final Rect mLastFrame = new Rect(); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 290 | // Frame that is scaled to the application's coordinate space when in |
| 291 | // screen size compatibility mode. |
| 292 | final Rect mCompatFrame = new Rect(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 293 | |
| 294 | final Rect mContainingFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 295 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 296 | final Rect mParentFrame = new Rect(); |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 297 | |
Wale Ogunwale | 9459665 | 2015-02-06 19:27:34 -0800 | [diff] [blame] | 298 | // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the |
| 299 | // screen area of the device. |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 300 | final Rect mDisplayFrame = new Rect(); |
| 301 | |
| 302 | // The region of the display frame that the display type supports displaying content on. This |
| 303 | // is mostly a special case for TV where some displays don’t have the entire display usable. |
| 304 | // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow |
| 305 | // window display contents to extend into the overscan region. |
| 306 | final Rect mOverscanFrame = new Rect(); |
| 307 | |
| 308 | // The display frame minus the stable insets. This value is always constant regardless of if |
| 309 | // the status bar or navigation bar is visible. |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 310 | final Rect mStableFrame = new Rect(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 311 | |
Wale Ogunwale | c6061fa | 2014-10-21 13:15:11 -0700 | [diff] [blame] | 312 | // The area not occupied by the status and navigation bars. So, if both status and navigation |
| 313 | // bars are visible, the decor frame is equal to the stable frame. |
| 314 | final Rect mDecorFrame = new Rect(); |
| 315 | |
| 316 | // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame |
| 317 | // minus the area occupied by the IME if the IME is present. |
| 318 | final Rect mContentFrame = new Rect(); |
| 319 | |
| 320 | // Legacy stuff. Generally equal to the content frame expect when the IME for older apps |
| 321 | // displays hint text. |
| 322 | final Rect mVisibleFrame = new Rect(); |
| 323 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 324 | // Frame that includes dead area outside of the surface but where we want to pretend that it's |
| 325 | // possible to draw. |
| 326 | final Rect mOutsetFrame = new Rect(); |
| 327 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 328 | /** |
| 329 | * Usually empty. Set to the task's tempInsetFrame. See |
| 330 | *{@link android.app.IActivityManager#resizeDockedStack}. |
| 331 | */ |
| 332 | final Rect mInsetFrame = new Rect(); |
| 333 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 334 | private static final Rect sTmpRect = new Rect(); |
| 335 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 336 | boolean mContentChanged; |
| 337 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 338 | // If a window showing a wallpaper: the requested offset for the |
| 339 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 340 | float mWallpaperX = -1; |
| 341 | float mWallpaperY = -1; |
| 342 | |
| 343 | // If a window showing a wallpaper: what fraction of the offset |
| 344 | // range corresponds to a full virtual screen. |
| 345 | float mWallpaperXStep = -1; |
| 346 | float mWallpaperYStep = -1; |
| 347 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 348 | // If a window showing a wallpaper: a raw pixel offset to forcibly apply |
| 349 | // to its window; if a wallpaper window: not used. |
| 350 | int mWallpaperDisplayOffsetX = Integer.MIN_VALUE; |
| 351 | int mWallpaperDisplayOffsetY = Integer.MIN_VALUE; |
| 352 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 353 | // Wallpaper windows: pixels offset based on above variables. |
| 354 | int mXOffset; |
| 355 | int mYOffset; |
| 356 | |
Craig Mautner | 2268e7e | 2012-12-13 15:40:00 -0800 | [diff] [blame] | 357 | /** |
| 358 | * This is set after IWindowSession.relayout() has been called at |
| 359 | * least once for the window. It allows us to detect the situation |
| 360 | * where we don't yet have a surface, but should have one soon, so |
| 361 | * we can give the window focus before waiting for the relayout. |
| 362 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 363 | boolean mRelayoutCalled; |
| 364 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 365 | boolean mInRelayout; |
| 366 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 367 | /** |
| 368 | * If the application has called relayout() with changes that can |
| 369 | * impact its window's size, we need to perform a layout pass on it |
| 370 | * even if it is not currently visible for layout. This is set |
| 371 | * when in that case until the layout is done. |
| 372 | */ |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 373 | boolean mLayoutNeeded; |
| 374 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 375 | /** Currently running an exit animation? */ |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 376 | boolean mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 377 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 378 | /** Currently on the mDestroySurface list? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 379 | boolean mDestroying; |
| 380 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 381 | /** Completely remove from window manager after exit animation? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 382 | boolean mRemoveOnExit; |
| 383 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 384 | /** |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 385 | * Whether the app died while it was visible, if true we might need |
| 386 | * to continue to show it until it's restarted. |
| 387 | */ |
| 388 | boolean mAppDied; |
| 389 | |
| 390 | /** |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 391 | * Set when the orientation is changing and this window has not yet |
| 392 | * been updated for the new orientation. |
| 393 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 394 | boolean mOrientationChanging; |
| 395 | |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 396 | /** |
| 397 | * How long we last kept the screen frozen. |
| 398 | */ |
| 399 | int mLastFreezeDuration; |
| 400 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 401 | /** Is this window now (or just being) removed? */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 402 | boolean mRemoved; |
| 403 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 404 | /** |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 405 | * It is save to remove the window and destroy the surface because the client requested removal |
| 406 | * or some other higher level component said so (e.g. activity manager). |
| 407 | * 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] | 408 | */ |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 409 | boolean mWindowRemovalAllowed; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 410 | |
| 411 | /** |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 412 | * Temp for keeping track of windows that have been removed when |
| 413 | * rebuilding window list. |
| 414 | */ |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 415 | boolean mRebuilding; |
| 416 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 417 | // Input channel and input window handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 418 | final InputWindowHandle mInputWindowHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 419 | InputChannel mInputChannel; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 420 | InputChannel mClientChannel; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 421 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 422 | // Used to improve performance of toString() |
| 423 | String mStringNameCache; |
| 424 | CharSequence mLastTitle; |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 425 | boolean mWasExiting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 426 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 427 | final WindowStateAnimator mWinAnimator; |
| 428 | |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 429 | boolean mHasSurface = false; |
| 430 | |
Craig Mautner | 19ab828 | 2014-05-07 10:35:34 -0700 | [diff] [blame] | 431 | boolean mNotOnAppsDisplay = false; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 432 | DisplayContent mDisplayContent; |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 433 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 434 | /** When true this window can be displayed on screens owther than mOwnerUid's */ |
| 435 | private boolean mShowToOwnerOnly; |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 436 | |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 437 | // Whether the window has a saved surface from last pause, which can be |
| 438 | // used to start an entering animation earlier. |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 439 | private boolean mSurfaceSaved = false; |
| 440 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 441 | // Whether we're performing an entering animation with a saved surface. This flag is |
| 442 | // true during the time we're showing a window with a previously saved surface. It's |
| 443 | // cleared when surface is destroyed, saved, or re-drawn by the app. |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 444 | private boolean mAnimatingWithSavedSurface; |
| 445 | |
| 446 | // Whether the window was visible when we set the app to invisible last time. WM uses |
| 447 | // this as a hint to restore the surface (if available) for early animation next time |
| 448 | // the app is brought visible. |
| 449 | boolean mWasVisibleBeforeClientHidden; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 450 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 451 | // This window will be replaced due to relaunch. This allows window manager |
| 452 | // to differentiate between simple removal of a window and replacement. In the latter case it |
| 453 | // will preserve the old window until the new one is drawn. |
| 454 | boolean mWillReplaceWindow = false; |
| 455 | // If true, the replaced window was already requested to be removed. |
| 456 | boolean mReplacingRemoveRequested = false; |
| 457 | // Whether the replacement of the window should trigger app transition animation. |
| 458 | boolean mAnimateReplacingWindow = false; |
| 459 | // If not null, the window that will be used to replace the old one. This is being set when |
| 460 | // the window is added and unset when this window reports its first draw. |
| 461 | WindowState mReplacingWindow = null; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 462 | // For the new window in the replacement transition, if we have |
| 463 | // requested to replace without animation, then we should |
| 464 | // make sure we also don't apply an enter animation for |
| 465 | // the new window. |
| 466 | boolean mSkipEnterAnimationForSeamlessReplacement = false; |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 467 | // Whether this window is being moved via the resize API |
| 468 | boolean mMovedByResize; |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 469 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 470 | /** |
| 471 | * Wake lock for drawing. |
| 472 | * Even though it's slightly more expensive to do so, we will use a separate wake lock |
| 473 | * for each app that is requesting to draw while dozing so that we can accurately track |
| 474 | * who is preventing the system from suspending. |
| 475 | * This lock is only acquired on first use. |
| 476 | */ |
| 477 | PowerManager.WakeLock mDrawLock; |
| 478 | |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 479 | final private Rect mTmpRect = new Rect(); |
| 480 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 481 | /** |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 482 | * See {@link #notifyMovedInStack}. |
| 483 | */ |
| 484 | private boolean mJustMovedInStack; |
| 485 | |
| 486 | /** |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 487 | * Whether the window was resized by us while it was gone for layout. |
| 488 | */ |
| 489 | boolean mResizedWhileGone = false; |
| 490 | |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 491 | /** @see #isResizedWhileNotDragResizing(). */ |
| 492 | private boolean mResizedWhileNotDragResizing; |
| 493 | |
| 494 | /** @see #isResizedWhileNotDragResizingReported(). */ |
| 495 | private boolean mResizedWhileNotDragResizingReported; |
Jorim Jaggi | f3df0aa | 2016-04-06 15:56:33 -0700 | [diff] [blame] | 496 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame^] | 497 | /** |
| 498 | * During seamless rotation we have two phases, first the old window contents |
| 499 | * are rotated to look as if they didn't move in the new coordinate system. Then we |
| 500 | * have to freeze updates to this layer (to preserve the transformation) until |
| 501 | * the resize actually occurs. This is true from when the transformation is set |
| 502 | * and false until the transaction to resize is sent. |
| 503 | */ |
| 504 | boolean mSeamlesslyRotated = false; |
| 505 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 506 | WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 507 | WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a, |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 508 | int viewVisibility, final DisplayContent displayContent) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 509 | mService = service; |
| 510 | mSession = s; |
| 511 | mClient = c; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 512 | mAppOp = appOp; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 513 | mToken = token; |
Craig Mautner | a2d7b11 | 2012-08-21 15:12:20 -0700 | [diff] [blame] | 514 | mOwnerUid = s.mUid; |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 515 | mWindowId = new IWindowId.Stub() { |
| 516 | @Override |
| 517 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 518 | WindowState.this.registerFocusObserver(observer); |
| 519 | } |
| 520 | @Override |
| 521 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 522 | WindowState.this.unregisterFocusObserver(observer); |
| 523 | } |
| 524 | @Override |
| 525 | public boolean isFocused() { |
| 526 | return WindowState.this.isFocused(); |
| 527 | } |
| 528 | }; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 529 | mAttrs.copyFrom(a); |
| 530 | mViewVisibility = viewVisibility; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 531 | mDisplayContent = displayContent; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 532 | mPolicy = mService.mPolicy; |
| 533 | mContext = mService.mContext; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 534 | DeathRecipient deathRecipient = new DeathRecipient(); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 535 | mSeq = seq; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 536 | mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 537 | if (WindowManagerService.localLOGV) Slog.v( |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 538 | TAG, "Window " + this + " client=" + c.asBinder() |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 539 | + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 540 | try { |
| 541 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 542 | } catch (RemoteException e) { |
| 543 | mDeathRecipient = null; |
| 544 | mAttachedWindow = null; |
| 545 | mLayoutAttached = false; |
| 546 | mIsImWindow = false; |
| 547 | mIsWallpaper = false; |
| 548 | mIsFloatingLayer = false; |
| 549 | mBaseLayer = 0; |
| 550 | mSubLayer = 0; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 551 | mInputWindowHandle = null; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 552 | mWinAnimator = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 553 | return; |
| 554 | } |
| 555 | mDeathRecipient = deathRecipient; |
| 556 | |
| 557 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 558 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 559 | // The multiplier here is to reserve space for multiple |
| 560 | // windows in the same type layer. |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 561 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 562 | attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 563 | + WindowManagerService.TYPE_LAYER_OFFSET; |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 564 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 565 | mAttachedWindow = attachedWindow; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 566 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow); |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 567 | |
tiger_huang | e2a98a7 | 2014-11-13 19:46:28 +0800 | [diff] [blame] | 568 | final WindowList childWindows = mAttachedWindow.mChildWindows; |
| 569 | final int numChildWindows = childWindows.size(); |
| 570 | if (numChildWindows == 0) { |
| 571 | childWindows.add(this); |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 572 | } else { |
tiger_huang | e2a98a7 | 2014-11-13 19:46:28 +0800 | [diff] [blame] | 573 | boolean added = false; |
| 574 | for (int i = 0; i < numChildWindows; i++) { |
| 575 | final int childSubLayer = childWindows.get(i).mSubLayer; |
| 576 | if (mSubLayer < childSubLayer |
| 577 | || (mSubLayer == childSubLayer && childSubLayer < 0)) { |
| 578 | // We insert the child window into the list ordered by the sub-layer. For |
| 579 | // same sub-layers, the negative one should go below others; the positive |
| 580 | // one should go above others. |
| 581 | childWindows.add(i, this); |
| 582 | added = true; |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 583 | break; |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 584 | } |
| 585 | } |
tiger_huang | e2a98a7 | 2014-11-13 19:46:28 +0800 | [diff] [blame] | 586 | if (!added) { |
| 587 | childWindows.add(this); |
takeda.masayuki | 1873509 | 2012-12-12 11:06:24 +0900 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 591 | mLayoutAttached = mAttrs.type != |
| 592 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 593 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 594 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 595 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 596 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| 597 | } else { |
| 598 | // The multiplier here is to reserve space for multiple |
| 599 | // windows in the same type layer. |
Craig Mautner | e7ae250 | 2012-03-26 17:11:19 -0700 | [diff] [blame] | 600 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 601 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 602 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 603 | mSubLayer = 0; |
| 604 | mAttachedWindow = null; |
| 605 | mLayoutAttached = false; |
| 606 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 607 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| 608 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 609 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| 610 | } |
| 611 | |
| 612 | WindowState appWin = this; |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 613 | while (appWin.isChildWindow()) { |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 614 | appWin = appWin.mAttachedWindow; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 615 | } |
| 616 | WindowToken appToken = appWin.mToken; |
| 617 | while (appToken.appWindowToken == null) { |
| 618 | WindowToken parent = mService.mTokenMap.get(appToken.token); |
| 619 | if (parent == null || appToken == parent) { |
| 620 | break; |
| 621 | } |
| 622 | appToken = parent; |
| 623 | } |
| 624 | mRootToken = appToken; |
| 625 | mAppToken = appToken.appWindowToken; |
Craig Mautner | 19ab828 | 2014-05-07 10:35:34 -0700 | [diff] [blame] | 626 | if (mAppToken != null) { |
| 627 | final DisplayContent appDisplay = getDisplayContent(); |
| 628 | mNotOnAppsDisplay = displayContent != appDisplay; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 629 | |
| 630 | if (mAppToken.showForAllUsers) { |
| 631 | // Windows for apps that can show for all users should also show when the |
| 632 | // device is locked. |
| 633 | mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED; |
| 634 | } |
Craig Mautner | 19ab828 | 2014-05-07 10:35:34 -0700 | [diff] [blame] | 635 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 636 | |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 637 | mWinAnimator = new WindowStateAnimator(this); |
| 638 | mWinAnimator.mAlpha = a.alpha; |
| 639 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 640 | mRequestedWidth = 0; |
| 641 | mRequestedHeight = 0; |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 642 | mLastRequestedWidth = 0; |
| 643 | mLastRequestedHeight = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 644 | mXOffset = 0; |
| 645 | mYOffset = 0; |
| 646 | mLayer = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 647 | mInputWindowHandle = new InputWindowHandle( |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 648 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, |
| 649 | displayContent.getDisplayId()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void attach() { |
| 653 | if (WindowManagerService.localLOGV) Slog.v( |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 654 | TAG, "Attaching " + this + " token=" + mToken |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 655 | + ", list=" + mToken.windows); |
| 656 | mSession.windowAddedLocked(); |
| 657 | } |
| 658 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 659 | @Override |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 660 | public int getOwningUid() { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 661 | return mOwnerUid; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public String getOwningPackage() { |
| 666 | return mAttrs.packageName; |
| 667 | } |
| 668 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 669 | /** |
| 670 | * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame} |
| 671 | * from {@param frame}. In other words, it applies the insets that would result if |
| 672 | * {@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] | 673 | * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum |
| 674 | * width/height applied and insets should be overridden. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 675 | */ |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 676 | private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) { |
| 677 | final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left)); |
| 678 | final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top)); |
| 679 | final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right); |
| 680 | 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] | 681 | frame.inset(left, top, right, bottom); |
| 682 | } |
| 683 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 684 | @Override |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 685 | public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf, |
| 686 | Rect osf) { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 687 | if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 688 | // This window is being replaced and either already got information that it's being |
| 689 | // removed or we are still waiting for some information. Because of this we don't |
| 690 | // want to apply any more changes to it, so it remains in this state until new window |
| 691 | // appears. |
| 692 | return; |
| 693 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 694 | mHaveFrame = true; |
| 695 | |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 696 | final Task task = getTask(); |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 697 | final boolean fullscreenTask = !isInMultiWindowMode(); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 698 | final boolean windowsAreFloating = task != null && task.isFloating(); |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 699 | |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 700 | // If the task has temp inset bounds set, we have to make sure all its windows uses |
| 701 | // the temp inset frame. Otherwise different display frames get applied to the main |
| 702 | // window and the child window, making them misaligned. |
| 703 | if (fullscreenTask) { |
| 704 | mInsetFrame.setEmpty(); |
| 705 | } else { |
| 706 | task.getTempInsetBounds(mInsetFrame); |
| 707 | } |
| 708 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 709 | // Denotes the actual frame used to calculate the insets and to perform the layout. When |
| 710 | // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the |
| 711 | // insets temporarily. By the notion of a task having a different layout frame, we can |
| 712 | // achieve that while still moving the task around. |
| 713 | final Rect layoutContainingFrame; |
| 714 | final Rect layoutDisplayFrame; |
| 715 | |
| 716 | // The offset from the layout containing frame to the actual containing frame. |
| 717 | final int layoutXDiff; |
| 718 | final int layoutYDiff; |
Wale Ogunwale | 7cd4b01 | 2016-05-07 12:41:22 -0700 | [diff] [blame] | 719 | if (fullscreenTask || layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 720 | // We use the parent frame as the containing frame for fullscreen and child windows |
| 721 | mContainingFrame.set(pf); |
| 722 | mDisplayFrame.set(df); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 723 | layoutDisplayFrame = df; |
| 724 | layoutContainingFrame = pf; |
| 725 | layoutXDiff = 0; |
| 726 | layoutYDiff = 0; |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 727 | } else { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 728 | task.getBounds(mContainingFrame); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 729 | if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) { |
| 730 | |
| 731 | // If the bounds are frozen, we still want to translate the window freely and only |
| 732 | // freeze the size. |
| 733 | Rect frozen = mAppToken.mFrozenBounds.peek(); |
| 734 | mContainingFrame.right = mContainingFrame.left + frozen.width(); |
| 735 | mContainingFrame.bottom = mContainingFrame.top + frozen.height(); |
| 736 | } |
Wale Ogunwale | f9c8149 | 2015-02-25 18:06:17 -0800 | [diff] [blame] | 737 | final WindowState imeWin = mService.mInputMethodWindow; |
Robert Carr | fc03b2b | 2016-03-31 15:22:02 -0700 | [diff] [blame] | 738 | // IME is up and obscuring this window. Adjust the window position so it is visible. |
| 739 | if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) { |
| 740 | if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) { |
| 741 | // In freeform we want to move the top up directly. |
| 742 | // TODO: Investigate why this is cf not pf. |
| 743 | mContainingFrame.top -= mContainingFrame.bottom - cf.bottom; |
| 744 | } else if (mContainingFrame.bottom > pf.bottom) { |
| 745 | // But in docked we want to behave like fullscreen |
| 746 | // and behave as if the task were given smaller bounds |
| 747 | // for the purposes of layout. |
| 748 | mContainingFrame.bottom = pf.bottom; |
| 749 | } |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 750 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 751 | |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 752 | if (windowsAreFloating) { |
Chong Zhang | 65d15d0 | 2016-03-14 13:59:32 -0700 | [diff] [blame] | 753 | // In floating modes (e.g. freeform, pinned) we have only to set the rectangle |
| 754 | // 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] | 755 | // "content frame" since it is allowed to be outside the visible desktop. |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 756 | if (mContainingFrame.isEmpty()) { |
| 757 | mContainingFrame.set(cf); |
| 758 | } |
Doris Liu | 06d582d | 2015-06-01 13:18:43 -0700 | [diff] [blame] | 759 | } |
Wale Ogunwale | 9459665 | 2015-02-06 19:27:34 -0800 | [diff] [blame] | 760 | mDisplayFrame.set(mContainingFrame); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 761 | layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0; |
| 762 | layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0; |
| 763 | layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame; |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 764 | mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth, |
| 765 | mDisplayContent.getDisplayInfo().logicalHeight); |
| 766 | subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 767 | if (!layoutInParentFrame()) { |
Andrii Kulian | daea357 | 2016-04-08 13:20:51 -0700 | [diff] [blame] | 768 | subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect); |
| 769 | subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect); |
Robert Carr | fd2bd1b | 2016-04-07 13:52:43 -0700 | [diff] [blame] | 770 | } |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 771 | layoutDisplayFrame = df; |
| 772 | layoutDisplayFrame.intersect(layoutContainingFrame); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 773 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 774 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 775 | final int pw = mContainingFrame.width(); |
| 776 | final int ph = mContainingFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 777 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 778 | if (!mParentFrame.equals(pf)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 779 | //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 780 | // + " to " + pf); |
| 781 | mParentFrame.set(pf); |
| 782 | mContentChanged = true; |
| 783 | } |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 784 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 785 | mLastRequestedWidth = mRequestedWidth; |
| 786 | mLastRequestedHeight = mRequestedHeight; |
| 787 | mContentChanged = true; |
| 788 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 789 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 790 | mOverscanFrame.set(of); |
| 791 | mContentFrame.set(cf); |
| 792 | mVisibleFrame.set(vf); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 793 | mDecorFrame.set(dcf); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 794 | mStableFrame.set(sf); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 795 | final boolean hasOutsets = osf != null; |
| 796 | if (hasOutsets) { |
| 797 | mOutsetFrame.set(osf); |
| 798 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 799 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 800 | final int fw = mFrame.width(); |
| 801 | final int fh = mFrame.height(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 802 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 803 | applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame); |
| 804 | |
Filip Gruszczynski | aaf1811 | 2015-06-05 13:37:40 -0700 | [diff] [blame] | 805 | // Calculate the outsets before the content frame gets shrinked to the window frame. |
| 806 | if (hasOutsets) { |
| 807 | mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0), |
| 808 | Math.max(mContentFrame.top - mOutsetFrame.top, 0), |
| 809 | Math.max(mOutsetFrame.right - mContentFrame.right, 0), |
| 810 | Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0)); |
| 811 | } else { |
| 812 | mOutsets.set(0, 0, 0, 0); |
| 813 | } |
| 814 | |
Craig Mautner | a248eee | 2013-05-07 11:41:27 -0700 | [diff] [blame] | 815 | // Make sure the content and visible frames are inside of the |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 816 | // final window frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 817 | if (windowsAreFloating && !mFrame.isEmpty()) { |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 818 | // Keep the frame out of the blocked system area, limit it in size to the content area |
| 819 | // and make sure that there is always a minimum visible so that the user can drag it |
| 820 | // into a usable area.. |
| 821 | final int height = Math.min(mFrame.height(), mContentFrame.height()); |
| 822 | final int width = Math.min(mContentFrame.width(), mFrame.width()); |
Wale Ogunwale | 231b06e | 2015-09-16 12:03:09 -0700 | [diff] [blame] | 823 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 824 | final int minVisibleHeight = WindowManagerService.dipToPixel( |
| 825 | MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics); |
| 826 | final int minVisibleWidth = WindowManagerService.dipToPixel( |
| 827 | MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 828 | final int top = Math.max(mContentFrame.top, |
| 829 | Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight)); |
| 830 | final int left = Math.max(mContentFrame.left + minVisibleWidth - width, |
| 831 | Math.min(mFrame.left, mContentFrame.right - minVisibleWidth)); |
| 832 | mFrame.set(left, top, left + width, top + height); |
| 833 | mContentFrame.set(mFrame); |
| 834 | mVisibleFrame.set(mContentFrame); |
| 835 | mStableFrame.set(mContentFrame); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 836 | } else if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 837 | mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame); |
| 838 | mContentFrame.set(mFrame); |
| 839 | if (!mFrame.equals(mLastFrame)) { |
| 840 | mMovedByResize = true; |
Filip Gruszczynski | ae10080 | 2015-11-11 15:58:03 -0800 | [diff] [blame] | 841 | } |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 842 | } else { |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 843 | mContentFrame.set(Math.max(mContentFrame.left, mFrame.left), |
| 844 | Math.max(mContentFrame.top, mFrame.top), |
| 845 | Math.min(mContentFrame.right, mFrame.right), |
| 846 | Math.min(mContentFrame.bottom, mFrame.bottom)); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 847 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 848 | mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left), |
| 849 | Math.max(mVisibleFrame.top, mFrame.top), |
| 850 | Math.min(mVisibleFrame.right, mFrame.right), |
| 851 | Math.min(mVisibleFrame.bottom, mFrame.bottom)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 852 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 853 | mStableFrame.set(Math.max(mStableFrame.left, mFrame.left), |
| 854 | Math.max(mStableFrame.top, mFrame.top), |
| 855 | Math.min(mStableFrame.right, mFrame.right), |
| 856 | Math.min(mStableFrame.bottom, mFrame.bottom)); |
Skuhne | 81c524a | 2015-08-12 13:34:14 -0700 | [diff] [blame] | 857 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 858 | |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 859 | if (fullscreenTask && !windowsAreFloating) { |
| 860 | // Windows that are not fullscreen can be positioned outside of the display frame, |
| 861 | // but that is not a reason to provide them with overscan insets. |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 862 | mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0), |
| 863 | Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0), |
| 864 | Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0), |
| 865 | Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0)); |
Filip Gruszczynski | 01ef404d5 | 2016-01-28 18:14:27 -0800 | [diff] [blame] | 866 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 867 | |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 868 | if (mAttrs.type == TYPE_DOCK_DIVIDER) { |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 869 | // For the docked divider, we calculate the stable insets like a full-screen window |
| 870 | // so it can use it to calculate the snap positions. |
| 871 | mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0), |
| 872 | Math.max(mStableFrame.top - mDisplayFrame.top, 0), |
| 873 | Math.max(mDisplayFrame.right - mStableFrame.right, 0), |
| 874 | Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0)); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 875 | |
| 876 | // The divider doesn't care about insets in any case, so set it to empty so we don't |
| 877 | // trigger a relayout when moving it. |
| 878 | mContentInsets.setEmpty(); |
| 879 | mVisibleInsets.setEmpty(); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 880 | } else { |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 881 | getDisplayContent().getLogicalDisplayRect(mTmpRect); |
Andrii Kulian | a9d168c | 2016-03-23 13:19:32 -0700 | [diff] [blame] | 882 | // Override right and/or bottom insets in case if the frame doesn't fit the screen in |
| 883 | // non-fullscreen mode. |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 884 | boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right; |
| 885 | boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom; |
| 886 | mContentInsets.set(mContentFrame.left - mFrame.left, |
| 887 | mContentFrame.top - mFrame.top, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 888 | overrideRightInset ? mTmpRect.right - mContentFrame.right |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 889 | : mFrame.right - mContentFrame.right, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 890 | overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 891 | : mFrame.bottom - mContentFrame.bottom); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 892 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 893 | mVisibleInsets.set(mVisibleFrame.left - mFrame.left, |
| 894 | mVisibleFrame.top - mFrame.top, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 895 | overrideRightInset ? mTmpRect.right - mVisibleFrame.right |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 896 | : mFrame.right - mVisibleFrame.right, |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 897 | overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 898 | : mFrame.bottom - mVisibleFrame.bottom); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 899 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 900 | mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0), |
| 901 | Math.max(mStableFrame.top - mFrame.top, 0), |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 902 | overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0) |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 903 | : Math.max(mFrame.right - mStableFrame.right, 0), |
Andrii Kulian | d900337 | 2016-04-04 17:46:59 -0700 | [diff] [blame] | 904 | overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0) |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 905 | : Math.max(mFrame.bottom - mStableFrame.bottom, 0)); |
Jorim Jaggi | 81fe2d1 | 2015-12-21 14:45:18 +0100 | [diff] [blame] | 906 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 907 | |
Jorim Jaggi | 656f650 | 2016-04-11 21:08:17 -0700 | [diff] [blame] | 908 | // Offset the actual frame by the amount layout frame is off. |
| 909 | mFrame.offset(-layoutXDiff, -layoutYDiff); |
| 910 | mCompatFrame.offset(-layoutXDiff, -layoutYDiff); |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 911 | mContentFrame.offset(-layoutXDiff, -layoutYDiff); |
| 912 | mVisibleFrame.offset(-layoutXDiff, -layoutYDiff); |
| 913 | mStableFrame.offset(-layoutXDiff, -layoutYDiff); |
| 914 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 915 | mCompatFrame.set(mFrame); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 916 | if (mEnforceSizeCompat) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 917 | // If there is a size compatibility scale being applied to the |
| 918 | // window, we need to apply this to its insets so that they are |
| 919 | // reported to the app in its coordinate space. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 920 | mOverscanInsets.scale(mInvGlobalScale); |
| 921 | mContentInsets.scale(mInvGlobalScale); |
| 922 | mVisibleInsets.scale(mInvGlobalScale); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 923 | mStableInsets.scale(mInvGlobalScale); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 924 | mOutsets.scale(mInvGlobalScale); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 925 | |
| 926 | // Also the scaled frame that we report to the app needs to be |
| 927 | // adjusted to be in its coordinate space. |
| 928 | mCompatFrame.scale(mInvGlobalScale); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 929 | } |
| 930 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 931 | if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 932 | final DisplayContent displayContent = getDisplayContent(); |
| 933 | if (displayContent != null) { |
| 934 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Wale Ogunwale | e8069dc | 2015-08-18 09:52:01 -0700 | [diff] [blame] | 935 | mService.mWallpaperControllerLocked.updateWallpaperOffset( |
| 936 | this, displayInfo.logicalWidth, displayInfo.logicalHeight, false); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 937 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 940 | if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG, |
| 941 | "Resolving (mRequestedWidth=" |
| 942 | + mRequestedWidth + ", mRequestedheight=" |
| 943 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 944 | + "): frame=" + mFrame.toShortString() |
| 945 | + " ci=" + mContentInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 946 | + " vi=" + mVisibleInsets.toShortString() |
Andrii Kulian | a9d168c | 2016-03-23 13:19:32 -0700 | [diff] [blame] | 947 | + " si=" + mStableInsets.toShortString() |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 948 | + " of=" + mOutsets.toShortString()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 949 | } |
| 950 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 951 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 952 | public Rect getFrameLw() { |
| 953 | return mFrame; |
| 954 | } |
| 955 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 956 | @Override |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 957 | public Point getShownPositionLw() { |
| 958 | return mShownPosition; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 961 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 962 | public Rect getDisplayFrameLw() { |
| 963 | return mDisplayFrame; |
| 964 | } |
| 965 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 966 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 967 | public Rect getOverscanFrameLw() { |
| 968 | return mOverscanFrame; |
| 969 | } |
| 970 | |
| 971 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 972 | public Rect getContentFrameLw() { |
| 973 | return mContentFrame; |
| 974 | } |
| 975 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 976 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 977 | public Rect getVisibleFrameLw() { |
| 978 | return mVisibleFrame; |
| 979 | } |
| 980 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 981 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 982 | public boolean getGivenInsetsPendingLw() { |
| 983 | return mGivenInsetsPending; |
| 984 | } |
| 985 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 986 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 987 | public Rect getGivenContentInsetsLw() { |
| 988 | return mGivenContentInsets; |
| 989 | } |
| 990 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 991 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 992 | public Rect getGivenVisibleInsetsLw() { |
| 993 | return mGivenVisibleInsets; |
| 994 | } |
| 995 | |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 996 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 997 | public WindowManager.LayoutParams getAttrs() { |
| 998 | return mAttrs; |
| 999 | } |
| 1000 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1001 | @Override |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1002 | public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { |
| 1003 | int index = -1; |
| 1004 | WindowState ws = this; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1005 | WindowList windows = getWindowList(); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1006 | while (true) { |
Wale Ogunwale | 393b1c1 | 2014-10-18 16:22:01 -0700 | [diff] [blame] | 1007 | if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) { |
| 1008 | return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE; |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1009 | } |
| 1010 | // If we reached the bottom of the range of windows we are considering, |
| 1011 | // assume no menu is needed. |
| 1012 | if (ws == bottom) { |
| 1013 | return false; |
| 1014 | } |
| 1015 | // The current window hasn't specified whether menu key is needed; |
| 1016 | // look behind it. |
| 1017 | // First, we may need to determine the starting position. |
| 1018 | if (index < 0) { |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1019 | index = windows.indexOf(ws); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1020 | } |
| 1021 | index--; |
| 1022 | if (index < 0) { |
| 1023 | return false; |
| 1024 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1025 | ws = windows.get(index); |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1029 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1030 | public int getSystemUiVisibility() { |
| 1031 | return mSystemUiVisibility; |
| 1032 | } |
| 1033 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1034 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1035 | public int getSurfaceLayer() { |
| 1036 | return mLayer; |
| 1037 | } |
| 1038 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1039 | @Override |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1040 | public int getBaseType() { |
| 1041 | WindowState win = this; |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 1042 | while (win.isChildWindow()) { |
Selim Cinek | d662361 | 2015-05-22 18:56:22 -0700 | [diff] [blame] | 1043 | win = win.mAttachedWindow; |
| 1044 | } |
| 1045 | return win.mAttrs.type; |
| 1046 | } |
| 1047 | |
| 1048 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1049 | public IApplicationToken getAppToken() { |
| 1050 | return mAppToken != null ? mAppToken.appToken : null; |
| 1051 | } |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1052 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1053 | @Override |
| 1054 | public boolean isVoiceInteraction() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1055 | return mAppToken != null && mAppToken.voiceInteraction; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1058 | boolean setInsetsChanged() { |
| 1059 | mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets); |
| 1060 | mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets); |
| 1061 | mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1062 | mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1063 | mOutsetsChanged |= !mLastOutsets.equals(mOutsets); |
| 1064 | return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged |
| 1065 | || mOutsetsChanged; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1068 | public DisplayContent getDisplayContent() { |
Chad Jones | f391ebc | 2014-06-12 17:45:05 -0700 | [diff] [blame] | 1069 | if (mAppToken == null || mNotOnAppsDisplay) { |
Craig Mautner | be63495 | 2014-06-12 13:39:24 -0700 | [diff] [blame] | 1070 | return mDisplayContent; |
| 1071 | } |
| 1072 | final TaskStack stack = getStack(); |
| 1073 | return stack == null ? mDisplayContent : stack.getDisplayContent(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 1076 | public DisplayInfo getDisplayInfo() { |
| 1077 | final DisplayContent displayContent = getDisplayContent(); |
| 1078 | return displayContent != null ? displayContent.getDisplayInfo() : null; |
| 1079 | } |
| 1080 | |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1081 | public int getDisplayId() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1082 | final DisplayContent displayContent = getDisplayContent(); |
| 1083 | if (displayContent == null) { |
| 1084 | return -1; |
| 1085 | } |
| 1086 | return displayContent.getDisplayId(); |
Craig Mautner | 19d59bc | 2012-09-04 11:15:56 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1089 | Task getTask() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 1090 | return mAppToken != null ? mAppToken.mTask : null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | TaskStack getStack() { |
| 1094 | Task task = getTask(); |
| 1095 | if (task != null) { |
| 1096 | if (task.mStack != null) { |
| 1097 | return task.mStack; |
Craig Mautner | f06b8c1 | 2013-04-18 14:27:28 -0700 | [diff] [blame] | 1098 | } |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1099 | } |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1100 | // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still |
| 1101 | // associate them with some stack to enable dimming. |
| 1102 | return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1103 | && mDisplayContent != null ? mDisplayContent.getHomeStack() : null; |
Craig Mautner | d9a2288 | 2013-03-16 15:00:36 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1106 | /** |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1107 | * Retrieves the visible bounds of the window. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1108 | * @param bounds The rect which gets the bounds. |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 1109 | */ |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1110 | void getVisibleBounds(Rect bounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1111 | final Task task = getTask(); |
| 1112 | boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds(); |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1113 | bounds.setEmpty(); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1114 | mTmpRect.setEmpty(); |
| 1115 | if (intersectWithStackBounds) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1116 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1117 | if (stack != null) { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1118 | stack.getDimBounds(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1119 | } else { |
| 1120 | intersectWithStackBounds = false; |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1121 | } |
| 1122 | } |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1123 | |
Chong Zhang | 9184ec6 | 2015-09-24 12:32:21 -0700 | [diff] [blame] | 1124 | bounds.set(mVisibleFrame); |
| 1125 | if (intersectWithStackBounds) { |
| 1126 | bounds.intersect(mTmpRect); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 1129 | if (bounds.isEmpty()) { |
| 1130 | bounds.set(mFrame); |
Wale Ogunwale | 2b19b60 | 2015-09-18 15:14:59 -0700 | [diff] [blame] | 1131 | if (intersectWithStackBounds) { |
| 1132 | bounds.intersect(mTmpRect); |
| 1133 | } |
Craig Mautner | bdc748af | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 1134 | return; |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1135 | } |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1138 | public long getInputDispatchingTimeoutNanos() { |
| 1139 | return mAppToken != null |
| 1140 | ? mAppToken.inputDispatchingTimeoutNanos |
| 1141 | : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 1142 | } |
| 1143 | |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1144 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1145 | public boolean hasAppShownWindows() { |
Craig Mautner | f412095 | 2012-06-21 18:25:39 -0700 | [diff] [blame] | 1146 | return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1147 | } |
| 1148 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1149 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 1150 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 1151 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 1152 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 1153 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 1154 | return true; |
| 1155 | } |
| 1156 | |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1157 | void prelayout() { |
| 1158 | if (mEnforceSizeCompat) { |
| 1159 | mGlobalScale = mService.mCompatibleScreenScale; |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1160 | mInvGlobalScale = 1/mGlobalScale; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1161 | } else { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 1162 | mGlobalScale = mInvGlobalScale = 1; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1166 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1167 | * Does the minimal check for visibility. Callers generally want to use one of the public |
| 1168 | * methods as they perform additional checks on the app token. |
| 1169 | * 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] | 1170 | */ |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1171 | private boolean isVisibleUnchecked() { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1172 | return mHasSurface && mPolicyVisibility && !mAttachedHidden |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1173 | && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1177 | * Is this window visible? It is not visible if there is no surface, or we are in the process |
| 1178 | * of running an exit animation that will remove the surface, or its app token has been hidden. |
| 1179 | */ |
| 1180 | @Override |
| 1181 | public boolean isVisibleLw() { |
| 1182 | return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked(); |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the |
| 1187 | * keyguard as visible. This allows us to apply things like window flags that impact the |
| 1188 | * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this |
| 1189 | * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1190 | */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1191 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1192 | public boolean isVisibleOrBehindKeyguardLw() { |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1193 | if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 1194 | return false; |
| 1195 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1196 | final AppWindowToken atoken = mAppToken; |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1197 | final boolean animating = atoken != null && atoken.mAppAnimator.animation != null; |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1198 | return mHasSurface && !mDestroying && !mAnimatingExit |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1199 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1200 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1201 | || mWinAnimator.mAnimation != null || animating); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1205 | * Is this window visible, ignoring its app token? It is not visible if there is no surface, |
| 1206 | * 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] | 1207 | */ |
| 1208 | public boolean isWinVisibleLw() { |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1209 | return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating) |
| 1210 | && isVisibleUnchecked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /** |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1214 | * The same as isVisible(), but follows the current hidden state of the associated app token, |
| 1215 | * not the pending requested hidden state. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1216 | */ |
| 1217 | boolean isVisibleNow() { |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1218 | return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING) |
| 1219 | && isVisibleUnchecked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * Can this window possibly be a drag/drop target? The test here is |
| 1224 | * a combination of the above "visible now" with the check that the |
| 1225 | * Input Manager uses when discarding windows from input consideration. |
| 1226 | */ |
| 1227 | boolean isPotentialDragTarget() { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1228 | return isVisibleNow() && !mRemoved |
| 1229 | && mInputChannel != null && mInputWindowHandle != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * Same as isVisible(), but we also count it as visible between the |
| 1234 | * call to IWindowSession.add() and the first relayout(). |
| 1235 | */ |
| 1236 | boolean isVisibleOrAdding() { |
| 1237 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf08af3 | 2012-05-16 19:43:42 -0700 | [diff] [blame] | 1238 | return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1239 | && mPolicyVisibility && !mAttachedHidden |
| 1240 | && (atoken == null || !atoken.hiddenRequested) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1241 | && !mAnimatingExit && !mDestroying; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Is this window currently on-screen? It is on-screen either if it |
| 1246 | * is visible or it is currently running an animation before no longer |
| 1247 | * being visible. |
| 1248 | */ |
| 1249 | boolean isOnScreen() { |
Jorim Jaggi | 44f60cc | 2014-11-07 20:33:51 +0100 | [diff] [blame] | 1250 | return mPolicyVisibility && isOnScreenIgnoringKeyguard(); |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Like isOnScreen(), but ignores any force hiding of the window due |
| 1255 | * to the keyguard. |
| 1256 | */ |
| 1257 | boolean isOnScreenIgnoringKeyguard() { |
| 1258 | if (!mHasSurface || mDestroying) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1259 | return false; |
| 1260 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1261 | final AppWindowToken atoken = mAppToken; |
| 1262 | if (atoken != null) { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1263 | return ((!mAttachedHidden && !atoken.hiddenRequested) |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1264 | || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1265 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1266 | return !mAttachedHidden || mWinAnimator.mAnimation != null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /** |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1270 | * Whether this window's drawn state might affect the drawn states of the app token. |
| 1271 | * |
| 1272 | * @param visibleOnly Whether we should consider only the windows that's currently |
| 1273 | * visible in layout. If true, windows that has not relayout to VISIBLE |
| 1274 | * would always return false. |
| 1275 | * |
| 1276 | * @return true if the window should be considered while evaluating allDrawn flags. |
| 1277 | */ |
| 1278 | boolean mightAffectAllDrawn(boolean visibleOnly) { |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 1279 | final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden) |
| 1280 | && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1281 | return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible) |
| 1282 | || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION) |
| 1283 | && !mAnimatingExit && !mDestroying; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * Whether this window is "interesting" when evaluating allDrawn. If it's interesting, |
| 1288 | * it must be drawn before allDrawn can become true. |
| 1289 | */ |
| 1290 | boolean isInteresting() { |
| 1291 | return mAppToken != null && !mAppDied |
| 1292 | && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing); |
| 1293 | } |
| 1294 | |
| 1295 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1296 | * Like isOnScreen(), but we don't return true if the window is part |
| 1297 | * of a transition that has not yet been started. |
| 1298 | */ |
| 1299 | boolean isReadyForDisplay() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1300 | if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1301 | return false; |
| 1302 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1303 | return mHasSurface && mPolicyVisibility && !mDestroying |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1304 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1305 | || mWinAnimator.mAnimation != null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1306 | || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null))); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1307 | } |
| 1308 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1309 | /** |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1310 | * Like isReadyForDisplay(), but ignores any force hiding of the window due |
| 1311 | * to the keyguard. |
| 1312 | */ |
| 1313 | boolean isReadyForDisplayIgnoringKeyguard() { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1314 | if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) { |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1315 | return false; |
| 1316 | } |
| 1317 | final AppWindowToken atoken = mAppToken; |
| 1318 | if (atoken == null && !mPolicyVisibility) { |
| 1319 | // If this is not an app window, and the policy has asked to force |
| 1320 | // hide, then we really do want to hide. |
| 1321 | return false; |
| 1322 | } |
| 1323 | return mHasSurface && !mDestroying |
Wale Ogunwale | 329b7e5 | 2016-01-15 15:00:57 -0800 | [diff] [blame] | 1324 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden) |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1325 | || mWinAnimator.mAnimation != null |
Craig Mautner | 9c5bf3b | 2012-06-22 15:19:13 -0700 | [diff] [blame] | 1326 | || ((atoken != null) && (atoken.mAppAnimator.animation != null) |
| 1327 | && !mWinAnimator.isDummyAnimation())); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | /** |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1331 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 1332 | * been drawn. |
| 1333 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1334 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1335 | public boolean isDisplayedLw() { |
| 1336 | final AppWindowToken atoken = mAppToken; |
Craig Mautner | bf90eaa | 2012-03-15 11:28:53 -0700 | [diff] [blame] | 1337 | return isDrawnLw() && mPolicyVisibility |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1338 | && ((!mAttachedHidden && |
| 1339 | (atoken == null || !atoken.hiddenRequested)) |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1340 | || mWinAnimator.mAnimating |
| 1341 | || (atoken != null && atoken.mAppAnimator.animation != null)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1344 | /** |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1345 | * Return true if this window or its app token is currently animating. |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1346 | */ |
Craig Mautner | e6f7d505 | 2012-10-08 10:34:17 -0700 | [diff] [blame] | 1347 | @Override |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1348 | public boolean isAnimatingLw() { |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 1349 | return mWinAnimator.mAnimation != null |
| 1350 | || (mAppToken != null && mAppToken.mAppAnimator.animation != null); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1353 | @Override |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1354 | public boolean isGoneForLayoutLw() { |
| 1355 | final AppWindowToken atoken = mAppToken; |
| 1356 | return mViewVisibility == View.GONE |
| 1357 | || !mRelayoutCalled |
| 1358 | || (atoken == null && mRootToken.hidden) |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 1359 | || (atoken != null && atoken.hiddenRequested) |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1360 | || mAttachedHidden |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1361 | || (mAnimatingExit && !isAnimatingLw()) |
Craig Mautner | 0e415c6 | 2013-04-29 16:10:58 -0700 | [diff] [blame] | 1362 | || mDestroying; |
Dianne Hackborn | cfbf7de | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 1363 | } |
| 1364 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1365 | /** |
| 1366 | * Returns true if the window has a surface that it has drawn a |
| 1367 | * complete UI in to. |
| 1368 | */ |
Craig Mautner | ccc9e9b | 2012-12-11 09:40:34 -0800 | [diff] [blame] | 1369 | public boolean isDrawFinishedLw() { |
| 1370 | return mHasSurface && !mDestroying && |
| 1371 | (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING |
| 1372 | || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW |
| 1373 | || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * Returns true if the window has a surface that it has drawn a |
| 1378 | * complete UI in to. |
| 1379 | */ |
Adrian Roos | 76d2fe4 | 2015-07-09 14:54:08 -0700 | [diff] [blame] | 1380 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1381 | public boolean isDrawnLw() { |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 1382 | return mHasSurface && !mDestroying && |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1383 | (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW |
| 1384 | || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | /** |
| 1388 | * Return true if the window is opaque and fully drawn. This indicates |
| 1389 | * it may obscure windows behind it. |
| 1390 | */ |
| 1391 | boolean isOpaqueDrawn() { |
Chong Zhang | 66bf071d | 2016-02-05 14:42:36 -0800 | [diff] [blame] | 1392 | // When there is keyguard, wallpaper could be placed over the secure app |
| 1393 | // window but invisible. We need to check wallpaper visibility explicitly |
| 1394 | // to determine if it's occluding apps. |
| 1395 | return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE) |
| 1396 | || (mIsWallpaper && mWallpaperVisible)) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1397 | && isDrawnLw() && mWinAnimator.mAnimation == null |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1398 | && (mAppToken == null || mAppToken.mAppAnimator.animation == null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /** |
Craig Mautner | 4557c08 | 2015-04-27 13:07:40 -0700 | [diff] [blame] | 1402 | * Return whether this window has moved. (Only makes |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1403 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 1404 | */ |
Craig Mautner | 4557c08 | 2015-04-27 13:07:40 -0700 | [diff] [blame] | 1405 | boolean hasMoved() { |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 1406 | return mHasSurface && (mContentChanged || mMovedByResize) |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1407 | && !mAnimatingExit && mService.okToDisplay() |
Chong Zhang | bd0d937 | 2015-12-28 15:18:29 -0800 | [diff] [blame] | 1408 | && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left) |
Craig Mautner | 4557c08 | 2015-04-27 13:07:40 -0700 | [diff] [blame] | 1409 | && (mAttachedWindow == null || !mAttachedWindow.hasMoved()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1410 | } |
| 1411 | |
Chong Zhang | 0abb20f | 2015-11-19 14:17:31 -0800 | [diff] [blame] | 1412 | boolean isObscuringFullscreen(final DisplayInfo displayInfo) { |
| 1413 | Task task = getTask(); |
| 1414 | if (task != null && task.mStack != null && !task.mStack.isFullscreen()) { |
| 1415 | return false; |
| 1416 | } |
| 1417 | if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) { |
| 1418 | return false; |
| 1419 | } |
| 1420 | return true; |
| 1421 | } |
| 1422 | |
| 1423 | boolean isFrameFullscreen(final DisplayInfo displayInfo) { |
| 1424 | return mFrame.left <= 0 && mFrame.top <= 0 |
| 1425 | && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1426 | } |
| 1427 | |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1428 | boolean isConfigChanged() { |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1429 | getMergedConfig(mTmpConfig); |
| 1430 | |
| 1431 | // If the merged configuration is still empty, it means that we haven't issues the |
| 1432 | // configuration to the client yet and we need to return true so the configuration updates. |
| 1433 | boolean configChanged = mMergedConfiguration.equals(Configuration.EMPTY) |
| 1434 | || mTmpConfig.diff(mMergedConfiguration) != 0; |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1435 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1436 | if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1437 | // Retain configuration changed status until resetConfiguration called. |
| 1438 | mConfigHasChanged |= configChanged; |
| 1439 | configChanged = mConfigHasChanged; |
| 1440 | } |
| 1441 | |
| 1442 | return configChanged; |
Craig Mautner | 812d2ca | 2012-09-27 15:35:34 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Jorim Jaggi | b72c9ad | 2016-04-11 18:27:58 -0700 | [diff] [blame] | 1445 | boolean isAdjustedForMinimizedDock() { |
| 1446 | return mAppToken != null && mAppToken.mTask != null |
| 1447 | && mAppToken.mTask.mStack.isAdjustedForMinimizedDock(); |
| 1448 | } |
| 1449 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1450 | void removeLocked() { |
| 1451 | disposeInputChannel(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1452 | |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 1453 | if (isChildWindow()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 1454 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1455 | mAttachedWindow.mChildWindows.remove(this); |
| 1456 | } |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1457 | mWinAnimator.destroyDeferredSurfaceLocked(); |
| 1458 | mWinAnimator.destroySurfaceLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1459 | mSession.windowRemovedLocked(); |
| 1460 | try { |
| 1461 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 1462 | } catch (RuntimeException e) { |
| 1463 | // Ignore if it has already been removed (usually because |
| 1464 | // we are doing this as part of processing a death note.) |
| 1465 | } |
| 1466 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1467 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 1468 | void setHasSurface(boolean hasSurface) { |
| 1469 | mHasSurface = hasSurface; |
| 1470 | } |
| 1471 | |
Filip Gruszczynski | 92e432c | 2015-12-15 19:17:09 -0800 | [diff] [blame] | 1472 | int getAnimLayerAdjustment() { |
| 1473 | if (mTargetAppToken != null) { |
| 1474 | return mTargetAppToken.mAppAnimator.animLayerAdjustment; |
| 1475 | } else if (mAppToken != null) { |
| 1476 | return mAppToken.mAppAnimator.animLayerAdjustment; |
| 1477 | } else { |
| 1478 | // Nothing is animating, so there is no animation adjustment. |
| 1479 | return 0; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | void scheduleAnimationIfDimming() { |
| 1484 | if (mDisplayContent == null) { |
| 1485 | return; |
| 1486 | } |
| 1487 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
| 1488 | if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming( |
| 1489 | dimLayerUser, mWinAnimator)) { |
| 1490 | // Force an animation pass just to update the mDimLayer layer. |
| 1491 | mService.scheduleAnimationLocked(); |
| 1492 | } |
| 1493 | } |
| 1494 | |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 1495 | /** |
| 1496 | * Notifies this window that the corresponding task has just moved in the stack. |
| 1497 | * <p> |
| 1498 | * This is used to fix the following: If we moved in the stack, and if the last clip rect was |
| 1499 | * empty, meaning that our task was completely offscreen, we need to keep it invisible because |
| 1500 | * the actual app transition that updates the visibility is delayed by a few transactions. |
| 1501 | * Instead of messing around with the ordering and timing how transitions and transactions are |
| 1502 | * executed, we introduce this little hack which prevents this window of getting visible again |
| 1503 | * with the wrong bounds until the app transitions has started. |
| 1504 | * <p> |
| 1505 | * This method notifies the window about that we just moved in the stack so we can apply this |
| 1506 | * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop} |
| 1507 | */ |
| 1508 | void notifyMovedInStack() { |
| 1509 | mJustMovedInStack = true; |
| 1510 | } |
| 1511 | |
| 1512 | /** |
| 1513 | * See {@link #notifyMovedInStack}. |
| 1514 | * |
| 1515 | * @return Whether we just got moved in the corresponding stack. |
| 1516 | */ |
| 1517 | boolean hasJustMovedInStack() { |
| 1518 | return mJustMovedInStack; |
| 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}. |
| 1523 | */ |
| 1524 | void resetJustMovedInStack() { |
| 1525 | mJustMovedInStack = false; |
| 1526 | } |
| 1527 | |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 1528 | private final class DeadWindowEventReceiver extends InputEventReceiver { |
| 1529 | DeadWindowEventReceiver(InputChannel inputChannel) { |
| 1530 | super(inputChannel, mService.mH.getLooper()); |
| 1531 | } |
| 1532 | @Override |
| 1533 | public void onInputEvent(InputEvent event) { |
| 1534 | finishInputEvent(event, true); |
| 1535 | } |
| 1536 | } |
| 1537 | /** |
| 1538 | * Dummy event receiver for windows that died visible. |
| 1539 | */ |
| 1540 | private DeadWindowEventReceiver mDeadWindowEventReceiver; |
| 1541 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1542 | void openInputChannel(InputChannel outInputChannel) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1543 | if (mInputChannel != null) { |
| 1544 | throw new IllegalStateException("Window already has an input channel."); |
| 1545 | } |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1546 | String name = makeInputChannelName(); |
| 1547 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 1548 | mInputChannel = inputChannels[0]; |
| 1549 | mClientChannel = inputChannels[1]; |
| 1550 | mInputWindowHandle.inputChannel = inputChannels[0]; |
| 1551 | if (outInputChannel != null) { |
| 1552 | mClientChannel.transferTo(outInputChannel); |
| 1553 | mClientChannel.dispose(); |
| 1554 | mClientChannel = null; |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 1555 | } else { |
| 1556 | // If the window died visible, we setup a dummy input channel, so that taps |
| 1557 | // can still detected by input monitor channel, and we can relaunch the app. |
| 1558 | // Create dummy event receiver that simply reports all events as handled. |
| 1559 | mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1560 | } |
| 1561 | mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1564 | void disposeInputChannel() { |
Chong Zhang | acf1140 | 2015-11-04 16:23:10 -0800 | [diff] [blame] | 1565 | if (mDeadWindowEventReceiver != null) { |
| 1566 | mDeadWindowEventReceiver.dispose(); |
| 1567 | mDeadWindowEventReceiver = null; |
| 1568 | } |
| 1569 | |
| 1570 | // unregister server channel first otherwise it complains about broken channel |
| 1571 | if (mInputChannel != null) { |
| 1572 | mService.mInputManager.unregisterInputChannel(mInputChannel); |
| 1573 | mInputChannel.dispose(); |
| 1574 | mInputChannel = null; |
| 1575 | } |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1576 | if (mClientChannel != null) { |
| 1577 | mClientChannel.dispose(); |
| 1578 | mClientChannel = null; |
| 1579 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1580 | mInputWindowHandle.inputChannel = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1581 | } |
| 1582 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1583 | void applyDimLayerIfNeeded() { |
Chong Zhang | eb91732 | 2015-11-10 14:05:40 -0800 | [diff] [blame] | 1584 | // When the app is terminated (eg. from Recents), the task might have already been |
| 1585 | // removed with the window pending removal. Don't apply dim in such cases, as there |
| 1586 | // will be no more updateDimLayer() calls, which leaves the dimlayer invalid. |
| 1587 | final AppWindowToken token = mAppToken; |
| 1588 | if (token != null && token.removed) { |
| 1589 | return; |
| 1590 | } |
| 1591 | |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1592 | if (!mAnimatingExit && mAppDied) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1593 | // If app died visible, apply a dim over the window to indicate that it's inactive |
| 1594 | mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator); |
| 1595 | } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 |
Robert Carr | 9fe459d | 2016-04-07 23:32:28 -0700 | [diff] [blame] | 1596 | && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1597 | mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator); |
Filip Gruszczynski | 4501d23 | 2015-09-02 13:00:02 -0700 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 1601 | DimLayer.DimLayerUser getDimLayerUser() { |
| 1602 | Task task = getTask(); |
| 1603 | if (task != null) { |
| 1604 | return task; |
| 1605 | } |
| 1606 | return getStack(); |
| 1607 | } |
| 1608 | |
Filip Gruszczynski | 76cc44f | 2015-09-03 16:03:10 -0700 | [diff] [blame] | 1609 | void maybeRemoveReplacedWindow() { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 1610 | if (mAppToken == null) { |
| 1611 | return; |
| 1612 | } |
| 1613 | for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) { |
| 1614 | final WindowState win = mAppToken.allAppWindows.get(i); |
Robert Carr | dcdca58 | 2016-04-07 22:59:24 -0700 | [diff] [blame] | 1615 | if (win.mWillReplaceWindow && win.mReplacingWindow == this && hasDrawnLw()) { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 1616 | if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win); |
Robert Carr | 9fe459d | 2016-04-07 23:32:28 -0700 | [diff] [blame] | 1617 | if (win.isDimming()) { |
| 1618 | win.transferDimToReplacement(); |
| 1619 | } |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 1620 | win.mWillReplaceWindow = false; |
Wale Ogunwale | d0a166a | 2016-05-09 11:18:18 -0700 | [diff] [blame] | 1621 | final boolean animateReplacingWindow = win.mAnimateReplacingWindow; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 1622 | win.mAnimateReplacingWindow = false; |
| 1623 | win.mReplacingRemoveRequested = false; |
| 1624 | win.mReplacingWindow = null; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 1625 | mSkipEnterAnimationForSeamlessReplacement = false; |
Wale Ogunwale | d0a166a | 2016-05-09 11:18:18 -0700 | [diff] [blame] | 1626 | if (win.mAnimatingExit || !animateReplacingWindow) { |
Filip Gruszczynski | 76cc44f | 2015-09-03 16:03:10 -0700 | [diff] [blame] | 1627 | mService.removeWindowInnerLocked(win); |
| 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | } |
| 1632 | |
Filip Gruszczynski | e92179d | 2015-09-26 16:12:30 -0700 | [diff] [blame] | 1633 | void setDisplayLayoutNeeded() { |
| 1634 | if (mDisplayContent != null) { |
| 1635 | mDisplayContent.layoutNeeded = true; |
| 1636 | } |
| 1637 | } |
| 1638 | |
Filip Gruszczynski | 955b2fc | 2015-10-15 14:46:07 -0700 | [diff] [blame] | 1639 | boolean inDockedWorkspace() { |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 1640 | final Task task = getTask(); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 1641 | return task != null && task.inDockedWorkspace(); |
| 1642 | } |
| 1643 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 1644 | // TODO: Strange usage of word workspace here and above. |
| 1645 | boolean inPinnedWorkspace() { |
| 1646 | final Task task = getTask(); |
| 1647 | return task != null && task.inPinnedWorkspace(); |
| 1648 | } |
| 1649 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 1650 | boolean isDockedInEffect() { |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 1651 | final Task task = getTask(); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 1652 | return task != null && task.isDockedInEffect(); |
Filip Gruszczynski | 955b2fc | 2015-10-15 14:46:07 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 1655 | void applyScrollIfNeeded() { |
| 1656 | final Task task = getTask(); |
Chong Zhang | f66db43 | 2016-01-13 10:39:51 -0800 | [diff] [blame] | 1657 | if (task != null) { |
| 1658 | task.applyScrollToWindowIfNeeded(this); |
Chong Zhang | 2a88fc3 | 2016-01-11 17:14:24 -0800 | [diff] [blame] | 1659 | } |
| 1660 | } |
| 1661 | |
Chong Zhang | 5117e27 | 2016-05-03 12:47:34 -0700 | [diff] [blame] | 1662 | void applyAdjustForImeIfNeeded() { |
| 1663 | final Task task = getTask(); |
| 1664 | if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) { |
| 1665 | task.mStack.applyAdjustForImeIfNeeded(task); |
| 1666 | } |
| 1667 | } |
| 1668 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 1669 | int getTouchableRegion(Region region, int flags) { |
| 1670 | final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0; |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 1671 | if (modal && mAppToken != null) { |
| 1672 | // Limit the outer touch to the activity stack region. |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 1673 | flags |= FLAG_NOT_TOUCH_MODAL; |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1674 | // If this is a modal window we need to dismiss it if it's not full screen and the |
| 1675 | // touch happens outside of the frame that displays the content. This means we |
| 1676 | // need to intercept touches outside of that window. The dim layer user |
| 1677 | // associated with the window (task or stack) will give us the good bounds, as |
| 1678 | // they would be used to display the dim layer. |
| 1679 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
| 1680 | if (dimLayerUser != null) { |
| 1681 | dimLayerUser.getDimBounds(mTmpRect); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 1682 | } else { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1683 | getVisibleBounds(mTmpRect); |
| 1684 | } |
| 1685 | if (inFreeformWorkspace()) { |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 1686 | // For freeform windows we the touch region to include the whole surface for the |
| 1687 | // shadows. |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 1688 | final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics(); |
| 1689 | final int delta = WindowManagerService.dipToPixel( |
| 1690 | RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics); |
| 1691 | mTmpRect.inset(-delta, -delta); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 1692 | } |
| 1693 | region.set(mTmpRect); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 1694 | cropRegionToStackBoundsIfNeeded(region); |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 1695 | } else { |
| 1696 | // Not modal or full screen modal |
| 1697 | getTouchableRegion(region); |
| 1698 | } |
| 1699 | return flags; |
| 1700 | } |
| 1701 | |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 1702 | void checkPolicyVisibilityChange() { |
| 1703 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 1704 | if (DEBUG_VISIBILITY) { |
| 1705 | Slog.v(TAG, "Policy visibility changing after anim in " + |
| 1706 | mWinAnimator + ": " + mPolicyVisibilityAfterAnim); |
| 1707 | } |
| 1708 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 1709 | setDisplayLayoutNeeded(); |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 1710 | if (!mPolicyVisibility) { |
| 1711 | if (mService.mCurrentFocus == this) { |
| 1712 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
| 1713 | "setAnimationLocked: setting mFocusMayChange true"); |
| 1714 | mService.mFocusMayChange = true; |
| 1715 | } |
| 1716 | // Window is no longer visible -- make sure if we were waiting |
| 1717 | // for it to be displayed before enabling the display, that |
| 1718 | // we allow the display to be enabled now. |
| 1719 | mService.enableScreenIfNeededLocked(); |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | void setRequestedSize(int requestedWidth, int requestedHeight) { |
| 1725 | if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) { |
| 1726 | mLayoutNeeded = true; |
| 1727 | mRequestedWidth = requestedWidth; |
| 1728 | mRequestedHeight = requestedHeight; |
| 1729 | } |
| 1730 | } |
| 1731 | |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 1732 | void prepareWindowToDisplayDuringRelayout(Configuration outConfig) { |
| 1733 | if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST) |
| 1734 | == SOFT_INPUT_ADJUST_RESIZE) { |
| 1735 | mLayoutNeeded = true; |
| 1736 | } |
| 1737 | if (isDrawnLw() && mService.okToDisplay()) { |
| 1738 | mWinAnimator.applyEnterAnimationLocked(); |
| 1739 | } |
| 1740 | if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) { |
| 1741 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this); |
| 1742 | mTurnOnScreen = true; |
| 1743 | } |
| 1744 | if (isConfigChanged()) { |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 1745 | final Configuration newConfig = updateConfiguration(); |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 1746 | if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: " |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 1747 | + newConfig); |
| 1748 | outConfig.setTo(newConfig); |
Filip Gruszczynski | 84cc5e3 | 2015-11-03 18:05:47 -0800 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | void adjustStartingWindowFlags() { |
| 1753 | if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null |
| 1754 | && mAppToken.startingWindow != null) { |
| 1755 | // Special handling of starting window over the base |
| 1756 | // window of the app: propagate lock screen flags to it, |
| 1757 | // to provide the correct semantics while starting. |
| 1758 | final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD |
| 1759 | | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| 1760 | WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs; |
| 1761 | sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask); |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | void setWindowScale(int requestedWidth, int requestedHeight) { |
| 1766 | final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0; |
| 1767 | |
| 1768 | if (scaledWindow) { |
| 1769 | // requested{Width|Height} Surface's physical size |
| 1770 | // attrs.{width|height} Size on screen |
| 1771 | // TODO: We don't check if attrs != null here. Is it implicitly checked? |
| 1772 | mHScale = (mAttrs.width != requestedWidth) ? |
| 1773 | (mAttrs.width / (float)requestedWidth) : 1.0f; |
| 1774 | mVScale = (mAttrs.height != requestedHeight) ? |
| 1775 | (mAttrs.height / (float)requestedHeight) : 1.0f; |
| 1776 | } else { |
| 1777 | mHScale = mVScale = 1; |
| 1778 | } |
| 1779 | } |
| 1780 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1781 | private class DeathRecipient implements IBinder.DeathRecipient { |
Craig Mautner | e855214 | 2012-11-07 13:55:47 -0800 | [diff] [blame] | 1782 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1783 | public void binderDied() { |
| 1784 | try { |
| 1785 | synchronized(mService.mWindowMap) { |
| 1786 | WindowState win = mService.windowForClientLocked(mSession, mClient, false); |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1787 | Slog.i(TAG, "WIN DEATH: " + win); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1788 | if (win != null) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 1789 | mService.removeWindowLocked(win, shouldKeepVisibleDeadAppWindow()); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 1790 | if (win.mAttrs.type == TYPE_DOCK_DIVIDER) { |
| 1791 | // The owner of the docked divider died :( We reset the docked stack, |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 1792 | // just in case they have the divider at an unstable position. Better |
| 1793 | // also reset drag resizing state, because the owner can't do it |
| 1794 | // anymore. |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 1795 | final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID); |
| 1796 | if (stack != null) { |
| 1797 | stack.resetDockedStackToMiddle(); |
| 1798 | } |
Jorim Jaggi | dcb6814 | 2016-02-09 21:51:30 -0800 | [diff] [blame] | 1799 | mService.setDockedStackResizing(false); |
Wale Ogunwale | a9f9b37 | 2016-02-04 18:04:39 -0800 | [diff] [blame] | 1800 | } |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 1801 | } else if (mHasSurface) { |
Craig Mautner | a99764e | 2013-03-06 10:22:16 -0800 | [diff] [blame] | 1802 | Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid."); |
Wale Ogunwale | a6ab5c4 | 2015-04-24 09:00:25 -0700 | [diff] [blame] | 1803 | mService.removeWindowLocked(WindowState.this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | } catch (IllegalArgumentException ex) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 1807 | // This will happen if the window has already been removed. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | } |
| 1811 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 1812 | /** |
| 1813 | * Returns true if this window is visible and belongs to a dead app and shouldn't be removed, |
| 1814 | * because we want to preserve its location on screen to be re-activated later when the user |
| 1815 | * interacts with it. |
| 1816 | */ |
| 1817 | boolean shouldKeepVisibleDeadAppWindow() { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 1818 | if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) { |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 1819 | // Not a visible app window or the app isn't dead. |
| 1820 | return false; |
| 1821 | } |
| 1822 | |
Wale Ogunwale | 51d1d91 | 2016-05-04 13:27:18 -0700 | [diff] [blame] | 1823 | if (mAttrs.token != mClient.asBinder()) { |
| 1824 | // The window was add by a client using another client's app token. We don't want to |
| 1825 | // keep the dead window around for this case since this is meant for 'real' apps. |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
Wale Ogunwale | 3fd20fe | 2016-01-23 17:41:28 -0800 | [diff] [blame] | 1829 | if (mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 1830 | // We don't keep starting windows since they were added by the window manager before |
| 1831 | // the app even launched. |
| 1832 | return false; |
| 1833 | } |
| 1834 | |
| 1835 | final TaskStack stack = getStack(); |
| 1836 | return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId); |
| 1837 | } |
| 1838 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 1839 | /** @return true if this window desires key events. */ |
| 1840 | boolean canReceiveKeys() { |
Craig Mautner | 5810681 | 2012-12-28 12:27:40 -0800 | [diff] [blame] | 1841 | return isVisibleOrAdding() |
Chong Zhang | e292eb3 | 2016-05-21 09:23:55 -0700 | [diff] [blame] | 1842 | && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 1843 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0) |
Jorim Jaggi | b72c9ad | 2016-04-11 18:27:58 -0700 | [diff] [blame] | 1844 | && (mAppToken == null || mAppToken.windowsAreFocusable()) |
| 1845 | && !isAdjustedForMinimizedDock(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1846 | } |
| 1847 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1848 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1849 | public boolean hasDrawnLw() { |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1850 | return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1851 | } |
| 1852 | |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 1853 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1854 | public boolean showLw(boolean doAnimation) { |
| 1855 | return showLw(doAnimation, true); |
| 1856 | } |
| 1857 | |
| 1858 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 1859 | if (isHiddenFromUserLocked()) { |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 1860 | return false; |
| 1861 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 1862 | if (!mAppOpVisibility) { |
| 1863 | // Being hidden due to app op request. |
| 1864 | return false; |
| 1865 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1866 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 1867 | // Already showing. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1868 | return false; |
| 1869 | } |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1870 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1871 | if (doAnimation) { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1872 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1873 | + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation); |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 1874 | if (!mService.okToDisplay()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1875 | doAnimation = false; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1876 | } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1877 | // Check for the case where we are currently visible and |
| 1878 | // not animating; we do not want to do animation at such a |
| 1879 | // point to become visible when we already are. |
| 1880 | doAnimation = false; |
| 1881 | } |
| 1882 | } |
| 1883 | mPolicyVisibility = true; |
| 1884 | mPolicyVisibilityAfterAnim = true; |
| 1885 | if (doAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1886 | mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1887 | } |
| 1888 | if (requestAnim) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1889 | mService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1890 | } |
| 1891 | return true; |
| 1892 | } |
| 1893 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1894 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1895 | public boolean hideLw(boolean doAnimation) { |
| 1896 | return hideLw(doAnimation, true); |
| 1897 | } |
| 1898 | |
| 1899 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| 1900 | if (doAnimation) { |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 1901 | if (!mService.okToDisplay()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1902 | doAnimation = false; |
| 1903 | } |
| 1904 | } |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 1905 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 1906 | : mPolicyVisibility; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1907 | if (!current) { |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 1908 | // Already hiding. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1909 | return false; |
| 1910 | } |
| 1911 | if (doAnimation) { |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 1912 | mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false); |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 1913 | if (mWinAnimator.mAnimation == null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1914 | doAnimation = false; |
| 1915 | } |
| 1916 | } |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 1917 | if (doAnimation) { |
| 1918 | mPolicyVisibilityAfterAnim = false; |
| 1919 | } else { |
Craig Mautner | d87946b | 2012-03-29 18:00:19 -0700 | [diff] [blame] | 1920 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 1921 | mPolicyVisibilityAfterAnim = false; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1922 | mPolicyVisibility = false; |
| 1923 | // Window is no longer visible -- make sure if we were waiting |
| 1924 | // for it to be displayed before enabling the display, that |
| 1925 | // we allow the display to be enabled now. |
| 1926 | mService.enableScreenIfNeededLocked(); |
| 1927 | if (mService.mCurrentFocus == this) { |
Filip Gruszczynski | 14b4e57 | 2015-11-03 15:53:55 -0800 | [diff] [blame] | 1928 | if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 1929 | "WindowState.hideLw: setting mFocusMayChange true"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1930 | mService.mFocusMayChange = true; |
| 1931 | } |
| 1932 | } |
| 1933 | if (requestAnim) { |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 1934 | mService.scheduleAnimationLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1935 | } |
| 1936 | return true; |
| 1937 | } |
| 1938 | |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 1939 | public void setAppOpVisibilityLw(boolean state) { |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 1940 | if (mAppOpVisibility != state) { |
| 1941 | mAppOpVisibility = state; |
| 1942 | if (state) { |
| 1943 | // If the policy visibility had last been to hide, then this |
| 1944 | // will incorrectly show at this point since we lost that |
| 1945 | // information. Not a big deal -- for the windows that have app |
| 1946 | // ops modifies they should only be hidden by policy due to the |
| 1947 | // lock screen, and the user won't be changing this if locked. |
| 1948 | // 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] | 1949 | showLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 1950 | } else { |
Craig Mautner | fb32c6e | 2013-02-12 15:08:44 -0800 | [diff] [blame] | 1951 | hideLw(true, true); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 1952 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 1953 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 1954 | } |
| 1955 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1956 | public void pokeDrawLockLw(long timeout) { |
| 1957 | if (isVisibleOrAdding()) { |
| 1958 | if (mDrawLock == null) { |
| 1959 | // We want the tag name to be somewhat stable so that it is easier to correlate |
| 1960 | // in wake lock statistics. So in particular, we don't want to include the |
| 1961 | // window's hash code as in toString(). |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 1962 | final CharSequence tag = getWindowTag(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1963 | mDrawLock = mService.mPowerManager.newWakeLock( |
| 1964 | PowerManager.DRAW_WAKE_LOCK, "Window:" + tag); |
| 1965 | mDrawLock.setReferenceCounted(false); |
| 1966 | mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName)); |
| 1967 | } |
| 1968 | // Each call to acquire resets the timeout. |
| 1969 | if (DEBUG_POWER) { |
| 1970 | Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by " |
| 1971 | + mAttrs.packageName); |
| 1972 | } |
| 1973 | mDrawLock.acquire(timeout); |
| 1974 | } else if (DEBUG_POWER) { |
| 1975 | Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window " |
| 1976 | + "owned by " + mAttrs.packageName); |
| 1977 | } |
| 1978 | } |
| 1979 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1980 | @Override |
| 1981 | public boolean isAlive() { |
| 1982 | return mClient.asBinder().isBinderAlive(); |
| 1983 | } |
| 1984 | |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 1985 | boolean isClosing() { |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 1986 | return mAnimatingExit || (mService.mClosingApps.contains(mAppToken)); |
Craig Mautner | a987d43 | 2012-10-11 14:07:58 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 1989 | boolean isAnimatingWithSavedSurface() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 1990 | return mAnimatingWithSavedSurface; |
| 1991 | } |
| 1992 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 1993 | boolean isAnimatingInvisibleWithSavedSurface() { |
| 1994 | return mAnimatingWithSavedSurface |
| 1995 | && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed); |
| 1996 | } |
| 1997 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 1998 | public void setVisibleBeforeClientHidden() { |
| 1999 | mWasVisibleBeforeClientHidden |= |
| 2000 | (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface); |
| 2001 | } |
| 2002 | |
| 2003 | public void clearVisibleBeforeClientHidden() { |
| 2004 | mWasVisibleBeforeClientHidden = false; |
| 2005 | } |
| 2006 | |
| 2007 | public boolean wasVisibleBeforeClientHidden() { |
| 2008 | return mWasVisibleBeforeClientHidden; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2011 | private boolean shouldSaveSurface() { |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2012 | if (mWinAnimator.mSurfaceController == null) { |
| 2013 | // Don't bother if the surface controller is gone for any reason. |
| 2014 | return false; |
| 2015 | } |
| 2016 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2017 | if (!mWasVisibleBeforeClientHidden) { |
| 2018 | return false; |
| 2019 | } |
| 2020 | |
Wale Ogunwale | 945d197 | 2016-03-23 13:16:41 -0700 | [diff] [blame] | 2021 | if ((mAttrs.flags & FLAG_SECURE) != 0) { |
| 2022 | // We don't save secure surfaces since their content shouldn't be shown while the app |
| 2023 | // isn't on screen and content might leak through during the transition animation with |
| 2024 | // saved surface. |
| 2025 | return false; |
| 2026 | } |
| 2027 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2028 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 2029 | // Don't save surfaces on Svelte devices. |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2030 | return false; |
| 2031 | } |
| 2032 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2033 | Task task = getTask(); |
| 2034 | if (task == null || task.inHomeStack()) { |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2035 | // Don't save surfaces for home stack apps. These usually resume and draw |
| 2036 | // first frame very fast. Saving surfaces are mostly a waste of memory. |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2037 | return false; |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2038 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2039 | |
| 2040 | final AppWindowToken taskTop = task.getTopVisibleAppToken(); |
| 2041 | if (taskTop != null && taskTop != mAppToken) { |
| 2042 | // Don't save if the window is not the topmost window. |
| 2043 | return false; |
| 2044 | } |
| 2045 | |
Jorim Jaggi | 8fa4522 | 2016-02-19 19:54:39 -0800 | [diff] [blame] | 2046 | if (mResizedWhileGone) { |
| 2047 | // Somebody resized our window while we were gone for layout, which means that the |
| 2048 | // client got an old size, so we have an outdated surface here. |
| 2049 | return false; |
| 2050 | } |
| 2051 | |
Robert Carr | 7098dbd | 2016-02-01 12:31:01 -0800 | [diff] [blame] | 2052 | if (DEBUG_DISABLE_SAVING_SURFACES) { |
| 2053 | return false; |
| 2054 | } |
| 2055 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2056 | return mAppToken.shouldSaveSurface(); |
| 2057 | } |
| 2058 | |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 2059 | static final Region sEmptyRegion = new Region(); |
| 2060 | |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2061 | void destroyOrSaveSurface() { |
| 2062 | mSurfaceSaved = shouldSaveSurface(); |
| 2063 | if (mSurfaceSaved) { |
| 2064 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 2065 | Slog.v(TAG, "Saving surface: " + this); |
| 2066 | } |
Chris Craik | 3131bde | 2016-05-06 13:39:08 -0700 | [diff] [blame] | 2067 | // Previous user of the surface may have set a transparent region signaling a portion |
| 2068 | // doesn't need to be composited, so reset to default empty state. |
| 2069 | mSession.setTransparentRegion(mClient, sEmptyRegion); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2070 | |
| 2071 | mWinAnimator.hide("saved surface"); |
| 2072 | mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE; |
| 2073 | setHasSurface(false); |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 2074 | // The client should have disconnected at this point, but if it doesn't, |
| 2075 | // we need to make sure it's disconnected. Otherwise when we reuse the surface |
| 2076 | // the client can't reconnect to the buffer queue, and rendering will fail. |
| 2077 | if (mWinAnimator.mSurfaceController != null) { |
| 2078 | mWinAnimator.mSurfaceController.disconnectInTransaction(); |
| 2079 | } |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 2080 | mAnimatingWithSavedSurface = false; |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2081 | } else { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2082 | mWinAnimator.destroySurfaceLocked(); |
| 2083 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2084 | // Clear animating flags now, since the surface is now gone. (Note this is true even |
| 2085 | // if the surface is saved, to outside world the surface is still NO_SURFACE.) |
| 2086 | mAnimatingExit = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2087 | } |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2088 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2089 | void destroySavedSurface() { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2090 | if (mSurfaceSaved) { |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2091 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 2092 | Slog.v(TAG, "Destroying saved surface: " + this); |
| 2093 | } |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2094 | mWinAnimator.destroySurfaceLocked(); |
| 2095 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2096 | mWasVisibleBeforeClientHidden = false; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2097 | } |
| 2098 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2099 | void restoreSavedSurface() { |
Chong Zhang | 4113ffa | 2016-02-18 12:39:13 -0800 | [diff] [blame] | 2100 | if (!mSurfaceSaved) { |
| 2101 | return; |
| 2102 | } |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2103 | mSurfaceSaved = false; |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2104 | if (mWinAnimator.mSurfaceController != null) { |
| 2105 | setHasSurface(true); |
| 2106 | mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2107 | mAnimatingWithSavedSurface = true; |
Chong Zhang | 6c71c0b | 2016-04-01 15:10:31 -0700 | [diff] [blame] | 2108 | |
| 2109 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 2110 | Slog.v(TAG, "Restoring saved surface: " + this); |
| 2111 | } |
| 2112 | } else { |
| 2113 | // mSurfaceController shouldn't be null if mSurfaceSaved was still true at |
| 2114 | // this point. Even if we destroyed the saved surface because of rotation |
| 2115 | // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf. |
| 2116 | Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this); |
Chong Zhang | eb22e8e | 2016-01-20 19:52:22 -0800 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2120 | boolean canRestoreSurface() { |
| 2121 | return mWasVisibleBeforeClientHidden && mSurfaceSaved; |
| 2122 | } |
| 2123 | |
| 2124 | boolean hasSavedSurface() { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 2125 | return mSurfaceSaved; |
| 2126 | } |
| 2127 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2128 | void clearHasSavedSurface() { |
| 2129 | mSurfaceSaved = false; |
| 2130 | mAnimatingWithSavedSurface = false; |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 2131 | if (mWasVisibleBeforeClientHidden) { |
| 2132 | mAppToken.destroySavedSurfaces(); |
| 2133 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2136 | boolean clearAnimatingWithSavedSurface() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2137 | if (mAnimatingWithSavedSurface) { |
| 2138 | // App has drawn something to its windows, we're no longer animating with |
| 2139 | // the saved surfaces. |
| 2140 | if (DEBUG_ANIM) Slog.d(TAG, |
| 2141 | "clearAnimatingWithSavedSurface(): win=" + this); |
| 2142 | mAnimatingWithSavedSurface = false; |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2143 | return true; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2144 | } |
Chong Zhang | cbbcc0f | 2016-05-17 20:46:58 -0700 | [diff] [blame] | 2145 | return false; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2148 | @Override |
| 2149 | public boolean isDefaultDisplay() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2150 | final DisplayContent displayContent = getDisplayContent(); |
| 2151 | if (displayContent == null) { |
| 2152 | // Only a window that was on a non-default display can be detached from it. |
| 2153 | return false; |
| 2154 | } |
Winson Chung | 47a3e65 | 2014-05-21 16:03:42 -0700 | [diff] [blame] | 2155 | return displayContent.isDefaultDisplay; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 2158 | @Override |
| 2159 | public boolean isDimming() { |
Filip Gruszczynski | 0689ae9 | 2015-10-01 12:30:31 -0700 | [diff] [blame] | 2160 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
| 2161 | return dimLayerUser != null && mDisplayContent != null && |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2162 | mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator); |
Adrian Roos | cd3884d | 2015-02-18 17:25:23 +0100 | [diff] [blame] | 2163 | } |
| 2164 | |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2165 | public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) { |
| 2166 | mShowToOwnerOnly = showToOwnerOnly; |
| 2167 | } |
| 2168 | |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2169 | boolean isHiddenFromUserLocked() { |
Craig Mautner | 341220f | 2012-10-16 15:20:09 -0700 | [diff] [blame] | 2170 | // Attached windows are evaluated based on the window that they are attached to. |
| 2171 | WindowState win = this; |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 2172 | while (win.isChildWindow()) { |
Craig Mautner | 341220f | 2012-10-16 15:20:09 -0700 | [diff] [blame] | 2173 | win = win.mAttachedWindow; |
| 2174 | } |
| 2175 | if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2176 | && win.mAppToken != null && win.mAppToken.showForAllUsers) { |
Jorim Jaggi | dbe44ac | 2016-04-22 19:50:13 -0700 | [diff] [blame] | 2177 | |
| 2178 | // All window frames that are fullscreen extend above status bar, but some don't extend |
| 2179 | // below navigation bar. Thus, check for display frame for top/left and stable frame for |
| 2180 | // bottom right. |
| 2181 | if (win.mFrame.left <= win.mDisplayFrame.left |
| 2182 | && win.mFrame.top <= win.mDisplayFrame.top |
| 2183 | && win.mFrame.right >= win.mStableFrame.right |
| 2184 | && win.mFrame.bottom >= win.mStableFrame.bottom) { |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 2185 | // Is a fullscreen window, like the clock alarm. Show to everyone. |
| 2186 | return false; |
| 2187 | } |
| 2188 | } |
| 2189 | |
Craig Mautner | 341220f | 2012-10-16 15:20:09 -0700 | [diff] [blame] | 2190 | return win.mShowToOwnerOnly |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 2191 | && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid)); |
Craig Mautner | 9dc52bc | 2012-08-06 14:15:42 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2194 | private static void applyInsets(Region outRegion, Rect frame, Rect inset) { |
| 2195 | outRegion.set( |
| 2196 | frame.left + inset.left, frame.top + inset.top, |
| 2197 | frame.right - inset.right, frame.bottom - inset.bottom); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2200 | void getTouchableRegion(Region outRegion) { |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2201 | final Rect frame = mFrame; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2202 | switch (mTouchableInsets) { |
| 2203 | default: |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2204 | case TOUCHABLE_INSETS_FRAME: |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2205 | outRegion.set(frame); |
| 2206 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2207 | case TOUCHABLE_INSETS_CONTENT: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2208 | applyInsets(outRegion, frame, mGivenContentInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2209 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2210 | case TOUCHABLE_INSETS_VISIBLE: |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2211 | applyInsets(outRegion, frame, mGivenVisibleInsets); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2212 | break; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2213 | case TOUCHABLE_INSETS_REGION: { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2214 | final Region givenTouchableRegion = mGivenTouchableRegion; |
| 2215 | outRegion.set(givenTouchableRegion); |
| 2216 | outRegion.translate(frame.left, frame.top); |
| 2217 | break; |
| 2218 | } |
| 2219 | } |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2220 | cropRegionToStackBoundsIfNeeded(outRegion); |
| 2221 | } |
| 2222 | |
| 2223 | void cropRegionToStackBoundsIfNeeded(Region region) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2224 | final Task task = getTask(); |
| 2225 | if (task == null || !task.cropWindowsToStackBounds()) { |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2226 | return; |
| 2227 | } |
| 2228 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2229 | final TaskStack stack = task.mStack; |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 2230 | if (stack == null) { |
| 2231 | return; |
| 2232 | } |
| 2233 | |
| 2234 | stack.getDimBounds(mTmpRect); |
| 2235 | region.op(mTmpRect, Region.Op.INTERSECT); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2236 | } |
| 2237 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2238 | WindowList getWindowList() { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2239 | final DisplayContent displayContent = getDisplayContent(); |
| 2240 | return displayContent == null ? null : displayContent.getWindowList(); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2243 | /** |
| 2244 | * Report a focus change. Must be called with no locks held, and consistently |
| 2245 | * from the same serialized thread (such as dispatched from a handler). |
| 2246 | */ |
| 2247 | public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) { |
| 2248 | try { |
| 2249 | mClient.windowFocusChanged(focused, inTouchMode); |
| 2250 | } catch (RemoteException e) { |
| 2251 | } |
| 2252 | if (mFocusCallbacks != null) { |
| 2253 | final int N = mFocusCallbacks.beginBroadcast(); |
| 2254 | for (int i=0; i<N; i++) { |
| 2255 | IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i); |
| 2256 | try { |
| 2257 | if (focused) { |
| 2258 | obs.focusGained(mWindowId.asBinder()); |
| 2259 | } else { |
| 2260 | obs.focusLost(mWindowId.asBinder()); |
| 2261 | } |
| 2262 | } catch (RemoteException e) { |
| 2263 | } |
| 2264 | } |
| 2265 | mFocusCallbacks.finishBroadcast(); |
| 2266 | } |
| 2267 | } |
| 2268 | |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 2269 | /** |
| 2270 | * Update our current configurations, based on task configuration. |
| 2271 | * |
| 2272 | * @return A configuration suitable for sending to the client. |
| 2273 | */ |
| 2274 | private Configuration updateConfiguration() { |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 2275 | final boolean configChanged = isConfigChanged(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 2276 | getMergedConfig(mMergedConfiguration); |
| 2277 | mConfigHasChanged = false; |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 2278 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) { |
| 2279 | Slog.i(TAG, "Sending new config to window " + this + ": " + |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 2280 | " / mergedConfig=" + mMergedConfiguration); |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 2281 | } |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 2282 | return mMergedConfiguration; |
| 2283 | } |
| 2284 | |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 2285 | private void getMergedConfig(Configuration outConfig) { |
| 2286 | if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) { |
| 2287 | outConfig.setTo(mAppToken.mFrozenMergedConfig.peek()); |
| 2288 | return; |
| 2289 | } |
| 2290 | final Task task = getTask(); |
| 2291 | final Configuration overrideConfig = task != null |
| 2292 | ? task.mOverrideConfig |
| 2293 | : Configuration.EMPTY; |
| 2294 | final Configuration serviceConfig = mService.mCurConfiguration; |
| 2295 | outConfig.setTo(serviceConfig); |
| 2296 | if (overrideConfig != Configuration.EMPTY) { |
| 2297 | outConfig.updateFrom(overrideConfig); |
| 2298 | } |
| 2299 | } |
| 2300 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2301 | void reportResized() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2302 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag()); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2303 | try { |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 2304 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this |
| 2305 | + ": " + mCompatFrame); |
Robert Carr | c24d8f9 | 2016-02-29 16:24:33 -0800 | [diff] [blame] | 2306 | final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null; |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 2307 | if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING) |
| 2308 | Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING"); |
| 2309 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2310 | final Rect frame = mFrame; |
| 2311 | final Rect overscanInsets = mLastOverscanInsets; |
| 2312 | final Rect contentInsets = mLastContentInsets; |
| 2313 | final Rect visibleInsets = mLastVisibleInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2314 | final Rect stableInsets = mLastStableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2315 | final Rect outsets = mLastOutsets; |
Craig Mautner | d1c2c54 | 2014-02-06 10:31:41 -0800 | [diff] [blame] | 2316 | final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING; |
Chet Haase | 8eb48d2 | 2014-09-24 07:31:29 -0700 | [diff] [blame] | 2317 | if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 2318 | && mClient instanceof IWindow.Stub) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2319 | // To prevent deadlock simulate one-way call if win.mClient is a local object. |
| 2320 | mService.mH.post(new Runnable() { |
| 2321 | @Override |
| 2322 | public void run() { |
| 2323 | try { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 2324 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, |
| 2325 | stableInsets, outsets, reportDraw, newConfig); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2326 | } catch (RemoteException e) { |
| 2327 | // Not a remote call, RemoteException won't be raised. |
| 2328 | } |
| 2329 | } |
| 2330 | }); |
| 2331 | } else { |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 2332 | dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2333 | outsets, reportDraw, newConfig); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2334 | } |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 2335 | |
| 2336 | //TODO (multidisplay): Accessibility supported only for the default display. |
| 2337 | if (mService.mAccessibilityController != null |
| 2338 | && getDisplayId() == Display.DEFAULT_DISPLAY) { |
Svetoslav | f7174e8 | 2014-06-12 11:29:35 -0700 | [diff] [blame] | 2339 | mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked(); |
Svetoslav | 4604abc | 2014-06-10 18:59:30 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2342 | mOverscanInsetsChanged = false; |
| 2343 | mContentInsetsChanged = false; |
| 2344 | mVisibleInsetsChanged = false; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2345 | mStableInsetsChanged = false; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2346 | mOutsetsChanged = false; |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 2347 | mResizedWhileNotDragResizingReported = true; |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2348 | mWinAnimator.mSurfaceResized = false; |
| 2349 | } catch (RemoteException e) { |
| 2350 | mOrientationChanging = false; |
| 2351 | mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() |
| 2352 | - mService.mDisplayFreezeTime); |
tiger_huang | 950ee77 | 2014-07-11 18:41:48 +0800 | [diff] [blame] | 2353 | // We are assuming the hosting process is dead or in a zombie state. |
| 2354 | Slog.w(TAG, "Failed to report 'resized' to the client of " + this |
| 2355 | + ", removing this window."); |
| 2356 | mService.mPendingRemove.add(this); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 2357 | mService.mWindowPlacerLocked.requestTraversal(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2358 | } |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2359 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2360 | } |
| 2361 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2362 | Rect getBackdropFrame(Rect frame) { |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 2363 | // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing |
| 2364 | // start even if we haven't received the relayout window, so that the client requests |
| 2365 | // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen |
| 2366 | // until the window to small size, otherwise the multithread renderer will shift last |
| 2367 | // one or more frame to wrong offset. So here we send fullscreen backdrop if either |
| 2368 | // isDragResizing() or isDragResizeChanged() is true. |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 2369 | boolean resizing = isDragResizing() || isDragResizeChanged(); |
| 2370 | if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) { |
| 2371 | return frame; |
| 2372 | } |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2373 | DisplayInfo displayInfo = getDisplayInfo(); |
| 2374 | mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 2375 | return mTmpRect; |
| 2376 | } |
| 2377 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 2378 | @Override |
| 2379 | public int getStackId() { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 2380 | final TaskStack stack = getStack(); |
| 2381 | if (stack == null) { |
| 2382 | return INVALID_STACK_ID; |
| 2383 | } |
| 2384 | return stack.mStackId; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
| 2388 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
| 2389 | Configuration newConfig) throws RemoteException { |
Chong Zhang | edaf305 | 2016-04-22 15:04:31 -0700 | [diff] [blame] | 2390 | final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing; |
| 2391 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2392 | mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets, |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 2393 | reportDraw, newConfig, getBackdropFrame(frame), |
Chong Zhang | edaf305 | 2016-04-22 15:04:31 -0700 | [diff] [blame] | 2394 | forceRelayout, mPolicy.isNavBarForcedShownLw(this)); |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 2395 | mDragResizingChangeReported = true; |
Jorim Jaggi | 253a20f | 2015-11-03 12:38:42 +0100 | [diff] [blame] | 2396 | } |
| 2397 | |
Dianne Hackborn | e3f23a3 | 2013-03-01 13:25:35 -0800 | [diff] [blame] | 2398 | public void registerFocusObserver(IWindowFocusObserver observer) { |
| 2399 | synchronized(mService.mWindowMap) { |
| 2400 | if (mFocusCallbacks == null) { |
| 2401 | mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>(); |
| 2402 | } |
| 2403 | mFocusCallbacks.register(observer); |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | public void unregisterFocusObserver(IWindowFocusObserver observer) { |
| 2408 | synchronized(mService.mWindowMap) { |
| 2409 | if (mFocusCallbacks != null) { |
| 2410 | mFocusCallbacks.unregister(observer); |
| 2411 | } |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | public boolean isFocused() { |
| 2416 | synchronized(mService.mWindowMap) { |
| 2417 | return mService.mCurrentFocus == this; |
| 2418 | } |
| 2419 | } |
| 2420 | |
Filip Gruszczynski | 1a1d831 | 2015-08-26 17:00:47 -0700 | [diff] [blame] | 2421 | boolean inFreeformWorkspace() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 2422 | final Task task = getTask(); |
Chong Zhang | 09b21ef | 2015-09-14 10:20:21 -0700 | [diff] [blame] | 2423 | return task != null && task.inFreeformWorkspace(); |
| 2424 | } |
| 2425 | |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 2426 | @Override |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2427 | public boolean isInMultiWindowMode() { |
Wale Ogunwale | 9185fb0 | 2016-03-11 18:06:14 -0800 | [diff] [blame] | 2428 | final Task task = getTask(); |
| 2429 | return task != null && !task.isFullscreen(); |
| 2430 | } |
| 2431 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 2432 | boolean isDragResizeChanged() { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 2433 | return mDragResizing != computeDragResizing(); |
| 2434 | } |
| 2435 | |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 2436 | /** |
| 2437 | * @return Whether we reported a drag resize change to the application or not already. |
| 2438 | */ |
| 2439 | boolean isDragResizingChangeReported() { |
| 2440 | return mDragResizingChangeReported; |
| 2441 | } |
| 2442 | |
| 2443 | /** |
| 2444 | * Resets the state whether we reported a drag resize change to the app. |
| 2445 | */ |
| 2446 | void resetDragResizingChangeReported() { |
| 2447 | mDragResizingChangeReported = false; |
| 2448 | } |
| 2449 | |
Andrii Kulian | eb1d322 | 2016-05-16 15:17:55 -0700 | [diff] [blame] | 2450 | /** |
| 2451 | * Set whether we got resized but drag resizing flag was false. |
| 2452 | * @see #isResizedWhileNotDragResizing(). |
| 2453 | */ |
| 2454 | void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) { |
| 2455 | mResizedWhileNotDragResizing = resizedWhileNotDragResizing; |
| 2456 | mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing; |
| 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | * Indicates whether we got resized but drag resizing flag was false. In this case, we also |
| 2461 | * need to recreate the surface and defer surface bound updates in order to make sure the |
| 2462 | * buffer contents and the positioning/size stay in sync. |
| 2463 | */ |
| 2464 | boolean isResizedWhileNotDragResizing() { |
| 2465 | return mResizedWhileNotDragResizing; |
| 2466 | } |
| 2467 | |
| 2468 | /** |
| 2469 | * @return Whether we reported "resize while not drag resizing" to the application. |
| 2470 | * @see #isResizedWhileNotDragResizing() |
| 2471 | */ |
| 2472 | boolean isResizedWhileNotDragResizingReported() { |
| 2473 | return mResizedWhileNotDragResizingReported; |
| 2474 | } |
| 2475 | |
Jorim Jaggi | dcf467c | 2015-11-05 13:59:32 +0100 | [diff] [blame] | 2476 | int getResizeMode() { |
| 2477 | return mResizeMode; |
| 2478 | } |
| 2479 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2480 | boolean computeDragResizing() { |
Wale Ogunwale | 5a2f2cb | 2015-09-17 12:31:55 -0700 | [diff] [blame] | 2481 | final Task task = getTask(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 2482 | if (task == null) { |
| 2483 | return false; |
| 2484 | } |
Jorim Jaggi | dd6e4c1 | 2016-02-17 22:13:43 -0800 | [diff] [blame] | 2485 | if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) { |
| 2486 | |
| 2487 | // Floating windows never enter drag resize mode. |
| 2488 | return false; |
| 2489 | } |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 2490 | if (task.isDragResizing()) { |
| 2491 | return true; |
| 2492 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 2493 | |
| 2494 | // If the bounds are currently frozen, it means that the layout size that the app sees |
| 2495 | // and the bounds we clip this window to might be different. In order to avoid holes, we |
| 2496 | // simulate that we are still resizing so the app fills the hole with the resizing |
| 2497 | // background. |
| 2498 | return (mDisplayContent.mDividerControllerLocked.isResizing() |
| 2499 | || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) && |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 2500 | !task.inFreeformWorkspace() && !isGoneForLayoutLw(); |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 2501 | |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | void setDragResizing() { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 2505 | final boolean resizing = computeDragResizing(); |
| 2506 | if (resizing == mDragResizing) { |
| 2507 | return; |
| 2508 | } |
| 2509 | mDragResizing = resizing; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2510 | final Task task = getTask(); |
| 2511 | if (task != null && task.isDragResizing()) { |
| 2512 | mResizeMode = task.getDragResizeMode(); |
| 2513 | } else { |
| 2514 | mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing() |
| 2515 | ? DRAG_RESIZE_MODE_DOCKED_DIVIDER |
| 2516 | : DRAG_RESIZE_MODE_FREEFORM; |
| 2517 | } |
Chong Zhang | 3005e75 | 2015-09-18 18:46:28 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | boolean isDragResizing() { |
| 2521 | return mDragResizing; |
Skuhne | f932e56 | 2015-08-20 12:07:30 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
Robert Carr | 2487ce7 | 2016-04-07 15:18:45 -0700 | [diff] [blame] | 2524 | boolean isDockedResizing() { |
| 2525 | return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER; |
| 2526 | } |
| 2527 | |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2528 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
Wale Ogunwale | 30cc7bf | 2015-02-04 16:47:57 -0800 | [diff] [blame] | 2529 | final TaskStack stack = getStack(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2530 | pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId()); |
Wale Ogunwale | 30cc7bf | 2015-02-04 16:47:57 -0800 | [diff] [blame] | 2531 | if (stack != null) { |
| 2532 | pw.print(" stackId="); pw.print(stack.mStackId); |
| 2533 | } |
Wale Ogunwale | 4c5aa517 | 2016-04-19 11:29:05 -0700 | [diff] [blame] | 2534 | if (mNotOnAppsDisplay) { |
| 2535 | pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay); |
| 2536 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 2537 | pw.print(" mSession="); pw.print(mSession); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2538 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 2539 | pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2540 | pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly); |
| 2541 | pw.print(" package="); pw.print(mAttrs.packageName); |
| 2542 | pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2543 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2544 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| 2545 | pw.print(" h="); pw.print(mRequestedHeight); |
| 2546 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1743b64 | 2012-03-12 17:04:43 -0700 | [diff] [blame] | 2547 | if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) { |
| 2548 | pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth); |
| 2549 | pw.print(" h="); pw.println(mLastRequestedHeight); |
| 2550 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 2551 | if (isChildWindow() || mLayoutAttached) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2552 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 2553 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 2554 | } |
| 2555 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 2556 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 2557 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| 2558 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 2559 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| 2560 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2561 | if (dumpAll) { |
| 2562 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 2563 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 2564 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 2565 | pw.print((mTargetAppToken != null ? |
| 2566 | mTargetAppToken.mAppAnimator.animLayerAdjustment |
| 2567 | : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0))); |
Craig Mautner | c2f9be0 | 2012-03-27 17:32:29 -0700 | [diff] [blame] | 2568 | pw.print("="); pw.print(mWinAnimator.mAnimLayer); |
| 2569 | pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer); |
Dianne Hackborn | 6d05fd3 | 2011-11-19 14:36:15 -0800 | [diff] [blame] | 2570 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2571 | if (dumpAll) { |
| 2572 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 2573 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 2574 | if (mAppToken != null) { |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 2575 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 2576 | pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()="); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 2577 | pw.print(isAnimatingWithSavedSurface()); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2578 | pw.print(" mAppDied=");pw.println(mAppDied); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2579 | } |
| 2580 | if (mTargetAppToken != null) { |
| 2581 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 2582 | } |
| 2583 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 2584 | pw.print(Integer.toHexString(mViewVisibility)); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2585 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 2586 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2587 | pw.print(prefix); pw.print("mSeq="); pw.print(mSeq); |
| 2588 | pw.print(" mSystemUiVisibility=0x"); |
| 2589 | pw.println(Integer.toHexString(mSystemUiVisibility)); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2590 | } |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2591 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility |
| 2592 | || mAttachedHidden) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2593 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 2594 | pw.print(mPolicyVisibility); |
| 2595 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 2596 | pw.print(mPolicyVisibilityAfterAnim); |
Dianne Hackborn | b6b23ec | 2013-02-11 19:29:06 -0800 | [diff] [blame] | 2597 | pw.print(" mAppOpVisibility="); |
| 2598 | pw.print(mAppOpVisibility); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2599 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 2600 | } |
Dianne Hackborn | b7ff51b | 2012-01-23 19:15:27 -0800 | [diff] [blame] | 2601 | if (!mRelayoutCalled || mLayoutNeeded) { |
| 2602 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled); |
| 2603 | pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2604 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2605 | if (mXOffset != 0 || mYOffset != 0) { |
| 2606 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 2607 | pw.print(" y="); pw.println(mYOffset); |
| 2608 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2609 | if (dumpAll) { |
| 2610 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 2611 | mGivenContentInsets.printShortString(pw); |
| 2612 | pw.print(" mGivenVisibleInsets="); |
| 2613 | mGivenVisibleInsets.printShortString(pw); |
| 2614 | pw.println(); |
| 2615 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 2616 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 2617 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 2618 | Region region = new Region(); |
| 2619 | getTouchableRegion(region); |
| 2620 | pw.print(prefix); pw.print("touchable region="); pw.println(region); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2621 | } |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 2622 | pw.print(prefix); pw.print("mMergedConfiguration="); pw.println(mMergedConfiguration); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2623 | } |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 2624 | pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface); |
Filip Gruszczynski | 2a6a2c2 | 2015-10-14 12:00:53 -0700 | [diff] [blame] | 2625 | pw.print(" mShownPosition="); mShownPosition.printShortString(pw); |
Chong Zhang | a8975bd | 2016-01-28 17:13:47 -0800 | [diff] [blame] | 2626 | pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay()); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 2627 | pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface()); |
| 2628 | pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2629 | if (dumpAll) { |
| 2630 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 2631 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 2632 | pw.println(); |
| 2633 | } |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2634 | if (mEnforceSizeCompat) { |
| 2635 | pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw); |
Dianne Hackborn | ffb3d93 | 2011-05-17 17:44:51 -0700 | [diff] [blame] | 2636 | pw.println(); |
| 2637 | } |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2638 | if (dumpAll) { |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2639 | pw.print(prefix); pw.print("Frames: containing="); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2640 | mContainingFrame.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2641 | pw.print(" parent="); mParentFrame.printShortString(pw); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2642 | pw.println(); |
| 2643 | pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw); |
| 2644 | pw.print(" overscan="); mOverscanFrame.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2645 | pw.println(); |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2646 | pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2647 | pw.print(" visible="); mVisibleFrame.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2648 | pw.println(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2649 | pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw); |
| 2650 | pw.println(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2651 | pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw); |
| 2652 | pw.println(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2653 | pw.print(prefix); pw.print("Cur insets: overscan="); |
| 2654 | mOverscanInsets.printShortString(pw); |
| 2655 | pw.print(" content="); mContentInsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2656 | pw.print(" visible="); mVisibleInsets.printShortString(pw); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2657 | pw.print(" stable="); mStableInsets.printShortString(pw); |
Wale Ogunwale | 6bab4cf | 2016-04-07 12:23:08 -0700 | [diff] [blame] | 2658 | pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2659 | pw.print(" outsets="); mOutsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2660 | pw.println(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2661 | pw.print(prefix); pw.print("Lst insets: overscan="); |
| 2662 | mLastOverscanInsets.printShortString(pw); |
| 2663 | pw.print(" content="); mLastContentInsets.printShortString(pw); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2664 | pw.print(" visible="); mLastVisibleInsets.printShortString(pw); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 2665 | pw.print(" stable="); mLastStableInsets.printShortString(pw); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 2666 | pw.print(" physical="); mLastOutsets.printShortString(pw); |
| 2667 | pw.print(" outset="); mLastOutsets.printShortString(pw); |
Dianne Hackborn | a44abeb | 2011-08-08 19:24:01 -0700 | [diff] [blame] | 2668 | pw.println(); |
| 2669 | } |
Dianne Hackborn | 529e744 | 2012-11-01 14:22:28 -0700 | [diff] [blame] | 2670 | pw.print(prefix); pw.print(mWinAnimator); pw.println(":"); |
| 2671 | mWinAnimator.dump(pw, prefix + " ", dumpAll); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2672 | if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) { |
| 2673 | pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2674 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 2675 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 2676 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 2677 | } |
| 2678 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| 2679 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 2680 | pw.print(mOrientationChanging); |
| 2681 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 2682 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| 2683 | } |
Dianne Hackborn | a57c695 | 2013-03-29 14:46:40 -0700 | [diff] [blame] | 2684 | if (mLastFreezeDuration != 0) { |
| 2685 | pw.print(prefix); pw.print("mLastFreezeDuration="); |
| 2686 | TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println(); |
| 2687 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2688 | if (mHScale != 1 || mVScale != 1) { |
| 2689 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 2690 | pw.print(" mVScale="); pw.println(mVScale); |
| 2691 | } |
| 2692 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| 2693 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 2694 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 2695 | } |
| 2696 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 2697 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 2698 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 2699 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2700 | if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE |
| 2701 | || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) { |
| 2702 | pw.print(prefix); pw.print("mWallpaperDisplayOffsetX="); |
| 2703 | pw.print(mWallpaperDisplayOffsetX); |
| 2704 | pw.print(" mWallpaperDisplayOffsetY="); |
| 2705 | pw.println(mWallpaperDisplayOffsetY); |
| 2706 | } |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2707 | if (mDrawLock != null) { |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 2708 | pw.print(prefix); pw.println("mDrawLock=" + mDrawLock); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 2709 | } |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 2710 | if (isDragResizing()) { |
| 2711 | pw.print(prefix); pw.println("isDragResizing=" + isDragResizing()); |
| 2712 | } |
| 2713 | if (computeDragResizing()) { |
| 2714 | pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing()); |
| 2715 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2716 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2717 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2718 | String makeInputChannelName() { |
| 2719 | return Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2720 | + " " + getWindowTag(); |
| 2721 | } |
| 2722 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 2723 | CharSequence getWindowTag() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2724 | CharSequence tag = mAttrs.getTitle(); |
| 2725 | if (tag == null || tag.length() <= 0) { |
| 2726 | tag = mAttrs.packageName; |
| 2727 | } |
| 2728 | return tag; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | @Override |
| 2732 | public String toString() { |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2733 | final CharSequence title = getWindowTag(); |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2734 | if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 2735 | mLastTitle = title; |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2736 | mWasExiting = mAnimatingExit; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2737 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 2738 | + " u" + UserHandle.getUserId(mSession.mUid) |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 2739 | + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2740 | } |
| 2741 | return mStringNameCache; |
| 2742 | } |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 2743 | |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 2744 | void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) { |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 2745 | if (mHScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 2746 | clipRect.left = (int) (clipRect.left / mHScale); |
| 2747 | clipRect.right = (int) Math.ceil(clipRect.right / mHScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 2748 | } |
| 2749 | if (mVScale >= 0) { |
Chia-I Wu | e6bcaf1 | 2016-05-27 10:58:48 +0800 | [diff] [blame] | 2750 | clipRect.top = (int) (clipRect.top / mVScale); |
| 2751 | clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale); |
Robert Carr | 58f2913 | 2015-10-29 14:19:05 -0700 | [diff] [blame] | 2752 | } |
| 2753 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 2754 | |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 2755 | void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) { |
| 2756 | final int pw = containingFrame.width(); |
| 2757 | final int ph = containingFrame.height(); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 2758 | final Task task = getTask(); |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 2759 | final boolean nonFullscreenTask = isInMultiWindowMode(); |
Jorim Jaggi | 5f23a57 | 2016-04-22 15:05:50 -0700 | [diff] [blame] | 2760 | final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0; |
| 2761 | |
| 2762 | // We need to fit it to the display if either |
| 2763 | // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless |
| 2764 | // windows) |
| 2765 | // b) If it's a child window, we also need to fit it to the display unless |
| 2766 | // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popup and similar windows on screen, |
| 2767 | // but SurfaceViews want to be always at a specific location so we don't fit it to the |
| 2768 | // display. |
| 2769 | final boolean fitToDisplay = (task == null || !nonFullscreenTask) |
| 2770 | || (isChildWindow() && !noLimits); |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 2771 | float x, y; |
| 2772 | int w,h; |
| 2773 | |
| 2774 | if ((mAttrs.flags & FLAG_SCALED) != 0) { |
| 2775 | if (mAttrs.width < 0) { |
| 2776 | w = pw; |
| 2777 | } else if (mEnforceSizeCompat) { |
| 2778 | w = (int)(mAttrs.width * mGlobalScale + .5f); |
| 2779 | } else { |
| 2780 | w = mAttrs.width; |
| 2781 | } |
| 2782 | if (mAttrs.height < 0) { |
| 2783 | h = ph; |
| 2784 | } else if (mEnforceSizeCompat) { |
| 2785 | h = (int)(mAttrs.height * mGlobalScale + .5f); |
| 2786 | } else { |
| 2787 | h = mAttrs.height; |
| 2788 | } |
| 2789 | } else { |
| 2790 | if (mAttrs.width == MATCH_PARENT) { |
| 2791 | w = pw; |
| 2792 | } else if (mEnforceSizeCompat) { |
| 2793 | w = (int)(mRequestedWidth * mGlobalScale + .5f); |
| 2794 | } else { |
| 2795 | w = mRequestedWidth; |
| 2796 | } |
| 2797 | if (mAttrs.height == MATCH_PARENT) { |
| 2798 | h = ph; |
| 2799 | } else if (mEnforceSizeCompat) { |
| 2800 | h = (int)(mRequestedHeight * mGlobalScale + .5f); |
| 2801 | } else { |
| 2802 | h = mRequestedHeight; |
| 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | if (mEnforceSizeCompat) { |
| 2807 | x = mAttrs.x * mGlobalScale; |
| 2808 | y = mAttrs.y * mGlobalScale; |
| 2809 | } else { |
| 2810 | x = mAttrs.x; |
| 2811 | y = mAttrs.y; |
| 2812 | } |
| 2813 | |
Robert Carr | 1d2bacb | 2016-03-30 14:29:35 -0700 | [diff] [blame] | 2814 | if (nonFullscreenTask && !layoutInParentFrame()) { |
Wale Ogunwale | 79f268d | 2015-12-18 08:25:47 -0800 | [diff] [blame] | 2815 | // 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] | 2816 | // required by {@link Gravity#apply} call. |
| 2817 | w = Math.min(w, pw); |
| 2818 | h = Math.min(h, ph); |
| 2819 | } |
| 2820 | |
| 2821 | // Set mFrame |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 2822 | Gravity.apply(mAttrs.gravity, w, h, containingFrame, |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 2823 | (int) (x + mAttrs.horizontalMargin * pw), |
| 2824 | (int) (y + mAttrs.verticalMargin * ph), mFrame); |
| 2825 | |
| 2826 | // Now make sure the window fits in the overall display frame. |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 2827 | if (fitToDisplay) { |
Jorim Jaggi | f583427 | 2016-04-04 20:25:41 -0700 | [diff] [blame] | 2828 | Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame); |
Robert Carr | e627558 | 2016-02-29 15:45:45 -0800 | [diff] [blame] | 2829 | } |
Robert Carr | 6e18c5e | 2016-02-29 15:57:13 -0800 | [diff] [blame] | 2830 | |
| 2831 | // We need to make sure we update the CompatFrame as it is used for |
| 2832 | // cropping decisions, etc, on systems where we lack a decor layer. |
| 2833 | mCompatFrame.set(mFrame); |
| 2834 | if (mEnforceSizeCompat) { |
| 2835 | // See comparable block in computeFrameLw. |
| 2836 | mCompatFrame.scale(mInvGlobalScale); |
| 2837 | } |
Robert Carr | 31e2848 | 2015-12-02 16:53:18 -0800 | [diff] [blame] | 2838 | } |
Robert Carr | 51a1b87 | 2015-12-08 14:03:13 -0800 | [diff] [blame] | 2839 | |
| 2840 | boolean isChildWindow() { |
| 2841 | return mAttachedWindow != null; |
| 2842 | } |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 2843 | |
Robert Carr | f3b72c7 | 2016-03-21 18:16:39 -0700 | [diff] [blame] | 2844 | boolean layoutInParentFrame() { |
| 2845 | return isChildWindow() && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0; |
| 2846 | } |
| 2847 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 2848 | void setReplacing(boolean animate) { |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 2849 | if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0 |
| 2850 | || mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 2851 | // We don't set replacing on starting windows since they are added by window manager and |
| 2852 | // not the client so won't be replaced by the client. |
| 2853 | return; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 2854 | } |
Wale Ogunwale | 6d8e06b | 2016-01-05 10:43:25 -0800 | [diff] [blame] | 2855 | |
| 2856 | mWillReplaceWindow = true; |
| 2857 | mReplacingWindow = null; |
| 2858 | mAnimateReplacingWindow = animate; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 2859 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2860 | |
| 2861 | void resetReplacing() { |
| 2862 | mWillReplaceWindow = false; |
| 2863 | mReplacingWindow = null; |
| 2864 | mAnimateReplacingWindow = false; |
| 2865 | } |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 2866 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 2867 | void requestUpdateWallpaperIfNeeded() { |
| 2868 | if (mDisplayContent != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 2869 | mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
| 2870 | mDisplayContent.layoutNeeded = true; |
| 2871 | mService.mWindowPlacerLocked.requestTraversal(); |
| 2872 | } |
| 2873 | } |
| 2874 | |
Vladislav Kaznacheev | 989b58a | 2016-02-10 12:19:33 -0800 | [diff] [blame] | 2875 | float translateToWindowX(float x) { |
| 2876 | float winX = x - mFrame.left; |
| 2877 | if (mEnforceSizeCompat) { |
| 2878 | winX *= mGlobalScale; |
| 2879 | } |
| 2880 | return winX; |
| 2881 | } |
| 2882 | |
| 2883 | float translateToWindowY(float y) { |
| 2884 | float winY = y - mFrame.top; |
| 2885 | if (mEnforceSizeCompat) { |
| 2886 | winY *= mGlobalScale; |
| 2887 | } |
| 2888 | return winY; |
| 2889 | } |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 2890 | |
Robert Carr | 9fe459d | 2016-04-07 23:32:28 -0700 | [diff] [blame] | 2891 | void transferDimToReplacement() { |
| 2892 | final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser(); |
| 2893 | if (dimLayerUser != null && mDisplayContent != null) { |
| 2894 | mDisplayContent.mDimLayerController.applyDim(dimLayerUser, |
| 2895 | mReplacingWindow.mWinAnimator, |
| 2896 | (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false); |
| 2897 | } |
| 2898 | } |
| 2899 | |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 2900 | // During activity relaunch due to resize, we sometimes use window replacement |
| 2901 | // for only child windows (as the main window is handled by window preservation) |
| 2902 | // and the big surface. |
| 2903 | // |
| 2904 | // Though windows of TYPE_APPLICATION (as opposed to TYPE_BASE_APPLICATION) |
| 2905 | // are not children in the sense of an attached window, we also want to replace |
| 2906 | // them at such phases, as they won't be covered by window preservation, |
| 2907 | // and in general we expect them to return following relaunch. |
| 2908 | boolean shouldBeReplacedWithChildren() { |
| 2909 | return isChildWindow() || mAttrs.type == TYPE_APPLICATION; |
| 2910 | } |
satok | cef37fb | 2011-10-24 21:49:38 +0900 | [diff] [blame] | 2911 | } |