From b7e2433127c3d5ac8bc19dd2edf31a9004ecfa89 Mon Sep 17 00:00:00 2001 From: Joe Bolinger Date: Tue, 1 Feb 2022 14:47:30 -0800 Subject: [PATCH] Remove duplicated UDFPS view into single fingerprint view. Bug: 217393533 Test: manual (using BP test app) Change-Id: I9969bf26f119b2e0b267f9363f6084f8316040b1 --- .../res/layout/auth_biometric_udfps_view.xml | 26 ------ .../AuthBiometricFingerprintView.java | 51 ++++++++++++ .../biometrics/AuthBiometricUdfpsView.java | 80 ------------------- .../biometrics/AuthContainerView.java | 18 ++--- .../systemui/biometrics/UdfpsBpView.kt | 2 +- 5 files changed, 59 insertions(+), 118 deletions(-) delete mode 100644 packages/SystemUI/res/layout/auth_biometric_udfps_view.xml delete mode 100644 packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricUdfpsView.java diff --git a/packages/SystemUI/res/layout/auth_biometric_udfps_view.xml b/packages/SystemUI/res/layout/auth_biometric_udfps_view.xml deleted file mode 100644 index 238288eb9f69c..0000000000000 --- a/packages/SystemUI/res/layout/auth_biometric_udfps_view.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.java index ee602bc9cb78d..4242c9bbfff6d 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.java @@ -17,11 +17,15 @@ package com.android.systemui.biometrics; +import android.annotation.NonNull; import android.content.Context; import android.graphics.drawable.AnimatedVectorDrawable; import android.graphics.drawable.Drawable; +import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.util.AttributeSet; import android.util.Log; +import android.widget.FrameLayout; +import android.widget.TextView; import androidx.annotation.Nullable; @@ -31,6 +35,9 @@ public class AuthBiometricFingerprintView extends AuthBiometricView { private static final String TAG = "BiometricPrompt/AuthBiometricFingerprintView"; + private boolean mIsUdfps = false; + @Nullable private UdfpsDialogMeasureAdapter mUdfpsAdapter; + public AuthBiometricFingerprintView(Context context) { this(context, null); } @@ -39,6 +46,50 @@ public class AuthBiometricFingerprintView extends AuthBiometricView { super(context, attrs); } + @Override + AuthDialog.LayoutParams onMeasureInternal(int width, int height) { + final AuthDialog.LayoutParams layoutParams = super.onMeasureInternal(width, height); + return mUdfpsAdapter != null + ? mUdfpsAdapter.onMeasureInternal(width, height, layoutParams) + : layoutParams; + } + + /** + * Set the properties of this sensor so the view can be customized prior to layout. + * + * @param sensorProps sensor properties + */ + public void setSensorProperties(@NonNull FingerprintSensorPropertiesInternal sensorProps) { + mIsUdfps = sensorProps.isAnyUdfpsType(); + mUdfpsAdapter = mIsUdfps ? new UdfpsDialogMeasureAdapter(this, sensorProps) : null; + } + + @Override + void onLayoutInternal() { + super.onLayoutInternal(); + + if (mUdfpsAdapter != null) { + // Move the UDFPS icon and indicator text if necessary. This probably only needs to happen + // for devices where the UDFPS sensor is too low. + // TODO(b/201510778): Update this logic to support cases where the sensor or text overlap + // the button bar area. + final int bottomSpacerHeight = mUdfpsAdapter.getBottomSpacerHeight(); + Log.w(TAG, "bottomSpacerHeight: " + bottomSpacerHeight); + if (bottomSpacerHeight < 0) { + FrameLayout iconFrame = findViewById(R.id.biometric_icon_frame); + iconFrame.setTranslationY(-bottomSpacerHeight); + + TextView indicator = findViewById(R.id.indicator); + indicator.setTranslationY(-bottomSpacerHeight); + } + } + } + + /** If this view is for a UDFPS sensor. */ + public boolean isUdfps() { + return mIsUdfps; + } + @Override protected int getDelayAfterAuthenticatedDurationMs() { return 0; diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricUdfpsView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricUdfpsView.java deleted file mode 100644 index d80d9cc9d62dc..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricUdfpsView.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2020 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.annotation.NonNull; -import android.annotation.Nullable; -import android.content.Context; -import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; -import android.util.AttributeSet; -import android.util.Log; -import android.widget.FrameLayout; -import android.widget.TextView; - -import com.android.systemui.R; - -/** - * Manages the layout for under-display fingerprint sensors (UDFPS). Ensures that UI elements - * do not overlap with - */ -public class AuthBiometricUdfpsView extends AuthBiometricFingerprintView { - private static final String TAG = "AuthBiometricUdfpsView"; - - @Nullable private UdfpsDialogMeasureAdapter mMeasureAdapter; - - public AuthBiometricUdfpsView(Context context) { - this(context, null /* attrs */); - } - - public AuthBiometricUdfpsView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - void setSensorProps(@NonNull FingerprintSensorPropertiesInternal sensorProps) { - if (mMeasureAdapter == null || mMeasureAdapter.getSensorProps() != sensorProps) { - mMeasureAdapter = new UdfpsDialogMeasureAdapter(this, sensorProps); - } - } - - @Override - @NonNull - AuthDialog.LayoutParams onMeasureInternal(int width, int height) { - final AuthDialog.LayoutParams layoutParams = super.onMeasureInternal(width, height); - return mMeasureAdapter != null - ? mMeasureAdapter.onMeasureInternal(width, height, layoutParams) - : layoutParams; - } - - @Override - void onLayoutInternal() { - super.onLayoutInternal(); - - // Move the UDFPS icon and indicator text if necessary. This probably only needs to happen - // for devices where the UDFPS sensor is too low. - // TODO(b/201510778): Update this logic to support cases where the sensor or text overlap - // the button bar area. - final int bottomSpacerHeight = mMeasureAdapter.getBottomSpacerHeight(); - Log.w(TAG, "bottomSpacerHeight: " + bottomSpacerHeight); - if (bottomSpacerHeight < 0) { - FrameLayout iconFrame = findViewById(R.id.biometric_icon_frame); - iconFrame.setTranslationY(-bottomSpacerHeight); - - TextView indicator = findViewById(R.id.indicator); - indicator.setTranslationY(-bottomSpacerHeight); - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java index 21edb2478c797..c63aa7ac648a8 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java @@ -319,15 +319,11 @@ public class AuthContainerView extends LinearLayout } } - if (sensorProps.isAnyUdfpsType()) { - AuthBiometricUdfpsView udfpsView = (AuthBiometricUdfpsView) factory - .inflate(R.layout.auth_biometric_udfps_view, null, false); - udfpsView.setSensorProps(sensorProps); - mBiometricView = udfpsView; - } else { - mBiometricView = (AuthBiometricFingerprintView) factory - .inflate(R.layout.auth_biometric_fingerprint_view, null, false); - } + + final AuthBiometricFingerprintView fpView = (AuthBiometricFingerprintView) + factory.inflate(R.layout.auth_biometric_fingerprint_view, null, false); + fpView.setSensorProperties(sensorProps); + mBiometricView = fpView; } else if (Utils.containsSensorId(mFaceProps, singleSensorAuthId)) { mBiometricView = (AuthBiometricFaceView) factory.inflate(R.layout.auth_biometric_face_view, null, false); @@ -555,8 +551,8 @@ public class AuthContainerView extends LinearLayout } private static boolean shouldUpdatePositionForUdfps(@NonNull View view) { - if (view instanceof AuthBiometricUdfpsView) { - return true; + if (view instanceof AuthBiometricFingerprintView) { + return ((AuthBiometricFingerprintView) view).isUdfps(); } if (view instanceof AuthBiometricFaceToFingerprintView) { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsBpView.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsBpView.kt index 6607915fac9d9..cc4e2af9dfa0d 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsBpView.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsBpView.kt @@ -23,7 +23,7 @@ import android.util.AttributeSet * * Currently doesn't draw anything. * - * Note that [AuthBiometricUdfpsView] also shows UDFPS animations. At some point we should + * Note that [AuthBiometricFingerprintView] also shows UDFPS animations. At some point we should * de-dupe this if necessary. */ class UdfpsBpView(context: Context, attrs: AttributeSet?) : UdfpsAnimationView(context, attrs) {