Merge "Read flag to show/hide notification slider" into tm-qpr-dev am: 2552ae08ae
am: 6b156be280
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/20180104 Change-Id: If6e7bd4facd8a3bea6528b25767aed45e7175f7d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
committed by
Automerger Merge Worker
commit
bff773b41b
@@ -18,6 +18,7 @@ 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;
|
||||
|
||||
@@ -25,10 +26,17 @@ 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.R;
|
||||
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;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -37,11 +45,12 @@ 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)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class NotificationVolumePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private AudioHelper mHelper;
|
||||
@Mock
|
||||
@@ -52,6 +61,11 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
private Vibrator mVibrator;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
private static final String READ_DEVICE_CONFIG_PERMISSION =
|
||||
"android.permission.READ_DEVICE_CONFIG";
|
||||
|
||||
private Context mContext;
|
||||
private NotificationVolumePreferenceController mController;
|
||||
@@ -87,7 +101,9 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
public void isAvailable_voiceCapable_aliasedWithRing_shouldReturnFalse() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
|
||||
when(mResources.getBoolean(R.bool.config_alias_ring_notif_stream_types)).thenReturn(true);
|
||||
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
|
||||
|
||||
NotificationVolumePreferenceController controller =
|
||||
new NotificationVolumePreferenceController(mContext);
|
||||
@@ -105,7 +121,9 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
public void isAvailable_voiceCapable_separatedFromRing_shouldReturnTrue() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
|
||||
when(mResources.getBoolean(R.bool.config_alias_ring_notif_stream_types)).thenReturn(false);
|
||||
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
|
||||
|
||||
NotificationVolumePreferenceController controller =
|
||||
new NotificationVolumePreferenceController(mContext);
|
||||
@@ -170,4 +188,70 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
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()
|
||||
== BasePreferenceController.AVAILABLE).isTrue();
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,10 +27,13 @@ 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.R;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -39,9 +42,11 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
public class RingVolumePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
@@ -124,9 +129,10 @@ public class RingVolumePreferenceControllerTest {
|
||||
// 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);
|
||||
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "true", false);
|
||||
|
||||
final RingVolumePreferenceController controller =
|
||||
new RingVolumePreferenceController(mContext);
|
||||
|
||||
@@ -138,8 +144,9 @@ public class RingVolumePreferenceControllerTest {
|
||||
@Test
|
||||
public void ringNotificationStreamsAliased_sliderTitleIncludesBothRingNotification() {
|
||||
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_alias_ring_notif_stream_types)).thenReturn(true);
|
||||
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI,
|
||||
SystemUiDeviceConfigFlags.VOLUME_SEPARATE_NOTIFICATION, "false", false);
|
||||
|
||||
final RingVolumePreferenceController control = new RingVolumePreferenceController(mContext);
|
||||
|
||||
int expectedTitleId = R.string.ring_volume_option_title;
|
||||
@@ -150,39 +157,39 @@ public class RingVolumePreferenceControllerTest {
|
||||
@Test
|
||||
public void setHintsRing_aliased_Matches() {
|
||||
assertThat(mController.hintsMatch(
|
||||
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, true)).isTrue();
|
||||
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, false)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRingNotification_aliased_Matches() {
|
||||
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
|
||||
true)).isTrue();
|
||||
false)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintNotification_aliased_Matches() {
|
||||
assertThat(mController
|
||||
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
|
||||
true)).isTrue();
|
||||
false)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRing_unaliased_Matches() {
|
||||
assertThat(mController.hintsMatch(
|
||||
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, false)).isTrue();
|
||||
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, true)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRingNotification_unaliased_Matches() {
|
||||
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
|
||||
false)).isTrue();
|
||||
true)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintNotification_unaliased_doesNotMatch() {
|
||||
assertThat(mController
|
||||
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
|
||||
false)).isFalse();
|
||||
true)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user