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

Commit 9301ca97 authored by Andrew Lee's avatar Andrew Lee
Browse files

Enable proximity sensor onPause.

+ When using speakerphone, add flag to keep the screen on.

Bug: 22047261
Change-Id: I4e28ab526218b4cc1f53f2ec98c4749f24ac95af
parent 0feab022
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.PowerManager;
import android.provider.VoicemailContract;
import android.util.Log;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.SeekBar;

import com.android.dialer.R;
@@ -285,6 +286,7 @@ public class VoicemailPlaybackPresenter
            mMediaPlayer = null;
        }

        mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
        disableProximitySensor(false /* waitForFarState */);
    }

@@ -578,8 +580,12 @@ public class VoicemailPlaybackPresenter

        Log.d(TAG, "Resumed playback at " + mPosition + ".");
        mView.onPlaybackStarted(mDuration.get(), getScheduledExecutorServiceInstance());
        if (isSpeakerphoneOn()) {
            mActivity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {
            enableProximitySensor();
        }
    }

    /**
     * Pauses voicemail playback at the current position. Null-op if already paused.
@@ -600,6 +606,8 @@ public class VoicemailPlaybackPresenter

        mView.onPlaybackStopped();
        mAudioManager.abandonAudioFocus(this);

        mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
        disableProximitySensor(true /* waitForFarState */);
    }

@@ -621,11 +629,8 @@ public class VoicemailPlaybackPresenter
    }

    private void enableProximitySensor() {
        // Disable until proximity sensor behavior in onPause is fixed: b/21932251.

        /*
        if (mProximityWakeLock == null || isSpeakerphoneOn() || !mIsPrepared
                || !mMediaPlayer.isPlaying()) {
                || mMediaPlayer == null || !mMediaPlayer.isPlaying()) {
            return;
        }

@@ -635,7 +640,6 @@ public class VoicemailPlaybackPresenter
        } else {
            Log.i(TAG, "Proximity wake lock already acquired");
        }
        */
    }

    private void disableProximitySensor(boolean waitForFarState) {
@@ -653,10 +657,15 @@ public class VoicemailPlaybackPresenter

    public void setSpeakerphoneOn(boolean on) {
        mAudioManager.setSpeakerphoneOn(on);

        if (on) {
            disableProximitySensor(false /* waitForFarState */);
            if (mIsPrepared && mMediaPlayer != null && mMediaPlayer.isPlaying()) {
                mActivity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
            }
        } else {
            enableProximitySensor();
            mActivity.getWindow().clearFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    }