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