1 package com.android.systemui.biometrics 2 3 import android.content.Context 4 import android.os.RemoteException 5 import android.os.Trace 6 import android.util.Log 7 import com.android.systemui.dagger.SysUISingleton 8 import com.android.systemui.util.concurrency.Execution 9 import javax.inject.Inject 10 11 private const val TAG = "UdfpsDisplayMode" 12 13 /** 14 * UdfpsDisplayMode that encapsulates pixel-specific code, such as enabling the high-brightness mode 15 * (HBM) in a display-specific way and freezing the display's refresh rate. 16 */ 17 @SysUISingleton 18 class UdfpsDisplayMode 19 @Inject 20 constructor( 21 private val context: Context, 22 private val execution: Execution, 23 private val authController: AuthController 24 ) : UdfpsDisplayModeProvider { 25 26 // The request is reset to null after it's processed. 27 private var currentRequest: Request? = null 28 enablenull29 override fun enable(onEnabled: Runnable?) { 30 execution.isMainThread() 31 Log.v(TAG, "enable") 32 33 if (currentRequest != null) { 34 Log.e(TAG, "enable | already requested") 35 return 36 } 37 if (authController.udfpsHbmListener == null) { 38 Log.e(TAG, "enable | mDisplayManagerCallback is null") 39 return 40 } 41 42 Trace.beginSection("UdfpsDisplayMode.enable") 43 44 // Track this request in one object. 45 val request = Request(context.displayId) 46 currentRequest = request 47 48 try { 49 // This method is a misnomer. It has nothing to do with HBM, its purpose is to set 50 // the appropriate display refresh rate. 51 authController.udfpsHbmListener!!.onHbmEnabled(request.displayId) 52 Log.v(TAG, "enable | requested optimal refresh rate for UDFPS") 53 } catch (e: RemoteException) { 54 Log.e(TAG, "enable", e) 55 } 56 57 onEnabled?.run() ?: Log.w(TAG, "enable | onEnabled is null") 58 Trace.endSection() 59 } 60 disablenull61 override fun disable(onDisabled: Runnable?) { 62 execution.isMainThread() 63 Log.v(TAG, "disable") 64 65 val request = currentRequest 66 if (request == null) { 67 Log.w(TAG, "disable | already disabled") 68 return 69 } 70 71 Trace.beginSection("UdfpsDisplayMode.disable") 72 73 try { 74 // Allow DisplayManager to unset the UDFPS refresh rate. 75 authController.udfpsHbmListener!!.onHbmDisabled(request.displayId) 76 Log.v(TAG, "disable | removed the UDFPS refresh rate request") 77 } catch (e: RemoteException) { 78 Log.e(TAG, "disable", e) 79 } 80 81 currentRequest = null 82 onDisabled?.run() ?: Log.w(TAG, "disable | onDisabled is null") 83 Trace.endSection() 84 } 85 } 86 87 /** Tracks a request to enable the UDFPS mode. */ 88 private data class Request(val displayId: Int) 89