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

Commit a00bdf6b authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

Improve broadcast supported check to support private audio sharing

For private audio sharing, the device might have no actively connected LEA devices.
Need to improve the broadcast support check for callback unregister and
active broadcasting cases.

Tag: #bug
Bug: 294618457
Test: atest MediaOutputDialogTest MediaOutputBaseDialogTest
Test: manual Broadcast with two connected pair of LE Audio devices
Change-Id: Ibf939a09a2d376b7aa834ccb2f7c96df4db08b5c
parent 1b20950e
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -296,7 +296,10 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements

    @Override
    public void stop() {
        if (isBroadcastSupported() && mIsLeBroadcastCallbackRegistered) {
        // unregister broadcast callback should only depend on profile and registered flag
        // rather than remote device or broadcast state
        // otherwise it might have risks of leaking registered callback handle
        if (mMediaOutputController.isBroadcastSupported() && mIsLeBroadcastCallbackRegistered) {
            mMediaOutputController.unregisterLeBroadcastServiceCallback(mBroadcastCallback);
            mIsLeBroadcastCallbackRegistered = false;
        }
+7 −1
Original line number Diff line number Diff line
@@ -104,11 +104,16 @@ public class MediaOutputDialog extends MediaOutputBaseDialog {
    @Override
    public boolean isBroadcastSupported() {
        boolean isBluetoothLeDevice = false;
        boolean isBroadcastEnabled = false;
        if (FeatureFlagUtils.isEnabled(mContext,
                FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST)) {
            if (mMediaOutputController.getCurrentConnectedMediaDevice() != null) {
                isBluetoothLeDevice = mMediaOutputController.isBluetoothLeDevice(
                    mMediaOutputController.getCurrentConnectedMediaDevice());
                // if broadcast is active, broadcast should be considered as supported
                // there could be a valid case that broadcast is ongoing
                // without active LEA device connected
                isBroadcastEnabled = mMediaOutputController.isBluetoothLeBroadcastEnabled();
            }
        } else {
            // To decouple LE Audio Broadcast and Unicast, it always displays the button when there
@@ -116,7 +121,8 @@ public class MediaOutputDialog extends MediaOutputBaseDialog {
            isBluetoothLeDevice = true;
        }

        return mMediaOutputController.isBroadcastSupported() && isBluetoothLeDevice;
        return mMediaOutputController.isBroadcastSupported()
                && (isBluetoothLeDevice || isBroadcastEnabled);
    }

    @Override
+15 −0
Original line number Diff line number Diff line
@@ -277,6 +277,21 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase {
        verify(mLocalBluetoothLeBroadcast, never()).unregisterServiceCallBack(any());
    }

    @Test
    public void
            whenNotBroadcasting_verifyLeBroadcastServiceCallBackIsUnregisteredIfProfileEnabled() {
        when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(
                mLocalBluetoothLeBroadcast);
        mIsBroadcasting = true;

        mMediaOutputBaseDialogImpl.start();
        verify(mLocalBluetoothLeBroadcast).registerServiceCallBack(any(), any());

        mIsBroadcasting = false;
        mMediaOutputBaseDialogImpl.stop();
        verify(mLocalBluetoothLeBroadcast).unregisterServiceCallBack(any());
    }

    @Test
    public void refresh_checkStopText() {
        mStopText = "test_string";
+24 −0
Original line number Diff line number Diff line
@@ -255,6 +255,30 @@ public class MediaOutputDialogTest extends SysuiTestCase {
        assertThat(mMediaOutputDialog.isBroadcastSupported()).isTrue();
    }

    @Test
    public void isBroadcastSupported_noBleDeviceAndEnabledBroadcast_returnsTrue() {
        when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(
                mLocalBluetoothLeBroadcast);
        when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(true);
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
        when(mMediaDevice.isBLEDevice()).thenReturn(false);

        assertThat(mMediaOutputDialog.isBroadcastSupported()).isTrue();
    }

    @Test
    public void isBroadcastSupported_noBleDeviceAndDisabledBroadcast_returnsFalse() {
        when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(
                mLocalBluetoothLeBroadcast);
        when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false);
        FeatureFlagUtils.setEnabled(mContext,
                FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
        when(mMediaDevice.isBLEDevice()).thenReturn(false);

        assertThat(mMediaOutputDialog.isBroadcastSupported()).isFalse();
    }

    @Test
    public void getBroadcastIconVisibility_isBroadcasting_returnVisible() {
        when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(