1 /*
2  * Copyright (C) 2016 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;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 import android.hardware.biometrics.BiometricSourceType;
24 import android.os.Build;
25 
26 import com.android.keyguard.KeyguardUpdateMonitor;
27 import com.android.systemui.broadcast.BroadcastDispatcher;
28 import com.android.systemui.dagger.SysUISingleton;
29 import com.android.systemui.statusbar.phone.BiometricUnlockController;
30 
31 import javax.inject.Inject;
32 
33 /**
34  * Class that only runs on debuggable builds that listens to broadcasts that simulate actions in the
35  * system that are used for testing the latency.
36  */
37 @SysUISingleton
38 public class LatencyTester extends SystemUI {
39 
40     private static final String
41             ACTION_FINGERPRINT_WAKE =
42             "com.android.systemui.latency.ACTION_FINGERPRINT_WAKE";
43     private static final String
44             ACTION_FACE_WAKE =
45             "com.android.systemui.latency.ACTION_FACE_WAKE";
46     private final BiometricUnlockController mBiometricUnlockController;
47     private final BroadcastDispatcher mBroadcastDispatcher;
48 
49     @Inject
LatencyTester(Context context, BiometricUnlockController biometricUnlockController, BroadcastDispatcher broadcastDispatcher)50     public LatencyTester(Context context, BiometricUnlockController biometricUnlockController,
51             BroadcastDispatcher broadcastDispatcher) {
52         super(context);
53 
54         mBiometricUnlockController = biometricUnlockController;
55         mBroadcastDispatcher = broadcastDispatcher;
56     }
57 
58     @Override
start()59     public void start() {
60         if (!Build.IS_DEBUGGABLE) {
61             return;
62         }
63 
64         IntentFilter filter = new IntentFilter();
65         filter.addAction(ACTION_FINGERPRINT_WAKE);
66         filter.addAction(ACTION_FACE_WAKE);
67         mBroadcastDispatcher.registerReceiver(new BroadcastReceiver() {
68             @Override
69             public void onReceive(Context context, Intent intent) {
70                 String action = intent.getAction();
71                 if (ACTION_FINGERPRINT_WAKE.equals(action)) {
72                     fakeWakeAndUnlock(BiometricSourceType.FINGERPRINT);
73                 } else if (ACTION_FACE_WAKE.equals(action)) {
74                     fakeWakeAndUnlock(BiometricSourceType.FACE);
75                 }
76             }
77         }, filter);
78     }
79 
fakeWakeAndUnlock(BiometricSourceType type)80     private void fakeWakeAndUnlock(BiometricSourceType type) {
81         mBiometricUnlockController.onBiometricAcquired(type);
82         mBiometricUnlockController.onBiometricAuthenticated(
83                 KeyguardUpdateMonitor.getCurrentUser(), type, true /* isStrongBiometric */);
84     }
85 }
86