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