Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [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 | |
Winson | bf8c2c0 | 2016-10-18 18:56:24 -0700 | [diff] [blame] | 17 | package com.android.systemui.pip.tv; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 18 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 19 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
| 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 22 | |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 23 | import android.app.ActivityManager.RunningTaskInfo; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 24 | import android.app.ActivityManager.StackInfo; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 25 | import android.app.ActivityTaskManager; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 26 | import android.app.IActivityTaskManager; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.IntentFilter; |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 32 | import android.content.pm.ParceledListSlice; |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 33 | import android.content.res.Configuration; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 34 | import android.content.res.Resources; |
| 35 | import android.graphics.Rect; |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 36 | import android.media.session.MediaController; |
| 37 | import android.media.session.MediaSessionManager; |
Jaewan Kim | 8f584b8 | 2016-03-22 22:16:59 +0900 | [diff] [blame] | 38 | import android.media.session.PlaybackState; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 39 | import android.os.Debug; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 40 | import android.os.Handler; |
| 41 | import android.os.RemoteException; |
Kyeongkab.Nam | d61de15 | 2018-10-09 14:55:42 +0900 | [diff] [blame] | 42 | import android.os.UserHandle; |
Dongwon Kang | 353d8d7 | 2016-04-13 21:55:22 -0700 | [diff] [blame] | 43 | import android.text.TextUtils; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 44 | import android.util.Log; |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 45 | import android.util.Pair; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 46 | import android.view.DisplayInfo; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 47 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 48 | import com.android.systemui.Dependency; |
Jaewan Kim | 8f584b8 | 2016-03-22 22:16:59 +0900 | [diff] [blame] | 49 | import com.android.systemui.R; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 50 | import com.android.systemui.UiOffloadThread; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 51 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 52 | import com.android.systemui.pip.BasePipManager; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 53 | import com.android.systemui.pip.PipBoundsHandler; |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 54 | import com.android.systemui.pip.PipSurfaceTransactionHelper; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 55 | import com.android.systemui.pip.PipTaskOrganizer; |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 56 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 57 | import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 58 | import com.android.systemui.shared.system.TaskStackChangeListener; |
| 59 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Hongwei Wang | 5c52ff8 | 2020-04-20 16:02:30 -0700 | [diff] [blame] | 60 | import com.android.systemui.stackdivider.Divider; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 61 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 62 | import java.util.ArrayList; |
| 63 | import java.util.List; |
| 64 | |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 65 | import javax.inject.Inject; |
| 66 | import javax.inject.Singleton; |
| 67 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 68 | /** |
| 69 | * Manages the picture-in-picture (PIP) UI and states. |
| 70 | */ |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 71 | @Singleton |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 72 | public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitionCallback { |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 73 | private static final String TAG = "PipManager"; |
Jaewan Kim | 26c6356 | 2017-04-26 15:41:43 +0900 | [diff] [blame] | 74 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 75 | |
Jaewan Kim | 8af250e | 2017-02-14 19:12:01 +0900 | [diff] [blame] | 76 | private static final String SETTINGS_PACKAGE_AND_CLASS_DELIMITER = "/"; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 77 | |
Jaewan Kim | 8af250e | 2017-02-14 19:12:01 +0900 | [diff] [blame] | 78 | private static List<Pair<String, String>> sSettingsPackageAndClassNamePairList; |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 79 | |
| 80 | /** |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 81 | * State when there's no PIP. |
| 82 | */ |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 83 | public static final int STATE_NO_PIP = 0; |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 84 | /** |
Jaewan Kim | e630923 | 2017-04-14 15:26:20 +0900 | [diff] [blame] | 85 | * State when PIP is shown. This is used as default PIP state. |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 86 | */ |
Jaewan Kim | e630923 | 2017-04-14 15:26:20 +0900 | [diff] [blame] | 87 | public static final int STATE_PIP = 1; |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 88 | /** |
| 89 | * State when PIP menu dialog is shown. |
| 90 | */ |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 91 | public static final int STATE_PIP_MENU = 2; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 92 | |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 93 | private static final int TASK_ID_NO_PIP = -1; |
| 94 | private static final int INVALID_RESOURCE_TYPE = -1; |
| 95 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 96 | public static final int SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH = 0x1; |
Jaewan Kim | f40fcdc | 2016-03-04 17:58:22 +0900 | [diff] [blame] | 97 | |
Jaewan Kim | 8f584b8 | 2016-03-22 22:16:59 +0900 | [diff] [blame] | 98 | /** |
| 99 | * PIPed activity is playing a media and it can be paused. |
| 100 | */ |
| 101 | static final int PLAYBACK_STATE_PLAYING = 0; |
| 102 | /** |
| 103 | * PIPed activity has a paused media and it can be played. |
| 104 | */ |
| 105 | static final int PLAYBACK_STATE_PAUSED = 1; |
| 106 | /** |
| 107 | * Users are unable to control PIPed activity's media playback. |
| 108 | */ |
| 109 | static final int PLAYBACK_STATE_UNAVAILABLE = 2; |
| 110 | |
Jaewan Kim | f40fcdc | 2016-03-04 17:58:22 +0900 | [diff] [blame] | 111 | private static final int CLOSE_PIP_WHEN_MEDIA_SESSION_GONE_TIMEOUT_MS = 3000; |
| 112 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 113 | private int mSuspendPipResizingReason; |
| 114 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 115 | private Context mContext; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 116 | private PipBoundsHandler mPipBoundsHandler; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 117 | private PipTaskOrganizer mPipTaskOrganizer; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 118 | private IActivityTaskManager mActivityTaskManager; |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 119 | private MediaSessionManager mMediaSessionManager; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 120 | private int mState = STATE_NO_PIP; |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 121 | private int mResumeResizePinnedStackRunnableState = STATE_NO_PIP; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 122 | private final Handler mHandler = new Handler(); |
| 123 | private List<Listener> mListeners = new ArrayList<>(); |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 124 | private List<MediaListener> mMediaListeners = new ArrayList<>(); |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 125 | private Rect mCurrentPipBounds; |
| 126 | private Rect mPipBounds; |
Winson Chung | db2ad5d | 2017-02-07 17:18:01 -0800 | [diff] [blame] | 127 | private Rect mDefaultPipBounds = new Rect(); |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 128 | private Rect mSettingsPipBounds; |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 129 | private Rect mMenuModePipBounds; |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 130 | private int mLastOrientation = Configuration.ORIENTATION_UNDEFINED; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 131 | private boolean mInitialized; |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 132 | private int mPipTaskId = TASK_ID_NO_PIP; |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 133 | private int mPinnedStackId = INVALID_STACK_ID; |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 134 | private ComponentName mPipComponentName; |
| 135 | private MediaController mPipMediaController; |
Dongwon Kang | 353d8d7 | 2016-04-13 21:55:22 -0700 | [diff] [blame] | 136 | private String[] mLastPackagesResourceGranted; |
Jaewan Kim | 26c6356 | 2017-04-26 15:41:43 +0900 | [diff] [blame] | 137 | private PipNotification mPipNotification; |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 138 | private ParceledListSlice mCustomActions; |
Ben Lin | ede9a60 | 2020-02-26 12:16:09 -0800 | [diff] [blame] | 139 | private int mResizeAnimationDuration; |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 140 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 141 | // Used to calculate the movement bounds |
| 142 | private final DisplayInfo mTmpDisplayInfo = new DisplayInfo(); |
| 143 | private final Rect mTmpInsetBounds = new Rect(); |
| 144 | private final Rect mTmpNormalBounds = new Rect(); |
| 145 | |
Winson Chung | 44315c6 | 2017-08-24 13:35:24 -0700 | [diff] [blame] | 146 | // Keeps track of the IME visibility to adjust the PiP when the IME is visible |
| 147 | private boolean mImeVisible; |
| 148 | private int mImeHeightAdjustment; |
| 149 | |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 150 | private final PinnedStackListener mPinnedStackListener = new PipManagerPinnedStackListener(); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 151 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 152 | private final Runnable mResizePinnedStackRunnable = new Runnable() { |
| 153 | @Override |
| 154 | public void run() { |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 155 | resizePinnedStack(mResumeResizePinnedStackRunnableState); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 156 | } |
| 157 | }; |
Jaewan Kim | f40fcdc | 2016-03-04 17:58:22 +0900 | [diff] [blame] | 158 | private final Runnable mClosePipRunnable = new Runnable() { |
| 159 | @Override |
| 160 | public void run() { |
| 161 | closePip(); |
| 162 | } |
| 163 | }; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 164 | |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 165 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 166 | @Override |
| 167 | public void onReceive(Context context, Intent intent) { |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 168 | String action = intent.getAction(); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 169 | if (Intent.ACTION_MEDIA_RESOURCE_GRANTED.equals(action)) { |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 170 | String[] packageNames = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES); |
| 171 | int resourceType = intent.getIntExtra(Intent.EXTRA_MEDIA_RESOURCE_TYPE, |
| 172 | INVALID_RESOURCE_TYPE); |
Dongwon Kang | 353d8d7 | 2016-04-13 21:55:22 -0700 | [diff] [blame] | 173 | if (packageNames != null && packageNames.length > 0 |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 174 | && resourceType == Intent.EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC) { |
| 175 | handleMediaResourceGranted(packageNames); |
| 176 | } |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 177 | } |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 178 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 179 | } |
| 180 | }; |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 181 | private final MediaSessionManager.OnActiveSessionsChangedListener mActiveMediaSessionListener = |
| 182 | new MediaSessionManager.OnActiveSessionsChangedListener() { |
| 183 | @Override |
| 184 | public void onActiveSessionsChanged(List<MediaController> controllers) { |
| 185 | updateMediaController(controllers); |
| 186 | } |
| 187 | }; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 188 | |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 189 | /** |
| 190 | * Handler for messages from the PIP controller. |
| 191 | */ |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 192 | private class PipManagerPinnedStackListener extends PinnedStackListener { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 193 | @Override |
Winson Chung | 44315c6 | 2017-08-24 13:35:24 -0700 | [diff] [blame] | 194 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
| 195 | if (mState == STATE_PIP) { |
| 196 | if (mImeVisible != imeVisible) { |
| 197 | if (imeVisible) { |
| 198 | // Save the IME height adjustment, and offset to not occlude the IME |
| 199 | mPipBounds.offset(0, -imeHeight); |
| 200 | mImeHeightAdjustment = imeHeight; |
| 201 | } else { |
| 202 | // Apply the inverse adjustment when the IME is hidden |
| 203 | mPipBounds.offset(0, mImeHeightAdjustment); |
| 204 | } |
| 205 | mImeVisible = imeVisible; |
| 206 | resizePinnedStack(STATE_PIP); |
| 207 | } |
| 208 | } |
| 209 | } |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 210 | |
| 211 | @Override |
Hongwei Wang | 3c981f6 | 2020-04-07 16:16:26 -0700 | [diff] [blame] | 212 | public void onMovementBoundsChanged(boolean fromImeAdjustment) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 213 | mHandler.post(() -> { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 214 | // Populate the inset / normal bounds and DisplayInfo from mPipBoundsHandler first. |
Hongwei Wang | 3c981f6 | 2020-04-07 16:16:26 -0700 | [diff] [blame] | 215 | final Rect destinationBounds = new Rect(); |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 216 | mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, |
Hongwei Wang | 3c981f6 | 2020-04-07 16:16:26 -0700 | [diff] [blame] | 217 | destinationBounds, mTmpDisplayInfo); |
| 218 | mDefaultPipBounds.set(destinationBounds); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 219 | }); |
| 220 | } |
| 221 | |
| 222 | @Override |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 223 | public void onActionsChanged(ParceledListSlice actions) { |
| 224 | mCustomActions = actions; |
| 225 | mHandler.post(() -> { |
| 226 | for (int i = mListeners.size() - 1; i >= 0; --i) { |
| 227 | mListeners.get(i).onPipMenuActionsChanged(mCustomActions); |
| 228 | } |
| 229 | }); |
| 230 | } |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 233 | @Inject |
jorgegil@google.com | 5bdec5f | 2020-02-28 13:14:39 -0800 | [diff] [blame] | 234 | public PipManager(Context context, BroadcastDispatcher broadcastDispatcher, |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 235 | PipBoundsHandler pipBoundsHandler, |
Ben Lin | 6189fa4 | 2020-04-29 14:59:16 -0700 | [diff] [blame] | 236 | PipTaskOrganizer pipTaskOrganizer, |
Hongwei Wang | 5c52ff8 | 2020-04-20 16:02:30 -0700 | [diff] [blame] | 237 | PipSurfaceTransactionHelper surfaceTransactionHelper, |
| 238 | Divider divider) { |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 239 | if (mInitialized) { |
| 240 | return; |
| 241 | } |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 242 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 243 | mInitialized = true; |
| 244 | mContext = context; |
jorgegil@google.com | 5bdec5f | 2020-02-28 13:14:39 -0800 | [diff] [blame] | 245 | mPipBoundsHandler = pipBoundsHandler; |
Sergey Nikolaienkov | e767da4 | 2020-04-10 15:47:22 +0200 | [diff] [blame] | 246 | // Ensure that we have the display info in case we get calls to update the bounds before the |
| 247 | // listener calls back |
| 248 | final DisplayInfo displayInfo = new DisplayInfo(); |
| 249 | context.getDisplay().getDisplayInfo(displayInfo); |
| 250 | mPipBoundsHandler.onDisplayInfoChanged(displayInfo); |
| 251 | |
Ben Lin | ede9a60 | 2020-02-26 12:16:09 -0800 | [diff] [blame] | 252 | mResizeAnimationDuration = context.getResources() |
| 253 | .getInteger(R.integer.config_pipResizeAnimationDuration); |
Ben Lin | 6189fa4 | 2020-04-29 14:59:16 -0700 | [diff] [blame] | 254 | mPipTaskOrganizer = pipTaskOrganizer; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 255 | mPipTaskOrganizer.registerPipTransitionCallback(this); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 256 | mActivityTaskManager = ActivityTaskManager.getService(); |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 257 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 258 | IntentFilter intentFilter = new IntentFilter(); |
| 259 | intentFilter.addAction(Intent.ACTION_MEDIA_RESOURCE_GRANTED); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 260 | broadcastDispatcher.registerReceiver(mBroadcastReceiver, intentFilter, |
| 261 | null /* handler */, UserHandle.ALL); |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 262 | |
Jaewan Kim | 8af250e | 2017-02-14 19:12:01 +0900 | [diff] [blame] | 263 | if (sSettingsPackageAndClassNamePairList == null) { |
| 264 | String[] settings = mContext.getResources().getStringArray( |
| 265 | R.array.tv_pip_settings_class_name); |
| 266 | sSettingsPackageAndClassNamePairList = new ArrayList<>(); |
| 267 | if (settings != null) { |
| 268 | for (int i = 0; i < settings.length; i++) { |
| 269 | Pair<String, String> entry = null; |
| 270 | String[] packageAndClassName = |
| 271 | settings[i].split(SETTINGS_PACKAGE_AND_CLASS_DELIMITER); |
| 272 | switch (packageAndClassName.length) { |
| 273 | case 1: |
| 274 | entry = Pair.<String, String>create(packageAndClassName[0], null); |
| 275 | break; |
| 276 | case 2: |
Shuichi.Noguchi | d206782 | 2018-01-13 21:47:04 +0900 | [diff] [blame] | 277 | if (packageAndClassName[1] != null) { |
| 278 | entry = Pair.<String, String>create(packageAndClassName[0], |
| 279 | packageAndClassName[1].startsWith(".") |
| 280 | ? packageAndClassName[0] + packageAndClassName[1] |
| 281 | : packageAndClassName[1]); |
Jaewan Kim | dc29875 | 2017-02-24 10:45:12 +0900 | [diff] [blame] | 282 | } |
Shuichi.Noguchi | d206782 | 2018-01-13 21:47:04 +0900 | [diff] [blame] | 283 | break; |
Jaewan Kim | 8af250e | 2017-02-14 19:12:01 +0900 | [diff] [blame] | 284 | } |
| 285 | if (entry != null) { |
| 286 | sSettingsPackageAndClassNamePairList.add(entry); |
Jaewan Kim | dc29875 | 2017-02-24 10:45:12 +0900 | [diff] [blame] | 287 | } else { |
| 288 | Log.w(TAG, "Ignoring malformed settings name " + settings[i]); |
Jaewan Kim | 8af250e | 2017-02-14 19:12:01 +0900 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
Winson Chung | 8068ec2 | 2017-06-02 09:58:00 -0700 | [diff] [blame] | 294 | // Initialize the last orientation and apply the current configuration |
| 295 | Configuration initialConfig = mContext.getResources().getConfiguration(); |
| 296 | mLastOrientation = initialConfig.orientation; |
| 297 | loadConfigurationsAndApply(initialConfig); |
| 298 | |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 299 | mMediaSessionManager = |
| 300 | (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE); |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 301 | |
| 302 | try { |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 303 | WindowManagerWrapper.getInstance().addPinnedStackListener(mPinnedStackListener); |
Wale Ogunwale | adf116e | 2020-03-27 16:36:01 -0700 | [diff] [blame] | 304 | mPipTaskOrganizer.registerOrganizer(WINDOWING_MODE_PINNED); |
Hongwei Wang | c90eb8e | 2020-03-27 12:45:13 -0700 | [diff] [blame] | 305 | } catch (RemoteException | UnsupportedOperationException e) { |
Winson Chung | 2a82fe5 | 2017-02-02 14:43:34 -0800 | [diff] [blame] | 306 | Log.e(TAG, "Failed to register pinned stack listener", e); |
| 307 | } |
Jaewan Kim | 26c6356 | 2017-04-26 15:41:43 +0900 | [diff] [blame] | 308 | |
Dave Mankoff | f501914 | 2019-12-20 16:22:57 -0500 | [diff] [blame] | 309 | mPipNotification = new PipNotification(context, broadcastDispatcher, this); |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 310 | } |
| 311 | |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 312 | private void loadConfigurationsAndApply(Configuration newConfig) { |
| 313 | if (mLastOrientation != newConfig.orientation) { |
| 314 | // Don't resize the pinned stack on orientation change. TV does not care about this case |
| 315 | // and this could clobber the existing animation to the new bounds calculated by WM. |
| 316 | mLastOrientation = newConfig.orientation; |
| 317 | return; |
| 318 | } |
| 319 | |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 320 | Resources res = mContext.getResources(); |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 321 | mSettingsPipBounds = Rect.unflattenFromString(res.getString( |
| 322 | R.string.pip_settings_bounds)); |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 323 | mMenuModePipBounds = Rect.unflattenFromString(res.getString( |
Jaewan Kim | 8f584b8 | 2016-03-22 22:16:59 +0900 | [diff] [blame] | 324 | R.string.pip_menu_bounds)); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 325 | |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 326 | // Reset the PIP bounds and apply. PIP bounds can be changed by two reasons. |
| 327 | // 1. Configuration changed due to the language change (RTL <-> RTL) |
| 328 | // 2. SystemUI restarts after the crash |
| 329 | mPipBounds = isSettingsShown() ? mSettingsPipBounds : mDefaultPipBounds; |
Jaewan Kim | e630923 | 2017-04-14 15:26:20 +0900 | [diff] [blame] | 330 | resizePinnedStack(getPinnedStackInfo() == null ? STATE_NO_PIP : STATE_PIP); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 333 | /** |
Jaewan Kim | 2d4d07c | 2016-05-20 10:28:17 +0900 | [diff] [blame] | 334 | * Updates the PIP per configuration changed. |
| 335 | */ |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 336 | public void onConfigurationChanged(Configuration newConfig) { |
| 337 | loadConfigurationsAndApply(newConfig); |
Jaewan Kim | 26c6356 | 2017-04-26 15:41:43 +0900 | [diff] [blame] | 338 | mPipNotification.onConfigurationChanged(mContext); |
Jaewan Kim | 2d4d07c | 2016-05-20 10:28:17 +0900 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /** |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 342 | * Shows the picture-in-picture menu if an activity is in picture-in-picture mode. |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 343 | */ |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 344 | public void showPictureInPictureMenu() { |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 345 | if (DEBUG) Log.d(TAG, "showPictureInPictureMenu(), current state=" + getStateDescription()); |
| 346 | |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 347 | if (getState() == STATE_PIP) { |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 348 | resizePinnedStack(STATE_PIP_MENU); |
Jaewan Kim | c552b04 | 2016-01-18 16:08:45 +0900 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 352 | /** |
Jaewan Kim | 977dcdc | 2016-01-20 19:21:08 +0900 | [diff] [blame] | 353 | * Closes PIP (PIPed activity and PIP system UI). |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 354 | */ |
| 355 | public void closePip() { |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 356 | if (DEBUG) Log.d(TAG, "closePip(), current state=" + getStateDescription()); |
| 357 | |
Youngsang Cho | 336007b | 2016-02-22 11:17:29 -0800 | [diff] [blame] | 358 | closePipInternal(true); |
Youngsang Cho | 23df699 | 2016-01-26 17:51:33 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Youngsang Cho | 336007b | 2016-02-22 11:17:29 -0800 | [diff] [blame] | 361 | private void closePipInternal(boolean removePipStack) { |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 362 | if (DEBUG) { |
| 363 | Log.d(TAG, |
| 364 | "closePipInternal() removePipStack=" + removePipStack + ", current state=" |
| 365 | + getStateDescription()); |
| 366 | } |
| 367 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 368 | mState = STATE_NO_PIP; |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 369 | mPipTaskId = TASK_ID_NO_PIP; |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 370 | mPipMediaController = null; |
| 371 | mMediaSessionManager.removeOnActiveSessionsChangedListener(mActiveMediaSessionListener); |
Youngsang Cho | 23df699 | 2016-01-26 17:51:33 -0800 | [diff] [blame] | 372 | if (removePipStack) { |
| 373 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 374 | mActivityTaskManager.removeStack(mPinnedStackId); |
Youngsang Cho | 23df699 | 2016-01-26 17:51:33 -0800 | [diff] [blame] | 375 | } catch (RemoteException e) { |
| 376 | Log.e(TAG, "removeStack failed", e); |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 377 | } finally { |
| 378 | mPinnedStackId = INVALID_STACK_ID; |
Youngsang Cho | 23df699 | 2016-01-26 17:51:33 -0800 | [diff] [blame] | 379 | } |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 380 | } |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 381 | for (int i = mListeners.size() - 1; i >= 0; --i) { |
| 382 | mListeners.get(i).onPipActivityClosed(); |
| 383 | } |
Jaewan Kim | f40fcdc | 2016-03-04 17:58:22 +0900 | [diff] [blame] | 384 | mHandler.removeCallbacks(mClosePipRunnable); |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 385 | updatePipVisibility(false); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | /** |
Jaewan Kim | 977dcdc | 2016-01-20 19:21:08 +0900 | [diff] [blame] | 389 | * Moves the PIPed activity to the fullscreen and closes PIP system UI. |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 390 | */ |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 391 | void movePipToFullscreen() { |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 392 | if (DEBUG) Log.d(TAG, "movePipToFullscreen(), current state=" + getStateDescription()); |
| 393 | |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 394 | mPipTaskId = TASK_ID_NO_PIP; |
Jaewan Kim | b003364 | 2016-04-22 18:41:37 +0900 | [diff] [blame] | 395 | for (int i = mListeners.size() - 1; i >= 0; --i) { |
| 396 | mListeners.get(i).onMoveToFullscreen(); |
| 397 | } |
Winson Chung | f04c1dd | 2017-02-24 16:47:37 -0800 | [diff] [blame] | 398 | resizePinnedStack(STATE_NO_PIP); |
Jaewan Kim | 47fe286 | 2016-10-10 16:23:28 +0900 | [diff] [blame] | 399 | updatePipVisibility(false); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 403 | * Suspends resizing operation on the Pip until {@link #resumePipResizing} is called |
| 404 | * @param reason The reason for suspending resizing operations on the Pip. |
| 405 | */ |
| 406 | public void suspendPipResizing(int reason) { |
| 407 | if (DEBUG) Log.d(TAG, |
| 408 | "suspendPipResizing() reason=" + reason + " callers=" + Debug.getCallers(2)); |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 409 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 410 | mSuspendPipResizingReason |= reason; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Resumes resizing operation on the Pip that was previously suspended. |
| 415 | * @param reason The reason resizing operations on the Pip was suspended. |
| 416 | */ |
| 417 | public void resumePipResizing(int reason) { |
| 418 | if ((mSuspendPipResizingReason & reason) == 0) { |
| 419 | return; |
| 420 | } |
| 421 | if (DEBUG) Log.d(TAG, |
| 422 | "resumePipResizing() reason=" + reason + " callers=" + Debug.getCallers(2)); |
| 423 | mSuspendPipResizingReason &= ~reason; |
| 424 | mHandler.post(mResizePinnedStackRunnable); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Resize the Pip to the appropriate size for the input state. |
| 429 | * @param state In Pip state also used to determine the new size for the Pip. |
| 430 | */ |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 431 | void resizePinnedStack(int state) { |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 432 | if (DEBUG) { |
| 433 | Log.d(TAG, "resizePinnedStack() state=" + stateToName(state) + ", current state=" |
| 434 | + getStateDescription(), new Exception()); |
| 435 | } |
| 436 | |
Winson Chung | f04c1dd | 2017-02-24 16:47:37 -0800 | [diff] [blame] | 437 | boolean wasStateNoPip = (mState == STATE_NO_PIP); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 438 | for (int i = mListeners.size() - 1; i >= 0; --i) { |
| 439 | mListeners.get(i).onPipResizeAboutToStart(); |
| 440 | } |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 441 | if (mSuspendPipResizingReason != 0) { |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 442 | mResumeResizePinnedStackRunnableState = state; |
Winson Chung | d62acec | 2017-03-31 19:42:32 -0700 | [diff] [blame] | 443 | if (DEBUG) Log.d(TAG, "resizePinnedStack() deferring" |
| 444 | + " mSuspendPipResizingReason=" + mSuspendPipResizingReason |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 445 | + " mResumeResizePinnedStackRunnableState=" |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 446 | + stateToName(mResumeResizePinnedStackRunnableState)); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 447 | return; |
| 448 | } |
Winson Chung | d62acec | 2017-03-31 19:42:32 -0700 | [diff] [blame] | 449 | mState = state; |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 450 | switch (mState) { |
| 451 | case STATE_NO_PIP: |
| 452 | mCurrentPipBounds = null; |
Winson Chung | f04c1dd | 2017-02-24 16:47:37 -0800 | [diff] [blame] | 453 | // If the state was already STATE_NO_PIP, then do not resize the stack below as it |
| 454 | // will not exist |
| 455 | if (wasStateNoPip) { |
| 456 | return; |
| 457 | } |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 458 | break; |
| 459 | case STATE_PIP_MENU: |
| 460 | mCurrentPipBounds = mMenuModePipBounds; |
| 461 | break; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 462 | case STATE_PIP: // fallthrough |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 463 | default: |
| 464 | mCurrentPipBounds = mPipBounds; |
| 465 | break; |
| 466 | } |
Sergey Nikolaienkov | fe0723f | 2020-04-13 09:14:23 +0200 | [diff] [blame] | 467 | if (mCurrentPipBounds != null) { |
| 468 | mPipTaskOrganizer.scheduleAnimateResizePip(mCurrentPipBounds, mResizeAnimationDuration, |
| 469 | null); |
| 470 | } else { |
| 471 | mPipTaskOrganizer.dismissPip(mResizeAnimationDuration); |
| 472 | } |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /** |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 476 | * @return the current state, or the pending state if the state change was previously suspended. |
| 477 | */ |
| 478 | private int getState() { |
| 479 | if (mSuspendPipResizingReason != 0) { |
| 480 | return mResumeResizePinnedStackRunnableState; |
| 481 | } |
| 482 | return mState; |
| 483 | } |
| 484 | |
| 485 | /** |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 486 | * Shows PIP menu UI by launching {@link PipMenuActivity}. It also locates the pinned |
Jaewan Kim | 8f584b8 | 2016-03-22 22:16:59 +0900 | [diff] [blame] | 487 | * stack to the centered PIP bound {@link R.config_centeredPictureInPictureBounds}. |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 488 | */ |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 489 | private void showPipMenu() { |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 490 | if (DEBUG) Log.d(TAG, "showPipMenu(), current state=" + getStateDescription()); |
| 491 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 492 | mState = STATE_PIP_MENU; |
| 493 | for (int i = mListeners.size() - 1; i >= 0; --i) { |
| 494 | mListeners.get(i).onShowPipMenu(); |
| 495 | } |
| 496 | Intent intent = new Intent(mContext, PipMenuActivity.class); |
| 497 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 498 | intent.putExtra(PipMenuActivity.EXTRA_CUSTOM_ACTIONS, mCustomActions); |
Jaewan Kim | 1a9dc56 | 2016-02-17 13:41:51 -0800 | [diff] [blame] | 499 | mContext.startActivity(intent); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 502 | /** |
| 503 | * Adds a {@link Listener} to PipManager. |
| 504 | */ |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 505 | public void addListener(Listener listener) { |
| 506 | mListeners.add(listener); |
| 507 | } |
| 508 | |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 509 | /** |
| 510 | * Removes a {@link Listener} from PipManager. |
| 511 | */ |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 512 | public void removeListener(Listener listener) { |
| 513 | mListeners.remove(listener); |
| 514 | } |
| 515 | |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 516 | /** |
| 517 | * Adds a {@link MediaListener} to PipManager. |
| 518 | */ |
| 519 | public void addMediaListener(MediaListener listener) { |
| 520 | mMediaListeners.add(listener); |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Removes a {@link MediaListener} from PipManager. |
| 525 | */ |
| 526 | public void removeMediaListener(MediaListener listener) { |
| 527 | mMediaListeners.remove(listener); |
| 528 | } |
| 529 | |
Jaewan Kim | c92a7d1 | 2016-02-15 17:33:25 -0800 | [diff] [blame] | 530 | /** |
| 531 | * Returns {@code true} if PIP is shown. |
| 532 | */ |
| 533 | public boolean isPipShown() { |
Jaewan Kim | 82ac50d | 2016-03-21 17:34:28 +0900 | [diff] [blame] | 534 | return mState != STATE_NO_PIP; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 535 | } |
| 536 | |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 537 | private StackInfo getPinnedStackInfo() { |
| 538 | StackInfo stackInfo = null; |
| 539 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 540 | stackInfo = ActivityTaskManager.getService().getStackInfo( |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 541 | WINDOWING_MODE_PINNED, ACTIVITY_TYPE_UNDEFINED); |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 542 | } catch (RemoteException e) { |
| 543 | Log.e(TAG, "getStackInfo failed", e); |
| 544 | } |
| 545 | return stackInfo; |
| 546 | } |
| 547 | |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 548 | private void handleMediaResourceGranted(String[] packageNames) { |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 549 | if (getState() == STATE_NO_PIP) { |
Dongwon Kang | 353d8d7 | 2016-04-13 21:55:22 -0700 | [diff] [blame] | 550 | mLastPackagesResourceGranted = packageNames; |
| 551 | } else { |
| 552 | boolean requestedFromLastPackages = false; |
| 553 | if (mLastPackagesResourceGranted != null) { |
| 554 | for (String packageName : mLastPackagesResourceGranted) { |
| 555 | for (String newPackageName : packageNames) { |
| 556 | if (TextUtils.equals(newPackageName, packageName)) { |
| 557 | requestedFromLastPackages = true; |
| 558 | break; |
| 559 | } |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | } |
Dongwon Kang | 353d8d7 | 2016-04-13 21:55:22 -0700 | [diff] [blame] | 563 | mLastPackagesResourceGranted = packageNames; |
| 564 | if (!requestedFromLastPackages) { |
| 565 | closePip(); |
| 566 | } |
Youngsang Cho | ad8ceb0 | 2016-01-15 16:59:27 -0800 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 570 | private void updateMediaController(List<MediaController> controllers) { |
| 571 | MediaController mediaController = null; |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 572 | if (controllers != null && getState() != STATE_NO_PIP && mPipComponentName != null) { |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 573 | for (int i = controllers.size() - 1; i >= 0; i--) { |
| 574 | MediaController controller = controllers.get(i); |
| 575 | // We assumes that an app with PIPable activity |
| 576 | // keeps the single instance of media controller especially when PIP is on. |
| 577 | if (controller.getPackageName().equals(mPipComponentName.getPackageName())) { |
| 578 | mediaController = controller; |
| 579 | break; |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | if (mPipMediaController != mediaController) { |
| 584 | mPipMediaController = mediaController; |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 585 | for (int i = mMediaListeners.size() - 1; i >= 0; i--) { |
| 586 | mMediaListeners.get(i).onMediaControllerChanged(); |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 587 | } |
Jaewan Kim | f40fcdc | 2016-03-04 17:58:22 +0900 | [diff] [blame] | 588 | if (mPipMediaController == null) { |
| 589 | mHandler.postDelayed(mClosePipRunnable, |
| 590 | CLOSE_PIP_WHEN_MEDIA_SESSION_GONE_TIMEOUT_MS); |
| 591 | } else { |
| 592 | mHandler.removeCallbacks(mClosePipRunnable); |
| 593 | } |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * Gets the {@link android.media.session.MediaController} for the PIPed activity. |
| 599 | */ |
| 600 | MediaController getMediaController() { |
| 601 | return mPipMediaController; |
| 602 | } |
| 603 | |
Jaewan Kim | 8f584b8 | 2016-03-22 22:16:59 +0900 | [diff] [blame] | 604 | /** |
| 605 | * Returns the PIPed activity's playback state. |
Jaewan Kim | 26c6356 | 2017-04-26 15:41:43 +0900 | [diff] [blame] | 606 | * This returns one of {@link #PLAYBACK_STATE_PLAYING}, {@link #PLAYBACK_STATE_PAUSED}, |
| 607 | * or {@link #PLAYBACK_STATE_UNAVAILABLE}. |
Jaewan Kim | 8f584b8 | 2016-03-22 22:16:59 +0900 | [diff] [blame] | 608 | */ |
| 609 | int getPlaybackState() { |
| 610 | if (mPipMediaController == null || mPipMediaController.getPlaybackState() == null) { |
| 611 | return PLAYBACK_STATE_UNAVAILABLE; |
| 612 | } |
| 613 | int state = mPipMediaController.getPlaybackState().getState(); |
| 614 | boolean isPlaying = (state == PlaybackState.STATE_BUFFERING |
| 615 | || state == PlaybackState.STATE_CONNECTING |
| 616 | || state == PlaybackState.STATE_PLAYING |
| 617 | || state == PlaybackState.STATE_FAST_FORWARDING |
| 618 | || state == PlaybackState.STATE_REWINDING |
| 619 | || state == PlaybackState.STATE_SKIPPING_TO_PREVIOUS |
| 620 | || state == PlaybackState.STATE_SKIPPING_TO_NEXT); |
| 621 | long actions = mPipMediaController.getPlaybackState().getActions(); |
| 622 | if (!isPlaying && ((actions & PlaybackState.ACTION_PLAY) != 0)) { |
| 623 | return PLAYBACK_STATE_PAUSED; |
| 624 | } else if (isPlaying && ((actions & PlaybackState.ACTION_PAUSE) != 0)) { |
| 625 | return PLAYBACK_STATE_PLAYING; |
| 626 | } |
| 627 | return PLAYBACK_STATE_UNAVAILABLE; |
| 628 | } |
| 629 | |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 630 | private boolean isSettingsShown() { |
| 631 | List<RunningTaskInfo> runningTasks; |
| 632 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 633 | runningTasks = mActivityTaskManager.getTasks(1); |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 634 | if (runningTasks.isEmpty()) { |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | } catch (RemoteException e) { |
| 638 | Log.d(TAG, "Failed to detect top activity", e); |
| 639 | return false; |
| 640 | } |
| 641 | ComponentName topActivity = runningTasks.get(0).topActivity; |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 642 | for (Pair<String, String> componentName : sSettingsPackageAndClassNamePairList) { |
| 643 | String packageName = componentName.first; |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 644 | if (topActivity.getPackageName().equals(packageName)) { |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 645 | String className = componentName.second; |
| 646 | if (className == null || topActivity.getClassName().equals(className)) { |
| 647 | return true; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | return false; |
| 652 | } |
| 653 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 654 | private TaskStackChangeListener mTaskStackListener = new TaskStackChangeListener() { |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 655 | @Override |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 656 | public void onTaskStackChanged() { |
Jaewan Kim | 17ca4e3 | 2016-10-31 13:55:43 +0900 | [diff] [blame] | 657 | if (DEBUG) Log.d(TAG, "onTaskStackChanged()"); |
Shuichi.Noguchi | e9d2dd6 | 2017-11-22 17:24:17 +0900 | [diff] [blame] | 658 | |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 659 | if (getState() != STATE_NO_PIP) { |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 660 | boolean hasPip = false; |
| 661 | |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 662 | StackInfo stackInfo = getPinnedStackInfo(); |
| 663 | if (stackInfo == null || stackInfo.taskIds == null) { |
| 664 | Log.w(TAG, "There is nothing in pinned stack"); |
| 665 | closePipInternal(false); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 666 | return; |
| 667 | } |
| 668 | for (int i = stackInfo.taskIds.length - 1; i >= 0; --i) { |
| 669 | if (stackInfo.taskIds[i] == mPipTaskId) { |
| 670 | // PIP task is still alive. |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 671 | hasPip = true; |
| 672 | break; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 673 | } |
| 674 | } |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 675 | if (!hasPip) { |
| 676 | // PIP task doesn't exist anymore in PINNED_STACK. |
| 677 | closePipInternal(true); |
| 678 | return; |
| 679 | } |
| 680 | } |
Winson Chung | 0a65737 | 2017-05-12 15:04:54 -0700 | [diff] [blame] | 681 | if (getState() == STATE_PIP) { |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 682 | Rect bounds = isSettingsShown() ? mSettingsPipBounds : mDefaultPipBounds; |
| 683 | if (mPipBounds != bounds) { |
| 684 | mPipBounds = bounds; |
Jaewan Kim | e630923 | 2017-04-14 15:26:20 +0900 | [diff] [blame] | 685 | resizePinnedStack(STATE_PIP); |
Jaewan Kim | d89a694 | 2016-04-08 11:41:45 +0900 | [diff] [blame] | 686 | } |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 687 | } |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | @Override |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 691 | public void onActivityPinned(String packageName, int userId, int taskId, int stackId) { |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 692 | if (DEBUG) Log.d(TAG, "onActivityPinned()"); |
Shuichi.Noguchi | e9d2dd6 | 2017-11-22 17:24:17 +0900 | [diff] [blame] | 693 | |
Jaewan Kim | 73ef351 | 2016-07-18 13:50:33 +0900 | [diff] [blame] | 694 | StackInfo stackInfo = getPinnedStackInfo(); |
| 695 | if (stackInfo == null) { |
| 696 | Log.w(TAG, "Cannot find pinned stack"); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 697 | return; |
| 698 | } |
| 699 | if (DEBUG) Log.d(TAG, "PINNED_STACK:" + stackInfo); |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 700 | mPinnedStackId = stackInfo.stackId; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 701 | mPipTaskId = stackInfo.taskIds[stackInfo.taskIds.length - 1]; |
| 702 | mPipComponentName = ComponentName.unflattenFromString( |
| 703 | stackInfo.taskNames[stackInfo.taskNames.length - 1]); |
Jaewan Kim | e630923 | 2017-04-14 15:26:20 +0900 | [diff] [blame] | 704 | // Set state to STATE_PIP so we show it when the pinned stack animation ends. |
| 705 | mState = STATE_PIP; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 706 | mCurrentPipBounds = mPipBounds; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 707 | mMediaSessionManager.addOnActiveSessionsChangedListener( |
| 708 | mActiveMediaSessionListener, null); |
| 709 | updateMediaController(mMediaSessionManager.getActiveSessions(null)); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 710 | for (int i = mListeners.size() - 1; i >= 0; i--) { |
Sergey Nikolaienkov | 00861da | 2020-04-27 10:56:26 +0200 | [diff] [blame] | 711 | mListeners.get(i).onPipEntered(packageName); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 712 | } |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 713 | updatePipVisibility(true); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 714 | } |
Wale Ogunwale | cc25a8a | 2016-01-23 14:31:37 -0800 | [diff] [blame] | 715 | |
| 716 | @Override |
Winson Chung | e789ff6 | 2020-02-24 14:40:23 -0800 | [diff] [blame] | 717 | public void onActivityRestartAttempt(RunningTaskInfo task, boolean homeTaskVisible, |
Evan Rosky | 8d1c24e | 2020-04-23 09:21:16 -0700 | [diff] [blame] | 718 | boolean clearedTask, boolean wasVisible) { |
| 719 | if (!wasVisible || task.configuration.windowConfiguration.getWindowingMode() |
Winson Chung | e789ff6 | 2020-02-24 14:40:23 -0800 | [diff] [blame] | 720 | != WINDOWING_MODE_PINNED) { |
| 721 | return; |
| 722 | } |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 723 | if (DEBUG) Log.d(TAG, "onPinnedActivityRestartAttempt()"); |
Shuichi.Noguchi | e9d2dd6 | 2017-11-22 17:24:17 +0900 | [diff] [blame] | 724 | |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 725 | // If PIPed activity is launched again by Launcher or intent, make it fullscreen. |
| 726 | movePipToFullscreen(); |
Wale Ogunwale | cc25a8a | 2016-01-23 14:31:37 -0800 | [diff] [blame] | 727 | } |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 728 | }; |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 729 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 730 | @Override |
Hongwei Wang | 221fe3d | 2020-03-26 13:13:04 -0700 | [diff] [blame] | 731 | public void onPipTransitionStarted(ComponentName activity, int direction) { } |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 732 | |
| 733 | @Override |
Hongwei Wang | 221fe3d | 2020-03-26 13:13:04 -0700 | [diff] [blame] | 734 | public void onPipTransitionFinished(ComponentName activity, int direction) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 735 | onPipTransitionFinishedOrCanceled(); |
| 736 | } |
| 737 | |
| 738 | @Override |
Hongwei Wang | 221fe3d | 2020-03-26 13:13:04 -0700 | [diff] [blame] | 739 | public void onPipTransitionCanceled(ComponentName activity, int direction) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 740 | onPipTransitionFinishedOrCanceled(); |
| 741 | } |
| 742 | |
| 743 | private void onPipTransitionFinishedOrCanceled() { |
| 744 | if (DEBUG) Log.d(TAG, "onPipTransitionFinishedOrCanceled()"); |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 745 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 746 | if (getState() == STATE_PIP_MENU) { |
| 747 | showPipMenu(); |
| 748 | } |
| 749 | } |
| 750 | |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 751 | /** |
| 752 | * A listener interface to receive notification on changes in PIP. |
| 753 | */ |
| 754 | public interface Listener { |
Jaewan Kim | 82ac50d | 2016-03-21 17:34:28 +0900 | [diff] [blame] | 755 | /** |
| 756 | * Invoked when an activity is pinned and PIP manager is set corresponding information. |
| 757 | * Classes must use this instead of {@link android.app.ITaskStackListener.onActivityPinned} |
| 758 | * because there's no guarantee for the PIP manager be return relavent information |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 759 | * correctly. (e.g. {@link isPipShown}). |
Jaewan Kim | 82ac50d | 2016-03-21 17:34:28 +0900 | [diff] [blame] | 760 | */ |
Sergey Nikolaienkov | 00861da | 2020-04-27 10:56:26 +0200 | [diff] [blame] | 761 | void onPipEntered(String packageName); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 762 | /** Invoked when a PIPed activity is closed. */ |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 763 | void onPipActivityClosed(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 764 | /** Invoked when the PIP menu gets shown. */ |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 765 | void onShowPipMenu(); |
Winson Chung | b6de872 | 2017-06-02 12:45:51 -0700 | [diff] [blame] | 766 | /** Invoked when the PIP menu actions change. */ |
| 767 | void onPipMenuActionsChanged(ParceledListSlice actions); |
Jaewan Kim | 10a8691 | 2016-04-04 16:01:51 +0900 | [diff] [blame] | 768 | /** Invoked when the PIPed activity is about to return back to the fullscreen. */ |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 769 | void onMoveToFullscreen(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 770 | /** Invoked when we are above to start resizing the Pip. */ |
| 771 | void onPipResizeAboutToStart(); |
Jaewan Kim | a0d4d25 | 2016-03-31 13:37:10 +0900 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /** |
| 775 | * A listener interface to receive change in PIP's media controller |
| 776 | */ |
| 777 | public interface MediaListener { |
Jaewan Kim | 6233819 | 2016-02-25 10:00:05 -0800 | [diff] [blame] | 778 | /** Invoked when the MediaController on PIPed activity is changed. */ |
| 779 | void onMediaControllerChanged(); |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Winson | ab21660 | 2016-08-09 14:05:20 -0700 | [diff] [blame] | 782 | private void updatePipVisibility(final boolean visible) { |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 783 | Dependency.get(UiOffloadThread.class).execute(() -> { |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 784 | WindowManagerWrapper.getInstance().setPipVisibility(visible); |
| 785 | }); |
Jaewan Kim | f0fd218 | 2016-04-20 21:17:58 +0900 | [diff] [blame] | 786 | } |
Sergey Nikolaienkov | 53da4da | 2020-04-08 14:31:16 +0200 | [diff] [blame] | 787 | |
| 788 | private String getStateDescription() { |
| 789 | if (mSuspendPipResizingReason == 0) { |
| 790 | return stateToName(mState); |
| 791 | } |
| 792 | return stateToName(mResumeResizePinnedStackRunnableState) + " (while " + stateToName(mState) |
| 793 | + " is suspended)"; |
| 794 | } |
| 795 | |
| 796 | private static String stateToName(int state) { |
| 797 | switch (state) { |
| 798 | case STATE_NO_PIP: |
| 799 | return "NO_PIP"; |
| 800 | |
| 801 | case STATE_PIP: |
| 802 | return "PIP"; |
| 803 | |
| 804 | case STATE_PIP_MENU: |
| 805 | return "PIP_MENU"; |
| 806 | |
| 807 | default: |
| 808 | return "UNKNOWN(" + state + ")"; |
| 809 | } |
| 810 | } |
Youngsang Cho | f164792 | 2015-12-17 13:39:39 -0800 | [diff] [blame] | 811 | } |