diff options
| author | 2020-06-12 12:55:24 +0000 | |
|---|---|---|
| committer | 2020-06-12 12:55:24 +0000 | |
| commit | 93e4930a971b7a0d62ba017fbb2aa5f3c8f14940 (patch) | |
| tree | d818455d4002d9432f073f5f0981858a4ec1b459 | |
| parent | b749be45c7b3627127b9d052937c77b3d302e4e5 (diff) | |
| parent | f6d5b3c7c406ac4a0aa1608c4e41cecb3fe615f7 (diff) | |
Merge "Handle a pair of hearing aid devcies" into rvc-dev
| -rw-r--r-- | services/core/java/com/android/server/media/BluetoothRouteProvider.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/media/BluetoothRouteProvider.java b/services/core/java/com/android/server/media/BluetoothRouteProvider.java index 30a636d4240e..c7575d4fc8a4 100644 --- a/services/core/java/com/android/server/media/BluetoothRouteProvider.java +++ b/services/core/java/com/android/server/media/BluetoothRouteProvider.java @@ -48,6 +48,7 @@ import java.util.Objects; class BluetoothRouteProvider { private static final String TAG = "BTRouteProvider"; + private static final String HEARING_AID_ROUTE_ID_PREFIX = "HEARING_AID_"; private static BluetoothRouteProvider sInstance; @SuppressWarnings("WeakerAccess") /* synthetic access */ @@ -179,9 +180,16 @@ class BluetoothRouteProvider { @NonNull List<MediaRoute2Info> getAllBluetoothRoutes() { - ArrayList<MediaRoute2Info> routes = new ArrayList<>(); + List<MediaRoute2Info> routes = new ArrayList<>(); + List<String> routeIds = new ArrayList<>(); + for (BluetoothRouteInfo btRoute : mBluetoothRoutes.values()) { + // A pair of hearing aid devices or the same hardware address + if (routeIds.contains(btRoute.route.getId())) { + continue; + } routes.add(btRoute.route); + routeIds.add(btRoute.route.getId()); } return routes; } @@ -222,8 +230,8 @@ class BluetoothRouteProvider { private BluetoothRouteInfo createBluetoothRoute(BluetoothDevice device) { BluetoothRouteInfo newBtRoute = new BluetoothRouteInfo(); newBtRoute.btDevice = device; - // Current volume will be set when connected. - // TODO: Is there any BT device which has fixed volume? + + String routeId = device.getAddress(); String deviceName = device.getName(); if (TextUtils.isEmpty(deviceName)) { deviceName = mContext.getResources().getText(R.string.unknownName).toString(); @@ -236,10 +244,13 @@ class BluetoothRouteProvider { if (mHearingAidProfile != null && mHearingAidProfile.getConnectedDevices().contains(device)) { newBtRoute.connectedProfiles.put(BluetoothProfile.HEARING_AID, true); + // Intentionally assign the same ID for a pair of devices to publish only one of them. + routeId = HEARING_AID_ROUTE_ID_PREFIX + mHearingAidProfile.getHiSyncId(device); type = MediaRoute2Info.TYPE_HEARING_AID; } - newBtRoute.route = new MediaRoute2Info.Builder(device.getAddress(), deviceName) + // Current volume will be set when connected. + newBtRoute.route = new MediaRoute2Info.Builder(routeId, deviceName) .addFeature(MediaRoute2Info.FEATURE_LIVE_AUDIO) .setConnectionState(MediaRoute2Info.CONNECTION_STATE_DISCONNECTED) .setDescription(mContext.getResources().getText( |