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

Commit 7c2e0ac9 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Fix issues with video auto-fullscreen mode.

There were a few issues with the auto-fullscreen mode code which is present in
video calls.
1. If the Incall UI is backgrounded, the auto-fullscreen mode code would still
trigger and put the user into fullscreen mode when they return to the InCall
UI.
2. If the user is already in a video call and the remote party enables their
camera, the auto fullscreen mode code would trigger and enable fullscreen mode.
Ultimately we only want to go into fullscreen mode if we are entering a video
call from a non-video state.
3. It is possible for the call to cease to be a video call by the time the auto
fullscreen code triggers, meaning that an audio only call would go into
fullscreen mode:

Change-Id: I338a9ba4bb8d171752dcb38c16363bf0ded701af
CL: 120864913
Bug: 28093622
parent 9bb027e7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -499,6 +499,7 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter,
    public void onPause() {
        super.onPause();
        Log.d(this, "onPause:");
        getPresenter().cancelAutoFullScreen();
    }

    @Override
@@ -549,6 +550,7 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter,
     * Hides and shows the incoming video view and changes the outgoing video view's state based on
     * whether outgoing view is enabled or not.
     */
    @Override
    public void showVideoViews(boolean previewPaused, boolean showIncoming) {
        inflateVideoUi(true);

@@ -567,6 +569,7 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter,
    /**
     * Hide all video views.
     */
    @Override
    public void hideVideoUi() {
        inflateVideoUi(false);
    }
+26 −22
Original line number Diff line number Diff line
@@ -81,7 +81,9 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
    private Runnable mAutoFullscreenRunnable =  new Runnable() {
        @Override
        public void run() {
            if (mAutoFullScreenPending && !InCallPresenter.getInstance().isDialpadVisible()) {
            if (mAutoFullScreenPending && !InCallPresenter.getInstance().isDialpadVisible()
                    && mIsVideoMode) {

                Log.v(this, "Automatically entering fullscreen mode.");
                InCallPresenter.getInstance().setFullScreen(true);
                mAutoFullScreenPending = false;
@@ -258,6 +260,8 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
            return;
        }

        cancelAutoFullScreen();

        InCallPresenter.getInstance().removeListener(this);
        InCallPresenter.getInstance().removeDetailsListener(this);
        InCallPresenter.getInstance().removeIncomingCallListener(this);
@@ -495,7 +499,7 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
        updateCameraSelection(call);

        if (isVideoCall) {
            enterVideoMode(call);
            adjustVideoMode(call);
        } else if (isVideoMode()) {
            exitVideoMode();
        }
@@ -555,7 +559,7 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
            Log.d(this, "onPrimaryCallChanged: Entering video mode...");

            updateCameraSelection(newPrimaryCall);
            enterVideoMode(newPrimaryCall);
            adjustVideoMode(newPrimaryCall);
        }
    }

@@ -630,7 +634,7 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
     * Handles a change to the video call. Sets the surfaces on the previous call to null and sets
     * the surfaces on the new video call accordingly.
     *
     * @param videoCall The new video call.
     * @param call The new video call.
     */
    private void changeVideoCall(Call call) {
        final VideoCall videoCall = call.getTelecomCall().getVideoCall();
@@ -651,13 +655,13 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
        }

        if (VideoUtils.isVideoCall(call) && hasChanged) {
            enterVideoMode(call);
            adjustVideoMode(call);
        }
    }

    private static boolean isCameraRequired(int videoState) {
        return VideoProfile.isBidirectional(videoState) ||
                VideoProfile.isTransmissionEnabled(videoState);
        return VideoProfile.isBidirectional(videoState)
                || VideoProfile.isTransmissionEnabled(videoState);
    }

    private boolean isCameraRequired() {
@@ -665,14 +669,16 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
    }

    /**
     * Enters video mode by showing the video surfaces and making other adjustments (eg. audio).
     * Adjusts the current video mode by setting up the preview and display surfaces as necessary.
     * Expected to be called whenever the video state associated with a call changes (e.g. a user
     * turns their camera on or off) to ensure the correct surfaces are shown/hidden.
     * TODO(vt): Need to adjust size and orientation of preview surface here.
     */
    private void enterVideoMode(Call call) {
    private void adjustVideoMode(Call call) {
        VideoCall videoCall = call.getVideoCall();
        int newVideoState = call.getVideoState();

        Log.d(this, "enterVideoMode videoCall= " + videoCall + " videoState: " + newVideoState);
        Log.d(this, "adjustVideoMode videoCall= " + videoCall + " videoState: " + newVideoState);
        VideoCallUi ui = getUi();
        if (ui == null) {
            Log.e(this, "Error VideoCallUi is null so returning");
@@ -692,16 +698,15 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
            videoCall.setDeviceOrientation(mDeviceOrientation);
            enableCamera(videoCall, isCameraRequired(newVideoState));
        }
        int previousVideoState = mCurrentVideoState;
        mCurrentVideoState = newVideoState;

        mIsVideoMode = true;

        // adjustVideoMode may be called if we are already in a 1-way video state.  In this case
        // we do not want to trigger auto-fullscreen mode.
        if (!VideoUtils.isVideoCall(previousVideoState) && VideoUtils.isVideoCall(newVideoState)) {
            maybeAutoEnterFullscreen(call);
        }

    private static boolean isSpeakerEnabledForVideoCalls() {
        // TODO: Make this a carrier configurable setting. For now this is always true. b/20090407
        return true;
    }

    private void enableCamera(VideoCall videoCall, boolean isCameraRequired) {
@@ -1068,6 +1073,8 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
     * 2. Call is not active
     * 3. Call is not video call
     * 4. Already in fullscreen mode
     * 5. The current video state is not bi-directional (if the remote party stops transmitting,
     *    the user's contact photo would dominate in fullscreen mode).
     *
     * @param call The current call.
     */
@@ -1079,7 +1086,8 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
        if (call == null || (
                call != null && (call.getState() != Call.State.ACTIVE ||
                        !VideoUtils.isVideoCall(call)) ||
                        InCallPresenter.getInstance().isFullscreen())) {
                        InCallPresenter.getInstance().isFullscreen()) ||
                        !VideoUtils.isBidirectionalVideoCall(call)) {
            // Ensure any previously scheduled attempt to enter fullscreen is cancelled.
            cancelAutoFullScreen();
            return;
@@ -1106,10 +1114,6 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
        mAutoFullScreenPending = false;
    }

    private static boolean isAudioRouteEnabled(int audioRoute, int audioRouteMask) {
        return ((audioRoute & audioRouteMask) != 0);
    }

    private static void updateCameraSelection(Call call) {
        Log.d(TAG, "updateCameraSelection: call=" + call);
        Log.d(TAG, "updateCameraSelection: call=" + toSimpleString(call));