Merge "Remove volume_separate_notification flag" into udc-dev

This commit is contained in:
Behnam Heydarshahi
2023-05-22 14:09:22 +00:00
committed by Android (Google) Code Review
10 changed files with 13 additions and 308 deletions

View File

@@ -18,7 +18,6 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -26,15 +25,11 @@ import android.content.Context;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.service.notification.NotificationListenerService;
import android.telephony.TelephonyManager;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
@@ -45,7 +40,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@@ -64,9 +58,6 @@ public class NotificationVolumePreferenceControllerTest {
@Mock
private PreferenceManager mPreferenceManager;
private static final String READ_DEVICE_CONFIG_PERMISSION =
"android.permission.READ_DEVICE_CONFIG";
private Context mContext;
private NotificationVolumePreferenceController mController;
@@ -97,34 +88,15 @@ public class NotificationVolumePreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_voiceCapable_aliasedWithRing_shouldReturnFalse() {
when(mResources.getBoolean(
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
NotificationVolumePreferenceController controller =
new NotificationVolumePreferenceController(mContext);
when(mHelper.isSingleVolume()).thenReturn(false);
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
assertThat(controller.isAvailable()).isFalse();
}
/**
* With the introduction of ring-notification volume separation, voice-capable devices could now
* display the notification volume slider.
*/
@Test
public void isAvailable_voiceCapable_separatedFromRing_shouldReturnTrue() {
public void isAvailable_whenVoiceCapable_shouldReturnTrue() {
when(mResources.getBoolean(
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
NotificationVolumePreferenceController controller =
new NotificationVolumePreferenceController(mContext);
@@ -189,84 +161,13 @@ public class NotificationVolumePreferenceControllerTest {
}
@Test
public void enableSeparateNotificationConfig_controllerBecomesAvailable() {
PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
VolumeSeekBarPreference volumeSeekBarPreference = mock(VolumeSeekBarPreference.class);
when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
when(screen.getContext()).thenReturn(mContext);
when(mResources.getBoolean(
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
// block the alternative condition to enable controller
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
NotificationVolumePreferenceController controller =
new NotificationVolumePreferenceController(mContext);
when(screen.findPreference(controller.getPreferenceKey()))
.thenReturn(volumeSeekBarPreference);
// allow the controller to subscribe
Shadows.shadowOf((android.app.Application) ApplicationProvider.getApplicationContext())
.grantPermissions(READ_DEVICE_CONFIG_PERMISSION);
controller.onResume();
controller.displayPreference(screen);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, Boolean.toString(true),
false);
assertThat(controller.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.AVAILABLE);
}
@Test
public void disableSeparateNotificationConfig_controllerBecomesUnavailable() {
PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
VolumeSeekBarPreference volumeSeekBarPreference = mock(VolumeSeekBarPreference.class);
when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
when(screen.getContext()).thenReturn(mContext);
when(mResources.getBoolean(
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
// block the alternative condition to enable controller
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
NotificationVolumePreferenceController controller =
new NotificationVolumePreferenceController(mContext);
when(screen.findPreference(controller.getPreferenceKey()))
.thenReturn(volumeSeekBarPreference);
Shadows.shadowOf((android.app.Application) ApplicationProvider.getApplicationContext())
.grantPermissions(READ_DEVICE_CONFIG_PERMISSION);
controller.onResume();
controller.displayPreference(screen);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
assertThat(controller.getAvailabilityStatus()
== BasePreferenceController.UNSUPPORTED_ON_DEVICE).isTrue();
}
@Test
public void ringerModeSilent_unaliased_getAvailability_returnsDisabled() {
public void ringerModeSilent_getAvailability_returnsDisabled() {
when(mResources.getBoolean(
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
when(mHelper.isSingleVolume()).thenReturn(false);
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}

View File

@@ -27,11 +27,9 @@ import android.content.Context;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.service.notification.NotificationListenerService;
import android.telephony.TelephonyManager;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
@@ -83,9 +81,6 @@ public class RingVolumePreferenceControllerTest {
when(mContext.getResources()).thenReturn(mResources);
mController = new RingVolumePreferenceController(mContext);
mController.setAudioHelper(mHelper);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
}
@Test
@@ -110,7 +105,6 @@ public class RingVolumePreferenceControllerTest {
@Test
public void isAvailable_notSingleVolume_VoiceCapable_shouldReturnTrue() {
when(mHelper.isSingleVolume()).thenReturn(false);
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
@@ -139,10 +133,6 @@ public class RingVolumePreferenceControllerTest {
*/
@Test
public void ringNotificationStreamsSeparate_controllerIsNotAvailable() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
final RingVolumePreferenceController controller =
new RingVolumePreferenceController(mContext);
@@ -153,58 +143,19 @@ public class RingVolumePreferenceControllerTest {
}
@Test
public void setHintsRing_aliased_Matches() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
public void setHintsRing_Matches() {
assertThat(mController.hintsMatch(
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS)).isTrue();
}
@Test
public void setHintsRingNotification_aliased_Matches() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
public void setHintsRingNotification_Matches() {
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS))
.isTrue();
}
@Test
public void setHintNotification_aliased_Matches() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
assertThat(mController
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS))
.isTrue();
}
@Test
public void setHintsRing_unaliased_Matches() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
assertThat(mController.hintsMatch(
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS)).isTrue();
}
@Test
public void setHintsRingNotification_unaliased_Matches() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS))
.isTrue();
}
@Test
public void setHintNotification_unaliased_doesNotMatch() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
public void setHintNotification_doesNotMatch() {
assertThat(mController
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS))
.isFalse();

View File

@@ -27,10 +27,8 @@ import android.content.Context;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.telephony.TelephonyManager;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import org.junit.Before;
@@ -81,21 +79,11 @@ public class SeparateRingVolumePreferenceControllerTest {
mController.setAudioHelper(mHelper);
}
@Test
public void isAvailable_ringNotificationAliased_shouldReturnFalse() {
when(mHelper.isSingleVolume()).thenReturn(true);
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
assertThat(mController.isAvailable()).isFalse();
}
/**
* Maintain that the device does not need to be voice capable to display this slider
*/
@Test
public void isAvailable_ringNotificationSeparated_isNotVoiceCapable_shouldReturnTrue() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
public void isAvailable_whenNotVoiceCapable_shouldReturnTrue() {
when(mHelper.isSingleVolume()).thenReturn(false);
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);

View File

@@ -69,7 +69,7 @@ public class SoundSettingsTest {
keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.zen_mode_settings));
// Add keys with hidden resources
keys.add("alarm_volume");
keys.add("ring_volume");
keys.add("separate_ring_volume");
keys.add("notification_volume");
assertThat(keys).containsAtLeastElementsIn(niks);
@@ -93,7 +93,7 @@ public class SoundSettingsTest {
final int xmlId = settings.getPreferenceScreenResId();
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
int ring = keys.indexOf("ring_volume");
int ring = keys.indexOf("separate_ring_volume");
int notification = keys.indexOf("notification_volume");
int alarm = keys.indexOf("alarm_volume");