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

Commit 01bfb9f0 authored by Dan Pasanen's avatar Dan Pasanen Committed by Ethan Chen
Browse files

ProximitySensorManager: disable TapToWake while we have a prox wakelock

* When the proximity sensor has grabbed a wakelock, the screen is turned
  off (in-call). On devices with TapToWake, the kernel sees that the
  screen is off and will then allow for a TapToWake action to fire in the
  hopes of turning the device on by simulating a power button press. This
  causes the device to go to sleep since it's not actually off at that
  moment. On a device that can't wake via proximity sensor, the only way
  to recover from this is to use the power button.

Change-Id: I246f38b41caea6c7d7ac50293c7012120499643b
parent dbf5ca0f
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -3,7 +3,10 @@ LOCAL_PATH:= $(call my-dir)
# Build the Telecom service.
include $(CLEAR_VARS)

LOCAL_JAVA_LIBRARIES := telephony-common
LOCAL_JAVA_LIBRARIES := \
        org.cyanogenmod.hardware \
        telephony-common

LOCAL_STATIC_JAVA_LIBRARIES := \
        guava \

+2 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@
            android:allowBackup="false"
            android:supportsRtl="true">

        <uses-library android:name="org.cyanogenmod.hardware" android:required="false" />

        <!-- CALL vs CALL_PRIVILEGED vs CALL_EMERGENCY
             We have three different intents through which a call can be initiated each with its
             own behavior.
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.telecom;

import android.content.Context;
import android.os.PowerManager;
import org.cyanogenmod.hardware.TapToWake;

/**
 * This class manages the proximity sensor and allows callers to turn it on and off.
@@ -63,6 +64,9 @@ public class ProximitySensorManager extends CallsManagerListenerBase {
        if (!mProximityWakeLock.isHeld()) {
            Log.i(this, "Acquiring proximity wake lock");
            mProximityWakeLock.acquire();
            if (isTapToWakeSupported() && TapToWake.isEnabled()) {
                TapToWake.setEnabled(false);
            }
        } else {
            Log.i(this, "Proximity wake lock already acquired");
        }
@@ -77,6 +81,9 @@ public class ProximitySensorManager extends CallsManagerListenerBase {
            return;
        }
        if (mProximityWakeLock.isHeld()) {
            if (isTapToWakeSupported() && !TapToWake.isEnabled()) {
                TapToWake.setEnabled(true);
            }
            Log.i(this, "Releasing proximity wake lock");
            int flags =
                (screenOnImmediately ? 0 : PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
@@ -85,4 +92,13 @@ public class ProximitySensorManager extends CallsManagerListenerBase {
            Log.i(this, "Proximity wake lock already released");
        }
    }

    private static boolean isTapToWakeSupported() {
        try {
            return TapToWake.isSupported();
        } catch (NoClassDefFoundError e) {
            // Hardware abstraction framework not installed
            return false;
        }
    }
}