From c5584ceaad422c96f978132aee4d21ee1f61fc7d Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 24 Feb 2016 14:17:19 -0800 Subject: 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 --- .../systemui/classifier/FalsingManager.java | 27 +++++++++++++++++----- .../classifier/HumanInteractionClassifier.java | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java index 735a7c4bad4a..c09376bdd37e 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java +++ b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java @@ -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() { diff --git a/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java b/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java index 7ddbdf0e6e70..45eb9ad3115a 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java +++ b/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java @@ -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 -- cgit v1.2.3-59-g8ed1b