Loading res/xml/channel_notification_settings.xml +1 −2 Original line number Diff line number Diff line Loading @@ -63,8 +63,7 @@ android:dialogTitle="@string/notification_channel_sound_title" android:order="11" android:showSilent="true" android:showDefault="true" android:ringtoneType="notification" /> android:showDefault="true"/> <!-- Vibration --> <com.android.settingslib.RestrictedSwitchPreference Loading src/com/android/settings/notification/SoundPreferenceController.java +14 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,14 @@ package com.android.settings.notification; import static android.media.AudioAttributes.USAGE_ALARM; import static android.media.AudioAttributes.USAGE_NOTIFICATION_RINGTONE; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; import android.preference.PreferenceManager; Loading Loading @@ -91,6 +95,16 @@ public class SoundPreferenceController extends NotificationPreferenceController public boolean handlePreferenceTreeClick(Preference preference) { if (KEY_SOUND.equals(preference.getKey()) && mFragment != null) { NotificationSoundPreference pref = (NotificationSoundPreference) preference; if (mChannel != null && mChannel.getAudioAttributes() != null) { if (USAGE_ALARM == mChannel.getAudioAttributes().getUsage()) { pref.setRingtoneType(RingtoneManager.TYPE_ALARM); } else if (USAGE_NOTIFICATION_RINGTONE == mChannel.getAudioAttributes().getUsage()) { pref.setRingtoneType(RingtoneManager.TYPE_RINGTONE); } else { pref.setRingtoneType(RingtoneManager.TYPE_NOTIFICATION); } } pref.onPrepareRingtonePickerIntent(pref.getIntent()); mFragment.startActivityForResult(preference.getIntent(), CODE); return true; Loading tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java +66 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.media.AudioAttributes; import android.media.RingtoneManager; import android.net.Uri; import android.os.UserManager; import android.provider.Settings; Loading @@ -54,6 +56,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.Robolectric; Loading Loading @@ -230,6 +233,69 @@ public class SoundPreferenceControllerTest { verify(mFragment, times(1)).startActivityForResult(any(), anyInt()); } @Test public void testOnPreferenceTreeClick_alarmSound() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); channel.setSound(null, new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_ALARM).build()); mController.onResume(appRow, channel, null, null); AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); NotificationSoundPreference pref = spy(new NotificationSoundPreference(mContext, attributeSet)); pref.setKey(mController.getPreferenceKey()); mController.handlePreferenceTreeClick(pref); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); assertEquals(RingtoneManager.TYPE_ALARM, intentArgumentCaptor.getValue().getIntExtra( RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); } @Test public void testOnPreferenceTreeClick_ringtoneSound() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); channel.setSound(null, new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build()); mController.onResume(appRow, channel, null, null); AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); NotificationSoundPreference pref = spy(new NotificationSoundPreference(mContext, attributeSet)); pref.setKey(mController.getPreferenceKey()); mController.handlePreferenceTreeClick(pref); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); assertEquals(RingtoneManager.TYPE_RINGTONE, intentArgumentCaptor.getValue().getIntExtra( RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); } @Test public void testOnPreferenceTreeClick_otherSound() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); channel.setSound(null, new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_UNKNOWN).build()); mController.onResume(appRow, channel, null, null); AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); NotificationSoundPreference pref = spy(new NotificationSoundPreference(mContext, attributeSet)); pref.setKey(mController.getPreferenceKey()); mController.handlePreferenceTreeClick(pref); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); assertEquals(RingtoneManager.TYPE_NOTIFICATION, intentArgumentCaptor.getValue().getIntExtra( RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); } @Test public void testOnActivityResult() { NotificationSoundPreference pref = mock(NotificationSoundPreference.class); Loading Loading
res/xml/channel_notification_settings.xml +1 −2 Original line number Diff line number Diff line Loading @@ -63,8 +63,7 @@ android:dialogTitle="@string/notification_channel_sound_title" android:order="11" android:showSilent="true" android:showDefault="true" android:ringtoneType="notification" /> android:showDefault="true"/> <!-- Vibration --> <com.android.settingslib.RestrictedSwitchPreference Loading
src/com/android/settings/notification/SoundPreferenceController.java +14 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,14 @@ package com.android.settings.notification; import static android.media.AudioAttributes.USAGE_ALARM; import static android.media.AudioAttributes.USAGE_NOTIFICATION_RINGTONE; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; import android.preference.PreferenceManager; Loading Loading @@ -91,6 +95,16 @@ public class SoundPreferenceController extends NotificationPreferenceController public boolean handlePreferenceTreeClick(Preference preference) { if (KEY_SOUND.equals(preference.getKey()) && mFragment != null) { NotificationSoundPreference pref = (NotificationSoundPreference) preference; if (mChannel != null && mChannel.getAudioAttributes() != null) { if (USAGE_ALARM == mChannel.getAudioAttributes().getUsage()) { pref.setRingtoneType(RingtoneManager.TYPE_ALARM); } else if (USAGE_NOTIFICATION_RINGTONE == mChannel.getAudioAttributes().getUsage()) { pref.setRingtoneType(RingtoneManager.TYPE_RINGTONE); } else { pref.setRingtoneType(RingtoneManager.TYPE_NOTIFICATION); } } pref.onPrepareRingtonePickerIntent(pref.getIntent()); mFragment.startActivityForResult(preference.getIntent(), CODE); return true; Loading
tests/robotests/src/com/android/settings/notification/SoundPreferenceControllerTest.java +66 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.media.AudioAttributes; import android.media.RingtoneManager; import android.net.Uri; import android.os.UserManager; import android.provider.Settings; Loading @@ -54,6 +56,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.Robolectric; Loading Loading @@ -230,6 +233,69 @@ public class SoundPreferenceControllerTest { verify(mFragment, times(1)).startActivityForResult(any(), anyInt()); } @Test public void testOnPreferenceTreeClick_alarmSound() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); channel.setSound(null, new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_ALARM).build()); mController.onResume(appRow, channel, null, null); AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); NotificationSoundPreference pref = spy(new NotificationSoundPreference(mContext, attributeSet)); pref.setKey(mController.getPreferenceKey()); mController.handlePreferenceTreeClick(pref); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); assertEquals(RingtoneManager.TYPE_ALARM, intentArgumentCaptor.getValue().getIntExtra( RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); } @Test public void testOnPreferenceTreeClick_ringtoneSound() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); channel.setSound(null, new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build()); mController.onResume(appRow, channel, null, null); AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); NotificationSoundPreference pref = spy(new NotificationSoundPreference(mContext, attributeSet)); pref.setKey(mController.getPreferenceKey()); mController.handlePreferenceTreeClick(pref); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); assertEquals(RingtoneManager.TYPE_RINGTONE, intentArgumentCaptor.getValue().getIntExtra( RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); } @Test public void testOnPreferenceTreeClick_otherSound() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH); channel.setSound(null, new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_UNKNOWN).build()); mController.onResume(appRow, channel, null, null); AttributeSet attributeSet = Robolectric.buildAttributeSet().build(); NotificationSoundPreference pref = spy(new NotificationSoundPreference(mContext, attributeSet)); pref.setKey(mController.getPreferenceKey()); mController.handlePreferenceTreeClick(pref); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture()); assertEquals(RingtoneManager.TYPE_NOTIFICATION, intentArgumentCaptor.getValue().getIntExtra( RingtoneManager.EXTRA_RINGTONE_TYPE, 0)); } @Test public void testOnActivityResult() { NotificationSoundPreference pref = mock(NotificationSoundPreference.class); Loading