Ringer mode button state a11y

Content description for ringer drawer will reflect the ringer mode.

Bug: b/201749323

Test: atest VolumeDialogImplTest

Change-Id: I65f6f995abf860f5fe0e71fef4e1671f025df5ec
This commit is contained in:
Behnam Heydarshahi
2023-07-17 12:43:47 +00:00
parent 9ae24ee9bb
commit 59803adcc0
2 changed files with 136 additions and 14 deletions

View File

@@ -945,6 +945,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
showRingerDrawer();
}
});
updateSelectedRingerContainerDescription(mIsRingerDrawerOpen);
mRingerDrawerVibrate.setOnClickListener(
new RingerDrawerItemClickListener(RINGER_MODE_VIBRATE));
@@ -1007,6 +1008,19 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
: 0;
}
@VisibleForTesting String getSelectedRingerContainerDescription() {
return mSelectedRingerContainer == null ? null :
mSelectedRingerContainer.getContentDescription().toString();
}
@VisibleForTesting void toggleRingerDrawer(boolean show) {
if (show) {
showRingerDrawer();
} else {
hideRingerDrawer();
}
}
/** Animates in the ringer drawer. */
private void showRingerDrawer() {
if (mIsRingerDrawerOpen) {
@@ -1084,12 +1098,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
.start();
}
// When the ringer drawer is open, tapping the currently selected ringer will set the ringer
// to the current ringer mode. Change the content description to that, instead of the 'tap
// to change ringer mode' default.
mSelectedRingerContainer.setContentDescription(
mContext.getString(getStringDescriptionResourceForRingerMode(
mState.ringerModeInternal)));
updateSelectedRingerContainerDescription(true);
mIsRingerDrawerOpen = true;
}
@@ -1135,14 +1144,38 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
.translationY(0f)
.start();
// When the drawer is closed, tapping the selected ringer drawer will open it, allowing the
// user to change the ringer.
mSelectedRingerContainer.setContentDescription(
mContext.getString(R.string.volume_ringer_change));
updateSelectedRingerContainerDescription(false);
mIsRingerDrawerOpen = false;
}
/**
* @param open false to set the description when drawer is closed
*/
private void updateSelectedRingerContainerDescription(boolean open) {
if (mState == null || mSelectedRingerContainer == null) return;
String currentMode = mContext.getString(getStringDescriptionResourceForRingerMode(
mState.ringerModeInternal));
String tapToSelect;
if (open) {
// When the ringer drawer is open, tapping the currently selected ringer will set the
// ringer to the current ringer mode. Change the content description to that, instead of
// the 'tap to change ringer mode' default.
tapToSelect = "";
} else {
// When the drawer is closed, tapping the selected ringer drawer will open it, allowing
// the user to change the ringer. The user needs to know that, and also the current mode
currentMode += ", ";
tapToSelect = mContext.getString(R.string.volume_ringer_change);
}
mSelectedRingerContainer.setContentDescription(currentMode + tapToSelect);
}
private void initSettingsH(int lockTaskModeState) {
if (mSettingsView != null) {
mSettingsView.setVisibility(
@@ -1726,7 +1759,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
});
}
private int getStringDescriptionResourceForRingerMode(int mode) {
@VisibleForTesting int getStringDescriptionResourceForRingerMode(int mode) {
switch (mode) {
case RINGER_MODE_SILENT:
return R.string.volume_ringer_status_silent;
@@ -1823,6 +1856,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
updateVolumeRowH(row);
}
updateRingerH();
updateSelectedRingerContainerDescription(mIsRingerDrawerOpen);
mWindow.setTitle(composeWindowTitle());
}

View File

@@ -16,14 +16,20 @@
package com.android.systemui.volume;
import static android.media.AudioManager.RINGER_MODE_NORMAL;
import static android.media.AudioManager.RINGER_MODE_SILENT;
import static android.media.AudioManager.RINGER_MODE_VIBRATE;
import static com.android.systemui.flags.Flags.ONE_WAY_HAPTICS_API_MIGRATION;
import static com.android.systemui.volume.Events.DISMISS_REASON_UNKNOWN;
import static com.android.systemui.volume.Events.SHOW_REASON_UNKNOWN;
import static com.android.systemui.volume.VolumeDialogControllerImpl.STREAMS;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -360,7 +366,7 @@ public class VolumeDialogImplTest extends SysuiTestCase {
public void testSelectVibrateFromDrawer_OnewayAPI_On() {
mFeatureFlags.set(ONE_WAY_HAPTICS_API_MIGRATION, true);
final State initialUnsetState = new State();
initialUnsetState.ringerModeInternal = AudioManager.RINGER_MODE_NORMAL;
initialUnsetState.ringerModeInternal = RINGER_MODE_NORMAL;
mDialog.onStateChangedH(initialUnsetState);
mActiveRinger.performClick();
@@ -390,7 +396,7 @@ public class VolumeDialogImplTest extends SysuiTestCase {
public void testSelectMuteFromDrawer_OnewayAPI_On() {
mFeatureFlags.set(ONE_WAY_HAPTICS_API_MIGRATION, true);
final State initialUnsetState = new State();
initialUnsetState.ringerModeInternal = AudioManager.RINGER_MODE_NORMAL;
initialUnsetState.ringerModeInternal = RINGER_MODE_NORMAL;
mDialog.onStateChangedH(initialUnsetState);
mActiveRinger.performClick();
@@ -428,7 +434,7 @@ public class VolumeDialogImplTest extends SysuiTestCase {
// Make sure we've actually changed the ringer mode.
verify(mVolumeDialogController, times(1)).setRingerMode(
AudioManager.RINGER_MODE_NORMAL, false);
RINGER_MODE_NORMAL, false);
}
/**
@@ -625,6 +631,88 @@ public class VolumeDialogImplTest extends SysuiTestCase {
}
}
private enum RingerDrawerState {INIT, OPEN, CLOSE}
@Test
public void ringerModeNormal_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_NORMAL, RingerDrawerState.INIT);
}
@Test
public void ringerModeSilent_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_SILENT, RingerDrawerState.INIT);
}
@Test
public void ringerModeVibrate_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_VIBRATE, RingerDrawerState.INIT);
}
@Test
public void ringerModeNormal_openDrawer_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_NORMAL, RingerDrawerState.OPEN);
}
@Test
public void ringerModeSilent_openDrawer_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_SILENT, RingerDrawerState.OPEN);
}
@Test
public void ringerModeVibrate_openDrawer_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_VIBRATE, RingerDrawerState.OPEN);
}
@Test
public void ringerModeNormal_closeDrawer_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_NORMAL, RingerDrawerState.CLOSE);
}
@Test
public void ringerModeSilent_closeDrawer_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_SILENT, RingerDrawerState.CLOSE);
}
@Test
public void ringerModeVibrate_closeDrawer_ringerContainerDescribesItsState() {
assertRingerContainerDescribesItsState(RINGER_MODE_VIBRATE, RingerDrawerState.CLOSE);
}
/**
* The content description should include ringer state, and the correct one.
*/
private void assertRingerContainerDescribesItsState(int ringerMode,
RingerDrawerState drawerState) {
State state = createShellState();
state.ringerModeInternal = ringerMode;
mFeatureFlags.set(ONE_WAY_HAPTICS_API_MIGRATION, true);
mDialog.onStateChangedH(state);
mDialog.show(SHOW_REASON_UNKNOWN);
if (drawerState != RingerDrawerState.INIT) {
// in both cases we first open the drawer
mDialog.toggleRingerDrawer(true);
if (drawerState == RingerDrawerState.CLOSE) {
mDialog.toggleRingerDrawer(false);
}
}
String ringerContainerDescription = mDialog.getSelectedRingerContainerDescription();
assumeNotNull(ringerContainerDescription);
String ringerDescription = mContext.getString(
mDialog.getStringDescriptionResourceForRingerMode(ringerMode));
if (drawerState == RingerDrawerState.OPEN) {
assertEquals(ringerDescription, ringerContainerDescription);
} else {
assertNotSame(ringerDescription, ringerContainerDescription);
assertTrue(ringerContainerDescription.startsWith(ringerDescription));
}
}
@After
public void teardown() {
cleanUp(mDialog);