Skip to content

Commit bcf21e9

Browse files
committed
Properly switch MediaRouter to wired audio over a2dp.
The system gives priority to physically connected headphones/speakers/docks/etc. Reflect this in MediaRouter and associated UI. Bug 6777592 Change-Id: Ibabf3d7512207117e892c99f004443490c3d0612
1 parent c03f0a1 commit bcf21e9

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

media/java/android/media/MediaRouter.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ void updateRoutes(AudioRoutesInfo newRoutes) {
126126
sStatic.mDefaultAudio.mNameResId = name;
127127
dispatchRouteChanged(sStatic.mDefaultAudio);
128128
}
129+
130+
boolean a2dpEnabled;
131+
try {
132+
a2dpEnabled = mAudioService.isBluetoothA2dpOn();
133+
} catch (RemoteException e) {
134+
Log.e(TAG, "Error querying Bluetooth A2DP state", e);
135+
a2dpEnabled = false;
136+
}
137+
129138
if (!TextUtils.equals(newRoutes.mBluetoothName, mCurRoutesInfo.mBluetoothName)) {
130139
mCurRoutesInfo.mBluetoothName = newRoutes.mBluetoothName;
131140
if (mCurRoutesInfo.mBluetoothName != null) {
@@ -135,13 +144,6 @@ void updateRoutes(AudioRoutesInfo newRoutes) {
135144
info.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO;
136145
sStatic.mBluetoothA2dpRoute = info;
137146
addRoute(sStatic.mBluetoothA2dpRoute);
138-
try {
139-
if (mAudioService.isBluetoothA2dpOn()) {
140-
selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mBluetoothA2dpRoute);
141-
}
142-
} catch (RemoteException e) {
143-
Log.e(TAG, "Error selecting Bluetooth A2DP route", e);
144-
}
145147
} else {
146148
sStatic.mBluetoothA2dpRoute.mName = mCurRoutesInfo.mBluetoothName;
147149
dispatchRouteChanged(sStatic.mBluetoothA2dpRoute);
@@ -151,6 +153,16 @@ void updateRoutes(AudioRoutesInfo newRoutes) {
151153
sStatic.mBluetoothA2dpRoute = null;
152154
}
153155
}
156+
157+
if (mBluetoothA2dpRoute != null) {
158+
if (mCurRoutesInfo.mMainType != AudioRoutesInfo.MAIN_SPEAKER &&
159+
mSelectedRoute == mBluetoothA2dpRoute) {
160+
selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mDefaultAudio);
161+
} else if (mCurRoutesInfo.mMainType == AudioRoutesInfo.MAIN_SPEAKER &&
162+
mSelectedRoute == mDefaultAudio && a2dpEnabled) {
163+
selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mBluetoothA2dpRoute);
164+
}
165+
}
154166
}
155167
}
156168

0 commit comments

Comments
 (0)