Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 940ed9ab authored by Yiyi Shen's avatar Yiyi Shen
Browse files

[Audiosharing] Avoid fallback device update when onSourceRemoved.

Also check if there is playing broadcast before updating the fallback.

Updating fallback device during call audio will hit race condition in
broadcast-unicast switching. Considering there is no use case for
removing source in current product, we will disable fallback device
update when onSourceRemoved.

Bug: 329003470
Test: manual
Change-Id: I3038d2ecff91c26cf1b2fbda44476c8a8e31f4dd
parent b6eb1a21
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -336,7 +336,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                                        + ", sourceId = "
                                        + sourceId);
                    }
                    updateFallbackActiveDeviceIfNeeded();
                }

                @Override
@@ -468,6 +467,15 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
        mServiceBroadcast.startBroadcast(settings);
    }

    /** Checks if the broadcast is playing. */
    public boolean isPlaying(int broadcastId) {
        if (mServiceBroadcast == null) {
            Log.d(TAG, "check isPlaying failed, the BluetoothLeBroadcast is null.");
            return false;
        }
        return mServiceBroadcast.isPlaying(broadcastId);
    }

    private BluetoothLeBroadcastSettings buildBroadcastSettings(
            boolean isPublic,
            @Nullable String broadcastName,
@@ -1025,6 +1033,16 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {

    /** Update fallback active device if needed. */
    public void updateFallbackActiveDeviceIfNeeded() {
        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");
            return;