Add notification volume controller in settings

Separate notification and ring controllers based on the ring/volume
stream alias boolean in config.xml.

For both ring and volume controller: Not show vibrate icon when vibration is not supported on device. Show
silent icon instead.

Known issue: Add the notification volume slider only in Settings, and
not in VolumePanelDialog. When the alias is set to false and the streams
separated, the ring volume slider in VolumePanelDialog keeps its title
of "Ring & notification volume" instead of changing to "Ring volume".

Bug: b/38477228

Test: make DEBUG_ROBOLECTRIC=1 ROBOTEST_FILTER=NotificationVolumePreferenceControllerTest RunSettingsRoboTests -j40
      make DEBUG_ROBOLECTRIC=1 ROBOTEST_FILTER=RingVolumePreferenceControllerTest RunSettingsRoboTests -j40
      make DEBUG_ROBOLECTRIC=1 ROBOTEST_FILTER=SoundSettingsTest RunSettingsRoboTests

Change-Id: Id17523f49b291a5cf612b90f93c3b2ab6486c62f
This commit is contained in:
Behnam Heydarshahi
2022-09-06 22:12:37 +00:00
parent 6ecbe4c18e
commit 3ac6aaf796
11 changed files with 590 additions and 36 deletions

View File

@@ -18,15 +18,20 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Vibrator;
import android.service.notification.NotificationListenerService;
import android.telephony.TelephonyManager;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,8 +56,13 @@ public class RingVolumePreferenceControllerTest {
private NotificationManager mNotificationManager;
@Mock
private ComponentName mSuppressor;
@Mock
private Resources mResources;
@Mock
private VolumeSeekBarPreference mPreference;
private Context mContext;
private RingVolumePreferenceController mController;
@Before
@@ -63,8 +73,9 @@ public class RingVolumePreferenceControllerTest {
shadowContext.setSystemService(Context.AUDIO_SERVICE, mAudioManager);
shadowContext.setSystemService(Context.VIBRATOR_SERVICE, mVibrator);
shadowContext.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application;
mContext = spy(RuntimeEnvironment.application);
when(mNotificationManager.getEffectsSuppressor()).thenReturn(mSuppressor);
when(mContext.getResources()).thenReturn(mResources);
mController = new RingVolumePreferenceController(mContext);
mController.setAudioHelper(mHelper);
}
@@ -109,4 +120,92 @@ public class RingVolumePreferenceControllerTest {
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
// todo: verify that the title change is displayed, by examining the underlying preference
@Test
public void ringNotificationStreamsNotAliased_sliderTitleSetToRingOnly() {
when(mResources.getBoolean(
com.android.internal.R.bool.config_alias_ring_notif_stream_types))
.thenReturn(false);
final RingVolumePreferenceController controller =
new RingVolumePreferenceController(mContext);
int expectedTitleId = R.string.separate_ring_volume_option_title;
assertThat(controller.mTitleId).isEqualTo(expectedTitleId);
}
@Test
public void ringNotificationStreamsAliased_sliderTitleIncludesBothRingNotification() {
when(mResources.getBoolean(
com.android.internal.R.bool.config_alias_ring_notif_stream_types)).thenReturn(true);
final RingVolumePreferenceController control = new RingVolumePreferenceController(mContext);
int expectedTitleId = R.string.ring_volume_option_title;
assertThat(control.mTitleId).isEqualTo(expectedTitleId);
}
@Test
public void setHintsRing_aliased_Matches() {
assertThat(mController.hintsMatch(
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, true)).isTrue();
}
@Test
public void setHintsRingNotification_aliased_Matches() {
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
true)).isTrue();
}
@Test
public void setHintNotification_aliased_Matches() {
assertThat(mController
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
true)).isTrue();
}
@Test
public void setHintsRing_unaliased_Matches() {
assertThat(mController.hintsMatch(
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, false)).isTrue();
}
@Test
public void setHintsRingNotification_unaliased_Matches() {
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
false)).isTrue();
}
@Test
public void setHintNotification_unaliased_doesNotMatch() {
assertThat(mController
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
false)).isFalse();
}
@Test
public void setRingerModeToVibrate_butNoVibratorAvailable_iconIsSilent() {
when(mHelper.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
mController.setPreference(mPreference);
mController.setVibrator(null);
mController.updateRingerMode();
assertThat(mController.getMuteIcon()).isEqualTo(mController.mSilentIconId);
}
@Test
public void setRingerModeToVibrate_VibratorAvailable_iconIsVibrate() {
when(mHelper.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
when(mVibrator.hasVibrator()).thenReturn(true);
mController.setPreference(mPreference);
mController.setVibrator(mVibrator);
mController.updateRingerMode();
assertThat(mController.getMuteIcon()).isEqualTo(mController.mVibrateIconId);
}
}