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

Commit 9696c218 authored by Hall Liu's avatar Hall Liu
Browse files

Switch to speakerphone when upgrading to video

When an audio-only call gets upgraded to a video call, switch to
speakerphone if the call would have been started in speakerphone had it
been a video call from the beginning (i.e. if there's no headset or
bluetooth connected and config options support it)

Change-Id: I4b8eb1c0f21753a8878f72d9279335a946c9f5a9
Fixes: 29563103
parent eeeb2a10
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ public class Call implements CreateConnectionResponse {
        void onExtrasRemoved(Call c, int source, List<String> keys);
        void onHandleChanged(Call call);
        void onCallerDisplayNameChanged(Call call);
        void onVideoStateChanged(Call call);
        void onVideoStateChanged(Call call, int previousVideoState, int newVideoState);
        void onTargetPhoneAccountChanged(Call call);
        void onConnectionManagerPhoneAccountChanged(Call call);
        void onPhoneAccountChanged(Call call);
@@ -160,7 +160,7 @@ public class Call implements CreateConnectionResponse {
        @Override
        public void onCallerDisplayNameChanged(Call call) {}
        @Override
        public void onVideoStateChanged(Call call) {}
        public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {}
        @Override
        public void onTargetPhoneAccountChanged(Call call) {}
        @Override
@@ -1895,11 +1895,14 @@ public class Call implements CreateConnectionResponse {
            mVideoStateHistory = mVideoStateHistory | videoState;
        }

        int previousVideoState = mVideoState;
        mVideoState = videoState;
        if (mVideoState != previousVideoState) {
            Log.event(this, Log.Events.VIDEO_STATE_CHANGED,
                    VideoProfile.videoStateToString(videoState));
        mVideoState = videoState;
            for (Listener l : mListeners) {
            l.onVideoStateChanged(this);
                l.onVideoStateChanged(this, previousVideoState, mVideoState);
            }
        }
    }

+19 −0
Original line number Diff line number Diff line
@@ -314,6 +314,25 @@ public class CallAudioManager extends CallsManagerListenerBase {
                CallAudioRouteStateMachine.UPDATE_SYSTEM_AUDIO_ROUTE);
    }

    @Override
    public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {
        if (call != getForegroundCall()) {
            Log.d(LOG_TAG, "Ignoring video state change from %s to %s for call %s -- not " +
                    "foreground.", VideoProfile.videoStateToString(previousVideoState),
                    VideoProfile.videoStateToString(newVideoState), call.getId());
            return;
        }

        if (!VideoProfile.isVideo(previousVideoState) &&
                mCallsManager.isSpeakerphoneAutoEnabledForVideoCalls(newVideoState)) {
            Log.d(LOG_TAG, "Switching to speaker because call %s transitioned video state from %s" +
                    " to %s", call.getId(), VideoProfile.videoStateToString(previousVideoState),
                    VideoProfile.videoStateToString(newVideoState));
            mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                    CallAudioRouteStateMachine.SWITCH_SPEAKER);
        }
    }

    public CallAudioState getCallAudioState() {
        return mCallAudioRouteStateMachine.getCurrentCallAudioState();
    }
+6 −6
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ public class CallsManager extends Call.ListenerBase
        void onRingbackRequested(Call call, boolean ringback);
        void onIsConferencedChanged(Call call);
        void onIsVoipAudioModeChanged(Call call);
        void onVideoStateChanged(Call call);
        void onVideoStateChanged(Call call, int previousVideoState, int newVideoState);
        void onCanAddCallChanged(boolean canAddCall);
        void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile);
        void onHoldToneRequested(Call call);
@@ -493,9 +493,9 @@ public class CallsManager extends Call.ListenerBase
    }

    @Override
    public void onVideoStateChanged(Call call) {
    public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {
        for (CallsManagerListener listener : mListeners) {
            listener.onVideoStateChanged(call);
            listener.onVideoStateChanged(call, previousVideoState, newVideoState);
        }
    }

@@ -924,7 +924,7 @@ public class CallsManager extends Call.ListenerBase
        final boolean useSpeakerWhenDocked = mContext.getResources().getBoolean(
                R.bool.use_speaker_when_docked);
        final boolean useSpeakerForDock = isSpeakerphoneEnabledForDock();
        final boolean useSpeakerForVideoCall = isSpeakerphoneAutoEnabled(videoState);
        final boolean useSpeakerForVideoCall = isSpeakerphoneAutoEnabledForVideoCalls(videoState);

        // Auto-enable speakerphone if the originating intent specified to do so, if the call
        // is a video call, of if using speaker when docked
@@ -1023,7 +1023,7 @@ public class CallsManager extends Call.ListenerBase
            // We do not update the UI until we get confirmation of the answer() through
            // {@link #markCallAsActive}.
            call.answer(videoState);
            if (isSpeakerphoneAutoEnabled(videoState)) {
            if (isSpeakerphoneAutoEnabledForVideoCalls(videoState)) {
                call.setStartWithSpeakerphoneOn(true);
            }
        }
@@ -1037,7 +1037,7 @@ public class CallsManager extends Call.ListenerBase
     * @param videoState The video state of the call.
     * @return {@code true} if the speakerphone should be enabled.
     */
    private boolean isSpeakerphoneAutoEnabled(int videoState) {
    public boolean isSpeakerphoneAutoEnabledForVideoCalls(int videoState) {
        return VideoProfile.isVideo(videoState) &&
            !mWiredHeadsetManager.isPluggedIn() &&
            !mBluetoothManager.isBluetoothAvailable() &&
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class CallsManagerListenerBase implements CallsManager.CallsManagerListen
    }

    @Override
    public void onVideoStateChanged(Call call) {
    public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -546,7 +546,7 @@ public final class InCallController extends CallsManagerListenerBase {
        }

        @Override
        public void onVideoStateChanged(Call call) {
        public void onVideoStateChanged(Call call, int previousVideoState, int newVideoState) {
            updateCall(call);
        }