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

Commit b6a26e30 authored by Lucas Silva's avatar Lucas Silva
Browse files

Ensure reordering of notifications is allowed when communal is showing.

When on the hub, we should still allow notification reordering - as
notifications are hidden but can still be accessible via the shade.

Bug: 330532773
Test: dumpsysui VisualStabilityCoordinator
Test: atest VisualStabilityCoordinatorTest
Flag: ACONFIG com.android.systemui.communal_hub TEAMFOOD
Change-Id: I8a5b20feff062f4176cdc3927858d3f167a5d239
parent 2c765457
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.android.systemui.Dumpable;
import com.android.systemui.communal.domain.interactor.CommunalInteractor;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dump.DumpManager;
@@ -68,6 +69,7 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
    private final VisibilityLocationProvider mVisibilityLocationProvider;
    private final VisualStabilityProvider mVisualStabilityProvider;
    private final WakefulnessLifecycle mWakefulnessLifecycle;
    private final CommunalInteractor mCommunalInteractor;

    private boolean mSleepy = true;
    private boolean mFullyDozed;
@@ -75,6 +77,7 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
    private boolean mPulsing;
    private boolean mNotifPanelCollapsing;
    private boolean mNotifPanelLaunchingActivity;
    private boolean mCommunalShowing = false;

    private boolean mPipelineRunAllowed;
    private boolean mReorderingAllowed;
@@ -101,7 +104,8 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
            StatusBarStateController statusBarStateController,
            VisibilityLocationProvider visibilityLocationProvider,
            VisualStabilityProvider visualStabilityProvider,
            WakefulnessLifecycle wakefulnessLifecycle) {
            WakefulnessLifecycle wakefulnessLifecycle,
            CommunalInteractor communalInteractor) {
        mHeadsUpManager = headsUpManager;
        mShadeAnimationInteractor = shadeAnimationInteractor;
        mJavaAdapter = javaAdapter;
@@ -110,6 +114,7 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
        mWakefulnessLifecycle = wakefulnessLifecycle;
        mStatusBarStateController = statusBarStateController;
        mDelayableExecutor = delayableExecutor;
        mCommunalInteractor = communalInteractor;

        dumpManager.registerDumpable(this);
    }
@@ -126,6 +131,8 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
                this::onShadeOrQsClosingChanged);
        mJavaAdapter.alwaysCollectFlow(mShadeAnimationInteractor.isLaunchingActivity(),
                this::onLaunchingActivityChanged);
        mJavaAdapter.alwaysCollectFlow(mCommunalInteractor.isIdleOnCommunal(),
                this::onCommunalShowingChanged);

        pipeline.setVisualStabilityManager(mNotifStabilityManager);
    }
@@ -231,7 +238,7 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
    }

    private boolean isReorderingAllowed() {
        return ((mFullyDozed && mSleepy) || !mPanelExpanded) && !mPulsing;
        return ((mFullyDozed && mSleepy) || !mPanelExpanded || mCommunalShowing) && !mPulsing;
    }

    /**
@@ -315,6 +322,7 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
        pw.println("  fullyDozed: " + mFullyDozed);
        pw.println("  panelExpanded: " + mPanelExpanded);
        pw.println("  pulsing: " + mPulsing);
        pw.println("  communalShowing: " + mCommunalShowing);
        pw.println("isSuppressingPipelineRun: " + mIsSuppressingPipelineRun);
        pw.println("isSuppressingGroupChange: " + mIsSuppressingGroupChange);
        pw.println("isSuppressingEntryReorder: " + mIsSuppressingEntryReorder);
@@ -338,4 +346,9 @@ public class VisualStabilityCoordinator implements Coordinator, Dumpable {
        mNotifPanelLaunchingActivity = isLaunchingActivity;
        updateAllowedStates("notifPanelLaunchingActivity", isLaunchingActivity);
    }

    private void onCommunalShowingChanged(boolean isShowing) {
        mCommunalShowing = isShowing;
        updateAllowedStates("communalShowing", isShowing);
    }
}
+35 −3
Original line number Diff line number Diff line
@@ -29,15 +29,19 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import static kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow;

import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import androidx.test.filters.SmallTest;

import com.android.keyguard.TestScopeProvider;
import com.android.compose.animation.scene.ObservableTransitionState;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.communal.shared.model.CommunalScenes;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shade.data.repository.FakeShadeRepository;
import com.android.systemui.shade.data.repository.ShadeAnimationRepository;
@@ -67,6 +71,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.verification.VerificationMode;

import kotlinx.coroutines.flow.MutableStateFlow;
import kotlinx.coroutines.test.TestScope;

@SmallTest
@@ -89,9 +94,10 @@ public class VisualStabilityCoordinatorTest extends SysuiTestCase {
    @Captor private ArgumentCaptor<StatusBarStateController.StateListener> mSBStateListenerCaptor;
    @Captor private ArgumentCaptor<NotifStabilityManager> mNotifStabilityManagerCaptor;

    private final KosmosJavaAdapter mKosmos = new KosmosJavaAdapter(this);
    private FakeSystemClock mFakeSystemClock = new FakeSystemClock();
    private FakeExecutor mFakeExecutor = new FakeExecutor(mFakeSystemClock);
    private final TestScope mTestScope = TestScopeProvider.getTestScope();
    private final TestScope mTestScope = mKosmos.getTestScope();
    private final JavaAdapter mJavaAdapter = new JavaAdapter(mTestScope.getBackgroundScope());

    private ShadeAnimationInteractor mShadeAnimationInteractor;
@@ -118,8 +124,10 @@ public class VisualStabilityCoordinatorTest extends SysuiTestCase {
                mStatusBarStateController,
                mVisibilityLocationProvider,
                mVisualStabilityProvider,
                mWakefulnessLifecycle);
                mWakefulnessLifecycle,
                mKosmos.getCommunalInteractor());
        mCoordinator.attach(mNotifPipeline);
        mTestScope.getTestScheduler().runCurrent();

        // capture arguments:
        verify(mWakefulnessLifecycle).addObserver(mWakefulnessObserverCaptor.capture());
@@ -496,6 +504,7 @@ public class VisualStabilityCoordinatorTest extends SysuiTestCase {
        setFullyDozed(false);
        setSleepy(false);
        setPanelExpanded(true);
        setCommunalShowing(false);

        assertFalse(mNotifStabilityManager.isEntryReorderingAllowed(mEntry));
        // The pipeline still has to report back that entry reordering was suppressed
@@ -508,6 +517,19 @@ public class VisualStabilityCoordinatorTest extends SysuiTestCase {
        verifyStabilityManagerWasInvalidated(times(1));
    }

    @Test
    public void testCommunalShowingWillNotSuppressReordering() {
        // GIVEN panel is expanded and communal is showing
        setPulsing(false);
        setFullyDozed(false);
        setSleepy(false);
        setPanelExpanded(true);
        setCommunalShowing(true);

        // Reordering should be allowed
        assertTrue(mNotifStabilityManager.isEntryReorderingAllowed(mEntry));
    }

    @Test
    public void testQueryingEntryReorderingButNotReportingReorderSuppressedDoesNotInvalidate() {
        // GIVEN visual stability is being maintained b/c panel is expanded
@@ -561,6 +583,16 @@ public class VisualStabilityCoordinatorTest extends SysuiTestCase {
        mTestScope.getTestScheduler().runCurrent();
    }

    private void setCommunalShowing(boolean isShowing) {
        final MutableStateFlow<ObservableTransitionState> showingFlow =
                MutableStateFlow(
                        new ObservableTransitionState.Idle(
                                isShowing ? CommunalScenes.Communal : CommunalScenes.Blank)
                );
        mKosmos.getCommunalRepository().setTransitionState(showingFlow);
        mTestScope.getTestScheduler().runCurrent();
    }

    private void setPulsing(boolean pulsing) {
        mStatusBarStateListener.onPulsingChanged(pulsing);
    }