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 <jiwon88.kim@samsung.com>
Change-Id: Ifca0c25411f56a4de79d89d262d2b4e61045a8ed
This commit is contained in:
Jiwon Kim
2020-11-24 10:56:59 +09:00
parent 5e3a035a3d
commit bdabd396f4

View File

@@ -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<MotionEvent> 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);
}