1 /*
2  * Copyright (C) 2020 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.keyguard.dagger;
18 
19 import static com.android.systemui.biometrics.SideFpsControllerKt.hasSideFpsSensor;
20 
21 import android.annotation.Nullable;
22 import android.hardware.fingerprint.FingerprintManager;
23 import android.view.LayoutInflater;
24 import android.view.ViewGroup;
25 
26 import com.android.keyguard.KeyguardSecurityContainer;
27 import com.android.keyguard.KeyguardSecurityViewFlipper;
28 import com.android.systemui.R;
29 import com.android.systemui.biometrics.SideFpsController;
30 import com.android.systemui.dagger.qualifiers.RootView;
31 import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor;
32 
33 import java.util.Optional;
34 
35 import javax.inject.Provider;
36 
37 import dagger.Module;
38 import dagger.Provides;
39 
40 /**
41  * Module to create and access view related to the {@link PrimaryBouncerInteractor}.
42  */
43 @Module
44 public interface KeyguardBouncerModule {
45 
46     /** */
47     @Provides
48     @KeyguardBouncerScope
providesKeyguardSecurityContainer(@ootView ViewGroup rootView, LayoutInflater layoutInflater)49     static KeyguardSecurityContainer providesKeyguardSecurityContainer(@RootView ViewGroup rootView,
50             LayoutInflater layoutInflater) {
51         KeyguardSecurityContainer securityContainer =
52                 (KeyguardSecurityContainer) layoutInflater.inflate(
53                         R.layout.keyguard_security_container_view, rootView, false);
54         rootView.addView(securityContainer);
55         return securityContainer;
56     }
57 
58     /** */
59     @Provides
60     @KeyguardBouncerScope
providesKeyguardSecurityViewFlipper( KeyguardSecurityContainer containerView)61     static KeyguardSecurityViewFlipper providesKeyguardSecurityViewFlipper(
62             KeyguardSecurityContainer containerView) {
63         return containerView.findViewById(R.id.view_flipper);
64     }
65 
66     /** Provides {@link SideFpsController} if the device has the side fingerprint sensor. */
67     @Provides
68     @KeyguardBouncerScope
providesOptionalSidefpsController( @ullable FingerprintManager fingerprintManager, Provider<SideFpsController> sidefpsControllerProvider)69     static Optional<SideFpsController> providesOptionalSidefpsController(
70             @Nullable FingerprintManager fingerprintManager,
71             Provider<SideFpsController> sidefpsControllerProvider) {
72         if (!hasSideFpsSensor(fingerprintManager)) {
73             return Optional.empty();
74         }
75         return Optional.of(sidefpsControllerProvider.get());
76     }
77 }
78