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

Commit 3fa8128d authored by Yuyang Huang's avatar Yuyang Huang Committed by Gerrit Code Review
Browse files

Merge "Change inband ringtone based with active device." into main

parents 1de36803 32263c95
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -1393,6 +1393,9 @@ public class HeadsetService extends ProfileService {
            mActiveDevice = null;
            mNativeInterface.setActiveDevice(null);
            broadcastActiveDevice(null);
            if (Flags.updateActiveDeviceInBandRingtone()) {
                updateInbandRinging(null, true);
            }
        }
    }

@@ -1469,6 +1472,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
@@ -1520,6 +1526,9 @@ public class HeadsetService extends ProfileService {
                                    BluetoothProfileConnectionInfo.createHfpInfo());
                }
                broadcastActiveDevice(mActiveDevice);
                if (Flags.updateActiveDeviceInBandRingtone()) {
                    updateInbandRinging(device, true);
                }
            }
        }
        return true;
@@ -2206,8 +2215,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;

@@ -2216,6 +2230,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 {