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

Commit ba098cee authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Fix falsing in new QS

This reproduces the falsing calls that indicates interactions with QS
from the legacy code.

Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Bug: 379311646
Test: manual, swipe pages and brightness on lockscreen
Change-Id: I071e759ec0db19a23887e1f65ded6f6f827b72b9
parent edf62212
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.brightness.domain.interactor.brightnessPolicyEnforce
import com.android.systemui.brightness.domain.interactor.screenBrightnessInteractor
import com.android.systemui.brightness.shared.model.GammaBrightness
import com.android.systemui.brightness.shared.model.LinearBrightness
import com.android.systemui.classifier.domain.interactor.falsingInteractor
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
@@ -61,6 +62,7 @@ class BrightnessSliderViewModelTest : SysuiTestCase() {
                brightnessPolicyEnforcementInteractor,
                sliderHapticsViewModelFactory,
                brightnessMirrorShowingInteractor,
                falsingInteractor,
                supportsMirroring = true,
                brightnessWarningToast,
            )
+12 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.brightness.ui.compose

import android.view.MotionEvent
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.Orientation
@@ -41,6 +42,7 @@ import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
@@ -221,7 +223,16 @@ fun BrightnessSliderContainer(
                    )
                    .then(if (viewModel.showMirror) Modifier.drawInOverlay() else Modifier)
                    .sliderBackground(containerColor)
                    .fillMaxWidth(),
                    .fillMaxWidth()
                    .pointerInteropFilter {
                        if (
                            it.actionMasked == MotionEvent.ACTION_UP ||
                                it.actionMasked == MotionEvent.ACTION_CANCEL
                        ) {
                            viewModel.emitBrightnessTouchForFalsing()
                        }
                        false
                    },
            formatter = viewModel::formatValue,
            hapticsViewModelFactory = viewModel.hapticsViewModelFactory,
        )
+8 −1
Original line number Diff line number Diff line
@@ -16,12 +16,14 @@

package com.android.systemui.brightness.ui.viewmodel

import androidx.compose.runtime.getValue
import android.content.Context
import androidx.annotation.StringRes
import androidx.compose.runtime.getValue
import com.android.systemui.brightness.domain.interactor.BrightnessPolicyEnforcementInteractor
import com.android.systemui.brightness.domain.interactor.ScreenBrightnessInteractor
import com.android.systemui.brightness.shared.model.GammaBrightness
import com.android.systemui.classifier.Classifier
import com.android.systemui.classifier.domain.interactor.FalsingInteractor
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
@@ -52,6 +54,7 @@ constructor(
    private val brightnessPolicyEnforcementInteractor: BrightnessPolicyEnforcementInteractor,
    val hapticsViewModelFactory: SliderHapticsViewModel.Factory,
    private val brightnessMirrorShowingInteractor: BrightnessMirrorShowingInteractor,
    private val falsingInteractor: FalsingInteractor,
    @Assisted private val supportsMirroring: Boolean,
    private val brightnessWarningToast: BrightnessWarningToast,
) : ExclusiveActivatable() {
@@ -87,6 +90,10 @@ constructor(
        brightnessWarningToast.show(viewContext, resId)
    }

    fun emitBrightnessTouchForFalsing() {
        falsingInteractor.isFalseTouch(Classifier.BRIGHTNESS_SLIDER)
    }

    /**
     * As a brightness slider is dragged, the corresponding events should be sent using this method.
     */
+30 −0
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ constructor(
                // Only allow scrolling when we are fully expanded. That way, we don't intercept
                // swipes in lockscreen (when somehow QS is receiving touches).
                { (scrollState.canScrollForward && viewModel.isQsFullyExpanded) || isCustomizing },
                viewModel::emitMotionEventForFalsingSwipeNested,
            )
        frame.addView(
            composeView,
@@ -951,6 +952,7 @@ private class FrameLayoutTouchPassthrough(
    private val clippingEnabledProvider: () -> Boolean,
    private val clippingTopProvider: () -> Int,
    private val canScrollForwardQs: () -> Boolean,
    private val emitMotionEventForFalsing: () -> Unit,
) : FrameLayout(context) {
    override fun isTransformedTouchPointInView(
        x: Float,
@@ -967,6 +969,32 @@ private class FrameLayoutTouchPassthrough(

    val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
    var downY = 0f
    var preventingIntercept = false

    override fun onTouchEvent(event: MotionEvent): Boolean {
        val action = event.actionMasked
        when (action) {
            MotionEvent.ACTION_DOWN -> {
                preventingIntercept = false
                if (canScrollVertically(1)) {
                    // If we can scroll down, make sure we're not intercepted by the parent
                    preventingIntercept = true
                    parent?.requestDisallowInterceptTouchEvent(true)
                } else if (!canScrollVertically(-1)) {
                    // Don't pass on the touch to the view, because scrolling will unconditionally
                    // disallow interception even if we can't scroll.
                    // if a user can't scroll at all, we should never listen to the touch.
                    return false
                }
            }
            MotionEvent.ACTION_UP -> {
                if (preventingIntercept) {
                    emitMotionEventForFalsing()
                }
            }
        }
        return super.onTouchEvent(event)
    }

    override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
        // If there's a touch on this view and we can scroll down, we don't want to be intercepted
@@ -974,8 +1002,10 @@ private class FrameLayoutTouchPassthrough(

        when (action) {
            MotionEvent.ACTION_DOWN -> {
                preventingIntercept = false
                // If we can scroll down, make sure none of our parents intercepts us.
                if (canScrollForwardQs()) {
                    preventingIntercept = true
                    parent?.requestDisallowInterceptTouchEvent(true)
                }
                downY = ev.y
+0 −1
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.qs.composefragment.dagger

import android.content.Context
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.table.TableLogBuffer
import com.android.systemui.log.table.TableLogBufferFactory
import com.android.systemui.qs.flags.QSComposeFragment
Loading