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

Commit 0d288bc1 authored by nift4's avatar nift4 Committed by Sahil Sonar
Browse files

SystemUI: udfps: fix framework dimming

Change-Id: I8719d1d3b86403266c2055ddb38f34b3a27ef6fb
parent 8bea74a3
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -1071,8 +1071,8 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        return brightness;
    }

    private void updateViewDimAmount() {
        if (mOverlay == null || !mUseFrameworkDimming) {
    private void updateViewDimAmount(UdfpsControllerOverlay overlay) {
        if (overlay == null || !mUseFrameworkDimming) {
            return;
        } else if (isFingerDown()) {
            int curBrightness = getBrightness();
@@ -1089,9 +1089,9 @@ public class UdfpsController implements DozeReceiver, Dumpable {
                        mBrightnessAlphaArray[i][0], mBrightnessAlphaArray[i-1][0],
                        mBrightnessAlphaArray[i][1], mBrightnessAlphaArray[i-1][1]);
            }
            mOverlay.setDimAmount(dimAmount / 255.0f);
            overlay.setDimAmount(dimAmount / 255.0f);
        } else {
            mOverlay.setDimAmount(0.0f);
            overlay.setDimAmount(0.0f);
        }
    }

@@ -1103,7 +1103,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mFingerprintManager.onUdfpsUiEvent(FingerprintManager.UDFPS_UI_READY, requestId,
                mSensorProps.sensorId);
        mLatencyTracker.onActionEnd(LatencyTracker.ACTION_UDFPS_ILLUMINATE);
        updateViewDimAmount();
        updateViewDimAmount(mOverlay);
    }

    private void onFingerDown(
@@ -1237,15 +1237,12 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        final int delay = mContext.getResources().getInteger(
                com.android.systemui.res.R.integer.config_udfpsDimmingDisableDelay);
        if (delay > 0) {
            UdfpsControllerOverlay overlay = mOverlay;
            mFgExecutor.executeDelayed(() -> {
                // A race condition exists where the overlay is destroyed before the dim amount
                // is updated. This check ensures that the overlay is still valid.
                if (mOverlay != null && mOverlay.matchesRequestId(requestId)) {
                    updateViewDimAmount();
                }
                updateViewDimAmount(overlay);
            }, delay);
        } else {
            updateViewDimAmount();
            updateViewDimAmount(mOverlay);
        }
    }

+38 −10
Original line number Diff line number Diff line
@@ -126,6 +126,10 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
        private val powerInteractor: PowerInteractor,
        @Application private val scope: CoroutineScope,
) {
    private var frame: View? = null
    private var isDimmed = false
    private var hideOnUndim = false

    private val currentStateUpdatedToOffAodOrDozing: Flow<Unit> =
        transitionInteractor.currentKeyguardState
            .filter {
@@ -171,21 +175,34 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
        layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
        flags = (Utils.FINGERPRINT_OVERLAY_LAYOUT_PARAM_FLAGS or
                WindowManager.LayoutParams.FLAG_SPLIT_TOUCH)
        if (frameworkDimming) {
            flags = flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND
        }
        privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY
        dimAmount = 0.0f
        // Avoid announcing window title.
        accessibilityTitle = " "
        inputFeatures = WindowManager.LayoutParams.INPUT_FEATURE_SPY
    }

    var dimAmount
        get() = coreLayoutParams.dimAmount
    var dimAmount: Float = 0f
        set(value) {
            coreLayoutParams.dimAmount = value
            windowManager.updateViewLayout(getTouchOverlay(), coreLayoutParams)
            frame?.setBackgroundColor((value * 255).toInt() shl 24)
            isDimmed = value > 0
            if (hideOnUndim) {
                hideFrame()
            }
        }

    private val frameLayoutParams = WindowManager.LayoutParams(
        WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
        Utils.FINGERPRINT_OVERLAY_LAYOUT_PARAM_FLAGS
            or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            or WindowManager.LayoutParams.FLAG_FULLSCREEN,
        PixelFormat.TRANSLUCENT
    ).apply {
        fitInsetsTypes = 0
        gravity = android.view.Gravity.TOP or android.view.Gravity.LEFT
        layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
        privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY
        // Avoid announcing window title.
        accessibilityTitle = " "
    }

    /** If the overlay is currently showing. */
@@ -220,6 +237,8 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
            overlayParams = params
            sensorBounds = Rect(params.sensorBounds)
            try {
                frame = View(context)
                dimAmount = 0f
                if (DeviceEntryUdfpsRefactor.isEnabled) {
                    overlayTouchView = (inflater.inflate(
                            R.layout.udfps_touch_overlay, null, false
@@ -229,7 +248,7 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
                        if (requestReason.isImportantForAccessibility()) {
                            importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
                        }

                        windowManager.addView(frame, frameLayoutParams)
                        addViewNowOrLater(this, null)
                        when (requestReason) {
                            REASON_AUTH_KEYGUARD ->
@@ -262,7 +281,7 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
                        if (requestReason.isImportantForAccessibility()) {
                            importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
                        }

                        windowManager.addView(frame, frameLayoutParams)
                        addViewNowOrLater(this, animation)
                        sensorRect = sensorBounds
                    }
@@ -420,6 +439,7 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
    /** Hide the overlay or return false and do nothing if it is already hidden. */
    fun hide(): Boolean {
        val wasShowing = isShowing
        hideOnUndim = isDimmed

        overlayViewLegacy?.apply {
            if (isDisplayConfigured) {
@@ -451,9 +471,17 @@ class UdfpsControllerOverlay @JvmOverloads constructor(
        overlayTouchListener = null
        listenForCurrentKeyguardState?.cancel()

        if (!hideOnUndim) hideFrame()
        return wasShowing
    }

    private fun hideFrame() {
        frame?.apply {
            windowManager.removeView(this)
        }
        frame = null
    }

    /** Cancel this request. */
    fun cancel() {
        try {