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

Commit 32263c95 authored by Nitin Jadhav's avatar Nitin Jadhav
Browse files

Change inband ringtone based with active device.

Description: Previously when there is no LE Audio, if there is 1 connected HFP device, it will always be active. But with LE Audio, it might be connected but not active. In such case, phone should notify the remote that in band ringtone will not be played. It should use out band ringtone.
Bug: 346498545
Bug: 349318724
Test: Manual | Make a incomming call, observe inband ringtone behaviour
Test: atest HeadsetServiceAndStateMachineTest#testIsInbandRingingEnabled_SwitchActiveDevice
Flag: com.android.bluetooth.flags.update_active_device_in_band_ringtone
Change-Id: I1470bf06b0639732eab48447b134694123241f58
parent 3643150a
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -1395,6 +1395,9 @@ public class HeadsetService extends ProfileService {
            mActiveDevice = null;
            mNativeInterface.setActiveDevice(null);
            broadcastActiveDevice(null);
            if (Flags.updateActiveDeviceInBandRingtone()) {
                updateInbandRinging(null, true);
            }
        }
    }

@@ -1472,6 +1475,9 @@ public class HeadsetService extends ProfileService {
                                    BluetoothProfileConnectionInfo.createHfpInfo());
                }
                broadcastActiveDevice(mActiveDevice);
                if (Flags.updateActiveDeviceInBandRingtone()) {
                    updateInbandRinging(device, true);
                }
            } else if (shouldPersistAudio()) {
                /* If HFP is getting active for a phonecall and there is LeAudio device active,
                 * Lets inactive LeAudio device as soon as possible so there is no CISes connected
@@ -1523,6 +1529,9 @@ public class HeadsetService extends ProfileService {
                                    BluetoothProfileConnectionInfo.createHfpInfo());
                }
                broadcastActiveDevice(mActiveDevice);
                if (Flags.updateActiveDeviceInBandRingtone()) {
                    updateInbandRinging(device, true);
                }
            }
        }
        return true;
@@ -2218,8 +2227,13 @@ public class HeadsetService extends ProfileService {
        synchronized (mStateMachines) {
            final boolean inbandRingingRuntimeDisable = mInbandRingingRuntimeDisable;

            mInbandRingingRuntimeDisable =
                    getConnectedDevices().size() > 1 || isHeadsetClientConnected();
            if (getConnectedDevices().size() > 1
                    || isHeadsetClientConnected()
                    || (Flags.updateActiveDeviceInBandRingtone() && mActiveDevice == null)) {
                mInbandRingingRuntimeDisable = true;
            } else {
                mInbandRingingRuntimeDisable = false;
            }

            final boolean updateAll = inbandRingingRuntimeDisable != mInbandRingingRuntimeDisable;

@@ -2228,6 +2242,8 @@ public class HeadsetService extends ProfileService {
                    "updateInbandRinging():"
                            + " Device="
                            + device
                            + " ActiveDevice="
                            + mActiveDevice
                            + " enabled="
                            + !mInbandRingingRuntimeDisable
                            + " connected="
+22 −0
Original line number Diff line number Diff line
@@ -494,6 +494,28 @@ public class HeadsetServiceAndStateMachineTest {
        assertThat(mHeadsetService.isVirtualCallStarted()).isFalse();
    }

    /** Test the value of isInbandRingingEnabled will be changed with the change of active device */
    @Test
    public void testIsInbandRingingEnabled_SwitchActiveDevice() {
        mSetFlagsRule.enableFlags(Flags.FLAG_UPDATE_ACTIVE_DEVICE_IN_BAND_RINGTONE);
        BluetoothDevice device = TestUtils.getTestDevice(mAdapter, 0);
        connectTestDevice(device);

        assertThat(mHeadsetService.setActiveDevice(device)).isTrue();
        mTestLooper.dispatchAll();
        assertThat(mHeadsetService.isInbandRingingEnabled()).isTrue();

        assertThat(mHeadsetService.setActiveDevice(null)).isTrue();
        mTestLooper.dispatchAll();
        verify(mNativeInterface, atLeastOnce()).sendBsir(eq(device), eq(false));
        assertThat(mHeadsetService.isInbandRingingEnabled()).isFalse();

        assertThat(mHeadsetService.setActiveDevice(device)).isTrue();
        mTestLooper.dispatchAll();
        verify(mNativeInterface, atLeastOnce()).sendBsir(eq(device), eq(true));
        assertThat(mHeadsetService.isInbandRingingEnabled()).isTrue();
    }

    /** Test the behavior when dialing outgoing call from the headset */
    @Test
    public void testDialingOutCall_NormalDialingOut() throws RemoteException {