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
This commit is contained in:
@@ -26,6 +26,7 @@ import android.content.res.Configuration;
|
|||||||
import android.metrics.LogMaker;
|
import android.metrics.LogMaker;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.internal.logging.UiEventLogger;
|
import com.android.internal.logging.UiEventLogger;
|
||||||
import com.android.systemui.Dumpable;
|
import com.android.systemui.Dumpable;
|
||||||
@@ -79,7 +80,8 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
|
|||||||
|
|
||||||
private final QSHost.Callback mQSHostCallback = this::setTiles;
|
private final QSHost.Callback mQSHostCallback = this::setTiles;
|
||||||
|
|
||||||
private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener =
|
@VisibleForTesting
|
||||||
|
protected final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener =
|
||||||
new QSPanel.OnConfigurationChangedListener() {
|
new QSPanel.OnConfigurationChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChange(Configuration newConfig) {
|
public void onConfigurationChange(Configuration newConfig) {
|
||||||
@@ -156,6 +158,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
|
|||||||
mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener);
|
mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener);
|
||||||
mHost.addCallback(mQSHostCallback);
|
mHost.addCallback(mQSHostCallback);
|
||||||
setTiles();
|
setTiles();
|
||||||
|
mLastOrientation = getResources().getConfiguration().orientation;
|
||||||
switchTileLayout(true);
|
switchTileLayout(true);
|
||||||
|
|
||||||
mDumpManager.registerDumpable(mView.getDumpableTag(), this);
|
mDumpManager.registerDumpable(mView.getDumpableTag(), this);
|
||||||
@@ -356,8 +359,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mUsingMediaPlayer && mMediaHost.getVisible()
|
return mUsingMediaPlayer && mMediaHost.getVisible()
|
||||||
&& getResources().getConfiguration().orientation
|
&& mLastOrientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||||
== Configuration.ORIENTATION_LANDSCAPE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logTiles() {
|
private void logTiles() {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.doAnswer;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.reset;
|
import static org.mockito.Mockito.reset;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -95,11 +96,11 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
|
|||||||
Resources mResources;
|
Resources mResources;
|
||||||
@Mock
|
@Mock
|
||||||
Configuration mConfiguration;
|
Configuration mConfiguration;
|
||||||
|
@Mock
|
||||||
|
Runnable mHorizontalLayoutListener;
|
||||||
|
|
||||||
private QSPanelControllerBase<QSPanel> mController;
|
private QSPanelControllerBase<QSPanel> mController;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Implementation needed to ensure we have a reflectively-available class name. */
|
/** Implementation needed to ensure we have a reflectively-available class name. */
|
||||||
private class TestableQSPanelControllerBase extends QSPanelControllerBase<QSPanel> {
|
private class TestableQSPanelControllerBase extends QSPanelControllerBase<QSPanel> {
|
||||||
protected TestableQSPanelControllerBase(QSPanel view, QSTileHost host,
|
protected TestableQSPanelControllerBase(QSPanel view, QSTileHost host,
|
||||||
@@ -239,17 +240,43 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
|
|||||||
when(mMediaHost.getVisible()).thenReturn(true);
|
when(mMediaHost.getVisible()).thenReturn(true);
|
||||||
|
|
||||||
when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(false);
|
when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(false);
|
||||||
|
when(mQSPanel.getDumpableTag()).thenReturn("QSPanelLandscape");
|
||||||
mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost,
|
mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost,
|
||||||
mQSCustomizerController, mMediaHost,
|
mQSCustomizerController, mMediaHost,
|
||||||
mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager);
|
mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager);
|
||||||
|
mController.init();
|
||||||
|
|
||||||
assertThat(mController.shouldUseHorizontalLayout()).isTrue();
|
assertThat(mController.shouldUseHorizontalLayout()).isTrue();
|
||||||
|
|
||||||
when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
|
when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
|
||||||
|
when(mQSPanel.getDumpableTag()).thenReturn("QSPanelPortrait");
|
||||||
mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost,
|
mController = new TestableQSPanelControllerBase(mQSPanel, mQSTileHost,
|
||||||
mQSCustomizerController, mMediaHost,
|
mQSCustomizerController, mMediaHost,
|
||||||
mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager);
|
mMetricsLogger, mUiEventLogger, mQSLogger, mDumpManager);
|
||||||
|
mController.init();
|
||||||
|
|
||||||
assertThat(mController.shouldUseHorizontalLayout()).isFalse();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import static org.mockito.Mockito.never;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
import android.testing.TestableLooper.RunWithLooper;
|
import android.testing.TestableLooper.RunWithLooper;
|
||||||
|
|
||||||
@@ -98,6 +100,10 @@ public class QSPanelControllerTest extends SysuiTestCase {
|
|||||||
@Mock
|
@Mock
|
||||||
CommandQueue mCommandQueue;
|
CommandQueue mCommandQueue;
|
||||||
FalsingManagerFake mFalsingManager = new FalsingManagerFake();
|
FalsingManagerFake mFalsingManager = new FalsingManagerFake();
|
||||||
|
@Mock
|
||||||
|
Resources mResources;
|
||||||
|
@Mock
|
||||||
|
Configuration mConfiguration;
|
||||||
|
|
||||||
private QSPanelController mController;
|
private QSPanelController mController;
|
||||||
|
|
||||||
@@ -109,7 +115,8 @@ public class QSPanelControllerTest extends SysuiTestCase {
|
|||||||
when(mQSPanel.getDumpableTag()).thenReturn("QSPanel");
|
when(mQSPanel.getDumpableTag()).thenReturn("QSPanel");
|
||||||
when(mQSPanel.getOrCreateTileLayout()).thenReturn(mPagedTileLayout);
|
when(mQSPanel.getOrCreateTileLayout()).thenReturn(mPagedTileLayout);
|
||||||
when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
|
when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
|
||||||
when(mQSPanel.getResources()).thenReturn(mContext.getResources());
|
when(mQSPanel.getResources()).thenReturn(mResources);
|
||||||
|
when(mResources.getConfiguration()).thenReturn(mConfiguration);
|
||||||
when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile));
|
when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile));
|
||||||
when(mQSTileHost.createTileView(any(), eq(mQSTile), anyBoolean())).thenReturn(mQSTileView);
|
when(mQSTileHost.createTileView(any(), eq(mQSTile), anyBoolean())).thenReturn(mQSTileView);
|
||||||
when(mToggleSliderViewControllerFactory.create(any(), any()))
|
when(mToggleSliderViewControllerFactory.create(any(), any()))
|
||||||
|
|||||||
Reference in New Issue
Block a user