From 73bf6685f632bec46c9f7f88e5cd0638b2844770 Mon Sep 17 00:00:00 2001 From: Beth Thibodeau Date: Thu, 22 Sep 2022 18:09:44 -0500 Subject: [PATCH] Simplify config changes and request media host layout updates - Each QSPanelController* class had its own OnConfigurationChangeListener, in addition to an overridable method in the base class that was called in the listener - moved the child class listener code into that method so there's a single listener registered. - When reattaching the media host after an orientation change, explicitly call setLayoutParams to ensure that a layout update is requested - Add more info about current config to dumpsys Bug: 198319256 Test: atest com.android.systemui.qs Test: manual - verify media view looks correct when rotating Change-Id: I5b34ba85e98b4fbf8fe3b24893d0423146aa5f75 Merged-In: I5b34ba85e98b4fbf8fe3b24893d0423146aa5f75 (cherry picked from commit 48cd3b609d8883978bf93ce159aa971f6b064fe3) --- .../src/com/android/systemui/qs/QSPanel.java | 2 ++ .../systemui/qs/QSPanelController.java | 22 +++++++------------ .../systemui/qs/QSPanelControllerBase.java | 4 +++- .../systemui/qs/QuickQSPanelController.java | 14 ++++-------- .../qs/QSPanelControllerBaseTest.java | 4 +++- .../systemui/qs/QuickQSPanelControllerTest.kt | 3 +-- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index 7155626a1aa1d..29f3e2ad10e50 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -465,6 +465,8 @@ public class QSPanel extends LinearLayout implements Tunable { ? Math.max(mMediaTotalBottomMargin - getPaddingBottom(), 0) : 0; layoutParams.topMargin = mediaNeedsTopMargin() && !horizontal ? mMediaTopMargin : 0; + // Call setLayoutParams explicitly to ensure that requestLayout happens + hostView.setLayoutParams(layoutParams); } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java index 918c6be582e76..a15cffd4f7ad5 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java @@ -21,7 +21,6 @@ import static com.android.systemui.media.dagger.MediaModule.QS_PANEL; import static com.android.systemui.qs.QSPanel.QS_SHOW_BRIGHTNESS; import static com.android.systemui.qs.dagger.QSFragmentModule.QS_USING_MEDIA_PLAYER; -import android.content.res.Configuration; import android.view.MotionEvent; import android.view.View; @@ -63,17 +62,6 @@ public class QSPanelController extends QSPanelControllerBase { private boolean mGridContentVisible = true; - private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener = - new QSPanel.OnConfigurationChangedListener() { - @Override - public void onConfigurationChange(Configuration newConfig) { - mView.updateResources(); - if (mView.isListening()) { - refreshAllTiles(); - } - } - }; - private View.OnTouchListener mTileLayoutTouchListener = new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { @@ -131,7 +119,6 @@ public class QSPanelController extends QSPanelControllerBase { if (mView.isListening()) { refreshAllTiles(); } - mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener); switchTileLayout(true); mBrightnessMirrorHandler.onQsPanelAttached(); @@ -148,11 +135,18 @@ public class QSPanelController extends QSPanelControllerBase { @Override protected void onViewDetached() { mTunerService.removeTunable(mView); - mView.removeOnConfigurationChangedListener(mOnConfigurationChangedListener); mBrightnessMirrorHandler.onQsPanelDettached(); super.onViewDetached(); } + @Override + protected void onConfigurationChanged() { + mView.updateResources(); + if (mView.isListening()) { + refreshAllTiles(); + } + } + /** */ public void setVisibility(int visibility) { mView.setVisibility(visibility); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java index 6d5f844667e71..9e1c0034f55a7 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java @@ -90,11 +90,11 @@ public abstract class QSPanelControllerBase extends ViewContr LargeScreenUtils.shouldUseSplitNotificationShade(getResources()); mQSLogger.logOnConfigurationChanged(mLastOrientation, newConfig.orientation, mView.getDumpableTag()); - onConfigurationChanged(); if (newConfig.orientation != mLastOrientation) { mLastOrientation = newConfig.orientation; switchTileLayout(false); } + onConfigurationChanged(); } }; @@ -408,6 +408,8 @@ public abstract class QSPanelControllerBase extends ViewContr } if (mMediaHost != null) { pw.println(" media bounds: " + mMediaHost.getCurrentBounds()); + pw.println(" horizontal layout: " + mUsingHorizontalLayout); + pw.println(" last orientation: " + mLastOrientation); } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanelController.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanelController.java index 833573dd38730..8ca7b2770b997 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanelController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanelController.java @@ -44,14 +44,6 @@ import javax.inject.Named; @QSScope public class QuickQSPanelController extends QSPanelControllerBase { - private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener = - newConfig -> { - int newMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_tiles); - if (newMaxTiles != mView.getNumQuickTiles()) { - setMaxTiles(newMaxTiles); - } - }; - private final boolean mUsingCollapsedLandscapeMedia; @Inject @@ -95,13 +87,11 @@ public class QuickQSPanelController extends QSPanelControllerBase @Override protected void onViewAttached() { super.onViewAttached(); - mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener); } @Override protected void onViewDetached() { super.onViewDetached(); - mView.removeOnConfigurationChangedListener(mOnConfigurationChangedListener); } private void setMaxTiles(int parseNumTiles) { @@ -111,6 +101,10 @@ public class QuickQSPanelController extends QSPanelControllerBase @Override protected void onConfigurationChanged() { + int newMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_tiles); + if (newMaxTiles != mView.getNumQuickTiles()) { + setMaxTiles(newMaxTiles); + } updateMediaExpansion(); } 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 c127a6b87da7a..3cad2a005882b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerBaseTest.java @@ -224,7 +224,9 @@ public class QSPanelControllerBaseTest extends SysuiTestCase { + " Tile records:\n" + " " + mockTileString + "\n" + " " + mockTileViewString + "\n" - + " media bounds: null\n"; + + " media bounds: null\n" + + " horizontal layout: false\n" + + " last orientation: 0\n"; assertEquals(expected, w.getBuffer().toString()); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QuickQSPanelControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/QuickQSPanelControllerTest.kt index 1f28210acc64a..e98f2146d0629 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QuickQSPanelControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QuickQSPanelControllerTest.kt @@ -126,8 +126,7 @@ class QuickQSPanelControllerTest : SysuiTestCase() { @Test fun testMediaExpansionUpdatedWhenConfigurationChanged() { - // times(2) because both controller and base controller are registering their listeners - verify(quickQSPanel, times(2)).addOnConfigurationChangedListener(captor.capture()) + verify(quickQSPanel).addOnConfigurationChangedListener(captor.capture()) // verify that media starts in the expanded state by default verify(mediaHost).expansion = MediaHostState.EXPANDED