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

Commit 3d3ef502 authored by Matías Hernández's avatar Matías Hernández
Browse files

Fix a11y announcements in DND duration dialogs

We are using a separate RadioButton just for the button and a view (possibly complex) fo the text. The latter didn't report an accurate selection status (especially when selecting, which didn't announce anything at all). Note that we are _not_ setting the "unselected" status to avoid repetition when walking through with Talkback (button -> text -> button -> text, ...).

Fixes: 265468127
Test: Unit tests
Change-Id: I87aad93d942a868776ecec163136fd9bfcb8276f
parent 9070618c
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -65,7 +65,7 @@ android_library {
        "src/**/*.kt",
        "src/**/*.kt",
    ],
    ],


    min_sdk_version: "29",
    min_sdk_version: "30",


}
}


+3 −0
Original line number Original line Diff line number Diff line
@@ -224,6 +224,9 @@ public class EnableZenModeDialog {
                    mMetricsLogger.logOnConditionSelected();
                    mMetricsLogger.logOnConditionSelected();
                    updateAlarmWarningText(tag.condition);
                    updateAlarmWarningText(tag.condition);
                }
                }
                tag.line1.setStateDescription(
                        isChecked ? buttonView.getContext().getString(
                                com.android.internal.R.string.selected) : null);
            }
            }
        });
        });


+3 −0
Original line number Original line Diff line number Diff line
@@ -196,6 +196,9 @@ public class ZenDurationDialog {
                if (isChecked) {
                if (isChecked) {
                    tag.rb.setChecked(true);
                    tag.rb.setChecked(true);
                }
                }
                tag.line1.setStateDescription(
                        isChecked ? buttonView.getContext().getString(
                                com.android.internal.R.string.selected) : null);
            }
            }
        });
        });


+25 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.settingslib.notification;
package com.android.settingslib.notification;


import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
@@ -78,6 +80,8 @@ public class EnableZenModeDialogTest {
        mController.mForeverId =  Condition.newId(mContext).appendPath("forever").build();
        mController.mForeverId =  Condition.newId(mContext).appendPath("forever").build();
        when(mContext.getString(com.android.internal.R.string.zen_mode_forever))
        when(mContext.getString(com.android.internal.R.string.zen_mode_forever))
                .thenReturn("testSummary");
                .thenReturn("testSummary");
        when(mContext.getString(com.android.internal.R.string.selected))
                .thenReturn("selected");
        NotificationManager.Policy alarmsEnabledPolicy = new NotificationManager.Policy(
        NotificationManager.Policy alarmsEnabledPolicy = new NotificationManager.Policy(
                NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS, 0, 0, 0);
                NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS, 0, 0, 0);
        doReturn(alarmsEnabledPolicy).when(mNotificationManager).getNotificationPolicy();
        doReturn(alarmsEnabledPolicy).when(mNotificationManager).getNotificationPolicy();
@@ -190,4 +194,25 @@ public class EnableZenModeDialogTest {
        // alarm warning should NOT be null
        // alarm warning should NOT be null
        assertNotNull(mController.computeAlarmWarningText(null));
        assertNotNull(mController.computeAlarmWarningText(null));
    }
    }

    @Test
    public void testAccessibility() {
        mController.bindConditions(null);
        EnableZenModeDialog.ConditionTag forever = mController.getConditionTagAt(
                ZenDurationDialog.FOREVER_CONDITION_INDEX);
        EnableZenModeDialog.ConditionTag countdown = mController.getConditionTagAt(
                ZenDurationDialog.COUNTDOWN_CONDITION_INDEX);
        EnableZenModeDialog.ConditionTag alwaysAsk = mController.getConditionTagAt(
                ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX);

        forever.rb.setChecked(true);
        assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected");
        assertThat(countdown.line1.getStateDescription()).isNull();
        assertThat(alwaysAsk.line1.getStateDescription()).isNull();

        alwaysAsk.rb.setChecked(true);
        assertThat(forever.line1.getStateDescription()).isNull();
        assertThat(countdown.line1.getStateDescription()).isNull();
        assertThat(alwaysAsk.line1.getStateDescription().toString()).isEqualTo("selected");
    }
}
}
 No newline at end of file
+25 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.settingslib.notification;
package com.android.settingslib.notification;


import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertTrue;
@@ -205,4 +207,27 @@ public class ZenDurationDialogTest {
                ZenDurationDialog.COUNTDOWN_CONDITION_INDEX);
                ZenDurationDialog.COUNTDOWN_CONDITION_INDEX);
        assertEquals(120, tag.countdownZenDuration);
        assertEquals(120, tag.countdownZenDuration);
    }
    }

    @Test
    public void testAccessibility() {
        Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
                Settings.Secure.ZEN_DURATION_FOREVER);
        mController.setupDialog(mBuilder);
        ZenDurationDialog.ConditionTag forever = mController.getConditionTagAt(
                ZenDurationDialog.FOREVER_CONDITION_INDEX);
        ZenDurationDialog.ConditionTag countdown = mController.getConditionTagAt(
                ZenDurationDialog.COUNTDOWN_CONDITION_INDEX);
        ZenDurationDialog.ConditionTag alwaysAsk = mController.getConditionTagAt(
                ZenDurationDialog.ALWAYS_ASK_CONDITION_INDEX);

        forever.rb.setChecked(true);
        assertThat(forever.line1.getStateDescription().toString()).isEqualTo("selected");
        assertThat(countdown.line1.getStateDescription()).isNull();
        assertThat(alwaysAsk.line1.getStateDescription()).isNull();

        alwaysAsk.rb.setChecked(true);
        assertThat(forever.line1.getStateDescription()).isNull();
        assertThat(countdown.line1.getStateDescription()).isNull();
        assertThat(alwaysAsk.line1.getStateDescription().toString()).isEqualTo("selected");
    }
}
}
 No newline at end of file