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

Commit 554206ba authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Guard nulling fields in NSSLC with flag

Test: manual, destroy QSFragment
Test: atest QuickSettingsControllerImplTest
Bug: 353254345
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Change-Id: Ied84ef17cb55910a4359d3f3d3c0b961e9488968
parent 5b3a397d
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -2256,8 +2256,11 @@ public class QuickSettingsControllerImpl implements QuickSettingsController, Dum
            // panel, mQs will not need to be null cause it will be tied to the same lifecycle.
            if (fragment == mQs) {
                // Clear it to remove bindings to mQs from the provider.
                if (QSComposeFragment.isEnabled()) {
                    mNotificationStackScrollLayoutController.setQsHeaderBoundsProvider(null);
                } else {
                    mNotificationStackScrollLayoutController.setQsHeader(null);
                }
                mQs = null;
            }
        }
+1 −0
Original line number Diff line number Diff line
@@ -266,6 +266,7 @@ public class QuickSettingsControllerImplBaseTest extends SysuiTestCase {

        when(mPanelView.getParent()).thenReturn(mPanelViewParent);
        when(mQs.getHeader()).thenReturn(mQsHeader);
        when(mQSFragment.getHeader()).thenReturn(mQsHeader);

        doAnswer(invocation -> {
            mLockscreenShadeTransitionCallback = invocation.getArgument(0);
+64 −2
Original line number Diff line number Diff line
@@ -24,34 +24,41 @@ import static android.view.MotionEvent.ACTION_UP;
import static android.view.MotionEvent.BUTTON_SECONDARY;
import static android.view.MotionEvent.BUTTON_STYLUS_PRIMARY;

import static com.android.systemui.Flags.FLAG_QS_UI_REFACTOR;
import static com.android.systemui.Flags.FLAG_QS_UI_REFACTOR_COMPOSE_FRAGMENT;
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
import static com.android.systemui.statusbar.StatusBarState.SHADE;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.graphics.Rect;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.FlagsParameterization;
import android.testing.TestableLooper;
import android.view.MotionEvent;
import android.view.ViewGroup;

import androidx.test.filters.SmallTest;

import com.android.systemui.plugins.qs.QS;
import com.android.systemui.qs.flags.QSComposeFragment;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;

import java.util.List;

@@ -65,7 +72,7 @@ public class QuickSettingsControllerImplTest extends QuickSettingsControllerImpl

    @Parameters(name = "{0}")
    public static List<FlagsParameterization> getParams() {
        return progressionOf(FLAG_QS_UI_REFACTOR, FLAG_QS_UI_REFACTOR_COMPOSE_FRAGMENT);
        return progressionOf(FLAG_QS_UI_REFACTOR_COMPOSE_FRAGMENT);
    }

    public QuickSettingsControllerImplTest(FlagsParameterization flags) {
@@ -243,6 +250,61 @@ public class QuickSettingsControllerImplTest extends QuickSettingsControllerImpl
        verify(mQSFragment).setIsNotificationPanelFullWidth(true);
    }

    @Test
    @DisableFlags(QSComposeFragment.FLAG_NAME)
    public void onQsFragmentAttached_qsComposeFragmentDisabled_setHeaderInNSSL() {
        mFragmentListener.onFragmentViewCreated(QS.TAG, mQSFragment);

        verify(mNotificationStackScrollLayoutController)
                .setQsHeader((ViewGroup) mQSFragment.getHeader());
        verify(mNotificationStackScrollLayoutController, never()).setQsHeaderBoundsProvider(any());
    }

    @Test
    @EnableFlags(QSComposeFragment.FLAG_NAME)
    public void onQsFragmentAttached_qsComposeFragmentEnabled_setQsHeaderBoundsProviderInNSSL() {
        mFragmentListener.onFragmentViewCreated(QS.TAG, mQSFragment);

        verify(mNotificationStackScrollLayoutController, never())
                .setQsHeader((ViewGroup) mQSFragment.getHeader());
        ArgumentCaptor<QSHeaderBoundsProvider> argumentCaptor =
                ArgumentCaptor.forClass(QSHeaderBoundsProvider.class);

        verify(mNotificationStackScrollLayoutController)
                .setQsHeaderBoundsProvider(argumentCaptor.capture());

        argumentCaptor.getValue().getLeftProvider().invoke();
        argumentCaptor.getValue().getHeightProvider().invoke();
        argumentCaptor.getValue().getBoundsOnScreenProvider().invoke(new Rect());
        InOrder inOrderVerifier = inOrder(mQSFragment);

        inOrderVerifier.verify(mQSFragment).getHeaderLeft();
        inOrderVerifier.verify(mQSFragment).getHeaderHeight();
        inOrderVerifier.verify(mQSFragment).getHeaderBoundsOnScreen(new Rect());
    }

    @Test
    @DisableFlags(QSComposeFragment.FLAG_NAME)
    public void onQSFragmentDetached_qsComposeFragmentFlagDisabled_setViewToNullInNSSL() {
        mFragmentListener.onFragmentViewCreated(QS.TAG, mQSFragment);

        mFragmentListener.onFragmentViewDestroyed(QS.TAG, mQSFragment);

        verify(mNotificationStackScrollLayoutController).setQsHeader(null);
        verify(mNotificationStackScrollLayoutController, never()).setQsHeaderBoundsProvider(null);
    }

    @Test
    @EnableFlags(QSComposeFragment.FLAG_NAME)
    public void onQSFragmentDetached_qsComposeFragmentFlagEnabled_setBoundsProviderToNullInNSSL() {
        mFragmentListener.onFragmentViewCreated(QS.TAG, mQSFragment);

        mFragmentListener.onFragmentViewDestroyed(QS.TAG, mQSFragment);

        verify(mNotificationStackScrollLayoutController, never()).setQsHeader(null);
        verify(mNotificationStackScrollLayoutController).setQsHeaderBoundsProvider(null);
    }

    @Test
    public void onQsFragmentAttached_notFullWidth_setsFullWidthFalseOnQS() {
        setIsFullWidth(false);