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

Commit 2d639a46 authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Gerrit Code Review
Browse files

Merge "Call setActiveDevice(null) when disconnected"

parents 8c9e68a1 5507bace
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -287,7 +287,7 @@ class ActiveDeviceManager {
                                    setA2dpActiveDevice(null);
                                }
                            } else {
                                mA2dpActiveDevice = null;
                                setA2dpActiveDevice(null);
                            }
                        }
                    }
@@ -366,7 +366,7 @@ class ActiveDeviceManager {
                                    setHfpActiveDevice(null);
                                }
                            } else {
                                mHfpActiveDevice = null;
                                setHfpActiveDevice(null);
                            }
                        }
                    }
+33 −8
Original line number Diff line number Diff line
@@ -133,16 +133,14 @@ public class ActiveDeviceManagerTest {
        when(mLeAudioService.setActiveDevice(any(), anyBoolean())).thenReturn(true);

        when(mA2dpService.getFallbackDevice()).thenAnswer(invocation -> {
            if (mDeviceConnectionStack.contains(mA2dpDevice)) {
                return mA2dpDevice;
            }
            return null;
            int index = Math.max(mDeviceConnectionStack.indexOf(mA2dpDevice),
                    mDeviceConnectionStack.indexOf(mA2dpHeadsetDevice));
            return (index == -1) ? null : mDeviceConnectionStack.get(index);
        });
        when(mHeadsetService.getFallbackDevice()).thenAnswer(invocation -> {
            if (mDeviceConnectionStack.contains(mHeadsetDevice)) {
                return mHeadsetDevice;
            }
            return null;
            int index = Math.max(mDeviceConnectionStack.indexOf(mHeadsetDevice),
                    mDeviceConnectionStack.indexOf(mA2dpHeadsetDevice));
            return (index == -1) ? null : mDeviceConnectionStack.get(index);
        });
        when(mDatabaseManager.getMostRecentlyConnectedDevicesInList(any())).thenAnswer(
                invocation -> {
@@ -320,6 +318,33 @@ 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.
     */