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