1 /* 2 * Copyright (C) 2019 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 package com.android.systemui.biometrics 17 18 import android.content.Context 19 import android.hardware.fingerprint.FingerprintSensorPropertiesInternal 20 import android.util.AttributeSet 21 import android.util.Log 22 import android.widget.FrameLayout 23 import android.widget.TextView 24 import com.android.systemui.R 25 import com.android.systemui.biometrics.AuthController.ScaleFactorProvider 26 27 private const val TAG = "AuthBiometricFingerprintView" 28 29 /** Fingerprint only view for BiometricPrompt. */ 30 open class AuthBiometricFingerprintView( 31 context: Context, 32 attrs: AttributeSet? = null 33 ) : AuthBiometricView(context, attrs) { 34 /** If this view is for a UDFPS sensor. */ 35 var isUdfps = false 36 private set 37 38 private var udfpsAdapter: UdfpsDialogMeasureAdapter? = null 39 private var scaleFactorProvider: ScaleFactorProvider? = null 40 41 /** Set the [sensorProps] of this sensor so the view can be customized prior to layout. */ setSensorPropertiesnull42 fun setSensorProperties(sensorProps: FingerprintSensorPropertiesInternal) { 43 isUdfps = sensorProps.isAnyUdfpsType 44 udfpsAdapter = if (isUdfps) UdfpsDialogMeasureAdapter(this, sensorProps) else null 45 } 46 setScaleFactorProvidernull47 fun setScaleFactorProvider(scaleProvider: ScaleFactorProvider?) { 48 scaleFactorProvider = scaleProvider 49 } 50 onMeasureInternalnull51 override fun onMeasureInternal(width: Int, height: Int): AuthDialog.LayoutParams { 52 val layoutParams = super.onMeasureInternal(width, height) 53 val scale = scaleFactorProvider?.provide() ?: 1.0f 54 return udfpsAdapter?.onMeasureInternal(width, height, layoutParams, 55 scale) ?: layoutParams 56 } 57 onLayoutnull58 override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { 59 super.onLayout(changed, left, top, right, bottom) 60 61 val adapter = udfpsAdapter 62 if (adapter != null) { 63 // Move the UDFPS icon and indicator text if necessary. This probably only needs to happen 64 // for devices where the UDFPS sensor is too low. 65 // TODO(b/201510778): Update this logic to support cases where the sensor or text overlap 66 // the button bar area. 67 val bottomSpacerHeight = adapter.bottomSpacerHeight 68 Log.w(TAG, "bottomSpacerHeight: $bottomSpacerHeight") 69 if (bottomSpacerHeight < 0) { 70 val iconFrame = findViewById<FrameLayout>(R.id.biometric_icon_frame)!! 71 iconFrame.translationY = -bottomSpacerHeight.toFloat() 72 val indicator = findViewById<TextView>(R.id.indicator)!! 73 indicator.translationY = -bottomSpacerHeight.toFloat() 74 } 75 } 76 } 77 getDelayAfterAuthenticatedDurationMsnull78 override fun getDelayAfterAuthenticatedDurationMs() = 500 79 80 override fun getStateForAfterError() = STATE_AUTHENTICATING 81 82 override fun handleResetAfterError() = showTouchSensorString() 83 84 override fun handleResetAfterHelp() = showTouchSensorString() 85 86 override fun supportsSmallDialog() = false 87 88 override fun createIconController(): AuthIconController = 89 AuthBiometricFingerprintIconController(mContext, mIconView, mIconViewOverlay) 90 91 fun updateOverrideIconLayoutParamsSize() { 92 udfpsAdapter?.let { 93 val sensorDiameter = it.getSensorDiameter(scaleFactorProvider?.provide() ?: 1.0f) 94 (mIconController as? AuthBiometricFingerprintIconController)?.iconLayoutParamSize = 95 Pair(sensorDiameter, sensorDiameter) 96 } 97 } 98 onAttachedToWindownull99 override fun onAttachedToWindow() { 100 super.onAttachedToWindow() 101 showTouchSensorString() 102 } 103 showTouchSensorStringnull104 private fun showTouchSensorString() { 105 mIndicatorView.setText(R.string.fingerprint_dialog_touch_sensor) 106 mIndicatorView.setTextColor(mTextColorHint) 107 } 108 } 109