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

Commit b9b748cc authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Update BT device properly in BluetoothDeviceManager when device with...

Merge "Update BT device properly in BluetoothDeviceManager when device with same address changed to other type."
parents 66029bb7 9c9876e6
Loading
Loading
Loading
Loading
+16 −1
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.telecom.Log;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.LocalLog;
import android.util.LocalLog;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.IndentingPrintWriter;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -176,6 +177,12 @@ public class BluetoothDeviceManager {
            new LinkedHashMap<>();
            new LinkedHashMap<>();
    private final LinkedHashMap<BluetoothDevice, Integer> mGroupsByDevice =
    private final LinkedHashMap<BluetoothDevice, Integer> mGroupsByDevice =
            new LinkedHashMap<>();
            new LinkedHashMap<>();
    private final ArrayList<LinkedHashMap<String, BluetoothDevice>>
            mDevicesByAddressMaps = new ArrayList<LinkedHashMap<String, BluetoothDevice>>(); {
        mDevicesByAddressMaps.add(mHfpDevicesByAddress);
        mDevicesByAddressMaps.add(mHearingAidDevicesByAddress);
        mDevicesByAddressMaps.add(mLeAudioDevicesByAddress);
    }
    private int mGroupIdActive = BluetoothLeAudio.GROUP_ID_INVALID;
    private int mGroupIdActive = BluetoothLeAudio.GROUP_ID_INVALID;
    private int mGroupIdPending = BluetoothLeAudio.GROUP_ID_INVALID;
    private int mGroupIdPending = BluetoothLeAudio.GROUP_ID_INVALID;
    private final LocalLog mLocalLog = new LocalLog(20);
    private final LocalLog mLocalLog = new LocalLog(20);
@@ -352,8 +359,10 @@ public class BluetoothDeviceManager {
        }
        }
    }
    }


    void onDeviceConnected(BluetoothDevice device, int deviceType) {
    @VisibleForTesting
    public void onDeviceConnected(BluetoothDevice device, int deviceType) {
        synchronized (mLock) {
        synchronized (mLock) {
            clearDeviceFromDeviceMaps(device.getAddress());
            LinkedHashMap<String, BluetoothDevice> targetDeviceMap;
            LinkedHashMap<String, BluetoothDevice> targetDeviceMap;
            if (deviceType == DEVICE_TYPE_LE_AUDIO) {
            if (deviceType == DEVICE_TYPE_LE_AUDIO) {
                if (mBluetoothLeAudioService == null) {
                if (mBluetoothLeAudioService == null) {
@@ -397,6 +406,12 @@ public class BluetoothDeviceManager {
        }
        }
    }
    }


    void clearDeviceFromDeviceMaps(String deviceAddress) {
        for (LinkedHashMap<String, BluetoothDevice> deviceMap : mDevicesByAddressMaps) {
            deviceMap.remove(deviceAddress);
        }
    }

    void onDeviceDisconnected(BluetoothDevice device, int deviceType) {
    void onDeviceDisconnected(BluetoothDevice device, int deviceType) {
        mLocalLog.log("Device disconnected -- address: " + device.getAddress() + " deviceType: "
        mLocalLog.log("Device disconnected -- address: " + device.getAddress() + " deviceType: "
                + deviceType);
                + deviceType);
+18 −0
Original line number Original line Diff line number Diff line
@@ -619,6 +619,24 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        assertFalse(mBluetoothDeviceManager.isHearingAidSetAsCommunicationDevice());
        assertFalse(mBluetoothDeviceManager.isHearingAidSetAsCommunicationDevice());
    }
    }


    @SmallTest
    @Test
    public void testConnectedDevicesDoNotContainDuplicateDevices() {
        BluetoothDevice hfpDevice = mock(BluetoothDevice.class);
        when(hfpDevice.getAddress()).thenReturn("00:00:00:00:00:00");
        when(hfpDevice.getType()).thenReturn(BluetoothDeviceManager.DEVICE_TYPE_HEADSET);
        BluetoothDevice leDevice = mock(BluetoothDevice.class);
        when(hfpDevice.getAddress()).thenReturn("00:00:00:00:00:00");
        when(hfpDevice.getType()).thenReturn(BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO);

        mBluetoothDeviceManager.onDeviceConnected(hfpDevice,
                BluetoothDeviceManager.DEVICE_TYPE_HEADSET);
        mBluetoothDeviceManager.onDeviceConnected(leDevice,
                BluetoothDeviceManager.DEVICE_TYPE_LE_AUDIO);

        assertEquals(1, mBluetoothDeviceManager.getNumConnectedDevices());
    }

    @SmallTest
    @SmallTest
    @Test
    @Test
    public void testInBandRingingEnabledForLeDevice() {
    public void testInBandRingingEnabledForLeDevice() {