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

Commit 40ffdccd authored by Alina Zaidi's avatar Alina Zaidi Committed by Android (Google) Code Review
Browse files

Merge "Use BooleanSupplier instead of a class for status bar interaction gate" into main

parents 228cb24a 4d19277d
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import com.android.systemui.res.R;
import com.android.systemui.shade.ShadeExpandsOnStatusBarLongPress;
import com.android.systemui.shade.StatusBarLongPressGestureDetector;
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays;
import com.android.systemui.statusbar.phone.PhoneStatusBarViewController.PhoneStatusBarViewInteractionsGate;
import com.android.systemui.statusbar.phone.userswitcher.StatusBarUserSwitcherContainer;
import com.android.systemui.statusbar.window.StatusBarWindowControllerStore;
import com.android.systemui.user.ui.binder.StatusBarUserChipViewBinder;
@@ -50,6 +49,7 @@ import com.android.systemui.user.ui.viewmodel.StatusBarUserChipViewModel;
import com.android.systemui.util.leak.RotationUtils;

import java.util.Objects;
import java.util.function.BooleanSupplier;

public class PhoneStatusBarView extends FrameLayout {
    private static final String TAG = "PhoneStatusBarView";
@@ -66,7 +66,7 @@ public class PhoneStatusBarView extends FrameLayout {
    @Nullable
    private Gefingerpoken mTouchEventHandler;
    @Nullable
    private PhoneStatusBarViewInteractionsGate mInteractionGate;
    private BooleanSupplier mIsStatusBarInteractiveSupplier;
    @Nullable
    private HasCornerCutoutFetcher mHasCornerCutoutFetcher;
    @Nullable
@@ -96,8 +96,8 @@ public class PhoneStatusBarView extends FrameLayout {
        mTouchEventHandler = handler;
    }

    void setInteractionGate(PhoneStatusBarViewInteractionsGate gate) {
        mInteractionGate = gate;
    void setIsStatusBarInteractiveSupplier(BooleanSupplier isStatusBarInteractiveSupplier) {
        mIsStatusBarInteractiveSupplier = isStatusBarInteractiveSupplier;
    }

    void setHasCornerCutoutFetcher(@NonNull HasCornerCutoutFetcher cornerCutoutFetcher) {
@@ -216,7 +216,8 @@ public class PhoneStatusBarView extends FrameLayout {

    @Override
    public boolean dispatchHoverEvent(MotionEvent event) {
        if (mInteractionGate != null && !mInteractionGate.shouldAllowInteractions()) {
        if (mIsStatusBarInteractiveSupplier != null
                && !mIsStatusBarInteractiveSupplier.getAsBoolean()) {
            // Consume the event to prevent any calls to #onHoverEvent on status bar view or its
            // components, essentially making the status bar and its children completely
            // non-interactive.
@@ -227,7 +228,8 @@ public class PhoneStatusBarView extends FrameLayout {

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        if (mInteractionGate != null && !mInteractionGate.shouldAllowInteractions()) {
        if (mIsStatusBarInteractiveSupplier != null
                && !mIsStatusBarInteractiveSupplier.getAsBoolean()) {
            // Consume the event to prevent any calls to #onTouchEvent on status bar view or its
            // components, essentially making the status bar and its children completely
            // non-interactive.
+7 −18
Original line number Diff line number Diff line
@@ -139,7 +139,13 @@ private constructor(
        ) {
            // With the StatusBarConnectedDisplays changes, external status bar elements are not
            // interactive when the shade window can't change displays.
            mView.setInteractionGate(PhoneStatusBarViewInteractionsGate())
            mView.setIsStatusBarInteractiveSupplier {
                val shadeDisplayPolicy =
                    if (ShadeWindowGoesAround.isEnabled) {
                        lazyShadeDisplaysRepository.get().currentPolicy
                    } else null
                shadeDisplayPolicy is StatusBarTouchShadeDisplayPolicy
            }
        }

        addCursorSupportToIconContainers()
@@ -245,23 +251,6 @@ private constructor(
        darkIconDispatcher.removeDarkReceiver(clock)
    }

    /**
     * Determines whether user interaction (e.g., touch and hover events with the phone's status bar
     * view should be allowed.
     */
    inner class PhoneStatusBarViewInteractionsGate {
        /** Checks if user interactions with the status bar are currently permitted. */
        fun shouldAllowInteractions(): Boolean {
            // With the StatusBarConnectedDisplays changes, external status bar elements are not
            // interactive when the shade window can't change displays.
            val shadeDisplayPolicy =
                if (ShadeWindowGoesAround.isEnabled) {
                    lazyShadeDisplaysRepository.get().currentPolicy
                } else null
            return shadeDisplayPolicy is StatusBarTouchShadeDisplayPolicy
        }
    }

    inner class PhoneStatusBarViewTouchHandler : Gefingerpoken {
        override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
            if (event.action == MotionEvent.ACTION_DOWN) {
+23 −23
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ import com.android.systemui.shade.shared.model.ShadeMode
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
import com.android.systemui.statusbar.data.repository.fakeStatusBarContentInsetsProviderStore
import com.android.systemui.statusbar.phone.PhoneStatusBarViewController.PhoneStatusBarViewInteractionsGate
import com.android.systemui.statusbar.policy.Clock
import com.android.systemui.statusbar.policy.mockStatusBarConfigurationController
import com.android.systemui.statusbar.window.StatusBarWindowStateController
@@ -75,6 +74,7 @@ import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.view.ViewUtil
import com.google.common.truth.Truth.assertThat
import java.util.Optional
import java.util.function.BooleanSupplier
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -214,7 +214,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
            controller = createAndInitController(view)
        }

        verify(view, never()).setInteractionGate(any())
        verify(view, never()).setIsStatusBarInteractiveSupplier(any())
    }

    @Test
@@ -226,7 +226,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
            controller = createAndInitController(view)
        }

        verify(view, never()).setInteractionGate(any())
        verify(view, never()).setIsStatusBarInteractiveSupplier(any())
    }

    @Test
@@ -238,7 +238,7 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
            controller = createAndInitController(viewForSecondaryDisplay)
        }

        verify(viewForSecondaryDisplay).setInteractionGate(any())
        verify(viewForSecondaryDisplay).setIsStatusBarInteractiveSupplier(any())
    }

    @Test
@@ -359,9 +359,9 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        whenever(shadeViewController.isViewEnabled).thenReturn(true)
        // Ensure test is set up with an interaction gate that allows interactions.
        whenever(shadeDisplayRepository.currentPolicy).thenReturn(statusBarTouchShadeDisplayPolicy)
        val argumentCaptor = ArgumentCaptor.forClass(PhoneStatusBarViewInteractionsGate::class.java)
        verify(viewForSecondaryDisplay).setInteractionGate(argumentCaptor.capture())
        assertThat(argumentCaptor.value.shouldAllowInteractions()).isTrue()
        val argumentCaptor = ArgumentCaptor.forClass(BooleanSupplier::class.java)
        verify(viewForSecondaryDisplay).setIsStatusBarInteractiveSupplier(argumentCaptor.capture())
        assertThat(argumentCaptor.value.asBoolean).isTrue()
        val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 2f, 0)

        viewForSecondaryDisplay.dispatchTouchEvent(event)
@@ -384,9 +384,9 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        whenever(shadeViewController.isViewEnabled).thenReturn(true)
        // Ensure test is set up with an interaction gate that does not allow interactions.
        whenever(shadeDisplayRepository.currentPolicy).thenReturn(kosmos.defaultShadeDisplayPolicy)
        val argumentCaptor = ArgumentCaptor.forClass(PhoneStatusBarViewInteractionsGate::class.java)
        verify(viewForSecondaryDisplay).setInteractionGate(argumentCaptor.capture())
        assertThat(argumentCaptor.value.shouldAllowInteractions()).isFalse()
        val argumentCaptor = ArgumentCaptor.forClass(BooleanSupplier::class.java)
        verify(viewForSecondaryDisplay).setIsStatusBarInteractiveSupplier(argumentCaptor.capture())
        assertThat(argumentCaptor.value.asBoolean).isFalse()
        val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 2f, 0)

        viewForSecondaryDisplay.dispatchTouchEvent(event)
@@ -553,10 +553,10 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            controller = createAndInitController(viewForSecondaryDisplay)
        }
        val argumentCaptor = ArgumentCaptor.forClass(PhoneStatusBarViewInteractionsGate::class.java)
        verify(viewForSecondaryDisplay).setInteractionGate(argumentCaptor.capture())
        val argumentCaptor = ArgumentCaptor.forClass(BooleanSupplier::class.java)
        verify(viewForSecondaryDisplay).setIsStatusBarInteractiveSupplier(argumentCaptor.capture())

        assertThat(argumentCaptor.value.shouldAllowInteractions()).isFalse()
        assertThat(argumentCaptor.value.asBoolean).isFalse()
    }

    @Test
@@ -566,11 +566,11 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            controller = createAndInitController(viewForSecondaryDisplay)
        }
        val argumentCaptor = ArgumentCaptor.forClass(PhoneStatusBarViewInteractionsGate::class.java)
        verify(viewForSecondaryDisplay).setInteractionGate(argumentCaptor.capture())
        val argumentCaptor = ArgumentCaptor.forClass(BooleanSupplier::class.java)
        verify(viewForSecondaryDisplay).setIsStatusBarInteractiveSupplier(argumentCaptor.capture())

        whenever(shadeDisplayRepository.currentPolicy).thenReturn(kosmos.defaultShadeDisplayPolicy)
        assertThat(argumentCaptor.value.shouldAllowInteractions()).isFalse()
        assertThat(argumentCaptor.value.asBoolean).isFalse()
    }

    @Test
@@ -580,11 +580,11 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            controller = createAndInitController(viewForSecondaryDisplay)
        }
        val argumentCaptor = ArgumentCaptor.forClass(PhoneStatusBarViewInteractionsGate::class.java)
        verify(viewForSecondaryDisplay).setInteractionGate(argumentCaptor.capture())
        val argumentCaptor = ArgumentCaptor.forClass(BooleanSupplier::class.java)
        verify(viewForSecondaryDisplay).setIsStatusBarInteractiveSupplier(argumentCaptor.capture())

        whenever(shadeDisplayRepository.currentPolicy).thenReturn(statusBarTouchShadeDisplayPolicy)
        assertThat(argumentCaptor.value.shouldAllowInteractions()).isTrue()
        assertThat(argumentCaptor.value.asBoolean).isTrue()
    }

    @Test
@@ -594,14 +594,14 @@ class PhoneStatusBarViewControllerTest(flags: FlagsParameterization) : SysuiTest
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            controller = createAndInitController(viewForSecondaryDisplay)
        }
        val argumentCaptor = ArgumentCaptor.forClass(PhoneStatusBarViewInteractionsGate::class.java)
        verify(viewForSecondaryDisplay).setInteractionGate(argumentCaptor.capture())
        val argumentCaptor = ArgumentCaptor.forClass(BooleanSupplier::class.java)
        verify(viewForSecondaryDisplay).setIsStatusBarInteractiveSupplier(argumentCaptor.capture())

        whenever(shadeDisplayRepository.currentPolicy).thenReturn(kosmos.defaultShadeDisplayPolicy)
        assertThat(argumentCaptor.value.shouldAllowInteractions()).isFalse()
        assertThat(argumentCaptor.value.asBoolean).isFalse()

        whenever(shadeDisplayRepository.currentPolicy).thenReturn(statusBarTouchShadeDisplayPolicy)
        assertThat(argumentCaptor.value.shouldAllowInteractions()).isTrue()
        assertThat(argumentCaptor.value.asBoolean).isTrue()
    }

    @Test
+4 −11
Original line number Diff line number Diff line
@@ -72,9 +72,6 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
    @Mock private lateinit var windowController: StatusBarWindowController
    @Mock private lateinit var windowControllerStore: StatusBarWindowControllerStore
    @Mock private lateinit var longPressGestureDetector: StatusBarLongPressGestureDetector
    @Mock
    private lateinit var interactionGate:
        PhoneStatusBarViewController.PhoneStatusBarViewInteractionsGate

    @Before
    fun setUp() {
@@ -121,8 +118,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
        val handler = TestTouchEventHandler()
        viewForSecondaryDisplay.setTouchEventHandler(handler)
        viewForSecondaryDisplay.setLongPressGestureDetector(longPressGestureDetector)
        whenever(interactionGate.shouldAllowInteractions()).thenReturn(true)
        viewForSecondaryDisplay.setInteractionGate(interactionGate)
        viewForSecondaryDisplay.setIsStatusBarInteractiveSupplier { true }

        val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
        viewForSecondaryDisplay.dispatchTouchEvent(event)
@@ -137,8 +133,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
        val handler = TestTouchEventHandler()
        viewForSecondaryDisplay.setTouchEventHandler(handler)
        viewForSecondaryDisplay.setLongPressGestureDetector(longPressGestureDetector)
        whenever(interactionGate.shouldAllowInteractions()).thenReturn(false)
        viewForSecondaryDisplay.setInteractionGate(interactionGate)
        viewForSecondaryDisplay.setIsStatusBarInteractiveSupplier { false }

        val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)

@@ -163,8 +158,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
        val handler = TestTouchEventHandler()
        viewForSecondaryDisplay.setTouchEventHandler(handler)
        viewForSecondaryDisplay.setLongPressGestureDetector(longPressGestureDetector)
        whenever(interactionGate.shouldAllowInteractions()).thenReturn(true)
        viewForSecondaryDisplay.setInteractionGate(interactionGate)
        viewForSecondaryDisplay.setIsStatusBarInteractiveSupplier { true }

        val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
        assertThat(viewForSecondaryDisplay.dispatchHoverEvent(event)).isEqualTo(false)
@@ -175,8 +169,7 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
        val handler = TestTouchEventHandler()
        viewForSecondaryDisplay.setTouchEventHandler(handler)
        viewForSecondaryDisplay.setLongPressGestureDetector(longPressGestureDetector)
        whenever(interactionGate.shouldAllowInteractions()).thenReturn(false)
        viewForSecondaryDisplay.setInteractionGate(interactionGate)
        viewForSecondaryDisplay.setIsStatusBarInteractiveSupplier { false }

        val event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)
        assertThat(viewForSecondaryDisplay.dispatchHoverEvent(event)).isEqualTo(true)