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