Bypass inband ringing check for condition that le device is the active am: 7a6ea1d434

Original change: https://android-review.googlesource.com/c/platform/packages/services/Telecomm/+/2239095

Change-Id: I8db947e2057941f083fbc7837b24e3f145e9974f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
index 7ced8c8..2b5a80b 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
@@ -223,10 +223,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;
@@ -646,6 +646,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 1945e28..7966f73 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java
@@ -850,12 +850,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 664c549..799f989 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;
@@ -517,6 +518,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;