From bdabd396f4d35dcf8662c25c8580743ed4be430e Mon Sep 17 00:00:00 2001 From: Jiwon Kim Date: Tue, 24 Nov 2020 10:56:59 +0900 Subject: [PATCH] Fixed Handler Leak on DistanceClassifier A VelocityTracker object is not recycled in case of motionEvents.size()<3 at calculateDistances function. private DistanceVectors calculateDistances() { // This code assumes that there will be no missed DOWN or UP events. VelocityTracker velocityTracker = VelocityTracker.obtain(); ... if (motionEvents.size() < 3) { logDebug("Only " + motionEvents.size() + " motion events recorded."); return new DistanceVectors(0, 0, 0, 0); } ... } Test: Manual Signed-off-by: Jiwon Kim Change-Id: Ifca0c25411f56a4de79d89d262d2b4e61045a8ed --- .../systemui/classifier/brightline/DistanceClassifier.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/classifier/brightline/DistanceClassifier.java b/packages/SystemUI/src/com/android/systemui/classifier/brightline/DistanceClassifier.java index 0329183e60481..9fa2557c23140 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/brightline/DistanceClassifier.java +++ b/packages/SystemUI/src/com/android/systemui/classifier/brightline/DistanceClassifier.java @@ -112,7 +112,6 @@ class DistanceClassifier extends FalsingClassifier { private DistanceVectors calculateDistances() { // This code assumes that there will be no missed DOWN or UP events. - VelocityTracker velocityTracker = VelocityTracker.obtain(); List motionEvents = getRecentMotionEvents(); if (motionEvents.size() < 3) { @@ -120,6 +119,8 @@ class DistanceClassifier extends FalsingClassifier { return new DistanceVectors(0, 0, 0, 0); } + VelocityTracker velocityTracker = VelocityTracker.obtain(); + for (MotionEvent motionEvent : motionEvents) { velocityTracker.addMovement(motionEvent); }