Merge "Rotate touch orientation to ROTATION_0" into tm-qpr-dev

This commit is contained in:
Austin Delgado
2023-01-11 00:39:38 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 11 deletions

View File

@@ -27,6 +27,8 @@ import com.android.systemui.biometrics.udfps.TouchProcessorResult.ProcessedTouch
import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject
private val SUPPORTED_ROTATIONS = setOf(Surface.ROTATION_90, Surface.ROTATION_270)
/**
* TODO(b/259140693): Consider using an object pool of TouchProcessorResult to avoid allocations.
*/
@@ -129,19 +131,27 @@ private fun MotionEvent.normalize(
val nativeY = naturalTouch.y / overlayParams.scaleFactor
val nativeMinor: Float = getTouchMinor(pointerIndex) / overlayParams.scaleFactor
val nativeMajor: Float = getTouchMajor(pointerIndex) / overlayParams.scaleFactor
var nativeOrientation: Float = getOrientation(pointerIndex)
if (SUPPORTED_ROTATIONS.contains(overlayParams.rotation)) {
nativeOrientation = toRadVerticalFromRotated(nativeOrientation.toDouble()).toFloat()
}
return NormalizedTouchData(
pointerId = getPointerId(pointerIndex),
x = nativeX,
y = nativeY,
minor = nativeMinor,
major = nativeMajor,
// TODO(b/259311354): touch orientation should be reported relative to Surface.ROTATION_O.
orientation = getOrientation(pointerIndex),
orientation = nativeOrientation,
time = eventTime,
gestureStart = downTime,
)
}
private fun toRadVerticalFromRotated(rad: Double): Double {
val piBound = ((rad % Math.PI) + Math.PI / 2) % Math.PI
return if (piBound < Math.PI / 2.0) piBound else piBound - Math.PI
}
/**
* Returns the [MotionEvent.getRawX] and [MotionEvent.getRawY] of the given pointer as if the device
* is in the [Surface.ROTATION_0] orientation.
@@ -152,7 +162,7 @@ private fun MotionEvent.rotateToNaturalOrientation(
): PointF {
val touchPoint = PointF(getRawX(pointerIndex), getRawY(pointerIndex))
val rot = overlayParams.rotation
if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
if (SUPPORTED_ROTATIONS.contains(rot)) {
RotationUtils.rotatePointF(
touchPoint,
RotationUtils.deltaRotation(rot, Surface.ROTATION_0),

View File

@@ -221,6 +221,14 @@ class SinglePointerTouchProcessorTest(val testCase: TestCase) : SysuiTestCase()
private const val ROTATION_0_NATIVE_DISPLAY_WIDTH = 400
private const val ROTATION_0_NATIVE_DISPLAY_HEIGHT = 600
/* Placeholder touch parameters. */
private const val POINTER_ID = 42
private const val NATIVE_MINOR = 2.71828f
private const val NATIVE_MAJOR = 3.14f
private const val ORIENTATION = 1.2345f
private const val TIME = 12345699L
private const val GESTURE_START = 12345600L
/*
* ROTATION_0 map:
* _ _ _ _
@@ -244,6 +252,7 @@ private val ROTATION_0_NATIVE_SENSOR_BOUNDS =
private val ROTATION_0_INPUTS =
OrientationBasedInputs(
rotation = Surface.ROTATION_0,
nativeOrientation = ORIENTATION,
nativeXWithinSensor = ROTATION_0_NATIVE_SENSOR_BOUNDS.exactCenterX(),
nativeYWithinSensor = ROTATION_0_NATIVE_SENSOR_BOUNDS.exactCenterY(),
nativeXOutsideSensor = 250f,
@@ -271,6 +280,7 @@ private val ROTATION_90_NATIVE_SENSOR_BOUNDS =
private val ROTATION_90_INPUTS =
OrientationBasedInputs(
rotation = Surface.ROTATION_90,
nativeOrientation = (ORIENTATION - Math.PI.toFloat() / 2),
nativeXWithinSensor = ROTATION_90_NATIVE_SENSOR_BOUNDS.exactCenterX(),
nativeYWithinSensor = ROTATION_90_NATIVE_SENSOR_BOUNDS.exactCenterY(),
nativeXOutsideSensor = 150f,
@@ -304,20 +314,13 @@ private val ROTATION_270_NATIVE_SENSOR_BOUNDS =
private val ROTATION_270_INPUTS =
OrientationBasedInputs(
rotation = Surface.ROTATION_270,
nativeOrientation = (ORIENTATION + Math.PI.toFloat() / 2),
nativeXWithinSensor = ROTATION_270_NATIVE_SENSOR_BOUNDS.exactCenterX(),
nativeYWithinSensor = ROTATION_270_NATIVE_SENSOR_BOUNDS.exactCenterY(),
nativeXOutsideSensor = 450f,
nativeYOutsideSensor = 250f,
)
/* Placeholder touch parameters. */
private const val POINTER_ID = 42
private const val NATIVE_MINOR = 2.71828f
private const val NATIVE_MAJOR = 3.14f
private const val ORIENTATION = 1.23f
private const val TIME = 12345699L
private const val GESTURE_START = 12345600L
/* Template [MotionEvent]. */
private val MOTION_EVENT =
obtainMotionEvent(
@@ -352,6 +355,7 @@ private val NORMALIZED_TOUCH_DATA =
*/
private data class OrientationBasedInputs(
@Rotation val rotation: Int,
val nativeOrientation: Float,
val nativeXWithinSensor: Float,
val nativeYWithinSensor: Float,
val nativeXOutsideSensor: Float,
@@ -404,6 +408,7 @@ private fun genPositiveTestCases(
y = nativeY * scaleFactor,
minor = NATIVE_MINOR * scaleFactor,
major = NATIVE_MAJOR * scaleFactor,
orientation = orientation.nativeOrientation
)
val expectedTouchData =
NORMALIZED_TOUCH_DATA.copy(