Merge "Remove volume_separate_notification flag" into udc-dev am: 7aa8424cc0 am: 2aecb2f1ea am: ffbc25e249

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23244447

Change-Id: I2fe0b29add60d26dab32d142d970f2ee3ad7781c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Behnam Heydarshahi
2023-05-22 15:17:18 +00:00
committed by Automerger Merge Worker
10 changed files with 13 additions and 308 deletions

View File

@@ -64,14 +64,6 @@
settings:searchable="false" settings:searchable="false"
settings:controller="com.android.settings.sound.HandsFreeProfileOutputPreferenceController"/> settings:controller="com.android.settings.sound.HandsFreeProfileOutputPreferenceController"/>
<!-- Ring volume -->
<com.android.settings.notification.VolumeSeekBarPreference
android:key="ring_volume"
android:icon="@drawable/ic_notifications"
android:title="@string/ring_volume_option_title"
android:order="-160"
settings:controller="com.android.settings.notification.RingVolumePreferenceController"/>
<!-- Separate Ring volume --> <!-- Separate Ring volume -->
<com.android.settings.notification.VolumeSeekBarPreference <com.android.settings.notification.VolumeSeekBarPreference
android:key="separate_ring_volume" android:key="separate_ring_volume"

View File

@@ -16,29 +16,23 @@
package com.android.settings.notification; package com.android.settings.notification;
import android.app.ActivityThread;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Binder;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.provider.DeviceConfig;
import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService;
import androidx.lifecycle.OnLifecycleEvent; import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.Set;
/** /**
* Update notification volume icon in Settings in response to user adjusting volume. * Update notification volume icon in Settings in response to user adjusting volume.
*/ */
@@ -84,37 +78,11 @@ public class NotificationVolumePreferenceController extends
updateEnabledState(); updateEnabledState();
} }
/**
* Only display the notification slider when the corresponding device config flag is set
*/
private void onDeviceConfigChange(DeviceConfig.Properties properties) {
Set<String> changeSet = properties.getKeyset();
if (changeSet.contains(SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION)) {
boolean newVal = isSeparateNotificationConfigEnabled();
if (newVal != mSeparateNotification) {
mSeparateNotification = newVal;
// Update UI if config change happens when Sound Settings page is on the foreground
if (mPreference != null) {
int status = getAvailabilityStatus();
mPreference.setVisible(status == AVAILABLE
|| status == DISABLED_DEPENDENT_SETTING);
if (status == DISABLED_DEPENDENT_SETTING) {
mPreference.setEnabled(false);
}
}
}
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mReceiver.register(true); mReceiver.register(true);
Binder.withCleanCallingIdentity(()
-> DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
ActivityThread.currentApplication().getMainExecutor(), this::onDeviceConfigChange));
} }
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
@@ -122,18 +90,13 @@ public class NotificationVolumePreferenceController extends
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
mReceiver.register(false); mReceiver.register(false);
Binder.withCleanCallingIdentity(() ->
DeviceConfig.removeOnPropertiesChangedListener(this::onDeviceConfigChange));
} }
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
boolean separateNotification = isSeparateNotificationConfigEnabled();
return mContext.getResources().getBoolean(R.bool.config_show_notification_volume) return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
&& !mHelper.isSingleVolume() && separateNotification && !mHelper.isSingleVolume() ? (mRingerMode == AudioManager.RINGER_MODE_NORMAL
? (mRingerMode == AudioManager.RINGER_MODE_NORMAL ? AVAILABLE : DISABLED_DEPENDENT_SETTING) : UNSUPPORTED_ON_DEVICE;
? AVAILABLE : DISABLED_DEPENDENT_SETTING)
: UNSUPPORTED_ON_DEVICE;
} }
@Override @Override

View File

@@ -16,28 +16,22 @@
package com.android.settings.notification; package com.android.settings.notification;
import android.app.ActivityThread;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Binder;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.provider.DeviceConfig;
import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService;
import androidx.lifecycle.OnLifecycleEvent; import androidx.lifecycle.OnLifecycleEvent;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.Set;
/** /**
* This slider represents both ring and notification * This slider represents both ring and notification
*/ */
@@ -61,33 +55,14 @@ public class RingVolumePreferenceController extends
mVibrateIconId = R.drawable.ic_volume_ringer_vibrate; mVibrateIconId = R.drawable.ic_volume_ringer_vibrate;
mSilentIconId = R.drawable.ic_notifications_off_24dp; mSilentIconId = R.drawable.ic_notifications_off_24dp;
mSeparateNotification = isSeparateNotificationConfigEnabled();
updateRingerMode(); updateRingerMode();
} }
/**
* As the responsibility of this slider changes, so should its title & icon
*/
private void onDeviceConfigChange(DeviceConfig.Properties properties) {
Set<String> changeSet = properties.getKeyset();
if (changeSet.contains(SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION)) {
boolean valueUpdated = readSeparateNotificationVolumeConfig();
if (valueUpdated) {
updateEffectsSuppressor();
selectPreferenceIconState();
}
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mReceiver.register(true); mReceiver.register(true);
readSeparateNotificationVolumeConfig();
Binder.withCleanCallingIdentity(()
-> DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
ActivityThread.currentApplication().getMainExecutor(), this::onDeviceConfigChange));
updateEffectsSuppressor(); updateEffectsSuppressor();
selectPreferenceIconState(); selectPreferenceIconState();
@@ -101,8 +76,6 @@ public class RingVolumePreferenceController extends
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
mReceiver.register(false); mReceiver.register(false);
Binder.withCleanCallingIdentity(() ->
DeviceConfig.removeOnPropertiesChangedListener(this::onDeviceConfigChange));
} }
@Override @Override
@@ -112,9 +85,7 @@ public class RingVolumePreferenceController extends
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
boolean separateNotification = isSeparateNotificationConfigEnabled(); return UNSUPPORTED_ON_DEVICE;
return !separateNotification && !mHelper.isSingleVolume()
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
} }
@Override @Override
@@ -124,14 +95,10 @@ public class RingVolumePreferenceController extends
@Override @Override
protected boolean hintsMatch(int hints) { protected boolean hintsMatch(int hints) {
boolean notificationSeparated = isSeparateNotificationConfigEnabled();
return (hints & NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS) != 0 return (hints & NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS) != 0
|| (hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0 || (hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0;
|| ((hints & NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS)
!= 0 && !notificationSeparated);
} }
private final class H extends Handler { private final class H extends Handler {
private static final int UPDATE_EFFECTS_SUPPRESSOR = 1; private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
private static final int UPDATE_RINGER_MODE = 2; private static final int UPDATE_RINGER_MODE = 2;

View File

@@ -21,14 +21,11 @@ import android.app.NotificationManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Binder;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.util.Log; import android.util.Log;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import java.util.Objects; import java.util.Objects;
@@ -48,11 +45,8 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
protected Vibrator mVibrator; protected Vibrator mVibrator;
protected int mRingerMode = AudioManager.RINGER_MODE_NORMAL; protected int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
protected ComponentName mSuppressor; protected ComponentName mSuppressor;
protected boolean mSeparateNotification;
protected INotificationManager mNoMan; protected INotificationManager mNoMan;
private static final boolean CONFIG_SEPARATE_NOTIFICATION_DEFAULT_VAL = false;
public RingerModeAffectedVolumePreferenceController(Context context, String key, String tag) { public RingerModeAffectedVolumePreferenceController(Context context, String key, String tag) {
super(context, key); super(context, key);
mTag = tag; mTag = tag;
@@ -118,28 +112,6 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
return mMuteIcon; return mMuteIcon;
} }
protected boolean isSeparateNotificationConfigEnabled() {
return Binder.withCleanCallingIdentity(()
-> DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION,
CONFIG_SEPARATE_NOTIFICATION_DEFAULT_VAL));
}
/**
* side effect: updates the cached value of the config
* @return has the config changed?
*/
protected boolean readSeparateNotificationVolumeConfig() {
boolean newVal = isSeparateNotificationConfigEnabled();
boolean valueUpdated = newVal != mSeparateNotification;
if (valueUpdated) {
mSeparateNotification = newVal;
}
return valueUpdated;
}
/** /**
* Updates UI Icon in response to ringer mode changes. * Updates UI Icon in response to ringer mode changes.
* @return whether the ringer mode has changed. * @return whether the ringer mode has changed.

View File

@@ -16,7 +16,6 @@
package com.android.settings.notification; package com.android.settings.notification;
import android.app.ActivityThread;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@@ -26,17 +25,13 @@ import android.media.AudioManager;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.provider.DeviceConfig;
import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService;
import androidx.lifecycle.OnLifecycleEvent; import androidx.lifecycle.OnLifecycleEvent;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.Set;
/** /**
* This slider is used to represent ring volume when ring is separated from notification * This slider is used to represent ring volume when ring is separated from notification
*/ */
@@ -60,32 +55,14 @@ public class SeparateRingVolumePreferenceController extends
mVibrateIconId = R.drawable.ic_volume_ringer_vibrate; mVibrateIconId = R.drawable.ic_volume_ringer_vibrate;
mSilentIconId = R.drawable.ic_ring_volume_off; mSilentIconId = R.drawable.ic_ring_volume_off;
mSeparateNotification = isSeparateNotificationConfigEnabled();
updateRingerMode(); updateRingerMode();
} }
/**
* Show/hide settings
*/
private void onDeviceConfigChange(DeviceConfig.Properties properties) {
Set<String> changeSet = properties.getKeyset();
if (changeSet.contains(SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION)) {
boolean valueUpdated = readSeparateNotificationVolumeConfig();
if (valueUpdated) {
updateEffectsSuppressor();
selectPreferenceIconState();
}
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mReceiver.register(true); mReceiver.register(true);
readSeparateNotificationVolumeConfig();
DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
ActivityThread.currentApplication().getMainExecutor(), this::onDeviceConfigChange);
updateEffectsSuppressor(); updateEffectsSuppressor();
selectPreferenceIconState(); selectPreferenceIconState();
@@ -99,7 +76,6 @@ public class SeparateRingVolumePreferenceController extends
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
mReceiver.register(false); mReceiver.register(false);
DeviceConfig.removeOnPropertiesChangedListener(this::onDeviceConfigChange);
} }
@Override @Override
@@ -109,9 +85,7 @@ public class SeparateRingVolumePreferenceController extends
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
boolean separateNotification = isSeparateNotificationConfigEnabled(); return !mHelper.isSingleVolume() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return separateNotification && !mHelper.isSingleVolume()
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
} }
@Override @Override
@@ -125,8 +99,6 @@ public class SeparateRingVolumePreferenceController extends
|| (hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0; || (hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0;
} }
private final class H extends Handler { private final class H extends Handler {
private static final int UPDATE_EFFECTS_SUPPRESSOR = 1; private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
private static final int UPDATE_RINGER_MODE = 2; private static final int UPDATE_RINGER_MODE = 2;

View File

@@ -196,7 +196,6 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
ArrayList<VolumeSeekBarPreferenceController> volumeControllers = new ArrayList<>(); ArrayList<VolumeSeekBarPreferenceController> volumeControllers = new ArrayList<>();
volumeControllers.add(use(AlarmVolumePreferenceController.class)); volumeControllers.add(use(AlarmVolumePreferenceController.class));
volumeControllers.add(use(MediaVolumePreferenceController.class)); volumeControllers.add(use(MediaVolumePreferenceController.class));
volumeControllers.add(use(RingVolumePreferenceController.class));
volumeControllers.add(use(SeparateRingVolumePreferenceController.class)); volumeControllers.add(use(SeparateRingVolumePreferenceController.class));
volumeControllers.add(use(NotificationVolumePreferenceController.class)); volumeControllers.add(use(NotificationVolumePreferenceController.class));
volumeControllers.add(use(CallVolumePreferenceController.class)); volumeControllers.add(use(CallVolumePreferenceController.class));

View File

@@ -18,7 +18,6 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat; 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.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -26,15 +25,11 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import androidx.preference.PreferenceManager; 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.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowDeviceConfig;
@@ -45,7 +40,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@@ -64,9 +58,6 @@ public class NotificationVolumePreferenceControllerTest {
@Mock @Mock
private PreferenceManager mPreferenceManager; private PreferenceManager mPreferenceManager;
private static final String READ_DEVICE_CONFIG_PERMISSION =
"android.permission.READ_DEVICE_CONFIG";
private Context mContext; private Context mContext;
private NotificationVolumePreferenceController mController; private NotificationVolumePreferenceController mController;
@@ -97,34 +88,15 @@ public class NotificationVolumePreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse(); 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 * With the introduction of ring-notification volume separation, voice-capable devices could now
* display the notification volume slider. * display the notification volume slider.
*/ */
@Test @Test
public void isAvailable_voiceCapable_separatedFromRing_shouldReturnTrue() { public void isAvailable_whenVoiceCapable_shouldReturnTrue() {
when(mResources.getBoolean( when(mResources.getBoolean(
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true); com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
NotificationVolumePreferenceController controller = NotificationVolumePreferenceController controller =
new NotificationVolumePreferenceController(mContext); new NotificationVolumePreferenceController(mContext);
@@ -189,84 +161,13 @@ public class NotificationVolumePreferenceControllerTest {
} }
@Test @Test
public void enableSeparateNotificationConfig_controllerBecomesAvailable() { public void ringerModeSilent_getAvailability_returnsDisabled() {
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() {
when(mResources.getBoolean( when(mResources.getBoolean(
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true); com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
when(mHelper.isSingleVolume()).thenReturn(false); when(mHelper.isSingleVolume()).thenReturn(false);
when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
assertThat(mController.getAvailabilityStatus()) assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING); .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
} }

View File

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

View File

@@ -27,10 +27,8 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import org.junit.Before; import org.junit.Before;
@@ -81,21 +79,11 @@ public class SeparateRingVolumePreferenceControllerTest {
mController.setAudioHelper(mHelper); 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 * Maintain that the device does not need to be voice capable to display this slider
*/ */
@Test @Test
public void isAvailable_ringNotificationSeparated_isNotVoiceCapable_shouldReturnTrue() { public void isAvailable_whenNotVoiceCapable_shouldReturnTrue() {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
when(mHelper.isSingleVolume()).thenReturn(false); when(mHelper.isSingleVolume()).thenReturn(false);
when(mTelephonyManager.isVoiceCapable()).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)); keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.zen_mode_settings));
// Add keys with hidden resources // Add keys with hidden resources
keys.add("alarm_volume"); keys.add("alarm_volume");
keys.add("ring_volume"); keys.add("separate_ring_volume");
keys.add("notification_volume"); keys.add("notification_volume");
assertThat(keys).containsAtLeastElementsIn(niks); assertThat(keys).containsAtLeastElementsIn(niks);
@@ -93,7 +93,7 @@ public class SoundSettingsTest {
final int xmlId = settings.getPreferenceScreenResId(); final int xmlId = settings.getPreferenceScreenResId();
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); 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 notification = keys.indexOf("notification_volume");
int alarm = keys.indexOf("alarm_volume"); int alarm = keys.indexOf("alarm_volume");