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

Commit 785457ec authored by Hall Liu's avatar Hall Liu Committed by Gerrit Code Review
Browse files

Merge "Remove active devices when the BT profile disconnects"

parents d3e1e439 b19c0d43
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -73,12 +73,14 @@ public class BluetoothDeviceManager {
                                        "Lost BluetoothHeadset service. " +
                                                "Removing all tracked devices.");
                                lostServiceDevices = mHfpDevicesByAddress;
                                mBluetoothRouteManager.onActiveDeviceChanged(null, false);
                            } else if (profile == BluetoothProfile.HEARING_AID) {
                                mBluetoothHearingAidService = null;
                                Log.i(BluetoothDeviceManager.this,
                                        "Lost BluetoothHearingAid service. " +
                                                "Removing all tracked devices.");
                                lostServiceDevices = mHearingAidDevicesByAddress;
                                mBluetoothRouteManager.onActiveDeviceChanged(null, true);
                            } else {
                                return;
                            }
+21 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import org.mockito.Mock;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
@@ -161,6 +162,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true));
        serviceListenerUnderTest.onServiceDisconnected(BluetoothProfile.HEADSET);

        verify(mRouteManager).onActiveDeviceChanged(isNull(), eq(false));
        verify(mRouteManager).onDeviceLost(device1.getAddress());
        verify(mRouteManager).onDeviceLost(device3.getAddress());
        verify(mRouteManager, never()).onDeviceLost(device2.getAddress());
@@ -168,6 +170,25 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        assertEquals(1, mBluetoothDeviceManager.getNumConnectedDevices());
    }

    @SmallTest
    @Test
    public void testHearingAidServiceDisconnect() {
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1, false));
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device3, false));
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true));
        serviceListenerUnderTest.onServiceDisconnected(BluetoothProfile.HEARING_AID);

        verify(mRouteManager).onActiveDeviceChanged(isNull(), eq(true));
        verify(mRouteManager).onDeviceLost(device2.getAddress());
        verify(mRouteManager, never()).onDeviceLost(device1.getAddress());
        verify(mRouteManager, never()).onDeviceLost(device3.getAddress());
        assertNull(mBluetoothDeviceManager.getHearingAidService());
        assertEquals(2, mBluetoothDeviceManager.getNumConnectedDevices());
    }

    @SmallTest
    @Test
    public void testConnectDisconnectAudioHeadset() {