From 31ef24c9342b8d7b09f4c2f655dc2517b11d578f Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Wed, 12 Aug 2020 16:48:33 -0700 Subject: [PATCH] Store mHistoricTimes as longs intead of floats The loss of precision was causing us to miscalculate the age of events, and thus not detecting any pause due to denominator = 0. Test: have a device that hasn't been rebooted for a certain amount of time such that SystemClock#uptimeMillis can't be accurately converted to a float, then try to swipe up and hold Fixes: 160568387 Change-Id: Idef112187f34a18feea7e6a0b77258626f9d0ed4 (cherry picked from commit a14567096922f23d6e03c84fc930e3451e7471c2) --- .../android/quickstep/util/MotionPauseDetector.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java index 969fa5067d..f60f7ad6d8 100644 --- a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java +++ b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java @@ -276,7 +276,7 @@ public class MotionPauseDetector { private static final int HISTORY_SIZE = 20; // Position history are stored in a circular array - private final float[] mHistoricTimes = new float[HISTORY_SIZE]; + private final long[] mHistoricTimes = new long[HISTORY_SIZE]; private final float[] mHistoricPos = new float[HISTORY_SIZE]; private int mHistoryCount = 0; private int mHistoryStart = 0; @@ -292,7 +292,7 @@ public class MotionPauseDetector { mHistoryCount = mHistoryStart = 0; } - private void addPositionAndTime(float eventTime, float eventPosition) { + private void addPositionAndTime(long eventTime, float eventPosition) { mHistoricTimes[mHistoryStart] = eventTime; mHistoricPos[mHistoryStart] = eventPosition; mHistoryStart++; @@ -322,7 +322,7 @@ public class MotionPauseDetector { * Based on solveUnweightedLeastSquaresDeg2 in VelocityTracker.cpp */ private Float solveUnweightedLeastSquaresDeg2(final int pointPos) { - final float eventTime = mHistoricTimes[pointPos]; + final long eventTime = mHistoricTimes[pointPos]; float sxi = 0, sxiyi = 0, syi = 0, sxi2 = 0, sxi3 = 0, sxi2yi = 0, sxi4 = 0; int count = 0; @@ -332,8 +332,8 @@ public class MotionPauseDetector { index += HISTORY_SIZE; } - float time = mHistoricTimes[index]; - float age = eventTime - time; + long time = mHistoricTimes[index]; + long age = eventTime - time; if (age > HORIZON_MS) { break; } @@ -364,7 +364,7 @@ public class MotionPauseDetector { if (endPos < 0) { endPos += HISTORY_SIZE; } - float denominator = eventTime - mHistoricTimes[endPos]; + long denominator = eventTime - mHistoricTimes[endPos]; if (denominator != 0) { return (mHistoricPos[pointPos] - mHistoricPos[endPos]) / denominator; }