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

Commit 0bfb405b authored by Lucas Silva's avatar Lucas Silva
Browse files

Hide the status bar dream overlay when low light is active.

We pipe the component name of the currently active dream into the
overlay service, and when the active dream is lowlight, we hide the
status bar.

Test: atest DreamOverlayStateControllerTest
Test: atest DreamOverlayStatusBarViewControllerTest
Test: manually on device by entering/exiting low light and ensuring the
status bar is hidden
Fixes: 245386662

Change-Id: I22973538bea19ef108360a319c70c878cfd81800
parent 591f54ba
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
@@ -36,6 +37,7 @@ public abstract class DreamOverlayService extends Service {
    private static final String TAG = "DreamOverlayService";
    private static final boolean DEBUG = false;
    private boolean mShowComplications;
    private ComponentName mDreamComponent;

    private IDreamOverlay mDreamOverlay = new IDreamOverlay.Stub() {
        @Override
@@ -56,6 +58,8 @@ public abstract class DreamOverlayService extends Service {
    public final IBinder onBind(@NonNull Intent intent) {
        mShowComplications = intent.getBooleanExtra(DreamService.EXTRA_SHOW_COMPLICATIONS,
                DreamService.DEFAULT_SHOW_COMPLICATIONS);
        mDreamComponent = intent.getParcelableExtra(DreamService.EXTRA_DREAM_COMPONENT,
                ComponentName.class);
        return mDreamOverlay.asBinder();
    }

@@ -84,4 +88,12 @@ public abstract class DreamOverlayService extends Service {
    public final boolean shouldShowComplications() {
        return mShowComplications;
    }

    /**
     * Returns the active dream component.
     * @hide
     */
    public final ComponentName getDreamComponent() {
        return mDreamComponent;
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -217,6 +217,12 @@ public class DreamService extends Service implements Window.Callback {
    public static final String EXTRA_SHOW_COMPLICATIONS =
            "android.service.dreams.SHOW_COMPLICATIONS";

    /**
     * Extra containing the component name for the active dream.
     * @hide
     */
    public static final String EXTRA_DREAM_COMPONENT = "android.service.dreams.DREAM_COMPONENT";

    /**
     * The default value for whether to show complications on the overlay.
     * @hide
@@ -271,6 +277,7 @@ public class DreamService extends Service implements Window.Callback {
            overlayIntent.setComponent(overlayService);
            overlayIntent.putExtra(EXTRA_SHOW_COMPLICATIONS,
                    fetchShouldShowComplications(context, serviceInfo));
            overlayIntent.putExtra(EXTRA_DREAM_COMPONENT, dreamService);

            context.bindService(overlayIntent,
                    this, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE);
+2 −0
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ android_library {
        "dagger2",
        "jsr330",
        "lottie",
        "LowLightDreamLib",
    ],
    manifest: "AndroidManifest.xml",

@@ -227,6 +228,7 @@ android_library {
        "dagger2",
        "jsr330",
        "WindowManager-Shell",
        "LowLightDreamLib",
    ],
    libs: [
        "android.test.runner",
+14 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.dreams;

import android.content.ComponentName;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
@@ -26,11 +27,13 @@ import android.view.WindowInsets;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.ViewModelStore;

import com.android.dream.lowlight.dagger.LowLightDreamModule;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.policy.PhoneWindow;
@@ -44,6 +47,7 @@ import com.android.systemui.dreams.touch.DreamOverlayTouchMonitor;
import java.util.concurrent.Executor;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * The {@link DreamOverlayService} is responsible for placing an overlay on top of a dream. The
@@ -62,6 +66,8 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
    // content area).
    private final DreamOverlayContainerViewController mDreamOverlayContainerViewController;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    @Nullable
    private final ComponentName mLowLightDreamComponent;
    private final UiEventLogger mUiEventLogger;

    // A reference to the {@link Window} used to hold the dream overlay.
@@ -125,10 +131,13 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
            DreamOverlayComponent.Factory dreamOverlayComponentFactory,
            DreamOverlayStateController stateController,
            KeyguardUpdateMonitor keyguardUpdateMonitor,
            UiEventLogger uiEventLogger) {
            UiEventLogger uiEventLogger,
            @Nullable @Named(LowLightDreamModule.LOW_LIGHT_DREAM_COMPONENT)
                    ComponentName lowLightDreamComponent) {
        mContext = context;
        mExecutor = executor;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mLowLightDreamComponent = lowLightDreamComponent;
        mKeyguardUpdateMonitor.registerCallback(mKeyguardCallback);
        mStateController = stateController;
        mUiEventLogger = uiEventLogger;
@@ -155,6 +164,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
            windowManager.removeView(mWindow.getDecorView());
        }
        mStateController.setOverlayActive(false);
        mStateController.setLowLightActive(false);
        mDestroyed = true;
        super.onDestroy();
    }
@@ -163,6 +173,9 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
    public void onStartDream(@NonNull WindowManager.LayoutParams layoutParams) {
        mUiEventLogger.log(DreamOverlayEvent.DREAM_OVERLAY_ENTER_START);
        setCurrentState(Lifecycle.State.STARTED);
        final ComponentName dreamComponent = getDreamComponent();
        mStateController.setLowLightActive(
                dreamComponent != null && dreamComponent.equals(mLowLightDreamComponent));
        mExecutor.execute(() -> {
            if (mDestroyed) {
                // The task could still be executed after the service has been destroyed. Bail if
+17 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ public class DreamOverlayStateController implements
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    public static final int STATE_DREAM_OVERLAY_ACTIVE = 1 << 0;
    public static final int STATE_LOW_LIGHT_ACTIVE = 1 << 1;

    private static final int OP_CLEAR_STATE = 1;
    private static final int OP_SET_STATE = 2;
@@ -193,6 +194,14 @@ public class DreamOverlayStateController implements
        return containsState(STATE_DREAM_OVERLAY_ACTIVE);
    }

    /**
     * Returns whether low light mode is active.
     * @return {@code true} if in low light mode, {@code false} otherwise.
     */
    public boolean isLowLightActive() {
        return containsState(STATE_LOW_LIGHT_ACTIVE);
    }

    private boolean containsState(int state) {
        return (mState & state) != 0;
    }
@@ -221,6 +230,14 @@ public class DreamOverlayStateController implements
        modifyState(active ? OP_SET_STATE : OP_CLEAR_STATE, STATE_DREAM_OVERLAY_ACTIVE);
    }

    /**
     * Sets whether low light mode is active.
     * @param active {@code true} if low light mode is active, {@code false} otherwise.
     */
    public void setLowLightActive(boolean active) {
        modifyState(active ? OP_SET_STATE : OP_CLEAR_STATE, STATE_LOW_LIGHT_ACTIVE);
    }

    /**
     * Returns the available complication types.
     */
Loading