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

Commit b29a6fd3 authored by Hall Liu's avatar Hall Liu Committed by Gerrit Code Review
Browse files

Merge "Notify BluetoothRouteManager when Bluetooth turned off"

parents d8a27d5f d4970c19
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -29,8 +29,13 @@ import com.android.server.telecom.BluetoothAdapterProxy;
import com.android.server.telecom.BluetoothHeadsetProxy;
import com.android.server.telecom.TelecomSystem;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class BluetoothDeviceManager {
    private final BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
@@ -60,7 +65,14 @@ public class BluetoothDeviceManager {
                    try {
                        synchronized (mLock) {
                            mBluetoothHeadsetService = null;
                            Log.i(BluetoothDeviceManager.this, "Lost BluetoothHeadset service.");
                            Log.i(BluetoothDeviceManager.this, "Lost BluetoothHeadset service. " +
                                    "Removing all tracked devices.");
                            List<BluetoothDevice> devicesToRemove = new LinkedList<>(
                                    mConnectedDevicesByAddress.values());
                            mConnectedDevicesByAddress.clear();
                            for (BluetoothDevice device : devicesToRemove) {
                                mBluetoothRouteManager.onDeviceLost(device);
                            }
                        }
                    } finally {
                        Log.endSession();
+14 −0
Original line number Diff line number Diff line
@@ -131,6 +131,20 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
                mBluetoothDeviceManager.getMostRecentlyConnectedDevice(device3.getAddress()));
    }

    @SmallTest
    public void testHeadsetServiceDisconnect() {
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1));
        receiverUnderTest.onReceive(mContext,
                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2));
        serviceListenerUnderTest.onServiceDisconnected(0);

        verify(mRouteManager).onDeviceLost(device1);
        verify(mRouteManager).onDeviceLost(device2);
        assertNull(mBluetoothDeviceManager.getHeadsetService());
        assertEquals(0, mBluetoothDeviceManager.getNumConnectedDevices());
    }

    private Intent buildConnectionActionIntent(int state, BluetoothDevice device) {
        Intent i = new Intent(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        i.putExtra(BluetoothHeadset.EXTRA_STATE, state);