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

Commit 3a4f48fc authored by Bryce Lee's avatar Bryce Lee Committed by Automerger Merge Worker
Browse files

Merge "Remove complication id from entry mapping on removal." into tm-dev am: 574ae112

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17225086

Change-Id: I83af46d267d8f7ae92d0de268fb1fe7e96f2c9d8
Signed-off-by: Automerger Merge Worker
parents f7ea6f15 574ae112
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -540,13 +540,15 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
    /**
     * Removes a complication by {@link ComplicationId}.
     */
    public void removeComplication(ComplicationId id) {
        if (!mEntries.containsKey(id)) {
    public boolean removeComplication(ComplicationId id) {
        final ViewEntry entry = mEntries.remove(id);

        if (entry == null) {
            Log.e(TAG, "could not find id:" + id);
            return;
            return false;
        }

        final ViewEntry entry = mEntries.get(id);
        entry.remove();
        return true;
    }
}
+34 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.dreams.complication;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -414,4 +415,37 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase {
            assertThat(lp.endToEnd == ConstraintLayout.LayoutParams.PARENT_ID).isTrue();
        });
    }

    /**
     * Ensures a second removal of a complication is a no-op.
     */
    @Test
    public void testDoubleRemoval() {
        final ComplicationLayoutEngine engine =
                new ComplicationLayoutEngine(mLayout, 0, mTouchSession, 0, 0);

        final ViewInfo firstViewInfo = new ViewInfo(
                new ComplicationLayoutParams(
                        100,
                        100,
                        ComplicationLayoutParams.POSITION_TOP
                                | ComplicationLayoutParams.POSITION_END,
                        ComplicationLayoutParams.DIRECTION_DOWN,
                        0),
                Complication.CATEGORY_STANDARD,
                mLayout);

        engine.addComplication(firstViewInfo.id, firstViewInfo.view, firstViewInfo.lp,
                firstViewInfo.category);
        verify(mLayout).addView(firstViewInfo.view);

        assertThat(engine.removeComplication(firstViewInfo.id)).isTrue();
        verify(firstViewInfo.view).getParent();
        verify(mLayout).removeView(firstViewInfo.view);

        Mockito.clearInvocations(mLayout, firstViewInfo.view);
        assertThat(engine.removeComplication(firstViewInfo.id)).isFalse();
        verify(firstViewInfo.view, never()).getParent();
        verify(mLayout, never()).removeView(firstViewInfo.view);
    }
}