From 0ea65316f496bdb866a50aaff5cc9f8acfd724e4 Mon Sep 17 00:00:00 2001 From: Sungsoo Lim Date: Fri, 19 Jun 2020 14:41:17 +0900 Subject: [PATCH] Prevent unnecessary call of setBluetoothA2dpOn(false) When an active BT device is changed, instead of just notifying that the changed BT name, AudioService sometimes notify it with two steps. 1) Notify prev BT disconnected 2) Notify new BT connected By not calling setBluetoothA2dpOn(false) when BT is disconnected, we can prvent the unnecessary call of it. Bug: 144784716 Test: manual Change-Id: I31442204cd4dd4a78552e0f993e9dfa37d6fc03f --- media/java/android/media/MediaRouter.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java index 7ae2949e60749..6fa378724240e 100644 --- a/media/java/android/media/MediaRouter.java +++ b/media/java/android/media/MediaRouter.java @@ -221,12 +221,11 @@ public class MediaRouter { if (!TextUtils.equals(newRoutes.bluetoothName, mCurAudioRoutesInfo.bluetoothName)) { forceUseDefaultRoute = false; - mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName; - if (mCurAudioRoutesInfo.bluetoothName != null) { + if (newRoutes.bluetoothName != null) { if (mBluetoothA2dpRoute == null) { // BT connected final RouteInfo info = new RouteInfo(mSystemCategory); - info.mName = mCurAudioRoutesInfo.bluetoothName; + info.mName = newRoutes.bluetoothName; info.mDescription = mResources.getText( com.android.internal.R.string.bluetooth_a2dp_audio_route_name); info.mSupportedTypes = ROUTE_TYPE_LIVE_AUDIO; @@ -234,13 +233,14 @@ public class MediaRouter { mBluetoothA2dpRoute = info; addRouteStatic(mBluetoothA2dpRoute); } else { - mBluetoothA2dpRoute.mName = mCurAudioRoutesInfo.bluetoothName; + mBluetoothA2dpRoute.mName = newRoutes.bluetoothName; dispatchRouteChanged(mBluetoothA2dpRoute); } } else if (mBluetoothA2dpRoute != null) { // BT disconnected - removeRouteStatic(mBluetoothA2dpRoute); + RouteInfo btRoute = mBluetoothA2dpRoute; mBluetoothA2dpRoute = null; + removeRouteStatic(btRoute); } audioRoutesChanged = true; } @@ -256,6 +256,7 @@ public class MediaRouter { } } } + mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName; } boolean isBluetoothA2dpOn() {