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

Commit a60c9366 authored by Chandru S's avatar Chandru S
Browse files

Potential fixes for the icon issue.

1. The udfps icon padding comes out to be a negative value when the params are not yet initialized.
2. Debounce the padding flow to limit it to 1 update per 100ms

Bug: 359154646
Test: unit test in a child CL
Flag: EXEMPT bugfix
Change-Id: Ib3d95740761a6e89c2918b1519a7d1cba857a25a
parent cc162545
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.ui.viewmodel.fakeDeviceEntryIconViewModelTransition
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -43,6 +44,7 @@ import kotlin.test.Test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.runner.RunWith
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
@@ -84,6 +86,12 @@ class UdfpsAccessibilityOverlayViewModelTest(flags: FlagsParameterization) : Sys
    @Before
    fun setup() {
        underTest = kosmos.deviceEntryUdfpsAccessibilityOverlayViewModel
        overrideResource(R.integer.udfps_padding_debounce_duration, 0)
    }

    @After
    fun teardown() {
        mContext.orCreateTestableResources.removeOverride(R.integer.udfps_padding_debounce_duration)
    }

    @Test
@@ -118,6 +126,7 @@ class UdfpsAccessibilityOverlayViewModelTest(flags: FlagsParameterization) : Sys
            runCurrent()
            assertThat(visible).isFalse()
        }

    fun fpNotRunning_overlayNotVisible() =
        testScope.runTest {
            val visible by collectLastValue(underTest.visible)
+13 −0
Original line number Diff line number Diff line
@@ -27,10 +27,13 @@ import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepos
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@@ -43,6 +46,16 @@ class DeviceEntryForegroundViewModelTest : SysuiTestCase() {
    private val underTest: DeviceEntryForegroundViewModel =
        kosmos.deviceEntryForegroundIconViewModel

    @Before
    fun setup() {
        context.orCreateTestableResources.addOverride(R.integer.udfps_padding_debounce_duration, 0)
    }

    @After
    fun teardown() {
        context.orCreateTestableResources.removeOverride(R.integer.udfps_padding_debounce_duration)
    }

    @Test
    fun aodIconColorWhite() =
        testScope.runTest {
+3 −0
Original line number Diff line number Diff line
@@ -2044,6 +2044,9 @@
    <!-- UDFPS view attributes -->
    <!-- UDFPS icon size in microns/um -->
    <dimen name="udfps_icon_size" format="float">6000</dimen>
    <!-- Limits the updates to at most one update per debounce duration to avoid too many
         updates due to quick changes to padding.   -->
    <integer name="udfps_padding_debounce_duration">100</integer>
    <!-- Microns/ums (1000 um = 1mm) per pixel for the given device. If unspecified, UI that
         relies on this value will not be sized correctly. -->
    <item name="pixel_pitch" format="float" type="dimen">-1</item>
+5 −2
Original line number Diff line number Diff line
@@ -36,8 +36,10 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlin.math.max

/** Encapsulates business logic for interacting with the UDFPS overlay. */
@SysUISingleton
@@ -124,8 +126,9 @@ constructor(
        udfpsOverlayParams.map { params ->
            val sensorWidth = params.nativeSensorBounds.right - params.nativeSensorBounds.left
            val nativePadding = (sensorWidth - iconSize) / 2
            (nativePadding * params.scaleFactor).toInt()
        }
            // padding can be negative when udfpsOverlayParams has not been initialized yet.
            max(0, (nativePadding * params.scaleFactor).toInt())
        }.distinctUntilChanged()

    companion object {
        private const val TAG = "UdfpsOverlayInteractor"
+7 −1
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@ import com.android.systemui.shade.ShadeDisplayAware
import javax.inject.Inject
import kotlin.math.roundToInt
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
@@ -40,6 +42,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart

/** Models the UI state for the device entry icon foreground view (displayed icon). */
@OptIn(FlowPreview::class)
@ExperimentalCoroutinesApi
@SysUISingleton
class DeviceEntryForegroundViewModel
@@ -97,7 +100,7 @@ constructor(
    private val padding: Flow<Int> =
        deviceEntryUdfpsInteractor.isUdfpsSupported.flatMapLatest { udfpsSupported ->
            if (udfpsSupported) {
                udfpsOverlayInteractor.iconPadding
                udfpsOverlayInteractor.iconPadding.debounce(udfpsPaddingDebounceDuration.toLong())
            } else {
                configurationInteractor.scaleForResolution.map { scale ->
                    (context.resources.getDimensionPixelSize(R.dimen.lock_icon_padding) * scale)
@@ -120,6 +123,9 @@ constructor(
            )
        }

    private val udfpsPaddingDebounceDuration: Int
        get() = context.resources.getInteger(R.integer.udfps_padding_debounce_duration)

    data class ForegroundIconViewModel(
        val type: DeviceEntryIconView.IconType,
        val useAodVariant: Boolean,