From 2955b163175b3dbdf69df34ea0c6f8c8c40642d3 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Fri, 21 Apr 2023 14:54:13 -0400 Subject: [PATCH] Don't show home controls complication if not available. There is a toggle to disable home controls in Settings, and we need to honor that toggle when determining if the complication should be shown on the dream. Bug: 278964460 Test: atest DreamOverlayStateControllerTest Test: flashed device and disabled toggle in settings, verified home controls does not show on clock dream Change-Id: I4e72f4619fd0ebbf5a78620796f0114ceabc9365 --- .../dreams/DreamOverlayStateController.java | 3 +- .../DreamOverlayStateControllerTest.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java index 0f370ac62b1f0..b141db15ea0f9 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java @@ -199,7 +199,8 @@ public class DreamOverlayStateController implements if (mShouldShowComplications) { return (requiredTypes & getAvailableComplicationTypes()) == requiredTypes; } - return (requiredTypes & mSupportedTypes) == requiredTypes; + final int typesToAlwaysShow = mSupportedTypes & getAvailableComplicationTypes(); + return (requiredTypes & typesToAlwaysShow) == requiredTypes; }) .collect(Collectors.toCollection(HashSet::new)) : mComplications); diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java index f143c46701c74..7b4160551c825 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java @@ -376,6 +376,34 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase { } } + @Test + public void testHomeControlsDoNotShowIfNotAvailable_featureEnabled() { + when(mFeatureFlags.isEnabled(Flags.ALWAYS_SHOW_HOME_CONTROLS_ON_DREAMS)).thenReturn(true); + + final DreamOverlayStateController stateController = getDreamOverlayStateController(true); + stateController.setShouldShowComplications(true); + + final Complication homeControlsComplication = Mockito.mock(Complication.class); + when(homeControlsComplication.getRequiredTypeAvailability()) + .thenReturn(Complication.COMPLICATION_TYPE_HOME_CONTROLS); + + stateController.addComplication(homeControlsComplication); + + final DreamOverlayStateController.Callback callback = + Mockito.mock(DreamOverlayStateController.Callback.class); + + stateController.addCallback(callback); + mExecutor.runAllReady(); + + // No home controls since it is not available. + assertThat(stateController.getComplications()).doesNotContain(homeControlsComplication); + + stateController.setAvailableComplicationTypes(Complication.COMPLICATION_TYPE_HOME_CONTROLS + | Complication.COMPLICATION_TYPE_WEATHER); + mExecutor.runAllReady(); + assertThat(stateController.getComplications()).contains(homeControlsComplication); + } + private DreamOverlayStateController getDreamOverlayStateController(boolean overlayEnabled) { return new DreamOverlayStateController(mExecutor, overlayEnabled, mFeatureFlags); }