From 8600720815955ba837e81a087780d0273ddc09cf Mon Sep 17 00:00:00 2001
From: LuK1337 <priv.luk@gmail.com>
Date: Fri, 25 Feb 2022 20:32:59 +0100
Subject: [PATCH] Remove navbar inset for UDFPS BiometricPrompt

This is not necessary because BiometricPrompt is not drawn above the
navigation bar.

Change-Id: I7a00a0d6f1b2b68d6c642be03e23849029f8faa1
---
 .../biometrics/UdfpsDialogMeasureAdapter.java | 37 +++++--------------
 1 file changed, 9 insertions(+), 28 deletions(-)

diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java
index 1624d5f68c35..e5f2310c81d1 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsDialogMeasureAdapter.java
@@ -97,10 +97,9 @@ public class UdfpsDialogMeasureAdapter {
         // Navbar + dialogMargin + buttonBar + textIndicator + spacerHeight = sensorDistFromBottom
         final int dialogMargin = getDialogMarginPx();
         final int displayHeight = getWindowBounds().height();
-        final Insets navbarInsets = getNavbarInsets();
         mBottomSpacerHeight = calculateBottomSpacerHeightForPortrait(
                 mSensorProps, displayHeight, textIndicatorHeight, buttonBarHeight,
-                dialogMargin, navbarInsets.bottom);
+                dialogMargin);
 
         // Go through each of the children and do the custom measurement.
         int totalHeight = 0;
@@ -161,17 +160,15 @@ public class UdfpsDialogMeasureAdapter {
         final int topSpacerHeight = getViewHeightPx(R.id.space_above_icon);
         final int textIndicatorHeight = getViewHeightPx(R.id.indicator);
         final int buttonBarHeight = getViewHeightPx(R.id.button_bar);
-        final Insets navbarInsets = getNavbarInsets();
         final int bottomSpacerHeight = calculateBottomSpacerHeightForLandscape(titleHeight,
                 subtitleHeight, descriptionHeight, topSpacerHeight, textIndicatorHeight,
-                buttonBarHeight, navbarInsets.bottom);
+                buttonBarHeight);
 
         // Find the spacer width needed to horizontally align the icon with the sensor.
         final int displayWidth = getWindowBounds().width();
         final int dialogMargin = getDialogMarginPx();
-        final int horizontalInset = navbarInsets.left + navbarInsets.right;
         final int horizontalSpacerWidth = calculateHorizontalSpacerWidthForLandscape(
-                mSensorProps, displayWidth, dialogMargin, horizontalInset);
+                mSensorProps, displayWidth, dialogMargin);
 
         final int sensorDiameter = mSensorProps.getLocation().sensorRadius * 2;
         final int remeasuredWidth = sensorDiameter + 2 * horizontalSpacerWidth;
@@ -236,15 +233,6 @@ public class UdfpsDialogMeasureAdapter {
         return mView.getResources().getDimensionPixelSize(R.dimen.biometric_dialog_border_padding);
     }
 
-    @NonNull
-    private Insets getNavbarInsets() {
-        final WindowManager windowManager = getWindowManager();
-        return windowManager != null && windowManager.getCurrentWindowMetrics() != null
-                ? windowManager.getCurrentWindowMetrics().getWindowInsets()
-                .getInsets(WindowInsets.Type.navigationBars())
-                : Insets.NONE;
-    }
-
     @NonNull
     private Rect getWindowBounds() {
         final WindowManager windowManager = getWindowManager();
@@ -268,8 +256,7 @@ public class UdfpsDialogMeasureAdapter {
     @VisibleForTesting
     static int calculateBottomSpacerHeightForPortrait(
             @NonNull FingerprintSensorPropertiesInternal sensorProperties, int displayHeightPx,
-            int textIndicatorHeightPx, int buttonBarHeightPx, int dialogMarginPx,
-            int navbarBottomInsetPx) {
+            int textIndicatorHeightPx, int buttonBarHeightPx, int dialogMarginPx) {
         final SensorLocationInternal location = sensorProperties.getLocation();
         final int sensorDistanceFromBottom = displayHeightPx
                 - location.sensorLocationY
@@ -278,13 +265,11 @@ public class UdfpsDialogMeasureAdapter {
         final int spacerHeight = sensorDistanceFromBottom
                 - textIndicatorHeightPx
                 - buttonBarHeightPx
-                - dialogMarginPx
-                - navbarBottomInsetPx;
+                - dialogMarginPx;
 
         Log.d(TAG, "Display height: " + displayHeightPx
                 + ", Distance from bottom: " + sensorDistanceFromBottom
                 + ", Bottom margin: " + dialogMarginPx
-                + ", Navbar bottom inset: " + navbarBottomInsetPx
                 + ", Bottom spacer height (portrait): " + spacerHeight);
 
         return spacerHeight;
@@ -297,7 +282,7 @@ public class UdfpsDialogMeasureAdapter {
     @VisibleForTesting
     static int calculateBottomSpacerHeightForLandscape(int titleHeightPx, int subtitleHeightPx,
             int descriptionHeightPx, int topSpacerHeightPx, int textIndicatorHeightPx,
-            int buttonBarHeightPx, int navbarBottomInsetPx) {
+            int buttonBarHeightPx) {
 
         final int dialogHeightAboveIcon = titleHeightPx
                 + subtitleHeightPx
@@ -307,8 +292,7 @@ public class UdfpsDialogMeasureAdapter {
         final int dialogHeightBelowIcon = textIndicatorHeightPx + buttonBarHeightPx;
 
         final int bottomSpacerHeight = dialogHeightAboveIcon
-                - dialogHeightBelowIcon
-                - navbarBottomInsetPx;
+                - dialogHeightBelowIcon;
 
         Log.d(TAG, "Title height: " + titleHeightPx
                 + ", Subtitle height: " + subtitleHeightPx
@@ -316,7 +300,6 @@ public class UdfpsDialogMeasureAdapter {
                 + ", Top spacer height: " + topSpacerHeightPx
                 + ", Text indicator height: " + textIndicatorHeightPx
                 + ", Button bar height: " + buttonBarHeightPx
-                + ", Navbar bottom inset: " + navbarBottomInsetPx
                 + ", Bottom spacer height (landscape): " + bottomSpacerHeight);
 
         return bottomSpacerHeight;
@@ -330,20 +313,18 @@ public class UdfpsDialogMeasureAdapter {
     @VisibleForTesting
     static int calculateHorizontalSpacerWidthForLandscape(
             @NonNull FingerprintSensorPropertiesInternal sensorProperties, int displayWidthPx,
-            int dialogMarginPx, int navbarHorizontalInsetPx) {
+            int dialogMarginPx) {
         final SensorLocationInternal location = sensorProperties.getLocation();
         final int sensorDistanceFromEdge = displayWidthPx
                 - location.sensorLocationY
                 - location.sensorRadius;
 
         final int horizontalPadding = sensorDistanceFromEdge
-                - dialogMarginPx
-                - navbarHorizontalInsetPx;
+                - dialogMarginPx;
 
         Log.d(TAG, "Display width: " + displayWidthPx
                 + ", Distance from edge: " + sensorDistanceFromEdge
                 + ", Dialog margin: " + dialogMarginPx
-                + ", Navbar horizontal inset: " + navbarHorizontalInsetPx
                 + ", Horizontal spacer width (landscape): " + horizontalPadding);
 
         return horizontalPadding;
-- 
GitLab