1 package com.android.systemui.biometrics.shared.model
2 
3 import android.view.Surface
4 
5 /** Shadows [Surface.Rotation] for kotlin use within SysUI. */
6 enum class DisplayRotation {
7     ROTATION_0,
8     ROTATION_90,
9     ROTATION_180,
10     ROTATION_270,
11 }
12 
isDefaultOrientationnull13 fun DisplayRotation.isDefaultOrientation() =
14     this == DisplayRotation.ROTATION_0 || this == DisplayRotation.ROTATION_180
15 
16 /** Converts [Surface.Rotation] to corresponding [DisplayRotation] */
17 fun Int.toDisplayRotation(): DisplayRotation =
18     when (this) {
19         Surface.ROTATION_0 -> DisplayRotation.ROTATION_0
20         Surface.ROTATION_90 -> DisplayRotation.ROTATION_90
21         Surface.ROTATION_180 -> DisplayRotation.ROTATION_180
22         Surface.ROTATION_270 -> DisplayRotation.ROTATION_270
23         else -> throw IllegalArgumentException("Invalid DisplayRotation value: $this")
24     }
25 
26 /** Converts [DisplayRotation] to corresponding [Surface.Rotation] */
DisplayRotationnull27 fun DisplayRotation.toRotation(): Int =
28     when (this) {
29         DisplayRotation.ROTATION_0 -> Surface.ROTATION_0
30         DisplayRotation.ROTATION_90 -> Surface.ROTATION_90
31         DisplayRotation.ROTATION_180 -> Surface.ROTATION_180
32         DisplayRotation.ROTATION_270 -> Surface.ROTATION_270
33     }
34