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;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.hardware.biometrics.BiometricSourceType;
23 
24 import com.android.systemui.dagger.SysUISingleton;
25 import com.android.systemui.statusbar.phone.SystemUIDialog;
26 
27 import javax.inject.Inject;
28 
29 /**
30  * Receives broadcasts sent by {@link BiometricNotificationService} and takes
31  * the appropriate action.
32  */
33 @SysUISingleton
34 public class BiometricNotificationBroadcastReceiver extends BroadcastReceiver {
35     static final String ACTION_SHOW_FACE_REENROLL_DIALOG = "face_action_show_reenroll_dialog";
36     static final String ACTION_SHOW_FINGERPRINT_REENROLL_DIALOG =
37             "fingerprint_action_show_reenroll_dialog";
38 
39     private static final String TAG = "BiometricNotificationBroadcastReceiver";
40 
41     private final Context mContext;
42     private final BiometricNotificationDialogFactory mNotificationDialogFactory;
43     @Inject
BiometricNotificationBroadcastReceiver(Context context, BiometricNotificationDialogFactory notificationDialogFactory)44     BiometricNotificationBroadcastReceiver(Context context,
45             BiometricNotificationDialogFactory notificationDialogFactory) {
46         mContext = context;
47         mNotificationDialogFactory = notificationDialogFactory;
48     }
49 
50     @Override
onReceive(Context context, Intent intent)51     public void onReceive(Context context, Intent intent) {
52         final String action = intent.getAction();
53 
54         switch (action) {
55             case ACTION_SHOW_FACE_REENROLL_DIALOG:
56                 mNotificationDialogFactory.createReenrollDialog(mContext,
57                         new SystemUIDialog(mContext),
58                         BiometricSourceType.FACE)
59                         .show();
60                 break;
61             case ACTION_SHOW_FINGERPRINT_REENROLL_DIALOG:
62                 mNotificationDialogFactory.createReenrollDialog(
63                         mContext,
64                         new SystemUIDialog(mContext),
65                         BiometricSourceType.FINGERPRINT)
66                         .show();
67                 break;
68             default:
69                 break;
70         }
71     }
72 }
73