From a8f2a06b51b3ea98b9024b5905e32d66a9f666e5 Mon Sep 17 00:00:00 2001 From: Kyunglyul Hyun Date: Wed, 17 Jun 2020 15:46:38 +0900 Subject: [PATCH] Enable transfer to hearing aid routes. There was a bug that transfer fails when a BT route has the route ID different from its hardware address. Bug: 157708273 Bug: 152585170 Test: run CTS & manually by assigning random ID to BT devices, which failed without this CL Change-Id: Ib2183f96b135bd2cef317234a8532b10994ca86b --- .../server/media/BluetoothRouteProvider.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/media/BluetoothRouteProvider.java b/services/core/java/com/android/server/media/BluetoothRouteProvider.java index c7575d4fc8a4b..4def7db76bc5f 100644 --- a/services/core/java/com/android/server/media/BluetoothRouteProvider.java +++ b/services/core/java/com/android/server/media/BluetoothRouteProvider.java @@ -52,6 +52,7 @@ class BluetoothRouteProvider { private static BluetoothRouteProvider sInstance; @SuppressWarnings("WeakerAccess") /* synthetic access */ + // Maps hardware address to BluetoothRouteInfo final Map mBluetoothRoutes = new HashMap<>(); @SuppressWarnings("WeakerAccess") /* synthetic access */ BluetoothRouteInfo mSelectedRoute = null; @@ -127,9 +128,10 @@ class BluetoothRouteProvider { return; } - BluetoothRouteInfo btRouteInfo = mBluetoothRoutes.get(routeId); + BluetoothRouteInfo btRouteInfo = findBluetoothRouteWithRouteId(routeId); + if (btRouteInfo == null) { - Slog.w(TAG, "transferTo: unknown route id=" + routeId); + Slog.w(TAG, "transferTo: Unknown route. ID=" + routeId); return; } @@ -194,6 +196,18 @@ class BluetoothRouteProvider { return routes; } + BluetoothRouteInfo findBluetoothRouteWithRouteId(String routeId) { + if (routeId == null) { + return null; + } + for (BluetoothRouteInfo btRouteInfo : mBluetoothRoutes.values()) { + if (TextUtils.equals(btRouteInfo.route.getId(), routeId)) { + return btRouteInfo; + } + } + return null; + } + /** * Updates the volume for {@link AudioManager#getDevicesForStream(int) devices}. *