PIP: Close PIP if media session is gone
This keeps the PIP if there's no media session from the beginning.
Bug: 26717072
Change-Id: Idf5bab14d8979c0e50f4451f61bb9355d4562b96
diff --git a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
index 123165e..59848cf 100644
--- a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
@@ -66,6 +66,9 @@
public static final int SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_MENU_ACTIVITY_FINISH = 0x1;
public static final int SUSPEND_PIP_RESIZE_REASON_WAITING_FOR_OVERLAY_ACTIVITY_FINISH = 0x2;
+
+ private static final int CLOSE_PIP_WHEN_MEDIA_SESSION_GONE_TIMEOUT_MS = 3000;
+
private int mSuspendPipResizingReason;
private static final float SCALE_FACTOR = 1.1f;
@@ -170,6 +173,12 @@
resizePinnedStack(mState);
}
};
+ private final Runnable mClosePipRunnable = new Runnable() {
+ @Override
+ public void run() {
+ closePip();
+ }
+ };
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
@@ -281,6 +290,7 @@
for (int i = mListeners.size() - 1; i >= 0; --i) {
mListeners.get(i).onPipActivityClosed();
}
+ mHandler.removeCallbacks(mClosePipRunnable);
}
/**
@@ -543,6 +553,12 @@
for (int i = mListeners.size() - 1; i >= 0; i--) {
mListeners.get(i).onMediaControllerChanged();
}
+ if (mPipMediaController == null) {
+ mHandler.postDelayed(mClosePipRunnable,
+ CLOSE_PIP_WHEN_MEDIA_SESSION_GONE_TIMEOUT_MS);
+ } else {
+ mHandler.removeCallbacks(mClosePipRunnable);
+ }
}
}