1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.biometrics.shared.model
18 
19 import android.hardware.fingerprint.FingerprintSensorProperties
20 
21 /** Fingerprint sensor types. Represents [FingerprintSensorProperties.SensorType]. */
22 enum class FingerprintSensorType {
23     UNKNOWN,
24     REAR,
25     UDFPS_ULTRASONIC,
26     UDFPS_OPTICAL,
27     POWER_BUTTON,
28     HOME_BUTTON;
29 
isUdfpsnull30     fun isUdfps(): Boolean {
31         return (this == UDFPS_OPTICAL) || (this == UDFPS_ULTRASONIC)
32     }
33 
isPowerButtonnull34     fun isPowerButton(): Boolean {
35         return this == POWER_BUTTON
36     }
37 }
38 
39 /** Convert [this] to corresponding [FingerprintSensorType] */
toSensorTypenull40 fun Int.toSensorType(): FingerprintSensorType =
41     when (this) {
42         FingerprintSensorProperties.TYPE_UNKNOWN -> FingerprintSensorType.UNKNOWN
43         FingerprintSensorProperties.TYPE_REAR -> FingerprintSensorType.REAR
44         FingerprintSensorProperties.TYPE_UDFPS_ULTRASONIC -> FingerprintSensorType.UDFPS_ULTRASONIC
45         FingerprintSensorProperties.TYPE_UDFPS_OPTICAL -> FingerprintSensorType.UDFPS_OPTICAL
46         FingerprintSensorProperties.TYPE_POWER_BUTTON -> FingerprintSensorType.POWER_BUTTON
47         FingerprintSensorProperties.TYPE_HOME_BUTTON -> FingerprintSensorType.HOME_BUTTON
48         else -> throw IllegalArgumentException("Invalid SensorType value: $this")
49     }
50 
51 /** Convert [this] to corresponding [Int] */
toIntnull52 fun FingerprintSensorType.toInt(): Int =
53     when (this) {
54         FingerprintSensorType.UNKNOWN -> FingerprintSensorProperties.TYPE_UNKNOWN
55         FingerprintSensorType.REAR -> FingerprintSensorProperties.TYPE_REAR
56         FingerprintSensorType.UDFPS_ULTRASONIC -> FingerprintSensorProperties.TYPE_UDFPS_ULTRASONIC
57         FingerprintSensorType.UDFPS_OPTICAL -> FingerprintSensorProperties.TYPE_UDFPS_OPTICAL
58         FingerprintSensorType.POWER_BUTTON -> FingerprintSensorProperties.TYPE_POWER_BUTTON
59         FingerprintSensorType.HOME_BUTTON -> FingerprintSensorProperties.TYPE_HOME_BUTTON
60     }
61