blob: 50f1b44b05b1d42d8c80dff5ea66a6ff062d5f28 [file] [log] [blame]
Jorim Jaggic3fe2042016-10-07 18:52:48 +02001/*
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
17package com.android.systemui;
18
19import android.content.BroadcastReceiver;
20import android.content.Context;
21import android.content.Intent;
22import android.content.IntentFilter;
Gus Prevasab336792018-11-14 13:52:20 -050023import android.hardware.biometrics.BiometricSourceType;
Jorim Jaggic3fe2042016-10-07 18:52:48 +020024import android.os.Build;
25import android.os.PowerManager;
26import android.os.SystemClock;
27
Jason Monkea03be12017-12-04 11:08:41 -050028import com.android.internal.util.LatencyTracker;
Gus Prevasab336792018-11-14 13:52:20 -050029import com.android.keyguard.KeyguardUpdateMonitor;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020030import com.android.systemui.statusbar.phone.BiometricUnlockController;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050031import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggic3fe2042016-10-07 18:52:48 +020032
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 */
37public class LatencyTester extends SystemUI {
38
39 private static final String ACTION_FINGERPRINT_WAKE =
40 "com.android.systemui.latency.ACTION_FINGERPRINT_WAKE";
41 private static final String ACTION_TURN_ON_SCREEN =
42 "com.android.systemui.latency.ACTION_TURN_ON_SCREEN";
43
44 @Override
45 public void start() {
46 if (!Build.IS_DEBUGGABLE) {
47 return;
48 }
49
50 IntentFilter filter = new IntentFilter();
51 filter.addAction(ACTION_FINGERPRINT_WAKE);
52 filter.addAction(ACTION_TURN_ON_SCREEN);
53 mContext.registerReceiver(new BroadcastReceiver() {
54 @Override
55 public void onReceive(Context context, Intent intent) {
56 String action = intent.getAction();
57 if (ACTION_FINGERPRINT_WAKE.equals(action)) {
58 fakeWakeAndUnlock();
59 } else if (ACTION_TURN_ON_SCREEN.equals(action)) {
60 fakeTurnOnScreen();
61 }
62 }
63 }, filter);
64 }
65
66 private void fakeTurnOnScreen() {
67 PowerManager powerManager = mContext.getSystemService(PowerManager.class);
68 if (LatencyTracker.isEnabled(mContext)) {
69 LatencyTracker.getInstance(mContext).onActionStart(
70 LatencyTracker.ACTION_TURN_ON_SCREEN);
71 }
72 powerManager.wakeUp(SystemClock.uptimeMillis(), "android.policy:LATENCY_TESTS");
73 }
74
75 private void fakeWakeAndUnlock() {
Gilad Brettercb51b8b2018-03-22 17:04:51 +020076 BiometricUnlockController biometricUnlockController = getComponent(StatusBar.class)
77 .getBiometricUnlockController();
78 biometricUnlockController.onBiometricAcquired(BiometricSourceType.FINGERPRINT);
79 biometricUnlockController.onBiometricAuthenticated(
80 KeyguardUpdateMonitor.getCurrentUser(), BiometricSourceType.FINGERPRINT);
Jorim Jaggic3fe2042016-10-07 18:52:48 +020081 }
82}