Support an x-coordinate for fps location

Test: manual, use AuthRipple adb commands
Bug: 197637248
Change-Id: I3943a65c91702b2c8ca532110ddc5ad05b239195
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 8650654..9f25746 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1559,6 +1559,13 @@
     <!-- Location on the screen of the center of the fingerprint sensor. For devices with under
      display fingerprint sensors, this directly corresponds to the fingerprint sensor's location.
      For devices with sensors on the back of the device, this corresponds to the location on the
+     screen directly in front of the sensor.
+     By default, this is set to @null to use the horizontal center of the screen. -->
+    <dimen name="physical_fingerprint_sensor_center_screen_location_x">@null</dimen>
+
+    <!-- Location on the screen of the center of the fingerprint sensor. For devices with under
+     display fingerprint sensors, this directly corresponds to the fingerprint sensor's location.
+     For devices with sensors on the back of the device, this corresponds to the location on the
      screen directly in front of the sensor. -->
     <dimen name="physical_fingerprint_sensor_center_screen_location_y">610px</dimen>
 
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
index 71445a7..f4b446b 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
@@ -29,6 +29,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.graphics.PointF;
 import android.hardware.biometrics.BiometricAuthenticator.Modality;
 import android.hardware.biometrics.BiometricConstants;
@@ -97,7 +98,7 @@
     private final Provider<UdfpsController> mUdfpsControllerFactory;
     private final Provider<SidefpsController> mSidefpsControllerFactory;
     @Nullable private final PointF mFaceAuthSensorLocation;
-    @Nullable private final PointF mFingerprintLocation;
+    @Nullable private PointF mFingerprintLocation;
     private final Set<Callback> mCallbacks = new HashSet<>();
 
     // TODO: These should just be saved from onSaveState
@@ -481,9 +482,7 @@
                     (float) faceAuthLocation[1]);
         }
 
-        mFingerprintLocation = new PointF(DisplayUtils.getWidth(mContext) / 2,
-                mContext.getResources().getDimensionPixelSize(
-                com.android.systemui.R.dimen.physical_fingerprint_sensor_center_screen_location_y));
+        updateFingerprintLocation();
 
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
@@ -491,6 +490,21 @@
         context.registerReceiver(mBroadcastReceiver, filter);
     }
 
+    private void updateFingerprintLocation() {
+        int xLocation = DisplayUtils.getWidth(mContext) / 2;
+        try {
+            xLocation = mContext.getResources().getDimensionPixelSize(
+                    com.android.systemui.R.dimen
+                            .physical_fingerprint_sensor_center_screen_location_x);
+        } catch (Resources.NotFoundException e) {
+        }
+        int yLocation = mContext.getResources().getDimensionPixelSize(
+                com.android.systemui.R.dimen.physical_fingerprint_sensor_center_screen_location_y);
+        mFingerprintLocation = new PointF(
+                xLocation,
+                yLocation);
+    }
+
     @SuppressWarnings("deprecation")
     @Override
     public void start() {
@@ -767,6 +781,7 @@
     @Override
     protected void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
+        updateFingerprintLocation();
 
         // Save the state of the current dialog (buttons showing, etc)
         if (mCurrentDialog != null) {
@@ -796,6 +811,7 @@
     }
 
     private void onOrientationChanged() {
+        updateFingerprintLocation();
         if (mCurrentDialog != null) {
             mCurrentDialog.onOrientationChanged();
         }
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt
index ba64195..eb6b193 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt
@@ -21,6 +21,7 @@
 import android.content.res.Configuration
 import android.graphics.PointF
 import android.hardware.biometrics.BiometricSourceType
+import android.util.DisplayMetrics
 import android.util.Log
 import androidx.annotation.VisibleForTesting
 import com.android.keyguard.KeyguardUpdateMonitor
@@ -45,6 +46,7 @@
 import javax.inject.Inject
 import javax.inject.Provider
 import com.android.systemui.plugins.statusbar.StatusBarStateController
+import com.android.systemui.util.leak.RotationUtils
 
 private const val WAKE_AND_UNLOCK_FADE_DURATION = 180L
 
@@ -182,7 +184,7 @@
     }
 
     fun updateSensorLocation() {
-        fingerprintSensorLocation = authController.fingerprintSensorLocation
+        updateFingerprintLocation()
         faceSensorLocation = authController.faceAuthSensorLocation
         fingerprintSensorLocation?.let {
             circleReveal = CircleReveal(
@@ -197,6 +199,35 @@
         }
     }
 
+    private fun updateFingerprintLocation() {
+        val displayMetrics = DisplayMetrics()
+        sysuiContext.display?.getRealMetrics(displayMetrics)
+        val width = displayMetrics.widthPixels
+        val height = displayMetrics.heightPixels
+
+        authController.fingerprintSensorLocation?.let {
+            fingerprintSensorLocation = when (RotationUtils.getRotation(sysuiContext)) {
+                RotationUtils.ROTATION_LANDSCAPE -> {
+                    val normalizedYPos: Float = it.y / width
+                    val normalizedXPos: Float = it.x / height
+                    PointF(width * normalizedYPos, height * (1 - normalizedXPos))
+                }
+                RotationUtils.ROTATION_UPSIDE_DOWN -> {
+                    PointF(width - it.x, height - it.y)
+                }
+                RotationUtils.ROTATION_SEASCAPE -> {
+                    val normalizedYPos: Float = it.y / width
+                    val normalizedXPos: Float = it.x / height
+                    PointF(width * (1 - normalizedYPos), height * normalizedXPos)
+                }
+                else -> {
+                    // ROTATION_NONE
+                    PointF(it.x, it.y)
+                }
+            }
+        }
+    }
+
     private fun updateRippleColor() {
         mView.setColor(
             Utils.getColorAttr(sysuiContext, android.R.attr.colorAccent).defaultColor)
@@ -314,10 +345,12 @@
                         }
                     }
                     "fingerprint" -> {
+                        updateSensorLocation()
                         pw.println("fingerprint ripple sensorLocation=$fingerprintSensorLocation")
                         showRipple(BiometricSourceType.FINGERPRINT)
                     }
                     "face" -> {
+                        updateSensorLocation()
                         pw.println("face ripple sensorLocation=$faceSensorLocation")
                         showRipple(BiometricSourceType.FACE)
                     }