Commit 3f1ee607 authored by Zhiqiang Zhang's avatar Zhiqiang Zhang Committed by Commit Bot

[Android MR] Fix an issue on session relaunching

Previously, we remove the SessionManagerListener upon session
ending/ended. This is to stop listening to session changes after we are
no longer interested in casting, while not being affected by MediaFling.
However there's some tricky SDK behavior, such that session ending could
be notified during a session relaunch. Then we never get
onSessionStarted() signal.

This CL checks for pending launch request before removing the listener,
so that sessions can be relaunched.

Bug: 711860
Change-Id: I582ae8bb6f038956c256ea88ae6115ed289fdfff
Reviewed-on: https://chromium-review.googlesource.com/1217749Reviewed-by: default avatarThomas Guilbert <tguilbert@chromium.org>
Commit-Queue: Zhiqiang Zhang <zqzhang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590158}
parent b0b26586
......@@ -210,6 +210,7 @@ public abstract class CafBaseMediaRouteProvider
@Override
public void onSessionStartFailed(CastSession session, int error) {
removeAllRoutesWithError("Launch error");
mPendingCreateRouteRequestInfo = null;
}
@Override
......@@ -263,8 +264,14 @@ public abstract class CafBaseMediaRouteProvider
mSessionController.detachFromCastSession();
getAndroidMediaRouter().selectRoute(getAndroidMediaRouter().getDefaultRoute());
removeAllRoutesWithError(error);
CastUtils.getCastContext().getSessionManager().removeSessionManagerListener(
this, CastSession.class);
if (mPendingCreateRouteRequestInfo == null) {
// The Cast SDK notifies about session ending when a route is unselected, even when
// there's no current session. Because CastSessionController unselects the route to set
// the receiver app ID, this needs to be guarded by a pending request null check to make
// sure the listener is not unregistered during a session relaunch.
CastUtils.getCastContext().getSessionManager().removeSessionManagerListener(
this, CastSession.class);
}
}
public @NonNull MediaRouter getAndroidMediaRouter() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment