From af05028e78c51817370e548e1d54be5505bf5755 Mon Sep 17 00:00:00 2001 From: Milton Wu Date: Tue, 24 May 2022 22:28:47 +0800 Subject: [PATCH] Update fingerprint icon layout size The fingerprint icon height and width in LayoutParams are not sync with its measuredHeight and measuredWidth which are set inside UdfpsDialogMeasureAdapter, and it causes a icon truncat issue after requestLayout() is triggered. Bug: 232744799 Test: Trigger a fail UDFPS on app, and make sure icon not truncate Test: atest AuthBiometricFingerprintViewTest AuthContainerViewTest \ UdfpsDialogMeasureAdapterTest Change-Id: I9e6cce1fa242967164cf07140d7256ebe891cc46 --- .../AuthBiometricFingerprintIconController.kt | 14 +++++++++++--- .../biometrics/AuthBiometricFingerprintView.kt | 7 +++++++ .../systemui/biometrics/AuthContainerView.java | 2 ++ .../biometrics/UdfpsDialogMeasureAdapter.java | 13 +++++++++---- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt index cd16379cd5b4c..606a73a6ac382 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintIconController.kt @@ -36,12 +36,20 @@ open class AuthBiometricFingerprintIconController( iconView: ImageView ) : AuthIconController(context, iconView) { + var iconLayoutParamsSize = 0 + set(value) { + if (field == value) { + return + } + iconView.layoutParams.width = value + iconView.layoutParams.height = value + field = value + } + init { - val size = context.resources.getDimensionPixelSize( + iconLayoutParamsSize = context.resources.getDimensionPixelSize( R.dimen.biometric_dialog_fingerprint_icon_size ) - iconView.layoutParams.width = size - iconView.layoutParams.height = size } override fun updateIcon(@BiometricState lastState: Int, @BiometricState newState: Int) { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.kt index ebed2962a33b2..24046f08e4894 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricFingerprintView.kt @@ -88,6 +88,13 @@ open class AuthBiometricFingerprintView( override fun createIconController(): AuthIconController = AuthBiometricFingerprintIconController(mContext, mIconView) + fun updateOverrideIconLayoutParamsSize() { + udfpsAdapter?.let { + (mIconController as? AuthBiometricFingerprintIconController)?.iconLayoutParamsSize = + it.getSensorDiameter(scaleFactorProvider?.provide() ?: 1.0f) + } + } + override fun onAttachedToWindow() { super.onAttachedToWindow() showTouchSensorString() diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java index 3c2de895bf267..8d4f9a9d04c66 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java @@ -304,6 +304,7 @@ public class AuthContainerView extends LinearLayout R.layout.auth_biometric_fingerprint_and_face_view, null, false); fingerprintAndFaceView.setSensorProperties(fpProperties); fingerprintAndFaceView.setScaleFactorProvider(config.mScaleProvider); + fingerprintAndFaceView.updateOverrideIconLayoutParamsSize(); mBiometricView = fingerprintAndFaceView; } else if (fpProperties != null) { final AuthBiometricFingerprintView fpView = @@ -311,6 +312,7 @@ public class AuthContainerView extends LinearLayout R.layout.auth_biometric_fingerprint_view, null, false); fpView.setSensorProperties(fpProperties); fpView.setScaleFactorProvider(config.mScaleProvider); + fpView.updateOverrideIconLayoutParamsSize(); mBiometricView = fpView; } else if (faceProperties != null) { mBiometricView = (AuthBiometricFaceView) layoutInflater.inflate( diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java index 2ab97e7cbf230..43745bf74aae6 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java @@ -90,6 +90,13 @@ public class UdfpsDialogMeasureAdapter { return mBottomSpacerHeight; } + /** + * @return sensor diameter size as scaleFactor + */ + public int getSensorDiameter(float scaleFactor) { + return (int) (scaleFactor * mSensorProps.getLocation().sensorRadius * 2); + } + @NonNull private AuthDialog.LayoutParams onMeasureInternalPortrait(int width, int height, float scaleFactor) { @@ -108,8 +115,7 @@ public class UdfpsDialogMeasureAdapter { // Go through each of the children and do the custom measurement. int totalHeight = 0; final int numChildren = mView.getChildCount(); - final int sensorDiameter = - (int) (scaleFactor * mSensorProps.getLocation().sensorRadius * 2); + final int sensorDiameter = getSensorDiameter(scaleFactor); for (int i = 0; i < numChildren; i++) { final View child = mView.getChildAt(i); if (child.getId() == R.id.biometric_icon_frame) { @@ -203,8 +209,7 @@ public class UdfpsDialogMeasureAdapter { final int horizontalSpacerWidth = calculateHorizontalSpacerWidthForLandscape( mSensorProps, displayWidth, dialogMargin, horizontalInset, scaleFactor); - final int sensorDiameter = - (int) (scaleFactor * mSensorProps.getLocation().sensorRadius * 2); + final int sensorDiameter = getSensorDiameter(scaleFactor); final int remeasuredWidth = sensorDiameter + 2 * horizontalSpacerWidth; int remeasuredHeight = 0;