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

Commit 10274f7f authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Auto downgrade video calls when phone account doesn't support video.

When adding calls to Telecom, ensure that incoming and outgoing video
calls are auto-downgraded to audio-only when the phone account does not
support video.

Bug: 27616192
Change-Id: I7fd15718af414903ab312f9aa9f20f8102a38f11
parent 6df997ac
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1143,7 +1143,8 @@ public class Call implements CreateConnectionResponse {
        setConnectionCapabilities(connection.getConnectionCapabilities());
        setConnectionProperties(connection.getConnectionProperties());
        setVideoProvider(connection.getVideoProvider());
        setVideoState(connection.getVideoState());
        setVideoState(mCallsManager.getCheckedVideoState(connection.getVideoState(),
                connection.getPhoneAccount()));
        setRingbackRequested(connection.isRingbackRequested());
        setIsVoipAudioMode(connection.getIsVoipAudioMode());
        setStatusHints(connection.getStatusHints());
+35 −3
Original line number Diff line number Diff line
@@ -802,11 +802,13 @@ public class CallsManager extends Call.ListenerBase

            // If this is an emergency video call, we need to check if the phone account supports
            // emergency video calling.
            if (call.isEmergencyCall() && VideoProfile.isVideo(videoState)) {
            // Also, ensure we don't try to place an outgoing call with video if video is not
            // supported.
            if (VideoProfile.isVideo(videoState)) {
                PhoneAccount account =
                        mPhoneAccountRegistrar.getPhoneAccount(phoneAccountHandle, initiatingUser);

                if (account != null &&
                if (call.isEmergencyCall() && account != null &&
                        !account.hasCapabilities(PhoneAccount.CAPABILITY_EMERGENCY_VIDEO_CALLING)) {
                    // Phone account doesn't support emergency video calling, so fallback to
                    // audio-only now to prevent the InCall UI from setting up video surfaces
@@ -814,6 +816,12 @@ public class CallsManager extends Call.ListenerBase
                    Log.i(this, "startOutgoingCall - emergency video calls not supported; " +
                            "falling back to audio-only");
                    videoState = VideoProfile.STATE_AUDIO_ONLY;
                } else if (account != null &&
                        !account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) {
                    // Phone account doesn't support video calling, so fallback to audio-only.
                    Log.i(this, "startOutgoingCall - video calls not supported; fallback to " +
                            "audio-only.");
                    videoState = VideoProfile.STATE_AUDIO_ONLY;
                }
            }

@@ -1631,7 +1639,8 @@ public class CallsManager extends Call.ListenerBase
                "new conference call");
        call.setConnectionCapabilities(parcelableConference.getConnectionCapabilities());
        call.setConnectionProperties(parcelableConference.getConnectionProperties());
        call.setVideoState(parcelableConference.getVideoState());
        call.setVideoState(
                getCheckedVideoState(parcelableConference.getVideoState(), phoneAccount));
        call.setVideoProvider(parcelableConference.getVideoProvider());
        call.setStatusHints(parcelableConference.getStatusHints());
        call.putExtras(Call.SOURCE_CONNECTION_SERVICE, parcelableConference.getExtras());
@@ -2154,4 +2163,27 @@ public class CallsManager extends Call.ListenerBase

      call.setIntentExtras(extras);
    }

    /**
     * Given a video state and phone account handle, converts the passed video state to
     * {@link VideoProfile#STATE_AUDIO_ONLY} if the phone account does not support video calling.
     *
     * Used to ensure that calls added by a connection service don't try to use video calling if
     * they have not advertised that they can.
     *
     * @param videoState The video state.
     * @param phoneAccountHandle The phone account handle.
     * @return {@link VideoProfile#STATE_AUDIO_ONLY} if the phone account does not support video,
     *      or the original videoState otherwise.
     */
    public int getCheckedVideoState(int videoState, PhoneAccountHandle phoneAccountHandle) {
        if (VideoProfile.isVideo(videoState) && phoneAccountHandle != null) {
            PhoneAccount account = mPhoneAccountRegistrar.getPhoneAccountUnchecked(
                    phoneAccountHandle);
            if (!account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) {
                return VideoProfile.STATE_AUDIO_ONLY;
            }
        }
        return videoState;
    }
}