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