Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 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 | |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 19 | import static android.os.PowerManager.WAKE_REASON_UNKNOWN; |
| 20 | |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.IntentFilter; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 25 | import android.hardware.biometrics.BiometricSourceType; |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 26 | import android.os.Build; |
| 27 | import android.os.PowerManager; |
| 28 | import android.os.SystemClock; |
| 29 | |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 30 | import com.android.internal.util.LatencyTracker; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 31 | import com.android.keyguard.KeyguardUpdateMonitor; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 32 | import com.android.systemui.statusbar.phone.BiometricUnlockController; |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 33 | |
| 34 | import javax.inject.Inject; |
| 35 | import javax.inject.Singleton; |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Class that only runs on debuggable builds that listens to broadcasts that simulate actions in the |
| 39 | * system that are used for testing the latency. |
| 40 | */ |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 41 | @Singleton |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 42 | public class LatencyTester extends SystemUI { |
| 43 | |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 44 | private static final String |
| 45 | ACTION_FINGERPRINT_WAKE = |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 46 | "com.android.systemui.latency.ACTION_FINGERPRINT_WAKE"; |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 47 | private static final String |
| 48 | ACTION_TURN_ON_SCREEN = |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 49 | "com.android.systemui.latency.ACTION_TURN_ON_SCREEN"; |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 50 | private final BiometricUnlockController mBiometricUnlockController; |
| 51 | private final PowerManager mPowerManager; |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 52 | |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 53 | @Inject |
| 54 | public LatencyTester(Context context, BiometricUnlockController biometricUnlockController, |
| 55 | PowerManager powerManager) { |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 56 | super(context); |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 57 | mBiometricUnlockController = biometricUnlockController; |
| 58 | mPowerManager = powerManager; |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 61 | @Override |
| 62 | public void start() { |
| 63 | if (!Build.IS_DEBUGGABLE) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | IntentFilter filter = new IntentFilter(); |
| 68 | filter.addAction(ACTION_FINGERPRINT_WAKE); |
| 69 | filter.addAction(ACTION_TURN_ON_SCREEN); |
| 70 | mContext.registerReceiver(new BroadcastReceiver() { |
| 71 | @Override |
| 72 | public void onReceive(Context context, Intent intent) { |
| 73 | String action = intent.getAction(); |
| 74 | if (ACTION_FINGERPRINT_WAKE.equals(action)) { |
| 75 | fakeWakeAndUnlock(); |
| 76 | } else if (ACTION_TURN_ON_SCREEN.equals(action)) { |
| 77 | fakeTurnOnScreen(); |
| 78 | } |
| 79 | } |
| 80 | }, filter); |
| 81 | } |
| 82 | |
| 83 | private void fakeTurnOnScreen() { |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 84 | if (LatencyTracker.isEnabled(mContext)) { |
| 85 | LatencyTracker.getInstance(mContext).onActionStart( |
| 86 | LatencyTracker.ACTION_TURN_ON_SCREEN); |
| 87 | } |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 88 | mPowerManager.wakeUp( |
| 89 | SystemClock.uptimeMillis(), WAKE_REASON_UNKNOWN, "android.policy:LATENCY_TESTS"); |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | private void fakeWakeAndUnlock() { |
Dave Mankoff | 7abd102 | 2019-10-23 15:18:49 -0400 | [diff] [blame] | 93 | mBiometricUnlockController.onBiometricAcquired(BiometricSourceType.FINGERPRINT); |
| 94 | mBiometricUnlockController.onBiometricAuthenticated( |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 95 | KeyguardUpdateMonitor.getCurrentUser(), BiometricSourceType.FINGERPRINT); |
Jorim Jaggi | c3fe204 | 2016-10-07 18:52:48 +0200 | [diff] [blame] | 96 | } |
| 97 | } |