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

Commit 231ca1c2 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 am: f8b9878c am: fb6d67a1 am: 92d04003 am: 91c51d2e

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



Change-Id: I82b6a9bdcc4b692c08e0655384e54a66800500a6
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 4b411d3f 91c51d2e
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 com.android.server.telecom.CallAudioCommunicationDeviceTracker;

@@ -177,6 +178,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);
@@ -356,8 +363,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) {
@@ -401,6 +410,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
@@ -731,6 +731,24 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
                AudioDeviceInfo.TYPE_BLE_HEADSET));
    }

    @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() {