Bypass inband ringing check for condition that le device is the active
bt device.

Bug: 242685105
Test: BluetoothDeviceManagerTest, manual test
Change-Id: I330c8f11ffe269c14648243177a1594fe839cf4d
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
index 64a3f20..6a701da 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
@@ -222,10 +222,10 @@
             }
 
             for (LinkedHashMap.Entry<BluetoothDevice, Integer> entry : mGroupsByDevice.entrySet()) {
-               if (Objects.equals(entry.getKey(),
+                if (Objects.equals(entry.getKey(),
                         mBluetoothLeAudioService.getConnectedGroupLeadDevice(entry.getValue()))) {
-                   devices.add(entry.getKey());
-               }
+                    devices.add(entry.getKey());
+                }
             }
             devices.removeIf(device -> !mLeAudioDevicesByAddress.containsValue(device));
             return devices;
@@ -637,6 +637,20 @@
         }
     }
 
+    public boolean isInbandRingingEnabled() {
+        BluetoothDevice activeDevice = mBluetoothRouteManager.getBluetoothAudioConnectedDevice();
+        Log.i(this, "isInbandRingingEnabled: activeDevice: " + activeDevice);
+        if (mBluetoothRouteManager.isCachedLeAudioDevice(activeDevice)) {
+            return true;
+        } else {
+            if (mBluetoothHeadset == null) {
+                Log.i(this, "isInbandRingingEnabled: no headset service available.");
+                return false;
+            }
+            return mBluetoothHeadset.isInbandRingingEnabled();
+        }
+    }
+
     public void dump(IndentingPrintWriter pw) {
         mLocalLog.dump(pw);
     }
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
index fea663d..9711d49 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
@@ -849,12 +849,7 @@
      */
     @VisibleForTesting
     public boolean isInbandRingingEnabled() {
-        BluetoothHeadset bluetoothHeadset = mDeviceManager.getBluetoothHeadset();
-        if (bluetoothHeadset == null) {
-            Log.i(this, "isInbandRingingEnabled: no headset service available.");
-            return false;
-        }
-        return bluetoothHeadset.isInbandRingingEnabled();
+        return mDeviceManager.isInbandRingingEnabled();
     }
 
     private boolean addDevice(String address) {
diff --git a/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java b/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
index 6c7c0ac..e730274 100644
--- a/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
+++ b/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
@@ -46,6 +46,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.any;
@@ -513,6 +514,27 @@
         assertFalse(mBluetoothDeviceManager.isHearingAidSetAsCommunicationDevice());
     }
 
+    @SmallTest
+    @Test
+    public void testInBandRingingEnabledForLeDevice() {
+        when(mBluetoothHeadset.isInbandRingingEnabled()).thenReturn(false);
+        receiverUnderTest.onReceive(mContext,
+                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1,
+                        BluetoothDeviceManager.DEVICE_TYPE_HEADSET));
+        receiverUnderTest.onReceive(mContext,
+                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2,
+                        BluetoothDeviceManager.DEVICE_TYPE_HEADSET));
+        receiverUnderTest.onReceive(mContext,
+                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device3,
+                        BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO));
+        leAudioCallbacksTest.getValue().onGroupNodeAdded(device3, 1);
+        when(mBluetoothLeAudio.getConnectedGroupLeadDevice(1)).thenReturn(device3);
+        when(mRouteManager.getBluetoothAudioConnectedDevice()).thenReturn(device3);
+        when(mRouteManager.isCachedLeAudioDevice(eq(device3))).thenReturn(true);
+        assertEquals(3, mBluetoothDeviceManager.getNumConnectedDevices());
+        assertTrue(mBluetoothDeviceManager.isInbandRingingEnabled());
+    }
+
     private Intent buildConnectionActionIntent(int state, BluetoothDevice device, int deviceType) {
         String intentString;