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

Commit ff5ef4ee authored by Austin Delgado's avatar Austin Delgado Committed by Automerger Merge Worker
Browse files

Merge "Ignore touches outside of Udfps Overlay bounds" into udc-dev am: aee24a21

parents 7410f65b aee24a21
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ data class UdfpsOverlayParams(
    /** Same as [sensorBounds], but in native resolution. */
    val nativeSensorBounds = Rect(sensorBounds).apply { scale(1f / scaleFactor) }

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

    /** See [android.view.DisplayInfo.logicalWidth] */
    val logicalDisplayWidth =
        if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
+1 −1
Original line number Diff line number Diff line
@@ -636,7 +636,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
                    mOverlay.getOverlayView().getViewRootImpl().getInputToken());
        }

        return processedTouch.getTouchData().isWithinSensor(mOverlayParams.getNativeSensorBounds());
        return processedTouch.getTouchData().isWithinBounds(mOverlayParams.getNativeSensorBounds());
    }

    private boolean oldOnTouch(long requestId, @NonNull MotionEvent event, boolean fromUdfpsView) {
+7 −2
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@ import com.android.systemui.dagger.SysUISingleton
/** Returns whether the touch coordinates are within the sensor's bounding box. */
@SysUISingleton
class BoundingBoxOverlapDetector : OverlapDetector {
    override fun isGoodOverlap(touchData: NormalizedTouchData, nativeSensorBounds: Rect): Boolean =
        touchData.isWithinSensor(nativeSensorBounds)
    override fun isGoodOverlap(
        touchData: NormalizedTouchData,
        nativeSensorBounds: Rect,
        nativeOverlayBounds: Rect,
    ): Boolean =
        touchData.isWithinBounds(nativeOverlayBounds) &&
            touchData.isWithinBounds(nativeSensorBounds)
}
+15 −6
Original line number Diff line number Diff line
@@ -30,8 +30,8 @@ private enum class SensorPixelPosition {
    TARGET // Pixel within sensor center target
}

private val isDebug = true
private val TAG = "EllipseOverlapDetector"
private const val isDebug = false
private const val TAG = "EllipseOverlapDetector"

/**
 * Approximates the touch as an ellipse and determines whether the ellipse has a sufficient overlap
@@ -39,12 +39,21 @@ private val TAG = "EllipseOverlapDetector"
 */
@SysUISingleton
class EllipseOverlapDetector(private val params: EllipseOverlapDetectorParams) : OverlapDetector {
    override fun isGoodOverlap(touchData: NormalizedTouchData, nativeSensorBounds: Rect): Boolean {
        // First, check if touch is within bounding box,
        if (nativeSensorBounds.contains(touchData.x.toInt(), touchData.y.toInt())) {
    override fun isGoodOverlap(
        touchData: NormalizedTouchData,
        nativeSensorBounds: Rect,
        nativeOverlayBounds: Rect,
    ): Boolean {
        // First, check if touch is within bounding box to exit early
        if (touchData.isWithinBounds(nativeSensorBounds)) {
            return true
        }

        // Check touch is within overlay bounds, not worth checking if outside
        if (!touchData.isWithinBounds(nativeOverlayBounds)) {
            return false
        }

        var isTargetTouched = false
        var sensorPixels = 0
        var coveredPixels = 0
@@ -77,7 +86,7 @@ class EllipseOverlapDetector(private val params: EllipseOverlapDetectorParams) :

        val percentage: Float = coveredPixels.toFloat() / sensorPixels
        if (isDebug) {
            Log.v(
            Log.d(
                TAG,
                "covered: $coveredPixels, sensor: $sensorPixels, " +
                    "percentage: $percentage, isCenterTouched: $isTargetTouched"
+8 −8
Original line number Diff line number Diff line
@@ -51,16 +51,16 @@ data class NormalizedTouchData(
) {

    /**
     * [nativeSensorBounds] contains the location and dimensions of the sensor area in native
     * resolution and natural orientation.
     * [nativeBounds] contains the location and dimensions of the area in native resolution and
     * natural orientation.
     *
     * Returns whether the coordinates of the given pointer are within the sensor's bounding box.
     * Returns whether the coordinates of the given pointer are within the bounding box.
     */
    fun isWithinSensor(nativeSensorBounds: Rect): Boolean {
        return nativeSensorBounds.left <= x &&
            nativeSensorBounds.right >= x &&
            nativeSensorBounds.top <= y &&
            nativeSensorBounds.bottom >= y
    fun isWithinBounds(nativeBounds: Rect): Boolean {
        return nativeBounds.left <= x &&
            nativeBounds.right >= x &&
            nativeBounds.top <= y &&
            nativeBounds.bottom >= y
    }

    @JvmOverloads
Loading