From 9e5e59b55201d50f9c251c1a2c72231c9bb21808 Mon Sep 17 00:00:00 2001 From: Kevin Chyn Date: Thu, 4 Mar 2021 17:53:11 -0800 Subject: [PATCH] Fix NPE crashes during UDFPS BiometricPrompt BiometricPrompt for UDFPS used to be working by coincidence. We were always passing null into non-null places. Just it actually broke now. Fixes: 181884785 Test: manual Test: atest com.android.systemui.biometrics Change-Id: Iae22966f0a3ea0bfc543cd01e4b3373d1cead937 --- .../res/layout/udfps_animation_view_bp.xml | 22 ++++++++++ .../biometrics/UdfpsAnimationView.java | 13 +++++- .../biometrics/UdfpsAnimationViewBp.java | 42 +++++++++++++++++++ .../systemui/biometrics/UdfpsController.java | 22 ++++++---- 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 packages/SystemUI/res/layout/udfps_animation_view_bp.xml create mode 100644 packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewBp.java diff --git a/packages/SystemUI/res/layout/udfps_animation_view_bp.xml b/packages/SystemUI/res/layout/udfps_animation_view_bp.xml new file mode 100644 index 0000000000000..0cfbf2e61dd12 --- /dev/null +++ b/packages/SystemUI/res/layout/udfps_animation_view_bp.xml @@ -0,0 +1,22 @@ + + + + diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java index f4dd181eb329d..6666c8dda5272 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationView.java @@ -62,7 +62,10 @@ public abstract class UdfpsAnimationView extends FrameLayout implements DozeRece @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); - getUdfpsAnimation().onDestroy(); + + if (getUdfpsAnimation() != null) { + getUdfpsAnimation().onDestroy(); + } } private int expansionToAlpha(float expansion) { @@ -78,11 +81,19 @@ public abstract class UdfpsAnimationView extends FrameLayout implements DozeRece } void onIlluminationStarting() { + if (getUdfpsAnimation() == null) { + return; + } + getUdfpsAnimation().setIlluminationShowing(true); postInvalidate(); } void onIlluminationStopped() { + if (getUdfpsAnimation() == null) { + return; + } + getUdfpsAnimation().setIlluminationShowing(false); postInvalidate(); } diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewBp.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewBp.java new file mode 100644 index 0000000000000..515b442b61f64 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsAnimationViewBp.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.biometrics; + +import android.content.Context; +import android.util.AttributeSet; + +import androidx.annotation.Nullable; + +/** + * Class that coordinates non-HBM animations during BiometricPrompt. + * + * Note that {@link AuthBiometricUdfpsView} also shows UDFPS animations. At some point we should + * de-dupe this if necessary. This will probably happen once the top-level TODO in UdfpsController + * is completed (inflate operation-specific views, instead of inflating generic udfps_view and + * adding operation-specific animations to it). + */ +public class UdfpsAnimationViewBp extends UdfpsAnimationView { + public UdfpsAnimationViewBp(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + @Nullable + @Override + protected UdfpsAnimation getUdfpsAnimation() { + return null; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java index e1d7eb3cbb193..be27b24c90ac5 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java @@ -358,23 +358,29 @@ public class UdfpsController implements DozeReceiver, HbmCallback { switch (reason) { case IUdfpsOverlayController.REASON_ENROLL_FIND_SENSOR: case IUdfpsOverlayController.REASON_ENROLL_ENROLLING: { - final UdfpsAnimationViewEnroll animation = (UdfpsAnimationViewEnroll) + final UdfpsAnimationViewEnroll view = (UdfpsAnimationViewEnroll) inflater.inflate(R.layout.udfps_animation_view_enroll, null, false); - animation.setEnrollHelper(mEnrollHelper); - return animation; + view.setEnrollHelper(mEnrollHelper); + return view; + } + + case IUdfpsOverlayController.REASON_AUTH_BP: { + final UdfpsAnimationViewBp view = (UdfpsAnimationViewBp) + inflater.inflate(R.layout.udfps_animation_view_bp, null, false); + return view; } case IUdfpsOverlayController.REASON_AUTH_FPM_KEYGUARD: { - final UdfpsAnimationViewKeyguard animation = (UdfpsAnimationViewKeyguard) + final UdfpsAnimationViewKeyguard view = (UdfpsAnimationViewKeyguard) inflater.inflate(R.layout.udfps_animation_view_keyguard, null, false); - animation.setStatusBarStateController(mStatusBarStateController); - return animation; + view.setStatusBarStateController(mStatusBarStateController); + return view; } case IUdfpsOverlayController.REASON_AUTH_FPM_OTHER: { - final UdfpsAnimationViewFpmOther animation = (UdfpsAnimationViewFpmOther) + final UdfpsAnimationViewFpmOther view = (UdfpsAnimationViewFpmOther) inflater.inflate(R.layout.udfps_animation_view_fpm_other, null, false); - return animation; + return view; } default: