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

Commit f87baef1 authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixed a crash with HUN's

The sorted order was never correctly updated, leading to
dead elements inside the map which might even be a memory
leak in the worst case.

Bug: 21725521
Change-Id: Ic2064a04d458445d11df94e0358d4d2044c8b995
parent 0e0942d5
Loading
Loading
Loading
Loading
+3 −12
Original line number Diff line number Diff line
@@ -552,6 +552,7 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
        }

        public void updateEntry() {
            mSortedEntries.remove(HeadsUpEntry.this);
            long currentTime = mClock.currentTimeMillis();
            earliestRemovaltime = currentTime + mMinimumDisplayTime;
            postTime = Math.max(postTime, currentTime);
@@ -561,13 +562,13 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
                long removeDelay = Math.max(finishTime - currentTime, mMinimumDisplayTime);
                mHandler.postDelayed(mRemoveHeadsUpRunnable, removeDelay);
            }
            updateSortOrder(HeadsUpEntry.this);
            mSortedEntries.add(HeadsUpEntry.this);
        }

        @Override
        public int compareTo(HeadsUpEntry o) {
            return postTime < o.postTime ? 1
                    : postTime == o.postTime ? 0
                    : postTime == o.postTime ? entry.key.compareTo(o.entry.key)
                            : -1;
        }

@@ -592,16 +593,6 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
        }
    }

    /**
     * Update the sorted heads up order.
     *
     * @param headsUpEntry the headsUp that changed
     */
    private void updateSortOrder(HeadsUpEntry headsUpEntry) {
        mSortedEntries.remove(headsUpEntry);
        mSortedEntries.add(headsUpEntry);
    }

    public static class Clock {
        public long currentTimeMillis() {
            return SystemClock.elapsedRealtime();