Launch correct tone picker for audio attributes
Test: robotests Fixes: 129353516 Change-Id: Iacbf5008f186e59377e534da747544d33a20f81f
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
Reference in New Issue
Block a user