Merge "Revert "Revert "Revert "Ringer mode button state a11y"""" into udc-dev

This commit is contained in:
Behnam Heydarshahi
2023-06-13 17:27:43 +00:00
committed by Android (Google) Code Review
2 changed files with 14 additions and 135 deletions

View File

@@ -928,7 +928,6 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
showRingerDrawer();
}
});
updateSelectedRingerContainerDescription(mIsRingerDrawerOpen);
mRingerDrawerVibrate.setOnClickListener(
new RingerDrawerItemClickListener(RINGER_MODE_VIBRATE));
@@ -991,19 +990,6 @@ 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) {
@@ -1081,7 +1067,12 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
.start();
}
updateSelectedRingerContainerDescription(true);
// 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)));
mIsRingerDrawerOpen = true;
}
@@ -1127,38 +1118,14 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
.translationY(0f)
.start();
updateSelectedRingerContainerDescription(false);
// 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));
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(
@@ -1734,7 +1701,7 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
});
}
@VisibleForTesting int getStringDescriptionResourceForRingerMode(int mode) {
private int getStringDescriptionResourceForRingerMode(int mode) {
switch (mode) {
case RINGER_MODE_SILENT:
return R.string.volume_ringer_status_silent;
@@ -1816,7 +1783,6 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable,
updateVolumeRowH(row);
}
updateRingerH();
updateSelectedRingerContainerDescription(mIsRingerDrawerOpen);
mWindow.setTitle(composeWindowTitle());
}

View File

@@ -16,19 +16,13 @@
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.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;
@@ -299,7 +293,7 @@ public class VolumeDialogImplTest extends SysuiTestCase {
@Test
public void testSelectVibrateFromDrawer() {
final State initialUnsetState = new State();
initialUnsetState.ringerModeInternal = RINGER_MODE_NORMAL;
initialUnsetState.ringerModeInternal = AudioManager.RINGER_MODE_NORMAL;
mDialog.onStateChangedH(initialUnsetState);
mActiveRinger.performClick();
@@ -313,7 +307,7 @@ public class VolumeDialogImplTest extends SysuiTestCase {
@Test
public void testSelectMuteFromDrawer() {
final State initialUnsetState = new State();
initialUnsetState.ringerModeInternal = RINGER_MODE_NORMAL;
initialUnsetState.ringerModeInternal = AudioManager.RINGER_MODE_NORMAL;
mDialog.onStateChangedH(initialUnsetState);
mActiveRinger.performClick();
@@ -335,7 +329,7 @@ public class VolumeDialogImplTest extends SysuiTestCase {
// Make sure we've actually changed the ringer mode.
verify(mVolumeDialogController, times(1)).setRingerMode(
RINGER_MODE_NORMAL, false);
AudioManager.RINGER_MODE_NORMAL, false);
}
/**
@@ -517,87 +511,6 @@ 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;
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() {
if (mDialog != null) {