diff options
author | Nicolo' Mazzucato <nicomazz@google.com> | 2022-10-05 13:49:21 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-11-15 01:47:51 +0000 |
commit | d5ac0ac93bd25f8a74ff35f1c89917f70ac5e99e (patch) | |
tree | 235cff06f6836ac9acfaf92297fee844daef392b | |
parent | 49419d93e57e0592aabc2a61d2a9a3f56d38ef77 (diff) | |
download | base-d5ac0ac93bd25f8a74ff35f1c89917f70ac5e99e.tar.gz |
Fix QSPanel horizontal layout issue after unfolding
QS (Quick Settings) layout could be horizontal or not. When it is horizontal, the media player is displayed on the side of QS.
This is based on orientation, split shade state, and media player visibility. However the configuration changed lister was triggering the update only after orientation changed, neglecting split shade state.
When a foldable device that is in the state "folded and landscape" is unfolded, the orientation stays the same, despite the split shade state changes.
QSPanelControllerBase was updating the QS layout only if the orientation changed, neglecting other condition changes.
Fixes: 216244185
Test: CorrectQSAfterUnfold QSPanelControllerBaseTest
Change-Id: I7f1444adf477f75c267a48bf8f420d3507f82709
(cherry picked from commit 3e6a8bcf0d78f2ed6fc4c298c5d25ace21c11ac8)
Merged-In: I7f1444adf477f75c267a48bf8f420d3507f82709
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java | 30 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java | 22 |
2 files changed, 36 insertions, 16 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java index ded466a0cb25..2727c83ad877 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java @@ -23,8 +23,8 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ComponentName; import android.content.res.Configuration; +import android.content.res.Configuration.Orientation; import android.metrics.LogMaker; -import android.util.Log; import android.view.View; import com.android.internal.annotations.VisibleForTesting; @@ -75,6 +75,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr @Nullable private Consumer<Boolean> mMediaVisibilityChangedListener; + @Orientation private int mLastOrientation; private String mCachedSpecs = ""; @Nullable @@ -88,21 +89,16 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr new QSPanel.OnConfigurationChangedListener() { @Override public void onConfigurationChange(Configuration newConfig) { + mQSLogger.logOnConfigurationChanged( + /* lastOrientation= */ mLastOrientation, + /* newOrientation= */ newConfig.orientation, + /* containerName= */ mView.getDumpableTag()); + mShouldUseSplitNotificationShade = - LargeScreenUtils.shouldUseSplitNotificationShade(getResources()); - // Logging to aid the investigation of b/216244185. - Log.d(TAG, - "onConfigurationChange: " - + "mShouldUseSplitNotificationShade=" - + mShouldUseSplitNotificationShade + ", " - + "newConfig.windowConfiguration=" - + newConfig.windowConfiguration); - mQSLogger.logOnConfigurationChanged(mLastOrientation, newConfig.orientation, - mView.getDumpableTag()); - if (newConfig.orientation != mLastOrientation) { - mLastOrientation = newConfig.orientation; - switchTileLayout(false); - } + LargeScreenUtils.shouldUseSplitNotificationShade(getResources()); + mLastOrientation = newConfig.orientation; + + switchTileLayoutIfNeeded(); onConfigurationChanged(); } }; @@ -334,6 +330,10 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr } } + private void switchTileLayoutIfNeeded() { + switchTileLayout(/* force= */ false); + } + boolean switchTileLayout(boolean force) { /* Whether or not the panel currently contains a media player. */ boolean horizontal = shouldUseHorizontalLayout(); 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 3cad2a005882..b847ad07cd72 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java @@ -277,7 +277,7 @@ public class QSPanelControllerBaseTest extends SysuiTestCase { // Then the layout changes assertThat(mController.shouldUseHorizontalLayout()).isTrue(); - verify(mHorizontalLayoutListener).run(); // not invoked + verify(mHorizontalLayoutListener).run(); // When it is rotated back to portrait mConfiguration.orientation = Configuration.ORIENTATION_PORTRAIT; @@ -300,4 +300,24 @@ public class QSPanelControllerBaseTest extends SysuiTestCase { verify(mQSTile).refreshState(); verify(mOtherTile, never()).refreshState(); } + + @Test + public void configurationChange_onlySplitShadeConfigChanges_horizontalLayoutStatusUpdated() { + // Preconditions for horizontal layout + when(mMediaHost.getVisible()).thenReturn(true); + when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(false); + mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE; + mController.setUsingHorizontalLayoutChangeListener(mHorizontalLayoutListener); + mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration); + assertThat(mController.shouldUseHorizontalLayout()).isTrue(); + reset(mHorizontalLayoutListener); + + // Only split shade status changes + when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true); + mController.mOnConfigurationChangedListener.onConfigurationChange(mConfiguration); + + // Horizontal layout is updated accordingly. + assertThat(mController.shouldUseHorizontalLayout()).isFalse(); + verify(mHorizontalLayoutListener).run(); + } } |