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

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

Made StackScrollAlgorithm HUN logic only depend on children

A racecondition could trigger that the two states where not in sync
anymore. We now only rely on the ordering of the children.
Bug: 20421801

Change-Id: I3b607adb3b4b22f04f465d5e5e23f6e514c35ef9
parent 2f6b3fb9
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.policy.HeadsUpManager;

import java.util.ArrayList;
import java.util.TreeSet;

/**
 * A global state to track all input states for the algorithm.
@@ -130,10 +129,6 @@ public class AmbientState {
        mHeadsUpManager = headsUpManager;
    }

    public TreeSet<HeadsUpManager.HeadsUpEntry> getSortedHeadsUpEntries() {
        return mHeadsUpManager.getSortedEntries();
    }

    public float getStackTranslation() {
        return mStackTranslation;
    }
+19 −25
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import com.android.systemui.statusbar.policy.HeadsUpManager;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

/**
 * The Algorithm of the {@link com.android.systemui.statusbar.stack
@@ -155,7 +154,7 @@ public class StackScrollAlgorithm {
        scrollY = Math.max(0, scrollY);
        algorithmState.scrollY = (int) (scrollY + mCollapsedSize + bottomOverScroll);

        updateVisibleChildren(resultState, algorithmState, ambientState);
        updateVisibleChildren(resultState, algorithmState);

        // Phase 1:
        findNumberOfItemsInTopStackAndUpdateState(resultState, algorithmState, ambientState);
@@ -337,27 +336,18 @@ public class StackScrollAlgorithm {
     * Update the visible children on the state.
     */
    private void updateVisibleChildren(StackScrollState resultState,
            StackScrollAlgorithmState state, AmbientState ambientState) {
            StackScrollAlgorithmState state) {
        ViewGroup hostView = resultState.getHostView();
        int childCount = hostView.getChildCount();
        state.visibleChildren.clear();
        state.visibleChildren.ensureCapacity(childCount);
        int notGoneIndex = 0;
        TreeSet<HeadsUpManager.HeadsUpEntry> headsUpEntries
                = ambientState.getSortedHeadsUpEntries();
        for (HeadsUpManager.HeadsUpEntry entry: headsUpEntries) {
            ExpandableView v = entry.entry.row;
            notGoneIndex = updateNotGoneIndex(resultState, state, notGoneIndex, v);
        }
        for (int i = 0; i < childCount; i++) {
            ExpandableView v = (ExpandableView) hostView.getChildAt(i);
            if (v.getVisibility() != View.GONE) {
                notGoneIndex = updateNotGoneIndex(resultState, state, notGoneIndex, v);
                if (v instanceof ExpandableNotificationRow) {
                    ExpandableNotificationRow row = (ExpandableNotificationRow) v;
                    if (row.isHeadsUp()) {
                        continue;
                    }
                    notGoneIndex = updateNotGoneIndex(resultState, state, notGoneIndex, v);

                    // handle the notgoneIndex for the children as well
                    List<ExpandableNotificationRow> children =
@@ -372,8 +362,6 @@ public class StackScrollAlgorithm {
                            }
                        }
                    }
                } else {
                    notGoneIndex = updateNotGoneIndex(resultState, state, notGoneIndex, v);
                }
            }
        }
@@ -507,15 +495,25 @@ public class StackScrollAlgorithm {
            childViewState.yTranslation += ambientState.getTopPadding()
                    + ambientState.getStackTranslation();
        }
        updateHeadsUpStates(resultState, ambientState);
        updateHeadsUpStates(resultState, algorithmState, ambientState);
    }

    private void updateHeadsUpStates(StackScrollState resultState, AmbientState ambientState) {
        TreeSet<HeadsUpManager.HeadsUpEntry> headsUpEntries = ambientState.getSortedHeadsUpEntries();
        for (HeadsUpManager.HeadsUpEntry entry: headsUpEntries) {
            ExpandableNotificationRow row = entry.entry.row;
    private void updateHeadsUpStates(StackScrollState resultState,
            StackScrollAlgorithmState algorithmState, AmbientState ambientState) {
        int childCount = algorithmState.visibleChildren.size();
        ExpandableNotificationRow topHeadsUpEntry = null;
        for (int i = 0; i < childCount; i++) {
            View child = algorithmState.visibleChildren.get(i);
            if (!(child instanceof ExpandableNotificationRow)) {
                break;
            }
            ExpandableNotificationRow row = (ExpandableNotificationRow) child;
            if (!row.isHeadsUp()) {
                break;
            } else if (topHeadsUpEntry == null) {
                topHeadsUpEntry = row;
            }
            StackViewState childState = resultState.getViewStateForView(row);
            ExpandableNotificationRow topHeadsUpEntry = ambientState.getTopHeadsUpEntry();
            boolean isTopEntry = topHeadsUpEntry == row;
            if (!row.isInShade()) {
                childState.yTranslation = 0;
@@ -537,7 +535,6 @@ public class StackScrollAlgorithm {
                childState.yTranslation = Math.min(childState.yTranslation,
                        bottomPosition);
            }

        }
    }

@@ -897,9 +894,6 @@ public class StackScrollAlgorithm {
    }

    private View findFirstVisibleChild(ViewGroup container) {
        if (mHeadsUpManager != null && mHeadsUpManager.getTopEntry() != null) {
            return mHeadsUpManager.getTopEntry().entry.row;
        }
        int childCount = container.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = container.getChildAt(i);