1 /* 2 * Copyright (C) 2022 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.hardware.biometrics.BiometricOverlayConstants.REASON_AUTH_BP 20 import android.hardware.biometrics.BiometricOverlayConstants.REASON_AUTH_KEYGUARD 21 import android.hardware.biometrics.BiometricOverlayConstants.REASON_AUTH_OTHER 22 import android.hardware.biometrics.BiometricOverlayConstants.REASON_AUTH_SETTINGS 23 import android.hardware.biometrics.BiometricOverlayConstants.REASON_ENROLL_ENROLLING 24 import android.hardware.biometrics.BiometricOverlayConstants.REASON_ENROLL_FIND_SENSOR 25 import android.hardware.biometrics.BiometricOverlayConstants.REASON_UNKNOWN 26 import android.hardware.fingerprint.IUdfpsOverlayController 27 import android.hardware.fingerprint.IUdfpsOverlayControllerCallback 28 import android.util.Log 29 import com.android.systemui.dagger.SysUISingleton 30 import com.android.systemui.statusbar.commandline.Command 31 import com.android.systemui.statusbar.commandline.CommandRegistry 32 import java.io.PrintWriter 33 import javax.inject.Inject 34 35 private const val TAG = "UdfpsShell" 36 private const val REQUEST_ID = 2L 37 private const val SENSOR_ID = 0 38 39 /** 40 * Used to show and hide the UDFPS overlay with statusbar commands. 41 */ 42 @SysUISingleton 43 class UdfpsShell @Inject constructor( 44 commandRegistry: CommandRegistry 45 ) : Command { 46 47 /** 48 * Set in [UdfpsController.java] constructor, used to show and hide the UDFPS overlay. 49 * TODO: inject after b/229290039 is resolved 50 */ 51 var udfpsOverlayController: IUdfpsOverlayController? = null 52 53 init { <lambda>null54 commandRegistry.registerCommand("udfps") { this } 55 } 56 executenull57 override fun execute(pw: PrintWriter, args: List<String>) { 58 if (args.size == 1 && args[0] == "hide") { 59 hideOverlay() 60 } else if (args.size == 2 && args[0] == "show") { 61 showOverlay(getEnrollmentReason(args[1])) 62 } else { 63 invalidCommand(pw) 64 } 65 } 66 helpnull67 override fun help(pw: PrintWriter) { 68 pw.println("Usage: adb shell cmd statusbar udfps <cmd>") 69 pw.println("Supported commands:") 70 pw.println(" - show <reason>") 71 pw.println(" -> supported reasons: [enroll-find-sensor, enroll-enrolling, auth-bp, " + 72 "auth-keyguard, auth-other, auth-settings]") 73 pw.println(" -> reason otherwise defaults to unknown") 74 pw.println(" - hide") 75 } 76 invalidCommandnull77 private fun invalidCommand(pw: PrintWriter) { 78 pw.println("invalid command") 79 help(pw) 80 } 81 getEnrollmentReasonnull82 private fun getEnrollmentReason(reason: String): Int { 83 return when (reason) { 84 "enroll-find-sensor" -> REASON_ENROLL_FIND_SENSOR 85 "enroll-enrolling" -> REASON_ENROLL_ENROLLING 86 "auth-bp" -> REASON_AUTH_BP 87 "auth-keyguard" -> REASON_AUTH_KEYGUARD 88 "auth-other" -> REASON_AUTH_OTHER 89 "auth-settings" -> REASON_AUTH_SETTINGS 90 else -> REASON_UNKNOWN 91 } 92 } 93 showOverlaynull94 private fun showOverlay(reason: Int) { 95 udfpsOverlayController?.showUdfpsOverlay( 96 REQUEST_ID, 97 SENSOR_ID, 98 reason, 99 object : IUdfpsOverlayControllerCallback.Stub() { 100 override fun onUserCanceled() { 101 Log.e(TAG, "User cancelled") 102 } 103 } 104 ) 105 } 106 hideOverlaynull107 private fun hideOverlay() { 108 udfpsOverlayController?.hideUdfpsOverlay(SENSOR_ID) 109 } 110 }