Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa4b1c42 authored by Ilya Matyukhin's avatar Ilya Matyukhin
Browse files

Change computed properties to regular in UdfpsOverlayParams

Bug: 218374828
Test: atest SystemUITests:com.android.systemui.biometrics
Change-Id: I07994051763a13486efbaa4cc7b6385b6dafa005
parent ea6cdd17
Loading
Loading
Loading
Loading
+25 −15
Original line number Diff line number Diff line
@@ -7,17 +7,23 @@ import android.view.Surface.Rotation
/**
 * Collection of parameters that define an under-display fingerprint sensor (UDFPS) overlay.
 *
 * @property sensorBounds coordinates of the bounding box around the sensor, in natural orientation,
 *     in pixels, for the current resolution.
 * @property naturalDisplayWidth width of the physical display, in natural orientation, in pixels,
 *     for the current resolution.
 * @property naturalDisplayHeight height of the physical display, in natural orientation, in pixels,
 *     for the current resolution.
 * @property scaleFactor ratio of a dimension in the current resolution to the corresponding
 *     dimension in the native resolution.
 * @property rotation current rotation of the display.
 * [sensorBounds] coordinates of the bounding box around the sensor in natural orientation, in
 * pixels, for the current resolution.
 *
 * [overlayBounds] coordinates of the UI overlay in natural orientation, in pixels, for the current
 * resolution.
 *
 * [naturalDisplayWidth] width of the physical display in natural orientation, in pixels, for the
 * current resolution.
 *
 * [naturalDisplayHeight] height of the physical display in natural orientation, in pixels, for the
 * current resolution.
 *
 * [scaleFactor] ratio of a dimension in the current resolution to the corresponding dimension in
 * the native resolution.
 *
 * [rotation] current rotation of the display.
 */

data class UdfpsOverlayParams(
    val sensorBounds: Rect = Rect(),
    val overlayBounds: Rect = Rect(),
@@ -26,17 +32,21 @@ data class UdfpsOverlayParams(
    val scaleFactor: Float = 1f,
    @Rotation val rotation: Int = Surface.ROTATION_0
) {

    /** Same as [sensorBounds], but in native resolution. */
    val nativeSensorBounds = Rect(sensorBounds).apply { scale(1f / scaleFactor) }

    /** See [android.view.DisplayInfo.logicalWidth] */
    val logicalDisplayWidth
        get() = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
    val logicalDisplayWidth =
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
            naturalDisplayHeight
        } else {
            naturalDisplayWidth
        }

    /** See [android.view.DisplayInfo.logicalHeight] */
    val logicalDisplayHeight
        get() = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
    val logicalDisplayHeight =
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
            naturalDisplayWidth
        } else {
            naturalDisplayHeight
+9 −8
Original line number Diff line number Diff line
@@ -16,9 +16,8 @@

package com.android.systemui.biometrics.udfps

import android.graphics.RectF
import android.graphics.Rect
import android.view.MotionEvent
import com.android.systemui.biometrics.UdfpsOverlayParams

/** Touch data in natural orientation and native resolution. */
data class NormalizedTouchData(
@@ -52,13 +51,15 @@ data class NormalizedTouchData(
) {

    /**
     * [overlayParams] contains the location and dimensions of the sensor area, as well as the scale
     * factor and orientation of the overlay. See [UdfpsOverlayParams].
     * [nativeSensorBounds] contains the location and dimensions of the sensor area in native
     * resolution and natural orientation.
     *
     * Returns whether the given pointer is within the sensor's bounding box.
     * Returns whether the coordinates of the given pointer are within the sensor's bounding box.
     */
    fun isWithinSensor(overlayParams: UdfpsOverlayParams): Boolean {
        val r = RectF(overlayParams.sensorBounds).apply { scale(1f / overlayParams.scaleFactor) }
        return r.left <= x && r.right >= x && r.top <= y && r.bottom >= y
    fun isWithinSensor(nativeSensorBounds: Rect): Boolean {
        return nativeSensorBounds.left <= x &&
            nativeSensorBounds.right >= x &&
            nativeSensorBounds.top <= y &&
            nativeSensorBounds.bottom >= y
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ private fun MotionEvent.preprocess(
    // TODO(b/253085297): Add multitouch support. pointerIndex can be > 0 for ACTION_MOVE.
    val pointerIndex = 0
    val touchData = normalize(pointerIndex, overlayParams)
    val isWithinSensor = touchData.isWithinSensor(overlayParams)
    val isWithinSensor = touchData.isWithinSensor(overlayParams.nativeSensorBounds)
    return PreprocessedTouch(touchData, previousPointerOnSensorId, isWithinSensor)
}

+1 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package com.android.systemui.biometrics.udfps
import android.graphics.Rect
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.UdfpsOverlayParams
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@@ -17,7 +16,7 @@ class NormalizedTouchDataTest(val testCase: TestCase) : SysuiTestCase() {
    @Test
    fun isWithinSensor() {
        val touchData = TOUCH_DATA.copy(x = testCase.x.toFloat(), y = testCase.y.toFloat())
        val actual = touchData.isWithinSensor(OVERLAY_PARAMS)
        val actual = touchData.isWithinSensor(SENSOR)

        assertThat(actual).isEqualTo(testCase.expected)
    }
@@ -66,7 +65,6 @@ private val TOUCH_DATA =
    )

private val SENSOR = Rect(100 /* left */, 200 /* top */, 300 /* right */, 500 /* bottom */)
private val OVERLAY_PARAMS = UdfpsOverlayParams(sensorBounds = SENSOR)

private fun genTestCases(
    xs: List<Int>,