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

Commit 07c1b0fe authored by Hall Liu's avatar Hall Liu
Browse files

Partially ignore hearing aid changes when not in call

When Telecom isn't in a call, don't send events indicating that BT audio
is active.

Test: atest TelecomUnitTests:BluetoothDeviceManagerTest
Fixes: 146873436
Change-Id: I53cd7a721155fa38b0a4bf54d186ea7d9c7d7966
parent 68b6108e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -146,6 +146,10 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
            if (device == null) {
                mBluetoothRouteManager.sendMessage(BT_AUDIO_LOST, args);
            } else {
                if (!mIsInCall) {
                    Log.i(LOG_TAG, "Ignoring hearing aid audio on since we're not in a call");
                    return;
                }
                args.arg2 = device.getAddress();
                mBluetoothRouteManager.sendMessage(BT_AUDIO_IS_ON, args);
            }
+17 −3
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {

    BluetoothDeviceManager mBluetoothDeviceManager;
    BluetoothProfile.ServiceListener serviceListenerUnderTest;
    BroadcastReceiver receiverUnderTest;
    BluetoothStateReceiver receiverUnderTest;

    private BluetoothDevice device1;
    private BluetoothDevice device2;
@@ -90,8 +90,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
                serviceCaptor.capture(), eq(BluetoothProfile.HEADSET));
        serviceListenerUnderTest = serviceCaptor.getValue();

        receiverUnderTest = new BluetoothStateReceiver(mBluetoothDeviceManager,
                null /* route mgr not needed here */);
        receiverUnderTest = new BluetoothStateReceiver(mBluetoothDeviceManager, mRouteManager);

        mBluetoothDeviceManager.setHeadsetServiceForTesting(mHeadsetProxy);
        mBluetoothDeviceManager.setHearingAidServiceForTesting(mBluetoothHearingAid);
@@ -196,6 +195,21 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        assertEquals(2, mBluetoothDeviceManager.getNumConnectedDevices());
    }

    @SmallTest
    @Test
    public void testHearingAidChangesIgnoredWhenNotInCall() {
        receiverUnderTest.setIsInCall(false);
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true));
        Intent activeDeviceChangedIntent =
                new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        activeDeviceChangedIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device2);
        receiverUnderTest.onReceive(mContext, activeDeviceChangedIntent);

        verify(mRouteManager).onActiveDeviceChanged(device2, true);
        verify(mRouteManager, never()).sendMessage(BluetoothRouteManager.BT_AUDIO_IS_ON);
    }

    @SmallTest
    @Test
    public void testConnectDisconnectAudioHeadset() {