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

Commit 3424bea3 authored by Hall Liu's avatar Hall Liu Committed by Chienyuan Huang
Browse files

DO NOT MERGE Speculative fix for BT race condition

When the BT stack goes down very soon after a device added broadcast is
received, we have the potential for a device to stick around in the
device manager with no active BT service, leading to repeated failure to
connect to said device. This change checks to make sure the service is
non null before adding the device.

Change-Id: Ibee8ba2c611d750147249ce1c750a8d433ebff5b
Bug: 124235726
Test: unit
parent afa27711
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -136,6 +136,11 @@ public class BluetoothDeviceManager {

    void onDeviceConnected(BluetoothDevice device) {
        synchronized (mLock) {
            if (mBluetoothHeadsetService == null) {
                Log.w(this, "Headset service null when receiving device added broadcast");
                return;
            }

            if (!mConnectedDevicesByAddress.containsKey(device.getAddress())) {
                mConnectedDevicesByAddress.put(device.getAddress(), device);
                mBluetoothRouteManager.onDeviceAdded(device.getAddress());
+11 −0
Original line number Diff line number Diff line
@@ -98,6 +98,17 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        assertNull(mBluetoothDeviceManager.getMostRecentlyConnectedDevice(null));
    }

    @SmallTest
    @Test
    public void testAddDeviceFailsWhenServicesAreNull() {
        mBluetoothDeviceManager.setHeadsetServiceForTesting(null);

        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1));

        assertEquals(0, mBluetoothDeviceManager.getNumConnectedDevices());
    }
    
    @SmallTest
    @Test
    public void testMultiDeviceConnectAndDisconnect() {