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

Commit 6d42d9c5 authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Gerrit Code Review
Browse files

Merge changes Ie0f9fb03,I3baceba1

* changes:
  Set LeAudio active properly for HAP devices
  Make LE hearing Aid active prior than non hearing aid devices
parents b0ef194e 972fa271
Loading
Loading
Loading
Loading
+66 −35
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ import com.android.bluetooth.hfp.HeadsetService;
import com.android.bluetooth.le_audio.LeAudioService;
import com.android.internal.annotations.VisibleForTesting;

import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@@ -131,11 +131,12 @@ class ActiveDeviceManager {
    private final AudioManager mAudioManager;
    private final AudioManagerAudioDeviceCallback mAudioManagerAudioDeviceCallback;

    private final List<BluetoothDevice> mA2dpConnectedDevices = new LinkedList<>();
    private final List<BluetoothDevice> mHfpConnectedDevices = new LinkedList<>();
    private final List<BluetoothDevice> mHearingAidConnectedDevices = new LinkedList<>();
    private final List<BluetoothDevice> mLeAudioConnectedDevices = new LinkedList<>();
    private final List<BluetoothDevice> mLeHearingAidConnectedDevices = new LinkedList<>();
    private final List<BluetoothDevice> mA2dpConnectedDevices = new ArrayList<>();
    private final List<BluetoothDevice> mHfpConnectedDevices = new ArrayList<>();
    private final List<BluetoothDevice> mHearingAidConnectedDevices = new ArrayList<>();
    private final List<BluetoothDevice> mLeAudioConnectedDevices = new ArrayList<>();
    private final List<BluetoothDevice> mLeHearingAidConnectedDevices = new ArrayList<>();
    private List<BluetoothDevice> mPendingLeHearingAidActiveDevice = new ArrayList<>();
    private BluetoothDevice mA2dpActiveDevice = null;
    private BluetoothDevice mHfpActiveDevice = null;
    private BluetoothDevice mHearingAidActiveDevice = null;
@@ -432,11 +433,17 @@ class ActiveDeviceManager {
                            break;      // The device is already connected
                        }
                        mLeAudioConnectedDevices.add(device);
                        if (mHearingAidActiveDevice == null && mLeHearingAidActiveDevice == null) {
                        if (mHearingAidActiveDevice == null && mLeHearingAidActiveDevice == null
                                && mPendingLeHearingAidActiveDevice.isEmpty()) {
                            // New connected device: select it as active
                            setLeAudioActiveDevice(device);
                            setA2dpActiveDevice(null);
                            setHfpActiveDevice(null);
                        } else if (mPendingLeHearingAidActiveDevice.contains(device)) {
                            setLeHearingAidActiveDevice(device);
                            setHearingAidActiveDevice(null);
                            setA2dpActiveDevice(null);
                            setHfpActiveDevice(null);
                        }
                        break;
                    }
@@ -447,6 +454,7 @@ class ActiveDeviceManager {
                                    + "_CHANGED): device " + device + " disconnected");
                        }
                        mLeAudioConnectedDevices.remove(device);
                        mLeHearingAidConnectedDevices.remove(device);
                        if (Objects.equals(mLeAudioActiveDevice, device)) {
                            if (mLeAudioConnectedDevices.isEmpty()) {
                                setLeAudioActiveDevice(null);
@@ -499,16 +507,16 @@ class ActiveDeviceManager {
                        }
                        mLeHearingAidConnectedDevices.add(device);
                        if (!mLeAudioConnectedDevices.contains(device)) {
                            mLeAudioConnectedDevices.add(device);
                        }
                        // New connected device: select it as active
                        setLeAudioActiveDevice(device);
                        if (mLeAudioActiveDevice == device) {
                            // setLeAudioActiveDevice succeed
                            mPendingLeHearingAidActiveDevice.add(device);
                        } else if (Objects.equals(mLeAudioActiveDevice, device)) {
                            mLeHearingAidActiveDevice = device;
                        }
                        } else {
                            // New connected device: select it as active
                            setLeHearingAidActiveDevice(device);
                            setHearingAidActiveDevice(null);
                            setA2dpActiveDevice(null);
                            setHfpActiveDevice(null);
                        }
                        break;
                    }
                    if (prevState == BluetoothProfile.STATE_CONNECTED) {
@@ -518,15 +526,9 @@ class ActiveDeviceManager {
                                    + "_CHANGED): device " + device + " disconnected");
                        }
                        mLeHearingAidConnectedDevices.remove(device);
                        mLeAudioConnectedDevices.remove(device);
                        // mLeAudioConnectedDevices should contain all of
                        // mLeHearingAidConnectedDevices. Call setLeAudioActiveDevice(null)
                        // only if there are no LE audio devices.
                        if (Objects.equals(mLeHearingAidConnectedDevices, device)) {
                            if (mLeAudioConnectedDevices.isEmpty()) {
                                setLeAudioActiveDevice(null);
                            }
                            setFallbackDeviceActive();
                        mPendingLeHearingAidActiveDevice.remove(device);
                        if (Objects.equals(mLeHearingAidActiveDevice, device)) {
                            mLeHearingAidActiveDevice = null;
                        }
                    }
                }
@@ -536,8 +538,8 @@ class ActiveDeviceManager {
                    Intent intent = (Intent) msg.obj;
                    BluetoothDevice device =
                            intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    if (device != null && !mLeAudioConnectedDevices.contains(device)) {
                        mLeAudioConnectedDevices.add(device);
                    if (device != null && !mLeHearingAidConnectedDevices.contains(device)) {
                        mLeHearingAidConnectedDevices.add(device);
                    }
                    if (DBG) {
                        Log.d(TAG, "handleMessage(MESSAGE_HAP_ACTION_ACTIVE_DEVICE_CHANGED): "
@@ -715,6 +717,18 @@ class ActiveDeviceManager {
        mLeAudioActiveDevice = device;
        if (device == null) {
            mLeHearingAidActiveDevice = null;
            mPendingLeHearingAidActiveDevice.remove(device);
        }
    }

    private void setLeHearingAidActiveDevice(BluetoothDevice device) {
        if (!Objects.equals(mLeAudioActiveDevice, device)) {
            setLeAudioActiveDevice(device);
        }
        if (Objects.equals(mLeAudioActiveDevice, device)) {
            // setLeAudioActiveDevice succeed
            mLeHearingAidActiveDevice = device;
            mPendingLeHearingAidActiveDevice.remove(device);
        }
    }

@@ -726,11 +740,18 @@ class ActiveDeviceManager {
        if (dbManager == null) {
            return;
        }

        List<BluetoothDevice> connectedHearingAidDevices = new ArrayList<>();
        if (!mHearingAidConnectedDevices.isEmpty()) {
            connectedHearingAidDevices.addAll(mHearingAidConnectedDevices);
        }
        if (!mLeHearingAidConnectedDevices.isEmpty()) {
            connectedHearingAidDevices.addAll(mLeHearingAidConnectedDevices);
        }
        if (!connectedHearingAidDevices.isEmpty()) {
            BluetoothDevice device =
                    dbManager.getMostRecentlyConnectedDevicesInList(mHearingAidConnectedDevices);
                    dbManager.getMostRecentlyConnectedDevicesInList(connectedHearingAidDevices);
            if (device != null) {
                if (mHearingAidConnectedDevices.contains(device)) {
                    if (DBG) {
                        Log.d(TAG, "set hearing aid device active: " + device);
                    }
@@ -738,6 +759,15 @@ class ActiveDeviceManager {
                    setA2dpActiveDevice(null);
                    setHfpActiveDevice(null);
                    setLeAudioActiveDevice(null);
                } else {
                    if (DBG) {
                        Log.d(TAG, "set LE hearing aid device active: " + device);
                    }
                    setLeHearingAidActiveDevice(device);
                    setHearingAidActiveDevice(null);
                    setA2dpActiveDevice(null);
                    setHfpActiveDevice(null);
                }
                return;
            }
        }
@@ -754,7 +784,7 @@ class ActiveDeviceManager {
            headsetFallbackDevice = headsetService.getFallbackDevice();
        }

        List<BluetoothDevice> connectedDevices = new LinkedList<>();
        List<BluetoothDevice> connectedDevices = new ArrayList<>();
        connectedDevices.addAll(mLeAudioConnectedDevices);
        switch (mAudioManager.getMode()) {
            case AudioManager.MODE_NORMAL:
@@ -829,6 +859,7 @@ class ActiveDeviceManager {

        mLeHearingAidConnectedDevices.clear();
        mLeHearingAidActiveDevice = null;
        mPendingLeHearingAidActiveDevice.clear();
    }

    @VisibleForTesting
+110 −48
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.util.List;
@@ -62,7 +63,11 @@ public class ActiveDeviceManagerTest {
    private BluetoothDevice mA2dpHeadsetDevice;
    private BluetoothDevice mHearingAidDevice;
    private BluetoothDevice mLeAudioDevice;
    private BluetoothDevice mLeHearingAidDevice;
    private BluetoothDevice mSecondaryAudioDevice;
    private BluetoothDevice mMostRecentDevice;
    private boolean mFallbackToA2dp;
    private boolean mFallbackToHfp;
    private ActiveDeviceManager mActiveDeviceManager;
    private static final int TIMEOUT_MS = 1000;

@@ -85,6 +90,7 @@ public class ActiveDeviceManagerTest {
        // Set up mocks and test assets
        MockitoAnnotations.initMocks(this);
        TestUtils.setAdapterService(mAdapterService);

        when(mAdapterService.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
        when(mAdapterService.getSystemServiceName(AudioManager.class))
                .thenReturn(Context.AUDIO_SERVICE);
@@ -93,12 +99,6 @@ public class ActiveDeviceManagerTest {
        when(mServiceFactory.getHeadsetService()).thenReturn(mHeadsetService);
        when(mServiceFactory.getHearingAidService()).thenReturn(mHearingAidService);
        when(mServiceFactory.getLeAudioService()).thenReturn(mLeAudioService);
        when(mA2dpService.setActiveDevice(any())).thenReturn(true);
        when(mHeadsetService.setActiveDevice(any())).thenReturn(true);
        when(mHearingAidService.setActiveDevice(any())).thenReturn(true);
        when(mLeAudioService.setActiveDevice(any())).thenReturn(true);
        when(mDatabaseManager.getMostRecentlyConnectedDevicesInList(any()))
                .thenReturn(mSecondaryAudioDevice);

        mActiveDeviceManager = new ActiveDeviceManager(mAdapterService, mServiceFactory);
        mActiveDeviceManager.start();
@@ -110,7 +110,46 @@ public class ActiveDeviceManagerTest {
        mA2dpHeadsetDevice = TestUtils.getTestDevice(mAdapter, 2);
        mHearingAidDevice = TestUtils.getTestDevice(mAdapter, 3);
        mLeAudioDevice = TestUtils.getTestDevice(mAdapter, 4);
        mSecondaryAudioDevice = TestUtils.getTestDevice(mAdapter, 5);
        mLeHearingAidDevice = TestUtils.getTestDevice(mAdapter, 5);
        mSecondaryAudioDevice = TestUtils.getTestDevice(mAdapter, 6);
        mMostRecentDevice = null;

        when(mA2dpService.setActiveDevice(any())).thenAnswer(invocation -> {
            BluetoothDevice device = invocation.getArgument(0);
            BluetoothDevice fallbackDevice = device;
            if (device == null && mFallbackToA2dp) {
                fallbackDevice = mA2dpDevice;
            }
            when(mA2dpService.getFallbackDevice()).thenReturn(fallbackDevice);
            return true;
        });
        when(mHeadsetService.setActiveDevice(any())).thenAnswer(invocation -> {
            BluetoothDevice device = invocation.getArgument(0);
            BluetoothDevice fallbackDevice = device;
            if (device == null && mFallbackToHfp) {
                fallbackDevice = mHeadsetDevice;
            }
            when(mHeadsetService.getFallbackDevice()).thenReturn(fallbackDevice);
            return true;
        });
        when(mHearingAidService.setActiveDevice(any())).thenReturn(true);
        when(mLeAudioService.setActiveDevice(any())).thenReturn(true);
        when(mDatabaseManager.getMostRecentlyConnectedDevicesInList(any())).thenAnswer(
                invocation -> {
                    List<BluetoothDevice> devices = invocation.getArgument(0);
                    if (devices == null || devices.size() == 0) {
                        return null;
                    } else if (mMostRecentDevice != null && devices.contains(mMostRecentDevice)) {
                        return mMostRecentDevice;
                    } else if (devices.contains(mLeHearingAidDevice)) {
                        return mLeHearingAidDevice;
                    } else if (devices.contains(mHearingAidDevice)) {
                        return mHearingAidDevice;
                    } else {
                        return devices.get(0);
                    }
                }
        );
    }

    @After
@@ -243,7 +282,6 @@ public class ActiveDeviceManagerTest {
        Assert.assertEquals(mHeadsetDevice, mActiveDeviceManager.getHfpActiveDevice());
    }


    /**
     * Two Headsets are connected and the current active is then disconnected.
     * Should then set active device to fallback device.
@@ -481,23 +519,18 @@ public class ActiveDeviceManagerTest {
     */
    @Test
    public void leAudioAndA2dpConnectedThenA2dpDisconnected_fallbackToLeAudio() {
        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);

        leAudioConnected(mLeAudioDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mLeAudioDevice);

        a2dpConnected(mA2dpDevice);
        verify(mA2dpService, timeout(TIMEOUT_MS)).setActiveDevice(mA2dpDevice);

        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);
        when(mDatabaseManager.getMostRecentlyConnectedDevicesInList(any())).thenAnswer(
                invocation -> {
                    List<BluetoothDevice> devices = invocation.getArgument(0);
                    return (devices != null && devices.contains(mLeAudioDevice))
                            ? mLeAudioDevice : null;
                }
        );
        Mockito.clearInvocations(mLeAudioService);
        a2dpDisconnected(mA2dpDevice);
        verify(mA2dpService, timeout(TIMEOUT_MS).atLeast(1)).setActiveDevice(isNull());
        verify(mLeAudioService, timeout(TIMEOUT_MS).times(2)).setActiveDevice(mLeAudioDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mLeAudioDevice);
    }

    /**
@@ -506,23 +539,18 @@ public class ActiveDeviceManagerTest {
     */
    @Test
    public void a2dpAndLeAudioConnectedThenLeAudioDisconnected_fallbackToA2dp() {
        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);

        a2dpConnected(mA2dpDevice);
        verify(mA2dpService, timeout(TIMEOUT_MS)).setActiveDevice(mA2dpDevice);

        leAudioConnected(mLeAudioDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mLeAudioDevice);

        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);
        when(mA2dpService.getFallbackDevice()).thenReturn(mA2dpDevice);
        when(mDatabaseManager.getMostRecentlyConnectedDevicesInList(any())).thenAnswer(
                invocation -> {
                    List<BluetoothDevice> devices = invocation.getArgument(0);
                    return (devices != null && devices.contains(mA2dpDevice)) ? mA2dpDevice : null;
                }
        );
        Mockito.clearInvocations(mA2dpService);
        leAudioDisconnected(mLeAudioDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS).atLeast(1)).setActiveDevice(isNull());
        verify(mA2dpService, timeout(TIMEOUT_MS).times(2)).setActiveDevice(mA2dpDevice);
        verify(mA2dpService, timeout(TIMEOUT_MS)).setActiveDevice(mA2dpDevice);
    }

    /**
@@ -547,6 +575,8 @@ public class ActiveDeviceManagerTest {
     */
    @Test
    public void activeDeviceDisconnected_fallbackToHearingAid() {
        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);

        hearingAidConnected(mHearingAidDevice);
        verify(mHearingAidService, timeout(TIMEOUT_MS)).setActiveDevice(mHearingAidDevice);

@@ -560,23 +590,6 @@ public class ActiveDeviceManagerTest {
        verify(mLeAudioService, never()).setActiveDevice(mLeAudioDevice);
        verify(mA2dpService, never()).setActiveDevice(mA2dpDevice);

        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);
        when(mDatabaseManager.getMostRecentlyConnectedDevicesInList(any())).thenAnswer(
                invocation -> {
                    List<BluetoothDevice> devices = invocation.getArgument(0);
                    if (devices == null) {
                        return null;
                    } else if (devices.contains(mA2dpDevice)) {
                        return mA2dpDevice;
                    } else if (devices.contains(mLeAudioDevice)) {
                        return mLeAudioDevice;
                    } else if (devices.contains(mHearingAidDevice)) {
                        return mHearingAidDevice;
                    } else {
                        return devices.get(0);
                    }
                }
        );
        a2dpDisconnected(mA2dpDevice);
        verify(mA2dpService, timeout(TIMEOUT_MS).atLeast(1)).setActiveDevice(isNull());
        verify(mHearingAidService, timeout(TIMEOUT_MS).times(2))
@@ -587,9 +600,13 @@ public class ActiveDeviceManagerTest {
     * One LE Hearing Aid is connected.
     */
    @Test
    public void onlyLeHearingAIdConnected_setHeadsetActive() {
        leAudioConnected(mLeAudioDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mLeAudioDevice);
    public void onlyLeHearingAidConnected_setLeAudioActive() {
        leHearingAidConnected(mLeHearingAidDevice);
        TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper());
        verify(mLeAudioService, never()).setActiveDevice(mLeHearingAidDevice);

        leAudioConnected(mLeHearingAidDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mLeHearingAidDevice);
    }

    /**
@@ -598,14 +615,45 @@ public class ActiveDeviceManagerTest {
     */
    @Test
    public void leAudioConnectedAfterLeHearingAid_setLeAudioActiveShouldNotBeCalled() {
        leHearingAidConnected(mSecondaryAudioDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mSecondaryAudioDevice);
        leHearingAidConnected(mLeHearingAidDevice);
        leAudioConnected(mLeHearingAidDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mLeHearingAidDevice);

        leAudioConnected(mLeAudioDevice);
        TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper());
        verify(mLeAudioService, never()).setActiveDevice(mLeAudioDevice);
    }

    /**
     * Test connect/disconnect of devices.
     * Hearing Aid, LE Hearing Aid, A2DP connected, then LE hearing Aid and hearing aid
     * disconnected.
     */
    @Test
    public void activeDeviceChange_withHearingAidLeHearingAidAndA2dpDevices() {
        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);

        hearingAidConnected(mHearingAidDevice);
        verify(mHearingAidService, timeout(TIMEOUT_MS)).setActiveDevice(mHearingAidDevice);

        leHearingAidConnected(mLeHearingAidDevice);
        leAudioConnected(mLeHearingAidDevice);
        verify(mLeAudioService, timeout(TIMEOUT_MS)).setActiveDevice(mLeHearingAidDevice);

        a2dpConnected(mA2dpDevice);
        TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper());
        verify(mA2dpService, never()).setActiveDevice(mA2dpDevice);

        Mockito.clearInvocations(mHearingAidService, mA2dpService);
        leHearingAidDisconnected(mLeHearingAidDevice);
        leAudioDisconnected(mLeHearingAidDevice);
        verify(mHearingAidService, timeout(TIMEOUT_MS)).setActiveDevice(mHearingAidDevice);
        verify(mA2dpService, timeout(TIMEOUT_MS)).setActiveDevice(isNull());

        hearingAidDisconnected(mHearingAidDevice);
        verify(mA2dpService, timeout(TIMEOUT_MS)).setActiveDevice(mA2dpDevice);
    }

    /**
     * A wired audio device is connected. Then all active devices are set to null.
     */
@@ -631,6 +679,8 @@ public class ActiveDeviceManagerTest {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_DISCONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
        mFallbackToA2dp = true;
    }

    /**
@@ -642,6 +692,7 @@ public class ActiveDeviceManagerTest {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_DISCONNECTED);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mFallbackToA2dp = false;
    }

    /**
@@ -651,6 +702,7 @@ public class ActiveDeviceManagerTest {
        Intent intent = new Intent(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }

    /**
@@ -662,6 +714,8 @@ public class ActiveDeviceManagerTest {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_DISCONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
        mFallbackToHfp = true;
    }

    /**
@@ -673,6 +727,7 @@ public class ActiveDeviceManagerTest {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_CONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_DISCONNECTED);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mFallbackToHfp = false;
    }

    /**
@@ -682,6 +737,7 @@ public class ActiveDeviceManagerTest {
        Intent intent = new Intent(BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }

    /**
@@ -693,6 +749,7 @@ public class ActiveDeviceManagerTest {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_DISCONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }

    /**
@@ -713,6 +770,7 @@ public class ActiveDeviceManagerTest {
        Intent intent = new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }

    /**
@@ -724,6 +782,7 @@ public class ActiveDeviceManagerTest {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_DISCONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }

    /**
@@ -744,6 +803,7 @@ public class ActiveDeviceManagerTest {
        Intent intent = new Intent(BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }

    /**
@@ -755,6 +815,7 @@ public class ActiveDeviceManagerTest {
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, BluetoothProfile.STATE_DISCONNECTED);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_CONNECTED);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }

    /**
@@ -775,5 +836,6 @@ public class ActiveDeviceManagerTest {
        Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_DEVICE_AVAILABLE);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        mActiveDeviceManager.getBroadcastReceiver().onReceive(mContext, intent);
        mMostRecentDevice = device;
    }
}