From 1946b312dfda7d2e46e602d1d2683c10ac282ca1 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Thu, 21 Mar 2019 14:48:23 -0700 Subject: [PATCH] Ignore prox data when it's obsolete The proximity sensor response is asynchronous, this means that the user might have interacted with the phone while sensor data is being processed. Let's ignore its response in case it arrives late. Fixes: 129012983 Test: press power while uncovering prox sensor Change-Id: Ib31e6c53b9f5993349c5eaed6122af5228d07728 --- .../src/com/android/systemui/doze/DozeMachine.java | 2 +- .../src/com/android/systemui/doze/DozeTriggers.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java b/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java index 6c4be06170432..c243899c6bc9d 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeMachine.java @@ -211,7 +211,7 @@ public class DozeMachine { mDozeService.requestWakeUp(); } - private boolean isExecutingTransition() { + public boolean isExecutingTransition() { return !mQueuedRequests.isEmpty(); } diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java index 031f56266ea4c..7189a48fed1f8 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java @@ -198,6 +198,14 @@ public class DozeTriggers implements DozeMachine.Part { } private void onProximityFar(boolean far) { + // Proximity checks are asynchronous and the user might have interacted with the phone + // when a new event is arriving. This means that a state transition might have happened + // and the proximity check is now obsolete. + if (mMachine.isExecutingTransition()) { + Log.w(TAG, "onProximityFar called during transition. Ignoring sensor response."); + return; + } + final boolean near = !far; final DozeMachine.State state = mMachine.getState(); final boolean paused = (state == DozeMachine.State.DOZE_AOD_PAUSED);