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

Commit 73637491 authored by Darrell Shi's avatar Darrell Shi
Browse files

Hide all complications as necessary.

Pass whether the dream overlay should show complications from the
overlay service to overlay state controller, and use the flag when
filtering what complications to show.

Test: atest DreamOverlayStateControllerTest
Bug: 211519550
Change-Id: I65841c880b4173bd5b7d0b489b0bd30ac4c0a2bf
parent cfe627f2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
    public void onStartDream(@NonNull WindowManager.LayoutParams layoutParams) {
        setCurrentState(Lifecycle.State.STARTED);
        mExecutor.execute(() -> {
            mStateController.setShouldShowComplications(shouldShowComplications());
            addOverlayWindowLocked(layoutParams);
            setCurrentState(Lifecycle.State.RESUMED);
            mStateController.setOverlayActive(true);
+27 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.dreams;

import android.service.dreams.DreamService;
import android.util.Log;

import androidx.annotation.NonNull;
@@ -84,6 +85,8 @@ public class DreamOverlayStateController implements
    @Complication.ComplicationType
    private int mAvailableComplicationTypes = Complication.COMPLICATION_TYPE_NONE;

    private boolean mShouldShowComplications = DreamService.DEFAULT_SHOW_COMPLICATIONS;

    private final Collection<Complication> mComplications = new HashSet();

    @VisibleForTesting
@@ -131,7 +134,12 @@ public class DreamOverlayStateController implements
                .filter(complication -> {
                    @Complication.ComplicationType
                    final int requiredTypes = complication.getRequiredTypeAvailability();
                    // If it should show complications, show ones whose required types are
                    // available. Otherwise, only show ones that don't require types.
                    if (mShouldShowComplications) {
                        return (requiredTypes & getAvailableComplicationTypes()) == requiredTypes;
                    }
                    return requiredTypes == Complication.COMPLICATION_TYPE_NONE;
                })
                .collect(Collectors.toCollection(HashSet::new))
                : mComplications);
@@ -221,7 +229,24 @@ public class DreamOverlayStateController implements
    public void setAvailableComplicationTypes(@Complication.ComplicationType int types) {
        mExecutor.execute(() -> {
            mAvailableComplicationTypes = types;
            mCallbacks.forEach(callback -> callback.onAvailableComplicationTypesChanged());
            mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
        });
    }

    /**
     * Returns whether the dream overlay should show complications.
     */
    public boolean getShouldShowComplications() {
        return mShouldShowComplications;
    }

    /**
     * Sets whether the dream overlay should show complications.
     */
    public void setShouldShowComplications(boolean shouldShowComplications) {
        mExecutor.execute(() -> {
            mShouldShowComplications = shouldShowComplications;
            mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
        });
    }
}
+47 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
    }

    @Test
    public void testComplicationFiltering() {
    public void testComplicationFilteringWhenShouldShowComplications() {
        final DreamOverlayStateController stateController =
                new DreamOverlayStateController(mExecutor);

@@ -160,4 +160,50 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
        }

    }

    @Test
    public void testComplicationFilteringWhenShouldHideComplications() {
        final DreamOverlayStateController stateController =
                new DreamOverlayStateController(mExecutor);
        stateController.setShouldShowComplications(true);

        final Complication alwaysAvailableComplication = Mockito.mock(Complication.class);
        final Complication weatherComplication = Mockito.mock(Complication.class);
        when(alwaysAvailableComplication.getRequiredTypeAvailability())
                .thenReturn(Complication.COMPLICATION_TYPE_NONE);
        when(weatherComplication.getRequiredTypeAvailability())
                .thenReturn(Complication.COMPLICATION_TYPE_WEATHER);

        stateController.addComplication(alwaysAvailableComplication);
        stateController.addComplication(weatherComplication);

        final DreamOverlayStateController.Callback callback =
                Mockito.mock(DreamOverlayStateController.Callback.class);

        stateController.setAvailableComplicationTypes(Complication.COMPLICATION_TYPE_WEATHER);
        stateController.addCallback(callback);
        mExecutor.runAllReady();

        {
            clearInvocations(callback);
            stateController.setShouldShowComplications(true);
            mExecutor.runAllReady();

            verify(callback).onAvailableComplicationTypesChanged();
            final Collection<Complication> complications = stateController.getComplications();
            assertThat(complications.contains(alwaysAvailableComplication)).isTrue();
            assertThat(complications.contains(weatherComplication)).isTrue();
        }

        {
            clearInvocations(callback);
            stateController.setShouldShowComplications(false);
            mExecutor.runAllReady();

            verify(callback).onAvailableComplicationTypesChanged();
            final Collection<Complication> complications = stateController.getComplications();
            assertThat(complications.contains(alwaysAvailableComplication)).isTrue();
            assertThat(complications.contains(weatherComplication)).isFalse();
        }
    }
}