Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63056aa9 authored by Austin Delgado's avatar Austin Delgado
Browse files

Move UdfpsDisplayMode to AOSP

Bug: 246580842
Test: N/A
Change-Id: Ibf209f10e608814d1035b15299380b5eaa7632ee
parent c62b8283
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
    @Nullable private IUdfpsHbmListener mUdfpsHbmListener;
    @Nullable private SidefpsController mSidefpsController;
    @Nullable private IBiometricContextListener mBiometricContextListener;
    @Nullable private UdfpsLogger mUdfpsLogger;
    @VisibleForTesting IBiometricSysuiReceiver mReceiver;
    @VisibleForTesting @NonNull final BiometricDisplayListener mOrientationListener;
    @Nullable private final List<FaceSensorPropertiesInternal> mFaceProps;
@@ -289,6 +290,8 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
                }
            });
            mUdfpsController.setAuthControllerUpdateUdfpsLocation(this::updateUdfpsLocation);
            mUdfpsController.setUdfpsDisplayMode(new UdfpsDisplayMode(mContext, mExecution,
                    this, mUdfpsLogger));
            mUdfpsBounds = mUdfpsProps.get(0).getLocation().getRect();
        }

@@ -688,6 +691,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
            @NonNull WakefulnessLifecycle wakefulnessLifecycle,
            @NonNull UserManager userManager,
            @NonNull LockPatternUtils lockPatternUtils,
            @NonNull UdfpsLogger udfpsLogger,
            @NonNull StatusBarStateController statusBarStateController,
            @NonNull InteractionJankMonitor jankMonitor,
            @Main Handler handler,
@@ -705,6 +709,7 @@ public class AuthController extends CoreStartable implements CommandQueue.Callba
        mFaceManager = faceManager;
        mUdfpsControllerFactory = udfpsControllerFactory;
        mSidefpsControllerFactory = sidefpsControllerFactory;
        mUdfpsLogger = udfpsLogger;
        mDisplayManager = displayManager;
        mWindowManager = windowManager;
        mInteractionJankMonitor = jankMonitor;
+5 −3
Original line number Diff line number Diff line
@@ -123,7 +123,6 @@ public class UdfpsController implements DozeReceiver {
    @NonNull private final PowerManager mPowerManager;
    @NonNull private final AccessibilityManager mAccessibilityManager;
    @NonNull private final LockscreenShadeTransitionController mLockscreenShadeTransitionController;
    @Nullable private final UdfpsDisplayModeProvider mUdfpsDisplayMode;
    @NonNull private final ConfigurationController mConfigurationController;
    @NonNull private final SystemClock mSystemClock;
    @NonNull private final UnlockedScreenOffAnimationController
@@ -139,6 +138,7 @@ public class UdfpsController implements DozeReceiver {
    // TODO(b/229290039): UDFPS controller should manage its dimensions on its own. Remove this.
    @Nullable private Runnable mAuthControllerUpdateUdfpsLocation;
    @Nullable private final AlternateUdfpsTouchProvider mAlternateTouchProvider;
    @Nullable private UdfpsDisplayModeProvider mUdfpsDisplayMode;

    // Tracks the velocity of a touch to help filter out the touches that move too fast.
    @Nullable private VelocityTracker mVelocityTracker;
@@ -319,6 +319,10 @@ public class UdfpsController implements DozeReceiver {
        mAuthControllerUpdateUdfpsLocation = r;
    }

    public void setUdfpsDisplayMode(UdfpsDisplayModeProvider udfpsDisplayMode) {
        mUdfpsDisplayMode = udfpsDisplayMode;
    }

    /**
     * Calculate the pointer speed given a velocity tracker and the pointer id.
     * This assumes that the velocity tracker has already been passed all relevant motion events.
@@ -594,7 +598,6 @@ public class UdfpsController implements DozeReceiver {
            @NonNull VibratorHelper vibrator,
            @NonNull UdfpsHapticsSimulator udfpsHapticsSimulator,
            @NonNull UdfpsShell udfpsShell,
            @NonNull Optional<UdfpsDisplayModeProvider> udfpsDisplayMode,
            @NonNull KeyguardStateController keyguardStateController,
            @NonNull DisplayManager displayManager,
            @Main Handler mainHandler,
@@ -626,7 +629,6 @@ public class UdfpsController implements DozeReceiver {
        mPowerManager = powerManager;
        mAccessibilityManager = accessibilityManager;
        mLockscreenShadeTransitionController = lockscreenShadeTransitionController;
        mUdfpsDisplayMode = udfpsDisplayMode.orElse(null);
        screenLifecycle.addObserver(mScreenObserver);
        mScreenOn = screenLifecycle.getScreenState() == ScreenLifecycle.SCREEN_ON;
        mConfigurationController = configurationController;
+100 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.biometrics

import android.content.Context
import android.os.RemoteException
import android.os.Trace
import com.android.systemui.util.concurrency.Execution

private const val TAG = "UdfpsDisplayMode"

/**
 * UdfpsDisplayMode configures the display for optimal UDFPS operation. For example, sets the
 * display refresh rate that's optimal for UDFPS.
 */
class UdfpsDisplayMode
constructor(
    private val context: Context,
    private val execution: Execution,
    private val authController: AuthController,
    private val logger: UdfpsLogger
) : UdfpsDisplayModeProvider {

    // The request is reset to null after it's processed.
    private var currentRequest: Request? = null

    override fun enable(onEnabled: Runnable?) {
        execution.isMainThread()
        logger.v(TAG, "enable")

        if (currentRequest != null) {
            logger.e(TAG, "enable | already requested")
            return
        }
        if (authController.udfpsHbmListener == null) {
            logger.e(TAG, "enable | mDisplayManagerCallback is null")
            return
        }

        Trace.beginSection("UdfpsDisplayMode.enable")

        // Track this request in one object.
        val request = Request(context.displayId)
        currentRequest = request

        try {
            // This method is a misnomer. It has nothing to do with HBM, its purpose is to set
            // the appropriate display refresh rate.
            authController.udfpsHbmListener!!.onHbmEnabled(request.displayId)
            logger.v(TAG, "enable | requested optimal refresh rate for UDFPS")
        } catch (e: RemoteException) {
            logger.e(TAG, "enable", e)
        }

        onEnabled?.run() ?: logger.w(TAG, "enable | onEnabled is null")
        Trace.endSection()
    }

    override fun disable(onDisabled: Runnable?) {
        execution.isMainThread()
        logger.v(TAG, "disable")

        val request = currentRequest
        if (request == null) {
            logger.w(TAG, "disable | already disabled")
            return
        }

        Trace.beginSection("UdfpsDisplayMode.disable")

        try {
            // Allow DisplayManager to unset the UDFPS refresh rate.
            authController.udfpsHbmListener!!.onHbmDisabled(request.displayId)
            logger.v(TAG, "disable | removed the UDFPS refresh rate request")
        } catch (e: RemoteException) {
            logger.e(TAG, "disable", e)
        }

        currentRequest = null
        onDisabled?.run() ?: logger.w(TAG, "disable | onDisabled is null")
        Trace.endSection()
    }
}

/** Tracks a request to enable the UDFPS mode. */
private data class Request(val displayId: Int)
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.biometrics

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel
import com.android.systemui.log.LogLevel.ERROR
import com.android.systemui.log.LogLevel.VERBOSE
import com.android.systemui.log.LogLevel.WARNING
import com.android.systemui.log.dagger.UdfpsLog
import com.google.errorprone.annotations.CompileTimeConstant
import javax.inject.Inject

private const val TAG = "UdfpsLogger"

/** Helper class for logging for Udfps */
class UdfpsLogger @Inject constructor(@UdfpsLog private val logBuffer: LogBuffer) {
    fun e(tag: String, @CompileTimeConstant msg: String) = log(tag, msg, ERROR)

    fun e(tag: String, @CompileTimeConstant msg: String, throwable: Throwable?) {
        logBuffer.log(tag, ERROR, {}, { msg }, exception = throwable)
    }

    fun v(tag: String, @CompileTimeConstant msg: String) = log(tag, msg, VERBOSE)

    fun w(tag: String, @CompileTimeConstant msg: String) = log(tag, msg, WARNING)

    fun log(tag: String, @CompileTimeConstant msg: String, level: LogLevel) {
        logBuffer.log(tag, level, msg)
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -160,6 +160,8 @@ public class AuthControllerTest extends SysuiTestCase {
    @Mock
    private StatusBarStateController mStatusBarStateController;
    @Mock
    private UdfpsLogger mUdfpsLogger;
    @Mock
    private InteractionJankMonitor mInteractionJankMonitor;
    @Captor
    private ArgumentCaptor<IFingerprintAuthenticatorsRegisteredCallback> mFpAuthenticatorsRegisteredCaptor;
@@ -978,7 +980,7 @@ public class AuthControllerTest extends SysuiTestCase {
            super(context, execution, commandQueue, activityTaskManager, windowManager,
                    fingerprintManager, faceManager, udfpsControllerFactory,
                    sidefpsControllerFactory, mDisplayManager, mWakefulnessLifecycle,
                    mUserManager, mLockPatternUtils, statusBarStateController,
                    mUserManager, mLockPatternUtils, mUdfpsLogger, statusBarStateController,
                    mInteractionJankMonitor, mHandler, mBackgroundExecutor, vibratorHelper);
        }

Loading