Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| 19 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
| 20 | import static android.util.TypedValue.COMPLEX_UNIT_DIP; |
| 21 | |
| 22 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 24 | |
| 25 | import android.animation.ValueAnimator; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 26 | import android.app.RemoteAction; |
| 27 | import android.content.pm.ParceledListSlice; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 28 | import android.content.res.Resources; |
| 29 | import android.graphics.Point; |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 30 | import android.graphics.PointF; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 31 | import android.graphics.Rect; |
| 32 | import android.os.Handler; |
| 33 | import android.os.IBinder; |
| 34 | import android.os.RemoteException; |
| 35 | import android.util.DisplayMetrics; |
| 36 | import android.util.Log; |
| 37 | import android.util.Size; |
| 38 | import android.util.Slog; |
| 39 | import android.util.TypedValue; |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 40 | import android.view.DisplayInfo; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 41 | import android.view.Gravity; |
| 42 | import android.view.IPinnedStackController; |
| 43 | import android.view.IPinnedStackListener; |
| 44 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 45 | import com.android.internal.policy.PipMotionHelper; |
| 46 | import com.android.internal.policy.PipSnapAlgorithm; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 47 | import com.android.server.UiThread; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 48 | |
| 49 | import java.io.PrintWriter; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 50 | import java.util.ArrayList; |
| 51 | import java.util.List; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Holds the common state of the pinned stack between the system and SystemUI. |
| 55 | */ |
| 56 | class PinnedStackController { |
| 57 | |
| 58 | private static final String TAG = TAG_WITH_CLASS_NAME ? "PinnedStackController" : TAG_WM; |
| 59 | |
| 60 | private final WindowManagerService mService; |
| 61 | private final DisplayContent mDisplayContent; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 62 | private final Handler mHandler = UiThread.getHandler(); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 63 | |
| 64 | private IPinnedStackListener mPinnedStackListener; |
| 65 | private final PinnedStackListenerDeathHandler mPinnedStackListenerDeathHandler = |
| 66 | new PinnedStackListenerDeathHandler(); |
| 67 | |
| 68 | private final PinnedStackControllerCallback mCallbacks = new PinnedStackControllerCallback(); |
| 69 | private final PipSnapAlgorithm mSnapAlgorithm; |
| 70 | private final PipMotionHelper mMotionHelper; |
| 71 | |
| 72 | // States that affect how the PIP can be manipulated |
| 73 | private boolean mInInteractiveMode; |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 74 | private boolean mIsMinimized; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 75 | private boolean mIsSnappingToEdge; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 76 | private boolean mIsImeShowing; |
| 77 | private int mImeHeight; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 78 | private ValueAnimator mBoundsAnimator = null; |
| 79 | |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 80 | // The set of actions that are currently allowed on the PiP activity |
| 81 | private ArrayList<RemoteAction> mActions = new ArrayList<>(); |
| 82 | |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 83 | // Used to calculate stack bounds across rotations |
| 84 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
Winson Chung | 114aeea | 2017-01-09 16:08:07 -0800 | [diff] [blame] | 85 | private final Rect mStableInsets = new Rect(); |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 86 | |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 87 | // The size and position information that describes where the pinned stack will go by default. |
| 88 | private int mDefaultStackGravity; |
| 89 | private Size mDefaultStackSize; |
| 90 | private Point mScreenEdgeInsets; |
| 91 | |
| 92 | // Temp vars for calculation |
| 93 | private final DisplayMetrics mTmpMetrics = new DisplayMetrics(); |
| 94 | private final Rect mTmpInsets = new Rect(); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 95 | private final Rect mTmpRect = new Rect(); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * The callback object passed to listeners for them to notify the controller of state changes. |
| 99 | */ |
| 100 | private class PinnedStackControllerCallback extends IPinnedStackController.Stub { |
| 101 | |
| 102 | @Override |
| 103 | public void setInInteractiveMode(final boolean inInteractiveMode) { |
| 104 | mHandler.post(() -> { |
| 105 | // Cancel any existing animations on the PIP once the user starts dragging it |
| 106 | if (mBoundsAnimator != null && inInteractiveMode) { |
| 107 | mBoundsAnimator.cancel(); |
| 108 | } |
| 109 | mInInteractiveMode = inInteractiveMode; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 110 | }); |
| 111 | } |
Winson Chung | dff5c08 | 2016-11-02 17:28:03 -0700 | [diff] [blame] | 112 | |
| 113 | @Override |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 114 | public void setIsMinimized(final boolean isMinimized) { |
| 115 | mHandler.post(() -> { |
| 116 | mIsMinimized = isMinimized; |
Mady Mellor | 3b10dcd | 2017-01-23 10:08:35 -0800 | [diff] [blame^] | 117 | mSnapAlgorithm.setMinimized(isMinimized); |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 118 | }); |
| 119 | } |
| 120 | |
| 121 | @Override |
Winson Chung | dff5c08 | 2016-11-02 17:28:03 -0700 | [diff] [blame] | 122 | public void setSnapToEdge(final boolean snapToEdge) { |
| 123 | mHandler.post(() -> { |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 124 | mIsSnappingToEdge = snapToEdge; |
Winson Chung | dff5c08 | 2016-11-02 17:28:03 -0700 | [diff] [blame] | 125 | mSnapAlgorithm.setSnapToEdge(snapToEdge); |
| 126 | }); |
| 127 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Handler for the case where the listener dies. |
| 132 | */ |
| 133 | private class PinnedStackListenerDeathHandler implements IBinder.DeathRecipient { |
| 134 | |
| 135 | @Override |
| 136 | public void binderDied() { |
| 137 | // Clean up the state if the listener dies |
| 138 | mInInteractiveMode = false; |
| 139 | mPinnedStackListener = null; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | PinnedStackController(WindowManagerService service, DisplayContent displayContent) { |
| 144 | mService = service; |
| 145 | mDisplayContent = displayContent; |
| 146 | mSnapAlgorithm = new PipSnapAlgorithm(service.mContext); |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 147 | mMotionHelper = new PipMotionHelper(UiThread.getHandler()); |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 148 | mDisplayInfo.copyFrom(mDisplayContent.getDisplayInfo()); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 149 | reloadResources(); |
| 150 | } |
| 151 | |
| 152 | void onConfigurationChanged() { |
| 153 | reloadResources(); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Reloads all the resources for the current configuration. |
| 158 | */ |
| 159 | void reloadResources() { |
| 160 | final Resources res = mService.mContext.getResources(); |
| 161 | final Size defaultSizeDp = Size.parseSize(res.getString( |
| 162 | com.android.internal.R.string.config_defaultPictureInPictureSize)); |
| 163 | final Size screenEdgeInsetsDp = Size.parseSize(res.getString( |
| 164 | com.android.internal.R.string.config_defaultPictureInPictureScreenEdgeInsets)); |
| 165 | mDefaultStackGravity = res.getInteger( |
| 166 | com.android.internal.R.integer.config_defaultPictureInPictureGravity); |
| 167 | mDisplayContent.getDisplay().getRealMetrics(mTmpMetrics); |
| 168 | mDefaultStackSize = new Size(dpToPx(defaultSizeDp.getWidth(), mTmpMetrics), |
| 169 | dpToPx(defaultSizeDp.getHeight(), mTmpMetrics)); |
| 170 | mScreenEdgeInsets = new Point(dpToPx(screenEdgeInsetsDp.getWidth(), mTmpMetrics), |
| 171 | dpToPx(screenEdgeInsetsDp.getHeight(), mTmpMetrics)); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Registers a pinned stack listener. |
| 176 | */ |
| 177 | void registerPinnedStackListener(IPinnedStackListener listener) { |
| 178 | try { |
| 179 | listener.asBinder().linkToDeath(mPinnedStackListenerDeathHandler, 0); |
| 180 | listener.onListenerRegistered(mCallbacks); |
| 181 | mPinnedStackListener = listener; |
| 182 | notifyBoundsChanged(mIsImeShowing); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 183 | notifyMinimizeChanged(mIsMinimized); |
| 184 | notifySnapToEdgeChanged(mIsSnappingToEdge); |
| 185 | notifyActionsChanged(mActions); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 186 | } catch (RemoteException e) { |
| 187 | Log.e(TAG, "Failed to register pinned stack listener", e); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 192 | * Returns the current bounds (or the default bounds if there are no current bounds) with the |
| 193 | * specified aspect ratio. |
| 194 | */ |
| 195 | Rect getAspectRatioBounds(Rect stackBounds, float aspectRatio) { |
| 196 | // Save the snap fraction, calculate the aspect ratio based on the current bounds |
| 197 | final float snapFraction = mSnapAlgorithm.getSnapFraction(stackBounds, |
| 198 | getMovementBounds(stackBounds)); |
| 199 | final float radius = PointF.length(stackBounds.width(), stackBounds.height()); |
| 200 | final int height = (int) Math.round(Math.sqrt((radius * radius) / |
| 201 | (aspectRatio * aspectRatio + 1))); |
| 202 | final int width = Math.round(height * aspectRatio); |
| 203 | final int left = (int) (stackBounds.centerX() - width / 2f); |
| 204 | final int top = (int) (stackBounds.centerY() - height / 2f); |
| 205 | stackBounds.set(left, top, left + width, top + height); |
| 206 | mSnapAlgorithm.applySnapFraction(stackBounds, getMovementBounds(stackBounds), snapFraction); |
| 207 | return stackBounds; |
| 208 | } |
| 209 | |
| 210 | /** |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 211 | * @return the default bounds to show the PIP when there is no active PIP. |
| 212 | */ |
| 213 | Rect getDefaultBounds() { |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 214 | final Rect insetBounds = new Rect(); |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 215 | getInsetBounds(insetBounds); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 216 | |
| 217 | final Rect defaultBounds = new Rect(); |
| 218 | Gravity.apply(mDefaultStackGravity, mDefaultStackSize.getWidth(), |
| 219 | mDefaultStackSize.getHeight(), insetBounds, 0, 0, defaultBounds); |
| 220 | return defaultBounds; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @return the movement bounds for the given {@param stackBounds} and the current state of the |
| 225 | * controller. |
| 226 | */ |
| 227 | Rect getMovementBounds(Rect stackBounds) { |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 228 | return getMovementBounds(stackBounds, true /* adjustForIme */); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @return the movement bounds for the given {@param stackBounds} and the current state of the |
| 233 | * controller. |
| 234 | */ |
| 235 | Rect getMovementBounds(Rect stackBounds, boolean adjustForIme) { |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 236 | final Rect movementBounds = new Rect(); |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 237 | getInsetBounds(movementBounds); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 238 | |
| 239 | // Adjust the right/bottom to ensure the stack bounds never goes offscreen |
| 240 | movementBounds.right = Math.max(movementBounds.left, movementBounds.right - |
| 241 | stackBounds.width()); |
| 242 | movementBounds.bottom = Math.max(movementBounds.top, movementBounds.bottom - |
| 243 | stackBounds.height()); |
| 244 | |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 245 | // Apply the movement bounds adjustments based on the current state |
| 246 | if (adjustForIme) { |
| 247 | if (mIsImeShowing) { |
| 248 | movementBounds.bottom -= mImeHeight; |
| 249 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 250 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 251 | return movementBounds; |
| 252 | } |
| 253 | |
| 254 | /** |
Winson Chung | 114aeea | 2017-01-09 16:08:07 -0800 | [diff] [blame] | 255 | * @return the repositioned PIP bounds given it's pre-change bounds, and the new display |
| 256 | * content. |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 257 | */ |
Winson Chung | 114aeea | 2017-01-09 16:08:07 -0800 | [diff] [blame] | 258 | Rect onDisplayChanged(Rect preChangeStackBounds, DisplayContent displayContent) { |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 259 | final Rect postChangeStackBounds = new Rect(preChangeStackBounds); |
Winson Chung | 114aeea | 2017-01-09 16:08:07 -0800 | [diff] [blame] | 260 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 261 | if (!mDisplayInfo.equals(displayInfo)) { |
| 262 | // Calculate the snap fraction of the current stack along the old movement bounds, and |
| 263 | // then update the stack bounds to the same fraction along the rotated movement bounds. |
| 264 | final Rect preChangeMovementBounds = getMovementBounds(preChangeStackBounds); |
| 265 | final float snapFraction = mSnapAlgorithm.getSnapFraction(preChangeStackBounds, |
| 266 | preChangeMovementBounds); |
| 267 | mDisplayInfo.copyFrom(displayInfo); |
| 268 | |
| 269 | final Rect postChangeMovementBounds = getMovementBounds(preChangeStackBounds, |
| 270 | false /* adjustForIme */); |
| 271 | mSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds, |
| 272 | snapFraction); |
Winson Chung | d5a0159 | 2016-11-11 16:25:04 -0800 | [diff] [blame] | 273 | if (mIsMinimized) { |
| 274 | final Point displaySize = new Point(mDisplayInfo.logicalWidth, |
| 275 | mDisplayInfo.logicalHeight); |
Winson Chung | 114aeea | 2017-01-09 16:08:07 -0800 | [diff] [blame] | 276 | mService.getStableInsetsLocked(displayContent.getDisplayId(), mStableInsets); |
Winson Chung | d5a0159 | 2016-11-11 16:25:04 -0800 | [diff] [blame] | 277 | mSnapAlgorithm.applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds, |
Winson Chung | 114aeea | 2017-01-09 16:08:07 -0800 | [diff] [blame] | 278 | displaySize, mStableInsets); |
Winson Chung | d5a0159 | 2016-11-11 16:25:04 -0800 | [diff] [blame] | 279 | } |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 280 | } |
| 281 | return postChangeStackBounds; |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Sets the Ime state and height. |
| 286 | */ |
| 287 | void setAdjustedForIme(boolean adjustedForIme, int imeHeight) { |
| 288 | // Return early if there is no state change |
| 289 | if (mIsImeShowing == adjustedForIme && mImeHeight == imeHeight) { |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | final Rect stackBounds = new Rect(); |
| 294 | mService.getStackBounds(PINNED_STACK_ID, stackBounds); |
| 295 | final Rect prevMovementBounds = getMovementBounds(stackBounds); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 296 | mIsImeShowing = adjustedForIme; |
| 297 | mImeHeight = imeHeight; |
| 298 | if (mInInteractiveMode) { |
| 299 | // If the user is currently interacting with the PIP and the ime state changes, then |
| 300 | // don't adjust the bounds and defer that to after the interaction |
| 301 | notifyBoundsChanged(adjustedForIme /* adjustedForIme */); |
| 302 | } else { |
| 303 | // Otherwise, we can move the PIP to a sane location to ensure that it does not block |
| 304 | // the user from interacting with the IME |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 305 | final Rect movementBounds = getMovementBounds(stackBounds); |
| 306 | final Rect toBounds = new Rect(stackBounds); |
| 307 | if (adjustedForIme) { |
| 308 | // IME visible |
Winson Chung | d5a0159 | 2016-11-11 16:25:04 -0800 | [diff] [blame] | 309 | if (stackBounds.top == prevMovementBounds.bottom) { |
| 310 | // If the PIP is resting on top of the IME, then adjust it with the hiding IME |
| 311 | toBounds.offsetTo(toBounds.left, movementBounds.bottom); |
| 312 | } else { |
| 313 | toBounds.offset(0, Math.min(0, movementBounds.bottom - stackBounds.top)); |
| 314 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 315 | } else { |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 316 | // IME hidden |
| 317 | if (stackBounds.top == prevMovementBounds.bottom) { |
| 318 | // If the PIP is resting on top of the IME, then adjust it with the hiding IME |
| 319 | toBounds.offsetTo(toBounds.left, movementBounds.bottom); |
| 320 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 321 | } |
| 322 | if (!toBounds.equals(stackBounds)) { |
| 323 | if (mBoundsAnimator != null) { |
| 324 | mBoundsAnimator.cancel(); |
| 325 | } |
| 326 | mBoundsAnimator = mMotionHelper.createAnimationToBounds(stackBounds, toBounds); |
| 327 | mBoundsAnimator.start(); |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /** |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 333 | * Sets the current set of actions. |
| 334 | */ |
| 335 | void setActions(List<RemoteAction> actions) { |
| 336 | mActions.clear(); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 337 | if (actions != null) { |
| 338 | mActions.addAll(actions); |
| 339 | } |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 340 | notifyActionsChanged(mActions); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Notifies listeners that the PIP movement bounds have changed. |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 345 | */ |
| 346 | private void notifyBoundsChanged(boolean adjustedForIme) { |
| 347 | if (mPinnedStackListener != null) { |
| 348 | try { |
| 349 | mPinnedStackListener.onBoundsChanged(adjustedForIme); |
| 350 | } catch (RemoteException e) { |
| 351 | Slog.e(TAG_WM, "Error delivering bounds changed event.", e); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | /** |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 357 | * Notifies listeners that the PIP minimized state has changed. |
| 358 | */ |
| 359 | private void notifyMinimizeChanged(boolean isMinimized) { |
| 360 | if (mPinnedStackListener != null) { |
| 361 | try { |
| 362 | mPinnedStackListener.onMinimizedStateChanged(isMinimized); |
| 363 | } catch (RemoteException e) { |
| 364 | Slog.e(TAG_WM, "Error delivering minimize changed event.", e); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Notifies listeners that the PIP snap-to-edge state has changed. |
| 371 | */ |
| 372 | private void notifySnapToEdgeChanged(boolean isSnappingToEdge) { |
| 373 | if (mPinnedStackListener != null) { |
| 374 | try { |
| 375 | mPinnedStackListener.onSnapToEdgeStateChanged(isSnappingToEdge); |
| 376 | } catch (RemoteException e) { |
| 377 | Slog.e(TAG_WM, "Error delivering snap-to-edge changed event.", e); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Notifies listeners that the PIP actions have changed. |
| 384 | */ |
| 385 | private void notifyActionsChanged(List<RemoteAction> actions) { |
| 386 | if (mPinnedStackListener != null) { |
| 387 | try { |
| 388 | mPinnedStackListener.onActionsChanged(new ParceledListSlice(actions)); |
| 389 | } catch (RemoteException e) { |
| 390 | Slog.e(TAG_WM, "Error delivering actions changed event.", e); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 396 | * @return the bounds on the screen that the PIP can be visible in. |
| 397 | */ |
Winson Chung | 14fefc2 | 2016-11-02 10:02:29 -0700 | [diff] [blame] | 398 | private void getInsetBounds(Rect outRect) { |
| 399 | mService.mPolicy.getStableInsetsLw(mDisplayInfo.rotation, mDisplayInfo.logicalWidth, |
| 400 | mDisplayInfo.logicalHeight, mTmpInsets); |
| 401 | outRect.set(mTmpInsets.left + mScreenEdgeInsets.x, mTmpInsets.top + mScreenEdgeInsets.y, |
| 402 | mDisplayInfo.logicalWidth - mTmpInsets.right - mScreenEdgeInsets.x, |
| 403 | mDisplayInfo.logicalHeight - mTmpInsets.bottom - mScreenEdgeInsets.y); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /** |
| 407 | * @return the pixels for a given dp value. |
| 408 | */ |
| 409 | private int dpToPx(float dpValue, DisplayMetrics dm) { |
| 410 | return (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, dpValue, dm); |
| 411 | } |
| 412 | |
| 413 | void dump(String prefix, PrintWriter pw) { |
| 414 | pw.println(prefix + "PinnedStackController"); |
Jorim Jaggi | ad5d284 | 2016-11-01 18:22:53 -0700 | [diff] [blame] | 415 | pw.print(prefix + " defaultBounds="); getDefaultBounds().printShortString(pw); |
| 416 | pw.println(); |
| 417 | mService.getStackBounds(PINNED_STACK_ID, mTmpRect); |
| 418 | pw.print(prefix + " movementBounds="); getMovementBounds(mTmpRect).printShortString(pw); |
| 419 | pw.println(); |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 420 | pw.println(prefix + " mIsImeShowing=" + mIsImeShowing); |
| 421 | pw.println(prefix + " mInInteractiveMode=" + mInInteractiveMode); |
Winson Chung | fa705378 | 2016-11-08 15:45:10 -0800 | [diff] [blame] | 422 | pw.println(prefix + " mIsMinimized=" + mIsMinimized); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 423 | if (mActions.isEmpty()) { |
| 424 | pw.println(prefix + " mActions=[]"); |
| 425 | } else { |
| 426 | pw.println(prefix + " mActions=["); |
| 427 | for (int i = 0; i < mActions.size(); i++) { |
| 428 | RemoteAction action = mActions.get(i); |
| 429 | pw.print(prefix + " Action[" + i + "]: "); |
| 430 | action.dump("", pw); |
| 431 | } |
| 432 | pw.println(prefix + " ]"); |
| 433 | } |
Winson Chung | 655332c | 2016-10-31 13:14:28 -0700 | [diff] [blame] | 434 | } |
| 435 | } |