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

Commit c5584cea authored by Adrian Roos's avatar Adrian Roos
Browse files

Fix anti falsing detection

The falsing detection stopped listening for touches
when the lockscreen showed without turning the screen off.

This happens e.g. when SystemUI crashes, when switching users,
when ending lock-to-task.

As a result, the falsing detection usually got stuck on a bad
value and without further touches continued preventing all input.

Bug: 27227578
Change-Id: I6717c04b0271e4d2578b88fc584b6ad46492e497
parent 1142b265
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.PowerManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.view.MotionEvent;
@@ -64,6 +65,7 @@ public class FalsingManager implements SensorEventListener {
    private boolean mBouncerOn = false;
    private boolean mSessionActive = false;
    private int mState = StatusBarState.SHADE;
    private boolean mScreenOn;

    protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
        @Override
@@ -77,6 +79,7 @@ public class FalsingManager implements SensorEventListener {
        mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
        mDataCollector = DataCollector.getInstance(mContext);
        mHumanInteractionClassifier = HumanInteractionClassifier.getInstance(mContext);
        mScreenOn = context.getSystemService(PowerManager.class).isInteractive();

        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(ENFORCE_BOUNCER), false,
@@ -98,17 +101,21 @@ public class FalsingManager implements SensorEventListener {
                ENFORCE_BOUNCER, 0);
    }

    private boolean shouldSessionBeActive() {
        return isEnabled() && mScreenOn &&
                (mState == StatusBarState.KEYGUARD || mState == StatusBarState.SHADE_LOCKED);
    }

    private boolean sessionEntrypoint() {
        if (!mSessionActive && isEnabled() &&
                (mState == StatusBarState.KEYGUARD || mState == StatusBarState.SHADE_LOCKED)) {
        if (!mSessionActive && shouldSessionBeActive()) {
            onSessionStart();
            return true;
        }
        return false;
    }

    private void sessionExitpoint() {
        if (mSessionActive) {
    private void sessionExitpoint(boolean force) {
        if (mSessionActive && (force || !shouldSessionBeActive())) {
            mSessionActive = false;
            mSensorManager.unregisterListener(this);
        }
@@ -167,15 +174,22 @@ public class FalsingManager implements SensorEventListener {

    public void setStatusBarState(int state) {
        mState = state;
        if (shouldSessionBeActive()) {
            sessionEntrypoint();
        } else {
            sessionExitpoint(false /* force */);
        }
    }

    public void onScreenTurningOn() {
        mScreenOn = true;
        if (sessionEntrypoint()) {
            mDataCollector.onScreenTurningOn();
        }
    }

    public void onScreenOnFromTouch() {
        mScreenOn = true;
        if (sessionEntrypoint()) {
            mDataCollector.onScreenOnFromTouch();
        }
@@ -183,12 +197,13 @@ public class FalsingManager implements SensorEventListener {

    public void onScreenOff() {
        mDataCollector.onScreenOff();
        sessionExitpoint();
        mScreenOn = false;
        sessionExitpoint(false /* force */);
    }

    public void onSucccessfulUnlock() {
        mDataCollector.onSucccessfulUnlock();
        sessionExitpoint();
        sessionExitpoint(true /* force */);
    }

    public void onBouncerShown() {
+1 −1
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public class HumanInteractionClassifier extends Classifier {
            return;
        }

        // If the user is dragging down the notification, he might want to drag it down
        // If the user is dragging down the notification, they might want to drag it down
        // enough to see the content, read it for a while and then lift the finger to open
        // the notification. This kind of motion scores very bad in the Classifier so the
        // MotionEvents which are close to the current position of the finger are not