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.keyguard.shared.model 18 19 import android.hardware.face.FaceAuthenticateOptions 20 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_ALTERNATE_BIOMETRIC_BOUNCER_SHOWN 21 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_ASSISTANT_VISIBLE 22 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_NOTIFICATION_PANEL_CLICKED 23 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_OCCLUDING_APP_REQUESTED 24 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_PICK_UP_GESTURE_TRIGGERED 25 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_PRIMARY_BOUNCER_SHOWN 26 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_STARTED_WAKING_UP 27 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_SWIPE_UP_ON_BOUNCER 28 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_UDFPS_POINTER_DOWN 29 import android.hardware.face.FaceAuthenticateOptions.AUTHENTICATE_REASON_UNKNOWN 30 import android.hardware.face.FaceAuthenticateOptions.AuthenticateReason 31 import android.os.PowerManager 32 import android.os.PowerManager.WAKE_REASON_UNKNOWN 33 import android.util.Log 34 import com.android.internal.logging.UiEventLogger 35 import com.android.systemui.deviceentry.shared.FaceAuthUiEvent 36 37 /** 38 * Wrapper for [FaceAuthenticateOptions] to convert SystemUI values to their corresponding value in 39 * [FaceAuthenticateOptions]. 40 */ 41 data class SysUiFaceAuthenticateOptions( 42 val userId: Int, 43 private val faceAuthUiEvent: UiEventLogger.UiEventEnum, 44 @PowerManager.WakeReason val wakeReason: Int = WAKE_REASON_UNKNOWN 45 ) { 46 private val authenticateReason = setAuthenticateReason(faceAuthUiEvent) 47 48 /** 49 * The [FaceAuthUiEvent] for this operation. This method converts the UiEvent to the framework 50 * [AuthenticateReason]. 51 */ 52 @AuthenticateReason setAuthenticateReasonnull53 fun setAuthenticateReason(uiEvent: UiEventLogger.UiEventEnum): Int { 54 return when (uiEvent) { 55 FaceAuthUiEvent.FACE_AUTH_UPDATED_STARTED_WAKING_UP -> { 56 AUTHENTICATE_REASON_STARTED_WAKING_UP 57 } 58 FaceAuthUiEvent.FACE_AUTH_UPDATED_PRIMARY_BOUNCER_SHOWN, 59 FaceAuthUiEvent.FACE_AUTH_UPDATED_PRIMARY_BOUNCER_SHOWN_OR_WILL_BE_SHOWN -> { 60 AUTHENTICATE_REASON_PRIMARY_BOUNCER_SHOWN 61 } 62 FaceAuthUiEvent.FACE_AUTH_UPDATED_ASSISTANT_VISIBILITY_CHANGED -> { 63 AUTHENTICATE_REASON_ASSISTANT_VISIBLE 64 } 65 FaceAuthUiEvent.FACE_AUTH_TRIGGERED_ALTERNATE_BIOMETRIC_BOUNCER_SHOWN -> { 66 AUTHENTICATE_REASON_ALTERNATE_BIOMETRIC_BOUNCER_SHOWN 67 } 68 FaceAuthUiEvent.FACE_AUTH_TRIGGERED_NOTIFICATION_PANEL_CLICKED -> { 69 AUTHENTICATE_REASON_NOTIFICATION_PANEL_CLICKED 70 } 71 FaceAuthUiEvent.FACE_AUTH_TRIGGERED_OCCLUDING_APP_REQUESTED -> { 72 AUTHENTICATE_REASON_OCCLUDING_APP_REQUESTED 73 } 74 FaceAuthUiEvent.FACE_AUTH_TRIGGERED_PICK_UP_GESTURE_TRIGGERED -> { 75 AUTHENTICATE_REASON_PICK_UP_GESTURE_TRIGGERED 76 } 77 FaceAuthUiEvent.FACE_AUTH_TRIGGERED_SWIPE_UP_ON_BOUNCER -> { 78 AUTHENTICATE_REASON_SWIPE_UP_ON_BOUNCER 79 } 80 FaceAuthUiEvent.FACE_AUTH_TRIGGERED_UDFPS_POINTER_DOWN -> { 81 AUTHENTICATE_REASON_UDFPS_POINTER_DOWN 82 } 83 else -> { 84 Log.e("FaceAuthenticateOptions", " unmapped FaceAuthUiEvent $uiEvent") 85 AUTHENTICATE_REASON_UNKNOWN 86 } 87 } 88 } 89 90 /** Builds the instance. */ toFaceAuthenticateOptionsnull91 fun toFaceAuthenticateOptions(): FaceAuthenticateOptions { 92 return FaceAuthenticateOptions.Builder() 93 .setUserId(userId) 94 .setAuthenticateReason(authenticateReason) 95 .setWakeReason(wakeReason) 96 .build() 97 } 98 } 99