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

Commit 67e107ad authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[CS] 1/ Define transientShown in status bar repo not CentralSurfaces.

Bug: 300519002
Test: Open fullscreen app & swipe down -> verify transientShown updates
to true, CentralSurfaces notified. After some time, wait for status bar
to disappear -> verify transientShown updates to false, CentralSurfaces
notified
Test: atest StatusBarModeRepositoryImplTest CentralSurfacesImplTest

Change-Id: I1600092f6de92ee10575696b5021c6d3648b6092
parent 71d19fb9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.connectivity.ConnectivityModule;
import com.android.systemui.statusbar.dagger.StatusBarModule;
import com.android.systemui.statusbar.disableflags.dagger.DisableFlagsModule;
import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
import com.android.systemui.statusbar.notification.NotifPipelineFlags;
@@ -198,6 +199,7 @@ import javax.inject.Named;
            SettingsUtilModule.class,
            SmartRepliesInflationModule.class,
            SmartspaceModule.class,
            StatusBarModule.class,
            StatusBarPipelineModule.class,
            StatusBarPolicyModule.class,
            StatusBarWindowModule.class,
+1 −8
Original line number Diff line number Diff line
@@ -372,18 +372,11 @@ public class CommandQueue extends IStatusBar.Stub implements
                @Behavior int behavior, @InsetsType int requestedVisibleTypes,
                String packageName, LetterboxDetails[] letterboxDetails) { }

        /**
         * @see IStatusBar#showTransient(int, int, boolean).
         */
        default void showTransient(int displayId, @InsetsType int types) { }

        /**
         * @see IStatusBar#showTransient(int, int, boolean).
         */
        default void showTransient(int displayId, @InsetsType int types,
                boolean isGestureOnSystemBar) {
            showTransient(displayId, types);
        }
                boolean isGestureOnSystemBar) {}

        /**
         * @see IStatusBar#abortTransient(int, int).
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.dagger

import com.android.systemui.CoreStartable
import com.android.systemui.statusbar.data.repository.StatusBarModeRepository
import com.android.systemui.statusbar.data.repository.StatusBarModeRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap

/**
 * A module for **only** classes related to the status bar **UI element**. This module specifically
 * should **not** include:
 * - Classes in the `statusbar` package that are unrelated to the status bar UI.
 * - Status bar classes that are already provided by other modules
 *   ([com.android.systemui.statusbar.pipeline.dagger.StatusBarPipelineModule],
 *   [com.android.systemui.statusbar.policy.dagger.StatusBarPolicyModule], etc.).
 */
@Module
abstract class StatusBarModule {
    @Binds
    abstract fun bindStatusBarModeRepository(
        impl: StatusBarModeRepositoryImpl
    ): StatusBarModeRepository

    @Binds
    @IntoMap
    @ClassKey(StatusBarModeRepositoryImpl::class)
    abstract fun bindStatusBarModeRepositoryStart(impl: StatusBarModeRepositoryImpl): CoreStartable
}
+113 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.data.repository

import android.view.WindowInsets
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.DisplayId
import com.android.systemui.statusbar.CommandQueue
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

/**
 * A repository for the current mode of the status bar on the homescreen (translucent, transparent,
 * opaque, lights out, hidden, etc.).
 *
 * Note: These status bar modes are status bar *window* states that are sent to us from
 * WindowManager, not determined internally.
 */
interface StatusBarModeRepository {
    /**
     * True if the status bar window is showing transiently and will disappear soon, and false
     * otherwise. ("Otherwise" in this case means the status bar is persistently hidden OR
     * persistently shown.)
     *
     * This behavior is controlled by WindowManager via
     * [android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE], *not* calculated
     * internally. SysUI merely obeys the behavior sent to us.
     */
    val isTransientShown: StateFlow<Boolean>

    /**
     * Requests for the status bar to be shown transiently.
     *
     * TODO(b/277764509): Don't allow [CentralSurfaces] to set the transient mode; have it
     *   determined internally instead.
     */
    fun showTransient()

    /**
     * Requests for the status bar to be no longer showing transiently.
     *
     * TODO(b/277764509): Don't allow [CentralSurfaces] to set the transient mode; have it
     *   determined internally instead.
     */
    fun clearTransient()
}

@SysUISingleton
class StatusBarModeRepositoryImpl
@Inject
constructor(
    @DisplayId thisDisplayId: Int,
    private val commandQueue: CommandQueue,
) : StatusBarModeRepository, CoreStartable {

    private val commandQueueCallback =
        object : CommandQueue.Callbacks {
            override fun showTransient(
                displayId: Int,
                @WindowInsets.Type.InsetsType types: Int,
                isGestureOnSystemBar: Boolean,
            ) {
                if (isTransientRelevant(displayId, types)) {
                    _isTransientShown.value = true
                }
            }

            override fun abortTransient(displayId: Int, @WindowInsets.Type.InsetsType types: Int) {
                if (isTransientRelevant(displayId, types)) {
                    _isTransientShown.value = false
                }
            }

            private fun isTransientRelevant(
                displayId: Int,
                @WindowInsets.Type.InsetsType types: Int,
            ): Boolean {
                return displayId == thisDisplayId && (types and WindowInsets.Type.statusBars() != 0)
            }
        }

    override fun start() {
        commandQueue.addCallback(commandQueueCallback)
    }

    private val _isTransientShown = MutableStateFlow(false)
    override val isTransientShown: StateFlow<Boolean> = _isTransientShown.asStateFlow()

    override fun showTransient() {
        _isTransientShown.value = true
    }

    override fun clearTransient() {
        _isTransientShown.value = false
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -310,10 +310,6 @@ public interface CentralSurfaces extends Dumpable, LifecycleOwner {
    @VisibleForTesting
    void setBarStateForTest(int state);

    void showTransientUnchecked();

    void clearTransient();

    void acquireGestureWakeLock(long time);

    boolean setAppearance(int appearance);
Loading