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

Commit 6774ac7e authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "[CS] 3/ Move isStatusBarFullscreen tracking to repo." into main

parents 0f550188 0f1eb193
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -123,13 +123,6 @@ public interface StatusBarStateController {
         */
        default void onDozeAmountChanged(float linear, float eased) {}

        /**
         * Callback to be notified when the fullscreen or immersive state changes.
         *
         * @param isFullscreen if any of the system bar is hidden by the focused window.
         */
        default void onFullscreenStateChanged(boolean isFullscreen) {}

        /**
         * Callback to be notified when the pulsing state changes
         */
+0 −36
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.statusbar;

import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_TRANSITION_FROM_AOD;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_TRANSITION_TO_AOD;

@@ -31,13 +29,7 @@ import android.text.format.DateFormat;
import android.util.FloatProperty;
import android.util.Log;
import android.view.Choreographer;
import android.view.InsetsFlags;
import android.view.View;
import android.view.ViewDebug;
import android.view.WindowInsets;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsController.Appearance;
import android.view.WindowInsetsController.Behavior;
import android.view.animation.Interpolator;

import androidx.annotation.NonNull;
@@ -553,34 +545,6 @@ public class StatusBarStateControllerImpl implements
        return mKeyguardRequested;
    }

    @Override
    public void setSystemBarAttributes(@Appearance int appearance, @Behavior int behavior,
            @InsetsType int requestedVisibleTypes, String packageName) {
        boolean isFullscreen = (requestedVisibleTypes & WindowInsets.Type.statusBars()) == 0
                || (requestedVisibleTypes & WindowInsets.Type.navigationBars()) == 0;
        if (mIsFullscreen != isFullscreen) {
            mIsFullscreen = isFullscreen;
            synchronized (mListeners) {
                for (RankedListener rl : new ArrayList<>(mListeners)) {
                    rl.mListener.onFullscreenStateChanged(isFullscreen);
                }
            }
        }

        // TODO (b/190543382): Finish the logging logic.
        // This section can be removed if we don't need to print it on logcat.
        if (DEBUG_IMMERSIVE_APPS) {
            boolean dim = (appearance & APPEARANCE_LOW_PROFILE_BARS) != 0;
            String behaviorName = ViewDebug.flagsToString(InsetsFlags.class, "behavior", behavior);
            String requestedVisibleTypesString = WindowInsets.Type.toString(requestedVisibleTypes);
            if (requestedVisibleTypesString.isEmpty()) {
                requestedVisibleTypesString = "none";
            }
            Log.d(TAG, packageName + " dim=" + dim + " behavior=" + behaviorName
                    + " requested visible types: " + requestedVisibleTypesString);
        }
    }

    @Override
    public void setPulsing(boolean pulsing) {
        if (mPulsing != pulsing) {
+0 −9
Original line number Diff line number Diff line
@@ -20,9 +20,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.IntDef;
import android.view.View;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsController.Appearance;
import android.view.WindowInsetsController.Behavior;

import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.phone.CentralSurfaces;
@@ -150,12 +147,6 @@ public interface SysuiStatusBarStateController extends StatusBarStateController
     */
    boolean isKeyguardRequested();

    /**
     * Set the system bar attributes
     */
    void setSystemBarAttributes(@Appearance int appearance, @Behavior int behavior,
            @InsetsType int requestedVisibleTypes, String packageName);

    /**
     * Set pulsing
     */
+53 −0
Original line number Diff line number Diff line
@@ -17,14 +17,22 @@
package com.android.systemui.statusbar.data.repository

import android.view.WindowInsets
import android.view.WindowInsetsController
import com.android.internal.statusbar.LetterboxDetails
import com.android.internal.view.AppearanceRegion
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.DisplayId
import com.android.systemui.statusbar.CommandQueue
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

/**
 * A repository for the current mode of the status bar on the homescreen (translucent, transparent,
@@ -45,6 +53,14 @@ interface StatusBarModeRepository {
     */
    val isTransientShown: StateFlow<Boolean>

    /**
     * True the focused window is fullscreen (aka immersive) and false otherwise.
     *
     * Typically, the only time the status bar window is hidden is when the focused window is
     * fullscreen.
     */
    val isInFullscreenMode: StateFlow<Boolean>

    /**
     * Requests for the status bar to be shown transiently.
     *
@@ -66,6 +82,7 @@ interface StatusBarModeRepository {
class StatusBarModeRepositoryImpl
@Inject
constructor(
    @Application scope: CoroutineScope,
    @DisplayId thisDisplayId: Int,
    private val commandQueue: CommandQueue,
) : StatusBarModeRepository, CoreStartable {
@@ -94,6 +111,23 @@ constructor(
            ): Boolean {
                return displayId == thisDisplayId && (types and WindowInsets.Type.statusBars() != 0)
            }

            override fun onSystemBarAttributesChanged(
                displayId: Int,
                @WindowInsetsController.Appearance appearance: Int,
                appearanceRegions: Array<AppearanceRegion>,
                navbarColorManagedByIme: Boolean,
                @WindowInsetsController.Behavior behavior: Int,
                @WindowInsets.Type.InsetsType requestedVisibleTypes: Int,
                packageName: String,
                letterboxDetails: Array<LetterboxDetails>,
            ) {
                if (displayId != thisDisplayId) return
                _originalStatusBarAttributes.value =
                    StatusBarAttributes(
                        requestedVisibleTypes,
                    )
            }
        }

    override fun start() {
@@ -103,6 +137,17 @@ constructor(
    private val _isTransientShown = MutableStateFlow(false)
    override val isTransientShown: StateFlow<Boolean> = _isTransientShown.asStateFlow()

    private val _originalStatusBarAttributes = MutableStateFlow<StatusBarAttributes?>(null)

    override val isInFullscreenMode: StateFlow<Boolean> =
        _originalStatusBarAttributes
            .map { params ->
                val requestedVisibleTypes = params?.requestedVisibleTypes ?: return@map false
                // When the status bar is not requested visible, we assume we're in fullscreen mode.
                requestedVisibleTypes and WindowInsets.Type.statusBars() == 0
            }
            .stateIn(scope, SharingStarted.Eagerly, false)

    override fun showTransient() {
        _isTransientShown.value = true
    }
@@ -110,4 +155,12 @@ constructor(
    override fun clearTransient() {
        _isTransientShown.value = false
    }

    /**
     * Internal class keeping track of the raw status bar attributes received from the callback.
     * Should never be exposed.
     */
    private data class StatusBarAttributes(
        @WindowInsets.Type.InsetsType val requestedVisibleTypes: Int,
    )
}
+10 −9
Original line number Diff line number Diff line
@@ -563,8 +563,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
    private final Executor mUiBgExecutor;

    protected boolean mDozing;
    private boolean mIsFullscreen;

    boolean mCloseQsBeforeScreenOff;

    private final NotificationMediaManager mMediaManager;
@@ -1192,6 +1190,9 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
        mDemoModeController.addCallback(mDemoModeCallback);
        mJavaAdapter.alwaysCollectFlow(
                mStatusBarModeRepository.isTransientShown(), this::onTransientShownChanged);
        mJavaAdapter.alwaysCollectFlow(
                mStatusBarModeRepository.isInFullscreenMode(),
                this::onStatusBarFullscreenChanged);

        mCommandQueueCallbacks = mCommandQueueCallbacksLazy.get();
        mCommandQueue.addCallback(mCommandQueueCallbacks);
@@ -1733,6 +1734,10 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
        maybeUpdateBarMode();
    }

    private void onStatusBarFullscreenChanged(boolean isWindowShown) {
        maybeUpdateBarMode();
    }

    private void maybeUpdateBarMode() {
        final int barMode = barMode(isTransientShown(), mAppearance);
        if (updateBarMode(barMode)) {
@@ -1752,8 +1757,10 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
    }

    private @TransitionMode int barMode(boolean isTransient, int appearance) {
        boolean isFullscreen = mStatusBarModeRepository.isInFullscreenMode().getValue();
        final int lightsOutOpaque = APPEARANCE_LOW_PROFILE_BARS | APPEARANCE_OPAQUE_STATUS_BARS;
        if (mOngoingCallController.hasOngoingCall() && mIsFullscreen) {
        if (mOngoingCallController.hasOngoingCall() && isFullscreen) {
            // Force show the status bar if there's an ongoing call.
            return MODE_SEMI_TRANSPARENT;
        } else if (isTransient) {
            return MODE_SEMI_TRANSPARENT;
@@ -3349,12 +3356,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
                    updateReportRejectedTouchVisibility();
                    Trace.endSection();
                }

                @Override
                public void onFullscreenStateChanged(boolean isFullscreen) {
                    mIsFullscreen = isFullscreen;
                    maybeUpdateBarMode();
                }
            };

    private final BatteryController.BatteryStateChangeCallback mBatteryStateChangeCallback =
Loading