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 import android.os.PowerManager; 26 import android.os.SystemClock; 27 28 import com.android.internal.util.LatencyTracker; 29 import com.android.keyguard.KeyguardUpdateMonitor; 30 import com.android.systemui.statusbar.phone.BiometricUnlockController; 31 import com.android.systemui.statusbar.phone.StatusBar; 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 public 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 start()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 fakeTurnOnScreen()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 fakeWakeAndUnlock()75 private void fakeWakeAndUnlock() { 76 BiometricUnlockController biometricUnlockController = getComponent(StatusBar.class) 77 .getBiometricUnlockController(); 78 biometricUnlockController.onBiometricAcquired(BiometricSourceType.FINGERPRINT); 79 biometricUnlockController.onBiometricAuthenticated( 80 KeyguardUpdateMonitor.getCurrentUser(), BiometricSourceType.FINGERPRINT); 81 } 82 } 83