Merge "Correctly scale down UDFPS offset for diff display" into tm-d1-dev

This commit is contained in:
Joshua Mccloskey
2022-05-13 23:17:40 +00:00
committed by Android (Google) Code Review
5 changed files with 58 additions and 20 deletions

View File

@@ -22,6 +22,7 @@ import android.util.Log
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.TextView import android.widget.TextView
import com.android.systemui.R import com.android.systemui.R
import com.android.systemui.biometrics.AuthController.ScaleFactorProvider
private const val TAG = "AuthBiometricFingerprintView" private const val TAG = "AuthBiometricFingerprintView"
@@ -35,6 +36,7 @@ open class AuthBiometricFingerprintView(
private set private set
private var udfpsAdapter: UdfpsDialogMeasureAdapter? = null private var udfpsAdapter: UdfpsDialogMeasureAdapter? = null
private var scaleFactorProvider: ScaleFactorProvider? = null
/** Set the [sensorProps] of this sensor so the view can be customized prior to layout. */ /** Set the [sensorProps] of this sensor so the view can be customized prior to layout. */
fun setSensorProperties(sensorProps: FingerprintSensorPropertiesInternal) { fun setSensorProperties(sensorProps: FingerprintSensorPropertiesInternal) {
@@ -42,9 +44,15 @@ open class AuthBiometricFingerprintView(
udfpsAdapter = if (isUdfps) UdfpsDialogMeasureAdapter(this, sensorProps) else null udfpsAdapter = if (isUdfps) UdfpsDialogMeasureAdapter(this, sensorProps) else null
} }
fun setScaleFactorProvider(scaleProvider: ScaleFactorProvider?) {
scaleFactorProvider = scaleProvider
}
override fun onMeasureInternal(width: Int, height: Int): AuthDialog.LayoutParams { override fun onMeasureInternal(width: Int, height: Int): AuthDialog.LayoutParams {
val layoutParams = super.onMeasureInternal(width, height) val layoutParams = super.onMeasureInternal(width, height)
return udfpsAdapter?.onMeasureInternal(width, height, layoutParams) ?: layoutParams val scale = scaleFactorProvider?.provide() ?: 1.0f
return udfpsAdapter?.onMeasureInternal(width, height, layoutParams,
scale) ?: layoutParams
} }
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {

View File

@@ -56,6 +56,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.animation.Interpolators; import com.android.systemui.animation.Interpolators;
import com.android.systemui.biometrics.AuthController.ScaleFactorProvider;
import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.keyguard.WakefulnessLifecycle; import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.util.concurrency.DelayableExecutor; import com.android.systemui.util.concurrency.DelayableExecutor;
@@ -133,6 +134,7 @@ public class AuthContainerView extends LinearLayout
long mRequestId = -1; long mRequestId = -1;
boolean mSkipAnimation = false; boolean mSkipAnimation = false;
@BiometricMultiSensorMode int mMultiSensorConfig = BIOMETRIC_MULTI_SENSOR_DEFAULT; @BiometricMultiSensorMode int mMultiSensorConfig = BIOMETRIC_MULTI_SENSOR_DEFAULT;
ScaleFactorProvider mScaleProvider;
} }
public static class Builder { public static class Builder {
@@ -196,6 +198,11 @@ public class AuthContainerView extends LinearLayout
return this; return this;
} }
public Builder setScaleFactorProvider(ScaleFactorProvider scaleProvider) {
mConfig.mScaleProvider = scaleProvider;
return this;
}
public AuthContainerView build(@Background DelayableExecutor bgExecutor, int[] sensorIds, public AuthContainerView build(@Background DelayableExecutor bgExecutor, int[] sensorIds,
@Nullable List<FingerprintSensorPropertiesInternal> fpProps, @Nullable List<FingerprintSensorPropertiesInternal> fpProps,
@Nullable List<FaceSensorPropertiesInternal> faceProps, @Nullable List<FaceSensorPropertiesInternal> faceProps,
@@ -296,12 +303,14 @@ public class AuthContainerView extends LinearLayout
(AuthBiometricFingerprintAndFaceView) layoutInflater.inflate( (AuthBiometricFingerprintAndFaceView) layoutInflater.inflate(
R.layout.auth_biometric_fingerprint_and_face_view, null, false); R.layout.auth_biometric_fingerprint_and_face_view, null, false);
fingerprintAndFaceView.setSensorProperties(fpProperties); fingerprintAndFaceView.setSensorProperties(fpProperties);
fingerprintAndFaceView.setScaleFactorProvider(config.mScaleProvider);
mBiometricView = fingerprintAndFaceView; mBiometricView = fingerprintAndFaceView;
} else if (fpProperties != null) { } else if (fpProperties != null) {
final AuthBiometricFingerprintView fpView = final AuthBiometricFingerprintView fpView =
(AuthBiometricFingerprintView) layoutInflater.inflate( (AuthBiometricFingerprintView) layoutInflater.inflate(
R.layout.auth_biometric_fingerprint_view, null, false); R.layout.auth_biometric_fingerprint_view, null, false);
fpView.setSensorProperties(fpProperties); fpView.setSensorProperties(fpProperties);
fpView.setScaleFactorProvider(config.mScaleProvider);
mBiometricView = fpView; mBiometricView = fpView;
} else if (faceProperties != null) { } else if (faceProperties != null) {
mBiometricView = (AuthBiometricFaceView) layoutInflater.inflate( mBiometricView = (AuthBiometricFaceView) layoutInflater.inflate(

View File

@@ -1037,10 +1037,23 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
.setOperationId(operationId) .setOperationId(operationId)
.setRequestId(requestId) .setRequestId(requestId)
.setMultiSensorConfig(multiSensorConfig) .setMultiSensorConfig(multiSensorConfig)
.setScaleFactorProvider(() -> {
return getScaleFactor();
})
.build(bgExecutor, sensorIds, mFpProps, mFaceProps, wakefulnessLifecycle, .build(bgExecutor, sensorIds, mFpProps, mFaceProps, wakefulnessLifecycle,
userManager, lockPatternUtils); userManager, lockPatternUtils);
} }
/**
* Provides a float that represents the resolution scale(if the controller is for UDFPS).
*/
public interface ScaleFactorProvider {
/**
* Returns a float representing the scaled resolution(if the controller if for UDFPS).
*/
float provide();
}
/** /**
* AuthController callback used to receive signal for when biometric authenticators are * AuthController callback used to receive signal for when biometric authenticators are
* registered. * registered.

View File

@@ -64,15 +64,16 @@ public class UdfpsDialogMeasureAdapter {
@NonNull @NonNull
AuthDialog.LayoutParams onMeasureInternal( AuthDialog.LayoutParams onMeasureInternal(
int width, int height, @NonNull AuthDialog.LayoutParams layoutParams) { int width, int height, @NonNull AuthDialog.LayoutParams layoutParams,
float scaleFactor) {
final int displayRotation = mView.getDisplay().getRotation(); final int displayRotation = mView.getDisplay().getRotation();
switch (displayRotation) { switch (displayRotation) {
case Surface.ROTATION_0: case Surface.ROTATION_0:
return onMeasureInternalPortrait(width, height); return onMeasureInternalPortrait(width, height, scaleFactor);
case Surface.ROTATION_90: case Surface.ROTATION_90:
case Surface.ROTATION_270: case Surface.ROTATION_270:
return onMeasureInternalLandscape(width, height); return onMeasureInternalLandscape(width, height, scaleFactor);
default: default:
Log.e(TAG, "Unsupported display rotation: " + displayRotation); Log.e(TAG, "Unsupported display rotation: " + displayRotation);
return layoutParams; return layoutParams;
@@ -90,7 +91,8 @@ public class UdfpsDialogMeasureAdapter {
} }
@NonNull @NonNull
private AuthDialog.LayoutParams onMeasureInternalPortrait(int width, int height) { private AuthDialog.LayoutParams onMeasureInternalPortrait(int width, int height,
float scaleFactor) {
final WindowMetrics windowMetrics = mWindowManager.getMaximumWindowMetrics(); final WindowMetrics windowMetrics = mWindowManager.getMaximumWindowMetrics();
// Figure out where the bottom of the sensor anim should be. // Figure out where the bottom of the sensor anim should be.
@@ -101,12 +103,13 @@ public class UdfpsDialogMeasureAdapter {
final Insets navbarInsets = getNavbarInsets(windowMetrics); final Insets navbarInsets = getNavbarInsets(windowMetrics);
mBottomSpacerHeight = calculateBottomSpacerHeightForPortrait( mBottomSpacerHeight = calculateBottomSpacerHeightForPortrait(
mSensorProps, displayHeight, textIndicatorHeight, buttonBarHeight, mSensorProps, displayHeight, textIndicatorHeight, buttonBarHeight,
dialogMargin, navbarInsets.bottom); dialogMargin, navbarInsets.bottom, scaleFactor);
// Go through each of the children and do the custom measurement. // Go through each of the children and do the custom measurement.
int totalHeight = 0; int totalHeight = 0;
final int numChildren = mView.getChildCount(); final int numChildren = mView.getChildCount();
final int sensorDiameter = mSensorProps.getLocation().sensorRadius * 2; final int sensorDiameter =
(int) (scaleFactor * mSensorProps.getLocation().sensorRadius * 2);
for (int i = 0; i < numChildren; i++) { for (int i = 0; i < numChildren; i++) {
final View child = mView.getChildAt(i); final View child = mView.getChildAt(i);
if (child.getId() == R.id.biometric_icon_frame) { if (child.getId() == R.id.biometric_icon_frame) {
@@ -176,7 +179,8 @@ public class UdfpsDialogMeasureAdapter {
} }
@NonNull @NonNull
private AuthDialog.LayoutParams onMeasureInternalLandscape(int width, int height) { private AuthDialog.LayoutParams onMeasureInternalLandscape(int width, int height,
float scaleFactor) {
final WindowMetrics windowMetrics = mWindowManager.getMaximumWindowMetrics(); final WindowMetrics windowMetrics = mWindowManager.getMaximumWindowMetrics();
// Find the spacer height needed to vertically align the icon with the sensor. // Find the spacer height needed to vertically align the icon with the sensor.
@@ -197,9 +201,10 @@ public class UdfpsDialogMeasureAdapter {
final int dialogMargin = getDialogMarginPx(); final int dialogMargin = getDialogMarginPx();
final int horizontalInset = navbarInsets.left + navbarInsets.right; final int horizontalInset = navbarInsets.left + navbarInsets.right;
final int horizontalSpacerWidth = calculateHorizontalSpacerWidthForLandscape( final int horizontalSpacerWidth = calculateHorizontalSpacerWidthForLandscape(
mSensorProps, displayWidth, dialogMargin, horizontalInset); mSensorProps, displayWidth, dialogMargin, horizontalInset, scaleFactor);
final int sensorDiameter = mSensorProps.getLocation().sensorRadius * 2; final int sensorDiameter =
(int) (scaleFactor * mSensorProps.getLocation().sensorRadius * 2);
final int remeasuredWidth = sensorDiameter + 2 * horizontalSpacerWidth; final int remeasuredWidth = sensorDiameter + 2 * horizontalSpacerWidth;
int remeasuredHeight = 0; int remeasuredHeight = 0;
@@ -281,11 +286,11 @@ public class UdfpsDialogMeasureAdapter {
static int calculateBottomSpacerHeightForPortrait( static int calculateBottomSpacerHeightForPortrait(
@NonNull FingerprintSensorPropertiesInternal sensorProperties, int displayHeightPx, @NonNull FingerprintSensorPropertiesInternal sensorProperties, int displayHeightPx,
int textIndicatorHeightPx, int buttonBarHeightPx, int dialogMarginPx, int textIndicatorHeightPx, int buttonBarHeightPx, int dialogMarginPx,
int navbarBottomInsetPx) { int navbarBottomInsetPx, float scaleFactor) {
final SensorLocationInternal location = sensorProperties.getLocation(); final SensorLocationInternal location = sensorProperties.getLocation();
final int sensorDistanceFromBottom = displayHeightPx final int sensorDistanceFromBottom = displayHeightPx
- location.sensorLocationY - (int) (scaleFactor * location.sensorLocationY)
- location.sensorRadius; - (int) (scaleFactor * location.sensorRadius);
final int spacerHeight = sensorDistanceFromBottom final int spacerHeight = sensorDistanceFromBottom
- textIndicatorHeightPx - textIndicatorHeightPx
@@ -298,7 +303,8 @@ public class UdfpsDialogMeasureAdapter {
+ ", Distance from bottom: " + sensorDistanceFromBottom + ", Distance from bottom: " + sensorDistanceFromBottom
+ ", Bottom margin: " + dialogMarginPx + ", Bottom margin: " + dialogMarginPx
+ ", Navbar bottom inset: " + navbarBottomInsetPx + ", Navbar bottom inset: " + navbarBottomInsetPx
+ ", Bottom spacer height (portrait): " + spacerHeight); + ", Bottom spacer height (portrait): " + spacerHeight
+ ", Scale Factor: " + scaleFactor);
} }
return spacerHeight; return spacerHeight;
@@ -346,11 +352,11 @@ public class UdfpsDialogMeasureAdapter {
@VisibleForTesting @VisibleForTesting
static int calculateHorizontalSpacerWidthForLandscape( static int calculateHorizontalSpacerWidthForLandscape(
@NonNull FingerprintSensorPropertiesInternal sensorProperties, int displayWidthPx, @NonNull FingerprintSensorPropertiesInternal sensorProperties, int displayWidthPx,
int dialogMarginPx, int navbarHorizontalInsetPx) { int dialogMarginPx, int navbarHorizontalInsetPx, float scaleFactor) {
final SensorLocationInternal location = sensorProperties.getLocation(); final SensorLocationInternal location = sensorProperties.getLocation();
final int sensorDistanceFromEdge = displayWidthPx final int sensorDistanceFromEdge = displayWidthPx
- location.sensorLocationY - (int) (scaleFactor * location.sensorLocationY)
- location.sensorRadius; - (int) (scaleFactor * location.sensorRadius);
final int horizontalPadding = sensorDistanceFromEdge final int horizontalPadding = sensorDistanceFromEdge
- dialogMarginPx - dialogMarginPx
@@ -361,7 +367,8 @@ public class UdfpsDialogMeasureAdapter {
+ ", Distance from edge: " + sensorDistanceFromEdge + ", Distance from edge: " + sensorDistanceFromEdge
+ ", Dialog margin: " + dialogMarginPx + ", Dialog margin: " + dialogMarginPx
+ ", Navbar horizontal inset: " + navbarHorizontalInsetPx + ", Navbar horizontal inset: " + navbarHorizontalInsetPx
+ ", Horizontal spacer width (landscape): " + horizontalPadding); + ", Horizontal spacer width (landscape): " + horizontalPadding
+ ", Scale Factor: " + scaleFactor);
} }
return horizontalPadding; return horizontalPadding;

View File

@@ -70,7 +70,7 @@ public class UdfpsDialogMeasureAdapterTest extends SysuiTestCase {
assertEquals(970, assertEquals(970,
UdfpsDialogMeasureAdapter.calculateBottomSpacerHeightForPortrait( UdfpsDialogMeasureAdapter.calculateBottomSpacerHeightForPortrait(
props, displayHeightPx, textIndicatorHeightPx, buttonBarHeightPx, props, displayHeightPx, textIndicatorHeightPx, buttonBarHeightPx,
dialogBottomMarginPx, navbarHeightPx dialogBottomMarginPx, navbarHeightPx, 1.0f /* resolutionScale */
)); ));
} }
@@ -135,6 +135,7 @@ public class UdfpsDialogMeasureAdapterTest extends SysuiTestCase {
assertEquals(1205, assertEquals(1205,
UdfpsDialogMeasureAdapter.calculateHorizontalSpacerWidthForLandscape( UdfpsDialogMeasureAdapter.calculateHorizontalSpacerWidthForLandscape(
props, displayWidthPx, dialogMarginPx, navbarHorizontalInsetPx)); props, displayWidthPx, dialogMarginPx, navbarHorizontalInsetPx,
1.0f /* resolutionScale */));
} }
} }