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

Commit d96a90be authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Avoid disabling long clicks for small dual target

Small dual target tiles use the main click on long press and should as a result ignore whether the tile handles normal long clicks

Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Fixes: 416246243
Test: manually, disabling long clicks for bluetooth and long pressing on its small format
Test: TileTest.kt
Change-Id: Iaa028697cc22261f9d36a98ed8e285a1b3785855
parent a60b62c5
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -192,21 +192,22 @@ fun Tile(
                    )
                    .graphicsLayer { alpha = animatedAlpha },
        ) { expandable ->
            // Use main click on long press for small, available dual target tiles.
            // Open settings otherwise.
            val useLongClickToSettings = !(iconOnly && isDualTarget && isClickable)
            val longClick: (() -> Unit)? =
                {
                        hapticsViewModel?.setTileInteractionState(
                            TileHapticsViewModel.TileInteractionState.LONG_CLICKED
                        )

                        // User main click on long press for small dual target tiles
                        if (iconOnly && isDualTarget) {
                            tile.mainClick(expandable)
                        } else {
                            // Settings click otherwise
                        if (useLongClickToSettings) {
                            tile.settingsClick(expandable)
                        } else {
                            tile.mainClick(expandable)
                        }
                    }
                    .takeIf { uiState.handlesLongClick }
                    .takeIf { !useLongClickToSettings || uiState.handlesLongClick }

            TileContainer(
                onClick = onClick@{
+106 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs.panels.ui.compose

import android.service.quicksettings.Tile.STATE_UNAVAILABLE
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.test.junit4.createComposeRule
@@ -204,6 +205,111 @@ class TileTest : SysuiTestCase() {
        assertThat(tile.interactions).containsExactly(InteractableFakeQSTile.Interaction.CLICK)
    }

    @Test
    fun longClick_smallDualTargetTile_doesNotHandleLongClick_shouldReceiveClick() {
        val tile = InteractableFakeQSTile()
        tile.fakeTile.changeState(
            QSTile.State().apply {
                contentDescription = "smallDualTargetTile"
                handlesSecondaryClick = true
                handlesLongClick = false
            }
        )
        val viewModel = TileViewModel(tile.fakeTile, TileSpec.Companion.create("test"))

        composeRule.setContent { TestTile(viewModel, iconOnly = true) }
        composeRule.waitForIdle()

        composeRule.onNodeWithContentDescription("smallDualTargetTile").performTouchInput {
            longClick()
        }

        assertThat(tile.interactions).containsExactly(InteractableFakeQSTile.Interaction.CLICK)
    }

    @Test
    fun longClick_largeDualTargetTile_doesNotHandleLongClick_shouldNotReceiveLongClick() {
        val tile = InteractableFakeQSTile()
        tile.fakeTile.changeState(
            QSTile.State().apply {
                label = "largeDualTargetTile"
                handlesSecondaryClick = true
                handlesLongClick = false
            }
        )
        val viewModel = TileViewModel(tile.fakeTile, TileSpec.Companion.create("test"))

        composeRule.setContent { TestTile(viewModel, iconOnly = false) }
        composeRule.waitForIdle()

        composeRule.onNodeWithText("largeDualTargetTile").performTouchInput { longClick() }

        // Long clicks default to a normal click when a tile does not handle long clicks
        assertThat(tile.interactions).containsExactly(InteractableFakeQSTile.Interaction.CLICK)
    }

    @Test
    fun longClick_smallTile_doesNotHandleLongClick_shouldNotReceiveLongClick() {
        val tile = InteractableFakeQSTile()
        tile.fakeTile.changeState(
            QSTile.State().apply {
                contentDescription = "smallTile"
                handlesLongClick = false
            }
        )
        val viewModel = TileViewModel(tile.fakeTile, TileSpec.Companion.create("test"))

        composeRule.setContent { TestTile(viewModel, iconOnly = true) }
        composeRule.waitForIdle()

        composeRule.onNodeWithContentDescription("smallTile").performTouchInput { longClick() }

        // Long clicks default to a normal click when a tile does not handle long clicks
        assertThat(tile.interactions).containsExactly(InteractableFakeQSTile.Interaction.CLICK)
    }

    @Test
    fun longClick_largeTile_doesNotHandleLongClick_shouldReceiveLongClick() {
        val tile = InteractableFakeQSTile()
        tile.fakeTile.changeState(
            QSTile.State().apply {
                label = "largeTile"
                handlesLongClick = false
            }
        )
        val viewModel = TileViewModel(tile.fakeTile, TileSpec.Companion.create("test"))

        composeRule.setContent { TestTile(viewModel, iconOnly = false) }
        composeRule.waitForIdle()

        composeRule.onNodeWithText("largeTile").performTouchInput { longClick() }

        // Long clicks default to a normal click when a tile does not handle long clicks
        assertThat(tile.interactions).containsExactly(InteractableFakeQSTile.Interaction.CLICK)
    }

    @Test
    fun longClick_smallDualTargetTile_isUnavailable_shouldReceiveLongClick() {
        val tile = InteractableFakeQSTile()
        tile.fakeTile.changeState(
            QSTile.State().apply {
                contentDescription = "smallDualTargetTile"
                handlesSecondaryClick = true
                state = STATE_UNAVAILABLE
            }
        )
        val viewModel = TileViewModel(tile.fakeTile, TileSpec.Companion.create("test"))

        composeRule.setContent { TestTile(viewModel, iconOnly = true) }
        composeRule.waitForIdle()

        composeRule.onNodeWithContentDescription("smallDualTargetTile").performTouchInput {
            longClick()
        }

        assertThat(tile.interactions).containsExactly(InteractableFakeQSTile.Interaction.LONG_CLICK)
    }

    private class InteractableFakeQSTile {
        val interactions = mutableListOf<Interaction>()