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

Commit fca3b87b authored by Jeffrey Young's avatar Jeffrey Young
Browse files

optional hide notifications shade on ALL_APPS key

Create boolean config_enableHideNotificationsShadeOnAllAppsKey to hide
notifications shade when a user presses ALL_APPS key to show the apps
drawer. The notifications shade will animate away as the apps drawer
animates in.

tablet with config enabled (default false):
go/scrcast/NDUwNzk0MDMwMzE0MjkxMnwwNWUwYTFjNy1jZA

desktop with config enabled (default true):
go/scrcast/NjY4NTU2MDY5NjQ3MTU1MnwxYWFhMmQwZS1jNQ

Bug: 433185712
Test: press ALL_APPS key on desktop
Test: atest SystemUITests
Flag: com.android.systemui.scene_container
Change-Id: I691bd850ed53d658c2dfa49b0b5b5b6e3a2b8bc8
parent 35a0ecb5
Loading
Loading
Loading
Loading
+45 −2
Original line number Diff line number Diff line
@@ -16,17 +16,22 @@

package com.android.systemui.keyevent

import android.content.res.Resources
import android.hardware.input.InputManager
import android.hardware.input.InputManager.KeyGestureEventHandler
import android.hardware.input.InputManager.KeyGestureEventListener
import android.hardware.input.KeyGestureEvent
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_ALL_APPS
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_QUICK_SETTINGS_PANEL
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TASKBAR
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_SCENE_CONTAINER
import com.android.systemui.SysuiTestCase
import com.android.systemui.res.R
import com.android.systemui.shade.display.StatusBarTouchShadeDisplayPolicy
import com.android.systemui.statusbar.CommandQueue
import com.google.common.truth.Truth.assertThat
@@ -39,8 +44,10 @@ import org.mockito.Captor
import org.mockito.Mock
import org.mockito.junit.MockitoJUnit
import org.mockito.kotlin.any
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoInteractions
import org.mockito.kotlin.whenever

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -49,15 +56,25 @@ class SysUIKeyGestureEventInitializerTest : SysuiTestCase() {
    @Mock private lateinit var inputManager: InputManager
    @Mock private lateinit var commandQueue: CommandQueue
    @Mock private lateinit var shadeDisplayPolicy: StatusBarTouchShadeDisplayPolicy
    @Mock private lateinit var resources: Resources
    @Captor private lateinit var keyGestureEventsCaptor: ArgumentCaptor<List<Int>>
    @Captor
    private lateinit var keyGestureEventHandlerCaptor: ArgumentCaptor<KeyGestureEventHandler>
    @Captor
    private lateinit var keyGestureEventListenerCaptor: ArgumentCaptor<KeyGestureEventListener>

    private lateinit var underTest: SysUIKeyGestureEventInitializer

    @Before
    fun setup() {
        underTest = SysUIKeyGestureEventInitializer(inputManager, commandQueue, shadeDisplayPolicy)
        underTest =
            SysUIKeyGestureEventInitializer(
                context.mainExecutor,
                resources,
                inputManager,
                commandQueue,
                shadeDisplayPolicy,
            )
    }

    @Test
@@ -133,10 +150,36 @@ class SysUIKeyGestureEventInitializerTest : SysuiTestCase() {
            .registerKeyGestureEventHandler(any(), keyGestureEventHandlerCaptor.capture())

        keyGestureEventHandlerCaptor.value.handleKeyGestureEvent(
            KeyGestureEvent.Builder().setKeyGestureType(KEY_GESTURE_TYPE_ALL_APPS).build(),
            KeyGestureEvent.Builder().setKeyGestureType(KEY_GESTURE_TYPE_TOGGLE_TASKBAR).build(),
            /* focusedToken= */ null,
        )

        verifyNoInteractions(commandQueue)
    }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun observeKeyGestureEvent_configEnableHideNotificationsShadeOff_noInteraction() {
        whenever(resources.getBoolean(R.bool.config_enableHideNotificationsShadeOnAllAppsKey))
            .thenReturn(false)
        underTest.start()
        verify(inputManager, never()).registerKeyGestureEventListener(any(), any())
        verifyNoInteractions(commandQueue)
    }

    @Test
    @EnableFlags(FLAG_SCENE_CONTAINER)
    fun observeKeyGestureEvent_configEnableHideNotificationsShadeOn_animateCollapsePanels() {
        whenever(resources.getBoolean(R.bool.config_enableHideNotificationsShadeOnAllAppsKey))
            .thenReturn(true)
        underTest.start()
        verify(inputManager)
            .registerKeyGestureEventListener(any(), keyGestureEventListenerCaptor.capture())

        keyGestureEventListenerCaptor.value.onKeyGestureEvent(
            KeyGestureEvent.Builder().setKeyGestureType(KEY_GESTURE_TYPE_ALL_APPS).build()
        )

        verify(commandQueue).animateCollapsePanels()
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -1189,4 +1189,7 @@

    <!-- Indicates whether the blurred wallpaper is supported -->
    <bool name="config_supportBlurredWallpaper">true</bool>

    <!-- Whether to hide notifications shade when the user presses ALL_APPS key. -->
    <bool name="config_enableHideNotificationsShadeOnAllAppsKey">false</bool>
</resources>
+27 −1
Original line number Diff line number Diff line
@@ -16,16 +16,22 @@

package com.android.systemui.keyevent

import android.content.res.Resources
import android.hardware.input.InputManager
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_ALL_APPS
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_QUICK_SETTINGS_PANEL
import android.util.Slog
import com.android.hardware.input.Flags.enableQuickSettingsPanelShortcut
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.res.R
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.shade.display.StatusBarTouchShadeDisplayPolicy
import com.android.systemui.statusbar.CommandQueue
import com.android.window.flags.Flags.enableKeyGestureHandlerForSysui
import java.util.concurrent.Executor
import javax.inject.Inject

/**
@@ -36,11 +42,18 @@ import javax.inject.Inject
class SysUIKeyGestureEventInitializer
@Inject
constructor(
    @Main private val mainExecutor: Executor,
    @Main private val resources: Resources,
    private val inputManager: InputManager,
    private val commandQueue: CommandQueue,
    private val shadeDisplayPolicy: StatusBarTouchShadeDisplayPolicy,
) : CoreStartable {
    override fun start() {
        registerKeyGestureEventHandlers()
        registerKeyGestureEventListeners()
    }

    private fun registerKeyGestureEventHandlers() {
        val supportedGestures = mutableListOf<Int>()
        if (enableKeyGestureHandlerForSysui()) {
            supportedGestures.add(KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL)
@@ -61,8 +74,21 @@ constructor(
                    shadeDisplayPolicy.onQSPanelKeyboardShortcut()
                    commandQueue.toggleQuickSettingsPanel()
                }
                else ->
                    Slog.w(TAG, "Unsupported key gesture event handler: ${event.keyGestureType}")
            }
        }
    }

                else -> Slog.w(TAG, "Unsupported key gesture event: ${event.keyGestureType}")
    private fun registerKeyGestureEventListeners() {
        val enableHideNotificationsShade =
            resources.getBoolean(R.bool.config_enableHideNotificationsShadeOnAllAppsKey)
        if (!SceneContainerFlag.isEnabled || !enableHideNotificationsShade) {
            return
        }
        inputManager.registerKeyGestureEventListener(mainExecutor) { event ->
            if (event.keyGestureType == KEY_GESTURE_TYPE_ALL_APPS) {
                commandQueue.animateCollapsePanels()
            }
        }
    }