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

Commit ad9b792d authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Attempt to create earpiece route on wired headset disconnect.

In cases where the CallAudioRouteController is initialized with a wired headset plugged in, we will skip creating the earpiece route. So when we do disconnect the headset, the current logic tries to retrieve an existing earpiece audio route mapping which doesn't exist. As a result, we end up not supporting earpiece during audio routing. We should attempt to create the route if it doesn't exist.

Bug: 388206422
Change-Id: Ifebb0b7f7dac1abeacb8ea8f0b385f1fd9d9c346
Flag: EXEMPT bugfix
Test: Manual
parent 8f3a7152
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -629,10 +629,25 @@ public class CallAudioRouteController implements CallAudioRouteAdapter {
            updateAvailableRoutes(wiredHeadsetRoute, false);
            mEarpieceWiredRoute = null;
        }
        AudioRoute earpieceRoute = mTypeRoutes.get(AudioRoute.TYPE_EARPIECE);
        AudioRoute earpieceRoute = null;
        try {
            earpieceRoute = mTypeRoutes.get(AudioRoute.TYPE_EARPIECE) == null
                ? mAudioRouteFactory.create(AudioRoute.TYPE_EARPIECE, null,
                    mAudioManager)
                : mTypeRoutes.get(AudioRoute.TYPE_EARPIECE);
        } catch (IllegalArgumentException e) {
            if (mFeatureFlags.telecomMetricsSupport()) {
                mMetricsController.getErrorStats().log(ErrorStats.SUB_CALL_AUDIO,
                        ErrorStats.ERROR_EXTERNAL_EXCEPTION);
            }
            Log.e(this, e, "Can't find available audio device info for route type:"
                    + AudioRoute.DEVICE_TYPE_STRINGS.get(AudioRoute.TYPE_EARPIECE));
        }
        if (earpieceRoute != null) {
            updateAvailableRoutes(earpieceRoute, true);
            mEarpieceWiredRoute = earpieceRoute;
            // In the case that the route was never created, ensure that we update the map.
            mTypeRoutes.putIfAbsent(AudioRoute.TYPE_EARPIECE, mEarpieceWiredRoute);
        }
        onAvailableRoutesChanged();

+22 −0
Original line number Diff line number Diff line
@@ -238,6 +238,28 @@ public class CallAudioRouteControllerTest extends TelecomTestCase {
        assertTrue(mController.getAvailableRoutes().contains(mSpeakerRoute));
    }

    @SmallTest
    @Test
    public void testEarpieceCreatedWhenWiredHeadsetDisconnected() {
        // Initialize the controller with the wired headset.
        AudioRoute wiredHeadsetRoute = new AudioRoute(AudioRoute.TYPE_WIRED, null, null);
        when(mWiredHeadsetManager.isPluggedIn()).thenReturn(true);
        mController.initialize();
        assertEquals(wiredHeadsetRoute, mController.getCurrentRoute());
        // Verify that the earpiece route isn't created.
        assertFalse(mController.getAvailableRoutes().contains(mEarpieceRoute));
        // When we disconnect the wired headset, we should create the earpiece route if it hasn't
        // already been created.
        mController.sendMessageWithSessionInfo(DISCONNECT_WIRED_HEADSET);
        CallAudioState expectedState = new CallAudioState(false, CallAudioState.ROUTE_EARPIECE,
                CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER, null,
                new HashSet<>());
        verify(mCallsManager, timeout(TEST_TIMEOUT)).onCallAudioStateChanged(
                any(CallAudioState.class), eq(expectedState));
        // Verify that the earpiece route is created.
        assertTrue(mController.getAvailableRoutes().contains(mEarpieceRoute));
    }

    @SmallTest
    @Test
    public void testNormalCallRouteToEarpiece() {