Winson | 73bc159 | 2016-10-18 18:47:43 -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.systemui.pip.phone; |
| 18 | |
Arthur Hung | d52d119 | 2019-08-30 16:06:59 +0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 21 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 23 | import android.app.ActivityTaskManager; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 24 | import android.app.IActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 25 | import android.app.IActivityTaskManager; |
Winson Chung | 3535df2 | 2017-01-17 18:43:39 -0800 | [diff] [blame] | 26 | import android.content.ComponentName; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 27 | import android.content.Context; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 28 | import android.content.pm.ParceledListSlice; |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 30 | import android.graphics.Rect; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 31 | import android.os.Handler; |
| 32 | import android.os.RemoteException; |
| 33 | import android.util.Log; |
Winson Chung | 85d3c8a | 2017-09-15 15:41:00 -0700 | [diff] [blame] | 34 | import android.util.Pair; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 35 | import android.view.DisplayInfo; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 36 | import android.view.IPinnedStackController; |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 37 | import android.view.WindowContainerTransaction; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 38 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 39 | import com.android.systemui.Dependency; |
| 40 | import com.android.systemui.UiOffloadThread; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 41 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 42 | import com.android.systemui.pip.BasePipManager; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 43 | import com.android.systemui.pip.PipBoundsHandler; |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 44 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 45 | import com.android.systemui.shared.system.InputConsumerController; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 46 | import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 47 | import com.android.systemui.shared.system.TaskStackChangeListener; |
| 48 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 49 | import com.android.systemui.wm.DisplayWindowController; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 50 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 51 | import java.io.PrintWriter; |
| 52 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Manages the picture-in-picture (PIP) UI and states for Phones. |
| 55 | */ |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 56 | public class PipManager implements BasePipManager { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 57 | private static final String TAG = "PipManager"; |
| 58 | |
| 59 | private static PipManager sPipController; |
| 60 | |
| 61 | private Context mContext; |
| 62 | private IActivityManager mActivityManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 63 | private IActivityTaskManager mActivityTaskManager; |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 64 | private Handler mHandler = new Handler(); |
| 65 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 66 | private final PinnedStackListener mPinnedStackListener = new PipManagerPinnedStackListener(); |
| 67 | private final DisplayInfo mTmpDisplayInfo = new DisplayInfo(); |
| 68 | private final Rect mTmpInsetBounds = new Rect(); |
| 69 | private final Rect mTmpNormalBounds = new Rect(); |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame] | 70 | private final Rect mReentryBounds = new Rect(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 71 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 72 | private PipBoundsHandler mPipBoundsHandler; |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 73 | private InputConsumerController mInputConsumerController; |
Winson Chung | 15504af | 2016-11-02 18:11:36 -0700 | [diff] [blame] | 74 | private PipMenuActivityController mMenuController; |
Winson Chung | 97a60d9 | 2017-01-18 16:01:53 -0800 | [diff] [blame] | 75 | private PipMediaController mMediaController; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 76 | private PipTouchHandler mTouchHandler; |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 77 | private PipAppOpsListener mAppOpsListener; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 78 | |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 79 | /** |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 80 | * Handler for display rotation changes. |
| 81 | */ |
| 82 | private final DisplayWindowController.OnDisplayWindowRotationController mRotationController = ( |
| 83 | int displayId, int fromRotation, int toRotation, WindowContainerTransaction t) -> { |
| 84 | final boolean changed = mPipBoundsHandler.onDisplayRotationChanged(mTmpNormalBounds, |
| 85 | displayId, fromRotation, toRotation, t); |
| 86 | if (changed) { |
| 87 | updateMovementBounds(mTmpNormalBounds, false /* fromImeAdjustment */, |
| 88 | false /* fromShelfAdjustment */); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | /** |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 93 | * Handler for system task stack changes. |
| 94 | */ |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 95 | private final TaskStackChangeListener mTaskStackListener = new TaskStackChangeListener() { |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 96 | @Override |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 97 | public void onActivityPinned(String packageName, int userId, int taskId, int stackId) { |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 98 | mTouchHandler.onActivityPinned(); |
Winson Chung | 97a60d9 | 2017-01-18 16:01:53 -0800 | [diff] [blame] | 99 | mMediaController.onActivityPinned(); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 100 | mMenuController.onActivityPinned(); |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 101 | mAppOpsListener.onActivityPinned(packageName); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 102 | |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 103 | Dependency.get(UiOffloadThread.class).execute(() -> { |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 104 | WindowManagerWrapper.getInstance().setPipVisibility(true); |
| 105 | }); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void onActivityUnpinned() { |
Winson Chung | 85d3c8a | 2017-09-15 15:41:00 -0700 | [diff] [blame] | 110 | final Pair<ComponentName, Integer> topPipActivityInfo = PipUtils.getTopPinnedActivity( |
| 111 | mContext, mActivityManager); |
| 112 | final ComponentName topActivity = topPipActivityInfo.first; |
Winson Chung | 85d3c8a | 2017-09-15 15:41:00 -0700 | [diff] [blame] | 113 | mMenuController.onActivityUnpinned(); |
| 114 | mTouchHandler.onActivityUnpinned(topActivity); |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 115 | mAppOpsListener.onActivityUnpinned(); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 116 | |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 117 | Dependency.get(UiOffloadThread.class).execute(() -> { |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 118 | WindowManagerWrapper.getInstance().setPipVisibility(topActivity != null); |
| 119 | }); |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 123 | public void onPinnedStackAnimationStarted() { |
| 124 | // Disable touches while the animation is running |
| 125 | mTouchHandler.setTouchEnabled(false); |
| 126 | } |
| 127 | |
| 128 | @Override |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 129 | public void onPinnedStackAnimationEnded() { |
Winson Chung | 85d3998 | 2017-02-24 15:21:25 -0800 | [diff] [blame] | 130 | // Re-enable touches after the animation completes |
| 131 | mTouchHandler.setTouchEnabled(true); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 132 | mTouchHandler.onPinnedStackAnimationEnded(); |
Winson Chung | 3448824 | 2017-04-26 15:53:51 -0700 | [diff] [blame] | 133 | mMenuController.onPinnedStackAnimationEnded(); |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Override |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 137 | public void onPinnedActivityRestartAttempt(boolean clearedTask) { |
Winson Chung | e6385a2 | 2017-05-02 18:15:16 -0700 | [diff] [blame] | 138 | mTouchHandler.getMotionHelper().expandPip(clearedTask /* skipAnimation */); |
Winson Chung | 929d4f7 | 2017-01-13 10:21:33 -0800 | [diff] [blame] | 139 | } |
| 140 | }; |
| 141 | |
| 142 | /** |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 143 | * Handler for messages from the PIP controller. |
| 144 | */ |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 145 | private class PipManagerPinnedStackListener extends PinnedStackListener { |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 146 | @Override |
| 147 | public void onListenerRegistered(IPinnedStackController controller) { |
| 148 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 149 | mPipBoundsHandler.setPinnedStackController(controller); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 150 | mTouchHandler.setPinnedStackController(controller); |
| 151 | }); |
| 152 | } |
| 153 | |
| 154 | @Override |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 155 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 156 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 157 | mPipBoundsHandler.onImeVisibilityChanged(imeVisible, imeHeight); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 158 | mTouchHandler.onImeVisibilityChanged(imeVisible, imeHeight); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 159 | }); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void onMinimizedStateChanged(boolean isMinimized) { |
| 164 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 165 | mPipBoundsHandler.onMinimizedStateChanged(isMinimized); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 166 | mTouchHandler.setMinimizedState(isMinimized, true /* fromController */); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 167 | }); |
| 168 | } |
| 169 | |
| 170 | @Override |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 171 | public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment, |
| 172 | boolean fromShelfAdjustment) { |
Hongwei Wang | 9b75180 | 2019-09-11 12:13:21 -0700 | [diff] [blame] | 173 | mHandler.post(() -> updateMovementBounds(animatingBounds, fromImeAdjustment, |
| 174 | fromShelfAdjustment)); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public void onActionsChanged(ParceledListSlice actions) { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 179 | mHandler.post(() -> mMenuController.setAppActions(actions)); |
| 180 | } |
| 181 | |
| 182 | @Override |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame] | 183 | public void onSaveReentryBounds(ComponentName componentName, Rect bounds) { |
| 184 | mHandler.post(() -> { |
| 185 | // On phones, the expansion animation that happens on pip tap before restoring |
| 186 | // to fullscreen makes it so that the bounds received here are the expanded |
| 187 | // bounds. We want to restore to the unexpanded bounds when re-entering pip, |
| 188 | // so we save the bounds before expansion (normal) instead of the current |
| 189 | // bounds. |
| 190 | mReentryBounds.set(mTouchHandler.getNormalBounds()); |
| 191 | // Apply the snap fraction of the current bounds to the normal bounds. |
| 192 | float snapFraction = mPipBoundsHandler.getSnapFraction(bounds); |
| 193 | mPipBoundsHandler.applySnapFraction(mReentryBounds, snapFraction); |
| 194 | // Save reentry bounds (normal non-expand bounds with current position applied). |
| 195 | mPipBoundsHandler.onSaveReentryBounds(componentName, mReentryBounds); |
| 196 | }); |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
jorgegil@google.com | 62f735e | 2019-10-30 14:37:19 -0700 | [diff] [blame] | 200 | public void onResetReentryBounds(ComponentName componentName) { |
| 201 | mHandler.post(() -> mPipBoundsHandler.onResetReentryBounds(componentName)); |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void onDisplayInfoChanged(DisplayInfo displayInfo) { |
| 206 | mHandler.post(() -> mPipBoundsHandler.onDisplayInfoChanged(displayInfo)); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void onConfigurationChanged() { |
| 211 | mHandler.post(() -> mPipBoundsHandler.onConfigurationChanged()); |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public void onAspectRatioChanged(float aspectRatio) { |
| 216 | mHandler.post(() -> mPipBoundsHandler.onAspectRatioChanged(aspectRatio)); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void onPrepareAnimation(Rect sourceRectHint, float aspectRatio, Rect bounds) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 221 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 222 | mPipBoundsHandler.onPrepareAnimation(sourceRectHint, aspectRatio, bounds); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 223 | }); |
| 224 | } |
| 225 | } |
| 226 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 227 | private PipManager() {} |
| 228 | |
| 229 | /** |
| 230 | * Initializes {@link PipManager}. |
| 231 | */ |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 232 | public void initialize(Context context, BroadcastDispatcher broadcastDispatcher, |
| 233 | DisplayWindowController displayWindowController) { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 234 | mContext = context; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 235 | mActivityManager = ActivityManager.getService(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 236 | mActivityTaskManager = ActivityTaskManager.getService(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 237 | |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 238 | try { |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 239 | WindowManagerWrapper.getInstance().addPinnedStackListener(mPinnedStackListener); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 240 | } catch (RemoteException e) { |
| 241 | Log.e(TAG, "Failed to register pinned stack listener", e); |
| 242 | } |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 243 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Winson Chung | a29eb98 | 2016-12-14 12:01:27 -0800 | [diff] [blame] | 244 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 245 | mPipBoundsHandler = new PipBoundsHandler(context); |
Winson Chung | cbb15a9 | 2018-01-25 17:46:16 +0000 | [diff] [blame] | 246 | mInputConsumerController = InputConsumerController.getPipInputConsumer(); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 247 | mMediaController = new PipMediaController(context, mActivityManager, broadcastDispatcher); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 248 | mMenuController = new PipMenuActivityController(context, mActivityManager, mMediaController, |
| 249 | mInputConsumerController); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 250 | mTouchHandler = new PipTouchHandler(context, mActivityManager, mActivityTaskManager, |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 251 | mMenuController, mInputConsumerController, mPipBoundsHandler); |
Winson Chung | 95bccdc | 2018-01-03 11:45:47 -0800 | [diff] [blame] | 252 | mAppOpsListener = new PipAppOpsListener(context, mActivityManager, |
| 253 | mTouchHandler.getMotionHelper()); |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 254 | displayWindowController.addRotationController(mRotationController); |
Arthur Hung | d52d119 | 2019-08-30 16:06:59 +0800 | [diff] [blame] | 255 | |
| 256 | // If SystemUI restart, and it already existed a pinned stack, |
| 257 | // register the pip input consumer to ensure touch can send to it. |
| 258 | try { |
| 259 | ActivityManager.StackInfo stackInfo = mActivityTaskManager.getStackInfo( |
| 260 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); |
| 261 | if (stackInfo != null) { |
| 262 | mInputConsumerController.registerInputConsumer(); |
| 263 | } |
| 264 | } catch (RemoteException e) { |
| 265 | e.printStackTrace(); |
| 266 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Updates the PIP per configuration changed. |
| 271 | */ |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 272 | public void onConfigurationChanged(Configuration newConfig) { |
Winson Chung | 303c6b7 | 2016-10-24 17:12:49 -0700 | [diff] [blame] | 273 | mTouchHandler.onConfigurationChanged(); |
| 274 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 275 | |
| 276 | /** |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 277 | * Expands the PIP. |
| 278 | */ |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 279 | @Override |
| 280 | public void expandPip() { |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 281 | mTouchHandler.getMotionHelper().expandPip(false /* skipAnimation */); |
| 282 | } |
| 283 | |
| 284 | /** |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 285 | * Hides the PIP menu. |
| 286 | */ |
| 287 | @Override |
| 288 | public void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) { |
| 289 | mMenuController.hideMenu(onStartCallback, onEndCallback); |
| 290 | } |
| 291 | |
| 292 | /** |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 293 | * Sent from KEYCODE_WINDOW handler in PhoneWindowManager, to request the menu to be shown. |
| 294 | */ |
| 295 | public void showPictureInPictureMenu() { |
| 296 | mTouchHandler.showPictureInPictureMenu(); |
| 297 | } |
| 298 | |
| 299 | /** |
Ben Lin | 1a80f12 | 2020-01-27 14:09:52 -0800 | [diff] [blame] | 300 | * Sets a customized touch gesture that replaces the default one. |
| 301 | */ |
| 302 | public void setTouchGesture(PipTouchGesture gesture) { |
| 303 | mTouchHandler.setTouchGesture(gesture); |
| 304 | } |
| 305 | |
| 306 | /** |
Hongwei Wang | 9b75180 | 2019-09-11 12:13:21 -0700 | [diff] [blame] | 307 | * Sets both shelf visibility and its height. |
| 308 | */ |
| 309 | @Override |
| 310 | public void setShelfHeight(boolean visible, int height) { |
| 311 | mHandler.post(() -> { |
| 312 | final boolean changed = mPipBoundsHandler.setShelfHeight(visible, height); |
| 313 | if (changed) { |
| 314 | mTouchHandler.onShelfVisibilityChanged(visible, height); |
| 315 | updateMovementBounds(mPipBoundsHandler.getLastDestinationBounds(), |
| 316 | false /* fromImeAdjustment */, true /* fromShelfAdjustment */); |
| 317 | } |
| 318 | }); |
| 319 | } |
| 320 | |
| 321 | private void updateMovementBounds(Rect animatingBounds, boolean fromImeAdjustment, |
| 322 | boolean fromShelfAdjustment) { |
| 323 | // Populate inset / normal bounds and DisplayInfo from mPipBoundsHandler first. |
| 324 | mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, |
| 325 | animatingBounds, mTmpDisplayInfo); |
| 326 | mTouchHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, |
| 327 | animatingBounds, fromImeAdjustment, fromShelfAdjustment, |
| 328 | mTmpDisplayInfo.rotation); |
| 329 | } |
| 330 | |
| 331 | /** |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 332 | * Gets an instance of {@link PipManager}. |
| 333 | */ |
| 334 | public static PipManager getInstance() { |
| 335 | if (sPipController == null) { |
| 336 | sPipController = new PipManager(); |
| 337 | } |
| 338 | return sPipController; |
| 339 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 340 | |
| 341 | public void dump(PrintWriter pw) { |
| 342 | final String innerPrefix = " "; |
| 343 | pw.println(TAG); |
Winson Chung | d2d9097 | 2017-02-28 11:40:41 -0800 | [diff] [blame] | 344 | mInputConsumerController.dump(pw, innerPrefix); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 345 | mMenuController.dump(pw, innerPrefix); |
| 346 | mTouchHandler.dump(pw, innerPrefix); |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 347 | mPipBoundsHandler.dump(pw, innerPrefix); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 348 | } |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 349 | } |