diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java index 6667b71efc0e9..198bbe5c37094 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java @@ -34,7 +34,6 @@ import android.media.session.PlaybackState; import android.os.Debug; import android.os.Handler; import android.os.RemoteException; -import android.os.SystemProperties; import android.text.TextUtils; import android.util.Log; import android.util.Pair; @@ -43,7 +42,6 @@ import android.view.IPinnedStackListener; import android.view.IWindowManager; import android.view.WindowManagerGlobal; -import com.android.systemui.Prefs; import com.android.systemui.R; import com.android.systemui.pip.BasePipManager; import com.android.systemui.recents.misc.SystemServicesProxy; @@ -109,7 +107,7 @@ public class PipManager implements BasePipManager { private IWindowManager mWindowManager; private MediaSessionManager mMediaSessionManager; private int mState = STATE_NO_PIP; - private int mResumeResizePinnedStackRunnable = STATE_NO_PIP; + private int mResumeResizePinnedStackRunnableState = STATE_NO_PIP; private final Handler mHandler = new Handler(); private List mListeners = new ArrayList<>(); private List mMediaListeners = new ArrayList<>(); @@ -130,7 +128,7 @@ public class PipManager implements BasePipManager { private final Runnable mResizePinnedStackRunnable = new Runnable() { @Override public void run() { - resizePinnedStack(mResumeResizePinnedStackRunnable); + resizePinnedStack(mResumeResizePinnedStackRunnableState); } }; private final Runnable mClosePipRunnable = new Runnable() { @@ -278,7 +276,7 @@ public class PipManager implements BasePipManager { * Shows the picture-in-picture menu if an activity is in picture-in-picture mode. */ public void showPictureInPictureMenu() { - if (mState == STATE_PIP) { + if (getState() == STATE_PIP) { resizePinnedStack(STATE_PIP_MENU); } } @@ -352,14 +350,15 @@ public class PipManager implements BasePipManager { void resizePinnedStack(int state) { if (DEBUG) Log.d(TAG, "resizePinnedStack() state=" + state, new Exception()); boolean wasStateNoPip = (mState == STATE_NO_PIP); - mResumeResizePinnedStackRunnable = state; for (int i = mListeners.size() - 1; i >= 0; --i) { mListeners.get(i).onPipResizeAboutToStart(); } if (mSuspendPipResizingReason != 0) { + mResumeResizePinnedStackRunnableState = state; if (DEBUG) Log.d(TAG, "resizePinnedStack() deferring" + " mSuspendPipResizingReason=" + mSuspendPipResizingReason - + " mResumeResizePinnedStackRunnable=" + mResumeResizePinnedStackRunnable); + + " mResumeResizePinnedStackRunnableState=" + + mResumeResizePinnedStackRunnableState); return; } mState = state; @@ -391,6 +390,16 @@ public class PipManager implements BasePipManager { } } + /** + * @return the current state, or the pending state if the state change was previously suspended. + */ + private int getState() { + if (mSuspendPipResizingReason != 0) { + return mResumeResizePinnedStackRunnableState; + } + return mState; + } + /** * Returns the default PIP bound. */ @@ -459,7 +468,7 @@ public class PipManager implements BasePipManager { } private void handleMediaResourceGranted(String[] packageNames) { - if (mState == STATE_NO_PIP) { + if (getState() == STATE_NO_PIP) { mLastPackagesResourceGranted = packageNames; } else { boolean requestedFromLastPackages = false; @@ -482,7 +491,7 @@ public class PipManager implements BasePipManager { private void updateMediaController(List controllers) { MediaController mediaController = null; - if (controllers != null && mState != STATE_NO_PIP && mPipComponentName != null) { + if (controllers != null && getState() != STATE_NO_PIP && mPipComponentName != null) { for (int i = controllers.size() - 1; i >= 0; i--) { MediaController controller = controllers.get(i); // We assumes that an app with PIPable activity @@ -571,7 +580,7 @@ public class PipManager implements BasePipManager { if (!checkCurrentUserId(DEBUG)) { return; } - if (mState != STATE_NO_PIP) { + if (getState() != STATE_NO_PIP) { boolean hasPip = false; StackInfo stackInfo = getPinnedStackInfo(); @@ -593,7 +602,7 @@ public class PipManager implements BasePipManager { return; } } - if (mState == STATE_PIP) { + if (getState() == STATE_PIP) { Rect bounds = isSettingsShown() ? mSettingsPipBounds : mDefaultPipBounds; if (mPipBounds != bounds) { mPipBounds = bounds; @@ -645,7 +654,7 @@ public class PipManager implements BasePipManager { if (!checkCurrentUserId(DEBUG)) { return; } - switch (mState) { + switch (getState()) { case STATE_PIP_MENU: showPipMenu(); break;