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

Commit 15b62e6c authored by Grace Cheng's avatar Grace Cheng Committed by Automerger Merge Worker
Browse files

Update PromptFingerprintIconViewModel to use DisplayRotation am: b05e1c7e

parents 3091bc06 b05e1c7e
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -41,6 +41,12 @@ import kotlinx.coroutines.flow.stateIn

/** Repository for the current state of the display */
interface DisplayStateRepository {
    /**
     * Whether or not the direction rotation is applied to get to an application's requested
     * orientation is reversed.
     */
    val isReverseDefaultRotation: Boolean

    /** Provides the current rear display state. */
    val isInRearDisplayMode: StateFlow<Boolean>

@@ -59,6 +65,9 @@ constructor(
    @Main handler: Handler,
    @Main mainExecutor: Executor
) : DisplayStateRepository {
    override val isReverseDefaultRotation =
        context.resources.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)

    override val isInRearDisplayMode: StateFlow<Boolean> =
        conflatedCallbackFlow {
                val sendRearDisplayStateUpdate = { state: Boolean ->
@@ -94,7 +103,11 @@ constructor(
    private fun getDisplayRotation(): DisplayRotation {
        val cachedDisplayInfo = DisplayInfo()
        context.display?.getDisplayInfo(cachedDisplayInfo)
        return cachedDisplayInfo.rotation.toDisplayRotation()
        var rotation = cachedDisplayInfo.rotation
        if (isReverseDefaultRotation) {
            rotation = (rotation + 1) % 4
        }
        return rotation.toDisplayRotation()
    }

    override val currentRotation: StateFlow<DisplayRotation> =
+3 −4
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@

package com.android.systemui.biometrics.ui.binder

import android.view.DisplayInfo
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.airbnb.lottie.LottieAnimationView
@@ -33,14 +32,14 @@ object PromptFingerprintIconViewBinder {
    fun bind(view: LottieAnimationView, viewModel: PromptFingerprintIconViewModel) {
        view.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                val displayInfo = DisplayInfo()
                view.context.display?.getDisplayInfo(displayInfo)
                viewModel.setRotation(displayInfo.rotation)
                viewModel.onConfigurationChanged(view.context.resources.configuration)
                launch {
                    viewModel.iconAsset.collect { iconAsset ->
                        if (iconAsset != -1) {
                            view.setAnimation(iconAsset)
                            // TODO: must replace call below once non-sfps asset logic and
                            // shouldAnimateIconView logic is migrated to this ViewModel.
                            view.playAnimation()
                        }
                    }
                }
+11 −12
Original line number Diff line number Diff line
@@ -19,10 +19,10 @@ package com.android.systemui.biometrics.ui.viewmodel

import android.annotation.RawRes
import android.content.res.Configuration
import android.view.Surface
import com.android.systemui.R
import com.android.systemui.biometrics.domain.interactor.DisplayStateInteractor
import com.android.systemui.biometrics.domain.interactor.PromptSelectorInteractor
import com.android.systemui.biometrics.shared.model.DisplayRotation
import com.android.systemui.biometrics.shared.model.FingerprintSensorType
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
@@ -35,19 +35,21 @@ constructor(
    private val displayStateInteractor: DisplayStateInteractor,
    promptSelectorInteractor: PromptSelectorInteractor,
) {
    /** Current device rotation. */
    private var rotation: Int = Surface.ROTATION_0

    /** Current BiometricPromptLayout.iconView asset. */
    val iconAsset: Flow<Int> =
        combine(
            displayStateInteractor.currentRotation,
            displayStateInteractor.isFolded,
            displayStateInteractor.isInRearDisplayMode,
            promptSelectorInteractor.sensorType,
        ) { isFolded: Boolean, isInRearDisplayMode: Boolean, sensorType: FingerprintSensorType ->
        ) {
            rotation: DisplayRotation,
            isFolded: Boolean,
            isInRearDisplayMode: Boolean,
            sensorType: FingerprintSensorType ->
            when (sensorType) {
                FingerprintSensorType.POWER_BUTTON ->
                    getSideFpsAnimationAsset(isFolded, isInRearDisplayMode)
                    getSideFpsAnimationAsset(rotation, isFolded, isInRearDisplayMode)
                // Replace below when non-SFPS iconAsset logic is migrated to this ViewModel
                else -> -1
            }
@@ -55,11 +57,12 @@ constructor(

    @RawRes
    private fun getSideFpsAnimationAsset(
        rotation: DisplayRotation,
        isDeviceFolded: Boolean,
        isInRearDisplayMode: Boolean,
    ): Int =
        when (rotation) {
            Surface.ROTATION_90 ->
            DisplayRotation.ROTATION_90 ->
                if (isInRearDisplayMode) {
                    R.raw.biometricprompt_rear_portrait_reverse_base
                } else if (isDeviceFolded) {
@@ -67,7 +70,7 @@ constructor(
                } else {
                    R.raw.biometricprompt_portrait_base_topleft
                }
            Surface.ROTATION_270 ->
            DisplayRotation.ROTATION_270 ->
                if (isInRearDisplayMode) {
                    R.raw.biometricprompt_rear_portrait_base
                } else if (isDeviceFolded) {
@@ -89,8 +92,4 @@ constructor(
    fun onConfigurationChanged(newConfig: Configuration) {
        displayStateInteractor.onConfigurationChanged(newConfig)
    }

    fun setRotation(newRotation: Int) {
        rotation = newRotation
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -82,6 +82,11 @@ class DisplayStateRepositoryTest : SysuiTestCase() {
            rearDisplayDeviceStates
        )

        mContext.orCreateTestableResources.addOverride(
            com.android.internal.R.bool.config_reverseDefaultRotation,
            false
        )

        mContext = spy(mContext)
        whenever(mContext.display).thenReturn(display)

+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ class FakeDisplayStateRepository : DisplayStateRepository {
    private val _currentRotation = MutableStateFlow<DisplayRotation>(DisplayRotation.ROTATION_0)
    override val currentRotation: StateFlow<DisplayRotation> = _currentRotation.asStateFlow()

    override val isReverseDefaultRotation = false

    fun setIsInRearDisplayMode(isInRearDisplayMode: Boolean) {
        _isInRearDisplayMode.value = isInRearDisplayMode
    }