Skip to content

Commit dd0a192

Browse files
committed
MediaRouter bluetooth a2dp selection
Remove bluetooth permission check from internal AudioService method setBluetoothA2dpOn Manage BT A2DP state in MediaRouter. A2DP is only enabled or disabled when either the system built-in audio route or the A2DP audio route is selected; when selecting any other route the current state is left alone. Change-Id: Ib14274e206e79bd8762edca1205ecfa87b7a94cf
1 parent eb2c1b2 commit dd0a192

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

media/java/android/media/AudioService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,9 +1660,6 @@ public boolean isBluetoothScoOn() {
16601660

16611661
/** @see AudioManager#setBluetoothA2dpOn() */
16621662
public void setBluetoothA2dpOn(boolean on) {
1663-
if (!checkAudioSettingsPermission("setBluetoothA2dpOn()")) {
1664-
return;
1665-
}
16661663
setBluetoothA2dpOnInt(on);
16671664
}
16681665

media/java/android/media/MediaRouter.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ public void dispatchAudioRoutesChanged(final AudioRoutesInfo newRoutes) {
8181
IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
8282
mAudioService = IAudioService.Stub.asInterface(b);
8383

84-
// XXX this doesn't deal with locale changes!
85-
mSystemCategory = new RouteCategory(mResources.getText(
86-
com.android.internal.R.string.default_audio_route_category_name),
84+
mSystemCategory = new RouteCategory(
85+
com.android.internal.R.string.default_audio_route_category_name,
8786
ROUTE_TYPE_LIVE_AUDIO, false);
8887
}
8988

@@ -130,6 +129,13 @@ void updateRoutes(AudioRoutesInfo newRoutes) {
130129
info.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO;
131130
sStatic.mBluetoothA2dpRoute = info;
132131
addRoute(sStatic.mBluetoothA2dpRoute);
132+
try {
133+
if (mAudioService.isBluetoothA2dpOn()) {
134+
selectRouteStatic(ROUTE_TYPE_LIVE_AUDIO, mBluetoothA2dpRoute);
135+
}
136+
} catch (RemoteException e) {
137+
Log.e(TAG, "Error selecting Bluetooth A2DP route", e);
138+
}
133139
} else {
134140
sStatic.mBluetoothA2dpRoute.mName = mCurRoutesInfo.mBluetoothName;
135141
dispatchRouteChanged(sStatic.mBluetoothA2dpRoute);
@@ -279,6 +285,16 @@ static void selectRouteStatic(int types, RouteInfo route) {
279285
return;
280286
}
281287

288+
final RouteInfo btRoute = sStatic.mBluetoothA2dpRoute;
289+
if (btRoute != null && (types & ROUTE_TYPE_LIVE_AUDIO) != 0 &&
290+
(route == btRoute || route == sStatic.mDefaultAudio)) {
291+
try {
292+
sStatic.mAudioService.setBluetoothA2dpOn(route == btRoute);
293+
} catch (RemoteException e) {
294+
Log.e(TAG, "Error changing Bluetooth A2DP state", e);
295+
}
296+
}
297+
282298
if (sStatic.mSelectedRoute != null) {
283299
// TODO filter types properly
284300
dispatchRouteUnselected(types & sStatic.mSelectedRoute.getSupportedTypes(),

0 commit comments

Comments
 (0)