From 225ce63f0bb27e9bac050cd960ebd7912dd40470 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Fri, 9 Dec 2022 16:30:23 -0800 Subject: [PATCH] Do not allow complications when dream overlay is not enabled. Complications are currently only hosted by the dream overlay. Dependent logic that listens on the DreamOverlayStateController for changes around complications should not be triggered when the dream overlay is not enabled. This changelist addresses this by preventing the DreamOverlayStateController from accepting complications when the overlay is not enabled (component wise). This change also null checks a complication view retrieved from the view holder before adding it to the layout. Test: atest DreamOverlayStateControllerTest Test: atest ComplicationHostViewControllerTest Fixes: 259859096 Change-Id: Ifa1b4a9da0070a949e422003d3fd4e9ca484a16e --- .../dreams/DreamOverlayRegistrant.java | 8 +++-- .../dreams/DreamOverlayStateController.java | 29 +++++++++++++++-- .../ComplicationHostViewController.java | 14 +++++++-- .../systemui/dreams/dagger/DreamModule.java | 28 +++++++++++++++++ .../DreamOverlayStateControllerTest.java | 31 ++++++++++++++----- .../ComplicationHostViewControllerTest.java | 17 ++++++++++ 6 files changed, 112 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java index d145f5c14917a..87c5f51ce13ad 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayRegistrant.java @@ -16,6 +16,8 @@ package com.android.systemui.dreams; +import static com.android.systemui.dreams.dagger.DreamModule.DREAM_OVERLAY_SERVICE_COMPONENT; + import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -35,6 +37,7 @@ import com.android.systemui.CoreStartable; import com.android.systemui.dagger.qualifiers.Main; import javax.inject.Inject; +import javax.inject.Named; /** * {@link DreamOverlayRegistrant} is responsible for telling system server that SystemUI should be @@ -98,12 +101,13 @@ public class DreamOverlayRegistrant implements CoreStartable { } @Inject - public DreamOverlayRegistrant(Context context, @Main Resources resources) { + public DreamOverlayRegistrant(Context context, @Main Resources resources, + @Named(DREAM_OVERLAY_SERVICE_COMPONENT) ComponentName dreamOverlayServiceComponent) { mContext = context; mResources = resources; mDreamManager = IDreamManager.Stub.asInterface( ServiceManager.getService(DreamService.DREAM_SERVICE)); - mOverlayServiceComponent = new ComponentName(mContext, DreamOverlayService.class); + mOverlayServiceComponent = dreamOverlayServiceComponent; } @Override diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java index 5f942b6fb834f..ccfdd0966e983 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayStateController.java @@ -16,6 +16,8 @@ package com.android.systemui.dreams; +import static com.android.systemui.dreams.dagger.DreamModule.DREAM_OVERLAY_ENABLED; + import android.service.dreams.DreamService; import android.util.Log; @@ -37,6 +39,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import javax.inject.Inject; +import javax.inject.Named; /** * {@link DreamOverlayStateController} is the source of truth for Dream overlay configurations and @@ -83,6 +86,7 @@ public class DreamOverlayStateController implements } private final Executor mExecutor; + private final boolean mOverlayEnabled; private final ArrayList mCallbacks = new ArrayList<>(); @Complication.ComplicationType @@ -94,14 +98,27 @@ public class DreamOverlayStateController implements @VisibleForTesting @Inject - public DreamOverlayStateController(@Main Executor executor) { + public DreamOverlayStateController(@Main Executor executor, + @Named(DREAM_OVERLAY_ENABLED) boolean overlayEnabled) { mExecutor = executor; + mOverlayEnabled = overlayEnabled; + if (DEBUG) { + Log.d(TAG, "Dream overlay enabled:" + mOverlayEnabled); + } } /** * Adds a complication to be included on the dream overlay. */ public void addComplication(Complication complication) { + if (!mOverlayEnabled) { + if (DEBUG) { + Log.d(TAG, + "Ignoring adding complication due to overlay disabled:" + complication); + } + return; + } + mExecutor.execute(() -> { if (mComplications.add(complication)) { if (DEBUG) { @@ -116,6 +133,14 @@ public class DreamOverlayStateController implements * Removes a complication from inclusion on the dream overlay. */ public void removeComplication(Complication complication) { + if (!mOverlayEnabled) { + if (DEBUG) { + Log.d(TAG, + "Ignoring removing complication due to overlay disabled:" + complication); + } + return; + } + mExecutor.execute(() -> { if (mComplications.remove(complication)) { if (DEBUG) { @@ -193,7 +218,7 @@ public class DreamOverlayStateController implements * @return {@code true} if overlay is active, {@code false} otherwise. */ public boolean isOverlayActive() { - return containsState(STATE_DREAM_OVERLAY_ACTIVE); + return mOverlayEnabled && containsState(STATE_DREAM_OVERLAY_ACTIVE); } /** diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java index 100ccc35e638f..a2e11b21ea595 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java @@ -138,19 +138,27 @@ public class ComplicationHostViewController extends ViewController> observer = + captureComplicationViewModelsObserver(); + + // Add a complication and ensure it is added to the view. + final HashSet complications = new HashSet<>( + Collections.singletonList(mComplicationViewModel)); + when(mViewHolder.getView()).thenReturn(null); + observer.onChanged(complications); + + verify(mLayoutEngine, never()).addComplication(any(), any(), any(), anyInt()); + + } + @Test public void testNewComplicationsBeforeEntryAnimationsFinishSetToInvisible() { final Observer> observer =