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