1 /* 2 * Copyright (C) 2022 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.server.biometrics.log; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.Context; 22 import android.hardware.biometrics.AuthenticateOptions; 23 import android.hardware.biometrics.IBiometricContextListener; 24 import android.hardware.biometrics.common.OperationContext; 25 import android.view.Surface; 26 27 import com.android.server.biometrics.sensors.AuthSessionCoordinator; 28 29 import java.util.function.Consumer; 30 31 /** 32 * Cache for system state not directly related to biometric operations that is used for 33 * logging or optimizations. 34 * 35 * This class is also used to inject dependencies such as {@link AuthSessionCoordinator} 36 */ 37 public interface BiometricContext { 38 /** Gets the context source from the system context. */ getInstance(@onNull Context context)39 static BiometricContext getInstance(@NonNull Context context) { 40 return BiometricContextProvider.defaultProvider(context); 41 } 42 43 /** Update the given context with the most recent values and return it. */ updateContext(@onNull OperationContextExt operationContext, boolean isCryptoOperation)44 OperationContextExt updateContext(@NonNull OperationContextExt operationContext, 45 boolean isCryptoOperation); 46 47 /** The session id for keyguard entry, if active, or null. */ getKeyguardEntrySessionInfo()48 @Nullable BiometricContextSessionInfo getKeyguardEntrySessionInfo(); 49 50 /** The session id for biometric prompt usage, if active, or null. */ getBiometricPromptSessionInfo()51 @Nullable BiometricContextSessionInfo getBiometricPromptSessionInfo(); 52 53 /** If the display is in AOD. */ isAod()54 boolean isAod(); 55 56 /** If the device is awake or is becoming awake. */ isAwake()57 boolean isAwake(); 58 59 /** If the display is on. */ isDisplayOn()60 boolean isDisplayOn(); 61 62 /** Current dock state from {@link android.content.Intent#EXTRA_DOCK_STATE}. */ getDockedState()63 int getDockedState(); 64 65 /** 66 * Current fold state from 67 * {@link android.hardware.biometrics.IBiometricContextListener.FoldState}. 68 */ 69 @IBiometricContextListener.FoldState getFoldState()70 int getFoldState(); 71 72 /** Current device display rotation. */ 73 @Surface.Rotation getCurrentRotation()74 int getCurrentRotation(); 75 76 /** Current display state. */ 77 @AuthenticateOptions.DisplayState getDisplayState()78 int getDisplayState(); 79 80 /** Gets whether touches on sensor are ignored by HAL */ isHardwareIgnoringTouches()81 boolean isHardwareIgnoringTouches(); 82 83 /** 84 * Subscribe to context changes and start the HAL operation. 85 * 86 * Note that this method only notifies for properties that are visible to the HAL. 87 * 88 * @param context context that will be modified when changed 89 * @param startHalConsumer callback to start HAL operation after subscription is done 90 * @param updateContextConsumer callback when the context is modified 91 * @param options authentication options for updating the context 92 */ subscribe(@onNull OperationContextExt context, @NonNull Consumer<OperationContext> startHalConsumer, @NonNull Consumer<OperationContext> updateContextConsumer, @Nullable AuthenticateOptions options)93 void subscribe(@NonNull OperationContextExt context, 94 @NonNull Consumer<OperationContext> startHalConsumer, 95 @NonNull Consumer<OperationContext> updateContextConsumer, 96 @Nullable AuthenticateOptions options); 97 98 /** Unsubscribe from context changes. */ unsubscribe(@onNull OperationContextExt context)99 void unsubscribe(@NonNull OperationContextExt context); 100 101 /** Obtains an AuthSessionCoordinator. */ getAuthSessionCoordinator()102 AuthSessionCoordinator getAuthSessionCoordinator(); 103 } 104