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

Commit 447e4f16 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix a potential NPE

I've never been able to reproduce this and the stack traces I have
of it don't match existing code, but looking at the code paths I think
this could still happen, there are a couple of places where the
mMagnetizedBubbleDraggingOut gets nulled out (e.g. on child removed)
I've tried to repro by:
 - canceling the bubbles in the middle of dragging to dismiss
 - trying to snap the bubble back and then drag it again to dismiss
   (snap back also nulls it)

I see a recent stack of it in pitot so I think it's worth adding the
null check.

Test: atest ExpandedAnimationControllerTest
Bug: 201866808
Change-Id: Ib9425a2b63410c95fddaaea59761dfd18557ed54
parent eeb998c0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -346,6 +346,9 @@ public class ExpandedAnimationController
     * bubble is dragged back into the row.
     */
    public void dragBubbleOut(View bubbleView, float x, float y) {
        if (mMagnetizedBubbleDraggingOut == null) {
            return;
        }
        if (mSpringToTouchOnNextMotionEvent) {
            springBubbleTo(mMagnetizedBubbleDraggingOut.getUnderlyingObject(), x, y);
            mSpringToTouchOnNextMotionEvent = false;
+11 −3
Original line number Diff line number Diff line
@@ -59,19 +59,21 @@ public class ExpandedAnimationControllerTest extends PhysicsAnimationLayoutTestC
    private int mStackOffset;
    private PointF mExpansionPoint;
    private BubblePositioner mPositioner;
    private BubbleStackView.StackViewState mStackViewState;
    private BubbleStackView.StackViewState mStackViewState = new BubbleStackView.StackViewState();

    @SuppressLint("VisibleForTests")
    @Before
    public void setUp() throws Exception {
        super.setUp();

        BubbleStackView stackView = mock(BubbleStackView.class);
        when(stackView.getState()).thenReturn(getStackViewState());
        mPositioner = new BubblePositioner(getContext(), mock(WindowManager.class));
        mPositioner.updateInternal(Configuration.ORIENTATION_PORTRAIT,
                Insets.of(0, 0, 0, 0),
                new Rect(0, 0, mDisplayWidth, mDisplayHeight));

        BubbleStackView stackView = mock(BubbleStackView.class);
        when(stackView.getState()).thenReturn(getStackViewState());

        mExpandedController = new ExpandedAnimationController(mPositioner,
                mOnBubbleAnimatedOutAction,
                stackView);
@@ -135,6 +137,12 @@ public class ExpandedAnimationControllerTest extends PhysicsAnimationLayoutTestC
        testBubblesInCorrectExpandedPositions();
    }

    @Test
    public void testDragBubbleOutDoesntNPE() throws InterruptedException {
        mExpandedController.onGestureFinished();
        mExpandedController.dragBubbleOut(mViews.get(0), 1, 1);
    }

    /** Expand the stack and wait for animations to finish. */
    private void expand() throws InterruptedException {
        mExpandedController.expandFromStack(mock(Runnable.class));