Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 21 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 22 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
| 23 | import static android.view.Surface.ROTATION_270; |
| 24 | import static android.view.Surface.ROTATION_90; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 25 | import static android.view.WindowManager.DOCKED_BOTTOM; |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 26 | import static android.view.WindowManager.DOCKED_INVALID; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 27 | import static android.view.WindowManager.DOCKED_LEFT; |
| 28 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 29 | import static android.view.WindowManager.DOCKED_TOP; |
Evan Rosky | 35630df | 2018-10-31 10:22:08 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.TRANSIT_NONE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 31 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT; |
| 32 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_RIGHT; |
Evan Rosky | 35630df | 2018-10-31 10:22:08 -0700 | [diff] [blame] | 33 | |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 34 | import static com.android.server.wm.AppTransition.DEFAULT_APP_TRANSITION_DURATION; |
| 35 | import static com.android.server.wm.AppTransition.TOUCH_RESPONSE_INTERPOLATOR; |
Evan Rosky | 35630df | 2018-10-31 10:22:08 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.DockedStackDividerControllerProto.MINIMIZED_DOCK; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 38 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 39 | import static com.android.server.wm.WindowManagerService.LAYER_OFFSET_DIM; |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 40 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 41 | import android.content.Context; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 42 | import android.content.res.Configuration; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 43 | import android.graphics.Rect; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 44 | import android.os.RemoteCallbackList; |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 45 | import android.os.RemoteException; |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 46 | import android.util.ArraySet; |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 47 | import android.util.Slog; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 48 | import android.util.proto.ProtoOutputStream; |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 49 | import android.view.DisplayCutout; |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 50 | import android.view.DisplayInfo; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 51 | import android.view.IDockedStackListener; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 52 | import android.view.animation.AnimationUtils; |
| 53 | import android.view.animation.Interpolator; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 54 | import android.view.animation.PathInterpolator; |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 55 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 56 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 57 | import com.android.internal.policy.DividerSnapAlgorithm; |
| 58 | import com.android.internal.policy.DockedDividerUtils; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 59 | import com.android.server.LocalServices; |
Yohei Yukawa | c3de83e | 2018-08-28 16:09:34 -0700 | [diff] [blame] | 60 | import com.android.server.inputmethod.InputMethodManagerInternal; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 61 | import com.android.server.wm.WindowManagerService.H; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 62 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 63 | import java.io.PrintWriter; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 64 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 65 | /** |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 66 | * Keeps information about the docked stack divider. |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 67 | */ |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 68 | public class DockedStackDividerController { |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 69 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 70 | private static final String TAG = TAG_WITH_CLASS_NAME ? "DockedStackDividerController" : TAG_WM; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 71 | |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 72 | /** |
| 73 | * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip |
| 74 | * revealing surface at the earliest. |
| 75 | */ |
| 76 | private static final float CLIP_REVEAL_MEET_EARLIEST = 0.6f; |
| 77 | |
| 78 | /** |
| 79 | * The fraction during the maximize/clip reveal animation the divider meets the edge of the clip |
| 80 | * revealing surface at the latest. |
| 81 | */ |
| 82 | private static final float CLIP_REVEAL_MEET_LAST = 1f; |
| 83 | |
| 84 | /** |
| 85 | * If the app translates at least CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance, we start |
| 86 | * meet somewhere between {@link #CLIP_REVEAL_MEET_LAST} and {@link #CLIP_REVEAL_MEET_EARLIEST}. |
| 87 | */ |
| 88 | private static final float CLIP_REVEAL_MEET_FRACTION_MIN = 0.4f; |
| 89 | |
| 90 | /** |
| 91 | * If the app translates equals or more than CLIP_REVEAL_MEET_FRACTION_MIN * minimize distance, |
| 92 | * we meet at {@link #CLIP_REVEAL_MEET_EARLIEST}. |
| 93 | */ |
| 94 | private static final float CLIP_REVEAL_MEET_FRACTION_MAX = 0.8f; |
| 95 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 96 | private static final Interpolator IME_ADJUST_ENTRY_INTERPOLATOR = |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 97 | new PathInterpolator(0.2f, 0f, 0.1f, 1f); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 98 | |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 99 | private static final long IME_ADJUST_ANIM_DURATION = 280; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 100 | |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 101 | private static final long IME_ADJUST_DRAWN_TIMEOUT = 200; |
| 102 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 103 | private static final int DIVIDER_WIDTH_INACTIVE_DP = 4; |
| 104 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 105 | private final WindowManagerService mService; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 106 | private final DisplayContent mDisplayContent; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 107 | private int mDividerWindowWidth; |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 108 | private int mDividerWindowWidthInactive; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 109 | private int mDividerInsets; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 110 | private int mTaskHeightInMinimizedMode; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 111 | private boolean mResizing; |
| 112 | private WindowState mWindow; |
| 113 | private final Rect mTmpRect = new Rect(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 114 | private final Rect mTmpRect2 = new Rect(); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 115 | private final Rect mTmpRect3 = new Rect(); |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 116 | private final Rect mLastRect = new Rect(); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 117 | private boolean mLastVisibility = false; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 118 | private final RemoteCallbackList<IDockedStackListener> mDockedStackListeners |
| 119 | = new RemoteCallbackList<>(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 120 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 121 | private boolean mMinimizedDock; |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 122 | private int mOriginalDockedSide = DOCKED_INVALID; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 123 | private boolean mAnimatingForMinimizedDockedStack; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 124 | private boolean mAnimationStarted; |
| 125 | private long mAnimationStartTime; |
| 126 | private float mAnimationStart; |
| 127 | private float mAnimationTarget; |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 128 | private long mAnimationDuration; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 129 | private boolean mAnimationStartDelayed; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 130 | private final Interpolator mMinimizedDockInterpolator; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 131 | private float mMaximizeMeetFraction; |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 132 | private final Rect mTouchRegion = new Rect(); |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 133 | private boolean mAnimatingForIme; |
| 134 | private boolean mAdjustedForIme; |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 135 | private int mImeHeight; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 136 | private WindowState mDelayedImeWin; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 137 | private boolean mAdjustedForDivider; |
| 138 | private float mDividerAnimationStart; |
| 139 | private float mDividerAnimationTarget; |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 140 | float mLastAnimationProgress; |
| 141 | float mLastDividerProgress; |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 142 | private final DividerSnapAlgorithm[] mSnapAlgorithmForRotation = new DividerSnapAlgorithm[4]; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 143 | private boolean mImeHideRequested; |
Jorim Jaggi | f93ac2b | 2017-10-25 15:20:24 +0200 | [diff] [blame] | 144 | private final Rect mLastDimLayerRect = new Rect(); |
| 145 | private float mLastDimLayerAlpha; |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 146 | private TaskStack mDimmedStack; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 147 | |
| 148 | DockedStackDividerController(WindowManagerService service, DisplayContent displayContent) { |
| 149 | mService = service; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 150 | mDisplayContent = displayContent; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 151 | final Context context = service.mContext; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 152 | mMinimizedDockInterpolator = AnimationUtils.loadInterpolator( |
| 153 | context, android.R.interpolator.fast_out_slow_in); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 154 | loadDimens(); |
| 155 | } |
| 156 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 157 | int getSmallestWidthDpForBounds(Rect bounds) { |
| 158 | final DisplayInfo di = mDisplayContent.getDisplayInfo(); |
| 159 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 160 | final int baseDisplayWidth = mDisplayContent.mBaseDisplayWidth; |
| 161 | final int baseDisplayHeight = mDisplayContent.mBaseDisplayHeight; |
| 162 | int minWidth = Integer.MAX_VALUE; |
| 163 | |
| 164 | // Go through all screen orientations and find the orientation in which the task has the |
| 165 | // smallest width. |
| 166 | for (int rotation = 0; rotation < 4; rotation++) { |
| 167 | mTmpRect.set(bounds); |
| 168 | mDisplayContent.rotateBounds(di.rotation, rotation, mTmpRect); |
| 169 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 170 | mTmpRect2.set(0, 0, |
| 171 | rotated ? baseDisplayHeight : baseDisplayWidth, |
| 172 | rotated ? baseDisplayWidth : baseDisplayHeight); |
| 173 | final int orientation = mTmpRect2.width() <= mTmpRect2.height() |
| 174 | ? ORIENTATION_PORTRAIT |
| 175 | : ORIENTATION_LANDSCAPE; |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 176 | final int dockSide = getDockSide(mTmpRect, mTmpRect2, orientation, rotation); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 177 | final int position = DockedDividerUtils.calculatePositionForBounds(mTmpRect, dockSide, |
| 178 | getContentWidth()); |
| 179 | |
Adrian Roos | 2aa0fcd | 2018-02-19 18:07:49 +0100 | [diff] [blame] | 180 | final DisplayCutout displayCutout = mDisplayContent.calculateDisplayCutoutForRotation( |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 181 | rotation).getDisplayCutout(); |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 182 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 183 | // Since we only care about feasible states, snap to the closest snap target, like it |
| 184 | // would happen when actually rotating the screen. |
| 185 | final int snappedPosition = mSnapAlgorithmForRotation[rotation] |
| 186 | .calculateNonDismissingSnapTarget(position).position; |
| 187 | DockedDividerUtils.calculateBoundsForPosition(snappedPosition, dockSide, mTmpRect, |
| 188 | mTmpRect2.width(), mTmpRect2.height(), getContentWidth()); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 189 | mDisplayContent.getDisplayPolicy().getStableInsetsLw(rotation, mTmpRect2.width(), |
| 190 | mTmpRect2.height(), displayCutout, mTmpRect3); |
Winson Chung | bdc646f | 2017-02-13 12:12:22 -0800 | [diff] [blame] | 191 | mService.intersectDisplayInsetBounds(mTmpRect2, mTmpRect3, mTmpRect); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 192 | minWidth = Math.min(mTmpRect.width(), minWidth); |
| 193 | } |
| 194 | return (int) (minWidth / mDisplayContent.getDisplayMetrics().density); |
| 195 | } |
| 196 | |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 197 | /** |
| 198 | * Get the current docked side. Determined by its location of {@param bounds} within |
| 199 | * {@param displayRect} but if both are the same, it will try to dock to each side and determine |
| 200 | * if allowed in its respected {@param orientation}. |
| 201 | * |
| 202 | * @param bounds bounds of the docked task to get which side is docked |
| 203 | * @param displayRect bounds of the display that contains the docked task |
| 204 | * @param orientation the origination of device |
| 205 | * @return current docked side |
| 206 | */ |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 207 | int getDockSide(Rect bounds, Rect displayRect, int orientation, int rotation) { |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 208 | if (orientation == Configuration.ORIENTATION_PORTRAIT) { |
| 209 | // Portrait mode, docked either at the top or the bottom. |
| 210 | final int diff = (displayRect.bottom - bounds.bottom) - (bounds.top - displayRect.top); |
| 211 | if (diff > 0) { |
| 212 | return DOCKED_TOP; |
| 213 | } else if (diff < 0) { |
| 214 | return DOCKED_BOTTOM; |
| 215 | } |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 216 | return canPrimaryStackDockTo(DOCKED_TOP, displayRect, rotation) |
| 217 | ? DOCKED_TOP : DOCKED_BOTTOM; |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 218 | } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 219 | // Landscape mode, docked either on the left or on the right. |
| 220 | final int diff = (displayRect.right - bounds.right) - (bounds.left - displayRect.left); |
| 221 | if (diff > 0) { |
| 222 | return DOCKED_LEFT; |
| 223 | } else if (diff < 0) { |
| 224 | return DOCKED_RIGHT; |
| 225 | } |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 226 | return canPrimaryStackDockTo(DOCKED_LEFT, displayRect, rotation) |
| 227 | ? DOCKED_LEFT : DOCKED_RIGHT; |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 228 | } |
| 229 | return DOCKED_INVALID; |
| 230 | } |
| 231 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 232 | void getHomeStackBoundsInDockedMode(Configuration parentConfig, int dockSide, Rect outBounds) { |
| 233 | final DisplayCutout displayCutout = mDisplayContent.getDisplayInfo().displayCutout; |
| 234 | final int displayWidth = parentConfig.windowConfiguration.getBounds().width(); |
| 235 | final int displayHeight = parentConfig.windowConfiguration.getBounds().height(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 236 | mDisplayContent.getDisplayPolicy().getStableInsetsLw( |
| 237 | parentConfig.windowConfiguration.getRotation(), displayWidth, displayHeight, |
| 238 | displayCutout, mTmpRect); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 239 | int dividerSize = mDividerWindowWidth - 2 * mDividerInsets; |
Matthew Ng | a9e173d | 2017-05-17 15:03:18 -0700 | [diff] [blame] | 240 | // The offset in the left (landscape)/top (portrait) is calculated with the minimized |
| 241 | // offset value with the divider size and any system insets in that direction. |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 242 | if (parentConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 243 | outBounds.set(0, mTaskHeightInMinimizedMode + dividerSize + mTmpRect.top, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 244 | displayWidth, displayHeight); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 245 | } else { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 246 | // In landscape also inset the left/right side with the status bar height to match the |
Matthew Ng | a9e173d | 2017-05-17 15:03:18 -0700 | [diff] [blame] | 247 | // minimized size height in portrait mode. |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 248 | final int primaryTaskWidth = mTaskHeightInMinimizedMode + dividerSize + mTmpRect.top; |
| 249 | int left = mTmpRect.left; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 250 | int right = displayWidth - mTmpRect.right; |
| 251 | if (dockSide == DOCKED_LEFT) { |
| 252 | left += primaryTaskWidth; |
| 253 | } else if (dockSide == DOCKED_RIGHT) { |
| 254 | right -= primaryTaskWidth; |
Matthew Ng | 62c7846 | 2018-04-09 14:43:21 -0700 | [diff] [blame] | 255 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 256 | outBounds.set(left, 0, right, displayHeight); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | boolean isHomeStackResizable() { |
| 261 | final TaskStack homeStack = mDisplayContent.getHomeStack(); |
| 262 | if (homeStack == null) { |
| 263 | return false; |
| 264 | } |
| 265 | final Task homeTask = homeStack.findHomeTask(); |
| 266 | return homeTask != null && homeTask.isResizeable(); |
| 267 | } |
| 268 | |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 269 | private void initSnapAlgorithmForRotations() { |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 270 | final Configuration baseConfig = mDisplayContent.getConfiguration(); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 271 | |
| 272 | // Initialize the snap algorithms for all 4 screen orientations. |
| 273 | final Configuration config = new Configuration(); |
| 274 | for (int rotation = 0; rotation < 4; rotation++) { |
| 275 | final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270); |
| 276 | final int dw = rotated |
| 277 | ? mDisplayContent.mBaseDisplayHeight |
| 278 | : mDisplayContent.mBaseDisplayWidth; |
| 279 | final int dh = rotated |
| 280 | ? mDisplayContent.mBaseDisplayWidth |
| 281 | : mDisplayContent.mBaseDisplayHeight; |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 282 | final DisplayCutout displayCutout = |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 283 | mDisplayContent.calculateDisplayCutoutForRotation(rotation).getDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 284 | final DisplayPolicy displayPolicy = mDisplayContent.getDisplayPolicy(); |
| 285 | displayPolicy.getStableInsetsLw(rotation, dw, dh, displayCutout, mTmpRect); |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 286 | config.unset(); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 287 | config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE; |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 288 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 289 | final int appWidth = displayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, |
| 290 | baseConfig.uiMode, displayCutout); |
| 291 | final int appHeight = displayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, |
| 292 | baseConfig.uiMode, displayCutout); |
| 293 | displayPolicy.getNonDecorInsetsLw(rotation, dw, dh, displayCutout, mTmpRect); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 294 | final int leftInset = mTmpRect.left; |
| 295 | final int topInset = mTmpRect.top; |
| 296 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 297 | config.windowConfiguration.setAppBounds(leftInset /*left*/, topInset /*top*/, |
| 298 | leftInset + appWidth /*right*/, topInset + appHeight /*bottom*/); |
Bryce Lee | 7566d76 | 2017-03-30 09:34:15 -0700 | [diff] [blame] | 299 | |
Adrian Roos | 11c2558 | 2018-02-19 18:06:36 +0100 | [diff] [blame] | 300 | final float density = mDisplayContent.getDisplayMetrics().density; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 301 | config.screenWidthDp = (int) (displayPolicy.getConfigDisplayWidth(dw, dh, rotation, |
| 302 | baseConfig.uiMode, displayCutout) / density); |
| 303 | config.screenHeightDp = (int) (displayPolicy.getConfigDisplayHeight(dw, dh, rotation, |
| 304 | baseConfig.uiMode, displayCutout) / density); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 305 | final Context rotationContext = mService.mContext.createConfigurationContext(config); |
| 306 | mSnapAlgorithmForRotation[rotation] = new DividerSnapAlgorithm( |
| 307 | rotationContext.getResources(), dw, dh, getContentWidth(), |
| 308 | config.orientation == ORIENTATION_PORTRAIT, mTmpRect); |
| 309 | } |
| 310 | } |
| 311 | |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 312 | private void loadDimens() { |
| 313 | final Context context = mService.mContext; |
| 314 | mDividerWindowWidth = context.getResources().getDimensionPixelSize( |
| 315 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
| 316 | mDividerInsets = context.getResources().getDimensionPixelSize( |
| 317 | com.android.internal.R.dimen.docked_stack_divider_insets); |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 318 | mDividerWindowWidthInactive = WindowManagerService.dipToPixel( |
| 319 | DIVIDER_WIDTH_INACTIVE_DP, mDisplayContent.getDisplayMetrics()); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 320 | mTaskHeightInMinimizedMode = context.getResources().getDimensionPixelSize( |
| 321 | com.android.internal.R.dimen.task_height_of_minimized_mode); |
Jorim Jaggi | 8563943 | 2016-05-06 17:27:55 -0700 | [diff] [blame] | 322 | initSnapAlgorithmForRotations(); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void onConfigurationChanged() { |
| 326 | loadDimens(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 329 | boolean isResizing() { |
| 330 | return mResizing; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 333 | int getContentWidth() { |
| 334 | return mDividerWindowWidth - 2 * mDividerInsets; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Jorim Jaggi | 81ba11e | 2016-02-03 22:04:22 -0800 | [diff] [blame] | 337 | int getContentInsets() { |
| 338 | return mDividerInsets; |
| 339 | } |
| 340 | |
Chong Zhang | 198afac | 2016-04-15 12:03:11 -0700 | [diff] [blame] | 341 | int getContentWidthInactive() { |
| 342 | return mDividerWindowWidthInactive; |
| 343 | } |
| 344 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 345 | void setResizing(boolean resizing) { |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 346 | if (mResizing != resizing) { |
| 347 | mResizing = resizing; |
| 348 | resetDragResizingChangeReported(); |
| 349 | } |
| 350 | } |
| 351 | |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 352 | void setTouchRegion(Rect touchRegion) { |
| 353 | mTouchRegion.set(touchRegion); |
| 354 | } |
| 355 | |
| 356 | void getTouchRegion(Rect outRegion) { |
| 357 | outRegion.set(mTouchRegion); |
| 358 | outRegion.offset(mWindow.getFrameLw().left, mWindow.getFrameLw().top); |
| 359 | } |
| 360 | |
Jorim Jaggi | c662d8e | 2016-02-05 16:54:54 -0800 | [diff] [blame] | 361 | private void resetDragResizingChangeReported() { |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 362 | mDisplayContent.forAllWindows(WindowState::resetDragResizingChangeReported, |
| 363 | true /* traverseTopToBottom */ ); |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void setWindow(WindowState window) { |
| 367 | mWindow = window; |
Filip Gruszczynski | 85d5cc4 | 2015-12-04 09:21:37 -0800 | [diff] [blame] | 368 | reevaluateVisibility(false); |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Filip Gruszczynski | 85d5cc4 | 2015-12-04 09:21:37 -0800 | [diff] [blame] | 371 | void reevaluateVisibility(boolean force) { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 372 | if (mWindow == null) { |
| 373 | return; |
| 374 | } |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 375 | TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Jorim Jaggi | 7998e48 | 2016-02-12 18:47:06 -0800 | [diff] [blame] | 376 | |
| 377 | // If the stack is invisible, we policy force hide it in WindowAnimator.shouldForceHide |
| 378 | final boolean visible = stack != null; |
Filip Gruszczynski | 85d5cc4 | 2015-12-04 09:21:37 -0800 | [diff] [blame] | 379 | if (mLastVisibility == visible && !force) { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 380 | return; |
| 381 | } |
| 382 | mLastVisibility = visible; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 383 | notifyDockedDividerVisibilityChanged(visible); |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 384 | if (!visible) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 385 | setResizeDimLayer(false, WINDOWING_MODE_UNDEFINED, 0f); |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 386 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 389 | private boolean wasVisible() { |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 390 | return mLastVisibility; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 393 | void setAdjustedForIme( |
| 394 | boolean adjustedForIme, boolean adjustedForDivider, |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 395 | boolean animate, WindowState imeWin, int imeHeight) { |
| 396 | if (mAdjustedForIme != adjustedForIme || (adjustedForIme && mImeHeight != imeHeight) |
| 397 | || mAdjustedForDivider != adjustedForDivider) { |
Jorim Jaggi | 3070e77 | 2016-05-17 16:41:32 -0700 | [diff] [blame] | 398 | if (animate && !mAnimatingForMinimizedDockedStack) { |
lumark | bcc316e | 2018-12-25 21:37:05 +0800 | [diff] [blame] | 399 | // Notify SystemUI to set the target docked stack size according current docked |
| 400 | // state without animation when calling startImeAdjustAnimation. |
| 401 | notifyDockedStackMinimizedChanged(mMinimizedDock, false /* animate */, |
| 402 | isHomeStackResizable()); |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 403 | startImeAdjustAnimation(adjustedForIme, adjustedForDivider, imeWin); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 404 | } else { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 405 | // Animation might be delayed, so only notify if we don't run an animation. |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 406 | notifyAdjustedForImeChanged(adjustedForIme || adjustedForDivider, 0 /* duration */); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 407 | } |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 408 | mAdjustedForIme = adjustedForIme; |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 409 | mImeHeight = imeHeight; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 410 | mAdjustedForDivider = adjustedForDivider; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 411 | } |
Chong Zhang | b58bbcc | 2016-03-23 11:57:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Keisuke Kuroyanagi | 19d9a8f | 2016-05-12 16:49:02 -0700 | [diff] [blame] | 414 | int getImeHeightAdjustedFor() { |
| 415 | return mImeHeight; |
| 416 | } |
| 417 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 418 | void positionDockedStackedDivider(Rect frame) { |
Matthew Ng | 0808af3 | 2018-05-07 12:11:13 -0700 | [diff] [blame] | 419 | TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 420 | if (stack == null) { |
| 421 | // Unfortunately we might end up with still having a divider, even though the underlying |
| 422 | // stack was already removed. This is because we are on AM thread and the removal of the |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 423 | // divider was deferred to WM thread and hasn't happened yet. In that case let's just |
| 424 | // keep putting it in the same place it was before the stack was removed to have |
| 425 | // continuity and prevent it from jumping to the center. It will get hidden soon. |
| 426 | frame.set(mLastRect); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 427 | return; |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 428 | } else { |
Chong Zhang | 4c9ba52a | 2015-11-10 18:36:33 -0800 | [diff] [blame] | 429 | stack.getDimBounds(mTmpRect); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 430 | } |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 431 | int side = stack.getDockSide(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 432 | switch (side) { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 433 | case DOCKED_LEFT: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 434 | frame.set(mTmpRect.right - mDividerInsets, frame.top, |
| 435 | mTmpRect.right + frame.width() - mDividerInsets, frame.bottom); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 436 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 437 | case DOCKED_TOP: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 438 | frame.set(frame.left, mTmpRect.bottom - mDividerInsets, |
| 439 | mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 440 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 441 | case DOCKED_RIGHT: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 442 | frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top, |
| 443 | mTmpRect.left + mDividerInsets, frame.bottom); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 444 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 445 | case DOCKED_BOTTOM: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 446 | frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets, |
| 447 | frame.right, mTmpRect.top + mDividerInsets); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 448 | break; |
| 449 | } |
Filip Gruszczynski | 7704905 | 2015-11-09 14:01:21 -0800 | [diff] [blame] | 450 | mLastRect.set(frame); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 451 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 452 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 453 | private void notifyDockedDividerVisibilityChanged(boolean visible) { |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 454 | final int size = mDockedStackListeners.beginBroadcast(); |
| 455 | for (int i = 0; i < size; ++i) { |
| 456 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 457 | try { |
| 458 | listener.onDividerVisibilityChanged(visible); |
| 459 | } catch (RemoteException e) { |
| 460 | Slog.e(TAG_WM, "Error delivering divider visibility changed event.", e); |
| 461 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 462 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 463 | mDockedStackListeners.finishBroadcast(); |
| 464 | } |
| 465 | |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 466 | /** |
| 467 | * Checks if the primary stack is allowed to dock to a specific side based on its original dock |
| 468 | * side. |
| 469 | * |
| 470 | * @param dockSide the side to see if it is valid |
| 471 | * @return true if the side provided is valid |
| 472 | */ |
Evan Rosky | 39b6f23 | 2018-10-30 18:35:41 -0700 | [diff] [blame] | 473 | boolean canPrimaryStackDockTo(int dockSide, Rect parentRect, int rotation) { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 474 | final DisplayPolicy policy = mDisplayContent.getDisplayPolicy(); |
| 475 | return isDockSideAllowed(dockSide, mOriginalDockedSide, |
| 476 | policy.navigationBarPosition(parentRect.width(), parentRect.height(), rotation), |
| 477 | policy.navigationBarCanMove()); |
| 478 | } |
| 479 | |
| 480 | @VisibleForTesting |
| 481 | static boolean isDockSideAllowed(int dockSide, int originalDockSide, int navBarPosition, |
| 482 | boolean navigationBarCanMove) { |
| 483 | if (dockSide == DOCKED_TOP) { |
| 484 | return true; |
| 485 | } |
| 486 | |
| 487 | if (navigationBarCanMove) { |
| 488 | // Only allow the dockside opposite to the nav bar position in landscape |
| 489 | return dockSide == DOCKED_LEFT && navBarPosition == NAV_BAR_RIGHT |
| 490 | || dockSide == DOCKED_RIGHT && navBarPosition == NAV_BAR_LEFT; |
| 491 | } |
| 492 | |
| 493 | // Side is the same as original side |
| 494 | if (dockSide == originalDockSide) { |
| 495 | return true; |
| 496 | } |
| 497 | |
| 498 | // Only if original docked side was top in portrait will allow left for landscape |
| 499 | return dockSide == DOCKED_LEFT && originalDockSide == DOCKED_TOP; |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 502 | void notifyDockedStackExistsChanged(boolean exists) { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 503 | // TODO(multi-display): Perform all actions only for current display. |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 504 | final int size = mDockedStackListeners.beginBroadcast(); |
| 505 | for (int i = 0; i < size; ++i) { |
| 506 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 507 | try { |
| 508 | listener.onDockedStackExistsChanged(exists); |
| 509 | } catch (RemoteException e) { |
| 510 | Slog.e(TAG_WM, "Error delivering docked stack exists changed event.", e); |
| 511 | } |
| 512 | } |
| 513 | mDockedStackListeners.finishBroadcast(); |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 514 | if (exists) { |
| 515 | InputMethodManagerInternal inputMethodManagerInternal = |
| 516 | LocalServices.getService(InputMethodManagerInternal.class); |
| 517 | if (inputMethodManagerInternal != null) { |
| 518 | |
| 519 | // Hide the current IME to avoid problems with animations from IME adjustment when |
| 520 | // attaching the docked stack. |
| 521 | inputMethodManagerInternal.hideCurrentInputMethod(); |
| 522 | mImeHideRequested = true; |
| 523 | } |
Matthew Ng | e8b052a | 2018-01-16 14:33:47 -0800 | [diff] [blame] | 524 | |
| 525 | // If a primary stack was just created, it will not have access to display content at |
| 526 | // this point so pass it from here to get a valid dock side. |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 527 | final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Matthew Ng | e8b052a | 2018-01-16 14:33:47 -0800 | [diff] [blame] | 528 | mOriginalDockedSide = stack.getDockSideForDisplay(mDisplayContent); |
Matthew Ng | bc527a3 | 2017-06-19 16:42:31 -0700 | [diff] [blame] | 529 | return; |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 530 | } |
Matthew Ng | cb1b8e4 | 2017-10-20 16:29:23 -0700 | [diff] [blame] | 531 | mOriginalDockedSide = DOCKED_INVALID; |
Matthew Ng | bc527a3 | 2017-06-19 16:42:31 -0700 | [diff] [blame] | 532 | setMinimizedDockedStack(false /* minimizedDock */, false /* animate */); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 533 | |
| 534 | if (mDimmedStack != null) { |
| 535 | mDimmedStack.stopDimming(); |
| 536 | mDimmedStack = null; |
| 537 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 540 | /** |
| 541 | * Resets the state that IME hide has been requested. See {@link #isImeHideRequested}. |
| 542 | */ |
| 543 | void resetImeHideRequested() { |
| 544 | mImeHideRequested = false; |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * The docked stack divider controller makes sure the IME gets hidden when attaching the docked |
| 549 | * stack, to avoid animation problems. This flag indicates whether the request to hide the IME |
| 550 | * has been sent in an asynchronous manner, and the IME should be treated as hidden already. |
| 551 | * |
| 552 | * @return whether IME hide request has been sent |
| 553 | */ |
| 554 | boolean isImeHideRequested() { |
| 555 | return mImeHideRequested; |
| 556 | } |
| 557 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 558 | private void notifyDockedStackMinimizedChanged(boolean minimizedDock, boolean animate, |
| 559 | boolean isHomeStackResizable) { |
| 560 | long animDuration = 0; |
| 561 | if (animate) { |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 562 | final TaskStack stack = |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 563 | mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 564 | final long transitionDuration = isAnimationMaximizing() |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 565 | ? mDisplayContent.mAppTransition.getLastClipRevealTransitionDuration() |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 566 | : DEFAULT_APP_TRANSITION_DURATION; |
| 567 | mAnimationDuration = (long) |
| 568 | (transitionDuration * mService.getTransitionAnimationScaleLocked()); |
| 569 | mMaximizeMeetFraction = getClipRevealMeetFraction(stack); |
| 570 | animDuration = (long) (mAnimationDuration * mMaximizeMeetFraction); |
| 571 | } |
Yunfan Chen | cafc706 | 2019-01-22 17:21:32 +0900 | [diff] [blame] | 572 | mService.mAtmInternal.notifyDockedStackMinimizedChanged(minimizedDock); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 573 | final int size = mDockedStackListeners.beginBroadcast(); |
| 574 | for (int i = 0; i < size; ++i) { |
| 575 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 576 | try { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 577 | listener.onDockedStackMinimizedChanged(minimizedDock, animDuration, |
| 578 | isHomeStackResizable); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 579 | } catch (RemoteException e) { |
| 580 | Slog.e(TAG_WM, "Error delivering minimized dock changed event.", e); |
| 581 | } |
| 582 | } |
| 583 | mDockedStackListeners.finishBroadcast(); |
| 584 | } |
| 585 | |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 586 | void notifyDockSideChanged(int newDockSide) { |
| 587 | final int size = mDockedStackListeners.beginBroadcast(); |
| 588 | for (int i = 0; i < size; ++i) { |
| 589 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 590 | try { |
| 591 | listener.onDockSideChanged(newDockSide); |
| 592 | } catch (RemoteException e) { |
| 593 | Slog.e(TAG_WM, "Error delivering dock side changed event.", e); |
| 594 | } |
| 595 | } |
| 596 | mDockedStackListeners.finishBroadcast(); |
| 597 | } |
| 598 | |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 599 | private void notifyAdjustedForImeChanged(boolean adjustedForIme, long animDuration) { |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 600 | final int size = mDockedStackListeners.beginBroadcast(); |
| 601 | for (int i = 0; i < size; ++i) { |
| 602 | final IDockedStackListener listener = mDockedStackListeners.getBroadcastItem(i); |
| 603 | try { |
| 604 | listener.onAdjustedForImeChanged(adjustedForIme, animDuration); |
| 605 | } catch (RemoteException e) { |
| 606 | Slog.e(TAG_WM, "Error delivering adjusted for ime changed event.", e); |
| 607 | } |
| 608 | } |
| 609 | mDockedStackListeners.finishBroadcast(); |
| 610 | } |
| 611 | |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 612 | void registerDockedStackListener(IDockedStackListener listener) { |
| 613 | mDockedStackListeners.register(listener); |
| 614 | notifyDockedDividerVisibilityChanged(wasVisible()); |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 615 | notifyDockedStackExistsChanged( |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 616 | mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility() != null); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 617 | notifyDockedStackMinimizedChanged(mMinimizedDock, false /* animate */, |
| 618 | isHomeStackResizable()); |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 619 | notifyAdjustedForImeChanged(mAdjustedForIme, 0 /* animDuration */); |
| 620 | |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 621 | } |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 622 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 623 | /** |
| 624 | * Shows a dim layer with {@param alpha} if {@param visible} is true and |
| 625 | * {@param targetWindowingMode} isn't |
| 626 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_UNDEFINED} and there is a stack on the |
| 627 | * display in that windowing mode. |
| 628 | */ |
| 629 | void setResizeDimLayer(boolean visible, int targetWindowingMode, float alpha) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 630 | // TODO: Maybe only allow split-screen windowing modes? |
| 631 | final TaskStack stack = targetWindowingMode != WINDOWING_MODE_UNDEFINED |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 632 | ? mDisplayContent.getTopStackInWindowingMode(targetWindowingMode) |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 633 | : null; |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 634 | final TaskStack dockedStack = mDisplayContent.getSplitScreenPrimaryStack(); |
Jorim Jaggi | bc5425c | 2016-03-01 13:51:16 +0100 | [diff] [blame] | 635 | boolean visibleAndValid = visible && stack != null && dockedStack != null; |
chaviw | 783729c | 2018-01-25 15:14:10 -0800 | [diff] [blame] | 636 | |
| 637 | // Ensure an old dim that was shown for the docked stack divider is removed so we don't end |
| 638 | // up with dim layers that can no longer be removed. |
| 639 | if (mDimmedStack != null && mDimmedStack != stack) { |
| 640 | mDimmedStack.stopDimming(); |
| 641 | mDimmedStack = null; |
| 642 | } |
| 643 | |
Jorim Jaggi | 7b371dd | 2016-01-05 15:32:34 +0100 | [diff] [blame] | 644 | if (visibleAndValid) { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 645 | mDimmedStack = stack; |
| 646 | stack.dim(alpha); |
Jorim Jaggi | 7b371dd | 2016-01-05 15:32:34 +0100 | [diff] [blame] | 647 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 648 | if (!visibleAndValid && stack != null) { |
| 649 | mDimmedStack = null; |
| 650 | stack.stopDimming(); |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 651 | } |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 652 | } |
| 653 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 654 | /** |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 655 | * @return The layer used for dimming the apps when dismissing docked/fullscreen stack. Just |
| 656 | * above all application surfaces. |
| 657 | */ |
| 658 | private int getResizeDimLayer() { |
| 659 | return (mWindow != null) ? mWindow.mLayer - 1 : LAYER_OFFSET_DIM; |
| 660 | } |
| 661 | |
| 662 | /** |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 663 | * Notifies the docked stack divider controller of a visibility change that happens without |
| 664 | * an animation. |
| 665 | */ |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 666 | void notifyAppVisibilityChanged() { |
| 667 | checkMinimizeChanged(false /* animate */); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 668 | } |
| 669 | |
Jorim Jaggi | 84afb1a | 2016-09-28 14:54:04 +0200 | [diff] [blame] | 670 | void notifyAppTransitionStarting(ArraySet<AppWindowToken> openingApps, int appTransition) { |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 671 | final boolean wasMinimized = mMinimizedDock; |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 672 | checkMinimizeChanged(true /* animate */); |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 673 | |
| 674 | // We were minimized, and now we are still minimized, but somebody is trying to launch an |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 675 | // app in docked stack, better show recent apps so we actually get unminimized! However do |
| 676 | // not do this if keyguard is dismissed such as when the device is unlocking. This catches |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 677 | // any case that was missed in ActivityStarter.postStartActivityUncheckedProcessing because |
| 678 | // we couldn't retrace the launch of the app in the docked stack to the launch from |
| 679 | // homescreen. |
Jorim Jaggi | 84afb1a | 2016-09-28 14:54:04 +0200 | [diff] [blame] | 680 | if (wasMinimized && mMinimizedDock && containsAppInDockedStack(openingApps) |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 681 | && appTransition != TRANSIT_NONE && |
| 682 | !AppTransition.isKeyguardGoingAwayTransit(appTransition)) { |
Wale Ogunwale | 6767eae | 2018-05-03 15:52:51 -0700 | [diff] [blame] | 683 | if (mService.mAtmInternal.isRecentsComponentHomeActivity(mService.mCurrentUserId)) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 684 | // When the home activity is the recents component and we are already minimized, |
| 685 | // then there is nothing to do here since home is already visible |
| 686 | } else { |
| 687 | mService.showRecentApps(); |
| 688 | } |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * @return true if {@param apps} contains an activity in the docked stack, false otherwise. |
| 694 | */ |
| 695 | private boolean containsAppInDockedStack(ArraySet<AppWindowToken> apps) { |
| 696 | for (int i = apps.size() - 1; i >= 0; i--) { |
| 697 | final AppWindowToken token = apps.valueAt(i); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 698 | if (token.getTask() != null && token.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | 936aaeb | 2016-08-26 19:02:11 -0700 | [diff] [blame] | 699 | return true; |
| 700 | } |
| 701 | } |
| 702 | return false; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Jorim Jaggi | 1ae68bf | 2016-05-09 18:44:34 -0700 | [diff] [blame] | 705 | boolean isMinimizedDock() { |
| 706 | return mMinimizedDock; |
| 707 | } |
| 708 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 709 | void checkMinimizeChanged(boolean animate) { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 710 | if (mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility() == null) { |
Jorim Jaggi | 817a524 | 2016-05-06 15:45:00 -0700 | [diff] [blame] | 711 | return; |
| 712 | } |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 713 | final TaskStack homeStack = mDisplayContent.getHomeStack(); |
| 714 | if (homeStack == null) { |
| 715 | return; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 716 | } |
Jorim Jaggi | d3ec507 | 2016-04-28 15:57:47 -0700 | [diff] [blame] | 717 | final Task homeTask = homeStack.findHomeTask(); |
| 718 | if (homeTask == null || !isWithinDisplay(homeTask)) { |
| 719 | return; |
| 720 | } |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 721 | |
| 722 | // Do not minimize when dock is already minimized while keyguard is showing and not |
| 723 | // occluded such as unlocking the screen |
Adrian Roos | b56b3c3 | 2018-05-17 17:32:26 +0200 | [diff] [blame] | 724 | if (mMinimizedDock && mService.mKeyguardOrAodShowingOnDefaultDisplay) { |
Matthew Ng | 8e26552 | 2017-02-13 11:09:37 -0800 | [diff] [blame] | 725 | return; |
| 726 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 727 | final TaskStack topSecondaryStack = mDisplayContent.getTopStackInWindowingMode( |
Wale Ogunwale | b62139d | 2017-09-20 15:37:35 -0700 | [diff] [blame] | 728 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 729 | final RecentsAnimationController recentsAnim = mService.getRecentsAnimationController(); |
| 730 | final boolean minimizedForRecentsAnimation = recentsAnim != null && |
| 731 | recentsAnim.isSplitScreenMinimized(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 732 | boolean homeVisible = homeTask.getTopVisibleAppToken() != null; |
| 733 | if (homeVisible && topSecondaryStack != null) { |
| 734 | // Home should only be considered visible if it is greater or equal to the top secondary |
| 735 | // stack in terms of z-order. |
| 736 | homeVisible = homeStack.compareTo(topSecondaryStack) >= 0; |
| 737 | } |
Winson Chung | f557c3b | 2018-03-16 10:55:20 -0700 | [diff] [blame] | 738 | setMinimizedDockedStack(homeVisible || minimizedForRecentsAnimation, animate); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | private boolean isWithinDisplay(Task task) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 742 | task.getBounds(mTmpRect); |
| 743 | mDisplayContent.getBounds(mTmpRect2); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 744 | return mTmpRect.intersect(mTmpRect2); |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Sets whether the docked stack is currently in a minimized state, i.e. all the tasks in the |
| 749 | * docked stack are heavily clipped so you can only see a minimal peek state. |
| 750 | * |
| 751 | * @param minimizedDock Whether the docked stack is currently minimized. |
| 752 | * @param animate Whether to animate the change. |
| 753 | */ |
| 754 | private void setMinimizedDockedStack(boolean minimizedDock, boolean animate) { |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 755 | final boolean wasMinimized = mMinimizedDock; |
| 756 | mMinimizedDock = minimizedDock; |
Jorim Jaggi | 817a524 | 2016-05-06 15:45:00 -0700 | [diff] [blame] | 757 | if (minimizedDock == wasMinimized) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 758 | return; |
| 759 | } |
| 760 | |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 761 | final boolean imeChanged = clearImeAdjustAnimation(); |
| 762 | boolean minimizedChange = false; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 763 | if (isHomeStackResizable()) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 764 | notifyDockedStackMinimizedChanged(minimizedDock, animate, |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 765 | true /* isHomeStackResizable */); |
| 766 | minimizedChange = true; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 767 | } else { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 768 | if (minimizedDock) { |
| 769 | if (animate) { |
| 770 | startAdjustAnimation(0f, 1f); |
| 771 | } else { |
| 772 | minimizedChange |= setMinimizedDockedStack(true); |
| 773 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 774 | } else { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 775 | if (animate) { |
| 776 | startAdjustAnimation(1f, 0f); |
| 777 | } else { |
| 778 | minimizedChange |= setMinimizedDockedStack(false); |
| 779 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 780 | } |
| 781 | } |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 782 | if (imeChanged || minimizedChange) { |
| 783 | if (imeChanged && !minimizedChange) { |
| 784 | Slog.d(TAG, "setMinimizedDockedStack: IME adjust changed due to minimizing," |
| 785 | + " minimizedDock=" + minimizedDock |
| 786 | + " minimizedChange=" + minimizedChange); |
| 787 | } |
| 788 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 789 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 790 | } |
| 791 | |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 792 | private boolean clearImeAdjustAnimation() { |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 793 | final boolean changed = mDisplayContent.clearImeAdjustAnimation(); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 794 | mAnimatingForIme = false; |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 795 | return changed; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 798 | private void startAdjustAnimation(float from, float to) { |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 799 | mAnimatingForMinimizedDockedStack = true; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 800 | mAnimationStarted = false; |
| 801 | mAnimationStart = from; |
| 802 | mAnimationTarget = to; |
| 803 | } |
| 804 | |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 805 | private void startImeAdjustAnimation( |
| 806 | boolean adjustedForIme, boolean adjustedForDivider, WindowState imeWin) { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 807 | |
| 808 | // If we're not in an animation, the starting point depends on whether we're adjusted |
| 809 | // or not. If we're already in an animation, we start from where the current animation |
| 810 | // left off, so that the motion doesn't look discontinuous. |
| 811 | if (!mAnimatingForIme) { |
| 812 | mAnimationStart = mAdjustedForIme ? 1 : 0; |
| 813 | mDividerAnimationStart = mAdjustedForDivider ? 1 : 0; |
| 814 | mLastAnimationProgress = mAnimationStart; |
| 815 | mLastDividerProgress = mDividerAnimationStart; |
| 816 | } else { |
| 817 | mAnimationStart = mLastAnimationProgress; |
| 818 | mDividerAnimationStart = mLastDividerProgress; |
| 819 | } |
Jorim Jaggi | 3070e77 | 2016-05-17 16:41:32 -0700 | [diff] [blame] | 820 | mAnimatingForIme = true; |
| 821 | mAnimationStarted = false; |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 822 | mAnimationTarget = adjustedForIme ? 1 : 0; |
| 823 | mDividerAnimationTarget = adjustedForDivider ? 1 : 0; |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 824 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 825 | mDisplayContent.beginImeAdjustAnimation(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 826 | |
| 827 | // We put all tasks into drag resizing mode - wait until all of them have completed the |
| 828 | // drag resizing switch. |
| 829 | if (!mService.mWaitingForDrawn.isEmpty()) { |
| 830 | mService.mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT); |
| 831 | mService.mH.sendEmptyMessageDelayed(H.WAITING_FOR_DRAWN_TIMEOUT, |
| 832 | IME_ADJUST_DRAWN_TIMEOUT); |
| 833 | mAnimationStartDelayed = true; |
| 834 | if (imeWin != null) { |
| 835 | |
| 836 | // There might be an old window delaying the animation start - clear it. |
| 837 | if (mDelayedImeWin != null) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 838 | mDelayedImeWin.endDelayingAnimationStart(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 839 | } |
| 840 | mDelayedImeWin = imeWin; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 841 | imeWin.startDelayingAnimationStart(); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 842 | } |
Jorim Jaggi | 3188386 | 2016-11-04 15:45:30 -0700 | [diff] [blame] | 843 | |
| 844 | // If we are already waiting for something to be drawn, clear out the old one so it |
| 845 | // still gets executed. |
| 846 | // TODO: Have a real system where we can wait on different windows to be drawn with |
| 847 | // different callbacks. |
| 848 | if (mService.mWaitingForDrawnCallback != null) { |
| 849 | mService.mWaitingForDrawnCallback.run(); |
| 850 | } |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 851 | mService.mWaitingForDrawnCallback = () -> { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 852 | synchronized (mService.mGlobalLock) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 853 | mAnimationStartDelayed = false; |
| 854 | if (mDelayedImeWin != null) { |
| 855 | mDelayedImeWin.endDelayingAnimationStart(); |
| 856 | } |
| 857 | // If the adjust status changed since this was posted, only notify |
| 858 | // the new states and don't animate. |
| 859 | long duration = 0; |
| 860 | if (mAdjustedForIme == adjustedForIme |
| 861 | && mAdjustedForDivider == adjustedForDivider) { |
| 862 | duration = IME_ADJUST_ANIM_DURATION; |
| 863 | } else { |
| 864 | Slog.w(TAG, "IME adjust changed while waiting for drawn:" |
| 865 | + " adjustedForIme=" + adjustedForIme |
| 866 | + " adjustedForDivider=" + adjustedForDivider |
| 867 | + " mAdjustedForIme=" + mAdjustedForIme |
| 868 | + " mAdjustedForDivider=" + mAdjustedForDivider); |
| 869 | } |
| 870 | notifyAdjustedForImeChanged( |
| 871 | mAdjustedForIme || mAdjustedForDivider, duration); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 872 | } |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 873 | }; |
| 874 | } else { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 875 | notifyAdjustedForImeChanged( |
| 876 | adjustedForIme || adjustedForDivider, IME_ADJUST_ANIM_DURATION); |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 877 | } |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 880 | private boolean setMinimizedDockedStack(boolean minimized) { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 881 | final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 882 | notifyDockedStackMinimizedChanged(minimized, false /* animate */, isHomeStackResizable()); |
Chong Zhang | 22eff0a | 2016-07-01 14:48:11 -0700 | [diff] [blame] | 883 | return stack != null && stack.setAdjustedForMinimizedDock(minimized ? 1f : 0f); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 884 | } |
| 885 | |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 886 | private boolean isAnimationMaximizing() { |
| 887 | return mAnimationTarget == 0f; |
| 888 | } |
| 889 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 890 | public boolean animate(long now) { |
Wale Ogunwale | 20ec11b | 2016-04-22 12:11:51 -0700 | [diff] [blame] | 891 | if (mWindow == null) { |
| 892 | return false; |
| 893 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 894 | if (mAnimatingForMinimizedDockedStack) { |
| 895 | return animateForMinimizedDockedStack(now); |
lumark | bcc316e | 2018-12-25 21:37:05 +0800 | [diff] [blame] | 896 | } else if (mAnimatingForIme && !mDisplayContent.mAppTransition.isRunning()) { |
| 897 | // To prevent task stack resize animation may flicking when playing app transition |
| 898 | // animation & IME window enter animation in parallel, make sure app transition is done |
| 899 | // and then start to animate for IME. |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 900 | return animateForIme(now); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 901 | } |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 902 | return false; |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 903 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 904 | |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 905 | private boolean animateForIme(long now) { |
Jorim Jaggi | ff71d20 | 2016-04-14 13:12:36 -0700 | [diff] [blame] | 906 | if (!mAnimationStarted || mAnimationStartDelayed) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 907 | mAnimationStarted = true; |
| 908 | mAnimationStartTime = now; |
| 909 | mAnimationDuration = (long) |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 910 | (IME_ADJUST_ANIM_DURATION * mService.getWindowAnimationScaleLocked()); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 911 | } |
| 912 | float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration); |
| 913 | t = (mAnimationTarget == 1f ? IME_ADJUST_ENTRY_INTERPOLATOR : TOUCH_RESPONSE_INTERPOLATOR) |
| 914 | .getInterpolation(t); |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 915 | final boolean updated = |
| 916 | mDisplayContent.animateForIme(t, mAnimationTarget, mDividerAnimationTarget); |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 917 | if (updated) { |
| 918 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 919 | } |
| 920 | if (t >= 1.0f) { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 921 | mLastAnimationProgress = mAnimationTarget; |
| 922 | mLastDividerProgress = mDividerAnimationTarget; |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 923 | mAnimatingForIme = false; |
| 924 | return false; |
| 925 | } else { |
| 926 | return true; |
| 927 | } |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | private boolean animateForMinimizedDockedStack(long now) { |
Matthew Ng | 64e77cf | 2017-10-31 14:01:31 -0700 | [diff] [blame] | 931 | final TaskStack stack = mDisplayContent.getSplitScreenPrimaryStackIgnoringVisibility(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 932 | if (!mAnimationStarted) { |
| 933 | mAnimationStarted = true; |
| 934 | mAnimationStartTime = now; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 935 | notifyDockedStackMinimizedChanged(mMinimizedDock, true /* animate */, |
| 936 | isHomeStackResizable() /* isHomeStackResizable */); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 937 | } |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 938 | float t = Math.min(1f, (float) (now - mAnimationStartTime) / mAnimationDuration); |
| 939 | t = (isAnimationMaximizing() ? TOUCH_RESPONSE_INTERPOLATOR : mMinimizedDockInterpolator) |
| 940 | .getInterpolation(t); |
Chong Zhang | 741c0ba | 2016-05-27 12:52:11 -0700 | [diff] [blame] | 941 | if (stack != null) { |
| 942 | if (stack.setAdjustedForMinimizedDock(getMinimizeAmount(stack, t))) { |
| 943 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
| 944 | } |
| 945 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 946 | if (t >= 1.0f) { |
Chong Zhang | baba783 | 2016-03-24 10:21:26 -0700 | [diff] [blame] | 947 | mAnimatingForMinimizedDockedStack = false; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 948 | return false; |
| 949 | } else { |
| 950 | return true; |
| 951 | } |
| 952 | } |
| 953 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 954 | float getInterpolatedAnimationValue(float t) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 955 | return t * mAnimationTarget + (1 - t) * mAnimationStart; |
| 956 | } |
| 957 | |
Wale Ogunwale | 1012458 | 2016-09-15 20:25:50 -0700 | [diff] [blame] | 958 | float getInterpolatedDividerValue(float t) { |
Chong Zhang | f347ab5 | 2016-04-18 21:02:01 -0700 | [diff] [blame] | 959 | return t * mDividerAnimationTarget + (1 - t) * mDividerAnimationStart; |
| 960 | } |
| 961 | |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 962 | /** |
| 963 | * Gets the amount how much to minimize a stack depending on the interpolated fraction t. |
| 964 | */ |
| 965 | private float getMinimizeAmount(TaskStack stack, float t) { |
Jorim Jaggi | eb88d83 | 2016-04-13 20:17:43 -0700 | [diff] [blame] | 966 | final float naturalAmount = getInterpolatedAnimationValue(t); |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 967 | if (isAnimationMaximizing()) { |
| 968 | return adjustMaximizeAmount(stack, t, naturalAmount); |
| 969 | } else { |
| 970 | return naturalAmount; |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | /** |
| 975 | * When maximizing the stack during a clip reveal transition, this adjusts the minimize amount |
| 976 | * during the transition such that the edge of the clip reveal rect is met earlier in the |
| 977 | * transition so we don't create a visible "hole", but only if both the clip reveal and the |
| 978 | * docked stack divider start from about the same portion on the screen. |
| 979 | */ |
| 980 | private float adjustMaximizeAmount(TaskStack stack, float t, float naturalAmount) { |
| 981 | if (mMaximizeMeetFraction == 1f) { |
| 982 | return naturalAmount; |
| 983 | } |
| 984 | final int minimizeDistance = stack.getMinimizeDistance(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 985 | final float startPrime = mDisplayContent.mAppTransition.getLastClipRevealMaxTranslation() |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 986 | / (float) minimizeDistance; |
| 987 | final float amountPrime = t * mAnimationTarget + (1 - t) * startPrime; |
| 988 | final float t2 = Math.min(t / mMaximizeMeetFraction, 1); |
| 989 | return amountPrime * t2 + naturalAmount * (1 - t2); |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * Retrieves the animation fraction at which the docked stack has to meet the clip reveal |
| 994 | * edge. See {@link #adjustMaximizeAmount}. |
| 995 | */ |
| 996 | private float getClipRevealMeetFraction(TaskStack stack) { |
| 997 | if (!isAnimationMaximizing() || stack == null || |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 998 | !mDisplayContent.mAppTransition.hadClipRevealAnimation()) { |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 999 | return 1f; |
| 1000 | } |
| 1001 | final int minimizeDistance = stack.getMinimizeDistance(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1002 | final float fraction = Math.abs(mDisplayContent.mAppTransition |
| 1003 | .getLastClipRevealMaxTranslation()) / (float) minimizeDistance; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 1004 | final float t = Math.max(0, Math.min(1, (fraction - CLIP_REVEAL_MEET_FRACTION_MIN) |
| 1005 | / (CLIP_REVEAL_MEET_FRACTION_MAX - CLIP_REVEAL_MEET_FRACTION_MIN))); |
| 1006 | return CLIP_REVEAL_MEET_EARLIEST |
| 1007 | + (1 - t) * (CLIP_REVEAL_MEET_LAST - CLIP_REVEAL_MEET_EARLIEST); |
| 1008 | } |
| 1009 | |
Jorim Jaggi | 5098159 | 2015-12-29 17:54:12 +0100 | [diff] [blame] | 1010 | public String toShortString() { |
| 1011 | return TAG; |
| 1012 | } |
Robert Carr | e63e01a | 2016-04-18 20:27:34 -0700 | [diff] [blame] | 1013 | |
| 1014 | WindowState getWindow() { |
| 1015 | return mWindow; |
| 1016 | } |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 1017 | |
| 1018 | void dump(String prefix, PrintWriter pw) { |
| 1019 | pw.println(prefix + "DockedStackDividerController"); |
| 1020 | pw.println(prefix + " mLastVisibility=" + mLastVisibility); |
| 1021 | pw.println(prefix + " mMinimizedDock=" + mMinimizedDock); |
| 1022 | pw.println(prefix + " mAdjustedForIme=" + mAdjustedForIme); |
| 1023 | pw.println(prefix + " mAdjustedForDivider=" + mAdjustedForDivider); |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 1024 | } |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 1025 | |
| 1026 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 1027 | final long token = proto.start(fieldId); |
| 1028 | proto.write(MINIMIZED_DOCK, mMinimizedDock); |
| 1029 | proto.end(token); |
| 1030 | } |
Robert Carr | e63e01a | 2016-04-18 20:27:34 -0700 | [diff] [blame] | 1031 | } |