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

Commit c3738b93 authored by Joe Bolinger's avatar Joe Bolinger
Browse files

Cache all lottie assets early for side fingerprint sensor icon view.

Fix: 267225109
Test: manaul with BP test app (see bug for detailed repro steps)
Change-Id: I414ce0a095dd502f3e880b8a56593f91a1d026d5
parent f38ff6c1
Loading
Loading
Loading
Loading
+40 −10
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.biometrics

import android.annotation.RawRes
import android.content.Context
import android.content.Context.FINGERPRINT_SERVICE
import android.content.res.Configuration
import android.hardware.fingerprint.FingerprintManager
import android.view.DisplayInfo
@@ -66,16 +67,11 @@ open class AuthBiometricFingerprintIconController(
                R.dimen.biometric_dialog_fingerprint_icon_width),
                context.resources.getDimensionPixelSize(
                        R.dimen.biometric_dialog_fingerprint_icon_height))
        var sideFps = false
        (context.getSystemService(Context.FINGERPRINT_SERVICE)
                as FingerprintManager?)?.let { fpm ->
            for (prop in fpm.sensorPropertiesInternal) {
                if (prop.isAnySidefpsType) {
                    sideFps = true
                }
            }
        }
        isSideFps = sideFps
        isSideFps =
            (context.getSystemService(FINGERPRINT_SERVICE) as FingerprintManager?)?.let { fpm ->
                fpm.sensorPropertiesInternal.any { it.isAnySidefpsType }
            } ?: false
        preloadAssets(context)
        val displayInfo = DisplayInfo()
        context.display?.getDisplayInfo(displayInfo)
        if (isSideFps && getRotationFromDefault(displayInfo.rotation) == Surface.ROTATION_180) {
@@ -329,6 +325,40 @@ open class AuthBiometricFingerprintIconController(
        else -> null
    }

    private fun preloadAssets(context: Context) {
        if (isSideFps) {
            cacheLottieAssetsInContext(
                context,
                R.raw.biometricprompt_fingerprint_to_error_landscape,
                R.raw.biometricprompt_folded_base_bottomright,
                R.raw.biometricprompt_folded_base_default,
                R.raw.biometricprompt_folded_base_topleft,
                R.raw.biometricprompt_landscape_base,
                R.raw.biometricprompt_portrait_base_bottomright,
                R.raw.biometricprompt_portrait_base_topleft,
                R.raw.biometricprompt_symbol_error_to_fingerprint_landscape,
                R.raw.biometricprompt_symbol_error_to_fingerprint_portrait_bottomright,
                R.raw.biometricprompt_symbol_error_to_fingerprint_portrait_topleft,
                R.raw.biometricprompt_symbol_error_to_success_landscape,
                R.raw.biometricprompt_symbol_error_to_success_portrait_bottomright,
                R.raw.biometricprompt_symbol_error_to_success_portrait_topleft,
                R.raw.biometricprompt_symbol_fingerprint_to_error_portrait_bottomright,
                R.raw.biometricprompt_symbol_fingerprint_to_error_portrait_topleft,
                R.raw.biometricprompt_symbol_fingerprint_to_success_landscape,
                R.raw.biometricprompt_symbol_fingerprint_to_success_portrait_bottomright,
                R.raw.biometricprompt_symbol_fingerprint_to_success_portrait_topleft
            )
        } else {
            cacheLottieAssetsInContext(
                context,
                R.raw.fingerprint_dialogue_error_to_fingerprint_lottie,
                R.raw.fingerprint_dialogue_error_to_success_lottie,
                R.raw.fingerprint_dialogue_fingerprint_to_error_lottie,
                R.raw.fingerprint_dialogue_fingerprint_to_success_lottie
            )
        }
    }

    override fun onFoldUpdated(isFolded: Boolean) {
        isDeviceFolded = isFolded
    }
+11 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.Drawable
import android.util.Log
import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieCompositionFactory
import com.android.systemui.biometrics.AuthBiometricView.BiometricState

private const val TAG = "AuthIconController"
@@ -94,4 +95,12 @@ abstract class AuthIconController(
    open fun handleAnimationEnd(drawable: Drawable) {}

    open fun onConfigurationChanged(newConfig: Configuration) {}

    // TODO(b/251476085): Migrate this to an extension at the appropriate level?
    /** Load the given [rawResources] immediately so they are cached for use in the [context]. */
    protected fun cacheLottieAssetsInContext(context: Context, vararg rawResources: Int) {
        for (res in rawResources) {
            LottieCompositionFactory.fromRawRes(context, res)
        }
    }
}