diff options
author | Beth Thibodeau <ethibodeau@google.com> | 2021-09-22 19:25:47 -0400 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-12-25 00:33:57 +0000 |
commit | 5250b955de3639434318cbb6e006f3086ebd2f27 (patch) | |
tree | 4afe279324de7c2c0abcd603b388a7371f490e53 | |
parent | 956b9937d06b7532369493f99c23f83e27747ac5 (diff) | |
download | base-5250b955de3639434318cbb6e006f3086ebd2f27.tar.gz |
[DO NOT MERGE] Use orientation value from config change event
Before, when the device was rotated we would get the new orientation value
from the event but then use the value from getResources() to decide
which layout to show. This discrepancy is a potential cause for an issue
where QS uses the landscape layout when the device was actually portrait
Fixes: 159737544
Test: atest QSPanelControllerBaseTest QSPanelControllerTest
Change-Id: Icd15712cd4821b7833a3373978a92f8b5959ac12
Merged-In: Icd15712cd4821b7833a3373978a92f8b5959ac12
(cherry picked from commit 917a11a54a41f79e01b176fb5d98d346e0f76ff5)
(cherry picked from commit a8e1bbf7c0195875f4f6692a8108e2e48db2a255)
Merged-In:Icd15712cd4821b7833a3373978a92f8b5959ac12
3 files changed, 42 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java index 4739a3f4c7d6..08cb4a9d44b6 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java @@ -25,6 +25,7 @@ import android.content.ComponentName; import android.content.res.Configuration; import android.metrics.LogMaker; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.UiEventLogger; import com.android.systemui.Dumpable; @@ -80,7 +81,8 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr private final QSHost.Callback mQSHostCallback = this::setTiles; - private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener = + @VisibleForTesting + protected final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener = new QSPanel.OnConfigurationChangedListener() { @Override public void onConfigurationChange(Configuration newConfig) { @@ -156,6 +158,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener); mHost.addCallback(mQSHostCallback); setTiles(); + mLastOrientation = getResources().getConfiguration().orientation; switchTileLayout(true); mDumpManager.registerDumpable(mView.getDumpableTag(), this); @@ -356,8 +359,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr return false; } return mUsingMediaPlayer && mMediaHost.getVisible() - && getResources().getConfiguration().orientation - == Configuration.ORIENTATION_LANDSCAPE; + && mLastOrientation == Configuration.ORIENTATION_LANDSCAPE; } private void logTiles() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java index 65e5f9703d84..faef87069084 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -98,11 +99,11 @@ public class QSPanelControllerBaseTest extends SysuiTestCase { Resources mResources; @Mock Configuration mConfiguration; + @Mock + Runnable mHorizontalLayoutListener; private QSPanelControllerBase<QSPanel> mController; - - /** Implementation needed to ensure we have a reflectively-available class name. */ private class TestableQSPanelControllerBase extends QSPanelControllerBase<QSPanel> { protected TestableQSPanelControllerBase(QSPanel view, QSTileHost host, @@ -242,18 +243,44 @@ public class QSPanelControllerBaseTest extends SysuiTestCase { when(mMediaHost.getVisible()).thenReturn(true); when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(false); + when(mQSPanel.getDumpableTag()).thenReturn("QSPanelLandscape"); mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost, mQSCustomizerController, mMediaHost, mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager, mFeatureFlags); + mController.init(); assertThat(mController.shouldUseHorizontalLayout()).isTrue(); when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true); when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true); + when(mQSPanel.getDumpableTag()).thenReturn("QSPanelPortrait"); mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost, mQSCustomizerController, mMediaHost, mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager, mFeatureFlags); + mController.init(); + + assertThat(mController.shouldUseHorizontalLayout()).isFalse(); + } + + @Test + public void testChangeConfiguration_shouldUseHorizontalLayout() { + when(mMediaHost.getVisible()).thenReturn(true); + mController.setUsingHorizontalLayoutChangeListener(mHorizontalLayoutListener); + + // When device is rotated to landscape + mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE; + mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration); + + // Then the layout changes + assertThat(mController.shouldUseHorizontalLayout()).isTrue(); + verify(mHorizontalLayoutListener).run(); // not invoked + + // When it is rotated back to portrait + mConfiguration.orientation = Configuration.ORIENTATION_PORTRAIT; + mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration); + // Then the layout changes back assertThat(mController.shouldUseHorizontalLayout()).isFalse(); + verify(mHorizontalLayoutListener, times(2)).run(); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.java index bf6c981bf05c..35ebacb85203 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.java @@ -23,6 +23,8 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.content.res.Configuration; +import android.content.res.Resources; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper.RunWithLooper; @@ -98,6 +100,10 @@ public class QSPanelControllerTest extends SysuiTestCase { FalsingManagerFake mFalsingManager = new FalsingManagerFake(); @Mock FeatureFlags mFeatureFlags; + @Mock + Resources mResources; + @Mock + Configuration mConfiguration; private QSPanelController mController; @@ -109,6 +115,8 @@ public class QSPanelControllerTest extends SysuiTestCase { when(mQSPanel.getDumpableTag()).thenReturn("QSPanel"); when(mQSPanel.getOrCreateTileLayout()).thenReturn(mPagedTileLayout); when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout); + when(mQSPanel.getResources()).thenReturn(mResources); + when(mResources.getConfiguration()).thenReturn(mConfiguration); when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile)); when(mQSTileHost.createTileView(any(), eq(mQSTile), anyBoolean())).thenReturn(mQSTileView); when(mToggleSliderViewControllerFactory.create(any(), any())) |