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

Commit 711d5b4a authored by Justin Weir's avatar Justin Weir
Browse files

Replace ShadeRepository.shadeModel

All usage could be satisfied by legacyShadeExpansion. That flow is
deprecated, but using allows us to delete ShadeExpansionStateManager.

Bug: 269323368
Test: Verified identical expansion values were emitted by the 2 flows
Test: Updated and ran existing tests
Flag: NONE
Change-Id: I41150dada9ffaa1d4c9d6436a123db3a83a64481
parent 59d4fd4a
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -214,7 +214,7 @@ constructor(
    private fun listenForLockscreenToPrimaryBouncerDragging() {
        var transitionId: UUID? = null
        scope.launch("$TAG#listenForLockscreenToPrimaryBouncerDragging") {
            shadeRepository.shadeModel
            shadeRepository.legacyShadeExpansion
                .sample(
                    combine(
                        transitionInteractor.startedKeyguardTransitionStep,
@@ -224,23 +224,23 @@ constructor(
                    ),
                    ::toQuad
                )
                .collect { (shadeModel, keyguardState, statusBarState, isKeyguardUnlocked) ->
                .collect { (shadeExpansion, keyguardState, statusBarState, isKeyguardUnlocked) ->
                    val id = transitionId
                    if (id != null) {
                        if (keyguardState.to == KeyguardState.PRIMARY_BOUNCER) {
                            // An existing `id` means a transition is started, and calls to
                            // `updateTransition` will control it until FINISHED or CANCELED
                            var nextState =
                                if (shadeModel.expansionAmount == 0f) {
                                if (shadeExpansion == 0f) {
                                    TransitionState.FINISHED
                                } else if (shadeModel.expansionAmount == 1f) {
                                } else if (shadeExpansion == 1f) {
                                    TransitionState.CANCELED
                                } else {
                                    TransitionState.RUNNING
                                }
                            transitionRepository.updateTransition(
                                id,
                                1f - shadeModel.expansionAmount,
                                1f - shadeExpansion,
                                nextState,
                            )

@@ -274,7 +274,7 @@ constructor(
                        // integrated into KeyguardTransitionRepository
                        if (
                            keyguardState.to == KeyguardState.LOCKSCREEN &&
                                shadeModel.isUserDragging &&
                                shadeRepository.legacyShadeTracking.value &&
                                !isKeyguardUnlocked &&
                                statusBarState == KEYGUARD
                        ) {
+3 −3
Original line number Diff line number Diff line
@@ -221,8 +221,8 @@ constructor(
        configurationInteractor
            .dimensionPixelSize(R.dimen.keyguard_translate_distance_on_swipe_up)
            .flatMapLatest { translationDistance ->
                shadeRepository.shadeModel.map {
                    if (it.expansionAmount == 0f) {
                shadeRepository.legacyShadeExpansion.map {
                    if (it == 0f) {
                        // Reset the translation value
                        0f
                    } else {
@@ -230,7 +230,7 @@ constructor(
                        MathUtils.lerp(
                            translationDistance,
                            0,
                            Interpolators.FAST_OUT_LINEAR_IN.getInterpolation(it.expansionAmount)
                            Interpolators.FAST_OUT_LINEAR_IN.getInterpolation(it)
                        )
                    }
                }
+2 −40
Original line number Diff line number Diff line
@@ -15,25 +15,14 @@
 */
package com.android.systemui.shade.data.repository

import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.shade.ShadeExpansionChangeEvent
import com.android.systemui.shade.ShadeExpansionListener
import com.android.systemui.shade.ShadeExpansionStateManager
import com.android.systemui.shade.domain.model.ShadeModel
import javax.inject.Inject
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged

/** Data for the shade, mostly related to expansion of the shade and quick settings. */
interface ShadeRepository {
    /** ShadeModel information regarding shade expansion events */
    val shadeModel: Flow<ShadeModel>

    /**
     * Amount qs has expanded, [0-1]. 0 means fully collapsed, 1 means fully expanded. Quick
     * Settings can be expanded without the full shade expansion.
@@ -167,34 +156,7 @@ interface ShadeRepository {

/** Business logic for shade interactions */
@SysUISingleton
class ShadeRepositoryImpl
@Inject
constructor(shadeExpansionStateManager: ShadeExpansionStateManager) : ShadeRepository {
    override val shadeModel: Flow<ShadeModel> =
        conflatedCallbackFlow {
                val callback =
                    object : ShadeExpansionListener {
                        override fun onPanelExpansionChanged(event: ShadeExpansionChangeEvent) {
                            // Don't propagate ShadeExpansionChangeEvent.dragDownPxAmount field.
                            // It is too noisy and produces extra events that consumers won't care
                            // about
                            val info =
                                ShadeModel(
                                    expansionAmount = event.fraction,
                                    isExpanded = event.expanded,
                                    isUserDragging = event.tracking
                                )
                            trySendWithFailureLogging(info, TAG, "updated shade expansion info")
                        }
                    }

                val currentState = shadeExpansionStateManager.addExpansionListener(callback)
                callback.onPanelExpansionChanged(currentState)

                awaitClose { shadeExpansionStateManager.removeExpansionListener(callback) }
            }
            .distinctUntilChanged()

class ShadeRepositoryImpl @Inject constructor() : ShadeRepository {
    private val _qsExpansion = MutableStateFlow(0f)
    override val qsExpansion: StateFlow<Float> = _qsExpansion.asStateFlow()

+0 −28
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.shade.domain.model

import android.annotation.FloatRange

/** Information about shade (NotificationPanel) expansion */
data class ShadeModel(
    /** 0 when collapsed, 1 when fully expanded. */
    @FloatRange(from = 0.0, to = 1.0) val expansionAmount: Float = 0f,
    /** Whether the panel should be considered expanded */
    val isExpanded: Boolean = false,
    /** Whether the user is actively dragging the panel. */
    val isUserDragging: Boolean = false,
)
+4 −15
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.runCurrent
import com.android.systemui.runTest
import com.android.systemui.shade.data.repository.FakeShadeRepository
import com.android.systemui.shade.domain.model.ShadeModel
import com.android.systemui.statusbar.phone.SystemUIDialogManager
import com.android.systemui.user.domain.UserDomainLayerModule
import com.android.systemui.util.mockito.mock
@@ -83,23 +82,13 @@ class DefaultUdfpsTouchOverlayViewModelTest : SysuiTestCase() {

    private fun TestComponent.shadeExpanded(expanded: Boolean) {
        if (expanded) {
            shadeRepository.setShadeModel(
                ShadeModel(
                    expansionAmount = 1f,
                    isExpanded = true,
                    isUserDragging = false,
                )
            )
            shadeRepository.setLegacyShadeExpansion(1f)
            shadeRepository.setLegacyShadeTracking(false)
            shadeRepository.setLegacyExpandedOrAwaitingInputTransfer(true)
        } else {
            keyguardRepository.setStatusBarState(StatusBarState.SHADE)
            shadeRepository.setShadeModel(
                ShadeModel(
                    expansionAmount = 0f,
                    isExpanded = false,
                    isUserDragging = false,
                )
            )
            shadeRepository.setLegacyShadeExpansion(0f)
            shadeRepository.setLegacyShadeTracking(false)
            shadeRepository.setLegacyExpandedOrAwaitingInputTransfer(false)
        }
    }
Loading