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