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

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

Merge "[Audiosharing] Add more checks before show notif from receiver" into main

parents fe36b334 d800a32c
Loading
Loading
Loading
Loading
+55 −42
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

import com.android.settings.R;
@@ -45,6 +46,7 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.flags.Flags;

import com.google.common.collect.ImmutableList;

@@ -129,8 +131,9 @@ public class AudioSharingReceiver extends BroadcastReceiver {
                cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
                break;
            case LocalBluetoothLeBroadcast.ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED:
                if (!BluetoothUtils.isAudioSharingUIAvailable(context)) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED, feature disabled.");
                if (!Flags.promoteAudioSharingForSecondAutoConnectedLeaDevice()
                        || !BluetoothUtils.isAudioSharingUIAvailable(context)) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED, flag/feature off");
                    return;
                }
                BluetoothDevice device = intent.getParcelableExtra(EXTRA_BLUETOOTH_DEVICE,
@@ -144,64 +147,72 @@ public class AudioSharingReceiver extends BroadcastReceiver {
                    Log.d(TAG, "App in foreground, show share audio dialog");
                } else {
                    Log.d(TAG, "App not in foreground, show share audio notification");
                    LocalBluetoothManager manager = Utils.getLocalBtManager(context);
                    if (!validToAddSource(device, action, manager).isEmpty()) {
                        showAddSourceNotification(context, device);
                    }
                }
                break;
            case ACTION_LE_AUDIO_SHARING_ADD_SOURCE:
                if (!BluetoothUtils.isAudioSharingUIAvailable(context)) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, feature disabled.");
                if (!Flags.promoteAudioSharingForSecondAutoConnectedLeaDevice()
                        || !BluetoothUtils.isAudioSharingUIAvailable(context)) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, flag/feature off");
                    cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
                    return;
                }
                BluetoothDevice sink = intent.getParcelableExtra(EXTRA_BLUETOOTH_DEVICE,
                        BluetoothDevice.class);
                if (sink == null) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, null device");
                LocalBluetoothManager manager = Utils.getLocalBtManager(context);
                ImmutableList<BluetoothDevice> sinksToAdd = validToAddSource(sink, action, manager);
                AudioSharingUtils.addSourceToTargetSinks(sinksToAdd, manager);
                cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
                    return;
                break;
            case ACTION_LE_AUDIO_SHARING_CANCEL_NOTIF:
                int notifId = intent.getIntExtra(EXTRA_NOTIF_ID, -1);
                if (notifId != -1) {
                    cancelSharingNotification(context, notifId);
                }
                LocalBluetoothManager manager = Utils.getLocalBtManager(context);
                boolean isBroadcasting = BluetoothUtils.isBroadcasting(manager);
                break;
            default:
                Log.w(TAG, "Received unexpected intent " + action);
        }
    }

    private ImmutableList<BluetoothDevice> validToAddSource(@Nullable BluetoothDevice sink,
            @NonNull String action, @Nullable LocalBluetoothManager btManager) {
        if (sink == null) {
            Log.d(TAG, "Skip " + action + ", null device");
            return ImmutableList.of();
        }
        boolean isBroadcasting = BluetoothUtils.isBroadcasting(btManager);
        if (!isBroadcasting) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, not broadcasting");
                    cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
                    return;
            Log.d(TAG, "Skip " + action + ", not broadcasting");
            return ImmutableList.of();
        }
        Map<Integer, List<BluetoothDevice>> groupedDevices =
                        AudioSharingUtils.fetchConnectedDevicesByGroupId(manager);
                AudioSharingUtils.fetchConnectedDevicesByGroupId(btManager);
        int groupId = groupedDevices.entrySet().stream().filter(
                entry -> entry.getValue().contains(sink)).findFirst().map(
                Map.Entry::getKey).orElse(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
        if (groupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, no valid group id");
                    cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
                    return;
            Log.d(TAG, "Skip " + action + ", no valid group id");
            return ImmutableList.of();
        }
        List<BluetoothDevice> sinksToAdd = groupedDevices.getOrDefault(groupId,
                ImmutableList.of()).stream().filter(
                    d -> !BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(d,
                                manager)).toList();
                        btManager)).toList();
        if (sinksToAdd.isEmpty()) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, already has source");
            Log.d(TAG, "Skip " + action + ", already has source");
            return ImmutableList.of();
        } else if (groupedDevices.entrySet().stream().filter(
                entry -> entry.getKey() != groupId && entry.getValue().stream().anyMatch(
                        d -> BluetoothUtils.hasConnectedBroadcastSourceForBtDevice(d,
                                        manager))).toList().size() >= 2) {
                    Log.d(TAG, "Skip ACTION_LE_AUDIO_SHARING_ADD_SOURCE, already 2 sinks");
                } else {
                    AudioSharingUtils.addSourceToTargetSinks(sinksToAdd, manager);
                }
                cancelSharingNotification(context, ADD_SOURCE_NOTIFICATION_ID);
                break;
            case ACTION_LE_AUDIO_SHARING_CANCEL_NOTIF:
                int notifId = intent.getIntExtra(EXTRA_NOTIF_ID, -1);
                if (notifId != -1) {
                    cancelSharingNotification(context, notifId);
                }
                break;
            default:
                Log.w(TAG, "Received unexpected intent " + intent.getAction());
                                btManager))).toList().size() >= 2) {
            Log.d(TAG, "Skip " + action + ", already 2 sinks");
            return ImmutableList.of();
        }
        return ImmutableList.copyOf(sinksToAdd);
    }

    private void showSharingNotification(@NonNull Context context) {
@@ -273,12 +284,14 @@ public class AudioSharingReceiver extends BroadcastReceiver {
        Intent addSourceIntent =
                new Intent(ACTION_LE_AUDIO_SHARING_ADD_SOURCE).setPackage(context.getPackageName())
                        .putExtra(EXTRA_BLUETOOTH_DEVICE, device);
        // Use PendingIntent.FLAG_UPDATE_CURRENT here because intent extra (device) could be updated
        PendingIntent addSourcePendingIntent =
                PendingIntent.getBroadcast(
                        context,
                        R.string.audio_sharing_share_button_label,
                        addSourceIntent,
                        PendingIntent.FLAG_IMMUTABLE);
                        PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT
                                | PendingIntent.FLAG_IMMUTABLE);
        NotificationCompat.Action addSourceAction =
                new NotificationCompat.Action.Builder(
                        0,
+183 −10
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
@@ -306,7 +307,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_broadcastDisabled_doNothing() {
        mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
                BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED);
@@ -325,6 +327,38 @@ public class AudioSharingReceiverTest {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE)
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_flagOff_doNothing() {
        setAppInForeground(false);
        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
        intent.setPackage(mContext.getPackageName());
        intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
        AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
        audioSharingReceiver.onReceive(mContext, intent);

        verify(mNm, never()).notify(
                eq(com.android.settings.R.string.share_audio_notification_title),
                any(Notification.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_nullArg_doNothing() {
        setAppInForeground(false);
        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
        intent.setPackage(mContext.getPackageName());
        AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
        audioSharingReceiver.onReceive(mContext, intent);

        verify(mNm, never()).notify(
                eq(com.android.settings.R.string.share_audio_notification_title),
                any(Notification.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_showDialog() {
        setAppInForeground(true);
        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
@@ -340,9 +374,139 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_notInBroadcast_noNotif() {
        setAppInForeground(false);
        when(mBroadcast.isEnabled(null)).thenReturn(false);

        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
        intent.setPackage(mContext.getPackageName());
        intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
        AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
        audioSharingReceiver.onReceive(mContext, intent);

        verify(mNm, never()).notify(
                eq(com.android.settings.R.string.share_audio_notification_title),
                any(Notification.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_invalidGroupId_noNotif() {
        setAppInForeground(false);
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
        when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
        CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice);
        when(cachedDevice.getDevice()).thenReturn(mDevice);
        when(cachedDevice.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice));

        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
        intent.setPackage(mContext.getPackageName());
        intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
        AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
        audioSharingReceiver.onReceive(mContext, intent);

        verify(mNm, never()).notify(
                eq(com.android.settings.R.string.share_audio_notification_title),
                any(Notification.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_alreadyTwoSinks_noNotif() {
        setAppInForeground(false);
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
        CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
        when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
        CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
        when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice1);
        BluetoothDevice device2 = mock(BluetoothDevice.class);
        CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
        when(deviceManager.findDevice(device2)).thenReturn(cachedDevice2);
        when(cachedDevice1.getGroupId()).thenReturn(1);
        when(cachedDevice1.getDevice()).thenReturn(mDevice);
        when(cachedDevice1.getName()).thenReturn(TEST_DEVICE_NAME);
        when(cachedDevice2.getGroupId()).thenReturn(2);
        when(cachedDevice2.getDevice()).thenReturn(device2);
        when(cachedDevice2.getName()).thenReturn(TEST_DEVICE_NAME);
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice, device2));
        BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
        when(state.getBroadcastId()).thenReturn(1);
        when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(state));

        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
        intent.setPackage(mContext.getPackageName());
        intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
        AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
        audioSharingReceiver.onReceive(mContext, intent);

        verify(mNm, never()).notify(
                eq(com.android.settings.R.string.share_audio_notification_title),
                any(Notification.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void
            broadcastReceiver_receiveAudioSharingDeviceConnected_alreadyHasSource_cancelNotif() {
        setAppInForeground(false);
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
        CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
        when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
        CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice);
        when(cachedDevice.getGroupId()).thenReturn(1);
        when(cachedDevice.getDevice()).thenReturn(mDevice);
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice));
        BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
        when(state.getBroadcastId()).thenReturn(1);
        when(mAssistant.getAllSources(mDevice)).thenReturn(ImmutableList.of(state));

        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
        intent.setPackage(mContext.getPackageName());
        intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
        AudioSharingReceiver audioSharingReceiver = getAudioSharingReceiver(intent);
        audioSharingReceiver.onReceive(mContext, intent);

        verify(mNm, never()).notify(
                eq(com.android.settings.R.string.share_audio_notification_title),
                any(Notification.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingDeviceConnected_showNotification() {
        setAppInForeground(false);
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
        BluetoothLeBroadcastMetadata metadata = mock(BluetoothLeBroadcastMetadata.class);
        when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(metadata);
        CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
        when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
        CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class);
        when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice1);
        BluetoothDevice device2 = mock(BluetoothDevice.class);
        CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
        when(deviceManager.findDevice(device2)).thenReturn(cachedDevice2);
        when(cachedDevice1.getGroupId()).thenReturn(1);
        when(cachedDevice1.getDevice()).thenReturn(mDevice);
        when(cachedDevice2.getGroupId()).thenReturn(2);
        when(cachedDevice2.getDevice()).thenReturn(device2);
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice, device2));
        BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
        when(state.getBroadcastId()).thenReturn(1);
        when(mAssistant.getAllSources(device2)).thenReturn(ImmutableList.of(state));

        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_DEVICE_CONNECTED);
        intent.setPackage(mContext.getPackageName());
        intent.putExtra(EXTRA_BLUETOOTH_DEVICE, mDevice);
@@ -355,7 +519,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_broadcastDisabled_cancelNotif() {
        mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
                BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED);
@@ -372,7 +537,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_nullArg_cancelNotif() {
        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_ADD_SOURCE);
        intent.setPackage(mContext.getPackageName());
@@ -385,7 +551,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_notInBroadcast_cancelNotif() {
        when(mBroadcast.isEnabled(null)).thenReturn(false);

@@ -401,7 +568,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_notConnected_cancelNotif() {
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of());
@@ -418,7 +586,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_invalidGroupId_cancelNotif() {
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
@@ -426,6 +595,7 @@ public class AudioSharingReceiverTest {
        CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        when(deviceManager.findDevice(mDevice)).thenReturn(cachedDevice);
        when(cachedDevice.getDevice()).thenReturn(mDevice);
        when(cachedDevice.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice));

        Intent intent = new Intent(ACTION_LE_AUDIO_SHARING_ADD_SOURCE);
@@ -440,7 +610,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX})
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_alreadyTwoSinks_cancelNotif() {
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
@@ -474,7 +645,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX})
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_alreadyHasSource_cancelNotif() {
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        when(mBroadcast.getLatestBroadcastId()).thenReturn(1);
@@ -501,7 +673,8 @@ public class AudioSharingReceiverTest {
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX})
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX,
            Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE})
    public void broadcastReceiver_receiveAudioSharingAddSource_addSource() {
        when(mBroadcast.isEnabled(null)).thenReturn(true);
        when(mBroadcast.getLatestBroadcastId()).thenReturn(1);