diff options
| author | 2023-02-10 22:40:38 +0000 | |
|---|---|---|
| committer | 2023-02-10 22:40:38 +0000 | |
| commit | 7dddb47ad9a48565714be27867595b8498af3795 (patch) | |
| tree | 4f74cc26eba22aa1f51524893889dfd332b1a70f | |
| parent | 1885fa0a6e223fe2e62a7d6fcfa327a1239b6a1d (diff) | |
| parent | c3738b93f3c4376e445cc3941f4c5c2c68a2da2a (diff) | |
Merge "Cache all lottie assets early for side fingerprint sensor icon view." into tm-qpr-dev
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt | 50 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/biometrics/AuthIconController.kt (renamed from packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricIconController.kt) | 13 |
2 files changed, 51 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt index 1f6f6d97680c..3ea3cd171062 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt @@ -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 } diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricIconController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthIconController.kt index b3b6fa25c9b2..d6ad4da04dbe 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricIconController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthIconController.kt @@ -24,14 +24,15 @@ 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" /** Controller for animating the BiometricPrompt icon/affordance. */ abstract class AuthIconController( - protected val context: Context, - protected val iconView: LottieAnimationView + protected val context: Context, + protected val iconView: LottieAnimationView ) : Animatable2.AnimationCallback() { /** If this controller should ignore events and pause. */ @@ -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) + } + } } |