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

Commit f8b9878c authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
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." am: b9b748cc am: 8759d8a9

Original change: https://android-review.googlesource.com/c/platform/packages/services/Telecomm/+/2132724



Change-Id: Ieef6701d6580af4aa3aedfb002796f712f816486
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 4edc329e 8759d8a9
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.telecom.Log;
import android.util.ArraySet;
import android.util.LocalLog;

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

import java.util.ArrayList;
@@ -176,6 +177,12 @@ public class BluetoothDeviceManager {
            new LinkedHashMap<>();
    private final LinkedHashMap<BluetoothDevice, Integer> mGroupsByDevice =
            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 mGroupIdPending = BluetoothLeAudio.GROUP_ID_INVALID;
    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) {
            clearDeviceFromDeviceMaps(device.getAddress());
            LinkedHashMap<String, BluetoothDevice> targetDeviceMap;
            if (deviceType == DEVICE_TYPE_LE_AUDIO) {
                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) {
        mLocalLog.log("Device disconnected -- address: " + device.getAddress() + " deviceType: "
                + deviceType);
+18 −0
Original line number Diff line number Diff line
@@ -619,6 +619,24 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        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
    @Test
    public void testInBandRingingEnabledForLeDevice() {