1 package com.android.settingslib.udfps
2 
3 import android.graphics.Rect
4 import android.view.Surface
5 import android.view.Surface.Rotation
6 
7 /**
8  * Collection of parameters that define an under-display fingerprint sensor (UDFPS) overlay.
9  *
10  * [sensorBounds] coordinates of the bounding box around the sensor in natural orientation, in
11  * pixels, for the current resolution.
12  *
13  * [overlayBounds] coordinates of the UI overlay in natural orientation, in pixels, for the current
14  * resolution.
15  *
16  * [naturalDisplayWidth] width of the physical display in natural orientation, in pixels, for the
17  * current resolution.
18  *
19  * [naturalDisplayHeight] height of the physical display in natural orientation, in pixels, for the
20  * current resolution.
21  *
22  * [scaleFactor] ratio of a dimension in the current resolution to the corresponding dimension in
23  * the native resolution.
24  *
25  * [rotation] current rotation of the display.
26  */
27 data class UdfpsOverlayParams(
28     val sensorBounds: Rect = Rect(),
29     val overlayBounds: Rect = Rect(),
30     val naturalDisplayWidth: Int = 0,
31     val naturalDisplayHeight: Int = 0,
32     val scaleFactor: Float = 1f,
33     @Rotation val rotation: Int = Surface.ROTATION_0
34 ) {
35 
36     /** Same as [sensorBounds], but in native resolution. */
37     val nativeSensorBounds = Rect(sensorBounds).apply { scale(1f / scaleFactor) }
38 
39     /** Same as [overlayBounds], but in native resolution. */
40     val nativeOverlayBounds = Rect(overlayBounds).apply { scale(1f / scaleFactor) }
41 
42     /** See [android.view.DisplayInfo.logicalWidth] */
43     val logicalDisplayWidth =
44         if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
45             naturalDisplayHeight
46         } else {
47             naturalDisplayWidth
48         }
49 
50     /** See [android.view.DisplayInfo.logicalHeight] */
51     val logicalDisplayHeight =
52         if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
53             naturalDisplayWidth
54         } else {
55             naturalDisplayHeight
56         }
57 }
58