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

Commit 59579ce5 authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

MediaRouter: Introduce and use getFallbackRoute method

Instead of selecting default route, select the fallback route to avoid
making sound via the default route while a BT route is available.

Bug: 63582431
Test: manual
Change-Id: I2cb8fbf6c518294fcec2bf14a5d8175c7302396f
parent ca007e52
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -142,7 +142,11 @@ public class MediaRouteControllerDialog extends AlertDialog {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int id) {
                        if (mRoute.isSelected()) {
                            if (mRoute.isBluetooth()) {
                                mRouter.getDefaultRoute().select();
                            } else {
                                mRouter.getFallbackRoute().select();
                            }
                        }
                        dismiss();
                    }
+27 −0
Original line number Diff line number Diff line
@@ -752,6 +752,15 @@ public class MediaRouter {
        return sStatic.mDefaultAudioVideo;
    }

    /**
     * Returns a Bluetooth route if available, otherwise the default route.
     * @hide
     */
    public RouteInfo getFallbackRoute() {
        return (sStatic.mBluetoothA2dpRoute != null)
                ? sStatic.mBluetoothA2dpRoute : sStatic.mDefaultAudioVideo;
    }

    /**
     * @hide for use by framework routing UI
     */
@@ -934,6 +943,19 @@ public class MediaRouter {
                (route == btRoute || route == sStatic.mDefaultAudioVideo)) {
            try {
                sStatic.mAudioService.setBluetoothA2dpOn(route == btRoute);
                // TODO: Remove the following logging when no longer needed.
                if (route != btRoute) {
                    StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
                    StringBuffer sb = new StringBuffer();
                    // callStack[3] is the caller of this method.
                    for (int i = 3; i < callStack.length; i++) {
                        StackTraceElement caller = callStack[i];
                        sb.append(caller.getClassName() + "." + caller.getMethodName()
                                + ":" + caller.getLineNumber()).append("  ");
                    }
                    Log.w(TAG, "Default route is selected while a BT route is available: pkgName="
                            + sStatic.mPackageName + ", callers=" + sb.toString());
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Error changing Bluetooth A2DP state", e);
            }
@@ -2019,6 +2041,11 @@ public class MediaRouter {
            return this == sStatic.mDefaultAudioVideo;
        }

        /** @hide */
        public boolean isBluetooth() {
            return this == sStatic.mBluetoothA2dpRoute;
        }

        /** @hide */
        public void select() {
            selectRouteStatic(mSupportedTypes, this, true);
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ public class CastControllerImpl implements CastController {
                Log.w(TAG, "Projection is no longer active: " + projection);
            }
        } else {
            mMediaRouter.getDefaultRoute().select();
            mMediaRouter.getFallbackRoute().select();
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ public final class MediaProjectionManagerService extends SystemService
            mProjectionGrant.stop();
        }
        if (mMediaRouteInfo != null) {
            mMediaRouter.getDefaultRoute().select();
            mMediaRouter.getFallbackRoute().select();
        }
        mProjectionToken = projection.asBinder();
        mProjectionGrant = projection;