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

Commit a43128a1 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

[flexiglass] Removes GestureFilter.

This is no longer deemed needed (and was the wrong solution anyway).

This is a manual revert of ag/29522052.

Bug: 367447743
Test: switched scenes successfully
Flag: com.android.systemui.scene_container
Change-Id: Ic80bd571482169f7d594320a017087b9ec6ef981
parent fa312e81
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.shared.model.sceneDataSourceDelegator
import com.android.systemui.scene.ui.composable.Scene
import com.android.systemui.scene.ui.composable.SceneContainer
import com.android.systemui.settings.displayTracker
import com.android.systemui.testKosmos
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.awaitCancellation
@@ -127,7 +126,7 @@ class BouncerPredictiveBackTest : SysuiTestCase() {

    private val sceneContainerViewModel by lazy {
        kosmos.sceneContainerViewModelFactory
            .create(view, kosmos.displayTracker.defaultDisplayId, {})
            .create(view) {}
            .apply { setTransitionState(transitionState) }
    }

+0 −112
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

@file:OptIn(ExperimentalCoroutinesApi::class)

package com.android.systemui.scene.ui.viewmodel

import android.graphics.Region
import android.view.setSystemGestureExclusionRegion
import androidx.compose.ui.geometry.Offset
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.testScope
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.scene.sceneContainerGestureFilterFactory
import com.android.systemui.settings.displayTracker
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class SceneContainerGestureFilterTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val displayId = kosmos.displayTracker.defaultDisplayId

    private val underTest = kosmos.sceneContainerGestureFilterFactory.create(displayId)
    private val activationJob = Job()

    @Test
    fun shouldFilterGesture_whenNoRegion_returnsFalse() =
        testScope.runTest {
            activate()
            setSystemGestureExclusionRegion(displayId, null)
            runCurrent()

            assertThat(underTest.shouldFilterGesture(Offset(100f, 100f))).isFalse()
        }

    @Test
    fun shouldFilterGesture_whenOutsideRegion_returnsFalse() =
        testScope.runTest {
            activate()
            setSystemGestureExclusionRegion(displayId, Region(0, 0, 200, 200))
            runCurrent()

            assertThat(underTest.shouldFilterGesture(Offset(300f, 100f))).isFalse()
        }

    @Test
    fun shouldFilterGesture_whenInsideRegion_returnsTrue() =
        testScope.runTest {
            activate()
            setSystemGestureExclusionRegion(displayId, Region(0, 0, 200, 200))
            runCurrent()

            assertThat(underTest.shouldFilterGesture(Offset(100f, 100f))).isTrue()
        }

    @Test(expected = IllegalStateException::class)
    fun shouldFilterGesture_beforeActivation_throws() =
        testScope.runTest {
            setSystemGestureExclusionRegion(displayId, Region(0, 0, 200, 200))
            runCurrent()

            underTest.shouldFilterGesture(Offset(100f, 100f))
        }

    @Test(expected = IllegalStateException::class)
    fun shouldFilterGesture_afterCancellation_throws() =
        testScope.runTest {
            activate()
            setSystemGestureExclusionRegion(displayId, Region(0, 0, 200, 200))
            runCurrent()

            cancel()

            underTest.shouldFilterGesture(Offset(100f, 100f))
        }

    private fun TestScope.activate() {
        underTest.activateIn(testScope, activationJob)
        runCurrent()
    }

    private fun TestScope.cancel() {
        activationJob.cancel()
        runCurrent()
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import com.android.systemui.scene.sceneContainerViewModelFactory
import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.shared.model.fakeSceneDataSource
import com.android.systemui.settings.displayTracker
import com.android.systemui.shade.data.repository.fakeShadeRepository
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.shared.flag.DualShade
@@ -82,7 +81,6 @@ class SceneContainerViewModelTest : SysuiTestCase() {
        underTest =
            kosmos.sceneContainerViewModelFactory.create(
                view,
                kosmos.displayTracker.defaultDisplayId,
                { motionEventHandler ->
                    this@SceneContainerViewModelTest.motionEventHandler = motionEventHandler
                },
+0 −56
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.scene.data.repository

import android.graphics.Region
import android.view.ISystemGestureExclusionListener
import android.view.IWindowManager
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import javax.inject.Inject
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow

@SysUISingleton
class SystemGestureExclusionRepository
@Inject
constructor(private val windowManager: IWindowManager) {

    /**
     * Returns [Flow] of the [Region] in which system gestures should be excluded on the display
     * identified with [displayId].
     */
    fun exclusionRegion(displayId: Int): Flow<Region?> {
        return conflatedCallbackFlow {
            val listener =
                object : ISystemGestureExclusionListener.Stub() {
                    override fun onSystemGestureExclusionChanged(
                        displayId: Int,
                        restrictedRegion: Region?,
                        unrestrictedRegion: Region?,
                    ) {
                        trySend(restrictedRegion)
                    }
                }
            windowManager.registerSystemGestureExclusionListener(listener, displayId)

            awaitClose {
                windowManager.unregisterSystemGestureExclusionListener(listener, displayId)
            }
        }
    }
}
+0 −35
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.scene.domain.interactor

import android.graphics.Region
import com.android.systemui.scene.data.repository.SystemGestureExclusionRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow

class SystemGestureExclusionInteractor
@Inject
constructor(private val repository: SystemGestureExclusionRepository) {

    /**
     * Returns [Flow] of the [Region] in which system gestures should be excluded on the display
     * identified with [displayId].
     */
    fun exclusionRegion(displayId: Int): Flow<Region?> {
        return repository.exclusionRegion(displayId)
    }
}
Loading