Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 914d6619 authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Android (Google) Code Review
Browse files

Merge "Removing accessibility "Collapse" action from QS when in split shade" into tm-qpr-dev

parents 8432dbc4 54cee9c7
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -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,8 +653,10 @@ public class QSPanel extends LinearLayout implements Tunable {
    @Override
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfo(info);
        if (mCanCollapse) {
            info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE);
        }
    }

    @Override
    public boolean performAccessibilityAction(int action, Bundle arguments) {
@@ -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 {
+2 −1
Original line number Diff line number Diff line
@@ -148,9 +148,10 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
    }

    @Override
    protected void onSplitShadeChanged() {
    protected void onSplitShadeChanged(boolean shouldUseSplitNotificationShade) {
        ((PagedTileLayout) mView.getOrCreateTileLayout())
                .forceTilesRedistribution("Split shade state changed");
        mView.setCanCollapse(!shouldUseSplitNotificationShade);
    }

    /** */
+2 −2
Original line number Diff line number Diff line
@@ -104,14 +104,14 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
                    switchTileLayoutIfNeeded();
                    onConfigurationChanged();
                    if (previousSplitShadeState != mShouldUseSplitNotificationShade) {
                        onSplitShadeChanged();
                        onSplitShadeChanged(mShouldUseSplitNotificationShade);
                    }
                }
            };

    protected void onConfigurationChanged() { }

    protected void onSplitShadeChanged() { }
    protected void onSplitShadeChanged(boolean shouldUseSplitNotificationShade) { }

    private final Function1<Boolean, Unit> mMediaHostVisibilityListener = (visible) -> {
        if (mMediaVisibilityChangedListener != null) {
+22 −3
Original line number Diff line number Diff line
@@ -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)
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -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)