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

Commit e124cacc authored by Beverly's avatar Beverly
Browse files

Add DeviceEntryIconView after fingerprintProps are initialized

Don't add the view before the properties are initialized. Since the fingerprint
properties comes from FingerprintManager (system server), this can be
delayed and not ready immediately when the Keyguard shows.

Fixes: 326023271
Flag: ACONFIG com.android.systemui.device_entry_udfps_refactor STAGING
Test: atest DefaultDeviceEntrySectionTest FingerprintRepositoryImplTest
Test: manually add a delay to the propx being updated in
FingerprintPropertyRepository, see icon shows correctly when the
properties are initialized after the delay

Change-Id: I110cf8b687967808112b7805238ad2ddccf4f8c6
parent dc5a7c2b
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor
import com.android.systemui.flags.FeatureFlagsClassic
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.ui.binder.DeviceEntryIconViewBinder
import com.android.systemui.keyguard.ui.composable.blueprint.BlueprintAlignmentLines
import com.android.systemui.keyguard.ui.view.DeviceEntryIconView
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryBackgroundViewModel
@@ -78,15 +77,16 @@ constructor(
                    if (DeviceEntryUdfpsRefactor.isEnabled) {
                        DeviceEntryIconView(context, null).apply {
                            id = R.id.device_entry_icon_view
                            DeviceEntryIconViewBinder.bind(
                                applicationScope,
                                this,
                                deviceEntryIconViewModel.get(),
                                deviceEntryForegroundViewModel.get(),
                                deviceEntryBackgroundViewModel.get(),
                                falsingManager.get(),
                                vibratorHelper.get(),
                            )
                            // TODO: b/326624996 Bind the DeviceEntryIcon
                            //                            DeviceEntryIconViewBinder.bind(
                            //                                applicationScope,
                            //                                this,
                            //                                deviceEntryIconViewModel.get(),
                            //                                deviceEntryForegroundViewModel.get(),
                            //                                deviceEntryBackgroundViewModel.get(),
                            //                                falsingManager.get(),
                            //                                vibratorHelper.get(),
                            //                            )
                        }
                    } else {
                        // keyguardBottomAreaRefactor()
+23 −1
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ import kotlinx.coroutines.withContext
 * There is never more than one instance of the FingerprintProperty at any given time.
 */
interface FingerprintPropertyRepository {
    /** Whether the fingerprint properties have been initialized yet. */
    val propertiesInitialized: StateFlow<Boolean>

    /** The id of fingerprint sensor. */
    val sensorId: Flow<Int>
@@ -105,7 +107,16 @@ constructor(
            .stateIn(
                applicationScope,
                started = SharingStarted.Eagerly,
                initialValue = DEFAULT_PROPS,
                initialValue = UNINITIALIZED_PROPS,
            )

    override val propertiesInitialized: StateFlow<Boolean> =
        props
            .map { it != UNINITIALIZED_PROPS }
            .stateIn(
                applicationScope,
                started = SharingStarted.WhileSubscribed(),
                initialValue = props.value != UNINITIALIZED_PROPS,
            )

    override val sensorId: Flow<Int> = props.map { it.sensorId }
@@ -124,6 +135,17 @@ constructor(

    companion object {
        private const val TAG = "FingerprintPropertyRepositoryImpl"
        private val UNINITIALIZED_PROPS =
            FingerprintSensorPropertiesInternal(
                -2 /* sensorId */,
                SensorProperties.STRENGTH_CONVENIENCE,
                0 /* maxEnrollmentsPerUser */,
                listOf<ComponentInfoInternal>(),
                FingerprintSensorProperties.TYPE_UNKNOWN,
                false /* halControlsIllumination */,
                true /* resetLockoutRequiresHardwareAuthToken */,
                listOf<SensorLocationInternal>(SensorLocationInternal.DEFAULT)
            )
        private val DEFAULT_PROPS =
            FingerprintSensorPropertiesInternal(
                -1 /* sensorId */,
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
@@ -39,6 +40,7 @@ constructor(
    configurationInteractor: ConfigurationInteractor,
    displayStateInteractor: DisplayStateInteractor,
) {
    val propertiesInitialized: StateFlow<Boolean> = repository.propertiesInitialized
    val isUdfps: Flow<Boolean> = repository.sensorType.map { it.isUdfps() }

    /**
+22 −0
Original line number Diff line number Diff line
@@ -22,11 +22,14 @@ import android.content.res.ColorStateList
import android.util.StateSet
import android.view.HapticFeedbackConstants
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.common.ui.view.LongPressHandlingView
import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor
import com.android.systemui.keyguard.ui.view.DeviceEntryIconView
import com.android.systemui.keyguard.ui.view.layout.sections.DefaultDeviceEntrySection
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryBackgroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryForegroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryIconViewModel
@@ -51,6 +54,8 @@ object DeviceEntryIconViewBinder {
    @JvmStatic
    fun bind(
        applicationScope: CoroutineScope,
        keyguardRootView: ConstraintLayout,
        section: DefaultDeviceEntrySection,
        view: DeviceEntryIconView,
        viewModel: DeviceEntryIconViewModel,
        fgViewModel: DeviceEntryForegroundViewModel,
@@ -76,6 +81,23 @@ object DeviceEntryIconViewBinder {
                }
            }

        keyguardRootView.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    viewModel.positionAtUdfpsLocation.collect { supportsUdfps ->
                        section.removeViews(keyguardRootView)
                        keyguardRootView.addView(view)
                        val constraintSet = ConstraintSet().apply { clone(keyguardRootView) }
                        section.applyConstraintsAfterPropertiesInitialized(
                            constraintSet,
                            supportsUdfps,
                        )
                        constraintSet.applyTo(keyguardRootView)
                    }
                }
            }
        }

        view.repeatWhenAttached {
            // Repeat on CREATED so that the view will always observe the entire
            // GONE => AOD transition (even though the view may not be visible until the middle
+26 −11
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.view.WindowManager
import androidx.annotation.VisibleForTesting
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.LockIconView
import com.android.keyguard.LockIconViewController
import com.android.systemui.Flags.keyguardBottomAreaRefactor
@@ -56,7 +55,6 @@ class DefaultDeviceEntrySection
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val authController: AuthController,
    private val windowManager: WindowManager,
    private val context: Context,
@@ -69,6 +67,7 @@ constructor(
    private val falsingManager: Lazy<FalsingManager>,
    private val vibratorHelper: Lazy<VibratorHelper>,
) : KeyguardSection() {
    private var deviceEntryIconView: DeviceEntryIconView? = null
    private val deviceEntryIconViewId = R.id.device_entry_icon_view

    override fun addViews(constraintLayout: ConstraintLayout) {
@@ -80,21 +79,22 @@ constructor(
            notificationPanelView.removeView(it)
        }

        val view =
        if (DeviceEntryUdfpsRefactor.isEnabled) {
            deviceEntryIconView =
                DeviceEntryIconView(context, null).apply { id = deviceEntryIconViewId }
        } else {
            // keyguardBottomAreaRefactor()
                LockIconView(context, null).apply { id = R.id.lock_icon_view }
            constraintLayout.addView(LockIconView(context, null).apply { id = R.id.lock_icon_view })
        }
        constraintLayout.addView(view)
    }

    override fun bindData(constraintLayout: ConstraintLayout) {
        if (DeviceEntryUdfpsRefactor.isEnabled) {
            constraintLayout.findViewById<DeviceEntryIconView?>(deviceEntryIconViewId)?.let {
            deviceEntryIconView?.let {
                DeviceEntryIconViewBinder.bind(
                    applicationScope,
                    constraintLayout,
                    this,
                    it,
                    deviceEntryIconViewModel.get(),
                    deviceEntryForegroundViewModel.get(),
@@ -111,7 +111,22 @@ constructor(
    }

    override fun applyConstraints(constraintSet: ConstraintSet) {
        val isUdfpsSupported = keyguardUpdateMonitor.isUdfpsSupported
        if (!DeviceEntryUdfpsRefactor.isEnabled) {
            applyConstraints(constraintSet, authController.isUdfpsSupported)
        }
    }

    fun applyConstraintsAfterPropertiesInitialized(
        constraintSet: ConstraintSet,
        isUdfpsSupported: Boolean
    ) {
        if (DeviceEntryUdfpsRefactor.isUnexpectedlyInLegacyMode()) {
            return
        }
        applyConstraints(constraintSet, isUdfpsSupported)
    }

    private fun applyConstraints(constraintSet: ConstraintSet, isUdfpsSupported: Boolean) {
        val scaleFactor: Float = authController.scaleFactor
        val mBottomPaddingPx =
            context.resources.getDimensionPixelSize(R.dimen.lock_icon_margin_bottom)
Loading