From 54cee9c7cd0c8edae93b2c3c038ec94a0314e355 Mon Sep 17 00:00:00 2001 From: Michal Brzezinski Date: Wed, 15 Feb 2023 18:25:19 +0000 Subject: [PATCH] Removing accessibility "Collapse" action from QS when in split shade This action resulted in broken QS state in split shade and didn't make much sense as QS can't be collapsed. Now this action is dependent on split shade state and is only announced in non-split shade. Fixes: 269462512 Test: QSPanelControllerTest Test: talkback on -> open split shade -> focus on QS -> tap with three fingers -> see no "Actions" in menu Change-Id: I007f0e87d41a36bd71c28d95f566335852e2e732 --- .../src/com/android/systemui/qs/QSPanel.java | 25 ++++++++++--------- .../systemui/qs/QSPanelController.java | 3 ++- .../systemui/qs/QSPanelControllerBase.java | 4 +-- .../systemui/qs/QSPanelControllerTest.kt | 25 ++++++++++++++++--- .../com/android/systemui/qs/QSPanelTest.kt | 11 ++++++++ 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index 7067c220da871..a0be151e15a10 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -25,8 +25,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Rect; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; import android.util.ArrayMap; import android.util.AttributeSet; import android.util.Log; @@ -108,6 +106,11 @@ public class QSPanel extends LinearLayout implements Tunable { private boolean mShouldMoveMediaOnExpansion = true; private boolean mUsingCombinedHeaders = false; private QSLogger mQsLogger; + /** + * Specifies if we can collapse to QQS in current state. In split shade that should be always + * false. It influences available accessibility actions. + */ + private boolean mCanCollapse = true; public QSPanel(Context context, AttributeSet attrs) { super(context, attrs); @@ -650,7 +653,9 @@ public class QSPanel extends LinearLayout implements Tunable { @Override public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(info); - info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE); + if (mCanCollapse) { + info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE); + } } @Override @@ -669,15 +674,11 @@ public class QSPanel extends LinearLayout implements Tunable { mCollapseExpandAction = action; } - private class H extends Handler { - private static final int ANNOUNCE_FOR_ACCESSIBILITY = 1; - - @Override - public void handleMessage(Message msg) { - if (msg.what == ANNOUNCE_FOR_ACCESSIBILITY) { - announceForAccessibility((CharSequence) msg.obj); - } - } + /** + * Specifies if these expanded QS can collapse to QQS. + */ + public void setCanCollapse(boolean canCollapse) { + mCanCollapse = canCollapse; } public interface QSTileLayout { diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java index cabe1daf16f46..01dbb1825208e 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelController.java @@ -148,9 +148,10 @@ public class QSPanelController extends QSPanelControllerBase { } @Override - protected void onSplitShadeChanged() { + protected void onSplitShadeChanged(boolean shouldUseSplitNotificationShade) { ((PagedTileLayout) mView.getOrCreateTileLayout()) .forceTilesRedistribution("Split shade state changed"); + mView.setCanCollapse(!shouldUseSplitNotificationShade); } /** */ diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java index e85d0a32cfa8e..bbdf6cc705412 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanelControllerBase.java @@ -104,14 +104,14 @@ public abstract class QSPanelControllerBase extends ViewContr switchTileLayoutIfNeeded(); onConfigurationChanged(); if (previousSplitShadeState != mShouldUseSplitNotificationShade) { - onSplitShadeChanged(); + onSplitShadeChanged(mShouldUseSplitNotificationShade); } } }; protected void onConfigurationChanged() { } - protected void onSplitShadeChanged() { } + protected void onSplitShadeChanged(boolean shouldUseSplitNotificationShade) { } private final Function1 mMediaHostVisibilityListener = (visible) -> { if (mMediaVisibilityChangedListener != null) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt index 6cf642cb7fd2c..09156d6d67521 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelControllerTest.kt @@ -70,7 +70,7 @@ class QSPanelControllerTest : SysuiTestCase() { whenever(brightnessSliderFactory.create(any(), any())).thenReturn(brightnessSlider) whenever(brightnessControllerFactory.create(any())).thenReturn(brightnessController) - testableResources.addOverride(R.bool.config_use_split_notification_shade, false) + setShouldUseSplitShade(false) whenever(qsPanel.resources).thenReturn(testableResources.resources) whenever(qsPanel.getOrCreateTileLayout()).thenReturn(pagedTileLayout) whenever(statusBarKeyguardViewManager.isPrimaryBouncerInTransit()).thenReturn(false) @@ -133,12 +133,31 @@ class QSPanelControllerTest : SysuiTestCase() { @Test fun configurationChange_onlySplitShadeConfigChanges_tileAreRedistributed() { - testableResources.addOverride(R.bool.config_use_split_notification_shade, false) + setShouldUseSplitShade(false) controller.mOnConfigurationChangedListener.onConfigurationChange(configuration) verify(pagedTileLayout, never()).forceTilesRedistribution(any()) - testableResources.addOverride(R.bool.config_use_split_notification_shade, true) + setShouldUseSplitShade(true) controller.mOnConfigurationChangedListener.onConfigurationChange(configuration) verify(pagedTileLayout).forceTilesRedistribution("Split shade state changed") } + + @Test + fun configurationChange_onlySplitShadeConfigChanges_qsPanelCanBeCollapsed() { + setShouldUseSplitShade(false) + controller.mOnConfigurationChangedListener.onConfigurationChange(configuration) + verify(qsPanel, never()).setCanCollapse(anyBoolean()) + + setShouldUseSplitShade(true) + controller.mOnConfigurationChangedListener.onConfigurationChange(configuration) + verify(qsPanel).setCanCollapse(false) + + setShouldUseSplitShade(false) + controller.mOnConfigurationChangedListener.onConfigurationChange(configuration) + verify(qsPanel).setCanCollapse(true) + } + + private fun setShouldUseSplitShade(shouldUse: Boolean) { + testableResources.addOverride(R.bool.config_use_split_notification_shade, shouldUse) + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.kt index d52b29642acff..a8cfb256bc7cb 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.kt @@ -37,6 +37,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @@ -196,6 +197,16 @@ class QSPanelTest : SysuiTestCase() { qsPanel.setSquishinessFraction(0.5f) } + @Test + fun testSplitShade_CollapseAccessibilityActionNotAnnounced() { + qsPanel.setCanCollapse(false) + val accessibilityInfo = mock(AccessibilityNodeInfo::class.java) + qsPanel.onInitializeAccessibilityNodeInfo(accessibilityInfo) + + val actionCollapse = AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE + verify(accessibilityInfo, never()).addAction(actionCollapse) + } + private infix fun View.isLeftOf(other: View): Boolean { val rect = Rect() getBoundsOnScreen(rect)