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

Commit 555c5744 authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Check for screen aspect ratio when picking layout of QS media card

We only want the media card to be on the side of the tiles on wide
screens. It previously only checked for screen orientation, but a
landscape device doesn't guarantee the device is wide enough to properly
display this layout (ex: unfolded foldable device).

Flag: none
Test: manually with changing the display size
Fixes: 316241883
Fixes: 321627754
Change-Id: I077f4efbbbbea82ce16947ad19df8e836fadeb0f
parent 9812a64b
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
    private Consumer<Boolean> mMediaVisibilityChangedListener;
    @Orientation
    private int mLastOrientation;
    private int mLastScreenLayout;
    private String mCachedSpecs = "";
    @Nullable
    private QSTileRevealController mQsTileRevealController;
@@ -93,15 +94,19 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
                public void onConfigurationChange(Configuration newConfig) {
                    final boolean previousSplitShadeState = mShouldUseSplitNotificationShade;
                    final int previousOrientation = mLastOrientation;
                    final int previousScreenLayout = mLastScreenLayout;
                    mShouldUseSplitNotificationShade = mSplitShadeStateController
                            .shouldUseSplitNotificationShade(getResources());
                    mLastOrientation = newConfig.orientation;
                    mLastScreenLayout = newConfig.screenLayout;

                    mQSLogger.logOnConfigurationChanged(
                        /* oldOrientation= */ previousOrientation,
                        /* newOrientation= */ mLastOrientation,
                        /* oldShouldUseSplitShade= */ previousSplitShadeState,
                        /* newShouldUseSplitShade= */ mShouldUseSplitNotificationShade,
                        /* oldScreenLayout= */ previousScreenLayout,
                        /* newScreenLayout= */ mLastScreenLayout,
                        /* containerName= */ mView.getDumpableTag());

                    switchTileLayoutIfNeeded();
@@ -198,6 +203,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
        mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener);
        setTiles();
        mLastOrientation = getResources().getConfiguration().orientation;
        mLastScreenLayout = getResources().getConfiguration().screenLayout;
        mQSLogger.logOnViewAttached(mLastOrientation, mView.getDumpableTag());
        switchTileLayout(true);

@@ -447,7 +453,9 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
            return false;
        }
        return mUsingMediaPlayer && mMediaHost.getVisible()
                && mLastOrientation == Configuration.ORIENTATION_LANDSCAPE;
                && mLastOrientation == Configuration.ORIENTATION_LANDSCAPE
                && (mLastScreenLayout & Configuration.SCREENLAYOUT_LONG_MASK)
                == Configuration.SCREENLAYOUT_LONG_YES;
    }

    private void logTiles() {
+17 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.systemui.qs.logging
import android.content.res.Configuration.ORIENTATION_LANDSCAPE
import android.content.res.Configuration.ORIENTATION_PORTRAIT
import android.content.res.Configuration.Orientation
import android.content.res.Configuration.SCREENLAYOUT_LONG_NO
import android.content.res.Configuration.SCREENLAYOUT_LONG_YES
import android.service.quicksettings.Tile
import android.view.View
import com.android.systemui.log.ConstantStringsLogger
@@ -266,8 +268,10 @@ constructor(
    fun logOnConfigurationChanged(
        @Orientation oldOrientation: Int,
        @Orientation newOrientation: Int,
        newShouldUseSplitShade: Boolean,
        oldShouldUseSplitShade: Boolean,
        newShouldUseSplitShade: Boolean,
        oldScreenLayout: Int,
        newScreenLayout: Int,
        containerName: String
    ) {
        configChangedBuffer.log(
@@ -277,6 +281,8 @@ constructor(
                str1 = containerName
                int1 = oldOrientation
                int2 = newOrientation
                long1 = oldScreenLayout.toLong()
                long2 = newScreenLayout.toLong()
                bool1 = oldShouldUseSplitShade
                bool2 = newShouldUseSplitShade
            },
@@ -284,6 +290,8 @@ constructor(
                "config change: " +
                    "$str1 orientation=${toOrientationString(int2)} " +
                    "(was ${toOrientationString(int1)}), " +
                    "screen layout=${toScreenLayoutString(long1.toInt())} " +
                    "(was ${toScreenLayoutString(long2.toInt())}), " +
                    "splitShade=$bool2 (was $bool1)"
            }
        )
@@ -370,3 +378,11 @@ private inline fun toOrientationString(@Orientation orientation: Int): String {
        else -> "undefined"
    }
}

private inline fun toScreenLayoutString(screenLayout: Int): String {
    return when (screenLayout) {
        SCREENLAYOUT_LONG_YES -> "long"
        SCREENLAYOUT_LONG_NO -> "notlong"
        else -> "undefined"
    }
}
+29 −3
Original line number Diff line number Diff line
@@ -246,8 +246,9 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {


    @Test
    public void testShouldUzeHorizontalLayout_falseForSplitShade() {
    public void testShouldUseHorizontalLayout_falseForSplitShade() {
        mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE;
        mConfiguration.screenLayout = Configuration.SCREENLAYOUT_LONG_YES;
        when(mMediaHost.getVisible()).thenReturn(true);

        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(false);
@@ -270,12 +271,13 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
    }

    @Test
    public void testChangeConfiguration_shouldUseHorizontalLayout() {
    public void testChangeConfiguration_shouldUseHorizontalLayoutInLandscape_true() {
        when(mMediaHost.getVisible()).thenReturn(true);
        mController.setUsingHorizontalLayoutChangeListener(mHorizontalLayoutListener);

        // When device is rotated to landscape
        // When device is rotated to landscape and is long
        mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE;
        mConfiguration.screenLayout = Configuration.SCREENLAYOUT_LONG_YES;
        mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration);

        // Then the layout changes
@@ -291,6 +293,29 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
        verify(mHorizontalLayoutListener, times(2)).run();
    }

    @Test
    public void testChangeConfiguration_shouldUseHorizontalLayoutInLongDevices_true() {
        when(mMediaHost.getVisible()).thenReturn(true);
        mController.setUsingHorizontalLayoutChangeListener(mHorizontalLayoutListener);

        // When device is rotated to landscape and is long
        mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE;
        mConfiguration.screenLayout = Configuration.SCREENLAYOUT_LONG_YES;
        mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration);

        // Then the layout changes
        assertThat(mController.shouldUseHorizontalLayout()).isTrue();
        verify(mHorizontalLayoutListener).run();

        // When device changes to not-long
        mConfiguration.screenLayout = Configuration.SCREENLAYOUT_LONG_NO;
        mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration);

        // Then the layout changes back
        assertThat(mController.shouldUseHorizontalLayout()).isFalse();
        verify(mHorizontalLayoutListener, times(2)).run();
    }

    @Test
    public void testRefreshAllTilesDoesntRefreshListeningTiles() {
        when(mQSHost.getTiles()).thenReturn(List.of(mQSTile, mOtherTile));
@@ -310,6 +335,7 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
        when(mMediaHost.getVisible()).thenReturn(true);
        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(false);
        mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE;
        mConfiguration.screenLayout = Configuration.SCREENLAYOUT_LONG_YES;
        mController.setUsingHorizontalLayoutChangeListener(mHorizontalLayoutListener);
        mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration);
        assertThat(mController.shouldUseHorizontalLayout()).isTrue();