1 /*
2  * Copyright (C) 2024 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.data.repository
18 
19 import android.hardware.face.FaceManager
20 import com.android.systemui.CoreStartable
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.deviceentry.data.repository.DeviceEntryFaceAuthRepository
23 import com.android.systemui.deviceentry.data.repository.DeviceEntryFaceAuthRepositoryImpl
24 import com.android.systemui.deviceentry.domain.interactor.DeviceEntryFaceAuthInteractor
25 import com.android.systemui.deviceentry.domain.interactor.NoopDeviceEntryFaceAuthInteractor
26 import com.android.systemui.deviceentry.domain.interactor.SystemUIDeviceEntryFaceAuthInteractor
27 import com.android.systemui.deviceentry.ui.binder.LiftToRunFaceAuthBinder
28 import com.android.systemui.log.table.TableLogBuffer
29 import com.android.systemui.log.table.TableLogBufferFactory
30 import dagger.Binds
31 import dagger.Module
32 import dagger.Provides
33 import dagger.multibindings.ClassKey
34 import dagger.multibindings.IntoMap
35 
36 @Module
37 interface DeviceEntryFaceAuthModule {
38     @Binds
deviceEntryFaceAuthRepositorynull39     fun deviceEntryFaceAuthRepository(
40         impl: DeviceEntryFaceAuthRepositoryImpl
41     ): DeviceEntryFaceAuthRepository
42 
43     @Binds
44     @IntoMap
45     @ClassKey(DeviceEntryFaceAuthInteractor::class)
46     fun bindFaceAuthStartable(impl: DeviceEntryFaceAuthInteractor): CoreStartable
47 
48     @Binds
49     @IntoMap
50     @ClassKey(LiftToRunFaceAuthBinder::class)
51     fun bindLiftToRunFaceAuthBinder(impl: LiftToRunFaceAuthBinder): CoreStartable
52 
53     companion object {
54 
55         @Provides
56         @SysUISingleton
57         fun providesFaceAuthInteractorInstance(
58             faceManager: FaceManager?,
59             systemUIDeviceEntryFaceAuthInteractor:
60                 dagger.Lazy<SystemUIDeviceEntryFaceAuthInteractor>,
61             noopDeviceEntryFaceAuthInteractor: dagger.Lazy<NoopDeviceEntryFaceAuthInteractor>,
62         ): DeviceEntryFaceAuthInteractor {
63             return if (faceManager != null) {
64                 systemUIDeviceEntryFaceAuthInteractor.get()
65             } else {
66                 noopDeviceEntryFaceAuthInteractor.get()
67             }
68         }
69 
70         @Provides
71         @SysUISingleton
72         @FaceAuthTableLog
73         fun provideFaceAuthTableLog(factory: TableLogBufferFactory): TableLogBuffer {
74             return factory.create("FaceAuthTableLog", 400)
75         }
76 
77         @Provides
78         @SysUISingleton
79         @FaceDetectTableLog
80         fun provideFaceDetectTableLog(factory: TableLogBufferFactory): TableLogBuffer {
81             return factory.create("FaceDetectTableLog", 400)
82         }
83     }
84 }
85