Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2e0cc09 authored by Michael Bestas's avatar Michael Bestas
Browse files

FlingTracker can divide by zero and hang StatusBar in an infinite loop



if 2 events have the same timestamp then FlingTracker in PanelView will divide
by zero causing NaNs. the bug is usually triggered by rapid StatusBar up/down
dragging activity and updateCarrierLabelVisibility can then loop indefinitely
looking at NaNs. the user visible symptom is that StatusBar refuses to pull
down and is burning cpu time.

Signed-off-by: default avatarMichael Bestas <mikeioannina@gmail.com>

Change-Id: I0791c6bea953bf03346185fc6aaf44aaea79aace
parent da062dc6
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ public class PanelView extends FrameLayout {
            mVX = mVY = 0;
            MotionEventCopy last = null;
            int i = 0;
            int j = 0;
            float totalweight = 0f;
            float weight = 10f;
            for (final Iterator<MotionEventCopy> iter = mEventBuf.descendingIterator();
@@ -121,6 +122,10 @@ public class PanelView extends FrameLayout {
                final MotionEventCopy event = iter.next();
                if (last != null) {
                    final float dt = (float) (event.t - last.t) / timebase;
                    if (dt == 0) {
                        last = event;
                        continue;
                    }
                    final float dx = (event.x - last.x);
                    final float dy = (event.y - last.y);
                    if (FlingTracker.DEBUG) {
@@ -135,12 +140,15 @@ public class PanelView extends FrameLayout {
                    mVY += weight * dy / dt;
                    totalweight += weight;
                    weight *= DECAY;
                    j++;
                }
                last = event;
                i++;
            }
            if (j != 0) {
                mVX /= totalweight;
                mVY /= totalweight;
            }

            if (FlingTracker.DEBUG) {
                Slog.v("FlingTracker", "computed: vx=" + mVX + " vy=" + mVY);