Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d4971dc authored by Shenqiu Zhang's avatar Shenqiu Zhang
Browse files

Fix the failure of transferring to unselected system route

If we firstly pair the phone to a bluetooth speaker which is
the selected route, then we cast to a remote device. At this
moment, transferring from the remote device back to the
builtin speaker will fail. The fix is to first transfer from
the selected bluetooth system route to the builtin speaker
route, and then release the remote route.

Flag: com.android.media.flags.fix_transfer_from_user_route_to_unselected_system_route
Test: presubmit and manually tested with demo app
Bug: b/398527989
Fix: b/398527989
Change-Id: I1622347bc75290ea08d7cf376983dfee7f3ccde8
parent ed28223b
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -1082,6 +1082,12 @@ public final class MediaRouter2 {
            @NonNull MediaRoute2Info route,
            long managerRequestId) {

        if (Flags.fixTransferFromUserRouteToUnselectedSystemRoute() && route.isSystemRoute()) {
            notifyTransfer(controller, getSystemController());
            controller.release();
            return;
        }

        final int requestId = mNextRequestId.getAndIncrement();

        ControllerCreationRequest request =
@@ -2945,9 +2951,9 @@ public final class MediaRouter2 {
                return;
            }

            // If this call is trying to transfer to a selected system route, we let them
            // through as a provider driven transfer in order to update the transfer reason and
            // initiator data.
            // If this call is trying to transfer from an existing system route to a selected system
            // route, we will handle the transfer through as a provider driven transfer in order to
            // update the transfer reason and initiator data.
            boolean isSystemRouteReselection =
                    Flags.enableBuiltInSpeakerRouteSuitabilityStatuses()
                            && sessionInfo.isSystemSession()
@@ -2957,6 +2963,19 @@ public final class MediaRouter2 {
                    || isSystemRouteReselection) {
                transferToRoute(sessionInfo, route, mClientUser, mClientPackageName);
            } else {
                RoutingSessionInfo systemSessionInfo = mSystemController.getRoutingSessionInfo();
                boolean isTransferFromUserRouteToUnselectedSystemRoute =
                        Flags.fixTransferFromUserRouteToUnselectedSystemRoute()
                                && !sessionInfo.isSystemSession()
                                && route.isSystemRoute()
                                && !systemSessionInfo.getSelectedRoutes().contains(route.getId());
                if (isTransferFromUserRouteToUnselectedSystemRoute) {
                    // During a transfer from a user route to an unselected system route, the system
                    // session must first be transferred to the target system route. Subsequently,
                    // the user route to system route transfer is processed by releasing the user
                    // route.
                    transferToRoute(systemSessionInfo, route, mClientUser, mClientPackageName);
                }
                requestCreateSession(sessionInfo, route);
            }
        }
+11 −1
Original line number Diff line number Diff line
@@ -266,3 +266,13 @@ flag {
    description: "Enables personal audio sharing in the output switcher."
    bug: "385672684"
}

flag {
    name: "fix_transfer_from_user_route_to_unselected_system_route"
    namespace: "media_better_together"
    description: "Fixes a bug causing the failure of transferring to a builtin speaker."
    bug: "398527989"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}