Loading media/java/android/media/MediaRouter.java +32 −8 Original line number Diff line number Diff line Loading @@ -219,12 +219,26 @@ public class MediaRouter { } if (mBluetoothA2dpRoute != null) { if (mSelectedRoute == mDefaultAudioVideo || mSelectedRoute == null) { final boolean a2dpEnabled = isBluetoothA2dpOn(); if (mainType != AudioRoutesInfo.MAIN_SPEAKER && mSelectedRoute == mBluetoothA2dpRoute && !a2dpEnabled) { selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mDefaultAudioVideo, false); } else if ((mSelectedRoute == mDefaultAudioVideo || mSelectedRoute == null) && a2dpEnabled) { selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mBluetoothA2dpRoute, false); } } } boolean isBluetoothA2dpOn() { try { return mAudioService.isBluetoothA2dpOn(); } catch (RemoteException e) { Log.e(TAG, "Error querying Bluetooth A2DP state", e); return false; } } void updateDiscoveryRequest() { // What are we looking for today? int routeTypes = 0; Loading Loading @@ -893,11 +907,6 @@ public class MediaRouter { static void selectRouteStatic(int types, @NonNull RouteInfo route, boolean explicit) { Log.v(TAG, "Selecting route: " + route); assert(route != null); if (route == sStatic.mDefaultAudioVideo && sStatic.mBluetoothA2dpRoute != null) { Log.i(TAG, "Change the route to a BT route: " + sStatic.mBluetoothA2dpRoute + "\nDo not select the default route when a BT route is available."); route = sStatic.mBluetoothA2dpRoute; } final RouteInfo oldRoute = sStatic.mSelectedRoute; if (oldRoute == route) return; if (!route.matchesTypes(types)) { Loading @@ -907,6 +916,16 @@ public class MediaRouter { return; } final RouteInfo btRoute = sStatic.mBluetoothA2dpRoute; if (btRoute != null && (types & ROUTE_TYPE_LIVE_AUDIO) != 0 && (route == btRoute || route == sStatic.mDefaultAudioVideo)) { try { sStatic.mAudioService.setBluetoothA2dpOn(route == btRoute); } catch (RemoteException e) { Log.e(TAG, "Error changing Bluetooth A2DP state", e); } } final WifiDisplay activeDisplay = sStatic.mDisplayService.getWifiDisplayStatus().getActiveDisplay(); final boolean oldRouteHasAddress = oldRoute != null && oldRoute.mDeviceAddress != null; Loading Loading @@ -946,7 +965,7 @@ public class MediaRouter { static void selectDefaultRouteStatic() { // TODO: Be smarter about the route types here; this selects for all valid. if (sStatic.mSelectedRoute != sStatic.mBluetoothA2dpRoute && sStatic.mBluetoothA2dpRoute != null) { && sStatic.mBluetoothA2dpRoute != null && sStatic.isBluetoothA2dpOn()) { selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mBluetoothA2dpRoute, false); } else { selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mDefaultAudioVideo, false); Loading Loading @@ -1278,7 +1297,12 @@ public class MediaRouter { selectedRoute == sStatic.mDefaultAudioVideo) { dispatchRouteVolumeChanged(selectedRoute); } else if (sStatic.mBluetoothA2dpRoute != null) { dispatchRouteVolumeChanged(sStatic.mBluetoothA2dpRoute); try { dispatchRouteVolumeChanged(sStatic.mAudioService.isBluetoothA2dpOn() ? sStatic.mBluetoothA2dpRoute : sStatic.mDefaultAudioVideo); } catch (RemoteException e) { Log.e(TAG, "Error checking Bluetooth A2DP state to report volume change", e); } } else { dispatchRouteVolumeChanged(sStatic.mDefaultAudioVideo); } Loading Loading
media/java/android/media/MediaRouter.java +32 −8 Original line number Diff line number Diff line Loading @@ -219,12 +219,26 @@ public class MediaRouter { } if (mBluetoothA2dpRoute != null) { if (mSelectedRoute == mDefaultAudioVideo || mSelectedRoute == null) { final boolean a2dpEnabled = isBluetoothA2dpOn(); if (mainType != AudioRoutesInfo.MAIN_SPEAKER && mSelectedRoute == mBluetoothA2dpRoute && !a2dpEnabled) { selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mDefaultAudioVideo, false); } else if ((mSelectedRoute == mDefaultAudioVideo || mSelectedRoute == null) && a2dpEnabled) { selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mBluetoothA2dpRoute, false); } } } boolean isBluetoothA2dpOn() { try { return mAudioService.isBluetoothA2dpOn(); } catch (RemoteException e) { Log.e(TAG, "Error querying Bluetooth A2DP state", e); return false; } } void updateDiscoveryRequest() { // What are we looking for today? int routeTypes = 0; Loading Loading @@ -893,11 +907,6 @@ public class MediaRouter { static void selectRouteStatic(int types, @NonNull RouteInfo route, boolean explicit) { Log.v(TAG, "Selecting route: " + route); assert(route != null); if (route == sStatic.mDefaultAudioVideo && sStatic.mBluetoothA2dpRoute != null) { Log.i(TAG, "Change the route to a BT route: " + sStatic.mBluetoothA2dpRoute + "\nDo not select the default route when a BT route is available."); route = sStatic.mBluetoothA2dpRoute; } final RouteInfo oldRoute = sStatic.mSelectedRoute; if (oldRoute == route) return; if (!route.matchesTypes(types)) { Loading @@ -907,6 +916,16 @@ public class MediaRouter { return; } final RouteInfo btRoute = sStatic.mBluetoothA2dpRoute; if (btRoute != null && (types & ROUTE_TYPE_LIVE_AUDIO) != 0 && (route == btRoute || route == sStatic.mDefaultAudioVideo)) { try { sStatic.mAudioService.setBluetoothA2dpOn(route == btRoute); } catch (RemoteException e) { Log.e(TAG, "Error changing Bluetooth A2DP state", e); } } final WifiDisplay activeDisplay = sStatic.mDisplayService.getWifiDisplayStatus().getActiveDisplay(); final boolean oldRouteHasAddress = oldRoute != null && oldRoute.mDeviceAddress != null; Loading Loading @@ -946,7 +965,7 @@ public class MediaRouter { static void selectDefaultRouteStatic() { // TODO: Be smarter about the route types here; this selects for all valid. if (sStatic.mSelectedRoute != sStatic.mBluetoothA2dpRoute && sStatic.mBluetoothA2dpRoute != null) { && sStatic.mBluetoothA2dpRoute != null && sStatic.isBluetoothA2dpOn()) { selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mBluetoothA2dpRoute, false); } else { selectRouteStatic(ROUTE_TYPE_ANY, sStatic.mDefaultAudioVideo, false); Loading Loading @@ -1278,7 +1297,12 @@ public class MediaRouter { selectedRoute == sStatic.mDefaultAudioVideo) { dispatchRouteVolumeChanged(selectedRoute); } else if (sStatic.mBluetoothA2dpRoute != null) { dispatchRouteVolumeChanged(sStatic.mBluetoothA2dpRoute); try { dispatchRouteVolumeChanged(sStatic.mAudioService.isBluetoothA2dpOn() ? sStatic.mBluetoothA2dpRoute : sStatic.mDefaultAudioVideo); } catch (RemoteException e) { Log.e(TAG, "Error checking Bluetooth A2DP state to report volume change", e); } } else { dispatchRouteVolumeChanged(sStatic.mDefaultAudioVideo); } Loading