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

Commit 32d4117c authored by Santos Cordon's avatar Santos Cordon
Browse files

Unplugging headset shouldn't stop Bluetooth.

When the headset was unplugged, we changes audio to earpiece even if the
audio was currently going through Bluetooth.

This change makes it so that we keep the current routing scheme when a
headset is unplugged unless the audio was actually going through the
wired earpiece.  In that case, we go to either earpiece or speaker
depending on whether speaker was on prior to going to the wired headset.

Bug: 18823515
Change-Id: Ib12d669c2bcd8f4c8a95d450af6bcc28f15122f3
parent 5b069901
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -131,16 +131,35 @@ final class CallAudioManager extends CallsManagerListenerBase
            return;
        }

        int newRoute = AudioState.ROUTE_EARPIECE;
        boolean isCurrentlyWiredHeadset = mAudioState.getRoute() == AudioState.ROUTE_WIRED_HEADSET;

        int newRoute = mAudioState.getRoute();  // start out with existing route
        if (newIsPluggedIn) {
            newRoute = AudioState.ROUTE_WIRED_HEADSET;
        } else if (mWasSpeakerOn) {
        } else if (isCurrentlyWiredHeadset) {
            Call call = getForegroundCall();
            if (call != null && call.isAlive()) {
                // Restore the speaker state.
            boolean hasLiveCall = call != null && call.isAlive();

            if (hasLiveCall) {
                // In order of preference when a wireless headset is unplugged.
                if (mWasSpeakerOn) {
                    newRoute = AudioState.ROUTE_SPEAKER;
                } else {
                    newRoute = AudioState.ROUTE_EARPIECE;
                }

                // We don't automatically connect to bluetooth when user unplugs their wired headset
                // and they were previously using the wired. Wired and earpiece are effectively the
                // same choice in that they replace each other as an option when wired headsets
                // are plugged in and out. This means that keeping it earpiece is a bit more
                // consistent with the status quo.  Bluetooth also has more danger associated with
                // choosing it in the wrong curcumstance because bluetooth devices can be
                // semi-public (like in a very-occupied car) where earpiece doesn't carry that risk.
            }
        }

        // We need to call this every time even if we do not change the route because the supported
        // routes changed either to include or not include WIRED_HEADSET.
        setSystemAudioState(mAudioState.isMuted(), newRoute, calculateSupportedRoutes());
    }