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

Commit 895a715e authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "[Audiosharing] Avoid fallback device update when onSourceRemoved." into main

parents 08df28f4 940ed9ab
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -337,7 +337,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                                        + ", sourceId = "
                                        + sourceId);
                    }
                    updateFallbackActiveDeviceIfNeeded();
                }

                @Override
@@ -469,6 +468,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,
@@ -1026,6 +1034,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;