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

Commit 8759d8a9 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

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



Change-Id: Ifb46f1c7c6da200f473fe6d5b7d9d7c7b571d46e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 638df3a8 b9b748cc
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() {