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

Commit 315afe8f authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Revert "Call setActiveDevice(null) when disconnected"

This reverts commit 5507bace.

Reason for revert: b/262155254

Bug: 262155254
Bug: 261366232
Test: atest BluetoothInstrumentationTests
Change-Id: Ieb438152be66594df030b9c2a6975069303c5738
Merged-In: Ieb438152be66594df030b9c2a6975069303c5738
(cherry picked from commit 3f497536)
parent ac1d60c9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -287,7 +287,7 @@ class ActiveDeviceManager {
                                    setA2dpActiveDevice(null);
                                }
                            } else {
                                setA2dpActiveDevice(null);
                                mA2dpActiveDevice = null;
                            }
                        }
                    }
@@ -366,7 +366,7 @@ class ActiveDeviceManager {
                                    setHfpActiveDevice(null);
                                }
                            } else {
                                setHfpActiveDevice(null);
                                mHfpActiveDevice = null;
                            }
                        }
                    }
+8 −33
Original line number Diff line number Diff line
@@ -133,14 +133,16 @@ public class ActiveDeviceManagerTest {
        when(mLeAudioService.setActiveDevice(any(), anyBoolean())).thenReturn(true);

        when(mA2dpService.getFallbackDevice()).thenAnswer(invocation -> {
            int index = Math.max(mDeviceConnectionStack.indexOf(mA2dpDevice),
                    mDeviceConnectionStack.indexOf(mA2dpHeadsetDevice));
            return (index == -1) ? null : mDeviceConnectionStack.get(index);
            if (mDeviceConnectionStack.contains(mA2dpDevice)) {
                return mA2dpDevice;
            }
            return null;
        });
        when(mHeadsetService.getFallbackDevice()).thenAnswer(invocation -> {
            int index = Math.max(mDeviceConnectionStack.indexOf(mHeadsetDevice),
                    mDeviceConnectionStack.indexOf(mA2dpHeadsetDevice));
            return (index == -1) ? null : mDeviceConnectionStack.get(index);
            if (mDeviceConnectionStack.contains(mHeadsetDevice)) {
                return mHeadsetDevice;
            }
            return null;
        });
        when(mDatabaseManager.getMostRecentlyConnectedDevicesInList(any())).thenAnswer(
                invocation -> {
@@ -318,33 +320,6 @@ public class ActiveDeviceManagerTest {
        verify(mHeadsetService, timeout(TIMEOUT_MS)).setActiveDevice(mHeadsetDevice);
    }

    /**
     * Test setActiveDevice(null) for both A2dpService and HeadsetService are called when an
     * activated combo (A2DP + Headset) device is disconnected while in call.
     */
    @Test
    public void a2dpHeadsetDisconnected_callsSetActiveDeviceNull() {
        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL);
        // A2dpHeadset connected
        headsetConnected(mA2dpHeadsetDevice);
        a2dpConnected(mA2dpHeadsetDevice);
        // Verify activation of A2DP in media mode
        verify(mA2dpService, timeout(TIMEOUT_MS)).setActiveDevice(mA2dpHeadsetDevice, false);

        // Mode changed to call mode
        when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL);
        mAudioModeChangedListener.onModeChanged(AudioManager.MODE_IN_CALL);
        // Verify activation of HFP in call mode
        verify(mHeadsetService, timeout(TIMEOUT_MS)).setActiveDevice(mA2dpHeadsetDevice);

        // A2dpHeadset disconnected
        headsetDisconnected(mA2dpHeadsetDevice);
        a2dpDisconnected(mA2dpHeadsetDevice);
        // Verify setActiveDevice(null) called
        verify(mHeadsetService, timeout(TIMEOUT_MS)).setActiveDevice(null);
        verify(mA2dpService, timeout(TIMEOUT_MS)).setActiveDevice(null, false);
    }

    /**
     * A combo (A2DP + Headset) device is connected. Then a Hearing Aid is connected.
     */