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

Unverified Commit 6dd85e90 authored by Hikari-no-Tenshi's avatar Hikari-no-Tenshi Committed by Michael Bestas
Browse files

Let InCallUI handle proximity sensor for incoming calls [2/2]

Change-Id: I939a70ac09a8868e128a7ecc982a570993cb86c7

Dialer: Fix proximity on wake handling

*) http://review.cyanogenmod.org/#/c/167122/ introduced an issue
   where the screen would never turn off during a call if the system
   proximity on wake setting was turned off.

*) Fix this by making sure the proximity_on_wake setting is only
   used when we have an incoming call.

Change-Id: I49f8759112c4f9bfe41325dd3329eb2d1902231f
parent 5dbc8bea
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.res.Configuration;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.os.PowerManager;
import cyanogenmod.providers.CMSettings;
import android.telecom.CallAudioState;
import android.view.Display;

@@ -50,8 +51,10 @@ public class ProximitySensor implements AccelerometerListener.OrientationListene
    private final ProximityDisplayListener mDisplayListener;
    private int mOrientation = AccelerometerListener.ORIENTATION_UNKNOWN;
    private boolean mUiShowing = false;
    private boolean mHasIncomingCall = false;
    private boolean mIsPhoneOffhook = false;
    private boolean mDialpadVisible;
    private Context mContext;

    // True if the keyboard is currently *not* hidden
    // Gets updated whenever there is a Configuration change
@@ -59,6 +62,7 @@ public class ProximitySensor implements AccelerometerListener.OrientationListene

    public ProximitySensor(Context context, AudioModeProvider audioModeProvider,
            AccelerometerListener accelerometerListener) {
        mContext = context;
        mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (mPowerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
            mProximityWakeLock = mPowerManager.newWakeLock(
@@ -106,6 +110,7 @@ public class ProximitySensor implements AccelerometerListener.OrientationListene
        // can also put the in-call screen in the INCALL state.
        boolean hasOngoingCall = InCallState.INCALL == newState && callList.hasLiveCall();
        boolean isOffhook = (InCallState.OUTGOING == newState) || hasOngoingCall;
        mHasIncomingCall = (InCallState.INCOMING == newState);

        if (isOffhook != mIsPhoneOffhook) {
            mIsPhoneOffhook = isOffhook;
@@ -115,6 +120,10 @@ public class ProximitySensor implements AccelerometerListener.OrientationListene

            updateProximitySensorMode();
        }

        if (mHasIncomingCall) {
            updateProximitySensorMode();
        }
    }

    @Override
@@ -257,10 +266,14 @@ public class ProximitySensor implements AccelerometerListener.OrientationListene
                    .add("aud", CallAudioState.audioRouteToString(audioMode))
                    .toString());

            if (mIsPhoneOffhook && !screenOnImmediately) {
            final boolean proximityOnWake = CMSettings.System.getInt(mContext.getContentResolver(),
                    CMSettings.System.PROXIMITY_ON_WAKE, 1) == 1;

            if ((mIsPhoneOffhook || (mHasIncomingCall && proximityOnWake))
                    && !screenOnImmediately) {
                Log.d(this, "Turning on proximity sensor");
                // Phone is in use!  Arrange for the screen to turn off
                // automatically when the sensor detects a close object.
                // Phone is idle.  We don't want any special proximity sensor
                // behavior in this case.
                turnOnProximitySensor();
            } else {
                Log.d(this, "Turning off proximity sensor");