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

Commit 065c12c7 authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Update BubbleViewInfoTask to verify that the state hasn't changed after the...

Update BubbleViewInfoTask to verify that the state hasn't changed after the task was scheduled or while it is running.
Without this there is a race condition that causes the task to inflate a bubble incorrectly, e.g. without a dot path, which then leads to an NPE trying to render the dot.

Bug: 269670598
Test: Tested on a physical device
Change-Id: Ib2cbd4ef0fd2a33766620a0997f130eb4b8bb86f
parent 9ce13dd2
Loading
Loading
Loading
Loading
+17 −1
Original line number Original line Diff line number Diff line
@@ -104,7 +104,11 @@ public class BubbleViewInfoTask extends AsyncTask<Void, Void, BubbleViewInfoTask


    @Override
    @Override
    protected BubbleViewInfo doInBackground(Void... voids) {
    protected BubbleViewInfo doInBackground(Void... voids) {
        if (mController.get().isShowingAsBubbleBar()) {
        if (!verifyState()) {
            // If we're in an inconsistent state, then switched modes and should just bail now.
            return null;
        }
        if (mLayerView.get() != null) {
            return BubbleViewInfo.populateForBubbleBar(mContext.get(), mController.get(),
            return BubbleViewInfo.populateForBubbleBar(mContext.get(), mController.get(),
                    mLayerView.get(), mIconFactory, mBubble, mSkipInflation);
                    mLayerView.get(), mIconFactory, mBubble, mSkipInflation);
        } else {
        } else {
@@ -118,7 +122,11 @@ public class BubbleViewInfoTask extends AsyncTask<Void, Void, BubbleViewInfoTask
        if (isCancelled() || viewInfo == null) {
        if (isCancelled() || viewInfo == null) {
            return;
            return;
        }
        }

        mMainExecutor.execute(() -> {
        mMainExecutor.execute(() -> {
            if (!verifyState()) {
                return;
            }
            mBubble.setViewInfo(viewInfo);
            mBubble.setViewInfo(viewInfo);
            if (mCallback != null) {
            if (mCallback != null) {
                mCallback.onBubbleViewsReady(mBubble);
                mCallback.onBubbleViewsReady(mBubble);
@@ -126,6 +134,14 @@ public class BubbleViewInfoTask extends AsyncTask<Void, Void, BubbleViewInfoTask
        });
        });
    }
    }


    private boolean verifyState() {
        if (mController.get().isShowingAsBubbleBar()) {
            return mLayerView.get() != null;
        } else {
            return mStackView.get() != null;
        }
    }

    /**
    /**
     * Info necessary to render a bubble.
     * Info necessary to render a bubble.
     */
     */