[Audiosharing] Fix hysteresis mode

Move add source logic from onReceiveStateChanged(BIS>0) to onSourceAdded

Test: atest
Bug: 355222285
Bug: 377658982
Flag: com.android.settingslib.flags.audio_sharing_hysteresis_mode_fix
Change-Id: I93db0422b028ec192a1ffea9545da4ee5c6d2e44
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
index 6a9d568..8851e14 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
@@ -18,6 +18,8 @@
 
 import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
 
+import static com.android.settingslib.Utils.isAudioModeOngoingCall;
+
 import static java.util.stream.Collectors.toList;
 
 import android.annotation.CallbackExecutor;
@@ -303,6 +305,7 @@
                                         + ", sourceId = "
                                         + sourceId);
                     }
+                    updateFallbackActiveDeviceIfNeeded();
                 }
 
                 @Override
@@ -390,9 +393,6 @@
                                         + ", state = "
                                         + state);
                     }
-                    if (BluetoothUtils.isConnected(state)) {
-                        updateFallbackActiveDeviceIfNeeded();
-                    }
                 }
             };
 
@@ -1130,18 +1130,8 @@
             Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded for work profile.");
             return;
         }
-        if (mServiceBroadcast == null) {
-            Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded due to broadcast profile is null");
-            return;
-        }
-        List<BluetoothLeBroadcastMetadata> sources = mServiceBroadcast.getAllBroadcastMetadata();
-        if (sources.stream()
-                .noneMatch(source -> mServiceBroadcast.isPlaying(source.getBroadcastId()))) {
-            Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded due to no broadcast ongoing");
-            return;
-        }
-        if (mServiceBroadcastAssistant == null) {
-            Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded due to assistant profile is null");
+        if (isAudioModeOngoingCall(mContext)) {
+            Log.d(TAG, "Skip updateFallbackActiveDeviceIfNeeded due to ongoing call");
             return;
         }
         Map<Integer, List<BluetoothDevice>> deviceGroupsInBroadcast = getDeviceGroupsInBroadcast();
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistantCallbackExt.kt b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistantCallbackExt.kt
index 91a99ae..a0a6d26 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistantCallbackExt.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistantCallbackExt.kt
@@ -35,11 +35,7 @@
                     sink: BluetoothDevice,
                     sourceId: Int,
                     state: BluetoothLeBroadcastReceiveState
-                ) {
-                    if (BluetoothUtils.isConnected(state)) {
-                        launch { send(Unit) }
-                    }
-                }
+                ) {}
 
                 override fun onSourceRemoved(sink: BluetoothDevice, sourceId: Int, reason: Int) {
                     launch { send(Unit) }
@@ -55,7 +51,9 @@
 
                 override fun onSourceFound(source: BluetoothLeBroadcastMetadata) {}
 
-                override fun onSourceAdded(sink: BluetoothDevice, sourceId: Int, reason: Int) {}
+                override fun onSourceAdded(sink: BluetoothDevice, sourceId: Int, reason: Int) {
+                    launch { send(Unit) }
+                }
 
                 override fun onSourceAddFailed(
                     sink: BluetoothDevice,