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

Commit ce05f32c authored by pjgowtham's avatar pjgowtham Committed by Bruno Martins
Browse files

UdfpsHelper: Track brightness mirror to hide/show dim layer

This provides a much deeper integration with UDFPS dim layer and the new
brightness slider such that we don't need to look for APIs that can
track temporary brightness. That is because when the brightness mirror
is shown, there is no necessity for the UDFPS dim layer to be present.
This change also isn't functional with the legacy slider.

It also fixes the issue where the dim layer is hidden with QS expansion
-> Device Control where the alternate bouncer is brought up.

Test: Ensure that appropriate transparency of the dim layer is set when
dragging or selecting the preferred brightness with the slider.

Change-Id: I53f78cbcfd3b42a3b5dbe6110424687ebfac102d
parent 6ef425b8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ import com.android.systemui.log.SessionTracker;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.power.domain.interactor.PowerInteractor;
import com.android.systemui.settings.brightness.domain.interactor.BrightnessMirrorShowingInteractor;
import com.android.systemui.shade.ShadeDisplayAware;
import com.android.systemui.shade.domain.interactor.ShadeInteractor;
import com.android.systemui.shared.system.SysUiStatsLog;
@@ -185,6 +186,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
    @NonNull private final AlternateBouncerInteractor mAlternateBouncerInteractor;
    @NonNull private final UdfpsOverlayInteractor mUdfpsOverlayInteractor;
    @NonNull private final PowerInteractor mPowerInteractor;
    @NonNull private final BrightnessMirrorShowingInteractor mBrightnessMirrorShowingInteractor;
    @NonNull private final CoroutineScope mScope;
    @NonNull private final InputManager mInputManager;
    @NonNull private final SelectedUserInteractor mSelectedUserInteractor;
@@ -297,6 +299,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
                        mShadeInteractor,
                        mUdfpsOverlayInteractor,
                        mPowerInteractor,
                        mBrightnessMirrorShowingInteractor,
                        mScope
                    )));
        }
@@ -695,6 +698,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
            Lazy<PromptUdfpsTouchOverlayViewModel> promptUdfpsTouchOverlayViewModel,
            @NonNull UdfpsOverlayInteractor udfpsOverlayInteractor,
            @NonNull PowerInteractor powerInteractor,
            @NonNull BrightnessMirrorShowingInteractor brightnessMirrorShowingInteractor,
            @Application CoroutineScope scope,
            UserActivityNotifier userActivityNotifier) {
        mContext = context;
@@ -739,6 +743,7 @@ public class UdfpsController implements DozeReceiver, Dumpable {
        mAlternateBouncerInteractor = alternateBouncerInteractor;
        mUdfpsOverlayInteractor = udfpsOverlayInteractor;
        mPowerInteractor = powerInteractor;
        mBrightnessMirrorShowingInteractor = brightnessMirrorShowingInteractor;
        mScope = scope;
        mInputManager = inputManager;
        mSelectedUserInteractor = selectedUserInteractor;
+4 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInterac
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.res.R
import com.android.systemui.settings.brightness.domain.interactor.BrightnessMirrorShowingInteractor
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.statusbar.policy.KeyguardStateController
import dagger.Lazy
@@ -88,6 +89,7 @@ constructor(
    private val shadeInteractor: ShadeInteractor,
    private val udfpsOverlayInteractor: UdfpsOverlayInteractor,
    private val powerInteractor: PowerInteractor,
    private val brightnessMirrorShowingInteractor: BrightnessMirrorShowingInteractor,
    @Application private val scope: CoroutineScope,
) {
    private val currentStateUpdatedToOffAodOrDozing: Flow<Unit> =
@@ -119,7 +121,8 @@ constructor(
    )

    private val udfpsHelper: UdfpsHelper? = if (useFrameworkDimming) {
        UdfpsHelper(context, windowManager, shadeInteractor, requestReason)
        UdfpsHelper(context, windowManager, shadeInteractor, requestReason,
                brightnessMirrorShowingInteractor)
    } else {
        null
    }
+14 −21
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The LineageOS Project
 * Copyright (C) 2024-2025 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.settings.brightness.domain.interactor.BrightnessMirrorShowingInteractor
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
@@ -49,6 +50,7 @@ class UdfpsHelper(
    private val windowManager: WindowManager,
    private val shadeInteractor: ShadeInteractor,
    @RequestReason val requestReason: Int,
    private val brightnessMirrorShowingInteractor: BrightnessMirrorShowingInteractor,
    private var view: View = View(context).apply {
        setBackgroundColor(Color.BLACK)
        visibility = View.GONE
@@ -56,7 +58,6 @@ class UdfpsHelper(
) {
    private val displayManager = context.getSystemService(DisplayManager::class.java)!!
    private val isKeyguard = requestReason == REASON_AUTH_KEYGUARD
    private var newIsQsExpanded = false

    private val currentBrightness: Float get() =
        displayManager.getBrightness(Display.DEFAULT_DISPLAY)
@@ -165,16 +166,23 @@ class UdfpsHelper(
    fun addDimLayer() {
        brightnessToAlpha()
        windowManager.addView(view, dimLayoutParams)
        displayManager.registerDisplayListener(
            displayListener,
            null,
            /* eventFlags */ 0,
            DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS,
        )
    }

    fun removeDimLayer() {
        windowManager.removeView(view)
        displayManager.unregisterDisplayListener(displayListener)
    }

    init {
        view.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.CREATED) {
                listenForQsExpansion(this)
                listenForBrightnessMirror(this)

                if (isKeyguard) {
                    listenForShadeTouchability(this)
@@ -187,25 +195,10 @@ class UdfpsHelper(
        }
    }

    // We don't have ways to get temporary brightness when operating the brightness slider.
    // Therefore, the dim layer is hidden when the slider is expected to be utilized.
    private suspend fun listenForQsExpansion(scope: CoroutineScope): Job {
    private suspend fun listenForBrightnessMirror(scope: CoroutineScope): Job {
        return scope.launch {
            shadeInteractor.qsExpansion.collect { qsExpansion ->
                if (qsExpansion == 1f && !newIsQsExpanded) {
                    newIsQsExpanded = true
                    displayManager.registerDisplayListener(
                        displayListener,
                        null,
                        /* eventFlags */ 0,
                        DisplayManager.PRIVATE_EVENT_TYPE_DISPLAY_BRIGHTNESS,
                    )
                    view.isVisible = false
                } else if (qsExpansion == 0f && newIsQsExpanded) {
                    newIsQsExpanded = false
                    displayManager.unregisterDisplayListener(displayListener)
                    view.isVisible = true
                }
            brightnessMirrorShowingInteractor.isShowing.collect {
                view.isVisible = !it
            }
        }
    }