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 =