Always clear the communication device when call disconnected

Flag: EXEMPT bugfix
Bug: 408211130
Bug: 406836000
Test: manual
Test: atest TelecomUnitTests
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b72d2dfc55dc0f8e000fa070d37c036ae8219823)
Merged-In: I6b31ab8b6eeb39417bbaa2ab9f1b8377f0310fb8
Change-Id: I6b31ab8b6eeb39417bbaa2ab9f1b8377f0310fb8
diff --git a/src/com/android/server/telecom/AudioRoute.java b/src/com/android/server/telecom/AudioRoute.java
index 2b03182..661f1db 100644
--- a/src/com/android/server/telecom/AudioRoute.java
+++ b/src/com/android/server/telecom/AudioRoute.java
@@ -443,22 +443,22 @@
         }
 
         int result = BluetoothStatusCodes.SUCCESS;
-        if (pendingAudioRoute.getCommunicationDeviceType() == TYPE_BLUETOOTH_SCO
-                && !mIsScoManagedByAudio) {
+        boolean shouldDisconnectSco = !mIsScoManagedByAudio
+                && pendingAudioRoute.getCommunicationDeviceType() == TYPE_BLUETOOTH_SCO;
+        if (shouldDisconnectSco) {
             Log.i(this, "Disconnecting SCO device via BluetoothHeadset.");
             result = bluetoothRouteManager.getDeviceManager().disconnectSco();
-        } else {
-            // Only clear communication device if the destination route will be inactive; route to
-            // route transitions do not require clearing the communication device.
-            boolean onlyClearCommunicationDeviceOnInactive =
-                    pendingAudioRoute.getFeatureFlags().onlyClearCommunicationDeviceOnInactive();
-            if (!onlyClearCommunicationDeviceOnInactive
-                    || (onlyClearCommunicationDeviceOnInactive && !pendingAudioRoute.isActive())) {
-                Log.i(this,
-                        "clearCommunicationDevice: AudioManager#clearCommunicationDevice, type=%s",
-                        DEVICE_TYPE_STRINGS.get(pendingAudioRoute.getCommunicationDeviceType()));
-                audioManager.clearCommunicationDevice();
-            }
+        }
+        // Only clear communication device if the destination route will be inactive; route to
+        // route transitions do not require clearing the communication device.
+        boolean onlyClearCommunicationDeviceOnInactive =
+                pendingAudioRoute.getFeatureFlags().onlyClearCommunicationDeviceOnInactive();
+        if ((!onlyClearCommunicationDeviceOnInactive && !shouldDisconnectSco)
+                || !pendingAudioRoute.isActive()) {
+            Log.i(this,
+                    "clearCommunicationDevice: AudioManager#clearCommunicationDevice, type=%s",
+                    DEVICE_TYPE_STRINGS.get(pendingAudioRoute.getCommunicationDeviceType()));
+            audioManager.clearCommunicationDevice();
         }
 
         if (result == BluetoothStatusCodes.SUCCESS) {